s_id
stringlengths
10
10
p_id
stringlengths
6
6
u_id
stringlengths
10
10
date
stringlengths
10
10
language
stringclasses
1 value
original_language
stringclasses
11 values
filename_ext
stringclasses
1 value
status
stringclasses
1 value
cpu_time
stringlengths
1
5
memory
stringlengths
1
7
code_size
stringlengths
1
6
code
stringlengths
1
539k
s315033702
p03680
u586478468
1546137844
Python
Python (3.4.3)
py
Runtime Error
216
7084
256
N = int(input()) A = [] for i in range(N): A.append(int(input())) count=1 num=0 ans = A.index(2) st = A[0] for i in range(N): count+=1 if(st==ans+1): print(count) num=1 break st = A[st-1] if(num!=1): print(-1)
s619738242
p03680
u219180252
1544822664
Python
Python (3.4.3)
py
Runtime Error
256
17892
365
n = int(input()) edges = {i: int(input())-1 for i in range(n)} mem = {} d = 0 def has_edge(edges, v, g, d): target = edges.get(v) if target is not None and mem.get(v) is None: mem[v] = 1 if target == g: return d else: return has_edge(edges, target, g, d+1) r...
s345655955
p03680
u219180252
1544822616
Python
Python (3.4.3)
py
Runtime Error
18
2940
364
n = int(input()) edges = {i: int(input())-1 for i in range(n)} mem = {} d = 0 def has_edge(edges, v, g, d): target = edges.get(v) if target is not None and mem.get(v) is None mem[v] = 1 if target == g: return d else: return has_edge(edges, target, g, d+1) re...
s398900276
p03680
u219180252
1544822602
Python
Python (3.4.3)
py
Runtime Error
17
2940
364
n = int(input()) edges = {i: int(input())-1 for i in range(n)} mem = {} d = 0 def has_edge(edges, v, g, d): target = edges.get(v) if target is not None and mem.get(v) is None mem[v] = 1 if target == g: return d else: return has_edge(edges, target, g, d+1) re...
s883469835
p03680
u219180252
1544822520
Python
Python (3.4.3)
py
Runtime Error
255
17892
377
n = int(input()) edges = {i: int(input())-1 for i in range(n)} mem = [0 for _ in range(n)] d = 0 def has_edge(edges, v, g, d): target = edges.get(v) if target is not None and mem[v] == 0: mem[v] = 1 if target == g: return d else: return has_edge(edges, target, g...
s871713775
p03680
u219180252
1544822389
Python
Python (3.4.3)
py
Runtime Error
244
17892
338
n = int(input()) edges = {i: int(input())-1 for i in range(n)} mem = {} d = 0 def has_edge(edges, v, g, d): target = edges[v] if mem.get(v) is None: mem[v] = 1 if target == g: return d else: return has_edge(edges, target, g, d+1) return -2 print(has_edge(e...
s569529248
p03680
u219180252
1544822294
Python
Python (3.4.3)
py
Runtime Error
254
17892
350
n = int(input()) edges = {i: int(input())-1 for i in range(n)} mem = [0 for _ in range(n)] d = 0 def has_edge(edges, v, g, d): target = edges[v] if mem[v] == 0: mem[v] = 1 if target == g: return d else: return has_edge(edges, target, g, d+1) return -2 prin...
s547210278
p03680
u369212307
1542175666
Python
Python (3.4.3)
py
Runtime Error
17
2940
362
n = int(input()) botan = [int(input()) for i in range(n)] light = 1 # 1番目のボタンが初め光ってる count = 1 exi = [1] if 2 in botan: while True: light = botan[light - 1] if light in exi: print(-1) exit() exi.append(light) if 2 in exi: print(count) exit() count += 1 els...
s984466029
p03680
u369212307
1542175603
Python
Python (3.4.3)
py
Runtime Error
17
2940
369
n = int(input()) botan = [int(input()) for i in range(n)] light = 1 # 1番目のボタンが初め光ってる count = 1 exi = [1] if 2 is not in botan: print(-1) exit() while True: light = botan[light - 1] if light in exi: print(-1) exit() exi.append(light) if 2 in exi: print(count) ...
s980904425
p03680
u163449343
1540224115
Python
Python (3.4.3)
py
Runtime Error
2104
7084
209
n = int(input()) a = [int(input())-1 for x in range(n)] ans = 1 ok = False i = a.index(1) for x in range(n): if i == 0: ok = True break i = a.index(i) ans += 1 print([-1, ans][ok])
s009428971
p03680
u790877102
1538810420
Python
Python (3.4.3)
py
Runtime Error
17
2940
161
n = int(input()) a =[] for i in range(n): a.append(int(input())) x = 0 b = 0 for i in range(n): b = a[b]-1 x +=1 if a[b] == a[1]: print(x) break else:
s312849981
p03680
u940102677
1538424342
Python
Python (3.4.3)
py
Runtime Error
2104
7084
156
n = int(input()) a=[] for i in range(n): a.append(int(input())) c = 1 k = a[1] while k != 1: if k == 2: print(c) k = a[k] c += 1 print(-1)
s471676374
p03680
u853900545
1538357278
Python
Python (3.4.3)
py
Runtime Error
196
7072
161
n = int(input()) a = list(int(input()) for i in range(n)) s = 0 c = 0 while s != 1 and c < n: c += 1 s = a[s] if c < n: print(c) else: print(-1)
s155386338
p03680
u826263061
1537481065
Python
Python (3.4.3)
py
Runtime Error
186
7100
320
n = int(input()) a = [0] for _ in range(n+1): a.append(int(input())) visited = [False]*(n+1) visited[1] = True cnt = 0 but = 1 while True: nextb = a[but] if visited[nextb]: cnt = -1 break elif nextb == 2: cnt += 1 break else: but = nextb cnt += 1 visited[but] = True print(cnt)
s709166956
p03680
u419686324
1531881101
Python
Python (3.4.3)
py
Runtime Error
186
7084
142
n = int(input()) a = [int(input()) for _ in range(n)] c = 1 for i in range(n): if c == 2: print(i + 1) exit(0) c = a[c] print(-1)
s139652945
p03680
u492532572
1531243735
Python
Python (3.4.3)
py
Runtime Error
209
7084
198
N = int(input()) alist = [] for _ in range(N): alist.append(int(input())) i = 1 for n in range(N): i = alist[i - 1] if i == 2: print(len(n + 1)) break else: print(-1)
s141365134
p03680
u492532572
1531243608
Python
Python (3.4.3)
py
Runtime Error
200
7084
200
N = int(input()) alist = [] for _ in range(N): alist.append(int(input())) i = 1 for _ in range(N): i = alist[i - 1] if i == 2: print(len(history)) break else: print(-1)
s439613621
p03680
u333139319
1530633440
Python
Python (3.4.3)
py
Runtime Error
204
3612
243
""" https://abc065.contest.atcoder.jp/tasks/abc065_b """ n=int(input()) a="S" for i in range(n): a=a+input() #print(a) t=1 c=0 for i in range(n): t=int(a[t]) c=c+1 if t==2: print(c) break if t!=2: print(-1)
s839428899
p03680
u702582248
1529319414
Python
Python (3.4.3)
py
Runtime Error
17
2940
746
import java.util.HashSet; import java.util.Scanner; import java.util.Set; public class Main { static int[] g; public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); g = new int[n+1]; for (int i = 1; i <= n; i++) { int a =...
s822138373
p03680
u024804656
1529111210
Python
Python (3.4.3)
py
Runtime Error
251
17892
285
n = int(input()) a = {i+1:int(input()) for i in range(n)} def find(ad, nexti, cnt, s): cnt += 1 s.add(nexti) if ad[nexti] == 2: return cnt elif ad[nexti] in s: return -1 else: return find(ad, ad[nexti], cnt, s) print(find(a, 1, 0, set()))
s349299599
p03680
u024804656
1529110976
Python
Python (3.4.3)
py
Runtime Error
253
17892
327
n = int(input()) a = {i+1:int(input()) for i in range(n)} def find(a, nexti, cnt, s): global n if cnt > n: return -1 cnt += 1 s.add(nexti) if a[nexti] == 2: return cnt elif a[nexti] in s: return -1 else: return find(a, a[nexti], cnt, s) print(find(a, 1, 0, s...
s831028961
p03680
u024804656
1529107857
Python
Python (3.4.3)
py
Runtime Error
256
17892
280
n = int(input()) a = {i+1:int(input()) for i in range(n)} def find(a, nexti, cnt, s): cnt += 1 s.add(nexti) if a[nexti] == 2: return cnt elif a[nexti] in s: return -1 else: return find(a, a[nexti], cnt, s) print(find(a, 1, 0, set()))
s574982407
p03680
u597436499
1528468403
Python
Python (3.4.3)
py
Runtime Error
209
7084
324
n = int(input()) a = [] for _ in range(n): a.append(int(input())) if a[0] == 2: print(0) else: count = 0 flag = False i = a[0] for _ in range(n): count += 1 if a[i-1] == 2: flag = True break i = a[i-1] if flag: print(count+1) else: print(...
s848197599
p03680
u766407523
1523480200
Python
Python (3.4.3)
py
Runtime Error
17
3064
268
n = int(input()) a = [] hist = [] for i in range(N): a.append(int(input())) pos = 1 count = 0 while True: if pos == 2: print(count) break if pos in hist: print(-1) break hist.append(pos) pos = a[pos-1] count += 1
s219590061
p03680
u766407523
1523479610
Python
Python (3.4.3)
py
Runtime Error
20
3060
273
N = int(input()) a = [] hist = [] for i in range(N): a.appnd(int(input())) pos = 0 count = 0 while True: if pos+1 in hist: print(-1) break hist.append(a[pos]) pos = a[pos]-1 count += 1 if pos == 1: print(count) break
s864911026
p03680
u766407523
1523479585
Python
Python (3.4.3)
py
Runtime Error
17
2940
271
N = int(input()) a = [] hist = [] for i in range(N): a.appnd(int(input())) pos = 0 count = 0 while True: if pos+1 in hist: print(-1) break hist.append(a[pos]) pos = a[pos]-1 count += 1 if pos = 1: print(count) break
s189793255
p03680
u778700306
1515376163
Python
Python (3.4.3)
py
Runtime Error
18
2940
947
#include <bits/stdc++.h> using namespace std; using ll = long long; #define gc getchar int getint() { unsigned int c; int x = 0; while (((c = gc()) - '0') >= 10) { if (c == '-') return -getint(); if (!~c) exit(0); } do { x = (x << 3) + (x << 1) + (c - '0'); } while (((c = gc()) - '0') < 10); return x; } int getstr(ch...
s400684683
p03680
u136090046
1510274495
Python
Python (3.4.3)
py
Runtime Error
219
7084
316
num = int(input()) array = [] for i in range(num): array.append(int(input())) res = -1 if 2 in array: judge = array[0] roop = 1 while judge != 2 and roop != 100001: roop += 1 judge = array[judge-1] if judge == 2: break if judge == 2: res = roop print(res)
s509040545
p03680
u182399833
1507331520
Python
Python (3.4.3)
py
Runtime Error
229
7852
519
# -*- coding: utf-8 -*- n = int(input()) a = [] for i in range(n): a.append(int(input())) if 2 not in a: print(-1) else: cnt = 0 before_num = 1 lighted_bottons = [0 for i in range(n)] while True: cnt += 1 if a[before_num - 1] == 2: print(cnt) break ...
s195584815
p03680
u243370518
1507243305
Python
Python (3.4.3)
py
Runtime Error
226
7848
284
x = input() a = [] check = [] for i in range(int(x)): a.append(int(input()) - 1) check.append(1) index = 0 while True: check[index] = 0 index = a[index] if check[index] == 0: print(-1) break if index == 1: print(count) break
s505282473
p03680
u243370518
1507242965
Python
Python (3.4.3)
py
Runtime Error
2104
15744
257
x = input() a = [] check = [] for i in range(int(x)): a.append(int(input()) - 1) check.append(1) index = 0 while True: check[index] = 0 index = a[index] if check[index] == 0: print(-1) if index == 1: print(count)
s469674864
p03680
u612721349
1505262439
Python
Python (3.4.3)
py
Runtime Error
185
13724
240
n = int(input()) lst = [int(input()) for _ in[0]*n] visit = set() current = 0 while True: visit.add(current) current = lst[current] if current == 2: print(len(visit) + 1) break if current in visit: print(-1) break
s598304876
p03680
u762008592
1503500463
Python
Python (3.4.3)
py
Runtime Error
42
3060
229
N = int(input()) a_n=list(map(int,input().split())) import sys i=1 count=0 for k in range(N): if a_n[i-1]==2: count+=1 print(count) sys.exit() else: i=a_n[i-1] count+=1 print(-1)
s518613443
p03680
u047535298
1503033888
Python
Python (3.4.3)
py
Runtime Error
236
8764
312
n = int(input()) a = [int(input()) if(i) else 0 for i in range(n+1)] distance = [None] * (n+1) def dfs(p, d): if(p==2): return d if(distance[p]!=None): return -1 ans = 100001 distance[p] = d nextp = a[p] ans = min(ans, dfs(nextp, d + 1)) return ans print(dfs(1, 0))
s484330360
p03680
u364386647
1502391719
Python
Python (3.4.3)
py
Runtime Error
181
9492
230
N = int(input()) a = [input() for i in range(N)] now = 1 count = 0 for i in range(N): if now != 2: now = int(a[now-1]) count += 1 else: print(count) break if count == loop: print(-1)
s808308641
p03680
u125205981
1501447913
Python
Python (3.4.3)
py
Runtime Error
187
7888
351
def main(): N = int(input()) A = tuple([int(input()) for _ in range(N)]) a = list(A) idx = a.index(1) ans = 0 while True: btn = a[idx] if btn == 0: ans = -1 break elif btn == 2: break a[idx] = 0 idx = btn - 1 an...
s125278165
p03680
u343437894
1499642903
Python
Python (3.4.3)
py
Runtime Error
200
7084
189
n = int(input()) a = [] for i in range(n): a.append(int(input())) light=0 for i in range(n): light=a[light] if light == 1: print(i) break else: print(-1)
s273122817
p03680
u343437894
1499642667
Python
Python (3.4.3)
py
Runtime Error
202
7084
187
n = int(input()) a = [] for i in range(n): a.append(int(input())) light=1 for i in range(n): light=a[light] if light == 2: print(i) break else: print(-1)
s020740553
p03680
u343437894
1499642621
Python
Python (3.4.3)
py
Runtime Error
17
2940
186
n = int(input()) a = [] for i in range(n): a.append(int(input())) light=1 for i in range(n): light=a[light] if light = 2: print(i) break else: print(-1)
s917540420
p03680
u343437894
1499642452
Python
Python (3.4.3)
py
Runtime Error
17
3064
185
n = int(input()) a = [] for i in range(n): a.append(int(input()) light=1 for i in range(n): light=a[light] if light = 2: print(i) break else: print(-1)
s829247428
p03680
u552668967
1498684392
Python
Python (2.7.6)
py
Runtime Error
10
2580
241
from sys import stdin a = [0] n = int(stdin.readline()) for _ in xrange(n): a.append(int(stdin.readline()) ans = -1 cur = 0 x = 1 s = set() while True: if x in s: break if x==2: ans = cur break s.add(x) cur+=1 x = a[x] print ans
s186261791
p03680
u085883871
1498610160
Python
Python (3.4.3)
py
Runtime Error
241
7988
323
def f(l, a, hist): if(a in hist): return -1 if(a == 1): return len(hist) hist.append(a) return f(l,l[a]-1,hist) def solve(): n = int(input()) l = [] for i in range(n): l.append(int(input())) print(f(l,l[0]-1,[0])) if(__name__ == "__main__"): solve...
s288932559
p03680
u085883871
1498609845
Python
Python (3.4.3)
py
Runtime Error
243
7996
323
def f(l, a, hist): if(a in hist): return -1 if(a == 1): return len(hist) hist.append(a) return f(l,l[a]-1,hist) def solve(): n = int(input()) l = [] for i in range(n): l.append(int(input())) print(f(l,l[0]-1,[0])) if(__name__ == "__main__"): solve...
s300543279
p03680
u085883871
1498609649
Python
Python (3.4.3)
py
Runtime Error
179
7084
324
def f(l, a, hist): if(l[a] in hist): return -1 if(l[a] == 1): return len(hist) hist.append(l[a]) return f(l,a,hist) def solve(): n = int(input()) l = [] for i in range(n): l.append(int(input())) print(f(l,l[0],[])) if(__name__ == "__main__"): solv...
s197975639
p03680
u376420711
1498506762
Python
Python (3.4.3)
py
Runtime Error
18
3060
187
n = input() a = (input() for i in range(n)) counter = 0 i = 1 while counter < n: i = a[i - 1] counter += 1 if i == 2: print(counter) break else: print(-1)
s978155817
p03680
u419832736
1498443030
Python
Python (3.4.3)
py
Runtime Error
584
7960
434
N=int(input()) a=[int(input()) for i in range(N)] b=[] j=1 def c(j): if j==1: return 1 else: return a[c(j-1)-1] if 2 not in a: print(-1) else: while j in range(1,N+1): if a[c(j)-1] not in b: b.append(a[c(j)-1]) if a[c(j)-1]==2: break else: ...
s995238373
p03680
u419832736
1498366576
Python
Python (3.4.3)
py
Runtime Error
603
7940
373
N=int(input()) a=[int(input()) for i in range(N)] b=[] j=1 def c(j): if j==1: return 1 else: return a[c(j-1)-1] if 2 not in a: print(-1) else: while a[c(j)-1] not in b: b.append(a[c(j)-1]) if a[c(j)-1]==2: break else: j += 1 if 2 not in...
s284848567
p03680
u419832736
1498365672
Python
Python (3.4.3)
py
Runtime Error
466
7936
318
N=int(input()) a=[int(input()) for i in range(N)] b=[] def c(j): if j==1: return 1 else: return a[c(j-1)-1] j=1 if 2 not in a: print(-1) else: while a[c(j)-1] not in b: b.append(a[c(j)-1]) j += 1 if 2 not in b: print(-1) else: print(b.index(2)+1)
s626934817
p03680
u602740328
1498360288
Python
Python (3.4.3)
py
Runtime Error
2104
7852
223
N = int(input()) a = [] for i in range(N): a.append(int(input())) x = [False]*N n,i = (1, 0) while x[n-1] == False: x[n] = True n = a[n-1] i+=1 if n==2: print(i) break else: print(-1)
s201275874
p03680
u602740328
1498360152
Python
Python (3.4.3)
py
Runtime Error
206
7852
252
N = int(input()) a = [] for i in range(N): a.append(int(input())) if not(2 in a): print(-1) x = [False]*N n,i = (1, 0) while x[n] == False: x[n] = True n = a[n-1] i+=1 if n==2: print(i) break else: print(-1)
s707834674
p03680
u062864034
1498358385
Python
Python (3.4.3)
py
Runtime Error
18
3064
352
N = int(input()) data_input = [int(input()) for _ in range(N)] history = [] i = 1 count = 0 if 2 not in data_input: print(-1) elif: while True: count += 1 history.append(i) i = data_input[i-1] if i in history: print(-1) break if i == 2: ...
s632428224
p03680
u602860891
1498358068
Python
Python (3.4.3)
py
Runtime Error
387
27196
897
N = int(input()) a_list = [None] index_dict = dict() loop_dict = dict() for i in range(N): a = int(input()) a_list.append(a) if a not in index_dict.keys(): index_dict[a] = [i+1] else: index_dict[a].append(i+1) def rec_search(index, loop): if index in loop_dict.keys(): retu...
s254138465
p03680
u971672726
1498358034
Python
Python (3.4.3)
py
Runtime Error
253
8044
281
def push(i, count): already.append(i + 1) if buttons[i] == 2: print(count) elif buttons[i] in already: print('-1') else: push(buttons[i] - 1, count + 1) N = int(input()) buttons = [] already = [] for i in range(N): buttons.append(int(input())) push(0, 1)
s031198443
p03680
u120026978
1498357718
Python
Python (3.4.3)
py
Runtime Error
209
7080
269
n = int(input()) a = [0] for i in range(n): a.append(int(input())) btn2 = a.index(2) cnt = 1 idx = 1 for i in range(n+1): if a[idx] == btn2: cnt += 1 print(cnt) break else: idx = a[idx] cnt += 1 else: print(-1)
s763503948
p03680
u116142267
1498357421
Python
Python (3.4.3)
py
Runtime Error
224
7888
320
# coding: utf-8 a=[] b=[0]*100000 n = int(input()) for i in range(n): a.append(int(input())) cnt=0 temp = a[0] b[0] = 1 b[1] = 1 while True: temp = a[temp-1] if b[temp+1] == 1: print(-1) break elif temp==2: cnt+=1 print(cnt) break b[temp+1] = 1 cnt+=1
s676157536
p03680
u116142267
1498357379
Python
Python (3.4.3)
py
Runtime Error
224
9896
329
# coding: utf-8 a=[] b=[0]*100000 n = int(input()) for i in range(n): a.append(int(input())) cnt=0 print(a) temp = a[0] b[0] = 1 b[1] = 1 while True: temp = a[temp-1] if b[temp+1] == 1: print(-1) break elif temp==2: cnt+=1 print(cnt) break b[temp+1] = 1 cn...
s353507404
p03680
u794543767
1498357360
Python
Python (3.4.3)
py
Runtime Error
500
21656
221
import numpy as np N = int(input()) a = np.zeros(N) for i in range(N): a[i+1] = int(input()) i = 1 n = 0 for j in range(N): n = n+1 i = a[i] if i == 2: print(n) break if i!=2: print(-1)
s663154118
p03680
u120026978
1498356936
Python
Python (3.4.3)
py
Runtime Error
217
7208
291
n = int(input()) a = [0] for i in range(n): a.append(int(input())) btn2 = a.index(2) cnt = 1 idx = 1 for i in range(n): if a[idx] == btn2: if cnt != 1: cnt += 1 print(cnt) break else: idx = a[idx] cnt += 1 else: print(-1)
s256940041
p03680
u120026978
1498356413
Python
Python (3.4.3)
py
Runtime Error
209
7080
266
n = int(input()) a = [0] for i in range(n): a.append(int(input())) btn2 = a.index(2) cnt = 1 idx = 1 for i in range(n): if a[idx] == btn2: cnt += 1 print(cnt) break else: idx = a[idx] cnt += 1 else: print(-1)
s017182621
p03680
u116142267
1498356366
Python
Python (3.4.3)
py
Runtime Error
231
7852
326
# coding: utf-8 a=[] b=[0]*100000 n = int(input()) for i in range(n): a.append(int(input())) cnt=0 temp = a[1] b[0] = 1 b[1] = 1 while True: temp = a[temp-1] if b[temp+1]==1: print(-1) break else: b[temp+1]=1 cnt+=1 if temp-1==1: cnt +=1 print(cnt) ...
s595921576
p03680
u019578976
1498356071
Python
Python (3.4.3)
py
Runtime Error
182
7084
218
n=int(input()) a=[] for i in range(n): a.append(int(input())) tmp=0 i=0 cnt=0 while i != 1 and cnt < 1000: tmp = a[i] r.append(i) cnt += 1 i = tmp-1 if cnt<1000: print(cnt) else: print(-1)
s534086061
p03680
u120026978
1498355921
Python
Python (3.4.3)
py
Runtime Error
208
7080
280
n = int(input()) a = [0] for i in range(1, n + 1): a.append(int(input())) btn2 = a.index(2) cnt = 1 idx = 1 for i in range(1, n + 1): if a[idx] == btn2: cnt += 1 print(cnt) break else: idx = a[idx] cnt += 1 else: print(-1)
s981743766
p03680
u019578976
1498355918
Python
Python (3.4.3)
py
Runtime Error
189
7208
216
n=int(input()) a=[] for i in range(n): a.append(int(input())) tmp=0 i=0 cnt=0 while i != 1 and cnt < 100: tmp = a[i] r.append(i) cnt += 1 i = tmp-1 if cnt<100: print(cnt) else: print(-1)
s872112740
p03680
u019578976
1498355746
Python
Python (3.4.3)
py
Runtime Error
194
7084
216
n=int(input()) a=[] for i in range(n): a.append(int(input())) tmp=0 i=0 cnt=0 while i != 1 and cnt < 100: tmp = a[i] r.append(i) cnt += 1 i = tmp-1 if cnt<100: print(cnt) else: print(-1)
s088457512
p03680
u702719601
1498355395
Python
Python (3.4.3)
py
Runtime Error
2104
7116
164
N = int(input()) a = [] for i in range(N): a.append(int(input())) b = 1 c = [1] for i in range(N): b = a[b-1] if b in c: break c.append(b) print(c.index(2))
s864857948
p03680
u116142267
1498355391
Python
Python (3.4.3)
py
Runtime Error
223
7852
326
# coding: utf-8 a=[] b=[0]*100000 n = int(input()) for i in range(n): a.append(int(input())) cnt=0 temp = a[0] b[0] = 1 b[1] = 1 while True: temp = a[temp-1] if b[temp+1]==1: print(-1) break else: b[temp+1]=1 cnt+=1 if temp-1==1: cnt +=1 print(cnt) ...
s128782057
p03680
u581309643
1498354648
Python
Python (3.4.3)
py
Runtime Error
174
7884
302
N = int(input()) a = [int(input()) for i in range(N)] ch = [0] * (10**5 + 1) if a[0] == 1 or a[1] == 2: print(-1) ch[1] = numB c = 1 while True: numB = a[numB-1] if numB == 2: print(c) break if ch[numB] == 1: print(-1) break c += 1 ch[numB] = 1
s658482086
p03680
u971672726
1498354423
Python
Python (3.4.3)
py
Runtime Error
251
8048
335
import sys def push(i, count): if buttons[i] == 2: print(count) sys.exit() elif buttons[i] in already: print('-1') sys.exit() else: already.append(i + 1) push(buttons[i] - 1, count + 1) N = int(input()) buttons = [] already = [] count = 0 for i in range(N): buttons.append(int(input()...
s130169788
p03680
u581309643
1498353752
Python
Python (3.4.3)
py
Runtime Error
209
7852
304
N = int(input()) a = [int(input()) for i in range(N)] ch = [0] * 10**5 ch[1] = 1 if a[0] == 1 or a[1] == 2: print(-1) numB = 1 c = 1 while True: numB = a[numB-1] if numB == 2: print(c) break if ch[numB] == 1: print(-1) break c += 1 ch[numB] = 1
s927207876
p03680
u894844146
1498353596
Python
Python (3.4.3)
py
Runtime Error
35
3440
183
n=int(input()) a=[0]*10007 for i in range(n): a[i+1]=int(input()) cnt=0 needle=1 while not(needle==2 or cnt >10007): needle=a[needle] cnt+=1 if cnt>10001: cnt=-1 print(cnt)
s461738187
p03680
u894844146
1498353192
Python
Python (3.4.3)
py
Runtime Error
35
3440
149
n=int(input()) a=[0]*10007 for i in range(n): a[i+1]=int(input()) cnt=0 needle=1 while not(needle==2 or cnt >10007): needle=a[needle] cnt+=1
s395003242
p03681
u581403769
1598048579
Python
Python (3.8.2)
py
Runtime Error
28
8924
292
n, m = map(int, input().split()) import math if n == m: dog = math.factorial(n) mon = math.factorial(m) ans = dog * mon * 2 elif n == m + 1 or n == m - 1: dog = math.factorial(n) mon = math.factorial(m) ans = dog * mon else: ans = 0 print(ans // (10 ** 9 + 7))
s924607995
p03681
u962330718
1597939560
Python
Python (3.8.2)
py
Runtime Error
432
10812
276
from math import factorial N,M=map(int,input().split()) ans=0 if abs(N-M)>1: ans=0 else: if N==M: a=N b=M ans=factorial(a)*factorial(b)*2 else: a=max(N,M) b=min(N,M) ans=factorial(a)*facotrial(b) print(ans%(10**9+7))
s567654743
p03681
u739843002
1597906449
Python
Python (3.8.2)
py
Runtime Error
32
9592
347
def main(): N, M = [int(n) for n in input().split(" ")] if abs(N - M) > 2: print(0) elif abs(N - M) == 1: print((factorial(N) * factorial(M)) % 1000000007) else: print((factorial(N) * factorial(M) * 2) % 1000000007) def factorial(n): if n > 1: return (n * factorial(n - 1)) % 1000000007 els...
s371137685
p03681
u739843002
1597906221
Python
Python (3.8.2)
py
Runtime Error
27
9660
347
def main(): N, M = [int(n) for n in input().split(" ")] if abs(N - M) > 2: print(0) elif abs(N - M) == 1: print((factorial(N) * factorial(M)) % 1000000007) else: print((factorial(N) * factorial(M) * 2) % 1000000007) def factorial(n): if n > 1: return (n * factorial(n - 1)) % 1000000007 els...
s363757497
p03681
u786020649
1595819927
Python
Python (3.8.2)
py
Runtime Error
24
8920
304
def main(): p=10**9+7 def modpfac(n): ret=1 for i in range(1,n+1): ret*=i % p return ret n,m=map(int,input().split()) if abs(m-n)>1: return print(0) elif abs(m-n)=1: return print(modpfac(n)*modpfac(m)%p) else: return print(2*modpfac(n)*modpfac(m)%p) main()
s101626761
p03681
u813387707
1594995237
Python
Python (3.8.2)
py
Runtime Error
2205
9332
278
n, m = sorted([int(x) for x in input().split()]) gap = m - n if gap > 1: print(0) exit() mod = 10 ** 9 + 7 f = 1 for i in range(2, m + 1): f *= i if i == n: f_n = f % mod f_m = f % mod ans = f_n * f_m % mod if gap == 0: ans = ans * 2 % mod print(ans)
s202489364
p03681
u512266180
1594690740
Python
Python (3.8.2)
py
Runtime Error
28
9080
345
ans = 1 if abs(N-M) >= 2: print(0) elif abs(N-M) == 1: for i in range(1,min(N,M)+1): ans *= i ans = ans % (10**9 + 7) ans = ans**2 * max(N,M) ans = ans % (10**9 + 7) print(ans) elif abs(N-M) == 0: for i in range(1,N+1): ans *= i ans = ans % (10**9 + 7) ans = ans**2 ans *= 2 ans = ans %...
s349774298
p03681
u976225138
1594616307
Python
Python (3.8.2)
py
Runtime Error
23
8844
205
from math import factorial as f n, m = map(int(), input().split()) if n == m: print((f(n) ** 2 * 2) % (10 ** 9 + 7)) elif abs(n - m) == 1: print((f(n) * f(m)) % (10 ** 9 + 7)) else: print(0)
s645316177
p03681
u823885866
1594339281
Python
Python (3.8.2)
py
Runtime Error
23
8952
598
import sys import math import itertools import collections import heapq import re import numpy as np from functools import reduce rr = lambda: sys.stdin.readline().rstrip() rs = lambda: sys.stdin.readline().split() ri = lambda: int(sys.stdin.readline()) rm = lambda: map(int, sys.stdin.readline().split()) rl = lambda: ...
s637646091
p03681
u131881594
1592594912
Python
Python (3.8.2)
py
Runtime Error
31
10316
311
n,m=map(int,input().split()) if abs(n-m)>1: print(0) else: mod=10**9+7 fac=[0]*(n+1) fac[0]=1 fac[1]=1 def fact(k): if fac[k]>0: return fac[k] fac[k]=k*fact(k-1)%mod return fac[k] ans=(fact(n)*fact(m))%mod if n==m: print((2*ans)%mod) else: print(ans)
s640806833
p03681
u131881594
1592594730
Python
Python (3.8.2)
py
Runtime Error
30
9436
305
n,m=map(int,input().split()) if abs(n-m)>1: print(0) else: mod=10**9+7 fac=[0]*n fac[0]=1 fac[1]=1 def fact(n): if fac[n]>0: return fac[n] fac[n]=n*fact(n-1)%mod return fac[n] ans=(fac(n)*fac(m))%mod if n==m: print((2*ans)%mod) else: print(ans)
s071940733
p03681
u670961163
1592486271
Python
Python (3.4.3)
py
Runtime Error
442
4088
491
def main(): import math n, m = map(int, input().split()) if n - m <= -2 or n - m >= 2: print(0) exit() else: if n < m: n, m = m, n else: if n != m: ans = math.factorial(n) % (10*9 + 7) * math.factorial(m) % (10**9 + 7) ...
s318035232
p03681
u285891772
1591280018
Python
Python (3.4.3)
py
Runtime Error
85
9552
1140
import sys, re from collections import deque, defaultdict, Counter from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2 from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby from operator import itemgetter, mu...
s770831895
p03681
u312078744
1590906564
Python
Python (3.4.3)
py
Runtime Error
17
3060
263
import math n, m = map(int, input().split()) dif = abs(n - m) if (diff > 1): print(0) else: x = math.factorial(n) y = math.factorial(m) if (n == m): tt = 2 else: tt = 1 ans = tt * (x * y) / (10 ** 9 + 7) print(ans)
s669471719
p03681
u519923151
1590290007
Python
Python (3.4.3)
py
Runtime Error
46
7060
249
n,m = map(int, input().split()) if abs(n-m) >1: print(0) exit() p = 10**9+7 fact =[1,1] for i in range(2, n + 1): fact.append((fact[-1] * i) % p) if n ==m: res = fact[n]*fact[m]*2 else: res = fact[n]*fact[m] print(res%p)
s407684604
p03681
u630511239
1590200971
Python
Python (3.4.3)
py
Runtime Error
75
3956
528
N, M = map(int, input().split()) import math def facto(n,m): if m-n ==1: return m*n elif m-n == 2: return m*(m-1)*n elif (m-n)%2 ==1: s = facto(n,(n+m-1)/2) t = facto((n+m+1)/2,m) return s*t else: s = facto(n,(n+m)/2) t = facto((n+m)/2+1,m) return s*t n = 1 m = 1 if N - M == -...
s506942611
p03681
u057964173
1589830661
Python
PyPy3 (2.4.0)
py
Runtime Error
170
38384
437
import sys def input(): return sys.stdin.readline().strip() def resolve(): n=int(input()) l=[int(input()) for i in range(n)] light=0 cnt=0 while True: if l[light]==2: cnt+=1 print(cnt) break else: if cnt>n: print(-1) ...
s763349071
p03681
u492447501
1589723163
Python
Python (3.4.3)
py
Runtime Error
2106
89812
246
import sys sys.setrecursionlimit(100000) def f(n): if n==1: return 1 return n*f(n-1) N,M = map(int, input().split()) if abs(N-M)>=2: print(0) elif abs(N-M)==1: print(f(N)*f(M)) else: print((2*f(N)*f(M))%(10**9+7))
s304038561
p03681
u851704997
1589645437
Python
Python (3.4.3)
py
Runtime Error
18
2940
140
import math N,M = int(input()) if(N == 1 or M == 1): print("0") else: print(str(((math.factorial(N) * math.factorial(M))% 10 ** 9 + 7)))
s808742727
p03681
u114641312
1589229161
Python
Python (3.4.3)
py
Runtime Error
18
3064
427
from math import factorial,sqrt,ceil,gcd N,M = map(int,input().split()) MOD = 10**9 + 7 if abs(N-M)>=2: print(0) exit() if N==M: ans = factorial(N) % MOD ans = ans * factorial(M) % MOD ans = ans * 2 % MOD print(ans) exit() elif N>M: ans = factorial(N) % MOD * factorial(M) % MOD ...
s297356557
p03681
u135116520
1589079536
Python
Python (3.4.3)
py
Runtime Error
38
3060
222
N,M=map(int,input().split()) MOD=10**9+7 s=1 for i in range(2,N+1): s=(s*i)%MOD t=1 for i in range(2,M+1): t=(t*j)%MOD if abs(N-M)>1: print(0) exit() if abs(N-M)==1: print((s*t)%MOD) else: print((2*s*t)%MOD)
s056912420
p03681
u135116520
1589078440
Python
Python (3.4.3)
py
Runtime Error
17
3064
217
N.M=map(int,input().split()) MOD=10**9+7 s=1 for i in range(2,N+1): s=s*i t=1 for j in range(2,N+1): t=t*j if N-1==M: print((s*t)%MOD) if N==M-1: print((s*t)%MOD) if N==M: print((2*s*t)%MOD) else: print(0)
s209253133
p03681
u652656291
1588381721
Python
Python (3.4.3)
py
Runtime Error
18
3060
240
import math n,m = map(int.input().split()) nm_abs = abs(n-m) n_lad = math.factorial(n) m_lad = math.factorial(m) if nm_abs >= 2: print(0) elif nm_abs == 1: print((n_lad * m_lad) % (10**9+7)) else: print((n_lad * m_lad*2) % (10**9+7))
s060930380
p03681
u423665486
1588129953
Python
Python (3.4.3)
py
Runtime Error
18
3060
208
def resolve(): n, m = map(int, input().split()) mod = 10**9+7 if abs(n - m) > 1: print(0) return a = factorial(m) % mod * factorial(n) % mod if (n + m) % 2 == 0: a = a * 2 % mod print(a) resolve()
s496659139
p03681
u459150945
1588046945
Python
Python (3.4.3)
py
Runtime Error
702
5180
182
import math mod = 10e+9 + 7 n, m = map(int, input().split()) ans = math.factorial(n)*math.factorial(m) if abs(n-m) > 1: ans = 0 elif abs(n-m) == 0: ans *= 2 print(ans % mod)
s727775732
p03681
u459150945
1588046766
Python
Python (3.4.3)
py
Runtime Error
230
4028
264
import math mod = 10e+9 + 7 n, m = map(int, input().split()) if abs(n-m) > 1: ans = 0 elif abs(n-m) == 1: ans = (math.factorial(n) % mod)*(math.factorial(m) % mod) else: ans = (math.factorial(n) % mod)*(math.factorial(m) % mod)*2 print(int(ans % mod))
s171191459
p03681
u298633786
1587182501
Python
Python (3.4.3)
py
Runtime Error
17
3064
323
N, M = map(int, input().split()) MOD = 1_000_000_007 if abs(N - M) > 1: print(0) exit(0) dogs = 1 for i in range(1, N + 1): dogs *= i dogs %= MOD monks = 1 for i in range(1, M + 1): monks *= i monks %= MOD res = (dogs * monks) % MOD if (N + M) % 2 == 0: res *= 2 res %= MOD print(re...
s943116570
p03681
u298633786
1587182480
Python
PyPy3 (2.4.0)
py
Runtime Error
167
38384
323
N, M = map(int, input().split()) MOD = 1_000_000_007 if abs(N - M) > 1: print(0) exit(0) dogs = 1 for i in range(1, N + 1): dogs *= i dogs %= MOD monks = 1 for i in range(1, M + 1): monks *= i monks %= MOD res = (dogs * monks) % MOD if (N + M) % 2 == 0: res *= 2 res %= MOD print(re...
s181305882
p03681
u423585790
1587139762
Python
PyPy3 (2.4.0)
py
Runtime Error
188
44912
277
mod = 10 ** 9 + 7 fact = [i for i in range(10**5)] fact[0] = 1 for i in range(10 ** 5-1): fact[i+1] *= fact[i] fact[i+1] %= mod n,m = map(int,input().split()) if abs(n-m)>1: print(0) else: if n!=m: print(fact[n]*fact[m]%mod) else: print(fact[n]*fact[m]*2%mod)