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


n = int(raw_input())
S = []
S = map(int, raw_input().split())

q = int(raw_input())
T = []
T = map(int, raw_input().split())

count = 0

for i in T:
	if i in S:
		count += 1

print count

### FIXED CODE ###

def binarySearch(S, key):
	left = 0
	right = len(S)
	while left < right:
		mid = (left + right) / 2
		if S[mid] == key:
			return True		
		elif key < S[mid]:
			right = mid
		else:
			left = mid + 1
	return False


n = int(raw_input())
S = []
S = map(int, raw_input().split())

q = int(raw_input())
T = []
T = map(int, raw_input().split())
count = 0
for key in T:
	if binarySearch(S, key):
		count += 1
print count
### BUGGY CODE ###

# coding: utf-8 
# Your code here!
import sys 
sys.setrecursionlimit(100000000)

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

l=[[i] for i in range(N)] 

#print(l) 
def dfs(num,point,visited): 
    visited[num]=1 
    point+=plus[num] 
    
    ans[num]=point 
    while l[num][-1]!=num: 
        temp=l[num].pop(-1) 
        if visited[temp]==0: 
            dfs(temp,point,visited) 
            
    return 0 

for _ in range(N-1): 
    a,b=map(int,input().split()) 
    l[a-1].append(b-1) 
    l[b-1].append(a-1) 
    
ans=[0]*N 
plus=[0]*N 

for _ in range(Q): 
    p,x=map(int,input().split()) 
    plus[p-1]+=x 

dfs(0,0,[0]*N) 

print(*ans)


### FIXED CODE ###

# coding: utf-8
# Your code here!
#パクリゆるして
#グラフのようななにか

import sys
input=sys.stdin.readline
sys.setrecursionlimit(1000000)

from collections import deque


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

tree=[[]*(N+1) for i in range(N+1)]
point=[0]*(N+1)

for _ in range(N-1):
    a,b=map(int,input().split())
    tree[a].append(b)
    tree[b].append(a)
    
for _ in range(Q):
    p,x=map(int,input().split())
    point[p]+=x
#print(point)

d=deque([[1,0]])

while d:
    node,parent=d.popleft()
    point[node]+=point[parent]
    lis=tree[node]
    for child in lis:
        if child==parent:
            continue
        d.append([child,node])
    #print(d)

print(*point[1:])
### BUGGY CODE ###

#初期入力
S = input()
Q = int(input())
FQ_dic =tuple()
rev =0
for i in range(Q):
    FQ_dic =tuple(input().split())

    if      FQ_dic[0] =="1": #逆転する
                rev +=1
    else:                   #逆転なし   
        if      FQ_dic[1]=="1":     #後ろにつける
            if rev %2 ==0:
                    S = FQ_dic[2] + S
            else:
                    S = S +FQ_dic[2] 
        else: #                      #前につける
            if rev %2 ==0:
                    S = S + FQ_dic[2]
            else:        
                    S = FQ_dic[2] + S
if rev %2 ==0:
    print(S)
else:
    print(S[::-1])

### FIXED CODE ###

#前・左につける変数、後ろ・右につける変数を用意して最後に足す
#前・左は最後にひっくり返す（abc ⇒cba)

#初期入力
import sys
input = sys.stdin.readline
S = input()
S=S.strip("\n")
Q = int(input())
FQ_dic={}
for i in range(Q):
    FQ_dic[i] =input().split()

rev =0
front =""
back =""

for i in range(Q):
   # print(S) 

    if FQ_dic[i][0] =="1": #逆転する
                rev +=1
    else:                   #逆転なし  
        if FQ_dic[i][1]=="1":     #前=左につける 
            if rev %2 ==0:
                front += FQ_dic[i][2]
            else:
                back  += FQ_dic[i][2]  
        else: #                      #後ろ=右につける
            if rev %2 ==0:
                back  += FQ_dic[i][2]  
            else:        
                front += FQ_dic[i][2]
front =front[::-1]
S =front + S + back

if rev %2 ==0:
    print(*S,sep="")
else:
    print(*S[::-1],sep="")
### BUGGY CODE ###

import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    N = I()

    ng = 0
    ok = N
    print(ng)
    ng_s = SS()
    ok_s = ng_s
    while abs(ok-ng)>1:
        m = (ng+ok)//2
        print(m)
        s = SS()
        if s == 'Vacant':
            break
        elif (ok - m) % 2 == 1 and ok_s != s or (ok - m) % 2 == 0 and ok_s == s:
            ok = m
            ok_s = s
        else:
            ng = m
            ng_s = s



if __name__ == '__main__':
    resolve()


### FIXED CODE ###

import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    N = I()

    ng = 0
    ok = N
    print(ng, flush=True)
    ng_s = SS()
    ok_s = ng_s
    while abs(ok-ng)>1:
        m = (ng+ok)//2
        print(m, flush=True)
        s = SS()
        if s == 'Vacant':
            sys.exit()
        elif (ok - m) % 2 == 1 and ok_s != s or (ok - m) % 2 == 0 and ok_s == s:
            ok = m
            ok_s = s
        else:
            ng = m
            ng_s = s

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

X,Y,A,B,C = map(int,input().split())

p = sorted(list(map(int,input().split()))) #A
q = sorted(list(map(int,input().split()))) #B
r = sorted(list(map(int,input().split()))) #C

xlist = p[-X:] #X
ylist = q[-Y:] #Y

def main(X,Y,xlist,ylist,r):
    for i in range(min(X,Y)):
        if xlist[i] < ylist[i] and min(xlist) < max(r):
            xlist.remove(min(xlist))
            xlist.append(max(r))
            r.pop()
        elif ylist[i] < xlist[i] and min(ylist) < max(r):
            ylist.remove(min(ylist))
            ylist.append(max(r))
            r.pop()
        else:
            continue
    
    print(sum(xlist)+sum(ylist))

main(X,Y,xlist,ylist,r)

### FIXED CODE ###

X,Y,A,B,C = map(int,input().split())

p = sorted(list(map(int,input().split()))) #A
q = sorted(list(map(int,input().split()))) #B
r = sorted(list(map(int,input().split()))) #C

xlist = p[-X:] #X
ylist = q[-Y:] #Y

"""
def main(X,Y,xlist,ylist,r):
    for i in range(min(X,Y)):
        if xlist[i] < ylist[i] and min(xlist) < max(r):
            xlist.remove(min(xlist))
            xlist.append(r.pop())
            
        elif ylist[i] < xlist[i] and min(ylist) < max(r):
            ylist.remove(min(ylist))
            ylist.append(r.pop())
            
        elif min(xlist) >= max(r) and min(ylist) >= max(r):
            break
        else:
            continue
    
    print(sum(xlist + ylist))

main(X,Y,xlist,ylist,r)
"""
all_apples = sorted(xlist + ylist + r)
print(sum(all_apples[-(X+Y):]))
### BUGGY CODE ###

#coding=utf-8

def solve(A, B):
    count = 0
    for b in range(B + 1, A + 1):
        for a in range(1, A + 1):
            if a % b >= B:
                count += 1
    return count

def main():
    A, B = input().split(' ')
    print(solve(int(A), int(B)))


if __name__ == '__main__':
    main()



### FIXED CODE ###

#coding=utf-8

def solve(N, K):
    count = 0
    if K == 0:
        return N * N
    for b in range(K + 1, N + 1):
        p = N // b
        r = N % b
        count += p * (b - K)
        if r >= K:
            count += r - K + 1
    return count

def main():
    A, B = input().split(' ')
    print(solve(int(A), int(B)))


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

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

ans = 0

for i in range(1, len(P)+1):
    M = min(P[:i])
    if P[i-1] == M:
        ans = ans +1

print(ans)

### FIXED CODE ###

N = int(input())
P = list(map(int,input().split()))
m = float("inf")
count = 0

for i in P:
    if m > i:
        m = i
    if m == i:
        count += 1
print(count)
### BUGGY CODE ###

#c
import sys
sys.setrecursionlimit(10000)
n,m = map(int,input().split())
a=[]
for i in range(m):
    a.append(int(input()) )
mod=10**9 + 7

def cmb(n, r, m,g1,g2):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % m

def nCrMOD(n,r,m):
    g1 = [1, 1]
    g2 = [1, 1]
    inverse = [0, 1]
    for i in range( 2, n + 1 ):
        g1.append( ( g1[-1] * i ) % m )
        inverse.append( ( -inverse[m % i] * (m//i) ) % m )
        g2.append( (g2[-1] * inverse[-1]) % m )
    return cmb(n,r,m,g1,g2)


c=0
for i in range(m-1):
    if a[i]==a[i+1]-1: c+=1
if c!=0:
    print(0)
elif m==0:
     print( sum( nCrMOD(n-i,i,mod) for i in range(n//2+1) )%mod )
    
    
else:
    b=[a[0]-1] + [a[j+1]-a[j]-2 for j in range(m-1)] + [n-a[-1]-1]
    cc=[ sum( nCrMOD(bb-i,i,mod) for i in range(bb//2+1) )%mod for bb in b ]

    ans=1
    for ccc in cc:
        ans = ans*ccc%mod
    print(ans)

### FIXED CODE ###

#c dp version
n,m = map(int,input().split())
a=[]
for i in range(m):
    a.append(int(input()) )
from collections import deque
a=deque(a)
mod=10**9 + 7

dp=[0]*(n+2)
dp[0]=0
dp[1]=1
aa=0
if len(a)>0:
    aa=a.popleft()
for i in range(2,n+2):
    if i-1 == aa:
        dp[i]=0
        if len(a)>0:
            aa=a.popleft()
    else:
        dp[i]=( dp[i-1]+dp[i-2] )%mod
print(dp[-1])
### BUGGY CODE ###

import math
def isPrime(n):
  if n<2:
    return False
  if n == 2:
    return True
  if n % 2 == 0:
    return False
  m = math.floor(math.sqrt(n))
  for p in range(3,n+1,2):
      if n % p == 0:
        return False
      if p > m:
        # 素数がnの平方根を超えたら終了
        break
  return True
N=int(input())
if isPrime(N):
    print(1)
else:
    n=N
    count=0
    s=0
    S=0
    for i in range(2,N+1):
        if n<i:
            break
        s=0
        count=0
        while 1:
            if n%i!=0:
                break
            count+=1
            n=int(n/i)
        while 1:
            if count<int(s*(s+1)/2):
                S+=s-1
                break
            s+=1
    print(S)
            









### FIXED CODE ###

import math
def isPrime(n):
  if n<2:
    return False
  if n == 2:
    return True
  if n % 2 == 0:
    return False
  m = math.floor(math.sqrt(n))
  for p in range(3,n+1,2):
      if n % p == 0:
        return False
      if p > m:
        # 素数がnの平方根を超えたら終了
        break
  return True
N=int(input())
if isPrime(N):
    print(1)
else:
    n=N
    count=0
    s=0
    S=0
    for i in range(2,N+1):
        if n<i:
            break
        s=1
        count=0
        while 1:
            if n%i!=0:
                break
            count+=1
            n=int(n/i)
        while 1:
            if count<int(s*(s+1)/2):
                S+=s-1
                break
            s+=1
        if i==10000:
            if isPrime(n):
                S+=1
                break
    print(S)
### BUGGY CODE ###

from collections import Counter

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

c = Counter(a)

dp = [[[0.0 for _ in range(n+1)] for _ in range(n+1)] for _ in range(n+1)]

for z in range(c[3] + 1):
    for y in range(c[2]+1 + c[3] - z):
        for x in range(n+1 - z - y):
            if x + y + z == 0:
                continue
            ret = 0.0
            if x > 0:
                ret += dp[x-1][y][z] * x
            if y > 0:
                ret += dp[x+1][y-1][z] * y
            if z > 0:
                ret += dp[x][y+1][z-1] * z
            dp[x][y][z] = (ret + n) / (x + y + z)

print(dp[c[1]][c[2]][c[3]])


### FIXED CODE ###

from collections import Counter

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

c = Counter(a)

dp = [[[0.0 for _ in range(n+1)] for _ in range(n+1)] for _ in range(n+1)]

for z in range(c[3] + 1):
    for y in range(c[2]+1 + c[3] - z):
        for x in range(n+1 - z - y):
            if x + y + z == 0:
                continue
            ret = 0.0
            if x > 0:
                ret += dp[x-1][y][z] * x
            if y > 0:
                ret += dp[x+1][y-1][z] * y
            if z > 0:
                ret += dp[x][y+1][z-1] * z
            dp[x][y][z] = (ret + n) / (x + y + z)

print(dp[c[1]][c[2]][c[3]])
### BUGGY CODE ###

make=False
def check_possible(req,num,cur,count):
  if cur<num:
    check_possible(req,num,cur+2,count+1)
    check_possible(req,num,cur+4,count+1)
  if cur==num:
    if count==req:
      global make
      make=True
req,num=list(map(int,input().split()))
check_possible(req,num,0,0)
if make:
  print('Yes')
else:
  print('No')

### FIXED CODE ###

make=False
def check_possible(req,num):
  for i in range(0,req+1):
      for j in range(0,req+1):
          if 2*i+4*j==num and i+j==req:
              return True
  return False
req,num=list(map(int,input().split()))
if check_possible(req,num):
  print("Yes")
else:
  print("No")
### BUGGY CODE ###

import sys
input = sys.stdin.readline
import heapq

def main():
    X, Y, Z, K = [int(x) for x in input().split()]
    A = [int(x) for x in input().split()]
    B = [int(x) for x in input().split()]
    C = [int(x) for x in input().split()]

    ans = []
    for a in A:
        for b in B:
            for c in C:
                heapq.heappush(ans, -(a + b + c))

    for _ in range(K):
        print(-heapq.heappop(ans))



if __name__ == '__main__':
    main()



### FIXED CODE ###

import sys
input = sys.stdin.readline

def main():
    X, Y, Z, K = [int(x) for x in input().split()]
    A = [int(x) for x in input().split()]
    B = [int(x) for x in input().split()]
    C = [int(x) for x in input().split()]

    ans = []
    for a in A:
        for b in B:
            ans.append(a + b)

    ans_s = sorted(ans, reverse=True)

    ans2 = []
    for a in ans_s[:3000]:
        for c in C:
            ans2.append(a + c)

    ans2_s = sorted(ans2, reverse=True)

    for i in range(K):
        print(ans2_s[i])


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

from fractions import gcd
# def GCD(a: int, b: int) -> int:
#     return a if b == 0 else GCD(b, a % b)


class SegTree():
    def __init__(self, n_, ele_id, operation_func):
        self.n = 1
        while self.n < n_:
            self.n *= 2
        self.data = [ele_id] * (2 * self.n - 1)
        self.ele_id = ele_id
        self.operation_func = operation_func

    def __getitem__(self, idx):
        return self.data[idx + self.n - 1]

    def init(self, data_init):
        for i in range(len(data_init)):
            self.data[i + self.n - 1] = data_init[i]
        for i in range(self.n - 2, -1, -1):
            self.data[i] = self.operation_func(self.data[2 * i + 1],
                                               self.data[2 * i + 2])

    def update(self, idx, x):
        # idx番目の要素をxに更新する
        idx += self.n - 1
        self.data[idx] = x
        while idx > 0:
            idx = (idx - 1) // 2
            self.data[idx] = self.operation_func(self.data[2 * idx + 1],
                                                 self.data[2 * idx + 2])

    def query(self, a, b):
        return self.query_(a, b, 0, 0, self.n)

    def query_(self, a, b, k, l, r):
        # [a, b)の最小値を求める
        if r <= a or b <= l:
            # [a, b)が[l, r)と交差しない
            return self.ele_id

        if a <= l and r <= b:
            # [a, b)が[l, r)を完全に含む
            return self.data[k]
        else:
            # [a, b)と[l, r)は一部被る
            child_l = self.query_(a, b, 2 * k + 1, l, (l + r) // 2)
            child_r = self.query_(a, b, 2 * k + 2, (l + r) // 2, r)
            return self.operation_func(child_l, child_r)


n = int(input())
a = list(map(int, input().split()))
seg_gcd = SegTree(n, 0, gcd)
seg_gcd.init(a)

ans = seg_gcd.data[0]
for i in range(n):
    seg_gcd.update(i, 0)
    ans = max(ans, seg_gcd.data[0])
    seg_gcd.update(i, a[i])

print(ans)


### FIXED CODE ###

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

def GCD(a: int, b: int) -> int:
    return a if b == 0 else GCD(b, a % b)

l = [0]
r = [0]
for i in range(n):
    l.append(GCD(l[i], a[i]))
    r.append(GCD(r[i], a[n-1 - i]))
r = r[::-1]

ans = 1
for i in range(n):
    ans = max(ans, GCD(l[i], r[i+1]))

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

from collections import deque
N = int(input())
X = [[] for _ in range(N)]
for i in range(N):
    s = input()
    for j in range(N):
        if s[j] == "1":
            X[i].append(j)

def bipartite(n, E):
    col = [-1] * n
    que = deque([[0, 0]])
    f = 0
    while que:
        v, c = que.popleft()
        col[v] = c
        for ne in E[v]:
            if col[ne] == c:
                f = 1
                break
            if col[ne] < 0:
                que.append([ne, 1-c])

        if f:
            break
    return 1-f

def BFS(n, E, i0=0):
    Q = deque([i0])
    D = [-1] * n
    D[i0] = 0
    while Q:
        x = Q.popleft()
        for c in E[x]:
            if D[c] == -1:
                D[c] = D[x] + 1
                Q.append(c)
    return D

if bipartite(N, X):
    print(max([max(BFS(N, X, i)) for i in range(N)])+1)
else:
    print(-1)


### FIXED CODE ###

from collections import deque
N = int(input())
X = [[] for _ in range(N)]
for i in range(N):
    s = input()
    for j in range(N):
        if s[j] == "1":
            X[i].append(j)

def bipartite(n, E):
    col = [-1] * n
    f = 0
    for i in range(n):
        if col[i] >= 0: continue
        que = deque([[i, 0]])
        while que:
            v, c = que.popleft()
            if col[v] == -1:
                col[v] = c
            elif col[v] == c:
                continue
            else:
                f = 1
                break
            for ne in E[v]:
                if col[ne] == c:
                    f = 1
                    break
                if col[ne] < 0:
                    que.append([ne, 1-c])

            if f:
                break
        if f:
            break
    return 1-f

def BFS(n, E, i0=0):
    Q = deque([i0])
    D = [-1] * n
    D[i0] = 0
    while Q:
        x = Q.popleft()
        for c in E[x]:
            if D[c] == -1:
                D[c] = D[x] + 1
                Q.append(c)
    return D

if bipartite(N, X):
    print(max([max(BFS(N, X, i)) for i in range(N)])+1)
else:
    print(-1)
### BUGGY CODE ###


#! //Users/daigofujiwara/anaconda3/bin python3

#h行で列和がyかy+1であるかどうかとサンプルを出力

input1=input()

input2=input()

x,y=input1.split(" ")
N,M=int(x),int(y)

A=input2.split(" ")

A=[int(a) for a in A ]

B=[]
for a in A:
    B.append(a//2)

count=0

for i in range(1,M+1):
    T=1
    for b in B:
        if not ((i//b)%2==1 and i%b==0):
            T=0
    if T==1:
        count+=1

print(count)




### FIXED CODE ###

import math
from functools import reduce
from fractions import gcd

def lcm_base(x, y):
    return (x * y) // gcd(x, y)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)
#! //Users/daigofujiwara/anaconda3/bin python3

#h行で列和がyかy+1であるかどうかとサンプルを出力

input1=input()

input2=input()

x,y=input1.split(" ")
N,M=int(x),int(y)

A=input2.split(" ")

A=[int(a) for a in A ]

B=[]
for a in A:
    B.append(a//2)


Mb=lcm_list(B)
gmp=None


T=1
for b in B:
    if not (Mb//b)%2==1:
        T=0
if T==1:
    gmp=Mb




if gmp is None:
    print(0)
else:
    print(int(math.floor(M/gmp+1.0)/2.0))
### BUGGY CODE ###

q = int(input())

l = []
x = ""
y = ""
def lcs(yIndex, xIndex):
    global l, x, y
    if xIndex < 0 or yIndex < 0:
        return 0
    elif l[yIndex][xIndex] != -1:
        return l[yIndex][xIndex]
    elif x[xIndex] == y[yIndex]:
        return 1 + lcs(yIndex - 1, xIndex - 1)
    else:
        return max(lcs(yIndex, xIndex - 1), lcs(yIndex - 1, xIndex))

for i in range(q):
    x = input()
    y = input()

    l = [[-1] * len(x) for j in range(len(y))]

    for j in range(len(y)):
        for k in range(len(x)):
            l[j][k] = lcs(j, k)

    print(l[len(y)- 1][len(x) - 1])


### FIXED CODE ###

q = int(input())

for i in range(q):
    x = input()
    y = input()
 
    l = []
    for j, s in enumerate(x):
        l.append([])
        l[j].append(-1)
        if j == 0:
            endPos = y.find(s)
            if endPos != -1: 
                l[j].append(endPos)
        else:
            for k, t in enumerate(l[j - 1][:-1]):
                endPos = y.find(s, t + 1)
                if endPos != -1:
                    l[j].append(min(endPos, l[j - 1][k + 1]))
                else:
                    l[j].append(l[j - 1][k + 1])
            endPos = y.find(s, l[j - 1][-1] + 1)
            if endPos != -1:
                l[j].append(endPos)

    print(len(l[-1]) - 1)
### BUGGY CODE ###

N, M = map(int, input().split())
edges = [[0, 0] for _ in range(M)]
for i in range(M):
    edges[i][0], edges[i][1] = map(int, input().split())

stack = list(range(1, N+1))
# dp[n]: nに到達する最長のパス
dp = [0] * N
while stack:
    n = stack.pop()
    childs = [edge[1] for edge in edges if edge[0] == n]
    for nc in childs:
        stack.append(nc)
        if dp[nc-1] < dp[n-1] + 1:
            dp[nc-1] = dp[n-1] + 1

print(max(dp))


### FIXED CODE ###

import sys
sys.setrecursionlimit(100000)

N, M = map(int, input().split())
childs = [[] for _ in range(N)]
for i in range(M):
    p, c = map(int, input().split())
    childs[p-1].append(c-1)

depth = [-1] * N
def dfs(n):
    if depth[n] != -1:
        return depth[n]
    if childs[n]:
        depth[n] = max((dfs(nc) for nc in childs[n])) + 1
    else:
        depth[n] = 0
    return depth[n]

print(max((dfs(n) for n in range(N))))
### BUGGY CODE ###

N = int(input())
A = list(map(int, input().split()))
for i in range(1,N+1):
	print(A.count(i))

### FIXED CODE ###

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

B = [0]*N
for i in range(N-1):
	B[A[i]-1] += 1
for i in range(N):
	print(B[i])
### BUGGY CODE ###

import sys
input = sys.stdin.readline
N = int(input())
A = [list(map(int, input().split())) for i in range(N)]
index = [0]*(N+1)

ans = -1
for _ in range(600000):
    today = [True]*(N+1)
    flag = 0
    for j in range(N):
        if not today[j+1]:
            continue
        if index[j+1] >= N-1:
            continue
        #print(j, index[j+1])
        opponent = A[j][index[j+1]]
        if today[j+1] and today[opponent] and A[opponent-1][index[opponent]] == j+1:
            index[opponent] += 1
            index[j+1] += 1
            today[opponent] = False
            today[j+1] = False
            flag = 1
    ans += 1
    if flag == 0:
        if sum(index) == N*(N-1):
            break
        else:
            ans = -1
            break
    #print(index)

print(ans)


### FIXED CODE ###

import sys
input = sys.stdin.readline
N = int(input())
A = []
for i in range(N):
    A.append(list(map(int, input().split())))
index = [0]*(N+1)
ans = -2
for k in range(10000):
    today = set()
    flag = 0
    for j in range(N):
        if j+1 in today:
            continue
        if index[j+1] >= N-1:
            continue
        #print(j, index[j+1])
        opponent = A[j][index[j+1]]
        if A[opponent-1][index[opponent]] == j+1:
            if opponent not in today:
                index[opponent] += 1
                index[j+1] += 1
                today.add(opponent)
                today.add(j+1)
                flag = 1
    if flag == 0:
        if sum(index) == N*(N-1):
            ans = k
            break
        else:
            ans = -1
            break
    #print(index)

if ans == -2:
    print(N*(N-1)//2)
else:
    print(ans)
### BUGGY CODE ###

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

for i in range(n):
    l = a[i+1:]
    r = a[:i]
    ans = l + r
    print(max(ans))

### FIXED CODE ###

n = int(input())
a = [int(input()) for _ in range(n)] + [0]

sorted_a = sorted(a)
a_first = sorted_a[-1]
a_second = sorted_a[-2]

for i in range(n):
    if a[i] == a_first:
        print(a_second)
    else:
        print(a_first)