Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

def main():

    N, K, Q = map(int, input().split())
    player = np.array([K] * N)
    sub = np.array([-1] * N)
    A = [int(input()) for i in range(Q)]
    for i in range(Q):
        player[A[i] - 1] += 1
        player += sub
    for k in range(N):
        if player[k] <= 0:
            print("No")
        else:
            print("Yes")

if __name__ == "__main__":
    main()

Fixed submission:
import numpy as np

def main():

    N, K, Q = map(int, input().split())
    player = np.array([K - Q] * N)
    sub = np.array([-1] * N)
    A = [int(input()) for i in range(Q)]
    for i in range(Q):
        player[A[i] - 1] += 1
    for k in range(N):
        if player[k] <= 0:
            print("No")
        else:
            print("Yes")

if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():

    N, K, Q = map(int, input().split())
    player = [K] * N
    A = []
    for _ in range(Q):
        a = int(input())
        A.append(a)
    for i in range(Q):
        player[A[i] - 1] += 1
        player = [j - 1 for j in player]
    for k in range(N):
        if player[k] <= 0:
            print("No")
        else:
            print("Yes")

if __name__ == "__main__":
    main()

Fixed submission:
import numpy as np

def main():

    N, K, Q = map(int, input().split())
    player = np.array([K - Q] * N)
    sub = np.array([-1] * N)
    A = [int(input()) for i in range(Q)]
    for i in range(Q):
        player[A[i] - 1] += 1
    for k in range(N):
        if player[k] <= 0:
            print("No")
        else:
            print("Yes")

if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
def main():

    n, m = map(int, input().split())
    a = list(map(int, input().split()))
    total = 0
    for _ in range(m):
        mx = max(a)
        a[a.index(mx)] //= 2
    for i in range(n):
        total += a[i]
    print(total)

if __name__ == "__main__":
    main()

Fixed submission:
import heapq

def main():

    n, m = map(int, input().split())
    a = list(map(lambda x: int(x) * (-1), input().split()))
    heapq.heapify(a)
    sum = 0

    for _ in range(m):
        mn = heapq.heappop(a)
        heapq.heappush(a, (-1) * (-mn // 2))

    for i in range(n):
        sum += a[i]

    print(-sum)

if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
def main():

    N = int(input())
    S = []
    cnt = 0
    for _ in range(N):
        s = input()
        S.append(sorted(s))
    for i in range(N - 1):
        for j in range(i + 1, N):
            if S[i] == S[j]:
                cnt += 1
    print(cnt)

if __name__ == "__main__":
    main()


Fixed submission:
def main():

    N = int(input())
    S = {}
    cnt = 0
    for _ in range(N):
        s = list(input())
        s.sort()
        s = "".join(s)
        if s not in S:
            S[s] = 0
        else:
            S[s] += 1
            cnt += S[s]
    print(cnt)

if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
def main():

    N, M = map(int, input().split())
    A = [int(input()) for _ in range(M)]
    stairs = [0] * N
    for i in range(N):
        if (i + 1) in A:
            stairs[i] = 0
        elif i == 0:
            stairs[i] = 1
        elif i == 1:
            stairs[i] = 1 + stairs[i - 1]
        else:
            stairs[i] = (stairs[i - 1] + stairs[i - 2]) % (10 ** 9 + 7)
    print(stairs[N - 1])

if __name__ == "__main__":
    main()

Fixed submission:
def main():

    N, M = map(int, input().split())
    stairs = [1] * N
    ans = [0] * N
    for _ in range(M):
        stairs[int(input()) - 1] = 0
    for i in range(N):
        if i == 0:
            ans[i] = stairs[i]
        elif i == 1:
            ans[i] = ans[i - 1] * stairs[i - 1] + stairs[i]
        else:
            ans[i] = (stairs[i - 1] * ans[i - 1] + stairs[i - 2] * ans[i - 2]) % (10 ** 9 + 7)
    print(ans[N - 1])

if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
n,m = input().split()
a = [i for i in input.split()]
if sum(a)>n:
    print(-1)
else:
    print(m-sum(a))

Fixed submission:
n,m = (int(x) for x in input().split())
a = [int(i) for i in input().split()]
if sum(a)>n:
    print(-1)
else:
    print(n-sum(a))
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = [int(i) for i in input().split()]
A = [0 for i in range(n)]
for aa in a:
    A[a]+=1
for aa in A:
    print(aa)

Fixed submission:
n = int(input())
a = [int(i) for i in input().split()]
A = [0 for i in range(n)]
for aa in a:
    A[int(aa)-1]+=1
for aaa in A:
    print(aaa)

Buggy python submission (verdict: Runtime Error):
n = int(input())
a = [int(i) for i in input().split()]
A = [0 for i in range(n)]
for aa in a:
    A[a]+=1
for aa in A:
    print(aa)

Fixed submission:
n = int(input())
a = [int(i) for i in input().split()]
A = [0 for i in range(n)]
for aa in a:
    A[int(aa)-1]+=1
for aaa in A:
    print(aaa)

Buggy python submission (verdict: Runtime Error):
n = int(input())
a = [int(i) for i in input().split()]
A = [0 for i in range(n)]
for aa in a:
    A[a]+=1
for aa in A:
    print(aa)

Fixed submission:
n = int(input())
a = [int(i) for i in input().split()]
A = [0 for i in range(n)]
for aa in a:
    A[int(aa)-1]+=1
for aaa in A:
    print(aaa)
Buggy python submission (verdict: Runtime Error):
n,k = (int(x) for x in input().split())
M = 10**9+7
s = 0

for i in range(n+2-k):
    ad = 1 + (n+1-k-i)*(k+i)
    s += ad
    if s >= M:
        s -= N
        
print(s)

Fixed submission:
n,k = (int(x) for x in input().split())
M = 10**9+7
s = 0

for i in range(n+2-k):
    ad = 1 + (n+1-k-i)*(k+i)
    s += ad
#if s >= M:
#    s -= M
        
print(s%M)

Buggy python submission (verdict: Runtime Error):
n,k = (int(x) for x in input().split())
M = 10**9+7
s = 0

for i in range(n-k):
    ad = 1 + i*(n-i+1)
    s += ad
    if s >= M:
        s -= N
        
print(s)

Fixed submission:
n,k = (int(x) for x in input().split())
M = 10**9+7
s = 0

for i in range(n+2-k):
    ad = 1 + (n+1-k-i)*(k+i)
    s += ad
#if s >= M:
#    s -= M
        
print(s%M)
Buggy python submission (verdict: Runtime Error):
N,L=map(int ,input().split())
print((2*L+N)*(N-1)/2 )

Fixed submission:
N,L=map(int ,input().split())
if L >= 0:
    print(int((2*L+N)*(N-1)/2) )
elif L < 0 and L+N-1>=0:
    print(int((2*L+N-1)*(N)/2) )
else:
    print(int((2*L+N-2)*(N-1)/2) )
Buggy python submission (verdict: Runtime Error):
import math
def lcm(x, y):
    return (x * y) // math.gcd(x, y)

A,B,C,D=map(int ,input().split())
a = B//C-(A-1)//C
b = B//D-(A-1)//D
c  =lcm(C,D)
d = B//c-(A-1)//c
e = B - A +1 - a -b + d 
print(e)

Fixed submission:
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

def lcm(x, y):
    return (x * y) // gcd(x, y)

A,B,C,D=map(int ,input().split())
a = B//C-(A-1)//C
b = B//D-(A-1)//D
c  =lcm(C,D)
d = B//c-(A-1)//c
e = B - A +1 - a -b + d 
print(e)

Buggy python submission (verdict: Runtime Error):
import math
A,B,C,D=map(int ,input().split())
a = B//C-A//C
b = B//D-A//D
c  = math.gcd(C,D)
d = B//c-A//c
e = B - A - a -b + d 
print(e)

Fixed submission:
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

def lcm(x, y):
    return (x * y) // gcd(x, y)

A,B,C,D=map(int ,input().split())
a = B//C-(A-1)//C
b = B//D-(A-1)//D
c  =lcm(C,D)
d = B//c-(A-1)//c
e = B - A +1 - a -b + d 
print(e)
Buggy python submission (verdict: Runtime Error):
import numpy as np
N =int(input())
A =[]
B =[]
for i in range(N):
    a,b = map(int,input().split())
    A.append(a)
    B.append(b)
index = np.argsort(B)
time = 0
f = 0
for i in index:
    time += A[index]
    if time>B[index]:
        f = 1
        break
if f == 1:
    print('No')
else:
    print('Yes')

Fixed submission:
import numpy as np
N =int(input())
A =[]
B =[]
for i in range(N):
    a,b = map(int,input().split())
    A.append(a)
    B.append(b)
index = np.argsort(B)
time = 0
f = 0
for i in index:
    time += A[i]
    if time>B[i]:
        f = 1
        break
if f == 1:
    print('No')
else:
    print('Yes')
Buggy python submission (verdict: Runtime Error):
N X=map(int ,raw_input().split())
L =list(map(int ,raw_input().split()))
p = 0
y = -1
for i in range(N):
    p += L[i]
    if p>X:
        y = i
        break
if y>=0:
    print y
else:
    print X

Fixed submission:
N,X=map(int ,raw_input().split())
L =list(map(int ,raw_input().split()))
p = 0
y = -1
for i in range(N):
    p += L[i]
    if p>X:
        y = i
        break
if y>=0:
    print y+1
else:
    print N+1
Buggy python submission (verdict: Runtime Error):
W,H,x,y =map(int ,raw_input().split())
i = 0
if x*2 == W and y +2 ==H:
    i = 1
print float(W*H)/2,i

Fixed submission:
W,H,x,y =map(int ,raw_input().split())
i = 0
if x*2 == W and y*2 ==H:
    i = 1
print float(W*H)/2,i

Buggy python submission (verdict: Runtime Error):
W,H,x,y ==map(int ,raw_input().split())
i = 0
if x*2 == W and y +2 ==H:
    i = 1
print float(W*H)/2,i

Fixed submission:
W,H,x,y =map(int ,raw_input().split())
i = 0
if x*2 == W and y*2 ==H:
    i = 1
print float(W*H)/2,i

Buggy python submission (verdict: Runtime Error):
W,H,x,y ==map(int ,raw_input().split())
i = 0
if x*2 = W and y +2 =H:
    i = 1
print float(W*H)/2,i

Fixed submission:
W,H,x,y =map(int ,raw_input().split())
i = 0
if x*2 == W and y*2 ==H:
    i = 1
print float(W*H)/2,i
Buggy python submission (verdict: Runtime Error):
S =raw_input()
print (S-2)*180

Fixed submission:
S =int(raw_input())
print (S-2)*180
Buggy python submission (verdict: Runtime Error):
N =int(raw_input())
S =[]
P =[]
for i in range(N):
    s,p=map(str,raw_input().split())
    S.append(s)
    P.append(p)
ss=sorted(list(set(S)))
for i in range(len(ss)):
    a =[]
    b =[]
    for j in range(N):
        if ss[i]==S[j]:
            a.append(j)
            b.append(P[i])
    c = list(sorted(b)).reverse()
    if len(c)>0:
        for k in c:
            for j in range(len(b)):
                if k == b[j]:
                    print(a[j])



Fixed submission:
N =int(raw_input())
S =[]
P =[]
for i in range(N):
    s,p=map(str,raw_input().split())
    S.append(s)
    P.append(int(p))
ss=sorted(list(set(S)))
for sss in ss:
    a =[]
    b =[]
    for j in range(N):
        if sss==S[j]:
            a.append(j)
            b.append(P[j])
    if len(b)>0:
        c = sorted(b,reverse=True)
        #print c,b
        for k in c:
            for j in range(len(b)):
                if k == b[j]:
                    print(a[j]+1)

Buggy python submission (verdict: Runtime Error):
N =int(raw_input())
S =[]
P =[]
for i in range(N):
    s,p=map(str,raw_input().split())
    S.append(s)
    P.append(p)
ss=sorted(list(set(S)))
for i in range(len(ss)):
    a =[]
    b =[]
    for j in range(N):
        if ss[i]==S[j]:
            a.append(j)
            b.append(P[i])
    c = sorted(b).reverse()
    for k in c:
        for j in range(len(b)):
            if k == b[j]:
                print(a[j])

Fixed submission:
N =int(raw_input())
S =[]
P =[]
for i in range(N):
    s,p=map(str,raw_input().split())
    S.append(s)
    P.append(int(p))
ss=sorted(list(set(S)))
for sss in ss:
    a =[]
    b =[]
    for j in range(N):
        if sss==S[j]:
            a.append(j)
            b.append(P[j])
    if len(b)>0:
        c = sorted(b,reverse=True)
        #print c,b
        for k in c:
            for j in range(len(b)):
                if k == b[j]:
                    print(a[j]+1)

Buggy python submission (verdict: Runtime Error):
N =int(raw_input())
S =[]
P =[]
for i in range(N):
    s,p=map(str,raw_input().split())
    S.append(s)
    P.append(p)
ss=sorted(list(set(S)))
for i in range(len(ss)):
    a =[]
    b =[]
    for j in range(100):
        if ss[i]==S[j]:
            a.append(j)
            b.append(P[i])
    c = sorted(b).reverse()
    for k in c:
        for j in range(len(b)):
            if k == b[j]:
                print(a[j])

Fixed submission:
N =int(raw_input())
S =[]
P =[]
for i in range(N):
    s,p=map(str,raw_input().split())
    S.append(s)
    P.append(int(p))
ss=sorted(list(set(S)))
for sss in ss:
    a =[]
    b =[]
    for j in range(N):
        if sss==S[j]:
            a.append(j)
            b.append(P[j])
    if len(b)>0:
        c = sorted(b,reverse=True)
        #print c,b
        for k in c:
            for j in range(len(b)):
                if k == b[j]:
                    print(a[j]+1)
Buggy python submission (verdict: Runtime Error):
import numpy as np
A =int(raw_input())
B =int(raw_input())
T =int(raw_input())
print str(int(np.trunc((T+0.5)/A)*B))

Fixed submission:
import numpy as np
nums = map(int ,raw_input().split())
print str(int(np.trunc((nums[2]+0.5)/nums[0])*nums[1]))

Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
import numpy as np
A =int(raw_input())
B =int(raw_input())
T =int(raw_input())
print str(int(np.trunc((T+0.5)/A)*B))

Fixed submission:
import numpy as np
nums = map(int ,raw_input().split())
print str(int(np.trunc((nums[2]+0.5)/nums[0])*nums[1]))

Buggy python submission (verdict: Runtime Error):
import numpy as np
A =int(raw_input())
B =int(raw_input())
T =int(raw_input())
print str(int(np.trunc((T+0.5)/A)*B))

Fixed submission:
import numpy as np
nums = map(int ,raw_input().split())
print str(int(np.trunc((nums[2]+0.5)/nums[0])*nums[1]))

Buggy python submission (verdict: Runtime Error):
import numpy as np
A =int(raw_input())
B =int(raw_input())
T =int(raw_input())
print int(np.trunc((T+0.5)/A)*B)

Fixed submission:
import numpy as np
nums = map(int ,raw_input().split())
print str(int(np.trunc((nums[2]+0.5)/nums[0])*nums[1]))
Buggy python submission (verdict: Runtime Error):
N =int(raw_input())
V =map(int ,raw_input().split())
C =map(int ,raw_input().split())
V = V-C
v = 0
for i in range(N):
    if V[i]>0:
        v = v+V[i]
print v

Fixed submission:
N =int(raw_input())
V =map(int ,raw_input().split())
C =map(int ,raw_input().split())
v = 0
for i in range(N):
    if V[i]-C[i]>0:
        v = v+V[i]-C[i]
print v
Buggy python submission (verdict: Runtime Error):
s=input()
count=0
i=0
while i<len(s):
    summ=0
    while s[i]=='R':
        summ+=1
        i+=1
    if summ>count:
        count=summ
    i+=1


print(count)        

Fixed submission:
s=input()
count=0
i=0
while i<len(s):
    summ=0
    while i<len(s) and s[i]=='R':
        summ+=1
        i+=1
    if summ>count:
        count=summ
    i+=1


print(count)
Buggy python submission (verdict: Time Limit Exceeded):
x,k,d=map(int,input().split())
i=0
while i<k:
    pos=abs(x-d)
    neg=abs(x+d)
    if pos<=neg:
        x=x-d
    elif neg<pos:
        x=x+d
    else:
        break
    i+=1
print(abs(x))

Fixed submission:
x,k,d=map(int,input().split())
x=abs(x)
if x>k*d:
    print(x-k*d)
else:
    if (k-x//d)%2==0:
        print(x-d*(x//d))
    else:
 
        print(abs(d-(x-d*(x//d))))

Buggy python submission (verdict: Time Limit Exceeded):
x,k,d=map(int,input().split())
for _ in range(k):
    pos=abs(x-d)
    neg=abs(x+d)
    if pos<neg:
        x=x-d
    else:
        x=x+d
print(abs(x))

Fixed submission:
x,k,d=map(int,input().split())
x=abs(x)
if x>k*d:
    print(x-k*d)
else:
    if (k-x//d)%2==0:
        print(x-d*(x//d))
    else:
 
        print(abs(d-(x-d*(x//d))))
Buggy python submission (verdict: Runtime Error):
R, C, K = map(int, input().split(" "))
board = [ [0]*(C+1) for _ in range(R+1) ]
for _ in range(K) :
    i, j, v = map(int, input().split(" "))
    board[i][j] = v

score = [ [ [0]*4 for _ in range(C+1) ] for _ in range(R+1) ] 

for i in range(1, R+1) :
    for j in range(1, C+1) : 
        if board[i][j] == 0 :
            for k in range(4) :
                score[i][j][k] = score[i][j-1][k]    
        else :
            for k in range(3):
                score[i][j][k+1] = score[i][j-1][k] + board[i][j]
        
        descent = max(score[i-1][j])
        score[i][j][1] = max(descent + board[i][j], score[i][j-1][1], score[i][j-1][0]+board[i][j])
        score[i][j][0] = max(descent, score[i][j-1][0])



print(max(score[-1][-1]))


Fixed submission:
s = input()
prev = "R"
res = 0
a = 0
for c in s :
    if c=="R" :
        a+=1
    else :
        a = 0
    res = max(res, a)
print(res)
Buggy python submission (verdict: Time Limit Exceeded):
def solve():
    MAX = 1000001
    N = int(input())
    arr = list(map(int, input().split(" ")))
    arr.sort()
    is_ans = [True]*MAX
    ans = 0

    dup = set()
    for a in arr :
        if a in dup:
            j = a
            while j < MAX :
                is_ans[j] = False
                j += a

        dup.add(a)

    for a in arr :
        if is_ans[a]:
            ans += 1
            j = a
            while j < MAX :
                is_ans[j] = False
                j += a

    return ans

print(solve())


Fixed submission:
def solve():
    MAX = 1000001
    N = int(input())
    arr = list(map(int, input().split(" ")))
    arr.sort()
    is_ans = [True]*MAX
    ans = 0

    dup = set()
    for a in arr :
        if a in dup and is_ans[a] :
            j = a
            while j < MAX :
                is_ans[j] = False
                j += a

        dup.add(a)

    for a in arr :
        if is_ans[a]:
            ans += 1
            j = a
            while j < MAX :
                is_ans[j] = False
                j += a

    return ans

print(solve())
Buggy python submission (verdict: Runtime Error):
N, A, B, C = map(int, input().split(" "))
commands = []
data = {
    'A': A,
    'B': B,
    'C': C
}
ans = [] 

if A >=1 and B >= 1 and C >= 1 :
    print("Yes")
    for _ in range(N) :
        command = input()
        if data[command[0]] > data[command[1]] :
            data[command[0]] -= 1
            data[command[1]] += 1
            print(command[1])
        else :
            data[command[0]] += 1
            data[command[1]] -= 1
            print(command[0]) 
else :
    safe = []
    commands = []
    for _ in range(N) :
        commands.append(input())

    fail = False
    i = 0 
    ans = []
    
    while i < N : 
        if data[commands[i][0]] == 0 and data[commands[i][1]] == 0 :
            if safe == [] :
                fail = True
                break
            else : 
                data, i, _ans = safe.pop()
                ans = ans[:i+1]
                ans.append(_ans)
                
        elif data[commands[i][0]] == 1 and data[commands[i][1]] == 1 :
            _data = { 'A' :data['A'], 'B' :data['B'], 'C' :data['C'] }
            _i = i
            
            _data[commands[i][1]] += 1
            _data[commands[i][0]] -= 1
            _ans = commands[i][1] 
            safe.append( [_data, _i, _ans] )  

            data[commands[i][0]] += 1
            data[commands[i][1]] -= 1
            ans.append( commands[i][0] )
        else :
            if data[commands[i][0]] > data[commands[i][1]] :
                x = commands[i][0] 
                y = commands[i][1] 
            else :
                x = commands[i][1] 
                y = commands[i][0]

            data[x] -= 1 
            data[y] += 1
            ans.append(y)

        i += 1

    if fail :
        print("No")
    else :
        print("Yes")
        for c in ans :
            print(c)

Fixed submission:
s = input()
if s == "ABC" :
    print("ARC")
else :
    print("ABC")
Buggy python submission (verdict: Runtime Error):
x, y, z = input().split(" ")
print(f"{z} {x} {y}")

Fixed submission:
x, y, z = input().split(" ")
print("{} {} {}".format(z,x,y))

Buggy python submission (verdict: Runtime Error):
x, y, z = input().split(" ")
print( f"{z} {x} {y}")

Fixed submission:
x, y, z = input().split(" ")
print("{} {} {}".format(z,x,y))
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = []*N
A[:] = map(int,input().split())

S = ""
for i in range(N):
  S += str(A.index(i+1)+1)
  if i != N:
    S += " "
  
print(S)

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

S = [' ']*N

for i in range(N):
  S[A[i]-1] = str(i+1)

print(" ".join(S))
Buggy python submission (verdict: Time Limit Exceeded):
N,K,Q = map(int,input().split())

A = [K]*N

for r in range(Q):
  correct = int(input())
  for i in range(N):
    if i != correct-1:
      A[i] = A[i] - 1

for i in range(N):
  if A[i] > 0:
    print('Yes')
  else:
    print('No')

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

A = [K]*N
C = [0]*N

for r in range(Q):
  correct = int(input())
  C[correct-1] = C[correct-1] + 1

for i in range(N):
  A[i] = A[i] - Q + C[i]
  
  if A[i] > 0:
    print('Yes')
  else:
    print('No')
Buggy python submission (verdict: Runtime Error):
import sys

D,T,S = [int(i) for i in sys.stdin.readline()]

if(S*T>=D):
	print("Yes")
else:
	print("No")

Fixed submission:
import sys

D,T,S = [int(i) for i in sys.stdin.readline().split()]

if(S*T>=D):
	print("Yes")
else:
	print("No")
Buggy python submission (verdict: Time Limit Exceeded):
n,k = map(int, input().split())
a = list(map(int,input().split()))
ans = 1
c = [1]
for j in range(1,2*n):
    i = a[c[-1]-1]
    if i in set(c):
        g = i
        break
    c.append(i)
s = c.index(g)
r = len(c)-s
if k <=s:
    print(c[k])
else:
    b = (k-s)%r
    print(c[s+b])

Fixed submission:
n,k = map(int, input().split())
a = list(map(int,input().split()))
ans = 1
c = [1]
d = [0]*(n+5)
d[1] = 1
for j in range(1,2*n):
    i = a[c[-1]-1]
    if d[i] == 1:
        g = i
        break
    # if i in set(c):
    #     g = i
    #     break
    d[i] = 1
    c.append(i)
s = c.index(g)
r = len(c)-s
if k <=s:
    print(c[k])
else:
    b = (k-s)%r
    print(c[s+b])

Buggy python submission (verdict: Runtime Error):
n,k = map(int, input().split())
a = list(map(int,input().split()))
ans = 1
c = [1]
for j in range(2*n):
    i = a[c[-1]-1]
    if i in set(c):
        g = j+1
        break
    c.append(i)
s = c.index(g)

print(c[k] if k < s else c[s - 1 + ((k-s+1) % (len(c)-s+1))])

Fixed submission:
n,k = map(int, input().split())
a = list(map(int,input().split()))
ans = 1
c = [1]
d = [0]*(n+5)
d[1] = 1
for j in range(1,2*n):
    i = a[c[-1]-1]
    if d[i] == 1:
        g = i
        break
    # if i in set(c):
    #     g = i
    #     break
    d[i] = 1
    c.append(i)
s = c.index(g)
r = len(c)-s
if k <=s:
    print(c[k])
else:
    b = (k-s)%r
    print(c[s+b])
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = input()
ans = 0
for i in range(n):
    for j in range(i+1,n):
        for k in range(j+1,n):
            if j-i == k-j:
                continue
            elif len(set([s[i],s[j],s[k]])) >= 3:
                ans += 1
print(ans)

Fixed submission:
n = int(input())
s = input()
r = s.count("R")
g = s.count("G")
b = s.count("B")
c = 0
for i in range(n):
    for j in range(1,int((n-i-1)/2)+1):
        if len(set([s[i],s[i+j],s[i+j+j]])) == 3:
            c += 1
print((r*g*b) - c)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = input()
ans = 0
for i in range(n):
    for j in range(i+1,n):
        for k in range(j+1,n):
            if len(set([s[i],s[j],s[k]])) >= 3 and j-i != k-j:
                ans += 1
print(ans) 

Fixed submission:
n = int(input())
s = input()
r = s.count("R")
g = s.count("G")
b = s.count("B")
c = 0
for i in range(n):
    for j in range(1,int((n-i-1)/2)+1):
        if len(set([s[i],s[i+j],s[i+j+j]])) == 3:
            c += 1
print((r*g*b) - c)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter
n,x,y = map(int, input().split())
x -= 1
y -= 1
ans = [0]*n
dp = [[0]*n for _ in range(n)]
for i in range(n):
    for j in range(n):
         ans[min(abs(i-j),(abs(i-x)+abs(j-y)+1),(abs(i-y)+abs(j-x)+1))]+=1
for k in range(1,n):
    print(ans[k]//2)

Fixed submission:
from collections import Counter
n,x,y = map(int, input().split())
x -= 1
y -= 1
ans = [0]*n
dp = [[0]*n for _ in range(n)]
for i in range(n):
    for j in range(i,n):
         ans[min(abs(i-j),(abs(i-x)+abs(j-y)+1),(abs(i-y)+abs(j-x)+1))]+=1
for k in range(1,n):
    print(ans[k])