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)
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)
import sys

def do_deduction(S, T):
    while True:
        if len(S) == len(T):
            if S == T:
                print (1)
            else:
                print (0)
            return
        
        if T[-1] == "A":
            T = T[:-1]
        else:
            T = T[:-1][::-1]

if __name__ == "__main__":
    input = sys.stdin.readline
    S = input().strip()
    T = input().strip()
    do_deduction(S, T)
import sys
from bisect import bisect_left
input = sys.stdin.readline

N = int(input())
A = list(map(int, input().split()))
stack = [0]

for i in A:
    if stack[-1] < i:
        stack.append(i)
    else:
        stack[bisect_left(stack, i)] = i
    
print (len(stack)-1)
import sys
input = sys.stdin.readline

N = int(input())

DP = [0] * 1001
DP[1] = 1
DP[2] = 3

for i in range(3, 1001):
    DP[i] = DP[i-1] + (DP[i-2] * 2)

print (DP[N] % 10007)
import sys
input = sys.stdin.readline
words = input()
for i in range(0, len(words), 10):
    print (words[i:i+10])
#include <iostream>
#include <string>
using namespace std;

int main(void)
{
	// 1. 변수 선언부 
	int N = 0; // 입력 받을 N개의 숫자 
	string M; // N개의 숫자를 문자열로 받기 위한 변수 
	int sum = 0; // 문자열로 받은 N개의 숫자의 합을 담는 변수  
	cin >> N; // N개의 숫자 입력 
	char *arr = new char[N]; // N개의 숫자를 동적 배열로 받음 
	cin >> M; // N개의 숫자를 문자열로 받아 M에 넣음 
	
	// 2. 핵심 알고리즘 동작부 
	for (int i =0; i<N; i++)
	{
		arr[i] = M[i];
		sum = sum + arr[i] - 48; // 아스키코드 0에 해당하는 수 48을 빼줌
	}
	
	// 3. 결과 출력부 
	cout << sum << endl;
	return 0;
}
while True:
    try:
        print (input())
    except EOFError:
        break
import sys
input = sys.stdin.readline

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

coordinates.sort(key=lambda x: (x[1], x[0]))
for i in coordinates:
    print (*i)

+ Recent posts