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

#"""
N, K = [int(n) for n in input().split(" ")]
Ps = [int(n) for n in input().split(" ")]
Cs = [int(n) for n in input().split(" ")]
#"""
"""
N = 10
K = 58345
Ps = [9, 1, 6, 7, 8, 4, 3, 2, 10, 5]
Cs = [695279662, 988782657, -119067776, 382975538, -151885171, -177220596, -169777795, 37619092, 389386780, 980092719]
"""
"""
N = 3
K = 3
Ps = [3, 1, 2]
Cs = [-1000,-2000,-3000]
"""

circles = []
already = {}
for p in range(N):
    if p not in already:
        tmp = []
        nowp = p
        while nowp not in tmp:
            tmp.append(nowp)
            already[nowp] = 1
            nowp = Ps[nowp] - 1
        circles.append(tmp)

#print(circles)

finalResult = -100000000000

def getCircleScore(circle, start, kk):
    #print(circle, start, kk)
    s = 0
    for k in range(kk):
        index = start + k
        if index >= len(circle):
            index = index % len(circle)
        s += Cs[circle[index]]
    return s

"""
maxCircle = []
maxCircleScore = -10000000000
maxIndex = 0
for circle in circles:
    CircleSum = sum([Cs[n] for n in circle])
    if maxCircleScore <= CircleSum:
        maxCircleScore = CircleSum
        maxCircle = circle
"""
#for circle in [maxCircle]:
for circle in circles:
    
    CircleSum = sum([Cs[n] for n in circle])
    #print(circle, CircleSum)
    score = 0
    if CircleSum > 0:
        score = K // len(circle) * CircleSum

    K = K % len(circle)
    if K == 0:
        K = len(circle)

    maxScore = -100000000000
    for start in range(len(circle)):
        #print("start", start)
        for kk in range(1, K+1):
            s = getCircleScore(circle, start, kk)
            #print(s)
            if maxScore <= s:
                maxScore = s

    final = score + maxScore

    if final >= finalResult:
        finalResult = final

print(finalResult)

Fixed submission:
LL = input()


count = 0
maxcount = 0

for ll in LL:
    if ll == "R":
        count+= 1
    else:
        count = 0
    
    if maxcount <= count:
        maxcount = count

print(maxcount)
Buggy python submission (verdict: Runtime Error):
X, K, D = [int(n) for n in input()]

#X = 10
#K = 1
#D = 2


startN = (D * K - X) // (2 * D)

N1 = startN + 1
N2 = startN
N3 = startN - 1

if N1 < 0:
    N1 = 0
if N2 < 0:
    N2 = 0
if N3 < 0:
    N3 = 0

def getScore(n):
    score = X + n * D - D * (K - n)
    if score < 0:
        score = score * -1
    return score

score1 = getScore(N1)
score2 = getScore(N2)
score3 = getScore(N3)

minScore = score1
if minScore > score2:
    minScore = score2
if minScore > score3:
    minScore = score3

print(minScore)

Fixed submission:
X, K, D = [int(n) for n in input().split(" ")]

#X = 10
#K = 1
#D = 2


startN = (D * K - X) // (2 * D)

N1 = startN + 1
N2 = startN
N3 = startN - 1

if N1 < 0:
    N1 = 0
if N2 < 0:
    N2 = 0
if N3 < 0:
    N3 = 0
if N1 > K:
    N1 = K
if N2 > K:
    N2 = K
if N3 > K:
    N3 = K

def getScore(n):
    score = X + n * D - D * (K - n)
    if score < 0:
        score = score * -1
    return score

score1 = getScore(N1)
score2 = getScore(N2)
score3 = getScore(N3)

minScore = score1
if minScore > score2:
    minScore = score2
if minScore > score3:
    minScore = score3

print(minScore)
Buggy python submission (verdict: Runtime Error):
a = input()
print(a + a * a + a * a * a)

Fixed submission:
a = int(input())

print(a + a ** 2 + a ** 3)
Buggy python submission (verdict: Runtime Error):
W, S = input()

if W >= S:
  print("unsafe")
else:
  print("safe")

Fixed submission:
S, W = map(int, input().split())

if W >= S:
  print("unsafe")
else:
  print("safe")
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = [input() for _ in range(N)]
already = []
for a in A:
  if a not in already:
    already.append(a)
print(len(already))

Fixed submission:
N = int(input())
A = [input() for _ in range(N)]
print(len(list(set(A))))

Buggy python submission (verdict: Runtime Error):
N = int(input())
A = [int(input()) for _ in range(N)]
already = []
for a in A:
  if a not in already:
    already.append(a)
print(len(already))

Fixed submission:
N = int(input())
A = [input() for _ in range(N)]
print(len(list(set(A))))
Buggy python submission (verdict: Time Limit Exceeded):
N, X, Y = [int(n) for n in input().split(" ")]

X = X - 1
Y = Y - 1

D = {}
for i in range(N):
    D[i] = []

for i in range(N):
    if i != N - 1:
        D[i].append(i + 1)
        if i != 0:
            D[i].append(i - 1)
    else:
        D[i].append(i - 1)

D[X].append(Y)
D[Y].append(X)


def search(start):
    queue = [start]
    depth = 0
    dic = {start: 0}

    while len(queue) > 0:
        depth += 1
        nextQueue = []
        while len(queue) > 0:
            now = queue[0]
            del(queue[0])
            neighbors = D[now]
            for n in neighbors:
                if n not in dic:
                    nextQueue.append(n)
                    dic[n] = depth
        queue = nextQueue
    return dic
    
lenD = []
for i in range(N):
    d = search(i)
    lenD.append(d)

kcounter = [0 for _ in range(N - 1)]

for i in range(N):
    for j in range(i + 1, N):
        k = lenD[i][j]
        kcounter[k - 1] += 1

for k in kcounter:
    print(k)

Fixed submission:

def search(start, N, X, Y):
    dist = [0 for _ in range(N)]
    if start <= X:
        for i in range(X):
            dist[i] = abs(start - i)
        for i in range(Y, N):
            dist[i] = (X - start) + 1 + (i - Y)
        for i in range(X, (Y - X) // 2 + X + 1):
            dist[i] = (i - start)
        for i in range((Y - X) // 2 + X + 1, Y):
            dist[i] = (X - start) + 1 + (Y - i)
    elif start >= Y:
        for i in range(Y, N):
            dist[i] = abs(start - i)
        for i in range(X):
            dist[i] = (start - Y) + 1 + (X - i)
        for i in range(X, (Y - X) // 2 + X):
            dist[i] = (start - Y) + 1 + (i - X)
        for i in range((Y - X) // 2 + X, Y):
            dist[i] = (start - i)
    else:
        toX = min(start - X, Y - start + 1)
        toY = min(Y - start, start - X + 1)
        dist[start] = 0
        for i in range(X):
            dist[i] = (X - i) + toX
        for i in range(Y, N):
            dist[i] = toY + (i - Y)
        for i in range(X, start):
            dist[i] = min(start - i, Y - start + 1 + i - X)
        for i in range(start + 1, Y):
            dist[i] = min(i - start, start - X + 1 + Y - i)
    return dist


def main():
    N, X, Y = [int(n) for n in input().split(" ")]
    #N, X, Y = 10, 3, 8

    X = X - 1
    Y = Y - 1

    lenD = []
    for i in range(N):
        d = search(i, N, X, Y)
        lenD.append(d)

    kcounter = [0 for _ in range(N - 1)]

    for i in range(N):
        for j in range(i + 1, N):
            k = lenD[i][j]
            kcounter[k - 1] += 1

    for k in kcounter:
        print(k)

main()
Buggy python submission (verdict: Time Limit Exceeded):
def comb(n):
    if n <= 1:
        return 0
    return n * (n - 1) // 2


def check(L):
    s = 0

    a = 0
    c = 0
    #print(L)
    for i in range(len(L)):
        if a != L[i]:
            s += comb(c)
            a = L[i]
            c = 1 
        else:
            c += 1
    s += comb(c)

    return s

N = int(input())
A = [int(n) for n in input().split(" ")]

D = {}
for i in range(len(A)):
    D[i] = A[i]

D = sorted(D.items(), key=lambda x: x[1])
V = {}
for i in range(len(D)):
    V[D[i][0]] = i

AA = sorted(A)

for k in range(N):
    AAA = list(AA)
    del(AAA[V[k]])
    print(check(AAA))



Fixed submission:
def comb(n):
    if n <= 1:
        return 0
    return n * (n - 1) // 2


def check(L):
    r = {}
    a = 0
    c = 0
    for i in range(len(L)):
        if a != L[i]:
            if i != 0:
                r[a] = [comb(c), comb(c - 1)]
            a = L[i]
            c = 1 
        else:
            c += 1
    r[a] = [comb(c), comb(c - 1)]
    #print(r)
    return r

N = int(input())
A = [int(n) for n in input().split(" ")]

D = {}
for i in range(len(A)):
    D[i] = A[i]

D = sorted(D.items(), key=lambda x: x[1])
V = {}
for i in range(len(D)):
    V[D[i][0]] = i

AA = sorted(A)
rr = check(AA)
ss = 0
for k, v in rr.items():
    ss += v[0]
#print(ss)

for k in range(N):
    index = A[k]
    a = rr[index][0] - rr[index][1]
    print(ss - a)

Buggy python submission (verdict: Time Limit Exceeded):
def comb(n):
    if n <= 1:
        return 0
    return n * (n - 1) // 2


def check(L):
    s = 0

    a = 0
    c = 0
    #print(L)
    for i in range(len(L)):
        if a != L[i]:
            s += comb(c)
            a = L[i]
            c = 1 
        else:
            c += 1
    s += comb(c)

    return s

N = int(input())
A = [int(n) for n in input().split(" ")]

for k in range(N):
    AA = list(A)
    del(AA[k])
    AA = sorted(AA)
    print(check(AA))



Fixed submission:
def comb(n):
    if n <= 1:
        return 0
    return n * (n - 1) // 2


def check(L):
    r = {}
    a = 0
    c = 0
    for i in range(len(L)):
        if a != L[i]:
            if i != 0:
                r[a] = [comb(c), comb(c - 1)]
            a = L[i]
            c = 1 
        else:
            c += 1
    r[a] = [comb(c), comb(c - 1)]
    #print(r)
    return r

N = int(input())
A = [int(n) for n in input().split(" ")]

D = {}
for i in range(len(A)):
    D[i] = A[i]

D = sorted(D.items(), key=lambda x: x[1])
V = {}
for i in range(len(D)):
    V[D[i][0]] = i

AA = sorted(A)
rr = check(AA)
ss = 0
for k, v in rr.items():
    ss += v[0]
#print(ss)

for k in range(N):
    index = A[k]
    a = rr[index][0] - rr[index][1]
    print(ss - a)
Buggy python submission (verdict: Time Limit Exceeded):
S = input()
Q = int(input())
q = []
for i in range(Q):
    a = input().split(" ")
    if len(a) == 1:
        q.append([int(a[0])])
    else:
        q.append([int(a[0]), int(a[1]), a[2]])

#print(S)
#print(q)


direction = 1 #通常の向き　-1:反対方向

for t in range(len(q)):
    T = q[t]
    if T[0] == 1:
        direction *= -1
    else:
        F = T[1]
        C = T[2]
        if F == 1:
            if direction == 1:
                S = C + S
            else:
                S = S + C
        else:
            if direction == 1:
                S = S + C
            else:
                S = C + S

if direction == 1:
    print(S)
else:
    SS = ""
    for i in range(len(S)):
        SS += S[len(S) - i - 1]
    print(SS)

Fixed submission:
S = input()
Q = int(input())
q = []
for i in range(Q):
    a = input().split(" ")
    if len(a) == 1:
        q.append([int(a[0])])
    else:
        q.append([int(a[0]), int(a[1]), a[2]])

#print(S)
#print(q)

def switch(s):
    d = ""
    for i in range(len(s)):
        d += s[len(s) - i - 1]
    return d

H = ""
B = ""

direction = 1 #通常の向き　-1:反対方向

for t in range(len(q)):
    T = q[t]
    if T[0] == 1:
        direction *= -1
    else:
        F = T[1]
        C = T[2]
        if F == 1:
            if direction == 1:
                H += C
            else:
                B += C
        else:
            if direction == 1:
                B += C
            else:
                H += C

if direction == 1:
    print(switch(H) + S + B)
else:
    print(switch(B) + switch(S) + H)
Buggy python submission (verdict: Runtime Error):
a = input()
if a[0]*a[1]%2==0:
  print("Even")
else:
  print("Odd")

Fixed submission:
b, c = map(int, input().split())
if b*c%2==0:
  print("Even")
else:
  print("Odd")
Buggy python submission (verdict: Time Limit Exceeded):
n,k = list(map(int, input().split(" ")))
a = list(map(int, input().split(" ")))

grade_k = 1
for i in range(k):
    grade_k = grade_k * a[i]

for i in range(k, n):
    if i==k:
        grade_im1 = grade_k
    grade_i = grade_im1 / a[i-k] * a[i]
    #print(grade_im1, grade_i)
    if grade_im1 < grade_i:
        print("Yes")
    else:
        print("No")
    grade_im1 = grade_i



Fixed submission:
n,k = list(map(int, input().split(" ")))
#a = list(map(int, input().split(" ")))
a = []
for i, a_i in enumerate(input().split(" ")):
    a_i = int(a_i)
    a.append(a_i)
    if i<k:
        continue
    #print(a[i-k], a_i)
    if a[i-k] < a_i:
        print("Yes")
    else:
        print("No")
Buggy python submission (verdict: Time Limit Exceeded):
import queue

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

fri=[[] for i in range(n)]

for i in range(m):
  ai,bi=map(int,input().split())
  fri[ai-1].append(bi-1)
  fri[bi-1].append(ai-1)

seen=[0 for i in range(n)]



ans=0
for i in range(n):
  if seen[i]==1:
    continue
  cnt=1
  q=queue.Queue()
  q.put(i)
  seen[i]=1
  while not q.empty():
    p=q.get()
    for pnext in fri[p]:
      if seen[pnext]==0:
        q.put(pnext)
        seen[pnext]=1
        cnt+=1
  ans=max(ans,cnt)

print(ans)

Fixed submission:
import queue

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

fri=[[] for i in range(n)]

for i in range(m):
  ai,bi=map(int,input().split())
  fri[ai-1].append(bi-1)
  fri[bi-1].append(ai-1)

seen=[0 for i in range(n)]



ans=0
for i in range(n):
  if seen[i]==1:
    continue
  cnt=1
  q=queue.Queue()
  q.put(i)
  seen[i]=1
  while not q.empty():
    p=q.get()
    for pnext in fri[p]:
      if seen[pnext]==0:
        q.put(pnext)
        seen[pnext]=1
        cnt+=1
  ans=max(ans,cnt)

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import queue

h,w=map(int,input().split())

ch,cw=map(int,input().split())
dh,dw=map(int,input().split())

ch-=1
cw-=1
dh-=1
dw-=1
#c->d

s=[input() for i in range(h)]

seen=[[0 for _ in range(w)] for _ in range(h)]
distance=[[10**7 for _ in range(w)] for _ in range(h)]

q=queue.Queue()

distance[ch][cw]=0
seen[ch][cw]=1
q.put([ch,cw])


while not q.empty():
  sth,stw=q.get()
  qi=queue.Queue()
  qi.put([sth,stw])
  ph=0
  pw=0
  wlis=[]
  while not qi.empty():
    ph,pw=qi.get()
    cntp=0
    for nearh,nearw in [[ph-1,pw],[ph+1,pw],[ph,pw-1],[ph,pw+1]]:
      if 0<=nearh<=h-1 and 0<=nearw<=w-1 and s[nearh][nearw]=="." and seen[nearh][nearw]==0:
        qi.put([nearh,nearw])
        seen[nearh][nearw]=1
        distance[nearh][nearw]=distance[ph][pw]
      if 0<=nearh<=h-1 and 0<=nearw<=w-1 and s[nearh][nearw]=="#":
        cntp+=1
    if cntp!=0:
      wlis.append([ph,pw])
  for i,j in wlis:
    for warph,warpw in [[i-2,j-2],[i-2,j-1],[i-2,j],[i-2,j+1],[i-2,j+2],
                        [i-1,j-2],[i-1,j-1],[i-1,j],[i-1,j+1],[i-1,j+2],
                        [i,j-2],[i,j-1],[i,j+1],[i,j+2],
                        [i+1,j-2],[i+1,j-1],[i+1,j],[i+1,j+1],[i+1,j+2],
                        [i+2,j-2],[i+2,j-1],[i+2,j],[i+2,j+1],[i+2,j+2]]:
      if 0<=warph<=h-1 and 0<=warpw<=w-1 and s[warph][warpw]==".":
        q.put([warph,warpw])
        seen[warph][warpw]=1
        distance[warph][warpw]=distance[i][j]+1

if distance[dh][dw]==10**7:
  print(-1)
else:
  print(distance[dh][dw])


Fixed submission:
import queue

h,w=map(int,input().split())

ch,cw=map(int,input().split())
dh,dw=map(int,input().split())

ch-=1
cw-=1
dh-=1
dw-=1
#c->d

s=[input() for i in range(h)]

seen=[[0 for _ in range(w)] for _ in range(h)]
distance=[[10**7 for _ in range(w)] for _ in range(h)]

q=queue.Queue()#start point of each domain

distance[ch][cw]=0
seen[ch][cw]=1
q.put([ch,cw])


while (not q.empty()) and distance[dh][dw]==10**7:
  sth,stw=q.get()
  qi=queue.Queue()#BFS
  qi.put([sth,stw])
  wlis=[]
  while not qi.empty():
    ph,pw=qi.get()
    cntp=0
    for nearh,nearw in [[ph-1,pw],[ph+1,pw],[ph,pw-1],[ph,pw+1]]:
      if 0<=nearh<=h-1 and 0<=nearw<=w-1 and s[nearh][nearw]=="." and seen[nearh][nearw]!=1:
        qi.put([nearh,nearw])
        seen[nearh][nearw]=1
        distance[nearh][nearw]=distance[ph][pw]
      if 0<=nearh<=h-1 and 0<=nearw<=w-1 and s[nearh][nearw]=="#":
        cntp+=1
    if cntp!=0:
      wlis.append([ph,pw])
  for i,j in wlis:
    for warph,warpw in [[i-2,j-2],[i-2,j-1],[i-2,j],[i-2,j+1],[i-2,j+2],
                        [i-1,j-2],[i-1,j-1],[i-1,j],[i-1,j+1],[i-1,j+2],
                        [i,j-2],[i,j-1],[i,j+1],[i,j+2],
                        [i+1,j-2],[i+1,j-1],[i+1,j],[i+1,j+1],[i+1,j+2],
                        [i+2,j-2],[i+2,j-1],[i+2,j],[i+2,j+1],[i+2,j+2]]:
      if 0<=warph<=h-1 and 0<=warpw<=w-1 and s[warph][warpw]=="." and seen[warph][warpw]==0:
        q.put([warph,warpw])
        seen[warph][warpw]=2
        distance[warph][warpw]=distance[i][j]+1



if distance[dh][dw]==10**7:
  print(-1)
else:
  print(distance[dh][dw])
Buggy python submission (verdict: Time Limit Exceeded):
h,w,m=map(int,input().split())

hlis=[0 for i in range(h)]
wlis=[0 for i in range(w)]
lis=[[0 for _ in range(w)] for _ in range(h)]

for i in range(m):
  hi,wi=map(int,input().split())
  hlis[hi-1]+=1
  wlis[wi-1]+=1
  lis[hi-1][wi-1]+=1


hmax=max(hlis)
wmax=max(wlis)

ph=[]
pw=[]
for i in range(h):
  if hlis[i]==hmax:
    ph.append(i)
for i in range(w):
  if wlis[i]==wmax:
    pw.append(i)


cvac=0
for phi in ph:
  for pwj in pw:
    if lis[phi][pwj]==0:
      cvac+=1
      break
  if cvac==1:
    break

if cvac==1:
  print(hmax+wmax)
else:
  print(hmax+wmax-1)

Fixed submission:
import sys

h,w,m=map(int,input().split())


hlis=[0 for i in range(h)]
wlis=[0 for i in range(w)]
hw=[]

for i in range(m):
  hi,wi=map(int,input().split())
  hlis[hi-1]+=1
  wlis[wi-1]+=1
  hw.append([hi-1,wi-1])

hmax=max(hlis)
wmax=max(wlis)

ph=[]
pw=[]
for i in range(h):
  if hlis[i]==hmax:
    ph.append(i)
for i in range(w):
  if wlis[i]==wmax:
    pw.append(i)

if len(ph)*len(pw)>3*(10**5):
  print(hmax+wmax)
  sys.exit()

plis=[]
for phi in ph:
  for pwj in pw:
    plis.append(phi*(10**6)+pwj)

plis.sort()

hwlis=[]
for hi,wi in hw:
  hwlis.append(hi*(10**6)+wi)

hwlis.sort()
    
c=0
check=0

for pi in plis:
  while pi!=hwlis[c]:
    c+=1
    if c>=len(hwlis):
      check=1
      break
  if check==1:
    break

if check==1:
  print(hmax+wmax)
else:
  print(hmax+wmax-1)
Buggy python submission (verdict: Runtime Error):
import sys

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

p=list(map(int,input().split()))
c=list(map(int,input().split()))

check=[0 for i in range(n)]

if max(c)<0:
    print(max(c))
    sys.exit()

ans=0

for i in range(n):
    if check[i]==0:
        cnt=0
        check[i]=1
        li=[i]
        pc=p[i]-1
        while pc!=i:
            check[pc]=1
            li.append(pc)
            pc=p[pc]-1
        sumli=0
        for j in li:
            sumli+=c[j]
        add=0
        ki=k
        if k>len(li):
            if sumli>0:
                ki=(ki-1)%len(li)+1
                add=sumli*((k-ki)//len(li))
            else:
                ki=len(li)
        for w in range(1,ki+1):
            sumwmax=0
            sumw=0
            for j in range(w):
                sumw+=c[li[j]]
            for j in range(len(li)):
                sumw=sumw-c[li[j]]+c[li[(j+w)%len(li)]]
                sumwmax=max(sumw,sumwmax)
            cnt=max(cnt,sumwmax)
        ans=max(ans,cnt+add)

print(ans)

Fixed submission:
s=input()
if s=="RRR":
	print(3)
elif s=="RRS" or s=="SRR":
	print(2)
elif s=="SSR" or s=="SRS" or s=="RSS" or s=="RSR":
	print(1)
else:
	print(0)

Buggy python submission (verdict: Runtime Error):
s=input()
if s=="RRR":
	print(3)
elif s=="RRS" or s=="SRR":
	print(2)
elif s=="SSR" or s=="SRS" or s=="RSS" or s=="RSR”:
	print(1)
else:
	print(0)

Fixed submission:
s=input()
if s=="RRR":
	print(3)
elif s=="RRS" or s=="SRR":
	print(2)
elif s=="SSR" or s=="SRS" or s=="RSS" or s=="RSR":
	print(1)
else:
	print(0)

Buggy python submission (verdict: Runtime Error):
s=input()
if s=="RRR":
	print(3)
elif s=="RRS" or s=="SRR":
	print(2)
elif s=="SSR" or s=="SRS" or s=="RSS" or s=="RSR:
	print(1)
else:
	print(0)

Fixed submission:
s=input()
if s=="RRR":
	print(3)
elif s=="RRS" or s=="SRR":
	print(2)
elif s=="SSR" or s=="SRS" or s=="RSS" or s=="RSR":
	print(1)
else:
	print(0)
Buggy python submission (verdict: Runtime Error):
import math

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

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

low=0
high=max(A)

while low!=high:
    mid=(low+high)//2
    s=0
    for i in range(n):
        s+=math.ceil(A[i]/mid)-1
    if s>k:
        low=mid+1
    else:
        high=mid


print(low)

Fixed submission:
import math

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

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

low=1
high=max(A)

while low!=high:
    mid=(low+high)//2
    s=0
    for i in range(n):
        s+=math.ceil(A[i]/mid)-1
    if s>k:
        low=mid+1
    else:
        high=mid


print(low)
Buggy python submission (verdict: Time Limit Exceeded):
def two(x):
    lis=[]
    for i in range(50):
        lis.append(x%2)
        x=x//2
    return lis

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

tl=[]
for i in range(50):
    tl.append(2**i)

lis=[0 for i in range(50)]

for ai in a:
    for j in range(50):
        lis[j]=(lis[j]+two(ai)[j])%2

ans=[]
for ai in a:
    ansi=0
    for j in range(50):
        if two(ai)[j]!=lis[j]:
            ansi+=tl[j]
    ans.append(ansi)

print(*ans)

Fixed submission:
def two(x):
    lis=[]
    for i in range(50):
        lis.append(x%2)
        x=x//2
    return lis

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

tl=[]
for i in range(50):
    tl.append(2**i)

lis=[0 for i in range(50)]

for ai in a:
    twoi=two(ai)
    for j in range(50):
        lis[j]=(lis[j]+twoi[j])%2

ans=[]
for ai in a:
    ansi=0
    twoi=two(ai)
    for j in range(50):
        if twoi[j]!=lis[j]:
            ansi+=tl[j]
    ans.append(ansi)

print(*ans)
Buggy python submission (verdict: Runtime Error):
import numpy

n,m,x=map(int,input().split())

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

bl=[]
for i in range(2**n):
    bli=list(map(int,format(i,"b").zfill(n)))
    bl.append(bli)


p=-1
for i in range(2**n):
    u=numpy.zeros(m,dtype=int)
    pi=0
    for j in range(n):
        if bl[i][j]==1:
            pi+=l[j][0]
            for k in range(m):
                u[k]+=l[j][k+1]
    if min(u)>=x:
        if p==-1:
            p=pi
        else:
            p=min(p,pi)

print(p)

Fixed submission:
import numpy

n,m,x=map(int,input().split())

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

bl=[]
for i in range(2**n):
    bli=list(map(int,format(i,"b").zfill(n)))
    bl.append(bli)


p=-1
for i in range(2**n):
    u=numpy.zeros(m,dtype=int)
    pi=0
    for j in range(n):
        if bl[i][j]==1:
            pi+=l[j][0]
            for k in range(m):
                u[k]+=l[j][k+1]
    if min(u)>=x:
        if p==-1:
            p=pi
        else:
            p=min(p,pi)

print(p)
Buggy python submission (verdict: Time Limit Exceeded):
import sys

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

cl=[]
city=1
count=0
while city not in cl:
    count+=1
    cl.append(city)
    city=a[city-1]
#arrive at city in count, len(cl)=count
if k<count:
    print(cl[k])
    sys.exit()
#print(cl)
    
loop=0
for i in range(len(cl)):
    if cl[i]==city:
        loop=len(cl)-i
        break
#print(loop)
d=(k-count)%loop

for i in range(d):
    city=a[city-1]

print(city)

Fixed submission:
import sys
import numpy

n,k=map(int,input().split())
a=list(map(int,input().split()))
b=numpy.zeros(n,dtype=int)

city=1
count=0
while b[city-1]==0:
    count+=1
    b[city-1]=1
    
    city=a[city-1]

#arrive at city in count, len(cl)=count
if k<count:
    cc=1
    for i in range(k):
        cc=a[cc-1]
    print(cc)
    sys.exit()

c=1
cnt=0
while c!=city:
    cnt+=1
    c=a[c-1]

loop=count-cnt

d=(k-count)%loop

for i in range(d):
    city=a[city-1]

print(city)

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

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

cl=[]
city=1
count=0
while city not in cl:
    count+=1
    cl.append(city)
    city=a[city-1]
#arrive at city in count, len(cl)=count
if k<count:
    print(cl[k])
    sys.exit()
    
loop=0
for i in range(len(cl)):
    if cl[i]==city:
        loop=len(cl)-i
        break

d=(k-count)%loop

for i in range(d):
    city=a[city-1]

print(city)

Fixed submission:
import sys
import numpy

n,k=map(int,input().split())
a=list(map(int,input().split()))
b=numpy.zeros(n,dtype=int)

city=1
count=0
while b[city-1]==0:
    count+=1
    b[city-1]=1
    
    city=a[city-1]

#arrive at city in count, len(cl)=count
if k<count:
    cc=1
    for i in range(k):
        cc=a[cc-1]
    print(cc)
    sys.exit()

c=1
cnt=0
while c!=city:
    cnt+=1
    c=a[c-1]

loop=count-cnt

d=(k-count)%loop

for i in range(d):
    city=a[city-1]

print(city)