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

from collections import defaultdict


def dfs(graph, start):
    visited, stack = set(), [start]
    while stack:
        vertex = stack.pop()
        if vertex not in visited:
            visited.add(vertex)
            stack.extend(graph[vertex] - visited)
    return visited


if __name__ == "__main__":
    n, m, k = map(int, input().split())
    AB = [map(int, input().split()) for _ in range(m)]
    CD = [map(int, input().split()) for _ in range(k)]

    graph_f = defaultdict(set)
    graph_b = defaultdict(set)

    for a, b in AB:
        graph_f[a - 1].add(b - 1)
        graph_f[b - 1].add(a - 1)

    for c, d in CD:
        graph_b[c - 1].add(d - 1)
        graph_b[d - 1].add(c - 1)

    visited = set()
    conns = []
    for i in range(n):
        if i not in visited:
            conn = dfs(graph_f, i)
            visited |= conn
            conns.append(conn)

    res = []
    for i in range(n):
        suggestion_cnt = 0
        current_conn = list(filter(lambda x: i in x, conns))[0]
        for j in range(n):
            if i == j:
                continue
            else:
                if j in current_conn and j not in graph_f[i] and j not in graph_b[i]:
                    suggestion_cnt += 1
        res.append(suggestion_cnt)

    print(' '.join(map(str, res)))


### FIXED CODE ###

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 same(self, x, y):
        return self.find(x) == self.find(y)

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


if __name__ == "__main__":
    n, m, k = map(int, input().split())

    u = UnionFind(n)
    f_cnt = [0] * n
    b_cnt = [0] * n

    for _ in range(m):
        a, b = map(int, input().split())
        u.union(a - 1, b - 1)
        f_cnt[a - 1] += 1
        f_cnt[b - 1] += 1

    for _ in range(k):
        c, d = map(int, input().split())
        if u.same(c - 1, d - 1):
            b_cnt[c - 1] += 1
            b_cnt[d - 1] += 1

    print(*[(u.size(i) - f_cnt[i] - b_cnt[i] - 1) for i in range(n)])
### BUGGY CODE ###

#coding:utf-8
import itertools

n = int(input())
numbers = list(map(int, input().split()))
count = 0

for item in itertools.combinations(numbers, 2):
    if item[0] > item[1]:
        count += 1

print(count)

### FIXED CODE ###

#coding:utf-8
#1_5_D

def merge(array, left, mid, right):
    global cnt
    L = array[left:mid]  + [SENTINEL]
    R = array[mid:right] + [SENTINEL]
    i = j = 0

    for k in range(left, right):
        if L[i] <= R[j]:
            array[k] = L[i]
            i += 1
        else:
            array[k] = R[j]
            j += 1
            cnt += len(L) - 1 - i

def merge_sort(array, left, right):
    if left + 1 < right:
        mid = (left + right) // 2
        merge_sort(array, left, mid)
        merge_sort(array, mid, right)
        merge(array, left, mid, right)

n = int(input())
numbers = list(map(int, input().split()))
cnt = 0
SENTINEL = 10 ** 9 + 1
merge_sort(numbers, 0, len(numbers))
print(cnt)
### BUGGY CODE ###

"""
import sys
input = sys.stdin.readline
#"""
def main():
    N=int(input())
    A = [list(map(int,input().split())) for _ in [0]*N]

    V = {(i,j):0 for i in range(N) for j in range(i+1,N)}
    Ef = {(i,j):[] for i in range(N) for j in range(i+1,N)}
    for i,B in enumerate(A):
        a0 = B[0]-1
        k1 = (i,a0) if i<a0 else (a0,i)
        for a1 in B[1:]:
            a1 -= 1
            k0 = k1
            k1 = (i,a1) if i<a1 else (a1,i)
            Ef[k0].append(k1)
            V[k1] += 1

    q = [k for k in V if V[k] == 0]
    ans = 0
    rmv = 0
    while q:
        qq = []
        for k in q:
            for k2 in Ef[k]:
                V[k2] -= 1
                rmv += 1
                if V[k2] == 0 : qq.append(k2)
        ans += 1
        q = qq
    if rmv != N*(N-2) : ans = -1
    print(ans)
main()

### FIXED CODE ###

#"""
import sys
input = sys.stdin.readline
#"""
def main():
    def get_key(i,j):
        if i<j: i,j = j,i
        return i*N+j
    N=int(input())
    A = [list(map(int,input().split())) for _ in [0]*N]
    V = [-1]*(N*N)
    for i in range(N):
        for j in range(i+1,N):
            V[get_key(i,j)] = 0
    Ef = [[] for _ in V]

    for i,B in enumerate(A):
        a0 = B[0]-1
        k1 = (i,a0)
        for a1 in B[1:]:
            a1 -= 1
            k0 = k1
            k1 = (i,a1)
            Ef[get_key(*k0)].append(get_key(*k1))
            V[get_key(*k1)] += 1

    q = [i for i,v in enumerate(V) if v == 0]
    ans = 0
    rmv = 0
    while q:
        qq = []
        for i in q:
            for j in Ef[i]:
                V[j] -= 1
                rmv += 1
                if V[j] == 0 : qq.append(j)
        ans += 1
        q = qq
    if rmv != N*(N-2) : ans = -1
    print(ans)
main()
### BUGGY CODE ###

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

d = 0
ans = 0

for i in range(1, n):
  f = 1 if i == 1 else f * (i-1) % mod
  d = d * i + f
  ans = (ans * i + (l[i] - l[i-1]) * d) % mod

print(ans)

### FIXED CODE ###

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

d = 0
ans = 0

for i in range(1, n):
  f = 1 if i == 1 else f * (i-1) % mod
  d = (d * i + f) % mod
  ans = (ans * i + (lx[i] - lx[i-1]) * d) % mod

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


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

rei=list(map(int, input().split())) 
den=list(map(int, input().split())) 
cou = [0] * m
ans = []
for i in range(m):
	cou[i]=list(map(int, input().split()))
	ans.append(rei[cou[i][0]-1]+den[cou[i][1]-1]-cou[i][2])
	
for i in range(len(den)):
	for j in range(len(rei)):
		ans.append(rei[j]+den[i])

print(min(ans))

### FIXED CODE ###

m=list(map(int, input().split()))
rei=list(map(int, input().split())) 
den=list(map(int, input().split())) 
cou = [0] * m[2]
ans = []
for i in range(m[2]):
	cou[i]=list(map(int, input().split()))
	ans.append(rei[cou[i][0]-1]+den[cou[i][1]-1]-cou[i][2])

ans.append(min(rei)+min(den))
print(min(ans))
### BUGGY CODE ###

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

k = min(k, n-1)
dp = [0] * (n+1)
diff = [[0] * (n) for _ in range(n)]
for i in range(0, n-1):
    for j in range(i+1, n):
        diff[i][j] = diff[j][i] = abs(h[i] - h[j])

for i in range(2, k+1):
    dp[i] = min([dp[ki] + diff[i-1][ki-1] for ki in range(1,i)])

for i in range(k+1, n+1):
    dp[i] = min([dp[i-ki] + diff[i-1][i-1-ki] for ki in range(1,k+1)])

print(dp[n])

### FIXED CODE ###

import numpy as np

n, k = list(map(int, input().split()))
h = np.array(list(map(int, input().split())))

k = min(k, n-1)
dp = np.zeros(n+1)

for i in range(2, k+1):
    dp[i] = np.min(dp[1:i] + np.abs(h[i-1] - h[0:i-1]))

for i in range(k+1, n+1):
    dp[i] = (dp[i-k:i] + np.abs(h[i-1] - h[i-k-1:i-1])).min()
    
print(int(dp[n]))
### BUGGY CODE ###

N=int(input())
a=input().split()
A=[int(b) for b in a]
answers=[]
for n in range(1,N):
    first=sum(A[:n])
    last=sum(A[n:])
    answers.append(abs(first-last))
print(min(answers))


### FIXED CODE ###

N=int(input())
a=input().split()
a=[int(b) for b in a]
numbers=[]
number=0
for a_ in a:
    number+=a_
    numbers.append(number)
del numbers[-1]
if N==2:
    print(abs(a[0]-a[1]))
else:
    whole=sum(a)
    answers=[]
    for number in numbers:
        answer=abs(number*2-whole)
        answers.append(answer)
    print(min(answers))
### BUGGY CODE ###

def main():
  from collections import Counter
  n = int(input())
  s = input()
  mod = 10**9+7
  c = Counter(s)
  cv = list(c.values())
  cl = len(cv)
  ans = 0
  for i in range(1,1<<cl):
    da =1
    for j in range(cl):
      if (i>>j)%2:
        da *= cv[j]
    ans += da%mod
  print(ans%mod)
main()

### FIXED CODE ###

def main():
  from collections import Counter
  n = int(input())
  s = input()
  mod = 10**9+7
  c = Counter(s)
  cv = list(c.values())
  cl = len(cv)
  ans = 1
  for i in range(cl):
    ans *= (cv[i]+1)
  print((ans-1)%mod)
main()
### BUGGY CODE ###

n=int(input())
a=[int(i) for i in input().split()]
ans=n
for i in range(n-1):
    w=x=a[i]
    for j in range(i+1,n):
        w+=a[j]
        x^=a[j]
        if w!=x: break
        ans+=1
print(ans)

### FIXED CODE ###

def sol():
    n=int(input())+1
    a=[int(i) for i in input().split()]+[2**21-1]
    ans=0
    i=j=w=x=0
    while i<n-1:
        while j<n and w==x:
            w+=a[j]
            x^=a[j]
            j+=1
        ans+=(j-i-1)
        w-=a[i]
        x^=a[i]
        i+=1
    print(ans)

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

import sys 
input = sys.stdin.readline
# ABC140E
class SegTree:
    def __init__(self, init_val, n, ide_ele, seg_func):
        self.segfunc = seg_func
        self.num = 2**(n-1).bit_length()
        self.ide_ele = ide_ele
        self.seg=[self.ide_ele]*2*self.num
        for i in range(n):
            self.seg[i+self.num-1]=init_val[i]    
        for i in range(self.num-2,-1,-1) :
            self.seg[i]=self.segfunc(self.seg[2*i+1],self.seg[2*i+2]) 
        
    def update(self, k, x):
        k += self.num-1
        self.seg[k] = x
        while k+1:
            k = (k-1)//2
            self.seg[k] = self.segfunc(self.seg[k*2+1],self.seg[k*2+2])
        
    def query(self, p, q):
        if q<=p:
            return self.ide_ele
        p += self.num-1
        q += self.num-2
        res=self.ide_ele
        while q-p>1:
            if p&1 == 0:
                res = self.segfunc(res,self.seg[p])
            if q&1 == 1:
                res = self.segfunc(res,self.seg[q])
                q -= 1
            p = p//2
            q = (q-1)//2
        if p == q:
            res = self.segfunc(res,self.seg[p])
        else:
            res = self.segfunc(self.segfunc(res,self.seg[p]),self.seg[q])
        return res

n,Q=map(int,input().split())
xs,qs,tmp = [],[],set()
for _ in range(n):
    s,t,x=map(int,input().split())
    s,t,x=s-x-0.5,t-x-0.5,x
    xs += [(s,1,x), (t,0,x)]
    tmp.add(x)
for _ in range(Q):
    qs.append(int(input()))

xs.sort()
mx = max(tmp) + 1
tmp = list(tmp)
x2i = dict()
for i, x in enumerate(tmp):
    x2i[x] = i

qi = 0
q = qs[qi]
XN = len(tmp)
st = SegTree([mx]*XN, XN, mx, min)
for t,r,x in xs:
    if q < t:
        c = st.query(0,XN)
        while True:
            if q < t:
                print(c if c!= mx else -1)
                Q-=1
                if Q:
                    qi += 1
                    q = qs[qi]
                    continue
                sys.exit()
            break
    st.update(x2i[x], x if r else mx)
print("-1\n"*Q)

### FIXED CODE ###

import sys
input = sys.stdin.readline

n,Q=map(int,input().split())
b_num = 2**(n-1).bit_length()
mx = 10**9
segl=[mx]*2*b_num 

def update( k, x):
    k += b_num-1
    segl[k] = x
    while k+1:
        k = (k-1)//2
        segl[k] = min(segl[k*2+1],segl[k*2+2])
    
if __name__ == '__main__':
    xs = []
    for i in range(n):
        s,t,x=map(int,input().split())
        xs += [(s-x-0.4,True,x,i), (t-x-0.5,False,x,i)]
    for _ in range(Q):
        xs.append((int(input()),2))
    xs.sort(key=lambda x:x[0])
    for x in xs:
        if x[1]==2:
            print(segl[0] if segl[0]!= mx else -1)
            continue
        update(x[3], x[2] if x[1] else mx)
### BUGGY CODE ###

#!python3

import numpy as np

LI = lambda: list(map(int, input().split()))

# input
S = input()

MOD = 10 ** 9 + 7


def main():
    n = len(S)
    m = 5
    w = []
    p = 1
    for i in range(n):
        s = S[-1 - i]
        if s == "?":
            w.append(p)
        else:
            m = (m - int(s) * p) % 13
        p = p * 10 % 13

    n = len(w)
    l1 = np.zeros(13, dtype=int)
    l1[0] = 1
    for i in range(1, n + 1):
        l2 = np.zeros(13, dtype=int)
        for j in range(10):
            x = w[i - 1] * j % 13
            l2 += np.roll(l1, x)
        l2 %= MOD
        l1 = l2
    
    ans = l1[m]
    print(ans)


if __name__ == "__main__":
    main()


### FIXED CODE ###

#!python3

LI = lambda: list(map(int, input().split()))

# input
S = input()

MOD = 10 ** 9 + 7


def main():
    n = len(S)
    m = 5
    w = []
    p = 1
    for i in range(n):
        s = S[-1 - i]
        if s == "?":
            w.append(p)
        else:
            m = (m - int(s) * p) % 13
        p = p * 10 % 13

    n = len(w)
    l1 = [0] * 13
    l1[0] = 1
    for i in range(1, n + 1):
        l2 = [0] * 13
        for j in range(10):
            x = w[i - 1] * j % 13
            for k in range(13):
                t = (x + k) % 13
                l2[t] += l1[k]
        l1 = [y % MOD for y in l2]
    
    ans = l1[m]
    print(ans)


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

from collections import Counter
import sys
input = sys.stdin.buffer.readline

def main():
    n = int(input())
    lis = list(map(int,input().split()))
    ans = Counter(lis)
    for j in lis:
        su = 0
        for k, v in ans.items():
            if k == j:
                su += (v - 2) * (v - 1) // 2
            else:
                su += (v - 1) * v // 2
        print(su)

if __name__ == '__main__':
    main()

### FIXED CODE ###

from collections import Counter
import sys
input = sys.stdin.buffer.readline

def main():
    n = int(input())
    lis = list(map(int,input().split()))
    d = Counter(lis)
    su = 0
    for e in d:
        su += (d[e] - 1) * d[e] // 2

    for e in lis:
        if d[e] <= 1:
            print(su)
        else:
            k = d[e]
            res = su - k*(k-1)//2 + (k-1)*(k-2)//2
            print(res)

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

import sys
#input = sys.stdin.readline

n=int(input())
xs=input()
xk=list(map(int,list(xs)))
xj=xk.count(1)

x=int(xs,2)

def popcount(x):
    '''xの立っているビット数をカウントする関数
    (xは64bit整数)'''

    # 2bitごとの組に分け、立っているビット数を2bitで表現する
    x = x - ((x >> 1) & 0x5555555555555555)

    # 4bit整数に 上位2bit + 下位2bit を計算した値を入れる
    x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)

    x = (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f # 8bitごと
    x = x + (x >> 8) # 16bitごと
    x = x + (x >> 16) # 32bitごと
    x = x + (x >> 32) # 64bitごと = 全部の合計
    return x & 0x0000007f

for i in range(n-1,-1,-1):
    xi=x^(1<<i)
    pxi=xj
    if xk[n-1-i]==0:
        pxi=pxi+1
    else:
        pxi=pxi-1
    if xi==0:
        print(0)
    else:
        xi=xi%pxi
        if xi==0:
            print(1)
        else:
            icnt=1
            while xi>0:
                icnt+=1
                xi=xi%popcount(xi)
            print(icnt)


### FIXED CODE ###

import sys
def input(): return sys.stdin.readline().strip()

n=int(input())
xs=input()
xj=xs.count("1")

x=int(xs,2)
xip=x%(xj+1)
if xj!=1:
    xim=x%(xj-1)

for i in range(n-1,-1,-1):
    if xs[n-1-i]=="0":
        pxi=xj+1
        i2=pow(2,i,pxi)
        xi=(xip+i2)%pxi
    elif xj==1:
        print(0)
        continue
    else:
        pxi=xj-1
        i2=pow(2,i,pxi)
        xi=(xim-i2)%pxi
    xi=xi%pxi
    if xi==0:
        print(1)
        continue
    icnt=1
    while xi>0:
#        print("i",i,"xi",xi,"icnt",icnt)
        icnt+=1
        xi=xi%(bin(xi).count("1"))
    print(icnt)
### BUGGY CODE ###

s = input()
ans = [0 for _ in range(len(s))]
for i in range(len(s)-5, -1, -1):
    for j in range(i+4, len(s)):
        x = int(s[i:j+1])
        if x %2019 != 0:
            continue
        ans[i] += 1
        if j+1 < len(s):
            ans[i] += ans[j+1]
        break

print(sum(ans))

### FIXED CODE ###

import collections
S = list(map(int, input()))[::-1]
mod_list = [0 for _ in range(len(S)+1)]
x = 0
d = 0
for i, s in enumerate(S):
    x += s * pow(10, d, 2019)
    d += 1
    mod_list[i] = x%2019
c = collections.Counter(mod_list)
ans = 0
for i in range(2020):
    ans += c[i] * (c[i]-1)//2
print(ans)
### BUGGY CODE ###

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

B = [0] * (N + 1)
B[0] = 1
if 1 not in A:
    B[1] = 1
else:
    B[1] = 0
mod = 10**9 + 7

for i in range(2, N + 1):
    if i != 2 and i - 1 in A and i - 2 in A:
        print(0)
        exit()
    elif i - 2 in A:
        B[i] = B[i - 1]
    elif i - 1 in A:
        B[i] = B[i - 2]
    else:
        B[i] = B[i - 1] + B[i - 2]
    B[i] %= mod
print(B[N] % mod)


### FIXED CODE ###

import sys
input = sys.stdin.readline


def binary_search(l, value):
    low = 0
    high = len(l) - 1
    while low <= high:
        mid = (low + high) // 2
        if l[mid] == value:
            return True
        elif l[mid] < value:
            low = mid + 1
        else:
            high = mid - 1
    return False


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

A.append(10**6)
A.append(10**6)
B = [0] * (N + 1)
B[0] = 1
if binary_search(A, 1) is True:
    B[1] = 0
else:
    B[1] = 1
mod = 10**9 + 7

for i in range(2, N + 1):
    if i != 2 and binary_search(A, i - 1) is True and binary_search(
            A, i - 2) is True:
        print(0)
        exit()
    elif binary_search(A, i - 2) is True:
        B[i] = B[i - 1]
    elif binary_search(A, i - 1) is True:
        B[i] = B[i - 2]
    else:
        B[i] = B[i - 1] + B[i - 2]
    B[i] %= mod
print(B[N] % mod)
### BUGGY CODE ###

from collections import Counter
n = int(input())
S = [input() for _ in range(n)]

poll = dict(Counter(S))

ans = [k for k in poll.keys() if poll[k] == max(list(poll.values()))]
ans.sort()
for a in ans:
     print(a)

### FIXED CODE ###

from collections import Counter
n = int(input())
S = [input() for _ in range(n)]

poll = Counter(S)
max_c = max(list(poll.values()))
ans = [k for k in poll.keys() if poll[k] == max_c]
ans.sort()
for a in ans:
     print(a)
### BUGGY CODE ###

import collections
N = int(input())
a = list(map(int, input().split()))
a_c = collections.Counter(a)
Q = int(input())
BC = [list(map(int, input().split())) for _ in range(Q)]
S = [0]*Q

for i, bc in enumerate(BC):
  b = bc[0]
  c = bc[1]
  s = 0
  if b in a_c:
    a_c[c]+=a_c[b]
    del a_c[b]
  for k, v in a_c.items():
    s += k*v
  S[i] = s

[print(i) for i in S]

### FIXED CODE ###

import collections
N = int(input())
a = list(map(int, input().split()))
a_c = collections.Counter(a)
Q = int(input())
BC = [list(map(int, input().split())) for _ in range(Q)]
s_old = 0
for k, v in a_c.items():
    s_old += k*v
for bc in BC:
  b = bc[0]
  c = bc[1]
  s = s_old
  if b in a_c:
    n = a_c.pop(b)
    a_c[c]+=n
    s-=n*b
    s+=n*c
  print(s)
  s_old = s
### BUGGY CODE ###

n = int(input())
A = [int(i) for i in input().split()]

cnt = 0
for i in range(n):
    for j in range(i + 1, n + 1):
        if sum(A[i : j]) == 0:
            cnt += 1
            
print(cnt)

### FIXED CODE ###

from collections import Counter

def comb(n, k):
    k = min(k, n - k)
    result = 1
    for i in range(n, n - k, -1):
        result *= i
    for i in range(1, k + 1):
        result //= i 
    return result

n = int(input())
A = [int(i) for i in input().split()]

S = [0] * (n + 1)
for i in range(1, n + 1):
    S[i] = S[i - 1] + A[i - 1]
    
S = Counter(S)
ans = 0
for v in S.values():
    if v > 1:
        ans += comb(v, 2)
        
print(ans)
### BUGGY CODE ###

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

n_pears = 0
used_balls = []

for i in reversed(range(0, len(A))):
    if i in used_balls:
        continue
    for j in reversed(range(0, i)):
        if j in used_balls:
            continue
        if not (A[i] + A[j]) & (A[i] + A[j] - 1):
            n_pears += 1
            used_balls.append(i)
            used_balls.append(j)
            break

print(n_pears)

### FIXED CODE ###

import math
from collections import Counter


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

n_pears = 0
counter = Counter(A)

for i in reversed(range(0, len(A))):
    if counter[A[i]] <= 0:
        continue
    counter[A[i]] -= 1
    Aj = 2 ** int(math.log2(A[i]) + 1) - A[i]
    if counter[Aj] > 0:
        n_pears += 1
        counter[Aj] -= 1

print(n_pears)
### BUGGY CODE ###

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

### FIXED CODE ###

import sys
input = sys.stdin.readline

n, q = map(int, input().split())
s = input()
memo = [0] * n
cnt = 0

for i in range(1, n):
    if s[i - 1] == 'A' and s[i] == 'C':
        cnt += 1
    memo[i] = cnt

for i in range(q):
    l, r = map(int, input().split())
    print(memo[r - 1] - memo[l - 1])
### BUGGY CODE ###

import sys
input = sys.stdin.readline
#a = input().rstrip() 文字の時rstrip()で改行削除

N = int(input())
S = input().rstrip()

min = float("inf")
for i in range(N):
    cnt = 0
    for j in range(i):
        if S[j] != "E":
            cnt += 1
    for j in range(i+1, N):
        if S[j] != "W":
            cnt += 1
    if cnt < min:
        min = cnt

print(min)


### FIXED CODE ###

import sys
input = sys.stdin.readline

N = int(input())
S = input().rstrip()
W = [0] * N
E = [0] * N

cnt = 0
for i in range(1, N):
    if S[i-1] == "W":
        cnt += 1
        W[i] = cnt
    else:
        W[i] = cnt
cnt = 0
for i in reversed(range(N-1)):
    if S[i+1] == "E":
        cnt += 1
        E[i] = cnt
    else:
        E[i] = cnt

min = float("inf")
for i in range(N):
    if W[i] + E[i] < min:
        min = W[i] + E[i]
print(min)
### BUGGY CODE ###

N=int(input())
A=list(map(int,input().split()))
B=A
for i in range(N):
  x=A[i]
  A.pop(i)
  S=list(set(A))
  sum=0
  for j in range(len(S)):
    a=A.count(S[j])
    sum+=a*(a-1)//2
  A.insert(i,x)
  print(sum)

### FIXED CODE ###

n=int(input())
a=list(map(int,input().split()))
b=[0]*n
cnt=0
for i in a:
  b[i-1]+=1
for i in b:
  cnt+=i*(i-1)//2
for i in a:
  print(cnt+(1-b[i-1]))
### BUGGY CODE ###

N = input()
num = len(N)
mod_sum = [0]*2019
mod_sum[0] = 1
ans = 0
a = 0
for i in range(num):
  a += int(N[-i-1])*10**i
  mod = a%2019
  mod_sum[mod] += 1
for i in mod_sum:
  ans += i*(i-1)//2
print(ans)


### FIXED CODE ###

N = input()
num = len(N)
mod_sum = [0]*2019
mod_sum[0] = 1
ans = 0
a = 0
d = 1
for i in range(num):
  a = (a + int(N[-i-1])*d)%2019
  d = (d*10)%2019
  mod_sum[a] += 1
for i in mod_sum:
  ans += i*(i-1)//2
print(ans)
### BUGGY CODE ###

N = int(input())
A = []
for i in range(N):
    A.append(int(input()))
    
MAX1 = max(A)
MAX2 = -1
for i in range(N):
    if i != A.index(MAX1):
        MAX2 = max(MAX2,A[i])
        
if MAX1 == MAX2:
    for i in range(N):
        print(MAX1)
else:
    for i in range(N):
        if i == A.index(MAX1):
            print(MAX2)
        else:
            print(MAX1)
            
    

### FIXED CODE ###

N = int(input())
A = []
for i in range(N):
    A.append(int(input()))
    
MAX1 = max(A)
MAX2 = -1
index = A.index(MAX1)
for i in range(N):
    if i != index:
        MAX2 = max(MAX2,A[i])
        
if MAX1 == MAX2:
    for i in range(N):
        print(MAX1)
else:
    for i in range(N):
        if i == index:
            print(MAX2)
        else:
            print(MAX1)