Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
n,m = map(int,input().split())
ans = []
data1 = deque([1])
data2 = deque([])
hantei = [0]*(10**5+2)
hantei[1] = 1
for i in range(m):
    data2.append(list(map(int,input().split())))
while data1 and data2:
    i = data1.popleft()
    for k in range(len(data2)):
        a,b = map(int,data2.popleft())
        if a == i and hantei[b] == 0:
            ans.append([b,a])
            data1.append(b)
            hantei[b] = 1
        elif hantei[a] == 0 and b == i:
            ans.append([a,b])
            data1.append(a)
            hantei[a] = 1
        else:
            if hantei[a]*hantei[b] == 1:
                continue
            else:
                data2.append([a,b])
else:
    if data2:
        print("No")
    else:
        print("Yes")
        ans.sort()
        for i in ans:
            print(i[-1])

Fixed submission:
from collections import deque
n,m = map(int,input().split())
data = [[] for i in range(n)]
ans = [0]*n
for i in range(m):
    a,b =map(int,input().split())
    a -= 1
    b -= 1
    data[a].append(b)
    data[b].append(a)
hantei = [False]*n
hantei[0] = True
deq = deque([0])
while deq:
    k = deq.popleft()
    for i in data[k]:
        if hantei[i]:
            continue
        hantei[i] = True
        ans[i] = k
        deq.append(i)
print("Yes")
for i in range(1,n):
    print(ans[i]+1)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
n,m = map(int,input().split())
ans = []
data1 = deque([1])
data2 = deque([])
hantei = [0]*(10**5+2)
hantei[1] = 1
for i in range(m):
    data2.append(list(map(int,input().split())))
while data1 and data2:
    i = data1.popleft()
    for k in range(len(data2)):
        a,b = map(int,data2.popleft())
        if a == i and hantei[b] == 0:
            ans.append([b,a])
            data1.append(b)
            hantei[b] = 1
        elif hantei[a] == 0 and b == i:
            ans.append([a,b])
            data1.append(a)
            hantei[a] = 1
        else:
            if hantei[a]*hantei[b] == 1:
                continue
            else:
                data2.append([a,b])
else:
    if data2:
        print("No")
    else:
        print("Yes")
        ans.sort()
        for i in ans:
            print(i[-1])

Fixed submission:
from collections import deque
n,m = map(int,input().split())
data = [[] for i in range(n)]
ans = [0]*n
for i in range(m):
    a,b =map(int,input().split())
    a -= 1
    b -= 1
    data[a].append(b)
    data[b].append(a)
hantei = [False]*n
hantei[0] = True
deq = deque([0])
while deq:
    k = deq.popleft()
    for i in data[k]:
        if hantei[i]:
            continue
        hantei[i] = True
        ans[i] = k
        deq.append(i)
print("Yes")
for i in range(1,n):
    print(ans[i]+1)
Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
"""
Created on Sun May 10 21:34:02 2020

@author: shinba
"""


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

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

data = [0]*n
data[0] = 1

li = [0]

while k > 0:
    b = a[li[-1]]-1
    if data[b] == 0:
        data[b] = 1
        li.append(b)
        k -= 1
    else:
        break

if k != 0:
    for i in range(len(li)-1,-1,-1):
        if li[i] == b:
            s = b
            break
    newli = li[b:]
    l = (k-1) % len(newli)
    print(li[l]+1)
else:
    print(li[-1]+1)
    

Fixed submission:
# -*- coding: utf-8 -*-
"""
Created on Sun May 10 21:34:02 2020

@author: shinba
"""
import sys
sys.setrecursionlimit(500000)

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

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

data = [0]*n
data[0] = 1

li = [0]

while k > 0:
    b = a[li[-1]]-1
    if data[b] == 0:
        data[b] = 1
        li.append(b)
        k -= 1
    else:
        break

if k != 0:
    for i in range(len(li)-1,-1,-1):
        if li[i] == b:
            s = i
            break
    newli = li[s:]
    l = (k-1) % len(newli)
    print(newli[l]+1)
else:
    print(li[-1]+1)
Buggy python submission (verdict: Runtime Error):
S = input()

if S = "ABC":
    print("ARC")
else:
    print("ABC")


Fixed submission:
S = input()

if S == "ABC":
    print("ARC")
else:
    print("ABC")
Buggy python submission (verdict: Runtime Error):
X = int(input())

B = [n**5 for n in range(300)]

A = []

for i in range(300):
    a = i**5- X if i**5 >= X else X-i**5
    A.append(a)

for j in range(300):
    if A[j] in B:
        a = j
        b = B.index(A[j])
        if a**5-b**5 = X:
            print(a,b)
        elif a**+b**5 = X:
            print(a,-b)
        break


Fixed submission:
X = int(input())

B = [n**5 for n in range(200)]

A = []

for i in range(200):
    a = i**5- X if i**5 >= X else X-i**5
    A.append(a)

for j in range(200):
    if A[j] in B:
        a = j
        b = B.index(A[j])
        if a**5-b**5 == X:
            print(a,b)
        elif a**5+b**5 == X:
            print(a,-b)
        else:
            print(b,a)
        break
Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
"""
Created on Thu May  7 00:07:17 2020

@author: shinba
"""
import collections

def conbination(n):
    return int(n*(n-1)/2)

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

B = collections.Counter(A)

key = []
val = []

for i,j in B.items():
    key.append(i)
    val.append(j)

for i in range(len(B)):
    W = 0
    for j in range(len(B)):
        if i == j:
            val[j] -= 1
            s = j
        W += conbination(val[j])
    B[key[i]] = W
    val[s] += 1

for i in A:
    print(B[i])

    

Fixed submission:
# -*- coding: utf-8 -*-
"""
Created on Thu May  7 01:30:29 2020

@author: shinba
"""
import collections

def conbination(n):
    return int(n*(n-1)/2)

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

B = collections.Counter(A)

W = 0
for i in B.values():
    W += conbination(i)

for i in A:
    print(W-B[i]+1)

Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
"""
Created on Thu May  7 00:07:17 2020

@author: shinba
"""
import collections

def conbination(n):
    return int(n*(n-1)/2)

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

B = collections.Counter(A)

key = []
val = []

for i,j in B.items():
    key.append(i)
    val.append(j)

for i in range(len(B)):
    W = 0
    for j in range(len(B)):
        if i == j:
            val[j] -= 1
            s = j
        W += conbination(val[j])
    B[key[i]] = W
    val[s] += 1

for i in A:
    print(B[i])

    

Fixed submission:
# -*- coding: utf-8 -*-
"""
Created on Thu May  7 01:30:29 2020

@author: shinba
"""
import collections

def conbination(n):
    return int(n*(n-1)/2)

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

B = collections.Counter(A)

W = 0
for i in B.values():
    W += conbination(i)

for i in A:
    print(W-B[i]+1)
Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
"""
Created on Thu May  7 13:56:40 2020

@author: shinba
"""
import sys
from collections import deque

s = input()
q = int(input())

dq = deque(s)

for i in range(q):
    t = sys.stdin.readline().rstrip().split()
    if t[0] == "1":
        dq.reverse()
    else:
        if t[1] == "1":
            dq.appendleft(t[2])
        else:
            dq.append(t[2])

print("".join(list(dq)))
        
        


Fixed submission:
# -*- coding: utf-8 -*-
"""
Created on Thu May  7 13:56:40 2020

@author: shinba
"""
import sys
from collections import deque

s = input()
q = int(input())

dq = deque(s)
rev = False

for i in range(q):
    t = sys.stdin.readline().rstrip().split()
    if t[0] == "1":
        rev = not rev
    else:
        if t[1] == "1":
            if rev:
                dq.append(t[2])
            else:
                dq.appendleft(t[2])
        else:
            if rev:
                dq.appendleft(t[2])
            else:
                dq.append(t[2])

s = "".join(list(dq))

if rev:
    print(s[::-1])
else:
    print(s)

Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
"""
Created on Thu May  7 13:25:51 2020

@author: shinba
"""
import sys

S = input()
Q = int(input())
data = [sys.stdin.readline().rstrip().split() for i in range(Q)]

for i in data:
    if i[0] == "1":
        S = S[::-1]
    else:
        if i[1] == "1":
            S = i[2] + S
        else:
            S = S + i[2]

print(S)

Fixed submission:
# -*- coding: utf-8 -*-
"""
Created on Thu May  7 13:56:40 2020

@author: shinba
"""
import sys
from collections import deque

s = input()
q = int(input())

dq = deque(s)
rev = False

for i in range(q):
    t = sys.stdin.readline().rstrip().split()
    if t[0] == "1":
        rev = not rev
    else:
        if t[1] == "1":
            if rev:
                dq.append(t[2])
            else:
                dq.appendleft(t[2])
        else:
            if rev:
                dq.appendleft(t[2])
            else:
                dq.append(t[2])

s = "".join(list(dq))

if rev:
    print(s[::-1])
else:
    print(s)
Buggy python submission (verdict: Time Limit Exceeded):
h,n = map(int,input().split())
data = []
ans = 0
M = -1
for _ in range(n):
    a,b = map(int,input().split())
    data.append((a,b))
    M = max(a,M)
dp = [float("inf") for _ in range(h+M)]
dp[0] = 0
for i,j in data:
    for k in range(h+M-1):
        if k+i <= h+M-1:
            dp[k+i] = min(dp[k]+j,dp[k+i])
print(min(dp[h:]))

Fixed submission:
h,n = map(int,input().split())
data = []
ans = 0
M = -1
for _ in range(n):
    a,b = map(int,input().split())
    data.append((a,b))
    M = max(a,M)
dp = [float("inf") for _ in range(h+M)]
dp[0] = 0
for i,j in data:
    for k in range(h+M-1):
        if k+i <= h+M-1:
            dp[k+i] = min(dp[k]+j,dp[k+i])
print(min(dp[h:]))
Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
"""
Created on Sat May  9 01:31:32 2020

@author: shinba
"""
a,b = map(int,input().split())

if a >= b:
    print(f'{b}'*a)
else:
    print(f'{a}'*b)



Fixed submission:
# -*- coding: utf-8 -*-
"""
Created on Sat May  9 01:31:32 2020

@author: shinba
"""
a,b = map(int,input().split())

if a >= b:
    print("{}".format(b)*a)
else:
    print("{}".format(a)*b)
Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
"""
Created on Sat May  9 16:09:21 2020

@author: shinba
"""

import math

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

print(int(a*b/math.gcd(a,b)))



Fixed submission:
# -*- coding: utf-8 -*-
"""
Created on Sat May  9 16:09:21 2020

@author: shinba
"""

import fractions

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

print(int(a*b/fractions.gcd(a,b)))
Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
"""
Created on Sat May  9 16:33:03 2020

@author: shinba
"""


n = int(input())
a = list(map(input().split()))
cnt = 0
st = 1
for i in range(n):
    if a[i] == st:
        st += 1
    else:
        cnt += 1

if 1 in a:
    print(cnt)
else:
    print(-1)
    
    

Fixed submission:
# -*- coding: utf-8 -*-
"""
Created on Sat May  9 16:33:03 2020

@author: shinba
"""


n = int(input())
a = list(map(int,input().split()))
cnt = 0
st = 1
for i in range(n):
    if a[i] == st:
        st += 1
    else:
        cnt += 1

if 1 in a:
    print(cnt)
else:
    print(-1)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict
n = int(input())
A = list(map(int, input().split()))
mod = pow(10,9) + 7
D = defaultdict(lambda:0)
for a in A:
    for i in range(61):
        D[1 << i] += bool(a & (1 << i))
ans = 0
for k, v in D.items():
    ans += k * (v * (n - v))
    ans %= mod
print(ans)

Fixed submission:
from collections import defaultdict
n = int(input())
A = list(map(int, input().split()))
mod = pow(10,9) + 7
D = defaultdict(lambda:0)
for a in A:
    for i in range(61):
        D[1 << i] += bool(a & (1 << i))
ans = 0
for k, v in D.items():
    ans += k * (v * (n - v))
    ans %= mod
print(ans)
Buggy python submission (verdict: Runtime Error):
n = int(input())
A = list(map(int,input().split()))
data = [0]*3
ans = 1
mod = pow(10,9)+7
for i in A:
    ans *= data.count(i)
    ans %= mod
    data[data.index(i)] += 1
print(ans)

Fixed submission:
n = int(input())
A = list(map(int,input().split()))
data = [0]*3
ans = 1
mod = pow(10,9)+7
for i in A:
    ans *= data.count(i)
    ans %= mod
    if ans == 0:
        break
    data[data.index(i)] += 1
print(ans)
Buggy python submission (verdict: Runtime Error):
from itertools import combinations

n = int(input())
D = []
ans = 0
for i in range(n):
    x,y = map(int,input().split())
    D.append((x,y))
for i,j in combinations(range(1,n+1),r=2):
    p,q = D[i-1]
    r,s = D[j-1]
    ans += ((p-r)**2+(q-s)**2)**(0.5)
print(2*ans/n)

Fixed submission:
print(int(input())**2)
Buggy python submission (verdict: Runtime Error):
s = input() 
ans = 0
flag = False
s += "|"
if s[0] == ">": 
    cntl = 1
    flag = True
else:
    cntr = 1
for i in range(1,len(s)):
    if flag:
        if s[i] == ">":
            ans += cntl
            cntl += 1
        else:
            ans += cntl if cntl >= need else need
            flag = False
            cntr = 1
    else:
        if s[i] == "<":
            ans += cntr
            cntr += 1
        else:
            need = cntr
            flag = True
            cntl = 1
            if i == len(s)-1:
                ans += need
print(ans)
    

Fixed submission:
s = input() 
ans = 0
flag = False
s += "|"
if s[0] == ">": 
    cntl = 1
    flag = True
    need = 0
else:
    cntr = 1
for i in range(1,len(s)):
    if flag:
        if s[i] == ">":
            ans += cntl
            cntl += 1
        else:
            ans += cntl if cntl >= need else need
            flag = False
            cntr = 1
    else:
        if s[i] == "<":
            ans += cntr
            cntr += 1
        else:
            need = cntr
            flag = True
            cntl = 1
            if i == len(s)-1:
                ans += need
print(ans)
Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
"""
Created on Tue May 12 00:13:44 2020

@author: shinba
"""
import sys

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

if (x==0 and y==0) or (x==w and y==0) or (x==0 and y==h) or (x==w and y==h):
    print((w*h)/2,0)
    sys.exit()
if w != x:
    if y/x == h/w or y/(w-x) == h/w:
        #print(y/x,h/w,y/(w-x))
        if y/x == h/w and y/(w-x) == h/w:
            print((w*h)/2,1)
        else:
            print((w*h)/2,0)
        sys.exit()
    
a1 = h*min(w-x,x)
a2 = w*min(h-y,y)

if a1 == a2:
    print(a1,1)
else:
    print(max(a1,a2),0)

Fixed submission:
# -*- coding: utf-8 -*-
"""
Created on Tue May 12 00:13:44 2020

@author: shinba
"""
import sys

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

if w%2 == 0 and h%2 == 0:
    if w//2 == x and h//2 == y:
        print((h*w)/2,1)
        sys.exit()
        
print(h*w/2,0)

Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
"""
Created on Tue May 12 00:13:44 2020

@author: shinba
"""
import sys

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

if (x==0 and y==0) or (x==w and y==0) or (x==0 and y==h) or (x==w and y==h):
    print((w*h)/2,0)
    sys.exit()
if y/x == h/w or y/(w-x) == h/w:
    #print(y/x,h/w,y/(w-x))
    if y/x == h/w and y/(w-x) == h/w:
         print((w*h)/2,1)
    else:
        print((w*h)/2,0)
    sys.exit()
    
a1 = h*min(w-x,x)
a2 = w*min(h-y,y)

if a1 == a2:
    print(a1,1)
else:
    print(max(a1,a2),0)

Fixed submission:
# -*- coding: utf-8 -*-
"""
Created on Tue May 12 00:13:44 2020

@author: shinba
"""
import sys

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

if w%2 == 0 and h%2 == 0:
    if w//2 == x and h//2 == y:
        print((h*w)/2,1)
        sys.exit()
        
print(h*w/2,0)
Buggy python submission (verdict: Time Limit Exceeded):
N,M = map(int,input().split())
a = [int(input()) for i in range(M)]

dp = [0]*(N+1)
dp[0] = 1

if 1 in a:
    dp[1] = 0
else:
    dp[1] = 1

for i in range(2,N+1):
    if i in a:
        continue
    dp[i] = dp[i-2] + dp[i-1]
    dp[i] = dp[i] % (10**9+7)

print(dp[N])


Fixed submission:
N,M = map(int,input().split())
a = [int(input()) for i in range(M)]

dp = [-float("inf")]*(N+1)
dp[0] = 1
dp[1] = 1

for i in a:
    dp[i] = 0

for i in range(2,N+1):
    if dp[i] == 0:
        continue
    dp[i] = dp[i-2] + dp[i-1]
    dp[i] = dp[i] % (10**9+7)

print(dp[N])

Buggy python submission (verdict: Time Limit Exceeded):
N,M = map(int,input().split())
a = [int(input()) for i in range(M)]

dp = [0]*(N+1)
dp[0] = 1

if 1 in a:
    dp[1] = 0
else:
    dp[1] = 1

for i in range(2,N+1):
    if i in a:
        continue
    dp[i] = dp[i-2] + dp[i-1]

print(dp[N] % (10**9+7))


Fixed submission:
N,M = map(int,input().split())
a = [int(input()) for i in range(M)]

dp = [-float("inf")]*(N+1)
dp[0] = 1
dp[1] = 1

for i in a:
    dp[i] = 0

for i in range(2,N+1):
    if dp[i] == 0:
        continue
    dp[i] = dp[i-2] + dp[i-1]
    dp[i] = dp[i] % (10**9+7)

print(dp[N])
Buggy python submission (verdict: Runtime Error):
from operator import itemgetter
n,m = map(int,input().split())
A = list(map(int,input().split()))
A.sort()
data = []
now = 0
for i in range(m):
    b,c = map(int,input().split())
    data.append((b,c))
for i,j in sorted(data,key=itemgetter(1),reverse=True):
    while A[now] < j and i:
        A[now] = j
        i -= 1
        now += 1
    if now == n:
        print(sum(A))
        break
    if A[now] >= j:
        print(sum(A))
        break
else:
    print(sum(A))        

Fixed submission:
from operator import itemgetter
n,m = map(int,input().split())
A = list(map(int,input().split()))
A.sort()
data = []
now = 0
for i in range(m):
    b,c = map(int,input().split())
    data.append((b,c))
for i,j in sorted(data,key=itemgetter(1),reverse=True):
    while A[now] < j and i:
        A[now] = j
        i -= 1
        now += 1
        if now == n:
            print(sum(A))
            exit()
    if A[now] >= j:
        print(sum(A))
        break
else:
    print(sum(A))
Buggy python submission (verdict: Runtime Error):
n = int(input())
s = list(input())
while s[-1] == "#":
    s.pop()
s = "".join(s)
n = len(s)
data = []
ind = []
cnt = 0
ans = 0
for i in range(n):
    if s[i] == "#":
        cnt += 1
        ind.append(i)
    data.append(cnt)
if not ind:
    print(0)
    exit()
for i in ind:
    m = data[-1]-data[i]+1
    l = n-m-i
    if l > m:
        ans += 1
    else:
        print(ans+l)
        break
else:
    print(ans)

Fixed submission:
n = int(input())
s = input()
rw = s.count(".")
lb = 0
M = rw+lb
for i in range(n):
    if s[i] =="#":
        lb += 1
    else:
        rw -= 1
    M = min(M,rw+lb)
print(M)
Buggy python submission (verdict: Runtime Error):
N,K = map(int,input().split())
h = list(map(int,input().split()))

dp = [float("inf")]*(10**5+10)
dp[0] = 0

for i in range(N-1):
    Mi = min(K+1,N-i)
    for j in range(1,Mi):
            dp[i+j] = min(dp[i+j],dp[i]+abs(h[i+j]-h[i]))

print(dp[N-1])


Fixed submission:
N = int(input())
H = list(map(int,input().split()))

dp = [float("inf")]*N
dp[0] = 0

for i in range(1,N):
    if i == 1:
        dp[i] = min(dp[i],dp[i-1] + abs(H[i]-H[i-1]))
    else:
        dp[i] = min(dp[i],dp[i-1]+abs(H[i]-H[i-1]),dp[i-2]+abs(H[i]-H[i-2]))

print(dp[N-1])
Buggy python submission (verdict: Time Limit Exceeded):
N,K = map(int,input().split())
h = list(map(int,input().split()))

dp = [float("inf")]*(10**5+10)
dp[0] = 0

for i in range(N-1):
    Mi = min(K+1,N-i)
    for j in range(1,Mi):
            dp[i+j] = min(dp[i+j],dp[i]+abs(h[i+j]-h[i]))

print(dp[N-1])


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

dp = [float("inf")]*(10**5+10)
dp[0] = 0

for i in range(N-1):
    Mi = min(K+1,N-i)
    for j in range(1,Mi):
            dp[i+j] = min(dp[i+j],dp[i]+abs(h[i+j]-h[i]))

print(dp[N-1])

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

dp = [float("inf")]*(10**5+1000)
dp[0] = 0

for i in range(N):
    for j in range(1,K+1):
        if 1 <= i+j <= N-1:
            dp[i+j] = min(dp[i+j],dp[i]+abs(h[i+j]-h[i]))

print(dp[N-1])


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

dp = [float("inf")]*(10**5+10)
dp[0] = 0

for i in range(N-1):
    Mi = min(K+1,N-i)
    for j in range(1,Mi):
            dp[i+j] = min(dp[i+j],dp[i]+abs(h[i+j]-h[i]))

print(dp[N-1])
Buggy python submission (verdict: Time Limit Exceeded):
N,W = map(int,input().split())
li = [list(map(int,input().split())) for i in range(N)]

dp = [[0 for i in range(W+1)] for j in range(N+1)]

for i in range(N):
    for sum_w in range(W+1):
        if sum_w >= li[i][0]:
            dp[i+1][sum_w] = max(dp[i][sum_w-li[i][0]]+li[i][1],dp[i][sum_w])
        else:
            dp[i+1][sum_w] = dp[i][sum_w]

print(dp[N][W])


Fixed submission:
N,W = map(int,input().split())
li = [list(map(int,input().split())) for i in range(N)]

dp = [[0 for i in range(W+1)] for j in range(N+1)]

for i in range(N):
    for sum_w in range(W+1):
        if sum_w >= li[i][0]:
            dp[i+1][sum_w] = max(dp[i][sum_w-li[i][0]]+li[i][1],dp[i][sum_w])
        else:
            dp[i+1][sum_w] = dp[i][sum_w]

print(dp[N][W])
Buggy python submission (verdict: Runtime Error):
n,x = map(int,input().split())
a = [1]
p = [1]
for i in range(n):
    a.append(2*a[i]+3)
    p.append(2*p[i]+1)
def f(n,x):
    if x == 1:
        return 0
    elif 1 < x <= a[n-1]:
        return f(n-1,x-1)
    elif x == 2 + a[n-1]:
        return 1+p[n-1]
    elif 2 + a[n-1] < x <= 2+2*a[n-1]:
        return p[n-1]+1+f(n-1,x-2-a[n-1])
    elif x == 2*a[n-1]+3:
        return 2*p[n-1]+1

print(f(n,x)) 

Fixed submission:
n,x = map(int,input().split())
a = [1]
p = [1]
for i in range(n):
    a.append(2*a[i]+3)
    p.append(2*p[i]+1)
def f(n,x):
    if x == 1:
        return int(n <= 0)
    elif 1 < x <= a[n-1]+1:
        return f(n-1,x-1)
    elif x == 2 + a[n-1]:
        return 1+p[n-1]
    elif 2 + a[n-1] < x <= 2+2*a[n-1]:
        return p[n-1]+1+f(n-1,x-2-a[n-1])
    elif x == 2*a[n-1]+3:
        return 2*p[n-1]+1

print(f(n,x))
Buggy python submission (verdict: Runtime Error):
from collections import deque
n = int(input())
A = []
for _ in range(n):
    A.append(int(input()))
dq = deque(sorted(A))
ans = deque([dq.popleft()])
ans.append(dq.pop())
ans.appendleft(dq.pop())
flag = True
while dq:
    if flag:
        ans.append(dq.popleft())
        if dq:
            ans.appendleft(dq.popleft())
            flag = False
    else:
        ans.append(dq.pop())
        if dq:
            ans.appendleft(dq.pop())
            flag = True
B = list(ans)
s = 0
for i in range(n-1):
    s += abs(B[i+1]-B[i])
print(s)

Fixed submission:
from collections import deque
n = int(input())
A = []
for _ in range(n):
    A.append(int(input()))
if n == 2:
    print(abs(A[1]-A[0]))
    exit()
A.sort()
s = sum(A)
if n % 2 == 1:
    small = 0
    for i in range(n//2):
        small += A[i]
    big = s - small
    ans1 = 2*big-2*small-A[n//2]-A[n//2+1]
    small += A[n//2]
    big = s-small
    ans2 = 2*big -2*small+A[n//2]+A[n//2-1]
    print(max(ans1,ans2))
else:
    small = 0
    for i in range(n//2):
        small += A[i]
    big = s -small
    ans1 = 2*big -2*small + A[n//2-1]-A[n//2]
    small += A[n//2]
    big = s -small
    ans2 = 2*big-2*small+A[n//2]-A[n//2+1]
    print(max(ans1,ans2))
Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
"""
Created on Sat May  9 16:54:06 2020

@author: shinba
"""

s = input()
k = int(input())

cnt = 0

while s[cnt] == "1":
    cnt += 1

if cnt >= k:
    print(1)
else:
    print(s[cnt])


Fixed submission:
# -*- coding: utf-8 -*-
"""
Created on Sat May  9 16:54:06 2020

@author: shinba
"""

s = input()
k = int(input())

cnt = 0

while s[cnt] == "1":
    cnt += 1
    if cnt == len(s):
        break

if cnt >= k:
    print(1)
else:
    print(s[cnt])