Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
import math

def isPrime(num):
    if num < 2:
        return False
    else:
        rootNum = math.floor(math.sqrt(num))
        for i in range(2,rootNum+1):
            if num % i == 0:
                return False
    return True

def solve():
    lst = []
    count = int(input())
    for i in range(count):
        ans = 0
        l, r = map(int, input().split())
        t = l
        while k <= r
            if isPrime(k) and isPrime((k+1)/2):
                ans += 1
            k += 2
        lst.append(str(ans))
    print('\n'.join(lst))
solve()


Fixed submission:
print("{}".format(24 - int(input()) + 24))

Buggy python submission (verdict: Runtime Error):
i = input()
i = 24+i
print("{}".format(i))

Fixed submission:
print("{}".format(24 - int(input()) + 24))

Buggy python submission (verdict: Runtime Error):
i = input()
print(24+i)

Fixed submission:
print("{}".format(24 - int(input()) + 24))
Buggy python submission (verdict: Runtime Error):

a,b,k=map(int, input().split())

l = list(range(a,b+1))

x = list()
for i in range(0, min([k,len(l)])):
  x.append(l[i])
  x.append(l[-i-1])

for xx in sorted(set(x)):
  print(xx)


Fixed submission:
a,b,k=map(int, input().split())

x = list()
for i in range(a, a+min([k,b+1-a])):
  #print(i)
  x.append(i)
#print('---')
for i in range(b-min([k,b+1-a])+1, b+1):
  #print(i)
  x.append(i)
#print('---')

for xx in sorted(set(x)):
  print(xx)
Buggy python submission (verdict: Time Limit Exceeded):
#coding: utf-8
N = int(input())
A= list(map(int,input().split()))
A = [0] + A + [0]
Adiff = list(range(N+1))
def diff(X):
    diff_x = 0
    for i in range(len(X)-1):
        diff_x += abs(X[i] - X[i+1])
    return diff_x
for i in range(N):
    B = A[:]
    del B[i+1]
    diffB = diff(B)
    print(diffB)


Fixed submission:
#coding: utf-8
N = int(input())
A= list(map(int,input().split()))
A = [0] + A + [0]
def diff(X):
    diff_x = list(range(len(X)-1))
    for i in range(len(X)-1):
        diff_x[i] = abs(X[i] - X[i+1])
    return diff_x
Adiff = diff(A)
SUM = 0
for i in range(len(Adiff)):
    SUM += Adiff[i]
for i in range(N):
    SUMM = SUM
    SUMM += abs(A[i]-A[i+2]) - Adiff[i+1]-Adiff[i]
    print(SUMM)

Buggy python submission (verdict: Time Limit Exceeded):
#coding: utf-8
N = int(input())
A= list(map(int,input().split()))
A = [0] + A + [0]
Adiff = list(range(N+1))
def diff(X):
    diff_x = list(range(len(X)-1))
    for i in range(len(X)-1):
        diff_x[i] = abs(X[i] - X[i+1])
    return diff_x
for i in range(N):
    B = A[:]
    del B[i+1]
    diffB = diff(B)
    SUM = 0
    for j in range(N):
        SUM += diffB[j]
    print(SUM)


Fixed submission:
#coding: utf-8
N = int(input())
A= list(map(int,input().split()))
A = [0] + A + [0]
def diff(X):
    diff_x = list(range(len(X)-1))
    for i in range(len(X)-1):
        diff_x[i] = abs(X[i] - X[i+1])
    return diff_x
Adiff = diff(A)
SUM = 0
for i in range(len(Adiff)):
    SUM += Adiff[i]
for i in range(N):
    SUMM = SUM
    SUMM += abs(A[i]-A[i+2]) - Adiff[i+1]-Adiff[i]
    print(SUMM)
Buggy python submission (verdict: Runtime Error):
A, B, K = map(int, input().split())

list2 = [ A + K - 1 , B - K + 1]
if min(list2) == max(list2):
    list3 = ["-1"]
else:
    list3 = list(range(min(list2)+1,max(list2)))
i = A
while i <= B:
    if i not in list3:
        print(i)
    elif A > B - K:
        print(i)
    i += 1


Fixed submission:
A, B, K = map(int, input().split())

list2 = [ A + K - 1 , B - K + 1]
if A + K - 1 >= B - K +1 or A > B - K:
    i = A
    while i <= B:
        print(i)
        i += 1
else:
    i = A
    while i <= A + K - 1:
        print(i)
        i += 1
    i = B - K + 1
    while i <= B:
        print(i)
        i += 1

Buggy python submission (verdict: Runtime Error):
A, B, K = map(int, input().split())

list2 = [ A + K , B - K]
list3 = list(range(min(list2),max(list2)+1))
i = A
while i <= B:
    if i not in list3:
        print(i)
    elif A > B - K:
        print(i)
    i += 1


Fixed submission:
A, B, K = map(int, input().split())

list2 = [ A + K - 1 , B - K + 1]
if A + K - 1 >= B - K +1 or A > B - K:
    i = A
    while i <= B:
        print(i)
        i += 1
else:
    i = A
    while i <= A + K - 1:
        print(i)
        i += 1
    i = B - K + 1
    while i <= B:
        print(i)
        i += 1
Buggy python submission (verdict: Runtime Error):
s = str(input())

b = s.find("a")
v = s.find("b")
t = s.find("c")

m = int(b) + int(a) + int(c)

if m == 3:
    print("Yes")
if m != 3:
    print("No")

Fixed submission:
s = str(input())

b = s.find("a")
v = s.find("b")
t = s.find("c")

m = int(b) + int(v) + int(t)

if m == 3:
    print("Yes")
if m != 3:
    print("No")
Buggy python submission (verdict: Time Limit Exceeded):

a, b, c = map(int, input().split())
 
for i in range(a, b+1):
    if i<a+c or i>b-c:
        print(i)
    else:
        i += b-a-2*c-2

Fixed submission:

a, b, c = map(int, input().split())

if b - a + 1 > 2 * c:
    for i in range(a, a+c):
        print(i)
    for i in range(b-c+1, b+1):
        print(i)
else:
    for i in range(a, b+1):
        print(i)

Buggy python submission (verdict: Time Limit Exceeded):

a, b, c = map(int, input().split())

for i in range(a, b+1):
    if i<a+c or i>b-c:
        print(i)

Fixed submission:

a, b, c = map(int, input().split())

if b - a + 1 > 2 * c:
    for i in range(a, a+c):
        print(i)
    for i in range(b-c+1, b+1):
        print(i)
else:
    for i in range(a, b+1):
        print(i)
Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-

import numpy as np
import scipy

#N = int(input())
#C = [[0 for i in range(3)] for j in range(3)]
#for i in range(3):
#    C[i] = list(map(int, input().split()))
S = list(map(int, input().split()))
#A, B, C = map(int, input().split())

def plus1(X, Y):
    return X+1, Y+1

def plus2(Z):
    return Z+2

c = 0
S = sorted(S)

while True:
    S[0], S[1] = plus1(S[0], S[1])
    c += 1
    if S[1] == S[2]:
        break

if (S[1] - S[0])%2 != 0:
    S[1], S[2] = plus1(S[1], S[2])
    c += 1

while True:
    S[0] = plus2(S[0])
    c += 1
    if S[0] == S[1]:
        break

print(c)


Fixed submission:
# -*- coding: utf-8 -*-

import numpy as np
import scipy

#N = int(input())
#C = [[0 for i in range(3)] for j in range(3)]
#for i in range(3):
#    C[i] = list(map(int, input().split()))
S = list(map(int, input().split()))
#A, B, C = map(int, input().split())

def plus1(X, Y):
    return X+1, Y+1

def plus2(Z):
    return Z+2

c = 0
S = sorted(S)

while True:
    if S[1] == S[2]:
        break
    S[0], S[1] = plus1(S[0], S[1])
    c += 1

if (S[1] - S[0])%2 != 0:
    S[1], S[2] = plus1(S[1], S[2])
    c += 1

while True:
    if S[0] == S[1]:
        break
    S[0] = plus2(S[0])
    c += 1

print(c)
Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-

import numpy
import scipy
#import sys


N = int(input())
P = []
for n in range(N):
    P.append(map(int, input().split()))

for i, p in enumerate(P):
    if i == 0:
        t_p, x_p, y_p = 0, 0, 0
    else:
        t_p, x_p, y_p = P[i-1][0], P[i-1][1], P[i-1][2]
    t, x, y = p
    dt = t - t_p
    dx = x - x_p
    dy = y - y_p
    dist = abs(dx) + abs(dy)

    if dist > dt:
        print("No")
        exit()

    if dist%2 != dt%2:
        print("No")
        exit()

print("Yes")



Fixed submission:
# -*- coding: utf-8 -*-

import numpy
import scipy
#import sys


N = int(input())
P = []
for n in range(N):
    P.append(list(map(int, input().split())))

for i, p in enumerate(P):
    if i == 0:
        t_p, x_p, y_p = 0, 0, 0
    else:
        t_p, x_p, y_p = P[i-1][0], P[i-1][1], P[i-1][2]
    t, x, y = p
    dt = t - t_p
    dx = x - x_p
    dy = y - y_p
    dist = abs(dx) + abs(dy)

    if dist > dt:
        print("No")
        exit()

    if dist%2 != dt%2:
        print("No")
        exit()

print("Yes")
Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-

import numpy
import scipy
#import sys


N, Y = map(int, input().split())

find = False
for x in range(N+1):
    for y in range(N+1-x):
        for z in range(N+1-x-y):
            sum = x*10000 + y*5000 + z*1000
            if sum == Y and not find:
                find = True
                print("{} {} {}".format(x, y, z))
                #sys.exit()

if not find:
    print("-1 -1 -1")


Fixed submission:
# -*- coding: utf-8 -*-

import numpy
import scipy
#import sys


N, Y = map(int, input().split())

find = False
for x in range(N+1):
    for y in range(N+1-x):
        z = N - x - y
        if find:
            break
        sum = x*10000 + y*5000 + z*1000
        if sum == Y:
            find = True
            print("{} {} {}".format(x, y, z))
            #sys.exit()

if not find:
    print("-1 -1 -1")
Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-

import numpy
import scipy

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

c = 0
while True:
    for i, a in enumerate(A):
        if a%2 == 0:
            A[i] = A[i]/2
        else:
            break;
    c += 1
print(c)

Fixed submission:
# -*- coding: utf-8 -*-

import numpy
import scipy

N = int(input())
A = list(map(int, input().split()))
#print(A)

c = 0
flg = False
while True:
    #print(A)
    for i, a in enumerate(A):
        if a%2 == 0:
            A[i] /= 2
            #pass
        else:
            flg = True
            break
    if flg:
        break
    c += 1
print(c)
Buggy python submission (verdict: Runtime Error):
a = int(input())
b = input().split()
x = []
for i in b:
    x.append(int(i))

count = 0

for i in x:
    if i % 2 != 0:
        count += 1

flag = 0
while True:
    z = divmod(count,2)

    #print(z)

    if z[0] == 1:
        break

    if z[1] == 1:
        flag = 1
        break

    count = z[0]

if flag == 1:
    print("NO")
else:
    print("YES")a = int(input())
b = input().split()
x = []
for i in b:
    x.append(int(i))

count = 0

for i in x:
    if i % 2 != 0:
        count += 1

flag = 0
while True:
    z = divmod(count,2)

    #print(z)

    if z[0] == 1:
        break

    if z[1] == 1:
        flag = 1
        break

    count = z[0]

if flag == 1:
    print("NO")
else:
    print("YES")

Fixed submission:

a = int(input())
b = input().split()
x = []
for i in b:
    x.append(int(i))

count = 0

for i in x:
    if i % 2 != 0:
        count += 1

z = divmod(count,2)


if z[1] == 1:
    print("NO")
else:
    print("YES")
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = [0] * N
B = [0] * N
for i in range(N):
    A[i], B[i] = map(int, input().split())

c = 0

if A == B:
    print(c)
    exit()

# A[i] < B[i]のところはA[i] == 0になるまで追いつけない
for i in range(N):
    if A[i] < B[i]:
        c += A[i]
        B[i] -= A[i]
        A[i] = 0

while A != B:
    x = 0
    for i in range(N):
        if A[i] == 0:
            continue
        x = i
        if A[i] < B[i]:
            break
    A[x] -= 1
    y = 0
    for i in range(N):
        if A[i] == B[i]:
            continue
        y = i
        if A[i] < B[i]:
            break
    B[y] -= 1
    c += 1

print(c)


Fixed submission:
N = int(input())

same = True
sum_a = 0
min_b = None

for _ in range(N):
    a, b = map(int, input().split())
    # Aの総和を求める
    sum_a += a
    # AとBが等しいどうかを調べる
    if a != b:
        same = False
    # Ai > Biの中で最小のbを求める
    if a > b and (min_b is None or b < min_b):
        min_b = b

# 初めから同じなら手数なし
if same:
    print(0)
    exit()

# Ai > Biの中で最小のbを求める
if min_b is None:
    min_b = 0

print(sum_a - min_b)

Buggy python submission (verdict: Runtime Error):
N = int(input())
A = [0] * N
B = [0] * N
for i in range(N):
    A[i], B[i] = map(int, input().split())

c = 0

if A == B:
    print(c)
    exit()

# A[i] < B[i]のところはA[i] == 0になるまで追いつけない
for i in range(N):
    if A[i] < B[i]:
        c += A[i]
        B[i] -= A[i]
        A[i] = 0

while A != B:
    x = 0
    for i in range(N):
        if A[i] == 0:
            continue
        x = i
        if A[i] < B[i]:
            break
    A[x] -= 1
    y = 0
    for i in range(N):
        if A[i] == B[i]:
            continue
        y = i
        if A[i] < B[i]:
            break
    B[y] -= 1
    candy += 1

print(candy)


Fixed submission:
N = int(input())

same = True
sum_a = 0
min_b = None

for _ in range(N):
    a, b = map(int, input().split())
    # Aの総和を求める
    sum_a += a
    # AとBが等しいどうかを調べる
    if a != b:
        same = False
    # Ai > Biの中で最小のbを求める
    if a > b and (min_b is None or b < min_b):
        min_b = b

# 初めから同じなら手数なし
if same:
    print(0)
    exit()

# Ai > Biの中で最小のbを求める
if min_b is None:
    min_b = 0

print(sum_a - min_b)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = [0] * N
B = [0] * N
for i in range(N):
    A[i], B[i] = map(int, input().split())

candy = 0
while A != B:
    x = 0
    for i in range(N):
        if A[i] == 0:
            continue
        x = i
        if A[i] < B[i]:
            break
    A[x] -= 1
    y = 0
    for i in range(N):
        if A[i] == B[i]:
            continue
        y = i
        if A[i] < B[i]:
            break
    B[y] -= 1
    candy += 1

print(candy)


Fixed submission:
N = int(input())

same = True
sum_a = 0
min_b = None

for _ in range(N):
    a, b = map(int, input().split())
    # Aの総和を求める
    sum_a += a
    # AとBが等しいどうかを調べる
    if a != b:
        same = False
    # Ai > Biの中で最小のbを求める
    if a > b and (min_b is None or b < min_b):
        min_b = b

# 初めから同じなら手数なし
if same:
    print(0)
    exit()

# Ai > Biの中で最小のbを求める
if min_b is None:
    min_b = 0

print(sum_a - min_b)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))

for i in range(N):
    s = 0
    a = 0
    for j, b in enumerate(A):
        if i == j:
            continue
        s += abs(a - b)
        a = b
    s += abs(a)
    print(s)


Fixed submission:
N = int(input())
A = [0] + list(map(int, input().split())) + [0]


s = 0
for i in range(1, N+2):
    x = abs(A[i-1] - A[i])
    s += x

for i in range(1, N+1):
    x = abs(A[i-1] - A[i])
    y = abs(A[i] - A[i+1])
    z = abs(A[i-1] - A[i+1])
    print(s - x - y + z)
Buggy python submission (verdict: Runtime Error):
A, B = map(int, input().split())
A -= 1
B -= 1

print('100 100')

for i in range(25):
    print('#' * 100)
    if A:
        x = min(A, 50)
        A = A - x
        print('#.'*x + '##'*(50-x))
    else:
        print('#' * 100)

for i in range(25):
    print('.' * 100)
    if B:
        x = min(B, 50)
        B = B - x
        print('.#'*x + '..'*(50-x))
    else:
        print('.' * 100)
A, B = map(int, input().split())
A -= 1
B -= 1

print('100 100')

for i in range(25):
    print('#' * 100)
    if A:
        x = min(A, 50)
        A = A - x
        print('#.'*x + '##'*(50-x))
    else:
        print('#' * 100)

for i in range(25):
    print('.' * 100)
    if B:
        x = min(B, 50)
        B = B - x
        print('.#'*x + '..'*(50-x))
    else:
        print('.' * 100)


Fixed submission:
def print_component(a, b, n):
    for _ in range(25):
        print(a * 100)
        if n:
            x = min(n, 50)
            n -= x
            print((a+b)*x + a*2*(50-x))
        else:
            print(a * 100)


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

print('100 100')
print_component('#', '.', A - 1)
print_component('.', '#', B - 1)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
R = [tuple(map(int, input().split())) for _ in range(N)]
B = [tuple(map(int, input().split())) for _ in range(N)]

dp = {}


def check(v, p):
    return p & (1 << v)


def visit(v, p):
    return p ^ (1 << v)


def count(p):
    return bin(p).count('1')


def solve(i, p):
    if i == N:
        return count(p)

    k = (i, p)
    if k in dp:
        return dp[k]

    a, b = R[i]
    # ペアにならなかった
    m = solve(i+1, p)
    for j, (c, d) in enumerate(B):
        # すでにペアを持つ要素は無視
        if check(j, p):
            continue
        # ペアになった
        if a < c and b < d:
            m = max(m, solve(i+1, visit(j, p)))
    dp[k] = m
    return m


print(solve(0, 0))


Fixed submission:
N = int(input())
R = [tuple(map(int, input().split())) for _ in range(N)]
B = [tuple(map(int, input().split())) for _ in range(N)]


R.sort(reverse=True, key=lambda k: k[1])
B.sort()

p = []
q = []
for c, d in B:
    for a, b in R:
        if (a, b) in p:
            continue
        if a < c and b < d:
            p.append((a, b))
            q.append((c, d))
            break

print(len(p))

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
R = [tuple(map(int, input().split())) for _ in range(N)]
B = [tuple(map(int, input().split())) for _ in range(N)]


def check(v, p):
    return p & (1 << v)


def visit(v, p):
    return p ^ (1 << v)


def count(p):
    return bin(p).count('1')


def solve(i, p):
    if i == N:
        return count(p)

    a, b = R[i]
    # ペアにならなかった
    m = solve(i+1, p)
    for j, (c, d) in enumerate(B):
        # すでにペアを持つ要素は無視
        if check(j, p):
            continue
        # ペアになった
        if a < c and b < d:
            m = max(m, solve(i+1, visit(j, p)))
    return m


print(solve(0, 0))


Fixed submission:
N = int(input())
R = [tuple(map(int, input().split())) for _ in range(N)]
B = [tuple(map(int, input().split())) for _ in range(N)]


R.sort(reverse=True, key=lambda k: k[1])
B.sort()

p = []
q = []
for c, d in B:
    for a, b in R:
        if (a, b) in p:
            continue
        if a < c and b < d:
            p.append((a, b))
            q.append((c, d))
            break

print(len(p))

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
R = [tuple(map(int, input().split())) for _ in range(N)]
B = [tuple(map(int, input().split())) for _ in range(N)]


def solve(i, p):
    if i == N:
        return len(p)

    a, b = R[i]
    # ペアにならなかった
    s = [solve(i+1, p)]
    for c, d in B:
        # すでにペアを持つ要素は無視
        if (c, d) in p:
            continue
        # ペアになった
        if a < c and b < d:
            s.append(solve(i+1, p + [(c, d)]))
    return max(s)


print(solve(0, []))


Fixed submission:
N = int(input())
R = [tuple(map(int, input().split())) for _ in range(N)]
B = [tuple(map(int, input().split())) for _ in range(N)]


R.sort(reverse=True, key=lambda k: k[1])
B.sort()

p = []
q = []
for c, d in B:
    for a, b in R:
        if (a, b) in p:
            continue
        if a < c and b < d:
            p.append((a, b))
            q.append((c, d))
            break

print(len(p))
Buggy python submission (verdict: Runtime Error):
# ABC 075 B

# H, W = 4, 3
# S = "#.."\
#     "..#"\
#     ".#."\
#     ".#."

H, W = map(int, input().split())
S = ''
for _ in range(H):
    S += input()
    

def cell_of(x, y):
    return S[W*x + y]

def neighbor_indice_of(x, y):
    return [
        (x+m, y+n)
        for m in range(-1, 2)
        for n in range(-1, 2)
        if 0 <= x+m < H and 0 <= y+n < W
    ]

def neighbors_of(x, y):
    return [
        cell_of(i, j)
        for i, j in neighbor_indice(x, y)
    ]

def mine(x, y):
    cell = cell_of(x, y)
    if cell != '.':
        return cell
    return str(neighbors_of(x, y).count('#'))


for x in range(H):
    print(''.join([mine(x, y) for y in range(W)]))

Fixed submission:
# ABC 075 B

# H, W = 4, 3
# S = "#.."\
#     "..#"\
#     ".#."\
#     ".#."

H, W = map(int, input().split())
S = ''
for _ in range(H):
    S += input()
    

def cell_of(x, y):
    return S[W*x + y]

def neighbor_indice_of(x, y):
    return [
        (x+m, y+n)
        for m in range(-1, 2)
        for n in range(-1, 2)
        if 0 <= x+m < H and 0 <= y+n < W
    ]

def neighbors_of(x, y):
    return [cell_of(i, j) for i, j in neighbor_indice_of(x, y)]

def mine(x, y):
    cell = cell_of(x, y)
    if cell != '.':
        return cell
    return str(neighbors_of(x, y).count('#'))


for x in range(H):
    print(''.join([mine(x, y) for y in range(W)]))
Buggy python submission (verdict: Time Limit Exceeded):
# ABC 065 B

N = int(input())
A = [int(input()) for _ in range(N)]

i = 1
q = []
while i != 2:
    q.append(i)
    i = A[i-1]
    if i in q:
        print(-1)
        break
else:
    print(len(q))

Fixed submission:
# ABC 065 B

N = int(input())
A = [int(input()) for _ in range(N)]

i = 1
s = 0
while i != 2:
    s += 1
    A[i-1], i = 1, A[i-1]
    if i == 1:
        print(-1)
        break
else:
    print(s)

Buggy python submission (verdict: Time Limit Exceeded):
# ABC 065 B

N = int(input())
A = [int(input()) for _ in range(N)]

i = 1
q = []
while i != 2:
    q.append(i)
    if A[i-1] in q:
        print(-1)
        break
    i = A[i-1]
else:
    print(len(q))

Fixed submission:
# ABC 065 B

N = int(input())
A = [int(input()) for _ in range(N)]

i = 1
s = 0
while i != 2:
    s += 1
    A[i-1], i = 1, A[i-1]
    if i == 1:
        print(-1)
        break
else:
    print(s)

Buggy python submission (verdict: Time Limit Exceeded):
# ABC 065 B

N = int(input())
A = [int(input()) for _ in range(N)]

q = []
i = 1
while i != 2:
    if A[i-1] in q:
        print(-1)
        break
    q.append(i)
    i = A[i-1]
else:
    print(len(q))

Fixed submission:
# ABC 065 B

N = int(input())
A = [int(input()) for _ in range(N)]

i = 1
s = 0
while i != 2:
    s += 1
    A[i-1], i = 1, A[i-1]
    if i == 1:
        print(-1)
        break
else:
    print(s)

Buggy python submission (verdict: Time Limit Exceeded):
# ABC 065 B

N = int(input())
A = [int(input()) for _ in range(N)]

q = []
i = 0
while i != 1:
    if A[i] in q:
        print(-1)
        break
    q.append(A[i])
    i = A[i] - 1
else:
    print(len(q))

Fixed submission:
# ABC 065 B

N = int(input())
A = [int(input()) for _ in range(N)]

i = 1
s = 0
while i != 2:
    s += 1
    A[i-1], i = 1, A[i-1]
    if i == 1:
        print(-1)
        break
else:
    print(s)
Buggy python submission (verdict: Time Limit Exceeded):
N, L, T = map(int, input().split())
L *= 2
T *= 2

X = [0] * N
W = [0] * N
for i in range(N):
    X[i], W[i] = map(int, input().split())
    X[i] *= 2
    if W[i] == 2:
        W[i] = -1

# print(X, W)
for t in range(T):
    for i in range(N):
        X[i] = (X[i] + W[i]) % L
    for i in range(N):
        if X[i-1] == X[i]:
            W[i-1] *= -1
            W[i] *= -1
    # print(X, W)

for x in X:
    print(x // 2)


Fixed submission:
N, L, T = map(int, input().split())

s = 0
X = [0] * N
for i in range(N):
    x, w = map(int, input().split())
    if w == 1:
        x += T
    else:
        x -= T
    # xが0点を通る回数を足す
    s += x // L
    X[i] = x % L

X.sort()
for i in range(N):
    print(X[(i+s) % N])
Buggy python submission (verdict: Time Limit Exceeded):
# ABC 055 B

N = int(input())
p = 1
for i in range(1, N+1):
    p *= i
print(p % 1000000007)

Fixed submission:
# ABC 055 B

N = int(input())
p = 1
for i in range(1, N+1):
    p = p * i % 1000000007
print(p)
Buggy python submission (verdict: Runtime Error):
x = input().split
if x[2] <= x[0] + x[1]:
    print("Yes")
else:
    print("No")


Fixed submission:
x = raw_input().split()
if (int(x[2]) <= int(x[0])+int(x[1])):
    print("Yes")

else:
    print("No")
Buggy python submission (verdict: Runtime Error):
import numpy as np

W,H,N = map(int,input().split())
l = np.zeros((H,W)) #	要素0のH×W配列

for i in range(N):
  x,y,a = map(int,input().split())

  if a==1:
    l[:,:x] = 1
    #print(l[:,x:])
  elif a==2:
    l[:,x:] = 1
  elif a==3:
    l[:y,:] = 1
  elif a==4:
    l[y:,:] = 1
#print(H*W-int(l.sum().sum()))
print(H*W-int(l.sum()))

Fixed submission:
import numpy as np

W,H,N = map(int,input().split())
l = np.zeros((H,W)) #	要素0のH×W配列

for i in range(N):
  x,y,a = map(int,input().split())

  if a==1:
    l[:,:x] = 1
    #print(l[:,x:])
  elif a==2:
    l[:,x:] = 1
  elif a==3:
    l[:y,:] = 1
  elif a==4:
    l[y:,:] = 1
#print(H*W-int(l.sum().sum()))
print(H*W-int(l.sum()))
Buggy python submission (verdict: Runtime Error):
N,K=map(int,input().split())

ans = (K-1)**(N-1)*K

print(ans)

Fixed submission:
#辞書型リスト作成
dic ={
  "a":list(input()),
  "b":list(input()),
  "c":list(input())
}
#print(dic)

now = "a"
while True:
  if len(dic[now]) == 0:
    print(now.upper()) #大文字変換
    break
  now = dic[now].pop(0) #値削除