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

import itertools
import collections
n=int(input())
s=list(str(input()))
c=collections.Counter(s)
alph_num=len(c.values())
ans=0
for i in range(alph_num):
    testlist=list(itertools.combinations(s,i+1))
    for seg in testlist:
        c_test=collections.Counter(seg)
        if len(c_test.values())==i+1:
            ans+=1
        else:
            pass
print(int(ans%(1e+9 + 7)))

### FIXED CODE ###

import collections
n=int(input())
s=list(str(input()))
c=collections.Counter(s)

testlist=list(c.values())
ans=1

for i in range(len(testlist)):
    ans=ans*(testlist[i]+1)
    ans=ans%(10**9+7)
ans=ans-1

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

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

b = []

for i in range(n):
    if i % 2 == 0:
        b.append(a[i])
    else:
        b.insert(0, a[i])

if n % 2 == 1:
    b.reverse()

print(" ".join(map(str, b)))

### FIXED CODE ###

from collections import deque
n = int(input())
a = list(map(int, input().split()))

b = deque()

for i in range(n):
    if i % 2 == 0:
        b.append(a[i])
    else:
        b.appendleft(a[i])

if n % 2 == 1:
    b.reverse()

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

import itertools

tmp = list(map(int, input().split()))
N, M = tmp[0], tmp[1]
A = []
B = []
for i in [0]*M:
    tmp = list(map(int, input().split()))
    A.append(tmp[0])
    B.append(tmp[1])

arranged = [[1]]
nextroom = []
ans = [0]*(N-1)
for j in [0]*M:
    flattenarr = sum(arranged, [])
    for i in range(M):
        for rooms in arranged:
            if A[i] in rooms and B[i] not in flattenarr:
                nextroom.append(B[i])
                if ans[B[i]-2] == 0:
                    ans[B[i]-2]=A[i]
                break

            if B[i] in rooms and A[i] not in flattenarr:
                nextroom.append(A[i])
                if ans[A[i]-2] == 0:
                    ans[A[i]-2]=B[i]
                break
    arranged.append(nextroom)
    nextroom = []

if 0 in ans:
    print('No')
else:
    print('Yes')
    for x in ans:
        print(x)

### FIXED CODE ###

import queue

N, M = map(int, input().split())
adj = [[] for i in [0]*N] # 隣接リスト
for i in [0]*M:
    a, b = map(int, input().split())
    adj[a-1].append(b)
    adj[b-1].append(a)

que = queue.Queue()
que.put(1)
guide = [-1]*(N)
 
while not que.empty():
    x = que.get()
    for y in adj[x-1]:
        if guide[y-1] == -1:
            que.put(y)
            guide[y-1] = x


print('Yes')
for i in guide[1:]:
        print(i)
### BUGGY CODE ###

n,q = map(int, input().split())
s=input()

for i in range(q):
    l,r=map(int, input().split())
    print(s[l-1:r].count('AC'))




### FIXED CODE ###

n,q = map(int, input().split())
s=input()
a=[0]*n
for i in range(1,n):
    a[i]+=a[i-1]
    if s[i-1]=='A' and s[i]=='C':
        a[i]+=1
for i in range(q):
    l,r=map(int, input().split())
    print(a[r-1]-a[l-1])
### BUGGY CODE ###

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

vc=[[] for _ in range(n)]
ec=[-1]*(n-1)
for p,ci in enumerate(g):
    for c, i in ci:
        color = 1
        while True:
            if color not in vc[p]:
                vc[p].append(color)
                vc[c].append(color)
                ec[i] = color
                break
            else:
                color += 1
        

print(max(ec))
for i in range(n-1):
    print(ec[i])


### FIXED CODE ###

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

vc=[0] * n
ec=[-1]*(n-1)
for p,ci in enumerate(g):
    color = 1
    for c, i in ci:
        if vc[p] == color:
            color += 1
        vc[c] = color
        ec[i] = color
        color += 1
        

print(max(ec))
for i in range(n-1):
    print(ec[i])
### BUGGY CODE ###

from itertools import chain
n,m=map(int,input().split())
a=list(map(int,input().split()))
bc=[list(map(int,input().split())) for i in range(m)]
a.sort()
bc.sort(key=lambda x:x[1],reverse=True)
t=[]
for i in range(m):
    t.append([bc[i][1]]*bc[i][0])
t=list(chain.from_iterable(t))

ans=sum(a)
j=0
while j<len(t) and j<n and t[j]>a[j]:
    ans+=t[j]-a[j]
    j+=1
#for i in range(n):
#   if i<len(t):
#       ans+=max(a[i],t[i])
#   else:
#       ans+=a[i]
print(ans)


### FIXED CODE ###

n,m=map(int,input().split())
a=list(map(int,input().split()))
bc=[list(map(int,input().split())) for i in range(m)]
a.sort()
bc.sort(key=lambda x:x[1],reverse=True)
t=[]

for b,c in bc:
    a.extend([c]*b)
    if len(a)>2*n:
        break
a.sort(reverse=True)
print(sum(a[:n]))
### BUGGY CODE ###

def main():
    l, r = map(int, input().split())

    res = 2018
    for i in range(l, r):
        for j in range(l+1, r+1):
            mod = (i*j)%2019
            if mod < res:
                res = mod
            if res == 0:
                break
        else:
            continue
        
    print(res)


if __name__ == '__main__':
    main()


### FIXED CODE ###

def main():
    l, r = map(int, input().split())

    res = 2018
    for i in range(l, r):
        for j in range(l+1, r+1):
            mod = (i*j)%2019
            if mod < res:
                res = mod
            if res == 0:
                break
        else:
            continue
        break
        
    print(res)


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

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


c=1
while P>1:
	for i in range(2,P+1):
		if P%i==0:
			if P%(i**N)==0:
				c*=i
				P=P//(i**N)
				break
			else:
				P=P//i
				break

print(c)

### FIXED CODE ###

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

root=P**(1/N)
x=round(root)

for i in range(x):
	if P%((x-i)**N)==0:
		print(x-i)
		break
### BUGGY CODE ###

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

# Kステップ手前までの座標からの所要コストをリスト化、最小値を計算
# 構造がかなり複雑

# i番目のcostと0番目のcost,i番目のcostと1番目のcost…と一個ずつ比較していく手法
# 構造的にはかなりすっきりしてて分かりやすい

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

dp = [0] + [10**9]*(N-1)
for i in range(1,N):
    for j in range(1, min(i+1,K+1)):
        dp[i] = min(dp[i],dp[i-j]+abs(h[i]-h[i-j]))
print(dp[-1])


### FIXED CODE ###

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

cost = [0]
for i in range(2,N+1):
    cost.append( min([cost[j] + abs(h[i-1]-h[j]) for j in range(max(0,i-K-1), i-1)]) )
print(cost[-1])
### BUGGY CODE ###

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

a.insert(0,0)
result = []

for i in range(1,N+1):
  idx = a.index(i)
  result.append(idx)

print(*result)

### FIXED CODE ###

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

a.insert(0,0)
result = []

tmp = []
for i in range(N+1):
  tmp.append([a[i],i])

tmp_sorted = sorted(tmp)

for i in range(1,N+1):
  result.append(tmp_sorted[i][1])

print(*result)
### BUGGY CODE ###

def main():
    n = int(input())
    a = [format(i, "b") for i in map(int, input().split())]
    mod = 10**9+7
    b = [0 for _ in range(61)]

    for i in range(n):
        for j in range(1, len(a[i])+1):
            b[j-1] += int(a[i][-j])

    result = 0
    for i in range(61):
        r = b[i]*(n-b[i])%mod
        for j in range(i):
            r = r*2 %mod
        result += r
    print(result%mod)

if __name__=="__main__":
    main()

### FIXED CODE ###

import numpy as np
mod = 10**9+7
n = int(input())
a = np.fromstring(input(), dtype = np.int64, sep = ' ')

result = 0
for i in range(60):
    count_one = int((a&1).sum())
    result += count_one*(n-count_one)*(2**i)
    a >>= 1
print(result%mod)
### BUGGY CODE ###

# -*- coding: utf-8 -*-
import math
S = input()
remainder = [0 for _ in range(2019)]
for i in range(len(S)):
  s = int(S[-1*i:])
  remainder[s % 2019] += 1
ans = 0
for i in range(2019):
  if i == 0:
      ans += remainder[i]
  else:
    if remainder[i] > 1:
      # 組み合わせ
      ans += (math.factorial(remainder[i]) // (math.factorial(remainder[i] - 2) * math.factorial(2)))
print(ans)

### FIXED CODE ###

# -*- coding: utf-8 -*-
import math
S = input()[::-1]
remainder = [0] * 2019

# 2つ選ぶ組み合わせにおいて余り0の場合は1つしか選ばなくて良いので
# 2つ目に0を選んだ場合として便宜的に設定
remainder[0] = 1

num = 0
d = 1
for s in S:
  num += int(s) * d
  remainder[num % 2019] += 1
  d *= 10
  
  # numが大きくなりすぎると計算量が膨大になってしまうのを防ぐ
  # num%2019を計算するので、先に%2019で計算しても結果は変わらない
  d %= 2019
ans = 0
for i in range(2019):
  ans += remainder[i] * (remainder[i]-1) // 2
print(ans)
### BUGGY CODE ###

n=int(input())
a=list(map(int,input().split()))
for i in range(n-1):
    j=i
    k=0
    while j<n-1:
        if i+1==a[j]:
            k=k+1
        j=j+1

    print(k)
print(0)


### FIXED CODE ###

n=int(input())
a=list(map(int,input().split()))
 
jyoshi=[0]*n
for i in range(n-1):
  jyo=a[i]
  jyoshi[jyo-1]=jyoshi[jyo-1]+1
  
for k in jyoshi:
  print(k)
### BUGGY CODE ###

def g(i,j):
    if i+j<10:
        return 1,i+j
    else:
        a = i+j
        b = a%10+a//10
        return 2,b
def f(c,d):
    if d==1:
        return 0,c
    if d==2:
        return g(c,c)
    if d%2==0:
        return f(c,d//2)[0]*2+g(f(c,d//2)[1],f(c,d//2)[1])[0],g(f(c,d//2)[1],f(c,d//2)[1])[1]
    else:
        return f(c,d-1)[0]+g(c,f(c,d-1)[1])[0],g(c,f(c,d-1)[1])[1]
M = int(input())
A = [list(map(int,input().split())) for _ in range(M)]
cnt = 0
B = []
for i in range(M):
    c,d = A[i][0],A[i][1]
    a,b = f(c,d)
    cnt += a
    B.append(b)
b = B[0]
for i in range(1,M):
    a,b = g(b,B[i])
    cnt += a
print(cnt)   


### FIXED CODE ###

def g(i,j):
    if i+j<10:
        return 1,i+j
    else:
        a = i+j
        b = a%10+a//10
        return 2,b
def f(c,d):
    if d==1:
        return 0,c
    if d==2:
        return g(c,c)
    if d%2==0:
        a,b = f(c,d//2)
        x,y = g(b,b)
        return 2*a+x,y
    else:
        a,b = f(c,(d-1)//2)
        x1,y1 = g(b,b)
        x2,y2 = g(c,y1)
        return 2*a+x1+x2,y2
M = int(input())
A = [list(map(int,input().split())) for _ in range(M)]
cnt = 0
B = []
for i in range(M):
    c,d = A[i][0],A[i][1]
    a,b = f(c,d)
    cnt += a
    B.append(b)
b = B[0]
for i in range(1,M):
    a,b = g(b,B[i])
    cnt += a
print(cnt)
### 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 f(x):
    cnt = 0
    for i,j in enumerate(a):
        if j == 0:
            if x < 0:
                continue
            cnt += n-i-1
        elif j > 0:
            r =  br(a,x//j)
            if r <= i:
                continue
            cnt += r - i - 1
        else:
            l = bl(a,-(x//-j))
            if l <= i:
                l = i+1
            cnt += n - l
        if cnt >= k:
            return True
    return False

n,k = LI()
a = LI()
a.sort()

ok = 10**18
ng = -10**18
while ok-ng > 1:
    mid = (ok+ng)//2
    if f(mid):
        ok = mid
    else:
        ng = mid
print(ok)



    

### FIXED 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 f(x):
    cnt = 0
    if x < 0:
        j = p-1
        for i in range(m)[::-1]:
            while j >= 0:
                if minus[i]*plus[j] <= x:
                    j -= 1
                else:
                    break
            cnt += p - j - 1
    else:
        j = p-1
        for i in range(p):
            while j >= 0:
                if plus[i]*plus[j] > x:
                    j -= 1
                else:
                    break
            cnt += max(0,j - i)
        j = 0
        for i in range(m)[::-1]:
            while j < m:
                if minus[i]*minus[j] > x:
                    j += 1
                else:
                    break
            cnt += max(0,i - j)
        cnt += (m+p)*zero + zero*(zero-1)//2 + m*p
    return cnt >= k
        
n,k = LI()
a = LI()
a.sort()
minus = [x for x in a if x < 0]
plus = [x for x in a if x > 0]
m = len(minus)
p = len(plus)
zero = bl(a,1) - br(a,-1)
ok = 10**18
ng = -10**18-1
while ok-ng > 1:
    mid = (ok+ng)//2
    if f(mid):
        ok = mid
    else:
        ng = mid
print(ok)
### BUGGY CODE ###

import sys
import collections
import math
input = lambda: sys.stdin.readline().rstrip()

def main():
    n = int(input())
    a = list(map(int, input().split()))
    cnts = []
    for i in range(n):
        if i == 0:
            tmp = dict(collections.Counter(a[1:])) 
        elif i == n-1:
            tmp = dict(collections.Counter(a[:n-1])) 
        else:
            tmp = dict(collections.Counter(a[:i] + a[i+1:]))
        cnts.append(tmp)
    for cnt in cnts:
        ans = 0
        for x, y in cnt.items():
            if y >= 2:
                ans += math.factorial(y)//(2*math.factorial(y-2))
        print(ans)
        
if __name__ == '__main__':
    main()

### FIXED CODE ###

import sys
import collections
input = lambda: sys.stdin.readline().rstrip()

def main():
    n = int(input())
    a = list(map(int, input().split()))
    cnt = collections.Counter(a)
    all_comb = 0
    for i in cnt.keys():
        all_comb += cnt[i] * (cnt[i]-1) // 2
    for i in range(n):
        comb = all_comb
        comb -= cnt[a[i]] * (cnt[a[i]]-1) // 2
        comb += (cnt[a[i]]-1) * (cnt[a[i]]-2) // 2
        print(comb)
        
if __name__ == '__main__':
    main()
### BUGGY CODE ###

s = input()
s = s[::-1]
n = len(s)
mod = 10**9 + 7

dp = [0 for j in range(13)]
if s[0] == '?':
    for i in range(10):
        dp[i] = 1
else:
    num = int(s[0])
    dp[num] = 1

for i in range(1, n):
    dp_new = [0 for j in range(13)]
    if s[i] == '?':
        for m in range(10):
            num = (m * 10**i) % 13
            for j in range(13):
                dp_new[(j+num)%13] += dp[j]
                dp_new[(j+num)%13] %= mod
    else:
        num = (int(s[i]) * 10**i) % 13
        for j in range(13):
            dp_new[(j+num)%13] += dp[j]
            dp_new[(j+num)%13] %= mod
    dp = dp_new

print(dp[5])

### FIXED CODE ###

s = input()
s = s[::-1]
n = len(s)
mod = 10**9 + 7

dp = [[0 for j in range(13)] for i in range(n)]
if s[0] == '?':
    for i in range(10):
        dp[0][i] = 1
else:
    num = int(s[0])
    dp[0][num] = 1

mul = 1
for i in range(1, n):
    mul = (mul*10) % 13
    if s[i] == '?':
        for m in range(10):
            num = (m * mul) % 13
            for j in range(13):
                dp[i][(j+num)%13] = (dp[i][(j+num)%13] + dp[i-1][j]) % mod
    else:
        num = (int(s[i]) * mul) % 13
        for j in range(13):
            dp[i][(j+num)%13] = (dp[i][(j+num)%13] + dp[i-1][j]) % mod

print(dp[n-1][5])
### BUGGY CODE ###

#!/usr/bin/env python3
import sys
from itertools import accumulate
def solve(k: int, q: int, d: "List[int]", n: "List[int]", x: "List[int]", m: "List[int]"):
    for query in range(q):
        N,X,M = n[query],x[query],m[query]
        D = [d[i]%M for i in range(k)]
        accum = list(accumulate(D))
        COUNTD = D.count(0)
        SUMD = accum[-1]
        last = 0
        if (N-1)%k == 0:
            last = X+((N-1)//k)*SUMD
            equal_count = COUNTD*((N-1)//k)
        else:
            last = X + SUMD*((N-1)//k) + accum[(N-1)%k-1]
            equal_count = COUNTD*((N-1)//k)+D[:(N-1)%k].count(0)
        
        shounari_count = last//M - X//M
        dainari_count = N-shounari_count-equal_count-1
        print(dainari_count)
    return

def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    k = int(next(tokens))  # type: int
    q = int(next(tokens))  # type: int
    d = [int(next(tokens)) for _ in range(k - 1 - 0 + 1)]  # type: "List[int]"
    n = [int()] * (q)  # type: "List[int]"
    x = [int()] * (q)  # type: "List[int]"
    m = [int()] * (q)  # type: "List[int]"
    for i in range(q):
        n[i] = int(next(tokens))
        x[i] = int(next(tokens))
        m[i] = int(next(tokens))
    solve(k, q, d, n, x, m)

if __name__ == '__main__':
    main()


### FIXED CODE ###

#!/usr/bin/env python3
import sys
from itertools import accumulate
def solve(k: int, q: int, d: "List[int]", n: "List[int]", x: "List[int]", m: "List[int]"):
    for query in range(q):
        N,X,M = n[query],x[query],m[query]
        count = [0]*k
        D = [0]*k
        c = 0
        for i in range(k):
            D[i] = d[i]%M
            if D[i] == 0:
                c += 1
            count[i] = c
        accum = list(accumulate(D))
        SUMD = accum[-1]
        COUNTD = count[-1]

        if (N-1)%k == 0:
            last = X+((N-1)//k)*SUMD
            equal_count = COUNTD*((N-1)//k)
        else:
            last = X + SUMD*((N-1)//k) + accum[(N-1)%k-1]
            equal_count = COUNTD*((N-1)//k)+count[(N-1)%k-1]
        
        shounari_count = last//M - X//M
        dainari_count = N-shounari_count-equal_count-1
        print(dainari_count)
    return

def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    k = int(next(tokens))  # type: int
    q = int(next(tokens))  # type: int
    d = [int(next(tokens)) for _ in range(k - 1 - 0 + 1)]  # type: "List[int]"
    n = [int()] * (q)  # type: "List[int]"
    x = [int()] * (q)  # type: "List[int]"
    m = [int()] * (q)  # type: "List[int]"
    for i in range(q):
        n[i] = int(next(tokens))
        x[i] = int(next(tokens))
        m[i] = int(next(tokens))
    solve(k, q, d, n, x, m)

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

import math
import collections
n, m = map(int, input().split())

factor = []
tmp = int(m ** (1/2)) + 1
for i in range(2, tmp):
    while m % i == 0:
        m //= i
        factor.append(i)
if m > 1:
    factor.append(m)
num = list(collections.Counter(factor).most_common())

ans = 1
for x in num:
    ans *= (math.factorial(x[1] + n - 1) // (math.factorial(n - 1) * math.factorial(x[1])) % 1000000007)
    ans %= 1000000007
print(ans)

### FIXED CODE ###

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

factor = []
tmp = int(m ** (1/2)) + 1
for i in range(2, tmp):
    while m % i == 0:
        m //= i
        factor.append(i)
if m > 1:
    factor.append(m)
num = list(collections.Counter(factor).most_common())

def comb(n, r):
    tmp = 1
    for i in range(r):
        tmp *= n - i
    for i in range(r):
        tmp //= r - i
    return tmp

ans = 1
for x in num:
    ans *= (comb(x[1] + n - 1, x[1]) % 1000000007)
    ans %= 1000000007
print(ans)
### BUGGY CODE ###

#https://atcoder.jp/contests/dp/tasks/dp_b
import sys
inf = sys.maxsize

n, k = map(int,input().split())
h = [int(i) for i in input().split()]

dp = [0 for _ in range(n)]
dp[0] = 0

for i in range(1, n): #段数
    dp[i] = min([dp[max(0, i - j)] + abs(h[i] - h[max(0, i - j)]) for j in range(1, k + 1)])
    '''
    tmp = inf
    for j in range(1, k + 1): #一度に登る段数
        if i - j >= 0:
            tmp = min(tmp, dp[i - j] + abs(h[i] - h[i - j]))
    dp[i] = tmp
    '''

print(dp[n - 1])

### FIXED CODE ###

#https://atcoder.jp/contests/dp/tasks/dp_b
import sys
inf = sys.maxsize

n, k = map(int,input().split())
h = [int(i) for i in input().split()]

dp = [0 for _ in range(n)]
dp[0] = 0

for i in range(1, n): #段数
    tmp = min(k, i)
    dp[i] = min([dp[i - j] + abs(h[i] - h[i - j]) for j in range(1, tmp + 1)])
    '''
    tmp = inf
    for j in range(1, k + 1): #一度に登る段数
        if i - j >= 0:
            tmp = min(tmp, dp[i - j] + abs(h[i] - h[i - j]))
    dp[i] = tmp
    '''

print(dp[n - 1])
### BUGGY CODE ###

from collections import deque
import sys
H, W = map(int, input().split())
ch, cw = map(int, input().split())
dh, dw = map(int, input().split())
ch, cw, dh, dw = ch-1, cw-1, dh-1, dw-1
S = [input() for _ in range(H)]
d = [[0]*W for _ in range(H)]
d[ch][cw] = -1

que = deque([[cw, ch]])
count = 0
while que:
    while que:
        x, y = que.popleft()
        for i in range(-2, 3):
            for j in range(-2, 3):
                nnx, nny = x+i, y+j
                if 0<=nnx<W and 0<=nny<H and d[nny][nnx]==0 and S[nny][nnx]!='#':
                    d[nny][nnx] = 1
        
        for dx, dy in [1, 0], [0, 1], [-1, 0], [0, -1]:
            nx, ny = x+dx, y+dy
            if 0<=nx<W and 0<=ny<H and S[ny][nx]!='#' and d[ny][nx]!=-1:
                if nx == dw and ny == dh:
                    print(count)
                    sys.exit()
                
                d[ny][nx] = -1
                for i, j in [[-2, -2],
 [-2, -1],
 [-2, 0],
 [-2, 1],
 [-2, 2],
 [-1, -2],
 [-1, -1],
 [-1, 1],
 [-1, 2],
 [0, -2],
 [0, 2],
 [1, -2],
 [1, -1],
 [1, 1],
 [1, 2],
 [2, -2],
 [2, -1],
 [2, 0],
 [2, 1],
 [2, 2]]:
                        nnx, nny = nx+i, ny+j
                        if 0<=nnx<W and 0<=nny<H and d[nny][nnx]==0 and S[nny][nnx]!='#':
                            d[nny][nnx] = 1
                que.append([nx, ny])
                
    for i in range(W):
        for j in range(H):
            if d[j][i] == 1:
                d[j][i] == -1
                if i==dw and j==dh:
                    print(count+1)
                    sys.exit()
                que.append([i, j])
                
    count += 1
    
print(-1)

### FIXED CODE ###

from collections import deque
H, W = map(int, input().split())
ch, cw = map(int, input().split())
dh, dw = map(int, input().split())
ch, cw, dh, dw = ch-1, cw-1, dh-1, dw-1
s = [input() for _ in range(H)]

d = [[-1]*W for _ in range(H)]

que = deque([[cw, ch, 0]])
while que:
    x, y, cost = que.popleft()
    if d[y][x]==-1 or d[y][x]>cost:
        d[y][x] = cost
        for dx in range(-2, 3):
            for dy in range(-2, 3):
                nx, ny = x+dx, y+dy
                if 0<=nx<W and 0<=ny<H and s[ny][nx]!='#':
                    if abs(dx)+abs(dy) == 1:
                        que.appendleft([nx, ny, cost])
                    else:
                        que.append([nx, ny, cost+1])  
print(d[dh][dw])
### BUGGY CODE ###

# E - This Message Will Self-Destruct in 5s
from bisect import *
N = int(input())
A = list(map(int,input().split()))
l = []
ans = 0
for j in range(N):
    tmp = j-A[j]
    ans += bisect_right(l,tmp)-bisect_left(l,tmp)
    insort(l,A[j]+j)
print(ans)

### FIXED CODE ###

# E - This Message Will Self-Destruct in 5s
from bisect import *
N = int(input())
A = list(map(int,input().split()))
l = []
ans = 0
for j in range(N):
    tmp = j-A[j]
    ans += bisect_right(l,tmp)-bisect_left(l,tmp)
    insort(l,A[j]+j)
print(ans)
### BUGGY CODE ###

#AGC003B

n=int(raw_input())
s=[]
for i in xrange(1,n+1):
 x=int(raw_input())
 for j in xrange(x):
  s.append(i)
cnt=0
i=0
while i<len(s)-1:
 if s[i+1]-s[i]==0 or s[i+1]-s[i]==1:
  cnt+=1
  i+=2
 else:
  i+=1
print cnt


### FIXED CODE ###

#AGC003B

n=int(raw_input())
s=[int(raw_input()) for i in xrange(n)]
cnt=0
temp=0
for d in s:
 cnt+=(d+temp)/2
 if d==0:
  temp=0
 else:
  temp=(d+temp)%2
print cnt
### BUGGY CODE ###

N = int(input())

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

for i in range(N):
  numbers_minus1 = numbers_full
  tmp = numbers_minus1[i]
  numbers_minus1[i] = 0
  print(str(max(numbers_minus1)))
  numbers_minus1[i] = tmp

### FIXED CODE ###

N = int(input())
number_list = [int(input()) for _ in range(N)]

sorted_num = sorted(number_list)
number_max = sorted_num[-1]
number_second_max = sorted_num[-2]

if number_max == number_second_max:
  output_always_max = True
else:
  output_always_max = False

for number in number_list:
  if output_always_max:
    print(str(number_max))
  else:
    if number == number_max:
      print(str(number_second_max))
    else:
      print(str(number_max))