Harryxun/sft_time huggingface dataset:
### BUGGY CODE ###

import numpy as np
import math
import itertools
n = np.arange(1,int(input())+1)
pp = list(itertools.product(n, repeat=3))
sum = 0
for p in pp:
  sum+=math.gcd(math.gcd(p[0],p[1]),p[2])
print(sum)

### FIXED CODE ###

import math
import itertools
n = range(1,int(input())+1)
ppp = list(itertools.combinations(n, 3))
pp = list(itertools.combinations(n, 2))
asum,bsum,csum = 0,0,0
for p in ppp:
  asum+=math.gcd(math.gcd(p[0],p[1]),p[2])

for p in pp:
  bsum+=math.gcd(p[0],p[1])

for p in n:
  csum+=p

print(asum*6+bsum*6+csum)
### BUGGY CODE ###

# -*- coding: utf-8 -*-

n = int(input())

nums = list(map(int, input().split()))

ans = 1
for i in range(n):
    ans *= nums[i]

if ans > 10 ** 18:
    print(-1)
    exit()

print(ans)


### FIXED CODE ###

# -*- coding: utf-8 -*-

n = int(input())

nums = sorted(list(map(int, input().split())))

ans = 1
for i in range(n):
    ans *= nums[i]

    if ans == 0:
        print(0)
        exit()

    if ans > 10 ** 18:
        print(-1)
        exit()

print(ans)
### BUGGY CODE ###

n, k = map(int, input().split())
a = list(map(int, input().split()))

li = []
for i in range(n-k +1):
    tmp = a[i]
    for j in range(1, k):
        tmp *= a[i +j]
    li.append(tmp)

for i in range(len(li) -1):
    if (li[i] >= li[i+1]):
        print("No")
    else:
        print("Yes")

### FIXED CODE ###

n, k = map(int, input().split())
a = list(map(int, input().split()))
for i in range(n -k):
    if a[i] >= a[k+i]:
        print("No")
    else:
        print("Yes")
### BUGGY CODE ###

import bisect

n = int(input())
a = sorted(list(map(int, input().split())))
b = sorted(list(map(int, input().split())))
c = sorted(list(map(int, input().split())))
cnt = 0
info = []

for i in range(n):
    b_p = bisect.bisect_left(a, b[i])
    info.append(b_p)

for k in range(n):
    a_p = bisect.bisect_left(b, c[k])
    cnt += sum(info[:a_p])

print(cnt)

### FIXED CODE ###

import bisect

n = int(input())
a = sorted(list(map(int, input().split())))
b = sorted(list(map(int, input().split())))
c = sorted(list(map(int, input().split())))
cnt = 0
info1 = []


for i in range(n):
    b_p = bisect.bisect_left(a, b[i])
    info1.append(b_p) # bがそれぞれ何種類のaを載せれるか

info2 = [info1[0]]
for l in range(1, n):
    info2.append(info2[l-1] + info1[l])

for k in range(n):
    a_p = bisect.bisect_left(b, c[k])
    if a_p != 0:
        cnt += info2[a_p - 1]  # cがそれぞれ何種類のbを載せれるか
print(cnt)
### BUGGY CODE ###

n = int(input())
c = input()
cc = c
ans = 0

while cc.count('WR') >= 1:
    leftW = cc.find('W')
    rightR = cc.rfind('R')
    if leftW != -1 and rightR != -1:
        cc = cc[:leftW] + 'R' + cc[leftW+1:rightR] + 'W' + cc[rightR+1:]
        ans += 1
print(ans)

### FIXED CODE ###

n = int(input())
c = input()

w = 0
r = c.count('R')
i = 0
ans = max(w, r)
while i <= n - 1:
    if c[i] == 'W':
        w += 1
    else:
        r -= 1
    ans = min(ans, max(w, r))
    i += 1
print(ans)
### BUGGY CODE ###

import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin, log, log10
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def debug(*args):
    if debugmode:
        print(*args)
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def FLOAT(): return float(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7
dx = [0, 0, 1, -1, 1, -1, -1, 1]
dy = [1, -1, 0, 0, 1, -1, 1, -1]
debugmode = True

#0埋め　桁合わせ
def digit(n, r):
    n = str(n)
    l = len(n)
    for i in range(r - l):
        n = '0' + n
    return n

n = INT()
a = LIST()
arr = [0 for _ in range(61)]
arr2 = [0 for _ in range(61)]
for i in range(1, n + 1):
    bn = digit(bin(a[i - 1])[2:], 61)
    for j in range(61):
        arr[j] += int(bn[j])
        arr2[j] += int(not int(bn[j]))
for i in range(61):
    if arr2[i] == n:
        arr2[i] = 0
ans = 0
for i in range(61):
    ans *= 2
    ans += arr[i] * arr2[i]
    ans %= mod
print(ans)


### FIXED CODE ###

import sys
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def LIST(): return list(map(int, input().split()))
mod = 10 ** 9 + 7

n = INT()
a = LIST()
arr = [0 for _ in range(61)]
for i in range(n):
    ai = a[i]
    for j in reversed(range(61)):
        arr[j] += ai % 2
        ai //= 2
ans = 0
for i in range(61):
    ans *= 2
    arri = arr[i]
    ans += arri * (n - arri if arri != 0 else 0)
    ans %= mod
print(ans)
### BUGGY CODE ###

a,b,c=map(int,input().split())
print("\n".join([str(i) for i in range(a,b+1) if abs(a-i)<c or abs(b-i)<c]))

### FIXED CODE ###

a,b,c=map(int,input().split())
l=set()
for i in range(a,a+c):
    if i!=b:l.add(i)
    else:break
for i in range(max(b-c+1,a),b+1):
        l.add(i)
print("\n".join(map(str,sorted(list(l)))))
### BUGGY CODE ###

from collections import deque
h,w = map(int, input().split())
al = [input() for _ in range(h)]

inf = 10**9
f = [[inf]*w for _ in range(h)]
q = deque()
for hi in range(h):
    for wi in range(w):
        if al[hi][wi]=="#":
            f[hi][wi] = 0
            q.append((hi,wi))

while len(q)>0:
    hi,wi = q.popleft()
    c = f[hi][wi]

    for dh,dw in [[0,1],[1,0],[0,-1],[-1,0]]:
        nh = hi+dh
        nw = wi+dw
        if h>nh>=0 and w>nw>=0:
            if f[nh][nw]>c+1:
                f[nh][nw] = c+1
                q.append((nh,nw))

res = 0
for hi in range(h):
    for wi in range(w):
        res = max(res,f[hi][wi])
print(res)

### FIXED CODE ###

# -*- coding: utf-8 -*-
h,w = map(int, input().split())
al = [list(input()) for _ in range(h)]
cnt = 0

q = []
for hi in range(h):
    for wi in range(w):
        if al[hi][wi]=="#":
            q.append((hi,wi))

while len(q)>0:
    nq = []
    cnt += 1
    for hi,wi in q:
        for d in [[1,0],[0,1],[-1,0],[0,-1]]:
            if h>hi+d[0]>=0 and w>wi+d[1]>=0:
                if al[hi+d[0]][wi+d[1]]==".":
                    al[hi+d[0]][wi+d[1]] = "#"
                    nq.append((hi+d[0], wi+d[1]))
    q = nq

print(cnt-1)
### BUGGY CODE ###

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

num = N
for i in range(N)[::-1]:
    sort_A[i] = A.index(num) + 1
    num -= 1

print(' '.join(list(map(str,sort_A))))

### FIXED CODE ###

from operator import itemgetter

N = int(input())
A = list(map(int,input().split()))
index_A = sorted([[i+1,x] for i,x in enumerate(A)],key=itemgetter(1))
A = [i[0] for i in index_A]

print(" ".join(list(map(str,A))))
### BUGGY CODE ###

straights=[]
nk =input().rstrip().split(" ")
n =int(nk[0])
k =int(nk[1])
numbers =input().rstrip().split(" ")
for i in range(n-k+1):
    wa=0
    for j in range(k):
        wa =wa+int(numbers[i+j])
    straights.append(wa)
#print(straights)
straights2 =sorted(straights, reverse=True)
#print(straights2)
sigma=straights2[0]
answer =(sigma+k)/2
print(answer)

### FIXED CODE ###

nk=input().rstrip().split(" ")
n=int(nk[0])
k=int(nk[1])
numbers=input().rstrip().split(" ")
sigmas=[0]
sigma=0
for i in range(n):
    sigma=sigma+(int(numbers[i])+1)/2
    sigmas.append(sigma)
#print(sigmas)
deltas=[]
for i in range(n-k+1):
    delta=sigmas[k+i]-sigmas[i]
    deltas.append(delta)
#print(deltas)
answer=0
for delt in deltas:
    if delt>=answer:
        answer=delt
print(answer)
### BUGGY CODE ###

S = input().split()

#冷蔵庫
A = int(S[0])
#電子レンジ
B = int(S[1])
#割引券
M = int(S[2])



a = list(map(int,input().split()))
b = list(map(int,input().split()))

total_mini = 999999999
for j in range(A):
    for k in range(B):
        total = a[j] + b[k]
        if total_mini > total:
            total_mini = total



minimum = 999999999
for i in range(M):
    m = list(map(int,input().split()))
    amount = a[m[0]-1] + b[m[1]-1] - m[2]

    if minimum > amount:
        minimum = amount


if minimum <= total_mini:
    print(minimum)
else:
    print(total_mini)


### FIXED CODE ###

S = input().split()

#冷蔵庫
A = int(S[0])
#電子レンジ
B = int(S[1])
#割引券
M = int(S[2])



a = list(map(int,input().split()))
b = list(map(int,input().split()))
total_mini = min(a) + min(b)


for i in range(M):
    m = list(map(int,input().split()))
    amount = a[m[0]-1] + b[m[1]-1] - m[2]

    if total_mini > amount:
        total_mini = amount


print(total_mini)
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10**5)

MOD=10**9+7
n,k=map(int,input().split())
a=list(map(int,input().split()))

a.sort(reverse=True)


from scipy.misc import comb


def mod_combination(n, k, mod):
    # nCk (mod m)
    def mod_permutation(n, k, mod):
        if n<=k:
            return 1
        else:
            return (n * mod_permutation(n-1,k,mod))%mod

    def mod_inv_permutation(k, mod):
        k, mod = int(k), int(mod)
        if k<=1:
            return 1
        else:
            return (pow(k,mod-2,mod) * mod_inv_permutation(k-1, mod))%mod

    return (mod_permutation(n,n-k,mod) * mod_inv_permutation(k, mod))%mod
  
  
c=[]
for i in range(1,n+1):
  c.append(mod_combination(n-i,k-1,MOD))
lc=len(c)
#print(c,a)
sum=0
for i in range(lc):
  sum+=c[i]*(a[i]-a[-i-1])%MOD
  
print(sum%MOD)


### FIXED CODE ###

MOD=10**9+7
n,k=map(int,input().split())
a=list(map(int,input().split()))

a.sort(reverse=True)


fact = [1]
fact_inv = [1]
mod=10**9+7
for i in range(10**5+1):
    new_fact = fact[-1]*(i+1)%mod
    fact.append(new_fact)
    fact_inv.append(pow(new_fact,mod-2,mod))


def mod_comb_k(n,k,mod):
    return fact[n] * fact_inv[k] % mod * fact_inv[n-k] %mod

  
c=[]
for i in range(1,n-k+1+1):
  c.append(mod_comb_k(n-i,k-1,MOD))
lc=len(c)
#print(c,a)
sum=0
for i in range(lc):
  sum+=c[i]*(a[i]-a[-i-1])%MOD
  
print(sum%MOD)
### BUGGY CODE ###

import math

ans = []
while True:
	try:
		n = int(raw_input())
		if n < 2:
			ans.append(0)
			continue
		prime_list = range(3, n + 1, 2)
		prime_list.insert(0, 2)
		head = prime_list[0]
		i = 0
		while head < math.sqrt(n):
			for j in range(len(prime_list) - 1, 0, -1):
				if (prime_list[j] % head == 0) & (prime_list[j] != head):
					del prime_list[j]
			i += 1
			head = prime_list[i]
		ans.append(len(prime_list))
	except EOFError:
		break
for num in ans:
	print num

### FIXED CODE ###

MAX = 1000000
prime = [1] * MAX
prime[0], prime[1] = 0, 0
i = 2
while i * i < MAX:
    j = 2
    while i * j < MAX:
        prime[i * j] = 0
        j += 1
    i += 1
for k in range(1, len(prime)):
    prime[k] += prime[k-1]

while True:
    try:
        n = int(raw_input())
        print prime[n]
    except EOFError:
        break
### BUGGY CODE ###

n = int(input())
p = list(map(int, input().split()))
c = 1
for i in range(1, n):
    flg = True
    for j in range(0, i):
        if p[j] < p[i]:
            flg = False
            break
    c += 1 if flg else 0
print(c)

### FIXED CODE ###

n = int(input())
p = list(map(int, input().split()))
m = [p[0]]
c = 1
for i in range(1, n):
    m.append(min(m[i - 1], p[i]))
    if m[i] == p[i]:
        c += 1
print(c)
### BUGGY CODE ###

import sys

sys.setrecursionlimit(10 ** 9)
from bisect import bisect, bisect_left

# class Node:
#     def __init__(self, idx):
#         self.idx = idx
#         self.v = 0
#         self.parent = None
#         # self.children = []
#
#     def make_tree(self, addval=0):
#         self.v += addval
#         keyidx = bisect_left(brs_keys, self.idx)
#         while keyidx < len(brs_keys) and brs_keys[keyidx] == self.idx:
#             ni = brs[keyidx][1]
#             node = nodes[ni]
#             # if not node.children:
#             #     self.children.append(node)
#             node.make_tree(self.v)
#             keyidx += 1
#         # for c in self.children:
#         #     c.make_tree(self.v)
#
#     def __str__(self):
#         return str(self.idx)


N, Q = [int(_) for _ in input().split()]
nodes = [0] * N

brs = []
for i in range(N - 1):
    a, b = [int(_) - 1 for _ in input().split()]
    brs.append((a, b))
    brs.append((b, a))

brs.sort()
brs_keys = [b[0] for b in brs]

for i in range(Q):
    p, x = [int(_) for _ in input().split()]
    nodes[p - 1] += x


ans = [-1] * N


def tree(node_idx, addval):
    ans[node_idx] = nodes[node_idx] + addval
    keyidx = bisect_left(brs_keys, node_idx)
    while keyidx < len(brs_keys) and brs_keys[keyidx] == node_idx:
        ni = brs[keyidx][1]
        if ans[ni] < 0:
            tree(ni, ans[node_idx])
        keyidx += 1


tree(0, 0)

print(*[n for n in ans])


### FIXED CODE ###

import sys
from collections import deque

sys.setrecursionlimit(10 ** 9)
input = sys.stdin.readline

N, Q = [int(_) for _ in input().split()]

edges = [[] for _ in range(N + 1)]
for i in range(N - 1):
    a, b = [int(_) for _ in input().split()]
    edges[a].append(b)
    edges[b].append(a)

P = [0] * (N + 1)

for q in range(Q):
    p, x = [int(_) for _ in input().split()]
    P[p] += x

que = deque()
que.append((1, 0))

while que:
    v, parent = que.popleft()
    P[v] += P[parent]
    for next_v in edges[v]:
        if next_v == parent: continue
        que.append((next_v, v))

# def f(v, parent=0):
#     P[v] += P[parent]
#
#     for next_v in edges[v]:
#         if next_v == parent: continue
#         f(next_v, v)
#
#
# f(1)
print(*[P[i] for i in range(1, N + 1)])
### BUGGY CODE ###

# python には結構厳しいTLE・・・python以外のお勉強時間ないよ～( ;∀;)
# . から見た # の最大距離の方が楽ではあるが・・・
# 嫌いだけど def main も使ってみた．
import numpy as np
import sys

def main():
  H, W = list(map(int, input().split()))
  all_in = sys.stdin.readlines()
  all_count = H * W
  blacks = [i*W+j for i in range(H) for j in range(W) if all_in[i][j] == "#"]
  L = [False] * all_count
  for black in blacks:
    L[black] = True
  black_count = len(blacks)
 
  cands_H = [-W, W]
  cands_W = [-1, 1]
  result = 0
  while black_count < all_count:
    next_steps = set([black+cand for black in blacks for cand in cands_H]) | set([black+cand for black in blacks for cand in cands_W if black%W not in [0, W-1]])
    blacks = [i for i in next_steps if i >= 0 and i < all_count and not L[i]]
    for i in blacks:
      L[i] = True
    black_count += len(blacks)
    result += 1

  print(result)

if __name__ == "__main__":
  main()

### FIXED CODE ###

# python には結構厳しいTLE・・・python以外のお勉強時間ないよ～( ;∀;)
# . から見た # の最大距離の方が楽ではあるが・・・
# 嫌いだけど def main も使ってみた．
from collections import deque
import copy

def main():
  H, W = list(map(int, input().split()))
  L = [[j=="#" for j in input()] for i in range(H)]
  q = deque([(i, j) for i in range(H) for j in range(W) if L[i][j]])
  cands = [(0, -1), (0, 1), (-1, 0), (1, 0)]
  result = 0
  while True:
    nq = deque()
    while q:
      i, j = q.popleft()
      if i > 0 and not L[i-1][j]:
        L[i-1][j] = True
        nq.append((i-1, j))
      if j > 0 and not L[i][j-1]:
        L[i][j-1] = True
        nq.append((i, j-1))
      if i < H-1 and not L[i+1][j]:
        L[i+1][j] = True
        nq.append((i+1, j))
      if j < W-1 and not L[i][j+1]:
        L[i][j+1] = True
        nq.append((i, j+1))
    if nq:
      q = copy.copy(nq)
    else:
      break    
    result += 1
  print(result)

if __name__ == "__main__":
  main()
### BUGGY CODE ###

N, M = map(int, input().split())
A = list(map(int, input().split()))
num = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]
B = [(i, num[i]) for i in A]
ans = {0: 0, 1: 0}
for i in range(2, N + 1):
    x = 0
    for j, k in B:
        if i - k < 0:
            continue
        if i == k:
            x = max(x, j)
            continue
        an = ans[i - k]
        if an == 0:
            continue
        x = max(x, an * 10 + j)
        x = max(x, j * 10 ** len(str(an)) + an)
    ans[i] = x
print(ans[N])

### FIXED CODE ###

N, M = map(int, input().split())
A = list(map(int, input().split()))
num = [2, 5, 5, 4, 5, 6, 3, 7, 6]
ans = {}
for i in range(N + 1):
    x = 0
    for j in A:
        k = num[j - 1]
        if i - k < 0:
            continue
        if i == k:
            x = max(x, j)
            continue
        an = ans[i - k]
        if an == 0:
            continue
        x = max(x, an * 10 + j)
    ans[i] = x
print(ans[N])
### BUGGY CODE ###

#!/usr/bin/env python3

def main():
    *N, = map(int, open(0).read().split())
    h = N[2:]
    K = N[1]
    N = N[0]

    D = [[] for i in range(0, N)]
    for i in range(0, N):
        for j in range(0, N):
            D[i].append(abs(h[i] - h[j]))
        D[i].sort()
    S = []
    for i in range(0, N):
        S.append(sum(D[i][0:K]))

    print(min(S))


main()

### FIXED CODE ###

#!/usr/bin/env python3

def main():
    *N, = map(int, open(0).read().split())
    h = N[2:]
    K = N[1]
    N = N[0]

    h.sort(reverse=True)
    ans = max(h) - min(h)
    for i in range(0, N - K + 1):
        d = h[i] - h[i + K -1]
        if d < ans:
            ans = d
    print(ans)


main()
### BUGGY CODE ###

num =int(input())
line = input()
line = line.rstrip().split(" ")
linei = []
for i in range(len(line)):
    linei.append(int(line[i]))
#print(max(linei))

for j in range(max(linei)):
    if linei.count(int(max(linei)/2)+j)>=1:
        if int(max(linei)/2)+j==max(linei):
            print(str(max(linei))+" 0")
            break
        else:
            print(str(max(linei))+" "+str(int(max(linei)/2)+j))
            break
    elif linei.count(int(max(linei)/2)-j)>=1:
        print(str(max(linei))+" "+str(int(max(linei)/2)-j))
        break
    else:
        j+=1

### FIXED CODE ###

n=int(input())
a=list(map(int,input().split()))

MAX=max(a)
Harf=MAX/2

cnt=10**20
ans=0
for i in range(n):
    if MAX==a[i]:
        continue
    elif abs(Harf-a[i])<cnt:
        ans=a[i]
        cnt=abs(Harf-a[i])
print(MAX,ans)
### BUGGY CODE ###

s = list(str(input()))

counter = 0
prev = None
while len(s) > 0:
    x = s.pop(0)
    if prev == x:
        if len(s) == 0:
            break

        x += s.pop(0)

    counter += 1
    prev = x

print(int(counter))

### FIXED CODE ###

s = str(input())
l = len(s)

counter = 0
prev = None
pivot = 0

while pivot < l:
    n = 1
    if prev == s[pivot]:
        if pivot + 1 < l:
            if pivot + 2 < l:
                prev = s[pivot + 2]
                counter += 2
                pivot += 3
            else:
                counter += 1
                break
        else:
            break
    else:
        counter += 1
        prev = s[pivot]
        pivot += n

print(int(counter))
### BUGGY CODE ###

#!/usr/bin/env python3

MOD = 1000000007
fact = []

def main():
    init_fact(200000)
    n = int(input())
    a = list(map(int, input().split()))
    sa = sorted(a)
    for i in range(n):
        if sa[i] == sa[i + 1]:
            double = sa[i]
            break
    idouble = []
    for i in range(n + 1):
        if a[i] == double:
            idouble.append(i)
    l = idouble[0]
    r = n - idouble[1]
    for k in range(1, n + 2):
        res = combi(n + 1, k) - combi(l + r, k - 1)
        res %= MOD
        print(res)

def combi(n, k):
    if k > n:
        return 0
    elif k == n:
        return 1
    numera = fact[n]
    denomi = (fact[n - k] * fact[k]) % MOD
    return (numera * inv(denomi)) % MOD

def init_fact(maxn):
    assert len(fact) == 0
    fact.append(1)
    for i in range(1, maxn + 1):
        fact.append((fact[i - 1] * i) % MOD)

def inv(n):
    return pow(n, MOD - 2)

def pow(n, p):
    if p == 0:
        return 1
    elif p % 2 == 0:
        x = pow(n, p // 2)
        return (x * x) % MOD
    else:
        x = pow(n, p - 1)
        return (x * n) % MOD

if __name__ == "__main__":
    main()


### FIXED CODE ###

#!/usr/bin/env python3

MOD = 1000000007
fact = []

def main():
    init_fact(200000)
    n = int(input())
    a = list(map(int, input().split()))
    sa = sorted(a)
    for i in range(n):
        if sa[i] == sa[i + 1]:
            double = sa[i]
            break
    idouble = []
    for i in range(n + 1):
        if a[i] == double:
            idouble.append(i)
    l = idouble[0]
    r = n - idouble[1]
    for k in range(1, n + 2):
        res = combi(n + 1, k) - combi(l + r, k - 1)
        res %= MOD
        print(res)

def combi(n, k):
    if k > n:
        return 0
    elif k == n:
        return 1
    numera = fact[n]
    denomi = (fact[n - k] * fact[k]) % MOD
    return (numera * inv(denomi)) % MOD

def init_fact(maxn):
    assert len(fact) == 0
    fact.append(1)
    for i in range(1, maxn + 1):
        fact.append((fact[i - 1] * i) % MOD)

def inv(n):
    return pow(n, MOD - 2)

def pow(n, p):
    if p == 0:
        return 1
    elif p % 2 == 0:
        x = pow(n, p // 2)
        return (x * x) % MOD
    else:
        x = pow(n, p - 1)
        return (x * n) % MOD

if __name__ == "__main__":
    main()
### BUGGY CODE ###

def sol():
    h,n=map(int,input().split())
    l=[]
    ans=0
    for i in range(n):
        a,b=map(int,input().split())
        l.append((a,b))
    d=[0]*20005
    for i in range(h):
        for j in l:
            a,b=j[0],j[1]
            x=d[i]+b
            if i==0 or (d[i]!=0 and d[i+a]==0):
                if d[i+a]==0:
                    d[i+a]=x
                else:
                    d[i+a]=min(d[i+a],x)
            elif d[i]!=0 and d[i+a]!=0:
                d[i+a]=min(d[i+a],x)

    for i in range(h,20005):
        if ans==0:
            ans=d[i]
        elif d[i]!=0:
            ans=min(ans,d[i])
    print(ans)

if __name__=="__main__":
    sol()


### FIXED CODE ###

def sol():
    h,n=map(int,input().split())
    l=[]
    ans=0
    for i in range(n):
        a,b=map(int,input().split())
        l.append((a,b))
    d=[0]*20005
    for i in range(h):
        for j in l:
            a,b=j[0],j[1]
            x=d[i]+b
            if i==0 or (d[i]!=0 and d[i+a]==0):
                if d[i+a]==0:
                    d[i+a]=x
                else:
                    d[i+a]=min(d[i+a],x)
            elif d[i]!=0 and d[i+a]!=0:
                d[i+a]=min(d[i+a],x)

    for i in range(h,20005):
        if ans==0:
            ans=d[i]
        elif d[i]!=0:
            ans=min(ans,d[i])
    print(ans)

if __name__=="__main__":
    sol()
### BUGGY CODE ###

n=int(input())
a=[int(input()) for _ in range(n)]
for i in range(n):
  b=a[i]
  a[i]=0
  print(max(a))
  a[i]=b
  

### FIXED CODE ###

n=int(input())
a=[int(input()) for _ in range(n)]

amax,b=max(a),a.index(max(a))
a.remove(amax)
bmax=max(a)
for i in range(n):
  if i==b:
    print(bmax)
  else:
    print(amax)