problem_id
stringlengths
6
6
user_id
stringlengths
10
10
time_limit
float64
1k
8k
memory_limit
float64
262k
1.05M
problem_description
stringlengths
48
1.55k
codes
stringlengths
35
98.9k
status
stringlengths
28
1.7k
submission_ids
stringlengths
28
1.41k
memories
stringlengths
13
808
cpu_times
stringlengths
11
610
code_sizes
stringlengths
7
505
p02684
u527454768
2,000
1,048,576
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
['N,K = map(int, input().split())\nA =[0]\nB=list(map(int, input().split()))\nfor m in range(N):\n A.append(B[m])\nplace=set([])\np=[]\ni=1\ncount=0\nwhile i not in place:\n place.add(i)\n p.append(i)\n i=A[i]\n count+=1\nif count>=K:\n print(p[K])\nelse:\n loop=[i]\n start=i\n j=A[i]\n count+=1\n while j!=start:\n loop.append(j)\n j=A[j]\n count+=1\n if count>=K:\n print(loop[K-len(p)])\n num=(K-count)%len(loop)\n print(loop[num])', 'N,K = map(int, input().split())\nA =[0]\nB=list(map(int, input().split()))\nfor m in range(N):\n A.append(B[m])\nplace=set([])\np=[]\ni=1\ncount=0\nwhile i not in place:\n place.add(i)\n p.append(i)\n i=A[i]\n count+=1\nif count>=K:\n print(p[K])\nelse:\n loop=[i]\n start=i\n j=A[i]\n count+=1\n while j!=start:\n loop.append(j)\n j=A[j]\n count+=1\n if count>=K:\n print(loop[0])\n else:\n num=(K-count)%len(loop)\n print(loop[num])', 'N,K = map(int, input().split())\nA =[0]\nB=list(map(int, input().split()))\nfor m in range(N):\n A.append(B[m])\nplace=set([])\ni=1\ncount=0\nwhile i not in place:\n place.add(i)\n i=A[i]\n count+=1\nif count>=K:\n print(place[K])\nelse:\n loop=[i]\n start=i\n j=A[i]\n count+=1\n while j!=start:\n loop.append(j)\n j=A[j]\n count+=1\n if count>=K:\n print(loop[K-len(place)-1])\n else:\n num=(K-count)%len(loop)\n print(loop[num])', 'N,K = map(int, input().split())\nA =[0]\nB=list(map(int, input().split()))\nfor m in range(N):\n A.append(B[m])\nplace=set([])\np=[]\ni=1\ncount=0\nwhile i not in place:\n place.add(i)\n p.append(i)\n i=A[i]\n count+=1\nif count>=K:\n print(p[K])\nelse:\n loop=[i]\n start=i\n j=A[i]\n count+=1\n while j!=start:\n loop.append(j)\n j=A[j]\n count+=1\n if count>=K:\n print(loop[K-len(p)])\n else:\n num=(K-count)%len(loop)\n print(loop[num])', 'N,K = map(int, input().split())\nA =[0]\nB=list(map(int, input().split()))\nfor m in range(N):\n A.append(B[m])\nplace=[]\ni=1\ncount=0\nwhile i not in place:\n place.append(i)\n i=A[i]\n count+=1\nprint(place)\nprint(i)\nloop=[i]\nstart=i\nj=A[i]\ncount+=1\nwhile j!=start:\n loop.append(j)\n j=A[j]\n count+=1\nprint(loop)\nnum=(K-count)%len(loop)\nprint(loop[num])', 'N,K = map(int, input().split())\nA =[0]\nB=list(map(int, input().split()))\nfor m in range(N):\n A.append(B[m])\nplace=set([])\np=[]\ni=1\ncount=0\nwhile i not in place:\n place.add(i)\n p.append(i)\n i=A[i]\n count+=1\nif count>K:\n print(p[K])\nelse:\n loop=[i]\n start=i\n j=A[i]\n count+=1\n while j!=start:\n loop.append(j)\n j=A[j]\n count+=1\n if count>K:\n print(loop[K-len(p)])\n else:\n num=(K-count)%len(loop)\n print(loop[num])']
['Runtime Error', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Wrong Answer', 'Accepted']
['s046072812', 's132602683', 's275200247', 's501992085', 's710122733', 's343342947']
[33916.0, 34112.0, 33400.0, 9088.0, 32404.0, 33816.0]
[185.0, 183.0, 176.0, 24.0, 2206.0, 230.0]
[475, 486, 482, 485, 364, 491]
p02684
u531599639
2,000
1,048,576
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
['N, K = map(int, input().split())\nA = list(map(int, input().split()))\nvisited = [-1]*(N+1)\npath = []\nat = 1\ncount = 0\nwhile True:\n if visited[at] != -1:\n loop = count-visited[at]\n if K < count: \n print(path[K]+1) \n else:\n print(path[(K-visited[at])%loop+visited[at]]+1)\n break\n visited[at] = count\n count += 1\n path.append(at)\n at = A[at]', 'n, k = map(int, input().split())\nq = list(map(int, input().split()))\nv = [-1]*(n+1)\np = []\na = 1\nc = 0\nwhile 1:\n if v[a] != -1:\n l = c-v[a]\n if k < c:\n print(p[k])\n else:\n print(p[(k-v[a])%l+v[a]])\n break\n v[a] = c\n c += 1\n p.append(a)\n a = q[a]', 'n, k = map(int, input().split())\nq = list(map(int, input().split()))\nv = [-1]*(n+1)\np = []\na = 1\nc = 0\nwhile 1:\n if v[a] != -1:\n l = c-v[a]\n if k < c:\n print(p[k])\n else:\n print(p[(k-v[a])%l+v[a]])\n break\n v[a] = c\n c += 1\n p.append(a)\n a = q[a-1]']
['Runtime Error', 'Runtime Error', 'Accepted']
['s169839143', 's366391102', 's546194772']
[32324.0, 32376.0, 32300.0]
[115.0, 124.0, 169.0]
[580, 310, 312]
p02684
u535010493
2,000
1,048,576
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
['n, k = map(int, input().split())\na = list(map(int, input().split()))\npath = []\n\nnow = a[0]\npath.append(now)\n\nfor i in range(1, k+1):\n now = a[now-1]\n if now in path:\n now = a[a.index(now) + (k-i)%(len(path) - a.index(now) - 1)]\n break\n path.append(now)\n\nprint(now)\n', 'n, k = map(int, input().split())\na = list(map(int, input().split()))\nalr = [0 for i in range(n)]\nnow = 1\npath = [now]\n\nfor i in range(k):\n now = a[now-1]\n # if now in path:\n # now = path[path.index(now) + (k-i-1)%(len(path) - path.index(now))]\n # break\n if alr[now-1] != 0:\n now = path[path.index(now) + (k-i-1)%(len(path) - path.index(now))]\n break\n path.append(now)\n alr[now-1] += 1\n\nprint(now)\n']
['Runtime Error', 'Accepted']
['s135562044', 's597590547']
[32328.0, 32172.0]
[2206.0, 178.0]
[288, 440]
p02684
u536034761
2,000
1,048,576
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
['N, K = map(int, input().split(" "))\nrouts = {}\ntereporter = list(map(int, input().split()))\nfor i in range(N):\n routs[i + 1] = tereporter[i]\npresent_location = 1\nn = 0\nfor i in range(K):\n n += 1\n present_location = routs[present_location]\n if present_location = 1:\n if n == 0 or K % n == 0:\n break\n for i in range(K % n):\n present_location = routs[present_location]\n break\n\nprint(present_location)\n', 'N, K = map(int, input().split(" "))\nrouts = {}\nlocation = [0 for i in range(N + 1)]\ntereporter = list(map(int, input().split()))\nfor i in range(N):\n routs[i] = tereporter[i] - 1\npresent_location = 0\nn = 0\nfor i in range(K):\n n += 1\n present_location = routs[present_location]\n if location[present_location] == 0:\n location[present_location] = n\n else:\n loop = n - location[present_location]\n if (K - location[present_location]) % loop == 0:\n break\n else:\n for i in range((K - location[present_location]) % loop):\n present_location = routs[present_location]\n\tbreak\nprint(present_location + 1)\n\n', 'N, K = map(int, input().split())\nrouts = {}\ntereporter = list(map(int, input().split()))\nfor i in range(N):\n routs[i] = tereporter[i]\npresent_location = 1\nfor i in tange(K):\n present_location = routs[present_location]\nprint(present_location)', 'from sys import exit\nn, K = map(int, input().split())\nA = list(map(lambda x: int(x) - 1, input().split()))\ndone = [-1 for _ in range(n)]\ntmp = 0\ndone[0] = 0\nfor k in range(1, K + 1):\n tmp = A[tmp]\n if done[tmp] >= 0:\n for i in range((K - done[tmp]) % (k - done[tmp])):\n tmp = A[tmp]\n print(tmp + 1)\n exit()\n else:\n done[tmp] = k\nprint(tmp + 1)\n']
['Runtime Error', 'Runtime Error', 'Runtime Error', 'Accepted']
['s557953075', 's696800639', 's979066444', 's176243484']
[9056.0, 8924.0, 40404.0, 32376.0]
[24.0, 23.0, 103.0, 135.0]
[421, 615, 243, 392]
p02684
u538808095
2,000
1,048,576
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
['N, K = map(int, input().split())N, K = map(int, input().split())\n\nA = list(map(int, input().split()))\n\nvisitcount = dict()\nn_point = list()\n\nx = 1\ncount = 0\nwhile(x not in set(visitcount)):\n visitcount[x] = count\n n_point.append(x)\n x = A[x-1]\n count += 1\n \nperiod = count - visitcount[x]\n\nif (K < visitcount[x]):\n print(n_point[K])\nelse:\n y = (K-visitcount[x]) % period\n print(n_point[visitcount[x] + y])\n \n\n', 'N, K = map(int, input().split())\n\nA = list(map(int, input().split()))\n\nvisitset = set()\nvisitcount = dict()\nn_point = dict()\n\nx = 1\ncount = 0\nwhile(x not in visitset):\n visitset.add(x)\n visitcount[x] = count\n n_point[count] = x\n x = A[x-1]\n count += 1\n\n\nperiod = count - visitcount[x]\n\nif (K < visitcount[x]):\n print(n_point[K])\nelse:\n y = (K-visitcount[x]) % period\n print(n_point[visitcount[x] + y])\n\n']
['Runtime Error', 'Accepted']
['s680427559', 's627223020']
[9016.0, 56080.0]
[24.0, 262.0]
[417, 411]
p02684
u547608423
2,000
1,048,576
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
['N,K=map(int,input().split())\nA=list(map(int,input().split()))\n\nans=[]\n\nj=0 \nwhile A[j] not in ans:\n ans.append(A[j])\n j=A[j]-1\nans.append(A[j])\n\nst=ans.index(A[j])\nans=ans[st:-1]\nK-=st\nl=len(ans)\nprint(ans)\nprint(ans[K%l-1])', 'N,K=map(int,input().split())\nA=list(map(int,input().split()))\n\nans=[]\njudge={}\nj=0 \nwhile judge[A[j]]!=2:\n ans.append(A[j])\n if A[j] not in judge.keys():\n judge[A[j]]=0\n judge[A[j]]+=1\n j=A[j]-1\nans.append(A[j])\n\nst=ans.index(A[j])\nans=ans[st:-1]\nK-=st\nl=len(ans)\n#print(ans)\nprint(ans[K%l-1])', 'N,K=map(int,input().split())\nA=list(map(int,input().split()))\n\nans=[]\njudge={}\nj=0 \nwhile A[j] not in judge.keys() or judge[A[j]]!=2:\n ans.append(A[j])\n if A[j] not in judge.keys():\n judge[A[j]]=0\n judge[A[j]]+=1\n j=A[j]-1\n\nst=ans.index(A[j])\n\nif st<K:\n ans=ans[st:]\n K-=st\n l=len(ans)\n #print(ans)\n print(ans[K%l-1])\nelse:\n print(ans[K-1])']
['Wrong Answer', 'Runtime Error', 'Accepted']
['s669860367', 's830478607', 's943844711']
[32380.0, 32384.0, 35412.0]
[2206.0, 66.0, 321.0]
[238, 320, 385]
p02684
u548069143
2,000
1,048,576
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
['\nn,k=map(int,input().split())\na=list(map(int, input().split()))\nb=[1]\nc=0\nm=0\n# while flag==1:\nfor i in range(n):\n if a[m] not in b:\n b.append(a[m])\n c+=1\n m=a[m]-1\n else:\n e=a[m]\n break\n\ne=b.index(e)\nprint(b,e)\nb=b[e:c+1]\nf=c+1-e\nif 1 not in b:\n ans=(e+2+k)%f\n print(b[ans])\nelse:\n ans=k%f\n print(b[ans])', '\nn,k=map(int,input().split())\na=list(map(int, input().split()))\nb=[1]\nba=set()\nc=0\nm=0\n# while flag==1:\nfor i in range(n):\n if a[m] not in ba:\n b.append(a[m])\n ba.add(a[m])\n c+=1\n m=a[m]-1\n else:\n e=a[m]\n break\n\ne=b.index(e)\n# print(b,e)\nb=b[e:c+1]\nf=c+1-e\nif 1 not in b:\n ans=(k%f+e-1)%f\n print(b[ans])\nelse:\n ans=k%f\n print(b[ans])', '\nn,k=map(int,input().split())\na=list(map(int, input().split()))\nb=[1]\nba={1}\nc=0\nm=0\n# while flag==1:\nfor i in range(n):\n if a[m] not in ba:\n b.append(a[m])\n ba.add(a[m])\n c+=1\n m=a[m]-1\n else:\n e=a[m]\n break\n# print(b,e,c+1)\ne=b.index(e)\n# print(b,e)\nbc=b\nb=b[e:c+1]\nf=c+1-e\nif c>k:\n if c-1>=k:\n\n print(bc[k])\n exit()\nif 1 not in b:\n # print(b,f)\n ans=(k-e)%f\n print(b[ans])\nelse:\n\n ans=k%f\n print(b[ans])']
['Wrong Answer', 'Wrong Answer', 'Accepted']
['s403047271', 's975638134', 's371558856']
[32384.0, 32304.0, 32304.0]
[2206.0, 181.0, 193.0]
[358, 393, 486]
p02684
u548976218
2,000
1,048,576
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
['n, k = map(int, input().split())\nA = list(map(int, input().split()))\nr = 1\nroot = [1]\nfor _ in range(n):\n roo = A[r-1]\n root.append(roo)\nfor i in range(n):\n if roo == root[i]:\n roopcount = n-i-1\n break\nif k <= n:\n print(root[k-1])\nelse:\n s = k%n\n print(root[i])', 'n, k = map(int, input().split())\nA = list(map(int, input().split()))\n\nf = 1\nfirst = []\nfor _ in range(n):\n num = A[f-1]\n first.append(num)\n f = num\n\nfor i in range(n):\n if num == first[i]:\n roopcount = n-i-1 #3\n break\n\nif k <= n:\n print(first[k-1])\nelse:\n s = (k-(n-roopcount))%roopcount\n print(first[i+s])']
['Wrong Answer', 'Accepted']
['s571193109', 's342981820']
[32308.0, 32300.0]
[102.0, 132.0]
[293, 341]
p02684
u552201227
2,000
1,048,576
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
['n,k=map(int,input().split())\na=list(map(lambda x:int(x)-1,input().split()))\nlst=[0]\nnow=0\nmemo=0\ntown=[0]*n\ntown[0]=1\nb=0 \nfor i in range(k):\n now=a[now]\n if town[now]==1:\n memo=now \n b=1\n break\n lst.append(now)\n town[now]=1\nif b==1:\n i=lst.index(now)\u3000\n l=len(lst)\n if memo!=0:\n lst=lst[i:]\n l-=len(lst)\n print(lst[(k-l)%len(lst)]+1)\n else:\n print(lst[k%l]+1)\nelse:\n print(now+1)\n', 'n,k=map(int,input().split())\na=list(map(lambda x:int(x)-1,input().split()))\nlst=[0]\nnow=0\nmemo=0\ntown=[0]*n\ntown[0]=1\nb=0 \nfor i in range(k):\n now=a[now]\n if town[now]==1:\n memo=now \n b=1\n break\n lst.append(now)\n town[now]=1\nif b==1:\n i=lst.index(now)\u3000\n l=len(lst)\n if memo!=0:\n lst=lst[i:]\n l-=len(lst)\n print(lst[(k-l)%len(lst)]+1)\n else:\n print(lst[k%l]+1)\nelse:\n print(now)\n', 'n,k=map(int,input().split())\na=list(map(lambda x:int(x)-1,input().split()))\nlst=[0]\nnow=0\nmemo=0\ntown=[0]*n\ntown[0]=1\nb=0 \nfor i in range(k):\n now=a[now]\n if town[now]==1:\n memo=now \n b=1\n break\n lst.append(now)\n town[now]=1\nif b==1:\n i=lst.index(now)\u3000\n l=len(lst)\n if memo!=0:\n lst=lst[i:]\n l-=len(lst)\n print(lst[(k-l)%len(lst)]+1)\n', 'n,k=map(int,input().split())\na=list(map(lambda x:int(x)-1,input().split()))\nlst=[0]\nnow=0\nmemo=0\ntown=[0]*n\ntown[0]=1\nb=0 \nfor i in range(k):\n now=a[now]\n if town[now]==1:\n memo=now \n b=1\n break\n lst.append(now)\n town[now]=1\nif b==1:\n i=lst.index(now)\u3000\n l=len(lst)\n if memo!=0:\n lst=lst[i:]\n l-=len(lst)\n print(lst[(k-l)%len(lst)]+1)\n else:\n print(lst[k%l]+1)\nelse:\n print(now)', 'n,k=map(int,input().split())\na=list(map(lambda x:int(x)-1,input().split()))\nlst=[0]\nnow=0\nmemo=0\ntown=[0]*n\ntown[0]=1\nb=0\nfor i in range(k):\n\tnow=a[now]\n\tif town[now]==1:\n\t\tmemo=now\n\t\tb=1\n\t\tbreak\n\tlst.append(now)\n\ttown[now]=1\nif b==1:\n\ti=lst.index(memo)\n\tl=len(lst)\n\tif memo!=0:\n\t\tlst=lst[i:]\n\t\tl-=len(lst)\n\t\tprint(lst[(k-l)%len(lst)]+1)\n\telse:\n\t\tprint(lst[k%l]+1)\nelse:\n\tprint(now+1)']
['Runtime Error', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Accepted']
['s070208883', 's677017408', 's700375212', 's732804921', 's632721797']
[9072.0, 9064.0, 9072.0, 9084.0, 32328.0]
[23.0, 23.0, 24.0, 25.0, 152.0]
[431, 410, 474, 522, 384]
p02684
u552741877
2,000
1,048,576
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
['n,k = map(int, input().split())\na = list(map(int, input().split()))\n\nh = set([])\n\nc = 0\nfor i in range(2 * n):\n c = a[c] - 1\n if n < i:\n print("{} {}".format(i, c))\n if c in h:\n break\n else:\n h.add(c)\n\n\nc = 0\nd = 1\nfor i in range(n):\n c = a[c] - 1\n print("{} {}".format(i, c))\n if c in h:\n break\n else:\n d += 1\n\nc = 0\nif d >= len(a):\n for i in range(a):\n c = a[c] - 1\nelse:\n for i in range(d + (k % len(h))):\n print("{} {}".format(c, a[c]))\n c = a[c] - 1\n\nprint(c + 1)\n', 'n,k = map(int, input().split())\na = list(map(int, input().split()))\n\nh = set([])\n\nc = 0\nfor i in range(2 * n):\n c = a[c] - 1\n if n < i:\n if c + 1 in h:\n break\n else:\n h.add(c + 1)\n\nc = 0\nd = 0\nfor i in range(n):\n c = a[c] - 1\n if c + 1 in h:\n break\n else:\n d += 1\n\nc = 0\nif d >= k:\n for i in range(k):\n c = a[c] - 1\nelse:\n for i in range(d + ((k - d) % len(h) + len(h))):\n c = a[c] - 1\n', 'n,k = map(int, input().split())\na = list(map(int, input().split()))\n\nh = set([])\n\nc = 0\nfor i in range(2 * n):\n c = a[c] - 1\n if n < i:\n if c + 1 in h:\n break\n else:\n h.add(c + 1)\n\nc = 0\nd = 0\nfor i in range(n):\n c = a[c] - 1\n if c in h:\n break\n else:\n d += 1\n\nc = 0\nif d >= k:\n print("sss")\n for i in range(k):\n c = a[c] - 1\nelse:\n for i in range(d + (k % len(h))):\n print("{} {}".format(c, a[c]))\n c = a[c] - 1\n\nprint(c + 1)\n', 'n,k = map(int, input().split())\na = list(map(int, input().split()))\n\nh = set([])\n\nc = 0\nfor i in range(2 * n):\n c = a[c] - 1\n if n < i:\n if c + 1 in h:\n break\n else:\n h.add(c + 1)\n\nc = 0\nd = 0\nfor i in range(n):\n c = a[c] - 1\n if c + 1 in h:\n break\n else:\n d += 1\n\nc = 0\nif d >= k:\n for i in range(k):\n c = a[c] - 1\nelse:\n for i in range(d + ((k - d) % len(h) + len(h))):\n c = a[c] - 1\n\n\nprint(c + 1)\n']
['Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Accepted']
['s298103539', 's767806830', 's938150383', 's407945313']
[34644.0, 34784.0, 34692.0, 34680.0]
[457.0, 257.0, 326.0, 202.0]
[511, 421, 466, 436]
p02684
u563838154
2,000
1,048,576
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
['n,k = map(int,input().split())\ns = list(map(int,input().split()))\n# print(s)\nnow_city = 1\ns_l_city = 1\nt = [0] \nf = [0] \na=0\nb = 0\nf_l=0\nfor i in range(n):\n t.append(0)\n f.append(-1)\n# print(s)\nsycle = 0\nfor i in range(1,n+10):\n now_city = s[now_city-1]\n \n if t[now_city-1]==1:\n # print(i,f[j])\n sycle=i-f[now_city-1]\n f_l=f[now_city-1]\n # f_l=i\n # a = 1\n b = i\n # s_l_city=now_city\n \n break\n t[now_city-1]+=1\n f[now_city-1]=i\n# print(t)\n# print(f_l)\n# print(f_l,sycle,s_l_city)\n\nif k>b:\n # now_city=s_l_city\n for _ in range((k-f_l)%sycle):\n \n now_city = s[now_city-1]\n print((k-f_l)%sycle)\n print(now_city)\nelse:\n \n now_city=1\n for _ in range(k):\n now_city=s[now_city-1]\n print(now_city)\n', 'n,k = map(int,input().split())\ns = list(map(int,input().split()))\n# print(s)\nnow_city = 1\ns_l_city = 1\nt = [0] \nf = [0] \na=0\nb = 0\nf_l=0\nfor i in range(n):\n t.append(0)\n f.append(-1)\n# print(s)\nsycle = 0\nfor i in range(1,n+10):\n now_city = s[now_city-1]\n \n if t[now_city-1]==1:\n # print(i,f[j])\n sycle=i-f[now_city-1]\n f_l=f[now_city-1]\n # f_l=i\n # a = 1\n b = i\n # s_l_city=now_city\n print("ループの最初の数字",now_city,"最初は"+str(f_l)+"回目","周期は",sycle)\n break\n t[now_city-1]+=1\n f[now_city-1]=i\n# print(t)\n# print(f_l)\n# print(f_l,sycle,s_l_city)\n\nif k>b:\n # now_city=s_l_city\n for _ in range((k-f_l)%sycle):\n \n now_city = s[now_city-1]\n print((k-f_l)%sycle)\n print(now_city)\nelse:\n print("ループなし")\n now_city=1\n for _ in range(k):\n now_city=s[now_city-1]\n print(now_city)', 'n,k = map(int,input().split())\ns = list(map(int,input().split()))\n# print(s)\nnow_city = 1\ns_l_city = 1\nt = [0] \nf = [0] \na=0\nb = 0\nf_l=0\nfor i in range(n):\n t.append(0)\n f.append(-1)\n# print(s)\nsycle = 0\nfor i in range(1,n+10):\n now_city = s[now_city-1]\n \n if t[now_city-1]==1:\n # print(i,f[j])\n sycle=i-f[now_city-1]\n f_l=f[now_city-1]\n # f_l=i\n # a = 1\n b = i\n # s_l_city=now_city\n \n break\n t[now_city-1]+=1\n f[now_city-1]=i\n# print(t)\n# print(f_l)\n# print(f_l,sycle,s_l_city)\n\nif k>b:\n # now_city=s_l_city\n for _ in range((k-f_l)%sycle):\n \n now_city = s[now_city-1]\n # print((k-f_l)%sycle)\n print(now_city)\nelse:\n \n now_city=1\n for _ in range(k):\n now_city=s[now_city-1]\n print(now_city)\n\n']
['Wrong Answer', 'Wrong Answer', 'Accepted']
['s162692464', 's571634191', 's035179618']
[32260.0, 32392.0, 32204.0]
[262.0, 237.0, 237.0]
[1054, 1049, 1057]
p02684
u564525445
2,000
1,048,576
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
['import sys\n\nlines = sys.stdin.readlines()\nN, M, X = map(int, lines[0].split())\nA = []\nC = []\n\nfor i in range(N):\n line = list(map(int, lines[i+1].split()))\n A.append(line[1:])\n C.append(line[0])\n\n# return []\ndef full_search():\n costs = []\n for i in range(2**N):\n vals = [0] * M\n cost = 0\n\n \n for j in range(N):\n \n if ((i >> j) & 1):\n \n \n cost += C[j]\n\n \n for m in range(M):\n vals[m] += A[j][m]\n\n combination_ok = True\n for m in range(M):\n if vals[m] >= X:\n continue\n else:\n combination_ok = False\n break\n\n if combination_ok:\n costs.append(cost)\n return costs\n\ncosts = full_search()\nif len(costs) == 0:\n print(-1)\nelse:\n print(min(costs))\n', 'import sys\n\nN, K = map(int, input().split())\nA = list(map(int, input().split()))\n\ni = 1\nl = [1] * N\ns = set([1])\nn = 1\nwhile True:\n n = A[n-1]\n if n in s:\n l = l[:i]\n mod = i - l.index(n)\n init_len = l.index(n)\n break\n else:\n l[i] = n\n s.add(n)\n i += 1\n\nif K < init_len:\n print(l[K])\nelse:\n rest = ((K-init_len) % mod)\n print(l[init_len+rest])\n']
['Runtime Error', 'Accepted']
['s108636027', 's139045161']
[11480.0, 33688.0]
[26.0, 225.0]
[1254, 411]
p02684
u564770050
2,000
1,048,576
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
['n,k = map(int,input().split())\na = list(map(int, input().split()))\nns = [0] * (n+1)\ntree = []\n\nns = [0] * n\nns[0] = 1\n# max 2*10**5\n\nnexti = 0\nstarti = 0\nendi = 0\ntree.append(nexti)\n\nwhile k > 0 :\n nexti = a[nexti] - 1\n if ns[nexti] == 1:\n starti = nexti\n break\n ns[nexti] = 1\n endi = nexti\n tree.append(nexti)\n\nx = tree.index(starti) \n\ny = len(tree[x:])\n\nif k - x <= 0:\n print(tree[k-1])\nelse:\n k = k - x\n z = k % y\n if starti == 0:\n starti = -1\n temp = tree[starti+1:]\n\n print(temp[z] + 1,temp,z)', 'def main():\n n, k = map(int, input().split())\n a = list(map(int, input().split()))\n\n num = 1\n l = []\n s = [1]*n\n\n while s[num-1]:\n l.append(num)\n s[num-1] = 0\n num = a[num-1]\n\n if l.index(num) <= k:\n l2 = l[l.index(num):]\n kk = (k-len(set(l)-set(l2)))%len(l2)\n print(l2[kk])\n else:\n print(l[k])\n\nmain()\n']
['Runtime Error', 'Accepted']
['s624560335', 's764411947']
[32168.0, 45992.0]
[153.0, 157.0]
[604, 376]
p02684
u567534852
2,000
1,048,576
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
['sys.setrecursionlimit(10**7)\n\ndef teleport(city, end, teleportmap, count=1):\n\n next_city = teleportmap[city]\n\n if count == end:\n return next_city\n\n else:\n return teleport(next_city, end, teleportmap, count+1)\n\nn, k = map(int,input().split())\na = list(map(int, input().split()))\nteleportmap = dict(zip(range(1, len(a)+1), a))\n\nif k <= n:\n print(teleport(1, n, teleportmap))\n\nelse:\n countmap = [0]*n\n countmap[0] = 1\n\n next_city =1\n for _ in range(1, n+1):\n next_city = a[next_city-1]\n countmap[next_city -1] += 1\n if countmap[next_city -1] == 2:\n start = next_city\n break\n\n roop = {}\n for j in range(1, n+1):\n roop[start] = teleportmap[start]\n start = roop[start]\n \n num_r = len(roop)\n\n num_until_r= 0\n for m in teleportmap.keys():\n if m not in roop and countmap[m-1] != 0:\n num_until_r += 1\n \n k_r = k - num_until_r\n num_end = k_r%num_r\n\n if num_end == 0:\n print(next_city)\n \n else:\n print(teleport(next_city, num_end, roop))', 'import sys\nsys.setrecursionlimit(10**7)\n\ndef teleport(city, end, teleportmap, count=1):\n\n next_city = teleportmap[city]\n\n if count == end:\n return next_city\n\n else:\n return teleport(next_city, end, teleportmap, count+1)\n\nn, k = map(int,input().split())\na = list(map(int, input().split()))\nteleportmap = dict(zip(range(1, len(a)+1), a))\n\nif k <= n:\n print(teleport(1, k, teleportmap))\n\nelse:\n countmap = [0]*n\n countmap[0] = 1\n\n next_city =1\n for _ in range(1, n+1):\n next_city = a[next_city-1]\n countmap[next_city -1] += 1\n if countmap[next_city -1] == 2:\n start = next_city\n break\n\n roop = {}\n for j in range(1, n+1):\n roop[start] = teleportmap[start]\n start = roop[start]\n \n num_r = len(roop)\n\n num_until_r= 0\n for m in teleportmap.keys():\n if m not in roop and countmap[m-1] != 0:\n num_until_r += 1\n \n k_r = k - num_until_r\n num_end = k_r%num_r\n\n if num_end == 0:\n print(next_city)\n \n else:\n print(teleport(next_city, num_end, roop))\n \n\n\n \n\n \n']
['Runtime Error', 'Accepted']
['s238961969', 's016259505']
[9144.0, 214956.0]
[24.0, 314.0]
[1092, 1134]
p02684
u571281863
2,000
1,048,576
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
['N,K=map(int,input().split())\nt=list(map(int,input().split()))\ng=[1]\nfor i in range(N):\n gs=set(g)\n if t[g[i]-1] in gs:\n h=g.index(t[g[i]-1])\n s=i+1-h\n break\n g.append(t[g[i]-1])\nif K>h:\n K=(K-h)%s+h\nprint(g[K])\nprint(s,h)', 'N, K = map(int, input().split())\nT_list = list(map(int, input().split()))\nT_list = [T_list[i]-1 for i in range(N)]\n\nif K < N:\n while i < K:\n point = T_list[point]\n i += 1 \n\nelse:\n point = 0\n syuuki = 0\n i = 0\n while i < N:\n point = T_list[point]\n if point == 0:\n syuuki = i+1\n break\n i += 1\n\n second_point = point\n if syuuki != 0:\n L = K % syuuki\n\n else:\n j = 0\n while j < N:\n point = T_list[point]\n if point == second_point:\n syuuki = j+1\n break\n j += 1\n L = (K-i) % syuuki\n\n k = 0\n while k < L:\n point = T_list[point]\n k += 1\n \nprint(point+1)', 'N, K = map(int, input().split())\nT_list = list(map(int, input().split()))\nT_list = [T_list[i]-1 for i in range(N)]\ncount_list = []\n\nfor s_point in range(N):\n point = s_point\n count = 0\n i = 0\n while i < N:\n point = T_list[point]\n if point == s_point:\n count = i+1\n break\n i += 1\n count_list.append(count)\n\nprint(count_list)\n\npoint = 0\nwhile count_list[point] == 0:\n point = T_list[point]\n count += 1\n\nprint(count,point)\nL = K % count_list[point]\npoint = 0\ni = 0\nwhile i < L:\n point = T_list[point]\n i += 1\nprint(point+1)', 'N,K=map(int,input().split())\nt=list(map(int,input().split()))\ng=[1]\nh={1}\nfor i in range(N-1):\n x=t[g[i]-1]\n g.append(x)\n if x in h:\n break\n h.add(x)\nif K>len(g):\n a=g.index(g[-1])\n b=len(g)-a-1\n K=(K-a)%b+a\nprint(g[K])']
['Wrong Answer', 'Runtime Error', 'Wrong Answer', 'Accepted']
['s366680572', 's394032799', 's692212269', 's395733681']
[32284.0, 9032.0, 32240.0, 32396.0]
[2206.0, 23.0, 2206.0, 170.0]
[234, 624, 548, 229]
p02684
u576432509
2,000
1,048,576
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
['from bisect import bisect_right\nfrom bisect import bisect_left\n\nn,k=map(int,input().split())\na=list(map(int,input().split()))\n\n#n=6\n#k=727202214173249351\n#a=[6, 5, 2, 5, 3, 2]\n\nai=1\naj=[]\nfor i in range(min(n,k)):\n aim=ai\n ai=a[ai-1]\n# print(ai,aj)\n if ai in aj:\n# print(ai,aj)\n ic2=aim\n break\n else:\n aj.append(ai)\n \n\nic1=bisect_left(a,a[ic2])\nicyc=ic2-ic1\n \nk2=(k-ic1)%icyc+ic1\nai=1\nfor i in range(k2):\n ai=a[ai-1]\n \nprint(ai)\n', 'n,k=map(int,input().split())\na=list(map(int,input().split()))\n\n#n=6\n#k=727202214173249351\n#a=[6, 5, 2, 5, 3, 2]\n\n#n=4\n#k=5\n#a=[3,2,4,1]\n\nif n<k:\n ai=1\n aj=set()\n aj.add(1)\n for i in range(n):\n ai=a[ai-1]\n if ai in aj:\n ic2=i\n ai2=ai\n break\n else:\n aj.add(ai)\n\n ai=1\n for i in range(n):\n ai=a[ai-1]\n if ai==ai2:\n ic1=i\n break\n\n icyc=ic2-ic1\n k2=(k-ic1)%icyc+ic1\nelse:\n k2=k\n \nai=1\nfor i in range(k2):\n ai=a[ai-1]\n \nprint(ai)', 'import sys\n\nn,k=map(int,input().split())\na=list(map(int,input().split()))\n\nfor i in range(n):\n a[i]-=1\n#print(a)\n\nif k<=n:\n b=0\n for i in range(k):\n b=a[b]\n print(b+1)\n sys.exit()\n \nb=0\nc=[-1]*n\nc[0]=0\nfor i in range(n):\n# print(b,a[b])\n b=a[b]\n if c[b]>=0:\n# print("i:",i)\n break\n else:\n c[b]=i+1\n\nki=c[b]+1\nkc=(i+1)-c[b]\nk2=(k-ki)%kc+ki\n#print("ki:",ki,"kc:",kc,"k2:",k2)\nb=0\nfor i in range(k2):\n b=a[b]\nprint(b+1)\n']
['Runtime Error', 'Runtime Error', 'Accepted']
['s024632991', 's107574770', 's478621884']
[32384.0, 32376.0, 32404.0]
[2206.0, 219.0, 159.0]
[492, 564, 471]
p02684
u580273604
2,000
1,048,576
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
['N,K=map(int,input().split())\nA=list(map(int,input().split()))\nB=[0]*(N+1)\nB[0]=1;c=0;d=0\nif B[0] in A:c=B[0]\nfor i in range(1,N+1):\n B[i]=A[B[i-1]-1]\n# if c==B[i]:break\n# if A.count(B[i])>1 and d==0:c=B[i];d+=1\n\nd=B.index(B[-1])\n#print(B.index(B[N-1]))\n#print(d)\n#print(B[-1])\n#print(B,d)\n\nif (K-d-1)%(N-d-1)==0:print(B[N])\nelse:print(B[d+1+(K-d-1)%(N-d-1)])\n', 'N,K=map(int,input().split())\nA=list(map(int,input().split()))\nB=[0]*N\nB[0]=1\nif B[0] in A:c=B[0]\nfor i in range(1,N):\n B[i]=A[B[i-1]-1]\n\nd=B.index(B[-1])+1\nif K<=N:print(B[K]);exit()\nprint(B[d-1+(K+1-d)%(N-d)])\n']
['Wrong Answer', 'Accepted']
['s541504262', 's109487847']
[32224.0, 32296.0]
[142.0, 130.0]
[421, 212]
p02684
u581022379
2,000
1,048,576
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
['N, K = map(int, input().split(" "))\ntowns = [int(i)-1 for i in input().split(" ")]\nloopCount = 0\nnowPos = 0\nposList = [0]\nwhile not(nowPos==0 and loopCount!=0):\n nowPos = towns[nowPos]\n posList.append(nowPos)\n for i in range(0,len(posList)+1):\n for j in range(i+1,len(posList)):\n length = j - i\n for l in range(len(posList)-length):\n if posList[l: l + length] == posList[i: j] and i != l:\n remain = K % loopCount - i\n nowPos = posList[j-1]\n for k in range(remain):\n nowPos = towns[nowPos]\n print(nowPos + 1)\n exit()\n loopCount = loopCount + 1\n if loopCount == K:\n print(nowPos + 1)\n exit()\n ', 'N, K = map(int, input().split(" "))\ntowns = [int(i)-1 for i in input().split(" ")]\nloopCount = 0\nnowPos = 0\nposList = [0]\nwhile not(nowPos==0 and loopCount!=0):\n nowPos = towns[nowPos]\n posList.append(nowPos)\n for i in range(0,len(posList)+1):\n for j in range(i+1,len(posList)):\n length = j - i\n for l in range(len(posList)-length):\n if posList[l: l + length] == posList[i: j] and i != l:\n remain = K % loopCount - i\n nowPos = posList[j-1]\n for k in range(remain):\n nowPos = towns[nowPos]\n print(nowPos + 1)\n exit()\n loopCount = loopCount + 1\n if loopCount == K:\n print(nowPos + 1)\n exit()\nprint(nowPos + 1)\n ', 'N, K = map(int, input().split())\ntowns = [int(i) for i in input().split()]\narrivedList = [1]\nloopCount = 0\nprevious = 0\nfor i in range(len(towns)):\n idx = arrivedList[len(arrivedList) - 1] - 1\n current = towns[idx]\n if arrivedList.count(current) == 0:\n arrivedList.append(current)\n else:\n previous = len(arrivedList) - (len(arrivedList)-arrivedList.index(current))\n loopCount = len(arrivedList)-arrivedList.index(current)\n print(previous,current, loopCount, arrivedList)\n break\n if i == K - 1:\n print(arrivedList[len(arrivedList) - 1])\n exit()\nremain = K % loopCount - previous\nloopList = arrivedList[previous: previous + loopCount]\nprint(loopList[remain])', '\nN, K = map(int, input().split())\ntowns = [int(i) for i in input().split()]\narrivedList = [1]\nfor i in range(N * 2):\n arrivedList.append(towns[arrivedList[-1] - 1])\nif K <= N:\n print(arrivedList[K])\n exit()\n\nloop_end = N\nloop_start = N - 1\nwhile (arrivedList[loop_end] != arrivedList[loop_start]):\n loop_start -= 1\n\nloop_len = loop_end - loop_start\n\n\nK = K % loop_len\nwhile K < N:\n K += loop_len\n\nprint(arrivedList[K])\n']
['Wrong Answer', 'Wrong Answer', 'Runtime Error', 'Accepted']
['s022004701', 's196717129', 's602001292', 's058213209']
[33432.0, 33436.0, 33536.0, 32360.0]
[2206.0, 2206.0, 2206.0, 178.0]
[785, 803, 720, 514]
p02684
u585613332
2,000
1,048,576
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
["n, k = list(map(int, input().split()))\nt = list(map(int, input().split()))\n\nvisited = [False]*(2*10**5 + 10)\nval = 1\ncount = 0\nhold = k\nwhile hold > 0 :\n if visited[val] or val == t[val - 1]:\n break\n visited[val] = True\n val = t[val - 1]\n # print('a', val)\n count += 1\n hold -= 1\nif hold == 0:\n print(t[val - 1])\n exit(0)\ncount0 = count\ncount = 1\nnewval = val\nstart = t[newval - 1]\nwhile start != newval:\n count += 1\n start = t[start - 1]\n# print('count', count, 'count0', count0)\nif t[val - 1] == t[0]:\n temp = k\nelse:\n temp = k - count0\n# print('temp', temp)\njump = (temp) % (count)\n\n# print('val', val)\nans = val\nfor i in range(jump):\n ans = t[ans - 1]\n print('b', ans)\nprint(ans)", "n, k = list(map(int, input().split()))\nt = list(map(int, input().split()))\n\nvisited = [False]*(2*10**5 + 10)\nval = 1\ncount = 0\nhold = k\nwhile hold > 0 :\n if visited[val] or val == t[val - 1]:\n break\n visited[val] = True\n val = t[val - 1]\n # print('a', val)\n count += 1\n hold -= 1\ncount0 = count\ncount = 1\nnewval = val\nstart = t[newval - 1]\nwhile start != newval:\n count += 1\n start = t[start - 1]\n# print('count', count, 'count0', count0)\nif t[val - 1] == t[0]:\n temp = k\nelse:\n temp = k - count0\n# print('temp', temp)\njump = (temp) % (count)\n\n# print('val', val)\nans = val\nfor i in range(jump):\n ans = t[ans - 1]\n print('b', ans)\nprint(ans)", "n, k = list(map(int, input().split()))\nt = list(map(int, input().split()))\n\nvisited = [False]*(2*10**5 + 10)\nval = 1\ncount = 0\nhold = k\nwhile hold > 0 :\n if visited[val - 1] or val == t[val - 1]:\n break\n visited[val - 1] = True\n val = t[val - 1]\n # print('a', val)\n count += 1\n hold -= 1\n# print(hold)\nif hold == 0:\n print(val)\n exit(0)\nif val == t[val - 1]:\n print(val)\n exit(0)\ncount0 = count\ncount = 1\nnewval = val\nstart = t[newval - 1]\nwhile start != newval:\n count += 1\n start = t[start - 1]\n# print('count', count, 'count0', count0)\nif t[val - 1] == t[0]:\n temp = k\nelse:\n temp = k - count0\n# print('temp', temp)\njump = (temp) % (count)\n\n# print('val', val)\nans = val\nfor i in range(jump):\n ans = t[ans - 1]\n # print('b', ans)\nprint(ans)"]
['Wrong Answer', 'Wrong Answer', 'Accepted']
['s290944859', 's305817989', 's392356412']
[32348.0, 32184.0, 32392.0]
[155.0, 2206.0, 187.0]
[753, 705, 819]
p02684
u591143370
2,000
1,048,576
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
['N,K = map(int, input().split())\nList = list(map(int, input().split()))\n\na=[]\nb=1\nfor i in range(N):\n if not b in a:\n a[i]=b\n b=List[b-1]\n else:\n c=i\n break\n#print(a)\n#print(b,c)\nnum=a.index(b)\n#print(T,num)\nT=c-num\nif K<num:\n print(a[K])\nelse:\n print(a[num:][(K-num)%T])', 'N,K = map(int, input().split())\nList = list(map(int, input().split()))\n\na=[]\n\nfor i in range(N):\n a.append(-1)\nprint(a)\nb=1\nfor i in range(N):\n if not b in a:\n a[i]=b\n b=List[b-1]\n else:\n c=i\n break\nprint(a)\nprint(b,c)\nnum=a.index(b)\nprint(T,num)\nT=c-num\nif K<num:\n print(a[K])\nelse:\n print(a[num:][(K-num)%T])', 'N,K = map(int, input().split())\nList = list(map(int, input().split()))\n\na=[]\n\nfor i in range(N):\n a.append(-1)\n#print(a)\nb=1\nfor i in range(N):\n if a[b-1]==-1:\n a[b-1]=i+1\n b=List[b-1]\n \n else:\n c=i\n break\n#print(a)\n#print(b,c)\n\nnum=a[b-1]-1\nT=c-num\n#print(T)\ne=1\nif K<num:\n for i in range(K):\n e=List[e-1]\n print(e)\nelse:\n qw=(K-num)%T\n List_new=[]\n for i in range(T):\n List_new.append(b)\n b=List[b-1]\n print(List_new[qw])']
['Runtime Error', 'Runtime Error', 'Accepted']
['s340245886', 's782742896', 's234320193']
[32328.0, 32364.0, 32240.0]
[68.0, 2206.0, 178.0]
[310, 353, 506]
p02684
u591295155
2,000
1,048,576
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
['def get_keys(d, val):\n return [k for k, v in d.items() if v == val]\n \ndef main():\n read = lambda: sys.stdin.readline().rstrip()\n \n N, K = map(int,read().split())\n A = list(map(int,read().split()))\n \n g = collections.defaultdict(int)\n for i, val in enumerate(A):\n g[i + 1] = val\n \n v = collections.defaultdict(int)\n cnt = 0\n cur = 1\n p = 0\n mp = 0\n while True:\n if v[cur] > 0:\n p = cnt - v[cur]\n mp = v[cur]\n break\n v[cur] = cnt\n cnt += 1\n cur = g[cur]\n \n print(get_keys(v, (K-mp)%p + mp)[0] if K >= mp else get_keys(v, K)[0])\n\n\n \nif __name__ == "__main__":\n main()', 'import sys\nimport collections\n#import cython\ndef get_keys(d, val):\n return [k for k, v in d.items() if v == val]\n \ndef main():\n read = lambda: sys.stdin.readline().rstrip()\n \n N, K = map(int,read().split())\n A = list(map(int,read().split()))\n \n g = collections.defaultdict(int)\n for i, val in enumerate(A):\n g[i + 1] = val\n \n v = collections.defaultdict(int)\n cnt = 0\n cur = 1\n p = 0\n mp = 0\n while True:\n if v[cur] > 0 or cnt > 2*10**5:\n p = cnt - v[cur]\n mp = v[cur]\n break\n v[cur] = cnt\n cnt += 1\n cur = g[cur]\n \n print(get_keys(v, (K-mp)%p + mp)[0] if K >= mp else get_keys(v, K)[0])\n\n\n \nif __name__ == "__main__":\n main()']
['Runtime Error', 'Accepted']
['s732420893', 's774488578']
[9156.0, 60424.0]
[24.0, 240.0]
[694, 756]
p02684
u591812989
2,000
1,048,576
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
['N,K=list(map(int,input().split()))\nA=list(map(int,input().split()))\np = 1\nB = [-1]*N\nB[0] = 0\ncount = 1\nwhile K < count :\n\tp = A[p-1]\n\tif B[p-1] != -1:\n\t\tbreak\n\tB[p-1] = count\n\tcount += 1\nif K < count:\n\tprint(p)\n\treturn\nK -= count\nK = K % (count-B[p-1])\nfor i in range(K):\n\tp = A[p-1]\nprint(p)\n\n\t\n', 'import sys\nN,K=list(map(int,input().split()))\nA=list(map(int,input().split()))\np = 1\nB = [-1]*N\nB[0] = 0\ncount = 1\nwhile K >= count:\n\tp = A[p-1]\n\tif B[p-1] != -1:\n\t\tbreak\n\tB[p-1] = count\n\tcount += 1\nif K < count:\n\tprint(p)\n\tsys.exit()\nK -= count\nK = K % (count-B[p-1])\nfor i in range(K):\n\tp = A[p-1]\nprint(p)\n\n\t\n']
['Runtime Error', 'Accepted']
['s709344206', 's245729661']
[9144.0, 32272.0]
[23.0, 130.0]
[297, 312]
p02684
u592547545
2,000
1,048,576
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
["def readinput():\n n,k=list(map(int,input().split()))\n a=list(map(int,input().split()))\n return n,k,a\n\ndef main(n,k,a):\n tbl={}\n for i in range(1,n+1):\n tbl[i]=a[i-1]\n machi=1\n for i in range(k):\n machi=tbl[machi]\n return machi\n\ndef main2(n,k,a):\n a.insert(0,0)\n #print(a)\n nvisited=[0 for i in range(n+1)]\n #print(nvisited)\n visited=[]\n current=1\n visited.append(current)\n nvisited[current]+=1\n next=a[current]\n #print('next='+str(next))\n while(nvisited[next]==0):\n current=next\n visited.append(current)\n nvisited[current]+=1\n next=a[current]\n loophead=next\n #print('loophead:'+str(loophead))\n #print('visited'+str(visited))\n beforeloop=visited.index(loophead)\n #print('beforeloop:'+str(beforeloop))\n loop=visited[beforeloop:]\n #print('loop:'+str(loop))\n looplen=len(loop)\n\n if (k<beforeloop):\n return visited[k+1]\n else:\n return loop[(k-beforeloop)%looplen]\n\ndef detectloop(a):\n \n \n \n \n nvisit=[0 for i in range(len(a))]\n visited=[]\n n=a[0]\n while(nvisit[n-1]==0):\n nvisit[n-1]+=1\n visited.append(n)\n n=a[n-1]\n #print(visited,n)\n i=visited.index(n)\n #print(i)\n if(i==0):\n loop=visited[:]\n head=[]\n else:\n loop=visited[i:]\n head=visited[:i]\n return head,loop\n\ndef main3(n,k,a):\n head,loop=detectloop(a)\n print(head,loop,k)\n if(k<=len(head)):\n return head[k-1]\n else:\n return loop[(k-len(head))%len(loop) -1]\n\n\n\n\n\nif __name__=='__main__':\n n,k,a=readinput()\n ans=main3(n,k,a)\n print(ans)\n", "def readinput():\n n,k=list(map(int,input().split()))\n a=list(map(int,input().split()))\n return n,k,a\n\ndef main(n,k,a):\n tbl={}\n for i in range(1,n+1):\n tbl[i]=a[i-1]\n machi=1\n for i in range(k):\n machi=tbl[machi]\n return machi\n\ndef main2(n,k,a):\n a.insert(0,0)\n #print(a)\n nvisited=[0 for i in range(n+1)]\n #print(nvisited)\n visited=[]\n current=1\n visited.append(current)\n nvisited[current]+=1\n next=a[current]\n #print('next='+str(next))\n while(nvisited[next]==0):\n current=next\n visited.append(current)\n nvisited[current]+=1\n next=a[current]\n loophead=next\n #print('loophead:'+str(loophead))\n #print('visited'+str(visited))\n beforeloop=visited.index(loophead)\n #print('beforeloop:'+str(beforeloop))\n loop=visited[beforeloop:]\n #print('loop:'+str(loop))\n looplen=len(loop)\n\n if (k<beforeloop):\n return visited[k+1]\n else:\n return loop[(k-beforeloop)%looplen]\n\ndef detectloop(a):\n \n \n \n \n nvisit=[0 for i in range(len(a))]\n visited=[]\n n=a[0]\n while(nvisit[n-1]==0):\n nvisit[n-1]+=1\n visited.append(n)\n n=a[n-1]\n #print(visited,n)\n i=visited.index(n)\n #print(i)\n if(i==0):\n loop=visited[:]\n head=[]\n else:\n loop=visited[i:]\n head=visited[:i]\n return head,loop\n\ndef main3(n,k,a):\n head,loop=detectloop(a)\n #print(head,loop,k)\n if(k<=len(head)):\n return head[k-1]\n else:\n return loop[(k-len(head))%len(loop) -1]\n\n\n\n\n\nif __name__=='__main__':\n n,k,a=readinput()\n ans=main3(n,k,a)\n print(ans)\n"]
['Wrong Answer', 'Accepted']
['s177332523', 's507176368']
[32388.0, 32404.0]
[161.0, 151.0]
[1789, 1790]
p02684
u593019570
2,000
1,048,576
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
['n,k = map(int,input().split())\n\na = list(map(int,input().split()))\n\nb = [1 for i in range(n)]\n\n\nnow = 0\nnext = -1\nc = []\nfor i in range(n):\n if b[next] == 0:\n d = c[:c.index(next)]\n e = [c[-1]] + c[c.index(next):-1]\n #print(d,e)\n break\n #print(now)\n b[now] = 0\n c.append(now)\n next = a[now] - 1\n #print(" ",next)\n now = next\n\nk = k - len(d)\nk = k % len(e)\nprint(e[k])', 'n,k = map(int,input().split())\n\na = list(map(int,input().split()))\n\nb = [1 for i in range(n)]\n\n\nnow = 0\nnext = a[now] - 1\nc = []\ncheck = False\nfor i in range(n):\n if b[next] == 0:\n d = c[:c.index(next)]\n e = c[c.index(next):]\n print(d,e)\n check = True\n break\n print(now)\n b[now] = 0\n c.append(now)\n next = a[now] - 1\n print(" ",next)\n now = next\n\nif check:\n k = k - len(d)\n k = k % len(e)\n print(e[k]+1)\n\nelse:\n k = k % len(c)\n print(c[k]+1)\n ', 'n,k = map(int,input().split())\n\na = list(map(int,input().split()))\n\nb = [1 for i in range(n)]\n\n\nnow = 0\nnext = a[now] - 1\nc = []\nfor i in range(n):\n if b[next] == 0:\n d = c[:c.index(next)]\n e = c[c.index(next):]\n print(d,e)\n break\n print(now)\n b[now] = 0\n c.append(now)\n next = a[now] - 1\n print(" ",next)\n now = next\n\nif k >= len(d):\n k = k - len(d)\n k = k % len(e)\n print(e[k]+1)\n\nelse:\n print(d[k]+1)\n ', '# coding: utf-8\n# Your code here!\nn,k = map(int,input().split())\n\na = list(map(int,input().split()))\n\nb = [1 for i in range(n)]\n\n\nnow = 0\nnext = a[now] - 1\nc = []\nfor i in range(n):\n if b[next] == 0:\n d = c[:c.index(next)]\n e = c[c.index(next):]\n #print(d,e)\n break\n #print(now)\n b[now] = 0\n c.append(now)\n next = a[now] - 1\n #print(" ",next)\n now = next\n\nif k >= len(d):\n k = k - len(d)\n k = k % len(e)\n print(e[k]+1)\n\nelse:\n print(d[k]+1)\n \n \n']
['Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Accepted']
['s429102382', 's452888343', 's489250142', 's857162046']
[32252.0, 32256.0, 32360.0, 32256.0]
[189.0, 360.0, 359.0, 187.0]
[416, 521, 473, 516]
p02684
u595375942
2,000
1,048,576
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
["from itertools import combinations\nimport numpy as np\nN, M, X = map(int,input().split())\nxx = np.array([X]*M)\nC = {}\ncs = []\nfor _ in range(N):\n c, *A = map(int,input().split())\n C[c] = A\n cs.append(c)\nans = float('inf')\nfor i in range(0, N+1):\n for comb in combinations(cs,i):\n tmp = 0\n x = xx.copy()\n for cos in comb:\n tmp += cos\n x -= np.array(C[cos])\n if len(x[x <= 0]) >= M:ans = min(ans,tmp)\nif ans == float('inf'):ans = '-1'\nprint(ans)", 'N, K = map(int, input().split())\nA = list(map(int, input().split()))\nidx = 1\nS = [idx]\ned = set([idx])\n\nfor i in range(1, K+1):\n idx = A[idx-1]\n if idx in ed:\n start = S.index(idx)\n end = len(S)\n n = start + (K - start) % (end - start)\n print(S[n])\n break\n else:\n S.append(idx)\n ed.add(idx)\n continue\nelse:\n print(idx)']
['Runtime Error', 'Accepted']
['s227184051', 's938524202']
[27164.0, 32376.0]
[111.0, 170.0]
[504, 386]
p02684
u595893956
2,000
1,048,576
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
['\nimport sys\nN, K = map(int, input().split())\nA = list(map(int, input().split()))\n\n\nalready = [False] * N\nstep = 0\nnow = 1\ncount = 1\nwhile(already[now-1] != True):\n already[now - 1] = True\n now = A[now - 1]\n count += 1\n if count - 1 == K:\n print(now)\n exit(0)\n\n\n\nif(now-1 == 0):\n step = 0\n loop = count\nelse:\n step = 0\n temp = 1\n while(temp != now):\n temp = A[temp - 1]\n step += 1\n cycle = count - step\n loop= (K-step) % cycle\n \ntemp = 1\nfor i in range(step + loop -1):\n temp = A[temp - 1]\nprint(temp)\n', '\nimport sys\nN, K = map(int, input().split())\nA = list(map(int, input().split()))\n\n\nalready = [False] * N\nstep = 0\nnow = 1\ncount = 0\nwhile(already[now-1] != True):\n already[now - 1] = True\n now = A[now - 1]\n count += 1\n if count == K: \n print(now)\n exit(0)\n\n\n\n\n\n\nloop = 0\ncycle = 0\nif(now == 1):\n step = 0\n cycle = count\n loop = K % cycle\nelse:\n step = 0\n temp = 1\n while(temp != now):\n temp = A[temp - 1]\n step += 1\n cycle = count - step\n loop= (K - step) % cycle\n\ntemp = 1\nfor i in range(step + loop):\n temp = A[temp - 1]\nprint(temp)']
['Wrong Answer', 'Accepted']
['s488388248', 's636648133']
[32180.0, 32384.0]
[200.0, 191.0]
[729, 1030]
p02684
u596681540
2,000
1,048,576
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
['N, K = map(int, input().split())\n\nA_list = [int(a) for a in input().split()]\n\n\n# print(A_list)\n\nkeiro = [1]\nvisit_town = [0]*N\n\ntown = 1\nc = 1\nwhile True:\n visit_town[town - 1] = c\n c += 1\n town = A_list[town - 1]\n \n\n if len(keiro) > 1 and visit_town[town-1] != 0:\n break\n keiro.append(town)\n\n\n# print(visit_town)\n# print(town)\n\n\nfirst_visit = keiro[:visit_town[A_list[keiro[-1]-1]-1]-1]\nloop_visit = keiro[visit_town[A_list[keiro[-1]-1]-1]-1:]\n\nprint(first_visit)\nprint(loop_visit)\n\nif K <= len(first_visit):\n print(first_visit[k - 1])\nelse:\n l = K - len(first_visit)\n # print(l)\n c = (l-1) % len(loop_visit)\n # print(c)\n print(loop_visit[c-1])\n\n\n', 'N, K = map(int, input().split())\n\nA_list = [int(a) for a in input().split()]\n\n\n# print(A_list)\n\nkeiro = [1]\nvisit_town = [0]*N\n\ntown = 1\nc = 1\nwhile True:\n visit_town[town - 1] = c\n c += 1\n town = A_list[town - 1]\n \n\n if len(keiro) > 1 and visit_town[town-1] != 0:\n break\n keiro.append(town)\n\n\n# print(visit_town)\n# print(town)\n\n\nfirst_visit = keiro[:visit_town[A_list[keiro[-1]-1]-1]-1]\nloop_visit = keiro[visit_town[A_list[keiro[-1]-1]-1]-1:]\n\n# print(first_visit)\n# print(loop_visit)\n\nif K <= len(first_visit)-1:\n print(first_visit[K])\nelse:\n l = K - len(first_visit)\n # print(l)\n c = (l) % len(loop_visit)\n # print(c)\n print(loop_visit[c])\n\n\n']
['Runtime Error', 'Accepted']
['s310205578', 's034692498']
[32288.0, 32256.0]
[271.0, 178.0]
[814, 812]
p02684
u597455618
2,000
1,048,576
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
['import sys\n\ndef main():\n n, k = map(int, sys.stdin.buffer.readline().split())\n a = [0] + list(map(int, sys.stdin.buffer.readline().split()))\n\n visited = [0]*(n+1)\n town = 1\n for i in range(k+1):\n town = a[town]\n if visited[town] == 0:\n visited[town] = i\n else:\n print(visited.index( (k - visited[town])%(i + visited[town]) + visited[town]))\n exit()\n print(town)\n\nif __name__ == "__main__":\n main()', 'import sys\n\ndef main():\n n, k = map(int, sys.stdin.buffer.readline().split())\n a = [0] + list(map(int, sys.stdin.buffer.readline().split()))\n\n visited = [0]*(n+1)\n town = 1\n for i in range(k+1):\n town = a[town]\n if visited[town] == 0:\n visited[town] = i\n else:\n print(visited.index( (k - visited[town])%(i + visited[town]) + visited[town] ))\n exit()\n print(town)\n\nif __name__ == "__main__":\n main()', 'def main():\n n, k = map(int, input().split())\n a = list(map(int, input().split()))\n\n towns = [1]\n i = 0\n while a[i] not in towns:\n towns.append(a[i])\n i = a[i] - 1\n ti = towns.index(a[i]) + 1\n if ti > k:\n print(towns[ti - 1])\n else:\n print(towns[(k - ti)%(len(towns) - ti) + ti])\n\nif __name__ == "__main__":\n main()', 'import sys\n\ndef main():\n n, k = map(int, sys.stdin.buffer.readline().split())\n a = [0] + list(map(int, sys.stdin.buffer.readline().split()))\n\n visited = [0]*(n+1)\n town = 1\n for i in range(1, k+1):\n town = a[town]\n if visited[town] == 0:\n visited[town] = i\n else:\n cyc = (k - visited[town])%(i + visited[town]) + visited[town]\n print(visited.index(cyc))\n exit()\n print(town)\n\nif __name__ == "__main__":\n main()', 'import sys\n\ndef main():\n n, k = map(int, sys.stdin.buffer.readline().split())\n a = [0] + list(map(int, sys.stdin.buffer.readline().split()))\n\n visited = [0]*(n+1)\n town = 1\n for i in range(k+1):\n town = a[town]\n if visited[town] == 0:\n visited[town] = i\n else:\n print(visited.index( (k - visited[town])%(i - visited[town]) + visited[town]))\n exit()\n print(town)\n\nif __name__ == "__main__":\n main()', 'import sys\n\ndef main():\n n, k = map(int, sys.stdin.buffer.readline().split())\n a = [0] + list(map(int, sys.stdin.buffer.readline().split()))\n\n visited = [0]*(n+1)\n town = 1\n for i in range(1, k+1):\n town = a[town]\n if visited[town] == 0:\n visited[town] = i\n else:\n cyc = (k - visited[town])%(i - visited[town]) + visited[town]\n print(visited.index(cyc))\n exit()\n print(town)\n\nif __name__ == "__main__":\n main()']
['Runtime Error', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Wrong Answer', 'Accepted']
['s074542349', 's090562553', 's202710108', 's681462509', 's768544267', 's494198021']
[27796.0, 27800.0, 32228.0, 27964.0, 27968.0, 27812.0]
[98.0, 109.0, 2206.0, 102.0, 102.0, 102.0]
[472, 473, 370, 496, 472, 496]
p02684
u601620345
2,000
1,048,576
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
['import numpy as np\nimport math \nN, K=map(int,input().split())\nA2 = np.zeros(N)\nA = list(map(int,input().split()))\nA = list(map(lambda x: x -1 , A))\ncurrent_town = 0\n\n\n\ni=0\nwhile i<K:\n current_town = A[current_town]\n if A2[current_town] != 0:\n cycle = i - A2[current_town] \n i = K - (K-i) % cycle\n else:\n A2[current_town] = i\n\nprint(current_town+1)\n', 'import numpy as np\nimport math \nN, K=map(int,input().split())\nA2 = np.zeros(N)\nA = list(map(int,input().split()))\n#A = list(map(lambda x: x -1 , A))\ncurrent_town = 0\n\n\n\ni=0\nwhile i<K:\n current_town = A[current_town]\n if A2[current_town] != 0:\n cycle = i - A2[current_town] \n i = K - (K-i) % cycle\n else:\n A2[current_town] = i\n\nprint(current_town+1)\n', 'import numpy as np\nN, K=map(int,input().split())\n\nA2 = np.zeros(N)\nA = list(map(int,input().split()))\nA = list(map(lambda x: x -1 , A))\ncurrent_town = 0\n \n \n \ni=0\nwhile i<K:\n current_town = A[current_town]\n if A2[current_town] != 0:\n cycle = i - A2[current_town] \n i = K - ((K-i) % cycle)\n break\n else:\n A2[current_town] = i\n t=i+1\n i=t\n\nwhile i<K:\n current_town = A[current_town]\n t=i+1\n i=t\n\nprint(current_town+1)', 'import numpy as np\nn, k=map(int,input().split())\n\na = list(map(int,input().split()))\n\n \ns = list()\nord = np.full(n+1, -1)\nc=1\nl=0\n\nv=1\nwhile ord[v]==-1:\n ord[v]=len(s)\n s.append(v)\n v=a[v-1]\nc=len(s)-ord[v]\nl=ord[v]\n\nif k<l:\n print(s[k]) \nelse:\n k-=l\n k%=c\n print(s[l+k])\n']
['Time Limit Exceeded', 'Runtime Error', 'Wrong Answer', 'Accepted']
['s464654269', 's652493006', 's675431638', 's042769419']
[51028.0, 51016.0, 51040.0, 51072.0]
[2206.0, 2207.0, 2206.0, 278.0]
[379, 380, 476, 294]
p02684
u602773379
2,000
1,048,576
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
['\ndef input2():\n\treturn map(int,input().split())\n\n\ndef input_array():\n\treturn list(map(int,input().split()))\n \nn,k=input2()\nA=input_array()\n\n\ntmps=[1] \nloops=[] \ncount=0 \n\nfor i in range(2*(10**5)+1):\n\tif A[count] not in tmps:\n\t\ttmps.append(A[count])\n\telif (A[count] in tmps) and (A[count] not in loops):\n\t\tloops.append(A[count])\n\telif A[count] in loops:\n\t\tbreak\n\tcount=A[count]-1\n\ntmps=tmps[:-(len(loops))]\nprint(tmps)\nprint(loops)\n\nif k<=len(tmps):\n\tprint(tmps[k-1])\nelse:\n\tans=(k-(len(tmps)))%len(loops)\n\tprint(loops[ans])', '\ndef input2():\n\treturn map(int,input().split())\n\n\ndef input_array():\n\treturn list(map(int,input().split()))\n \nn,k=input2()\nA=input_array()\n\n\njudge=[True]*n\ntmps=[1] \ncount=0 \n\nfor i in range(2*(10**5)+1):\n\tif judge[count]==True:\n\t\tjudge[count]=False\n\t\tcount=A[count]-1\n\t\ttmps.append(count+1)\n\telse:\n\t\tbreak\n\nloop_st=tmps[-1]\nloops=tmps[loop_st:-1]\n\n\nif k<loop_st:\n\tprint(tmps[k])\nelse:\n\tk=k-loop_st\n\tk%=len(loops)\n\tprint(loops[k])', '\ndef input2():\n\treturn map(int,input().split())\n\n\ndef input_array():\n\treturn list(map(int,input().split()))\n \nn,k=input2()\nA=input_array()\n\n\ntmps=[1] \nloops=[] \nst=0 が始まる地点\ncount=0 \n\nfor i in range(10**5):\n\tif A[count] not in tmps:\n\t\ttmps.append(A[count])\n\telif (A[count] in tmps) and (A[count] not in loops):\n\t\tloops.append(A[count])\n\t\tst=i\n\telse:\n\t\tbreak\n\tcount=A[count]-1\n\n\nprint(tmps)\nprint(loops)\nprint(st)\n\nif k<=st:\n\tprint(tmps[k-1])\nelse:\n\tans=(k-(st-1))%len(loops)\n\tprint(ans)\n\tprint(loops[ans])', 'n,k=input2()\nA=input_array()\n\n\ntmps=[1] \nloops=[] \nst=0 が始まる地点\ncount=0 \n\nfor i in range(10**5):\n\tif A[count] not in tmps:\n\t\ttmps.append(A[count])\n\telif (A[count] in tmps) and (A[count] not in loops):\n\t\tloops.append(A[count])\n\t\tst=i\n\telse:\n\t\tbreak\n\tcount=A[count]-1\n\n\nif k<=st:\n\tprint(tmps[k-1])\nelse:\n\tans=(k-(st-1))%len(loops)\n\tprint(loops[ans])', '\ndef input2():\n\treturn map(int,input().split())\n\n\ndef input_array():\n\treturn list(map(int,input().split()))\n \nn,k=input2()\nA=input_array()\n\n\ntmps=[1] \nloops=[] \nst=0 が始まる地点\ncount=0 \n\nfor i in range(2*(10**5)+1):\n\tif A[count] not in tmps:\n\t\ttmps.append(A[count])\n\telif (A[count] in tmps) and (A[count] not in loops):\n\t\tloops.append(A[count])\n\t\tst=i\n\telif A[count] in loops:\n\t\tbreak\n\tcount=A[count]-1\n\n\n\nif k<=st:\n\tprint(tmps[k-1])\nelse:\n\tans=(k-(st-1))%len(loops)\n\tprint(loops[ans])', '\ndef input2():\n\treturn map(int,input().split())\n\n\ndef input_array():\n\treturn list(map(int,input().split()))\n \nn,k=input2()\nA=input_array()\n\n\ntmps=[1] \nloops=[] \nst=0 が始まる地点\ncount=0 \n\nfor i in range(10**5):\n\tif A[count] not in tmps:\n\t\ttmps.append(A[count])\n\telif (A[count] in tmps) and (A[count] not in loops):\n\t\tloops.append(A[count])\n\t\tst=i\n\telse:\n\t\tbreak\n\tcount=A[count]-1\n\n\n\n\nif k<st:\n\tprint(tmps[k])\nelse:\n\tans=(k-(st-1))%len(loops)\n\tprint(loops[ans])', '\ndef input2():\n\treturn map(int,input().split())\n\n\ndef input_array():\n\treturn list(map(int,input().split()))\n \nn,k=input2()\nA=input_array()\n\n\njudge=[True]*n\ntmps=[1] \ncount=0 \n\nfor i in range(2*(10**5)+1):\n\tif judge[count]==True:\n\t\tjudge[count]=False\n\t\tcount=A[count]-1\n\t\ttmps.append(count+1)\n\telse:\n\t\tbreak\n\nloop_st=tmps.index(tmps[-1])\nloops=tmps[loop_st:-1]\n\n\nif k<loop_st:\n\tprint(tmps[k])\nelse:\n\tk=k-loop_st\n\tk%=len(loops)\n\tprint(loops[k])']
['Wrong Answer', 'Runtime Error', 'Wrong Answer', 'Runtime Error', 'Wrong Answer', 'Wrong Answer', 'Accepted']
['s175111465', 's285131189', 's439279456', 's735408547', 's838240267', 's992784282', 's843128025']
[32364.0, 32384.0, 32296.0, 9100.0, 32244.0, 32308.0, 32268.0]
[2206.0, 183.0, 2206.0, 26.0, 2206.0, 2206.0, 154.0]
[655, 554, 654, 433, 631, 605, 566]
p02684
u606146341
2,000
1,048,576
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
['n, k = map(int, input().split())\nlst = list(map(int, input().split()))\n\nvisited = [0] * n\nflg = 1\ni = 0\nnow = 0\nwhile flg:\n if visited[now] == 0:\n i += 1\n visited[now] = i\n now = lst[now] \n else:\n break\nprint(i, now, visited)\n\nk_bk = k - visited[now]\nk_bk = k_bk // i\n\nlft = (k - visited[now]) - i* k_bk\n\nif lft ==0:\n print(now+1)\nelse:\n for _ in range(lft):\n now = lst[now]\n print(now+1)', 'n, k = map(int, input().split())\nlst = list(map(int, (input().split())))\nlst = [_ - 1 for _ in lst]\n\nvisited = [0] * n\nflg = 1\ni = 0\nnow = 0\nwhile flg:\n if visited[now] == 0:\n i += 1\n visited[now] = i\n now = lst[now] \n else:\n break\n \nk_bk = k - visited[now]\nk_bk = k_bk // (i - visited[now])\n\nlft = k - k_bk * (i - visited[now])\n\nif lft ==0:\n print(now+1)\nelse:\n for _ in range(lft):\n now = lst[now]\n print(now+1)', 'n, k = map(int, input().split())\nlst = list(map(int, input().split()))\n\nvisited = [0] * n\nflg = 1\ni = 0\nnow = 0\nwhile flg:\n if visited[now] == 0:\n i += 1\n visited[now] = i\n now = lst[now] \n else:\n break\n \nk_bk = k - visited[now]\nk_bk = k_bk // i\n\nlft = (k - visited[now]) - i* k_bk\n\nif lft ==0:\n print(now+1)\nelse:\n for _ in range(lft):\n now = lst[now]\n print(now+1)\n', 'n, k = map(int, input().split())\nlst = list(map(int, (input().split())))\nlst = [_ - 1 for _ in lst]\n\nvisited = [0] * n\ni = 0\nnow = 0\nwhile k > i:\n if visited[now] == 0:\n i += 1\n visited[now] = i\n now = lst[now] \n else:\n break\n\nlp = (i + 1) - visited[now]\nst = i - lp\nk_bk = k - st\nk_bk = k_bk // lp\nlft = k - (k_bk * lp + st)\n\nif lft == 0:\n print(now+1)\nelse:\n for _ in range(lft):\n now = lst[now]\n print(now+1)\n']
['Runtime Error', 'Runtime Error', 'Runtime Error', 'Accepted']
['s072059698', 's520926107', 's777931697', 's455744030']
[32364.0, 32332.0, 32396.0, 32252.0]
[113.0, 167.0, 111.0, 134.0]
[439, 471, 425, 462]
p02684
u607563136
2,000
1,048,576
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
['import numpy as np\n\ndef main():\n N,K = map(int,input().split())\n A = [0]\n A += list(map(int,input().split()))\n A = np.array(A)\n \n s_time =time.time()\n i = 1\n pas = np.zeros(N)\n pas[0] = i\n k = 1\n pass_set = set(pas)\n while k <= K:\n if A[i] in pass_set:\n rps = np.where(pas==(A[i]))[0]\n ans = A[i]\n break\n pas[k] = A[i]\n pass_set.add(A[i])\n ans = A[i]\n i = A[i]\n k += 1\n\n if k >= K:\n print(ans)\n else:\n rpnum = (K-rps[0])%(k-rps)\n print(int(pas[rps[0]+rpnum]))\n\nmain()', 'n,k = map(int,input().split())\na = list(map(int,input().split()))\n\nmemo = [1]\nsetm = set(memo)\ncnt = 1\nto = 1\nwhile cnt <= k:\n to = a[to-1]\n if to not in setm:\n memo.append(to)\n setm.add(to)\n cnt += 1\n else:\n break\n \nidx = memo.index(to)\nkidx = ((k - len(memo))%(len(memo)-idx))\nif len(memo)>k:\n print(memo[-2])\nelse:\n print(memo[-1] if kidx==0 else: memo[idx:][kidx])', '\nn,k = map(int,input().split())\na = list(map(int,input().split()))\n\nmemo = [1]\nsetm = set(memo)\ncnt = 1\nto = 1\nwhile cnt <= k:\n to = a[to-1]\n if to not in setm:\n memo.append(to)\n setm.add(to)\n cnt += 1\n else:\n break\n \nidx = memo.index(to)\nkidx = ((k - len(memo))%(len(memo)-idx))\nif cnt<=k:\n print(memo[-2])\nelse:\n print(memo[-1] if kidx==0 else memo[idx:][kidx-1])', 'def main():\n N,K = map(int,input().split())\n A = [0] + list(map(int,input().split()))\n \n i = 1\n pas = [i]\n pas_set = set(pas)\n k = 1\n while k <= K:\n if A[i] in pas_set:\n rps = pas.index(A[i])\n ans = A[i]\n break\n pas.append(A[i])\n pas_set.add(A[i])\n ans = A[i]\n i = A[i]\n k += 1\n\n if k >= K:\n print(ans)\n else:\n rpnum = (K-rps)%(k-rps)\n print(pas[rps+rpnum])\n\nmain()']
['Runtime Error', 'Runtime Error', 'Runtime Error', 'Accepted']
['s544228602', 's690052530', 's820724599', 's471451068']
[51028.0, 8996.0, 32280.0, 32208.0]
[169.0, 25.0, 161.0, 157.0]
[605, 418, 415, 491]
p02684
u607865971
2,000
1,048,576
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
['N, K = [int(x) for x in input().split()]\nA = [int(x) - 1 for x in input().split()]\n\ni = 0\nT = []\nS = set()\nst = 0\nwhile True:\n T.append(i)\n S.add(i)\n i = A[i]\n if i in S:\n st = T.index(i)\n break\n\nprint(T)\n\nidx = (K - st) % (len(T) - st)\nprint(T[st + idx] + 1)\n\n\n\n', 'N, K = [int(x) for x in input().split()]\nA = [int(x) - 1 for x in input().split()]\n\ni = 0\nT = []\nS = set()\nst = 0\nwhile True:\n T.append(i)\n S.add(i)\n i = A[i]\n if i in S:\n st = T.index(i)\n break\n\n# print(T)\n\n\nidx = (K - st) % (len(T) - st)\n\nif K > st:\n print(T[st + idx] + 1)\nelse:\n print(T[K] + 1)\n\n\n\n']
['Wrong Answer', 'Accepted']
['s572019124', 's255691027']
[32548.0, 32620.0]
[205.0, 155.0]
[289, 334]
p02684
u607884285
2,000
1,048,576
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
["n,k=map(int,input().split(' '))\na=list(map(int,input().split(' ')))\nloc=1\nbegin=0\nend=0\nd={1:0}\nfor i in range(n+1):\n loc=a[loc-1]\n if loc in d.keys():\n begin=d[loc]\n end=i+1\n break\n d[loc]=i+1\nif k<=end:\n end=0\nif end==begin+1:\n k=begin\n end=0\nif end !=0:\n k=(k-begin+1)%(end-begin)+begin-1\nloc=1\nfor _ in range(k):\n loc=a[loc-1]\nprint(loc)", "n,k=map(int,input().split(' '))\na=list(map(int,input().split(' ')))\nloc=1\nbegin=0\nend=0\nd={1:0}\nfor i in range(n+1):\n loc=a[loc-1]\n if loc in d.keys():\n begin=d[loc]\n end=i+1\n break\n d[loc]=i+1\nif k<=end:\n end=0\nif end==begin+1:\n k=begin\n end=0\nif end != 0:\n x=(k-begin+1)%(end-begin)\n if x==0:\n x=end-begin\n k=x+begin-1\nloc=1\nfor _ in range(k):\n loc=a[loc-1]\nprint(loc)"]
['Wrong Answer', 'Accepted']
['s270104728', 's665261427']
[38880.0, 39040.0]
[224.0, 223.0]
[386, 428]
p02684
u608007704
2,000
1,048,576
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
["N,K = map(int, input().split(' '))\n\ncache={}\nlog=[]\nA = list(map(lambda x:int(x)-1, input().split(' ')))\n\nnow=0\n\nwhile(True):\n log.append(now)\n cache[now]=1\n now=A[now]\n if(cache.get(now)):break\n\nloop_start=log.index(now)\nloop_end=len(log)\nloop=loop_end-loop_start\n#print(loop_end-loop_start,loop_start)\nprint(loop_start,loop_end,log)\nif len(log) >= loop:\n if loop_end>K:\n print(now)\n else:\n print(log[K%loop]+1)\nelse:\n print(log[K%loop+loop]+1)", "N,K = map(int, input().split(' '))\n\ncache={}\nlog=[]\nA = list(map(lambda x:int(x)-1, input().split(' ')))\n\nnow=0\n\nwhile(True):\n log.append(now)\n cache[now]=1\n now=A[now]\n if(cache.get(now)):break\n\nloop_start=log.index(now)\nloop_end=len(log)\nloop=loop_end-loop_start\n\nif K<len(log):\n print(log[K]+1)\nelse:\n print(log[(K-loop_start)%loop+loop_start]+1)\n"]
['Wrong Answer', 'Accepted']
['s287274837', 's364957973']
[35528.0, 35760.0]
[208.0, 166.0]
[458, 356]
p02684
u609307781
2,000
1,048,576
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
["# D\n\nN, K = list(map(int, input().split()))\nAs = list(map(int, input().split()))\n\ndef compute(city, K):\n for i in range(K):\n # print('\\t', city)\n city = As[city-1]\n print(city)\n\n\nif N > K:\n compute(1, K)\n\ncities_visited = [False] * N\ni = 0\ncity = 1\ncity_visited_time = {}\n\nwhile not cities_visited[city - 1]:\n # print(city)\n cities_visited[city - 1] = True\n city_visited_time[city-1] = i\n city = As[city-1]\n i += 1\n\nloop_start = city_visited_time[city-1]\nloop_end = i\n\nif loop_end - loop_start == 1:\n return city\ndiv = (K - loop_start) // (loop_end - loop_start + 1)\n# print(loop_start, loop_end, div, K % (loop_end - loop_start + 1))\ncompute(city, K % (loop_end - loop_start + 1) + loop_start + 1)", "# D\n\nN, K = list(map(int, input().split()))\nAs = list(map(int, input().split()))\n\ndef compute(city, K):\n for i in range(K):\n # print('\\t', city)\n city = As[city-1]\n print(city)\n\ncities_visited = [False] * N\ni = 0\ncity = 1\ncity_visited_time = {}\n\nwhile not cities_visited[city - 1]:\n # print(city)\n cities_visited[city - 1] = True\n city_visited_time[city-1] = i\n city = As[city-1]\n i += 1\n\nloop_start = city_visited_time[city-1]\nloop_end = i\n\n\ndiv = (K - loop_start) // (loop_end - loop_start)\nif K - loop_start < 0 or div == 0:\n compute(1, K)\nelse:\n compute(city, K - loop_start - div * (loop_end - loop_start))"]
['Runtime Error', 'Accepted']
['s733193197', 's201317373']
[9168.0, 45892.0]
[24.0, 214.0]
[739, 652]
p02684
u614162316
2,000
1,048,576
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
['n,k=map(int,input().split())\na=list(map(int,input().split()))\n\ns=[]\nd=[-1]*(n+1)\n\nv=1\nwhile(d[v]==-1):\n d[v]=len(s)\n s.append(v)\n v=a[v-1]\nc=len(s)-d[v]\nl=d[v]\n\nif(k<l):print(s[k])\nelse:\n k-=l\n k%=c\n print(k+l)', 'n,k=map(int,input().split())\na=list(map(int,input().split()))\n\ns=[]\nd=[-1]*(n+1)\n\nv=1\nwhile(d[v]==-1):\n d[v]=len(s)\n s.append(v)\n v=a[v-1]\nc=len(s)-d[v]\nl=d[v]\n\nif(k<l):print(s[k])\nelse:\n k-=l\n k%=c\n print(s[k+l])']
['Wrong Answer', 'Accepted']
['s263791134', 's738626105']
[32300.0, 32380.0]
[145.0, 180.0]
[228, 231]
p02684
u620238824
2,000
1,048,576
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
['N, K = list(map(int, input().split()))\nA = list(map(int, input().split()))\n\nB = [0] * N\nC = 0\nD = 0\nE = []\nfor i in range(K):\n if i == 0:\n B[i] += 1\n C = A[0]\n D += 1\n E.append(C)\n #print(i, C)\n \n else:\n if B[C - 1] == 0:\n B[C - 1] += 1\n C = A[C - 1]\n D += 1\n #E.append(C)\n #print(i, C)\n \n else:\n \n #print(D, K % D)\n #print(E)\n print(E[K % D])\n exit()\n\nprint(C)', 'n, k = map(int, input().split())\na = list(map(int, input().split()))\n\nmrk = [0] * n\nplc = a[0] - 1\nrp = 0 \nrpc = -1\nprc = 0\nfor i in range(1, k + 1):\n\n if rpc >= 0:\n rpc += 1\n if plc == rp:\n\n k = (k - prc) % rpc\n\n for i in range(k):\n plc = a[plc] - 1\n\n print(plc + 1)\n exit()\n if rpc == -1:\n prc += 1\n if mrk[plc] == 1 and rpc == -1:\n rp = plc\n rpc = 0\n mrk[plc] += 1\n if i < k:\n plc = a[plc] - 1\n\n\nprint(plc + 1)']
['Runtime Error', 'Accepted']
['s225496931', 's011082887']
[32376.0, 32376.0]
[162.0, 189.0]
[581, 838]
p02684
u623659526
2,000
1,048,576
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
['import logging\n\nlogging.basicConfig(level=logging.INFO, format="%(message)s")\n\n\n\ndef main():\n N, K = map(int, input().split())\n A_i = list(map(int, input().split()))\n B_i = []\n cycle_list = []\n \n cycle = 0\n diff = 0\n counter = 0\n machi = 1\n for num in A_i:\n if machi in B_i:\n diff = B_i.index(machi)\n cycle = counter - diff\n cycle_list = B_i[diff:]\n else:\n counter += 1\n machi = A_i[machi - 1]\n\n mod_K = (K - diff) % cycle\n\n print(cycle_list[mod_K])\n\nif __name__ == "__main__":\n main()\n', 'import logging\n\nlogging.basicConfig(level=logging.INFO, format="%(message)s")\n\n\n\ndef main():\n N, K = map(int, input().split())\n A_i = list(map(int, input().split()))\n B_i = [0 for i in range(N)]\n cycle_list = []\n \n cycle = 0\n diff = 0\n counter = 0\n machi = 1\n while counter < N:\n if B_i[machi] == 1:\n diff = cycle_list.index(machi)\n cycle = counter - diff\n cycle_list = cycle_list[diff:]\n break\n else:\n counter += 1\n B_i[machi] = 1\n cycle_list.append(machi)\n machi = A_i[machi - 1]\n \n mod_K = (K - diff) % cycle\n\n print(cycle_list[mod_K])\n\nif __name__ == "__main__":\n main()\n', 'import logging\n\nlogging.basicConfig(level=logging.INFO, format="%(message)s")\n\n\n\ndef main():\n N, K = map(int, input().split())\n A_i = list(map(int, input().split()))\n B_i = []\n cycle_list = []\n \n cycle = 0\n diff = 0\n counter = 0\n machi = 1\n while True:\n if machi in B_i:\n diff = B_i.index(machi)\n cycle = counter - diff\n cycle_list = B_i[diff:]\n break\n else:\n counter += 1\n machi = A_i[machi - 1]\n\n mod_K = (K - diff) % cycle\n\n print(cycle_list[mod_K])\n\nif __name__ == "__main__":\n main()\n', 'import logging\n\nlogging.basicConfig(level=logging.INFO, format="%(message)s")\n\n\n\ndef main():\n N, K = map(int, input().split())\n A_i = list(map(int, input().split()))\n B_i = [0 for i in range(N)]\n cycle_list = []\n \n cycle = 0\n diff = 0\n counter = 0\n machi = 1\n while counter < N:\n if B_i[machi] == 1:\n diff = cycle_list.index(machi)\n cycle = counter - diff\n cycle_list = cycle_list[diff:]\n break\n else:\n counter += 1\n B_i[mahci] = 1\n cycle_list.append(machi)\n machi = A_i[machi - 1]\n \n mod_K = (K - diff) % cycle\n\n print(cycle_list[mod_K])\n\nif __name__ == "__main__":\n main()\n', 'import logging\n\nlogging.basicConfig(level=logging.INFO, format="%(message)s")\n\n\n\ndef main():\n N, K = map(int, input().split())\n A_i = list(map(int, input().split()))\n B_i = [0 for i in range(N)]\n cycle_list = []\n diff_list = []\n cycle = 0\n diff = 0\n counter = 0\n machi = 1\n\n while counter < N:\n if B_i[machi - 1] == 1:\n diff = cycle_list.index(machi)\n cycle = counter - diff\n diff_list = cycle_list[:diff]\n cycle_list = cycle_list[diff:]\n break\n else:\n counter += 1\n B_i[machi - 1] = 1\n cycle_list.append(machi)\n machi = A_i[machi - 1]\n\n if K < diff:\n print(diff_list[K])\n else:\n mod_K = (K - diff) % cycle\n print(cycle_list[mod_K])\n\nif __name__ == "__main__":\n main()\n']
['Runtime Error', 'Runtime Error', 'Time Limit Exceeded', 'Runtime Error', 'Accepted']
['s103312543', 's409867243', 's752432712', 's996553952', 's924231521']
[33940.0, 33960.0, 33964.0, 33936.0, 33972.0]
[116.0, 153.0, 2206.0, 86.0, 160.0]
[628, 761, 642, 761, 876]
p02684
u623687794
2,000
1,048,576
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
['N,k=map(int,input().split())\na=list(map(int,input().split()))\nfor i in range(N):\n a[i]-=1\nif a[0]==1:print(1);exit()\nc=dict()\nvisited=[False]*N\nvisited[0]=True\nc[0]=0\ncnt=0\ndap=0\nn=0\nb=[0]\nwhile True:\n n=a[n]\n if visited[n]:\n dap=c[n] \n break\n visited[n]=True\n b.append(n)\n cnt+=1\n c[n]=cnt\nl=len(c)\nprint(b[(k-dap)%(l-dap)+dap]+1,b)', 'N,k=map(int,input().split())\na=list(map(int,input().split()))\nfor i in range(N):\n a[i]-=1\nif a[0]==0:print(1);exit()\nc=dict()\nvisited=[False]*N\nvisited[0]=True\nc[0]=0\ncnt=0\ndap=0\nn=0\nb=[0]\nwhile True:\n n=a[n]\n if visited[n]:\n dap=c[n] \n break\n visited[n]=True\n b.append(n)\n cnt+=1\n c[n]=cnt\nl=len(c)\nif k<dap:\n print(b[k]+1)\nelse:\n print(b[(k-dap)%(l-dap)+dap]+1)']
['Wrong Answer', 'Accepted']
['s725457401', 's003415444']
[40664.0, 40656.0]
[222.0, 208.0]
[368, 404]
p02684
u632125181
2,000
1,048,576
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
['import sys\ns = sys.stdin.readlines()\nN, K = map(int, s[0].split())\nA = list(map(int, s[1].split()))\n\nb = [1]\ni = 0\nwhile True:\n if A[i] in b:\n# print("m: "+str(b.index(A[i])))\n# print("n: "+str(len(b)-A[i]))\n m = b.index(A[i])\n n = len(b)-A[i]\n K = (K-m)%n + m\n break\n b.append(A[i])\n i = A[i] - 1\n \ntmp = 0\nfor i in range(K):\n next_town = A[tmp]\n tmp = next_town - 1\nprint(next_town)', 'N, K = map(int, input().split())\nA = list(map(int,input().split()))\nb = [0]*N\nnext_town = 1\nfor i in range(N+1):\n if b[next_town-1] != 0:\n start = next_town\n cycle = i - b[next_town-1]\n# print("start: "+str(start))\n\n break\n b[next_town-1] = i\n next_town = A[next_town-1]\n \nnext_town = 1\nif b[start-1] >= K:\n for i in range(K):\n next_town = A[next_town-1]\n print(next_town)\nelse:\n next_town = start\n for i in range((K-b[start-1])%cycle):\n next_town = A[next_town-1]\n print(next_town)']
['Runtime Error', 'Accepted']
['s624810824', 's726692200']
[32496.0, 32344.0]
[2206.0, 177.0]
[444, 587]
p02684
u633255271
2,000
1,048,576
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
['N, K = list(map(int, input().split()))\nA = list(map(lambda x: int(x) - 1, input().split()))\n\nnow = 0\nroute = []\nwhile True:\n route.append(now)\n to = A[now]\n if to == None:\n break\n else:\n A[now] = None\n now = to\n\nprint(route)\n\nloop_start = route.index(now)\nloop_size = len(route) - loop_start\n\nn_for_loop = min(K, loop_start)\nn_in_loop = (K - n_for_loop) % loop_size\n\nprint(route[n_for_loop + n_in_loop] + 1)', 'N, K = list(map(int, input().split()))\nA = list(map(lambda x: int(x) - 1, input().split()))\n\nnow = 0\nroute = []\nwhile True:\n route.append(now)\n to = A[now]\n if to == None:\n break\n else:\n A[now] = None\n now = to\n\nloop_start = route.index(now)\nloop_size = len(route) - loop_start\n\nn_for_loop = min(K, loop_start)\nn_in_loop = (K - n_for_loop) % loop_size\n\nprint(route[n_for_loop + n_in_loop] + 1)', 'N, K = list(map(int, input().split()))\nA = list(map(lambda x: int(x) - 1, input().split()))\n\nv = [A[:]]\nnow = 0\nfor i in range(60):\n tmp = v[-1]\n v.append([tmp[x] for x in tmp])\n if K>>i & 1:\n now = v[i][now]\nprint(now + 1)']
['Wrong Answer', 'Wrong Answer', 'Accepted']
['s915018153', 's924675567', 's661014862']
[32356.0, 32144.0, 115464.0]
[179.0, 145.0, 1755.0]
[440, 426, 239]
p02684
u636290142
2,000
1,048,576
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
["N, K = map(int, input().split())\nA = list(map(int, input().split()))\n\nroop_num = 1\ncity = 0\nfirst_city = 0\n\nwhile True:\n next_city = A[city] - 1\n if next_city == first_city:\n break\n if roop_num == K:\n print(city + 1)\n exit()\n city = next_city\n roop_num += 1\n\nrem_num = K % roop_num\ncity = 0\nnum = 0\n\nwhile True:\n next_city = A[city] - 1\n if num == rem_num:\n print('answer', city + 1)\n exit()\n city = next_city\n num += 1\n", 'n, k = map(int, input().split())\narr = list(map(int, input().split()))\nl = [-1]*(n+1) \ntmp = [] \npos = 1 \ncnt = 0 \nwhile 1:\n if l[pos] != -1: \n t = cnt-l[pos] \n if k < cnt:\n print(tmp[k])\n else: \n print(tmp[l[pos]+(k-cnt) % t])\n break\n l[pos] = cnt\n cnt += 1\n tmp.append(pos)\n pos = arr[pos-1]\n']
['Wrong Answer', 'Accepted']
['s435845541', 's874525699']
[32360.0, 32316.0]
[2206.0, 154.0]
[482, 679]
p02684
u638033979
2,000
1,048,576
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
['from collections import deque\nimport numpy as np\nn,k =map(int,input().split())\nA = [int(x)-1 for x in input().split()]\narrive_time = [0]*n\ntime = 1\ndone = [0]*n\ndone[A[0]] = 1\narrive_time[A[0]] = time\nlast = 0\nwhile True:\n v = A[0]\n if done[A[v]] == 0:\n done[A[v]] = 1 \n time += 1\n arrive_time[A[v]] = time\n else:\n last = A[v]\n break \n\nif time >= k:\n for i,a in enumerate(arrive_time):\n if a == k:\n print(i+1)\nelse:\n roop = time - arrive_time[last] + 1\n nokori = (k-arrive_time[last])%roop\n ans = nokori+arrive_time[last]\n for i,a in enumerate(arrive_time):\n if a == ans:\n print(i+1)\n\nprint(arrive_time)', 'from collections import deque\nimport numpy as np\nn,k =map(int,input().split())\nA = [int(x)-1 for x in input().split()]\narrive_time = [0]*n\ntime = 1\ndone = [0]*n\ndone[A[0]] = 1\narrive_time[A[0]] = time\nlast = 0\nnext = A[0]\nwhile True:\n v = next\n if done[A[v]] == 0:\n done[A[v]] = 1 \n time += 1\n arrive_time[A[v]] = time\n next = A[v]\n else:\n last = A[v]\n break \n\nif time >= k:\n for i,a in enumerate(arrive_time):\n if a == k:\n print(i+1)\nelse:\n roop = time - arrive_time[last] + 1\n nokori = (k-arrive_time[last])%roop\n ans = nokori+arrive_time[last]\n for i,a in enumerate(arrive_time):\n if a == ans:\n print(i+1)\n']
['Wrong Answer', 'Accepted']
['s896792198', 's364702666']
[51080.0, 51088.0]
[201.0, 342.0]
[700, 713]
p02684
u642012866
2,000
1,048,576
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
['N, K = map(int, input().split())\nA = list(map(int, ("0 "+input()).split()))\n\n\nc = [0]*(N+1)\ni = 1\ncnt = 0\nf = True\n\nwhile cnt < K:\n if f and c[A[i]]:\n print(cnt, i, c)\n loop = cnt-c[A[i]]\n cnt += (K-cnt-1)//loop*loop\n if cnt == K:\n break\n f = False\n\n cnt += 1\n i = A[i]\n c[i] = cnt\n\nprint(i)', 'N, K = map(int, input().split())\nA = list(map(int, ("0 "+input()).split()))\n\n\nc = [0]*(N+1)\ni = 1\ncnt = 0\nf = True\n\nwhile cnt < K:\n if f and (c[A[i]] or A[i]==1):\n loop = cnt-c[A[i]]+1\n cnt += (K-cnt-1)//loop*loop\n f = False\n\n cnt += 1\n i = A[i]\n c[i] = cnt\n\nprint(i)']
['Runtime Error', 'Accepted']
['s250319972', 's008349841']
[32332.0, 32384.0]
[158.0, 136.0]
[349, 300]
p02684
u648881683
2,000
1,048,576
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
["import sys\ninput = lambda: sys.stdin.readline().rstrip() \nsys.setrecursionlimit(10**7)\nINF = 10**20\ndef I(): return int(input())\ndef F(): return float(input())\ndef S(): return input()\ndef LI(): return [int(x) for x in input().split()]\ndef LI_(): return [int(x)-1 for x in input().split()]\ndef LF(): return [float(x) for x in input().split()]\ndef LS(): return input().split()\n\ndef resolve():\n N, K = LI()\n A = LI_()\n\n ord = [-1]*N\n\n city = 0\n cnt = 0\n teleport_path = []\n while ord[city]==-1:\n ord[city] = cnt\n teleport_path.append(city)\n city = A[city]\n cnt += 1\n loop_head = ord[city]\n loop_length = len(teleport_path) - loop_head\n # print(teleport_path, loop_head, loop_length)\n\n if K-1<loop_head:\n print(teleport_path[K]+1)\n else:\n K = loop_head + (K-loop_head)%loop_length\n print(teleport_path[K]+1)\n\nif __name__ == '__main__':\n r", "import sys\ninput = lambda: sys.stdin.readline().rstrip() \nsys.setrecursionlimit(10**7)\nINF = 10**20\ndef I(): return int(input())\ndef F(): return float(input())\ndef S(): return input()\ndef LI(): return [int(x) for x in input().split()]\ndef LI_(): return [int(x)-1 for x in input().split()]\ndef LF(): return [float(x) for x in input().split()]\ndef LS(): return input().split()\n\ndef resolve():\n N, K = LI()\n A = LI_()\n\n ord = [-1]*N\n\n city = 0\n cnt = 0\n teleport_path = []\n while ord[city]==-1:\n ord[city] = cnt\n teleport_path.append(city)\n city = A[city]\n cnt += 1\n loop_head = ord[city]\n loop_length = len(teleport_path) - loop_head\n # print(teleport_path, loop_head, loop_length)\n\n if K-1<loop_head:\n print(teleport_path[K]+1)\n else:\n K = loop_head + (K-loop_head)%loop_length\n print(teleport_path[K]+1)\n\nif __name__ == '__main__':\n resolve()"]
['Runtime Error', 'Accepted']
['s071844339', 's881193476']
[9188.0, 33440.0]
[22.0, 146.0]
[922, 930]
p02684
u648901783
2,000
1,048,576
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
['N,K = map(int,input().split())\nA = list(map(int, input().split()))\n\n\n\n\ntrace = [0]*N\nloop_start = 0\nloop_before = 0\ncnt = 0\nall_cnt = 0\n\nif K > N:\n loop = 0\n now = 0\n while(1):\n # print(trace)\n trace[now] += 1\n if trace[now] == 3:\n break\n if trace[now] == 2:\n cnt += 1\n loop += 1 \n if cnt == 1: \n loop_start = now\n loop_before = all_cnt\n now = A[now]-1\n all_cnt += 1\n\n loop_before = loop_before - loop \n\n # print(loop)\n # print(loop_start)\n # print(loop_before)\n # print(loop)\n min_K = (K-1-loop_before) % loop\n \n # print(loop_before)\n now = 0\n for i in range(loop_before):\n now = A[now]-1\n for i in range(min_K):\n now = A[now]-1\n print(A[now])\n\n# if K < N:\n now = 0\n for i in range(K-1):\n now = A[now]-1\n print(A[now])\n\n\n\n\n# print(now+1)\n\n\n\n\n ', 'N,K = map(int,input().split())\nA = list(map(int, input().split()))\n\n\n\n\ntrace = [0]*N\nloop_start = 0\nloop_before = 0\ncnt = 0\nall_cnt = 0\n\nif K > N:\n loop = 0\n now = 0\n while(1):\n # print(trace)\n trace[now] += 1\n if trace[now] == 3:\n break\n if trace[now] == 2:\n cnt += 1\n loop += 1 \n if cnt == 1: \n loop_start = now\n loop_before = all_cnt\n now = A[now]-1\n all_cnt += 1\n\n loop_before = loop_before - loop \n\n # print(loop)\n # print(loop_start)\n # print(loop_before)\n # print(loop)\n min_K = (K-1-loop_before) % loop\n \n # print(loop_before)\n now = 0\n for i in range(loop_before):\n now = A[now]-1\n for i in range(min_K):\n now = A[now]-1\n print(A[now])\n\nif K <= N:\n now = 0\n for i in range(K-1):\n now = A[now]-1\n print(A[now])\n\n\n\n\n# print(now+1)\n\n\n\n\n ']
['Wrong Answer', 'Accepted']
['s224536015', 's625294063']
[32392.0, 32392.0]
[2206.0, 186.0]
[1070, 1069]
p02684
u652656291
2,000
1,048,576
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
['n,k = map(int,input().split())\nA = [int(input()) for _ in range(n)]\nB = []\nb = 1\nans = 1\nwhile ans:\n a = b\n b = A[a-1]\n B.append(b)\n if len(B) == len(A):\n ans = 0\n else:\n continue\n\nprint(B[k-1])\n', 'n,k = map(int,input().split())\nA = list(map(int,input().split()))\nB = []\nb = 1\nans = 1\nwhile ans:\n a = b\n b = A[a-1]\n B.append(b)\n if len(B) == len(A):\n ans = 0\n else:\n continue\n\nB = B*1000000000000000000000\nprint(B[k-1])\n', 'n,k = map(int,input().split())\nA = list(map(int,input().split()))\nB = []\nb = 1\nans = 1\nwhile ans:\n a = b\n b = A[a-1]\n B.append(b)\n if len(B) == len(A):\n ans = 0\n else:\n continue\n\nprint(B[k-1])\n', "n,k = map(int,input().split(' '))\nA = list(map(int,input().split(' ')))\nB = []\nb = 1\nans = 1\nwhile ans:\n a = b\n b = A[a-1]\n B.append(b)\n if len(B) == len(A):\n ans = 0\n else:\n continue\n\nprint(B[k-1])\n", 'n,k = map(int,input().split())\nA = list(map(int,input().split()))\nB = []\nb = 1\nans = 1\nwhile ans:\n b = A[b-1]\n B.append(b)\n if len(A) == len(B):\n ans = 0\n', 'n,k = map(int,input().split())\nA = list(map(int,input().split()))\nB = []\nB.append(A[0])\nb = 1\n\nwhile True:\n a = A[b-1]\n b = A[a-1]\n B.append(b)\n if len(B) == len(A):\n break\n\nprint(B[k])\n', 'n,k = map(int,input().split())\nA = list(map(int,input().split()))\nB = []\nB.append(A[0])\nb = 1\nans = 1\nwhile ans:\n a = A[b-1]\n b = A[a-1]\n B.append(b)\n if len(B) == len(A):\n ans = 0\n\nprint(B[k])\n', 'n,k = map(int,input().split())\nA = list(map(int,input().split()))\nB = []\nb = 1\nans = 1\n', 'n,k = map(int,input().split())\nA = list(map(int,input().split()))\nB = []\nb = 1\nans = 1\nwhile ans:\n a = b\n b = A[a-1]\n B.append(b)\n if len(B) == k:\n ans = 0\n if B[-1] == B[-2]:\n ans = 0\nprint(B[k-1])\n', 'n,k = map(int,input().split())\nA = list(map(int,input().split()))\nB = []\nB.append(A[0])\nb = 1\nans = 1\nwhile ans:\n a = b\n b = A[a-1]\n B.append(b)\n if len(B) == len(A):\n ans = 0\n\nprint(B[k])\n', 'n,k = map(int,input().split())\nA = list(map(int,input().split()))\nB = []\nB.append(A[0])\nc = 0\nwhile True:\n b = A[0]\n c = A[b-1]\n B.append(c)\n if c == b:\n break\n if len(B) == len(A):\n break\nprint(B[k])\n\n \n', 'n,k = map(int,input().split())\nA = list(map(int,input().split()))\nB = []\nb = 1\nans = 1\nwhile ans:\n a = b\n b = A[a-1]\n B.append(b)\n if len(B) == len(A):\n ans = 0\nC = B * 10000000000\nprint(C[k-1])\n', 'n,k = map(int,input().split())\nA = list(map(int,input().split()))\nB = []\nB.append(A[0])\nb = 0\nc = 1\nwhile True:\n b = A[c-1]\n c = A[b-1]\n B.append(c)\n if A[-1] == A[-2]:\n break\n if len(B) == len(A):\n break\nprint(B[k])\n', 'n,k = map(int,input().split())\nA = list(map(int,input().split()))\nB = []\nans = 1\nc = 1\nwhile ans:\n b = A[c-1]\n c = A[b-1]\n c.append(B)\n if c == b:\n B = B*k\n break\nprint(B[k-1])\n \n ', 'n,k = map(int,input().split())\nA = list(map(int,input().split()))\nB = []\nB.append(A[0])\nc = 1\nwhile True:\n b = A[c-1]\n c = A[b-1]\n B.append(c)\n if c == b:\n break\n if len(B) == len(A):\n break\nB = B*(10**18)\nprint(B[k])\n\n \n', 'n,k = map(int,input().split())\nA = list(map(int,input().split()))\nB = []\nb = 1\nans = 1\nwhile ans:\n b = A[b-1]\n B.append(b)\n if len(B) == len(A):\n ', 'n,k = map(int,input().split())\nA = list(map(int,input().split()))\nB = []\nb = 1\nans = 1\nwhile ans:\n a = b\n b = A[a-1]\n B.append(b)\n if len(B) == k:\n ans = 0\n if B[-1] == B[-2]:\n ans = 0\ncnt = k % len(B)\nprint(B[cnt])\n', 'n,k = map(int,input().split())\nA = list(map(int,input().split()))\nB = []\nb = 1\nans = 1\nwhile ans:\n a = b\n b = A[a-1]\n B.append(b)\n if len(B) == len(A):\n ans = 0\n\nprint(B[k-1])\n', 'n,k = map(int,input().split())\nA = list(map(int,input().split()))\nB = []\nb = 1\nans = 1\nwhile ans:\n b = A[b-1]\n B.append(b)\n if len(A) == len(B):\n ans = 0\nB = B*1000000000\nprint(B[k-1])', 'n,k = map(int,input().split())\nA = list(map(int,input().split()))\nB = []\nb = 1\nans = 1\nwhile ans:\n b = A[b-1]\n B.append(b)\n if len(A) == len(B):\n ans = 0\n\nprint(B[k])', 'n,k = map(int,input().split())\nA = list(map(int,input().split()))\nB = []\nb = 1\nans = 1\nwhile ans:\n b = A[b-1]\n B.append(b)\n if len(B) == len(A):\n ans = 0\n \nprint(B[k-1])\n', 'n,k = map(int,input().split())\nA = list(map(int,input().split()))\nB = []\nb = 1\nans = 1\nwhile ans:\n b = A[b-1]\n B.append(b)\n ', 'N,K = map(int,input().split())\nA = list(map(int,input().split()))\npos = 0\nvisit = [0] * N\nmove = []\nroop = []\nwhile visit[pos]!=2:\n if visit[pos]==0:\n move.append(pos)\n else:\n roop.append(pos)\n visit[pos] += 1\n pos = A[pos] - 1\nif len(move)>K:\n print(move[K]+1)\nelse:\n print(roop[(K-(len(move)-len(roop)))%len(roop)]+1)\n']
['Runtime Error', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Wrong Answer', 'Runtime Error', 'Runtime Error', 'Wrong Answer', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Time Limit Exceeded', 'Accepted']
['s038166217', 's232172712', 's241688526', 's243465174', 's257061570', 's326564683', 's328371768', 's364176024', 's403142475', 's468744717', 's518701662', 's555507388', 's579006661', 's713937245', 's747295369', 's770234868', 's801493203', 's872188543', 's903435124', 's940460010', 's957961326', 's988655596', 's396998017']
[11496.0, 32292.0, 32228.0, 32380.0, 32376.0, 32324.0, 32356.0, 32268.0, 32296.0, 32368.0, 32372.0, 32384.0, 32396.0, 32364.0, 32380.0, 9036.0, 32376.0, 32380.0, 32316.0, 32296.0, 32124.0, 152444.0, 32676.0]
[34.0, 148.0, 175.0, 158.0, 149.0, 196.0, 181.0, 64.0, 67.0, 161.0, 139.0, 159.0, 194.0, 65.0, 225.0, 25.0, 68.0, 185.0, 153.0, 148.0, 149.0, 2211.0, 206.0]
[206, 233, 204, 210, 160, 193, 201, 87, 210, 196, 216, 202, 228, 192, 233, 152, 227, 183, 190, 172, 179, 127, 352]
p02684
u654590131
2,000
1,048,576
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
['N, K = map(int, input().split())\nA = list(map(int,input().split()))\n\nA.insert(0,-1)\nroot = [1]\nnext = A[1]\nrf = 0\n\nfor _ in range(K):\n if next not in root:\n root.append(next)\n next = A[next]\n else:\n rf = root.index(next)\n roop = root[rf:]\n break\n\n\nprint(root[(K - rf - 1) % len(roop)])\n', 'N, K = map(int, input().split())\nA = list(map(int,input().split()))\n\nA.insert(0,-1)\nroot = [1]\n\nfor _ in range(N-1):\n root.append(A[root[-1]])\n\nif K > N:\n start = root.index(root[-1])\n index = (K - start) % (len(root) - start - 1) + start\n ans = root[index]\nelse:\n ans = root[K]\n\nprint(ans)\n']
['Runtime Error', 'Accepted']
['s950094226', 's127503674']
[32376.0, 32284.0]
[2206.0, 120.0]
[327, 306]
p02684
u657719194
2,000
1,048,576
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
['n,k = map(int,input().split())\nA = [0]+list(map(int,input().split()))\nvisited = [False for _ in range(n+1)]\npos = 1\nx = []\nflg = False\nfor i in range(k):\n if visited[pos] == False:\n x.append(pos)\n visited[pos] = True\n pos = A[pos]\n else:\n flg = True\n pre = x.index(pos)\n loop = x[pre:]\n break\nif not flg:\n print(pos)\nelse:\n print(loop[(k-pre)%len(loop)])\n~ ', 'n,k = map(int,input().split())\nA = [0]+list(map(int,input().split()))\nvisited = [False for _ in range(n+1)]\npos = 1\nx = []\nflg = False\nfor i in range(k):\n if visited[pos] == False:\n x.append(pos)\n visited[pos] = True\n pos = A[pos]\n else:\n flg = True\n pre = x.index(pos)\n loop = x[pre:]\n break\nif not flg:\n print(pos)\nelse:\n print(loop[(k-pre)%len(loop)])']
['Runtime Error', 'Accepted']
['s309802254', 's486854781']
[9092.0, 32372.0]
[24.0, 151.0]
[452, 415]
p02684
u657786757
2,000
1,048,576
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
['n,k = list(map(int,input().split()))\nA = list(map(int,input().split()))\ntour=[0]\nnext_town = 0\nfor i in range(n*2):\n next_town=A[next_town]-1\n if next_town in tour:\n first_roop_idx = tour.index(next_town)\n break\n tour.append(next_town)\n#print(tour)\nif k<=len(tour):\n ans = tour[k]\nelse:\n k-=first_roop_idx\n ans = tour[k%(len(tour)+first_roop_idx)+first_roop_idx-1]\nprint(ans)\n', 'n,k = list(map(int,input().split()))\nA = list(map(int,input().split()))\ntour=[0]\nvisited=[0]*n\nvisited[0]=1\nnext_town = 0\nflag=False\nfor i in range(n):\n next_town=A[next_town]-1\n if i==k:\n flag = True\n ans = next_town\n break\n if next_town==0:\n first_roop_idx = 0\n break\n if visited[next_town]>0:\n first_roop_idx = visited[next_town]\n break\n tour.append(next_town)\n visited[next_town]=i+1\nprint(tour)\nprint(visited)\n#print(first_roop_idx)\nif not flag:\n if k<=len(tour):\n ans = tour[k]\n else:\n k-=first_roop_idx\n #print("k=",k)\n if len(tour)-first_roop_idx==0:\n k=0\n else:k=k%(len(tour)-first_roop_idx)\n #print("k=",k)\n ans = tour[first_roop_idx+k]\nprint(ans+1)\nprint(flag)\n', 'n,k = list(map(int,input().split()))\nA = list(map(int,input().split()))\ntour=[0]\nvisited=[0]*n\nvisited[0]=1\nnext_town = 0\nflag=False\nfor i in range(n):\n next_town=A[next_town]-1\n if i==k:\n flag = True\n ans = next_town\n if visited[next_town]>0:\n first_roop_idx = visited[next_town]\n break\n tour.append(next_town)\n visited[next_town]=i+1\n#print(tour)\n#print(visited)\n#print(first_roop_idx)\nif not flag:\n if k<=len(tour):\n ans = tour[k]\n else:\n k-=first_roop_idx\n #print(k)\n k=k%(len(tour)-first_roop_idx)\n #print(k)\n ans = tour[first_roop_idx+k]\nprint(ans+1)\n', 'n,k = list(map(int,input().split()))\nA = list(map(int,input().split()))\ntour=[0]\nnext_town = 0\nfor i in range(n*2):\n next_town=A[next_town]-1\n if next_town in tour:\n first_roop_idx = tour.index(next_town)\n break\n tour.append(next_town)\nprint(tour)\nif k<=len(tour):\n ans = tour[k]\nelse:\n k-=first_roop_idx\n ans = tour[k%(len(tour)+first_roop_idx)+first_roop_idx-1]\nprint(ans)\n', 'n,k = list(map(int,input().split()))\nA = list(map(int,input().split()))\ntour=[0]\nvisited=[0]*n\nvisited[0]=1\nnext_town = 0\nflag=False\nfor i in range(n):\n next_town=A[next_town]-1\n if i+1==k:\n flag = True\n ans = next_town\n break\n if next_town==0:\n first_roop_idx = 0\n break\n if visited[next_town]>0:\n first_roop_idx = visited[next_town]\n break\n tour.append(next_town)\n visited[next_town]=i+1\n#print(tour)\n#print(visited)\n#print(first_roop_idx)\nif not flag:\n if k<=len(tour):\n ans = tour[k]\n else:\n k-=first_roop_idx\n #print("k=",k)\n if len(tour)-first_roop_idx==0:\n k=0\n else:k=k%(len(tour)-first_roop_idx)\n #print("k=",k)\n ans = tour[first_roop_idx+k]\nprint(ans+1)\nprint(flag)\n', 'n,k = list(map(int,input().split()))\nA = list(map(int,input().split()))\ntour=[0]\nvisited=[0]*n\nvisited[0]=1\nnext_town = 0\nflag=False\nfor i in range(n):\n next_town=A[next_town]-1\n if i+1==k:\n flag = True\n ans = next_town\n break\n if next_town==0:\n first_roop_idx = 0\n break\n if visited[next_town]>0:\n first_roop_idx = visited[next_town]\n break\n tour.append(next_town)\n visited[next_town]=i+1\n#print(tour)\n#print(visited)\n#print(first_roop_idx)\nif not flag:\n if k<=len(tour):\n ans = tour[k]\n else:\n k-=first_roop_idx\n #print("k=",k)\n if len(tour)-first_roop_idx==0:\n k=0\n else:k=k%(len(tour)-first_roop_idx)\n #print("k=",k)\n ans = tour[first_roop_idx+k]\nprint(ans+1)\n#print(flag)\n']
['Runtime Error', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Wrong Answer', 'Accepted']
['s057951900', 's098398468', 's798348812', 's915355887', 's968483056', 's291907611']
[32376.0, 34712.0, 32368.0, 32404.0, 32364.0, 32388.0]
[2206.0, 213.0, 143.0, 2206.0, 158.0, 168.0]
[408, 805, 648, 407, 809, 810]
p02684
u657994700
2,000
1,048,576
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
["import sys\n\n# print('input >>')\nN, K = map(int,(input().split()))\nAs = list(map(lambda x: int(x)-1,(input().split())))\n\nvisited = [0] * N\nvisited[0] = 1\nroots = [0]\nnow = 0\n\n# print('-----output-----')\nwhile True:\n now = As[now]\n if visited[now] == 1:\n p = now\n rep_start = roots.index(now)\n move = len(roots) - rep_start\n break\n roots.append(now)\n visited[now] = 1\n\nnow = 0\nif rep_start > K:\n for i in range(K+1):\n now = As[now]\n print(now+1)\n sys.exit()\n\n# now = p\n\n # now = As[now]\n\n\nK -= rep_start\nK %= move\nnow = p\n\n\n# print('now',now)\n\nfor i in range(K):\n print(now+1)\n now = As[now]\n\nprint(now+1)", 'import sys\n\n# print(\'input >>\')\nN, K = map(int,(input().split()))\nAs = list(map(lambda x: int(x)-1,(input().split())))\n\nnow = 0\n# move = 1\nnows = [0]\np = 0\n\n# print(\'-----output-----\')\nwhile True:\n # move += 1\n now = As[now]\n if now in nows:\n p = now\n rep_start = len(nows)\n nows = nows[::-1]\n move = nows.index(now)+1\n break\n nows.append(now)\n\nprint(\'実行速度計測\')\n\n"""\nnow = 0\nif rep_start > K:\n for i in range(K):\n now = As[now]\n print(now+1)\n sys.exit()\n\nnow = 0\nfor i in range(rep_start):\n now = As[now]\n\n\nK -= rep_start\nK %= move\nnow = p\n\nfor i in range(K):\n now = As[now]\n\nprint(now+1)\n"""', "import sys\n\n# print('input >>')\nN, K = map(int,(input().split()))\nAs = list(map(lambda x: int(x)-1,(input().split())))\n\nvisited = [0] * N\nvisited[0] = 1\nroots = [0]\nnow = 0\n\n# print('-----output-----')\nwhile True:\n now = As[now]\n if visited[now] == 1:\n p = now\n rep_start = roots.index(now)\n move = len(roots) - rep_start\n break\n roots.append(now)\n visited[now] = 1\n\nnow = 0\nif rep_start > K:\n print(roots[K]+1)\n \n # now = As[now]\n # print(now+1)\n # sys.exit()\n\n# now = p\n\n # now = As[now]\n\n\nK -= rep_start\nK %= move\nnow = p\n\n\n# print('now',now)\n\nfor i in range(K):\n print(now+1)\n now = As[now]\n\nprint(now+1)", 'import sys\n\n# print(\'input >>\')\nN, K = map(int,(input().split()))\nAs = list(map(lambda x: int(x)-1,(input().split())))\n\nvisited = [0] * N\nvisited[0] = 1\n\nnow = 0\n# move = 1\nnows = [0]\np = 0\n\n# print(\'-----output-----\')\nwhile True:\n now = As[now]\n if visited[now] == 1:\n p = now\n break\n visited[now] = 1\n\nprint(\'実行速度計測\')\n\n"""\nnow = 0\nif rep_start > K:\n for i in range(K):\n now = As[now]\n print(now+1)\n sys.exit()\n\nnow = 0\nfor i in range(rep_start):\n now = As[now]\n\n\nK -= rep_start\nK %= move\nnow = p\n\nfor i in range(K):\n now = As[now]\n\nprint(now+1)\n"""', "import sys\n\n# print('input >>')\nN, K = map(int,(input().split()))\nAs = list(map(lambda x: int(x)-1,(input().split())))\n\nvisited = [0] * N\nvisited[0] = 1\nroots = [0]\nnow = 0\n\n# print('-----output-----')\nwhile True:\n now = As[now]\n if visited[now] == 1:\n p = now\n rep_start = roots.index(now)\n move = len(roots) - rep_start\n break\n roots.append(now)\n visited[now] = 1\n\nnow = 0\nif rep_start > K:\n for i in range(K+1):\n now = As[now]\n print(now+1)\n sys.exit()\n\n# now = p\n\n # now = As[now]\n\n\nK -= rep_start\nK %= move\nnow = p\n\n\n# print('now',now)\n\nfor i in range(K):\n print(now+1)\n now = As[now]\n\nprint(now+1)", "import sys\n\n# print('input >>')\nN, K = map(int,(input().split()))\nAs = list(map(lambda x: int(x)-1,(input().split())))\n\nvisited = [0] * N\nvisited[0] = 1\nroots = [0]\nnow = 0\n\n# print('-----output-----')\nwhile True:\n now = As[now]\n if visited[now] == 1:\n p = now\n rep_start = roots.index(now)\n move = len(roots) - rep_start\n break\n roots.append(now)\n visited[now] = 1\n\nnow = 0\nif rep_start > K:\n for i in range(K):\n now = As[now]\n print(now+1)\n sys.exit()\n\n# now = p\n\n # now = As[now]\n\n\nK -= rep_start\nK %= move\nnow = p\n\n\n# print('now',now)\n\nfor i in range(K):\n print(now+1)\n now = As[now]\n\nprint(now+1)", "import sys\n\n# print('input >>')\nN, K = map(int,(input().split()))\nAs = list(map(lambda x: int(x)-1,(input().split())))\n\nvisited = [0] * N\nvisited[0] = 1\nroots = [0]\nnow = 0\n\n# print('-----output-----')\nwhile True:\n now = As[now]\n if visited[now] == 1:\n p = now\n rep_start = roots.index(now)\n move = len(roots) - rep_start\n break\n roots.append(now)\n visited[now] = 1\n\nnow = 0\nif rep_start > K:\n for i in range(K):\n now = As[now]\n print(now+1)\n sys.exit()\n\n# now = p\n\n # now = As[now]\n\n\nK -= rep_start\nK %= move\nnow = p\n\n\n# print('now',now)\n\nfor i in range(K):\n now = As[now]\n\nprint(now+1)"]
['Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Accepted']
['s172204030', 's491014198', 's504168827', 's578703163', 's852546036', 's951318632', 's333268142']
[32380.0, 32380.0, 32308.0, 32384.0, 32396.0, 32236.0, 32392.0]
[193.0, 2206.0, 229.0, 115.0, 164.0, 157.0, 174.0]
[711, 680, 747, 615, 719, 709, 692]
p02684
u661343770
2,000
1,048,576
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
['a, b = list(map(int, input().split()))\nc = list(map(int, input().split()))\nitta2 = set([])\nmati = 1\ni = 0\nitta = []\nt0 = time.time()\nwhile True:\n if mati in itta2:\n saisyo = mati\n break\n else:\n itta2.add(mati)\n itta.append(mati)\n mati = c[mati-1]\n i += 1\nprint(time.time()-t0)\nrisuto2 = set([])\nrisuto = []\nt0 = time.time()\n\nwhile True:\n if mati in risuto2:\n break\n else:\n risuto2.add(mati)\n risuto.append(mati)\n mati = c[mati-1]\nprint(time.time()-t0)\nif b <= i-1:\n print(itta[b])\nelse:\n print(risuto[(b-i) % len(risuto)])', 'a, b = list(map(int, input().split()))\nc = list(map(int, input().split()))\nitta2 = set([])\nmati = 1\ni = 0\nitta = []\nwhile True:\n if mati in itta2:\n saisyo = mati\n break\n else:\n itta2.add(mati)\n itta.append(mati)\n mati = c[mati-1]\n i += 1\nrisuto2 = set([])\nrisuto = []\n\nwhile True:\n if mati in risuto2:\n break\n else:\n risuto2.add(mati)\n risuto.append(mati)\n mati = c[mati-1]\nif b <= i-1:\n print(itta[b])\nelse:\n print(risuto[(b-i) % len(risuto)])']
['Runtime Error', 'Accepted']
['s249408327', 's264688863']
[32388.0, 43428.0]
[67.0, 254.0]
[610, 532]
p02684
u661647607
2,000
1,048,576
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
['N, K = map(int, input().split())\nA = list(map(int, input().split()))\n\nt = 0\nnow = 1\nfootprint = [1]\n\nwhile t < K:\n if A[now-1] not in footprint:\n footprint.append(A[now-1])\n now = A[now-1]\n t += 1\n continue\n else:\n s = footprint.index(A[now-1])\n l = t - s + 1\n e = K % l\n now = footprint[i+e]\n break\n\nprint(now)', 'N, K = map(int, input().split())\nA = list(map(int, input().split()))\n\nt = 0\nnow = 1\nfootprint = [1]\n\nwhile t < K:\n if A[now-1] not in footprint:\n footprint.append(A[now-1])\n now = A[now-1]\n t += 1\n else:\n s = footprint.index(A[now-1])\n l = t - s + 1\n e = K % l\n now = footprint[i+e]\n break\n\nprint(now)', 'N, K = map(int, input().split())\nA = list(map(int, input().split()))\n\nt = 0\nnow = 1\nfootprint = [1]\n\nwhile t < K:\n if A[now-1] not in footprint:\n footprint.append(A[now-1])\n now = A[now-1]\n t += 1\n else:\n s = footprint.index(A[now-1])\n l = t - s + 1\n e = (K-s) % l\n now = footprint[i+e]\n break\n\nprint(now)', 'N, K = map(int, input().split())\nA = list(map(int, input().split()))\n \nt = 0\nnow = 1\nfootprint = [1]\npast = [0]*N\npast[0] = 1\n\nwhile t < K:\n if past[A[now-1]-1] == 0:\n now = A[now-1]\n footprint.append(now)\n past[now-1]=1\n t += 1\n else:\n s = footprint.index(A[now-1])\n l = t - s + 1\n e = (K-s) % l\n now = footprint[s+e]\n break\n \nprint(now)']
['Runtime Error', 'Runtime Error', 'Runtime Error', 'Accepted']
['s231171129', 's299827963', 's673649577', 's578863710']
[32396.0, 32376.0, 32412.0, 32372.0]
[2206.0, 2206.0, 2206.0, 166.0]
[340, 327, 331, 370]
p02684
u667949809
2,000
1,048,576
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
['dic = {}\nfor key, a in zip(range(1, n+1), list(map(int,input().split()))):\n dic[key] = a\n \nkeynum = 0\nlog = [-1]*(n+1)\nnext = dic[1]\nstep = 1\nlog[next] = step\nk -= 1\nwhile k:\n next = dic[next]\n step += 1\n k -= 1\n if log[next] != -1:\n k %= log[next] - step\n else:\n log[next] = step\nprint(next)', 'n,k = map(int,input().split())\n\na = [0]\na.extend(list(map(int,input().split())))\nl = [None]*(n+1)\n\nnow = 1\nstep = 0\nl[now] = 0\nwhile k:\n now = a[now]\n step += 1\n k -= 1\n if l[now] is not None:\n looplen = (step - l[now])\n k = k%looplen\n else:\n l[now] = step\nprint(now)']
['Runtime Error', 'Accepted']
['s571533820', 's568543953']
[9104.0, 32348.0]
[24.0, 141.0]
[324, 303]
p02684
u671211357
2,000
1,048,576
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
['from sys import\nN,K=map(int,input().split())\nA=list(map(int,input().split()))\nans=[]\ndef saiki(B):\n if len(B)==K+1:\n ans.append(B)\n print(B[-1])\n return\n B.append(A[B[-1]-1])\n saiki(B)\nsaiki([1])\n#print(ans)', 'N,K=map(int,input().split())\nA=list(map(int,input().split()))\nkari=set()\nhako=set()\ncount=1\ncnt=1\nzahyo=0\nans=0\nkari.add(zahyo)\nif K<=10**6:\n for i in range(K):\n ans=A[ans]-1\n print(ans+1)\n exit()\nfor i in range(N):\n zahyo=A[zahyo]-1\n if zahyo not in kari:\n kari.add(zahyo)\n count+=1\n else:\n break\n\nhako.add(zahyo)\nfor i in range(N):\n zahyo=A[zahyo]-1\n if zahyo not in hako:\n hako.add(zahyo)\n cnt+=1\n else:\n break\ncount=len(kari)\ncnt=len(hako)\nkaisu=K-count\n\nif kaisu>N:\n kaisu=kaisu%cnt\nfor i in range(kaisu):\n zahyo=A[zahyo]-1\n\n#print(kari,hako)\nprint(zahyo+1)']
['Runtime Error', 'Accepted']
['s804916641', 's043657039']
[9004.0, 35948.0]
[26.0, 189.0]
[237, 686]
p02684
u671446913
2,000
1,048,576
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
['#!/usr/bin/env python3\nimport collections\nimport itertools as it\nimport math\n#import numpy as np\n \n# = input()\n# = int(input())\nn, k = map(int, input().split())\na = list(map(int, input().split()))\n\n#\n# c = collections.Counter()\n\nord_ = [-1] * (n + 1) \ns = []\ncurrent = 0\nwhile ord_[v] == -1:\n ord_[v] = len(s)\n s.append(v)\n current = a[current] -1\nc = len(s) - ord_[current]\nl = ord_[current]\n\nif k < l:\n print(s[k])\nelse:\n k -= l\n k %= c\n print(s[l+k])\n\n', '#!/usr/bin/env python3\nimport collections\nimport itertools as it\nimport math\n#import numpy as np\n \n# = input()\n# = int(input())\nn, k = map(int, input().split())\na = list(map(int, input().split()))\n\n#\n# c = collections.Counter()\n\nord_ = [-1] * (n + 1) \nhomon = [] \ncurrent = 0\nwhile ord_[current] == -1:\n ord_[current] = len(homon)\n homon.append(current)\n current = a[current] - 1\n\nfreq = len(homon) - ord_[current] \nn_before_loop = ord_[current] \n\nif k < n_before_loop:\n print(homon[k] + 1)\nelse:\n k -= n_before_loop\n k %= freq\n print(homon[n_before_loop+k] + 1)\n\n']
['Runtime Error', 'Accepted']
['s623769368', 's712362171']
[33720.0, 33724.0]
[72.0, 176.0]
[541, 743]
p02684
u677121387
2,000
1,048,576
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
['n,k = map(int,input().split())\na = [int(i)-1 for i in input().split()]\nloc = 0\ncnt1 = 0\nseen = [False]*n\nseen[0] = True\nwhile not seen[loc]:\n loc = a[loc]\n cnt1 += 1\n if cnt1 == k:\n print(loc+1)\n exit()\ncnt2 = 0\nx = loc\nwhile loc != x:\n loc = a[loc]\n cnt2 += 1\ncnt1 -= cnt2\nk = (k-cnt1)%cnt2\nloc = 0\nwhile k > 0:\n loc = a[loc]\n k -= 1\nprint(loc+1)', 'n,k = map(int,input().split())\na = [int(i)-1 for i in input().split()]\nseen = []\ncnt = [-1]*n\nnow = 0\nwhile cnt[now] == -1:\n cnt[now] = len(seen)\n seen.append(now)\n now = a[now]\nloop = len(seen)-cnt[now]\ntoloop = cnt[now]\nif k <= toloop:\n ans = seen[k] + 1\nelse:\n k = (k-toloop)%loop\n ans = seen[toloop+k] + 1\nprint(ans)']
['Runtime Error', 'Accepted']
['s524392274', 's022991292']
[32328.0, 32324.0]
[79.0, 151.0]
[382, 338]
p02684
u678505520
2,000
1,048,576
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
['n,k = map(int,input().split())\nA = list(map(int,input().split()))\nB=[1]\nm=0\nj=0\nfor i in range(1,n):\n B.append(A[m])\n m=A[m]-1\n if B[i] in B[:i]:\n while B[j]!=B[i]:\n j+=1\n break\nT=len(B)-j-1\nif n!=2: \n print(B[k-((k-j)//T)*T],B)\nelse:\n print(B[k%2])', 'n,k = map(int,input().split())\nA = list(map(int,input().split()))\nB=[1]\nm=0\nj=0\nfor i in range(1,n):\n B.append(A[m])\n m=A[m]-1\n if B[i] in B[:i]:\n while B[j]!=B[i]:\n j+=1\n print(j)\n break\nT=len(B)-j-1\nprint(B[k-((k-j)//T)*T])', "'''\npath = 'sub1_51.txt'\nf=open(path)\ndata1 = f.read()\nf.close()\nN=data1.split()\n'''\nn,k=map(int,input().split())\nA=list(map(int,input().split()))\n'''\nn=int(N[0])\nk=int(N[1])\nA=N[2:]\n'''\nA=[int(i)-1 for i in A]\nB=[]\ncnt=[0]*n\nm=0\nfor i in range(2*10**5):\n B.append(m)\n cnt[m]+=1\n if cnt[m]>1:\n break\n m=A[m]\nc=len(B)-(B.index(m)+1)\nprint(1+B[(max(k-B.index(m),0))%c + min(B.index(m),k)])\n\n"]
['Wrong Answer', 'Wrong Answer', 'Accepted']
['s907091536', 's926676646', 's070086612']
[32360.0, 32388.0, 30960.0]
[2206.0, 68.0, 177.0]
[292, 266, 454]
p02684
u686036872
2,000
1,048,576
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
['N, K = map(int, input().split())\nA = list(map(int, input().split()))\nA = [i-1 for i in A]\n\ncheck = [0]*N\ni = 0\nc = 0\ncheck = []\nvisited = [0]*N\nflag = False\nwhile c<=K:\n if visited[i] == 1:\n flag = True\n break\n else:\n check.append(i)\n visited[i] = 1\n i = A[i]\n c += 1\nif flag==True:\n X = check[check.index(i):]\n print(1+X[(K-check.index(i))%(len(check)-check.index(i))) \nelse: \n print(i+1)', 'N, K = map(int, input().split())\nA = list(map(int, input().split()))\nA = [i-1 for i in A]\n\ncheck = [0]*N\ni = 0\nc = 1\ncheck = []\nvisited = [0]*N\nflag = False\nwhile c<=K:\n if visited[i] == 1:\n flag = True\n break\n else:\n check.append(i)\n visited[i] = 1\n i = A[i]\n c += 1\nif flag==True:\n X = check[check.index(i):]\n print(1+X[(K-check.index(i))%len(X)]) \nelse: \n print(i+1)']
['Runtime Error', 'Accepted']
['s688135934', 's985394803']
[8984.0, 32256.0]
[20.0, 141.0]
[447, 427]
p02684
u686230543
2,000
1,048,576
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
['def zero_index(i: str) -> int:\n return int(i) - 1\n\nn, k = map(int, input().split())\ntransition = map(zero_index, input().split())\nplaces = [0]\nnext_place = transition[0]\nwhile next_place not in places:\n places.append(next_place)\n next_place = transition[next_place]\nstart = places.index(next_place)\nperiod = len(places) - start\nif k < start:\n t = k\nelse:\n t = (k - start) % priod + start\nprint(place[t] + 1)', 'def zero_index(i: str) -> int:\n return int(i) - 1\n\nn, k = map(int, input().split())\ntransition = list(map(zero_index, input().split()))\nplaces = [0]\nnext_place = transition[0]\nvirgin = [True] * n\nvirgin[0] = False\nwhile virgin[next_place]:\n virgin[next_place] = False\n places.append(next_place)\n next_place = transition[next_place]\nstart = places.index(next_place)\nperiod = len(places) - start\nif k < start:\n t = k\nelse:\n t = (k - start) % period + start\nprint(places[t] + 1)']
['Runtime Error', 'Accepted']
['s263932734', 's718577630']
[24464.0, 32176.0]
[41.0, 148.0]
[412, 481]
p02684
u687574784
2,000
1,048,576
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
["# -*- coding: utf-8 -*-\nn, k = list(map(int, input().split()))\na = list(map(int, input().split()))\n\nrem=k\nnxt=1\nvisit=[]\nvisit_set={}\nfor i in range(k):\n visit.append(nxt)\n visit_set.add(nxt)\n nxt=a[nxt-1]\n \n if nxt in visit_set:\n break\n rem-=1\n\nif rem==0:\n print(nxt)\nelse:\n# print('-'*60)\n# print('nxt=', nxt)\n# print('rem=', rem)\n# print('visit=', visit)\n \n loops=visit[visit.index(nxt):]\n print(loops[(rem-1)%len(loops)]) \n \n# print('-'*60)\n# print('loops=', loops)\n", "# -*- coding: utf-8 -*-\nn, k = list(map(int, input().split()))\na = list(map(int, input().split()))\n\nrem=k\nnxt=1\nvisit=[]\nvisit_set=set([])\nfor i in range(k):\n visit.append(nxt)\n visit_set.add(nxt)\n nxt=a[nxt-1]\n \n if nxt in visit_set:\n break\n rem-=1\n\nif rem==0:\n print(nxt)\nelse:\n# print('-'*60)\n# print('nxt=', nxt)\n# print('rem=', rem)\n# print('visit=', visit)\n \n loops=visit[visit.index(nxt):]\n print(loops[(rem-1)%len(loops)]) \n \n# print('-'*60)\n# print('loops=', loops)\n"]
['Runtime Error', 'Accepted']
['s252819819', 's243281221']
[32368.0, 32388.0]
[69.0, 174.0]
[557, 562]
p02684
u693007703
2,000
1,048,576
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
["N, K = [int(i) for i in input().split()]\nX = [int(i) for i in input().split()]\n\ntown = []\ndic = {}\n\ni = 0\nj = 0\n\nwhile i not in dic and j < K:\n print('i', i)\n dic[i] = j\n town.append(i)\n i = X[i] - 1\n j += 1\n \nif j == K:\n output = i + 1\n \nelse : \n num = dic[i]\n loop = j - num\n output = town[((K-num) % loop) +num] + 1\n \nprint(output)", 'N, K = [int(i) for i in input().split()]\nX = [int(i) for i in input().split()]\n\ntown = []\ndic = {}\n\ni = 0\nj = 0\n\nwhile i not in dic and j < K:\n dic[i] = j\n town.append(i)\n i = X[i] - 1\n j += 1\n \nif j == K:\n output = i + 1\n \nelse : \n num = dic[i]\n loop = j - num\n output = town[((K-num) % loop) +num] + 1\n \nprint(output)']
['Wrong Answer', 'Accepted']
['s370483342', 's126931125']
[33496.0, 33224.0]
[238.0, 154.0]
[370, 352]
p02684
u693723949
2,000
1,048,576
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
['n, k = [int(x) for x in input().split()]\na = [int(x)-1 for x in input().split()]\n\nvisited = [0]\norder = {}\norder[0] = 0\nx = 0\nT = -1\ni = 0\nwhile T<0:\n x = a[x]\n i+=1\n if x in visited:\n s = order[x]\n T = i - s\n break\n else:\n visited.append(x)\n order[x] = i\nif k < s:\n print(visited[k])\nelse:\n mod = (k-s) % T\n print(visited[s+mod])\n', 'n, k = [int(x) for x in input().split()]\na = [int(x) for x in input().split()]\n\nvisited = []\nx=0\nfor i in range(n):\n x = a[x]\n if x in visited:\n for j in range(i):\n if visited[j] == x:\n first = j\n break\n T = i - j\n break\n else:\n visited.append(a[i])\nmod = (k-first) % T\nprint(a[first+mod]+1)\n', 'n, k = [int(x) for x in input().split()]\na = [int(x) for x in input().split()]\n\nvisited = []\norder = {}\nx = 1\nT = -1\nwhile T < 0:\n x = a[x-1] \n if x not in visited:\n visited.append(x)\n order[x] = len(visited)-1\n else:\n T = len(visited) - order[x]\n s = order[x]\nif k < s:\n print(visited[k])\nelse:\n mod = (k-s) % T\n print(visited[s+mod])', 'n, k = [int(x) for x in input().split()]\na = [int(x) for x in input().split()]\n\nx = 0\nfor i in range(k):\n x = a[x]\nprint(x+1)', 'n, k = [int(x) for x in input().split()]\na = [int(x)-1 for x in input().split()]\n\nvisited = [0]\nx = 0\nT = -1\nwhile T < 0:\n x = a[x]\n if x in visited:\n for j in range(i):\n if visited[j] == x:\n first = j\n break\n T = i - j\n else:\n visited.append(x)\n break\n \nmod = (k-first) % T\nprint(a[first+mod]+1)\n', 'n, k = [int(x) for x in input().split()]\na = [int(x)-1 for x in input().split()]\n\nvisited = [0]\nx = 0\nfor i in range(n):\n x = a[x]\n if x in visited:\n for j in range(i):\n if visited[j] == x:\n first = j\n break\n T = i - j\n break\n else:\n \nmod = (k-first) % T\nprint(a[first+mod]+1)\n', 'n, k = [int(x) for x in input().split()]\na = [int(x)-1 for x in input().split()]\n\nvisited = [0]\norder = {}\nx = 0\nT = -1\ni = 0\nwhile T<0:\n x = a[x]\n i+=1\n if x in visited:\n T = i - order[x]\n s = order[x]\n break\n else:\n visited.append(x)\n order[x] = i\nif k < s:\n print(visited[k])\nelse:\n mod = (k-s) % T\n print(visited[s+mod])', 'n, k = [int(x) for x in input().split()]\na = [int(x)-1 for x in input().split()]\n\nvisited = []\nx=0\nfor i in range(n):\n x = a[x]\n if x in visited:\n for j in range(i):\n if visited[j] == x:\n first = j\n break\n T = i - j\n break\n else:\n visited.append(a[i])\nmod = (k-first) % T\nprint(a[first+mod]+1)\n', 'n, k = [int(x) for x in input().split()]\na = [int(x) for x in input().split()]\n\nvisited = []\norder = {}\nx = 1\nT = -1\nwhile T < 0:\n x = a[x-1] \n if x not in visited:\n visited.append(x)\n order[x] = len(visited)-1\n else:\n T = len(visited) - order[x]\n s = order[x]\nif k < s:\n print(visited[k])\nelse:\n mod = (k-s) % T\n print(visited[s+mod])\n', 'n, k = [int(x) for x in input().split()]\na = [int(x) for x in input().split()]\n\nvisited = [0]\nx=1\nfor i in range(n):\n x = a[i]\n if x in visited:\n for j in range(i):\n if visited[j] == x:\n first = j\n break\n T = i - j\n else:\n visited.append(a[i])\nmod = (k-first) % T\nprint(a[first+mod])\n', 'n, k = [int(x) for x in input().split()]\na = [int(x)-1 for x in input().split()]\n\nvisited = [0]\norder = {}\nx = 0\nT = -1\ni = 0\nwhile T<0:\n x = a[x]\n i+=1\n if x in visited:\n T = i - order[x]\n s = order[x]\n break\n else:\n visited.append(x)\n order[x] = i\nif k < s:\n print(visited[k])\nelse:\n mod = (k-s) % T\n print(visited[s+mod])\n', 'n, k = [int(x) for x in input().split()]\na = [int(x) for x in input().split()]\n\nvisited = []\norder = {}\nx = 1\nT = -1\nwhile T < 0:\n x = a[x-1] \n if x not in visited:\n visited.append(x)\n order[x] = len(visited)-1\n else:\n T = len(visited) - order[x]\n s = order[x]\n break\nif k < s:\n print(visited[k])\nelse:\n mod = (k-s) % T\n print(visited[s+mod])\n', 'n, k = [int(x) for x in input().split()]\na = [int(x) for x in input().split()]\n\nvisited = [-1 for i in range(n+1)] \npoints = []\norder = {}\nx = 1\nT = -1\n\nwhile visited[x] == -1:\n x = a[x-1] \n points.append(x)\n visited[x] = len(points)\nT = len(points) - visited[x]\ns = visited[x]\nif k < s:\n print(points[k])\nelse:\n k -= s\n mod = k % T\n print(points[s+mod])\n ', 'n, k = [int(x) for x in input().split()]\na = [int(x) for x in input().split()]\n\nvisited = [-1 for i in range(n+1)] \npoints = []\np = 1\nwhile visited[p] == -1:\n visited[p] = len(points)\n points.append(p)\n p = a[p-1] \n\nT = len(points) - visited[p]\ns = visited[p]\n\nif k < s:\n print(points[k])\nelse:\n mod = (k - s) % T\n print(points[s+mod])\n \n']
['Wrong Answer', 'Runtime Error', 'Wrong Answer', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Wrong Answer', 'Runtime Error', 'Runtime Error', 'Wrong Answer', 'Runtime Error', 'Accepted']
['s034441513', 's035990983', 's104720546', 's204852724', 's218204782', 's226492859', 's397404615', 's440870978', 's467895223', 's528791368', 's738340398', 's804957120', 's915135196', 's128896318']
[32168.0, 32320.0, 32252.0, 32336.0, 32192.0, 9052.0, 32204.0, 9056.0, 32208.0, 32332.0, 32252.0, 32088.0, 32344.0, 32324.0]
[2206.0, 2206.0, 2206.0, 2206.0, 79.0, 26.0, 2206.0, 22.0, 2206.0, 2206.0, 2206.0, 2206.0, 75.0, 178.0]
[353, 326, 369, 126, 332, 309, 346, 326, 370, 315, 347, 380, 417, 423]
p02684
u694380052
2,000
1,048,576
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
['n, k = map(int, input().split())\nli = list(map(int, input().split()))\n \ncheck = [0] * (n+10)\nres = []\nnext = 0\n \nfor i in range(k):\n if check[next] == 0:\n check[next] = 1\n next = li[next]-1\n elif check[next] == 1:\n check[next] += 1\n res.append(next+1)\n next = li[next]-1\n else:\n cnt = len(res)\n k -= check.count(1)\n amari = k%cnt\n print(res[amari])\n break', 'n, k = map(int, input().split())\nli = list(map(int, input().split()))\n \ncheck = [0] * (n)\nres = []\nnext = 0\n \nfor i in range(n):\n if check[next] == 0:\n check[next] = 1\n next = li[next]-1\n elif check[next] == 1:\n check[next] += 1\n res.append(next+1)\n next = li[next]-1\n else:\n cnt = len(res)\n k -= check.count(1)\n amari = k%cnt\n print(res[amari])\n break\nelse:\n\tamari=k%n\n ans=li[amari-1]\n\tprint(ans)', 'n,k=map(int,input().split())\npl=list(map(int,input().split()))\ncl=[0]*2*n\nres=[]\nnext=0\nfor x in range 2*n:\n if cl[next]==0:\n cl[next]=1\n next=pl[next]-1\n if cl[next]==1:\n res.append(next+1)\n cl[next]=2\n next=pl[next]-1\n else:\n lroop=len(res)\n k-=count.cl(1)\n num=k%lroop\n print(res[num-1])\n break\nelse:\n print(next+1)', 'n, k = map(int, input().split())\nli = list(map(int, input().split()))\n \ncheck = [0] * (n+10)\nres = []\nnext = 0\n \nfor i in range(k):\n if check[next] == 0:\n check[next] = 1\n next = li[next]-1\n elif check[next] == 1:\n check[next] += 1\n res.append(next+1)\n next = li[next]-1\n else:\n cnt = len(res)\n k -= check.count(1)\n amari = k%cnt\n print(res[amari])\n break\nelse:\n amari=k%n\n ans=li[amari-1]\n print(ans)\n', 'n, k = map(int, input().split())\nli = list(map(int, input().split()))\n \ncheck = [0] * (n+10)\nres = []\nnext = 0\n \nfor i in range(k):\n if check[next] == 0:\n check[next] = 1\n next = li[next]-1\n elif check[next] == 1:\n check[next] += 1\n res.append(next+1)\n next = li[next]-1\n else:\n cnt = len(res)\n k -= check.count(1)\n amari = k%cnt\n print(res[amari])\n break\nelse:\n print(next+1)\namari=k%n\n\tans=li[amari-1]\n\tprint(ans)\nn, k = map(int, input().split())\nli = list(map(int, input().split()))\n \ncheck = [0] * (n+10)\nres = []\nnext = 0\n \nfor i in range(n+10):\n if check[next] == 0:\n check[next] = 1\n next = li[next]-1\n elif check[next] == 1:\n check[next] += 1\n res.append(next+1)\n next = li[next]-1\n else:\n cnt = len(res)\n k -= check.count(1)\n amari = k%cnt\n print(res[amari])\n break\nelse:\n\tamari=k%n\n\tans=li[amari-1]\n\tprint(ans)', 'n, k = map(int, input().split())\nli = list(map(int, input().split()))\n \ncheck = [0] * (n+10)\nres = []\nnext = 0\n \nfor i in range(k):\n if check[next] == 0:\n check[next] = 1\n next = li[next]-1\n elif check[next] == 1:\n check[next] += 1\n res.append(next+1)\n next = li[next]-1\n else:\n cnt = len(res)\n k -= check.count(1)\n amari = k%cnt\n print(res[amari])\n break\nelse:\n\tamari=k%n\n ans=li[amari-1]\n\tprint(ans)\n', 'n,k=map(int,input().split())\npl=list(map(int,input().split()))\ncl=[0]*2*n\norder=[]\nnext=0\nfor i in range(k):\n if cl[next]==0:\n cl[next]=1\n next=pl[next]-1\n elif cl[next]==1:\n cl[next]=2\n order.append(pl[next])\n next=pl[next]-1\n else:\n kk=len(order)\n hasuu=cl.count(1)\n newk=k-hasuu\n ans=newk%kk\n print(order[ans])\n break\nelse:\n print(pl[next])\n', 'n,k=map(int,input().split())\npl=list(map(int,input().split()))\ncl=[0]*2*n\norder=[]\nnext=0\nfor i in range(k):\n if cl[next]==0:\n cl[next]=1\n next=pl[next]-1\n elif cl[next]==1:\n cl[next]=2\n order.append(next+1)\n next=pl[next]-1\n else:\n kk=len(order)\n hasuu=cl.count(1)\n newk=k-hasuu\n ans=newk%kk\n print(order[ans])\n break\nelse:\n print(pl[next])\n', 'n, k = map(int, input().split())\nli = list(map(int, input().split()))\n \ncheck = [0] * (n+10)\nres = []\nnext = 0\n \nfor i in range(k):\n if check[next] == 0:\n check[next] = 1\n next = li[next]-1\n elif check[next] == 1:\n check[next] += 1\n res.append(next+1)\n next = li[next]-1\n else:\n cnt = len(res)\n k -= check.count(1)\n amari = k%cnt\n print(res[amari])\n break\nelse:\n print(next+1)\namari=k%n\n\tans=li[amari-1]\n\tprint(ans)\nn, k = map(int, input().split())\nli = list(map(int, input().split()))\n \ncheck = [0] * (n+10)\nres = []\nnext = 0\n \nfor i in range(n+10):\n if check[next] == 0:\n check[next] = 1\n next = li[next]-1\n elif check[next] == 1:\n check[next] += 1\n res.append(next+1)\n next = li[next]-1\n else:\n cnt = len(res)\n k -= check.count(1)\n amari = k%cnt\n print(res[amari])\n break\nelse:\n amari=k%n\n ans=li[amari-1]\n print(ans)\n', 'n,k=map(int,input().split())\npl=list(map(int,input().split()))\ncl=[0]*2*n\norder=[]\nnext=0\nfor i in range(k):\n if cl[next]==0:\n cl[next]=1\n next=pl[next]-1\n elif cl[next]==1:\n cl[next]=2\n order.append(pl[next])\n next=pl[next]-1\n else:\n kk=len(order)\n hasuu=order.count(1)\n newk=k-hasuu\n ans=newk%kk\n print(order[ans])\n break\nelse:\n print(pl[next])', 'n, k = map(int, input().split())\nli = list(map(int, input().split()))\n \ncheck = [0] * (n+10)\nres = []\nnext = 0\n \nfor i in range(n+10):\n if check[next] == 0:\n check[next] = 1\n next = li[next]-1\n elif check[next] == 1:\n check[next] += 1\n res.append(next+1)\n next = li[next]-1\n else:\n cnt = len(res)\n k -= check.count(1)\n amari = k%cnt\n print(res[amari])\n break\nelse:\n\tamari=k%n\n ans=li[amari-1]\n\tprint(ans)\n', 'n,k=map(int,input().split())\npl=list(map(int,input().split()))\ncl=[0]*2*n\norder=[]\nnext=0\nfor i in range(k):\n if cl[next]==0:\n cl[next]=1\n next=pl[next]-1\n elif cl[next]==1:\n cl[next]=2\n order.append(next+1)\n next=pl[next]-1\n else:\n kk=len(order)\n hasuu=cl.count(1)\n newk=k-hasuu\n ans=newk%kk\n print(order[ans])\n break\nelse:\n print(next+1)\n']
['Wrong Answer', 'Runtime Error', 'Runtime Error', 'Wrong Answer', 'Runtime Error', 'Runtime Error', 'Wrong Answer', 'Wrong Answer', 'Runtime Error', 'Wrong Answer', 'Runtime Error', 'Accepted']
['s060283196', 's101062061', 's401791281', 's407687673', 's428304656', 's537286585', 's603973864', 's801189342', 's815450207', 's914457049', 's980584150', 's348932078']
[32372.0, 9060.0, 8968.0, 32372.0, 9092.0, 9000.0, 32084.0, 32264.0, 9072.0, 32332.0, 9064.0, 32348.0]
[168.0, 26.0, 24.0, 168.0, 25.0, 24.0, 164.0, 168.0, 26.0, 170.0, 25.0, 160.0]
[434, 480, 352, 484, 981, 484, 381, 379, 985, 383, 487, 377]
p02684
u696444274
2,000
1,048,576
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
['from fractions import gcd\nfrom functools import reduce\nfrom collections import deque\n# from math import factorial\nimport collections\nimport math\nimport sys\nsys.setrecursionlimit(2000000)\n\nn, k = list(map(int, input().split()))\na = list(map(int, input().split()))\n\ncheck = [0]*n\ncheck[0] = 1\nstack = [a[0]]\ncity = deque()\ncount = 0\nwhile stack:\n x = stack.pop()\n count += 1\n if check[x-1] == 0:\n check[x-1] = 1\n city.append(x-1)\n stack.append(a[x-1])\n else:\n city.append(x-1)\n\nidx = city.index(city[-1])\nif idx == len(city)-1:\n idx = 0\n print(city[(k-idx) % len(city)-1]+1)\nelse:\n for i in range(idx+1):\n city.popleft()\n print((k-idx) % len(city)+1)\n', 'n, k = list(map(int, input().split()))\na = list(map(int, input().split()))\na = [aa-1 for aa in a]\ncheck = [0 for i in range(n)]\n\ncount = 0\npoint = 0\ncheck[0] = 1\npath = [0]\nfor i in range(min(n, k)):\n if i == 0 or check[point] == 0:\n check[point] = i+1\n point = a[point]\n path.append(point)\n else:\n break\n\n\ncycle_len = len(path)-check[point]\npre = check[point]\nif pre > k:\n print(path[k])\nelse:\n k -= pre\n k %= cycle_len\n print(path[pre+k]+1)\n']
['Wrong Answer', 'Accepted']
['s574432560', 's397153421']
[33568.0, 32412.0]
[200.0, 162.0]
[708, 489]
p02684
u701893485
2,000
1,048,576
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
['if __name__=="__main__":\n N, K = map(int, input().split(\' \'))\n _town_list = input().split(\' \')\n town_list = [int(n) for n in _town_list]\n\n next_town = town_list[0]\n visited_town = set()\n visited_town.add(1)\n visited_town.add(next_town)\n lst_visited_town = [1]\n lst_visited_town.append(next_town)\n counter = 1\n\n while True:\n counter += 1\n next_town = town_list[next_town-1]\n if counter == K:\n print(next_town)\n break\n if next_town in visited_town:\n repeated_town_idx = lst_visited_town.index(next_town)\n loop_num = counter - repeated_town_idx\n print(visited_town[(K-repeated_town_idx)%loop_num + repeated_town_idx])\n break\n lst_visited_town.append(next_town)\n visited_town.add(next_town)\n', 'if __name__=="__main__":\n N, K = map(int, input().split(\' \'))\n _town_list = input().split(\' \')\n town_list = [int(n) for n in _town_list]\n\n next_town = town_list[0]\n visited_town = set()\n visited_town.add(1)\n visited_town.add(next_town)\n lst_visited_town = [1]\n lst_visited_town.append(next_town)\n counter = 1\n\n while True:\n counter += 1\n next_town = town_list[next_town-1]\n if counter == K:\n print(next_town)\n break\n if next_town in visited_town:\n repeated_town_idx = lst_visited_town.index(next_town)\n loop_num = counter - repeated_town_idx\n print(visited_town[(K-repeated_town_idx)%loop_num + repeated_town_idx])\n break\n lst_visited_town.append(next_town)\n visited_town.add(next_town)', 'if __name__=="__main__":\n N, K = map(int, input().split(\' \'))\n _town_list = input().split(\' \')\n town_list = [int(n) for n in _town_list]\n\n next_town = town_list[0]\n visited_town = set()\n visited_town.add(1)\n visited_town.add(next_town)\n lst_visited_town = [1]\n lst_visited_town.append(next_town)\n counter = 1\n\n while True:\n counter += 1\n next_town = town_list[next_town-1]\n if counter == K:\n print(next_town)\n break\n if next_town in visited_town:\n repeated_town_idx = lst_visited_town.index(next_town)\n loop_num = counter - repeated_town_idx\n print(lst_visited_town[(K-repeated_town_idx)%loop_num + repeated_town_idx])\n break\n lst_visited_town.append(next_town)\n visited_town.add(next_town)\n\n']
['Runtime Error', 'Runtime Error', 'Accepted']
['s769471424', 's841331483', 's409697381']
[44420.0, 44572.0, 44648.0]
[156.0, 157.0, 155.0]
[828, 827, 833]
p02684
u704284486
2,000
1,048,576
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
['n,k=map(int,input().split())\nA=tuple(map(int,input().split()))\ns=1\nstate=[s]\ncount={}\nfor i in range(k+1):\n s=A[s-1]\n if s in count:\n start=len(state)\n end=i=1\n print(state[start+(k-start)%(end-start)])\n break\n else:\n count[state[i]]=i\n state.append[s]\nelse:\n print(s)\n', 'n,k=map(int,input().split())\nA=tuple(map(int,input().split()))\ns=1\nstate=[s]\ncount={}\nfor i in range(1,k+1):\n s=A[s-1]\n if s in count:\n start=state.index(s)\n end=len(state)\n print(state[start+(k-start)%(end-start)])\n break\n else:\n count[state[i]]=i\n state.append(s)\n continue\nelse:\n print(s)\n', 'n,k=map(int,input().split())\nA=tuple(map(int,input().split()))\ns=1\nstate=[s]\ncount={}\nfor i in range(1,k+1):\n s=A[s-1]\n if s in count:\n start=state.index(s)\n end=len(state)\n print(state[start+(k-start)%(end-start)])\n break\n else:\n count[s]=i\n state.append(s)\n continue\nelse:\n print(s)\n']
['Runtime Error', 'Runtime Error', 'Accepted']
['s027248972', 's454465740', 's444308046']
[32416.0, 32400.0, 32336.0]
[66.0, 70.0, 145.0]
[323, 353, 346]
p02684
u704470185
2,000
1,048,576
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
['N, K = map(int, input().split())\n\narray = input().split()\nfor i in range(len(array)):\n array[i] = int(array[i])\n\nnow = 1\n\nhistory = set()\nstart_number = -1\n\nfor i in range(K):\n history.add(now)\n now = array[now - 1]\n if(now in history):\n start_number = now\n break\n\nif not(start_number == -1):\n start_ind = history.index(start_number)\n length = len(history) - start_ind\n mod = (K - start_ind) % length\n now = history[start_ind + mod]\n\nprint(now)\n', 'N, K = map(int, input().split())\n\narray = input().split()\nfor i in range(len(array)):\n array[i] = int(array[i])\n\nnow = 1\n\nhistory = set()\nstart_number = -1\n\nfor i in range(K):\n history.append(now)\n now = array[now - 1]\n if(now in history):\n start_number = now\n break\n\nif not(start_number == -1):\n start_ind = history.index(start_number)\n length = len(history) - start_ind\n mod = (K - start_ind) % length\n now = history[start_ind + mod]\n\nprint(now)\n', 'N, K = map(int, input().split())\n\narray = input().split()\nfor i in range(len(array)):\n array[i] = int(array[i])\n\nnow = 1\n\nhistory = []\nsethistory = set()\nstart_number = -1\n\nfor i in range(K):\n history.append(now)\n sethistory.add(now)\n now = array[now - 1]\n if(now in sethistory):\n start_number = now\n break\n\nif not(start_number == -1):\n start_ind = history.index(start_number)\n length = len(history) - start_ind\n mod = (K - start_ind) % length\n now = history[start_ind + mod]\n\nprint(now)\n']
['Runtime Error', 'Runtime Error', 'Accepted']
['s693926741', 's902275946', 's505107701']
[36104.0, 25380.0, 36596.0]
[156.0, 86.0, 192.0]
[483, 486, 529]
p02684
u707030679
2,000
1,048,576
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
['n,k=map(int,input().split())\nA = list(map(int,input().split()))\n\nC=[0]*n\nC[0]=1\nc=0\nloopc=0\ni=0\nwhile i<n :\n newi = A[i]-1\n C[newi]+=1\n if C[newi]>=3 :\n rs=newi\n break\n elif C[newi]==2 :\n loopc+=1\n i=newi\n c+=1\n\nmod = (k-(c-loopc))%(loopc+1)\n# print( C, c, loopc, mod)\n\ni=rs\nwhile mod>0 :\n newi = A[i]-1\n i=newi\n mod-=1\n\nprint( i+1 )\n', 'n,k=map(int,input().split())\nA = list(map(int,input().split()))\n\nC=[0]*n\nC[0]=1\nc=0\nloopc=0\ni=0\nwhile i<n :\n newi = A[i]-1\n C[newi]+=1\n if C[newi]>=3 :\n rs=newi\n break\n elif C[newi]==2 :\n loopc+=1\n i=newi\n c+=1\n\nmod = (k-(c+1)%loopc)%(loopc)\nprint( C, c, loopc, mod)\n\ni=rs\nwhile mod>0 :\n newi = A[i]-1\n i=newi\n mod-=1\n\nprint( i+1 )\n', 'n,k=map(int,input().split())\nA = list(map(int,input().split()))\n\nC=[0]*n\nC[0]=1\nc=0\nloopc=0\ni=0\nio=0\nwhile c<k :\n newi = A[i]-1\n C[newi]+=1\n if C[newi]>=3 :\n rs=newi\n break\n elif C[newi]==2 :\n loopc+=1\n io=i\n i=newi\n c+=1\n\nif (k-c)<0 or loopc==0 :\n print(i+1)\n exit()\nmod = (k-c)%(loopc)\n# print( k, c, loopc, i, mod)\n\n\n# i=rs\nwhile mod>0 :\n newi = A[i]-1\n i=newi\n mod-=1\n\nprint( i+1 )\n']
['Wrong Answer', 'Wrong Answer', 'Accepted']
['s034471399', 's667452384', 's305661121']
[32336.0, 32356.0, 32068.0]
[279.0, 306.0, 223.0]
[382, 380, 443]
p02684
u708019102
2,000
1,048,576
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
['N,K = [int(x) for x in input().split()]\nA = [int(x) for x in input().split()]\ndoko = 0\nfor i in range(K):\n if A[doko] <= 0:\n saishou = min(A)\n loop = A[doko] - saishou + 1\n hajimarimade = A[doko]\n K += hajimarimade\n print(A)\n print(A.index(-1*(K % loop)+hajimarimade)+1)\n exit()\n if i == K - 1:\n print(doko+1)\n exit()\n hoji = doko\n doko = A[doko] - 1\n A[hoji] = (-1)*i', 'N,K = [int(x) for x in input().split()]\nA = [int(x) for x in input().split()]\ndoko = 0\nfor i in range(N):\n if A[doko] <= 0:\n saishou = min(A)\n loop = A[doko] - saishou + 1\n hajimarimade = A[doko]\n K += hajimarimade\n print(A.index(-1*(K % loop)+hajimarimade)+1)\n exit()\n if i == K:\n print(doko+1)\n exit()\n hoji = doko\n doko = A[doko] - 1\n A[hoji] = (-1)*i']
['Wrong Answer', 'Accepted']
['s785720834', 's306072054']
[32176.0, 32328.0]
[180.0, 154.0]
[446, 425]
p02684
u724844363
2,000
1,048,576
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
['n, k = map(int, input().split())\na = list(map(int, input().split()))\n\nzyun = [a[0]]\nalr = [False]*n\nalr[0] = True\ncrr = a[0]\n\nkey = True\n\nwhile key:\n if not alr[crr - 1]:\n alr[crr - 1] = True\n crr = a[crr - 1]\n zyun.append(crr)\n continue\n else:\n index1 = crr\n key = False\n\np = zyun[index1]\n\n\nif zyun.index(p) - 1 == 0:\n zyun1 = zyun\n zyun2 = zyun\nelse:\n zyun1 = zyun[:zyun.index(p)]\n zyun2 = zyun[zyun.index(p):]\n\nprint(zyun1, zyun2)\n\nif len(zyun1) >= k:\n ind = len(zyun1) % k\n if ind == 0:\n print(zyun1[-1])\n else:\n print(zyun1[ind - 1])\nelse:\n ind = (k - len(zyun1)) % len(zyun2)\n if ind == 0:\n print(zyun2[-1])\n else:\n print(zyun2[ind - 1])', 'n, k = map(int, input().split())\na = [int(n) - 1 for n in input().split()] \nv = [-1] * n \n\nD = [0] \nv[0] = 0 \n\ncur = a[0] \ni = 1\n\nwhile v[cur] == -1:\n D.append(cur)\n v[cur] = i \n if k == i: \n print(cur + 1)\n exit()\n\n i += 1\n cur = a[cur]\n\n\nk -= v[cur] \nk %= (i - v[cur]) \n\nprint(D[v[cur] + k] + 1) ']
['Runtime Error', 'Accepted']
['s971727311', 's067762798']
[32180.0, 33424.0]
[181.0, 158.0]
[780, 938]
p02684
u726285999
2,000
1,048,576
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
['N, K = map(int, input().split())\nA = [int(x) - 1 for x in input().split()]\n\n\nloop = 0\ncity = 0\nb = set([0])\nwhile True:\n loop += 1\n if A[city] in b:\n break\n else:\n city = A[city]\n b.add(city)\n\nloop_start = A[city]\n\n\npre = 0\ncity = 0\nwhile True:\n pre += 1\n if A[city] == loop_start:\n break\n else:\n city = A[city]\n\nif loop > pre:\n loop -= pre\n\nif K < c: \n city = 0\n for i in range(K):\n city = A[city]\n print(city + 1)\n \nelse: \n K -= pre\n last = K % loop\n city = loop_start\n \n for i in range(last):\n city = A[city]\n print(city + 1)', 'N, K = map(int, input().split())\nA = [int(x) - 1 for x in input().split()]\n\n\nloop = 0\ncity = 0\nb = set([0])\nwhile True:\n loop += 1\n if A[city] in b:\n break\n else:\n city = A[city]\n b.add(city)\n\nloop_start = A[city]\n\n\npre = 0\ncity = 0\nwhile True:\n pre += 1\n if A[city] == loop_start:\n break\n else:\n city = A[city]\n\nif loop > pre:\n loop -= pre\n\nif K < pre: \n city = 0\n for i in range(K):\n city = A[city]\n print(city + 1)\n \nelse: \n K -= pre\n last = K % loop\n city = loop_start\n \n for i in range(last):\n city = A[city]\n print(city + 1)']
['Runtime Error', 'Accepted']
['s692746372', 's499346927']
[32556.0, 32576.0]
[213.0, 275.0]
[779, 781]
p02684
u728473456
2,000
1,048,576
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
['n,k = map(int,input().split())\na = list(map(int,input().split()))\npos = 0\nvisit = [0] * n\nmove = []\nloop = []\nwhile visit[pos] != 2:\n if visit[pos] == 0:\n move.append(pos)\n else:\n loop.append(pos)\n visit[pos] += 1\n pos = a[pos] - 1\nif len(move[k]) > k:\n print(move[k]+1)\nelse:\n print(loop[(k-(len(move)-len(loop)))%len(loop)]+1)\n', 'n,k = map(int,input().split())\na = list(map(int,input().split()))\npos = 0\nvisit = [0] * n\nmove = []\nloop = []\nwhile visit[pos] != 2:\n if visit[pos] == 0:\n move.append(pos)\n else:\n loop.append(pos)\n visit[pos] += 1\n pos = A[pos] - 1\nif len(move[k]) > k:\n print(move[k]+1)\nelse:\n print(loop[(k-(len(move)-len(loop)))%len(loop)]+1)', 'from collections import deque\nimport numpy as np\nn,k = map(int,input().split())\na = list(map(int,input().split()))\nroop_find = deque([0])\ni = 0\ncount = 0 \nfor i in range(n):\n if a[i]-1 in roop_find:\n break\n else:\n roop_find.append(a[i]-1)\n i = a[i] - 1\n count += 1\nb = roop_find.index(a[i]-1)\n\nif k < b:\n print(list(roop_find)[k]+1)\nelse:\n k-=b\n e = k % (count+1-b)\n print(list(roop_find)[b+e]+1)\n', 'from collections import deque\nimport numpy as np\nn,k = map(int,input().split())\na = list(map(int,input().split()))\nroop_find = deque([0])\ni = 0\ncount = 0\nwhile a[i]-1 not in roop_find:\n roop_find.append(a[i]-1)\n i = a[i] - 1\n count += 1\n if count == k:\n print(i + 1)\n break\n else:\n pass\nif b < k:\n b = roop_find.index(a[i]-1)\n roop = list(roop_find)[b:count+1]\n\n k -= b\n e = k % (count+1-b)\n print(roop[e]+1)\n', 'n,k = map(int,input().split())\na = list(map(int,input().split()))\npos = 0\nvisit = [0] * n\nmove = []\nloop = []\nwhile visit[pos] != 2:\n if visit[pos] == 0:\n move.append(pos)\n else:\n loop.append(pos)\n visit[pos] += 1\n pos = a[pos] - 1\nif len(move) > k:\n print(move[k]+1)\nelse:\n print(loop[(k-(len(move)-len(loop)))%len(loop)]+1)\n']
['Runtime Error', 'Runtime Error', 'Wrong Answer', 'Runtime Error', 'Accepted']
['s380764313', 's437365296', 's604706229', 's907201022', 's805041491']
[32928.0, 32224.0, 50976.0, 51036.0, 32864.0]
[239.0, 68.0, 230.0, 2207.0, 231.0]
[361, 360, 443, 460, 358]
p02684
u728566015
2,000
1,048,576
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
['import sys\nimport numpy as np\nN, K = map(int, input().split())\nA = np.array(list(map(int, input().split())))\nA = np.insert(A, 0, 0)\n\nflg = [False for _ in range(N + 1)]\ntown = []\ni = 1\ncnt = 0\nfor i in range(N):\n town.append(i)\n flg[i] = True\n i = A[i]\n\nif len(town) >= K:\n print(town[K])\nelse:\n s = i\n to_s = town.index(s)\n loop = len(town) - to_s\n print(town[(K - to_s) % loop + to_s])', 'import sys\nimport numpy as np\nN, K = map(int, input().split())\nA = np.array(list(map(int, input().split())))\nA = np.insert(A, 0, 0)\n\nflg = [False for _ in range(N + 1)]\ntown = []\ni = 1\ncnt = 0\nfor _ in range(N):\n town.append(i)\n flg[i] = True\n i = A[i]\n\nif len(town) >= K:\n print(town[K])\nelse:\n s = i\n to_s = town.index(s)\n loop = len(town) - to_s\n print(town[(K - to_s) % loop + to_s])']
['Runtime Error', 'Accepted']
['s701260027', 's715413960']
[51024.0, 51072.0]
[255.0, 248.0]
[411, 411]
p02684
u729133443
2,000
1,048,576
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
['n,k,*a=map(int,open(0).read().split())\nd=[2*k]*n\ns=0\nwhile k:k-=1;k%=d[s:=a[s]-1]-k;d[s]=k\nprint(s)', 'n,k,*a=map(int,open(0).read().split())\nd=[2*k]*n\nwhile k:n=1-a[-n];d[n]=k=~-k%(d[n]+1-k)\nprint(1-n)']
['Runtime Error', 'Accepted']
['s815474361', 's637653595']
[9028.0, 31816.0]
[22.0, 168.0]
[99, 99]
p02684
u732061897
2,000
1,048,576
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
['N, K = map(int, input().split())\nroutes = list(map(int, input().split()))\n\notozureta = set([1])\notozureta_list = [1]\n\n\ndef search(list, next):\n if not otozureta.isdisjoint(set([next])):\n return next\n else:\n otozureta.add(next)\n otozureta_list.append(next)\n return search(list, routes[next - 1])\n\n\ntarget = search(routes, routes[0])\ntarget_index = otozureta_list.index(target)\n\notozureta_list_len = len(otozureta_list)\nloop_length = otozureta_list_len - target_index\nloop_made_length = target_index\nprint(otozureta)\n\nif K < otozureta_list_len:\n print(otozureta_list[K])\nelse:\n\n print(otozureta_list[loop_made_length + (K % loop_length) - 1])\n', 'N, K = map(int, input().split())\nroutes = list(map(int, input().split()))\n\notozureta = set([1])\notozureta_list = [1]\n\nimport sys\nsys.setrecursionlimit(1000000)\n\ndef search(list, next):\n if not otozureta.isdisjoint(set([next])):\n return next\n else:\n otozureta.add(next)\n otozureta_list.append(next)\n return search(list, routes[next - 1])\n\n\ntarget = search(routes, routes[0])\ntarget_index = otozureta_list.index(target)\n\notozureta_list_len = len(otozureta_list)\nloop_length = otozureta_list_len - target_index\nloop_made_length = target_index\n\n\nif K < otozureta_list_len:\n print(otozureta_list[K])\nelse:\n\n print(otozureta_list[loop_made_length + ((K - loop_made_length) % loop_length)])\n']
['Runtime Error', 'Accepted']
['s432959840', 's598483579']
[32300.0, 182572.0]
[72.0, 358.0]
[681, 741]
p02684
u733581231
2,000
1,048,576
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
["from collections import defaultdict\nimport sys\nsys.setrecursionlimit(10**6)\nn , k = map(int , input().split())\narr = list(map(int , input().split()))\ndic = defaultdict(int)\nfor i in range(1,n+1):\n\tdic[i] = arr[i-1]\ncycle = []\nvisited = [False]*(10**6)\ncurr = 1\nif k <= n:\n\tcurr = 1\n\tcount = 0\n\twhile count != k:\n\t\tcurr = dic[count]\n\t\tcount+=1\n\texit(print(curr))\nwhile True:\n\tcycle.append(curr)\n\tvisited[curr] = True\n\tcurr = dic[curr]\n\t#k -= 1\n\tif visited[curr]:\n\t\tbreak\n\ncsize = 0\nind = 0\nfor i in range(len(cycle)-1,-1,-1):\n\tif cycle[i] == curr:\n\t\tind = i + 1\n\t\tbreak\n\tcsize += 1\n'''\noffset = len(cycle) - csize - 1\n#print(cycle,csize+1, k , curr,offset)\nk -= offset\nk %= csize + 1\nprint(cycle[offset + k])\n'''\nprint(cycle[ind + ((k-ind)%csize)])\n", 'from collections import defaultdict\nimport sys\nsys.setrecursionlimit(10**6)\nn , k = map(int , input().split())\narr = list(map(int , input().split()))\ndic = defaultdict(int)\nfor i in range(1,n+1):\n\tdic[i] = arr[i-1]\ncycle = []\ndef dfs(node):\n\tif node in cycle:\n\t\treturn node\n\telse:\n\t\tcycle.append(node)\n\t\tk = dfs(dic[node])\n\treturn k\ncyele = dfs(1)\nind = 0\noffset = 0\nfor i in range(len(cycle)):\n\tif cycle[i] == cyele:\n\t\tind = i\n\t\tbreak\n\toffset+=1\n#rem = k - offset\ncsize = len(cycle[ind:])\nrem=rem%csize\n\ncount = 0\ncurr = 1\nwhile count != rem:\n\tcurr = dic[curr]\n\tcount+=1\nprint(curr)\n', "from collections import defaultdict\nimport sys\nsys.setrecursionlimit(10**6)\nn , k = map(int , input().split())\narr = list(map(int , input().split()))\ndic = defaultdict(int)\nfor i in range(1,n+1):\n\tdic[i] = arr[i-1]\ncycle = []\nvisited = [False]*(10**6)\ncurr = 1\nif k <= n:\n\tcurr = 1\n\tcount = 0\n\twhile count != k:\n\t\tcurr = dic[count]\n\t\tcount+=1\n\texit(print(curr))\nwhile True:\n\tcycle.append(curr)\n\tvisited[curr] = True\n\tcurr = dic[curr]\n\t#k -= 1\n\tif visited[curr]:\n\t\tbreak\n\ncsize = 0\nfor i in range(len(cycle)-1,-1,-1):\n\tif cycle[i] == curr:\n\t\tbreak\n\tcsize += 1\n'''\noffset = len(cycle) - csize - 1\n#print(cycle,csize+1, k , curr,offset)\nk -= offset\nk %= csize + 1\nprint(cycle[offset + k])\n'''\nk%=csize+1\ncount = 0\ncurr = 1\ncount = 0\nwhile count != k:\n\tcurr = dic[count]\n\tcount+=1\nexit(print(curr))\n", 'from collections import defaultdict\nimport sys\nsys.setrecursionlimit(10**6)\nn , k = map(int , input().split())\narr = list(map(int , input().split()))\ndic = defaultdict(int)\nfor i in range(1,n+1):\n\tdic[i] = arr[i-1]\ncycle = []\nvisited = [False]*(10**6)\ncurr = 1\nwhile True:\n\tcycle.append(curr)\n\tvisited[curr] = True\n\tcurr = dic[curr]\n\t#k -= 1\n\tif visited[curr]:\n\t\tbreak\n\ncsize = 0\nind = 0\nfor i in range(len(cycle)-1,-1,-1):\n\tif cycle[i] == curr:\n\t\tind = i + 1\n\t\tbreak\n\tcsize += 1\noffset = len(cycle) - csize - 1\n#print(cycle,csize+1, k , curr,offset)\nif k - offset < 0:\n\texit(print(cycle[k]))\nk -= offset\nk %= csize + 1\nprint(cycle[offset + k])\n']
['Runtime Error', 'Runtime Error', 'Wrong Answer', 'Accepted']
['s168722722', 's568374566', 's950757199', 's484930875']
[43832.0, 47300.0, 43820.0, 44088.0]
[200.0, 2207.0, 209.0, 227.0]
[748, 584, 795, 645]
p02684
u736470924
2,000
1,048,576
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
['def resolve():\n n, k = map(int, input().split())\n A = list(map(int, input().split()))\n path = {}\n c = 1\n i = 1\n while c < k:\n if not i in path.keys():\n path[i] = c\n i = A[i - 1]\n c += 1\n elif i in path.keys():\n start = path[i]\n roop = c - path[i]\n break\n roop += start - 1\n idx = 1\n for r in range(roop):\n idx = A[idx - 1]\n print(idx)\n\nresolve()', 'def resolve():\n n, k = map(int, input().split())\n A = list(map(int, input().split()))\n s = []\n ord = [-1 for i in range(n + 1)]\n rep = 1\n pos = 1\n while ord[pos] == -1:\n ord[pos] = len(s)\n s.append(pos)\n pos = A[pos - 1]\n rep += 1\n\n rep = len(s) - ord[pos]\n \n l = ord[pos]\n if k < l:\n print(s[k])\n else:\n \n k -= l\n k %= rep\n print(s[l + k])\nresolve()']
['Runtime Error', 'Accepted']
['s423721545', 's240698722']
[32376.0, 32240.0]
[173.0, 139.0]
[462, 516]
p02684
u737135713
2,000
1,048,576
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
['z = 0\n\nb = [1]\nfor i in range(1000000):\n j = [a[b[i]-1]]\n b.extend(j)\n\nfor i in range(n):\n if b.count(i+1)>=3:\n z = z + 1\n\nif k <= n:\n y = b[k]\nelse:\n l = (k-n)%z\n y = b[n+l]\nprint(y)', 'a = list(map(int,input().split()))\nz = 0\nb = [1]\nc = [0]*n\nfor i in range(n*3):\n j = [a[b[i]-1]]\n b.extend(j)\n c[a[b[i]-1]-1] = c[a[b[i]-1]-1]+1\n if c[a[b[i]-1]-1] == 2:\n z = z + 1\n\nif k <= n:\n y = b[k]\nelse:\n l = (k-n)%z\n y = b[n+l]\nprint(y)', 'n,k = map(int,input().split())\na = list(map(int,input().split()))\nz = 0\nb = [1]\nc = [0]*n\nfor i in range(n*3):\n j = [a[b[i]-1]]\n b.extend(j)\n c[a[b[i]-1]-1] = c[a[b[i]-1]-1]+1\n if c[a[b[i]-1]-1] == 2:\n z = z + 1\nif k <= n:\n y = b[k]\nelse:\n l = (k-n)%z\n y = b[n+l]\nprint(y)']
['Runtime Error', 'Runtime Error', 'Accepted']
['s353780002', 's502481193', 's739734465']
[9124.0, 9224.0, 32300.0]
[25.0, 24.0, 606.0]
[192, 252, 282]
p02684
u745687363
2,000
1,048,576
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
['n, k = map(int, input().split())\nA=list(map(int, input().split()))\nL=[1]\ndef f(L):\n L.append(A[l[-1]]) if A[l[-1]] in L\nf(L)\nprint(L[k//len(L)])\n ', 'n, k = map(int, input().split())\nA = list(map(int, input().split()))\nL = [1]\ndef f(L):\n if A[L[-1]-1] not in L:\n L.append(A[L[-1]-1])\n return f(L)\n else:\n return L\nP = f(L)\na = A[P[-1]-1]\nj = P.index(a)\nr = len(P)\nl = r - j\nprint(P)\nif k+1 <= j:\n print(P[k])\nelse:\n print(P[j+(k-j)%l])', 'n, k = map(int, input().split())\nA = list(map(int, input().split()))\nL = [1]\ndef f(L):\n if A[L[-1]-1] not in L:\n L.append(A[L[-1]-1])\n return f(L)\n else:\n return L\nP = f(L)\na = A[P[-1]-1]\nj = P.index(a)\nr = len(P)\nl = r - j\nprint(P)\nif k < j:\n print(P[k])\nelse:\n print(P[j+(k-j)%l])', 'n, k = map(int, input().split())\nA = list(map(int, input().split()))\nL = [1]\nS = {1}\n\nwhile A[L[-1]-1] not in S:\n last = L[-1]-1\n L.append(A[last])\n S |= {A[last]}\n\na = A[L[-1]-1]\nj = L.index(a)\nr = len(L)\nl = r - j\n\nif k+1 <= j:\n print(L[k])\nelse:\n print(L[j+(k-j)%l])\n']
['Runtime Error', 'Runtime Error', 'Runtime Error', 'Accepted']
['s842868514', 's959910501', 's986118918', 's195650994']
[8920.0, 32380.0, 32360.0, 33380.0]
[24.0, 79.0, 79.0, 204.0]
[148, 318, 315, 279]
p02684
u748241164
2,000
1,048,576
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
['\nN, K = map(int, input().split())\nA = list(map(int, input().split()))\n\ncheck = [0] * N\ntime = [-1] * N\ncheck[0] = 1\ntime[0] = 0\nnow = 1\nt = 1\nex = 0\nroop = 0\nfor i in range(N + 1):\n now = A[now - 1]\n if check[now - 1] == 0:\n check[now - 1] = 1\n time[now - 1] = t\n else:\n ex = time[now - 1]\n roop = t - time[now - 1]\n break\n t += 1\n \nif K < t:\n ans = time.index(K) + 1\n print(ans)\nelse:\n K -= (t - 1)\n K %= roop\n \n ans = time.index(ex + K - 1) + 1\n print(ans)\n#print(check, time, roop, t, ex) \n\n', '\nN, K = map(int, input().split())\nA = list(map(int, input().split()))\n\ncheck = [0] * N\ntime = [-1] * N\ncheck[0] = 1\ntime[0] = 0\nnow = 1\nt = 1\nex = 0\nroop = 0\nfor i in range(N + 1):\n now = A[now - 1]\n if check[now - 1] == 0:\n check[now - 1] = 1\n time[now - 1] = t\n else:\n ex = time[now - 1]\n roop = t - time[now - 1]\n break\n t += 1\n \nif K < t:\n ans = time.index(K) + 1\n print(ans)\nelse:\n K -= (t - 1)\n K %= roop\n if K == 0:\n K = roop\n \n ans = time.index(ex + K - 1) + 1\n print(ans)\n #print(check, time, roop, t, ex) \n\n']
['Wrong Answer', 'Accepted']
['s265969035', 's251192089']
[32304.0, 32224.0]
[197.0, 199.0]
[539, 567]
p02684
u750651325
2,000
1,048,576
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
['import re\nimport sys\nimport math\nimport itertools\nimport bisect\nfrom copy import copy\nfrom collections import deque,Counter\nfrom decimal import Decimal\nimport functools\ndef v(): return input()\ndef k(): return int(input())\ndef S(): return input().split()\ndef I(): return map(int,input().split())\ndef X(): return list(input())\ndef L(): return list(input().split())\ndef l(): return list(map(int,input().split()))\ndef lcm(a,b): return a*b//math.gcd(a,b)\nsys.setrecursionlimit(10 ** 9)\nmod = 10**9+7\ncnt = 0\nans = 0\ninf = float("inf")\n\nn,k=I()\na = l()\ntown = []\nnum = [0]*(n+1)\ncnt = 1\nnum[0]=1\n\nfor i in range(n):\n num[a[cnt-1]] += 1\n if num[a[cnt-1]] == 2:\n ans = a[cnt-1]\n break\n town.append(a[cnt-1])\n cnt = a[cnt-1]\n\np = town.index(ans)\nb = town[p-1:]\nx = len(town)\ny = len(b)\nq = k-x+y\nif y == 0:\n print(town[n-1])\n sys.exit()\nif q < 0:\n print(town[k-1])\n sys.exit()\nz = q%y\nif z == 0:\n print(town[k-1])\nelse:\n print(b[z-1])\n', 'import re\nimport sys\nimport math\nimport itertools\nimport bisect\nfrom copy import copy\nfrom collections import deque,Counter\nfrom decimal import Decimal\nimport functools\ndef v(): return input()\ndef k(): return int(input())\ndef S(): return input().split()\ndef I(): return map(int,input().split())\ndef X(): return list(input())\ndef L(): return list(input().split())\ndef l(): return list(map(int,input().split()))\ndef lcm(a,b): return a*b//math.gcd(a,b)\nsys.setrecursionlimit(10 ** 9)\nmod = 10**9+7\ncnt = 0\nans = 0\ninf = float("inf")\n\nn,k=I()\na = l()\ntown = []\nnum = [0]*(n+1)\ncnt = 1\nnum[0]=1\n\nfor i in range(n):\n num[a[cnt-1]] += 1\n if num[a[cnt-1]] == 2:\n ans = a[cnt-1]\n p = town.index(ans)\n b = town[p:]\n x = len(town)\n y = len(b)\n q = k-x+y\n if y == 0:\n print(town[n-1])\n sys.exit()\n if q < 0:\n print(town[k-1])\n sys.exit()\n z = q%y\n print(b[z-1])\n sys.exit()\n break\n town.append(a[cnt-1])\n cnt = a[cnt-1]\n']
['Runtime Error', 'Accepted']
['s753095430', 's694747923']
[34304.0, 34320.0]
[189.0, 189.0]
[970, 1048]
p02684
u751717561
2,000
1,048,576
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
['n, k = map(int, input().split())\na = list(map(int, input().split())) \n\nll = [a[0]]\n\nfor i in range(1, n):\n cnt = ll[i-1]\n if cnt = a[cnt-1]:\n print(cnt)\n exit()\n if a[cnt-1] == a[0]:\n break\n else:\n ll.append(a[cnt-1])\n\nprint(ll[k%3-1])\n', 'N, K = map(int, input().split())\nA = list(map(lambda x: int(x) - 1, input().split()))\n\ndone = [-1]*N\ndone[0] = 0\n\ntmp = 0\ndone[0] = 0\nfor k in range(1, K + 1):\n tmp = A[tmp]\n if done[tmp] >= 0:\n for _ in range((K - done[tmp]) % (k - done[tmp])):\n tmp = A[tmp]\n print(tmp + 1)\n exit()\n else:\n done[tmp] = k\nprint(tmp + 1)']
['Runtime Error', 'Accepted']
['s165127720', 's036816312']
[9020.0, 32368.0]
[26.0, 136.0]
[276, 368]
p02684
u751843916
2,000
1,048,576
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
['n,k=map(int,input().split())\na=list(map(int,input().split()))\na=[p-1 for p in a]\nl=[0]\ni=a[0]\np=-1\nq=-1\nfor x in range(n):\n if i in set(l):break\n l.append(i)\n i=a[i]\nd=-1\nfor x in range(n):\n if a[x]==i:\n d=x\n break\nf=l[:d]\nb=l[d:]\nprint(l,f,b,d)\nif len(f)==0 or len(b)==0:\n print(l[k%(n-1)]+1)\n exit()\n\nif k<=d:\n print(l[k]+1)\n exit()\n\nk-=len(f)\nprint(b[k%len(b)]+1)', 'n,k=map(int,input().split())\na=list(map(int,input().split()))\nvisited=[False]*(n+1)\nvisited[1]=True\nl=[1]\ni=a[0]\n\nfor x in range(n):\n if visited[i]:break\n visited[i]=True\n l.append(i)\n i=a[i-1]\n\nd=-1\nfor x in range(n):\n if l[x]==i:\n d=x\n break\n\nf=l[:d]\nb=l[d:]\n\nif len(f)==0:\n print(b[k%len(b)])\n exit()\n \nif len(b)==0:\n print(f[k%len(f)])\n exit()\n\nif k<=d:\n print(l[k])\n exit()\n \nk-=len(f)\nprint(b[k%len(b)])']
['Runtime Error', 'Accepted']
['s965250907', 's836117733']
[32308.0, 32332.0]
[2206.0, 153.0]
[404, 456]
p02684
u756420279
2,000
1,048,576
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
['#!/usr/bin/env python3\n\nn, k = map(int, input().split())\nA = list(map(int, input().split()))\na = [0]*n\nb = A[0]\nper = []\ntes = -1\n\nif n >= k:\n for _ in range(k-1):\n b = A[b-1]\n print(b)\n exit()\n\n\nfor _ in range(k*2):\n #print(b)\n a[b-1] += 1\n tes += 1\n if 3 in a:\n tes -= len(per)*2\n break\n if 2 in a:\n per.append(b)\n b = A[b-1]\n\n_len = len(per)\nprint(_len, tes)\n\nans = (k - tes) % _len\n\nprint(per[ans-1])', '#!/usr/bin/env python3\n\nn, k = map(int, input().split())\nA = list(map(int, input().split()))\na = [0]*n\nb = A[0]\nper = []\ntes = -1\n\nif n >= k:\n for _ in range(k-1):\n b = A[b-1]\n print(b)\n exit()\n\nfor _ in range(k+1):\n a[b-1] += 1\n tes += 1\n if 3 in a:\n tes -= len(per)*2\n break\n if 2 in a:\n per.append(b)\n b = A[b-1]\n\n_len = len(per)\n\nans = (k - tes) % _len\n\nprint(per[ans-1])', '#!/usr/bin/env python3\n\nN, K = map(int, input().split())\nA = [int(a) - 1 for a in input().split()]\n\nif K <= N:\n p = 0\n for _ in range(K):\n p = A[p]\n print(p + 1)\n exit()\n\np = 0\nt = [-1] * N\nt[0] = 0\nfor i in range(1, N):\n p = A[p]\n if t[p] != -1:\n break\n t[p] = i\n\nd = i - t[p]\nK -= i\nK %= d\n\nfor i in range(K):\n p = A[p]\nprint(p + 1)']
['Wrong Answer', 'Wrong Answer', 'Accepted']
['s591980015', 's934517134', 's299273163']
[32300.0, 32328.0, 32256.0]
[2206.0, 2206.0, 148.0]
[459, 427, 372]
p02684
u756607246
2,000
1,048,576
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
["\n\ndef main():\n N, K = map(int, input().split())\n As = list(map(int, input().split()))\n As = [0]+As\n ikisaki = As[1]\n aru = {1}\n itta = [1]\n imaitta = 1\n \n while not ikisaki in aru:\n imaitta = ikisaki\n ikisaki = As[ikisaki]\n itta.append(imaitta)\n aru.add(imaitta)\n ind = itta.index(ikisaki)\n kurikaesi = itta[ind:]\n itidokiri = itta[:ind]\n ans = itidokiri[K-1] if len(itidokiri) <= K else kurikaesi[(K-len(itidokiri))%len(kurikaesi)]\n\n\n return itta, itidokiri, kurikaesi, ans\n\nif __name__ == '__main__':\n #start = time.time()\n print(main())\n #elapsed_time = time.time() - start\n ", "\n\ndef main():\n N, K = map(int, input().split())\n As = list(map(int, input().split()))\n As = [0]+As\n ikisaki = As[1]\n aru = {1}\n itta = [1]\n imaitta = 1\n \n while not ikisaki in aru:\n imaitta = ikisaki\n ikisaki = As[ikisaki]\n itta.append(imaitta)\n aru.add(imaitta)\n ind = itta.index(ikisaki)\n kurikaesi = itta[ind:]\n itidokiri = itta[:ind]\n ans = itidokiri[K] if len(itidokiri) > K else kurikaesi[(K-len(itidokiri))%len(kurikaesi)]\n\n\n return ans\n\nif __name__ == '__main__':\n #start = time.time()\n print(main())\n #elapsed_time = time.time() - start\n "]
['Runtime Error', 'Accepted']
['s822185241', 's143296127']
[32232.0, 32348.0]
[176.0, 133.0]
[734, 703]
p02684
u760569096
2,000
1,048,576
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
['n, k = map(int, input().split())\na = list(map(int, input().split())) \nb = 0\nc = [0]\nif n < k:\n k = n\nfor i in range(k+2):\n b = a[b]-1\n if b in c:\n d = c.index(b)\n e = i-d+1\n k = k - len(c)+e\n c = c[-e:]\n print(c[k%e]+1)\n exit(0)\n else:\n c.append(b)\nprint(b+1)', 'NK = list(map(int, input().split())) \nA = list(map(int, input().split())) \ne = 0\nN = NK[0]\nK = NK[1]\ntown= 1\nlist = []\nfor i in range(N+1):\n town = A[town-1]\n list.append(town)\n if i > 0 and town == list[0]:\n e += 1\n break\nif e == 1:\n print(list[-1])\nelse:\n d = K % len(list[:-1])\n print(list1[d-1])', 'n, k = map(int, input().split())\na = list(map(int, input().split())) \nb = 0\nc = []\nfor i in range(k):\n b = a[b]-1\n if b in c:\n e = []\n e.append(b)\n d = c.index(b)\n for j in range(i-d-1):\n b = a[b]-1\n e.append(b)\n if c[-i+d:] == e:\n n = len(c[:-i+d])\n k = k-n\n print(e)\n print(e[k%len(e)-1]+1)\n exit(0) \n else:\n c.append(b)\nprint(b+1)\n', 'NK = list(map(int, input().split())) \nA = list(map(int, input().split())) \ne = 0\nN = NK[0]\nK = NK[1]\ntown= 1\nlist = []\nfor i in range(N+1):\n town = A[town-1]\n list.append(town)\n if i > 0 and town == list[0]:\n e += 1\n break\nif e == 1:\n print(list[-1])\nelse:\n list1 = list[:-1]\n d = K % len(list1)\n print(list1[d-1])', 'n, k = map(int, input().split())\na = list(map(int, input().split())) \nb = 0\nif k<=n:\n for i in range(k):\n b = a[b]-1\n print(b+1)\n exit(0)\nc = [0]\nfor i in range(n):\n b = a[b]-1\n c.append(b)\nd = c[:-1].index(c[-1])\nc = c[d:-1]\nk = k-d\nprint(c[k%len(c)]+1)\n\n']
['Wrong Answer', 'Runtime Error', 'Wrong Answer', 'Wrong Answer', 'Accepted']
['s128670270', 's811480229', 's844610353', 's909104402', 's356134661']
[32312.0, 32364.0, 32252.0, 32372.0, 32344.0]
[2206.0, 155.0, 2206.0, 133.0, 133.0]
[284, 311, 390, 327, 264]
p02684
u764501786
2,000
1,048,576
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
["# 4 5 (4 cities and 5 steps)\n# 3 2 4 1\n\n# 1 => 3\n# 2 => 2\n# 3 => 4\n# 4 => 1\n\nN, K = map(int, input().split())\nA_i = list(map(int, input().split()))\n\npaths = {}\n\nfor i in range(N):\n paths[i+1] = A_i[i]\n\n# print('paths:', paths)\n\n# 6 5 2 5 3 2\n\n# 1 => 6 (1)\n# 6 => 2 (2)\n# 2 => 5 (3)\n# 5 => 3 (4)\n# 3 => 2 (5)\n\nstate = 1\nsteps = 0\nflag = False\nknown_states = {}\n\nwhile steps < K:\n known_states[state] = steps # state => 2, steps => 2\n\n state = paths[state] # state => 5\n steps += 1 # steps => 3\n\n # print(f'steps: {steps}, state: {state}')\n\n if state in known_states and not flag: # state => 2 steps => 5\n loop_steps = (steps - known_states[state] - 1)\n steps = K - ((K - steps) % loop_steps)\n flag = True\n \n\n\nprint(state)\n", "# 4 5 (4 cities and 5 steps)\n# 3 2 4 1\n\n# 1 => 3\n# 2 => 2\n# 3 => 4\n# 4 => 1\n\nN, K = map(int, input().split())\nA_i = list(map(int, input().split()))\n\npaths = {}\n\nfor i in range(N):\n paths[i+1] = A_i[i]\n\n# print('paths:', paths)\n\n# 6 5 2 5 3 2\n\n# 1 => 6 (1)\n# 6 => 2 (2)\n# 2 => 5 (3)\n# 5 => 3 (4)\n# 3 => 2 (5)\n\n# loop_steps = 5 - 2 - 1 = 2\n# 5 + 2 * m + r = 727202214173249351\n# steps + loop_steps * m + r = K\n\n\nstate = 1\nsteps = 0\nflag = False\nknown_states = {}\n\nwhile steps < K:\n known_states[state] = steps # state => 2, steps => 2\n\n state = paths[state] # state => 5\n steps += 1 # steps => 3\n\n # print(f'steps: {steps}, state: {state}')\n\n if state in known_states and not flag: # state => 2 steps => 5\n loop_steps = steps - known_states[state] - 1\n if not loop_steps:\n continue\n steps = K - ((K - steps) % loop_steps)\n # print('steps:', steps)\n flag = True\n \n\n\nprint(state)\n", "# 4 5 (4 cities and 5 steps)\n# 3 2 4 1\n\n# 1 => 3\n# 2 => 2\n# 3 => 4\n# 4 => 1\n\nN, K = map(int, input().split())\nA_i = list(map(int, input().split()))\n\npaths = {}\n\nfor i in range(N):\n paths[i+1] = A_i[i]\n\n# print('paths:', paths)\n\n# 6 5 2 5 3 2\n\n# 1 => 6 (1)\n# 6 => 2 (2)\n# 2 => 5 (3)\n# 5 => 3 (4)\n# 3 => 2 (5)\n\n# loop_steps = 5 - 2 - 1 = 2\n# 5 + 2 * m + r = 727202214173249351\n# steps + loop_steps * m + r = K\n\n\nstate = 1\nsteps = 0\nflag = False\nknown_states = {}\n\nwhile steps < K:\n known_states[state] = steps # state => 2, steps => 2\n\n state = paths[state] # state => 5\n steps += 1 # steps => 3\n\n # print(f'steps: {steps}, state: {state}')\n\n if state in known_states and not flag: # state => 2 steps => 5\n loop_steps = steps - known_states[state] - 1\n steps = K - ((K - steps) % loop_steps)\n print('steps:', steps)\n flag = True\n \n\n\nprint(state)\n", "# 4 5 (4 cities and 5 steps)\n# 3 2 4 1\n\n# 1 => 3\n# 2 => 2\n# 3 => 4\n# 4 => 1\n\n# 1 (0)\n# 1 => 3 (1)\n# 3 => 4 (2)\n# 4 => 1 (3)\n\n\n# 2 = (5 - 3) % 2 + 3 - 1\n\nN, K = map(int, input().split())\nA_i = list(map(int, input().split()))\n\npaths = {}\n\nfor i in range(N):\n paths[i+1] = A_i[i]\n\n# print('paths:', paths)\n\n# 6 5 2 5 3 2\n\n# 1 => 6 (1)\n# 6 => 2 (2)\n# 2 => 5 (3)\n# 5 => 3 (4)\n# 3 => 2 (5)\n\n# loop_steps = 5 - 2 - 1 = 2\n# 5 + 2 * m + r = 727202214173249351\n# steps + loop_steps * m + r = K\n\n\nstate = 1\nsteps = 0\nflag = False\nknown_states = {}\n\nwhile steps < K:\n known_states[state] = steps # state => 2, steps => 2\n\n state = paths[state] # state => 5\n steps += 1 # steps => 3\n\n # print(f'steps: {steps}, state: {state}')\n\n if state in known_states and not flag: # state => 2 steps => 5\n loop_steps = steps - known_states[state]\n K = (steps - loop_steps) + (K - (steps - loop_steps)) % loop_steps\n print('loop_steps:', loop_steps)\n print('steps - loop_steps:', steps - loop_steps)\n print('K:', K)\n state = 1\n steps = 0\n # print('steps:', steps)\n flag = True\n \n\n\n\nprint(state)\n", "# 4 5 (4 cities and 5 steps)\n# 3 2 4 1\n\n# 1 => 3\n# 2 => 2\n# 3 => 4\n# 4 => 1\n\n# 1 (0)\n# 1 => 3 (1)\n# 3 => 4 (2)\n# 4 => 1 (3)\n\n\n# 2 = (5 - 3) % 2 + 3 - 1\n\nN, K = map(int, input().split())\nA_i = list(map(int, input().split()))\n\npaths = {}\n\nfor i in range(N):\n paths[i+1] = A_i[i]\n\n# print('paths:', paths)\n\n# 6 5 2 5 3 2\n\n# 1 => 6 (1)\n# 6 => 2 (2)\n# 2 => 5 (3)\n# 5 => 3 (4)\n# 3 => 2 (5)\n\n# loop_steps = 5 - 2 - 1 = 2\n# 5 + 2 * m + r = 727202214173249351\n# steps + loop_steps * m + r = K\n\n\nstate = 1\nsteps = 0\nflag = False\nknown_states = {}\n\nwhile steps < K:\n known_states[state] = steps # state => 2, steps => 2\n\n state = paths[state] # state => 5\n steps += 1 # steps => 3\n\n # print(f'steps: {steps}, state: {state}')\n\n if state in known_states and not flag: # state => 2 steps => 5\n loop_steps = steps - known_states[state]\n # print('loop_steps:', loop_steps)\n # print('steps - loop_steps', steps - loop_steps)\n K = (steps - loop_steps) + (K - (steps - loop_steps)) % loop_steps - 1\n \n steps = 0\n state = 1\n # print('steps:', steps)\n flag = True\n \n\n\n\nprint(state)\n", "# 4 5 (4 cities and 5 steps)\n# 3 2 4 1\n\n# 1 => 3\n# 2 => 2\n# 3 => 4\n# 4 => 1\n\nN, K = map(int, input().split())\nA_i = list(map(int, input().split()))\n\npaths = {}\n\nfor i in range(N):\n paths[i+1] = A_i[i]\n\n# print('paths:', paths)\n\n# 6 5 2 5 3 2\n\nstate = 1\nsteps = 0\nflag = False\nknown_states = {}\n\nwhile steps < K:\n known_states[state] = steps\n\n state = paths[state]\n steps += 1\n\n # print(f'steps: {steps}, state: {state}')\n\n if state in known_states and not flag:\n loop_steps = (steps - known_states[state])\n steps = K - (K % loop_steps) - 1\n flag = True\n \n\n\nprint(state)\n", "# 4 5 (4 cities and 5 steps)\n# 3 2 4 1\n\n# 1 => 3\n# 2 => 2\n# 3 => 4\n# 4 => 1\n\nN, K = map(int, input().split())\nA_i = list(map(int, input().split()))\n\npaths = {}\n\nfor i in range(N):\n paths[i+1] = A_i[i]\n\n# print('paths:', paths)\n\n# 6 5 2 5 3 2\n\nstate = 1\nsteps = 0\nflag = False\nknown_states = {}\n\nwhile steps < K:\n known_states[state] = steps\n\n state = paths[state]\n steps += 1\n\n # print(f'steps: {steps}, state: {state}')\n\n if state in known_states and not flag:\n K = K % (steps - known_states[state]) + 1\n steps = 0\n flag = True\n \n\n\nprint(state)\n", "# 4 5 (4 cities and 5 steps)\n# 3 2 4 1\n\n# 1 => 3\n# 2 => 2\n# 3 => 4\n# 4 => 1\n\n# 1 (0)\n# 1 => 3 (1)\n# 3 => 4 (2)\n# 4 => 1 (3)\n\n\n# 2 = (5 - 3) % 2 + 3 - 1\n\nN, K = map(int, input().split())\nA_i = list(map(int, input().split()))\n\npaths = {}\n\nfor i in range(N):\n paths[i+1] = A_i[i]\n\n# print('paths:', paths)\n\n# 6 5 2 5 3 2\n\n# 1 => 6 (1)\n# 6 => 2 (2)\n# 2 => 5 (3)\n# 5 => 3 (4)\n# 3 => 2 (5)\n\n# loop_steps = 5 - 2 - 1 = 2\n# 5 + 2 * m + r = 727202214173249351\n# steps + loop_steps * m + r = K\n\n\nstate = 1\nsteps = 0\nflag = False\nknown_states = {}\n\nwhile steps < K:\n known_states[state] = steps # state => 2, steps => 2\n\n state = paths[state] # state => 5\n steps += 1 # steps => 3\n\n # print(f'steps: {steps}, state: {state}')\n\n if state in known_states and not flag: # state => 2 steps => 5\n loop_steps = steps - known_states[state]\n K = (steps - loop_steps) + (K - (steps - loop_steps)) % loop_steps\n # print('loop_steps:', loop_steps)\n # print('steps - loop_steps:', steps - loop_steps)\n \n state = 1\n steps = 0\n # print('steps:', steps)\n flag = True\n \n\n\n\nprint(state)\n"]
['Runtime Error', 'Wrong Answer', 'Runtime Error', 'Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Accepted']
['s014002294', 's065250414', 's198087830', 's305382873', 's412641910', 's808508560', 's873929907', 's593839098']
[48804.0, 48808.0, 48812.0, 48540.0, 48656.0, 48720.0, 48704.0, 48700.0]
[193.0, 2207.0, 206.0, 302.0, 291.0, 197.0, 201.0, 282.0]
[791, 1001, 951, 1249, 1258, 641, 616, 1255]
p02684
u768256617
2,000
1,048,576
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
['n,k=map(int,input().split())\na=list(map(int,input().split()))\ntown=[0]*n\ninfo=[1]\nnow=1\nwhile town[now-1]==0:\n town[now-1]+=1\n now=a[now-1]\n info.append(now)\nloop_list=list(info[info.index(now):-1])\nloop_len=len(loop_list)\nbefore_loop_list=list(info[:info.index(now)])\nprint(town)\nprint(info)\nif k<len(before_loop_list):\n print(before_loop_list[k])\nelse:\n print(loop_list[((k-len(before_loop_list))%loop_len)])', 'n,k=map(int,input().split())\na=list(map(int,input().split()))\ntown=[0]*n\ninfo=[1]\nnow=1\nwhile town[now-1]==0:\n town[now-1]+=1\n now=a[now-1]\n info.append(now)\nloop_list=list(info[info.index(now):-1])\nloop_len=len(loop_list)\nbefore_loop_list=list(info[:info.index(now)])\n#print(town)\n#print(info)\nif k<len(before_loop_list):\n print(before_loop_list[k])\nelse:\n print(loop_list[((k-len(before_loop_list))%loop_len)])']
['Wrong Answer', 'Accepted']
['s699264427', 's348006838']
[32352.0, 32328.0]
[186.0, 172.0]
[425, 427]
p02684
u771167374
2,000
1,048,576
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
['#abc167c\nn, k = map(int, input().split())\na = [0] + list(map(int, input().split()))\n\nroot = [1]\nfor i in range(10**100):\n next_num = a[root[-1]]\n root.append(next_num)\n\nif k < n+1:\n print(root[k])\n exit()\n\nloop_end = n \nloop_start = n-1\nwhile(root[loop_start]!=root[loop_end]):\n loop_start -= 1\nperiod = loop_end - loop_start\nk%=period\nwhile k < n:\n k += period\nprint(root[k])\n\n\n\n', 'n, k = map(int, input().split())\na = [0] + list(map(int, input().split()))\nroot = [1]\nfor i in range(2*n+1000):\n next_num = a[root[-1]]\n root.append(next_num)\n\nif k < n+1:\n print(root[k])\n\nelse: \n loop_end = n \n loop_start = n-1\n while(root[loop_start]!=root[loop_end]):\n loop_start -= 1\n period = loop_end - loop_start\n k %= period\n while k < n:\n k += period\n print(root[k])\n\n\n\n']
['Time Limit Exceeded', 'Accepted']
['s687631342', 's237720435']
[104652.0, 32256.0]
[2208.0, 190.0]
[398, 423]
p02684
u777068250
2,000
1,048,576
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
['def detectCycle(x, a):\n start,length = 0, 1\n p1, p2 = a[x], a[a[x]]\n while p1 != p2:\n p1, p2 = a[p1], a[a[p2]]\n\n p2 = x\n while p1 != p2:\n p1, p2 = a[p1], a[p2]\n start += 1\n\n p2 = a[p1]\n while p1 != p2:\n p2 = a[p2]\n length += 1\n \n return start,length\n\nn, k = (int(x) for x in input().split())\na = [-1] + [int(x)-1 for x in input().split()]\nstart, length = detectCycle(1,a)\n\nloc = 1\nk -= start\nfor i in range(start):\n loc = a[loc]\n\nk %= length\nfor i in range(k):\n loc = a[loc]\nprint(loc)', 'def detectCycle(a):\n start, length = 0, 1\n p1, p2 = a[1], a[a[1]]\n while p1 != p2:\n p1, p2 = a[p1], a[a[p2]]\n \n p2 = 1\n while p1 != p2:\n p1, p2 = a[p1], a[p2]\n start += 1\n \n p2 = a[p1]\n while p1 != p2:\n p2 = a[p2]\n length += 1\n \n return start, length\n\nn, k = (int(x) for x in input().split())\na = [-1] + [int(x) for x in input().split()]\nstart, length = detectCycle(a)\n\nloc = 1\nfor i in range(min(start,k)):\n loc = a[loc]\nk = max(k-start,0)\n\nk %= length\nfor i in range(k):\n loc = a[loc]\nprint(loc)']
['Wrong Answer', 'Accepted']
['s931771866', 's881027553']
[32332.0, 32328.0]
[110.0, 225.0]
[553, 571]
p02684
u779728630
2,000
1,048,576
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
['N, K = map(int, input().split())\nA = tuple( map(int, input().split()) )\n\nL = [0 for i in range(N+1)]\nL[1] = 1\nx = 1\nt = 1\nwhile K>0:\n t += 1\n K -= 1\n x = A[x]\n if L[x] != 0:\n p = t - L[x]\n K %= p\n break\n else:\n L[x] = t\n \nwhile K>0:\n x = A[x]\n K -= 1\nprint(x)', 'N, K = map(int, input().split())\nA = tuple( map(int, input().split()) )\n\nL = [0 for i in range(N+1)]\nL[1] = 1\nx = 1\nt = 1\nwhile K>0:\n t += 1\n K -= 1\n x = A[x-1]\n if L[x] != 0:\n p = t - L[x]\n K %= p\n break\n else:\n L[x] = t\n \nwhile K>0:\n x = A[x-1]\n K -= 1\nprint(x)\n']
['Runtime Error', 'Accepted']
['s550821797', 's194057841']
[32408.0, 32404.0]
[127.0, 151.0]
[281, 286]
p02684
u785578220
2,000
1,048,576
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
['n,k = map(int,input().split())\nA = list(map(int,input().split()))\ndp = [0] * (n+1)\nB = []\nf = 1\nc = 0\nfor e,i in enumerate(A,1):\n if dp[f-1] or i == 1:\n ans = e-dp[f-1]\n bal = dp[f-1]\n break\n else:\n dp[f-1]+=c\n B.append(A[f-1])\n f = A[f-1]\n c+=1\nk-= bal\n# print(bal,ans)\nB = B[bal:ans+1]\n# print(dp)\nk = (k%ans+1)%ans\nprint(B[k])', 'n,k = map(int,input().split())\nA = list(map(int,input().split()))\ndp = [-1] * (n+1)\nB = []\nf = 1\nc = 0\nans = n\nbal = 0\nwhile dp[f-1] == -1:\n dp[f-1] =c\n B.append(f)\n f = A[f-1]\n c +=1\nt = B.index(f)\nif k>t:\n k -= t\n B = B[B.index(f):]\n k%=len(B)\n print(B[k])\nelse:\n print(B[k])']
['Runtime Error', 'Accepted']
['s586556046', 's666292605']
[32136.0, 32236.0]
[216.0, 164.0]
[384, 304]
p02684
u788260274
2,000
1,048,576
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
['from sys import stdin\nimport sys\nimport math\nfrom functools import reduce\nimport functools\nimport itertools\nfrom collections import deque\n\nn,k = [int(x) for x in stdin.readline().rstrip().split()]\na = [0] + [int(x) for x in stdin.readline().rstrip().split()]\n\nm = 0\nb = [1]\n\nc = 1\nfor i in range(n):\n c = a[c]\n if c not in b:\n b.append(c)\n if i == k-1: print(c)\n sys.exit()\n else:\n break\n\nidx = b.index(c)\nbn = len(b[idx:])\nsn = len(b[:idx])\n\n# print(b,idx,sn,bn)\nkk = (k-sn) % bn\nprint(b[idx+kk])', 'from sys import stdin\nimport sys\nimport math\nfrom functools import reduce\nimport functools\nimport itertools\nfrom collections import deque\n\nn,k = [int(x) for x in stdin.readline().rstrip().split()]\na = [0] + [int(x) for x in stdin.readline().rstrip().split()]\n\nm = 0\nb = [1]\nvisited = [-1 for i in range(n+1)]\n\nc = 1\nvisited[1] = 1\nfor i in range(n):\n c = a[c]\n if visited[c] != 1:\n b.append(c)\n visited[c] = 1\n if i == k-1:\n print(c)\n sys.exit()\n else:\n break\n\nidx = b.index(c)\nbn = len(b[idx:])\nsn = len(b[:idx])\n\n# print(b,idx,sn,bn)\nkk = (k-sn) % bn\nprint(b[idx+kk])']
['Wrong Answer', 'Accepted']
['s148877091', 's713947355']
[32212.0, 32024.0]
[81.0, 139.0]
[534, 628]
p02684
u788703383
2,000
1,048,576
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
['n,k =map(int,input().split())\na=list(map(int,input().split()))\na = [1] + a\ndef next(i):\n return a[i]\n\nz = [0] * (n+1)\n\nplace = 1\nT = 0\ninterval = 0\nif k < n:\n for i in range(k):\n place = next(place)\n print(place);exit()\nplace = 0\nfor i in range(n):\n place = next(place)\n if z[place] != 0:\n interval = T - z[place]\n break\n z[place] = T\n T += 1\nm = (k-z[place])%interval\nfor i in range(m):\n place = next(place)\nprint(place)\n', "import sys\nsys.setrecursionlimit(10**8)\nINF = float('inf')\nmod = 10**9 + 7\ninput = sys.stdin.readline\n\ndef inp():\n return int(input())\ndef inpl():\n return list(map(int,input().split()))\ndef inpm():\n return map(int,input().split())\n\nn,k =map(int,input().split())\n\na=[1] + inpl()\nb=[-1] * (n+1); b[1] = 0\nplace = 1\nturn = 0\n\nwhile b[a[place]] == -1:\n place = a[place]\n turn += 1\n b[place] = turn\nr = (k - turn) % (b[place] - b[a[place]] + 1)\n\nif k < turn:\n print(b.index(k))\nelse:\n for _ in range(r):\n place = a[place]\n print(place)\n\n"]
['Runtime Error', 'Accepted']
['s925700425', 's362716661']
[32380.0, 31064.0]
[166.0, 137.0]
[467, 566]
p02684
u789199177
2,000
1,048,576
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
['n, k = map(int, input().split())\nA = list(map(int, input().split()))\n \nnext_city = 1\nvisited = []\nx = [-1]*n\nwhile x[next_city-1] == -1:\n visited.append(next_city)\n next_city = A[next_city-1]\nidx = visited.index(next_city)\nvisited2 = visited[idx:]\nmod = len(visited2)\nx = (k%mod-idx)%mod\nprint(visited2[x])', 'n, k = map(int, input().split())\nA = list(map(int, input().split()))\nvisited = [0]*n\nn_city = 1\nwhile visited[n_city-1] == 0:\n visited[n_city-1] = 1\n n_city = A[n_city-1]\ncnt = 1\nroot = n_city\nn_city = A[n_city-1]\nwhile n_city != root:\n n_city = A[n_city-1]\n cnt += 1\nto_root = 0\nn_city = 1\nwhile n_city != root:\n n_city = A[n_city-1]\n to_root += 1\nloop_num = k if k < to_root else (k-to_root)%cnt + to_root\ncnt = 0\nn_city = 1\nwhile cnt < loop_num:\n n_city = A[n_city-1]\n cnt += 1\nprint(n_city)']
['Time Limit Exceeded', 'Accepted']
['s376891621', 's157155319']
[131620.0, 32284.0]
[2210.0, 176.0]
[312, 518]
p02684
u790710233
2,000
1,048,576
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
['from collections import Counter\nsys.setrecursionlimit(10**7)\nn, k = map(int, input().split())\nA = list(map(lambda x: int(x)-1, input().split()))\n\n\nvisited = [0]*n\n\n\ndef dfs(v):\n if visited[v]+1 == 3:\n return 0\n visited[v] += 1\n dfs(A[v])\n\n\ndfs(0)\n\nc = Counter(visited)\nloop_cnt = c[2]\ninit_cnt = c[1]\nk -= init_cnt\nk %= loop_cnt\n\ncnt = 0\nvisited = [0]*n\n\n\nans = 0\nfor _ in range(k+init_cnt):\n ans = A[ans]\nprint(ans+1)\n', 'n, k = map(int, input().split())\nA = list(map(lambda x: int(x)-1, input().split()))\n\nhistory = [-1]*n\nans = []\ncur = 0\nfor i in range(n):\n if history[cur] != -1:\n init_cnt = history[cur]\n loop_cnt = i - history[cur]\n break\n history[cur] = i\n ans.append(cur+1)\n cur = A[cur]\n\nloop = k if k <= init_cnt else init_cnt+((k-init_cnt) % loop_cnt)\nprint(ans[loop])']
['Runtime Error', 'Accepted']
['s692473192', 's764314394']
[9416.0, 32284.0]
[24.0, 181.0]
[438, 390]
p02684
u792670114
2,000
1,048,576
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
['N, K = map(int, input().split())\nAs = list(map(int, input().split()))\nAs = [A-1 for A in As]\nVs = [-1]*N\np = 0\np0 = -1\nRs = [p]\nVs[p] = p\nfor i in range(N):\n n = As[p]\n Rs.append(n)\n if not Vs[n] < 0:\n p0 = Vs[n]\n break\n p = n\n Vs[p] = p\n#print(Rs, p0)\nif K <= p0:\n r = Rs[K]\nelse:\n r = Rs[p0+(K-p0)%(len(Rs)-p0+1)]\nprint(r+1)\n', 'N, K = map(int, input().split())\nAs = list(map(int, input().split()))\nAs = [A-1 for A in As]\nVs = [False]*N\np = 0\nRs = [p]\nVs[p] = True\nfor i in range(N+3):\n n = As[p]\n Rs.append(n)\n if Vs[n]:\n break\n p = n\n Vs[p] = True\np0 = Rs.index(Rs[-1])\n#print(Rs, p0)\nif K <= p0:\n r = Rs[K]\nelse:\n r = Rs[p0+(K-p0)%(len(Rs)-p0-1)]\nprint(r+1)\n']
['Runtime Error', 'Accepted']
['s442421004', 's764402236']
[32312.0, 32376.0]
[178.0, 151.0]
[340, 342]
p02684
u793666115
2,000
1,048,576
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question.
['n, k = map(int,input().split())\na = list(map(int,input().split()))\nfrom collections import deque\n\nans = deque()\nans.appendleft(1)\ncount = 1\ns = -1\n\nwhile True:\n if a[count-1] in a[:count-1]:\n s = a[count-1]\n ans = a[:count-1]\n break\n else:\n count = a[count-1]\n\nif s == -1:\n print(ans[k-1])\nelse:\n t = ans.index(s)\n if t >= k:\n print(ans[k-1])\n else:\n ans = ans[t-1:]\n print(ans[(k-t)%len(ans)])', 'n, k = map(int,input().split())\na = list(map(int,input().split()))\nfrom collections import deque\n\nans = deque()\nans.appendleft(1)\ncount = 1\ns = -1\nzeros = [0]*n\n\nwhile True:\n if zeros[a[count-1]] == 1:\n s = a[count-1]\n break\n else:\n ans.append(a[count-1])\n zeros[count-1]=1\n count = a[count-1]\n\nans = list(ans)\nif s == -1:\n print(ans[k])\nelse:\n t = ans.index(s)\n if t >= k:\n print(ans[k])\n else:\n ans = ans[t:]\n print(ans[(k-t)%len(ans)])\n', 'n, k = map(int,input().split())\na = list(map(int,input().split()))\nfrom collections import deque\n\nans = deque()\nans.appendleft(1)\ncount = 1\ns = -1\n\nwhile True:\n if a[count-1] in a[:count-1]:\n s = a[count-1]\n ans = a[:count-1]\n break\n else:\n count = a[count-1]\n\nif s == -1:\n print(ans[k-1])\nelse:\n t = ans.index(s)\n if t >= k:\n print(ans[k-1])\n else:\n ans = ans[t:]\n print(ans[(k-t)%len(ans)])', 'n, k = map(int,input().split())\na = list(map(int,input().split()))\nfrom collections import deque\n\nans = deque()\nans.appendleft(1)\ncount = 1\ns = -1\nzeros = [0]*n\n\nwhile True:\n if zeros[a[count-1]-1] == 1:\n s = a[count-1]\n break\n else:\n ans.append(a[count-1])\n zeros[count-1]=1\n count = a[count-1]\n\nans = list(ans)\nif s == -1:\n print(ans[k])\nelse:\n t = ans.index(s)\n if t >= k:\n print(ans[k])\n else:\n ans = ans[t:]\n print(ans[(k-t)%len(ans)])\n']
['Wrong Answer', 'Runtime Error', 'Wrong Answer', 'Accepted']
['s534415175', 's682758744', 's966809521', 's009792100']
[32384.0, 88124.0, 32380.0, 32376.0]
[2206.0, 2208.0, 2206.0, 179.0]
[461, 513, 459, 515]