Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))
 
A1 = []
A2 = []
 
for i in range(N):
    A1.append(i + A[i])
    A2.append(i - A[i])
 
count = 0
for i in A1:
    count += A2.count(i)
        
print(count)

Fixed submission:
import collections
 
N = int(input())
A = list(map(int, input().split()))

A1 = []
A2 = []

for i in range(N):
    A1.append(i + A[i])
    A2.append(i - A[i])

C_A1 = collections.Counter(A1)
C_A2 = collections.Counter(A2)
ans = 0
for i in range(N):
    ans += C_A1[i]*C_A2[i]
    
print (ans)

Buggy python submission (verdict: Time Limit Exceeded):
import collections
 
N = int(input())
A = list(map(int, input().split()))

A1 = []
A2 = []

for i in range(N):
    A1.append(i + A[i])
    A2.append(i - A[i])

count = 0
for i in A1:
    for j in A2:
        if i ==j:
            count +=1
print(count)

Fixed submission:
import collections
 
N = int(input())
A = list(map(int, input().split()))

A1 = []
A2 = []

for i in range(N):
    A1.append(i + A[i])
    A2.append(i - A[i])

C_A1 = collections.Counter(A1)
C_A2 = collections.Counter(A2)
ans = 0
for i in range(N):
    ans += C_A1[i]*C_A2[i]
    
print (ans)

Buggy python submission (verdict: Time Limit Exceeded):
import itertools

N = list(range(int(input())))
A = list(map(int, input().split()))
count = 0

for i, j in itertools.combinations(N, 2):
    if j - i == A[i] + A[j]:
        count += 1
        
print(count)

Fixed submission:
import collections
 
N = int(input())
A = list(map(int, input().split()))

A1 = []
A2 = []

for i in range(N):
    A1.append(i + A[i])
    A2.append(i - A[i])

C_A1 = collections.Counter(A1)
C_A2 = collections.Counter(A2)
ans = 0
for i in range(N):
    ans += C_A1[i]*C_A2[i]
    
print (ans)
Buggy python submission (verdict: Time Limit Exceeded):
import itertools
import math
 
K = int(input())
l = range(1, K+1)
ans = 0
 
for a, b, c in itertools.product(l, repeat=3):
    ans += math.gcd(math.gcd(a, b), c)
 
print(ans)

Fixed submission:
import itertools
import math
 
K = int(input())
l = range(1, K+1)
ans = sum(l)
 
for a, b in itertools.combinations(l, 2):
    ans += math.gcd(a, b) * 6
 
for a, b, c in itertools.combinations(l, 3):
    ans += math.gcd(math.gcd(a,b), c)*6
    
        
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import itertools
from fractions import gcd
 
K = int(input())
l = range(1, K+1)
ans = sum(l)
 
for a, b in itertools.combinations(l, 2):
    ans += gcd(a, b) * 6
 
for a, b, c in itertools.combinations(l, 3):
    ans += gcd(gcd(a, b), c) * 6
        
print(ans)

Fixed submission:
import itertools
import math
 
K = int(input())
l = range(1, K+1)
ans = sum(l)
 
for a, b in itertools.combinations(l, 2):
    ans += math.gcd(a, b) * 6
 
for a, b, c in itertools.combinations(l, 3):
    ans += math.gcd(math.gcd(a,b), c)*6
    
        
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import itertools
from fractions import gcd

K = int(input())
l = range(1, K+1)
ans = 0

for a, b, c in itertools.product(l, repeat=3):
    ans += gcd(gcd(a, b), c)

print(ans)


Fixed submission:
import itertools
import math
 
K = int(input())
l = range(1, K+1)
ans = sum(l)
 
for a, b in itertools.combinations(l, 2):
    ans += math.gcd(a, b) * 6
 
for a, b, c in itertools.combinations(l, 3):
    ans += math.gcd(math.gcd(a,b), c)*6
    
        
print(ans)
Buggy python submission (verdict: Runtime Error):
L = input()
 
l = L / 3
 
print(l ** 3)

Fixed submission:
from decimal import Decimal

L = input()

l = Decimal(L) / 3

print(l ** 3)
Buggy python submission (verdict: Time Limit Exceeded):
S = input()
Q = int(input())

for _ in range(Q):
    q = input().split()
    if q[0] == "1":
        S = S[::-1]
    elif q[1] == "1":
        S = q[2] + S
    else:
        S = S + q[2]
        
print(S)

Fixed submission:
from collections import deque


S = deque(input())
Q = int(input())
flag = 1

for _ in range(Q):
    q = input().split()
    if q[0] == "1":
        flag *= -1
    elif q[1] == "1":
        if flag == 1:
            S.appendleft(q[2])
        else:
            S.append(q[2])
    else:
        if flag == 1:
            S.append(q[2])
        else:
            S.appendleft(q[2])
s = list(S)
if flag == 1:
    print("".join(s))
else:
    for i in reversed(s):
        print(i, end="")
Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int,input().split())
p = list(map(int,input().split()))

max_p = 0

for i in range(N - K + 1):
    max_p = max(sum(p[i:i+K]),max_p)

ex = (max_p - K + 2)/2

print(ex + K - 1)

Fixed submission:
N, K = map(int,input().split())
p = list(map(int,input().split()))

sum_p = 0

for i in range(K):
    sum_p += p[i]

max_p = sum_p

for j in range(K,N):
    sum_p -= p[j - K]
    sum_p += p[j]
    max_p = max(max_p,sum_p)

ex = (max_p - K + 2)/2

print(ex + K - 1)

Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int,input().split())
p = list(map(int,input().split()))

sum_p = []

for i in range(N - K + 1):
    sum_p.append(sum(p[i:i+K]))
    

ex = (max(sum_p)-K+2)/2

print(ex + K - 1)

Fixed submission:
N, K = map(int,input().split())
p = list(map(int,input().split()))

sum_p = 0

for i in range(K):
    sum_p += p[i]

max_p = sum_p

for j in range(K,N):
    sum_p -= p[j - K]
    sum_p += p[j]
    max_p = max(max_p,sum_p)

ex = (max_p - K + 2)/2

print(ex + K - 1)

Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int,input().split())
p = list(map(int,input().split()))

sum_p = []

for i in range(N - K + 1):
    sum_p.append(sum(p[i:i+K]))
    

ex = sum(list(range(1,max(sum_p)-K+2))) / (max(sum_p)-K+1)

print(ex + K - 1)

Fixed submission:
N, K = map(int,input().split())
p = list(map(int,input().split()))

sum_p = 0

for i in range(K):
    sum_p += p[i]

max_p = sum_p

for j in range(K,N):
    sum_p -= p[j - K]
    sum_p += p[j]
    max_p = max(max_p,sum_p)

ex = (max_p - K + 2)/2

print(ex + K - 1)

Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int,input().split())
p = list(map(int,input().split()))

sum_p = []

for i in range(N - K + 1):
    sum_p.append(sum(p[i:i+K]))
    

ex = sum(list(range(1,max(sum_p)-K+2))) / (max(sum_p)-K+1)

print(ex + K - 1)

Fixed submission:
N, K = map(int,input().split())
p = list(map(int,input().split()))

sum_p = 0

for i in range(K):
    sum_p += p[i]

max_p = sum_p

for j in range(K,N):
    sum_p -= p[j - K]
    sum_p += p[j]
    max_p = max(max_p,sum_p)

ex = (max_p - K + 2)/2

print(ex + K - 1)

Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int,input().split())
p = list(map(int,input().split()))

sum_p = []

for i in range(N - K + 1):
    sum_p.append(sum(p[i:i+K]))
    

ex = 0

for x in range(1,max(sum_p)-K+2):
    ex += x / (max(sum_p)-K+1)

print(ex + K - 1)

Fixed submission:
N, K = map(int,input().split())
p = list(map(int,input().split()))

sum_p = 0

for i in range(K):
    sum_p += p[i]

max_p = sum_p

for j in range(K,N):
    sum_p -= p[j - K]
    sum_p += p[j]
    max_p = max(max_p,sum_p)

ex = (max_p - K + 2)/2

print(ex + K - 1)
Buggy python submission (verdict: Time Limit Exceeded):
H,N = list(map(int, input().split()))
As = []
Bs = []
for _ in range(N):
    a, b = list(map(int, input().split()))
    As.append(a)
    Bs.append(b)
    
DP =[0]*(H+1)

for i in range(1,H+1):
    dp = []
    for j in range(len(As)):
        
        if i-As[j]>=0:
            dp.append(DP[i-As[j]] + Bs[j])
        else:
            dp.append(Bs[j])
    DP[i] = min(dp)        

print(DP[-1])

Fixed submission:
import numpy as np
 
H,N = list(map(int, input().split()))
A = []
B = []
for _ in range(N):
    a, b = list(map(int, input().split()))
    A.append(a)
    B.append(b)

A = np.array(A)
B = np.array(B)
DP = np.zeros(H+1)

for i in range(1,H+1):
    DP[i] = np.amin(DP[np.maximum(i - A, 0)] + B)
    
print(int(DP[-1]))
Buggy python submission (verdict: Time Limit Exceeded):
import itertools
 
N = int(input())
S = [int(c) for c in input()]
 
a = [b for b in itertools.combinations(S, 3)]
 
print(len(set(a))) 

Fixed submission:
N = int(input())
S = [int(c) for c in input()]

count = 0

for i in range(10):
    if i in S[:N-2]:
        a = S.index(i)
        for j in range(10):
            if j in S[a+1:N-1]:
                b = S[a+1:N-1].index(j) +a+1
                for k in range(10):
                    if k in S[b+1:]:
                        count +=1
print(count)

Buggy python submission (verdict: Time Limit Exceeded):
import itertools

def get_unique_list(seq):
    seen = []
    return [x for x in seq if x not in seen and not seen.append(x)]

N = int(input())
S = [int(c) for c in input()]

a = [b for b in itertools.combinations(S, 3)]

print(len(get_unique_list(a))) 

Fixed submission:
N = int(input())
S = [int(c) for c in input()]

count = 0

for i in range(10):
    if i in S[:N-2]:
        a = S.index(i)
        for j in range(10):
            if j in S[a+1:N-1]:
                b = S[a+1:N-1].index(j) +a+1
                for k in range(10):
                    if k in S[b+1:]:
                        count +=1
print(count)
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = list(map(int,input().split()))

c = [0]*3

a = 1

for i in A:
    a *= c.count(i)
    c[c.index(i)] += 1
    
print(a%1000000007)    

Fixed submission:
N = int(input())
A = list(map(int,input().split()))

c = [0]*3

a = 1

for i in A:
    if c.count(i) != 0:
        a *= c.count(i)
        c[c.index(i)] += 1
    
    else:
        print(0)
        break
else:
    print(a%1000000007)
Buggy python submission (verdict: Runtime Error):
import math
import numpy as np

x,y = map(int,input().split()) 

A = np.array([[1, 2],
             [2, 1]])

b = np.array([x, y])
 
sol_auto = np.linalg.solve(A, b)


if sol_auto[0].is_integer() == True and sol_auto[1].is_integer() == True:
    k = math.factorial(sol_auto[0]+sol_auto[1])/(math.factorial(sol_auto[0])*math.factorial(sol_auto[1]))

    print(int(k%1000000007))
else:
    print(0)

Fixed submission:
import math
import numpy as np

def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 
N = 10**6
g1 = [1, 1] 
g2 = [1, 1] 
inverse = [0, 1] 

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )





x,y = map(int,input().split()) 

if (x+y) % 3 == 0:

    A = np.array([[1, 2],
                  [2, 1]])

    b = np.array([x, y])

    N = np.linalg.solve(A, b)


    if N[0].is_integer() == True and N[1].is_integer() == True and N[0] >=0 and N[1] >=0:
          
        print(cmb(int(N[0]+N[1]),int(N[0]),mod))

    else:
        print(0)

else:
    print(0)

Buggy python submission (verdict: Runtime Error):
import math
import numpy as np

x,y = map(int,input().split()) 

A = np.array([[1, 2],
             [2, 1]])

b = np.array([x, y])
 
sol_auto = np.linalg.solve(A, b)


if sol_auto[0].is_integer() == True and sol_auto[1].is_integer() == True:
    k = math.factorial(sol_auto[0]+sol_auto[1])/(math.factorial(sol_auto[0])*math.factorial(sol_auto[1]))

    print(int(k%1000000007))
else:
    print(0)

Fixed submission:
import math
import numpy as np

def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 
N = 10**6
g1 = [1, 1] 
g2 = [1, 1] 
inverse = [0, 1] 

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )





x,y = map(int,input().split()) 

if (x+y) % 3 == 0:

    A = np.array([[1, 2],
                  [2, 1]])

    b = np.array([x, y])

    N = np.linalg.solve(A, b)


    if N[0].is_integer() == True and N[1].is_integer() == True and N[0] >=0 and N[1] >=0:
          
        print(cmb(int(N[0]+N[1]),int(N[0]),mod))

    else:
        print(0)

else:
    print(0)
Buggy python submission (verdict: Runtime Error):
import itertools

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


a = list(itertools.combinations(l, 3))
b = []

for i in a:
    b.append(tuple(sorted(i)))

c = list(set(b))

count = 0

for i in c:
    if i[0] < i[1] + i[2] and i[1] < i[0] + i[2] and i[2] < i[0] + i[1]:
        count += 1

print(count)        

Fixed submission:
n = int(input())
s = list(input())

ans = 1

for i in range(n-1):
    if s[i] == s[i+1]:
        continue
    else:
        ans += 1

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
left = 0
right = 0
for i in range(n):
  left += a[i]
  left %= (10**9+7)
for j in range(n):
  right += a[j]
  right %= (10**9+7)
c = (left*right)%(10**9+7)
l = [(k**2)%(10**9+7) for k in a]
print(((c+(10**9+7)-sum(l))**(10**9+5))%(10**9+7))

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
left = 0
right = 0
for i in range(n):
  left += a[i]
  left %= (10**9+7)
for j in range(n):
  right += a[j]
  right %= (10**9+7)
c = (left*right)%(10**9+7)
l = [(k**2)%(10**9+7) for k in a]
print(((c+(10**9+7)-sum(l)%(10**9+7))*pow(2, 10**9+5, 10**9+7))%(10**9+7))

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
c = 0
for i in range(0,n-1):
  for j in range(i+1,n):
    c += (a[i]%(10**9+7))*(a[j]%(10**9+7))%(10**9+7)
    c %= (10**9+7)
print(c)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
left = 0
right = 0
for i in range(n):
  left += a[i]
  left %= (10**9+7)
for j in range(n):
  right += a[j]
  right %= (10**9+7)
c = (left*right)%(10**9+7)
l = [(k**2)%(10**9+7) for k in a]
print(((c+(10**9+7)-sum(l)%(10**9+7))*pow(2, 10**9+5, 10**9+7))%(10**9+7))

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = [int(_)%(10**9+7) for _ in input().split()]
c = 0
for i in range(0,n-1):
  for j in range(i+1,n):
    c += (a[i]%(10**9+7))*(a[j]%(10**9+7))
    c %= (10**9+7)
print(c)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
left = 0
right = 0
for i in range(n):
  left += a[i]
  left %= (10**9+7)
for j in range(n):
  right += a[j]
  right %= (10**9+7)
c = (left*right)%(10**9+7)
l = [(k**2)%(10**9+7) for k in a]
print(((c+(10**9+7)-sum(l)%(10**9+7))*pow(2, 10**9+5, 10**9+7))%(10**9+7))

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
c = 0
for i in range(0,n-1):
  for j in range(i+1,n):
    c += (a[i]%(10**9+7))*(a[j]%(10**9+7))
    c %= (10**9+7)
print(c)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
left = 0
right = 0
for i in range(n):
  left += a[i]
  left %= (10**9+7)
for j in range(n):
  right += a[j]
  right %= (10**9+7)
c = (left*right)%(10**9+7)
l = [(k**2)%(10**9+7) for k in a]
print(((c+(10**9+7)-sum(l)%(10**9+7))*pow(2, 10**9+5, 10**9+7))%(10**9+7))

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
c = 0
for i in range(0,n-1):
  for j in range(i+1,n):
    c += a[i]*a[j]%(10**9+7)
    c %= (10**9+7)
print(c)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
left = 0
right = 0
for i in range(n):
  left += a[i]
  left %= (10**9+7)
for j in range(n):
  right += a[j]
  right %= (10**9+7)
c = (left*right)%(10**9+7)
l = [(k**2)%(10**9+7) for k in a]
print(((c+(10**9+7)-sum(l)%(10**9+7))*pow(2, 10**9+5, 10**9+7))%(10**9+7))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
l = list(map(int, input().split()))
c = 1
for i in l:
  c *= i
if c <= 1000000000000000000:
  print(c)
else:
  print(-1)

Fixed submission:
n = int(input())
l = list(map(int, input().split()))
l.sort()
c = 1
i = 0
while i < n:
  c *= l[i]
  i += 1
  if c > 1000000000000000000:
    break
if c <= 1000000000000000000:
  print(c)
else:
  print(-1)
Buggy python submission (verdict: Runtime Error):
k = int(input())
a,b = map(int, input().split)
largest = (b//k)*k
print("OK" if largest >= a else "NG")

Fixed submission:
k = int(input())
a,b = map(int, input().split())
largest = (b//k)*k
print("OK" if largest >= a else "NG")
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
number = [a.count(i) for i in range(1,n)]
for j in range(n-1):
  print(number[j])
print(0)

Fixed submission:
import collections
n = int(input())
a = list(map(int, input().split()))
c = collections.Counter(a)
for i in range(1,n+1):
  print(c[i])

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
number = []
for i in range(1,n):
  number.append(a.count(i))
  print(number[i-1])
print(0)

Fixed submission:
import collections
n = int(input())
a = list(map(int, input().split()))
c = collections.Counter(a)
for i in range(1,n+1):
  print(c[i])

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
number = []
for i in range(1,n):
  number.append(a.count(i))
for i in range(n-1):
  print(number[i])
print(0)

Fixed submission:
import collections
n = int(input())
a = list(map(int, input().split()))
c = collections.Counter(a)
for i in range(1,n+1):
  print(c[i])
Buggy python submission (verdict: Runtime Error):
n = int(input())
s = input()
c = 0
if n <= 2:
  print(0)
else:
  for i in range(2,n+1):
    if s[i-2] == "A" and s[i-1] == "B" and s[i] == "C":
      c += 1
  print(c)

Fixed submission:
n = int(input())
s = input()
c = 0
for i in range(2,n):
  if s[i-2] == "A" and s[i-1] == "B" and s[i] == "C":
    c += 1
print(c)

Buggy python submission (verdict: Runtime Error):
n = int(input())
s = input()
c = 0
for i in range(2,n+1):
  if s[i-2] == "A" and s[i-1] == "B" and s[i] == "C":
    c += 1
print(c)

Fixed submission:
n = int(input())
s = input()
c = 0
for i in range(2,n):
  if s[i-2] == "A" and s[i-1] == "B" and s[i] == "C":
    c += 1
print(c)
Buggy python submission (verdict: Runtime Error):
r = int((input))
print(r**2)

Fixed submission:
r = int(input())
print(r**2)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
ans = [0]*n
for i in range(n):
  x = a.index(i+1)
  ans[i] = str(x+1)
print(" ".join(ans))

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
ans = [0]*n
for i in range(n):
  ans[a[i]-1] += i+1
  ans[a[i]-1] = str(ans[a[i]-1])
print(" ".join(ans))

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
ans = [0 for _ in range(n)]
for i in range(n):
  x = a.index(i+1)
  ans[i] = str(x+1)
print(" ".join(ans))

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
ans = [0]*n
for i in range(n):
  ans[a[i]-1] += i+1
  ans[a[i]-1] = str(ans[a[i]-1])
print(" ".join(ans))

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
l = [_+1 for _ in range(n)]
ans = [0 for _ in range(n)]
for i in range(n):
  x = a.index(l[i])
  ans[i] = str(x+1)
print(" ".join(ans))

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
ans = [0]*n
for i in range(n):
  ans[a[i]-1] += i+1
  ans[a[i]-1] = str(ans[a[i]-1])
print(" ".join(ans))
Buggy python submission (verdict: Time Limit Exceeded):
n,m = map(int, input().split())
s = {_ for _ in range(1,n+1)}
for i in range(m):
  l,r = map(int, input().split())
  s &= {_ for _ in range(l,r+1)}
print(len(s))

Fixed submission:
n,m = map(int, input().split())
left = set()
right = set()
for i in range(m):
  l,r = map(int, input().split())
  left.add(l)
  right.add(r)
mini = max(left)
maxi = min(right)
print(len(range(mini,maxi+1)))
Buggy python submission (verdict: Runtime Error):
a,b,c,d = map(int, input().split())
if abs(a-c) <= d or (abs(a-b) <= d and abs(b-c) <= d):
  print("Yes")
else:
  print("No")

Fixed submission:
a,b = map(int, input().split())
if a <= b:
  print(a)
else:
  print(a-1)
Buggy python submission (verdict: Time Limit Exceeded):
a,b,k = map(int, input().split())
set0 = set(a+h for h in range(b-a+1))
setA = set(a+i for i in range(k))
setB = set(b-j for j in range(k))
l = list(set0&(setA|setB))
l.sort()
for k in l:
  print(k)

Fixed submission:
a,b,k = map(int, input().split())
setA = set(i for i in range(a,min(a+k,b+1)))
setB = set(j for j in range(b,max(b-k,a-1),-1))
l = list(setA|setB)
l.sort()
for m in l:
  print(m)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
l = [0 for _ in range(n)]
already = []
next = 1
c = 0
for i in range(n):
  a = int(input())
  l[i] = a
while c <= n:
  next = l[next-1]
  c += 1
  if next == 2:
    print(c)
    break
  elif next in already:
    print(-1)
    break
  already.append(next)

Fixed submission:
n = int(input())
l = [0 for _ in range(n)]
already = set()
next = 1
c = 0
for i in range(n):
  a = int(input())
  l[i] = a
while c <= n:
  next = l[next-1]
  c += 1
  if next == 2:
    print(c)
    break
  elif next in already:
    print(-1)
    break
  already.add(next)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
l = []
already = []
next = 1
c = 0
for i in range(n):
  a = int(input())
  l.append(a)
while True:
  next = l[next-1]
  c += 1
  if next == 2:
    print(c)
    break
  elif next in already:
    print(-1)
    break
  already.append(next)

Fixed submission:
n = int(input())
l = [0 for _ in range(n)]
already = set()
next = 1
c = 0
for i in range(n):
  a = int(input())
  l[i] = a
while c <= n:
  next = l[next-1]
  c += 1
  if next == 2:
    print(c)
    break
  elif next in already:
    print(-1)
    break
  already.add(next)
Buggy python submission (verdict: Runtime Error):
n,m = map(int, input().split())
st = []
pt = []
ch = []
for i in range(n):
  st.append(list(map(int, input().split())))
for i in range(n):
  pt.append(list(map(int, input().split())))
for j in st:
  for k in pt:
    d = abs(j[0]-k[0]) + abs(j[1]-k[1])
    ch.append(d)
  print(ch.index(min(ch))+1)
  ch = []

Fixed submission:
n,m = map(int, input().split())
st = []
pt = []
ch = []
for i in range(n):
  st.append(list(map(int, input().split())))
for i in range(m):
  pt.append(list(map(int, input().split())))
for j in st:
  for k in pt:
    d = abs(j[0]-k[0]) + abs(j[1]-k[1])
    ch.append(d)
  print(ch.index(min(ch))+1)
  ch = []
Buggy python submission (verdict: Time Limit Exceeded):
k,s = map(int, input().split())
c = 0
for x in range(k+1):
  for y in range(x,k+1):
    for z in range(y,k+1):
      if x+y+z == s:
        if x == y == z:
          c += 1
        elif (x == y and y != z) or (x != y and y == z):
          c += 3
        else:
          c += 6
print(c)

Fixed submission:
k,s = map(int, input().split())
c = 0
for x in range(k+1):
  for y in range(k+1):
    if 0 <= s-x-y <= k:
      c += 1
print(c)