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

MOD=10**9+7
N,x=map(int,input().split())
 
a=list(map(int,input().split()))
a.sort()
a.reverse()
table=[[0 for i in range(N+1)] for j in range(x+1)]
for i in range(x+1):
	table[i][N]=i
 
for i in range(N-1,-1,-1):
	for j in range(x+1):
		table[j][i]=(table[j][i+1]*(N-1-i)+table[j%a[i]][i+1]) % MOD
 
print(table[x][0])

### FIXED CODE ###

import math

def cul(i,x):
    if tmp[i][x]==-1:
        tmp[i][x]=( cul(i+1,x)*(N-1-i) + cul(i+1,x%a[i]) )%MOD
    return tmp[i][x]

MOD=10**9+7
N,x=map(int,input().split())

a=list(map(int,input().split()))
a.sort(reverse=True)
tmp= [[-1 for j in range(x+1)] for i in range(N)] + [[j for j in range(x+1)]]

print(cul(0,x))
### BUGGY CODE ###

import numpy as np
N = int(input())  # 個数
A = np.array([int(i) for i in input().split()], dtype=np.int64)  # 整数

sum_j = [sum(A[i + 1:N]) % 1000000007 for i in range(N - 1)]
mod_A = np.dot(A[0:N-1], sum_j) % 1000000007

print(mod_A)

### FIXED CODE ###

N = int(input())  # 個数
A = [int(i) for i in input().split()]  # 整数

sum_Aij = 0
sum_j = [0] * (N - 1)
for i in range(N - 1, 0, -1):
    sum_j[i - 1] = (A[i] + (0 if i == N - 1 else sum_j[i])) % 1000000007
    sum_Aij += sum_j[i - 1] * A[i - 1] % 1000000007

print(sum_Aij % 1000000007)
### BUGGY CODE ###

N = int(input())
ans  = 1
for i in range(1,N+1):
    ans = ans * i
print(ans % (10**9 + 7))

### FIXED CODE ###

N = int(input())
ans  = 1
for i in range(1,N+1):
    ans = ans * i % (10**9 + 7)
print(ans)
### BUGGY CODE ###

def pow_k(x, n):
    """
    O(log n)
    """
    if n == 0:
        return 1

    K = 1
    while n > 1:
        if n % 2 != 0:
            K *= x
        x *= x
        n //= 2

    return K * x

mod = 10 ** 9 + 7



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

m = 10 ** 5 * 2 + 100
fact = [0 for _ in range(m)]
fact[0] = 1
for i in range(m-1):
    fact[i+1] = (fact[i] * (n - i) * pow((i + 1), mod - 2, mod)) % mod



nca = fact[a] #comb(n, a, mod)#factorial(n) // factorial(a) // factorial(n-a)
ncb = fact[b] #comb(n, b, mod)#factorial(n) // factorial(b) // factorial(n-b)

ans = pow_k(2, n)

ans -= 1 + nca + ncb
ans %= mod
print(ans)


### FIXED CODE ###

mod = 10 ** 9 + 7

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

def combmod(n,k,mod):
    a = 1
    b = 1
    for i in range(k):
        a = a * (n-i) % mod
        b = b * (i+1) % mod
    return a * pow(b, mod-2, mod) % mod

nca = combmod(n, a, mod) #comb(n, a, mod)#factorial(n) // factorial(a) // factorial(n-a)
ncb = combmod(n, b, mod) #comb(n, b, mod)#factorial(n) // factorial(b) // factorial(n-b)

ans = pow(2, n, mod)

ans -= 1 + nca + ncb
ans %= mod
print(ans)
### BUGGY CODE ###

import fractions
#import math
from functools import reduce

def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)

n = int(input())
a = [int(i) for i in input().split()]
mod = 10 ** 9 + 7
ans = 0
b = lcm(*a)

for i in range(n):
    ans += b // a[i]
print(ans%mod)

### FIXED CODE ###

import fractions
#import math
from functools import reduce

def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)

n = int(input())
a = [int(i) for i in input().split()]
mod = 10 ** 9 + 7
ans = 0
b = lcm(*a)

for i in range(n):
    ans += b // a[i]
print(ans%mod)
### BUGGY CODE ###

from collections import deque

def reachable(es, source):
	ret = {source}
	Q = deque([source])
	while Q:
		cur = Q.popleft()
		for nxt in es[cur]:
			if nxt not in ret:
				Q.append(nxt)
				ret.add(nxt)
	return ret

def SPFA(G:list, source=0):
	from collections import deque
	V = len(G)
	d = [float("inf")]*V
	inQ = [False]*V
	cnt = [0]*V
	d[source] = 0
	cnt[source] = 1
	Q = deque([source])
	_sum = 0
	_len = 1
	while Q:
		f = Q.popleft()
		inQ[f] = False
		_sum -= d[f]
		_len -= 1
		for t,c in G[f]:
			dist = d[f] + c
			if dist < d[t]:
				d[t] = dist
				if not inQ[t]:
					inQ[t] = True
					cnt[t] += 1
					if dist*_len < _sum:
						Q.appendleft(t)
					else:
						Q.append(t)
					_sum += dist
					_len += 1
				if cnt[t] > V:
					#negative cycle
					return None
	return d[-1]
	
def main():
	N,M,P,*L=map(int,open(0).read().split())
	fwd = [[] for _ in range(N)]
	bwd = [[] for _ in range(N)]
	G = [[] for _ in range(N)]
	for a,b in zip(L[::3],L[1::3]):
		fwd[a-1].append(b-1)
		bwd[b-1].append(a-1)
	judge = reachable(fwd,0) & reachable(bwd,N-1)
	for a,b,c in zip(*[iter(L)]*3):
		if a-1 in judge and b-1 in judge:
			G[a-1].append((b-1,P-c))
	ans = SPFA(G)
	if ans==None:
		print(-1)
	else:
		print(max(0,-ans))

if __name__=="__main__":
	main()

### FIXED CODE ###

n,m,p = map(int,input().split())
graph = [[] for _ in range(n)]
INF = float("inf")
dist = [INF]*n
dist[0] = 0

for _ in range(m):
	f,t,c = map(int,input().split())
	graph[f-1].append((t-1,p-c))
#print(graph)

for _ in range(n):
	update = False
	for f,e in enumerate(graph):
		for t,c in e:
			if dist[f] != INF and dist[t] > dist[f] + c:
				dist[t] = dist[f] + c
				update = True
	if not update:
		break
else:
	prev = dist[-1]
	for _ in range(n):
		update = False
		for f,e in enumerate(graph):
			for t,c in e:
				if dist[f] != INF and dist[t] > dist[f] + c:
					dist[t] = dist[f] + c
					update = True
		if not update:
			break
	if dist[-1] != prev:
		print(-1)
		exit()
#print(dist)

print(max(0,dist[-1]*(-1)))
### BUGGY CODE ###

import fractions
import functools

def multiple(a, b):
    return a*b // fractions.gcd(a, b)
def lcm(nums):
  return functools.reduce(multiple, nums)

def main():
  N = int(input())
  A = list(map(int, input().split()))
  n = lcm(A)
  ans = 0
  mod = 10**9+7
  for a in A:
    ans += n//a
    ans %= mod
  print(ans)

if __name__ == "__main__":
  main()



### FIXED CODE ###

from fractions import gcd

N = int(input())
A = list(map(int, input().split()))
mod = 10**9+7

x = 1
for i in range(N):
  x = (x*A[i]) // gcd(x, A[i])

ans = 0
for a in A:
  ans += x//a
  #ans %= mod
print(ans%mod)
### BUGGY CODE ###

n,m = map(int,input().split())

a=[]
b=[]
cnt=0
sum=0


for i in range(0,n):
    ta,tb = map(int,input().split())
    a.append(ta)
    b.append(tb)


while m>0:
    mindex = a.index(min(a))
    num = m if m<b[mindex] else b[mindex]
    sum+=a[mindex]*num
    m-=num
    del b[mindex]
    del a[mindex]



print(sum)

### FIXED CODE ###

n,m = map(int,input().split())
data = []
sum=0


for i in range(0,n):
    a,b = map(int,input().split())
    data.append((a,b))

data.sort()

while m>0:
    num = m if m<data[0][1] else data[0][1]
    sum+=data[0][0]*num
    m-=num
    del data[0]

print(sum)
### BUGGY CODE ###

import fractions
n=int(input())
A=list(map(int,input().split()))

a=A[0]
for b in A:
    a = a /fractions.gcd(a, b)*b

count=0
for i in A:
    count+=a/i

print(round(count%((10**9)+7)))

### FIXED CODE ###

import fractions
n=int(input())
A=list(map(int,input().split()))

a=A[0]
for b in A:
    a = (a * b) // fractions.gcd(a, b)

count=0
for i in A:
    count+=a//i

print((count%((10**9)+7)))
### BUGGY CODE ###

N = int(input())
S = input()

r , g, b = S.count("R"), S.count("G"), S.count("B")
ans = r * g * b

for i in range(N-2):
    for j in range(i+1, N-1):
        k = 2*(j+1) - (i+1) # j > iより k = 2j - i > j
        if k <= N:
            if S[i] != S[j] and S[j] != S[k-1] and S[k-1] != S[i]:
                ans -= 1
print(ans)

### FIXED CODE ###

N = int(input())
S = input()

r , g, b = S.count("R"), S.count("G"), S.count("B")
ans = r * g * b

for i in range(N-2):
    for d in range(N//2+1):
        j = i + d
        k = j + d
        if k >= N:break
        if S[i] != S[j] and S[j] != S[k] and S[k] != S[i]:
            ans -= 1
print(ans)
### BUGGY CODE ###

s = str(input())
t= str(input())

sdict = {}
for i in range(len(s)):
    if s[i] not in sdict:
        sdict[s[i]]=[]
    sdict[s[i]].append(i+1)
    
#print(sdict)

#二分木探索
def search(list_,mark_):
    if  len(list_) == 1:
            return list_[0]
    else:
            mid = len(list_)//2
            if list_[mid-1]>mark_:
                return search(list_[:mid],mark_)
            else:
                return search(list_[mid:],mark_)

ans = 0
mark = 0
for _ in range(len(t)):
    target = t[_]
    if target not in sdict:
        ans = -1
        break
    else:
        if sdict[target][-1]<=mark:
            mark = sdict[target][0]
            ans += len(s)
        elif sdict[target][0]>mark:
            mark = sdict[target][0]
        else:
            posi = search(sdict[target],mark)
            mark = posi
        
if ans != -1:
    ans += mark
print(ans)

### FIXED CODE ###

s = str(input())
t= str(input())

sdict = {}
for i in range(len(s)):
    if s[i] not in sdict:
        sdict[s[i]]=[]
    sdict[s[i]].append(i+1)
    
#print(sdict)

#二分木探索
def search(list_,mark_,sta,gol):
    if  sta == gol:
            return list_[sta]
    else:
            mid = (gol+sta)//2
            if list_[mid]>mark_:
                return search(list_,mark_,sta,mid)
            else:
                return search(list_,mark_,mid+1,gol)

ans = 0
mark = 0
for _ in range(len(t)):
    target = t[_]
    if target not in sdict:
        ans = -1
        break
    else:
        if sdict[target][-1]<=mark:
            mark = sdict[target][0]
            ans += len(s)
        elif sdict[target][0]>mark:
            mark = sdict[target][0]
        else:
            posi = search(sdict[target],mark,0,len(sdict[target])-1)
            mark = posi
        
if ans != -1:
    ans += mark
print(ans)
### BUGGY CODE ###

#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**8)
input = sys.stdin.readline

MOD = 998244353
MAX_N = 10**7 

fac = [1] + [0] * MAX_N
fac_inv = [1] + [0] * MAX_N
mod_pow2_n = [1] + [0] * MAX_N
for i in range(1, MAX_N+1):
    fac[i] = fac[i-1] * i % MOD
    mod_pow2_n[i] = mod_pow2_n[i-1] * 2 % MOD

fac_inv[MAX_N] = pow(fac[MAX_N], MOD-2, MOD)
for i in range(MAX_N, 1, -1):
    fac_inv[i-1] = fac_inv[i] * i % MOD

def mod_nCr(n, r):
    if n < r or n < 0 or r < 0:
        return 0
    tmp = fac_inv[n-r] * fac_inv[r] % MOD
    return tmp * fac[n] % MOD 
    
n = int(input())
ans = 0
for i in range(n//2+1, n+1):
    ans += mod_nCr(n, i) * pow(2, n - i, MOD)
    ans %= MOD
print((pow(3, n, MOD) - ans * 2 + MOD)%MOD)

### FIXED CODE ###

#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**8)
input = sys.stdin.readline

MOD = 998244353
MAX_N = 10**7 

fac = [1] + [0] * MAX_N
fac_inv = [1] + [0] * MAX_N
mod_pow2_n = [1] + [0] * MAX_N
for i in range(1, MAX_N+1):
    fac[i] = fac[i-1] * i % MOD
    mod_pow2_n[i] = mod_pow2_n[i-1] * 2 % MOD

fac_inv[MAX_N] = pow(fac[MAX_N], MOD-2, MOD)
for i in range(MAX_N, 1, -1):
    fac_inv[i-1] = fac_inv[i] * i % MOD

def mod_nCr(n, r):
    if n < r or n < 0 or r < 0:
        return 0
    tmp = fac_inv[n-r] * fac_inv[r] % MOD
    return tmp * fac[n] % MOD 
    
n = int(input())
ans = 0
for i in range(n//2+1, n+1):
    ans += mod_nCr(n, i) * mod_pow2_n[n-i]
    ans %= MOD
print((pow(3, n, MOD) - ans * 2 + MOD)%MOD)
### BUGGY CODE ###

import bisect

def main():
    N = int(input())

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

    # print(A,B,C)

    A.sort()
    B.sort()
    C.sort()

    def f(b):
        """ bより大きい数がいくつあるか
        """
        p = bisect.bisect_right(C, b)
        return N - p

    cnt = 0
    for ai in A:
        for bi in B:
            if bi <= ai:
                continue
            x = f(bi)
            cnt += x

    print(cnt)


if __name__ == "__main__":
    main()

### FIXED CODE ###

import bisect

def main():
    N = int(input())

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

    # print(A,B,C)

    A.sort()
    B.sort()
    C.sort()

    def get_a(b):
        p = bisect.bisect_left(A, b)
        return p

    def get_c(b):
        """ bより大きい数がいくつあるか
        """
        p = bisect.bisect_right(C, b)
        return N - p

    cnt = 0
    for bi in B:
        x = get_a(bi) * get_c(bi)
        cnt += x

    print(cnt)


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

import sys
input = sys.stdin.readline

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

mod = 10 ** 9 + 7

a_bin = [format(i, 'b') for i in a]

m = len(max(a_bin, key = len))

ans = 0

for i in range(n):
    a_bin[i] = '0' * (m - len(a_bin[i])) + a_bin[i]

for i in range(1, m+1):
    count = [0, 0]
    for j in a_bin:
        count[int(j[-i])] += 1
    ans += count[0] * count[1] * 2 ** (i-1)

print(ans % mod)


### FIXED CODE ###

import sys
import numpy as np
input = sys.stdin.readline

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

    mod = 10 ** 9 + 7

    a_bin = [format(i, 'b') for i in a]

    m = len(max(a_bin, key = len))

    ans = 0

    for i in range(n):
        a_bin[i] = '0' * (m - len(a_bin[i])) + a_bin[i]

    for i in range(1, m+1):
        count = [0, 0]
        for j in a_bin:
            count[int(j[-i])] += 1
        ans += count[0] * count[1] * 2 ** (i-1)

    print(ans % mod)

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

    a = np.array(a)
    ans = 0
    mod = 10**9 + 7

    for i in range(60):
        count = np.count_nonzero(a & 1)
        ans += count * (n - count) * 2 ** i
        a >>= 1

    print(ans % mod)

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

A, B, K = [int(_) for _ in input().split()]

for n in range(A, B + 1):
    if n < A + K or n > B - K:
        print(n)
        


### FIXED CODE ###

A, B, K = [int(_) for _ in input().split()]

nums = set(
    [n for n in range(A, min(A + K, B + 1))] +
    [n for n in range(max(B - K + 1, A), B + 1)]
)

for n in sorted(nums):
    print(n)
### BUGGY CODE ###

R,G,B,N = map(int,input().split())
c = sorted([R,G,B])
R = c[1]
G = c[2]
B = c[0]
ans = 0
for r in range(N//R+1):
    tmp = N - r*R
    for g in range(N//G+1):
        ttmp = tmp - g*G
        ans += int(ttmp%B == 0 and ttmp >= 0)
print(ans)

### FIXED CODE ###

R,G,B,N = map(int,input().split())

ans = 0
for r in range(N+1):
    for g in range(N+1):
        tmp = N - r*R - g*G
        if tmp >= 0 and tmp%B == 0:
            ans += 1
print(ans)
### BUGGY CODE ###

from itertools import combinations
N = int(input())
scores = [int(input())for i in range(N)]
sums= sum(scores)
if sums % 10 != 0:
    print(sums)
    exit()
m = 0
for i in range(1,N):
    for j in combinations(scores,i):
        sj = sum(j)
        if (sums - sj) % 10 != 0:
            m = max(m, sums - sj)
print(m)

### FIXED CODE ###

from itertools import combinations
N = int(input())
scores = [int(input())for i in range(N)]
sums= sum(scores)
if sums % 10 != 0:
    print(sums)
    exit()
scores.sort()
for i in range(N):
    if (sums-scores[i]) % 10 != 0:
        print(sums - scores[i])
        exit()
print(0)
### BUGGY CODE ###

def main():
    N = int(input())
    P = list(map(int, input().split()))

    ans = 1

    for i in range(1, N):
        tmp = min(P[:i])
        if P[i] <= tmp:
            ans += 1

    print(ans)


if __name__ == "__main__":
    main()


### FIXED CODE ###

def main():
    N = int(input())
    P = list(map(int, input().split()))

    ans = 1
    tmp = P[0]
    for i in range(1, N):
        if P[i] == 1:
            print(ans + 1)
            return

        tmp = min(tmp, P[i])
        if P[i] <= tmp:
            ans += 1

    print(ans)


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

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

for _ in range(M):
  ma=max(A)
  A[A.index(ma)]//=2

print(sum(A))

### FIXED CODE ###

import heapq
N,M=map(int,input().split())
A=list(map(lambda x:-int(x),input().split()))
heapq.heapify(A)


for _ in range(M):
  ma=heapq.heappop(A)
  heapq.heappush(A,-((-ma)//2))
  
print(-sum(A))
### BUGGY CODE ###

import numpy as np

def count():
    pass

def one_game(i, D, A, start, end):
    current = np.array([])
    count = 0
    for X in range(start, end+1, D):
        old = np.copy(current)
        current = np.where(A==X)
        if X == start:
            continue
        count += abs(current[0][0] - old[0][0]) + abs(current[1][0] - old[1][0])
    return count

def f(H, W, D, A, Q, ST):
    A = np.array(A)
    counts = []
    for i in range(Q):
        start = ST[i][0]
        end = ST[i][1]
        count = one_game(i, D, A, start, end)
        counts.append(count)
    return counts

def main():
    H, W, D = map(int, input().split())
    A = [
        list(map(int, input().split())) for _ in range(H)
    ]
    Q = int(input())
    ST = [
        list(map(int, input().split())) for _ in range(Q)
    ]

    counts = f(H, W, D, A, Q, ST)
    for i in range(Q):
        print(counts[i])

if __name__ == '__main__':
    main()


### FIXED CODE ###

def main():
    H, W, D = map(int, input().split())
    A = [
        list(map(int, input().split())) for _ in range(H)
    ]
    Q = int(input())
    ST = [
        list(map(int, input().split())) for _ in range(Q)
    ]

    pos = [0] * (H * W + 1)
    for i, row in enumerate(A):
        for j, value in enumerate(row):
            pos[value] = (i, j)

    d = [0] * (H * W + 1)
    for x in range(D + 1, H * W + 1):
        y = x - D
        p1, p2 = pos[x], pos[y]
        d[x] = d[y] + abs(p1[0] - p2[0]) + abs(p1[1] - p2[1])

    for l, r in ST:
        print(d[r] - d[l])


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

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

dp = [[0 for i in range(N+1)] for j in range(N+1)]
dp[0][0] = 1

for i in range(1,N+1):
    for j in range(0,i+1):
        if j == 0:
            dp[i][j] = dp[i-1][j] * (1-P[i-1])
        elif j == i:
            dp[i][j] = dp[i-1][j-1] * P[i-1]
        else:
            dp[i][j] = dp[i-1][j]*(1-P[i-1]) + dp[i-1][j-1]*P[i-1]
print(sum(dp[-1][N//2 + 1:]))

### FIXED CODE ###

N = int(input())
P = [float(i) for i in input().split()] 
 
dp = [[0 for i in range(N+1)] for j in range(N+1)]
dp[0][0] = 1
 
for i in range(1,N+1):
    for j in range(0,i+1):
        if j == 0:
            dp[i][j] = dp[i-1][j] * (1-P[i-1])
        elif j == i:
            dp[i][j] = dp[i-1][j-1] * P[i-1]
        else:
            dp[i][j] = dp[i-1][j]*(1-P[i-1]) + dp[i-1][j-1]*P[i-1]
print(sum(dp[-1][N//2 + 1:]))
### BUGGY CODE ###

is_prime = [True] * (10**5)
is_prime[0] = False
is_prime[1] = False
primes = []
for i in range(2, len(is_prime)):
    if is_prime[i]:
        primes.append(i)
        for j in range(i*2, len(is_prime), i):
            is_prime[j] = False

def do_prime_fact(x):
    res = {}
    for prime in primes:
        if x == 1:
            return res
        while x % prime == 0:
            x /= prime
            if not prime in res:
                res[prime] = 0
            res[prime] += 1
    if x > 1: # x is large prime
        res[x] = 1
        primes.append(x)
    return res

def solve(x):
    ys = [do_prime_fact(x[i+1] - x[i]) for i in range(len(x)-1)]
    d = 1
    for k in ys[0].keys():
        ok = True
        while ok:
            for y in ys:
                if (not k in y) or (y[k] == 0):
                    ok = False
                    break
            if ok:
                for y in ys:
                    y[k] -= 1
                d *= k
    return d

n, x0 = map(int, raw_input().split())
x = map(int, raw_input().split())
x = list(sorted(set([x0] + x)))
print(solve(x))

### FIXED CODE ###

is_prime = [True] * (10**5)
is_prime[0] = False
is_prime[1] = False
primes = []
for i in range(2, len(is_prime)):
    if is_prime[i]:
        primes.append(i)
        for j in range(i*2, len(is_prime), i):
            is_prime[j] = False

def do_prime_fact(x, ps):
    res = {}
    for prime in ps:
        while x % prime == 0:
            x /= prime
            if not prime in res:
                res[prime] = 0
            res[prime] += 1
    if x > 1: # x is large prime
        res[x] = 1
    return res

def solve(x):
    y = do_prime_fact(x[1] - x[0], primes)
    ps = y.keys()
    ys = [do_prime_fact(x[i+1] - x[i], ps) for i in range(len(x)-1)]
    d = 1
    for k in ps:
        ok = True
        while ok:
            for y in ys:
                if (not k in y) or (y[k] == 0):
                    ok = False
                    break
            if ok:
                for y in ys:
                    y[k] -= 1
                d *= k
    return d

n, x0 = map(int, raw_input().split())
x = map(int, raw_input().split())
x = list(sorted(set([x0] + x)))
print(solve(x))
### BUGGY CODE ###

n = int(input())
x=0
c=n
for i in range(1,n+1):
  x+=i%(c)
print(x)

### FIXED CODE ###

n = int(input())
x=0
c=n
x=((n*(n-1))//2)
print(x)
### BUGGY CODE ###

N = int(input())
S = input()
#print(S)
cnt = 1
S_list = [s for s in S]
#print(S_list)
for i in range(N):
    if S_list[N-1-i] != S_list[N-1-(i+1)] and N-1-(i+1)>=0:
        S_list.insert(N-1-i,"|")
        cnt += 1
    #print(S_list)
print(cnt)

### FIXED CODE ###

N = int(input())
S = input()
#print(S)
cnt = 1
S_list = [s for s in S]
#print(S_list)
for i in range(N):
    if S_list[N-1-i] != S_list[N-1-(i+1)] and N-1-(i+1)>=0:
        #S_list.insert(N-1-i,"|")
        cnt += 1
    #print(S_list)
print(cnt)
### BUGGY CODE ###

def main():
    h,w = map(int,input().split()) 
    x=[[-1 for _ in range(w)] for _ in range(h)]
    a=[]
    for _ in range(h):
        a.append(list(input()))
    for i in range(h):
        for j in range(w):
            if a[i][j]=="#":
                x[i][j]=0
    cnt=0
    check=0
    while True:
        key=0
        for i in range(h):
            for j in range(w):
                if x[i][j]==-1:
                    key=1
                    if j<w-1 and x[i][j+1]==check:
                        x[i][j]=x[i][j+1]+1
                    elif 0<j and x[i][j-1]==check:
                        x[i][j]=x[i][j-1]+1
                    elif i<h-1 and x[i+1][j]==check:
                        x[i][j]=x[i+1][j]+1
                    elif 0<i and x[i-1][j]==check:
                        x[i][j]=x[i-1][j]+1
        if key==0:
            break
        else:
            check+=1
            cnt+=1
    print(cnt)
if __name__ == "__main__":
    main()

### FIXED CODE ###

def main():
    h,w = map(int,input().split())
    a=[]
    que=[]
    for _ in range(h):
        a.append(list(input()))
    for i in range(h):
        for j in range(w):
            if a[i][j]=="#":
                que.append([i,j])
                a[i][j]=0
    ans=0
    while que!=[]:
        tank=[]
        for i,j in que:
            if j<w-1 and a[i][j+1]==".":
                tank.append([i,j+1])
                a[i][j+1]=a[i][j]+1
            if 0<j and a[i][j-1]==".":
                tank.append([i,j-1])
                a[i][j-1]=a[i][j]+1
            if i<h-1 and a[i+1][j]==".":
                tank.append([i+1,j])
                a[i+1][j]=a[i][j]+1
            if 0<i and a[i-1][j]==".":
                tank.append([i-1,j])
                a[i-1][j]=a[i][j]+1
        que=tank
        ans+=1
    print(ans-1)
if __name__ == "__main__":
    main()
### 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)]

b = sorted(a)
a1 = b[-1]
a2 = b[-2]
for i in range(n):
    if a[i] == a1:
        print(a2)
    else:
        print(a1)