Harryxun/stf_run huggingface dataset:
# Python3 (3.4.3)
import sys
input = sys.stdin.readline

# -------------------------------------------------------------
# function
# -------------------------------------------------------------


# -------------------------------------------------------------
# main
# -------------------------------------------------------------
S = input().rstrip()
T = input().rstrip()


idx = S.index(T[0])
ans = idx+1
for i in range(1,len(T)):
    S = S[idx+1:] + S[:idx+1]
    idx = S.index(T[i])
    ans += idx+1

print(ans)

### FIXED CODE ###

#!/usr/bin/env python3
#ABC138 E

import sys
import math
import bisect
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

s = input()
t = input()
n = len(s)
m = len(t)
f = [False]*26
f2 = [False]*26
alpha = 'abcdefghijklmnopqrstuvwxyz'
for i in range(n):
    f[alpha.index(s[i])] = True
for i in range(m):
    f2[alpha.index(t[i])] = True
for i in range(26):
    if not f[i] and f2[i]:
        print(-1)
        quit()
ans = 0
inde = s.index(t[0])
ans += inde+1
for i in range(1,m):
    s = s[inde+1:] + s[:inde+1]
    inde = s.index(t[i])
    ans += inde+1
print(ans)
#何曜日かを入力
weekday = input()
#日曜日までの日数を出力
if weekday == "SUN":
    print(7)
elif weekday == "MON":
    print(6)S
elif weekday == "TUE":
    print(5)
elif weekday == "WED":
    print(4)
elif weekday == "THU":
    print(3)
elif weekday == "FRI":
    print(2)
elif weekday == "SAT":
    print(1)

### FIXED CODE ###

#何曜日かを入力
weekday = input()
#日曜日までの日数を出力
if weekday == "SUN":
    print(7)
elif weekday == "MON":
    print(6)
elif weekday == "TUE":
    print(5)
elif weekday == "WED":
    print(4)
elif weekday == "THU":
    print(3)
elif weekday == "FRI":
    print(2)
elif weekday == "SAT":
    print(1)
#!/usr/bin/python
# coding: UTF-8

def main():
    A,B,M = list(map(int, input().split(' ')))
    a_list = list(map(int, input().split(' ')))
    b_list = list(map(int, input().split(' ')))

    price_list = 2*10**5
    for i in range(M):
        temp = list(map(int, input().split(' ')))
        if price_list > a_list[temp[0]-1] + b_list[temp[1]-1] - temp[2]:
            price_list = a_list[temp[0]-1] + b_list[temp[1]-1] - temp[2]

    lower = min(a_list) + min(b_list)
    if lower < price_list:
        print(lower)
    else:
        print(price_list)

if __name__=='__main__':
    main()


### FIXED CODE ###

#!/usr/bin/python
# coding: UTF-8

def main():
    arg = input()
    if arg in ['hi'*i for i in range(1,6)]:
        print('Yes')
    else:
        print('No')

if __name__=='__main__':
    main()
N = input()
ans = (N + 1) / 2
print(ans)

### FIXED CODE ###

N = input()
M = int(N)
jud = M % 2
if jud == 1:
    ans = M // 2 + 1
else:
    ans = M // 2
print(ans)
N = int(input())
li = ['']
so = 0
for _ in range(9):
  l = len(li)
  for i in range(so, l):
    li.append(li[i] + '3')
    li.append(li[i] + '5')
    li.append(li[i] + '7')
  so = l
cnt = 0
for x in li:
  if int(x) <= N and 3 in x and 5 in x and 7 in x:
    cnt += 1
print(cnt)

### FIXED CODE ###

N = int(input())
li = ['']
so = 0
for _ in range(9):
  l = len(li)
  for i in range(so, l):
    li.append(li[i] + '3')
    li.append(li[i] + '5')
    li.append(li[i] + '7')
  so = l
cnt = 0
for x in li:
  if '3' in x and '5' in x and '7' in x and int(x) <= N:
    cnt += 1
print(cnt)
N = int(input())
b = [int(_) for _ in input().split()]


def delitable(numbers):
    return [v for i, v in enumerate(numbers) if v == i + 1]


b_searched = set()
b_unsearched = []


b_searched.add(tuple(b))
delit = delitable(b)

if delit == []:
    print("-1")
for delit_num in delit:
    b_unsearched.append([b[:delit_num - 1] + b[delit_num:], [delit_num]])


while b_unsearched:
    b, log = b_unsearched.pop()

    if max(b) > N - len(log):
        continue

    b_tuple = tuple(b)
    b_searched.add(b_tuple)
    delit = delitable(b)


    if not delit:
        if not b:
            log.reverse()
            print("\n".join(map(str, log)))
            break
        else:
            continue
    for delit_num in delit:
        b_temp = b[:delit_num - 1] + b[delit_num:]
        if not tuple(b_temp) in b_searched:
            b_unsearched.append([b_temp, log + [delit_num]])
else:
    print("-1")

### FIXED CODE ###

N = int(input())
b = [int(_) for _ in input().split()]


def delitable(numbers):
    return [v for i, v in enumerate(numbers) if v == i + 1]


log = []
while b:
    delit = delitable(b)
    if not delit:
        print(-1)
        break
    del b[delit[-1] - 1]
    log.append(delit[-1])
else:
    log.reverse()
    print("\n".join(map(str, log)))
import sys
import itertools
import numpy as np

from collections import defaultdict

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
 
N = int(readline())
A = [[int(x) - 1 for x in row.split()] for row in readlines()]


ids = [[0 for j in range(N)] for i in range(N)]
V = 0
for i in range(N):
    for j in range(N):
        ids[i][j] = V
        V += 1

MAXV = 1000 * 1000 // 2

visited = [False for i in range(MAXV)]
calculated = [False for i in range(MAXV)]
dp = [0 for i in range(MAXV)]

def dfs(v):
    if visited[v]:
        if not calculated[v]:
            print(-1)
            exit()

        return dp[v]

    visited[v] = True
    dp[v] = 1
    for u in to[v]:
        dp[v] = max(dp[v], dfs(u) + 1)

    calculated[v] = True
    return dp[v]

to = [[] for i in range(MAXV)]
for i in range(N):
    for j in range(N - 1):
        a = i
        b = A[i][j]
        if a > b:
            a, b = b, a
        A[i][j] = ids[a][b]
    for j in range(N - 2):
        to[A[i][j + 1]].append(A[i][j])

ans = 0
for i in range(V):
    ans = max(ans, dfs(i))

print(ans)

### FIXED CODE ###

import sys
import itertools
import numpy as np

from collections import defaultdict

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
 
N = int(readline())
A = [[-1] + [int(x) - 1 for x in row.split()][::-1] for row in readlines()]

# A.append([-1])

def f(cand):
    cand1 = set()
    can_use = []
    for n in cand:
        if A[A[n][-1]][-1] == n:
            can_use.append(n)
    for n in can_use:
        A[n].pop()
        cand1.add(n)
        if A[n][-1] != -1:
            cand1.add(A[n][-1])
    return len(can_use), cand1

answer = 0
rest = N*(N-1)
cand = set(range(N))
while True:
    answer += 1
    x, cand = f(cand)
    if x == 0:
        answer = -1
        break
    rest -= x
    if rest == 0:
        break

print(answer)
a, b, c = list(map(int, input().split()))
sort(a, b ,c)
print(a, b, c)

### FIXED CODE ###

num = list(map(int, input().split()))

num.sort()
print(num[0], num[1], num[2])
a,b,k = map(int,input().split())

result = set()

for i in range(a,min(a+k,b+1)):
    result.add(i)
for j in arnge(max(a,b-k+1),b+1):
    result.add(j)

for k in sorted(list(result)):
    print(k)

### FIXED CODE ###

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

result = set()

for i in range(a,min(a+k,b+1)):
    result.add(i)
for j in range(max(a,b-k+1),b+1):
    result.add(j)

for k in sorted(list(result)):
    print(k)
n = int(input())
xl = [list(map(int, input().split())) for _ in range(n)]
le = [[p[0]-p[1], p[0]+p[1]] for p in xl]
le.sort(key = lambda x　: x[1])

ans = 0
right = -(10 ** 9) -　1
for i in range(n):
    if right <= le[i][0]:
        ans += 1
        right = le[i][1]

print(ans)

### FIXED CODE ###

n = int(input())
xl = [list(map(int, input().split())) for _ in range(n)]
le = [[p[0]-p[1], p[0]+p[1]] for p in xl]
le.sort(key = lambda x : x[1])

ans = 0
right = -(10 ** 9) - 1
for i in range(n):
    if right <= le[i][0]:
        ans += 1
        right = le[i][1]

print(ans)
s = raw_input()
if s == "Sunny":
    print("Cloudy")
elif s == "Cloudy":
    print("Rainy")
else:
    print("Sunny")

### FIXED CODE ###

s = input()
if s == "Sunny":
    print("Cloudy")
elif s == "Cloudy":
    print("Rainy")
else:
    print("Sunny")
def main():
    S = input()
    judge = True
    if S[0] == "A":
        S[0] = S[0].lower()
    else:
        judge = False
    if S[1] == "C":
        judge = False
    if S[2:-2].count("C") == 1:
        for n, i in enumerate(S):
            if 2 <= n <= len(S) - 1:
                if i == "C":
                    S[n] = S[n].lower()
    else:
        judge = False
    if S[-1] == "C":
        judge = False
    if S.islower() == False:
        judge = False
    if judge:
        print("AC")
    else:
        print("WA")


if __name__ == '__main__':
    main()


### FIXED CODE ###

#!/usr/bin/env python3


def main():
    S = list(input())
    judge = True
    if S[0] == "A":
        S[0] = S[0].lower()
    else:
        judge = False
    if S[1] == "C":
        judge = False
    if S[2:-1].count("C") == 1:
        for n, i in enumerate(S):
            if 2 <= n <= len(S) - 1:
                if i == "C":
                    S[n] = S[n].lower()
    else:
        judge = False
    if S[-1] == "C":
        judge = False
    S = "".join(S)
    if S.islower() == False:
        judge = False
    if judge:
        print("AC")
    else:
        print("WA")


if __name__ == '__main__':
    main()
x = list(map(input().split(), int))

print(x.max() - x.min())

### FIXED CODE ###

x = list(map(int, input().split()))
print(max(x) - min(x))
N = int(input())
A = list(map(int, input().split()))

import collections
dic=dict(collections.Counter(A))
li=list(dic.values())

ans='No'

if len(li)==3:
    if N%3 == 0:
        if li[0]== N/3 and li[1]==N/3 and li[2]==N/3:
            ans='Yes'           
elif len(li)==2:
    if N%3 == 0:
        if li[0]== 2*N/3 or li[1]==2*N/3 or li[2]==2:
            ans='Yes'
elif len(li)==1:
        if list(dic.keys())[0]==0:
            ans='Yes'

print(ans)

### FIXED CODE ###

#!/usr/bin/env python3
import sys
from collections import Counter

def main():
    N = int(input())
    a = list(map(int, input().split()))
    l = Counter(a)
    if len(l)==1 and 0 in l:
        print('Yes')
        exit()
    if N%3==0 and len(l)==2 and 0 in l and l[0] == N//3:
        print('Yes')
        exit()
    if N%3==0 and len(l)==3:
        x,y,z = l.keys()
        if l[x] == l[y] == N//3 and x^y^z == 0:
            print('Yes')
            exit()
    print('No')

    

if __name__ == '__main__':
    main()
H,A=int(input().split())
count=0

while H>=0:
  H-=A
  count+=1

print(A)

### FIXED CODE ###

H,A=map(int,input().split())
count=0

while H>0:
  H=H-A
  count+=1

print(count)
while True:
    a = input()
    if a == "0 0 0 0 0":
        break
    a = a.split(" ")
    b = []
    for i in a:
        b.append(int(i))
    c = input()
    c = c.split(" ")
    d = []
    for i in c:
        d.append(int(i))
    if b[4] == d[0]:
        print(0)
        continue
    ans = 0
    x = b[4]
    for i in d:
        for e in range(10000):
            x = (b[1] * x + b[2]) % b[3]
            ans = ans + 1
            if x == i:
                break
    if ans >= 10001:
        ans = -1
    print(ans)


### FIXED CODE ###

while True:

    n, a, b, c, x = map(int, input().split(" "))

    if n == 0 and a == 0 and b == 0 and c == 0 and x == 0:
        break

    y = list(map(int, input().split(" ")))

    ans = 0
    i = 0
    
    while ans <= 10000:
        if x == y[i]:
            i += 1

        if i == n:
            break
        x = (a * x + b) % c
        ans += 1
    if ans >= 10001:
        ans = -1
    print(ans)
N = int(input())
S = list(input())
print(max([len(set(S[:i]) & set(S[i:])) for

### FIXED CODE ###

N = int(input())
S = list(input())
print(max([len(set(S[:i]) & set(S[i:])) for i in range(1,N)]))
import numpy as np

N,M = [int(i) for i in input().split(" ")]
H = [int(i) for i in input().split(" ")]
root = np.zeros([N,N],dtype='int16')
for i in range(M):
    a,b = [int(i)-1 for i in input().split(" ")]
    root[a,b] = 1
    root[b,a] = 1

ans = 0
for i in range(N):
    count = 0
    for l in range(N):
        if root[i,l] == 1 and H[i] <= H[l]:
            count = 1
    if count == 0:
        ans += 1
    
print(ans)

### FIXED CODE ###

import numpy as np

N,M = [int(i) for i in input().split(" ")]
H = [int(i) for i in input().split(" ")]
mh = np.zeros([N])
for i in range(M):
    a,b = [int(i)-1 for i in input().split(" ")]
    mh[a] = max(mh[a],H[b])
    mh[b] = max(mh[b],H[a])

ans = 0
for i in range(N):
    if mh[i] < H[i]:
        ans += 1

print(ans)
# solution
import io

print("Yes" if sorted(input()) < sorted(input(),reverse = True) else "No")

### FIXED CODE ###

print(-(-eval(input().replace(" ","+"))//2))
#!/usr/bin/env python3

# from numba import njit
from math import gcd
# input = stdin.readline

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

# @njit
def solve(n,m,s,t):
  L = lcm(n,m)
  
  lst = [""]*L
  s_interval = L//n
  t_interval = L//m
  for i in range(n):
    lst[i*s_interval] = s[i]
  for i in range(m):
    if lst[i*t_interval] =="":
      continue
    if lst[i*t_interval] != t[i]:
      return "-1"
  return L
  

def main():
  N,M = map(int,input().split())
  s = input()
  t = input()
  print(solve(N,M,s,t))
  return

if __name__ == '__main__':
  main()


### FIXED CODE ###

#!/usr/bin/env python3

# from numba import njit
from math import gcd
# input = stdin.readline

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

# @njit
def solve(n,m,s,t):
  L = lcm(n,m)
  G = gcd(n,m)
  s_interval = L//n
  t_interval = L//m
  for i in range(G):
    if s[i*n//G] != t[i*m//G]:
      return -1
  return L
  

def main():
  N,M = map(int,input().split())
  s = input()
  t = input()
  print(solve(N,M,s,t))
  return

if __name__ == '__main__':
  main()
N = list(map(int,list(input())))
K = int(input())
#print(N)

def main(k,p):
    l = len(k)
    x = 9 ** p###先頭桁が0
    for i in range(p):
        x *= max(l - 1 - i,0)
    for i in range(p):
        x //= (i+1)
    y = (k[0] - 1)*(9**(p-1))###先頭桁が1以上k[0]-1以下
    for i in range(p-1):
        y *= max(l - 1 - i,0)
    for i in range(p-1):
        y //= (i+1)
    ##以下, 先頭がk[0]
    i = 1
    while i < l-1 and k[i] == 0 :
        i += 1
    #print("i=",i)
    if p == 1:
        z = 1
    elif i == l-1 and k[i]==0:
        z = 0
    else:
        z = main(k[i:],p-1)
    #print(k,x,y,z)
    return (x+y)+z

print(main(N,K))

### FIXED CODE ###

N = list(map(int,list(input())))
K = int(input())
#print(N)

def main(k,p):
    l = len(k)
    x = 9 ** p###先頭桁が0
    for i in range(p):
        x *= max(l - 1 - i,0)
    for i in range(p):
        x //= (i+1)
    y = (k[0] - 1)*(9**(p-1))###先頭桁が1以上k[0]-1以下
    for i in range(p-1):
        y *= max(l - 1 - i,0)
    for i in range(p-1):
        y //= (i+1)
    ##以下, 先頭がk[0]
    i = 1
    while i < l-1 and k[i] == 0 :
        i += 1
    #print("i=",i)
    if p == 1:
        z = 1
    elif i == l-1 and k[i]==0:
        z = 0
    else:
        z = main(k[i:],p-1)
    #print(k,x,y,z)
    return (x+y)+z

if len(N) < K:
    print(0)
else:
    print(main(N,K))
n, m = map(int, input().split())
ps = [input().split() for _ in range(m)]
p, s = [list(i) for i in zip(*ps)]
p = list(map(int, p))

res = [0]*n
correct = 0
penalty = 0
for i in range(m):
    no = p[i] - 1
    if res[no] == 1:
        continue
    elif s[no] == 'WA':
        penalty += 1
    elif s[no] == 'AC':
        correct += 1
        res[no] = 1

print(correct, penalty)

### FIXED CODE ###

n, m = map(int, input().split())
p = []
s = []
for i in range(m):
    p_i, s_i = input().split()
    p.append(int(p_i))
    s.append(s_i)

correct = [0]*n
penalty = [0]*n

for i in range(m):
    no = p[i]
    if correct[no-1] == 1:
        continue
    elif s[i] == 'WA':
        penalty[no-1] += 1
    elif s[i] == 'AC':
        correct[no-1] = 1

pen = 0
for i in range(n):
    if correct[i] == 1:
        pen += penalty[i]
print(sum(correct), pen)
s=[int(i) for i in input().split()]
if s[1]==s[2] or s[2]==s[3] or s[3]==s[4]:
    print("Bad")
else:
    print("Good")

### FIXED CODE ###

s=input()
if int(s[0])==int(s[1]) or int(s[1])==int(s[2]) or int(s[2])==int(s[3]):
    print("Bad")
else:
    print("Good")
def minimumSquare(a, b): 
  
    result = 0
    rem = 0
 
    if (a < b): 
        a, b = b, a  
     while (b > 0): 
      
        # Update result 
        result += int(a / b)  
  
        rem = int(a % b)  
        a = b  
        b = rem  
  
    return result  
n = 13
m = 29
  
print(minimumSquare(n, m)) 

### FIXED CODE ###

#HIManshu
H = int(input())
E = H / 3
print(E ** 3)
N , M =map(int,input().split())
A_n =list(map(int,input().split()))

B_n=sorted(A_n)
i =0
count =N
while B_n[i] < sum(B_n)/(4*M) and i<=N-1:
    i +=1
    count -=1
if count >= M:
    print('Yes')
else:
    print('No')

### FIXED CODE ###

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

B_n=sorted(A_n,reverse=True)

if B_n[M-1] >= sum(B_n)/(4*M) :
    print('Yes')
else:
    print('No')
import sys
input = sys.stdin.readline

#n = int(input())
#l = list(map(int, input().split()))

'''
A=[]
B=[]
for i in range():
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)'''

poi=[]
pon=[]
s=input().rstrip("\n")
for i in range(len(s)-1):
    if s[i:i+2] == "RL":
        poi.append(i)
    if s[i:i+2] == "LR":
        pon.append(i)

r=[]
l=[]
k=0
ans=[0]*len(s)
for i in range(pon[-1]+1):
    if (poi[k]-i)%2==0:#L
        ans[poi[k]]+=1
    else:
        ans[poi[k]+1]+=1
    #print(ans)
    if i==pon[k]:
        k+=1
for i in range(pon[-1]+1,len(s)):
    if (poi[k]-i) % 2 == 0:  # L
        ans[poi[k]] += 1
    else:
        ans[poi[k]+1] += 1

print(*ans)


### FIXED CODE ###

import sys
input = sys.stdin.readline

#n = int(input())
#l = list(map(int, input().split()))

'''
A=[]
B=[]
for i in range():
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)'''

poi=[]
pon=[]
s=input().rstrip("\n")
for i in range(len(s)-1):
    if s[i:i+2] == "RL":
        poi.append(i)
    if s[i:i+2] == "LR":
        pon.append(i)

r=[]
l=[]
k=0
ans=[0]*len(s)
if pon!=[]:
    for i in range(pon[-1]+1):
        if (poi[k]-i)%2==0:#L
            ans[poi[k]]+=1
        else:
            ans[poi[k]+1]+=1
        #print(ans)
        if i==pon[k]:
            k+=1
    for i in range(pon[-1]+1,len(s)):
        if (poi[k]-i) % 2 == 0:  # L
            ans[poi[k]] += 1
        else:
            ans[poi[k]+1] += 1
else:
    for i in range(len(s)):
        if (poi[k]-i) % 2 == 0:  # L
            ans[poi[k]] += 1
        else:
            ans[poi[k]+1] += 1      
print(*ans)
import itertools
n=int(input())
p,q=[tuple(map(int,input().split())) for i in (1,1)]
j=itertools.permutations
l=list(j(range(1,n+1)))

for i,s in enumerate(l):
  if s==p:a=i
  elif s==q:b=i
print(abs(a-b))

### FIXED CODE ###

import itertools
n=int(input())
p,q=[tuple(map(int,input().split())) for i in (1,1)]
j=itertools.permutations
l=list(j(range(1,n+1)))

for i,s in enumerate(l):
  if s==p:a=i
  if s==q:b=i
print(abs(a-b))
N=int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
B.sort(reverse=True)
Arev=sorted(A, reverse=True)
Brev=sorted(B)
atai=0
s=0
for i in range(len(A)):
    if A[i]==B[i]:
        atai=A[i]
        s+=1
C=[]
for i in range(len(A)):
    C.append(A[i]-B[i])
if 0 in C =="True":
    hajime=C.index(0)
if s==0:
    print("Yes")
    print(*B)
else:
    Acount=A.count(atai)
    Bcount=B.count(atai)
    if N-Acount<Bcount:
        print("No")
    else:
        afirst=A.index(atai)
        alast=N-1-Arev.index(atai)
        bfirst=B.index(atai)
        blast=N-1-Brev.index(atai)
        t=min(afirst,bfirst)
        if t>=s:
            for i in range(0,s):
                B[hajime+i]=B[i]
                B[i]=atai
        else:
            for i in range(0,t):
                B[hajime+i]=B[i]
                B[i]=atai
            ss=s-t
            for i in range(0,ss):
                B[hajime+t+i]=B[-i-1]
                B[-i-1]=atai
        print("Yes")
        print(*B)

### FIXED CODE ###

N=int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
B.sort(reverse=True)
Arev=sorted(A, reverse=True)
Brev=sorted(B)
atai=0
s=0
for i in range(len(A)):
    if A[i]==B[i]:
        atai=A[i]
        s+=1
C=[]
for i in range(len(A)):
    C.append(A[i]-B[i])
if s>0:
    hajime=C.index(0)
if s==0:
    print("Yes")
    print(*B)
else:
    Acount=A.count(atai)
    Bcount=B.count(atai)
    if N-Acount<Bcount:
        print("No")
    else:
        afirst=A.index(atai)
        alast=N-1-Arev.index(atai)
        bfirst=B.index(atai)
        blast=N-1-Brev.index(atai)
        t=min(afirst,bfirst)
        if t>=s:
            for i in range(0,s):
                B[hajime+i]=B[i]
                B[i]=atai
        else:
            for i in range(0,t):
                B[hajime+i]=B[i]
                B[i]=atai
            ss=s-t
            for i in range(0,ss):
                B[hajime+t+i]=B[-i-1]
                B[-i-1]=atai
        print("Yes")
        print(*B)
'''
from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson, minimum_spanning_tree
from scipy.sparse import csr_matrix, coo_matrix, lil_matrix
import numpy as np
'''
from collections import deque, Counter, defaultdict
from itertools import product, permutations,combinations
from operator import itemgetter
from heapq import heappop, heappush
from bisect import bisect_left, bisect_right, bisect
from fractions import gcd
from math import ceil,floor, sqrt, cos, sin, pi, factorial
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**8)
INF = float('inf')
MOD = 10**9+7

def main():
  n = int(readline())
  v = list(map(int, readline().split()))
  odd = Counter(v[::2])
  even = Counter(v[1::2])
  odd[-1] = 0
  even[-2] = 0
  ev = even.most_common(2)
  od = odd.most_common(2)
  
  answer = n
  for (k1,v1), (k2,v2) in product(ev,od):
    if k1 == k2:
      continue
    x = n-x1-x2
    if answer>x:
      answer = x
      
  print(answe)
    
  
  
  
  
  
if __name__ == '__main__':
  main()

### FIXED CODE ###

'''
from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson, minimum_spanning_tree
from scipy.sparse import csr_matrix, coo_matrix, lil_matrix
import numpy as np
'''
from collections import deque, Counter, defaultdict
from itertools import product, permutations,combinations
from operator import itemgetter
from heapq import heappop, heappush
from bisect import bisect_left, bisect_right, bisect
from fractions import gcd
from math import ceil,floor, sqrt, cos, sin, pi, factorial
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**8)
INF = float('inf')
MOD = 10**9+7

def main():
  n = int(readline())
  v = list(map(int, readline().split()))
  odd = Counter(v[::2])
  even = Counter(v[1::2])
  odd[-1] = 0
  even[-2] = 0
  ev = even.most_common(2)
  od = odd.most_common(2)
  
  answer = n
  for (k1,v1), (k2,v2) in product(ev,od):
    if k1 == k2:
      continue
    x = n-v1-v2
    if answer>x:
      answer = x
      
  print(answer)
    
  
  
  
  
  
if __name__ == '__main__':
  main()
a,b,c = map(int,input.split())

def max(a,b):
    if a > b:
        return a
    else:
        return b

def min(a,b):
    if a < b :
        return a
    else:
        return b

if min(a,b) < c < max(a,b):
    print('Yes')
else:
    print('No')


### FIXED CODE ###

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

def max(a,b):
    if a > b:
        return a
    else:
        return b

def min(a,b):
    if a < b :
        return a
    else:
        return b

if min(a,b) < c < max(a,b):
    print('Yes')
else:
    print('No')
N=int(input())
a=[int(input()) for i in range(N)]
for i in range(N):
  print(max(a.remove(a[i])))

### FIXED CODE ###

N=int(input())
a=[int(input()) for i in range(N)]
b=sorted(a)[::-1]
for i in range(N):
  if a[i]==b[0]:
    print(b[1])
  else:
    print(b[0])