Harryxun/GPT-100-sft-dataset huggingface dataset:
Problem p02951 (python)

Fixed submission:
A, B, C = list(map(int, input().split()))

print(max(0,B+C-A))

Buggy submission (verdict: Runtime Error):
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
//using T = tuple<string, int, int>;

int main() {
  int A,B,C;
  cin >> A >> B >> C;
  cout << max(C-(A-B), 0) << endl;

  return 0;
}

// https://github.com/atcoder/live_library
Problem p03033 (python)

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

S,T,X = [],[],[]

Ev = []
for _ in range(N):
  s,t,x = map(int, input().split())
  Ev.append((s-x,True,x))
  Ev.append((t-x,False,x))
"""
2 5 6
5 -1
4 2
3 3
2 4
1 5
0 -1
"""
Ev.sort()
#print(Ev)
# C++のSetはminもO(logN)で取れるが、Pythonは無理。
# setとheapqを併用すると計算量が実現できる。
h = []
closed = set()
eidx = 0
for i in range(Q):
  # dはsortedでinputされる。
  d = int(input())
  #Query.append(d)
  while eidx < 2*N and Ev[eidx][0] <= d:
    #pop
    t,e,x = Ev[eidx]
    eidx += 1
    if e:
      heapq.heappush(h, x)
      closed.add(x)
    else:
      closed.remove(x)
      
  # heqpqの最小値がsetに含まれている間、捨て続ければ、setの要素とheapqの要素が一致する
  while h and h[0] not in closed:
    heapq.heappop(h)
    
  # assert( len(h) == len(set) )
  if h:
    print(h[0])
  else:
    print(-1)

Buggy submission (verdict: Runtime Error):
from collections import deque
N,M = map(int, input().split())
S = input() # len(S)=S+1 !!!
A = [-1 for _ in range(N+1)]
S = S[::-1]
for i in range(N+1):
  if S[i] == "1":
    continue
  flg = True
  for m in range(1,M+1):
    if i + m > N:
      A[i] = N
      flg = False
      break
    if S[i+m] == "0":
      A[i] = i+m
      flg = False
    else:
      continue
  if flg:
    print(-1)
    exit(0)
#print(A)
i = 0
ANS = []
while i < N :
  nxt = A[i]
  ANS.append(nxt - i)
  i = nxt
  
print(" ".join(map(str,ANS[::-1])))
Problem p03250 (python)

Fixed submission:
A, B, C = map(int, input().split())
S = A+B+C
print(max(S+9*A, S+9*B, S+9*C))

Buggy submission (verdict: Runtime Error):
A, B, C = map(int, input().split())
S = sum(A,B,C)
print(max(S+9*A, S+9*B, S+9*C))
Problem p03776 (python)

Fixed submission:
from collections import Counter

from scipy.misc import comb
#a = comb(n, r, exact=True)

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

V.sort(reverse = True)
C = Counter(V)

print(sum(V[:A]) / A)

max_value = V[0]

# V[0], ... V[A-1] がすべて同じとき、そうでないときで異なる
# V[0], ... V[A-1] に異なるものが含まれると、Aコ選ぶときがMAX
key_value = V[A-1]
if key_value < max_value:
  # V[A-1]の個数と、その前に何個あるかを数えればよい
  forward_item_count = 0
  for k,v in C.items():
    if k > key_value:
      forward_item_count += v

  print(int(comb(C[key_value], A - forward_item_count, exact=True)))
  exit(0)
  
# すべて同じときはAコ～Bコ選んでも平均一緒。組み合わせ数を足していく必要性
ans = 0
cnts = C[key_value]
for i in range(A,B+1):
  ans += comb(cnts,i, exact=True)
  
print(int(ans))

Buggy submission (verdict: Runtime Error):
from operator import mul
from functools import reduce
from math import sqrt

def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under

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

V.sort(reverse = True)

print(sum(V[:A]) / A)

# A番目と一緒の数字の数（A個より外で）
cnt_ext = 0
for i in range(A,min(A+B,N)):
  if V[A-1] == V[i]:
    cnt_ext += 1
    
# A番目と一緒の数字の数（A個の中で）
cnt_int = 0
for i in range(0,A):
  if V[A-1] == V[i]:
    cnt_int += 1
    
#print(cnt_int, cnt_ext)
cnt_all = cnt_int + cnt_ext

ans = 0
for i in range(A,B+1):
  ans += cmb(cnt_all, cnt_int)
  cnt_int += 1
  
print(ans)
Problem p03822 (python)

Fixed submission:
import sys
input = sys.stdin.readline
import heapq
from collections import deque
sys.setrecursionlimit(200000)

N = int(input())
X = [[] for _ in range(N)]
for i in range(N-1):
  a = int(input())
  X[a-1].append(i+1)
  
# dfsをして、Depthを計算しつつ、depth大きい順に取り出せるようにheapqを使う
h = []

seen = [False] * N
def dfs(a,depth):
  seen[a] = True
  heapq.heappush(h, (-depth, a))
  for nxt in X[a]:
    #if seen[nxt]:
      #continue
    dfs(nxt, depth+1)

dfs(0,0)
#rint(len(h))
DP = [0] * N
while h:
  depth, a = heapq.heappop(h)
  cand = []
  for child in X[a]:
    cand.append(DP[child])
  if not cand:
    DP[a] = 1
    continue
  cand.sort(reverse=True)
  for i in range(len(cand)):
    DP[a] = max(DP[a], cand[i]+i+1)
    
print(DP[0]-1)

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
import heapq
from collections import deque

N = int(input())
X = [[] for _ in range(N)]
for i in range(N-1):
  a = int(input())
  X[a-1].append(i+1)
  
# dfsをして、Depthを計算しつつ、depth大きい順に取り出せるようにheapqを使う
h = []

seen = [False] * N
def dfs(a,depth):
  seen[a] = True
  heapq.heappush(h, (-depth, a))
  for nxt in X[a]:
    #if seen[nxt]:
      #continue
    dfs(nxt, depth+1)

dfs(0,0)
#rint(len(h))
DP = [0] * N
while h:
  depth, a = heapq.heappop(h)
  cand = []
  for child in X[a]:
    cand.append(DP[child])
  if not cand:
    DP[a] = 1
    continue
  cand.sort(reverse=True)
  for i in range(len(cand)):
    DP[a] = max(DP[a], cand[i]+i+1)
    
print(DP[0]-1)
Problem p02820 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10**6)
if sys.platform in (['ios','darwin','win32']):
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return [int(s) for s in input().split()]

def main():
	N, K = MAP()
	R, S, P = MAP()
	T = input().rstrip()

	Tokuten = [R, S, P]
	Te = ['r', 's', 'p']

	A = [-1] * N
	for i in range(N):
		now = 0 if T[i]=='s' else 1 if T[i]=='p' else 2
		if i-K < 0:
			A[i] = now
		else:
			past = A[i-K]
			if now == past:
				if i+K < N:
					future = 0 if T[i+K]=='s' else 1 if T[i+K]=='p' else 2
					for j in range(3):
						if not j in [now, future]:
							A[i] = j
			else:
				A[i] = now
	
	# print(A)

	ans = 0
	for i in range(N):
		te = A[i]
		if te==0 and T[i]=='s':
			ans += Tokuten[0]
		elif te==1 and T[i]=='p':
			ans += Tokuten[1]
		elif te==2 and T[i]=='r':
			ans += Tokuten[2]

	print(ans)

if __name__ == '__main__':
	main()

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10**6)
if sys.platform in (['ios','darwin','win32']):
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return [int(s) for s in input().split()]

def main():
	N, K = MAP()
	R, S, P = MAP()
	T = input().rstrip()

	Tokuten = [R, S, P]
	Te = ['r', 's', 'p']

	A = [-1] * N

	ans = 0
	for i in range(N):
		now = 0 if T[i]=='s' else 1 if T[i]=='p' else 2
		# print(Te[now])
		if i-K >= 0:
			past = 0 if T[i-K]=='s' else 1 if T[i-K]=='p' else 2
			# print(now, past, i)
			# 過去に出している手だったら、違う手を出す
			if past == now:
				if i-(2*K) >= 0:
					ppast = 0 if T[i-2*K]=='s' else 1 if T[i-2*K]=='p' else 2
					if ppast == past:
						A[i] = now
						ans += Tokuten[now]
					else:
						if i+K < N:
							feature = 0 if T[i+K]=='s' else 1 if T[i+K]=='p' else 2
							for j in range(3):
								if not j in [now, feature]:
									A[i] = j
						else:
							A[i] = (now+1)%3
				else:
					if i+K < N:
						feature = 0 if T[i+K]=='s' else 1 if T[i+K]=='p' else 2
						for j in range(3):
							if not j in [now, feature]:
								A[i] = j
					else:
						A[i] = (now+1)%3
			else:
				A[i] = now
				ans += Tokuten[now]
		else:
			A[i] = now
			ans += Tokuten[now]

	# print(A)
	for i in range(K, N):
		if A[i]==A[i-K]:
			f = A[i+K]
			for j in range(3):
				if not j in [A[i],f]:
					A[i] = j
	# print(A)

	ans = 0
	for i in range(N):
		te = A[i]
		if te==0 and T[i]=='s':
			ans += Tokuten[0]
		elif te==1 and T[i]=='p':
			ans += Tokuten[1]
		elif te==2 and T[i]=='r':
			ans += Tokuten[2]

	print(ans)
	
if __name__ == '__main__':
	main()
Problem p02862 (python)

Fixed submission:
import math
import itertools
import sys

x, y = [int(x) for x in input().split()]

if (x+y) % 3:
  print(0)
  sys.exit()

total_move = (x+y) // 3
move_a = 2 * total_move - x

def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 #出力の制限
N = total_move
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

a = cmb(total_move,move_a,mod)

print(a)

Buggy submission (verdict: Runtime Error):
import math
import itertools

x, y = [int(x) for x in input().split()]

total_move = int((x+y) /3)
move_a = 2 * total_move - x

print(math.factorial(total_move) // (math.factorial(total_move - move_a) * math.factorial(move_a)))
Problem p02912 (python)

Fixed submission:
import sys
import heapq
sys.setrecursionlimit(10**6)
def MAP(): return [int(s) for s in input().split()]

if sys.platform =='ios':
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline

N, M = MAP()
# heapq.heappop（優先度『最小』の品物をO(logN)で取得）のため入力値をマイナスに変換
A = [int(s)*-1 for s in input().split()]

# 品物のリストをheapqのオブジェクトに変換
heapq.heapify(A)

while M > 0:
	# 以下、heapq　の計算誤差を防ぐため、(1) も (2) もそれぞれ -1 をかける
	# (1) 最小値を取り出す
	discount = heapq.heappop(A)*-1
	# (2) 最小値を2で切り捨て割ったものをAに戻す
	heapq.heappush(A, discount//2*-1)
	M -= 1

print(sum(A)*-1)

Buggy submission (verdict: Runtime Error):
import sys
import numpy as np
sys.setrecursionlimit(10**6)
def MAP(): return [int(s) for s in input().split()]

if sys.platform =='ios':
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline

N, M = MAP()
A = MAP()

while M > 0:
	A[np.argmax(A)] = A[np.argmax(A)] // 2
	M -= 1

print(sum(A))
Problem p03013 (python)

Fixed submission:
import sys
if sys.platform =='ios':
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline

N, M = map(int, input().split())
n = [True for _ in range(N+1)]
for _ in range(M):
	n[int(input())] = False

dp = [0 for _ in range(N+1)]
dp[0] = 1

for i in range(N+1):
	if not n[i]:
		continue
	for j in [1, 2]:
		if i - j >= 0:
			dp[i] += dp[i-j]
print(dp[-1]%1000000007)

Buggy submission (verdict: Runtime Error):
import sys
import numpy as np

if sys.platform =='ios':
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline

N, M = map(int, input().split())
a = np.array([int(input()) for _ in range(M)])

dp = np.array([0 for _ in range(N+1)])
dp[0] = 1

for i in range(N+1):
	if np.any(a == i):
		continue
	for j in [1, 2]:
		if i - j >= 0 and not np.any(a == i-j):
			dp[i] += dp[i-j]
print(dp[-1]%1000000007)
Problem p03038 (python)

Fixed submission:
import sys
from heapq import heapify, heappop
from operator import itemgetter

if sys.platform =='ios':
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return [int(s) for s in input().split()]

def main():
	N, M = MAP()
	A = MAP()
	BC = [MAP() for _ in range(M)]
	
	BC.sort(key= itemgetter(1), reverse=True)
	
	heapify(A)
	
	ans = 0
	
	fin = False
	for b, c in BC:
		#print(A, b, c)
		for _ in range(b):
			a = A[0]
			if a>c:
				fin = True
				break
			else:
				heappop(A)
				ans += c
				N -= 1
				if N == 0:
					fin = True
					break
		if fin:
			break
	
	print(ans+sum(A))

if __name__ == '__main__':
	main()

Buggy submission (verdict: Runtime Error):
import sys
from heapq import heapify, heappop
from operator import itemgetter

if sys.platform =='ios':
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return [int(s) for s in input().split()]

def main():
	N, M = MAP()
	A = MAP()
	BC = [MAP() for _ in range(M)]
	
	BC.sort(key= itemgetter(1), reverse=True)
	
	heapify(A)
	
	ans = 0
	
	fin = False
	for b, c in BC:
		#print(A, b, c)
		for _ in range(b):
			a = A[0]
			if a>c:
				fin = True
				break
			else:
				heappop(A)
				ans += c
		if fin:
			break
	
	print(ans+sum(A))

if __name__ == '__main__':
	main()
Problem p02570 (python)

Fixed submission:
d,t,s=map(int,input().split())
actualTime=d/s
 
if actualTime<=t:
  print('Yes')
else:
  print('No')

Buggy submission (verdict: Runtime Error):
d,t,s=map(int,input().split())
actualTime=d/s
 
if actualTime=<t:
  print('Yes')
else:
  print('No')
Problem p02629 (python)

Fixed submission:
n=int(input())
z=""
while n>0:
  n=n-1 ##for tracking last character
  z+= chr( n%26 + ord('a') )
  n=n//26
print(z[::-1])

Buggy submission (verdict: Runtime Error):
n=int(input())

while n>=0:
  n=n-1 ##for tracking last character
  z+= chr( n%26 + ord('a') )
  n=n//26
print(z[::-1])
Problem p02570 (python)

Fixed submission:
D,T,S=map(int,input().split())
if D/S<=T:
  print('Yes')
else:
  print('No')

Buggy submission (verdict: Runtime Error):
D,T,S=int(input().split())
if D/S=<T:
  print('Yes')
else:
  print('No')

Buggy submission (verdict: Runtime Error):
D,T,S=int(input().split())
if D/S<=T:
  print('Yes')
else:
  print('No')

Buggy submission (verdict: Runtime Error):
D,T,S=int(input().split())
if D/S<=T:
  print('Yes')
else:
  Print('No')
Problem p02577 (python)

Fixed submission:
N = int(input())
if N % 9 == 0:
  print('Yes')
else:
  print('No')

Buggy submission (verdict: Runtime Error):
def digitSum(n):
    # 桁数を判定する
    if len(str(n)) is 1:
        return n
    dst = sum(list(map(int, str(n))))
    return digitSum(dst)


if __name__ == "__main__":
  n = N
  result = digitSum(n)

    print(int(result))
Problem p02860 (python)

Fixed submission:
n=int(input())
s=str(input())
r=s[:n//2]
t=s[n//2:]
if(r==t):
  print("Yes")
else:
  print("No")

Buggy submission (verdict: Runtime Error):
n=int(input())
s=str(input())
r=s[:(n/2)]
t=s[(n/2):]
if(r==t):
  print("Yes")
else:
  print("No")

Buggy submission (verdict: Runtime Error):
n=int(input())
s=str(input())
if(n%2==0):
  r=s[:(n/2)]
  t=s[(n/2):]
  if(r==t):
    print("Yes")
  else:
    print("No")
    
else:
  print("No")
Problem p02627 (python)

Fixed submission:
str=str(input())
if str.isupper():
	print("A")
else:
	print("a")

Buggy submission (verdict: Runtime Error):
str=str(input())
if str.isupper():
	print("A")
else
	print("a")
Problem p02682 (python)

Fixed submission:
A, B, C, K = map(int, input().split())
if K<=A:
    print(K)
elif A<K<=A+B:
    print(A)
else:
    print(A-(K-A-B))

Buggy submission (verdict: Runtime Error):
A, B, C, K = int(input().split())
if K<=A:
    print(K)
elif A<K<=A+B:
    print(A)
else:
    print(A-(K-A-B))
Problem p02688 (python)

Fixed submission:
Sunuke=[]

N, K = map(int, input().split()) 
for i in range(K):
    d = int(input())
    A = list(map(int, input().split()))

    Sunuke.extend(A)

print(N-(len(set(Sunuke))))

Buggy submission (verdict: Runtime Error):
N,K= map(int, input().split())

A=[]

for i range(K):
    d = int(input())
    A[i] = [int(x) for x in input().split()]

print(3)

Buggy submission (verdict: Runtime Error):
N,K= map(int, input().split())

A=[]

for i range(K)
    d = int(input())
    A[i] = [int(x) for x in input().split()]

print("A")
Problem p02881 (python)

Fixed submission:
n=int(input())

ans=10**12
d=2
while d<=n**(1/2):
    if n%d==0:
        ans=min(ans,d+n//d-2)
    d+=1
if ans==10**12:
    print(n-1)
    exit()
print(ans)

Buggy submission (verdict: Runtime Error):
n=int(input())
import numpy
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

pri_fact=prime_factorize(n)

def prod(x):
    kotae=1
    for i in x:
        kotae*=i
    return kotae

ans=10**12
for i in range(len(pri_fact)):
    ans=min((prod(pri_fact[0:i])-1)+(prod(pri_fact[i:])-1),ans)

print(int(ans))
Problem p03013 (python)

Fixed submission:
n,m=map(int, input().split())
a=[False]*(n+1)
for i in range(m):
    A=int(input())
    a[A]=True
mod=10**9+7
dp=[0]*(n+1)

if not a[1]:
    dp[1]=1

if n>1:
    if not a[2]:
        dp[2]=dp[1]+1

for i in range(3,n+1):
    if not a[i-2]:
        dp[i]+=dp[i-2]
        dp[i]%=mod
    if not a[i-1]:
        dp[i]+=dp[i-1]
        dp[i]%=mod
    if a[i]:
        dp[i]=0

print(dp[n]%mod)

Buggy submission (verdict: Runtime Error):
n,m=map(int, input().split())
a=[False]*(n+1)
for i in range(m):
    A=int(input())
    a[A]=True
mod=10**9+7
dp=[0]*(n+1)

if not a[1]:
    dp[1]=1

if not a[2]:
    dp[2]=dp[1]+1

for i in range(3,n+1):
    if not a[i-2]:
        dp[i]+=dp[i-2]
        dp[i]%=mod
    if not a[i-1]:
        dp[i]+=dp[i-1]
        dp[i]%=mod
    if a[i]:
        dp[i]=0

print(dp[n]%mod)

Buggy submission (verdict: Runtime Error):
n,m=map(int, input().split())
a=[False]*(n+1)
for i in range(m):
    A=int(input())
    a[A]=True
mod=10**9+7
dp=[0]*(n+1)

if not a[1]:
    dp[1]=1

if not a[2]:
    dp[2]=dp[1]+1

for i in range(3,n+1):
    if not a[i-2]:
        dp[i]+=dp[i-2]
        dp[i]%=mod
    if not a[i-1]:
        dp[i]+=dp[i-1]
        dp[i]%=mod
    if a[i]:
        dp[i]=0

print(dp[n]%mod)
Problem p03038 (python)

Fixed submission:
n,m=map(int, input().split())
a=list(map(int, input().split()))
bc_list=[]
for i in range(m):
    b,c=map(int, input().split())
    bc_list.append([b,c])

a.sort()
import operator
bc_list.sort(key=operator.itemgetter(1),reverse=True)

s=0

ans=0
for i in range(m):
    for j in range(s,s+bc_list[i][0]):
        if j>=n:
            break
        if a[j]<bc_list[i][1]:
            ans+=bc_list[i][1]
            s+=1
        else:
            break

for i in range(s,n):
    ans+=a[i]
print(ans)

Buggy submission (verdict: Runtime Error):
a
Problem p03208 (python)

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

list2=list()
h.sort()

for i in range(N-K+1):
    list2.append(h[i+K-1]-h[i])
    continue
print(min(list2))

Buggy submission (verdict: Runtime Error):
N,K = int(input().split())
h = [int(input()) for i in range(N)]
 
 
list2=list()
 
h.sort()
 
for i in range(N-K):
    list2.append(h[i+K]-h[i+1])
    continue
print(min(list2))

Buggy submission (verdict: Runtime Error):
K,N = int(input().split())
h = [int(input()) for i in range(N)]


list2=list()

h.sort()

for i in range(N-K):
    list2.append(h[i+K]-h[i+1])
    continue
print(min(list2))
Problem p03077 (python)

Fixed submission:
N = int(input())
A = [0 for i in range(5)]
for i in range(5):
    A[i] = int(input())

if N % min(A) != 0:
    print(N // min(A) + 5)
else:
    print(N // min(A) + 4)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = [0 for i in range(5)]
for i in range(5):
    A[i] = int(input())

if N % min(A) != 0:
    print(N // min(A) + 5)
else
    print(N // min(A) + 4)
Problem p03209 (python)

Fixed submission:
def patty_num(N):
    if N == 0:
        return 1
    return 1 + 2 * patty_num(N - 1)

def burger_height(N):
    if N == 0:
        return 1
    else:
        return 3 + 2 * burger_height(N - 1)
    
def f(N, X):
    if X == 1:
        if N == 0:
            return 1
        else:
            return 0
    elif 1 < X and X <= burger_height(N - 1) + 1:
        return f(N - 1, X - 1)
    elif X == burger_height(N - 1) + 2:
        return patty_num(N - 1) + 1
    elif burger_height(N - 1) + 2 < X and X <= 2 * burger_height(N - 1) + 2:
        return patty_num(N - 1) + 1 + f(N - 1, X - 2 - burger_height(N - 1))
    
    return 2 * patty_num(N - 1) + 1
    
N, X = map(int, input().split())
print(f(N, X))

Buggy submission (verdict: Runtime Error):
def burger_size(N):
    if N == 0:
        return 1
    return 3 + 2 * burger_size(N - 1)

def burger_patty_num(N):
    if N == 0:
        return 1
    return 1+ 2 * burger_patty_num(N - 1)

def patty_num(N, X):
    if X == 0:
        return 0
    if X <= 1 + burger_size(N - 1):
        return patty_num(N - 1, X - 1)
    elif X == 2 + burger_size(N - 1):
        return 1 + burger_patty_num(N - 1)
    elif X <= 2 + 2 * burger_size(N - 1):
        return 1 + burger_patty_num(N - 1) + patty_num(N - 1, X - (2 + burger_size(N - 1)))
    else:
        return 1 + 2 * burger_patty_num(N - 1)
        
    
N, X = map(int, input().split())
print(patty_num(N, X))

Buggy submission (verdict: Runtime Error):
def burger_size(N):
    if N == 0:
        return 1
    return 3 + 2 * burger_size(N - 1)

def burger_patty_num(N):
    if N == 0:
        return 1
    return 1+ 2 * burger_patty_num(N - 1)

def patty_num(N, X):
    if X == 0:
        return 0
    if X <= 1 + burger_size(N - 1):
        return patty_num(N - 1, X - 1)
    elif X == 2 + burger_size(N - 1):
        return 1 + burger_patty_num(N - 1)
    elif X > 2 + burger_size(N - 1):
        return 1 + burger_patty_num(N - 1) + patty_num(N - 1, X - (2 + burger_size(N - 1)))
        
    
N, X = map(int, input().split())
print(patty_num(N, X))
Problem p03307 (python)

Fixed submission:
N = int(input())
if N % 2 == 0:
    print(N)
else:
    print(2 *N)

Buggy submission (verdict: Runtime Error):
if N % 2 == 0:
    print(N)
else:
    print(N)
Problem p03617 (python)

Fixed submission:
Q, H, S, D = map(int, input().split())
N = int(input())

most_bargain = min(8 * Q, 4 * H, 2 * S, D)
if most_bargain != D:
    print((most_bargain // 2) * N)
else:
    if N % 2 == 0:
        print((N // 2) * D)
    else:
        print((N // 2) * D + min(4 * Q, 2 * H, S))

Buggy submission (verdict: Runtime Error):
Q, H, S, D = map(int, input().split())
N = int(input())

most_bargain = min(8 * Q, 4 * H, 2 * S, D)
if most_bargain != D:
    print((most_bargain // 2) * N)
else:
    if N % 2 == 0:
        print((N // 2) * D)
    else:
        print((N // 2) * D + min(4 * Q, 2 * H, S))5410760474836152
1524157763907942
Problem p03774 (python)

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

a = [0 for i in range(N)]
b = [0 for i in range(N)]
c = [0 for i in range(M)]
d = [0 for i in range(M)]

for i in range(N):
    a[i], b[i] = map(int, input().split())
for i in range(M):
    c[i], d[i] = map(int, input().split())
    
for i in range(N):
    closest_ind = -1
    closest_dist = 10000000000
    for j in range(M):
        if closest_dist > abs(a[i] - c[j]) + abs(b[i] - d[j]):
            closest_ind = j
            closest_dist = abs(a[i] - c[j]) + abs(b[i] - d[j])
    print(closest_ind + 1)

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())

a = [0 for i in range(N)]
b = [0 for i in range(N)]
c = [0 for i in range(N)]
d = [0 for i in range(N)]

for i in range(N):
    a[i], b[i] = map(int, input().split())
for i in range(M):
    c[i], d[i] = map(int, input().split())
    
for i in range(N):
    closest_ind = -1
    closest_dist = 10000000000
    for j in range(M):
        if closest_dist > abs(a[i] - c[j]) + abs(b[i] - d[j]):
            closest_ind = j
            closest_dist = abs(a[i] - c[j]) + abs(b[i] - d[j])
    print(closest_ind + 1)
Problem p02596 (python)

Fixed submission:
k = int(input())
c = 0
t = 7%k
a = [t]*(k+1)

if k%2 == 0 or k%5 == 0:
	print('-1')
elif 7%k == 0:
	print('1')
else:
	for i in range(1,k):
		c += 1
		a[i+1] = (10*a[i] + 7)%k
		if a[i+1] == 0:
			break
	print(c + 1)

Buggy submission (verdict: Runtime Error):
k = int(input())
c = 0
a = [0]*(k+1)
a[0] = 7%k

if k%2 == 0 or k%5 == 0:
	print('-1')
else:
	for i in range(1,k+1):
		c += 1 
		a[i+1] = (10*a[i] + 7)%k
		if a[i+1] == 0:
			break
	print(c)