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

N,X,M = map(int,input().split())
ls = [X]
for i in range(M):
    Ai = ls[-1]**2 % M
    if Ai in ls:
        loop = ls[ls.index(Ai):]
        lenloop = len(loop)
        sumloop = sum(loop)
        startls = ls[:ls.index(Ai)]
        break
    ls.append(Ai)
if N <= len(startls):
    ans = sum(startls[:N])
else:
    ans = sum(startls) + ((N-len(startls))//lenloop)*sumloop + sum(loop[:(N-len(startls))%lenloop])
print(ans)


### FIXED CODE ###

N,X,M = map(int,input().split())
ls = [X]
for i in range(M):
    Ai = ls[-1]**2 % M
    if Ai in ls:
        loop = ls[ls.index(Ai):]
        lenloop = len(loop)
        sumloop = sum(loop)
        startls = ls[:ls.index(Ai)]
        break
    ls.append(Ai)
if N <= len(startls):
    ans = sum(startls[:N])
else:
    ans = sum(startls) + ((N-len(startls))//lenloop)*sumloop + sum(loop[:(N-len(startls))%lenloop])
print(ans)
### BUGGY CODE ###

#! /usr/bin/env python
# -*- coding: utf-8 -*-

N = int(raw_input())
while N!=0:
    (W, H) = map(int, raw_input().split())
    PT = []
    for i in range(N):
        PT.append(map(int, raw_input().split()))
    Max = 0
    (S, T) = map(int, raw_input().split())
    PT.sort()
    for i in range(1, W+1):
        for j in range(1, H+1):
            cnt = 0
            for k in range(N):
                if i <= PT[k][0] and PT[k][0] < i+S and \
                        j <= PT[k][1] and PT[k][1] < j+T:
                            cnt += 1
            if Max < cnt:
                Max = cnt
    print Max

    N = int(raw_input())

### FIXED CODE ###

#! /usr/bin/env python
# -*- coding: utf-8 -*-

N = int(raw_input())
while N!=0:
    (W, H) = map(int, raw_input().split())
    E = [[0]*H for i in range(W)]
    for i in range(N):
        (x, y) = map(int, raw_input().split())
        E[x-1][y-1] = 1
    (S, T) = map(int, raw_input().split())

    Max = 0
    for i in range(W-S+1):
        for j in range(H-T+1):
            Sum = 0
            for k in range(S):
                for l in range(T):
                    Sum += E[i+k][j+l]
            if Sum > Max:
                Max = Sum
    print Max
    N = int(raw_input())
### BUGGY CODE ###

import sys
input = sys.stdin.readline

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

a2 = 1
a1 = 0 if 1 in A else 1 
for i in range(2,N+1):
    if i in A:
        a = 0
        a2 = a1
        a1 = a
    else:
        a = (a2+a1)%1000000007
        a2 = a1
        a1 = a
print(1 if N == 1 else a%1000000007)


### FIXED CODE ###

n,m = map(int,input().split())
a = [ int(input()) for _ in range(m)]
M=10**9+7
lis = [1] + [0]*n

for i in a:
  lis[i]=-1
lis[1] += 1
for i in range(n-1):
  if lis[i+2]<0:
    lis[i+2]= 0
  else:
    lis[i+2] = (lis[i+1] + lis[i])%M
print(lis[n])
### BUGGY CODE ###

a = int(input())
b = list(map(int, input().split()))
c = 1
for n in b:
    c = c*n

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

### FIXED CODE ###

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

if 0 in b:
    print(0)
    exit()

for n in b:
    c = c*n
    if c > 10**18:
        print(-1)
        exit()

print(c)
### BUGGY CODE ###

# https://atcoder.jp/contests/abc140/tasks/abc140_d

n, k = map(int, input().split())
str_n = input()
changed_str = [str_n]
left = ""
right = ""

if str_n[0] == "R":
    left = "RL"
    right = "LR"
else:
    left = "LR"
    right = "RL"

for count in range(k): 
    ew_line = changed_str[count]
    first = ew_line.find(left)
    last = ew_line.rfind(right) or -1
    change_count = last - first

       
    head = ew_line[:first + 1]
    body = ""
    foot = ""
    if last != -1:
        body = ew_line[first + 1:last + 1][::-1]
        foot = ew_line[last + 1:]
    else:
        body = ew_line[first + 1:]
    
    body = body.replace("R","C").replace("L","R").replace("C","L")

    new_line = head + body + foot
    changed_str.append(new_line)

# print(changed_str[k])
count = 0
result_line = changed_str[k]
for i in range(len(changed_str[k]) - 1):
    if result_line[i] == result_line[i + 1]:
        count += 1

print(count)

### FIXED CODE ###

# https://atcoder.jp/contests/abc140/tasks/abc140_d

n, k = map(int, input().split())
str_n = input()
first = str_n[0]
last = ""
if first == "R":
    last = "L"
else:
    last = "R"

for count in range(k): 
    new_line = str_n
    next_last = new_line.find(last)
    next_first = new_line.find(first, next_last)
    next_line = new_line[0:next_last]
    if next_first != -1:
        next_line += new_line[next_last:next_first].replace(last, first) + new_line[next_first:]
    else:
        next_line += new_line[next_last:].replace(last, first)
    str_n = next_line

count = 0
result_line = str_n
for i in range(len(str_n) - 1):
    if result_line[i] == result_line[i + 1]:
        count += 1

print(count)
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10**9)
n,q = map(int,input().split())
ki = [[]for _ in range(n)]
def dfs(now,last = -1):
    for next in ki[now]:
        if next == last:continue
        cnt[next] += cnt[now]
        dfs(next,now)

for i in range(n-1):
    a,b = map(int,input().split())
    a -= 1
    b -= 1
    ki[a].append(b)
    ki[b].append(a)
cnt = [0]*n
for i in range(q):
    p,x = map(int,input().split())
    p-=1
    cnt[p]+=x
dfs(0)
print(*cnt)

### FIXED CODE ###

import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
N,Q = map(int,input().split())
 
AB = [[int(x) for x in input().split()] for _ in range(N-1)] 
PX = [[int(x) for x in input().split()] for _ in range(Q)]

ki = [[]for _ in range(N)]
for a,b in AB:
    a-=1
    b-=1
    ki[a].append(b)
    ki[b].append(a)
point = [0]*(N)
for p,x in PX:
    p-=1
    point[p]+=x
def dfs(now, last ,add):
    point[now]+= add
    for x in ki[now]:
        if (x == last):continue
        dfs(x,now,point[now])
dfs(0,0,0)
print(*point)
### BUGGY CODE ###

from functools import reduce
N,K = map(int, input().split())
A = list(map(int, input().split()))
M = reduce((lambda X,Y: X*Y), A[:K])
while True:
    A.pop(0)
    if len(A) == K - 1:
        break
    P = reduce((lambda X,Y: X*Y), A[:K])
    print('Yes' if P > M else 'No')
    M = P

### FIXED CODE ###

N,K = map(int, input().split())
A = list(map(int, input().split()))
for i in range (K,N):
    print('Yes' if A[i] > A[i-K] else 'No')
### BUGGY CODE ###

import sys
input = lambda: sys.stdin.readline().rstrip()
r, c, k = map(int, input().split())
pt = [[0 for _ in range(c + 5)] for _ in range(r + 5)]

for i in range(k):
    r1, c1, v = map(int, input().split())
    pt[r1][c1] = v

memo = [[0] * 4 for _ in range(c + 1)]
prev = [[0] * 4 for _ in range(c + 1)]
for i in range(1, r + 1):
    memo, prev = prev, memo
    for j in range(1, c + 1):
        V = pt[i][j]
        memo[j][0] = max(prev[j][3], memo[j - 1][0])
        memo[j][1] = max(memo[j][0] + V, memo[j - 1][1])
        memo[j][2] = max(memo[j][1], memo[j - 1][1] + V, memo[j - 1][2])
        memo[j][3] = max(memo[j][2], memo[j - 1][2] + V, memo[j - 1][3])
print(memo[-1][3])


### FIXED CODE ###

import sys
# import time
input = lambda: sys.stdin.readline().rstrip()
r, c, k = map(int, input().split())
# dp = [[[0] * 3 for _ in range(c + 5)] for _ in range(r + 5)]
pt = [[0 for _ in range(c + 5)] for _ in range(r + 5)]

for i in range(k):
    r1, c1, v = map(int, input().split())
    # dp[r1][c1][0] = v
    pt[r1][c1] = v

# start = time.time()
a = 0


def solve():
    memo = [[0] * 4 for _ in range(c + 1)]
    prev = [[0] * 4 for _ in range(c + 1)]
    for i in range(1, r + 1):
        memo, prev = prev, memo
        for j in range(1, c + 1):
            V = pt[i][j]
            memo[j][0] = max(prev[j][3], memo[j - 1][0])
            memo[j][1] = max(memo[j][0] + V, memo[j - 1][1])
            memo[j][2] = max(memo[j][1], memo[j - 1][1] + V, memo[j - 1][2])
            memo[j][3] = max(memo[j][2], memo[j - 1][2] + V, memo[j - 1][3])

            # dp[i][j][0] = max(dp[i - 1][j][2] + V, dp[i][j - 1][0])
            # dp[i][j][1] = max(dp[i][j - 1][0] + V, dp[i][j - 1][1],
            #                   dp[i][j][0])
            # dp[i][j][2] = max(dp[i][j - 1][1] + V, dp[i][j - 1][2],
            #                   dp[i][j][1])

    # process_time = time.time() - start

    # print(process_time)

    # print(dp[r][c][2])
    return memo[-1][3]





if __name__ == '__main__':
    print(solve())
### BUGGY CODE ###

HWD=input()
HWD=HWD.rstrip().split(" ")
H=int(HWD[0])
W=int(HWD[1])
D=int(HWD[2])
 
list1=[[0,0]]*(H*W)
for i in range(H):
    line=input()
    line=line.rstrip().split(" ")
    for j in range(W):
        list1[int(line[j])-1]=[i,j]
#print(list1)
 
 
    
N=int(input())
#print(N)
 
for k in range(N):
    LR=input()
    LR=LR.rstrip().split(" ")
    L=int(LR[0])
    R=int(LR[1])
    
    if L==R:
        print(0)
    else:
        count=0
        for l in range(int((R-L)/D)):
            L1=list1[L-1]
            L2=list1[L+D-1]
            #print(L1)
            #print(L2)
            count=count+abs(list1[L-1][0]-list1[L+D-1][0])+abs(list1[L-1][1]-list1[L+D-1][1])
            L=L+D
        print(int(count))

### FIXED CODE ###

H,W,D=map(int,input().split())
L=[0 for i in range(H*W+1)]
A=[]
for i in range(H):
    a=list(map(int,input().split()))
    A.append(a)
    
for i in range(H):
    for j in range(W):
        L[A[i][j]]=[i+1,j+1]
L[0]=[0,0]
#print(L)
l=[0 for i in range(H*W+1)]
for i in range(D):
    for j in range(H*W+1):
        if (i+j*D)>(H*W):
            break
        elif j==0:
            l[i+j*D]=0
        else:
            l[i+j*D]=l[i+(j-1)*D]+abs(L[i+j*D][0]-L[i+(j-1)*D][0])+abs(L[i+j*D][1]-L[i+(j-1)*D][1])
#print(l)
Q=int(input())
for i in range(Q):
    a,b=map(int,input().split())
    print(l[b]-l[a])
### BUGGY CODE ###

a,b,c,d = map(int,input().split())
ans = 0
dp = [[0]*(d+1) for i in range(c+1)]
mod = 998244353
dp[a][b] = 1
for i in range(a+1,c+1):
    dp[i][b] = dp[i-1][b] * b % mod
for i in range(b+1,d+1):
    dp[a][i] = dp[a][i-1] * a % mod
for i in range(a+1,c+1):
    for j in range(b+1,d+1):
        dp[i][j] = ((dp[i-1][j]*j) + (dp[i][j-1]*i) - (dp[i-1][j-1]*(i-1)*(j-1)))%mod
print(dp[c][d])

### FIXED CODE ###

a,b,c,d = map(int,input().split())
ans = 0
dp = [[0]*(d+1) for i in range(c+1)]
mod = 998244353
dp[a][b] = 1
for i in range(a+1,c+1):
    dp[i][b] = dp[i-1][b] * b % mod
for i in range(b+1,d+1):
    dp[a][i] = dp[a][i-1] * a % mod
for i in range(a+1,c+1):
    for j in range(b+1,d+1):
        dp[i][j] = ((dp[i-1][j]*j) + (dp[i][j-1]*i) - (dp[i-1][j-1]*(i-1)*(j-1)))%mod
print(dp[c][d])
### BUGGY CODE ###

from bisect import bisect_left
N = int(input())
X = list(map(int, input().split()))

sX = sorted(X)

for i in range(N):
    p = bisect_left(sX, X[i])
    lr = sX[:p] + sX[p+1:]
    print(lr[len(lr) // 2])

### FIXED CODE ###

# O(N * log(Xn))
from bisect import bisect_left
import sys
readline = sys.stdin.readline
N = int(readline())
X = [int(x) for x in readline().split()]

# X = [i for i in range(2*10**5)]
# N = len(X)

sX = sorted(X)
m = (N - 1) // 2
for i in range(N):
    p = bisect_left(sX, X[i])
    if p <= m:
        print(sX[m + 1])
    else:
        print(sX[m])
### BUGGY CODE ###

N = int(input())
X = list(map(int, input().split()))
Y = 1
for i in range(0, N):
  Y = X[i] * Y
if Y <= 1000000000000000000:
  print(Y)
else:
  print(-1)

### FIXED CODE ###

import sys

N = int(input())
X = list(map(int, input().split()))
if min(X) == 0:
  print(0)
  sys.exit()
Y = X[0]
for i in range(1, N):
  Y = X[i] * Y
  if Y > 10 ** 18:
    print(-1)
    sys.exit()
print(Y)
### BUGGY CODE ###

# abc077_c.py
'''
多分あとは、Bで重複がある場合は探索しないで個数かけていくとかにしないといけない。
'''
def is_okC(idx,key,target):
########## wirte criteria here ##########
    if target[idx] > key:
        return True
    return False

def meguru_bisectC(key,target):
    left = -1
    right = len(target)
    while (abs(right - left) > 1):
        mid = left + (right - left) // 2
        if is_okC(mid,key,target):
            right = mid
        else:
            left = mid
#    print("C : ",target[right:])
    return target[right:]


def is_okA(idx,key,target):
########## wirte criteria here ##########
    if target[idx] >= key:
        return True
    return False

def meguru_bisectA(key,target):
    left = -1
    right = len(target)
    while (abs(right - left) > 1):
        mid = left + (right - left) // 2
#        print("mid : " , mid)
        if is_okA(mid,key,target):
            right = mid
        else:
            left = mid
#    print("A : ",target[:right])
    return target[:right]

N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))
A.sort()
C.sort()
a = 0
c = 0
ans = 0

for i in B:
    a = len(meguru_bisectA(i,A))
#    print("i : ",i)
    c = len(meguru_bisectC(i,C))
    ans += a*c
#    print()

print(ans)

### FIXED CODE ###

# abc077_c.py
'''
多分あとは、Bで重複がある場合は探索しないで個数かけていくとかにしないといけない。
'''
def is_okC(idx,key,target):
########## wirte criteria here ##########
    if target[idx] > key:
        return True
    return False

def meguru_bisectC(key,target):
    left = -1
    length = len(target)
    right = length
    while (abs(right - left) > 1):
        mid = left + (right - left) // 2
        if is_okC(mid,key,target):
            right = mid
        else:
            left = mid
    return length-right


def is_okA(idx,key,target):
########## wirte criteria here ##########
    if target[idx] >= key:
        return True
    return False

def meguru_bisectA(key,target):
    left = -1
    length = len(target)
    right = length
    while (abs(right - left) > 1):
        mid = left + (right - left) // 2
#        print("mid : " , mid)
        if is_okA(mid,key,target):
            right = mid
        else:
            left = mid
    return right

N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))
A.sort()
C.sort()
a = 0
c = 0
ans = 0
#print(A)
#print(B)
#print(C)
for i in B:
    a = meguru_bisectA(i,A)
#    print(A[:a] )
#    print("i : ",i)
    c = meguru_bisectC(i,C)
#    print(C[c:])
    ans += a*c
#    print()

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

def resolve():
    import sys
    readline = sys.stdin.readline
    N = int(readline())
    info = [None] * N
    for i in range(N):
        p, l = map(int, input().split())
        info[i] = [p-l, p+l]
    info.sort(key=lambda x: x[0])

    def is_obstacle(i):
        count = 0
        for j in info[i+1:]:
            if info[i][1] > j[0]:
                count += 1
        for j in info[:i]:
            if info[i][0] < j[1]:
                count += 1
        return count

    obs_list = [1] * N
    while sum(obs_list) > 0:
        obs_list = [0] * N
        m = 0
        idx = 0
        for i in range(N):
            obs_list[i] = is_obstacle(i)
            if m < obs_list[i]:
                m = obs_list[i]
                idx = i
        if sum(obs_list) == 0:
            break
        info = info[:idx] + info[idx+1:]
        N -= 1

    print(N)

resolve()


### FIXED CODE ###

def resolve():
    import sys
    from operator import itemgetter
    readline = sys.stdin.readline
    N = int(readline())
    LR = [None] * N
    for i in range(N):
        p, l = map(int, input().split())
        LR[i] = [p-l, p+l]
    LR.sort(key=itemgetter(1))

    pre_r = -(10**18)
    count = 0
    for l, r in LR:
        if pre_r <= l:
            count += 1
            pre_r = r
    print(count)

resolve()
### BUGGY CODE ###

def solve(_list,_k):
  start = 0
  _sum = -1
  for i in range(len(_list)-_k+1):
    tmp = _list[i:i+_k]
    s = sum(tmp)
    if _sum < s:
      _sum = s
      start = i

  ans = 0.
  for item in _list[start:start+_k]:
    upper = sum([j for j in range(item+1)])
    ans += upper / item

  return ans


if __name__ == "__main__":
  _n, _k = map(int, input().split())
  _l = [int(i) for i in input().split()]
  #_l = np.array(_l)

  result = solve(_l, _k)
  print(result)


### FIXED CODE ###

def solve(_list,_k):
  accumulate_list = [0.]
  for i in _list:
    accumulate_list.append((i+1)/2 + accumulate_list[-1])

  ans = -1.0
  for i in range(len(accumulate_list)-_k):
    ans = max(ans, accumulate_list[i+_k]-accumulate_list[i])
  return ans

if __name__ == "__main__":
  _n, _k = map(int, input().split())
  _l = [int(i) for i in input().split()]

  result = solve(_l, _k)
  print(result)
### BUGGY CODE ###

N = int(input())
S = list(map(int, input().split()))
ans = 1

for s in S:
  ans *= s
  
if ans > 10 ** 18:
  print(-1)
else:
  print(ans)

### FIXED CODE ###

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

def f():
    if 0 in S:
        return 0
    elif 10 ** 18 in S:
        return -1
    else:
        ans = 1
        for s in S:
            ans *= s
            if ans > 10 ** 18:
                return -1
        return ans

print(f())
### BUGGY CODE ###

# ダイナミック・プログラミング

INF = float('inf')

H, N = map(int, input().split())
A = []
B = []

def chmin(a, b):
    if a>=b:
        return b
    else:
        return a

for i in range(N):
    a_i, b_i = map(int, input().split())
    A.append(a_i)
    B.append(b_i)

dp = [[INF]*(H+1) for i in range(N+1)] # DP用配列
dp[0][0] = 0 # 初期化処理
for i in range(0,N):
    for j in range(0,H+1):
        dp[i+1][j] = chmin(dp[i+1][j], dp[i][j])
        dp[i+1][min(j+A[i],H)] = chmin(dp[i+1][min(j+A[i],H)], dp[i+1][j]+B[i])

print(dp[N][H])


### FIXED CODE ###

# ダイナミック・プログラミング
# PythonではTLEを起こしてしまう例

INF = float('inf')

H, N = map(int, input().split())
A = []
B = []

for i in range(N):
    a_i, b_i = map(int, input().split())
    A.append(a_i)
    B.append(b_i)

dp = [[INF]*(H+1) for i in range(N+1)] # DP用配列
dp[0][0] = 0 # 初期化処理
for i in range(0,N):
    for j in range(0,H+1):
        a, b = j+A[i], H
        min_h = a
        if a>b:
            min_h = b
        a, b = dp[i+1][j], dp[i][j]
        if a>b:
            dp[i+1][j] = b
        a, b = dp[i+1][min_h], dp[i+1][j]+B[i]
        if a>b:
            dp[i+1][min_h] = b

print(dp[N][H])
### BUGGY CODE ###

H, W, M = map(int, input().split())

HB = [0] * H
WB = [0] * W

place = []

for i in range(M):
    h, w = map(int, input().split())
    place.append((h, w,))

    HB[h - 1] += 1
    WB[w - 1] += 1

HBC = [i for i, x in enumerate(HB) if x == max(HB)]
WBC = [i for i, x in enumerate(WB) if x == max(WB)]
result = max(HB) + max(WB)

sw = False
for i in HBC:
    for j in WBC:
        if (i + 1, j + 1,) not in place:
            sw = True
            break
    
    if sw:
        break

if not sw:
    result -= 1

print(result)

### FIXED CODE ###

H, W, M = map(int, input().split())
 
HB = [0] * H
WB = [0] * W
 
place = []
 
for i in range(M):
    h, w = map(int, input().split())
    place.append((h, w,))
 
    HB[h - 1] += 1
    WB[w - 1] += 1
m_hb = max(HB)
m_wb = max(WB)
result = m_hb + m_wb
 
count = 0
for x, y in place:
    if HB[x - 1] == m_hb and WB[y - 1] == m_wb:
        count += 1


 
if HB.count(m_hb) * WB.count(m_wb) <= count:
    result -= 1
 
print(result)
### BUGGY CODE ###

#!/usr/bin/env python

import random

class Dice:
    def __init__(self, top, s, e, w, n, bottom):
        self.top    = top
        self.s      = s
        self.e      = e
        self.w      = w
        self.n      = n
        self.bottom = bottom

    def rotate(self, dist):
        if dist == 'N':
            self.top, self.s, self.n, self.bottom = self.s, self.bottom, self.top, self.n 
        elif dist == 'S':
            self.s, self.bottom, self.top, self.n = self.top, self.s, self.n, self.bottom 
        elif dist == 'E':
            self.top, self.e, self.w, self.bottom = self.w, self.top, self.bottom, self.e 
        elif dist == 'W':
            self.w, self.top, self.bottom, self.e = self.top, self.e, self.w, self.bottom 

if __name__ == '__main__':
    dice1 = Dice(*map(int, raw_input().split()))
    dice2 = Dice(*map(int, raw_input().split()))

    ref1 = set()
    ref2 = set()
    while len(ref1)<24:
        ref1.add((dice1.top, dice1.s, dice1.e))
        ref2.add((dice2.top, dice2.s, dice2.e))

        dist = 'NSEW'[random.randint(0,3)]
        dice1.rotate(dist)
        dice2.rotate(dist)

    print 'Yes' if ref1==ref2 else 'No'



### FIXED CODE ###

#!/usr/bin/env python

import random

class Dice:
    def __init__(self, top, s, e, w, n, bottom):
        self.top    = top
        self.s      = s
        self.e      = e
        self.w      = w
        self.n      = n
        self.bottom = bottom

    def rotate(self, dist):
        if dist == 'N':
            self.top, self.s, self.n, self.bottom = self.s, self.bottom, self.top, self.n 
        elif dist == 'S':
            self.s, self.bottom, self.top, self.n = self.top, self.s, self.n, self.bottom 
        elif dist == 'E':
            self.top, self.e, self.w, self.bottom = self.w, self.top, self.bottom, self.e 
        elif dist == 'W':
            self.w, self.top, self.bottom, self.e = self.top, self.e, self.w, self.bottom 

if __name__ == '__main__':
    dice1 = Dice(*map(int, raw_input().split()))
    dice2 = Dice(*map(int, raw_input().split()))

    ref1 = set()
    ref2 = set()
    for _ in range(1000):
        if len(ref1) > 23:
            break

        ref1.add((dice1.top, dice1.s, dice1.e))
        ref2.add((dice2.top, dice2.s, dice2.e))

        dist = 'NSEW'[random.randint(0,3)]
        dice1.rotate(dist)
        dice2.rotate(dist)

    print 'Yes' if ref1==ref2 else 'No'
### BUGGY CODE ###

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


for i in range(len(a)):
  print(1+a.index(i+1),end=" ")


### FIXED CODE ###

a=int(input())
b=[0]*a
c=list(map(int,input().split()))

for i in range(a):
  b[c[i]-1]+=i+1
print(' '.join(map(str, b)))
### BUGGY CODE ###

import sys
from collections import deque

sys.setrecursionlimit(10000)
INF = float('inf')

H, W = list(map(int, input().split()))
A = [list(input()) for _ in range(H)]


def is_white(h, w):
    return 0 <= h < H and 0 <= w < W and A[h][w] == '.'


que = deque()
for h in range(H):
    for w in range(W):
        if A[h][w] == '#':
            if is_white(h + 1, w):
                que.append((h + 1, w))
            if is_white(h - 1, w):
                que.append((h - 1, w))
            if is_white(h, w + 1):
                que.append((h, w + 1))
            if is_white(h, w - 1):
                que.append((h, w - 1))

ans = 0
while len(que) > 0:
    ans += 1
    nextq = deque()
    while len(que) > 0:
        h, w = que.pop()
        A[h][w] = '#'
        if is_white(h + 1, w):
            nextq.append((h + 1, w))
        if is_white(h - 1, w):
            nextq.append((h - 1, w))
        if is_white(h, w + 1):
            nextq.append((h, w + 1))
        if is_white(h, w - 1):
            nextq.append((h, w - 1))
    que = nextq
print(ans)


### FIXED CODE ###

import sys
import numpy as np

sys.setrecursionlimit(10000)
INF = float('inf')

H, W = list(map(int, input().split()))
A = np.array([list(input()) for _ in range(H)])

counts = np.zeros((H, W))
counts[A == '.'] = np.inf

for h in range(1, H):
    counts[h, :] = np.minimum(counts[h, :], counts[h - 1, :] + 1)
    counts[-1 - h, :] = np.minimum(counts[-1 - h, :], counts[-h, :] + 1)
for w in range(1, W):
    counts[:, w] = np.minimum(counts[:, w], counts[:, w - 1] + 1)
    counts[:, -1 - w] = np.minimum(counts[:, -1 - w], counts[:, -w] + 1)

print(int(np.max(counts)))