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

Fixed submission:
import numpy as np
M=int(input())
D=0
C=0
for i in range(M):
  d,c=map(int,input().split())
  D+=c*d
  C+=c
# 桁数を減らす処理はC-1回行われる

# 桁数を減らさない処理は総和から9減る。(D-1)//9回行われる。
print((C-1)+(D-1)//9)

Buggy submission (verdict: Runtime Error):
import numpy as np
M=int(input())
D=np.zeros(M,dtype=int)
C=np.zeros(M,dtype=int)
for i in range(M):
  d,c=map(int,input().split())
  D[i]=d
  C[i]=c
  
A=np.zeros(C.sum(),dtype=int)
ind=0
for i in range(D.size):
  for j in range(C[i]):
    A[ind]=D[i]
    ind+=1

yosen=0
while A.size>1:
  found=False
  for i in range(A.size-1):
    if A[i]+A[i+1]>=10:
      newa=A[i]+A[i+1]
      A[i]=newa//10
      A[i+1]=newa%10
      found=True
      yosen+=1
      break
  if not found:
    if A.size<=1:
      break
    A[1]=A[0]+A[1]
    yosen+=1
    A=np.delete(A,0)
print(yosen)

Buggy submission (verdict: Runtime Error):
import numpy as np
M=int(input())
D=np.zeros(M,dtype=int)
C=np.zeros(M,dtype=int)
for i in range(M):
  d,c=map(int,input().split())
  D[i]=d
  C[i]=c
  
A=np.zeros(C.sum(),dtype=int)
ind=0
for i in range(D.size):
  for j in range(C[i]):
    A[ind]=D[i]
    ind+=1

yosen=0
while A.size>1:
  found=False
  for i in range(A.size-1):
    if A[i]+A[i+1]>=10:
      newa=A[i]+A[i+1]
      A[i]=newa//10
      A[i+1]=newa%10
      found=True
      yosen+=1
      break
  if not found:
    A[1]=A[0]+A[1]
    yosen+=1
    A=np.delete(A,0)
print(yosen)
Problem p02882 (python)

Fixed submission:
import math
a,b,x=map(int,input().split())

bottle=(a**2)*b

if x <= bottle/2:
  # 半分以上傾ける場合
  soko=(x*2/b)/a
  
  #bに対してtangent(r)がsokoとなるrを求める
  r=90-(math.degrees(math.atan(soko/b)))
  
else:
  # 半分傾けられない場合
  takasa=((a**2)*b-x)*2/(a**2)
  
  #takasaに対してtangent(r)がaとなるrを求める
  if takasa==0:
    r=0
  else:
      r=90-(math.degrees(math.atan(a/takasa)))

print(r)

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

bottle=(a**2)*b

if x <= bottle/2:
  # 半分以上傾ける場合
  soko=(x*2/b)/a
  
  #bに対してtangent(r)がsokoとなるrを求める
  r=90-(math.degrees(math.atan(soko/b)))
  
else:
  # 半分傾けられない場合
  takasa=((a**2)*b-x)*2/(a**2)
  
  #takasaに対してtangent(r)がaとなるrを求める
  r=90-(math.degrees(math.atan(a/takasa)))

print(r)
Problem p02937 (python)

Fixed submission:
s=input()
t=input()
if len(set(t)-set(s))>0:
  print(-1)
  exit(0)

ss=s*2
ind=-1
turn=0
for c in t:
  nex=ss[ind+1:].find(c)
  ind=(ind+1)+nex
  if ind>=len(s):
    ind-=len(s)
    turn+=1

print(turn*len(s)+ind+1)

Buggy submission (verdict: Runtime Error):
import sys
readline = sys.stdin.readline

S = readline().rstrip()
T = readline().rstrip()

if len(set(T) - set(S)) > 0:
  print(-1)
  exit(0)
  
import bisect
# Tの各文字を探す
S2 = S * 2
from collections import defaultdict
# ある文字が何文字目にあるか辞書
dic = defaultdict(list)

for i in range(len(S2)):
  dic[S2[i]] += [i]

ind = -1
ans = 0
for t in T:
  # 探す文字はt
  targets = dic[t]
#  print("targets",targets,"t",t,"ind + 1",ind + 1)
  newind = targets[bisect.bisect_left(targets, ind + 1)]
#  print("t",t,"S2",S2,"newind",newind)
  ans += (newind - ind)
  if newind > len(S):
    newind -= len(S)
  ind = newind

print(ans)

Buggy submission (verdict: Runtime Error):
s=input()
t=input()

if len(set(t)-set(s))>0:
  print(-1)
else:
  s2=s*2
  s2pos={}
  for i in range(len(s2)):
    if s2[i] in s2pos:
      s2pos[s2[i]].append(i)
    else:
      s2pos[s2[i]]=[i]

  cur=-1
  import bisect
  rev=0
  for c in t:
    cur+=1
    pos=s2pos[c]
    p=bisect.bisect_left(pos,cur)
    cur=pos[p]
    if cur>len(s):
      cur-=len(s)
      rev+=1
    if rev>=100:
      print(-1)
      break
  else:
    print(rev*len(s)+cur+1)
Problem p02947 (python)

Fixed submission:
n=int(input())
s=[None]*n
for i in range(n):
  s[i]="".join(sorted(input()))

s=sorted(s)

total=0
count=1
for j in range(1,n):
  if s[j]==s[j-1]:
    count = count+1
  else:
    if count>1:
      total = total+(count*(count-1))//2
    count=1

if count>1:
  total = total+(count*(count-1))//2

print(total)

Buggy submission (verdict: Runtime Error):
n=int(input())
s=[None]*n
for i in range(n):
  s[i]=sorted(input())
import collections
c=collections.Counter(s)
ans=0
for v in c.valeus():
  ans+=(v*(v-1))//2
print(ans)
Problem p03007 (python)

Fixed submission:
# 符号が異なる数同士の引き算をすれば絶対値が大きくなる
# 基本は負から正を引いて大きな負の数を作る
# 最後だけ正から負を引いて大きな正の数を作る
# 正と正しか存在しない場合は最も小さい数からその他の数を引くことで負の数を作れる
# 負と負しか存在しない場合は最も大きい数からその他の数を引くことで正の数を作れる
# 正のリストと負のリスト両方を管理する
# 0は何も影響を与えないのでとりあえず正のリストに入れておく

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

if len(A) == 2:
  x = max(A)
  y = min(A)
  print(x-y)
  print(x,y)
  exit(0)

plusA = []
minusA = []
for a in A:
  if a >= 0:
    plusA += [a]
  else:
    minusA += [a]
    
method = [] # 計算過程をメモ
if len(plusA) == 0:
  minusA = sorted(minusA) # 最も小さな数を取り出すため
#  print("minusA",minusA)
  x = minusA.pop()
  y = minusA.pop()
#  print("x",x,"y",y)
  method.append([x,y])
  plusA.append(x-y)
#  print("plusA",plusA,"minusA",minusA,"method",method)
elif len(minusA) == 0:
  plusA = sorted(plusA)[::-1] # 最も小さな数を取り出すため
  x = plusA.pop()
  y = plusA.pop()
  method.append([x,y])
  minusA.append(x-y)
  
while True:
  if len(minusA) + len(plusA) == 1:
    print(x-y)
    for m in method:
      print(*m)
    break
  if len(plusA) == 1:
    # 正の数が一つのときは、この数から残りの負の数を引いていく
    x = plusA.pop()
    y = minusA.pop()
    method.append([x,y])
    plusA.append(x-y)
  else:
    # 正の数が複数あるときは、負の数を作り続ける
    x = minusA.pop()
    y = plusA.pop()
    method.append([x,y])
    minusA.append(x-y)

Buggy submission (verdict: Runtime Error):
# 最も小さい数から最も大きい数を引く、を繰り返すことで、できるだけ小さい数が作れる
# 最後に残った数からできるだけ小さい数を引くことで答えが求められる

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

if N==2:
  print(A[1]-A[0])

from collections import deque
q = deque(A)

seq = []
x = q.popleft()
y = q.pop()
seq += [[x,y]]
x = x-y
while len(q) > 1:
  y = q.pop()
  seq += [[x,y]]
  x = x-y

y = q.pop()
seq += [[y,x]]
print(y - x)
for s in seq:
  print(*s)
Problem p03014 (python)

Fixed submission:
h,w=map(int,input().split())
grid=[None]*h

for i in range(h):
  grid[i]=input()

yoko=[[0 for i in range(w)] for j in range(h)]
tate=[[0 for i in range(w)] for j in range(h)]

for i in range(h):
  s=grid[i]
  left=0
  right=0
  while left<len(s):
    if s[left]=="#":
      left+=1
      right=left
      continue
    while right+1<w and s[right+1]==".":
      right+=1
  
    for j in range(left,right+1):
      yoko[i][j]=right-left
      
    left=right+1
    right=left
    
for i in range(w):
  up=0
  down=0
  while up<h:
    if grid[down][i]=="#":
      up+=1
      down=up
      continue
    while down+1<h and grid[down+1][i]==".":
      down+=1
    for j in range(up,down+1):
      tate[j][i]=down-up
    up=down+1
    down=up
    
ans=0
for i in range(h):
  for j in range(w):
    if grid[i][j]==".":
      ans=max(ans,tate[i][j]+yoko[i][j])
      
print(ans+1)

Buggy submission (verdict: Runtime Error):
h,w=map(int,input().split())
grid=[None]*h
for i in range(h):
  grid[i]=input()
  
L=[[0 for i in range(w)] for j in range(h)]
R=[[0 for i in range(w)] for j in range(h)]
U=[[0 for i in range(w)] for j in range(h)]
D=[[0 for i in range(w)] for j in range(h)]

for i in range(h):
  if grid[i][0]=="#":
    L[i][0]=0
  else:
    L[i][0]=1
  for l in range(1,w):
    if grid[i][l]=="#":
      L[i][l]=0
    else:
      L[i][l]=L[i][l-1]+1
      
  if grid[i][-1]=="#":
    R[i][-1]=0
  else:
    R[i][-1]=1
  for r in range(w-2,-1,-1):
    if grid[i][r]=="#":
      R[i][r]=0
    else:
      R[i][r]=R[i][r+1]+1
      
for j in range(w):
  if grid[0][j]=="#":
    U[0][j]=0
  else:
    U[0][j]=1
  for u in range(1,h):
    if grid[u][j]=="#":
      U[u][j]=0
    else:
      U[u][j]=U[u][j-1]+1
      
  if grid[-1][j]=="#":
    D[-1][j]=0
  else:
    D[-1][j]=1
  for d in range(h-2,-1,-1):
    if grid[d][j]=="#":
      D[d][j]=0
    else:
      D[d][j]=D[d][j+1]+1
      
ans=0
for i in range(h):
  for j in range(w):
    ans=max(ans,L[i][j]+R[i][j]+U[i][j]+D[i][j])

print(ans-3)

Buggy submission (verdict: Runtime Error):
h,w=map(int,input().split())
grid=[None]*h

for i in range(h):
  grid[i]=input()

yoko=[[0 for i in range(w)] for j in range(h)]
tate=[[0 for i in range(w)] for j in range(h)]

for i in range(h):
  s=grid[i]
  left=0
  right=0
  while left<len(s):
    if s[left]=="#":
      left+=1
      right=left
      continue
    while s[right+1]=="." and right+1<len(s):
      right+=1
  
    for j in range(left,right+1):
      yoko[i][j]=right-left
      
    left=right+1
    right=left
    
for i in range(w):
  up=0
  down=0
  while up<h:
    if grid[down][i]=="#":
      up+=1
      down=up
      continue
    while grid[down+1][i]=="." and down+1<h:
      down+=1
    for j in range(up,down+1):
      tate[j][i]=down-right
    up=down+1
    down=up
    
ans=0
for i in range(h):
  for j in range(w):
    if grid[i][j]==".":
      ans=max(ans,tate[i][j]+yoko[i][j])
      
print(ans)
Problem p03078 (python)

Fixed submission:
X,Y,Z,K=map(int,input().split())
A=sorted(list(map(int,input().split())))[::-1]
B=sorted(list(map(int,input().split())))[::-1]
C=sorted(list(map(int,input().split())))[::-1]
ans=[]
for a in range(len(A)):
  for b in range(len(B)):
    for c in range(len(C)):
      if (a+1)*(b+1)*(c+1)>K:
        break
      ans.append(A[a]+B[b]+C[c])

ans=sorted(ans)[::-1]
for i in range(min(K,len(ans))):
  print(ans[i])

Buggy submission (verdict: Runtime Error):
X,Y,Z,K=map(int,input().split())
A=sorted(list(map(int,input().split())))[::-1]
B=sorted(list(map(int,input().split())))[::-1]
C=sorted(list(map(int,input().split())))[::-1]
ans=[0]*(K**3)
ind=0
for a in range(len(A)):
  for b in range(len(B)):
    for c in range(len(C)):
      if (a+1)*(b+1)*(c+1)>K:
        break
      ans[ind]=A[a]+B[b]+C[c]
      ind+=1

ans=sorted(ans)[::-1]
for i in range(K):
  print(ans[i])

Buggy submission (verdict: Runtime Error):
X,Y,Z,K=map(int,input().split())
A=sorted(list(map(int,input().split())))[::-1]
B=sorted(list(map(int,input().split())))[::-1]
C=sorted(list(map(int,input().split())))[::-1]
ans=[0]*(K**3)
ind=0
for a in range(len(A)):
  for b in range(len(B)):
    for c in range(len(C)):
      if (a+1)*(b+1)*(c+1)>K:
        break
      ans[ind]=A[a]+B[b]+C[c]
      ind+=1

ans=sorted(ans)[::-1]
for i in range(min(K,len(ans))):
  print(ans[i])

Buggy submission (verdict: Runtime Error):
X,Y,Z,K=map(int,input().split())
A=sorted(list(map(int,input().split())))[::-1]
B=sorted(list(map(int,input().split())))[::-1]
C=sorted(list(map(int,input().split())))[::-1]
ans=[0]*max((len(A)*len(B)*len(C)),K)
ind=0
for a in range(len(A)):
  for b in range(len(B)):
    for c in range(len(C)):
      if (a+1)*(b+1)*(c+1)>K:
        break
      ans[ind]=A[a]+B[b]+C[c]
      ind+=1

ans=sorted(ans)[::-1]
for i in range(min(K,len(ans))):
  print(ans[i])

Buggy submission (verdict: Runtime Error):
X,Y,Z,K=map(int,input().split())
A=sorted(list(map(int,input().split())))[::-1]
B=sorted(list(map(int,input().split())))[::-1]
C=sorted(list(map(int,input().split())))[::-1]
ans=[0]*(len(A)*len(B)*len(C))
ind=0
for a in range(len(A)):
  for b in range(len(B)):
    for c in range(len(C)):
      if (a+1)*(b+1)*(c+1)>K:
        break
      ans[ind]=A[a]+B[b]+C[c]
      ind+=1

ans=sorted(ans)[::-1]
for i in range(K):
  print(ans[i])
Problem p03109 (python)

Fixed submission:
s=input()
y=int(s[:4])
print("Heisei" if y<2019 or (y==2019 and int(s[5:7])<5) else "TBD")

Buggy submission (verdict: Runtime Error):
s=input()
print("Heisei" if int(s[5:7])<5) else "TBD")
Problem p03130 (python)

Fixed submission:
d=[0 for i in range(4)]
for i in range(3):
  a,b=map(int,input().split())
  d[a-1]+=1
  d[b-1]+=1
print(("NO","YES")[d.count(1)==2 and d.count(2)==2])

Buggy submission (verdict: Runtime Error):
d=[0 for in range(4)]
for i in range(3):
  a,b=map(int,input().split())
  d[a-1]+=1
  d[b-1]+=1
print(("NO","YES")[d.count(1)==2 and d.count(2)==2])
Problem p03163 (python)

Fixed submission:
def calc():
  N,W=map(int,input().split())
  dp=[-1]*(W+1)
  dp[0]=0
  for i in range(N):
    w,v=map(int,input().split())
    for j in range(W-w,-1,-1):
      if dp[j]!=-1:
        if dp[j+w]<dp[j]+v:
          dp[j+w]=dp[j]+v
  print(max(dp))
  
calc()

Buggy submission (verdict: Runtime Error):
N,W=map(int,input().split())
weight=[0]*N
values=[0]*N
for i in range(N):
  weight[i],values[i]=map(int,input().split())

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

for i in range(N):
  for w in range(W+1):
    if w>=weight[i]:
      dp[i+1][w]=max(dp[i][w],dp[i][w-weight[i]]+values[i])
    else:
      dp[i+1][w]=dp[i][w]
      
print(dp[N][W])

Buggy submission (verdict: Runtime Error):
N,W=map(int,input().split())
weight=[0]*N
values=[0]*N
for i in range(N):
  weight[i],values[i]=map(int,input().split())

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

for i in range(N):
  for w in range(W+1):
    if w>=weight[i]:
      dp[i+1][w]=max(dp[i][w],dp[i][w-weight[i]]+values[i])
    else:
      dp[i+1][w]=dp[i][w]
      
print(dp[N][W])
Problem p03167 (python)

Fixed submission:
h,w=map(int,input().split())
grid=[None]*h
for i in range(h):
  grid[i]=input()
  
dp=[[0 for i in range(w)] for j in range(h)]
DIV=10**9+7

for i in range(h):
  for j in range(w):
    if grid[i][j]=="#":
      dp[i][j]=0
    elif i==0 and j==0:
      dp[i][j]=1
    else:
      up=0
      left=0
      if i>0:
        up=dp[i-1][j]
      if j>0:
        left=dp[i][j-1]
      dp[i][j]=(up+left)%DIV
        
print(dp[-1][-1])

Buggy submission (verdict: Runtime Error):
h,w=map(int,input().split())
grid=[None]*h
for i in range(h):
  grid[i]=input()
  
dp=[[0 for i in range(w)] for j in range(h)]
DIV=10**9+7
import deque
que=deque()
que.append([0,0,1])
while que:
  node=que.pop()
  y=node[0]
  x=node[1]
  p=node[2]
  dp[y][x]+=p
  dp[y][x]%=DIV
  if y+1<h and grid[y+1][x]!="#":
    que.append([y+1,x,dp[y][x]])
  if x+1<w and grid[y][x+1]!="#":
    que.append([y,x+1,dp[y][x+1]])
  
print(dp[-1][-1])
Problem p03171 (python)

Fixed submission:
import sys
readline = sys.stdin.readline

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

# dp[i][j] = 元の数列の中の連続する区間i～jに対して、最終局面に行った時のX-Yの最大値

dp = [[0] * (N + 1) for i in range(N + 1)]
  
for length in range(1, N + 1):
  for i in range(N - length + 1):
    j = i + length
    
    if (N - length) % 2 == 0: # 先手番
      dp[i][j] = max(dp[i + 1][j] + A[i], dp[i][j - 1] + A[j - 1])
      
    else: # 後手番
      dp[i][j] = min(dp[i + 1][j] - A[i], dp[i][j - 1] - A[j - 1])

print(dp[0][N])

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(5000)

readline = sys.stdin.readline

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

# dp[i][j] = 左端がi、右端がjの状態でのX - Yの最高得点
# dp[0][-1] = 0
# 奇数回目の処理では、
# dp[i][j] = max(dp[i-1][j] + A[i],dp[i][j - 1] + A[j])
# 偶数回目の処理では、
# dp[i][j] = min(dp[i - 1][j]) + A[i],dp[i][j - 1] + A[j])

from functools import lru_cache

@lru_cache(maxsize=3000)
def f(i,j):
  # 左端がi,右端がjのとき、これから取ることが出来る最大値 右端は含まない[i:j)
  if j - i == 1:
    if (N - (j - i)) % 2 == 0:
      return A[i]
    else:
      return -A[i]
  if (N - (j - i)) % 2 == 0:
    # 先手の場合
    return max(f(i + 1,j) + A[i],f(i,j - 1) + A[j - 1])
  else:
    return min(f(i + 1,j) - A[i],f(i,j - 1) - A[j - 1])
  
print(f(0,N))

Buggy submission (verdict: Runtime Error):
import sys
readline = sys.stdin.readline

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

# dp[i][j] = 左端がi、右端がjの状態でのX - Yの最高得点
# dp[0][-1] = 0
# 奇数回目の処理では、
# dp[i][j] = max(dp[i-1][j] + A[i],dp[i][j - 1] + A[j])
# 偶数回目の処理では、
# dp[i][j] = min(dp[i - 1][j]) + A[i],dp[i][j - 1] + A[j])

def f(i,j):
  # 左端がi,右端がjのとき、これから取ることが出来る最大値 右端は含まない[i:j)
  if j - i == 1:
    if (N - (j - i)) % 2 == 0:
      return A[i]
    else:
      return -A[i]
  if (N - (j - i)) % 2 == 0:
    # 先手の場合
    return max(f(i + 1,j) + A[i],f(i,j - 1) + A[j - 1])
  else:
    return min(f(i + 1,j) - A[i],f(i,j - 1) - A[j - 1])
  
print(f(0,N))
Problem p03238 (python)

Fixed submission:
n,*d=map(int,open(0).read().split())
print((sum(d),"Hello World")[n==1])

Buggy submission (verdict: Runtime Error):
n=list(map(int,open(0).read().split()))
print((n[1]+n[2],"Hello World")[n[0]==1])
Problem p03241 (python)

Fixed submission:
n,m=map(int,input().split())
ans=0
import math
for i in range(1,int(math.sqrt(m))+1):
  if m%i!=0:
    continue
  i2=m//i
  if i*n<=m:
    ans=max(ans,i)
  if i2*n<=m:
    ans=max(ans,i2)
print(ans)

Buggy submission (verdict: Runtime Error):
n,m=map(int,input().split())
ans=0
import math
for i in range(1,min(m//n+1,int(math.sqrt(m))+1):
  if m%i==0:
    ans=max(i,ans)
print(ans)
Problem p03282 (python)

Fixed submission:
s=input()
k=int(input())
if k<=len(s):
  if len(set(s[:k]))==1 and s[0]=="1":
    print(1)
    exit(0)
ans="1"
for c in s:
  if c!="1":
    ans=c
    break
print(ans)

Buggy submission (verdict: Runtime Error):
s=input()
k=int(input())
if k<=len(s):
  if len(set(s[:k]))==1 and s[0]=="1":
    print(1)
    exit(0)
print(s[1])

Buggy submission (verdict: Runtime Error):
s=input()
if s[0]=="1":
  print(s[1])
else:
  print(s[0])
Problem p03287 (python)

Fixed submission:
n,m=map(int,input().split())
a=[0]+list(map(int,input().split()))
from collections import defaultdict
mods=defaultdict(int)
mods[0]=1
for i in range(1,len(a)):
  a[i]=a[i-1]+a[i]%m
  mods[a[i]%m]+=1
ans=0
for v in mods.values():
  if v>1:
    ans+=v*(v-1)//2
print(ans)

Buggy submission (verdict: Runtime Error):
n,m=map(int,input().split())
a=[0]+list(map(int,input().split()))
mods=[0]*m
mods[0]=1
for i in range(1,len(a)):
  a[i]=a[i-1]+a[i]%m
  mods[a[i]%m]+=1
ans=0
for i in range(len(mods)):
  p=mods[i]
  if p>1:
    ans+=p*(p-1)//2
print(ans)

Buggy submission (verdict: Runtime Error):
n,m=map(int,input().split())
a=[0]+list(map(int,input().split()))
mods=[0]*m
mods[0]=1
for i in range(1,len(a)):
  a[i]=a[i-1]+a[i]
  mods[a[i]%m]+=1
ans=0
for i in range(len(mods)):
  p=mods[i]
  if p>1:
    ans+=p*(p-1)//2
print(ans)
Problem p03303 (python)

Fixed submission:
s=input()
x=int(input())
ans=""
for i in range(0,len(s),x):
  ans+=s[i]
print(ans)

Buggy submission (verdict: Runtime Error):
s=input()
x=int(input())
ans=""
for i in range(0,len(s)+1,x):
  ans+=s[i]
print(ans)
Problem p03309 (python)

Fixed submission:
import sys
readline=sys.stdin.readline

N=int(readline())
A=list(map(int,readline().split()))
B=[0]*N
sumB=0
for i in range(N):
  B[i]=A[i]-(i+1)
  
B=sorted(B)
mid=0
if len(B)&1:
  mid=B[N//2]
else:
  mid=(B[N//2-1]+B[N//2])//2
  
ans=0
for i in range(N):
  ans+=abs(B[i]-mid)

print(ans)

Buggy submission (verdict: Runtime Error):
import sys
readline=sys.stdin.readline

N=int(readline())
A=list(map(int,readline().split()))
B=[0]*N
sumB=0
for i in range(N):
  B[i]=A[i]-(i+1)
  
B=sorted(B)
candi=[0]*3
candi[0]=B[N//2-1]
candi[1]=B[N//2]
candi[2]=B[N//2+1]

ans=10**10
for c in candi:
  res=0
  for i in range(N):
    res+=abs(B[i]-c)
  if res<ans:
    ans=res
print(ans)
Problem p03316 (python)

Fixed submission:
n=input()
s=0
for i in range(len(n)):
  s=s+int(n[i])
print(("No","Yes")[int(n)%s==0])

Buggy submission (verdict: Runtime Error):
n=input()
s=0
for i in range(len(n)):
  s=s+int(n[i])
print(("No","Yes")[int(n)%s==0]
Problem p03380 (python)

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

import bisect
maxval=0
maxpair=None

def cmb(n, r):
    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

i=-1
bunshi=A[i]
target=A[i]/2
tarp=bisect.bisect_left(A,target)
diff=10**9+1
if tarp-1>=0:
  diff=abs(target-A[tarp-1])
if abs(target-A[tarp])<diff:
  print(bunshi,A[tarp])
else:
  print(bunshi,A[tarp-1])

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

import bisect
maxval=0
maxpair=None

def cmb(n, r):
    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(len(A)-1,len(A)//2,-1):
  bunshi=A[i]
  target=A[i]//2
  tarp=bisect.bisect_left(A,target)
  for j in (-1,0):
    if tarp+j>=0 and tarp+j<len(A):
      c=cmb(bunshi,A[tarp+j])
      if c>maxval:
        maxval=c
        maxpair=[bunshi,A[tarp+j]]

print(*maxpair)
Problem p03424 (python)

Fixed submission:
n=input()
a=input().split()
print(("Three","Four")[len(set(a))==4])

Buggy submission (verdict: Runtime Error):
n=input()
a=input().split()
print(("Three","Four")[len(set(a))==4]
Problem p03437 (python)

Fixed submission:
x,y=map(int,input().split())
if x%y==0:
  print(-1)
else:
  print(x)

Buggy submission (verdict: Runtime Error):
x,y=map(int,input())
if y==0:
  print(x)
elif x%y==0:
  print(-1)
else:
  print(x)

Buggy submission (verdict: Runtime Error):
x,y=map(int,input())
if x%y==0:
  print(-1)
else:
  print(x)
Problem p03455 (python)

Fixed submission:
a,b=map(int,input().split())
print(("Even","Odd")[a*b&1])

Buggy submission (verdict: Runtime Error):
print(("Even","Odd")[int(input())&1])
Problem p03505 (python)

Fixed submission:
K,A,B=map(int,input().split())
if A>=K:
  print(1)
elif A<=B:
  print(-1)
else:
  bef=((K-A)//(A-B))+((K-A)%(A-B)!=0)
  print(2*bef+1)

Buggy submission (verdict: Runtime Error):
K,A,B=map(int,input().split())
if A>=K:
  print(1)
elif A<B:
  print(-1)
else:
  bef=((K-A)//(A-B))+((K-A)%(A-B)!=0)
  print(2*bef+1)
Problem p03545 (python)

Fixed submission:
ss=input()
s=[0]*4
for i in range(len(ss)):
  s[i]=int(ss[i])
dif=7-s[0]
ans=str(s[0])
found=False
for b in [s[1],-s[1]]:
  for c in [s[2],-s[2]]:
    for d in [s[3],-s[3]]:
      if b+c+d==dif:
        if b==s[1]:
          ans+="+"
        else:
          ans+="-"
        ans+=str(s[1])
        if c==s[2]:
          ans+="+"
        else:
          ans+="-"
        ans+=str(s[2])
        if d==s[3]:
          ans+="+"
        else:
          ans+="-"
        ans+=str(s[3])
        found=True
        break
    if found:
      break
  if found:
    break
print(ans+"=7")

Buggy submission (verdict: Runtime Error):
s=input()
for i in range(2**3):
  f=s[0]
  for j in range(3):
    if i>>j&1:
      f+="+"
    f+=s[j+1]
  if eval(f)==7:
    print(f+"=7")
    break
Problem p03568 (python)

Fixed submission:
n=int(input())
a=list(map(int,input().split()))

odd=0
even=0
for i in range(n):
  if a[i]%2==1:
    odd+=1
  else:
    even+=1

all=3**n
oddgr=2**even
print(all-oddgr)

Buggy submission (verdict: Runtime Error):
n=inr(input())
a=list(map(int,input().split()))

odd=True
for p in a:
  if p%2==0:
    odd=False
    
print(3**n-1-(1 if not odd else 0))