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

Fixed submission:
import copy
n=int(input())
a=[int(input()) for i in range(n)]
maxa=max(a)
if len(set(a))!=1:
  maxa2=sorted(set(a))[-2]
maxs=a.count(maxa)
for i in range(n):
  if maxs==1:
    print(maxa if a[i]!=maxa else maxa2)
  else:
    print(maxa)

Buggy submission (verdict: Runtime Error):
import copy
n=int(input())
a=[int(input()) for i in range(n)]
maxa=max(a)
if len(a)!=1:
  maxa2=sorted(set(a))[-2]
maxs=a.count(maxa)
for i in range(n):
  if maxs==1:
    print(maxa if a[i]!=maxa else maxa2)
  else:
    print(maxa)

Buggy submission (verdict: Runtime Error):
import copy
n=int(input())
a=[int(input()) for i in range(n)]
maxa=max(a)
maxa2=sorted(set(a))[-2]
maxs=a.count(maxa)
for i in range(n):
  if maxs==1:
    print(maxa if a[i]!=maxa else maxa2)
  else:
    print(maxa)

Buggy submission (verdict: Runtime Error):
import copy
n=int(input())
a=[int(input()) for i in range(n)]
maxa=max(a)
maxa2=sorted(set(nums))[-2]
maxs=a.count(maxa)
for i in range(n):
  if maxs==1:
    print(maxa if a[i]!=maxa else maxa2)
  else:
    print(maxa)
Problem p02972 (python)

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

#箱の状態を記録しておく配列
box=[0]*n


for i in range(n):
  num=n-i

  #まず割って、その数より大きい倍数がいくつあるか探る
  baisu=n//num

  if baisu==1:
    box[num-1]=a[num-1]

  #1～baisu倍の箱の状態を調べる。
  temp=0
  for j in range(2,baisu+1):
    temp+=box[num*j-1]
  box[num-1]=abs(temp%2-a[num-1])

ans=[]
for i in range(n):
  if box[i]==1:
    ans.append(i+1)

if sum(ans)!=0:
  print(len(ans))
  print(*ans)
else:
  print("0")

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

#箱の状態を記録しておく配列
box=[0]*n


for i in range(1,n+1):
  num=n-i

  #まず割って、その数より大きい倍数がいくつあるか探る
  baisu=n//num

  if baisu==1:
    box[num-1]=a[num-1]

  #1～baisu倍の箱の状態を調べる。
  temp=0
  for j in range(2,baisu+1):
    temp+=box[num*j-1]
  box[num-1]=abs(temp%2-a[num-1])

ans=[]
for i in range(n):
  if box[i]==1:
    ans.append(i+1)

if sum(ans)!=0:
  print(len(ans))
  print(*ans)
else:
  print("0")
Problem p03059 (python)

Fixed submission:
a,b,t=map(int,input().split())
print((t//a)*b)

Buggy submission (verdict: Runtime Error):
a,b,t=int(input())
print((t//a)*b)
Problem p03085 (python)

Fixed submission:
s=input()
if s=="A":
  print("T")
elif s=="T":
  print("A")
elif s=="C":
  print("G")
else:
  print("C")

Buggy submission (verdict: Runtime Error):
if input=="A":
  print("T")
elif input=="T":
  print("A")
elif input=="C":
  print("G")
else input=="G":
  print("C")
Problem p03086 (python)

Fixed submission:
s=input()

temp=0
templi=[0]
for i in range(len(s)):
  if s[i]=="A" or s[i]=="C" or s[i]=="G" or s[i]=="T":
    temp+=1
  else:
    templi.append(temp)
    temp=0
templi.append(temp)

print(max(templi))

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

temp=0
templi=[]
for i in range(len(s)):
  if s[i]=="A" or s[i]=="C" or s[i]=="G" or s[i]=="T":
    temp+=1
  else:
    templi.append(temp)
    temp=0
print(max(templi))
Problem p03087 (python)

Fixed submission:
n,q=map(int,input().split())
s=input()
hantei=[0]
for i in range(1,len(s)):
  if s[i-1]=="A" and s[i]=="C":
    hantei.append(hantei[i-1]+1)
  else:
    hantei.append(hantei[i-1])
#print(hantei)
#ここまではあってる

for i in range(q):
  l,r=map(int,input().split())
  print(hantei[r-1]-hantei[l-1])

Buggy submission (verdict: Runtime Error):
n,q=map(int,input().split())
s=input()
retsu=[]
for i in range(len(s)):
  if s[i]=="A" and s[i+1]=="C":
    retsu.append(i+1)
#print(retsu)
#ここまではあってる

for i in range(q):
  temp=set(retsu)
  l,r=map(int,input().split())
  hani=set(range(l,r))
  #print(hani)
  hani&=temp

  print(len(hani))
Problem p03125 (python)

Fixed submission:
a,b=map(int,input().split())
print(a+b if b%a==0 else b-a)

Buggy submission (verdict: Runtime Error):
 提出
Problem p03148 (python)

Fixed submission:
n,k=map(int,input().split())
li=[list(map(int,input().split())) for i in range(n)]
gr=[0]*(n+1) #各グループの出現回数をメモする配列

from operator import itemgetter
li=sorted(li, key=itemgetter(1), reverse=True)

A=[] #大きい方からK個以内の配列で、2個以上あるやつの2番目以降のやつの大きさを記録

for i in range(k):
  if gr[li[i][0]]>=1:
    A.append(li[i][1])
  gr[li[i][0]]+=1

A.reverse()

B=[] #既に同じグループが登場してしまってない子の大きさを記録
for i in range(k,n):
  if gr[li[i][0]]==0:
    B.append(li[i][1])
  gr[li[i][0]]+=1

#現時点での種類数とポイントを測定
sp=set()
ans=0
for i in range(k):
  ans+=li[i][1]
  sp.add(li[i][0])
sp=len(sp)
ans+=sp*sp

koukan=[] #その交換で、累積でどの程度増減するか
zouka=0
for a,b in zip(A,B):
  zouka+=(sp+1)**2-sp**2-(a-b)
  #print(a,b,sp,zouka)
  koukan.append(zouka)
  sp+=1

#koukanの中で最大の増加を探して、ansに+する。
# print(A,B)
# print(koukan)
if koukan:
  ans+=max(0,max(koukan))

print(ans)

Buggy submission (verdict: Runtime Error):
n,k=map(int,input().split())
li=[list(map(int,input().split())) for i in range(n)]
gr=[0]*(n+1) #各グループの出現回数をメモする配列

from operator import itemgetter
li=sorted(li, key=itemgetter(1), reverse=True)

A=[] #大きい方からK個以内の配列で、2個以上あるやつの2番目以降のやつの大きさを記録

for i in range(k):
  if gr[li[i][0]]>=1:
    A.append(li[i][1])
  gr[li[i][0]]+=1

A.reverse()

B=[] #既に同じグループが登場してしまってない子の大きさを記録
for i in range(k,n):
  if gr[li[i][0]]==0:
    B.append(li[i][1])
  gr[li[i][0]]+=1

#現時点での種類数とポイントを測定
sp=set()
ans=0
for i in range(k):
  ans+=li[i][1]
  sp.add(li[i][0])
sp=len(sp)
ans+=sp*sp

koukan=[] #その交換で、累積でどの程度増減するか
zouka=0
for a,b in zip(A,B):
  zouka+=(sp+1)**2-sp**2-(a-b)
  #print(a,b,sp,zouka)
  koukan.append(zouka)
  sp+=1

#koukanの中で最大の増加を探して、ansに+する。
# print(A,B)
# print(koukan)
ans+=max(0,max(koukan))

print(ans)
Problem p03160 (python)

Fixed submission:
n=int(input())
h=list(map(int,input().split()))
dp=[0,abs(h[1]-h[0])]
for i in range(n-2):
  way1=dp[i]+abs(h[i+2]-h[i])
  way2=dp[i+1]+abs(h[i+2]-h[i+1])
  dp.append(min(way1,way2))
#print(dp)
print(dp[n-1])

Buggy submission (verdict: Runtime Error):
n,k=map(int,input().split())
h=list(map(int,input().split()))
dp=[0]
#まず,足場k+1番目までについて,それぞれ最小コスト入れる
for i in range(k):
  dp.append(abs(h[i+1]-h[0]))

#k+2番目以降について,それぞれ最小コストを求める
for i in range(k+1,n):
  #最小のものの候補配列を作る
  temp=[]
  for j in range(k):
    temp.append(abs(h[i]-h[i-j-1])+dp[i-j-1])
  dp.append(min(temp))
print(dp[-1])
Problem p03161 (python)

Fixed submission:
n,k=map(int,input().split())
h=list(map(int,input().split()))
dp=[0]
#まず,足場k+1番目までについて,それぞれ最小コスト入れる
if n>k-1:
  for i in range(k):
    dp.append(abs(h[i+1]-h[0]))
else:
  print(abs(h[n-1]-h[0]))
  exit()


#k+2番目以降について,それぞれ最小コストを求める
for i in range(k+1,n):
  #最小のものの候補配列を作る
  temp=[]
  for j in range(k):
    temp.append(abs(h[i]-h[i-j-1])+dp[i-j-1])
  dp.append(min(temp))

print(dp[n-1])

Buggy submission (verdict: Runtime Error):
n,k=map(int,input().split())
h=list(map(int,input().split()))
dp=[0]
#まず,足場k+1番目までについて,それぞれ最小コスト入れる
for i in range(k):
  dp.append(abs(h[i+1]-h[0]))

#k+2番目以降について,それぞれ最小コストを求める
for i in range(k+1,n):
  #最小のものの候補配列を作る
  temp=[]
  for j in range(k):
    temp.append(abs(h[i]-h[i-j-1])+dp[i-j-1])
  dp.append(min(temp))

print(dp[n-1])

Buggy submission (verdict: Runtime Error):
n,k=map(int,input().split())
h=list(map(int,input().split()))
dp=[0]
#まず,足場k+1番目までについて,それぞれ最小コスト入れる
for i in range(k):
  dp.append(abs(h[i+1]-h[0]))

#k+2番目以降について,それぞれ最小コストを求める
for i in range(k+1,n):
  #最小のものの候補配列を作る
  temp=[]
  for j in range(k):
    temp.append(abs(h[i]-h[i-j-1])+dp[i-j-1])
  dp.append(min(temp))
print(dp[-1])

Buggy submission (verdict: Runtime Error):
n,k=map(int,input().split())
h=list(map(int,input().split()))
dp=[0]
#まず,足場k+1番目までについて,それぞれ最小コスト入れる
for i in range(k):
  dp.append(abs(h[i+1]-h[0]))

#k+2番目以降について,それぞれ最小コストを求める
for i in range(k+1,n):
  #最小のものの候補配列を作る
  temp=[]
  for j in range(k):
    temp.append(abs(h[i]-h[i-j-1])+dp[i-j-1])
  dp.append(min(temp))
print(dp[-1])
Problem p03472 (python)

Fixed submission:
n,h=map(int,input().split())
li=[tuple(map(int,input().split())) for i in range(n)]

zenbu=[]

for i in range(n):
  a=[li[i][0],"a"]
  b=[li[i][1],"b"]
  zenbu.append(a)
  zenbu.append(b)

zenbu.sort(reverse=True)

life=h
ans=0

import math
for i in range(n):
  if zenbu[i][1]=="b":
    life-=zenbu[i][0]
    ans+=1
    if life<=0:
      print(ans)
      exit()
  elif zenbu[i][1]=="a":
    print(ans+math.ceil(life/zenbu[i][0]))
    exit()
#以下、bを全部投げて足りない場合。この場合は残りを最大のaで割る
ali=[]
for i in range(n):
  ali.append(li[i][0])
ali.sort()

print(ans+math.ceil(life/ali[-1]))

Buggy submission (verdict: Runtime Error):
n,h=map(int,input().split())
li=[tuple(map(int,input().split())) for i in range(n)]

zenbu=[]

for i in range(n):
  a=[li[i][0],"a"]
  b=[li[i][1],"b"]
  zenbu.append(a)
  zenbu.append(b)

zenbu.sort(reverse=True)

life=h
ans=0

import math
for i in range(n):
  if zenbu[i][1]=="b":
    life-=zenbu[i][0]
    ans+=1
    if life<=0:
      print(ans)
      exit()
  elif zenbu[i][1]=="a":
    print(ans+math.ceil(life/zenbu[i][1]))
    exit()
#以下、bを全部投げて足りない場合。この場合は残りを最大のaで割る
ali=[]
for i in range(n):
  ali.append(li[i][0])
ali.sort()

print(ans+math.ceil(life/ali[-1]))
Problem p03612 (python)

Fixed submission:
n=int(input())
p=list(map(int,input().split()))
r=p[:]

ans=0
for i in range(n):
  if p[i]==i+1:
    ans+=1
    if i!=n-1:
      p[i]=r[i+1]
      p[i+1]=r[i]
      
print(ans)

Buggy submission (verdict: Runtime Error):
n=int(input())
p=list(map(int,input().split()))
r=p[:]

ans=0
for i in range(n):
  if p[i]==i+1:
    ans+=1
    p[i]=r[i+1]
    p[i+1]=r[i]
    
print(ans)
Problem p03624 (python)

Fixed submission:
import string
alp=string.ascii_lowercase

s=input()
for i in range(26):
  temp=alp[i]
  if temp not in s:
    print(temp)
    exit()
print("None")

Buggy submission (verdict: Runtime Error):
import string
alp=string.ascii_lowercase

s=input()
for i in range(28):
  temp=alp[i]
  if temp not in s:
    print(temp)
    exit()
print("None")
Problem p03625 (python)

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

from collections import Counter
a=Counter(a)
a=sorted(a.items(), reverse=True)

x=0
y=0

for p,q in a:
  if q>=4:
    if x==0:
      x=y=p
      break
    else:
      y=p
      break
  elif q>=2:
    if x==0:
      x=p
    else:
      y=p
      break
print(x*y)

Buggy submission (verdict: Runtime Error):
4
1 2 3 4

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

from collections import Counter
a=Counter(a).most_common()

li=[]
li4=[]

for x,y in a:
  if  y>=4:
    li4.append(x)
  elif y>=2:
    li.append(x)

li.sort()
li4.sort()

if len(li4)<1 and len(li)<2:
  print(0)
  exit()

x=0
if li4:
  x=(li4[-1])**2

y=li[-1]*li[-2]

print(max(x,y))
Problem p03720 (python)

Fixed submission:
n,m=map(int,input().split())
li=[0]*n
for i in range(m):
  a,b=map(int,input().split())
  li[a-1]+=1
  li[b-1]+=1
for i in li:
  print(i)

Buggy submission (verdict: Runtime Error):
n,m=map(int,input().split())
li=[0]*n
for i in range(n):
  a,b=map(int,input().split())
  li[a-1]+=1
  li[b-1]+=1
for i in li:
  print(i)
Problem p03853 (python)

Fixed submission:
h,w=map(int,input().split())
for i in range(h):
  a=input()
  print(a)
  print(a)

Buggy submission (verdict: Runtime Error):
h,w=map(int,input().split())
for i in range(w):
  a=input()
  print(a)
  print(a)
Problem p03862 (python)

Fixed submission:
n,x=map(int,input().split())
a=list(map(int,input().split()))
ans=0
for i in range(n-1):
  if a[i]+a[i+1]>x: #xを上回る時のみ操作を行う
    temp=a[i]+a[i+1]-x #減らさなきゃいけない個数
    ans+=temp
    if a[i+1]>=temp: #減らすのは出来るだけ右側
      a[i+1]-=temp
    else:
      a[i+1]=0
print(ans)

Buggy submission (verdict: Runtime Error):
n,x=map(int,input().split())
a=list(map(int,input().split()))
ans=0
for i in range(n-1):
  if a[i]+a[i+1]>x:　#xを上回る時のみ操作を行う
    temp=a[i]+a[i+1]-x #減らさなきゃいけない個数
    ans+=temp
    if a[i+1]>=temp: #減らすのは出来るだけ右側
      a[i+1]-=temp
    else:
      a[i+1]=0
print(ans)
Problem p02663 (python)

Fixed submission:
inputs = input()

H1, M1, H2, M2, K = [int(f) for f in inputs.split(" ")]

elapsedHour = H2 - H1
elapsedMin = M2 - M1

maxStudyStartTimeLength = elapsedHour * 60 + elapsedMin - K

print(maxStudyStartTimeLength)

Buggy submission (verdict: Runtime Error):
T = list(input())

x = 0
while len(T) != 0:
    x += sum([int(f) for f in T[::2]])

    xmax = 0
    delIdx = 0
    for i in range(len(T)):
        T_copy = T.copy()
        _tmp = T_copy.pop(i)

        _x = sum([int(f) for f in T_copy[::2]])

        if _x > xmax:
            xmax = _x
            delIdx = i

    T.pop(delIdx)

print(x)
Problem p02703 (python)

Fixed submission:
def Int():
    return int(input())
def Ints():
    return map(int,input().split())
def IntList():
    return list(Ints())
def IntMat(N):
    return [IntList() for i in range(N)]

N,M,S = Ints()
from collections import defaultdict
Graph  = defaultdict(list)

for i in range(M):
    u,v,a,b = Ints()
    Graph[u-1].append([v-1,a,b])
    Graph[v-1].append([u-1,a,b])

City = [0]*N
for i in range(N):
    c,d = Ints()
    City[i] = [c,d]

import heapq
que = []
# [time, nowhere, money, flag, visited]
heapq.heappush(que, [0, 0, min(S,5000)])
ans = [[10**16]*5001 for i in range(N)]
#Min = [[10**16]*5001 for i in range(N+1)]
#print(Graph)
while que != []:
    time, nowhere, money = heapq.heappop(que)
    #print('here',time,nowhere,money)
    if time <= ans[nowhere][money]:
        ans[nowhere][money] = time
        c,d = City[nowhere]
        if time+d < ans[nowhere][min(5000,money+c)]:
            ans[nowhere][min(5000,money+c)] = time+d
            #print('to',time+d, nowhere, min(5000,money+c))
            heapq.heappush(que, [time+d, nowhere, min(5000,money+c)])
        for (to,a,b) in Graph[nowhere]:
            if 0 <= money - a and time+b < ans[to][min(5000,money-a)]:
                ans[to][min(5000,money-a)] = time+b
                #print('to',time+b, to, min(5000,money-a))
                heapq.heappush(que, [time+b, to, min(5000,money-a)])

for i in range(1,N):
    print(min(ans[i]))

Buggy submission (verdict: Runtime Error):
def Int():
    return int(input())
def Ints():
    return map(int,input().split())
def IntList():
    return list(Ints())
def IntMat(N):
    return [IntList() for i in range(N)]

N,M,S = Ints()
from collections import defaultdict
Graph  = defaultdict(list)

for i in range(M):
    u,v,a,b = Ints()
    Graph[u].append([v,a,b])
    Graph[v].append([u,a,b])

City = [0]*N
for i in range(N):
    c,d = Ints()
    City[i] = [c,d]

import heapq
visited = [-1]*(N+1)
visited[0] = 1
que = []
# [time, nowhere, money, flag, visited]
heapq.heappush(que, [0, 1, S, 0])
ans = [-1]*(N+1)
Min = [[10**16]*5000 for i in range(N+1)]
#print(Graph)
while visited != [1]*(N+1):
    #print(que)
    time, nowhere, money, flag = heapq.heappop(que)
    #print(time, nowhere, money, flag)
    #route[nowhere] = 1
    Min[nowhere][money] = min(Min[nowhere][money], time)
    if visited[nowhere] == -1:
        visited[nowhere] = 1
        ans[nowhere] = time
    if flag == 0:
        c,d = City[nowhere-1]
        if money >= 5000:
            heapq.heappush(que, [time+d, nowhere, money+c, 1])
        else:
            heapq.heappush(que, [time+d, nowhere, money+c, 0])
    for (to,a,b) in Graph[nowhere]:
        #if not to in route:
        if money-a >= 0:
            if Min[to][money-a] > time+b:
                heapq.heappush(que, [time+b, to, money-a, flag])

for i in range(2,N+1):
    print(ans[i])
Problem p02742 (python)

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

if H==1 or W==1:
    print(1)
else:
    print((H*W+1)//2)

Buggy submission (verdict: Runtime Error):
H,W = int(input())
print((H*W+1)//2)
Problem p02743 (python)

Fixed submission:
a,b,c = map(int,input().split())

if a+b >= c:
    print('No')
elif 4*a*b < c**2 + (a+b)**2 - 2*(a+b)*c:
    print('Yes')
else:
    print('No')

Buggy submission (verdict: Runtime Error):
a,b,c = map(int,input().split())
if 4*a*b < c**2 + (a+b)**2 - 2*(a+b)*c
    print('Yes')
else:
    print('No')
Problem p02787 (python)

Fixed submission:
H,N = map(int,input().split())
AB = []
 
for i in range(N):
    a,b = map(int,input().split())
    AB.append([a,b])
INF = 10**15
dp = [[INF]*(2*10**4+1) for i in range(N+1)]
for i in range(N+1):
    dp[i][0] = 0
 
for i in range(N):
    for j in range(1,2*10**4+1):
        dp[i+1][j] = min(dp[i][j],dp[i+1][j-AB[i][0]]+AB[i][1])
        
ans = float('inf')
for i in range(H,2*10**4+1):
    ans = min(ans,dp[N][i])
print(ans)

Buggy submission (verdict: Runtime Error):
#include <vector> // vectorを使うためにインクルードする
#include <iostream>
using namespace std;

const int MAX_N = 1000;
const int MAX_M = 20000;

int n, H;
int w[MAX_N], v[MAX_N];
// dp[i+1][j]: i番目までの品物から重さの総和がj以下となるように選んだ時の,
// 価値の総和の最大値
int dp[MAX_N + 1][MAX_M + 1];

int main() {
    cin >> H;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> w[i] >> v[i];
    }

    for (int i = 0; i < n+1; i++) {
        for (int j = 0; j <= MAX_M+1; j++) {
            dp[i][j] = 100000000;
        }
    }
  for (int i = 0; i < n+1; i++) {
            dp[i][0] = 0;
    }
    
    for (int i = 0; i < n; i++) {
        for (int j = 0; j <= MAX_M; j++) {
            dp[i+1][j] = min(dp[i][j],dp[i+1][j-w[i]]+v[i]);
        }
    }
    int ans = 100000000;
  for (int i=H; i<MAX_M+1; i++){
  	ans = min(ans, dp[n][i]);
  }

    cout << ans << '\n';

    return 0;
}
Problem p02788 (python)

Fixed submission:
N,D,A = map(int,input().split())
XH = []
X = []

for i in range(N):
    x,h = map(int,input().split())
    XH.append([x,h,0])
    X.append(x)
    
XH.sort(key = lambda a:a[0])
XH.append([float('inf'),0,0])
X.sort()
X.append(float('inf'))

import bisect
ans = 0

for i in range(N):
    x,h,k = XH[i]
    dk = max(-(-(h-k*A)//A),0)
    #print(x,h,k,dk)
    ans += dk
    
    XH[i][2] += dk
    j = bisect.bisect_right(X,x+2*D)
    XH[j][2] -= dk

    XH[i+1][2] += XH[i][2]
    
print(ans)

Buggy submission (verdict: Runtime Error):
H,N = map(int,input().split())
AB = []
 
for i in range(N):
    a,b = map(int,input().split())
    AB.append([a,b])
    
INF = 10**15
M = 2*10**4

dp = [[INF]*(M+1) for i in range(N+1)]

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

for i in range(N):
    A,B = AB[i]
    for j in range(A):
        dp[i+1][j] = min(dp[i+1][j],dp[i][j])
    for j in range(H)
        dp[i+1][j+A] = min(dp[i][j+A], dp[i+1][j]+B, dp[i+1][j+A])
        
ans = INF
for i in range(H,M):
    ans = min(ans,dp[N][i])
print(ans)

Buggy submission (verdict: Runtime Error):
H,N = map(int,input().split())
AB = []
 
for i in range(N):
    a,b = map(int,input().split())
    AB.append([a,b])
INF = 10**15
dp = [[INF]*(2*10**4+1) for i in range(N+1)]
for i in range(N+1):
    dp[i][0] = 0
 
for i in range(N):
    for j in range(1,2*10**4+1):
        dp[i+1][j] = min(dp[i][j],dp[i+1][j-AB[i][0]]+AB[i][1])
        
ans = float('inf')
for i in range(H,2*10**4+1):
    ans = min(ans,dp[N][i])
print(ans)

Buggy submission (verdict: Runtime Error):
H,N = map(int,input().split())
AB = []
 
for i in range(N):
    a,b = map(int,input().split())
    AB.append([a,b])

dp = [[float('inf')]*(H+1) for i in range(N+1)]
for i in range(N+1):
    dp[i][0] = 0

for i in range(N):
    for j in range(H):
        dp[i+1][min(j+AB[i][0],H)] = min(dp[i][min(j+AB[i][0],H)],dp[i+1][j]+AB[i][1],dp[i+1][min(j+AB[i][0],H)])
        
print(dp[N][H])

Buggy submission (verdict: Runtime Error):
H,N = map(int,input().split())
AB = []
 
for i in range(N):
    a,b = map(int,input().split())
    AB.append([a,b])

dp = [[float('inf')]*(H+1) for i in range(N+1)]
for i in range(N+1):
    dp[i][0] = 0

for i in range(N):
    for j in range(H):
        dp[i+1][min(j+AB[i][0],H)] = min(dp[i][min(j+AB[i][0],H)],dp[i+1][j]+AB[i][1],dp[i+1][min(j+AB[i][0],H)])
        
print(dp[N][H])
Problem p03062 (python)

Fixed submission:
def main():
    import sys
    from fractions import gcd
    input = sys.stdin.readline
    N = int(input())
    A = list(map(int, input().split()))
    tmp = float("inf")
    S = 0
    count = 0
    for i in A:
        if tmp > abs(i):
            tmp = abs(i)
        if abs(i) != i:
            count += 1
        S += abs(i)
    if count%2 == 0:
        print(S)
    else:
        print(S-2*tmp)
    
main()

Buggy submission (verdict: Runtime Error):
def main():
    import sys
    from fractions import gcd
    input = sys.stdin.readline
    N = int(input())
    A = list(map(int, input().split()))
    tmp = float("inf")
    S = 0
    count = 0
    for i in A:
        if tmp > abs(A[i]):
            tmp = abs(A[i])
        if abs(A[i]) != A[i]:
            count += 1
        S += abs(A[i])
    if count%2 == 0:
        print(S)
    else:
        print(S-2*tmp)
    
main()
Problem p03260 (python)

Fixed submission:
A,B = map(int,input().split())
 
if A%2==1 and B%2==1:
    print("Yes")
else:
    print("No")

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

if A%2==1 and B%2==1:
    print("Yes")
else:
    print("No")
Problem p03354 (python)

Fixed submission:
class UnionFind:
    def __init__(self, n):
        self.par = [-1 for i in range(n+1)]
        self.rank = [0] * (n+1)

    # 検索
    def find(self, x):
        if self.par[x] < 0:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    # 併合
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if not x==y: # 根が同じでない場合のみ併合する
            if self.rank[x] < self.rank[y]:
                self.par[y] += self.par[x] # 要素数を併合
                self.par[x] = y # 根を付け替えている
            else:
                self.par[x] += self.par[y]
                self.par[y] = x
                if self.rank[x] == self.rank[y]:
                    self.rank[x] += 1
        
    # 同じ集合に属するか判定
    def same_check(self, x, y):
        return self.find(x) == self.find(y) 

def main():
    import sys
    input = sys.stdin.readline
    N,M = map(int,input().split())
    P = list(map(int,input().split()))
    XY = [list(map(int,input().split())) for i in range(M)]
    A = UnionFind(N)
    
    for i in range(M):
        x,y = XY[i]
        A.union(x,y)
        
    ans = 0
    for i in range(N):
        j = i+1
        p = P[i]
        if A.same_check(j,p):
            ans += 1
    print(ans)
    
    
    
main()

Buggy submission (verdict: Runtime Error):
class UnionFind:
    def __init__(self, n):
        self.par = [-1 for i in range(n+1)]
        self.rank = [0] * (n+1)

    # 検索
    def find(self, x):
        if self.par[x] < 0:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    # 併合
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if not x==y: # 根が同じでない場合のみ併合する
            if self.rank[x] < self.rank[y]:
                self.par[y] += self.par[x] # 要素数を併合
                self.par[x] = y # 根を付け替えている
            else:
                self.par[x] += self.par[y]
                self.par[y] = x
                if self.rank[x] == self.rank[y]:
                    self.rank[x] += 1
        
    # 同じ集合に属するか判定
    def same_check(self, x, y):
        return self.find(x) == self.find(y) 

def main():
    import sys
    input = sys.stdin.readline
    N,M = map(int,input().split())
    P = list(map(int,input().split()))
    XY = [list(map(int,input().split())) for i in range(M)]
    A = UnionFind(M)
    
    for i in range(M):
        x,y = XY[i]
        A.union(x,y)
        
    ans = 0
    for i in range(M):
        j = i+1
        p = P[i]
        if A.same_check(j,p):
            ans += 1
    print(ans)
    
    
    
main()
Problem p03379 (python)

Fixed submission:
N = int(input())
X = list(map(int,input().split()))
Y = sorted(X)
M = Y[N//2]
if N%2==1:
    M2 = Y[N//2 + 1]
    for i in range(N):
        if X[i] > M:
            print(M)
        else:
            print(M2)
else:
    M2 = Y[N//2 - 1]
    for i in range(N):
        if X[i] < M:
            print(M)
        else:
            print(M2)

Buggy submission (verdict: Runtime Error):
N = int(input())
X = list(map(int,input().split()))
M = N//2
m = (N-1)//2
for i in range(N):
    if i <= M:
        print(A[m+1])
    else:
        print(A[m])
Problem p03479 (python)

Fixed submission:
X,Y = map(int,input().split())
tmp = X
ans = 0
while tmp <= Y:
    ans += 1
    tmp *= 2
print(ans)

Buggy submission (verdict: Runtime Error):
X,Y = map(int,input().split())
import math
ans = int(math.log2(Y/X))+1
print(ans)