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

Fixed submission:

# from math import gcd
from fractions import gcd
from functools import reduce


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

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

l=reduce(lcm,A)
    
ans=0
for i in range(N):
    ans+=l//A[i]

print(ans%(10**9+7))

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


def lcm(x,y):
    pre_x=x
    pre_y=y
    if x<y:
        x,y=y,x
    while x%y !=0:
        x,y=y,x%y
    
    return pre_x*pre_y//y

thr=1

l=lcm(A[0],A[1])

for i in range(2,N):
    l=lcm(l,A[i])
    
ans=0
for i in range(N):
    ans+=l//A[i]

print(ans%(10**9+7))
Problem p02819 (python)

Fixed submission:
import math
 

def is_prime(n):
    if n == 1: return False

    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return False

    return True


X=int(input())
judge=not is_prime(X)
while judge:
    X+=1
    judge=not is_prime(X)
    
print(X)

Buggy submission (verdict: Runtime Error):
from sympy import isprime


i=int(input())
judge=not isprime(i)
while judge:
    i+=1
    judge=not isprime(i)
print(i)
Problem p03077 (python)

Fixed submission:
def solve(n, traffic_list):
    min_val = min(traffic_list)
    if n % min_val == 0:
        return n // min_val + len(traffic_list) - 1
    else:
        return n // min_val + len(traffic_list)


def main():
    n = int(input())
    a = int(input())
    b = int(input())
    c = int(input())
    d = int(input())
    e = int(input())

    ans = solve(n, [a, b, c, d, e])
    print(ans)


main()

Buggy submission (verdict: Runtime Error):
def solve(n, traffic_list):
    min_val = min(traffic_list)
	if n % min_val == 0:
        return n // min_val + len(traffic_list) - 1
    else:
        return n // min_val + len(traffic_list)


def main():
    n = int(input())
    a = int(input())
    b = int(input())
    c = int(input())
    d = int(input())
    e = int(input())

    ans = solve(n, [a, b, c, d, e])
    print(ans)


main()
Problem p02831 (python)

Fixed submission:
import fractions

a,b = map(int,input().split())
print(a*b//fractions.gcd(a,b))

Buggy submission (verdict: Runtime Error):
import math
a,b = map(int,input().split())
 
print(a*b//math.gcd(a,b))

Buggy submission (verdict: Runtime Error):
import math
a,b = map(int,input().split())

print(a*b/math.gcd(a,b))
Problem p02860 (python)

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

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

if [:n] == [n:]:
  print("Yes")
else:
  print("No")

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

if n%2 == 0:
  for i in range(len(s)/2):
    if s[i] == s[-1-i]:
      cnt += 1
  if n/2 == cnt:
    print("Yes")
  else:
    print("No")
else:
  print("No")
Problem p02785 (python)

Fixed submission:
N, K = map(int, input().split())
H = list(map(int, input().split()))
if N <= K:
  print(0)
elif K == 0:
  print(sum(H))
else:
  H = sorted(H)
  print(sum(H[:-K]))

Buggy submission (verdict: Runtime Error):
N, K = map(int, input().split())
H = list(map(int, input().split()))
if N <= K:
  print(0)
elif K == 0:
  print(sum(H))
else:
  H = sort(H)
  print(sum(H[:-K]))

Buggy submission (verdict: Runtime Error):
N, K = map(int, input().split())
H = list(map(int, input().split()))
H = sort(H)
print(sum(H[:-K]))
Problem p02880 (python)

Fixed submission:
N=int(input())
if N%2==0 and N/2<10:
    print('Yes')
elif N%3==0 and N/3<10:
    print('Yes')
elif N%4==0 and N/4<10:
    print('Yes')
elif N%5==0 and N/5<10:
    print('Yes')
elif N%6==0 and N/6<10:
    print('Yes')
elif N%7==0 and N/7<10:
    print('Yes')
elif N%8==0 and N/8<10:
    print('Yes')
elif N%9==0 and N/9<10:
    print('Yes')
elif N==1:
    print('Yes')
else:
    print('No')

Buggy submission (verdict: Runtime Error):
N=int(input())
for i in range(9):
  if (N%i)==0 and N/i<10:
    print('Yes')
  else:
    print('No')
Problem p02862 (python)

Fixed submission:
def xgcd(a, b):
    x0, y0, x1, y1 = 1, 0, 0, 1
    while b != 0:
        q, a, b = a // b, b, a % b
        x0, x1 = x1, x0 - q * x1
        y0, y1 = y1, y0 - q * y1
    return a, x0, y0
  
def modinv(a, m):
    g, x, y = xgcd(a, m)
    if g != 1:
        raise Exception('modular inverse does not exist')
    else:
        return x % m
x, y = map(int, input().split())
inf = 10**9+7
if (x+y)%3 > 0:
  print(0)
else:
  n = (x+y)//3
  c = [1 for i in range(n+1)]
  invc = [1 for i in range(n+1)]
  for i in range(1, n+1):
    c[i] = c[i-1]*i % inf
    invc[i] = modinv(c[i], inf)
  cnt=-1
  for i in range(n+1):
    if (i+2*(n-i)==x)&(2*i+(n-i)==y):
      cnt = i
      break
  if cnt < 0:
    ans = 0
  else:
    ans = (c[n] * invc[cnt] * invc[n-cnt]) % inf
  print(ans)

Buggy submission (verdict: Runtime Error):

    def xgcd(a, b):
    x0, y0, x1, y1 = 1, 0, 0, 1
    while b != 0:
        q, a, b = a // b, b, a % b
        x0, x1 = x1, x0 - q * x1
        y0, y1 = y1, y0 - q * y1
    return a, x0, y0

def modinv(a, m):
    g, x, y = xgcd(a, m)
    if g != 1:
        raise Exception('modular inverse does not exist')
    else:
        return x % m

x, y = map(int, input().split())
inf = 10**9+7
if (x+y)%3 > 0:
  print(0)
else:
  n = (x+y)//3
  c = [1 for i in range(n+1)]
  invc = [1 for i in range(n+1)]
  for i in range(1, n+1):
    c[i] = c[i-1]*i % inf
    invc[i] = modinv(c[i], inf)
  cnt=-1
  for i in range(n+1):
    if (i+2*(n-i)==x)&(2*i+(n-i)==y):
      cnt = i
      break
  if cnt < 0:
    ans = 0
  else:
    ans = (c[n] * invc[cnt] * invc[n-cnt]) % inf
  print(ans)
Problem p02881 (python)

Fixed submission:
n = int(input())
cost = []
i = 2
while i <= n**0.5:
  if n % i == 0:
    cost.append(i+n/i-2)
  i += 1
if len(cost) == 0:
  cost.append(n-1)
print(int(min(cost)))

Buggy submission (verdict: Runtime Error):
n = int(input())
cost = []
i = 2
while i =< n**0.5:
  if n % i == 0:
    cost.append(i+n/i-2)
  i += 1
if len(cost) == 0:
  cost.append(n-1)
print(int(min(cost)))
Problem p02915 (python)

Fixed submission:
n = int(input())
print(n**3)

Buggy submission (verdict: Runtime Error):
n = input()
print(N**3)
Problem p02916 (python)

Fixed submission:
n = int(input())
a_list = list(map(int, input().split()))
b_list = list(map(int, input().split()))
c_list = list(map(int, input().split()))

ans = 0
prev = -1
for i in range(n):
  if a_list[i] == prev + 1:
    ans += b_list[a_list[i] - 1] + c_list[prev - 1]
  else:
    ans += b_list[a_list[i] - 1]
  prev = a_list[i]
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
a_list = list(map(int, input().split()))
b_list = list(map(int, input().split()))
c_list = list(map(int, input().split()))

ans = 0
prev = 0
for i in range(n):
  if a_list[i] == prev + 1:
    ans += b_list[i] + c_list[i]
  else:
    ans += b_list[i]
  prev = a_list[i]
print(ans)
Problem p02820 (python)

Fixed submission:
N, K = map(int, input().split())
R, S, P = map(int, input().split())
T = list(input())
r, s, p = 0,0,0
for i in range(N):
	if i-K >= 0 and T[i-K] == T[i]:
		T[i] = None
	elif T[i] == 'r':
		p += 1
	elif T[i] == 's':
		r += 1
	elif T[i] == 'p':
		s += 1
print(r*R+s*S+p*P)

Buggy submission (verdict: Runtime Error):
N, K = map(int, input().split())
R, S, P = map(int, input().split())
T = list(input())
ro, si, pa = 0,0,0
rp, sp, pp = 0,0,0
for t in range(len(T)):
	if T[t] == 'r':
		pa += 1
		if (t - K >= 0 and T[t-K] == 'r') and (t+K>N or(t+K<=N and T[t+K] != 'r')):
			pp += 1
	if T[t] == 's':
		ro += 1
		if (t - K >= 0 and T[t-K] == 's') and (t+K>N or(t+K<=N and T[t+K] != 's')):
			rp += 1
	if T[t] == 'p':
		si += 1
		if (t - K >= 0 and T[t-K] == 'p') and (t+K>N or(t+K<=N and T[t+K] != 'p')):
			sp += 1
s_r = (ro-rp)*R
s_s = (si-sp)*S
s_p = (pa-pp)*P
print(s_r+s_s+s_p)
Problem p02880 (python)

Fixed submission:
N = int(input())
ans = 'No'
for i in range(1,10):
	for j in range(1,10):
		if i*j == N:
			
			ans = 'Yes'
print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
S = input()
li = list(S)
n = int(len(li)/2)
half_li = list()
for i in range(n):
	half_li.append(li[i])
T = ''.join(half_li)
if S == T*2:
	print('Yes')
else:
	print('No')
Problem p02935 (python)

Fixed submission:
N = int(input())
li = list(map(int, input().split()))
sli = sorted(li)
temp = sli[0]
for i in range(N-1):
    temp = (temp+sli[i+1])/2
print(temp)

Buggy submission (verdict: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

int main(){
	int N;
	cin >> N;
	vector<int> vec(N);
	for(int i=0;i<N;i++){
		cin >> vec.at(i);
	}
	sort(vec.begin(), vec.end());
	double ans = vec.at(0);
	for(int i=1;i<N;i++){
		ans = (ans+vec.at(i))/2;
	}
	cout << ans << endl;
}

Buggy submission (verdict: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

int main(){
	int N;
	cin >> N;
	vector<int> vec(N);
	for(int i=0;i<N;i++){
		cin >> vec.at(i);
	}
	sort(vec.begin(), vec.end());
	double ans = vec.at(0);
	for(int i=1;i<N;i++){
		ans = (ans+vec.at(i))/2;
	}
	cout << ans << endl;
}
Problem p02790 (python)

Fixed submission:
a,b=map(int,input().split())
s=[]
s.append(str(a)*b)
s.append(str(b)*a)
s.sort()
print(s[0])

Buggy submission (verdict: Runtime Error):
a,b=map(int,input().split())
s.append(str(a)*b)
s.append(str(b)*a)
s.sort()
print(s[0])
Problem p02970 (python)

Fixed submission:
N, D = map(int,input().split())
a = N//(2*D+1)
if N%(2*D+1)==0:
  print(a)
else:
  print(a+1)

Buggy submission (verdict: Runtime Error):
N, D = map(int,input().split())
a = N//(2D+1)
if N%(2D+1)==0:
  print(a)
else:
  print(a+1)
Problem p02987 (python)

Fixed submission:
S = list(input())
S.sort()
if S[0]==S[1] and S[2]==S[3] and S[0]!=S[2]:
  print("Yes")
else:
  print("No")

Buggy submission (verdict: Runtime Error):
S = input()
S.sort()
if S[0]==S[1] and S[2]==S[3] and S[0]!=S[2]:
  print("Yes")
else:
  print("No")
Problem p02785 (python)

Fixed submission:
n, k = map(int, input().split())
hp_list = list(map(int, input().split()))
hp_list.sort()

attack = 0
for i, hp in enumerate(reversed(hp_list)):
  if i < k:
    continue
  attack += hp
print(attack)

Buggy submission (verdict: Runtime Error):
n, k = map(int, input().split())
hp_list = list(map(int, input().split()))
hp_list.sort()

attack = 0
for i, hp in enumurate(reversed(hp_list)):
  if i < k:
    continue
  attack += hp
print(attack)
Problem p03803 (python)

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

if (A==1 and B!=1):
    print("Alice")
    exit()
elif(B==1 and A!=1):
    print("Bob")   
    exit()




if (A>B):
    print("Alice")
elif(A<B):
    print("Bob")
elif(A==B):
    print("Draw")

Buggy submission (verdict: Runtime Error):
A,B = map(int,input().split())

if (A==1 and B!=1):
    print("Alice")
    exit()
 elif(B==1 and A!=1):
     print("Bob")   
   




if (A>B):
    print("Alice")
elif(A<B):
    print("Bob")
elif(A==B):
    print("Draw")

Buggy submission (verdict: Runtime Error):
A,B = map(int,input().split())

if (A==1 and B!=1):
    print("Alice")
    exit()
 elif(B==1 and A!=1):
     print("Bob")   
   




if (A>B):
    print("Alice")
elif(A<B):
    print("Bob")
elif(A==B):
    print("Draw")

Buggy submission (verdict: Runtime Error):
A,B = map(int,input().split())

if (A=1 and B!=1):
    print("Alice")
    
   




if (A>B):
    print("Alice")
elif(A<B):
    print("Bob")
elif(A==B):
    print("Draw")
Problem p03107 (python)

Fixed submission:
S = input()

red = 0  # 0
blue = 0 # 1
m = 0
for s in S:
	if s == '0':
		if blue != 0:
			blue -= 1
			m += 2
		else:
			red += 1
	elif s == '1':
		if red != 0:
			red -= 1
			m += 2
		else:
			blue += 1

print(m)

Buggy submission (verdict: Runtime Error):
S = input()

red = 0  # 0
blue = 0 # 1
m = 0
for s in S:
	if s = '0':
		if blue != 0:
			blue -= 1
			m += 2
		else:
			red += 1
	elif s = '1':
		if red != 0:
			red -= 1
			m += 2
		else:
			blue += 1

print(m)
Problem p03135 (python)

Fixed submission:
T, X = map(int, input().split())
print(T/X)

Buggy submission (verdict: Runtime Error):
a

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

k = [(K+1)&(1<<i) for i in range(40)]

c = [0]*40
for a in A:
	for i in range(40):
		if a&(1<<i):
			c[i] += 1

m = [0]*40
for i in range(40):
	if 2*c[i]<N:
		m[i] = (1<<i)*(N-c[i])
	else:
		m[i] = (1<<i)*c[i]

x = sum(A)
for i in reversed(range(40)):
	if k[i] != 0:
		x = max(x, sum(m[:i]+[(1<<i)*(N-c[i])]+k[i+1:]))

print(x)
Problem p03137 (python)

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

X.sort()
diffX = list(map(lambda x,y:x-y, X[1:], X[:-1]))
diffX.sort(reverse = True)

if N-1 >= len(diffX):
	print(0)
else:
	print(sum(diffX[N-1:]))

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

Y = sorted(X)
Y = list(map(lambda x,y:x-y, Y[1:],Y[:-1]))

for i in range(N-1):
	x = max(Y)
	Y.remove(x)

print(sum(Y))
Problem p02785 (python)

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

H_list.sort(reverse = True)

del H_list[0:K]

print(sum(H_list))

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

H_list.sort(reverse = True)

for i in range(K):
  del H_list[i]

print(sum(H_list))
Problem p03329 (python)

Fixed submission:
N=int(input())
def cou(n,x):
    i=0
    while(n>0):
        i+=n%x
        n//=x
    return i
ans=N
for j in range(N+1):
    ans=min(ans,cou(j,6)+cou(N-j,9))
print(ans)

Buggy submission (verdict: Runtime Error):
N=int(input())
def cou(n,x):
    i=0
    while(n>0):
        i+=n%x
        n//=x
    return i
ans=N
for i in range(N+1):
    ans=min(ans,cou(j,6)+cou(N-j,9))
print(ans)
Problem p02829 (python)

Fixed submission:
A = int(input())
B = int(input())
print(6 - A - B)

Buggy submission (verdict: Runtime Error):
A = input()
B = input()        
print(6 - A - B)

Buggy submission (verdict: Runtime Error):
A = input()
B = input()

ans = ['1', '2', '3']

for i in range(len(ans)):
  if ans[i] == A or ans[i] == B:
    del ans[i]
    
print(ans[0])

Buggy submission (verdict: Runtime Error):
A = input()
B = input()

ans = ['1', '2', '3']

for i in range(len(ans)):
  if ans[i] == A or ans[i] == B:
    del ans[i]
    
print(nas[0])

Buggy submission (verdict: Runtime Error):
A = input()
B = input()

ans = ['1', '2', '3']

for i in range(len(ans)):
  if ans[i] == A or ans[i] = B:
    del ans[i]
    
print(nas[0])
Problem p03327 (python)

Fixed submission:
N = int(input())

if N < 1000:
  print("ABC")
else:
  print("ABD")

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

if N < 1000:
  print("ABC" + N)
else:
  print("ABD" + (N - 999))
Problem p02847 (python)

Fixed submission:
D = {"SUN": 7, "MON": 6, "TUE": 5, "WED": 4, "THU": 3, "FRI": 2, "SAT": 1}
print(D[input()])

Buggy submission (verdict: Runtime Error):
D = {"SUN": 7, "MON": 6, "TUE": 5, "WED": 4, "THU": 3, "FRI": 2, "SUT": 1}
print(D[input()])
Problem p02970 (python)

Fixed submission:
N, D = map(int, input().split())
if N%(D*2+1)==0:
    print(N//(D*2+1))
else:
    print(N//(D*2+1)+1)

Buggy submission (verdict: Runtime Error):
N, D = map(int, input().split())
print(N//(D*2+1)+1)N, D = map(int, input().split())
print(-(-N//(D*2+1)))
Problem p02970 (python)

Fixed submission:
N,D=map(int,input().split())
people=N/(2*D+1)
if N % (2*D+1) == 0:
    print(int(people))
else:
    print(int(people)+1)

Buggy submission (verdict: Runtime Error):
N,D=map(int,input().split())
people=N/(2D+1)
if people%2==O:
    print(int(people))
else:
    print(int(people)+1)
Problem p03307 (python)

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

Buggy submission (verdict: Runtime Error):
N=int(input())
if N%2=0:
    ans=N
else:
    ans=N*2
print(ans)
Problem p02835 (python)

Fixed submission:
a,b,c = map(int, input().split())
if(a +b+c >= 22):
  print("bust")
else:
  print("win")

Buggy submission (verdict: Runtime Error):
a,b,c = int(input().split())
if(a+b+c >= 22):
  print("bust")
else:
  print("win")
Problem p02847 (python)

Fixed submission:
print(7 - ['SUN', 'MON', 'TUE', 'WED', 'THU', 'FRI', 'SAT'].index(input()))

Buggy submission (verdict: Runtime Error):
print(7 - ['SUN', 'MUN', 'TUE', 'WED', 'THU', 'FRI', 'SAT'].index(input()))

Buggy submission (verdict: Runtime Error):
l = ['SUN', 'MUN', 'TUE', 'WED', 'THU', 'FRI', 'SAT'];print(len(l) - l.index(input()))
Problem p03208 (python)

Fixed submission:
N, K = map(int, input().split())
tree = [int(input()) for n in range(N)]
diff = 10 ** 9
tree.sort()
for i in range(N - (K - 1)):
    if tree[i] == tree[i + 1] == tree[i + 2]:
        diff = 0
        break
    elif tree[i + K - 1] - tree[i] < diff:
        diff = tree[i + K - 1] - tree[i]
print(diff)

Buggy submission (verdict: Runtime Error):
N, K = map(int, input().split())
tree = []
diff = 10 ** 9
for n in range(N):
    tree.append(int(input()))
tree.sort()
for i in range(N - (K - 1)):
    print(tree[i], tree[i + 1], tree[i + 2])
    if tree[i + K - 1] - tree[i] < diff:
        diff = tree[i + K - 1] - tree[i]
print(diff)
Problem p02829 (python)

Fixed submission:
A = int(input())
B = int(input())
print(A ^ B)

Buggy submission (verdict: Runtime Error):
A, B = map(int, input().split())
print(A ^ B)
Problem p02933 (python)

Fixed submission:
A = int(input())
S = str(input())
if A >= 3200:print(S)
else: print("red")

Buggy submission (verdict: Runtime Error):
A = int(input())
S = str(input())
if A >= 3200:print(S)
else print("red")
Problem p03038 (python)

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

cb = {}
for i in range(M):
    b, c = map(int, input().split())
    if cb.get(c) is None:
        cb[c] = b
    else:
        cb[c] += b

a_ind = 0
for c in sorted(cb.keys(), reverse=True):
    flg = 0
    for b in range(cb[c]):
        if c < A[a_ind]:
            flg = 1
            break
        else:
            A[a_ind] = c
            a_ind += 1
            if a_ind == N:
                flg = 1
                break
    if flg:
        break
print(sum(A))

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

cb = {}
for i in range(M):
    b, c = map(int, input().split())
    if cb.get(c) is None:
        cb[c] = b
    else:
        cb[c] += b

a_ind = 0
for c in sorted(cb.keys(), reverse=True):
    flg = 0
    for b in range(cb[c]):
        if c < A[a_ind]:
            flg = 1
            break
        else:
            A[a_ind] = c
            a_ind += 1
    if flg:
        break
print(sum(A))
Problem p03137 (python)

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

if N >= M:
    print(0)
else:
    sub_X = []
    for i in range(0, M - 1):
        sub_X.append((i, abs(X[i+1] - X[i])))
    sub_X.sort(key=lambda x: x[1], reverse=True)

    division = set()
    if len(sub_X) != 0:
        for i in range(N-1):
            division.add(sub_X[i][0])
    ans = 0
    start = X[0]
    for i in range(M):
        if i in division:
            ans += X[i] - start
            start = X[i+1]
        if i == M-1:
            ans += X[i] - start

    print(ans)

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

sub_X = []
for i in range(0, M - 1):
    sub_X.append((i, abs(X[i+1] - X[i])))
sub_X.sort(key=lambda x: x[1], reverse=True)

division = set()
if len(sub_X) != 0:
    for i in range(N-1):
        division.add(sub_X[i][0])

ans = 0
start = X[0]
for i in range(M):
    if i in division:
        ans += X[i] - start
        start = X[i+1]
    if i == M-1:
        ans += X[i] - start

print(ans)
Problem p03209 (python)

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


def search(level, eat_num):
    if level == 0:
        if eat_num <= 0:
            return 0
        else:
            return 1

    elif eat_num == 1:
        return 0

    elif 1 < eat_num <= pow(2, level + 1) - 2:
        return search(level - 1, eat_num - 1)

    elif eat_num == pow(2, level + 1) - 1:
        return pow(2, level)

    elif pow(2, level + 1) - 1 < eat_num <= pow(2, level + 2):
        return pow(2, level) + search(level - 1, eat_num - (pow(2, level + 1) - 1))

    elif X == pow(2, level + 2) + 1:
        return pow(2, level + 1) - 1

    else:
        return pow(2, level + 1) - 1


print(search(level=N, eat_num=X))

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


def search(level, eat_num):
    if eat_num == 0:
        if eat_num <= 0:
            return 0
        else:
            return 1

    elif eat_num == 1:
        return 0

    elif 1 < eat_num <= pow(2, level + 1) - 2:
        return search(level - 1, eat_num - 1)

    elif eat_num == pow(2, level + 1) - 1:
        return pow(2, level)

    elif pow(2, level + 1) - 1 < eat_num <= pow(2, level + 2):
        return pow(2, level) + search(level - 1, eat_num - (pow(2, level + 1) - 1))

    elif X == pow(2, level + 2) + 1:
        return pow(2, level + 1) - 1

    else:
        print('out', X)

print(search(level=N, eat_num=X))

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


def search(level, eat_num):
    if eat_num == 0:
        return 1

    elif eat_num == 1:
        return 0

    elif 1 < eat_num <= pow(2, level + 1) - 2:
        return search(level - 1, eat_num - 1)

    elif eat_num == pow(2, level + 1) - 1:
        return pow(2, level)

    elif pow(2, level + 1) - 1 < eat_num <= pow(2, level + 2):
        return pow(2, level) + search(level - 1, eat_num - (pow(2, level + 1) - 1))

    elif X == pow(2, level + 2) + 1:
        return pow(2, level + 1) - 1

    else:
        print('out', X)


print(search(level=N, eat_num=X))
Problem p03250 (python)

Fixed submission:
nums = list(map(int, input().split()))
nums.sort()
print(nums[2] * 10 + nums[1] + nums[0])

Buggy submission (verdict: Runtime Error):
nums = list(map(int, input().split()))
nums.sort()
print(nums[2] * 10 + num[1] + num[0])
Problem p03307 (python)

Fixed submission:
N = int(input())

if N % 2 == 0:
    print(N)
else:
    print(2*N)

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

A_sorted = sorted([A[i] - (i+1) for i in range(N)])
b = A_sorted[int((len(A)-1)/2)]
b2 = A_sorted[int((len(A)-1)/2 + 1)]

sad_1 = sum([abs(A_sorted[i] - b) for i in range(N)])
sad_2 = sum([abs(A_sorted[i] - b2) for i in range(N)])

print(min(sad_1, sad_2))

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

# res = 0
# for i in range(N):
#     res += A[i] - (i+1)
# b = res // N
# print(res, b)
A_sorted = sorted([A[i] - (i+1) for i in range(N)])
b = A_sorted[int((len(A)-1)/2)]
b2 = A_sorted[int((len(A)-1)/2 + 1)]

print(A_sorted, b, b2)
sad_1 = sum([abs(A_sorted[i] - b) for i in range(N)])
sad_2 = sum([abs(A_sorted[i] - b2) for i in range(N)])

print(min(sad_1, sad_2))

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

# res = 0
# for i in range(N):
#     res += A[i] - (i+1)
# b = res // N
# print(res, b)
A_sorted = sorted(A)
b = A_sorted[int((len(A)-1)/2)]
b2 = A_sorted[int((len(A)-1)/2 + 1)]

sadness_1 = sum([abs(A[i] - b) for i in range(N)])
sadness_2 = sum([abs(A[i] - b2) for i in range(N)])

print(min(sadness_1, sadness_2))
Problem p03346 (python)

Fixed submission:
N = int(input())
Q = [0]*N
for i in range(N):
        Q[int(input())-1] = i

subset_num = num = 0
for i in range(N-1):
    num += 1
    if Q[i] > Q[i+1]:
        subset_num = max(subset_num, num)
        num = 0
else:
    num += 1   # 最後だけ数えられないので注意
    subset_num = max(subset_num, num)
print(N - subset_num)

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-

N = int(input())
P = [int(input()) for _ in range(N)]
Q = [P.index(i) for i in range(1, N + 1)]

candidate = []
num = 0
for i in range(N-2):
    num += 1
    if Q[i] > Q[i+1]:
        candidate.append(num)
        num = 0
    if i == N-2:
        candidate.append(num)
print(N - max(candidate))