Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))

cnt = 0
for i in range(1,5):
    #print(cnt)
    if a[i] < a[i-1]:
        cnt = cnt + (a[i-1] - a[i])
        a[i] = a[i-1]
        #print(cnt)
print(cnt)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))

cnt = 0
for i in range(1,n):
    if a[i] < a[i-1]:
        cnt = cnt + (a[i-1] - a[i])
        a[i] = a[i-1]

print(cnt)
Buggy python submission (verdict: Time Limit Exceeded):
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))


b = []
i = 0
while k != n+1:
    total = 1
    for j in range(i, k):
        total *= a[j]
    b.append(total)
    i += 1
    k += 1
l = len(b)
#print(b)
for i in range(l-1):
    if b[i] < b[i+1]:
        print('Yes')
    else:
        print('No')

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

for i in range(n-k):
    if a[i] < a[i+k] :
        print('Yes')
    else :
        print('No')
Buggy python submission (verdict: Time Limit Exceeded):
import itertools
n, k = list(map(int, input().split()))
p = list(map(int, input().split()))

sum0 = 100100100

for i in itertools.combinations(p, k):
    sum1 = sum(i)
    if sum0 > sum1:
        sum0 = sum1
        
print(sum0)
    
    


Fixed submission:
import itertools
n, k = list(map(int, input().split()))
p = list(map(int, input().split()))

p.sort()
sum = p[0]
for i in range(1,k):
    sum += p[i]
print(sum)

Buggy python submission (verdict: Time Limit Exceeded):
import itertools
n, k = list(map(int, input().split()))
p = list(map(int, input().split()))

sum0 = 100100100

for i in itertools.permutations(p, k):
    sum1 = sum(i)
    if sum0 > sum1:
        sum0 = sum1
        
print(sum0)

Fixed submission:
import itertools
n, k = list(map(int, input().split()))
p = list(map(int, input().split()))

p.sort()
sum = p[0]
for i in range(1,k):
    sum += p[i]
print(sum)
Buggy python submission (verdict: Runtime Error):
a, b = list(map(int, input()))

print(a*b)

Fixed submission:
a, b = list(map(int, input().split()))
print(a*b)
Buggy python submission (verdict: Runtime Error):
import sys
n = int(input())
a = list(map(int, input().split()))

total = 1
a.sort()
if a[0] == 0:
	print(0)
	sys.exit(1)
for i in range(n):
	total *= a[i]
	if total > 10**18:
		print('-1')
		sys.exit(1)
print(total)
	

Fixed submission:
import sys
n = int(input())
a = list(map(int, input().split()))

total = 1
a.sort()
if a[0] == 0:
	print(0)
	sys.exit()
for i in range(n):
	total *= a[i]
	if total > 10**18:
		print('-1')
		sys.exit()
print(total)

Buggy python submission (verdict: Runtime Error):
import sys
n = int(input())
a = list(map(int, input().split()))

total = 1
for i in range(n):
	if a[i] == 0:
		print(-1)
		sys.exit(1)
for i in range(n):
	total = total * a[i]
	if total > 10**18:
		print(-1)
		sys.exit(1)
print(total)

Fixed submission:
import sys
n = int(input())
a = list(map(int, input().split()))

total = 1
a.sort()
if a[0] == 0:
	print(0)
	sys.exit()
for i in range(n):
	total *= a[i]
	if total > 10**18:
		print('-1')
		sys.exit()
print(total)

Buggy python submission (verdict: Runtime Error):
import sys
n = int(input())
a = list(map(int, input().split()))

total = 1
for i in range(n):
	if a[i] == 0:
		print(0)
		sys.exit(1)
for i in range(n):
	total = total * a[i]
	if total > 10**18:
		print(-1)
		sys.exit(1)
print(total)

Fixed submission:
import sys
n = int(input())
a = list(map(int, input().split()))

total = 1
a.sort()
if a[0] == 0:
	print(0)
	sys.exit()
for i in range(n):
	total *= a[i]
	if total > 10**18:
		print('-1')
		sys.exit()
print(total)

Buggy python submission (verdict: Runtime Error):
import sys
n = int(input())
a = list(map(int, input().split()))

sum = 1
for i in range(n):
	if a[i] == 0:
		print(0)
		sys.exit(1)
for i in range(n):
	sum = sum * a[i]
	if sum > 10**18:
		print(-1)
		sys.exit(1)
print(sum)

Fixed submission:
import sys
n = int(input())
a = list(map(int, input().split()))

total = 1
a.sort()
if a[0] == 0:
	print(0)
	sys.exit()
for i in range(n):
	total *= a[i]
	if total > 10**18:
		print('-1')
		sys.exit()
print(total)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))

sum = 1
for i in range(n):
	sum = sum * a[i]
if sum > 10**18:
	print(-1)
else:
	print(sum)

Fixed submission:
import sys
n = int(input())
a = list(map(int, input().split()))

total = 1
a.sort()
if a[0] == 0:
	print(0)
	sys.exit()
for i in range(n):
	total *= a[i]
	if total > 10**18:
		print('-1')
		sys.exit()
print(total)
Buggy python submission (verdict: Runtime Error):
import itertools
N, K = list(map(int, input().split()))
d = []
A = [[0]]*N
for i in range(K):
    d.append(int(input()))
    A[i] = list(map(int, input().split()))
 
s = list(set((list(itertools.chain.from_iterable(A)))))

for i in range(len(s)):
    if s[i] == 0:
        s.remove(0)
        break

print(N-len(s)) 

Fixed submission:
import itertools
N, K = list(map(int, input().split()))
d = []
A = []
for i in range(K):
    d.append(int(input()))
    A.append(list(map(int, input().split())))
#print(A) 
s = list(set((list(itertools.chain.from_iterable(A)))))
print(N - len(s))

Buggy python submission (verdict: Runtime Error):
import itertools
N, K = list(map(int, input().split()))
d = []
A = [[0]]*N
for i in range(K):
    d.append(int(input()))
    A[i] = list(map(int, input().split()))

s = list(set((list(itertools.chain.from_iterable(A)))))
#print(s)
#s.pop(0)
#print(s)

S = list(range(1,N+1))
#print(S)

for i in range(len(s)):
    if s[i] == 0:
        s.remove(0)
        break

diff = list(set(S) - set(s))
#print(diff)
print(len(diff))

Fixed submission:
import itertools
N, K = list(map(int, input().split()))
d = []
A = []
for i in range(K):
    d.append(int(input()))
    A.append(list(map(int, input().split())))
#print(A) 
s = list(set((list(itertools.chain.from_iterable(A)))))
print(N - len(s))
Buggy python submission (verdict: Runtime Error):
s, w = list(map(int, input(split()))

if s > w:
    print('safe')
else:
    print('unsafe')

Fixed submission:
s, w = list(map(int, input().split()))

if s > w:
    print('safe')
else:
    print('unsafe')
Buggy python submission (verdict: Time Limit Exceeded):
n, m = list(map(int, input().split()))
a = list(map(int, input().split()))
for i in range(m):
    a.sort(reverse = True)
    a[0] //= 2
print(sum(a))

Fixed submission:
import heapq

n, m = map(int, input().split())
a = list(map(lambda x: int(x)*(-1), input().split()))
heapq.heapify(a)  # aを優先度付きキューに

for _ in range(m):
    tmp_min = heapq.heappop(a)
    heapq.heappush(a, (-1)*(-tmp_min//2))  # 計算誤差の関係で-1を2回かけてます
print(-sum(a))

Buggy python submission (verdict: Time Limit Exceeded):
n, m = list(map(int, input().split()))
a = list(map(int, input().split()))

for i in range(m):
    a.sort(reverse = True)
    a[0] = a[0] // 2

print(sum(a))

Fixed submission:
import heapq

n, m = map(int, input().split())
a = list(map(lambda x: int(x)*(-1), input().split()))
heapq.heapify(a)  # aを優先度付きキューに

for _ in range(m):
    tmp_min = heapq.heappop(a)
    heapq.heappush(a, (-1)*(-tmp_min//2))  # 計算誤差の関係で-1を2回かけてます
print(-sum(a))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split(' ')))
r = 1
for i in a:
    r *= i
r = -1 if r > 10 ** 18 else r
print(r)

Fixed submission:
n = int(input())
a = list(map(int, input().split(' ')))
o = 10 ** 18
r = 1
if 0 not in a:
    for i in a:
        r *= i
        if r > o:
            r = -1
            break
else:
    r = 0
print(r)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
n, m = map(int, input().split(' '))
c = [[] for i in range(n)]
r = [0] * n
q = deque()
for i in range(m):
    a, b = map(int, input().split(' '))
    c[a - 1].append(b - 1)
    c[b - 1].append(a - 1)
q.append([0] + c[0])
while(len(q) > 0):
    g = q.popleft()
    ix = g.pop(0)
    for i in g:
        r[i] = ix + 1 if r[i] == 0 else r[i]
        if len(c[i]) > 0:
            t = [i] + [j for j in c[i] if r[j] == 0]
            if len(t) > 1:
                q.append(t)
jg = 'Yes' if r.pop(0) > 0 else 'No'
print(jg)
for i in r:
    print(i)

Fixed submission:
from collections import deque
n, m = map(int, input().split(' '))
c = [[] for i in range(n)]
r = [0] * n
q = deque()
for i in range(m):
    a, b = map(int, input().split(' '))
    c[a - 1].append(b - 1)
    c[b - 1].append(a - 1)
q.append(0)
while len(q) > 0:
    ix = q.popleft()
    for i in c[ix]:
        if r[i] == 0:
            r[i] = ix + 1
            q.append(i)

jg = 'Yes' if r.pop(0) > 0 else 'No'
print(jg)
for i in r:
    print(i)

Buggy python submission (verdict: Time Limit Exceeded):
import queue
n, m = map(int, input().split(' '))
c = [[] for i in range(n)]
r = [0] * n
q = queue.Queue()
for i in range(m):
    a, b = map(int, input().split(' '))
    c[a - 1].append(b - 1)
    c[b - 1].append(a - 1)
q.put([0] + c[0])
while(q.qsize() > 0):
    g = q.get()
    ix = g.pop(0)
    for i in g:
        r[i] = ix + 1 if r[i] == 0 else r[i]
        if len(c[i]) > 0:
            t = [i] + [j for j in c[i] if r[j] == 0]
            if len(t) > 1:
                q.put(t)
jg = 'Yes' if r.pop(0) > 0 else 'No'
print(jg)
for i in r:
    print(i)

Fixed submission:
from collections import deque
n, m = map(int, input().split(' '))
c = [[] for i in range(n)]
r = [0] * n
q = deque()
for i in range(m):
    a, b = map(int, input().split(' '))
    c[a - 1].append(b - 1)
    c[b - 1].append(a - 1)
q.append(0)
while len(q) > 0:
    ix = q.popleft()
    for i in c[ix]:
        if r[i] == 0:
            r[i] = ix + 1
            q.append(i)

jg = 'Yes' if r.pop(0) > 0 else 'No'
print(jg)
for i in r:
    print(i)
Buggy python submission (verdict: Runtime Error):
n, m, x = map(int,input().split(' '))
a = [[] for i in range(n)]
e = [0] * m
sc = [0] * m
for i in range(n):
    l = list(map(int, input().split(' ')))
    l.append(l[0] / sum(l[1:]))
    a[i] = l
a.sort(key = lambda v : v[-1:])
p = 0
for i in a:
    p += i[0]
    for j in range(m):
        e[j] += i[j + 1]
        sc[j] = 1 if e[j] >= x else 0
    if sum(sc) == m:
        break
        
    
r = p if sum(sc) == m else -1
print(r)


Fixed submission:
n, m, x = map(int,input().split(' '))
a = [[] for i in range(n)]
p = 0
for i in range(n):
    a[i] = list(map(int, input().split(' ')))
sc = 12 * 100001
for i in range(1, 2 ** n):
    bi = '0' * n + bin(i)[2:]
    bi = bi[len(bi) - n:]
    cc = 0
    e = [0] * m
    for j in range(n):
        if bi[j] == '1':
            for k in range(m):
                e[k] += a[j][k + 1]
            cc += a[j][0]
    su =True
    for j in range(m):
        su &= e[j] >= x
    if su:
        sc = min(sc, cc)
sc = -1 if sc > 12 * 100000 else sc
print(sc)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split(' ')))
r = 0
for i in range(n - 1):
    for j in range(i, n):
        r += 1 if i + a[i] == j - a[j] else 0
print(r)

Fixed submission:
import collections
n = int(input())
a = list(map(int, input().split(' ')))
l, r = [], []
for i in range(n):
    l.append(i + a[i])
    r.append(i - a[i])
c = collections.Counter(r)
ans = 0
for i in l:
    ans += c.get(i, 0)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = input()
r = 0
if n > 2:
    for i in range(n - 2):
        for j in range(i + 1, n - 1):
            for k in range(j + 1, n):
                r += 1 if j - i != k - j and s[i] != s[j] and s[i] != s[k] and s[j] != s[k] else 0
print(r)

Fixed submission:
n = int(input())
s = input()
r = 0
if n > 2:
    r = s.count('R') * s.count('G') * s.count('B')
    for i in range(n - 2):
        k = i + 2
        for j in range(i + 1, n - 1):
            k += 2 if j > i + 1 else 0
            if k >= n:
                break
            r -= 1 if s[i] != s[j] and s[i] != s[k] and s[j] != s[k] else 0
print(r)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split(' ')))
c = [0] * (n + 1)
d = [0] * (n + 1)
for i in a:
    c[i] += 1
    d[i] = c[i] * (c[i] - 1) // 2
for i in a:
    if c[i] > 2:
        r = (((c[i] - 1) * (c[i] - 2)) // 2)
    else:
        r = 0
    print(sum(d) - d[i] + r)

Fixed submission:
n = int(input())
a = list(map(int, input().split(' ')))
c = [0] * (n + 1)
d = [0] * (n + 1)
for i in a:
    c[i] += 1
    d[i] = c[i] * (c[i] - 1) // 2
t = sum(d)
for i in a:
    if c[i] > 2:
        r = (((c[i] - 1) * (c[i] - 2)) // 2)
    else:
        r = 0
    print(t - d[i] + r)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split(' ')))
for i in range(n):
    rd = a.copy()
    del rd[i]
    co = 0
    for j in range(n - 2):
        co += rd[j + 1:].count(rd[j])
    print(co)

Fixed submission:
n = int(input())
a = list(map(int, input().split(' ')))
c = [0] * (n + 1)
d = [0] * (n + 1)
for i in a:
    c[i] += 1
    d[i] = c[i] * (c[i] - 1) // 2
t = sum(d)
for i in a:
    if c[i] > 2:
        r = (((c[i] - 1) * (c[i] - 2)) // 2)
    else:
        r = 0
    print(t - d[i] + r)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split(' ')))
for i in range(n):
    rd = a[0: i] + a[i + 1:]
    co = 0
    for j in range(n - 2):
        co += rd[j + 1:].count(rd[j])
    print(co)

Fixed submission:
n = int(input())
a = list(map(int, input().split(' ')))
c = [0] * (n + 1)
d = [0] * (n + 1)
for i in a:
    c[i] += 1
    d[i] = c[i] * (c[i] - 1) // 2
t = sum(d)
for i in a:
    if c[i] > 2:
        r = (((c[i] - 1) * (c[i] - 2)) // 2)
    else:
        r = 0
    print(t - d[i] + r)
Buggy python submission (verdict: Runtime Error):
h, w = map(int, input().split(' '))
print(int(h * w / 2 + h * w % 2)

Fixed submission:
h, w = map(int, input().split(' '))
print(int(h * w / 2) + h * w % 2 if h > 1 and w > 1 else 1)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = []
for i in range(n):
    s.append(input())
ss = set(s)
sd = {}
for i in ss:
    sd[i] = s.count(i)
m = max(sd.values())
r = [k for k, v in sd.items() if v == m]
r.sort()
for i in r:
    print(i)

Fixed submission:
n = int(input())
s = {}
for i in range(n):
    w = input()
    if w in s.keys():
        s[w] = s[w] + 1
    else:
        s[w] = 1
m = max(s.values())
r = [k for k, v in s.items() if v == m]
r.sort()
for i in r:
    print(i)
Buggy python submission (verdict: Runtime Error):
s = input()
d = ['SUN', 'MON', 'TUE', 'WED', 'THU', 'FRY', 'SAT']
print(7 - d.index(s))

Fixed submission:
s = input()
d = ['SUN', 'MON', 'TUE', 'WED', 'THU', 'FRI', 'SAT']
print(7 - d.index(s))
Buggy python submission (verdict: Time Limit Exceeded):
N, K, Q = input().split(' ')
n, k, q = int(N), int(K), int(Q)
a = []
for i in range(q):
    a.append(int(input()) - 1)
for i in range(n):
    res = 'No'
    if k - q + a.count(i) > 0:
        res = 'Yes'
    print(res)

Fixed submission:
N, K, Q = input().split(' ')
n, k, q = int(N), int(K), int(Q)
t = 'No'
if k - q > 0:
    t = 'Yes'
res = [t] * n

p = [k - q] * n
for i in range(q):
    r = int(input()) - 1
    p[r] += 1
    if p[r] > 0:
        res[r] = 'Yes'
for i in res:
    print(i)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
N, K, Q = input().split(' ')
n, k, q = int(N), int(K), int(Q)
a = []
p = np.array([k] * n)
d = np.array([1] * n)
for i in range(q):
    a.append(int(input()) - 1)

for i in a:
    d[i] = 0
    p -= d
    d[i] = 1
for i in p:
    res = 'Yes'
    if i < 1:
        res = 'No'
    print(res)

Fixed submission:
N, K, Q = input().split(' ')
n, k, q = int(N), int(K), int(Q)
t = 'No'
if k - q > 0:
    t = 'Yes'
res = [t] * n

p = [k - q] * n
for i in range(q):
    r = int(input()) - 1
    p[r] += 1
    if p[r] > 0:
        res[r] = 'Yes'
for i in res:
    print(i)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = []
for i in range(0, n):
    a.append(int(input()))
for i in a:
    b = a.copy()
    b.remove(i)
    print(max(b))

Fixed submission:
n = int(input())
a = []
for i in range(0, n):
    a.append(int(input()))
b = a.copy()
f = max(b)
b.remove(f)
s = max(b)

for i in a:
    r = f if i != f else s
    print(r)
Buggy python submission (verdict: Runtime Error):
D = int(input())
c = list(map(int,input().split()))
s = [list(map(int, input().split())) for l in range(D)]
last = [0]*26

def score_down(d):
    ans = 0
    for i in range(26):
        ans += c[i]*(d - last[i])
    return ans

for d in range(D):
    score = [(s[d][i] - score_down(d+1)) for i in range(D)]
    t = score.index(max(score))
    print(t+1)
    last[t] = d+1

Fixed submission:
D = int(input())
c = list(map(int,input().split()))
s = [list(map(int, input().split())) for l in range(D)]
last = [0]*26

def score_down(d):
    ans = 0
    for i in range(26):
        ans += c[i]*(d - last[i])
    return ans

for d in range(D):
    score = [(s[d][i] - score_down(d+1)) for i in range(26)]
    t = score.index(max(score))
    print(t+1)
    last[t] = d+1

Buggy python submission (verdict: Runtime Error):
D = int(input())
c = list(map(int,input().split()))
s = [list(map(int, input().split())) for l in range(D)]
last = [0]*26

def score_down(d):
    ans = 0
    for i in range(26):
        ans += c[i]*(d - last[i])
    return ans

for d in range(D):
    score = [(s[d][i] - score_down(d)) for i in range(D)]
    t = score.index(max(score))
    print(t+1)
    last[t] = d+1

Fixed submission:
D = int(input())
c = list(map(int,input().split()))
s = [list(map(int, input().split())) for l in range(D)]
last = [0]*26

def score_down(d):
    ans = 0
    for i in range(26):
        ans += c[i]*(d - last[i])
    return ans

for d in range(D):
    score = [(s[d][i] - score_down(d+1)) for i in range(26)]
    t = score.index(max(score))
    print(t+1)
    last[t] = d+1

Buggy python submission (verdict: Runtime Error):
D = int(input())
c = list(map(int,input().split()))
s = [list(map(int, input().split())) for l in range(D)]
last = [0]*26

def score_down(d):
    ans = 0
    for i in range(26):
        ans += c[i]*(d - last[i])
    return ans

for d in range(D):
    score = [(s[d][i] - score_down(d)) for i in range(D)]
    t = score.index(max(score))
    print(t+1)
    last[t] = d


Fixed submission:
D = int(input())
c = list(map(int,input().split()))
s = [list(map(int, input().split())) for l in range(D)]
last = [0]*26

def score_down(d):
    ans = 0
    for i in range(26):
        ans += c[i]*(d - last[i])
    return ans

for d in range(D):
    score = [(s[d][i] - score_down(d+1)) for i in range(26)]
    t = score.index(max(score))
    print(t+1)
    last[t] = d+1
Buggy python submission (verdict: Runtime Error):
from collections import deque
N, M = map(int, input().split())
G = [[] for _ in range(N+1)]

for i in range(M):
    x, y = map(int, input().split())
    G[x].append(y)
    G[y].append(x)

USED = [-1] * (N+1)
USED[0] = 0
USED[1] = 0

Q = deque()
Q.append(1)

while Q:
    x = Q.pop()
    for t in G[x]:
        if USED[t] == -1:
            Q.appendleft(t)
            USED[t] = x

if -1 in USED:
    print("No")
else:
    print("Yes")
    print(*USE[2:])


Fixed submission:
from collections import deque
N, M = map(int, input().split())
G = [[] for _ in range(N+1)]

for i in range(M):
    x, y = map(int, input().split())
    G[x].append(y)
    G[y].append(x)

USED = [-1] * (N+1)
USED[0] = 0
USED[1] = 0

Q = deque()
Q.append(1)

while Q:
    x = Q.pop()
    for t in G[x]:
        if USED[t] == -1:
            Q.appendleft(t)
            USED[t] = x

if -1 in USED:
    print("No")
else:
    print("Yes")
    for _ in USED[2::]:
        print(_)
Buggy python submission (verdict: Runtime Error):
S = input()
T = input()
ans = 0
for i in range(len(T)):
    if len(S) > 10:
        break
    if S[i] == T[i]:
        ans = 0
    else:
        ans = 1

if ans == 0:
    print('Yes')
else:
    print('No')


Fixed submission:
S = input()
T = input()
ans = 0
for i in range(len(S)):
    if len(S) > 10:
        break
    if len(T) != len(S) + 1:
        break
    if S[i] == T[i]:
        ans = 1
    else:
        ans = 0
        break

if ans == 1:
    print('Yes')
else:
    print('No')
Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
where_go = list(map(int, input().split()))
now = 0
PATH = []
start = 0
roop = 0
count = 0

while now not in PATH and count < K:
    PATH.append(now)
    now = where_go[now] -  1
    count += 1

if count < K:
    start = PATH.index(now)
    roop = len(PATH) - start
    K = (K - start) % roop
    count = 0
    while count < K:
        now = where_go[now] -  1
        count += 1

print(now+1)

Fixed submission:
N, K = map(int, input().split())
A = list(map(int, input().split())) #どこに行くかのリスト
now = 0 #どこにいるか
LOG = {}
roop = 0
count = 0

while now not in LOG and count < K:
    LOG.setdefault(now, count)
    now = A[now] -  1
    count += 1

if count < K:
    roop = len(LOG) - LOG[now]
    K = (K - count) % roop
    count = 0
    while count < K:
        now = A[now] -  1
        count += 1

print(now+1) #行った場所を保存

Buggy python submission (verdict: Runtime Error):
6 727202214173249351
6 5 2 5 3 2

Fixed submission:
N, K = map(int, input().split())
A = list(map(int, input().split())) #どこに行くかのリスト
now = 0 #どこにいるか
LOG = {}
roop = 0
count = 0

while now not in LOG and count < K:
    LOG.setdefault(now, count)
    now = A[now] -  1
    count += 1

if count < K:
    roop = len(LOG) - LOG[now]
    K = (K - count) % roop
    count = 0
    while count < K:
        now = A[now] -  1
        count += 1

print(now+1) #行った場所を保存

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

while count < K:
    now = where_go[now] - 1
    count += 1

print(now + 1)


Fixed submission:
N, K = map(int, input().split())
A = list(map(int, input().split())) #どこに行くかのリスト
now = 0 #どこにいるか
LOG = {}
roop = 0
count = 0

while now not in LOG and count < K:
    LOG.setdefault(now, count)
    now = A[now] -  1
    count += 1

if count < K:
    roop = len(LOG) - LOG[now]
    K = (K - count) % roop
    count = 0
    while count < K:
        now = A[now] -  1
        count += 1

print(now+1) #行った場所を保存
Buggy python submission (verdict: Runtime Error):
N = int(input())
A =  list(map(int, input().split()))
count = 0
flag = 0

while flag == 0:
    for i in range(N):
        if (A[i] % 2 == 0):
            A[i] = A[i] / 2
        else:
            flag = 1
    count += 1

print(count - 1)


Fixed submission:
a, b, c=input()
ans = 0
if a == "1":
    ans += 1
if b == "1":
    ans += 1
if c == "1":
    ans += 1
    
print(ans)
Buggy python submission (verdict: Runtime Error):
K, S = map(int, input().split())
ans = 0

for x in range(K+1):
    for y in range(K+1):
        if S - x - y < 0:
            break
        if K >= S - x - y >= 0:
            ans += 1
print(ans)


k,s = map(int, input().split())

ans = 0
for right in range(max(s-k, 0), min(s+1, 2*k+1)):
  lower = max(0, right-k)
  upper = min(k, right)
  if right % 2 != 0:
    ans += upper - lower + 1
  else:
    ans += upper - lower + 1
print(ans)


Fixed submission:
K, S = map(int, input().split())
ans = 0

for x in range(K+1):
    for y in range(K+1):
        if K >= S - x - y >= 0:
            ans += 1
print(ans)
Buggy python submission (verdict: Runtime Error):
N, L = map(int, input().split())
S = []
for _ in range(N):
    S.append(input())

S.sort()
print()''.join(S))


Fixed submission:
N, L = map(int, input().split())
S = []
for _ in range(N):
    S.append(input())

S.sort()
print(''.join(S))