Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
n,m,q = map(int, input().split())

import itertools
a = []
for i in range(q):
    a.append(input().split())

suma = sum([int(aa[3]) for aa in a])

ans = 0
l = [i for i in range(m)]
for v in itertools.combinations_with_replacement(l, n):
    ans_ = 0
    for j in range(q):
        if v[int(a[j][1])-1] - v[int(a[j][0])-1] == int(a[j][2]):
            ans_ += int(a[j][3])
    if ans_ > ans:
        ans = ans_
        if ans == suma:
            break
print(ans)

Fixed submission:
n,m,q = map(int, input().split())

import itertools
a = []
for i in range(q):
    a.append(input().split())

suma = sum([int(aa[3]) for aa in a])

ans = 0
l = [i for i in range(m)]
for v in itertools.combinations_with_replacement(l, n-1):
    ans_ = 0
    v = [0]+list(v)
    for j in range(q):
        if v[int(a[j][1])-1] - v[int(a[j][0])-1] == int(a[j][2]):
            ans_ += int(a[j][3])
    if ans_ > ans:
        ans = ans_
        if ans == suma:
            break
print(ans)

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

import itertools
a = []
for i in range(q):
    a.append(input().split())

ans = 0
l = [i for i in range(m)]
for v in itertools.combinations_with_replacement(l, n):
    ans_ = 0
    for j in range(q):
        if v[int(a[j][1])-1] - v[int(a[j][0])-1] == int(a[j][2]):
            ans_ += int(a[j][3])
    if ans_ > ans:
        ans = ans_

print(ans)

Fixed submission:
n,m,q = map(int, input().split())

import itertools
a = []
for i in range(q):
    a.append(input().split())

suma = sum([int(aa[3]) for aa in a])

ans = 0
l = [i for i in range(m)]
for v in itertools.combinations_with_replacement(l, n-1):
    ans_ = 0
    v = [0]+list(v)
    for j in range(q):
        if v[int(a[j][1])-1] - v[int(a[j][0])-1] == int(a[j][2]):
            ans_ += int(a[j][3])
    if ans_ > ans:
        ans = ans_
        if ans == suma:
            break
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))

for i in range(n):
    print(a.count(i+1))

Fixed submission:
import collections

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

c = collections.Counter(a)

for i in range(n):
    print(c[i+1])
Buggy python submission (verdict: Time Limit Exceeded):
s = input()
n = int(input())

h = 0
for i in range(n):
    qq = list(input().split())
    if qq[0] == '1':
        h += 1
    else:
        if qq[1] == '1':
            if h % 2 ==1:
                s = s + qq[2]
            else:
                s = qq[2] + s
        else:
            if h % 2 ==1:
                s = qq[2] + s
            else:
                s = s + qq[2]

if h % 2 ==1:
    s = s[::-1]
print(s)

Fixed submission:
s = input()
n = int(input())
b = ''
a = ''
h = 0
for i in range(n):
    qq = list(input().split())
    if qq[0] == '1':
        h += 1
    else:
        if qq[1] == '1':
            if h % 2 ==1:
                a = a + qq[2]
            else:
                b = qq[2] + b
        else:
            if h % 2 ==1:
                b = qq[2] + b
            else:
                a = a + qq[2]

s = b + s + a
if h % 2 ==1:
    s = s[::-1]
print(s)

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
n = int(input())

h = 0
for i in range(n):
    qq = list(input().split())
    if qq[0] == '1':
        h += 1
    else:
        if h % 2 ==1:
            s = s[::-1]
            h = 0
        if qq[1] == '1':
            s = qq[2] + s
        else:
            s = s + qq[2]

if h % 2 ==1:
    s = s[::-1]
print(s)

Fixed submission:
s = input()
n = int(input())
b = ''
a = ''
h = 0
for i in range(n):
    qq = list(input().split())
    if qq[0] == '1':
        h += 1
    else:
        if qq[1] == '1':
            if h % 2 ==1:
                a = a + qq[2]
            else:
                b = qq[2] + b
        else:
            if h % 2 ==1:
                b = qq[2] + b
            else:
                a = a + qq[2]

s = b + s + a
if h % 2 ==1:
    s = s[::-1]
print(s)

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
n = int(input())
for i in range(n):
    qq = list(input().split())
    if qq[0] == '1':
        s = s[::-1]
    else:
        if qq[1] == '1':
            s = qq[2] + s
        else:
            s = s + qq[2]

print(s)

Fixed submission:
s = input()
n = int(input())
b = ''
a = ''
h = 0
for i in range(n):
    qq = list(input().split())
    if qq[0] == '1':
        h += 1
    else:
        if qq[1] == '1':
            if h % 2 ==1:
                a = a + qq[2]
            else:
                b = qq[2] + b
        else:
            if h % 2 ==1:
                b = qq[2] + b
            else:
                a = a + qq[2]

s = b + s + a
if h % 2 ==1:
    s = s[::-1]
print(s)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))

ans = 'YES'
for i in range(n):
    for j in range(i+1,n):
        if a[i] == a[j]:
            ans = 'NO'



print(ans)

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

b = set(a)

if len(a) == len(b):
    print('YES')
else:
    print('NO')
Buggy python submission (verdict: Time Limit Exceeded):
import copy
n,k = map(int, input().split())
p = list(map(int, input().split()))

max_set = p[:k]
pair = p[:k]
for i in range(n-k):
    pair.remove(p[i])
    pair.append(p[i+k])
    if sum(max_set) < sum(pair):
        max_set = copy.copy(pair)

ans = 0
for i in max_set:
    ans += (i+1)/2
print(ans)

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

max_set = sum(p[:k])
pair = sum(p[:k])
for i in range(n-k):
    pair -= p[i]
    pair += p[i+k]
    if max_set < pair:
        max_set = pair

print((max_set+k)/2)

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

max_set = [0]
for i in range(n-k+1):
    pair = []
    for j in range(k):
        pair.append(p[i+j])
    if sum(max_set) < sum(pair):
        max_set = copy.copy(pair)

ans = 0
for i in max_set:
    ans += (i+1)/2
print(ans)

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

max_set = sum(p[:k])
pair = sum(p[:k])
for i in range(n-k):
    pair -= p[i]
    pair += p[i+k]
    if max_set < pair:
        max_set = pair

print((max_set+k)/2)
Buggy python submission (verdict: Runtime Error):
import math
a,b = map(int,input().split())

g = a*b/math.gcd(a,b)
print(g)


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

g = a*b/fractions.gcd(a,b)
print(int(g))
Buggy python submission (verdict: Runtime Error):
x = int(input())

nokori = x%100
max_n = x//100
print(int(nokori/5) + int(nokori%5/4) + int(nokori%5%4/3) + int(nokori%5%4%3/2) + int(nokori%5%4%3%2)
if max_n < int(nokori/5) + int(nokori%5/4) + int(nokori%5%4/3) + int(nokori%5%4%3/2) + nokori%5%4%3%2:
    print(0)
else:
    print(1)


Fixed submission:
x = int(input())

nokori = x%100
max_n = x//100

if max_n < nokori//5 + nokori%5//4 + nokori%5%4//3 + nokori%5%4%3//2 + nokori%5%4%3%2:
    print(0)
else:
    print(1)
Buggy python submission (verdict: Runtime Error):
s = input()

all = ['SUN','MON','TUE','WED','THU','FRI','SAT']


for i range(7):
	if all[i] == s:
		c = i
        
print(7-i)

Fixed submission:
s = input()
 
all_ = ['SUN','MON','TUE','WED','THU','FRI','SAT']
 
 
for i in range(7):
    if all_[i] == s:
        break
        
print(7-i)
Buggy python submission (verdict: Runtime Error):
import copy
S = list(input())
K = int(input())


a = S[0]
c = 0
S2 = copy.deepcopy(S)
for i in range(1,len(S)):
    if S[i] == S[i-1]:
        S[i] = '1'
        c += 1
if S[0] == S[-1]:
    c3 = 0
    S3 = copy.deepcopy(S)
    for i in range(2,len(S)+1):
        if S3[i] == S3[i-1]:
            S3[i] = '1'
            c3 += 1
    print(c + c3*(K-1))
else:
    print(c*K)



Fixed submission:
import copy
S = list(input())
K = int(input())


a = S[0]
c = 0
S2 = copy.deepcopy(S)
for i in range(1, len(S)):
    if S2[i] == S2[i-1]:
        S2[i] = '1'
        c += 1

a = S[-1]
last = 0
for i in range(2, len(S)+1):
    last += 1
    if S[-i] != a:
        break

if all([e == S[0] for e in S[1:]]) == True:
    if len(S)%2==0:
        print(int(len(S)/2*K))
    else:
        print(int(len(S)//2*((K+1)//2)+(len(S)//2+1)*(K//2)))
elif S[0] == S[-1] and last % 2 == 1:
    c3 = 0
    S3 = copy.deepcopy(S)
    for i in range(2, len(S)):
        if S3[i] == S3[i-1]:
            S3[i] = '1'
            c3 += 1
    print(c + (c3+1)*(K-1))
else:
    print(c*K)

Buggy python submission (verdict: Runtime Error):
import copy
S = list(input())
K = int(input())


a = S[0]
c = 0
S2 = copy.copy(S)
for i in range(1,len(S)):
    if S[i] == S[i-1]:
        S[i] = '1'
        c += 1
if S[0] == S[-1]:
    c3 = 0
    S3 = copy.copy(S)
    for i in range(2,len(S)+1):
        if S3[i] == S3[i-1]:
            S3[i] = '1'
            c3 += 1
    print(c + c3*(K-1))
else:
    print(c*K)



Fixed submission:
import copy
S = list(input())
K = int(input())


a = S[0]
c = 0
S2 = copy.deepcopy(S)
for i in range(1, len(S)):
    if S2[i] == S2[i-1]:
        S2[i] = '1'
        c += 1

a = S[-1]
last = 0
for i in range(2, len(S)+1):
    last += 1
    if S[-i] != a:
        break

if all([e == S[0] for e in S[1:]]) == True:
    if len(S)%2==0:
        print(int(len(S)/2*K))
    else:
        print(int(len(S)//2*((K+1)//2)+(len(S)//2+1)*(K//2)))
elif S[0] == S[-1] and last % 2 == 1:
    c3 = 0
    S3 = copy.deepcopy(S)
    for i in range(2, len(S)):
        if S3[i] == S3[i-1]:
            S3[i] = '1'
            c3 += 1
    print(c + (c3+1)*(K-1))
else:
    print(c*K)
Buggy python submission (verdict: Runtime Error):
import numpy as np


n,m = map(int,input().split())
a = np.array(list(map(int,input().split())))
for i in range(m):
    a[a.argmax()] = a[a.argmax()]//2 
print(np.sum(a))


Fixed submission:
s = input()

if s == 'Sunny':
    print('Cloudy')
elif s == 'Cloudy':
    print('Rainy')
else:
    print('Sunny')

Buggy python submission (verdict: Runtime Error):
import numpy as np
n = list(map(int,input().split()))
a = np.array(list(map(int,input().split())))
print(a)
for i in range(n[1]):
    a[a.argmax()] = a[a.argmax()]//2 
print(np.sum(a))


Fixed submission:
s = input()

if s == 'Sunny':
    print('Cloudy')
elif s == 'Cloudy':
    print('Rainy')
else:
    print('Sunny')

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

a = [int(input()) for i in range(n[2])]

for i in range(n[0]):
    if n[1]-(n[2]-a.count(i+1)) <= 0:
        print('No')
    else:
        print('Yes')


Fixed submission:
s = input()

if s == 'Sunny':
    print('Cloudy')
elif s == 'Cloudy':
    print('Rainy')
else:
    print('Sunny')
Buggy python submission (verdict: Time Limit Exceeded):
n = list(map(int,input().split()))

a = [int(input()) for i in range(n[2])]
kk = n[1]-n[2]


for i in range(n[0]):
    if kk+a.count(i+1) <= 0:
        print('No')
    else:
        print('Yes')


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

a = [int(input()) for i in range(n[2])]
kk = n[1]-n[2]


counter = collections.Counter(a)

for i in range(n[0]):
    if kk+counter[i+1] <= 0:
        print('No')
    else:
        print('Yes')

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

a = [int(input()) for i in range(n[2])]

for i in range(n[0]):
    if n[1]-(n[2]-a.count(i+1)) <= 0:
        print('No')
    else:
        print('Yes')


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

a = [int(input()) for i in range(n[2])]
kk = n[1]-n[2]


counter = collections.Counter(a)

for i in range(n[0]):
    if kk+counter[i+1] <= 0:
        print('No')
    else:
        print('Yes')
Buggy python submission (verdict: Runtime Error):
import numpy as np


n,m = map(int,input().split())
a = np.array(list(map(int,input().split())))
for i in range(m):
    a[a.argmax()] = a[a.argmax()]//2 
print(np.sum(a))


Fixed submission:

N, M = map(int,input().split())
A = list(-int(i) for i in input().split())
import heapq

heapq.heapify(A)
for _ in range(M):
    a = heapq.heappop(A)//(-2)
    heapq.heappush(A,-a)

print(-sum(A))

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
n = list(map(int,input().split()))
a = np.array(list(map(int,input().split())))
for i in range(n[1]):
    a[a.argmax()] = a[a.argmax()]//2 
print(np.sum(a))


Fixed submission:

N, M = map(int,input().split())
A = list(-int(i) for i in input().split())
import heapq

heapq.heapify(A)
for _ in range(M):
    a = heapq.heappop(A)//(-2)
    heapq.heappush(A,-a)

print(-sum(A))

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
import sys
n = list(map(int,input().split()))

a = np.array(list(map(int,input().split())))

for i in range(n[1]):
    a[a.argmax()] = a[a.argmax()]//2 
print(np.sum(a))


Fixed submission:

N, M = map(int,input().split())
A = list(-int(i) for i in input().split())
import heapq

heapq.heapify(A)
for _ in range(M):
    a = heapq.heappop(A)//(-2)
    heapq.heappush(A,-a)

print(-sum(A))

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

for i in range(n[1]):
    a[a.argmax()] = a[a.argmax()]//2 
print(np.sum(a))


Fixed submission:

N, M = map(int,input().split())
A = list(-int(i) for i in input().split())
import heapq

heapq.heapify(A)
for _ in range(M):
    a = heapq.heappop(A)//(-2)
    heapq.heappush(A,-a)

print(-sum(A))

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

for i in range(n[1]):
    a[a.argmax()] = a[a.argmax()]//2 
print(sum(a))


Fixed submission:

N, M = map(int,input().split())
A = list(-int(i) for i in input().split())
import heapq

heapq.heapify(A)
for _ in range(M):
    a = heapq.heappop(A)//(-2)
    heapq.heappush(A,-a)

print(-sum(A))

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

for i in range(n[1]):
    a[a.index(max(a))] = a[a.index(max(a))]//2 
print(sum(a))


Fixed submission:

N, M = map(int,input().split())
A = list(-int(i) for i in input().split())
import heapq

heapq.heapify(A)
for _ in range(M):
    a = heapq.heappop(A)//(-2)
    heapq.heappush(A,-a)

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

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

num = 0

import math

lcm = c*d//int(math.gcd(c, d))

num = b-b//c-b//d+b//lcm-((a-1)-(a-1)//c-(a-1)//d+(a-1)//lcm)





print(str(num))

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

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

num = 0

import fractions
lcm = c*d//int(fractions.gcd(c, d))

num = b-b//c-b//d+b//lcm-((a-1)-(a-1)//c-(a-1)//d+(a-1)//lcm)





print(str(num))

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

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

num = 0
for i in range(a,b+1):
    if i%c != 0 and i%d != 0:
        num += 1

print(str(num))

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

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

num = 0

import fractions
lcm = c*d//int(fractions.gcd(c, d))

num = b-b//c-b//d+b//lcm-((a-1)-(a-1)//c-(a-1)//d+(a-1)//lcm)





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

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

a = input().split()
num = 0

for i,s in enumerate(a):
  for j,g in enumerate(a):
    sum = 0
    for l,e in enumerate(a):
      if l >= i and l <= j:
        sum += int(e)
    if sum >= int(k):
       num += 1

print(str(num))

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

x,a = map(int, input().split())
if x<a:
  print("0")
else:
  print("10")
Buggy python submission (verdict: Runtime Error):
d,n = map(int,input().split())
 
if d == 0:
    if n == 100:
        print(101)
  print(n)
else:
    if d == 1 and n == 100:
        print(10001)
  print(100*d*n)


Fixed submission:
d,n = map(int,input().split())
 
if d == 0:
    if n == 100:
        print(101)
    else: 
        print(n)
else:
    if n == 100:
        print(pow(100,d)*(n+1)) 
    else:
        print(pow(100,d)*n)

Buggy python submission (verdict: Runtime Error):
d,n = map(int,input())

if d == 0:
  print(n)
else:
  print(100*d*n)

Fixed submission:
d,n = map(int,input().split())
 
if d == 0:
    if n == 100:
        print(101)
    else: 
        print(n)
else:
    if n == 100:
        print(pow(100,d)*(n+1)) 
    else:
        print(pow(100,d)*n)
Buggy python submission (verdict: Runtime Error):
s = input()
t = input()

ans = []
for i in range(len(s)-(len(t)-1)):
    f = True
    for j in range(len(t)):
        if s[-(j+i+1)] != t[-(j+1)] and s[-(j+i+1)] != '?':
            f = False
    if f == True:
        s = s[:-(len(t)+i)] + t + s[len(s)-1-i:0]
        s = s.replace('?','a')
        ans.append(s)



if len(ans) > 0:
    print(sorted(ans)[0])
else:
    print('UNRESTORABLE')

Fixed submission:
s = input()
t = input()

ans = []
for i in range(len(s)-(len(t)-1)):
    f = True
    for j in range(len(t)):
        if s[j+i] != t[j] and s[j+i] != '?':
            f = False
    if f == True:
        s2 = s[:i] + t + s[i+len(t):]
        s2 = s2.replace('?','a')
        ans.append(s2)



if len(ans) > 0:
    print(min(ans))
else:
    print('UNRESTORABLE')
Buggy python submission (verdict: Time Limit Exceeded):
k,s = map(int,input().split())

ans = 0
b = []
for i in range(k+1):
    for j in range(k+1):
        if i + j <= s:
            b.append(i+j)

for i in b:
    for j in range(k+1):
        if i + j == s:
            ans += 1
            break
print(ans)

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

ans = 0
for i in range(k+1):
    for j in range(k+1):
        l = s - i - j
        if l <= k and l >= 0:
            ans += 1

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
k,s = map(int,input().split())

ans = 0
for i in range(k+1):
    for j in range(k+1):
        for l in range(k+1):
            if i + j + l == s:
                ans += 1
print(ans)

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

ans = 0
for i in range(k+1):
    for j in range(k+1):
        l = s - i - j
        if l <= k and l >= 0:
            ans += 1

print(ans)
Buggy python submission (verdict: Runtime Error):
n,k = input().split()
d = list(input().split())

ans = ''

for i in range(10):
    if not str(i) in d:
        sm = str(i)
        break

for i in range(len(str(n))):
    if n[i] in d:
        co = str(int(n[i])+1)
        while(1):
            if not co in d:
                break
            co = co + 1
        ans = ans + co + sm*(len(n)-i-1)
        break
    else:
        ans = ans + n[i]
print(ans)




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

while 1:
    if all(dd not in str(n) for dd in d):
        print(n)
        break
    n = n+1
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

def imos(n,k,a):
    
    l=np.zeros((n+1),dtype=np.int64)
    for i in range(n):
        ai=a[i]
        start=max(0,i-ai) #StartIndex
        end=min(n,i+ai+1) #EndIndex + 1
        l[start]+=1
        l[end]-=1
    return np.cumsum(l)[:n]

if __name__=="__main__":
    n,k=map(int, input().split())
    a=list(map(int, input().split()))
    for _ in range(k):
        a=imos(n,k,a)
        if a.min()==n:
            break   
    
    print(*a)


Fixed submission:
import numpy as np
from numba import njit

@njit #処理の並列化
def imos(n,k,a):
    
    l=np.zeros((n+1),dtype=np.int64)
    for i in range(n):
        ai=a[i]
        start=max(0,i-ai) #StartIndex
        end=min(n,i+ai+1) #EndIndex + 1
        l[start]+=1
        l[end]-=1
    return np.cumsum(l)[:n]

if __name__=="__main__":
    n,k=map(int, input().split())
    a=list(map(int, input().split()))
    for _ in range(k):
        a=imos(n,k,a)
        if a.min()==n:
            break   
    
    print(*a)
Buggy python submission (verdict: Runtime Error):
if aa in (2,4,5,7,9):
    print('hon')
    exit()
if aa in (0,1,6,8):
    print('pon')
    exit()
if aa == 3:
    print('bon')
    exit()

Fixed submission:

a = int(input())
x = str(a)
aa = int(x[len(x)-1])

if aa in (2,4,5,7,9):
    print('hon')
    exit()
if aa in (0,1,6,8):
    print('pon')
    exit()
if aa == 3:
    print('bon')
    exit()
Buggy python submission (verdict: Runtime Error):
n,k = map(int,input().split())
a = list(map(int, input().split()))
ns = [0] * (n+1)
tree = []

ns = [0] * n
ns[0] = 1
# max 2*10**5
# どこかでループしてる
nexti = 0
starti = 0
endi = 0
tree.append(nexti)

while  k > 0 :
    nexti = a[nexti] - 1
    if ns[nexti] == 1:
        starti = nexti
        break
    ns[nexti] = 1
    endi = nexti
    tree.append(nexti)

x = tree.index(starti) 
# y = tree[starti:]
y = len(tree[x:])

if k - x <= 0:
    print(tree[k-1])
else:
    k = k - x
    z = k % y
    if starti == 0:
        starti = -1
    temp = tree[starti+1:]

    print(temp[z]+1)

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

    num = 1
    l = []
    s = [1]*n

    while s[num-1]:
        l.append(num)
        s[num-1] = 0
        num = a[num-1]

    if l.index(num) <= k:
        l2 = l[l.index(num):]
        kk = (k-len(set(l)-set(l2)))%len(l2)
        print(l2[kk])
    else:
        print(l[k])

main()

Buggy python submission (verdict: Runtime Error):
n,k = map(int,input().split())
a = list(map(int, input().split()))
ns = [0] * (n+1)
tree = []

ns = [0] * n
ns[0] = 1
# max 2*10**5
# どこかでループしてる
nexti = 0
starti = 0
endi = 0
tree.append(nexti)

while  k > 0 :
    nexti = a[nexti] - 1
    if ns[nexti] == 1:
        starti = nexti
        break
    ns[nexti] = 1
    endi = nexti
    tree.append(nexti)

x = tree.index(starti) 
# y = tree[starti:]
y = len(tree[x:])

if k - x <= 0:
    print(tree[k-1])
else:
    k = k - x
    z = k % y
    if starti == 0:
        starti = -1
    temp = tree[starti+1:]

    print(temp[z] + 1,temp,z)

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

    num = 1
    l = []
    s = [1]*n

    while s[num-1]:
        l.append(num)
        s[num-1] = 0
        num = a[num-1]

    if l.index(num) <= k:
        l2 = l[l.index(num):]
        kk = (k-len(set(l)-set(l2)))%len(l2)
        print(l2[kk])
    else:
        print(l[k])

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

for i in range(n):
    print(a.count(i+1))

Fixed submission:
n = int(input()) 
a = list(map(int, input().split()))
x = [0]*n
for i in a:
    x[i-1] += 1
for _ in x:
    print(_)

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

for i in range(n):
    print(a.count(i+1))

Fixed submission:
n = int(input()) 
a = list(map(int, input().split()))
x = [0]*n
for i in a:
    x[i-1] += 1
for _ in x:
    print(_)
Buggy python submission (verdict: Time Limit Exceeded):
import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)

k = int(input())
ans = 0
a = [i + 1 for i in range(k)]
b = [i + 1 for i in range(k)]
c = [i + 1 for i in range(k)]

for x in a:
    for y in b:
        for z in c:
            ans += gcd(x, y, z)

print(ans)

Fixed submission:
import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)

k = int(input())
ans = 0
a = [i + 1 for i in range(k)]
b = [i + 1 for i in range(k)]
c = [i + 1 for i in range(k)]

for x in a:
    for y in b:
        for z in c:
            ans += gcd(x, y, z)

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n,k = map(int,input().split())
while n > abs(n-k):
  n = abs(n-k)
print(n)

Fixed submission:
n,k = map(int,input().split())
n = n%k
while n > abs(n-k):
  n = abs(n-k)
print(n)