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

import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 998244353

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
     
def main():
    N, S = LI()
    a = LI()
    dp = [[0 for _ in range(S+1)] for _ in range(N+1)]
    for i in range(1, N+1):
        dp[i][0] = dp[i-1][0] * 2 + 1
        dp[i][0] %= mod
    for i in range(N):
        for j in range(1, S+1):
            if j - a[i] >= 0:
                dp[i+1][j] = (dp[i][j-a[i]] % mod) + (dp[i][j] * 2 % mod)
            else:
                dp[i+1][j] = dp[i][j] * 2 % mod
            if j == a[i]:
                dp[i+1][j] += 1
            dp[i+1][j] %= mod
    print(dp[N][S])

main()



### FIXED CODE ###

import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 998244353

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
     
def main():
    N, S = LI()
    a = LI()
    dp = [[0 for _ in range(S+1)] for _ in range(N+1)]
    for i in range(1, N+1):
        dp[i][0] = dp[i-1][0] * 2 + 1
        dp[i][0] %= mod
    for i in range(N):
        for j in range(1, S+1):
            if j - a[i] >= 0:
                dp[i+1][j] = (dp[i][j-a[i]] % mod) + (dp[i][j] * 2 % mod)
            else:
                dp[i+1][j] = dp[i][j] * 2 % mod
            if j == a[i]:
                dp[i+1][j] += 1
            dp[i+1][j] %= mod
    print(dp[N][S])

main()
### BUGGY CODE ###

N = int(input())
def q(i):
    print(i)
    r = input()
    if r[0]=='V': exit()
    return r[0]

X = q(0)
def is_ok(m):
    if m==N: return False
    return q(m)==X
ok = 0
ng = N
while ng-ok > 1:
    m = (ok+ng)//2
    if is_ok(m):
        ok = m
    else:
        ng = m

### FIXED CODE ###

N = int(input())

q = 0
res = []
for i in range(20):
    print(q)
    s = input()
    if s[0] == 'V':
        exit()
    res.append((q,s[0]))
    res.sort()
    if len(res) == 1:
        q = N//2
        continue
    for (i1,g1),(i2,g2) in zip(res,res[1:]):
        if i2-i1 == 1: continue
        if (i2-i1)%2 == int(g1==g2):
            q = (i2+i1)//2
            break
    else:
        q = (res[-1][0] + N + 1)//2
### BUGGY CODE ###

def getlist():
	return list(map(int, input().split()))

X = []
N = int(input())
for i in range(N):
	A = getlist()
	A.reverse()
	X.append([0] + A)

#日数
day = 0
while True:
	j = "No"
	check = [0] * N
	for i in range(N):
		x = X[i][-1] - 1
		if x != -1:
			if check[i] == 0 and check[x] == 0 and X[x][-1] == i + 1:
				check[i] = 1
				check[x] = 1
				X[x].pop(-1)
				X[i].pop(-1)
				j = "Yes"
	day += 1
	if j == "No":
		break

#判定
cc = "Yes"
for i in range(N):
	if X[i] != [0]:
		cc = "No"
		break

if cc == "No":
	print(-1)
else:
	print(day - 1)

### FIXED CODE ###

#設定
import sys
input = sys.stdin.buffer.readline

#ライブラリインポート
from collections import defaultdict, deque

#入力受け取り
def getlist():
	return list(map(int, input().split()))

#処理内容
def main():
	#入力
	N = int(input())
	outE = defaultdict(list)
	inE = defaultdict(int)
	for i in range(N):
		A = getlist()
		for j in range(N - 2):
			a, b = sorted([A[j] - 1, i])
			c, d = sorted([A[j + 1] - 1, i])
			outE[a * N + b].append(c * N + d)
			inE[c * N + d] += 1

	#キュー初期化
	Q = []
	for i in range(N):
		for j in range(i + 1, N):
			if inE[i * N + j] == 0:
				Q.append(i * N + j)
	#print(Q)
	#計算
	judge = "Yes"
	cnt = 0
	ans = 1
	while True:
		q = []
		for i in Q:
			for j in outE[i]:
				inE[j] -= 1
				cnt += 1
				if inE[j] == 0:
					q.append(j)

		if q == []:
			break
		else:
			Q = q
		ans += 1
	# print(ans)
	# print(cnt)

	if cnt != N * (N - 2):
		print(-1)
	else:
		print(ans)

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

N = int(input())
P = [int(p_) for p_ in input().split()]

ans = [1]
for i in range(1, len(P)):
    #print(i+1, P[0:i], min(P[0:i]), P[i])
    if P[i] <= min(P[0:i]):
        ans.append(i+1)
        
print(len(ans))

### FIXED CODE ###

N = int(input())
P = [int(p_) for p_ in input().split()]

ans = [1]
mini = P[0] 
for i in range(1, len(P)):
    if mini > P[i]:
        mini = P[i]
        ans.append(i+1)

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

import sys
sys.setrecursionlimit(10**6)
n,m=map(int,input().split())
graph=[[] for i in range(n)]
for i in range(m):
    l,r,d=map(int,input().split())
    graph[r-1].append((l-1,-d))
    graph[l-1].append((r-1,d))
INF=10**10
x_list=[INF]*n
def dfs(x):
    for i in graph[x]:
        if x_list[i[0]]==INF:
            x_list[i[0]]=x_list[x]+i[1]
            dfs(i[0])
        else:
            if x_list[i[0]]==x_list[x]+i[1]:
                pass
            else:
                print('No')
                sys.exit()
for i in range(n):
    if x_list[i]==INF:
        x_list[i]=0
        dfs(i)
print('Yes')


### FIXED CODE ###

import sys
n,m=map(int,input().split())
graph=[[] for i in range(n)]
for i in range(m):
    l,r,d=map(int,input().split())
    graph[r-1].append((l-1,-d))
    graph[l-1].append((r-1,d))
INF=10**9
x_list=[INF]*n
stack=[]
for i in range(n):
    if x_list[i]==INF:
        x_list[i]=0
        stack.append(i)
        while len(stack)>0:
            now=stack.pop()
            for j in graph[now]:
                if x_list[j[0]]==INF:
                    x_list[j[0]]=x_list[now]+j[1]
                    stack.append(j[0])
                else:
                    if x_list[j[0]]==x_list[now]+j[1]:
                        pass
                    else:
                        print('No')
                        sys.exit()
print('Yes')
### BUGGY CODE ###

N,Q=map(int,input().split())
S=input()
l=[0]*Q
r=[0]*Q
for i in range(Q):
  l[i],r[i]=map(int,input().split())
counter=[]
for i in range(len(S)-1):
  if S[i]=="A":
    counter.append((S[i+1]=="C"))
  else:counter.append(0)
for j in range(Q):
  print(sum(counter[l[j]-1:r[j]-1]))

### FIXED CODE ###

N,Q=map(int,input().split())
S=input()
l=[0]*Q
r=[0]*Q
for i in range(Q):
  l[i],r[i]=map(int,input().split())
counter=[0]*N
for i in range(N-1):
  if S[i]=="A":
    counter[i]=counter[i-1]+(S[i+1]=="C")
  else:counter[i]=counter[i-1]
for j in range(Q):
  print(counter[r[j]-2]-counter[l[j]-2])
### BUGGY CODE ###

from itertools import accumulate
from math import ceil

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


class BinaryIndexedTree:
    def __init__(self, n):
        self.size = n
        self.bit = [0] * (n + 1)

    def sum(self, i):
        s = 0
        while i > 0:
            s += self.bit[i]
            i -= (i & -i)
        return s

    def add(self, i, x):
        while i <= self.size:
            self.bit[i] += x
            i += (i & -i)

    def reset(self):
        self.bit = [0] * (self.size + 1)


BIT = BinaryIndexedTree(N + 1)
ng, ok = 10 ** 9 + 1, 0
while abs(ok - ng) > 1:
    X = (ok + ng) // 2

    B = [(1 if a >= X else -1) for a in A]
    B = [0] + list(accumulate(B))

    tmp = 0
    B_sorted = {b: i for i, b in enumerate(sorted(B), start=1)}
    BIT.reset()
    for j, b in enumerate(B):
        tmp += BIT.sum(B_sorted[b])
        BIT.add(B_sorted[b], 1)

    if tmp >= ceil((N * (N + 1) // 2) / 2):
        ok = X
    else:
        ng = X

print(ok)


### FIXED CODE ###

from itertools import accumulate
from math import ceil

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

if N == 1:
    print(A[0])
    exit()


class BinaryIndexedTree:
    def __init__(self, n):
        self.size = n
        self.bit = [0] * (n + 1)

    def sum(self, i):
        s = 0
        while i > 0:
            s += self.bit[i]
            i -= (i & -i)
        return s

    def add(self, i, x):
        while i <= self.size:
            self.bit[i] += x
            i += (i & -i)

    def reset(self):
        self.bit = [0] * (self.size + 1)


BIT = BinaryIndexedTree(N)  # Binaryの先頭の分
lo, hi = -1, 10 ** 9 + 1
while hi - lo > 1:
    # Xは中央値候補
    X = (hi + lo) // 2

    # X以上なら1、X未満なら-1に変換
    Binary = [(1 if a >= X else -1) for a in A]

    # 累積和をとる
    Binary = list(accumulate(Binary))

    # BITを初期化
    BIT.reset()

    # 転倒数っぽいものを数える
    inversion = 0
    Binary_sorted = {b: i for i, b in enumerate(sorted(Binary), start=1)}
    for j, b in enumerate(Binary):
        inversion += BIT.sum(Binary_sorted[b]) + (b >= 0)
        BIT.add(Binary_sorted[b], 1)

    if inversion >= ceil((N * (N + 1) / 2) / 2):
        lo = X
    else:
        hi = X

print(lo)
### BUGGY CODE ###

import sys

N = int(sys.stdin.readline())
A = list(map(int, sys.stdin.readline().split()))

ans = [0]*N
for i in range(1, N+1):
        ans[i-1] = A.index(i) + 1
print(" ".join(map(str, ans)))

### FIXED CODE ###

import sys

N = int(sys.stdin.readline())
A = list(map(int, sys.stdin.readline().split()))

ans = [None]*N
for i, order in enumerate(A, 1):
        ans[order-1] = i
print(" ".join(map(str, ans)))
### BUGGY CODE ###


def gcd(a, b):
    while a>0 and b >0:
        if a > b:
            a %= b
        else:
            b %= a
    return a + b

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

ans = 0
for i in range(N):
    a = A[1] if i == 0 else A[0]
    for j in range(N):
        if i == j:
            continue
        a = gcd(a, A[j])
    if a > ans:
        ans = a

print(ans)


### FIXED CODE ###

def gcd(a, b):
    while a>0 and b >0:
        if a > b:
            a %= b
        else:
            b %= a
    return a + b

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


forwards = [A[0]]
backwards = [A[-1]]
for i in range(1, N):
    forwards.append(gcd(forwards[-1], A[i]))
    backwards.append(gcd(backwards[-1], A[-(i+1)]))
backwards = list(reversed(backwards))

ans = 0
for i in range(1, N-1):
    a = gcd(forwards[i-1], backwards[i+1])
    if a > ans:
        ans = a

if N > 2:
    ans = max([ans, forwards[-2], backwards[1]])
elif N == 2:
    ans = max(A)
else:
    ans = A[0]

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

N, M = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
addable = []
for m in range(M):
    B, C = map(int, input().split())
    addable += [C] * B

addable.sort()
addable = addable[-len(A):]
NA = A + addable
NA.sort()
print(sum(NA[-len(A):]))


### FIXED CODE ###

N, M = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
p = [(A[i], 1) for i in range(N)]
for m in range(M):
    B, C = map(int, input().split())
    p.append((C, B))

p.sort()
p.reverse()

ans = 0
for v, n in p:
    use = min(N, n)
    ans += use * v
    N -= use
    if N == 0:
        break
print(ans)
### BUGGY CODE ###

N = int(input())
A = [int(x) for x in input().split()]
s = 0
for i in range(N-1):
    for j in range(i+1, N):
        s += (A[i] * A[j]) % (10**9+7)
print(s%(10**9+7))


### FIXED CODE ###

N = int(input())
A = [int(x) for x in input().split()]
S = [0] * (N+1)      #累積和用のリスト
s = 0
CONST = 10**9+7

#前準備として累積和を計算
for i in range(N):
    S[i+1] = S[i] + A[i]

#積の総和を計算
for i in range(N-1):
    s += A[i] * ((S[N] - S[i+1]) % CONST)
    s %= CONST

print(s)
### BUGGY CODE ###

N,W=map(int, input().split())
nm=[0]*W
wm=[0]*W
tm=[0]*W

for i in range(N):
  s = input()
  x = 0
  for j in range(W):
    if s[j]=='.':
        nm[j] += 1
    else:
        for k in range (x, j):
           wm[k] = max(wm[k], j-x)
        tm[j] = max(tm[j], wm[j]+nm[j]-1)
        x =j+1
        wm[j] = nm[j] = 0
  for k in range (x, W):
     wm[k] = max(wm[k],W-x)
for j in range (W):
   tm[j] = max(tm[j], wm[j]+nm[j]-1)
print(max(tm))

### FIXED CODE ###

import numpy as np

h,w=map(int,input().split())
s=np.array([[(1 if x=='.' else 0) for x in list(input())] for y in range(h)])

r=np.zeros((h,w),dtype=int)
l=np.zeros((h,w),dtype=int)
d=np.zeros((h,w),dtype=int)
u=np.zeros((h,w),dtype=int)

l[:,0] = s[:,0]
r[:,w-1] = s[:,w-1]
for i in range(1,w):
  l[:,i] = (l[:,i-1]+1) * s[:,i]
  r[:,w-i-1] = (r[:,w-i]+1) * s[:,w-i-1]

u[0]=s[0]
d[h-1]=s[h-1]
for i in range(1,h):
  u[i] = (u[i-1]+1) * s[i]
  d[h-i-1] = (d[h-i]+1) * s[h-i-1]

print(((l+r+u+d).max()-3))
### BUGGY CODE ###

n = int(input()) #number of input

a = list(map(int,input().strip().split()))[:n] #ask input to multiple in one line

result = 1 
for x in a:
    result = result * x #update result(multiple of all)


if result<=10**18:
    print(result)

else:
    print(-1)

### FIXED CODE ###

# we collect the input A1 upto An.
# limit cannot exceed 10**18
# if N = 0 then ans = 0
# in N is in range then compute ans * A[n]
# else if  ans is greater than limit then display 1
# finally if length equal 1 then display -1
N = int(input())
ans = 1
limit = 10 ** 18
length = 0

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

A0 = set(A)
if 0 in A0:
    ans = 0
else:
    pass

for n in range(N):
    ans = ans * A[n]
    if ans == 0:
        break
    elif ans > limit:
        length = 1
        break
    else:
        pass

if length == 1:
    print(-1)
else:
    print(ans)
### BUGGY CODE ###

Q = int(input())
mod = int(1e+6 + 3)
def gcd(a, b):
  p, q = a, b
  while q != 0:
    a, b = b, a % b
  return a
def doublestep(a):
  li = []
  while a != 0:
    li = [a%2] + li[:]
    a //= 2
  return li
def doubling(z, num):
  y = doublestep(num)
  tet = 1
  for i in range(len(y)):
    if y[i] == 1:
      tet *= z
      tet %= mod
    if i != len(y) - 1:
      tet *= tet
      tet %= mod
  return tet
modi = doublestep(mod-2)
def inved(s):
  y = 1
  for i in range(len(modi)):
    if modi[i] == 1:
      y *= s
      y %= mod
    if i != len(modi) - 1:
      y *= y
      y %= mod
  return y

frac = [1]
for i in range(2 * mod):
  frac.append((frac[i]*(i+1))%mod)
for i in range(Q):
  x, d, n = map(int, input().split())
  if x == 0:
    print(0)
  else:
    if d == 0:
      print(doubling(x, n))
    else:
      if n >= mod:
        print(0)
      else:
        dn = doubling(d, n)
        xinvd = x * inved(d) - 1
        xinvd %= mod
        print((dn * frac[xinvd + n] * inved(frac[xinvd])) % mod)

### FIXED CODE ###

Q = int(input())
mod = int(1e+6 + 3)

def doubling(n, m):
  y = 1
  p = n
  while m != 0:
    if m % 2 == 1:
      y *= p
      y %= mod
    m //= 2
    p *= p
    p %= mod
  return y

def inved(s):
  x, y, u, v, k, l = 1, 0, 0, 1, s, mod
  while l != 0:
    x, y, u, v = u, v, x - u * (k // l), y - v * (k // l)
    k, l = l, k % l
  return x % mod

frac = [1 for _ in range(mod+1)]
invf = [1 for _ in range(mod+1)]
invf[mod] = 0
for i in range(mod):
  frac[i+1] = (frac[i] * (i+1)) % mod
invf[mod-1] = inved(frac[mod-1])
for i in range(mod-1, 0, -1):
  invf[i-1] = (invf[i] * i) % mod

for i in range(Q):
  x, d, n = map(int, input().split())
  if x == 0:
    print(0)
  else:
    if d == 0:
      print(doubling(x, n))
    else:
      if n >= mod:
        print(0)
      else:
        xinvd = x * inved(d) - 1
        xinvd %= mod
        if xinvd + n >= mod:
          print(0)
        else:
          dn = doubling(d, n)
          print((dn * frac[xinvd + n] * invf[xinvd]) % mod)
### BUGGY CODE ###

n=int(input())
s=sorted(list(map(int,input().split())))
ans=0
for i in range(n-2):
  for j in range(i+1,n-1):
    for k in range(j+1,n):
      if s[i]+s[j]>s[k] :
        ans+=1
      
print(ans)


### FIXED CODE ###

from bisect import bisect_left
n = int(input())
l = [int(_) for _ in input().split()]
l.sort()
cnt = 0
for i in range(n):
    for j in range(i+1,n):
        cnt += max(0, bisect_left(l, l[i] + l[j]) - (j+1))
print(cnt)
### BUGGY CODE ###

import math

n, m = [int(i) for i in input().split()]

ans = 1
a_pre = -1
for mi in range(m):
    a = int(input())
    if a == a_pre:
        break
    elif a == a_pre + 1:
        ans = 0
        break
    k = a - a_pre - 2
    max_2 = k//2
    cnt = 0
    for i in range(max_2+1):
        cnt += math.factorial(k-i) // (math.factorial(k-2*i) * math.factorial(i)) % 1000000007
    ans = ans * cnt % 1000000007
    if ans == 0:
        break
    a_pre = a

a = n + 1
if a == a_pre:
    pass
elif a == a_pre + 1:
    ans = 0
else:
    k = a - a_pre - 2
    max_2 = k//2
    cnt = 0
    for i in range(max_2+1):
        cnt += math.factorial(k-i) // (math.factorial(k-2*i) * math.factorial(i)) % 1000000007
    ans = ans * cnt % 1000000007

print(ans)


### FIXED CODE ###

n, m = [int(i) for i in input().split()]

b = [0 for i in range(n+1)]

for mi in range(m):
    b[int(input())] = 1
cnt = 0
s = [0 for i in range(n+1)]
s[0] = 1
if b[1] == 0:
    s[1] = 1
else:
    s[1] = 0
for ni in range(2,n+1):
    if b[ni] == 0:
        s[ni] = (s[ni-1] + s[ni-2]) % 1000000007
    else:
        s[ni] = 0
print(s[n])
### BUGGY CODE ###

#input
H, W = map(int, input().split())
import numpy as np
S = np.array([input() for _ in range(H)])

#output
import numpy as np

INF = -1
dx = [1, 0, -1, 0]
dy = [0, 1, 0 ,-1]

answer = 0
for i in range(H):
    for j in range(W):
        if S[i][j] != "#":
            dp = np.full((H, W), INF)
            q = []
            q.insert(0, (i, j))
            dp[i, j] = 0
            while len(q):
                x, y = q.pop()

                for t in range(4):
                    nx, ny = x + dx[t], y + dy[t]

                    if (0 <= nx < H) and (0 <= ny < W) and (S[nx][ny] != "#") and (dp[nx, ny] == INF):
                        q.insert(0, (nx, ny))
                        dp[nx, ny] = dp[x, y] + 1
            for row in dp:
                answer = max(answer, max(row))
print(int(answer))


### FIXED CODE ###

#input
H, W = map(int, input().split())
import numpy as np
S = [input() for _ in range(H)]

#output
import numpy as np

INF = -1
dx = [1, 0, -1, 0]
dy = [0, 1, 0 ,-1]

answer = 0
for i in range(H):
    for j in range(W):
        if S[i][j] != "#":
            dp = np.full((H, W), INF)
            q = []
            q.insert(0, (i, j))
            dp[i, j] = 0
            while len(q):
                x, y = q.pop()

                for t in range(4):
                    nx, ny = x + dx[t], y + dy[t]

                    if (0 <= nx < H) and (0 <= ny < W) and (S[nx][ny] != "#") and (dp[nx, ny] == INF):
                        q.insert(0, (nx, ny))
                        dp[nx, ny] = dp[x, y] + 1
            for row in dp:
                answer = max(answer, max(row))
print(int(answer))
### BUGGY CODE ###


def merge(s, t):
    u = []

    while s + t:
        
        if s == [] or t == []:
            return u + s + t

        if s[0] <= t[0]:
            u.append(s[0])
            s = s[1:]
        else: # s0 > t0
            u.append(t[0])
            t = t[1:]

    return u

def merge_sort(A):
    while len(A) > 1:
        B = []
        for i in range(len(A) // 2):
            B.append(merge(A[2 * i], A[2 * i + 1]))
        if len(A) % 2 == 1:
            B.append(A[len(A) - 1])
        A = B

    return(A[0])

N = int(input())
A = []
B = []

for i in range(N):
    a, b = [[int(x)] for x in input().split()]
    A.append(a)
    B.append(b)

C = merge_sort(A)
D = merge_sort(B)

if N % 2 == 0:
    ans = D[N//2 - 1] + D[N//2] - C[N//2 - 1] - C[N//2] + 1
else: # N % 2 == 1
    ans = D[N//2] - C[N//2] + 1

print(ans)

### FIXED CODE ###

import numpy as np

N = int(input())
A = []
B = []

for i in range(N):
    a, b = [int(x) for x in input().split()]
    A.append(a)
    B.append(b)

C = np.array(A)
D = np.array(B)

m_inf = np.median(C)
m_sup = np.median(D)

if N % 2 == 0:
    ans = 2 * m_sup - 2 * m_inf + 1
else:
    ans = m_sup - m_inf + 1

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

N = int(input())
s = [''.join(sorted(list(input()))) for _ in range(N)]
ans = 0
for i in range(N - 1):
    for j in range(i + 1, N):
       if s[i] == s[j]:
           ans += 1

print(ans)
    

### FIXED CODE ###

N = int(input())
cnt_dict = dict()

for _ in range(N):
    s = ''.join(sorted(list(input())))
    if s in cnt_dict:
        cnt_dict[s] += 1
    else:
        cnt_dict[s] = 1

ans = 0
for cnt in cnt_dict.values():
    ans += cnt * (cnt - 1) // 2

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

import numpy as np
n = int(input())
a = np.array([int(i) for i in input().split()])
a = np.sort(a)
d = a[0]
while True:
    a1 = a % d
    if all(a1 == 0):
        ans = d
        break
    a1[0] = d
    d = min(a1[a1 != 0])    
print(ans)

### FIXED CODE ###

import numpy as np
n = int(input())
a = np.array([int(i) for i in input().split()])
d = a.min()
while True:
    a1 = a % d
    if all(a1 == 0):
        ans = d
        break
    d = min(a1[a1 != 0])    
print(ans)
### BUGGY CODE ###


A,B,M =map(int,input().split())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
x = []
for m in range(M):
    x.append([int(i) for i in input().split()])
_min = 10**7
for i in range(len(a)):
	for j in range(len(b)):
		_min = min(a[i]+b[j],_min)

for i in x:
    _min = min( (a[i[0]-1]+b[i[1]-1] - i[2]),_min)
print(_min)

### FIXED CODE ###


A,B,M =map(int,input().split())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
x = []
for m in range(M):
    x.append([int(i) for i in input().split()])
_min = min(a)+min(b)
		
for i in x:
    _min = min( (a[i[0]-1]+b[i[1]-1] - i[2]),_min)
print(_min)
### BUGGY CODE ###

X, K, D = map(int, input().split())
goal = []
times = 0
pos = [0]
movement = []

while times < K:
    for i in pos:
        plus = i + 1
        minus = i - 1
        movement.append(plus)
        movement.append(minus)
    times += 1
    pos.clear()
    for j in movement:
        pos.append(j)
    movement.clear()

for i in pos:
    goal.append(i * D + X)

print(abs(min(goal, key=abs)))


### FIXED CODE ###

import math
X, K, D = map(int, input().split())
ans = 0
if K * D < abs(X):
    ans = abs(X) - K * D
elif (K - math.floor(abs(X) / D)) % 2 == 0:
    ans = abs(X) - (math.floor(abs(X) / D)) * D
else:
    ans = abs(X) - (math.floor(abs(X) / D)) * D - D

print(abs(int(ans)))
### BUGGY CODE ###

n = int(input())
l = [int(i) for i in input().split()]


ans = 0
for i in range(n):
    j = l.count(i)
    ans += int(j * (j - 1) / 2)

for i in range(n):
    ans_i = 0
    j = l.count(l[i])
    print(ans - j + 1)


for i in range(3, n + 1):
    l.count(i)


### FIXED CODE ###

from collections import Counter

n = int(input())
l = [int(i) for i in input().split()]

S = Counter(l)

ans = 0
for i in S.values():
    ans += int(i * (i - 1) / 2)

for i in range(n):
    val = S[l[i]]
    print(ans - val + 1)
### BUGGY CODE ###

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

### FIXED CODE ###

import numpy as np
n = int(input())
a = np.array([int(input()) for _ in range(n)])
a1n = a.argmax()
a_s = sorted(a)
a1 = a_s[-1]
a2 = a_s[-2]
for i in range(n):
    if i == a1n:
        print(a2)
    else:
        print(a1)