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 = [-sys.maxsize]

for i in A:
    if stack[-1] < i:
        stack.append(i)
    else:
        stack[bisect_left(stack, i)] = i

print (len(stack)-1)
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

N = int(input())

DP = [0] * (1000 + 1)
DP[1] = 1
DP[2] = 2

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

print (DP[N] % 10007)
import sys

input = sys.stdin.readline
M = int(input())
S = set()

for _ in range(M):
    cmd = input().split()
    if cmd[0] == "all":
        S = set([i for i in range(1, 21)])
    elif cmd[0] == "empty":
        S = set()
    elif cmd[0] == "add":
        S.add(int(cmd[1]))
    elif cmd[0] == "check":
        print (1 if int(cmd[1]) in S else 0)
    elif cmd[0] == "remove":
        S.discard(int(cmd[1]))
    elif cmd[0] == "toggle":
        if int(cmd[1]) in S:
            S.discard(int(cmd[1]))
        else:
            S.add(int(cmd[1]))
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
while True:
    try:
        print (input())
    except EOFError:
        break
#include <iostream>

using namespace std;

int main(void)
{
	
	char character;
	
	cin >> character;
	int integer(character);
	
	cout << integer << endl;
	
	return 0;
}
#include <iostream>
using namespace std;

int main(void)
{
	int N = 0;
	int i = 2;
	
	cin >> N;
	
	if (N>=1 and N<=10000000)
	{
		while (true)
		{
			if(N % i == 0) // 72 % 2 == 0, 
			{
				cout << i << endl; // 2 
				N = N / i; // 36 = 72 / 2
				i = 1; 
			}	
			i = i + 1;
			
			if (N==1)
			{
				break;
			}
		}
	}
	
	return 0;
	
}
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)
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[0], x[1]))

for i in coordinates:
    print (*i)
import sys
input = sys.stdin.readline

N = int(input())

product = []
for _ in range(N):
    product.append(int(input()))

product.sort(reverse=True)

cost = 0
buffer = []
for i in range(len(product)):
    buffer.append(product[i])
    if len(buffer) == 3:
        cost += buffer[0] + buffer[1]
        buffer = []
    
    if i == len(product)-1:
        cost += sum(buffer)

print (cost)
N = int(input())
lines = list(map(int, input().split()))
lines = sorted(lines)
_sum = 0
times = []
for num in lines:
    _sum = _sum + num
    times.append(_sum)
print (sum(times))
import sys 
from math import factorial

if __name__ == "__main__":
    input = sys.stdin.readline
    N, K = list(map(int, input().split()))
    result = factorial(N) // (factorial(K) * factorial(N-K))
    print (result % 10007)
import sys
from math import factorial

def solution_manual(n):
    if n == 0:
        return 1

    if n == 1:
        return 1
    
    return n * solution_manual(n-1)

if __name__ == "__main__":
    input = sys.stdin.readline

    N, K = list(map(int, input().split()))
    
    # 1. library
    #print (factorial(N) // (factorial(K) * factorial(N-K)))

    # 2. solution_manual
    print (solution_manual(N) // (solution_manual(K) * solution_manual(N-K)))
import sys
input = sys.stdin.readline
N, K = map(int, input().split())
cnt = 0
coins = []
for _ in range(N):
    coins.append(int(input()))

coins.reverse()
_sum = 0

for coin in coins:
    if coin > K:
        continue
    
    while True:
        _sum = _sum + coin
        cnt = cnt + 1
        if _sum > K:
            _sum = _sum - coin
            cnt = cnt -1
            break
    if _sum == K:
        print(cnt)
        break
#include <iostream>

using namespace std;

int main(void)
{
	int T = 0;
	int A = 0;
	int B = 0;
	
	cin >> T;
	
	for (int i=0; i<T; i++)
	{
		cin >> A >> B;
		if (A>0 and B<10)
		{
			cout << "Case #" << i+1 << ": " << A << " + " << B << " = " << A+B << endl;
		}
	}
	
	return 0;
}
#include <iostream>
using namespace std;

int main(void)
{
	int T = 0;
	int A = 0;
	int B = 0;
	
	cin >> T;
	
	for (int i=0; i<T; i++)
	{
		cin >> A >> B;
		if (A>0 and B<10)
		{
			cout << "Case #" << i+1 << ": " << A+B << endl;	
		}
	}
	
	return 0;
}
import sys
import heapq
input = sys.stdin.readline

N = int(input())
lectures = []

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

lectures.sort(key = lambda x:x[0])
heap = []

heapq.heappush(heap, lectures[0][1])
for i in range(1, N):
    if heap[0] > lectures[i][0]:
        heapq.heappush(heap, lectures[i][1])
    else: # heap[0] <= lectures[i][0]
        heapq.heappop(heap)
        heapq.heappush(heap, lectures[i][1])

print (len(heap))

 

#include <stdio.h>

int main(void)
{
	int i = 0;
	int j = 0;
	
	scanf("%d %d", &i, &j);
	
	printf("%d", i*j);
	
	return 0;
}
import sys
input = sys.stdin.readline
N = int(input())
limit = 10001
numbers = [0] * limit

for _ in range(N):
    num = int(input())
    numbers[num] +=1

for i in range(len(numbers)):
    if i !=0:
        for _ in range(numbers[i]):
            print (i)

+ Recent posts