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

from sys import stdin
import math
import itertools


def makeIntMatrix(lines):
    intMatrix = []
    for a in makeStringMatrix(lines):
        intMatrix.append([int(b) for b in a])
    return intMatrix
 
 
def makeStringMatrix(lines):
    stringMatrix = [line.split() for line in lines]
    return stringMatrix
 
 
def makeInt(line):
    return int(line.rstrip())
 
 
def makeMultiInteger(line):
    return [int(x) for x in line.rstrip().split()]


def solve(input_string):
    r, g, b, n = makeMultiInteger(input_string[0])
    c = 0
    nr = int(n/r)+1
    ng = int(n/g)+1
    nb = int(n/b)+1
    #print(r, g, b, n, nr, ng, nb)
    for i in range(nr):
        _sum = i*r
        if _sum > n:
            break
        for j in range(ng):
            _sum = j*g+i*r
            if _sum > n:
                break
            for k in range(nb):
                _sum = i*r + j*g + k*b
                #print(_sum)
                if _sum == n:
                    c += 1
                if _sum > n:
                    break
    return c


def main():
    input_lines = stdin.readlines()
    answer = solve(input_lines)
    print(answer)


if __name__ == '__main__':
    main()


### FIXED CODE ###

from sys import stdin
import math
import itertools


def makeIntMatrix(lines):
    intMatrix = []
    for a in makeStringMatrix(lines):
        intMatrix.append([int(b) for b in a])
    return intMatrix
 
 
def makeStringMatrix(lines):
    stringMatrix = [line.split() for line in lines]
    return stringMatrix
 
 
def makeInt(line):
    return int(line.rstrip())
 
 
def makeMultiInteger(line):
    return [int(x) for x in line.rstrip().split()]


def solve(input_string):
    r, g, b, n = makeMultiInteger(input_string[0])
    c = 0
    nr = int(n/r)+1
    ng = int(n/g)+1
    nb = int(n/b)+1
    #print(r, g, b, n, nr, ng, nb)
    # 二分探索？
    """
    for i in range(nr):
        _sum = i*r
        if _sum == n:
            c += 1
            break
        for j in range(ng):
            _sum = j*g+i*r
            if _sum == n:
                c += 1
                break
            for k in range(nb):
                _sum = i*r + j*g + k*b
                #print(_sum)
                if _sum == n:
                    c += 1
                    break
    """
    for i in range(nr):
        _sum = i*r
        if _sum > n:
            break
        for j in range(ng):
            _sum = j*g+i*r
            if _sum > n:
                break
            rg_sum = j*g+i*r
            if (n - rg_sum) % b == 0:
                c += 1
            """
            for k in range(nb):
                _sum = i*r + j*g + k*b
                #print(_sum)
                if _sum == n:
                    c += 1
                    break
            """
    return c


def main():
    input_lines = stdin.readlines()
    answer = solve(input_lines)
    print(answer)


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

n = int(input())
a = list(map(int, input().split()))
mod = 10**9+7
max_len = len(format(max(a), "b"))
b = [0 for _ in range(max_len)]

for i in range(n):
    count = 0
    while a[i] > 0:
        b[count] += a[i]%2
        a[i] //= 2
        count += 1

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

### 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 ###

S=input()
length=len(S)
S=int(S)
count=[0 for i in range(2019)]

base=1
for i in range(length+1):
    mod=(S%base)%2019
    count[mod]+=1
    base*=10


retval=0
for key in range(2019):
    retval+=count[key]*(count[key]-1)//2

print(retval)


### FIXED CODE ###

from functools import lru_cache



S=input()
count=[0 for i in range(2019)]
length=len(S)
#S=int(S)
S=S+'0'
S=S[::-1]
_S=0

base=1
for i,s in enumerate(S):
    _S=base*int(s)+_S
    count[_S%2019]+=1
    base*=10
    base=base%2019
    _S=_S%2019



retval=0
for key in range(2019):
    retval+=count[key]*(count[key]-1)//2


print(retval)
### BUGGY CODE ###

n, k = map(int, input().split())
p = list(map(int, input().split()))
ans = 0
for i in range(n-k+1):
    a = 0
    for j in range(i, i+k):
        a += (p[j]*(1+p[j]))/2/p[j]
    ans = max(ans, a)
print(ans)

### FIXED CODE ###

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

ans = 0
kitai = []
for i in range(n):
    kitai.append((1+p[i])/2)
wa = []
a = 0
for i in range(n):
    a += kitai[i]
    wa.append(a)
if n == k:
    print(wa[n-1])
    exit()
ans = 0
for i in range(n-k):
    ans = max(ans, wa[i+k] - wa[i])

print(ans)
### 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()))

n = I()
edges = [[] for _ in range(n)]
ab = [[i] + LI() for i in range(n-1)]
col = [defaultdict(int) for _ in range(n)]
cnt = [0] * n
for i, a, b in ab:
    edges[a-1].append((i, b-1))
    edges[b-1].append((i, a-1))
    cnt[a-1] += 1
    cnt[b-1] += 1

k = max(cnt)
print(k)
used_edge = [False] * n
que = deque([(0, -1)])
edges_color = [None] * (n-1)
while que:
    v, p = que.popleft()
    for i, u in edges[v]:
        if used_edge[i]:
            continue
        if u == p:
            continue
        cnt = 1
        while col[u][cnt] or col[v][cnt]:
            cnt += 1
        col[u][cnt] = 1
        col[v][cnt] = 1
        edges_color[i] = cnt
        used_edge[i] = False
        que.append((u, v))
for c in edges_color:
    print(c)

### FIXED CODE ###

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

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(1000000)
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 = I()
graph = [[] for _ in range(n)]
edge = []
for i in range(n-1):
    a,b = LI()
    a -= 1
    b -= 1
    graph[a].append((b,i))
    graph[b].append((a,i))
    edge.append((a,b,i))

m = 0
for i in range(n):
    m = max(m,len(graph[i]))

print(m)
ans = [None]*(n-1)
que = deque()
que.append((0,0))
while que:
    v,color = que.popleft()
    cnt = 1
    for u,i in graph[v]:
        if ans[i] == None:
            if cnt != color:
                ans[i] = cnt
                que.append((u,cnt))
                cnt += 1
            else:
                ans[i] = cnt+1
                que.append((u,cnt+1))
                cnt += 2
print(*ans)
### BUGGY CODE ###

n = int(input())
s = [i for i in input()]

ans = 10 ** 6

for i in range(n-1):
    left = s[:i].count("W")
    right = s[i+1:].count("E")

    ans = min(ans, left+right)

print(ans)

### FIXED CODE ###

n = int(input())
s = input()

l = [0]
r = [0]

for i in s:
    if i == "W":
        l.append(l[-1] + 1)
    else:
        l.append(l[-1])

for i in s[::-1]:
    if i == "E":
        r.append(r[-1] + 1)
    else:
        r.append(r[-1])

l = l[1:]
r = r[1:][::-1]

ans = 10 ** 9

for i in zip(l, r):
    ans = min(sum(i), ans)

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

N = int(input())
l = []
for i in range(N):
    x = str(input())
    if x not in l:
        l.append(x)
print(len(l))

### FIXED CODE ###

import collections
N = int(input())
l = [str(input()) for i in range(N)]
c = collections.Counter(l)
print(len(c.keys()))
### BUGGY CODE ###

n=int(input())
l=list(map(int,input().split()))
l.sort()
chols={}
ansls={}
ans=0
for i in range(n):
  s=l[i]
  st=s//2
  flag=True
  for j in range(ans):
    if s%ansls[j]==0:
      if s==ansls[j]:
        chols[s]=1
      flag=False
      break
    if ansls[j]>st:
      if ansls[ans-1]==s:
        flag=False
        chols[s]=1
      break
  if flag:
    ansls[ans]=s
    ans+=1
de=chols.keys()

print(ans-len(de))


### FIXED CODE ###

n=int(input())
l=list(map(int,input().split()))
l.sort()
p=[1]*(l[-1]+1)
ans=0
for i in range(n):
  a=l[i]
  if p[a]==1:
    b=a
    while a<=l[-1]:
      p[a]=0
      a+=b
    if i<n-1:
      if l[i]==l[i+1]:
        pass
      else:
        ans+=1
    else:
      ans+=1
print(ans)
### BUGGY CODE ###

import itertools
N, K = list(map(int, input().split()))
poss = []
count = 0
poss = [n for n in range(1, N+1) if (2*n)%K==0]

poss2 = list(itertools.product(poss, repeat=3))

for comb in poss2:
    if (comb[0]+comb[1])%K==0 and (comb[1]+comb[2])%K==0: #and (comb[2]+comb[0])%K==0:
        count += 1

print(count)


### FIXED CODE ###

N, K = map(int, input().split())
num = {i%K:N//K for i in range(1, K+1)}
mod = N % K
for i in range(1, mod+1):
    num[i] += 1

ans = 0
for i in range(K):
    if (2*i) % K == 0:
        cnt = num[i]
        cnt *= num[(K-i)%K] * num[(K-i)%K]
        ans += cnt
print(ans)
### BUGGY CODE ###

n = int(input())
s = []
for i in range(n):
    s.append(sorted(input()))
res = 0
for index, j in enumerate(s):
    res += s[index + 1:].count(j)

print(res)


### FIXED CODE ###

n = int(input())
dic = {}
res = 0
for i in range(n):
    s = ''.join(sorted(input()))
    if s in dic.keys():
        res += dic[s]
        dic[s] += 1
    else:
        dic[s] = 1
print(res)
### BUGGY CODE ###

N = int(input())

X = input().split()


for i in range(N):
    x2 = [int(x) for x in X]
    del x2[i]
    x2.sort()
    
    print("%d"%x2[int((N/2)-1)])

### FIXED CODE ###

N = int(input())

X = input().split()
x1 = [int(x) for x in X]
x2 = [int(x) for x in X]

x2.sort()
ml = x2[int((N/2)-1)]
mr = x2[int(N/2)]

for i in range(N):
    if x1[i] <=  ml:
        print("%d"%mr)
    else:
        print("%d"%ml)
### BUGGY CODE ###

H,N=map(int,input().split())
A=[0]*N
B=[0]*N
for i in range(N):
  A[i],B[i]=map(int,input().split())
dp = [99999999999]*(H+1)
dp[0]=0
for h in range(H):
  for i in range(N):
    dp[min(H,h+A[i])]=min(dp[h] + B[i], dp[min(H,h+A[i])])
print(dp[-1])

### FIXED CODE ###

H,N=map(int,input().split())
A=[0]*N
B=[0]*N
for i in range(N):
  A[i],B[i]=map(int,input().split())
dp = [99999999999]*(H+1)
dp[0]=0
for h in range(H):
  for i in range(N):
    dp[min(H,h+A[i])]=min(dp[h] + B[i], dp[min(H,h+A[i])])
print(dp[-1])
### BUGGY CODE ###

A=list(map(int,input().split()))
K=A[0]
S=A[1]
count=0
for a in range(K+1):
    for b in range(K+1):
        for c in range(K+1):
            if a+b+c==S:
                count+=1
            else:
                continue
print(count)

### FIXED CODE ###

A=list(map(int,input().split()))
K=A[0]
S=A[1]
count=0
for a in range(K+1):
    for b in range(K+1):
        c=S-a-b
        if 0<=c<=K:
            count+=1
        else:
            continue
print(count)
### BUGGY CODE ###

N, M = map(int, input().split())
A = [int(_) for _ in input().split()]

while M != 0:
  ind = A.index(max(A))
  A[ind] = A[ind] // 2
  M -= 1
  
print(sum(A))

### FIXED CODE ###

import heapq
N, M = map(int, input().split())
A = [int(_)*(-1) for _ in input().split()]
heapq.heapify(A)

while M != 0:
  max_ = -heapq.heappop(A) // 2
  heapq.heappush(A, -max_)
  M -= 1
  
print(-sum(A))
### BUGGY CODE ###

N,K = map(int,input().split())
A = list(map(int,input().split()))
already_town =[1]
now_town=1
check=False
my_append = already_town.append
for i in range(K):
    check_town=A[now_town-1]
    if(check_town in already_town):
        cicle_start_value=check_town
        check=True
        break
    my_append(check_town)
    now_town = check_town

if(check==False):
    print(now_town)
else:
    cicle_start=already_town.index(cicle_start_value)
    roop_town=already_town[cicle_start:]
    print(roop_town[(K-cicle_start)%((i+1)-cicle_start)])


### FIXED CODE ###

N,K = map(int,input().split())
A = list(map(int,input().split()))
already_town_check =[False]*(N+1)
already_town_check[1] = True
already_town = [1]
now_town=1
check=False
my_append = already_town.append
for i in range(K):
    check_town=A[now_town-1]
    if(already_town_check[check_town]):
        cicle_start_value=check_town
        check=True
        break
    already_town_check[check_town]=True
    my_append(check_town)
    now_town = check_town

if(check==False):
    print(now_town)
else:
    cicle_start=already_town.index(cicle_start_value)
    roop_town=already_town[cicle_start:]
    print(roop_town[(K-cicle_start)%((i+1)-cicle_start)])
### BUGGY CODE ###

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

d = {}

for i in range(N):
    d[i+1] = []

for i in range(M):
    a, b = map(int,input().split())
    d[a].append(b)
    d[b].append(a)
que = [1]
checked = set()
ans = {}
while que:
    now = que.pop(0)
    for h in d[now]:
        if not h in ans and not h == 1:
            ans[h] = now
            que.append(h)
    
if len(ans) == N-1:
    print('Yes')
    for i in range(N-1):
        print(ans[i+2]) 
else:
    print('No')



### FIXED CODE ###

from collections import deque

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

d = {}

for i in range(N):
    d[i+1] = set()

for i in range(M):
    a, b = map(int,input().split())
    d[a].add(b)
    d[b].add(a)

que = deque([1])
checked = set()
ans = {1:-1}

while que:
    now = que.popleft()
    for h in d[now]:
        if not h in ans:
            ans[h] = now
            que.append(h)
    if len(ans) == N:
        break
    
if len(ans) == N:
    print('Yes')
    for i in range(N-1):
        print(ans[i+2]) 
else:
    print('No')
### BUGGY CODE ###

h, w = map(int, input().split())

grid = [input() for _ in range(h)]

field = [[0] * w for _ in range(h)]

for i, row in enumerate(grid):
    row = row + "#"
    cnt = row.count("#")

    idx = -1
    for j in range(cnt + 1):
        idx_next = row.find("#", idx + 1)
        for k in range(idx + 1, idx_next):
            field[i][k] = idx_next - idx - 1
        idx = idx_next

m = 0
for i, row in enumerate(zip(*grid)):
    row = "".join(row) + "#"
    cnt = row.count("#")

    idx = -1
    for j in range(cnt + 1):
        idx_next = row.find("#", idx + 1)
        for k in range(idx + 1, idx_next):
            field[k][i] += idx_next - idx - 1
            if field[k][i] > m:
                m = field[k][i]
        idx = idx_next

print(m - 1)

### FIXED CODE ###

def main():
    h, w = map(int, input().split())
    grid = [input() for _ in range(h)]
    field = [[0] * w for _ in range(h)]

    for i, row in enumerate(grid):
        row = row + "#"
        cnt = row.count("#")
        idx = -1
        for j in range(cnt + 1):
            idx_next = row.find("#", idx + 1)
            for k in range(idx + 1, idx_next):
                field[i][k] = idx_next - idx - 1
            idx = idx_next

    m = 0
    for i, row in enumerate(zip(*grid)):
        row = "".join(row) + "#"
        cnt = row.count("#")
        idx = -1
        for j in range(cnt + 1):
            idx_next = row.find("#", idx + 1)
            for k in range(idx + 1, idx_next):
                field[k][i] += idx_next - idx - 1
                if field[k][i] > m:
                    m = field[k][i]
            idx = idx_next
    print(m - 1)


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

import math

k = int(input())
ans = 0
for i in range(1, k+1):
  for j in range(1, k+1):
    for k in range(1, k+1):
      ans += math.gcd(math.gcd(i, j), k)

print(ans)


### FIXED CODE ###

import math

k = int(input())
ans = 0
for i in range(1, k+1):
  for j in range(1, k+1):
    for k in range(1, k+1):
      ans += math.gcd(math.gcd(i, j), k)

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

from fractions import gcd
N = int(input())
A = list(map(int, input().split()))
B = [A[0]]

for i in range(1, N):
    B.append(gcd(B[i - 1], A[i]))

ans = 0
for i in range(N):
    if i != 0:
        ans0 = B[i - 1]
    else:
        ans0 = A[1]
    for j in range(i + 1, N):
        ans0 = gcd(ans0, A[j])
    ans = max(ans, ans0)
print(ans)

### FIXED CODE ###

from fractions import gcd
N = int(input())
A = list(map(int, input().split()))
B, C = [A[0]], [A[N - 1]]

for i in range(1, N):
    B.append(gcd(B[i - 1], A[i]))

AA = list(reversed(A))
for i in range(1, N):
    C.append(gcd(C[i - 1], AA[i]))
C.reverse()
ans = 0
for i in range(1, N - 1):
    ans = max(ans, gcd(B[i - 1], C[i + 1]))
ans = max(ans, B[N - 2], C[1])
print(ans)
### BUGGY CODE ###

import sys
n = int(input())
a = list(map(int,input().split()))
'''
for num in a:
  i = a.index(num)
  if(num in a[i+1:]):
    print("NO")
    sys.exit()
print("YES")
'''

i=0
while(i<n):
  if(a[i] in a[i+1:]):
    print("NO")
    sys.exit()
  i += 1
print("YES")

### FIXED CODE ###

import sys
n = int(input())
a = list(map(int,input().split()))
'''
for num in a:
  i = a.index(num)
  if(num in a[i+1:]):
    print("NO")
    sys.exit()
print("YES")
'''

i=0
a.sort()
while(i<n-1):
  if(a[i] == a[i+1]):
    print("NO")
    sys.exit()
  i += 1
print("YES")
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10000000)
input=sys.stdin.readline
mod = 10 ** 9 + 7
 
def cmb(n, r):

    r = min(r, n - r)
    x = 1
    y = 1
    for i in range(r):
        x = x * (n - i) % mod
        y = y * (i + 1) % mod
    y = pow(y, mod-2, mod)
    return x * y % mod
 
n,k = map(int,input().split())
 
ans=0
k=min(k,n-1)
for i in range(k+1):
    ans += cmb(n,i) * cmb(n-1,i) %mod
 
print(ans%mod)
 


### FIXED CODE ###

import sys
sys.setrecursionlimit(10000000)
input=sys.stdin.readline
mod = 10 ** 9 + 7

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

fac = [1]*(n+1)
inv = [1]*(n+1)
for i in range(1,n+1):
  fac[i] = (fac[i-1]*i) % mod  
inv[n] = pow(fac[n], mod-2, mod)
for i in range(n, 0, -1):
  inv[i-1] = (inv[i]*i) % mod
    
def cmb(n, r):
     
  if r < 1:
        return 1
  return (((fac[n] * inv[r])%mod) * inv[n-r]) % mod
 


ans=0
k=min(k,n-1)
for i in range(k+1):
    ans += cmb(n,i) * cmb(n-1,i) %mod

print(ans%mod)
### BUGGY CODE ###

n, x, m = map(int, input().split())
l = [x]
loop = []
a = x

for i in range(n - 1):
    a = a**2%m
    if a not in l:
        l.append(a)
    else:
        if a not in loop:
            loop.append(a)
        else:
            break

if len(loop) > 0:
    rest = (n - len(l))%len(loop)
    times = (n - len(l))//len(loop)
    ans = sum(l) + sum(loop)*times
    for i in range(rest):
        ans += loop[i]
else:
    ans = sum(l)

print(ans)

### FIXED CODE ###

n, x, m = map(int, input().split())
l = [x]
a = x
loopsum = 0
loopnum = 0


for i in range(n - 1):
    a = a**2%m
    if a not in l:
        l.append(a)
    else:
        pos = l.index(a)
        loopnum = len(l[pos:])
        loopsum = sum(l[pos:])
        break

if loopnum > 0:
    rest = (n - len(l))%loopnum
    times = (n - len(l))//loopnum
    ans = sum(l) + loopsum*times
    for i in range(rest):
        ans += l[pos + i]
else:
    ans = sum(l)

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

N,K=map(int,input().split())
while True:
    num=abs(N-K)
    if num<N:
        N=num
    else:
        print(N)
        exit()


### FIXED CODE ###

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

N = int(input())
A = input().split()
A = [int(s) for s in A]
students = []
A_sort = sorted(A)
for a_sort in A_sort:
    for i, a in enumerate(A):
        if a_sort == a:
            print(i+1)
            break
    

### FIXED CODE ###

N = int(input())
A = list(map(int,input().split()))
L = [[] for i in range(N)]
for i in range(N):
    L[i] = [A[i], i+1]
L = sorted(L)
for i in range(N):
    print(L[i][1])
### BUGGY CODE ###

mod = int(1e9 + 7)
N = int(input())
A = list(map(int, input().split()))
S = 0
j = 0
while A != [0 for i in range(N)]:
  m = 0
  n = 0
  for i in range(N):
    if A[i] % 2 == 1:
      m += 1
    else:
      n += 1
    A[i] //= 2
  S += (m * n) * (2 ** j)
  j += 1
S %= mod
print(S)

### FIXED CODE ###

mod = int(1e9 + 7)
N = int(input())
A = [format(i, '060b') for i in map(int, input().split())]
S = 0
for k in range(60):
  s = [b[59-k] for b in A]
  v = s.count('0')*s.count('1')
  S += (v<<k)
S %= mod
print(S)
### BUGGY CODE ###

import sys
import math
import copy
import queue
input = sys.stdin.readline
n = int(input())
s = list(input().rstrip())
q = int(input())
for _ in range(q):
    t,i,c = input().split()

    if t == '1':
        s[int(i)-1] = c
    else:
        ss = set(s[int(i)-1:int(c)])
        print (len(ss))

### FIXED CODE ###

import sys,queue,math,copy,itertools,bisect,collections,heapq

def main():
    sys.setrecursionlimit(10**7)
    INF = 10**18
    MOD = 10**9 + 7
    LI = lambda : [int(x) for x in sys.stdin.readline().split()]
    NI = lambda : int(sys.stdin.readline())

    N = NI()

    R = 2**(N.bit_length())
    st = [0] * (R*2)

    def update(i,s):
        x = 2 ** (ord(s) - ord('a'))
        i += R-1
        st[i] = x
        while i > 0:
            i = (i-1) // 2
            st[i] = st[i*2+1] | st[i*2+2]

    def query(a,b,n,l,r):
        ret = 0
        if a <= l and r <= b: return st[n]
        if a < r and b > l:
            vl = query(a,b,n*2+1,l,(l+r)//2)
            vr = query(a,b,n*2+2,(l+r)//2,r)
            ret = vl | vr
        return ret

    for i,s in enumerate(sys.stdin.readline().rstrip()):
        update(i+1,s)
    Q = NI()
    for _ in range(Q):
        c,a,b = sys.stdin.readline().split()
        if c == '1':
            update(int(a),b)
        else:
            ret = query(int(a),int(b)+1,0,0,R)
            cnt = 0
            b = 1
            for i in range(26):
                cnt += (b & ret) > 0
                b <<= 1
            print(cnt)


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

n = int(input())
a = list(map(int, input().split()))
ans = 1
for x in a:
  ans *= x
if ans > pow(10, 18):
  print(-1)
else:
  print(ans)
  

### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))
ans = 1
ul = pow(10, 18)
if 0 in a:
  print(0)
  exit(0)
for x in a:
  ans *= x
  if ans > ul:
    print(-1)
    exit(0)
print(ans)
### BUGGY CODE ###

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

ans = 1
tmp = P
for i in range(2, P):
    while True:
        rest = tmp % (i ** N)
        newtmp = tmp // (i ** N)
        # print(tmp, rest, ans)
        if rest == 0:
            ans = ans * i
            tmp = newtmp
        else:
            break
    if newtmp == 0:
        break

print(ans)


### FIXED CODE ###

N, P = list(map(int, input().split()))
if N == 1:
    print(P)
    exit()
elif P == 1:
    print("1")
    exit()

ans = 1
tmp = P

for i in range(2, int(pow(P, 1 / N)) + 1):
    po = pow(i, N)
    while tmp % po == 0:
        tmp = tmp // po
        ans = ans * i
        # print(i, tmp, ans)

    if tmp < po:
        break

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

def main():
    N = int(input())
    S = tuple(map(int, input().split()))
    Q = int(input())
    T = tuple(map(int, input().split()))

    cnt = 0
    for i in T:
        if i in S:
            cnt += 1

    print(cnt)

main()

### FIXED CODE ###

def main():
    global N, S
    N = int(input())
    S = tuple(map(int, input().split()))
    Q = int(input())
    T = tuple(map(int, input().split()))

    cnt = 0
    for i in T:
        cnt += binsearch(i)
    print(cnt)

def binsearch(key):
    left = 0
    right = N
    while left < right:
        mid = (left + right) // 2
        if key == S[mid]:
            return 1
        if key > S[mid]:
            left = mid + 1
        else:
            right = mid
    return 0

main()
### BUGGY CODE ###

import copy

N = int(input())
A = [int(input()) for i in range(N)]

for i in range(N):
    B = copy.deepcopy(A)
    B[i] = 0
    ans = max(B)
    print(ans)


### FIXED CODE ###

N = int(input())
A = [int(input()) for i in range(N)]
B = [ [0] * 2 for i in range(N)]

for i in range(N):
    B[i][0] = A[i]
    B[i][1] = i

B.sort(reverse=True)
for i in range(N):
    if B[0][1] == i:
        print(B[1][0])
    else:
        print(B[0][0])