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

N = int(input())
A = list(map(int, input().split()))

results = A[0]
for i in range(N):
    if i==0:
        continue
    results *= A[i]

if results>10**18:
    print(-1)
else:
    print(results)

### FIXED CODE ###

N = int(input())
A = list(map(int, input().split()))
A.sort(reverse=True)

results = A[0]
can = True
zero = False
for i in range(N):
    if A[i]==0:
        zero = True
        break

if zero:
    print(0)
else:
    for i in range(N):
        if i==0:
            continue
        results *= A[i]
        if results>10**18:
            can = False
            break

    if can:
        print(results)
    else:
        print(-1)
### BUGGY CODE ###

from math import log
mod = int(1e9) + 7
n, k = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
a.sort()
m, ok = 0, 0

def sign(v):
    if v == 0:
        return 0
    return 1 if v > 0 else -1

for i in range(k + 1):
    c = 1
    sm = 0
    sgn = 1
    for j in range(i):
        c = c * a[j] % mod
        sgn *= sign(a[j])
        if a[j] != 0:
            sm += log(abs(a[j]))
    for j in range(k - i):
        c = c * a[n - j - 1] % mod
        sgn *= sign(a[n - j - 1])
        if a[n - j - 1] != 0:
            sm += log(abs(a[n - j - 1]))
    if not ok:
        m = (sgn * sm, c)
        ok = 1
    else:
        m = max(m, (sgn * sm, c))
    
print(m[1])

### FIXED CODE ###

from math import log
mod = int(1e9) + 7
n, k = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
a.sort()

def sign(v):
    if v == 0:
        return 0
    return 1 if v > 0 else -1

pref = [(0, 1)] * (n + 1)
suf = [(0, 1)] * (n + 1)

c = 1
sm = 0
sgn = 1
for j in range(n):
    c = c * a[j] % mod
    sgn *= sign(a[j])
    if a[j] != 0:
        sm += log(abs(a[j]))
    pref[j + 1] = (sgn * sm, c, sgn)

c = 1
sm = 0
sgn = 1
for j in range(n):
    c = c * a[n - j - 1] % mod
    sgn *= sign(a[n - j - 1])
    if a[n - j - 1] != 0:
        sm += log(abs(a[n - j - 1]))
    suf[j + 1] = (sgn * sm, c, sgn)

m = max(pref[k], suf[k])
for i in range(1, k):
    sgn = pref[i][2] * suf[k - i][2]
    pm = pref[i][1] * suf[k - i][1] % mod
    sm = abs(pref[i][0]) + abs(suf[k - i][0])
    m = max(m, (sgn * sm, pm, sgn))

    
print(m[1])
### BUGGY CODE ###

N = int(input())
A = map(int, input().split())

answer = 1

for i in A:
    answer = answer * i
    if i == 0:
        print(0)
        break
else:
    if answer > 10**18:
        print(-1)
    else:
        print(answer)

### FIXED CODE ###

N = int(input())
A = list(map(int, input().split()))
A.sort()
answer = 1

for i in A:
    answer = answer * i
    if i == 0:
        print(0)
        break
    if answer > 10 **18:
        print(-1)
        break
else:
        print(answer)
### BUGGY CODE ###

n,p = map(int,input().split())
if n == 1:
  print(p)
  exit()
a = 1
for i in range(1,1000001):
  if p< i**n:
    break
  if p%(i ** n) == 0:
    a = i
print(a)

### FIXED CODE ###

n,p = map(int,input().split())
if n == 1:
  print(p)
  exit()
a = 1
for k in range(2,1000001):
  c = 0
  while p%k == 0:
    p = p//k
    c += 1
  a *= k**(c//n)
  if p == 1:
    break
print(a)
### BUGGY CODE ###

N=int(input())
listA=list(map(int, input().split()))
Q=int(input())

listB=[] #appendのために宣言が必要
while True:
    try:
        listB.append(list(map(int,input().split())))

    except:
        break;
        
sum=sum(listA)
numlist=[0]*(10**5+1)
for i in range(10**5+1):
  numlist[i]=listA.count(i)
  
for i in range(Q):
  B=listB[i][0]
  C=listB[i][1]
  sum=sum+(C-B)*numlist[B]
  # print(C)
  numlist[C]+=numlist[B]
  numlist[B]=0
  # print(numlist)
  print(sum)


### FIXED CODE ###

N=int(input())
listA=list(map(int, input().split()))
Q=int(input())

listB=[] #appendのために宣言が必要
while True:
    try:
        listB.append(list(map(int,input().split())))

    except:
        break;
        
sum=sum(listA)
numlist=[0]*(10**5+1)
for i in listA:
  numlist[i]+=1
  
for i in range(Q):
  B=listB[i][0]
  C=listB[i][1]
  if numlist[B]!=0:
    sum=sum+(C-B)*numlist[B]
    # print(C)
    numlist[C]+=numlist[B]
    numlist[B]=0
    # print(numlist)
  print(sum)
### BUGGY CODE ###

import numpy as np
n = int(input())
a = list(map(int,input().split()))
a = np.array(a)
q = int(input())
import collections
co = collections.Counter(a)
# print(co)
for i in range(q):
    b,c = map(int,input().split())
    if b in co.keys():
        co[c]+=co[b]
        co.pop(b)
    s=0
    for k,v in co.items():
        s+=k*v
    print(s)

### FIXED CODE ###


# import random

import numpy as np
n = int(input())
a = list(map(int,input().split()))
a = np.array(a)
q = int(input())
# a = [random.randint(0, 10**4) for i in range(10**4)]
# 処理前の時刻
# t1 = time.time() 
import collections
co = collections.Counter(a)
s = 0
for k,v in co.items():
    s+=k*v
for i in range(q):
    b,c = map(int,input().split())
    if b in co.keys():
        s += (c-b)*co[b]
        co[c]+=co[b]
        co.pop(b)
    print(s)
### BUGGY CODE ###

N = int(input())
A_N=list(map(int, input().split()))

match = [2**i - 1for i in range(21)]
count = N
cands = []

def is_arriviable(val, past_num, added_num):
    return added_num==0 or val == past_num+added_num

for i in range(N):
#     print(i, cands, A_N[i])
    next_cands = []
    for c in cands:
        n = c ^ A_N[i]
        if is_arriviable(n, c, A_N[i]):
#             print('add {}'.format(n))
            count += 1
            next_cands.append(n)
    cands = next_cands
    cands.append(A_N[i])
print(count)

### FIXED CODE ###

N = int(input())
an = list(map(int, input().split()))

ans = 0
right = 0
arith_sum = 0
for left in range(N):
    while right < N and arith_sum ^ an[right] == arith_sum + an[right]:
        arith_sum += an[right]
        right += 1
    ans += right - left
    if left == right:
        right += 1
    else:
        arith_sum -= an[left]

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

from collections import deque
H,W,K,*L = open(0).read().split()
L = [list(a) for a in L]
H,W,K = map(int, (H,W,K))
q = deque([])
step = [(-1,0),(1,0),(0,-1),(0,1)]
for i,a in enumerate(L):
  if 'S' in a:
    q = deque([(0,i,a.index('S'))])
    break
ans = 10**10
while q:
  c,a,b = q.popleft()
  x = min(a,H-a-1,b,W-b-1)
  cnt = 1+(x+K-1)//K
  ans = min(cnt,ans)
  if c+1>K:
    continue
  for dx,dy in step:
    n = a+dx
    m = b+dy
    if not(-1<n<H and -1<m<W):
      continue
    if L[n][m]=='.':
      L[n][m]='#'
      q.append((c+1,n,m))
print(ans)

### FIXED CODE ###

from collections import deque
H,W,K,*L = open(0).read().split()
L = [list(a) for a in L]
H,W,K = map(int, (H,W,K))
q = deque([])
step = [(-1,0),(1,0),(0,-1),(0,1)]
for i,a in enumerate(L):
  if 'S' in a:
    q = deque([(0,i,a.index('S'))])
    break
ans = 10**10
while q:
  c,a,b = q.popleft()
  x = min(a,H-a-1,b,W-b-1)
  cnt = 1+(x+K-1)//K
  ans = min(cnt,ans)
  if c+1>K:
    continue
  for dx,dy in step:
    n = a+dx
    m = b+dy
    if not(-1<n<H and -1<m<W):
      continue
    if L[n][m]=='.':
      L[n][m]='#'
      q.append((c+1,n,m))
print(ans)
### BUGGY CODE ###

from bisect import bisect_left
H, W = map(int, input().split())
s = [input() for i in range(H)]

def length(index, block_idx, full_length):
    if len(block_idx) == 0:
        return full_length
    idx = bisect_left(block_idx, index)
    if idx == len(block_idx):
        return full_length - index
    return block_idx[idx] - index

rows = []

for i in range(H):
    row = []
    block_idx = []
    for k in range(len(s[i])):
        if s[i][k] == "#":
            block_idx.append(k)

    for j in range(W):
        if j == 0:
            if s[i][0] == "#":
                row.append(0)
            else:
                l = length(0, block_idx, W)
                row.append(l)
        else:
            if s[i][j] == "#":
                row.append(0)
            else:
                if s[i][j-1] != "#":
                    row.append(row[len(row)-1])
                else:
                    l = length(j, block_idx, W)
                    row.append(l)
    rows.append(row)

columns = []

for i in range(W):
    column = []

    _s = ""
    block_idx = []
    for k in range(H):
        _s += s[k][i]
        if s[k][i] == "#":
            block_idx.append(k)

    for j in range(H):
        if j == 0:
            if _s[0] == "#":
                column.append(0)
            else:
                l = length(0, block_idx, H)
                column.append(l)
        else:
            if _s[j] == "#":
                column.append(0)
            else:
                if _s[j - 1] != "#":
                    column.append(column[len(column) - 1])
                else:
                    l = length(j, block_idx, H)
                    column.append(l)
    columns.append(column)

res = []
max_score = 0
for i in range(H):
    for j in range(W):
        r = rows[i][j]
        c = columns[j][i]
        score = r + c - 1
        if max_score < score:
            max_score = score
print(max_score)

### FIXED CODE ###


H, W = map(int, input().split())
s = [input() for i in range(H)]

l = [[0 for i in range(W)] for j in range(H)]
r = [[0 for i in range(W)] for j in range(H)]
d = [[0 for i in range(W)] for j in range(H)]
u = [[0 for i in range(W)] for j in range(H)]

# Up-Light
for i in range(H):
    for j in range(W):
        if s[i][j] == "#":
            l[i][j] = 0
            u[i][j] = 0
            continue

        if j == 0:
            l[i][j] = 1
        else:
            l[i][j] = l[i][j-1] + 1

        if i == 0:
            u[i][j] = 1
        else:
            u[i][j] = u[i-1][j] + 1

# Right-Down
for i in range(H)[::-1]:
    for j in range(W)[::-1]:
        if s[i][j] == "#":
            r[i][j] = 0
            d[i][j] = 0
            continue

        if j == W-1:
            r[i][j] = 1
        else:
            r[i][j] = r[i][j+1] + 1

        if i == H-1:
            d[i][j] = 1
        else:
            d[i][j] = d[i+1][j] + 1

max_score = 0
for i in range(H):
    for j in range(W):
        score = l[i][j] + r[i][j] + u[i][j] + d[i][j] - 3
        if score > max_score:
            max_score = score
print(max_score)
### BUGGY CODE ###

#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

def dfs(v,p):
    for u in edges[v]:
        if u == p:
            continue
        lst[u] += lst[v]
        dfs(u,v)

n,q = LI()
edges = [[] for _ in range(n)]

for _ in range(n-1):
    a,b = LI()
    edges[a-1].append(b-1)
    edges[b-1].append(a-1)

lst = [0]*n
for i in range(q):
    p,x = LI()
    lst[p-1] += x

dfs(0,-1)
print(*lst)

### FIXED CODE ###

#!/usr/bin/env python3
#ABC138 D

import sys
import math
import bisect
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n,q = LI()
g = [[] for _ in range(n)]
for _ in range(n-1):
    a,b = LI()
    g[a-1].append(b-1)

ans = [0]*n
for _ in range(q):
    p,x = LI()
    ans[p-1] += x

que = deque()
que.append(0)
check = [True]*n
while que:
    v = que.popleft()
    for i in g[v]:
        if check[i]:
            check[i] = False
            que.append(i)
            ans[i] += ans[v]
print(*ans)
### BUGGY CODE ###



def solve():
    n = int(raw_input())
    R = []

    for i in xrange(n):
        R.append(int(raw_input()))

    #for i in xrange(n):
    #    print R[i]

    max_profit = -1000000000
    for i in xrange(n):
        for j in xrange(i + 1, n):
            if R[j] - R[i] > max_profit:
                max_profit = R[j] - R[i]


    print max_profit


if __name__ == "__main__":
    solve()

### FIXED CODE ###

import sys

def solve():
    n = int(raw_input())
    R = []

    for i in xrange(n):
        R.append(int(raw_input()))

    #for i in xrange(n):
    #    print R[i]

    max_profit = -sys.maxint
    min_R = R[0]

    for i in xrange(1, n):
        if R[i] - min_R > max_profit:
            max_profit = R[i] - min_R
        if min_R > R[i]:
            min_R = R[i]

    print max_profit


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

N,K = map(int,input().split())
p_list = list(map(int,input().split()))

kitaichi_p_list = [(p + 1)/2 for p in p_list]

max_kitaichi = 0
for i in range(N):
    kitaichi = sum(kitaichi_p_list[i:i+K])
    if(max_kitaichi < kitaichi):
        max_kitaichi = kitaichi

print(max_kitaichi)

### FIXED CODE ###

from sys import stdin

def main():

    input = stdin.readline

    N,K = map(int,input().split())
    p_list = [(p+1)/2 for p in list(map(int,input().split()))]

    # Sを計算
    S = [0]
    for p in p_list:
        S.append(S[-1] + p)
        # print(S)

    # i:i+kを計算

    maxs = 0
    for i in range(N-K+1):
        p_num = S[i+K] - S[i]
        if(maxs < p_num):
            maxs = p_num
    
    print(maxs)

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

N, K = map(int, input().split())
A_list = list(map(int,input().split()))
A_index = set(A_list)
A_count = sorted([ A_list.count(A) for A in A_index])
A_len = len(A_count)
total = 0
for i in range(A_len - K):
    total += A_count[i]
print(total)


### FIXED CODE ###

N, K = map(int, input().split())
A_list = list(map(int,input().split()))
A_dict = dict()
for elem in A_list:
    if not elem in A_dict:
        A_dict[elem] = 1
    else:
        A_dict[elem] += 1
total = 0
A_dict = sorted(A_dict.items(), key=lambda x: x[1])
for i in range(len(A_dict) - K):
    total += A_dict[i][1]
print(total)
### BUGGY CODE ###

import sys

def solve():
    input = lambda: sys.stdin.readline().rstrip()
    sys.setrecursionlimit(10 ** 7)
    mod = 10 ** 9 + 7
    
    def comb(n, r):
        if r > n: return 0
        return fac[n] * inv[r] * inv[n - r] % mod

    def dfs(v, Pa=-1):
        for u in to[v]:
            if u == Pa: continue
            dfs(u, v)
            size[v] += size[u]
            dp[v] *= dp[u] % mod
            dp[v] *= comb(size[v], size[u]) % mod
        size[v] += 1

    def bfs(v, Pa=-1, P_val=1, P_sz=0):
        ans[v] = P_val * dp[v] * comb(n - 1, P_sz) % mod
        for u in to[v]:
            if u == Pa: continue
            val = ans[v] * INV(dp[u] * comb(n - 1, size[u])) % mod
            bfs(u, v, val, n - size[u])

    n = int(input())
    to = [[] for _ in range(n)]
    for _ in range(n - 1):
        a, b = map(lambda x: int(x) - 1, input().split())
        to[a].append(b)
        to[b].append(a)

    fac = [1] * (n + 2)
    inv = [1] * (n + 2)

    for i in range(2, n + 1):
        fac[i] = fac[i - 1] * i % mod
    INV = lambda x: pow(x, mod - 2, mod)
    inv[n] = INV(fac[n])
    for i in range(n - 1, 1, -1):
        inv[i] = inv[i + 1] * (i + 1) % mod

    dp = [1] * n
    size = [0] * n
    ans = [0] * n

    dfs(0)
    bfs(0)
    print(*ans, sep='\n')

if __name__ == '__main__':
    solve()

### FIXED CODE ###

import sys

def solve():
    input = lambda: sys.stdin.readline().rstrip()
    sys.setrecursionlimit(10 ** 7)
    mod = 10 ** 9 + 7

    def comb(n, r):
        if r > n: return 0
        return fac[n] * inv[r] * inv[n - r] % mod

    def dfs(v, Pa=-1):
        for u in to[v]:
            if u == Pa: continue
            dfs(u, v)
            size[v] += size[u]
            dp[v] *= dp[u] % mod
            dp[v] *= inv[size[u]] % mod
        dp[v] *= fac[size[v]] % mod
        size[v] += 1

    def bfs(v, Pa=-1, P_val=1, P_sz=0):
        ans[v] = P_val * dp[v] * comb(n - 1, P_sz) % mod
        for u in to[v]:
            if u == Pa: continue
            val = ans[v] * INV(dp[u] * comb(n - 1, size[u])) % mod
            bfs(u, v, val, n - size[u])

    n = int(input())
    to = [[] for _ in range(n)]
    for _ in range(n - 1):
        a, b = map(lambda x: int(x) - 1, input().split())
        to[a].append(b)
        to[b].append(a)

    fac = [1] * (n + 2)
    inv = [1] * (n + 2)

    for i in range(2, n + 1):
        fac[i] = fac[i - 1] * i % mod
    INV = lambda x: pow(x, mod - 2, mod)
    inv[n] = INV(fac[n])
    for i in range(n - 1, 1, -1):
        inv[i] = inv[i + 1] * (i + 1) % mod

    dp = [1] * n
    size = [0] * n
    ans = [0] * n

    dfs(0)
    bfs(0)
    print(*ans, sep='\n')

if __name__ == '__main__':
    solve()
### BUGGY CODE ###

N = int(input())
E = [[int(l) for l in input().split()] for _ in range(N-1)]
M = int(input())
L = [[int(l) for l in input().split()] for _ in range(M)]

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.root = [-1]*(n+1)
        self.rnk = [0]*(n+1)
        
    def find_root(self, x):
        if self.root[x] < 0:
            return x
        else:
            self.root[x] = self.find_root(self.root[x])
            return self.root[x]
        
    def unite(self, x, y):
        x = self.find_root(x)
        y = self.find_root(y)
        if x == y:
            return
        elif self.rnk[x] > self.rnk[y]:
            self.root[x] += self.root[y]
            self.root[y] = x
        else:
            self.root[y] += self.root[x]
            self.root[x] = y
            if self.rnk[x] == self.rnk[y]:
                self.rnk[y] += 1
                
    def isSameGroup(self, x, y):
        return self.find_root(x) == self.find_root(y)

C = [set([]) for _ in range(M)]
for i in range(N-1):
    uf = UnionFind(N)
    for e in E:
        if e == E[i]:
            continue
        uf.unite(e[0], e[1])
    for l in range(M):
        if uf.isSameGroup(L[l][0], L[l][1]):
            continue
        C[l].add(i)

ans = 0
for i in range(2**M):
    cnt = 0
    white = set([])
    for j in range(M):
        if i & 1 << j:
            cnt += 1
            white = white | C[j]
    if cnt%2:
        ans -= 2**(N-1-len(white))
    else:
        ans += 2**(N-1-len(white))
print(ans)

### FIXED CODE ###

N = int(input())
E = [[int(l) for l in input().split()] for _ in range(N-1)]
M = int(input())
L = [[int(l) for l in input().split()] for _ in range(M)]

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.root = [-1]*(n+1)
        self.rnk = [0]*(n+1)
        
    def find_root(self, x):
        if self.root[x] < 0:
            return x
        else:
            self.root[x] = self.find_root(self.root[x])
            return self.root[x]
        
    def unite(self, x, y):
        x = self.find_root(x)
        y = self.find_root(y)
        if x == y:
            return
        elif self.rnk[x] > self.rnk[y]:
            self.root[x] += self.root[y]
            self.root[y] = x
        else:
            self.root[y] += self.root[x]
            self.root[x] = y
            if self.rnk[x] == self.rnk[y]:
                self.rnk[y] += 1
                
    def isSameGroup(self, x, y):
        return self.find_root(x) == self.find_root(y)

C = [0]*M
for i in range(N-1):
    uf = UnionFind(N)
    for e in E:
        if e == E[i]:
            continue
        uf.unite(e[0], e[1])
    for l in range(M):
        if uf.isSameGroup(L[l][0], L[l][1]):
            continue
        C[l] |= 1 << i

import itertools

ans = 0
L = [int(i) for i in range(M)]
for m in range(M+1):
    for P in itertools.combinations(L, m):
        white = 0
        for j in P:
            white |= C[j]
        if m%2:
            ans -= 1 << N-1-bin(white).count("1")
        else:
            ans += 1 << N-1-bin(white).count("1")
print(ans)
### BUGGY CODE ###

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

mod = 10 ** 9 + 7
total = 0
y = sum(list1)

for i in range(0,n-1):
    x = y- sum(list1[:i+1])
    total += list1[i] * x % mod

total = total % mod
print(total)


### FIXED CODE ###

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

mod = 10 ** 9 + 7
total = 0
y = sum(list1)

for i in range(0,n-1):
    y = y- list1[i]
    total += list1[i] * y % mod

total = total % mod
print(total)
### BUGGY CODE ###

import heapq

N,K = map(int,input().split(' '))
pn = list(map(int,input().split(' ')))
#Sn = [0] * N
#Sn[0] = pn[0]
#for i in range(1,len(pn)):
#    Sn[i] = Sn[i-1] + pn[i]
kakuritsu = [0] * N 
num_list = [0] * 1001
num_list[0] = 0
for i in range(1,1001):
    num_list[i] = num_list[i-1] + i

for i in range(N):
    kakuritsu[i] =  num_list[pn[i]] / pn[i]

max_sn = [0] * N

for i in range(N-K+1):
    max_sn[i] = sum(kakuritsu[i:i+K]) * (-1)

heapq.heapify(max_sn)
print(heapq.heappop(max_sn) * (-1))

### FIXED CODE ###

import heapq

N,K = map(int,input().split(' '))
pn = list(map(int,input().split(' ')))
#Sn = [0] * N
#Sn[0] = pn[0]
#for i in range(1,len(pn)):
#    Sn[i] = Sn[i-1] + pn[i]
kakuritsu = [0] * N 
num_list = [0] * 1001
num_list[0] = 0
for i in range(1,1001):
    num_list[i] = num_list[i-1] + i

for i in range(N):
    if i != 0:
        kakuritsu[i] = kakuritsu[i-1] + ( num_list[pn[i]] / pn[i] )
    else:
        kakuritsu[i] = num_list[pn[i]] / pn[i]

max_sn = [0] * N

for i in range(N-K+1):
    if i != 0:
        max_sn[i] = ( kakuritsu[i-1+K] - kakuritsu[i-1]   ) * (-1)
    else:
        max_sn[i] = kakuritsu[i-1+K] * (-1)

heapq.heapify(max_sn)
print(heapq.heappop(max_sn) * (-1))
### BUGGY CODE ###

N, K = map(int, input().split())
ans = 0
judge = True

while judge == True:
    if K == 1:
        N = 0
        break

    ans = N - K
    N = abs(ans)

    ans = N - K
    mem = abs(ans)

    if N > mem:
        pass
    else:
        judge = False


print(N)

### FIXED CODE ###

N, K = map(int, input().split())
a = abs(N%K)
print(min(a, abs(a-K)))
### BUGGY CODE ###

N, M = map(int, input().split())
Broken = []
for _ in range(M):
    broken = int(input())
    Broken.append(broken)

DP = [0] * (N+1)
DP[0] = 1

for i in range(1, N+1):
    if i in Broken:
        continue
    DP[i] = DP[i-1] + DP[i-2]
    DP[i] %= 10**9 + 7
print(DP[N])



### FIXED CODE ###

N, M = map(int, input().split())
Broken = set([])
for _ in range(M):
    broken = int(input())
    Broken.add(broken)

DP = [0] * (N+1)
DP[0] = 1

for i in range(1, N+1):
    if i in Broken:
        continue
    DP[i] = DP[i-1] + DP[i-2]
    DP[i] %= 10**9 + 7
print(DP[N])
### BUGGY CODE ###

from scipy.misc import comb
import collections

N = int(input())
BALLS = list(map(int, input().split()))

COUNTS = collections.Counter(BALLS)


MEMO = {}
def fact(n):
    if MEMO.get(n):
        return MEMO[n]
    r = 2
    if n - r < 0:
        return 0
    MEMO[n] = int(comb(n, r, exact=True))
    return MEMO[n]

MEMO2 = {}
def solve(n):
    if MEMO2.get(n):
        return MEMO2[n]

    MEMO2[n] = sum(fact(v if k != n else v - 1) for (k, v) in COUNTS.items())
    return MEMO2[n]

for i in range(N):
    print(solve(BALLS[i]))

### FIXED CODE ###

from math import factorial
import collections

N = int(input())
BALLS = list(map(int, input().split()))

MEMO = {}
def fact(n):
    if MEMO.get(n):
        return MEMO[n]
    r = 2
    if n - r < 0:
        MEMO[n] = 0
        return 0
    MEMO[n] = factorial(n) // factorial(r) // factorial(n - r)
    return MEMO[n]

COUNTS = collections.Counter(BALLS)
TOTAL = sum(fact(n) for n in COUNTS.values())

MEMO2 = {}
def solve(n):
    if MEMO2.get(n):
        return MEMO2[n]

    MEMO2[n] = TOTAL - fact(COUNTS[n]) + fact(COUNTS[n] - 1)
    return MEMO2[n]

for i in range(N):
    print(solve(BALLS[i]))
### BUGGY CODE ###

n=int(input())
a=[int(input())for _ in range(n)]
b=sorted(a)
for i in range(n):
    if a[i]==max(a):
        print(b[-2])
    else:
        print(max(a))

### FIXED CODE ###

n=int(input())
a=[int(input())for _ in range(n)]
b=sorted(a)
max_a=max(a)
second=b[-2]
for i in range(n):
    if a[i] != max_a:
        print(max_a)
    else:
        print(second)