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

import collections
n,p = map(int,input().split())

if n >= 40 or p == 1:
    print("1")
else:
    s = 0
    fact = {}
    while s == 0:
        for i in range(2,p+1):
            if p%i == 0:
                p = p//i
                if p == 1:
                    s = 1
                if i not in fact:
                    fact[i] = 1
                else:
                    fact[i] += 1
                break
    ans = 1
    for i in fact:
        if fact[i] >= n:
            ans = ans*i**(fact[i]//n)
    print(ans)

### FIXED CODE ###

import time

n,p = map(int,input().split())

if n >= 40 or p == 1:
    print("1")
elif n == 1:
    print(p)
else:
    s = 0
    fact = {}
    start = time.time()
    check = False
    while s == 0:
        for i in range(2,p+1):
            now = time.time()
            if now > start+1.9:
                s = 1
                check = True
                break
            if p%i == 0:
                p = p//i
                if p == 1:
                    s = 1
                if i not in fact:
                    fact[i] = 1
                else:
                    fact[i] += 1
                break
    ans = 1
    for i in fact:
        if fact[i] >= n:
            ans = ans*i**(fact[i]//n)
    print(ans)
### BUGGY CODE ###

n = int(input())
ans = 1
mod = 10 ** 9 + 7
for i in range(1, n + 1):
    ans *= i % mod
print(ans % mod)

### FIXED CODE ###

n = int(input())
ans = 1
for i in range(1, n + 1):
  ans = i * ans % 1000000007
print(ans)
### BUGGY CODE ###

import itertools
N = int(input())
L =list(map(int,input().split()))
S = []
ans = 0
for i, j, k in itertools.combinations(L,3):
  S.append([i, j, k])
for a, b, c in S:
  if a < b + c and b < c + a and c < a + b:
    ans += 1
print(ans)

### FIXED CODE ###

import bisect
N = int(input())
L = list(map(int,input().split()))
L = sorted(L)
ans = 0
for i in range(N):
  for j in range(i+1,N):
    x = bisect.bisect_left(L,L[i] + L[j])
    ans += x - j - 1
print(ans)
### BUGGY CODE ###

S = input()
dp = [0]*2020
if len(S) < 4:
    print(0)
    exit(0)

T = []
t = int(S[0])
T.append(t)
for k in range(1,len(S)):
    t = t*10 + int(S[k])
    t %= 2019
    T.append(t)

U = [0]
s = int(S[-1])
U.append(s)
for k in range(len(S)-2,-1,-1):
    s = int(S[k])*(10**(len(S)-k-1)) + s
    s %= 2019
    U.append(s)
ans = 0
U = sorted(U)
for k in range(1,len(U)):
    if U[k-1] == U[k]:
        ans += 1
print(ans)


### FIXED CODE ###

S = input()
if len(S) < 4:
    print(0)
    exit(0)
dp = [0]*2019
dp[0] = 1
s = int(S[-1])
dp[s] = 1
ans = 0
for k in range(len(S)-2,-1,-1):
    s = int(S[k])*(pow(10,len(S)-k-1,2019)) + s
    s %= 2019
    dp[s] += 1
for e in dp:
    ans += e*(e-1)//2
print(ans)
### BUGGY CODE ###

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

def gcd(a,b):
  if b==0:
    return a
  else:
  	return gcd(b, a%b)

def gcd_list(X):
  dmy=gcd(X[0],X[1])
  dmy=X[0]*X[1]
  for i in range(len(X)):
    dmy=gcd(dmy,X[i])
  return dmy

if N==2:
  print(max(A))
else:
  R=[]
  for i in range(N):
    C=A[:i]
    C.extend(A[i+1:])
    R.append(gcd_list(C))

  print(int(max(R)))

### FIXED CODE ###

def gcd(a,b):
    if b == 0:
        return a
    if a % b == 0:
        return b
    else:
        return gcd(b,a%b)

N = int(input())
A = [i for i in map(int,input().split())]
L = [0]
R = [0]
for i in range(N):
    L.append(gcd(L[-1],A[i]))
for i in range(N-1,-1,-1):
    R.append(gcd(R[-1],A[i]))
R.reverse()
g = []
for i in range(N):
    g.append(gcd(L[i],R[i+1]))
print(max(g))
### BUGGY CODE ###

import sys
import queue
input = sys.stdin.readline
INF=float('inf')
n,m=map(int,input().split())
l=[list(map(int,input().split())) for _ in range(m)]

d=[INF]*n
nbr=[[] for _ in range(n)]
used=[False]*m

for i in range(m):
    nbr[l[i][0]-1].append([l[i][0]-1,l[i][1]-1,l[i][2],i])
    nbr[l[i][1]-1].append([l[i][1]-1,l[i][0]-1,-l[i][2],i])
#print(nbr)
for i in range(n):
    if d[i]==INF:
        d[i]=0
        q=queue.Queue()
        for x in nbr[i]:
            q.put(x)
        while not q.empty():
            eg=q.get()
            used[eg[3]]=True
            if d[eg[1]]==d[eg[0]]+eg[2]:
                pass
            elif d[eg[1]]==INF:
                d[eg[1]]=d[eg[0]]+eg[2]
            else:
                print('No')
                exit()
            for x in nbr[eg[1]]:
                if not used[x[3]]:
                    q.put(x)
#print(d)
print('Yes')

### FIXED CODE ###

def solve():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**6)
    INF=float('inf')
    n,m=map(int,input().split())
    l=[list(map(int,input().split())) for _ in range(m)]
    d=[INF]*n
    nbr=[[] for _ in range(n)]
    used=[False]*m
    for x in l:
        x[0]-=1
        x[1]-=1
    #print(l)
    for i in range(m):
        nbr[l[i][0]].append(i)
        nbr[l[i][1]].append(i)
    #print(nbr)
    def sol(i):
        for x in nbr[i]:
            if used[x]:continue
            used[x]=True
            i1=l[x][0]^l[x][1]^i
            dd=d[i]+l[x][2]*(2*(l[x][0]==i)-1)
            if d[i1]!=dd and d[i1]!=INF:
                print('No')
                exit()
            elif d[i1]==INF:
                d[i1]=dd
                sol(i1)
    for i in range(n):
        if d[i]==INF:
            d[i]=0
            sol(i)
    #print(d)
    print('Yes')
solve()
### BUGGY CODE ###

#!/usr/bin/env python3


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    a = input()
    Q = int(input())
    qs = [input().split() for _ in range(Q)]
    ans = a
    for q in qs:
        if len(q) == 1:
            ans = ''.join(list(reversed(ans)))
        else:
            if int(q[1]) == 1:
                ans = q[2] + ans
            else:
                ans = ans + q[2]
    print(ans)
    return


if __name__ == '__main__':
    main()


### FIXED CODE ###

#!/usr/bin/env python3
from collections import deque


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    a = input()
    Q = int(input())
    qs = [input().split() for _ in range(Q)]
    ans = deque(a)
    revcount = 0
    for q in qs:
        if len(q) == 1:
            revcount += 1
        else:
            if int(q[1]) == 1:
                if revcount % 2 == 0:
                    ans.appendleft(q[2])
                else:
                    ans.append(q[2])
            else:
                if revcount % 2 == 0:
                    ans.append(q[2])
                else:
                    ans.appendleft(q[2])
    if revcount % 2 == 1:
        ans.reverse()
    print(''.join(list(ans)))
    return


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

# D - AtCoder Express 2

import numpy as np

N, M, Q = map(int, input().split())
L, R, = [], []
p, q = np.array([],np.int64), np.array([],np.int64)
for _ in range(M):
    l, r = map(int, input().split())
    L.append(l)
    R.append(r)
for _ in range(Q):
    tmp_p, tmp_q = map(int, input().split())
    p = np.append(p, [tmp_p])
    q = np.append(q, [tmp_q])
    
train = np.zeros((N+1, N+1))
np.add.at(train, (L,R), 1)

np.cumsum(train, axis = 0, out = train)
np.cumsum(train, axis = 1, out = train)

p -= 1
ans = train[q,q] - train[p,q] - train[q,p] + train[p,p]
for i in range(Q):
    print(int(ans[i]))

### FIXED CODE ###

# D - AtCoder Express 2

import numpy as np

N, M, Q = map(int, input().split())
LR = np.zeros((N+1, N+1))

for _ in range(M):
    l, r = map(int, input().split())
    LR[l,r] += 1

np.cumsum(LR, axis = 0, out = LR)
np.cumsum(LR, axis = 1, out = LR)
    
for _ in range(Q):
    p, q = map(int, input().split())
    print(int(LR[q,q] - LR[p-1,q] - LR[q,p-1] + LR[p-1,p-1]))
### BUGGY CODE ###

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

ans=0
for i in range(N-2):
  for j in range(i+1,N-1):
    for k in range(j+1, N):
      count=0
      for x in [i,j,k]:
        if 2*L[x]<L[i]+L[j]+L[k]:
          count+=1
      if count==3:
        ans+=1
print(ans)

### FIXED CODE ###

import bisect

N=int(input())
L=list(map(int, input().split()))
L=sorted(L)

count=0
for i in range(N-2):
  a=L[i]
  for j in range(i+1, N-1):
    b=L[j]
    r=bisect.bisect_left(L, a+b)
    count+=r-1-j
    
print(count)
### BUGGY CODE ###

import sys,queue,math,copy,itertools,bisect,collections
MOD = 10**9 + 7
S = sys.stdin.readline().rstrip()
dp = [[0] * 13 for _ in range(len(S)+1)]
dp[0][0] = 1

for i in range(1,len(S)+1):
    x = S[i-1]
    if x == '?':
        for j in range(10):
            for k in range(13):
                dp[i][(k * 10 + j) % 13] += dp[i - 1][k]
    else:
        for k in range(13):
            dp[i][(k * 10 + int(x)) % 13] += dp[i - 1][k]
    for j in range(13):
        dp[i][j] %= MOD

print (dp[-1][5])


### FIXED CODE ###

import sys,queue,math,copy,itertools,bisect,collections
MOD = 10**9 + 7
S = sys.stdin.readline().rstrip()
dp = [[0] * 13 for _ in range(len(S)+1)]
dp[0][0] = 1

for i in range(1,len(S)+1):
    x = S[i-1]
    if x == '?':
        for j in range(10):
            for k in range(13):
                dp[i][(k * 10 + j) % 13] += dp[i - 1][k]
    else:
        for k in range(13):
            dp[i][(k * 10 + int(x)) % 13] += dp[i - 1][k]
    for j in range(13):
        dp[i][j] %= MOD

print (dp[-1][5])
### BUGGY CODE ###

import sys
input = sys.stdin.readline
N, K = map(int, input().split())
num = list(map(int, input().split()))
cns = list(set(num))
f = []
for i in cns:
    f.append(num.count(i))
f.sort(reverse=True)
print(sum(f[K::]))

### FIXED CODE ###

import sys
input = sys.stdin.readline
import collections
n,k = map(int, input().split())
num = list(map(int, input().split()))
cns = collections.Counter(num)
f = [cns[i] for i in cns]
f.sort(reverse=True)
print(sum(f[k::]))
### BUGGY CODE ###

# -*- coding: utf-8 -*-
"""
D - Cake 123
https://atcoder.jp/contests/abc123/tasks/abc123_d

"""
import sys


from itertools import product

def solve(X, Y, Z, K, A, B, C):
    res_AB = sorted([sum(p) for p in product(A, B)], reverse=True)[:K]
    return sorted([sum(p) for p in product(res_AB, C)], reverse=True)[:K]


def main(args):
    X, Y, Z, K = map(int, input().split())
    A = [int(a) for a in input().split()]
    B = [int(b) for b in input().split()]
    C = [int(c) for c in input().split()]
    ans = solve(X, Y, Z, K, A, B, C)
    print(*ans, sep='\n')


if __name__ == '__main__':
    main(sys.argv[1:])


### FIXED CODE ###

# -*- coding: utf-8 -*-
"""
D - Cake 123
https://atcoder.jp/contests/abc123/tasks/abc123_d

"""
import sys


from itertools import product

def solve(X, Y, Z, K, A, B, C):
    # TLE
    res_AB = sorted([sum(p) for p in product(A, B)], reverse=True)[:K]
    return sorted([sum(p) for p in product(res_AB, C)], reverse=True)[:K]


def main(args):
    X, Y, Z, K = map(int, input().split())
    A = [int(a) for a in input().split()]
    B = [int(b) for b in input().split()]
    C = [int(c) for c in input().split()]
    ans = solve(X, Y, Z, K, A, B, C)
    print(*ans, sep='\n')


if __name__ == '__main__':
    main(sys.argv[1:])
### BUGGY CODE ###

N,K=map(int,input().split())
P=list(map(int,input().split()))
cnt=0
A=(N-K+1)
E=[0]*N
for i in range (N):
	E[i]=(P[i]+1)/2
for i in range(A):
	cnt=max(cnt,sum(E[i:i+K]))
print(cnt)

### FIXED CODE ###

N,K=map(int,input().split())
P=list(map(int,input().split()))
E=[0]*N

for i in range (N):
	E[i]=((P[i]+1)/2)

L=[0]*(N+1)
L[0]=0

for i in range (N):
	L[i+1]=L[i]+E[i]

ans=0

for i in range (K,N+1):
	ans=max(ans,L[i]-L[i-K])

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

s1 = input()
s2 = input()
list = s1

for i in range(len(list)):
    if s1[i] != s2[i]:
      s1 = s1.translate(str.maketrans( s1[i]+s2[i], s2[i]+s1[i]) )

if s1==s2:
  print ("Yes")
else:
  print ("No")


### FIXED CODE ###

def translate(x,y):
    if x == y[0]:
      return y[1]
    if x == y[1]:
      return y[0]
    return x

s1 = list(input())
s2 = list(input())
list = s1

count = 0
for i in range(len(list)):
    if s1[i] != s2[i]:
      x = s1[i]
      y = s2[i]
      for j in range(len(s1)):
        if s1[j] == x:
          s1[j]=y
        elif s1[j] == y:
          s1[j]=x
      #s1 = s1.translate(str.maketrans( s1[i]+s2[i], s2[i]+s1[i]) )
      #s1.replace( s1[i], "X").replace( s2[i], x).replace( 'X' , y)
      #s1 = list(map(translate, s1))
      
      count = count+1
    if count > 27:
      break

if s1==s2:
  print ("Yes")
else:
  print ("No")
### BUGGY CODE ###

from sys import stdin
import math
import itertools
import re
 
 
def makeIntMatrix(lines):
    intMatrix = []
    for a in makeStringMatrix(lines):
        intMatrix.append([int(b) for b in a])
    return intMatrix
 
 
def makeStringMatrix(lines):
    stringMatrix = [line.split() for line in lines]
    return stringMatrix
 
 
def makeInt(line):
    return int(line.rstrip())
 
 
def makeMultiInteger(line):
    return [int(x) for x in line.rstrip().split()]
 
dp = {}
 
def solve(input_string):
    S = input_string[1]
    intMatrix = makeIntMatrix(input_string[2:])
    #print(input_string[2:])
    for line in intMatrix:
        l, r = line
        #print(l, r)
        #print(S[l:r+1])
        #cnt = len(re.findall(r'AC', S[l-1:r]))
        cnt = cntAC(l, r, S[l-1:r])
        print(cnt)
    return
 
 
def cntAC(l, r, t):
    if l+r is not dp:
        dp[l+r] = len(re.findall(r'AC', t))
    return dp[l+r]
 
 
def main():
    input_lines = stdin.readlines()
    answer = solve(input_lines)
    #print(answer)
 
 
if __name__ == '__main__':
    main()

### FIXED CODE ###

N, Q = map(int, input().split())
S = input()
t=[0]*(N+1)
for i in range(N):
  t[i + 1] = t[i] + (1 if S[i : i + 2] == 'AC' else 0)
for i in range(Q):
  l, r = map(int, input().split())
  print(t[r-1] - t[l-1])
### BUGGY CODE ###

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

r = list()
g = list()
b = list()
for idx, si in enumerate(s):
    if si == 'R':
        r.append(idx)
    elif si == 'G':
        g.append(idx)
    else:
        b.append(idx)

ret = 0
for ri in r:
    for gi in g:
        for bi in b:
            comp = list(sorted([ri, gi, bi]))
            if (comp[1] - comp[0]) != (comp[2] - comp[1]):
                ret += 1

print(ret)

### FIXED CODE ###

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

r = list()
g = list()
b = list()
for idx, si in enumerate(s):
    if si == 'R':
        r.append(idx)
    elif si == 'G':
        g.append(idx)
    else:
        b.append(idx)

ret = 0
bi_cnt = len(b)
for ri in r:
    for gi in g:
        cnt = 0
        try:
            dan1 = 2*ri - gi
            if (dan1 > 0) & (s[dan1] == 'B'):
                cnt += 1
        except:
            pass

        try:
            dan3 = 2*gi - ri
            if (dan3 > 0) & (s[dan3] == 'B'):
                cnt += 1
        except:
            pass

        try:
            dan2, mod = divmod(ri+gi, 2)
            if (mod == 0) & (s[dan2] == 'B'):
                cnt += 1
        except:
            pass

        ret += (bi_cnt - cnt)

print(ret)
### BUGGY CODE ###

def warshall_floyd(n,e):
  INF=float("inf")
  g=[[INF]*n for _ in range(n)]
  for i in range(n):g[i][i]=0
  for a,b,c in e:g[a][b],g[b][a]=c,c
  for k in range(n):
    for i in range(n):
      for j in range(n):g[i][j]=min(g[i][k]+g[k][j],g[i][j])
  return g
n,m,rl=map(int,input().split());r,e=list(map(int,input().split())),[]
for i in range(m):x,y,z=map(int,input().split());e.append([x-1,y-1,z])
d=warshall_floyd(n,e)
a=float("inf")
from itertools import permutations
for i in permutations(range(rl)):
  aa=0
  for x,y in zip(i,i[1:]):aa+=d[r[x]-1][r[y]-1]
  a=min(a,aa)
print(a)

### FIXED CODE ###

from itertools import permutations
n,m,rl=map(int,input().split());r=list(map(int,input().split()))
d=[[float("inf")for _ in range(n)]for _ in range(n)]
for i in range(m):
  x,y,z=map(int,input().split())
  d[x-1][y-1],d[y-1][x-1]=z,z
for i in range(n):d[i][i]=0
for k in range(n):
  for i in range(n):
    for j in range(n):d[i][j]=min(d[i][j],d[i][k]+d[k][j])
a=float("inf")
for i in permutations(r,rl):
  aa=0
  for j in range(rl-1):aa+=d[i[j]-1][i[j+1]-1]
  a=min(a,aa)
print(a)
### BUGGY CODE ###

# https://atcoder.jp/contests/abc177/submissions/16358885

N = int(input())
A = list(map(int, input().split()))
B = []  # 累積和テーブル B[i] = sum(A[:i])
mod = 10**9 + 7
ans = 0

for i in range(N+1):
    B.append(sum(A[:i]))  # 累積和

for i in range(N):
    sum = (B[N] - B[i+1]) % mod
    ans += A[i] * sum
    ans %= mod

print(ans)


### FIXED CODE ###

import numpy as np
N = int(input())
A = list(map(int, input().split()))
B = [0] * (N+1)  # 累積和テーブル B[i] = sum(A[:i])
mod = 10**9 + 7
ans = 0

for i in range(N):
    B[i+1] = B[i] + A[i]  # 累積和

for i in range(N):
    sum = (B[N] - B[i+1]) % mod
    ans += A[i] * sum
    ans %= mod

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

def main():
    R, G, B, N = map(int, input().split())
    result = 0
    for i in range(N // G + 1):
        for j in range(N // B + 1):
            if (N - G*i - B*j) // R >= 0 and (N - G*i - B*j) % R == 0:
                result += 1
    print(result)
main()

### FIXED CODE ###

def main():
    R, G, B, N = map(int, input().split())
    R, G, B = sorted([R, G, B])
    result = 0
    for i in range(N // G + 1):
        for j in range(N // B + 1):
            if (N - G*i - B*j) < 0:
                break
            elif (N - G*i - B*j) % R == 0:
                result += 1
    print(result)
main()
### BUGGY CODE ###

r,g,b,n=map(int,input().split())
l=n//min(r,g,b)
ans=0
for i in range(l+1):
  for j in range(l+1):
      if n-(i*r+j*g)>=0 and (n-(i*r+j*g))%b==0:
        ans+=1
print(ans)


### FIXED CODE ###

r,g,b,n=map(int,input().split())
l=n//min(r,g,b)
ans=0
for i in range(l+1):
  for j in range(l+1):
      if n-(i*r+j*g)>=0 and (n-(i*r+j*g))%b==0:
        ans+=1
print(ans)
### BUGGY CODE ###

# coding: utf-8
N = int(input())
S = input()
ans = 0
for v in range(1000):
    used = [False for _ in range(len(S))]
    v = str(v).zfill(3)
    flag = [False for _ in range(3)]
    idx = 0
    for i in range(len(S)):
        if not flag[0] and v[0] == S[i] and not used[i]:
            used[i] = True
            flag[0] = True
            continue
        if not flag[1] and v[1] == S[i] and not used[i] and sum(used[:i]) == 1:
            used[i] = True
            flag[1] = True
            continue
        if not flag[2] and v[2] == S[i] and not used[i] and sum(used[:i]) == 2:
            used[i] = True
            flag[2] = True
            break
    if sum(flag) == 3:
        ans += 1
print(ans)

### FIXED CODE ###

# coding: utf-8
N = int(input())
S = input()
ans = []
for v in range(1000):
    used = [False for _ in range(len(S))]
    v = str(v).zfill(3)
    idx = 0
    for i in range(len(S)):
        if v[0] == S[i] and not used[i]:
            used[i] = True
            idx = i + 1
            break
    for i in range(idx, len(S)):
        if v[1] == S[i] and not used[i]:
            used[i] = True
            idx = i + 1
            break
    for i in range(idx, len(S)):
        if v[2] == S[i] and not used[i]:
            used[i] = True
            break
    if sum(used) == 3 and v not in ans:
        ans.append(v[:])
print(len(ans))
### BUGGY CODE ###

from heapq import heappush, heappop
import sys
input = sys.stdin.readline

H, W, K = map(int, input().split())
x1, y1, x2, y2 = map(int, input().split())
c = [[i for i in input()] for _ in range(H)]

INF = 1 << 60
dist = [[[INF] * 2 for _ in range(W)] for _ in range(H)]
dist[x1 - 1][y1 - 1] = [0, 0]

# (cost, x, y, mode)
q = [(0, x1 - 1, y1 - 1, 0), (0, x1 - 1, y1 - 1, 1)]
while q :
  ccost, cx, cy, cmode = heappop(q)
  if ccost > dist[cx][cy][cmode] :
    continue
  for i, (dx, dy) in enumerate(((-1, 0), (0, -1), (1, 0), (0, 1))) :
    nmode = i % 2
    nx, ny = cx + dx, cy + dy
    if cmode == nmode :
      ncost = ccost + 1
      if 0 <= nx < H and 0 <= ny < W and c[nx][ny] != '@' and ncost < dist[nx][ny][nmode] :
        heappush(q, (ncost, nx, ny, nmode))
        dist[nx][ny][nmode] = ncost
  ncost = (ccost + K - 1) // K * K
  if ncost < dist[cx][cy][cmode ^ 1] :
    dist[cx][cy][cmode ^ 1] = ncost
    heappush(q, (ncost, cx, cy, cmode ^ 1))
 
if min(dist[x2 - 1][y2 - 1]) == INF :
  print(-1)
else :
  print((min(dist[x2 - 1][y2 - 1]) + K - 1) // K)

### FIXED CODE ###

from heapq import heappush, heappop
import sys
input = sys.stdin.readline

H, W, K = map(int, input().split())
x1, y1, x2, y2 = map(int, input().split())
c = [[i == '.' for i in input()] for _ in range(H)]

x1, y1, x2, y2 = x1 - 1, y1 - 1, x2 - 1, y2 - 1
INF = 1 << 60
dist = [INF] * (H * W * 2)

def pos(x, y, m) :
  return (x * W + y) * 2 + m
dist[pos(x1, y1, 0)] = dist[pos(x1, y1, 1)] = 0

q = [(0, pos(x1, y1, 0)), (0, pos(x1, y1, 1))]
while q :
  ccost, cpos = heappop(q)
  if ccost > dist[cpos] : continue
  cx = cpos // 2 // W
  cy = cpos // 2 % W
  cmode = cpos % 2
  dir = [
    [(-1, 0), (1, 0)],
    [(0, -1), (0, 1)]
  ]
  for dx, dy in dir[cmode] :
    nx, ny = cx + dx, cy + dy
    ncost = ccost + 1
    if 0 <= nx < H and 0 <= ny < W and c[nx][ny] and ncost < dist[pos(nx, ny, cmode)] :
      heappush(q, (ncost, pos(nx, ny, cmode)))
      dist[pos(nx, ny, cmode)] = ncost
      
  ncost = (ccost + K - 1) // K * K
  if ncost < dist[pos(cx, cy, cmode ^ 1)] :
    dist[pos(cx, cy, cmode ^ 1)] = ncost
    heappush(q, (ncost, pos(cx, cy, cmode ^ 1)))

ans = min(dist[pos(x2, y2, 0)], dist[pos(x2, y2, 1)])
if ans == INF :
  print(-1)
else :
  print((ans + K - 1) // K)
### BUGGY CODE ###

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

res = 1
for i in A:
    res *= i

if res > 10**18:
    print(-1)
else:
    print(res)

### FIXED CODE ###

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

res = 1
for i in A:
    if res > 10**18:
        print(-1)
        sys.exit()
    res *= i

if res > 10**18:
    print(-1)
else:
    print(res)
### BUGGY CODE ###

import math

def cal(sum_, F, N, K, d):
    count = 0
    for i in range(N):
        if sum_[i] > d:
            count += math.ceil((sum_[i] - d) / F[i])
            if count > K:
                #作ることができない
                return False
    return True


def main():
    N, K = map(int, input().split())
    A = [int(i) for i in input().split()]
    F = [int(i) for i in input().split()]
    A.sort()
    F.sort(reverse=True)
    sum_ = []
    for i in range(N):
        sum_.append(A[i] * F[i])

    right = 10 ** 12
    left = 0
    count = 0
    while count < 100:
        mid = (right + left) // 2
        if cal(sum_, F, N, K, mid):
            # midを小さくすることができる
            right = mid
        else:
            # midを大きくしなければならない
            left = mid + 1
        count += 1
    print(mid)


if __name__ == "__main__":
    main()


### FIXED CODE ###

import math

def cal(sum_, F, N, K, d):
    count = 0
    for i in range(N):
        if sum_[i] > d:
            count += math.ceil((sum_[i] - d) / F[i])
            if count > K:
                #作ることができない
                return False
    return True


def main():
    N, K = map(int, input().split())
    A = [int(i) for i in input().split()]
    F = [int(i) for i in input().split()]
    A.sort()
    F.sort(reverse=True)
    sum_ = []
    for i in range(N):
        sum_.append(A[i] * F[i])

    right = 10 ** 12
    left = 0
    count = 0
    pre_mid = 0
    while True:
        mid = (right + left) // 2
        if pre_mid == mid:
            break
        if cal(sum_, F, N, K, mid):
            # midを小さくすることができる
            right = mid
        else:
            # midを大きくしなければならない
            left = mid + 1
        pre_mid = mid
        count += 1
    print(mid)


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


n = int(input())

A = [0] * n
for i in range(n):
    A[i] = int(input())

for i in range(n):
    temp = A[i]
    A[i] = 0
    print(max(A))
    A[i] = temp



### FIXED CODE ###


n = int(input())

A = [0] * n
for i in range(n):
    A[i] = int(input())

B = sorted(A, reverse=True)

for i in range(n):
    print(B[0] if A[i] != B[0] else B[1])