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

Fixed submission:
import collections

h,w=list(map(int,input().split()))
a=[input() for _ in range(h)]
#a[h][w]
direction=[[-1,0],[1,0],[0,-1],[0,1]]
visited=[[-1]*w for _ in range(h)]
q=collections.deque()

#全ての黒マスをキューに入れる
for hi in range(h):
  for wi in range(w):
    if a[hi][wi]=="#":
      q.append([hi,wi])
      visited[hi][wi]=0

while len(q)>0:
  ch,cw=q.popleft()
  for d in direction:
    nh=ch+d[0]
    nw=cw+d[1]
    #端からはみでない、まだ見てない白マス
    if nh>=0 and nw>=0 and nh<h and nw<w and visited[nh][nw]==-1:
      q.append([nh,nw])
      visited[nh][nw]=visited[ch][cw]+1

ans=0
for hi in range(h):
  tmp=max(visited[hi])
  if tmp > ans:
    ans=tmp
print(ans)

Buggy submission (verdict: Runtime Error):
import queue
h,w=list(map(int,input().split()))
a=[]
for i in range(h):
  a.append(input())

#a[たて][よこ]
ma=0
li=[[0]*w for _ in range(h)]
li2=[[True]*w for _ in range(h)]
#そのマスが何手目で黒くなるかを調べる
#隣に黒がなければ、上下左右の一番小さいserch+1
#隣に黒があれば、1
def search(i,j):
  li2[i][j]= False
  if li[i][j]!= 0:
    return li[i][j]
  u=9999
  d=9999
  r=9999
  l=9999
  if i-1>=0:
    if a[i-1][j]=="#":
      li[i][j]=1
      return 1
    elif li2[i-1][j]:
      u=search(i-1,j)
  if i+1<h:
    if a[i+1][j]=="#":
      li[i][j]=1
      return 1
    elif li2[i+1][j]:
      d=search(i+1,j)
  if j-1>=0:
    if a[i][j-1]=="#":
      li[i][j]=1
      return 1
    elif li2[i][j-1]:
      l=search(i,j-1)
  if j+1<w:
    if a[i][j+1]=="#":
      li[i][j]=1
      return 1
    elif li2[i][j+1]:
      r=search(i,j+1)
  li[i][j]=min(u,d,r,l)+1
  return min(u,d,r,l)+1

ans=0
for hi in range(h):
  for wi in range(w):
    if a[hi][wi]==".":
      li2=[[True]*w for _ in range(h)]
      tmp= search(hi,wi)
      if tmp>ans:
        ans=tmp
print(ans)
Problem p03805 (python)

Fixed submission:
import itertools

n,m=list(map(int,input().split()))
path=[[False]*n for _ in range(n)]
for i in range(m):
  a,b=list(map(int,input().split()))
  path[a-1][b-1]=True

ans=0
for i in itertools.permutations(list(range(n))):
  if i[0]!=0:
    continue
  flg=True
  for j in range(len(i)-1):
    if path[min(i[j],i[j+1])][max(i[j],i[j+1])]==False:
      flg=False
      break
  if flg:
    ans+=1
print(ans)

Buggy submission (verdict: Runtime Error):
import itertools

n,m=list(map(int,input().split()))
path=[[False]*m for _ in range(m)]
for i in range(m):
  a,b=list(map(int,input().split()))
  path[a-1][b-1]=True

ans=0
for i in itertools.permutations(list(range(n))):
  if i[0]!=0:
    continue
  flg=True
  for j in range(len(i)-1):
    if path[min(i[j],i[j+1])][max(i[j],i[j+1])]==False:
      flg=False
      break
  if flg:
    ans+=1
print(ans)
Problem p02847 (python)

Fixed submission:
S_L="""SUN,MON,TUE,WED,THU,FRI,SAT"""
S_L = S_L.split(",")
print(7 - S_L.index(input()) )

Buggy submission (verdict: Runtime Error):
iro = []
iro_i = []
res = []
r = 1
cm = []

N = int(input())
for i in range(N+1):
  cm.append([])
for i in range(N-1):
  a,b = input().split(" ")
  a = int(a)
  b = int(b)
  cr = set(iro_i) - set(cm[a] + cm[b])
  
  if len(cr):
    cr = list(cr)[0]
    res.append(cr)
    cm[a].append(cr)
    cm[b].append(cr)
  else:
    iro_i.append(r)
    cm[a].append(r)
    cm[b].append(r)
    res.append(r)
    r+=1

print(r-1)
for i in res:
  print(i)
Problem p02832 (python)

Fixed submission:
a = int(input())
n = input().split()
b = 0
c = 0
flag = 0
for i in n:
    if not int(i) == b+1:
        c +=1
    else:
        b += 1
        flag = 1
if flag == 0:
    c = -1
print(c)

Buggy submission (verdict: Runtime Error):
a = int(input())
n = list(map(int.input().split()))
b = 0
c = 0
flag = 0
for i in n:
    if not int(i) == b+1:
        c +=1
    else:
        b += 1
        flag = 1
if flag == 0:
    c = -1
print(c)
Problem p03221 (python)

Fixed submission:
N, M = map(int, input().split())
L = []
P = [0]*(N+1)
for i in range(M):
    p, y = map(int, input().split())
    L.append([i, p, y, 0])

L = sorted(L, key = lambda x:x[2])

for l in L:
    P[l[1]] += 1
    l[3] = P[l[1]]    
        
for l in sorted(L, key = lambda x:x[0]):
    print('{0:0>6d}{1:0>6d}'.format(l[1], l[3]))

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
P = []
Y = []
#var = []
for i in range(M):
    p, y = map(int, input().split())
    #if p not in P:
    #    var.append(p)
    P.append(p)
    Y.append(y)

L = zip(range(M), P, Y)     

Order = [None]*M

for v in set(P):
    l = filter(lambda x:x[1] == v, L)
    l_ = sorted(l, key = lambda x:x[2])
    
    for n in l_:
        Order[n[0]] = l_.index(n)+1
        
for (p, od) in zip(P, Order):
    print('{0:0>6d}{1:0>6d}'.format(p, od))

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
P = []
Y = []
var = []
for i in range(M):
    p, y = map(int, input().split())
    if p not in P:
        var.append(p)
    P.append(p)
    Y.append(y)

L = zip(range(M), P, Y)     

Order = [None]*M

for v in var:
    l = filter(lambda x:x[1] == v, L)
    l_ = sorted(l, key = lambda x:x[2])
    
    for n in l_:
        Order[n[0]] = l_.index(n)+1
        
for (p, od) in zip(P, Order):
    print('{0:0>6d}{1:0>6d}'.format(p, od))

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
P = []
Y = []
var = []
for i in range(M):
    p, y = map(int, input().split())
    if p in P:
        var.append(p)
    P.append(p)
    Y.append(y)

L = zip(range(M), P, Y)     

Order = [None]*M

for v in var:
    l = filter(lambda x:x[1] == v, L)
    l_ = sorted(l, key = lambda x:x[2])
    
    for n in l_:
        Order[n[0]] = l_.index(n)+1
        
for (p, od) in zip(P, Order):
    print('{0:0>6d}{1:0>6d}'.format(p, od))
Problem p03242 (python)

Fixed submission:
n = input()
#print(n)
new = []
for i in n:
    if i == '1':
        new.append('9')
    elif i =='9':
        new.append('1')
    else:
        new.append(i)
print(''.join(new))

Buggy submission (verdict: Runtime Error):
#import itertools
import collections

def op(v):
    count = collections.Counter(v).most_common() 

    #v_ = itertools.groupby(sorted(v))
    #count = sorted([(k, len(list(g))) for k, g in v_], key = lambda x:x[1])
    return count

n = int(input())
V = [int(n) for n in input().split()]

if len(set(V)) == 1:
    ans = len(V) // 2
else:
    vp_ = [v for i, v in enumerate(V) if i%2 == 0] 
    vn_ = [v for i, v in enumerate(V) if i%2 != 0] 

    vp = op(vp_)
    vn = op(vn_)    

    if vp[-1][0] != vn[-1][0]:
        gp = vp[-1][1]
        gn = vn[-1][1]
    else:
        if vp[-1][1] > vn[-1][1]:
            gp = vp[-1][1]
            gn = vn[-2][1]
        else:
            gp = vp[-2][1]
            gn = vn[-1][1]

    #ans_p = sum([g for k, g in vp]) - gp
    #ans_n = sum([g for k, g in vn]) - gn

    #ans  = ans_p + ans_n
    ans = n - gp - gn

print(ans)
Problem p03250 (python)

Fixed submission:
import itertools, copy

n = input().split()

ans = 0
for p0, p1 in itertools.permutations(n, 2):
    n_ = copy.copy(n)
    n_.remove(p0)
    n_.remove(p1)
    
    total = int(''.join([p0, p1])) + int(n_[0])
    ans = max(ans, total)

print(ans)

Buggy submission (verdict: Runtime Error):
n = list(map(int, input().split()))
nmax = max(n)
print(nmax * 10 + sum(n.remove(nmax)))

Buggy submission (verdict: Runtime Error):
n = list(map(int, input().split()))
print(max(n) * 10 + sum(n.remove(nmax)))
Problem p02835 (python)

Fixed submission:
A1, A2, A3 = map(int, input().split())

t = A1 + A2 + A3

if t >= 22:
  print("bust")
else:
  print("win")

Buggy submission (verdict: Runtime Error):
A1, A2, A3 = input().split()

T = A1 + A2 + A3

if T > 21:
  print("bust")
else:
  print("win")
Problem p03038 (python)

Fixed submission:
N, M = [int(x) for x in input().split()]

A = [int(x) for x in input().split()]
A.sort(reverse=True)

S = []
for _ in range(M):
  b, c = [int(x) for x in input().split()]
  S.append((c, b))

S.sort(reverse=True)

total = 0
count = 0

while count < N and len(S) > 0:
  if A[0] > S[0][0]:
    a = A.pop(0)
    total += a
    count += 1
  else:
    c = S.pop(0)
    if c[1] < N - count:
      total += c[0] * c[1]
      count += c[1]
    else:
      total += c[0] * (N - count)
      count = N
if len(S) == 0:
  total += sum(A[:N-count])
print(total)

Buggy submission (verdict: Runtime Error):
N, M = [int(x) for x in input().split()]

A = [int(x) for x in input().split()]
A.sort(reverse=True)

C = []
for _ in range(M):
  b, c = [int(x) for x in input().split()]
  C.extend([c]*b)
C.sort(reverse=True)

total = 0
for _ in range(N):
  if A[0] > C[0]:
    a = A.pop(0)
    total += a
  else:
    c = C.pop(0)
    total += c

print(total)
Problem p03108 (python)

Fixed submission:
class Union_Find():
  def __init__(self, n):
    self.par = list(range(n))
    self.size = [-1] * n
    self.rank = [0] * n
  def root(self, x):
    if self.par[x] == x:
      return x
    else:
      self.par[x] = self.root(self.par[x])
      return self.par[x]
  def unite(self, x, y):
    root_x = self.root(x)
    root_y = self.root(y)
    if root_x == root_y:
      pass
    else:
      if self.rank[root_x] > self.rank[root_y]:
        self.par[root_y] = root_x
        self.rank[root_x] += 1
        self.size[root_x] += self.size[root_y]
      else:
        self.par[root_x] = root_y
        self.rank[root_y] += 1
        self.size[root_y] += self.size[root_x]
        
        
  def same(self, x, y):
    root_x = self.root(x)
    root_y = self.root(y)
    return root_x == root_y
  def count_size(self, x):
    # 根を共有している要素の数を数える。
    return self.size[self.root(x)]
 
N, M = list(map(int, input().split()))
uf = Union_Find(N)
bridge_list = []
inconv_list = [0] * (M + 1)
inconv_list[0] = N * (N - 1) //2
for _ in range(M):
  a, b = list(map(int, input().split()))
  bridge_list.append((a-1, b-1))
bridge_list.reverse()
for i in range(M):
  x, y = bridge_list[i]
  if uf.same(x, y):
    inconv_list[i+1] = inconv_list[i]
  else:
    Nx = uf.count_size(x)
    Ny = uf.count_size(y)
    inconv_list[i+1] = inconv_list[i] - Nx * Ny
    uf.unite(x, y)
 
inconv_list.sort()  
 
for i in range(1, M+1):
  print(inconv_list[i])

Buggy submission (verdict: Runtime Error):
class Union_Find():
  def __init__(self, n):
    self.par = [-1] * n
  def root(self, x):
    if self.par[x] < 0:
      return x
    else:
      self.par[x] = root(par[x])
      return self.par[x]
  def unite(self, x, y):
    root_x = self.root(x)
    root_y = self.root(y)
    if root_x == root_y:
      pass
    else:
      self.par[root_x] = root_y
  def same(self, x, y):
    root_x = self.root(x)
    root_y = self.root(y)
    return root_x == root_y
  def count_size(self, x):
    # 根を共有している要素の数を数える。
    return self.par.count(self.root(x))
 
N, M = list(map(int, input().split()))
uf = Union_Find(N)
bridge_list = []
inconv_list = [0] * (M + 1)
inconv_list[0] = N * (N - 1) //2
for _ in range(M):
  a, b = list(map(int, input().split()))
  bridge_list.append((a-1, b-1))
bridge_list.reverse()
for i in range(M):
  x, y = bridge_list[i]
  if uf.same(x, y):
    inconv_list[i+1] = inconv_list[i]
  else:
    Nx = uf.count_size(x)
    Ny = uf.count_size(y)
    inconv_list[i+1] = inconv_list[i] - Nx * Ny
    uf.unite(x, y)
 
inconv_list.sort()  
 
for i in range(1, M+1):
  print(inconv_list[i])
Problem p02990 (python)

Fixed submission:

N, K = map(int, input().split())
MOD=10**9+7

def cmb(n, r):
    if n < r: return 0 #date added
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

for i in range(1,K+1):
    ans=cmb(N-K+1, i)%MOD*cmb(K-1, i-1)%MOD
    # cmb(N-K+i, i) -> cmb(N-K+1, i)
    #if N==K and 1 < i: ans=0
    print(int(ans%MOD))

Buggy submission (verdict: Runtime Error):

from math import factorial
import sys
sys.setrecursionlimit(10000000)

N, K = map(int, input().split())
MOD=10**9+7

nCr = {}
def cmb(n, r):
    if r == 0 or r == n: return 1
    if r == 1: return n
    #if (n,r) in nCr: return nCr[(n,r)]
    #nCr[(n,r)] = cmb(n-1,r)%MOD + cmb(n-1,r-1)%MOD
    #return nCr[(n,r)]
    a = factorial(n)%MOD / factorial(r)%MOD / factorial(n - r)%MOD
    return int(a)

presum=0
for i in range(1,K+1):
    tmp=cmb(N-K+i, i)%MOD
    ans=(tmp-presum)*cmb(K-1, i-1)%MOD
    presum += ans
    print(ans)
Problem p03107 (python)

Fixed submission:
S =list(input())
L =list(map(int,S))

print(min(L.count(0),L.count(1))*2)

Buggy submission (verdict: Runtime Error):
n = 0
X = 0
while X<1:
	# print(L)
	K = len(L)-1
	# print(K)
	for i in range(K):
		if L[i]+L[i+1]==1:
			L.pop(i)
			L.pop(i)
			n=n+1
			break
		elif i == K-1:
			X=1

# print(L)
print(n*2)
Problem p03209 (python)

Fixed submission:
n,x = (int(i) for i in input().split())
def pc(n,k):
	if n and k==1: return 0
	elif k==1: return 1
	elif k<2**(n+1)-1: return pc(n-1,k-1)
	elif k==2**(n+1)-1: return 2**n
	elif k<2**(n+2)-3: return 2**n+pc(n-1,k-2**(n+1)+1)
	else: return 2**(n+1)-1
print(pc(n,x))

Buggy submission (verdict: Runtime Error):
n,x = (int(i) for i in input().split())
def pc(n,k):
	if k==1: return 0
	elif k<2**(n+1)-1: return pc(n-1,k-1)
	elif k==2**(n+1)-1: return 2**n
	else: return 2**n+pc(n-1,k-2**(n+1)+1)
print(pc(n,x))
Problem p03250 (python)

Fixed submission:
a,b,c = (int(i) for i in input().split())
print(a+b+c+max(a,b,c)*9)

Buggy submission (verdict: Runtime Error):
a,b,c = (int(i) for i in input().split())
print(sum(a,b,c)+max(a,b,c)*9)
Problem p03365 (python)

Fixed submission:
n = int(input())
fn,fk,mod = [1]*n,[1]*n,10**9+7
for i in range(n-1): fn[i+1] = (fn[i]*(i+2))%mod
def power(n,k):
	if k==1: return n
	elif k%2==0: return power((n**2)%mod,k//2)
	else: return (n*power(n,k-1))%mod
def comb(n,k):
	if n<k or k<0: return 0
	elif k==0 or n==k: return 1
	else: return (((fn[n-1]*fk[n-k-1])%mod)*fk[k-1])%mod
fk[-1] = power(fn[-1],mod-2)
for i in range(2,n+1): fk[-i] = (fk[-i+1]*(n+2-i))%mod
fn.append(1)
ans = fn[n-2]*(n-1)
for i in range(n-2,(n-1)//2,-1):
	ans = (ans-comb(i-1,n-i-1)*fn[i-1]*fn[n-i-2])%mod
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
fn,fk,mod = [1]*n,[1]*n,10**9+7
for i in range(n-1): fn[i+1] = (fn[i]*(i+2))%mod
def power(n,k):
	if k==1: return n
	elif k%2==0: return power((n**2)%mod,k//2)
	else: return (n*power(n,k-1))%mod
def comb(n,k):
	if n<k or k<0: return 0
	elif k==0 or n==k: return 1
	else: return (((fn[n-1]*fk[n-k-1])%mod)*fk[k-1])%mod
fk[-1] = power(fn[-1],mod-2)
for i in range(2,n+1): fk[-i] = (fk[-i+1]*(n+2-i))%mod
fn.append(1)
ans = f[n-2]
for i in range(2,n):
	ans = (ans-comb(i-1,n-i-1)*fn[i-1]*fn[n-i-2])%mod
print(ans)
Problem p03745 (python)

Fixed submission:
import numpy as np
n = int(input())
a = [int(i) for i in input().split()]
answer = 1
if n!=1: flag = np.sign(a[1]-a[0])
for i in range(1,n-1):
	num = np.sign(a[i+1]-a[i])
	if flag==0:
		flag = num
	elif num==-flag:
		answer += 1
		flag = 0
print(answer)

Buggy submission (verdict: Runtime Error):
import numpy as np
n = int(input())
a = [int(i) for i in input().split()]
answer= 1
if n!=1: np.sign(a[1]-a[0])
for i in range(1,n-1):
	num = np.sign(a[i+1]-a[i])
	if flag==0:
		flag = num
	elif num==-flag:
		answer += 1
		flag = 0
print(answer)

Buggy submission (verdict: Runtime Error):
import numpy as np
n = int(input())
a = [int(i) for i in input().split()]
answer,flag = 1,np.sign(a[1]-a[0])
for i in range(1,n-1):
	num = np.sign(a[i+1]-a[i])
	if flag==0:
		flag = num
	elif num==-flag:
		answer += 1
		flag = 0
print(answer)
Problem p03822 (python)

Fixed submission:
from sys import setrecursionlimit
setrecursionlimit(100000)
n = int(input())
x,q = [[] for i in range(n)],[-1]*n
for i in range(n-1):
	a = int(input())-1
	x[a].append(i+1)
def f(z):
	y = []
	if x[z]:
		for i in x[z]:
			if q[i]+1: y.append(q(i))
			else: y.append(f(i))
		y = sorted(y)[::-1]
		for i in range(len(y)): y[i]+=i+1
		q[z] = max(y)
		return max(y)
	else:
		q[z] = 0
		return 0
print(f(0))

Buggy submission (verdict: Runtime Error):
n = int(input())
x,q = [[] for i in range(n)],[-1]*n
for i in range(n-1):
	a = int(input())-1
	x[a].append(i+1)
def f(z):
	y = []
	if x[z]:
		for i in x[z]:
			if q[i]+1: y.append(q(i))
			else: y.append(f(i))
		y = sorted(y)[::-1]
		for i in range(len(y)): y[i]+=i+1
		q[z] = max(y)
		return max(y)
	else:
		q[z] = 0
		return 0
print(f(0))
Problem p02847 (python)

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

Buggy submission (verdict: Runtime Error):
week = {'SUN':7, 'MON':6, 'TUE':5, 'WED':4, 'THE':3, 'FRI':2, 'SAT':1}
S = input()
print(week[S])
Problem p02881 (python)

Fixed submission:
import numpy as np
N = int(input())
result = []
for i in range(1, np.sqrt(N).astype(int)+1):
    if N % i == 0:
        result.append(i+int(N/i)-2)
print(min(result))

Buggy submission (verdict: Runtime Error):
N = int(input())
result = []
for i in tqdm(range(1, N+1)):
    if N % i == 0:
        result.append(i+int(N/i)-2)
print(min(result))
Problem p02897 (python)

Fixed submission:
import numpy as np
N = int(input())
a = np.arange(1, N+1)
print((a % 2).mean())

Buggy submission (verdict: Runtime Error):
import numpy as np
N = int(input())
print((a % 2).mean())

Buggy submission (verdict: Runtime Error):
import numpy as np
N = int(input())
print(np.mean([*map(lambda x: x % 2, np.arange(1, N+1))]))

Buggy submission (verdict: Runtime Error):
import numpy as np
import pandas as pd
N = int(input())
print(pd.Series(np.arange(1, N+1)).map(lambda x: x % 2).mean())
Problem p02935 (python)

Fixed submission:
N = int(input())
v_list = input().split()
v_list = [int(v_list[i]) for i in range(N)]
v_list.sort()
ans = int(v_list[0])
for i in range(1, N):
    ans = (ans + int(v_list[i]))/2 
print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
v_list = input().split()
v_list = [int(v_list(i)) for i in range(N)]
v_list.sort()
ans = int(v_list[0])
for i in range(1, N):
    ans = (ans + int(v_list[i]))/2 
print(ans)
Problem p02990 (python)

Fixed submission:
def cal(n, i):
    numerator = 1
    denominator = 1
    for j in range(1, i+1):
        numerator *= (n-j+1) 
        denominator *= j
    x = numerator // denominator
    return x

N, K = map(int, input().split())
for i in range(1, K+1):
    if i > N-K+1:
        print(0)
    else:
        ans = cal(N-K+1, i)
        ans *= cal(K-1, i-1)
        ans = ans % 1000000007
        print(int(ans))

Buggy submission (verdict: Runtime Error):
import math

def cal(n, i):
    x = 1
    for j in range(1, i+1):
        x *= (n-j+1) / j
    return x

N, K = map(int, input().split())
for i in range(1, K+1):
    if i > N-K+1:
        print(0)
    else:
        ans = cal(N-K+1, i)
        ans *= cal(K-1, i-1)
        ans = ans % 1000000007
        print(int(ans))

Buggy submission (verdict: Runtime Error):
import math

def cal(n, i):
    numerator = math.factorial(n)
    denominator = math.factorial(i)*math.factorial(n-i)

    return numerator / denominator

N, K = map(int, input().split())
for i in range(1, K+1):
    if i > N-K+1:
        print(0)
    else:
        ans = cal(N-K+1, i)
        ans *= cal(K-1, i-1) % 1000000007
        print(int(ans))

Buggy submission (verdict: Runtime Error):
def cal_position(a, i):
    x = 1
    for j in range(1, i+1):
        x *= (a - (j-1)) / j
    return x


def cal_pattern(position_num, red_num):
    return (cal_position(position_num + red_num, position_num)) % 1000000007


N, K = map(int, input().split())
for i in range(K):
    red_num = N - K - i
    if red_num < 0:
        print(0)
    else:
        ans = cal_position(K-1, i)
        ans *= cal_pattern(i+1, red_num)
        print(int(ans))
Problem p03137 (python)

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

if M <= N:
	print(0)
elif M == 2:
	if N == 1:
		X_list = [int(_) for _ in list(input().split())]
		print(abs(X_list[0]-X_list[1]))
	else:
		print(0)
else:
	X_list = [int(_) for _ in list(input().split())]

	X_list.sort()
	X_list.reverse()

	X_diff_list = [X_list[i-1]-X_list[i] for i in range(1, M)]
	X_diff_list.sort()
	X_diff_list.reverse()

	answer = sum(X_diff_list)

	if N == 1:
		print(answer)
	else:
		for n in range(N-1):
			answer -= X_diff_list[n]
		print(answer)

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

if M == 1:
	print(0)
elif M == 2:
	if N == 1:
		X_list = [int(_) for _ in list(input().split())]
		print(abs(X_list[0]-X_list[1]))
	else:
		print(0)
else:
	X_list = [int(_) for _ in list(input().split())]

	X_list.sort()
	X_list.reverse()

	X_diff_list = [X_list[i-1]-X_list[i] for i in range(1, M)]
	X_diff_list.sort()
	X_diff_list.reverse()

	answer = sum(X_diff_list)

	if N == 1:
		print(answer)
	else:
		for n in range(N-1):
			answer -= X_diff_list[n]
		print(answer)

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

if M == 1:
	print(0)
else:
	X_list = [int(_) for _ in list(input().split())]

	X_list.sort()
	X_list.reverse()

	X_diff_list = [X_list[i-1]-X_list[i] for i in range(1, M)]
	X_diff_list.sort()
	X_diff_list.reverse()

	answer = sum(X_diff_list)

	if N == 1:
		print(answer)
	else:
		for n in range(N-1):
			answer -= X_diff_list[n]
		print(answer)
Problem p03207 (python)

Fixed submission:
N = int(input())

answer = 0
big = 0

for i in range(N):
	a = int(input())
	answer += a
	if big < a:
		big = a

print(int(answer-(big/2)))

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

answer = 0
big = 0

for i in range(N):
	a = int(input())
	answer += a
	if big < a:
		big = a

print(int(answer-(big/2))
Problem p03209 (python)

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

a, p = [1], [1]

for i in range(N):
	a.append(a[i] * 2 + 3)
	p.append(p[i] * 2 + 1)

def f(N, X):
	if N == 0:
		return 0 if X <= 0 else 1
	elif X <= 1 + a[N-1]:
		return f(N-1, X-1)
	else:
		return p[N-1] + 1 + f(N-1, X-2-a[N-1])

print(f(N, X))

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

a, p = [1], [1]

for i in range(N):
	a.append(a[i] * 2 + 3)
	p.append(p[i] * 2 + 1)

def f(N, X):
	if N == 0:
		return 0 if X <= 0 else 1
	elif X <= 1 + a[N+1]:
		return f(N-1, X-1)
	else:
		return p[N-1] + 1 + f(N-1, X-2-a[N-1])

print(f(N, X))