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

n=int(input())
a=input()
q=int(input())
BC=[[] for _ in range(q)]
for i in range(q):
    b,c=input().split()
    BC[i].append(b)
    BC[i].append(c)
for i in range(q):
    a=a.replace(BC[i][0],BC[i][1])
    e=list(map(int,a.split()))
    print(sum(e))
        

### FIXED CODE ###

n=int(input())
a=list(map(int,input().split()))
q=int(input())
num=[0]*(10**5+1)
ans=sum(a)
for i in a:
    num[i]+=1
for i in range(q):
    b,c=map(int,input().split())
    ans=ans+(c-b)*num[b]
    num[c]+=num[b]
    num[b]=0
    print(ans)
### BUGGY CODE ###

def main():
  xs,ys,xt,yt=map(int,input().split())
  n=int(input())
  xyr=[list(map(int,input().split())) for _ in range(n)]
  xyr.append([xs,ys,0])
  xyr.append([xt,yt,0])
  n+=2
  def dist(xyr,i,j):
    x,y,r=xyr[i]
    x1,y1,r1=xyr[j]
    d=max(0,((x-x1)**2+(y-y1)**2)**0.5-r-r1)
    return d
  from heapq import heappop,heappush
  todo=[[0,n-2]]
  ka=set(())
  seen=[float('inf')]*n
  seen[n-2]=0
  while todo:
    d,v=heappop(todo)
    if v in ka:continue
    if v==n-1:
      print(d)
      exit()
    ka.add(v)
    for nv in range(n):
      if nv in ka:continue
      nd=dist(xyr,v,nv)
      if seen[nv]>d+nd:
        heappush(todo,[d+nd,nv])
        seen[nv]=d+nd
if __name__=='__main__':
  main()


### FIXED CODE ###

from heapq import heappop,heappush
from math import sqrt
def distf(xyr,i,j):
  x,y,r=xyr[i]
  x1,y1,r1=xyr[j]
  d=max(0,sqrt((x-x1)**2+(y-y1)**2)-r-r1)
  return d

def main():
  xs,ys,xt,yt=map(int,input().split())
  n=int(input())
  xyr=[list(map(int,input().split())) for _ in range(n)]
  xyr.append([xs,ys,0])
  xyr.append([xt,yt,0])
  inf=float('inf')
  dist=[[inf]*(n+2) for _ in range(n+2)]
  for i in range(n+2):
    dist[i][i]=0
  for i in range(n+1):
    for j in range(i+1,n+2):
      dist[i][j]=distf(xyr,i,j)
      dist[j][i]=dist[i][j]
  seen=[inf]*(n+2)
  seen[n]=0
  mi=set(range(n+2))
  while mi:
    d,v=inf,-1
    for j in mi:
      if d>seen[j]:
        d=seen[j]
        v=j
    mi.remove(v)
    for nv in mi:
      nd=dist[v][nv]
      if seen[nv]>seen[v]+nd:
        seen[nv]=seen[v]+nd
  print(seen[n+1])
if __name__=='__main__':
  main()
### BUGGY CODE ###

# -*- coding: utf-8 -*-
"""
Created on Wed May  6 02:13:01 2020

@author: shinba
"""

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

R = []
G = []
B = []

for i in range(N):
    if S[i] == "R":
        R.append(i+1)
    elif S[i] == "G":
        G.append(i+1)
    else:
        B.append(i+1)

ans = len(R)*len(G)*len(B)
#print(R)
#print(G)
#print(B)

for i in R:
    for j in G:
        if 2*j - i in B:
            ans -= 1
        if (i+j)%2 == 0:
            if (i+j)//2 in B:
                ans -= 1
        if 2*i - j in B:
            ans -= 1

print(ans)
        


### FIXED CODE ###

# -*- coding: utf-8 -*-
"""
Created on Wed May  6 02:13:01 2020

@author: shinba
"""
import sys

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

R = []
G = []
B = []

for i in range(N):
    if S[i] == "R":
        R.append(i+1)
    elif S[i] == "G":
        G.append(i+1)
    else:
        B.append(i+1)

if R==[] or G==[] or B==[]:
    print(0)
    sys.exit()
    
ans = len(R)*len(G)*len(B)

m = min(B)
M = max(B)

for i in R:
    for j in G:
        a = 2*j - i 
        b = (i+j)//2 if (i+j)%2 == 0 else 0
        c = 2*i - j
        if m <= a <= M:
            if S[a-1] == "B":
                ans -= 1
        if b != 0 and S[b-1] == "B":
            ans -= 1
        if m <= c <= M:
            if S[c-1] == "B":
                ans -= 1
            
print(ans)
### BUGGY CODE ###

# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

H,W = map(int,input().split())
S = [[] for i in range(H)]
for i in range(H):
    S[i] = list(str(input()))

lights = [[[0,0] for j in range(W)] for i in range(H)]

def count_ver(i,j):
    cnt = 0
    for x in range(i,W):
        if S[j][x] == ".":
            cnt += 1
        else:
            break
    for x in range(i,W):
        if S[j][x] == ".":
            lights[j][x][0] = cnt
        else:
            break
    return cnt


def count_hor(i,j):
    cnt = 0
    for y in range(j,H):
        if S[y][i] == ".":
            cnt += 1
        else:
            break
    for y in range(j,H):
        if S[y][i] == ".":
            lights[y][i][1] = cnt
        else:
            break
    return cnt

ans = -1
for i in range(H):
    for j in range(W):
        if S[i][j] == ".":
            ver,hor = lights[i][j]
            if ver == 0:
                ver = count_ver(j,i)
            if hor == 0:
                hor = count_hor(j,i)
            ans = max(ans,hor+ver-1)
        # print("y,x:",i,j)
        # print("ver,hor",ver,hor)

# print(lights)
print(ans)


### FIXED CODE ###

import fractions #最小公倍数などはこっち
import math
import sys

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

H,W = map(int,input().split())
S = [[] for i in range(H)]
for i in range(H):
    S[i] = list(str(input()))

lights = [[(0,0) for j in range(W)] for i in range(H)]

def count_ver(i,j):
    cnt = 0
    for x in range(i,W):
        if S[j][x] == ".":
            cnt += 1
        else:
            break
    for x in range(i,i+cnt):
        ver,hor = lights[j][x]
        lights[j][x] = (cnt,hor)
    return cnt


def count_hor(i,j):
    cnt = 0
    for y in range(j,H):
        if S[y][i] == ".":
            cnt += 1
        else:
            break
    for y in range(j,j+cnt):
        ver,hor = lights[y][i]
        lights[y][i] = (ver,cnt)
    return cnt

ans = -1
for i in range(H):
    for j in range(W):
        if S[i][j] == ".":
            ver,hor = lights[i][j]
            if ver == 0:
                ver = count_ver(j,i)
            if hor == 0:
                hor = count_hor(j,i)
            ans = max(ans,hor+ver-1)

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

mod = 998244353
size = 1 << 18
dat = [-mod] * (size * 2 - 1)
def seg_max(a, b, k = 0, l = 0, r = size):
    if r <= a or b <= l:
        return -mod
    if a <= l and r <= b:
        return dat[k]
    vl = seg_max(a, b, k * 2 + 1, l, (l + r) // 2)
    vr = seg_max(a, b, k * 2 + 2, (l + r) // 2, r)
    return max(vl, vr)

def seg_update(i, x):
    i += size - 1
    dat[i] = x
    while i > 0:
        i = (i - 1) // 2
        dat[i] = max(dat[i * 2 + 1], dat[i * 2 + 2]);

N = int(input())
tmpX = []
for i in range(N):
    x, d = list(map(int, input().split()))
    tmpX.append((x, d))
tmpX.sort()


X, D = [0] * N, [0] * N
for i in range(N):
    X[i] = tmpX[i][0]
    D[i] = tmpX[i][1]

to = [0] * N
for i in range(N):
    seg_update(i, i)

for i in range(N-1, -1, -1):
    ok = i
    ng = N
    while ng - ok > 1:
        mid = (ng + ok) // 2
        if X[i] + D[i] > X[mid]:
            ok = mid
        else :
            ng = mid
    to[i] = seg_max(i, ok+1)
    seg_update(i, to[i])

dp = [0] * (N+1)
dp[0] = 1
for i in range(N):
    dp[i+1] += dp[i]
    dp[i+1] %= mod
    dp[to[i]+1] += dp[i]
    dp[to[i]+1] %= mod
print(dp[N])


### FIXED CODE ###

import sys
sys.setrecursionlimit(10**9)

mod = 998244353

# segment tree
def init_max(init_max_val, n):
    #set_val
    for i in range(n):
        seg_max[i+num_max-1]=init_max_val[i]
    #built
    for i in range(num_max-2,-1,-1) :
        seg_max[i]=max(seg_max[2*i+1],seg_max[2*i+2])

def update_max(k,x):
    k += num_max-1
    seg_max[k] = x
    while k:
        k = (k-1)//2
        seg_max[k] = max(seg_max[k*2+1],seg_max[k*2+2])

def query_max(p,q):
    if q<=p:
        return ide_ele_max
    p += num_max-1
    q += num_max-2
    res=ide_ele_max
    while q-p>1:
        if p&1 == 0:
            res = max(res,seg_max[p])
        if q&1 == 1:
            res = max(res,seg_max[q])
            q -= 1
        p = p//2
        q = (q-1)//2
    if p == q:
        res = max(res,seg_max[p])
    else:
        res = max(max(res,seg_max[p]),seg_max[q])
    return res

#####単位元######
ide_ele_max = -1

#num_max:n以上の最小の2のべき乗
num_max = 1 << 18
seg_max=[ide_ele_max]*2*num_max



N = int(input())
tmpX = []
for i in range(N):
    x, d = list(map(int, input().split()))
    tmpX.append((x, d))
tmpX.sort()


X, D = [0] * N, [0] * N
for i in range(N):
    X[i] = tmpX[i][0]
    D[i] = tmpX[i][1]

to = [0] * N
for i in range(N):
    to[i] = i
init_max(to, N)

for i in range(N-1, -1, -1):
    ok = i
    ng = N
    while ng - ok > 1:
        mid = (ng + ok) // 2
        if X[i] + D[i] > X[mid]:
            ok = mid
        else :
            ng = mid
    to[i] = query_max(i, ok+1)
    update_max(i, to[i])

dp = [0] * (N+1)
dp[0] = 1
for i in range(N):
    dp[i+1] += dp[i]
    dp[i+1] %= mod
    dp[to[i]+1] += dp[i]
    dp[to[i]+1] %= mod
print(dp[N])
### BUGGY CODE ###

from collections import deque

n, x, y = [int(x) for x in input().split()]
x -= 1
y -= 1

# グラフを陽に持つ。
edges = [[] for _ in range(n)]
for i, e in enumerate(edges):
    if i == y:
        e.append(x)
    if i > 0:
        e.append(i - 1)
    if i < n - 1:
        e.append(i + 1)
    if i == x:
        e.append(y)

ans = [0] * n  # Patterns by distances

for v in range(n):
    que = deque()  # Queue
    que_append = que.append
    que_popleft = que.popleft
    dist = [-1] * n  # Distance

    dist[v] = 0
    que_append(v)

    while len(que):
        new_v = que_popleft()

        for adjacent in edges[new_v]:
            if dist[adjacent] != -1:
                continue
            que_append(adjacent)
            dist[adjacent] = dist[new_v] + 1

    for d in dist:
        ans[d] += 1

for a in ans[1:]:
    print(a // 2)


### FIXED CODE ###

from collections import deque

n, x, y = [int(x) for x in input().split()]
x -= 1
y -= 1
BIG = 65521
ans = {i: 0 for i in range(n)}


def bfs(start_v):
    """ある始点からほかの全点に行くまでの最短距離を求める。"""
    qu = deque()
    qu_append = qu.append
    qu_popleft = qu.popleft
    qu_append(start_v)
    # 始点からvに移動するまでの最短距離: dist[v]
    dist = [BIG] * n

    def push(v, d):
        """始点からvまでの最短距離が算出されていないときに，その距離を保存し，
        キューに頂点vを追加する。"""
        if dist[v] != BIG:
            # 既に訪問済みで距離が求められている。
            return
        dist[v] = d
        qu_append(v)

    push(start_v, 0)

    while len(qu):
        v = qu_popleft()
        # 始点からvの次の頂点へ移動する距離。
        d = dist[v] + 1
        if v < n - 1:
            push(v + 1, d)
        if v > 0:
            push(v - 1, d)
        if v == x:
            push(y, d)
        if v == y:
            push(x, d)

    for i in range(n):
        if dist[i] != 0:
            ans[dist[i]] += 1


def main():
    for i in range(n):
        bfs(i)

    for i in range(1, n):
        print(ans[i] // 2)


if __name__ == '__main__':
    main()

# TLE
### BUGGY CODE ###

n=int(input())
b=[0]*n
w=[0]*n
for i in range(2*n):
  c,a=input().split()
  if c=="B":b[int(a)-1]=i
  else:w[int(a)-1]=i
bit=[0]*2*n
dp=[(n+1)*[10**10]for _ in range(n+1)]
dp[0][0]=0
for i in range(n+1):
  bitt=bit[:]
  for j in range(n):
    a=0
    k=2*n
    while k:
      a+=bitt[k-1]
      k-=k&-k
    if w[j]!=0:
      k=w[j]
      while k:
        a-=bitt[k-1]
        k-=k&-k
    dp[i][j+1]=min(dp[i][j+1],dp[i][j]+a+w[j]-(i+j))
    k=w[j]+1
    while k<=2*n:
      bitt[k-1]+=1
      k+=k&-k
    if i!=n:
      a=0
      k=2*n
      while k:
        a+=bitt[k-1]
        k-=k&-k
      if b[i]!=0:
        k=b[i]
        while k:
          a-=bitt[k-1]
          k-=k&-k
      dp[i+1][j+1]=dp[i][j+1]+a+b[i]-(i+j+1)
  if i!=n:
    a=b[i]-i
    k=2*n
    while k:
      a+=bit[k-1]
      k-=k&-k
    if b[i]!=0:
      k=b[i]
      while k:
        a-=bit[k-1]
        k-=k&-k
    dp[i+1][0]=dp[i][0]+a
    k=b[i]+1
    while k<=2*n:
      bit[k-1]+=1
      k+=k&-k
print(dp[n][n])

### FIXED CODE ###

n=int(input())
b=[0]*n
w=[0]*n
for i in range(2*n):
  c,a=input().split()
  if c=="B":b[int(a)-1]=i
  else:w[int(a)-1]=i
bit=[0]*2*n
dp=[(n+1)*[10**10]for _ in range(n+1)]
dp[0][0]=0
for i in range(n+1):
  bitt=bit[:]
  for j in range(n):
    a=0
    k=2*n
    while k:
      a+=bitt[k-1]
      k-=k&-k
    if w[j]!=0:
      k=w[j]
      while k:
        a-=bitt[k-1]
        k-=k&-k
    dp[i][j+1]=min(dp[i][j+1],dp[i][j]+a+w[j]-(i+j))
    k=w[j]+1
    while k<=2*n:
      bitt[k-1]+=1
      k+=k&-k
    if i!=n:
      a=0
      k=2*n
      while k:
        a+=bitt[k-1]
        k-=k&-k
      if b[i]!=0:
        k=b[i]
        while k:
          a-=bitt[k-1]
          k-=k&-k
      dp[i+1][j+1]=dp[i][j+1]+a+b[i]-(i+j+1)
  if i!=n:
    a=b[i]-i
    k=2*n
    while k:
      a+=bit[k-1]
      k-=k&-k
    if b[i]!=0:
      k=b[i]
      while k:
        a-=bit[k-1]
        k-=k&-k
    dp[i+1][0]=dp[i][0]+a
    k=b[i]+1
    while k<=2*n:
      bit[k-1]+=1
      k+=k&-k
print(dp[n][n])
### BUGGY CODE ###

x = int(input())

def a(lst, target, with_replacement=False):
    def _a(idx, l, r, t, w):
        if t == sum(l):
            r.append(l)
            return r
        elif t < sum(l): return
        for u in range(idx, len(lst)):
            _a(u if w else (u + 1), l + [lst[u]], r, t, w)
        return r
    return _a(0, [], [], target, with_replacement)

goods = [100, 101, 102, 103, 104, 105]

res = a( goods, x, True)
print(1) if len(res)>0 else print(0)

### FIXED CODE ###

x = int(input())
cnt = int(x/100)

print(1) if x-cnt*105<=0 else print(0)
### BUGGY CODE ###

l,r=map(int,input().split())
m,ans=2019,2018
r=min(r,l+2019*2)
for i in range(l,r+1):
  for j in range(i+1,r+1):
    ans=min(ans,(i%m*j%m)%m)
print(ans)


### FIXED CODE ###

l,r=map(int,input().split())
m=2019
if l//m<r//m:
  print(0)
else:
  ans=m
  for i in range(l%m, r%m+1):
    for j in range(i+1,r%m+1):
      ans=min(ans,i%m*j%m)
  print(ans)
### BUGGY CODE ###

import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**5+1)
from functools import lru_cache

def main():
    N, M = map(int, input().split())
    G = [[] for _ in range(N)]
    for _ in range(M):
        x, y = map(int, input().split())
        x -= 1
        y -= 1
        G[x].append(y)

    @lru_cache(maxsize=10**5+1)
    def dp(v):
        res = 0
        for w in G[v]:
            res = max(res, dp(w)+1)
        return res

    ans = 0
    for i in range(N):
        ans = max(ans, dp(i))
    print(ans)

if __name__ == '__main__':
    main()

### FIXED CODE ###

import sys
sys.setrecursionlimit(10**5+1)

N, M = map(int, input().split())
graph = {i+1:[] for i in range(N)}

for _ in range(M):
    x, y = map(int, input().split())
    graph[x].append(y)

"""
dp[v]: ノードv(1~N)を始点とした最大長
"""
dp = [0] * (1+N)

def max_length_from(v):
    if dp[v] != 0:
        return dp[v]
    max_length = 0
    for vv in graph[v]:
        tmp = max_length_from(vv) + 1
        if tmp > max_length:
            max_length = tmp
    dp[v] = max_length
    return max_length

for v in range(1, N+1):
    max_length_from(v)

print(max(dp))
### BUGGY CODE ###

#A
from collections import deque
inf = float("inf")
H,W = map(int,input().split())
A = [list(str(input())) for _ in range(H)]

C = [[inf for w in range(W)] for h in range(H)]


start = deque([])
for h in range(H):
    for w in range(W):
        if A[h][w] == "#":
            start.append([h,w])
            C[h][w] = 0
            
while start:
    h,w = start.popleft()
    if h > 0:
        c_old = C[h][w]
        c_new = C[h-1][w]
        
        if c_old+1 < c_new:
            C[h-1][w] = c_old+1
            start.append([h-1,w])
            
    if w > 0:
        c_old = C[h][w]
        c_new = C[h][w-1]
        
        if c_old+1 < c_new:
            C[h][w-1] = c_old+1
            start.append([h,w-1])
            
    if w < W-1:
        c_old = C[h][w]
        c_new = C[h][w+1]
        
        if c_old+1 < c_new:
            C[h][w+1] = c_old+1
            start.append([h,w+1])
            
    if h < H-1:
        c_old = C[h][w]
        c_new = C[h+1][w]
        
        if c_old+1 < c_new:
            C[h+1][w] = c_old+1
            start.append([h+1,w])
            
            
ans = 0
for h in range(H):
    for w in range(W):
        ans = max(ans,C[h][w])
        
print(ans)
        
    




### FIXED CODE ###

#A
from collections import deque
H,W = map(int,input().split())
A = [list(str(input())) for h in range(H)]

C = [[-1 for w in range(W)] for h in range(H)]


start = deque([])
for h in range(H):
    for w in range(W):
        if A[h][w] == "#":
            start.append([h,w])
            C[h][w] = 0
            
while start:
    h,w = start.popleft()
    c_old = C[h][w]
    
    if h > 0:
        c_new = C[h-1][w]
        
        if c_new == -1:
            C[h-1][w] = c_old+1
            start.append([h-1,w])
            
    if w > 0:
        c_new = C[h][w-1]
        
        if c_new == -1:
            C[h][w-1] = c_old+1
            start.append([h,w-1])
            
    if w < W-1:
        c_new = C[h][w+1]
        
        if c_new == -1:
            C[h][w+1] = c_old+1
            start.append([h,w+1])
            
    if h < H-1:
        c_new = C[h+1][w]
        
        if c_new == -1:
            C[h+1][w] = c_old+1
            start.append([h+1,w])
            
            
ans = 0
for h in range(H):
    for w in range(W):
        ans = max(ans,C[h][w])
        
        
print(ans)
### BUGGY CODE ###

def main():
    h,w,m=map(int,input().split())
    target=[tuple(map(int,input().split())) for i in range(m)]
    lines=[0]*w
    rows=[0]*h
    for th,tw in target:
        lines[tw-1]+=1
        rows[th-1]+=1
    max_lines=max(lines)
    max_rows=max(rows)
    max_wi=[i for i,wi in enumerate(lines) if wi==max_lines]
    max_hi=[i for i,hi in enumerate(rows) if hi==max_rows]
    flag=[]
    for wi in max_wi:
        for hi in max_hi:
            if (hi+1,wi+1) in target:
                flag.append(-1)
            else:
                flag.append(0)
    # print(max_rows,max_hi,max_lines,max_wi,flag)
    ans=max_lines+max_rows+max(flag)
    return ans

if __name__=='__main__':
    ans=main()
    print(ans)


### FIXED CODE ###

def main():
    h,w,m=map(int,input().split())
    target=set()
    for i in range(m):
        th,tw=map(int,input().split())
        target.add((th-1,tw-1))
    lines=[0]*w
    rows=[0]*h
    for th,tw in target:
        lines[tw]+=1
        rows[th]+=1
    max_lines=max(lines)
    max_rows=max(rows)
    max_wi=[i for i,wi in enumerate(lines) if wi==max_lines]
    max_hi=[i for i,hi in enumerate(rows) if hi==max_rows]
    # print('rows\t',max_rows,max_hi,'\nlines\t',max_lines,max_wi)
    ans=max_lines+max_rows-1
    isLoop=True
    for wi in max_wi:
        if isLoop:
            for hi in max_hi:
                if not (hi,wi) in target:
                    ans+=1
                    isLoop=False
                    break
    return ans

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

n, m, k = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a = [0]+[sum(a[:i+1]) for i in range(len(a))]
b = [0]+[sum(b[:i+1]) for i in range(len(b))]
ans = 0
for i in range(n+1):
    if a[i]>k:
        break
    for j in reversed(range(m+1)):
        if a[i]+b[j]<=k:
            ans = max(ans, i+j)
            m=j
            break
print(ans)

### FIXED CODE ###

n, m, k = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
a, b = [0], [0]
for i in range(n):
    a.append(a[i]+A[i])
for i in range(m):
    b.append(b[i]+B[i])
ans = 0
for i in range(n+1):
    if a[i]>k:
        break
    for j in reversed(range(m+1)):
        if a[i]+b[j]<=k:
            ans = max(ans, i+j)
            m=j
            break
print(ans)
### BUGGY CODE ###

N,M,K=map(int,input().split())
AB=[[] for _ in range(N)]
for _ in range(M):
  a,b=map(int,input().split())
  AB[a-1].append(b)
  AB[b-1].append(a)

CD=[[] for _ in range(N)]
for _ in range(K):
  c,d=map(int,input().split())
  CD[c-1].append(d)
  CD[d-1].append(c)

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root and i+1 not in CD[x]]
      
uf=UnionFind(N)
for i in range(N):
  for j in AB[i]:
    uf.union(i,j-1)

ans=[0]*N
for i in range(N):
  ans[i]=len(uf.members(i))-1-len(AB[i])
print(*ans)

### FIXED CODE ###

N,M,K=map(int,input().split())
AB=[[] for _ in range(N)]
for _ in range(M):
  a,b=map(int,input().split())
  AB[a-1].append(b)
  AB[b-1].append(a)

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]
    def same(self, x, y):
        return self.find(x) == self.find(y)
      
uf=UnionFind(N)
for i in range(N):
  for j in AB[i]:
    uf.union(i,j-1)

ans=[0]*N
for i in range(N):
  ans[i]=uf.size(i)-1-len(AB[i])
for i in range(K):
  c,d=map(int,input().split())
  if uf.same(c-1,d-1):
    ans[c-1]-=1
    ans[d-1]-=1
print(*ans)
### BUGGY CODE ###

h,w = map(int,input().split())
lst = [input() for _ in range(h)]

L = [[0]*w for _ in range(h)]
R = [[0]*w for _ in range(h)]
D = [[0]*w for _ in range(h)]
U = [[0]*w for _ in range(h)]

for i in range(h):
    cnt = 1
    for j in range(w):
        if (lst[i][j] == '#'):
            cnt =1
        else:
            L[i][j] = cnt
            cnt += 1

for i in range(h):
    cnt = 1
    for j in range(w)[::-1]:
        if (lst[i][j] == '#'):
            cnt =1
        else:
            R[i][j] = cnt
            cnt += 1

for i in range(w):
    cnt = 1
    for j in range(h):
        if (lst[j][i] == '#'):
            cnt = 1
        else:
            U[j][i] = cnt
            cnt += 1

for i in range(w):
    cnt = 1
    for j in range(h)[::-1]:
        if (lst[j][i] == '#'):
            cnt = 1
        else:
            D[j][i] = cnt
            cnt += 1

ans = 0
for i in range(h):
    for j in range(w):
        tmp = L[i][j] + R[i][j] + D[i][j] + U[i][j] - 3
        if tmp > ans:
            ans = tmp
print(ans)

### FIXED CODE ###

h,w = map(int,input().split())
lst = [input() for _ in range(h)]

L = [[0]*w for _ in range(h)]
R = [[0]*w for _ in range(h)]
D = [[0]*w for _ in range(h)]
U = [[0]*w for _ in range(h)]

for i in range(h):
    cnt_L = 1
    for j in range(w):
        if (lst[i][j] == '#'):
            cnt_L =1
        else:
            L[i][j] = cnt_L
            cnt_L += 1
            
    cnt_R = 1
    for k in range(w)[::-1]:
        if (lst[i][k] == '#'):
            cnt_R = 1
        else:
            R[i][k] = cnt_R
            cnt_R += 1

for i in range(w):
    cnt_U = 1
    for j in range(h):
        if (lst[j][i] == '#'):
            cnt_U = 1
        else:
            U[j][i] = cnt_U
            cnt_U += 1
    
    cnt_D = 1
    for k in range(h)[::-1]:
        if (lst[k][i] == '#'):
            cnt_D = 1
        else:
            D[k][i] = cnt_D
            cnt_D += 1

ans = 0
for i in range(h):
    for j in range(w):
        tmp = L[i][j] + R[i][j] + D[i][j] + U[i][j] - 3
        if tmp > ans:
            ans = tmp
print(ans)
### BUGGY CODE ###

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

for i in range(N):
  if max(A) != A[i]:
    print(sorted(A)[-1])
  else:
    print(sorted(A)[-2])

### FIXED CODE ###

N = int(input())
A = []
for i in range(N):
  A.append(int(input()))
B = sorted(A)

for i in range(N):
  if B[-1] != A[i]:
    print(B[-1])
  else:
    print(B[-2])