from itertools import combinations

def dfs(start):
    if M == len(picked):
        print (*picked)
        return
    
    for i in range(start, N+1):
        if i not in picked:
            picked.append(i)
            dfs(i+1)
            picked.pop()

if __name__ == "__main__":
    N, M = list(map(int, input().split()))
    
    # method 1. using combinations in litertools library
    # array = [i+1 for i in range(N)]
    # result = list(combinations(array, M))
    # for i in result:
    #     print (*i)
    
    # method 2. using maual recursion
    picked = []
    dfs(start=1)
N, M = list(map(int, input().split()))
picked = []
array = [i for i in range(N)]
n = len(array)

def permutation():
    if len(picked) == M:
        print (' '.join(str(i) for i in picked))
        return
    else:
        for i in range(1, n+1):
            if i not in picked:
                picked.append(i)
                permutation()
                picked.pop()
permutation()
#include <iostream>
#include <vector>
using namespace std;

long long sum(vector<int> &a) // Solution 1
{
	long long ans = 0;
	
	for(vector<int>::iterator i = a.begin(); i<a.end(); i++)
	{
		ans = ans + *i;
	}
	
	return ans;
}

//long long sum(vector<int> &a) // Solution 2
//{
//	long long Sum = 0;
//	for(auto aa: a)
//	{
//		Sum = Sum + aa;
//	}
//	
//	return Sum;
//}


//int getSum(int a[], int l) // Solution 3
//{
//	int Sum = 0;
//	
//	for (int i=0; i<l); i++)
//	{
//		if (a[i] >=0 and a[i]<=1000000)
//		{
//			Sum = Sum + a[i];
//		}
//		
//		else
//			return 0;
//	}
//	
//	return Sum;
//}
//
//int main(void)
//{
//	
//	int n = 0;
//	
//	cin >> n;
//	
//	if (n>=1 and n<=300000)
//	{
//		int a[n] = {0,};
//		
//		for (int i=0; i<n; i++)
//		{
//			cin >> a[i];
//		}
//		
//		int Sum = getSum(a, sizeof(a)/sizeof(int));
//		
//		cout << Sum << endl;
//	}
//	
//	return 0;
//}
#include <iostream>

using namespace std;

int main(void)
{
	cin.tie(NULL);
	ios_base::sync_with_stdio(false);
	
	int T = 0;
	int A = 0;
	int B = 0;
	
	cin >> T;
	
	if (T<=1000000)
	{
		for (int i=0; i<T; i++)
		{
			cin >> A >> B;	
			if ((A>=1 and A<=1000) and (B>=1) and (B<=1000))
			{
				cout << A+B << '\n';	
			}
		}
	}
	
	return 0;
}
import sys
input = sys.stdin.readline
n = int(input())
Q1, R1 = divmod(n, 5)
while True:
    if R1 % 2 == 0:
        Q2, R2 = divmod(R1, 2)
        print (Q1 + Q2)
        break
    else:
        Q1 = Q1 - 1
        R1 = R1 + 5 
    
    if Q1 < 0:
        print (-1)
        break
import sys

def dfs(idx, count):
    global result
    if count == N // 2:
        start, link = 0, 0
        for i in range(N):
            for j in range(N):
                if selected[i] and selected[j]:
                    start += score[i][j]
                elif not selected[i] and not selected[j]:
                    link += score[i][j]
        result = min(result, abs(start - link))

    for i in range(idx, N):
        if selected[i]:
            continue
        selected[i] = 1
        dfs(i+1, count+1)
        selected[i] = 0

if __name__ == "__main__":
    sys.setrecursionlimit(100000)
    input = sys.stdin.readline
    N = int(input())
    score = [list(map(int, input().split())) for _ in range(N)]
    selected = [0 for _ in range(N)]
    result = sys.maxsize
    dfs(0, 0)
    print (result)
import sys
from itertools import permutations

def get_operations(in_operation: list) -> list:
    basic_operation = ['+', '-', '*', '/']
    operations : list = []
    for i in range(len(in_operation)): # [2, 1, 1, 1]
        for j in range(in_operation[i]):
            operations.append(basic_operation[i])
    
    return operations


def get_min_max_value(operations: list) -> None:
    global minimum, maximum
    for case in permutations(operations, N-1):
        total = numbers[0]
        for i in range(1, N):
            if case[i-1] == "+":
                total += numbers[i]
            
            elif case[i-1] == "-":
                total -= numbers[i]
                
            elif case[i-1] == "*":
                total *= numbers[i]
                
            elif case[i-1] == "/":
                total = int(total / numbers[i])
        
        if total > maximum:
            maximum = total
            
        if total < minimum:
            minimum = total
    
        
if __name__ == "__main__":
    input = sys.stdin.readline
    N = int(input())
    numbers = list(map(int, input().split()))
    in_operation = list(map(int, input().split()))
    maximum = -1e9
    minimum = 1e9
    
    operations = get_operations(in_operation)
    get_min_max_value(operations)
    
    print (maximum)
    print (minimum)
#include <iostream>
using namespace std;

int main(void)
{
	int X = 0;
	int Y = 0;
	
	cin >> X >> Y;
	
	if ((X>=-1000 and X<=1000) and (X!=0) and (Y>=-1000 and Y<=1000) and (Y!=0))
	{
		if (X>0 and Y>0)
			cout << "1" << endl;
		
		if (X<0 and Y>0)
			cout << "2" << endl;
			
		if (X<0 and Y<0)
			cout << "3" << endl;
			
		if (X>0 and Y<0)
			cout << "4" << endl;
	}
	
	return 0;
}
import sys
input = sys.stdin.readline

def get_max_profit(start):
    global profits, days, poss_profits
    if start > N:
        return

    for i in range(start, len(consulting)):
        day, profit = consulting[i]
        if i + day <= N:
            profits.append(profit)
            days.append(day)
            get_max_profit(day+i)
            profits.pop()
            days.pop()
    
    poss_profits.append(sum(profits))

N = int(input())
consulting = []
poss_profits = []
for _ in range(N):
    consulting.append(list(map(int, input().split())))

days, profits = [], []
get_max_profit(0)
print(max(poss_profits))
import sys
input = sys.stdin.readline

N = int(input())
road_len = list(map(int, input().split()))
oil_cost = list(map(int, input().split()))
total_cost = 0

total_cost += (road_len[0] * oil_cost[0])
min_price = oil_cost[0]

for i in range(1, N-1):
    if min_price > oil_cost[i]:
        min_price = oil_cost[i]

    total_cost += (min_price * road_len[i])

print (total_cost)

+ Recent posts