message
stringlengths
2
48.6k
message_type
stringclasses
2 values
message_id
int64
0
1
conversation_id
int64
318
108k
cluster
float64
8
8
__index_level_0__
int64
636
217k
Provide tags and a correct Python 3 solution for this coding contest problem. There are famous Russian nesting dolls named matryoshkas sold in one of the souvenir stores nearby, and you'd like to buy several of them. The store has n different matryoshkas. Any matryoshka is a figure of volume out_i with an empty space ...
instruction
0
91,005
8
182,010
Tags: binary search, combinatorics, data structures, dp, shortest paths, sortings Correct Solution: ``` import io, sys input = lambda f=io.StringIO(sys.stdin.buffer.read().decode()).readline: f().rstrip() from bisect import bisect_left as lb MOD = 10 ** 9 + 7 n = int(input()) a = [tuple(map(int, input().split())) for...
output
1
91,005
8
182,011
Provide tags and a correct Python 3 solution for this coding contest problem. There are famous Russian nesting dolls named matryoshkas sold in one of the souvenir stores nearby, and you'd like to buy several of them. The store has n different matryoshkas. Any matryoshka is a figure of volume out_i with an empty space ...
instruction
0
91,006
8
182,012
Tags: binary search, combinatorics, data structures, dp, shortest paths, sortings Correct Solution: ``` import io, sys input = lambda f=io.StringIO(sys.stdin.buffer.read().decode()).readline: f().rstrip() from bisect import bisect_left as lb MOD = 10 ** 9 + 7 n = int(input()) a = [tuple(map(int, input().split())) for...
output
1
91,006
8
182,013
Provide tags and a correct Python 3 solution for this coding contest problem. There are famous Russian nesting dolls named matryoshkas sold in one of the souvenir stores nearby, and you'd like to buy several of them. The store has n different matryoshkas. Any matryoshka is a figure of volume out_i with an empty space ...
instruction
0
91,007
8
182,014
Tags: binary search, combinatorics, data structures, dp, shortest paths, sortings Correct Solution: ``` mod = 1000000007 eps = 10**-9 def main(): import sys input = sys.stdin.buffer.readline N = int(input()) A = [] B = [] val = set() val.add(0) a_max = -1 for _ in range(N): ...
output
1
91,007
8
182,015
Provide tags and a correct Python 3 solution for this coding contest problem. There are famous Russian nesting dolls named matryoshkas sold in one of the souvenir stores nearby, and you'd like to buy several of them. The store has n different matryoshkas. Any matryoshka is a figure of volume out_i with an empty space ...
instruction
0
91,008
8
182,016
Tags: binary search, combinatorics, data structures, dp, shortest paths, sortings Correct Solution: ``` import sys input = sys.stdin.readline from bisect import bisect_right as br P = 10**9+7 N = int(input()) X = [] maxinn = 0 for _ in range(N): a, b = map(int, input().split()) maxinn = max(maxinn, b) X.app...
output
1
91,008
8
182,017
Provide tags and a correct Python 3 solution for this coding contest problem. There are famous Russian nesting dolls named matryoshkas sold in one of the souvenir stores nearby, and you'd like to buy several of them. The store has n different matryoshkas. Any matryoshka is a figure of volume out_i with an empty space ...
instruction
0
91,009
8
182,018
Tags: binary search, combinatorics, data structures, dp, shortest paths, sortings Correct Solution: ``` from bisect import bisect_left as lb MOD = 10 ** 9 + 7 n = int(input()) a = [tuple(map(int, input().split())) for _ in range(n)] a = sorted((in_, out) for out, in_ in a) dp_suf = [None] * n for i in range(n - 1, ...
output
1
91,009
8
182,019
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are famous Russian nesting dolls named matryoshkas sold in one of the souvenir stores nearby, and you'd like to buy several of them. The store has n different matryoshkas. Any matryoshka i...
instruction
0
91,010
8
182,020
No
output
1
91,010
8
182,021
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are famous Russian nesting dolls named matryoshkas sold in one of the souvenir stores nearby, and you'd like to buy several of them. The store has n different matryoshkas. Any matryoshka i...
instruction
0
91,011
8
182,022
No
output
1
91,011
8
182,023
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are famous Russian nesting dolls named matryoshkas sold in one of the souvenir stores nearby, and you'd like to buy several of them. The store has n different matryoshkas. Any matryoshka i...
instruction
0
91,012
8
182,024
No
output
1
91,012
8
182,025
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are famous Russian nesting dolls named matryoshkas sold in one of the souvenir stores nearby, and you'd like to buy several of them. The store has n different matryoshkas. Any matryoshka i...
instruction
0
91,013
8
182,026
No
output
1
91,013
8
182,027
Provide tags and a correct Python 3 solution for this coding contest problem. Fox Ciel has n boxes in her room. They have the same size and weight, but they might have different strength. The i-th box can hold at most xi boxes on its top (we'll call xi the strength of the box). Since all the boxes have the same size...
instruction
0
91,241
8
182,482
Tags: greedy, sortings Correct Solution: ``` def validate_stack(stack): for i in range(len(stack)): if stack[i] < len(stack)-i-1: return False return True # print(validate_stack([4,4,4,4,4])) if __name__ == '__main__': n = int(input()) box_strength = [int(x) for x in input().split()] box_strength = sorted(box...
output
1
91,241
8
182,483
Provide tags and a correct Python 3 solution for this coding contest problem. Fox Ciel has n boxes in her room. They have the same size and weight, but they might have different strength. The i-th box can hold at most xi boxes on its top (we'll call xi the strength of the box). Since all the boxes have the same size...
instruction
0
91,242
8
182,484
Tags: greedy, sortings Correct Solution: ``` def go(): n = int(input()) a = [int(i) for i in input().split(' ')] a.sort() o = 1 for i in range(n): if(a[i] < i // o): o += 1 return o print(go()) ```
output
1
91,242
8
182,485
Provide tags and a correct Python 3 solution for this coding contest problem. Fox Ciel has n boxes in her room. They have the same size and weight, but they might have different strength. The i-th box can hold at most xi boxes on its top (we'll call xi the strength of the box). Since all the boxes have the same size...
instruction
0
91,243
8
182,486
Tags: greedy, sortings Correct Solution: ``` import bisect n = int(input()) xi = list(sorted(map(int, input().split()))) s = set(xi) li = [] while len(xi) > 0: li.append([xi.pop(0)]) i = 0 while i < len(xi): if xi[i] >= len(li[-1]): li[-1].append(xi.pop(i)) else: i +=...
output
1
91,243
8
182,487
Provide tags and a correct Python 3 solution for this coding contest problem. Fox Ciel has n boxes in her room. They have the same size and weight, but they might have different strength. The i-th box can hold at most xi boxes on its top (we'll call xi the strength of the box). Since all the boxes have the same size...
instruction
0
91,244
8
182,488
Tags: greedy, sortings Correct Solution: ``` import math class CodeforcesTask388ASolution: def __init__(self): self.result = '' self.n = 0 self.boxes = [] def read_input(self): self.n = int(input()) self.boxes = [int(x) for x in input().split(" ")] def process_tas...
output
1
91,244
8
182,489
Provide tags and a correct Python 3 solution for this coding contest problem. Fox Ciel has n boxes in her room. They have the same size and weight, but they might have different strength. The i-th box can hold at most xi boxes on its top (we'll call xi the strength of the box). Since all the boxes have the same size...
instruction
0
91,245
8
182,490
Tags: greedy, sortings Correct Solution: ``` n=int(input()) x=list(map(int,input().split())) x.sort() nu=0 ans=0 mark=[] for i in range(0,n): mark.append(0) for i in range(0,n): fail=1 nu=0 for j in range(0,n): if mark[j] == 0: fail = 0 if x[j] >= nu: ...
output
1
91,245
8
182,491
Provide tags and a correct Python 3 solution for this coding contest problem. Fox Ciel has n boxes in her room. They have the same size and weight, but they might have different strength. The i-th box can hold at most xi boxes on its top (we'll call xi the strength of the box). Since all the boxes have the same size...
instruction
0
91,246
8
182,492
Tags: greedy, sortings Correct Solution: ``` n = int(input()) a = [int(i) for i in input().split(' ')] a.sort() s = 1 for i in range(n): if(a[i] < i // s): s += 1 print(s) ```
output
1
91,246
8
182,493
Provide tags and a correct Python 3 solution for this coding contest problem. Fox Ciel has n boxes in her room. They have the same size and weight, but they might have different strength. The i-th box can hold at most xi boxes on its top (we'll call xi the strength of the box). Since all the boxes have the same size...
instruction
0
91,247
8
182,494
Tags: greedy, sortings Correct Solution: ``` n=int(input()) l=list(map(int,input().split())) l=sorted(l) l=l[::-1] l1=[0]*n k=0 for i in range(n) : if l1[i]!=1 : t=l[i] p=1 r=0 l1[i]==1 V=[t] for j in range(n) : if l1[j]==0 and l[j]<t : t=l...
output
1
91,247
8
182,495
Provide tags and a correct Python 3 solution for this coding contest problem. Fox Ciel has n boxes in her room. They have the same size and weight, but they might have different strength. The i-th box can hold at most xi boxes on its top (we'll call xi the strength of the box). Since all the boxes have the same size...
instruction
0
91,248
8
182,496
Tags: greedy, sortings Correct Solution: ``` N = int(input()) ar = list(map(int, input().split())) ar.sort() a = 1 b = 100 while a < b: compliant = True k = (a+b) // 2 for i in range(len(ar)): if ar[i] < (i//k): compliant = False break if compliant: b = k else: a = k + 1 print(b) `...
output
1
91,248
8
182,497
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Fox Ciel has n boxes in her room. They have the same size and weight, but they might have different strength. The i-th box can hold at most xi boxes on its top (we'll call xi the strength of the...
instruction
0
91,249
8
182,498
Yes
output
1
91,249
8
182,499
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Fox Ciel has n boxes in her room. They have the same size and weight, but they might have different strength. The i-th box can hold at most xi boxes on its top (we'll call xi the strength of the...
instruction
0
91,250
8
182,500
Yes
output
1
91,250
8
182,501
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Fox Ciel has n boxes in her room. They have the same size and weight, but they might have different strength. The i-th box can hold at most xi boxes on its top (we'll call xi the strength of the...
instruction
0
91,251
8
182,502
Yes
output
1
91,251
8
182,503
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Fox Ciel has n boxes in her room. They have the same size and weight, but they might have different strength. The i-th box can hold at most xi boxes on its top (we'll call xi the strength of the...
instruction
0
91,252
8
182,504
Yes
output
1
91,252
8
182,505
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Fox Ciel has n boxes in her room. They have the same size and weight, but they might have different strength. The i-th box can hold at most xi boxes on its top (we'll call xi the strength of the...
instruction
0
91,253
8
182,506
No
output
1
91,253
8
182,507
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Fox Ciel has n boxes in her room. They have the same size and weight, but they might have different strength. The i-th box can hold at most xi boxes on its top (we'll call xi the strength of the...
instruction
0
91,254
8
182,508
No
output
1
91,254
8
182,509
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Fox Ciel has n boxes in her room. They have the same size and weight, but they might have different strength. The i-th box can hold at most xi boxes on its top (we'll call xi the strength of the...
instruction
0
91,255
8
182,510
No
output
1
91,255
8
182,511
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Fox Ciel has n boxes in her room. They have the same size and weight, but they might have different strength. The i-th box can hold at most xi boxes on its top (we'll call xi the strength of the...
instruction
0
91,256
8
182,512
No
output
1
91,256
8
182,513
Provide tags and a correct Python 2 solution for this coding contest problem. One day, little Vasya found himself in a maze consisting of (n + 1) rooms, numbered from 1 to (n + 1). Initially, Vasya is at the first room and to get out of the maze, he needs to get to the (n + 1)-th one. The maze is organized as follows...
instruction
0
91,257
8
182,514
Tags: dp, implementation Correct Solution: ``` from sys import stdin, stdout from collections import Counter, defaultdict from itertools import permutations, combinations raw_input = stdin.readline pr = stdout.write def in_arr(): return map(int,raw_input().split()) def pr_num(n): stdout.write(str(n)+'\n') ...
output
1
91,257
8
182,515
Provide tags and a correct Python 3 solution for this coding contest problem. One day, little Vasya found himself in a maze consisting of (n + 1) rooms, numbered from 1 to (n + 1). Initially, Vasya is at the first room and to get out of the maze, he needs to get to the (n + 1)-th one. The maze is organized as follows...
instruction
0
91,258
8
182,516
Tags: dp, implementation Correct Solution: ``` R = lambda: map(int, input().split()) n = int(input()) mod = 1000000007 arr = [x - 1 for x in R()] dp = [0] * (n + 1) sdp = [0] * (n + 1) dp[0] = sdp[0] = 2 for i in range(1, len(arr)): dp[i] = (2 + sdp[i - 1] - sdp[arr[i] - 1]) % mod sdp[i] = (sdp[i - 1] + dp[i]) ...
output
1
91,258
8
182,517
Provide tags and a correct Python 3 solution for this coding contest problem. One day, little Vasya found himself in a maze consisting of (n + 1) rooms, numbered from 1 to (n + 1). Initially, Vasya is at the first room and to get out of the maze, he needs to get to the (n + 1)-th one. The maze is organized as follows...
instruction
0
91,259
8
182,518
Tags: dp, implementation Correct Solution: ``` n = int(input()) a = list(map(int, input().split())) dp = [0 for i in range(n+1)] for i in range(n+1): if i > 0 : dp[i] = (2*dp[i-1]+2-dp[a[i-1]-1])%1000000007 print((dp[n]+1000000007)%1000000007) ```
output
1
91,259
8
182,519
Provide tags and a correct Python 3 solution for this coding contest problem. One day, little Vasya found himself in a maze consisting of (n + 1) rooms, numbered from 1 to (n + 1). Initially, Vasya is at the first room and to get out of the maze, he needs to get to the (n + 1)-th one. The maze is organized as follows...
instruction
0
91,260
8
182,520
Tags: dp, implementation Correct Solution: ``` import sys MOD = 10 ** 9 + 7 N = int(input()) bs = [int(b) - 1 for b in input().split()] fs = [0] for i in range(1,N+1): f = 2 * fs[i - 1] + 2 - fs[bs[i - 1]] fs.append(f % MOD) print(fs[-1]) ```
output
1
91,260
8
182,521
Provide tags and a correct Python 3 solution for this coding contest problem. One day, little Vasya found himself in a maze consisting of (n + 1) rooms, numbered from 1 to (n + 1). Initially, Vasya is at the first room and to get out of the maze, he needs to get to the (n + 1)-th one. The maze is organized as follows...
instruction
0
91,261
8
182,522
Tags: dp, implementation Correct Solution: ``` z = int(input()) l = [None] + [int(x) for x in input().split()] pt = [0] * (z + 2) for i in range(1, z + 1): pt[i + 1] = (2 * pt[i] - pt[l[i]] + 2) % 1000000007 print(pt[z + 1] % 1000000007) ```
output
1
91,261
8
182,523
Provide tags and a correct Python 3 solution for this coding contest problem. One day, little Vasya found himself in a maze consisting of (n + 1) rooms, numbered from 1 to (n + 1). Initially, Vasya is at the first room and to get out of the maze, he needs to get to the (n + 1)-th one. The maze is organized as follows...
instruction
0
91,262
8
182,524
Tags: dp, implementation Correct Solution: ``` n=int(input()) p=list(map(int,input().split(" ",n)[:n])) a=[i+1 for i in range(n)] dp1=[0]*(n+1) dp1[1]=2 dp2=[0]*(n+1) dp2[1]=2 mod=10**9 + 7 for i in range(2,n+1): k=p[i-1] an=2 for j in range(k,i): an+=dp2[j]%mod dp2[i]=an%mod dp1[i]=dp2[i]+d...
output
1
91,262
8
182,525
Provide tags and a correct Python 3 solution for this coding contest problem. One day, little Vasya found himself in a maze consisting of (n + 1) rooms, numbered from 1 to (n + 1). Initially, Vasya is at the first room and to get out of the maze, he needs to get to the (n + 1)-th one. The maze is organized as follows...
instruction
0
91,263
8
182,526
Tags: dp, implementation Correct Solution: ``` input() dp = [0] [dp.append((2 * dp[-1] + 2 - dp[u - 1]) % 1000000007) for u in map(int, input().split())] print (dp[-1]) ```
output
1
91,263
8
182,527
Provide tags and a correct Python 3 solution for this coding contest problem. One day, little Vasya found himself in a maze consisting of (n + 1) rooms, numbered from 1 to (n + 1). Initially, Vasya is at the first room and to get out of the maze, he needs to get to the (n + 1)-th one. The maze is organized as follows...
instruction
0
91,264
8
182,528
Tags: dp, implementation Correct Solution: ``` n,a= int(input()),list(map(int,input().split())) f,m= [0]*(n+1),10**9+7 for i in range(n): if a[i]==i+1: f[i+1]=f[i]+2 else: f[i+1]=(2+f[i]*2-f[a[i]-1])%m print(f[n]%m) ```
output
1
91,264
8
182,529
Provide tags and a correct Python 3 solution for this coding contest problem. One day, little Vasya found himself in a maze consisting of (n + 1) rooms, numbered from 1 to (n + 1). Initially, Vasya is at the first room and to get out of the maze, he needs to get to the (n + 1)-th one. The maze is organized as follows...
instruction
0
91,265
8
182,530
Tags: dp, implementation Correct Solution: ``` def bf(n, portal2): portal2.insert(0, -1) roomMark = [False]*(n+1) markCount = 0 room = 1 while(room != n+1): markCount += 1 roomMark[room] = not roomMark[room] if roomMark[room]: room = portal2[room] else: room += 1 print(markCount % 1000000007) ...
output
1
91,265
8
182,531
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. One day, little Vasya found himself in a maze consisting of (n + 1) rooms, numbered from 1 to (n + 1). Initially, Vasya is at the first room and to get out of the maze, he needs to get to the (n...
instruction
0
91,266
8
182,532
Yes
output
1
91,266
8
182,533
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. One day, little Vasya found himself in a maze consisting of (n + 1) rooms, numbered from 1 to (n + 1). Initially, Vasya is at the first room and to get out of the maze, he needs to get to the (n...
instruction
0
91,267
8
182,534
Yes
output
1
91,267
8
182,535
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. One day, little Vasya found himself in a maze consisting of (n + 1) rooms, numbered from 1 to (n + 1). Initially, Vasya is at the first room and to get out of the maze, he needs to get to the (n...
instruction
0
91,268
8
182,536
Yes
output
1
91,268
8
182,537
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. One day, little Vasya found himself in a maze consisting of (n + 1) rooms, numbered from 1 to (n + 1). Initially, Vasya is at the first room and to get out of the maze, he needs to get to the (n...
instruction
0
91,269
8
182,538
Yes
output
1
91,269
8
182,539
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. One day, little Vasya found himself in a maze consisting of (n + 1) rooms, numbered from 1 to (n + 1). Initially, Vasya is at the first room and to get out of the maze, he needs to get to the (n...
instruction
0
91,270
8
182,540
No
output
1
91,270
8
182,541
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. One day, little Vasya found himself in a maze consisting of (n + 1) rooms, numbered from 1 to (n + 1). Initially, Vasya is at the first room and to get out of the maze, he needs to get to the (n...
instruction
0
91,271
8
182,542
No
output
1
91,271
8
182,543
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. One day, little Vasya found himself in a maze consisting of (n + 1) rooms, numbered from 1 to (n + 1). Initially, Vasya is at the first room and to get out of the maze, he needs to get to the (n...
instruction
0
91,272
8
182,544
No
output
1
91,272
8
182,545
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. One day, little Vasya found himself in a maze consisting of (n + 1) rooms, numbered from 1 to (n + 1). Initially, Vasya is at the first room and to get out of the maze, he needs to get to the (n...
instruction
0
91,273
8
182,546
No
output
1
91,273
8
182,547
Evaluate the correctness of the submitted Python 2 solution to the coding contest problem. Provide a "Yes" or "No" response. One day, little Vasya found himself in a maze consisting of (n + 1) rooms, numbered from 1 to (n + 1). Initially, Vasya is at the first room and to get out of the maze, he needs to get to the (n...
instruction
0
91,274
8
182,548
No
output
1
91,274
8
182,549
Provide a correct Python 3 solution for this coding contest problem. Takahashi wants to gain muscle, and decides to work out at AtCoder Gym. The exercise machine at the gym has N buttons, and exactly one of the buttons is lighten up. These buttons are numbered 1 through N. When Button i is lighten up and you press it...
instruction
0
91,563
8
183,126
"Correct Solution: ``` n = int(input()) a = [int(input()) for i in range(n)] x = 1 i = 0 while i < n and x != 2: x = a[x-1] i += 1 if x == 2: print(i) else: print(-1) ```
output
1
91,563
8
183,127
Provide a correct Python 3 solution for this coding contest problem. Takahashi wants to gain muscle, and decides to work out at AtCoder Gym. The exercise machine at the gym has N buttons, and exactly one of the buttons is lighten up. These buttons are numbered 1 through N. When Button i is lighten up and you press it...
instruction
0
91,564
8
183,128
"Correct Solution: ``` N=int(input()) a=[int(input()) for i in range(N)] x=1 for i in range(N): if(x==2): print(i) exit() x=a[x-1] print("-1") ```
output
1
91,564
8
183,129
Provide a correct Python 3 solution for this coding contest problem. Takahashi wants to gain muscle, and decides to work out at AtCoder Gym. The exercise machine at the gym has N buttons, and exactly one of the buttons is lighten up. These buttons are numbered 1 through N. When Button i is lighten up and you press it...
instruction
0
91,565
8
183,130
"Correct Solution: ``` n=int(input()) a=[0]*(n+1) for i in range(n): a[i]=int(input()) k=0 ans=-1 for i in range(n): # print(k) k=a[k]-1 if(k==1): ans=i+1 break print(ans) ```
output
1
91,565
8
183,131
Provide a correct Python 3 solution for this coding contest problem. Takahashi wants to gain muscle, and decides to work out at AtCoder Gym. The exercise machine at the gym has N buttons, and exactly one of the buttons is lighten up. These buttons are numbered 1 through N. When Button i is lighten up and you press it...
instruction
0
91,566
8
183,132
"Correct Solution: ``` n=int(input()) a=[int(input()) for i in range(n)] count=1 for i in range(n): if count == 2: print(i) exit() count=a[count-1] print(-1) ```
output
1
91,566
8
183,133
Provide a correct Python 3 solution for this coding contest problem. Takahashi wants to gain muscle, and decides to work out at AtCoder Gym. The exercise machine at the gym has N buttons, and exactly one of the buttons is lighten up. These buttons are numbered 1 through N. When Button i is lighten up and you press it...
instruction
0
91,567
8
183,134
"Correct Solution: ``` n=int(input()) a=[int(input())-1 for _ in range(n)] i=0 ct=0 while i!=1: if a[i]==-1: print("-1") break k=i i=a[i] a[k]=-1 ct+=1 else: print(ct) ```
output
1
91,567
8
183,135
Provide a correct Python 3 solution for this coding contest problem. Takahashi wants to gain muscle, and decides to work out at AtCoder Gym. The exercise machine at the gym has N buttons, and exactly one of the buttons is lighten up. These buttons are numbered 1 through N. When Button i is lighten up and you press it...
instruction
0
91,568
8
183,136
"Correct Solution: ``` n=int(input()) l=[int(input()) for i in range(n)] count=0 for i in range(n): if l[count]==2: print(i+1) exit() else: count=l[count]-1 print(-1) ```
output
1
91,568
8
183,137
Provide a correct Python 3 solution for this coding contest problem. Takahashi wants to gain muscle, and decides to work out at AtCoder Gym. The exercise machine at the gym has N buttons, and exactly one of the buttons is lighten up. These buttons are numbered 1 through N. When Button i is lighten up and you press it...
instruction
0
91,569
8
183,138
"Correct Solution: ``` n,ans=int(input()),-1 a,m=[int(input())for i in range(n)],1 for i in range(n): m=a[m-1] if m==2: ans=i+1 break print(ans) ```
output
1
91,569
8
183,139