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

n, p = map(int, input().split())
if n==1:
  print(p)
  exit()
elif p==1:
  print(1)
  exit()
for i in range(int(p**(1/n))+1, 0, -1):
  if p%(i**n)==0:
    print(i)
    exit()

### FIXED CODE ###

n, p = map(int, input().split())
if n==1:
  print(p)
  exit()
elif p==1 or n>=60:
  print(1)
  exit()
for i in range(int(p**(1/n))+1, 0, -1):
  if p%(i**n)==0:
    print(i)
    exit()
### BUGGY CODE ###

import bisect
N = int(input())
A = [0 for i in range(N)]
for i in range(N):
    A[i] = int(input())
dp = [[] for i in range(N)]
dp[0] = [A[0]]

for i in range(1, N):
    index = bisect.bisect_left(dp[i-1], A[i])
    dp[i] = dp[i-1].copy()
    if index == 0:
        dp[i].insert(0, A[i])
    else:
        dp[i][index-1] = A[i]
print(len(dp[N-1]))




### FIXED CODE ###

import bisect
N = int(input())
A = [0 for i in range(N)]
for i in range(N):
    A[i] = int(input())
now = [-A[0]]

for i in range(1, N):

    index = bisect.bisect_right(now, -A[i])
    if index == len(now):
        now.append(-A[i])
    else:
        now[index] = -A[i]

print(len(now))
### BUGGY CODE ###

n = int(input())
A = list(map(int, input().split()))
ans = 0
for v in range(min(A), max(A) + 1):
    count = A.count(v - 1) + A.count(v) + A.count(v + 1)
    if ans < count:
        ans = count
print(ans)

### FIXED CODE ###

from collections import Counter
n = int(input())
A = list(map(int, input().split()))
C = Counter(A)
ans = 0
start, end = min(A), max(A) + 1
for v in range(start, end):
    ans = max(C[v - 1] + C[v] + C[v + 1], ans)
print(ans)
### BUGGY CODE ###

input()
ans=1
for i in map(int,input().split()):ans*=i
print(int(ans)if ans<=10**18 else -1)

### FIXED CODE ###

input()
ans=1
for i in sorted(map(int,input().split())):
    ans*=i
    if ans>10**18:ans=-1
    if -1<=ans<=0:break
print(int(ans))
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10**6)

n = int(input())
readline = sys.stdin.readline
a = [int(input()) for _ in range(n)]

ans = []

for _ in range(n):
    tmp = a.pop(0)
    ans.append(max(a))
    a.append(tmp)

print(*ans)

### FIXED CODE ###

import sys
sys.setrecursionlimit(10**6)

n = int(input())
readline = sys.stdin.readline
A = [int(input()) for _ in range(n)]

import heapq

Q = [-a for a in A]
heapq.heapify(Q)

ans = []

for i in range(n):
    if -Q[0] == A[i]:
        tmp = heapq.heappop(Q)
        ans.append(-Q[0])
        heapq.heappush(Q, tmp)
    else:
        ans.append(-Q[0])

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

n = int(input())
a = [0]*n
for i in range(n):
  a[i] = int(input())
for i in range(n):
  b = a[:]
  b[i] = 0
  print(max(set(b)))

### FIXED CODE ###

n = int(input())
a = [int(input()) for _ in range(n)]
b = a[:]
b.sort(reverse=True)
for i in range(n):
  if a[i] == b[0]:
    print(b[1])
  else:
    print(b[0])
### BUGGY CODE ###

ans = 0
n = int(input())+1
for i in range(1,n):
    for j in range(i,n,i):
        ans += j
print(ans)

### FIXED CODE ###

ans = 0
n = int(input())
for i in range(1,n+1):
    j = n//i
    ans += i*j*(j+1)//2
print(ans)
### BUGGY CODE ###

a,b=map(int,input().split())
import math
c= math.gcd(a,b)
l=[]
i=2
while i<=c:
  if c % i==0:
    c=c//i
    l.append(i)
  else:
    i+=1
print(len(set(l))+1)


### FIXED CODE ###

a,b=map(int,input().split())
import math
c= math.gcd(a,b)
c2=c
l=[]
i=2
while i<=c:
  if c % i==0:
    c=c//i
   
    l.append(i)
  else:
    i+=1
  if i*i-1>c:
    l.append(c)
    break
  
print(len(set(l))+1)
### BUGGY CODE ###

s = input()
q = int(input())
for i in range(q):
    query = input().split()
    if query[0] == '1':
        s = s[::-1]
    elif query[1] == '1':
        s = query[2] + s
    else:
        s = s + query[2]
print(s)


### FIXED CODE ###

from collections import deque

s = deque(input())
q = int(input())
is_reversed = False
for i in range(q):
    query = input().split()
    if query[0] == '1':
        is_reversed = not is_reversed
    elif (query[1] == '2') ^ is_reversed:
        s.append(query[2])
    else:
        s.appendleft(query[2])
if is_reversed:
    s.reverse()
print(''.join(s))
### BUGGY CODE ###

n = int(input())

nums = []
nums = list(map(int, input().split()))
nums = sorted(nums, reverse=True)

cnt = 0

fir_num = nums[0]

del nums[0]

for i in range(n-2):
    fir_num += nums[0]
    cnt += 1
    if cnt == 2:
        del nums[0]
        cnt = 0

print(fir_num)









### FIXED CODE ###

n = int(input())

nums = []
nums = list(map(int, input().split()))
nums = sorted(nums, reverse=True)

cnt = 0

fir_num = nums[0]

del nums[0]

for i in range(n-2):
    fir_num += nums[int(i/2)]


print(fir_num)
### BUGGY CODE ###

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

a = [0 for i in range(1, max(arr)+2)]

# print(arr)
# print(a)

for ar in arr:
  a[ar] += 1

t = []
for i, z in enumerate(a):
  if z >= 2:
    t.append(i)

if len(t) < 2:
  print(0)
else:
  sort = sorted(t, reverse=True)

  ans = sort[0] * sort[1]

  print(ans)

### FIXED CODE ###

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

li.sort(reverse=True)

vert = {}
even = []
ans = 0

for i in li:
	if i in vert:
		vert.pop(i)
		even.append(i)
		if len(even) == 2:
			ans = even[0] * even[1]
			break
	else:
		vert[i] = 1
print(ans)
### BUGGY CODE ###



def main():
    n, m = map(int, input().split())

    gate = []

    for _ in range(m):
        ngate = list(map(int, input().split()))
        gate.append(ngate)
    

    result = 0
    for i in range(1, n + 1):
        for j in range(m):
            if gate[j][0] <= i and i <= gate[j][1]:
                if j == len(gate) - 1:
                    result += 1
                continue
            else:
                break

    
    return result


if __name__ == "__main__":
    print(main())

### FIXED CODE ###



def main():
    n, m = map(int, input().split())

    A = []
    B = []

    for _ in range(m):
        a, b = list(map(int, input().split()))
        A.append(a)
        B.append(b)

         
    l = max(A)
    r = min(B)
    #print(l, r)

    if r >= l:
        return r - l + 1
    else:
        return 0

if __name__ == "__main__":
    print(main())



"""
for i in range(1, n + 1):
        for j in range(m):
            if gate[j][0] <= i and i <= gate[j][1]:
                if j == len(gate) - 1:
                    result += 1
                continue
            else:
                break
"""
### BUGGY CODE ###

N,K = list(map(int,input().split()))
gakki = list(map(int,input().split()))

temp1 = gakki[0]
for i in range(1,K):
    temp1 *= gakki[i]

for i in range(N - K):
    temp2 = int(temp1 / gakki[i] * gakki[K + i])
    if temp1 < temp2:
        print("Yes")
    else:
        print("No")
    temp1 = temp2
    


### FIXED CODE ###

N,K = list(map(int,input().split()))
gakki = list(map(int,input().split()))


for i in range(N - K):
    temp1 = gakki[i]
    temp2 = gakki[K + i]
    if temp1 < temp2:
        print("Yes")
    else:
        print("No")
    temp1 = temp2
### BUGGY CODE ###

point = []
yes_no = []
minus = []
output = []

N,K,Q = map(int,input().split())
A = []

for _ in range(Q):
    A.append(input())

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

for _ in range(N):
    point.append(K)

for _ in range(N):
    minus.append(Q)

for i in range(N):
    point[i] = point[i] - minus[i]

for j in range(N):
    point[j-1] = point[j-1] + A.count(j)

for p in point:
    if p >= 1:
        yes_no.append('Yes')
    else:
        yes_no.append('No')

s = '\n'.join(yes_no)
print(s)



### FIXED CODE ###

N,K,Q=map(int,input().split())
A = [int(input()) for i in range(Q)]

import collections
c = collections.Counter(A)
c_i=c.items()

m=[K-Q]*N
for i in c_i:
    m[i[0]-1]=m[i[0]-1]+i[1]
o=[]

for i in m:
    if i<=0:
        o.append('No')
    else:
        o.append('Yes')
print('\n'.join(o))
### BUGGY CODE ###

N = int(input())
a = list(map(int,input().split()))
q = int(input())
for i in range(q):
  summ = 0
  b,c = map(int,input().split())
  for i in range(N):
    if(a[i]==b):
      a[i] = c
    summ += a[i]
  print(summ)


### FIXED CODE ###

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

import sys
sys.setrecursionlimit(1000000)
N = int(input())

match = [[-1] * (N) for _ in range(N)]
c = 0
for i in range(N):
    for j in range(i+1, N):
        match[i][j] = c
        c += 1
# print(match)


def get_id(i, j):
    if i > j:
        i, j = j, i
    return match[i][j]


G = {k: [] for k in range(c)}
for i in range(N):
    L = map(int, input().split())
    pid = -1
    for l in L:
        id = get_id(i, l-1)
        if pid != -1:
            G[id].append(pid)
        pid = id

visited = [False]*c
calculated = [False]*c
dp = [-1]*c


def dfs(v):
    if visited[v]:
        if not calculated[v]:
            print(-1)
            exit()
        return dp[v]
    visited[v] = True
    dp[v] = 1
    for nxt in G[v]:
        dp[v] = max(dp[v], dfs(nxt)+1)
    calculated[v] = True
    return dp[v]


ans = 0
for i in range(c):
    res = dfs(i)
    ans = max(ans, res)
print(ans)


### FIXED CODE ###

from collections import deque

N = int(input())
L = [deque([int(i)-1 for i in input().split()]) for i in range(N)]

q = deque(range(N))
d = [0 for i in range(N)]
pairs = [-1 for i in range(N)]
while q:
    a = q.popleft()  # qの左端の選手のindexをpopleft
    if len(L[a]) == 0:
        continue
    b = L[a].popleft()

    if pairs[b] == a:  # bのリクエストがaなら
        d[a] = d[b] = max(d[a], d[b]) + 1
        q.append(a)
        q.append(b)
    else:
        pairs[a] = b
print(max(d) if not any(L) else -1)
### BUGGY CODE ###

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

N,M=map(int,input().split())
P=[i for i in range(N+1)]
size=[1 for i in range(N+1)]

def find(a):
    if a==P[a]:
        return a
    else:
        return find(P[a])
        
def union(b,c):
    B=find(b)
    C=find(c)
    if size[B]<size[C]:
        P[B]=P[C]
        size[C]=size[B]
    else:
        P[C]=P[B]
        size[B]+=size[C]

for i in range(M):
    a,b=map(int,input().split())
    if find(a)==find(b):
        continue
    else:
        union(a,b)
for i in range(N+1):
    P[i]=find(P[i])
#print(P)
D={}
for i in range(1,N+1):
    if P[i] not in D:
        D[P[i]]=1
    else:
        D[P[i]]+=1
ans=0
for k,v in D.items():
    if ans<v:
        ans=v
print(ans)

### FIXED CODE ###

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

N,M=map(int,input().split())
P=[i for i in range(N+1)]
size=[1 for i in range(N+1)]

def find(a):
    if a==P[a]:
        return a
    else:
        return find(P[a])
        
def union(b,c):
    B=find(b)
    C=find(c)
    if size[B]<size[C]:
        P[B]=P[C]
        size[C]+=size[B]
    else:
        P[C]=P[B]
        size[B]+=size[C]

for i in range(M):
    a,b=map(int,input().split())
    if find(a)==find(b):
        P[a]=find(a)
        P[b]=find(b)
        continue
    else:
        union(a,b)
for i in range(N+1):
    P[i]=find(P[i])
#print(P)
D={}
for i in range(1,N+1):
    if P[i] not in D:
        D[P[i]]=1
    else:
        D[P[i]]+=1
ans=0
for k,v in D.items():
    if ans<v:
        ans=v
print(ans)
### BUGGY CODE ###

from collections import Counter

N = int(input())
A = [int(a) for a in input().split()]

A1 = [0]*N
A2 = [0]*N

for i in range(N):
    A1[i] = A[i] + i
    A2[i] = i - A[i]

cnt = 0
for i in range(N):
    c = Counter(A2[i+1:])
    cnt += c[A1[i]]

print(cnt)

### FIXED CODE ###

from collections import Counter
# import sys

# input = sys.stdin.readline

N = int(input())
A = [int(a) for a in input().split()]

A1 = [0]*N
A2 = [0]*N

for i in range(N):
    A1[i] = A[i] + i
    A2[i] = i - A[i]

c = Counter(A2)

cnt = 0
for i in range(N):
    cnt += c[A1[i]]

print(cnt)
### BUGGY CODE ###

import sys
from bisect import bisect_left
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

H, N = map(int, readline().split())
AB = [list(map(int, readline().split())) for _ in range(N)]

dp = [10**9] * (H + 5)
dp[0] = 0

for i in range(1, H + 1):
    for (a, b) in AB:
        dp[i] = min(dp[i], min(dp[max(0, i - a):i + 1]) + b)

print(dp[H])


### FIXED CODE ###

import sys
from bisect import bisect_left
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

H, N = map(int, readline().split())
m = map(int, read().split())
AB = zip(m, m)

INF = 10**18

dp = [INF] * (H + (10**4))
dp[0] = 0
for a, b in AB:
    for n in range(H):
        if dp[n + a] > dp[n] + b:
            dp[n + a] = dp[n] + b

print(min(dp[H:]))
### BUGGY CODE ###

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

ans = 0
for i in range(N-1):
    tmp = 0
    for j in range(i, N-1):
        if H[j] >= H[j+1]:
            tmp += 1
        else: 
            break
    ans = max(ans, tmp)
print(ans)    

### FIXED CODE ###

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

ans = 0
cnt = 0

for i in range(N-1):
    if H[i] >= H[i+1]:
        cnt += 1
    else:
        if ans < cnt:
            ans = cnt
        cnt = 0    
if ans < cnt:
    ans = cnt
print(ans)
### BUGGY CODE ###

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

res = [a_s.index(i) + 1 for i in range(1, n + 1)]
for r in res:
	print(r, end=" ")


### FIXED CODE ###

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

res = sorted(range(1, n + 1), key=lambda k:a_s[k - 1])
for r in res:
	print(r, end=" ")
### BUGGY CODE ###

from collections import Counter
N = int(input())
A = list(map(int, input().split()))
B = Counter(A)
seen = [-1]*(5*10**5)
for i in range(N):
    if seen[A[i]] != -1:
        print(seen[A[i]])
        continue
    B[A[i]] -= 1
    ans = 0
    for n in B.values():
        ans += n*(n-1)//2
    print(ans)
    seen[A[i]] = ans
    B[A[i]] += 1

### FIXED CODE ###

from collections import Counter
N = int(input())
A = list(map(int, input().split()))
B = Counter(A)

ans = 0
for i in B.values():
    ans += i*(i-1)//2

for a in A:
    k = B[a]
    print(ans - (k*(k-1)//2)+((k-1)*(k-2)//2))
### BUGGY CODE ###

n = int(input())
h = [int(i) for i in input().split()]
for i in range(n - 1):
    if h[i] - 2 in h[i + 1:]:
        print("No")
        break
else:
    print("Yes")

### FIXED CODE ###

n = int(input())
h = [int(i) for i in input().split()]
x = True
c = 0
for i in range(n):
    if i > 0 and h[i - 1] - h[i] >= 2:
        x = False
        break
    elif i > 0 and h[i - 1] - h[i] == 1:
        c += 1
    elif i > 0 and h[i] > h[i - 1] and c == 1:
        c = 0
    if c == 2:
        x = False
        break
if x:
    print("Yes")
else:
    print("No")
### BUGGY CODE ###

N, M = map(int, input().split())
A, B = [], []
g = {}
for i in range(1, N+1):
    g[i] = []
for _ in range(M):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)
    g[a].append(b)
    g[b].append(a)


def dfs(graph, start):
    visited = []
    stack = []
    stack.append(start)
    result = []
    while len(stack) > 0:
        next = stack.pop()
        if next in visited:
            continue
        result.append(next)
        visited.append(next)
        for nei in graph[next]:
            stack.append(nei)
    return result


for i in range(M):
    ans = 0
    g[A[i]].remove(B[i])
    g[B[i]].remove(A[i])
    for j in range(1, N+1):
        for k in range(j, N+1):
            if k not in dfs(g, j):
                ans += 1
    print(ans)


### FIXED CODE ###

class UnionFind():
    # 初期化
    # 全てのノードの親は -1 とする
    def __init__(self, n):
        self.par = [-1] * n

    # xがどのグループに属しているか調べる
    def root(self, x):
        # xが親のとき
        if self.par[x] < 0:
            return x
        # xの親がさらに親をもつとき、それをxの親とする
        else:
            self.par[x] = self.root(self.par[x])
            return self.par[x]

    # 自分のいるグループの頂点数を調べる
    def size(self, x):
        return -self.par[self.root(x)]

    # xとyをくっつける
    def connect(self, x, y):
        x = self.root(x)
        y = self.root(y)
        # すでにくっついていたらくっつけない
        if x == y:
            return

        # 大きい方(x)に小さい方(y)をくっつける
        if self.size(x) < self.size(y):
            x, y = y, x

        # xのサイズを更新
        self.par[x] += self.par[y]
        # yの親をxに変更
        self.par[y] = x

        return


N, M = map(int, input().split())
A, B = [], []
for _ in range(M):
    a, b = map(int, input().split())
    # インデックスをずらす
    A.append(a-1)
    B.append(b-1)

uni = UnionFind(N)

ans = [N * (N-1) // 2]
for i in range(M-1, 0, -1):
    ans.append(ans[-1])
    # 繋がっていないグループがつながったとき
    if uni.root(A[i]) != uni.root(B[i]):
        ans[-1] -= uni.size(A[i]) * uni.size(B[i])
        uni.connect(A[i], B[i])

for item in reversed(ans):
    print(item)
### BUGGY CODE ###

def INT():
    return int(input())

def MI():
    return map(int, input().split())

def LI():
    return list(map(int, input().split()))

N = INT()
ans = [0] * N

def fn(x, y, z):
    f = x**2 + y**2 + z**2 + x * y + y * z + z * x
    return f

for n in range(1, N + 1):
    for x in range(1, int(N ** 0.5) + 1):
        for y in range(1, int(N ** 0.5) + 1):
            if fn(x, y, 1) > n:
                continue
            for z in range(1, int(N ** 0.5) + 1):
                f = fn(x, y, z)
                if f == n:
                    ans[f - 1] += 1

for a in ans:
    print(a)

### FIXED CODE ###

def INT():
    return int(input())

def MI():
    return map(int, input().split())

def LI():
    return list(map(int, input().split()))

N = INT()
ans = [0] * N

def fn(x, y, z):
    f = x**2 + y**2 + z**2 + x * y + y * z + z * x
    return f

for x in range(1, int(N ** 0.5) + 2):
    if fn(x, 1, 1) > N:
        break
    for y in range(1, int(N ** 0.5) + 2):
        if fn(x, y, 1) > N:
            break
        for z in range(1, int(N ** 0.5) + 2):
            f = fn(x, y, z)
            if f > N:
                break
            if f <= N:
                ans[f - 1] += 1

for a in ans:
    print(a)
### BUGGY CODE ###

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

aa = list(map(int, input().split()))
bb = list(map(int, input().split()))

mm = list()
for ii in range(0,m):
    mm.append(list(map(int, input().split())))

prices = list()

for ml in mm:
    prices.append(aa[ml[0]-1] + bb[ml[1]-1] - ml[2])

for al in aa:
    for bl in bb:
        prices.append(al + bl)

print(min(prices))


### FIXED CODE ###

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

aa = list(map(int, input().split()))
bb = list(map(int, input().split()))

mm = list()
for ii in range(0,m):
    mm.append(list(map(int, input().split())))

prices = list()

prices.append(int(min(aa)) + int(min(bb)))

for ml in mm:
    prices.append(aa[ml[0]-1] + bb[ml[1]-1] - ml[2])

print(min(prices))
### BUGGY CODE ###

s = str(input())
n=len(s)
left :int=1
mlist=[0]
while left<int(n)+1:
  m = int(s[n-left:n])%2019
  mlist.append(m)
  left+=1

ll=len(mlist)
l=len(set(mlist))
print(int(ll-l))

### FIXED CODE ###

import time

s = input()[::-1] # 入力文字列を逆順でsに格納

counts = [0] * 2019
counts[0] = 1

num, d = 0, 1

for char in s:
    num += int(char) * d
    num %= 2019
    d *= 10
    d%= 2019
    counts[num] += 1

#start = time.time()#計測始
ans = 0
for cnt in counts:
    ans += cnt * (cnt - 1) // 2

print(ans) # 答えの出力
#end = time.time()#計測終
#print(f"{end-start}sec.")#計測出力
### BUGGY CODE ###

import sys
sys.setrecursionlimit(300000)
from collections import defaultdict

def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def MI0(): return map(lambda s: int(s) - 1, sys.stdin.readline().split())
def LMI(): return list(map(int, sys.stdin.readline().split()))
def LMI0(): return list(map(lambda s: int(s) - 1, sys.stdin.readline().split()))
MOD = 10 ** 9 + 7
INF = float('inf')


D = I()
C = LMI()
S = [LMI() for _ in range(D)]
T = [I() - 1 for _ in range(D)]
M = I()


def eval(T):
    last = defaultdict(int)
    ans = 0
    for d in range(D):
        ans += S[d][T[d]]
        last[T[d]] = d + 1
        for i in range(26):
            ans -= C[i] * (d + 1 - last[i])
    return ans

for d, q in [tuple(MI0()) for _ in range(M)]:
    T[d] = q
    print(eval(T))


### FIXED CODE ###

import sys
sys.setrecursionlimit(300000)
from collections import defaultdict

def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def MI0(): return map(lambda s: int(s) - 1, sys.stdin.readline().split())
def LMI(): return list(map(int, sys.stdin.readline().split()))
def LMI0(): return list(map(lambda s: int(s) - 1, sys.stdin.readline().split()))
MOD = 10 ** 9 + 7
INF = float('inf')


D = I()
C = LMI()
S = [LMI() for _ in range(D)]
T = [I() - 1 for _ in range(D)]
M = I()

last = [[i + 1] * 26 for i in range(D)]
for d in range(D):
    i = T[d]
    j = 0
    for dd in range(d, D):
        last[dd][i] = j
        j += 1

def eval(d, q):
    i = T[d]
    val = S[d][q] - S[d][i]

    contrib = 0
    if d == 0:
        j = 1
    else:
        j = last[d - 1][i] + 1
    for dd in range(d, D):
        if dd > d and last[dd][i] == 0:
            break
        contrib += j - last[dd][i]
        last[dd][i] = j
        j += 1
    val -= contrib * C[i]

    contrib = 0
    j = 0
    for dd in range(d, D):
        if last[dd][q] == 0:
            break
        contrib += last[dd][q] - j
        last[dd][q] = j
        j += 1
    val += contrib * C[q]

    T[d] = q

    return val


def score0(T):
    last = defaultdict(int)
    ans = 0
    for d in range(D):
        ans += S[d][T[d]]
        last[T[d]] = d + 1
        for i in range(26):
            ans -= C[i] * (d + 1 - last[i])
    return ans


score = score0(T)
for d, q in [tuple(MI0()) for _ in range(M)]:
    val = eval(d, q)
    score += val
    print(score)
### BUGGY CODE ###

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

for i in range(N):
    kari = A[i]
    A[i] = 0
    print(max(A))
    A[i] = kari

### FIXED CODE ###

N = int(input())
A = [int(input()) for _ in range(N)]

MAX_1 = max(A)
MAX_2 = sorted(A)[-2]

for i in range(N):
    if A[i] == MAX_1:
        print(MAX_2)
    else:
        print(MAX_1)
### BUGGY CODE ###

from itertools import product
from collections import deque

H, W = [int(i) for i in input().split()]
grid = [list(input()) for _ in range(H)]
reached = [[0] * W for _ in range(H)]

queue = deque()
for y, x in product(range(H), range(W)):
    if grid[y][x] == "#":
        queue.append((y, x, 0))

if len(queue) == H * W:
    print(0)
    exit()

ans = 0
while queue:
    y, x, steps = queue.popleft()
    if not (0 <= y < H and 0 <= x < W):
        continue
    if reached[y][x]:
        continue
    reached[y][x] = 1
    ans = max(ans, steps)
    for dy, dx in ((-1, 0), (1, 0), (0, -1), (0, 1)):
        queue.append((y+dy, x+dx, steps+1))
print(ans)


### FIXED CODE ###

from itertools import product
from collections import deque

H, W = [int(i) for i in input().split()]
grid = [list(input()) for _ in range(H)]
reached = [[0] * W for _ in range(H)]

queue = deque()
for y, x in product(range(H), range(W)):
    if grid[y][x] == "#":
        queue.append((y, x, 0))

if len(queue) == H * W:
    print(0)
    exit()

while queue:
    y, x, steps = queue.popleft()
    for dy, dx in ((-1, 0), (1, 0), (0, -1), (0, 1)):
        ny, nx = y + dy, x + dx
        if not (0 <= ny < H and 0 <= nx < W):
            continue
        if reached[ny][nx]:
            continue
        reached[ny][nx] = 1
        queue.append((ny, nx, steps+1))
print(steps)