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

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

# ループする数を求める
loop_num = 2 * 10 ** 5
loop_start_index = 0
point = 1
route_list = [1]

for i in range(K):
    point = Alist[point - 1]
    if point in route_list:
        loop_start_index = route_list.index(point)
        loop_num = i + 1 - loop_start_index
        break

    route_list.append(point)

print(route_list[loop_start_index  + ((K-loop_start_index) % loop_num)])

### FIXED CODE ###

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

# ループする数を求める
loop_num = 2 * 10 ** 5
loop_start_point = -1
point = 1
count_list = [-1] * N

for i in range(K):
    #print("point:", point)
    count_list[point - 1] = i
    nextPoint = Alist[point - 1]

    if count_list[nextPoint - 1] != -1:
        loop_start_point = nextPoint
        loop_num = i - count_list[loop_start_point - 1] + 1
        break
    
    point = nextPoint

if loop_start_point == -1:
    print(point)
else:
    point = loop_start_point
    progress_num = (K - count_list[loop_start_point-1]) % loop_num
    for i in range(progress_num):
        point = Alist[point - 1]
    #print("pro:", progress_num)
    #print("ls:", loop_start_point)
    #print("ln:", loop_num)
    print(point)
### BUGGY CODE ###

from collections import deque

def bfs(graph, start, goal, connection):
    visited = {start: None}
    unvisited = deque()
    unvisited.append(start)
    while unvisited:
        now = unvisited.popleft()
        if now == goal or goal in connection[now]:
            connection[start].add(goal)
            connection[goal].add(start)
            return "yes"
        for next in graph[now]:
            if not (next in visited):
                unvisited.append(next)
                visited[next] = now
    return "no"

n, m = map(int, input().split())
g = [set() for i in range(n)]
c = [set() for i in range(n)]

for i in range(m):
    a, b = map(int, input().split())
    g[a].add(b)
    g[b].add(a)
    c[a].add(b)
    c[b].add(a)

q = int(input())

for i in range(q):
    s, t = map(int, input().split())
    print(bfs(g, s, t, c))

### FIXED CODE ###

from collections import deque

def bfs(graph, start):
    visited = {start: None}
    unvisited = deque()
    unvisited.append(start)
    while unvisited:
        now = unvisited.popleft()
        for next in graph[now]:
            if not (next in visited):
                unvisited.append(next)
                visited[next] = now
    return visited

n, m = map(int, input().split())
g = [set() for i in range(n)]
group = []

for i in range(m):
    a, b = map(int, input().split())
    g[a].add(b)
    g[b].add(a)

q = int(input())

for i in range(q):
    s, t = map(int, input().split())
    for j in range(len(group)):
        if s in group[j] and t in group[j]:
            print("yes")
            break
        elif s in group[j]:
            print("no")
            break
    else:
        group_tmp = set(bfs(g, s).keys())
        if t in group_tmp:
            print("yes")
        else:
            print("no")
        group.append(group_tmp)
### BUGGY CODE ###

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

if n == 1:
    a = int(input())
    for i in range(m):
        a //= 2
    print(a)
    exit()

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

for i in range(m):
    x = a.pop() // 2
    tmp = []
    for i in range(n):
        try:
            y = a.pop()
        except IndexError:
            a.append(x)
            a.extend(tmp[::-1])
            break

        if x < y:
            tmp.append(y)

        else:
            a.append(y)
            a.append(x)
            a.extend(tmp[::-1])
            break
print(sum(a))


### FIXED CODE ###

import heapq
import sys
input = sys.stdin.readline


def _heappush_max(heap, item):
    heap.append(item)
    heapq._siftdown_max(heap, 0, len(heap)-1)


def _heappop_max(heap):
    """Maxheap version of a heappop."""
    lastelt = heap.pop()    # raises appropriate IndexError if heap is empty
    if heap:
        returnitem = heap[0]
        heap[0] = lastelt
        heapq._siftup_max(heap, 0)
        return returnitem
    return lastelt


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

    if n == 1:
        a = int(input())
        for i in range(m):
            a //= 2
        print(a)
        exit()

    a = (list(map(int, input().split())))
    heapq._heapify_max(a)

    for i in range(m):
        tmp = _heappop_max(a) // 2
        _heappush_max(a, tmp)

    print(sum(a))


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

N,S=map(int,input().split())
A=[0]+list(map(int,input().split()))
         
mod = 998244353

note = [[0 for i in range(S+1)] for n in range(N+1)]

for n in range(1,N+1):
  for i in range(1,S+1):
    if A[n]>i:
      note[n][i] = (note[n-1][i]*2) % mod
    elif A[n] == i:
      note[n][i] = note[n-1][i]*2 + pow(2,n-1,mod)
      note[n][i] = note[n][i] % mod 
    else:
      note[n][i] = note[n-1][i] * 2 + note[n-1][i-A[n]]
      note[n][i] = note[n][i] % mod
  #print(note)
print(note[N][S] % mod)
  
    
       

### FIXED CODE ###

N,S=map(int,input().split())
A=[0]+list(map(int,input().split()))
       
mod = 998244353

note = [[0 for i in range(S+1)] for n in range(N+1)]

for n in range(1,N+1):
  for i in range(1,S+1):
    if A[n]>i:
      note[n][i] = (note[n-1][i]*2) % mod
    elif A[n] == i:
      note[n][i] = (note[n-1][i]*2 + pow(2,n-1,mod)) % mod
      note[n][i] = note[n][i] % mod 
    else:
      note[n][i] = (note[n-1][i] * 2 + note[n-1][i-A[n]]) % mod
      note[n][i] = note[n][i] % mod
  #print(note)
print(note[N][S] % mod)
### BUGGY CODE ###

N, Q = list(map(int, input().split()))
S = input()
l = [0] * Q
r = [0] * Q
for x in range(Q):
    l[x], r[x] = list(map(int, input().split()))

isAC = [False] * len(S)
for x in range(len(S) - 1):
    if S[x] == "A" and S[x + 1] == "C":
        isAC[x] = True

for x in range(Q):
    ans = 0
    cut_isAC = isAC[l[x] - 1:r[x] - 1]
    for y in range(len(cut_isAC)):
        if cut_isAC[y]:
            ans += 1
    print(ans)


### FIXED CODE ###

N, Q = list(map(int, input().split()))
S = input()
l = [0] * Q
r = [0] * Q
for x in range(Q):
    l[x], r[x] = list(map(int, input().split()))

countAC = [0] * len(S)
for x in range(len(S) - 1):
    countAC[x + 1] = countAC[x]
    if S[x] == "A" and S[x + 1] == "C":
        countAC[x + 1] += 1
for x in range(Q):
    print(countAC[r[x] - 1] - countAC[l[x] - 1])
### BUGGY CODE ###

from itertools import combinations, groupby
from operator import mul
from functools import reduce

def ncr(n,r):
  if r == 0: return 1
  numer = reduce(mul, range(n, n-r, -1))
  denom = reduce(mul, range(1, r+1))
  return numer//denom

N, K = map(int,input().split())
MOD = 10**9 + 7

for k in range(1,K+1): print((ncr(N-K+1,k)*ncr(K-1,k-1))%MOD)

### FIXED CODE ###

from itertools import combinations, groupby
from operator import mul
from functools import reduce

def ncr(n,r):
  if r == 0: return 1
  numer = reduce(mul, range(n, n-r, -1), 1)
  denom = reduce(mul, range(1, r+1), 1)
  return numer//denom

N, K = map(int,input().split())
MOD = 10**9 + 7

for k in range(1,K+1):
  print((ncr(N-K+1,k)*ncr(K-1,k-1))%MOD)
### BUGGY CODE ###

N,Q=[int(s) for s in input().split()]
e_list=[[int(s) for s in input().split()] for i in range(N-1)]
#########深さ優先探索DFS
#########親と子の判定
#########木であることを前提とする
def dfs(edge_list,root):
  reach=[[root,1,0]]
  e_list=[[e[0],e[1],0] for e in edge_list]
  vertex=root
  endflag=0
  depth=1
  ans=[]
  while True :
    ###まずvertexから到達可能なものをすべてreachに入れる
    #辺の始点がvertexであるもの
    for e in e_list:
      if (e[0]==vertex and e[2]==0):
        reach.append([e[1],0,depth])
        ans.append([e[0],e[1]])
        e[2]=1
      elif (e[1]==vertex and e[2]==0):
        reach.append([e[0],0,depth])
        ans.append([e[1],e[0]])
        e[2]=1
    ###起点になっていないもののうち最後にreachに入ったものを、次の起点とする
    for i in range(len(reach)+1):
      if reach[-i][1]==0 :
        vertex=reach[-i][0]
        depth=reach[-i][2]+1
        #####ここでprint(vertex)などを入れる
        reach[-i][1]=1
        break
      if i==len(reach):  ####全ての場所に行っていれば終了
        return ans
        break
 #   if endflag==1:   
 #     break
 # print(reach)
 # return [e[0] for e in reach]
e_list=dfs(e_list,1)
answer=[0 for i in range(N+1)]
for i in range(Q):
  a,b=[int(s) for s in input().split()]
  answer[a]+=b
for e in e_list:
  answer[e[1]]+=answer[e[0]]
answer.remove(0)
print(*answer)

### FIXED CODE ###

N,Q=[int(s) for s in input().split()]
#辺でつながれた場所をすべてリストアップ
con_list=[set() for s in range(N+1)]
for i in range(N-1):
  a,b=[int(s) for s in input().split()]
  con_list[a].add(b)
  con_list[b].add(a)

v_list=[0 for s in range(N+1)]
for i in range(Q):
  x,y=[int(s) for s in input().split()]
  v_list[x]+=y

position=1 #現在位置
counter=v_list[1] #カウンター
ans_list=[0 for s in range(N+1)] #答え
ans_list[1]=counter 
vertex_num=1 #訪れた場所の数
oya_list=[-1 for s in range(N+1)] #親に戻るためのリスト

while vertex_num<N:
  #まだ行っていない子があるか？
  if len(con_list[position])>0:
    x=con_list[position].pop()
    con_list[x].remove(position) #xの行先から親を消す
    oya_list[x]=position
    position=x
    counter+=v_list[position] #カウンターの更新
    ans_list[position]=counter
    vertex_num+=1
  else: #行き先がないなら戻る
    position=oya_list[position]
    counter=ans_list[position] #カウンターを戻す
print(*ans_list[1:])
### BUGGY CODE ###

# atcoder Educational DP contest/DP まとめコンテスト
# B-Frog2

def get_inputs():
    [n, k] = [int(x) for x in input().split()]
    h = list(map(int, input().split()))
    
    return n, k, h


if __name__ == "__main__":
    # 入力を受け取る
    # n 足場の数 2<= N <= 10**5
    # k k本先の足場まで飛ぶことができる 1<=K<=100
    # h 足場の高さ 配列
    n, k, h = get_inputs()
    
    # for文の二重ループではTLEになってしまう
    # dp = [10000000000] * (n + k)        # k個分を含む配列を用意し最大値で初期化する
    # h= h + [100000] * k
    # dp[0] = 0                             # 0番目の足場はコスト0
    # 足場iからj個先まで行く場合の最小コストを求める
    # for i in range(0, n - 1):
    #    for j in range(1, k + 1):
    #        dp[i + j] = min(dp[i] + abs(h[i + j] - h[i]), dp[i + j])
    # print(dp[n-1])
    
    dp = [10**9] * n
    dp[0] = 0
    
    for i in range(1, n):
        mc = 10**9
        for j in range(max(0, i - k), i):
            mc = min(mc, dp[j] + abs(h[i] - h[j]))
        dp[i] = mc
    
    print(dp[n-1])
          

### FIXED CODE ###

# atcoder Educational DP contest/DP まとめコンテスト
# B-Frog2

def get_inputs():
    [n, k] = [int(x) for x in input().split()]
    h = list(map(int, input().split()))
    
    return n, k, h


if __name__ == "__main__":
    # 入力を受け取る
    # n 足場の数 2<= N <= 10**5
    # k k本先の足場まで飛ぶことができる 1<=K<=100
    # h 足場の高さ 配列
    n, k, h = get_inputs()
    
    ########## first try
    # for文の二重ループではTLEになってしまう
    # dp = [10000000000] * (n + k)        # k個分を含む配列を用意し最大値で初期化する
    # h= h + [100000] * k
    # dp[0] = 0                             # 0番目の足場はコスト0
    # 足場iからj個先まで行く場合の最小コストを求める
    # for i in range(0, n - 1):
    #    for j in range(1, k + 1):
    #        dp[i + j] = min(dp[i] + abs(h[i + j] - h[i]), dp[i + j])
    # print(dp[n-1])
    
    ########## second try
    # 前案より速度は改善したが、まだ一部の問題でTLEになる
    # dp = [10**9] * n
    # dp[0] = 0
    #
    # for i in range(1, n):
    #     mc = 10**9
    #     for j in range(max(0, i - k), i):
    #         mc = min(mc, dp[j] + abs(h[i] - h[j]))
    #    dp[i] = mc
    # print(dp[n-1])
    
    ########## third try
    # 二重ループを内包表記表現に変更
    # zipを使うのがミソ
    
    dp = [10**9] * n
    dp[0] = 0
    for i in range(1, n):
        j = max(0, i - k)
        dp[i] = min([dd + abs(h[i] - hh) for (dd, hh) in zip(dp[j:i], h[j:i])])
    print(dp[n-1])
### BUGGY CODE ###

N=int(input())
S=list(input())
Q=int(input())

for i in range(Q):
  q=input().split()
  if q[0]=="1":
    S[int(q[1])-1]=q[2]
  else:
    print(len(set(S[int(q[1])-1:int(q[2])])))

### FIXED CODE ###

abc=list("abcdefghijklmnopqrstuvwxyz")

class SegmentTree:
    def __init__(self, init_value: list, segfunc, ide_ele):
        n = len(init_value)
        self.N0 = 1 << (n - 1).bit_length()
        self.ide_ele = ide_ele
        self.data = [ide_ele] * (2 * self.N0)
        self.segfunc = segfunc
        
        for i, x in enumerate(init_value):
            self.data[i + self.N0 - 1] = x
        for i in range(self.N0 - 2, -1, -1):
            self.data[i] = self.segfunc(self.data[2 * i + 1], self.data[2 * i + 2])
    
    def update(self, k: int, x):
        k += self.N0 - 1
        ############################
        self.data[k] = x
        ###########################
        while k:
            k = (k - 1) // 2
            self.data[k] = self.segfunc(self.data[k * 2 + 1], self.data[k * 2 + 2])
    
    def query(self, left: int, right: int):
        L = left + self.N0
        R = right + self.N0
        res = self.ide_ele
        ##########################
        a, b = [], []
        while L < R:
            if L & 1:
                a.append(L - 1)
                L += 1
            if R & 1:
                R -= 1
                b.append(R - 1)
            L >>= 1
            R >>= 1
        for i in a + b[::-1]:
            res = self.segfunc(res, self.data[i])
        ##########################
        return res



idx={}
for i in range(len(abc)):
    idx[abc[i]]=i
#print(idx)
N=int(input())
S=list(input())
Q=int(input())
L=[[0]*(N+1) for _ in range(26)]

def add(a,b):
    return a+b


for i in range(N):
    s=S[i]
    L[idx[s]][i+1]=1
    

segdict={}
for i in range(26):
    segdict[i]=SegmentTree(L[i],add,0)

for i in range(Q):
    query=input().split()
    num=int(query[0])

    if num==1:
        i=int(query[1])
        c=query[2]
        nows=S[i-1]
        segdict[idx[nows]].update(i,0)
        segdict[idx[c]].update(i,1)
        S[i-1]=c
    else:
        l=int(query[1])
        r=int(query[2])
        sub=0
        for j in range(26):
            x=segdict[j].query(l,r+1)
            if x>0:
                sub+=1
        print(sub)
### BUGGY CODE ###

N, M = map(int, input().split())
A = [int(input()) for _ in range(M)]
inf = float("inf")
dp = [inf] * (N+1)
dp[0] = 1
for i in range(1,N+1):
	if i in A:
		continue

	if i == 1:
		dp[i] = dp[0]
		continue

	a = dp[i-2] if dp[i-2] != inf else 0
	b = dp[i-1] if dp[i-1] != inf else 0

	dp[i] = (a + b) % 1000000007


print(dp[N])

### FIXED CODE ###

N, M = map(int, input().split())
A = [int(input()) for _ in range(M)]
inf = float("inf")
dp = [0] * (N+1)
for i in A:
	dp[i] = inf
dp[0] = 1
if dp[1] != inf:
	dp[1] = 1
for i in range(2,N+1):
	if dp[i] == inf:
		continue

	a = dp[i-2] if dp[i-2] != inf else 0
	b = dp[i-1] if dp[i-1] != inf else 0

	dp[i] = (a + b) % 1000000007


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

import numpy as np
n, m = map(int, input().split())
a = np.array(list(map(int, input().split())))
for i in range(m):
    a[np.argmax(a)] /= 2
b = [abc // 1 for abc in a]
print(np.sum(b))

### FIXED CODE ###

import heapq
n, m = map(int, input().split())
a = list(map(lambda x: int(x) * (-1), input().split()))
heapq.heapify(a)
for _ in range(m):
    tmp_min = heapq.heappop(a)
    heapq.heappush(a, (-1)*(-tmp_min//2))
print(-sum(a))
### BUGGY CODE ###

N, M, K = map(int, input().split())
F = [[] for _ in range(N)]
B = [[] for _ in range(N)]

# フレンドの隣接リスト
for _ in range(M):
    a, b = map(int, input().split())
    a, b = a - 1, b - 1
    F[a].append(b)
    F[b].append(a)

# ブロックの隣接リスト
for _ in range(K):
    c, d = map(int, input().split())
    c, d = c - 1, d - 1
    B[c].append(d)
    B[d].append(c)


# 交友関係グループ（辞書型）
D = {}
# グループの親
parent = [-1] * N
# 訪問管理
visited = [False] * N

for root in range(N):
    if visited[root]:
        continue

    D[root] = set([root])
    # 訪問先のスタック
    stack = [root]
    # 訪問先が無くなるまで
    while stack:
        # 訪問者をポップアップ
        n = stack.pop()
        # 訪問者を訪問済み
        visited[n] = True
        # 訪問者のグループの親を設定
        parent[n] = root

        # root のフレンドをグループと訪問先に追加
        for to in F[n]:
            if visited[to]:
                continue
            D[root].add(to)
            stack.append(to)

ans = [0] * N
for iam in range(N):
    # 自分の交友関係グループを設定
    group = D[parent[iam]]
    # グループからフレンドと自分を除く
    tmp_ans = len(group) - len(F[iam]) - 1
    # グループからブロックを除く
    for block in B[iam]:
        if block in group:
            tmp_ans -= 1
    ans[iam] = tmp_ans

print(*ans, sep=' ')

### FIXED CODE ###

from collections import deque

n,m,k = map(int,input().split())

cango = [[]for i in range(n)]
cannotgo=[[]for i in range(n)]
for i in range(m):
    a,b = (map(int,input().split()))
    a,b = a-1,b-1
    cango[a].append(b)
    cango[b].append(a)

for i in range(k):
    c,d =(map(int,input().split()))
    c,d = c-1,d-1
    cannotgo[c].append(d)
    cannotgo[d].append(c)
# print(a)
# cango = [[]for i in range(n)]
# for i in a:
#     cango[i[0]-1].append(i[1]-1)
#     cango[i[1]-1].append(i[0]-1)
# print(cango)

# cannotgo=[[]for i in range(n)]
# for i in c:
#     cannotgo[i[0]-1].append(i[1]-1)
#     cannotgo[i[1]-1].append(i[0]-1)
# # print(cannotgo)
alre = [False]*n
parent = [-1]*n
gro = {}
y = deque()
# print(gro)
for i in range(n):
    # if alre[i]==True:
    #     continue
    # gro[i]=set([i])
    y.append(i)
    leader = i
    cnt = 0 
    while len(y)>0:
        x = y.popleft()
        if parent[x]!=-1:
            continue
            # print(to)
        parent[x]=leader
        y.extend(cango[x])
        cnt +=1
    if cnt!=0:
        gro[leader]=cnt
# print(gro)
# print(parent)
ans = [0]*n
# print(ans)
for iam in range(n):
    # group = gro[parent[iam]]
    tmp_ans = gro[parent[iam]]
    tmp_ans -=1
    tmp_ans -= len(cango[iam])
    for block in cannotgo[iam]:
        if parent[block]==parent[iam] :
            tmp_ans -=1
    ans[iam]=tmp_ans
print(*ans, sep=' ')
### BUGGY CODE ###

A, B, K = map(int, input().split())
l = []
for i in range(A, B + 1):
    l.append(i)
if B - A + 1 < K:
    for j in l:
        print(j)

else:
    m = l[:K] + l[B - A + 1 - K:]
    
    
    
    for k in sorted(set(m), key = l.index):
        print(k)

### FIXED CODE ###

a, b, k = map(int, input().split())
l = []
for i in range(a, min(a + k, b)):
    l.append(i)

for i in range(max(a, b - k + 1), b + 1):
    l.append(i)

for i in sorted(set(l)):
    print(i)
### BUGGY CODE ###

X = int(input())

def han(X):
  i = 1
  while 1:
    i += 1
    if X**(1/i) == int(X**(1/i)):
      return True
    if X**(1/i) < 1:
      return False
    
while 1:
  if X == 1000:
    print(X)
    break  
  elif han(X):
    print(X)
    break
  X -= 1

### FIXED CODE ###

l = [1, 4, 8, 9, 16, 25, 27, 32, 36, 49, 64, 81, 100, 121, 125, 128, 144, 169, 196, 216, 225, 243, 256, 289, 324, 343, 361, 400, 441, 484, 512, 529, 576, 625, 676, 729, 784, 841, 900, 961, 1000]
X = int(input())
while 1:
  if X in l:
    print(X)
    break
  X -= 1
### BUGGY CODE ###

import sys
sys.setrecursionlimit(500000)
INF = -10000000001

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

a = int(n/2)

dpa = [[INF for j in range(a+1)] for i in range(n+1)]

for i in range(0,n+1):
	dpa[i][0] = 0

for i in range(1,n+1):
	if i % 2 == 0:
		j = int(i / 2)
		dpa[i][j] = max(dpa[i-2][j-1]+l[i-1],dpa[i-1][j])
	else:
		j = int((i-1)/2)
		dpa[i][j] = max(dpa[i-2][j-1]+l[i-1],dpa[i-1][j])
		if (i != n):
			j += 1
#			print(i,j,i-2,j-1,i-1,j)
			dpa[i][j] = max(dpa[i-2][j-1]+l[i-1],dpa[i-1][j])

#print(dpa)
print(dpa[n][a])

### FIXED CODE ###

from collections import defaultdict
INF = -1000000000000001

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

a = int(n/2)

dpa = defaultdict(lambda: -INF)
#dpa = [[0 for j in range(a+1)] for i in range(n+1)]

dpa[(0,0)] = 0
dpa[(1,0)] = 0
dpa[(1,1)] = l[0]
j = 1
for i in range(2,n+1):
	if i == j*2:
		dpa[(i,j)] = max(dpa[(i-2,j-1)]+l[i-1],dpa[(i-1,j)])
#		print(i,j,dpa[(i,j)])
	else:
		dpa[(i,j)] = max(dpa[(i-2,j-1)]+l[i-1],dpa[(i-1,j)])
#		print(i,j,dpa[(i,j)])
		if (i != n):
			j += 1
#			print(i,j,dpa[(i,j)])
#			print("   ",i-2,j-1,dpa[(i-2,j-1)],"")
			dpa[(i,j)] = dpa[(i-2,j-1)]+l[i-1]

#print(dpa)
print(dpa[n,a])
### BUGGY CODE ###

from collections import deque

H, W = map(int, input().split())
grid = [input() for i in range(H)]

# 初期の黒('#')の位置からの距離
dist = [[-1]*W for _ in range(H)]

# '#'の位置をキューに追加（＝今回はこれが複数あるので、複数スタートとなる）
black_cells = deque()
for h in range(H):
    for w in range(W):
        if grid[h][w] == '#':
            black_cells.append((h, w))
            dist[h][w] = 0

def bfs(black_cells, dist):
    """
    BFSを用いて、全マス目を黒くする回数を求める

    Args:
        black_cells: 「開始時の黒マス」の座標が入ったキュー（複数座標あり）
        dist: 「開始時の黒マス」からの距離の入ったリスト  [[-1, -1, 0], ...]
        　　　（白マスの初期値は0）

    Returns:
        g: 操作を繰り返した数
    """
    d = 0
    while black_cells:
        # キューとして使うのでpop()ではなくpopleft()
        h, w = black_cells.popleft()
        d = dist[h][w]
        for dy, dx in ((1, 0), (0, 1), (-1, 0), (0, -1)):
            new_h = h + dy
            new_w = w + dx
            if new_h < 0 or H <= new_h or new_w < 0 or W <= new_w:
                continue
            if dist[new_h][new_w] == -1:  # セルが白('.')であるのと同義
                dist[new_h][new_w] = d+1
                black_cells.append((new_h, new_w))
    return d

d = bfs(black_cells, dist)
print(d)

### FIXED CODE ###

from collections import deque

h, w = map(int, input().split())
a = [list(input()) for _ in range(h)]

cnt = [[10 ** 10] * w for _ in range(h)]
visited = [[0] * w for _ in range(h)]
queue = deque()
for i in range(h):
    for j in range(w):
        if a[i][j] == "#":
            cnt[i][j] = 0
            queue.append([i, j])
            visited[i][j] = 1

def bfs(q, v, c):
    while q:
        y, x = q.popleft()
        for i, j in ([0, 1], [1, 0], [-1, 0], [0, -1]):
            ny = y + i
            nx = x + j
            if 0 <= nx < w and 0 <= ny < h and v[ny][nx] == 0:
                c[ny][nx] = c[y][x] + 1
                v[ny][nx] = 1
                q.append([ny, nx])

bfs(queue, visited, cnt)

ans = 0
for i in range(h):
    ans = max(ans, max(cnt[i]))
print(ans)
### BUGGY CODE ###


X = int(input())

dic = {}
dic[0] = 1

time = 0

while True:

    time += 1

    dicc = dic.copy()
    for i in dicc:

        dic[i + time] = 1
        dic[i - time] = 1

    if X in dic:
        break

print (time)

### FIXED CODE ###


X = int(input())

ans = 0
cnt = 0

while ans < X:
    
    cnt += 1
    ans += cnt


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

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

ans = 0

for x in range(0, N+1):
  
  a = ( int((A*x)/B) - A*int(x/B) )
  if ans < a:
    ans = a
    
print(ans)

### FIXED CODE ###

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

#ans = ( int((A*x)/B) - A*int(x/B) )

if B <= N:
  x = B - 1
else:
  x = N
    
print(int((A*x)/B) - A*int(x/B))
### BUGGY CODE ###

##C
N = int(input())
S = list(input() for i in range(N))

import collections

c = collections.Counter(S)
ans = 0

if c.most_common()[0][1] == N:
    print(S[0])
else:
    for j in range(N):
        if c.most_common()[0][1] == c.most_common()[j][1]:
            ans += 1
        else:
            break
    ansl = list()
    for k in range(ans):
        ansl.append((c.most_common()[k][0]))
    ansl.sort()
    for l in ansl:
        print(l)

### FIXED CODE ###

N = int(input())
S = list(input() for i in range(N))

import collections

c = collections.Counter(S)
max = max(c.values())
 
max_k_list = [kv[0] for kv in c.items() if kv[1] == max]
max_k_list.sort()
for l in max_k_list:
    print(l)
### BUGGY CODE ###

N, P = map(int, input().split())
p = P**(1/N)
if p % 1 == 0:
    print(int(p))
    exit()

p = int(p) + 1

dic = {}

def my(N,p,s=2):
    for i in range(s,p+1):
        if p % i == 0:
            # print('ok')
            dic[i] = dic.get(i,0) + 1
            # print(dic)
            p = p//i
            s = i
            break
    
    if p == 1:
        res = 1
        for j,k in dic.items():
            res *= j**(k//N)
        print(res)
        exit()
    else:
        my(N,p,s)

my(N,P)

### FIXED CODE ###

N, P = map(int, input().split())
p = P**(1/N)
if p % 1 == 0:
    print(int(p))
    exit()

lim = int(p) + 1

dic = {}

def my(N,newP):
    for i in range(2,lim+1):
        while newP % i == 0:
            dic[i] = dic.get(i,0) + 1
            newP = newP // i
        if newP < i or i == lim:
            res = 1
            for j,k in dic.items():
                res *= j**(k//N)
            print(res)
            exit()
my(N,P)