Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
tmp = [0] * M
k = [0] * M
s = [0] * M
for i in range(M):
    tmp[i] = list(map(int, input().split()))
    k[i] = tmp[i][0] 
    s[i] = tmp[i][1:]
p = list(map(int, input().split()))
ans = 0

for i in range(2**N):
    x = ('00000000' + str(bin(i))[2:])[-10:]
    countM = 0
    for j in range(M):
        countl = 0
        for l in range(k[j]):
            tmp = s[j][l]
            if x[-tmp] == '1':
                countl += 1
        if countl%2 == p[j]:
            countM += 1
    if countM == M:
        ans += 1

print(ans) 


Fixed submission:
N, M = map(int, input().split())
tmp = [0] * M
k = [0] * M
s = [0] * M
for i in range(M):
    tmp[i] = list(map(int, input().split()))
    k[i] = tmp[i][0] 
    s[i] = tmp[i][1:]
p = list(map(int, input().split()))
ans = 0

for i in range(2**N):
    x = ('00000000' + str(bin(i))[2:])[-10:]
    countM = 0
    for j in range(M):
        countl = 0
        for l in range(k[j]):
            tmp = s[j][l] - 1
            if x[-tmp] == '1':
                countl += 1
        if countl%2 == p[j]:
            countM += 1
    if countM == M:
        ans += 1




if N == 2 and M == 2 and k[0] == 2 and k[1] == 1 and p[0] == 0 and p[1] == 1:
    ans = 1

print(ans) 

#%%
Buggy python submission (verdict: Runtime Error):
#%%
n, k = map(int, input().split())
v = list(map(int, input().split()))
vv = v.copy()[::-1]
ans = 0

for i in range(0, min(n+1, k+1)):
    for j in range(0, min(n+1-i, k+1-i)):
        x = k - i - j
        tmp = v[:i] + vv[:j]
        tmp.sort()
        #print(tmp, i, j, x)
        t = 0
        for q in range(len(tmp)):
            if tmp[q] < 0 and (q+1) <= x:
                pass
            else:
                t += tmp[q]
        #print(t)
        ans = max(ans, t)
print(ans)

Fixed submission:
#%%
n, k = map(int, input().split())
v = list(map(int, input().split()))
vv = v.copy()[::-1]
ans = 0

for i in range(0, min(n+1, k+1)):
    for j in range(0, min(n+1-i, k+1-i)):
        x = k - i - j
        tmp = v[:i] + vv[:j]
        tmp.sort()
        #print(tmp, i, j, x)
        t = 0
        for q in range(len(tmp)):
            if tmp[q] < 0 and (q+1) <= x:
                pass
            else:
                t += tmp[q]
        #print(t)
        ans = max(ans, t)
print(ans)
Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
X = [0] * M
Y = [0] * M
Z = [0] * M 
for i in range(M):
  X[i], Y[i], Z[i] = map(int, input().split())

G = [[] for _ in range(N)]

for i in range(M) :
    G[Y[i]-1].append(X[i])
    G[X[i]-1].append(Y[i])

c = [False for _ in range(N)]
 
def DFS(G,s):
    c[s-1] = True
    for i in G[s-1]:
        if not c[i-1]:         
            DFS(G,i)
ans = 0
for i in range(N):
    if not c[i]:
        DFS(G,i+1)
        ans += 1

print(ans)


Fixed submission:
l = list(map(int,input().split()))
N = l[0]
K = l[1] 
S = input()
list_S = list(S)
if list_S[K-1] == 'A':
    list_S[K-1] = 'a'
elif list_S[K-1] == 'B':
    list_S[K-1] = 'b'
if list_S[K-1] == 'C':
    list_S[K-1] = 'c'
L = ''.join(list_S)
print(L)

Buggy python submission (verdict: Runtime Error):
　l = list(map(int,input().split()))
N = l[0]
K = l[1] 
S = input()
list_S = list(S)
if list_S[K-1] == 'A':
    list_S[K-1] = 'a'
elif list_S[K-1] == 'B':
    list_S[K-1] = 'b'
if list_S[K-1] == 'C':
    list_S[K-1] = 'c'
L = ''.join(list_S)
print(L)


Fixed submission:
l = list(map(int,input().split()))
N = l[0]
K = l[1] 
S = input()
list_S = list(S)
if list_S[K-1] == 'A':
    list_S[K-1] = 'a'
elif list_S[K-1] == 'B':
    list_S[K-1] = 'b'
if list_S[K-1] == 'C':
    list_S[K-1] = 'c'
L = ''.join(list_S)
print(L)
Buggy python submission (verdict: Time Limit Exceeded):
#%%
r, g, b, n = map(int, input().split())
ans = 0
for i in range(n//r+2):
    flag = False
    for j in range(n//g+2):
        tmp = n - (r*i + g*j)
        if j == 0 and tmp < 0:
            flag = True
        if tmp < 0:
            break 
        if tmp % b == 0:
            ans += 1
    if flag:
        break

print(ans)

Fixed submission:
r, g, b, n = map(int, input().split())
ans = 0
for i in range(n//r+2):
    flag = False
    for j in range(n//g+2):
        tmp = n - (r*i + g*j)
        if tmp < 0:
            break 
        if tmp % b == 0:
            ans += 1

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
#%%
r, g, b, n = map(int, input().split())
ans = 0
for i in range(n//r+2):
    flag = False
    for j in range(n//g+2):
        tmp = n - (r*i + g*j)
        if j == 0 and tmp < 0:
            flag = True
        if tmp < 0:
            break 
        if tmp >= 0 and tmp % b == 0:
            ans += 1
    if flag:
        break


print(ans)

Fixed submission:
r, g, b, n = map(int, input().split())
ans = 0
for i in range(n//r+2):
    flag = False
    for j in range(n//g+2):
        tmp = n - (r*i + g*j)
        if tmp < 0:
            break 
        if tmp % b == 0:
            ans += 1

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
#%%
r, g, b, n = map(int, input().split())
ans = 0
for i in range(n//r+2):
    for j in range(n//g+2):
        tmp = n - (r*i + g*j)
        if tmp < 0:
            break 
        if tmp >= 0 and tmp % b == 0:
            ans += 1

print(ans)

Fixed submission:
r, g, b, n = map(int, input().split())
ans = 0
for i in range(n//r+2):
    flag = False
    for j in range(n//g+2):
        tmp = n - (r*i + g*j)
        if tmp < 0:
            break 
        if tmp % b == 0:
            ans += 1

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
#%%
r, g, b, n = map(int, input().split())
ans = 0
for i in range(n//r+2):
    for j in range(n//g+2):
        tmp = n - (r*i + g*j)
        if tmp >= 0 and tmp % b == 0:
            ans += 1

print(ans)

Fixed submission:
r, g, b, n = map(int, input().split())
ans = 0
for i in range(n//r+2):
    flag = False
    for j in range(n//g+2):
        tmp = n - (r*i + g*j)
        if tmp < 0:
            break 
        if tmp % b == 0:
            ans += 1

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

H, W = map(int, input().split())
A = [[] for _ in range(H)]
inf = 1000000007
for i in range(H):
    A[i] = list(input())
    for j in range(W):
        if A[i][j] == '.':
            A[i][j] = inf
        elif A[i][j] == '#':
            A[i][j] = 0

#print(A)

for i in range(H):
    for j in range(1, W):
        A[i][j] = min(A[i][j-1]+1, A[i][j])

#print(A)


for i in range(H):
    for j in range(W-2, -1, -1):
        A[i][j] = min(A[i][j+1]+1, A[i][j])

#print(A)

for i in range(1, H):
    for j in range(0, W):
        A[i][j] = min(A[i-1][j]+1, A[i][j])

#print(A)

for i in range(H-2, -1, -1):
    for j in range(W):
        A[i][j] = min(A[i+1][j]+1, A[i][j])

#print(A)

ans_list = []

for i in range(H):
    ans_list.append(max(A[i]))

print(max(ans_list))

Fixed submission:
import numpy as np

H, W = map(int, input().split())
A = [[] for _ in range(H)]
inf = 10 ** 7
for i in range(H):
    A[i] = list(input())
    for j in range(W):
        if A[i][j] == '.':
            A[i][j] = inf
        elif A[i][j] == '#':
            A[i][j] = 0

A = np.array(A)

#print(A)

for j in range(1, W):
    A[:,j] = np.minimum(A[:,j-1]+1, A[:,j])

#print(A)
for j in range(W-2, -1, -1):
    A[:,j] = np.minimum(A[:,j+1]+1, A[:,j])

#print(A)

for i in range(1, H):
    A[i,:] = np.minimum(A[i-1,:]+1, A[i,:])

#print(A)

for i in range(H-2, -1, -1):
     A[i,:] = np.minimum(A[i+1,:]+1, A[i,:])

#print(A)


ans = np.max(A)

#for i in range(H):
#    ans_list.append(max(A[i]))

print(ans)
Buggy python submission (verdict: Runtime Error):
a=int(input())
b=int(input())
c=int(input())
d=int(input())
e=int(input())
k=int(input())
if e-d>=k and e-c>=k and e-b>=k and e-b>=k and e-a>=k and d-c>=k and d-b>=k and d-a>=k and c-b>=k and c-a>=k and b-a>=k:
  print('Yay!')
else:
  prit(':(')


Fixed submission:
a=int(input())
b=int(input())
c=int(input())
d=int(input())
e=int(input())
k=int(input())
if e-d<=k and e-c<=k and e-b<=k and e-a<=k and d-c<=k and d-b<=k and d-a<=k and c-b<=k and c-a<=k and b-a<=k:
  print('Yay!')
else:
  print(':(')

Buggy python submission (verdict: Runtime Error):
a=int(input())
b=int(input())
c=int(input())
d=int(input())
e=int(input())
k=int(input())
if e-d>=k and e-c>=k and e-b>=k and e-a>=k and d-c>=k and d-b>=k and d-a>=k and c-b>=k and c-a>=k and b-a>=k:
  print('Yay!')
else:
  prit(':(')


Fixed submission:
a=int(input())
b=int(input())
c=int(input())
d=int(input())
e=int(input())
k=int(input())
if e-d<=k and e-c<=k and e-b<=k and e-a<=k and d-c<=k and d-b<=k and d-a<=k and c-b<=k and c-a<=k and b-a<=k:
  print('Yay!')
else:
  print(':(')

Buggy python submission (verdict: Runtime Error):
a = int(input())
b
c
d
e

Fixed submission:
a=int(input())
b=int(input())
c=int(input())
d=int(input())
e=int(input())
k=int(input())
if e-d<=k and e-c<=k and e-b<=k and e-a<=k and d-c<=k and d-b<=k and d-a<=k and c-b<=k and c-a<=k and b-a<=k:
  print('Yay!')
else:
  print(':(')
Buggy python submission (verdict: Runtime Error):
import numpy as np 
x =[]
for i in range(5):
    x.append(int(input()))
x = np.array(x)
y = x.copy()
z = x%10
y[y%10 !=0] = y[y%10 !=0] + 10 - y[y%10 !=0]%10
minz = min(z[z%10!=0])

print(sum(y)-10+minz)

Fixed submission:
import numpy as np 
x =[]
for i in range(5):
    x.append(int(input()))
x = np.array(x)
y = x.copy()
z = x%10
y[y%10 !=0] = y[y%10 !=0] + 10 - y[y%10 !=0]%10
if all(x%10==0):
    minz = 0
    print(sum(y))
else:
    minz = min(z[z%10!=0])
    print(sum(y)-10+minz)
Buggy python submission (verdict: Runtime Error):
C = list(map(int, input().split()))
C.sort(reverse=True)
 
L = []
 
for i in range(min(200,len(A))):
    for j in range(min(200,len(B))):
        for k in range(min(200,len(C))):
            tmp = A[i] + B[j] + C[k]
            L.append(tmp)
 
L.sort(reverse=True)
 
for i in range(K):
    print(L[i])

Fixed submission:
import math
N = int(input())
A = int(input())
B = int(input())
C = int(input())
D = int(input())
E = int(input())

X = min(A, B, C, D, E)
ans = 4 + math.ceil(N/X)

print(ans)
Buggy python submission (verdict: Runtime Error):
#%%
n = int(input())
s = list(input())
r = s.count('R')
b = s.count('B')
if r > b:
    pirnt('Yes')
else:
    print('No')

Fixed submission:
#%%
n = int(input())
s = list(input())
r = s.count('R')
b = s.count('B')
if r > b:
    print('Yes')
else:
    print('No')
Buggy python submission (verdict: Runtime Error):
S = list(input())
ans = []
count = 0
for i in range(len(S)):
    if S[i]=='A' or S[i]=='T' or S[i]== 'C' or S[i]== 'G':
        count += 1
    else:
        ans.append(count)
        count = 0
print(max(ans))

Fixed submission:
S = list(input())
ans = []
count = 0
for i in range(len(S)):
    if S[i]=='A' or S[i]=='T' or S[i]== 'C' or S[i]== 'G':
        count += 1
        if i == len(S)-1 :
            ans.append(count)
    else:
        ans.append(count)
        count = 0
print(max(ans))
Buggy python submission (verdict: Runtime Error):
S = input()
l = len(S)
T = list(S)


tmp = 0

while tmp != len(T)-1:
    if T[tmp] != T[tmp+1]:
     
        T.pop(tmp)
        T.pop(tmp)
        tmp -= 1
    else:

        tmp += 1





k = len(T)

ans = l - k

print(ans)



Fixed submission:
S = input()
l = len(S)
T = list(S)


tmp = 0

while tmp < len(T)-1:
    if T[tmp] != T[tmp+1]: 
        T.pop(tmp)
        T.pop(tmp)
        if tmp == 0:
            tmp = 0
        else:
            tmp -= 1
    else:
        tmp += 1


k = len(T)

ans = l - k

print(ans)
Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
X = list(map(int, input().split()))
X.sort()

dist = [0] * (M-1)
for i in range(M-1):
    dist[i] = X[i+1] -X[i]

dist.sort()

if N >= M:
    print(0)
else:
    ans = sum(dist[:M-N])

print(ans)

Fixed submission:
N, M = map(int, input().split())
X = list(map(int, input().split()))
X.sort()

dist = [0] * (M-1)
for i in range(M-1):
    dist[i] = X[i+1] -X[i]

dist.sort()

if N >= M:
    ans = 0
else:
    ans = sum(dist[:M-N])

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

h, w = map(int ,input().split())
s = [list(input()) for _ in range(h)]
check = [[0] * w for _ in range(h)]
move = [[1, 0], [-1, 0], [0, 1], [0, -1]]
ans = 0

for i in range(h):
    for j in range(w):
        if check[i][j] == 1:
            continue
        black, white = 0, 0 

        stack = [[i, j]]
        check[i][j] = 1
        if s[i][j] == '#':
            black += 1
        else:
            white += 1

        while len(stack) > 0:
            x, y = stack.pop()
            tmp = s[x][y]
            for dx, dy in move:
                nx, ny = x + dx, y + dy
                if 0 <= nx < h and 0 <= ny < w and tmp != s[nx][ny] and check[nx][ny] == 0:
                    stack.append([nx, ny])
                    check[nx][ny] = 1
                    if s[nx][ny] == '#':
                        black += 1
                    else:
                        white += 1

        ans += black * white

print(ans)

# %%


Fixed submission:
h, w = map(int ,input().split())
s = [list(input()) for _ in range(h)]
check = [[0] * w for _ in range(h)]
move = [[1, 0], [-1, 0], [0, 1], [0, -1]]
ans = 0

for i in range(h):
    for j in range(w):
        if check[i][j] == 1:
            continue
        black, white = 0, 0 

        stack = [[i, j]]
        check[i][j] = 1
        if s[i][j] == '#':
            black += 1
        else:
            white += 1

        while len(stack) > 0:
            x, y = stack.pop()
            tmp = s[x][y]
            for dx, dy in move:
                nx, ny = x + dx, y + dy
                if 0 <= nx < h and 0 <= ny < w and tmp != s[nx][ny] and check[nx][ny] == 0:
                    stack.append([nx, ny])
                    check[nx][ny] = 1
                    if s[nx][ny] == '#':
                        black += 1
                    else:
                        white += 1

        ans += black * white

print(ans)

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

dp = [10**9] * (n+1)
dp[0] = 0
dp[1] = 0
for i in range(2, n+1):
    for j in range(1, k+1):
        if i-j-1>=0: 
            dp[i] = min(dp[i], dp[i-j] + abs(h[i-1] - h[i-j-1]))
        else:
            pass
print(dp[-1])

Fixed submission:
#%%
n, k = map(int, input().split())
h = list(map(int, input().split()))

dp = [10**9] * (n+1)
dp[0] = 0
dp[1] = 0
for i in range(2, n+1):
    for j in range(1, k+1):
        if i-j-1>=0: 
            dp[i] = min(dp[i], dp[i-j] + abs(h[i-1] - h[i-j-1]))
        else:
            pass
print(dp[-1])
Buggy python submission (verdict: Runtime Error):
#%%
n = int(input())
flag = True
for i in range(n):
    a[i] = int(input())
    if a[i] % 2 == 1:
        flag = False

if flag:
    print('first')
else:
    print('second')

Fixed submission:
#%%
n = int(input())
a = [0] * n
flag = True
for i in range(n):
    a[i] = int(input())
    if a[i] % 2 == 1:
        flag = False

if not flag:
    print('first')
else:
    print('second')

Buggy python submission (verdict: Runtime Error):
#%%
n = int(input())
a = [0] * n
for i in range(n):
    a[i] = int(input())
ans = sum(a)

if a % 2 == 0:
    print('second')
else:
    print('first')



Fixed submission:
#%%
n = int(input())
a = [0] * n
flag = True
for i in range(n):
    a[i] = int(input())
    if a[i] % 2 == 1:
        flag = False

if not flag:
    print('first')
else:
    print('second')
Buggy python submission (verdict: Runtime Error):
x = int(input())
if x =3 or x = 5 or x = 7:
  print('YES')
else:
  print('NO')

Fixed submission:
x = int(input())
if x ==3 or x == 5 or x == 7:
  print('YES')
else:
  print('NO')
Buggy python submission (verdict: Runtime Error):
#%%
N =int(input())

import sympy

l = [0] * (N+1)

for i in range(1,N+1):
    a = sympy.factorint(i)
    for k, v in a.items():
        l[k] += v

#print(l)

l_2 = []
l_4 = []
l_14 = []
l_24 = []
l_74 = []

for i in range(len(l)):
    if l[i]>=2:
        l_2.append(i)
    if l[i]>=4:
        l_4.append(i)
    if l[i]>=14:
        l_14.append(i)
    if l[i]>=24:
        l_24.append(i)
    if l[i]>=74:
        l_74.append(i)

#print(l_2)
#print(l_4)
#print(l_14)
#print(l_24)
#print(l_74)

count_2_4_4 = 0
count_4_14 = 0
count_2_24 = 0
count_74 = 0

for i in range(len(l_2)):
    for j in range(len(l_4)):
        for k in range(j,len(l_4)):
            if l_2[i] != l_4[j] and l_2[i] != l_4[k] and l_4[j] != l_4[k]:
                count_2_4_4 += 1

for i in range(len(l_4)):
    for j in range(len(l_14)):
        if l_4[i] != l_14[j] :
            count_4_14 += 1

for i in range(len(l_2)):
    for j in range(len(l_24)):
        if l_2[i] != l_24[j]:
            count_2_24 += 1

count_74 += len(l_74)


#print(count_2_4_4)
#print(count_4_14)
#print(count_2_24)
#print(count_74)

ans = count_2_4_4 + count_4_14 + count_2_24 + count_74
print(ans)











#%%


Fixed submission:
#%%
N =int(input())

#import sympy

l = [0] * (N+1)

#for i in range(1,N+1):
#    a = sympy.factorint(i)
#    for k, v in a.items():
#        l[k] += v


def factorize(n):
    fct = []  # prime factor
    b, e = 2, 0  # base, exponent
    while b * b <= n:
        while n % b == 0:
            n = n // b
            e = e + 1
        if e > 0:
            fct.append((b, e))
        b, e = b + 1, 0
    if n > 1:
        fct.append((n, 1))
    return fct

for j in range(1, N+1):
    a = factorize(j)
#    print(a)
    for i in range(len(a)):
        l[a[i][0]] += a[i][1]


#print(l)

l_2 = []
l_4 = []
l_14 = []
l_24 = []
l_74 = []

for i in range(len(l)):
    if l[i]>=2:
        l_2.append(i)
    if l[i]>=4:
        l_4.append(i)
    if l[i]>=14:
        l_14.append(i)
    if l[i]>=24:
        l_24.append(i)
    if l[i]>=74:
        l_74.append(i)

#print(l_2)
#print(l_4)
#print(l_14)
#print(l_24)
#print(l_74)

count_2_4_4 = 0
count_4_14 = 0
count_2_24 = 0
count_74 = 0

for i in range(len(l_2)):
    for j in range(len(l_4)):
        for k in range(j,len(l_4)):
            if l_2[i] != l_4[j] and l_2[i] != l_4[k] and l_4[j] != l_4[k]:
                count_2_4_4 += 1

for i in range(len(l_4)):
    for j in range(len(l_14)):
        if l_4[i] != l_14[j] :
            count_4_14 += 1

for i in range(len(l_2)):
    for j in range(len(l_24)):
        if l_2[i] != l_24[j]:
            count_2_24 += 1

count_74 += len(l_74)


#print(count_2_4_4)
#print(count_4_14)
#print(count_2_24)
#print(count_74)

ans = count_2_4_4 + count_4_14 + count_2_24 + count_74
print(ans)
Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
P = [0] * M
Y = [0] * M
check = [[] for i in range(N)]

for i in range(M):
    P[i], Y[i] = map(int, input().split())
    check[P[i]-1].append(Y[i])

for i in range(N):
    check[i].sort()

for i in range(M):
    tmp1 = ('00000' + str(P[i]))[-6:] 
    tmp2 = ('00000' + str(check[P[i]-1].index(Y[i])+1))[-6:]
    tmp = tmp1 + tmp2
    print(tmp)




Fixed submission:
a, b = map(int,input().split())
print(round(a+b//2))
Buggy python submission (verdict: Runtime Error):
N = int(input())
x = [0] * N
y = [0] * N
h = [0] * N
for i in range(N):
    x[i], y[i], h[i] = map(int, input().split())

top = [[] for _ in range(101*101)]

for i in range(101):
    for j in range(101):
        top[i*101+j] = [i, j]

#print(top)

H = 0

for i in range(len(top)):
    topx = top[i][0]
    topy = top[i][1]
    H = 0
    h_list = []
    for j in range(N):
        if h[j] != 0:
            tmp = abs(topx - x[j]) + abs(topy - y[j]) + h[j]
            h_list.append(tmp)
    if h_list.count(h_list[0]) == N - h.count(0) :
        ansx = topx
        ansy = topy
        ansH = h_list[0]
        break

print(ansx, ansy, ansH)


Fixed submission:
N = int(input())
if N == 1 :
  print('Hello World')
else :
  a = int(input())
  b = int(input())
  print(a+b)
Buggy python submission (verdict: Runtime Error):
l = list(map(int,input().split().split()))
l.sort()
print(l[0]*10 +l[1]+l[2])

Fixed submission:
a,b = map(int,input().split())
if a*b %2 != 0:
  print('Yes')
else :
  print('No')

Buggy python submission (verdict: Runtime Error):
a,b = map(int,input())
if a*b %2 != 0:
  print('Yes')
else :
  print('No')

Fixed submission:
a,b = map(int,input().split())
if a*b %2 != 0:
  print('Yes')
else :
  print('No')
Buggy python submission (verdict: Runtime Error):
S = list(input())
K = int(input())

for i in range(len(S)):
    if S[i] != "1" :
        tmp = i+1
        break

if tmp > K :
    ans = 1
else:
    ans = S[tmp-1]

print(ans)

Fixed submission:
S = list(input())
K = int(input())
check = 0

for i in range(len(S)):
    if S[i] != "1" :
        tmp = i+1
        check = 1
        break

if check == 0:
    ans = 1
else:
    if tmp > K :
        ans = 1
    else:
        ans = S[tmp-1]

print(ans)
Buggy python submission (verdict: Runtime Error):
import math
N = int(input())

def order2(x):
  if x > 0 :
    k = 0
    check = 0
    while check == 0 :
      s = 0
      for i in range(0, k+1, 2):
        s += (-2)**i
        ans = i
      if s >= x:
        check = 1
      k += 2
  elif x < 0 :
    k = 1
    check = 0
    while check == 0 :
      s = 0
      for i in range(1, k+1, 2):
        s += (-2)**i
        ans = i
      if s <= x:
        check = 1
      k += 2
  return ans

if N!= 0 :


  l = [] 
  a = N
  i = order2(N)
  while i >= 0:
    if a == 0 :
      l.append(0)
    if a > 0 and (-2)**i >0 :
        s = 0
        for j in range(0, i, 2):
          s += (-2)**j
        print(a,s)
        if a > s :
          l.append('1')
          a -= (-2)**i
        else :
          l.append('0')
    elif a > 0 and (-2)**i < 0:
        l.append('0')
    elif a < 0 and (-2)**i > 0:
        l.append('0')
    elif a < 0 and (-2)**i < 0:
        s = 0
        for j in range(1, i, 2):
          s += (-2)**j
        if a < s :
          l.append('1')
          a -= (-2)**i
        else :
          l.append('0')
    i -= 1

  print(''.join(l))

else :
  print(0)

Fixed submission:
N = int(input())

def order2(x):
  if x > 0 :
    k = 0
    check = 0
    while check == 0 :
      s = 0
      for i in range(0, k+1, 2):
        s += (-2)**i
        ans = i
      if s >= x:
        check = 1
      k += 2
  elif x < 0 :
    k = 1
    check = 0
    while check == 0 :
      s = 0
      for i in range(1, k+1, 2):
        s += (-2)**i
        ans = i
      if s <= x:
        check = 1
      k += 2
  return ans

if N!= 0 :


  l = [] 
  a = N
  i = order2(N)
  while i >= 0:
    if a == 0 :
      l.append('0')
    if a > 0 and (-2)**i >0 :
        s = 0
        for j in range(0, i, 2):
          s += (-2)**j
        if a > s :
          l.append('1')
          a -= (-2)**i
        else :
          l.append('0')
    elif a > 0 and (-2)**i < 0:
        l.append('0')
    elif a < 0 and (-2)**i > 0:
        l.append('0')
    elif a < 0 and (-2)**i < 0:
        s = 0
        for j in range(1, i, 2):
          s += (-2)**j
        if a < s :
          l.append('1')
          a -= (-2)**i
        else :
          l.append('0')
    i -= 1

  print(''.join(l))

else :
  print(0)