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

from itertools import product

n = int(input())
ab = [list(map(int, input().split())) for _ in range(n - 1)]
m = int(input())
uv = [list(map(int, input().split())) for _ in range(m)]

adj = [[] for _ in range(n)]
ids = [[-1] * n for _ in range(n)]
for i, (a, b) in enumerate(ab):
    a -= 1
    b -= 1
    adj[a].append(b)
    adj[b].append(a)
    ids[a][b] = i
    ids[b][a] = i


def dfs(s, g):
    d = [-1] * n
    d[s] = 0
    p = [-1] * n
    stack = [s]

    while stack:
        u = stack.pop()
        for v in adj[u]:
            if d[v] == -1:
                d[v] = d[u] + 1
                p[v] = u
                stack.append(v)

    v = g
    ret = 0
    while v != s:
        i = ids[v][p[v]]
        ret += 1 << i
        v = p[v]

    return ret


path = [dfs(u - 1, v - 1) for u, v in uv]
ans = 0
for tpl in product([1, 0], repeat=m):
    coef = 1
    cnt = 0
    for bl, e in zip(tpl, path):
        if bl:
            cnt |= e
            coef *= -1
    ans += pow(2, n - 1 - bin(cnt).count("1")) * coef

print(ans)


### FIXED CODE ###

from itertools import combinations

n = int(input())
ab = [list(map(int, input().split())) for _ in range(n - 1)]
m = int(input())
uv = [list(map(int, input().split())) for _ in range(m)]

adj = [[] for _ in range(n)]
ids = [[-1] * n for _ in range(n)]
for i, (a, b) in enumerate(ab):
    a -= 1
    b -= 1
    adj[a].append(b)
    adj[b].append(a)
    ids[a][b] = i
    ids[b][a] = i


def dfs(s, g):
    d = [-1] * n
    d[s] = 0
    p = [-1] * n
    stack = [s]

    while stack:
        u = stack.pop()
        for v in adj[u]:
            if d[v] == -1:
                d[v] = d[u] + 1
                p[v] = u
                stack.append(v)

    v = g
    ret = 0
    while v != s:
        i = ids[v][p[v]]
        ret += 1 << i
        v = p[v]

    return ret


def bin_count(tpl):
    sm_or = 0
    for e in tpl:
        sm_or |= e

    return bin(sm_or).count("1")


path = [dfs(u - 1, v - 1) for u, v in uv]
ex = 0
for i in range(1, m + 1):
    for tpl in combinations(path, i):
        ex += pow(2, n - 1 - bin_count(tpl)) * (-1) ** (i % 2 + 1)

ans = pow(2, n - 1) - ex
print(ans)
### BUGGY CODE ###

from collections import deque

def main():
  n, m = map(int, input().split())
  ab = (map(int, input().split()) for i in range(m))
  
  ggg = [[0] * (n+1) for i in range(n+1)]
  ff = [0] * (n+1)
  
  for a, b in ab:
    ggg[a][b] = 1
    ggg[b][a] = 1
    
  qq = deque()
  qq.append(1)
  ff[1] = 1
  
  while qq:
    a = qq.popleft()
    for b in range(1, n+1):
      if ggg[a][b] and not ff[b]:
        ff[b] = a
        qq.append(b)
  
  rr = ff[2:]
  y = all(rr)
  
  print('Yes' if y else 'No')
  if y:
    for r in rr:
      print(r)

if __name__ == '__main__':
  main()


### FIXED CODE ###

from collections import deque

def main():
  n, m = map(int, input().split())
  ab = (map(int, input().split()) for i in range(m))
  
  ggg = [[] for i in range(n+1)]
  ff = [0] * (n+1)
  
  for a, b in ab:
    ggg[a].append(b)
    ggg[b].append(a)
    
  qq = deque()
  qq.append(1)
  ff[1] = 1
  
  while qq:
    a = qq.popleft()
    for b in ggg[a]:
      if not ff[b]:
        ff[b] = a
        qq.append(b)
  
  rr = ff[2:]
  y = all(rr)
  
  print('Yes' if y else 'No')
  if y:
    for r in rr:
      print(r)

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

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

ans = 0
for i in A:
    ans += i

for i in range(q):
    b, c = map(int, input().split())
    d = c - b
    cnt = 0
    for j in range(len(A)):
        if A[j] == b:
            A[j] = c
            cnt += 1
    ans += d*cnt
    print(ans)


### FIXED CODE ###

from collections import Counter
n = int(input())
A = list(map(int, input().split()))
q = int(input())

ans = sum(A)
dic = Counter(A)
for i in range(q):
    b, c = map(int, input().split())
    cnt = dic[b]
    dic[b] = 0
    dic[c] += cnt
    ans -= cnt*b
    ans += cnt*c
    print(ans)
### BUGGY CODE ###

import sys
input = sys.stdin.readline


def main():
    AB = []
    n = int(input())
    for i in range(n):
        a, b = map(int, input().split())
        AB.append([a, b])
    AB = sorted(AB, key=lambda x: (x[1], -x[0]))
    time = 0
    while AB:
        span, dead = AB.pop(0)
        time += span
        if time > dead:
            print('No')
            return
    print('Yes')
    return


if __name__ == "__main__":
    main()


### FIXED CODE ###

import sys
input = sys.stdin.readline


def main():
    AB = []
    n = int(input())
    for i in range(n):
        a, b = map(int, input().split())
        AB.append([a, b])
    AB = sorted(AB, key=lambda x: (x[1], -x[0]))
    time = 0
    for span, dead in AB:
        time += span
        if time > dead:
            print('No')
            return
    print('Yes')
    return


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

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

r = s.count("R")
g = s.count("G")
b = s.count("B")

comb = r*g*b

for i in range(1, n - 1):
    for j in range(2, n):
        if i < j:
            if (2*j - i) <= n:
                if s[i - 1] != s[j - 1]:
                    if s[i - 1] != s[2*j - i - 1]:
                        if s[j - 1] != s[2*j - i - 1]:
                            comb -= 1

print(comb)

### FIXED CODE ###

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

r = s.count("R")
g = s.count("G")
b = s.count("B")

comb = r*g*b

for i in range(1, n - 1):
    for j in range(2, n):
        if i < j:
            if (2*j - i) <= n:
                if s[i - 1] != s[j - 1]:
                    if s[i - 1] != s[2*j - i - 1]:
                        if s[j - 1] != s[2*j - i - 1]:
                            comb -= 1

print(comb)
### BUGGY CODE ###

from scipy.sparse.csgraph import dijkstra
from scipy.sparse import csr_matrix
from heapq import heappush, heappop

money = 10**15
N, M, s, t = map(int, input().split())
s -= 1; t -= 1
data1 = []; row1 = []; col1 = []
data2 = []; row2 = []; col2 = []
for i in range(M):
  u, v, a, b = map(int, input().split())
  u -= 1; v -= 1
  data1 += [a]; data2 += [b]
  row1 += [u]; row2 += [u]
  col1 += [v]; col2 += [v]

graph1 = csr_matrix((data1, (row1, col1)), shape=(N, N))
graph2 = csr_matrix((data2, (row2, col2)), shape=(N, N))
dist1 = dijkstra(graph1, indices=s, directed=False).astype(int)
dist2 = dijkstra(graph2, indices=t, directed=False).astype(int)

value = [dist1[i]+dist2[i] for i in range(N)]
ans = []
cost = []
for i in range(N-1, -1, -1):
  heappush(cost, value[i])
  ans.append(money - cost[0])

print(*(ans[::-1]), sep='\n')

### FIXED CODE ###

from heapq import heappush, heappop

money = 10**15
N, M, s, t = map(int, input().split())
s -= 1; t -= 1
graph = [[[] for i in range(N)] for _ in range(2)]
for i in range(M):
  u, v, a, b = map(int, input().split())
  u -= 1; v -= 1
  graph[0][u].append((v, a)); graph[0][v].append((u, a))
  graph[1][u].append((v, b)); graph[1][v].append((u, b))


def dijkstra(s, mode):
  dist = [-1] * N
  dist[s] = 0
  e = []
  for child, cost in graph[mode][s]:
    heappush(e, (cost, child))
  while e:
    cost, node = heappop(e)
    if dist[node] >= 0:
      continue
    dist[node] = cost
    for child, c in graph[mode][node]:
      if dist[child] >= 0:
        continue
      heappush(e, (cost+c, child))
  return dist
  
dist = [dijkstra(s, 0), dijkstra(t, 1)]  
value = [dist[0][i]+dist[1][i] for i in range(N)]

ans = []
cost = []
for i in range(N-1, -1, -1):
  heappush(cost, value[i])
  ans.append(money - cost[0])

print(*(ans[::-1]), sep='\n')
### BUGGY CODE ###

from collections import deque
n, m = map(int, input().split())
graph = [set([]) for _ in range(n+1)]
for _ in range(m):
    u, v = map(int, input().split())
    graph[u].add(v)

graph2 = [set([]) for _ in range(n+1)]
graph3 = [set([]) for _ in range(n+1)]
for i, g in enumerate(graph):
    if i == 0:
        continue

    for r in g:
        for w in graph[r]:
            graph3[i] |= graph[w]


s, t = map(int, input().split())
q = deque([s])
visited = [False] * (n+1)
visited[s] = True
dist = [-1] * (n+1)
dist[s] = 0
while q:
    now = q.popleft()
    for i in graph3[now]:
        if visited[i]:
            continue
        if i == now:
            continue
        q.append(i)
        visited[i] = True
        dist[i] = dist[now] + 1

print(dist[t])


### FIXED CODE ###

from collections import deque
n, m = map(int, input().split())
graph = [[[] for _ in range(3)] for _ in range(n+1)]
for _ in range(m):
    u, v = map(int, input().split())
    graph[u][0].append([v, 1])
    graph[u][1].append([v, 2])
    graph[u][2].append([v, 0])


s, t = map(int, input().split())
q = deque([[s, 0]])
visited = [[False] * 3 for _ in range(n+1)]
visited[s][0] = True
dist = [[-3] * 3 for _ in range(n+1)]
dist[s][0] = 0
while q:
    num, cnt = q.popleft()
    for i, j in graph[num][cnt]:
        if visited[i][j]:
            continue
        q.append([i, j])
        visited[i][j] = True
        dist[i][j] = dist[num][cnt] + 1

print(dist[t][0]//3)
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10**7)
from collections import deque

N = int(input())
ad = [[] for _ in range(N**2)]
num = [0] * (N**2)
for i in range(N):
    a = [int(e)-1 for e in input().split()]
    for k in range(N-2):
        j = a[k]
        nj = a[k+1]
        ti, tj = min(i, j), max(i, j)
        nti, ntj = min(i, nj), max(i, nj)
        v = N*ti + tj
        nv = N*nti + ntj
        ad[v].append(nv)
        num[nv] += 1

L = []
S = deque()

for v in range(N**2):
    i, j = divmod(v, N)
    if i >= j:
        continue
    if num[v] == 0:
        S.append(v)

while S:
    v = S.popleft()
    L.append(v)
    for nv in ad[v]:
        num[nv] -= 1
        if num[nv] == 0:
            S.append(nv)

if len(L) != N*(N-1)//2:
    print(-1)
    exit()

cand_list = []

def dfs(v):
    res = 1
    for nv in ad[v]:
        res = max(res, dfs(nv) + 1)
    return res

ans = dfs(L[0])
print(ans)

### FIXED CODE ###

from collections import deque

N = int(input())
ad = [[] for _ in range(N*N)]
num = [0] * (N*N)

for i in range(N):
    a = [int(e)-1 for e in input().split()]
    for k in range(N-2):
        j = a[k]
        nj = a[k+1]
        v = N*max(i,j) + min(i,j)
        nv = N*max(i,nj) + min(i,nj)
        ad[v].append(nv)
        num[nv] += 1

S = deque()
L = []

for v in range(N*N):
    if num[v] == 0:
        S.append((v,1))

while S:
    v, d = S.popleft()
    L.append(d)
    for nv in ad[v]:
        num[nv] -= 1
        if num[nv] == 0:
            S.append((nv, d+1))

if len(L) != N*N:
    print(-1)
    exit()

ans = max(L)
print(ans)
### BUGGY CODE ###

n,m = map(int,input().split())
a = list(map(int,input().split()))
p = [[aa,1] for aa in a]
for _ in range(m):
  b = list(map(int,input().split()))
  b.reverse()
  p.append(b)
p.sort()
p.reverse()
rest = n
score = 0
for ni in range(n):
  use = min(p[0][1],rest)
  rest -= use
  score += p[0][0] * use
  del p[0]
  if rest==0: break
print(score)

### FIXED CODE ###

n,m= map(int,input().split())
AA = list(map(int,input().split()))
A = [(AA[i],1) for i in range(n)]
for _ in range(m):
  b,c = map(int,input().split())
  A += [(c,b)]
A.sort()
A.reverse()
rest = n
score = 0
for (cc,bb) in A:
  use = min(bb,rest)
  rest -= use
  score += use*cc
print(score)
### BUGGY CODE ###

def dsum(n):
    wa = 0
    while n > 0:
        wa += n % 10
        n //= 10
    return wa


n = int(input())

print("Yes") if dsum(n) % 9 == 0 else print("No")



### FIXED CODE ###

n = int(input())
print("Yes") if n % 9 == 0 else print("No")
### BUGGY CODE ###

n = int(input())
list1 = list(map(int, input().split()))
s = 0
for i in range(n):
    p = list1[i] * sum(list1[i+1:n])
    s += p
print(s % (10**9 + 7))

### FIXED CODE ###

n = int(input())
list1 = list(map(int, input().split()))
s = 0
ss = sum(list1)
for i in range(n):
  a = list1[i]
  ss = ss - a
  p = a * ss
  s += p
print(s % (10**9 + 7))
### BUGGY CODE ###

import bisect
import copy
def two_int():
    N, K = map(int, input().split())
    return N,K

def one_int():
    return int(input())

def one_str():
    return input()

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




N=one_int()
L=many_int()

L=sorted(L)

sankaku_dict={}
count=0
for i in range(len(L)-1):
    low=L[i]
    Lcopy = copy.deepcopy(L)
    Lcopy.remove(low)
    
    for j in range(i+1, len(L)):
        #すでに探索済みか判定
        high = L[j]
        Lcopy2 = Lcopy[j:]
        
        #下限を取得    
#         under_index = bisect.bisect_right(Lcopy2,high-low)
        #上限を取得
        high_index = bisect.bisect_left(Lcopy2,high+low)
        
#         for va in Lcopy2[under_index:high_index]:
#             temp = sorted([high,low, va])
#             temp = (temp[0]*10**8) + (temp[1]*10**4) + temp[2]
#             sankaku_dict[temp]=1
        count+=len(Lcopy2[:high_index])

# len(sankaku_dict)
print(count)
# print(len(sankaku_dict.keys()))

### FIXED CODE ###

import bisect
import copy
def two_int():
    N, K = map(int, input().split())
    return N,K

def one_int():
    return int(input())

def one_str():
    return input()

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


N=one_int()
L=many_int()

L=sorted(L)

sankaku_dict={}
count=0
for i in range(len(L)-1):
    low=L[i]
    for j in range(i+1, len(L)):
        #すでに探索済みか判定
        high = L[j]
        
        #上限を取得
        high_index = bisect.bisect_left(L[j+1:], high+low)
        count+=high_index#len(L[j+1:high_index])

# len(sankaku_dict)
print(count)
# print(len(sankaku_dict.keys()))
### BUGGY CODE ###

import math

def pf(n):
    ans=[1]
    i=2
    while(n!=1):
        if (n%i==0):
            while(n%i==0):
                n=n/i
            ans.append(i)
        i+=1
    return ans

a,b = map(int,input().split())
pfa=pf(a)
ans=0
for i in range (len(pfa)):
    if(b%pfa[i]==0):
        ans+=1
print(ans)


### FIXED CODE ###

import math

def pf(n):
    ans=[1]
    i=2
    if(n%i==0):
        while(n%2==0):
            n = n/i
        ans.append(i)
    i+=1
    while(i<math.sqrt(n) and n!=1):
        if (n%i==0):
            while(n%i==0):
                n=n/i
            ans.append(i)
        i+=2
    if(n!=1):
        ans.append(n)
    return set(ans)

a,b = map(int,input().split())
pfa=pf(a)
a=0
for i in pfa:
    if(b%i==0):
        a+=1
print(a)
### BUGGY CODE ###

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

for i in range(M):
    idx = al.index(max(al))
    al[idx] = max(al) // 2

print(sum(al))

### FIXED CODE ###

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

for _ in range(M):
    tmp_min = heapq.heappop(al)
    heapq.heappush(al, -1*(-tmp_min//2))
print(-sum(al))
### BUGGY CODE ###

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

mul = 1
for a in A:
    mul *= a
    if mul == 0:
        break
    elif mul > 10 ** 18:
        mul = -1

print(mul)

### FIXED CODE ###

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

list.sort(A, reverse=True)
mx = 10 ** 18
mul = 1

if 0 in A:
    print(0)
    exit(0)
    
for a in A:
    mul *= a
    if mul > mx:
        mul = -1
        break

print(mul)
### BUGGY CODE ###

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

### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))
b = [0] * n
count = 0
for i in range(n):
    if i + a[i] < n:
        b[i + a[i]] += 1
    if i - a[i] >= 0:
        count += b[i-a[i]]
print(count)
### BUGGY CODE ###

N,K = map(int,input().split())
h = list(map(int,input().split()))
dp = [0]+[None]*(N-1) 
for i in range(1,N):
  dp[i] = min(dp[j] + abs(h[i]-h[j]) for j in range(max(i-K,0),i)) 
print(dp[-1])


### FIXED CODE ###

N,K = map(int,input().split())
h = list(map(int,input().split()))
dp = [0]+[None]*(N-1) 
def func(N,K,h,dp):
  for i in range(1,N):
    dp[i] = min(dp[j] + abs(h[i]-h[j]) for j in range(max(i-K,0),i)) 

func(N,K,h,dp)
print(dp[-1])
### BUGGY CODE ###

N=int(input())
s=[]
for i in range(N):
	s.append(str(input()))
ans=0
dic={}
for i in range(N):
	a=sorted(s[i])
	a=''.join(a)
	if a in list(dic.keys()):
		ans+=dic[a]
		dic[a]+=1
	else:
		dic[a] = 1
print(ans)

### FIXED CODE ###

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

R, C, K = map(int, input().split())

I = [[0 for j in range(C)] for i in range(R)]
for _ in range(K):
    r, c, v = map(int, input().split())
    I[r-1][c-1] = v   # 0-indexed

dp = [[[0 for k in range(4)]
       for j in range(C)] for i in range(R)]
for i in range(R):
    for j in range(C):
        for k in range(4):
            if i < R-1:
                if k <= 2:
                    dp[i+1][j][0] = max(dp[i+1][j][0], dp[i][j][k]+I[i][j])
                else:
                    dp[i+1][j][0] = max(dp[i+1][j][0], dp[i][j][k])
            if j < C-1:
                dp[i][j+1][k] = max(dp[i][j+1][k], dp[i][j][k])
                if k <= 2:
                    dp[i][j+1][k+1] = max(dp[i][j+1][k+1], dp[i][j][k]+I[i][j])


# print(*dp, sep='\n')

ans = 0
for k in range(4):
    if k <= 2:
        ans = max(ans, dp[R-1][C-1][k]+I[R-1][C-1])
    else:
        ans = max(ans, dp[R-1][C-1][k])
print(ans)


### FIXED CODE ###

import sys
input = sys.stdin.readline

R, C, K = map(int, input().split())

I = [[0]*C for i in range(R)]
for _ in range(K):
    r, c, v = map(int, input().split())
    I[r-1][c-1] = v   # 0-indexed

dp0 = [[0 for j in range(C+1)] for i in range(R+1)]
dp1 = [[0 for j in range(C+1)] for i in range(R+1)]
dp2 = [[0 for j in range(C+1)] for i in range(R+1)]
dp3 = [[0 for j in range(C+1)] for i in range(R+1)]
for i in range(R):
    for j in range(C):
        dp3[i][j] = max(dp3[i][j], dp2[i][j]+I[i][j])
        dp2[i][j] = max(dp2[i][j], dp1[i][j]+I[i][j])
        dp1[i][j] = max(dp1[i][j], dp0[i][j]+I[i][j])
        dp0[i+1][j] = max(dp0[i+1][j], dp0[i][j], dp1[i]
                          [j], dp2[i][j], dp3[i][j])
        dp0[i][j+1] = max(dp0[i][j+1], dp0[i][j])
        dp1[i][j+1] = max(dp1[i][j+1], dp1[i][j])
        dp2[i][j+1] = max(dp2[i][j+1], dp2[i][j])
        dp3[i][j+1] = max(dp3[i][j+1], dp3[i][j])


# print(*dp, sep=' \n')

ans = max(dp0[R-1][C-1], dp1[R-1][C-1], dp2[R-1][C-1], dp3[R-1][C-1])
print(ans)
### BUGGY CODE ###

import sys

N, T = map(int, input().split())
S = sys.stdin.readlines()
A = []
B = []
for s in S:
    a, b = map(int, s.split())
    A.append(a)
    B.append(b)

dp1 = [[0] * T for _ in range(N + 1)]
for i in range(N):
    for j in range(T):
        here = dp1[i][j]
        if j < A[i]:
            dp1[i + 1][j] = here
        else:
            dp1[i + 1][j] = max(here, dp1[i][j - A[i]] + B[i])

dp2 = [[0] * T for _ in range(N + 2)]
for i in range(N, 0, -1):
    for j in range(T):
        here = dp2[i + 1][j]
        if j < A[i - 1]:
            dp2[i][j] = here
        else:
            dp2[i][j] = max(here, dp2[i + 1][j - A[i - 1]] + B[i - 1])

ans = 0
for i in range(1, N + 1):
    t = 0
    for j in range(T):
        t2 = dp1[i - 1][j] + dp2[i + 1][T - 1 - j]
        t = max(t, t2)
    ans = max(ans, t + B[i - 1])

print(ans)


### FIXED CODE ###

import sys

N, T = map(int, input().split())
S = sys.stdin.readlines()
A = []
B = []
for s in S:
    a, b = map(int, s.split())
    A.append(a)
    B.append(b)

dp1 = [[0] * T for _ in range(N + 1)]
for i in range(N):
    for j in range(T):
        here = dp1[i][j]
        if j < A[i]:
            dp1[i + 1][j] = here
        else:
            dp1[i + 1][j] = max(here, dp1[i][j - A[i]] + B[i])

dp2 = [[0] * T for _ in range(N + 2)]
for i in range(N, 0, -1):
    for j in range(T):
        here = dp2[i + 1][j]
        if j < A[i - 1]:
            dp2[i][j] = here
        else:
            dp2[i][j] = max(here, dp2[i + 1][j - A[i - 1]] + B[i - 1])

ans = 0
for i in range(1, N + 1):
    t = 0
    for j in range(T):
        t2 = dp1[i - 1][j] + dp2[i + 1][T - 1 - j]
        t = max(t, t2)
    ans = max(ans, t + B[i - 1])

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

def main():
    N = int(input())
    S = list(input())
    R = []
    G = []
    B = []
    for i in range(N):
        if S[i] == "R":
            R.append(i)
        elif S[i] == "G":
            G.append(i)
        elif S[i] == "B":
            B.append(i)
            #if i / 2 in R or i / 2 in G or i / 2 in B
    count = len(R)*len(G)*len(B)

    for a in R:
        for b in G:
            if 2 * a - b in B:
                count -= 1
            if 2 * b - a in B:
                count -= 1
            if (a + b)/2 in B:
                count -= 1
    print(count)

if __name__ == "__main__":
    main()


### FIXED CODE ###

N = int(input())
S = list(input())
R = []
G = []
B = []
Reval = {}
Geval = {}
Beval = {}
for i in range(N):
    if S[i] == "R":
        R.append(i)
        Reval[2*i] = 2*i
    elif S[i] == "G":
        G.append(i)
        Geval[2*i] = 2*i
    elif S[i] == "B":
        B.append(i)
        Beval[2*i] = 2*i
count = len(R)*len(G)*len(B)

for a in R:
    for b in G:
        if (a + b) in Beval:
            count -= 1
for a in G:
    for b in B:
        if (a + b) in Reval:
            count -= 1
for a in B:
    for b in R:
        if (a + b) in Geval:
            count -= 1
print(count)
### BUGGY CODE ###

from numpy import array
n=int(input())
s=input()
t=s.count("E")
r=s.count("W")
dp =[r-(s[-1]=="W")]+[0 for i in range(n-1)]
dp2=[t-(s[0 ]=="E")]+[0 for i in range(n-1)]
for i in range(1,n):
    if s[::-1][i]=="E":
        dp[i]=dp[i-1]
    else:
        dp[i]=dp[i-1]-1

for i in range(1,n):
    if s[i]=="W":
        dp2[i]=dp2[i-1]
    else:
        dp2[i]=dp2[i-1]-1

print(min(array(dp[::-1])+array(dp2)))

### FIXED CODE ###

from numpy import*
n=int(input())
s=input()
x=[0]+[1 if i=="W" else 0 for i in s]
del x[-1]
y=[1 if i=="E" else 0 for i in s]
print(min(array(cumsum(x))+s.count("E")-array(cumsum(y))))
### BUGGY CODE ###

import math
def combinations_count(n, r):
    if n >= r:
        return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
    else:
        return 0
n = int(input())
s = [list(map(str, input())) for i in range(n)]
count = 0
for i in range(n):
    s[i].sort()
for i in s:
    k = s.count(i)
    l = i
    count += combinations_count(k, 2)
    for j in range(k):
        s.remove(s[s.index(l)])
print(count)

### FIXED CODE ###

from collections import Counter
n = int(input())
S = ["".join(sorted(input())) for i in range(n)]
s = Counter(S)


def calc(x):
    return x * (x-1) // 2


ans = 0
for i in s.values():
    ans += calc(i)
print(ans)
### BUGGY CODE ###

K, S = map(int,input().split())

cnt = 0
for i in range(K+1):
    x = i
    for j in range(K+1):
        y = j
        for k in range(K+1):
            z = k
            if x + y + z == S:
                cnt += 1
print(cnt)

### FIXED CODE ###

K, S = map(int,input().split())

cnt = 0
for i in range(K+1):
    for j in range(K+1):
        if 0 <= S - i - j <= K:
            cnt +=1
print(cnt)
### BUGGY CODE ###

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

cnt = 0

_R = N//R

for i in range(_R+1):
    _G = (N - R*i)//G 
    for j in range(_G+1):
        _B = (N - R*i - G*j)//B 
        for k in range(_B, _B+1):
            if i*R + j*G + k*B == N:
                cnt += 1
print(cnt)

### FIXED CODE ###

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

cnt = 0

li = [R, G, B]
li = sorted(li)

_i = N//li[2]
for i in range(_i+1):
    _j = (N - li[2]*i )//li[1]
    for j in range(_j + 1):
        if (N - i*li[2] -  j*li[1])%li[0] == 0:
            cnt += 1

print(cnt)
### BUGGY CODE ###

n = int(input())
lis = [int(input()) for _ in range(n)]

M = max(lis)

for i in range(n):
    if lis[i] == M:
        lis2 = lis[:i] + lis[(i+1):]
        print(max(lis2))
    else:
        print(M)


### FIXED CODE ###

n = int(input())
lis = [int(input()) for _ in range(n)]
lis2 = sorted(lis)
m1 = lis2[-1]
m2 = lis2[-2]

for a in lis:
    if a == m1:
        print(m2)
    else:
        print(m1)