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

Fixed submission:
import sys

N = int(input())
li = list(map(int,input().split()))
li.reverse()

for i in range(N-1):
  if li[i+1] >= li[i]+2:
    print("No")
    sys.exit()
    
  elif li[i+1] == li[i]+1:
    li[i+1] = li[i]
    
  else: continue
    
print("Yes")

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

for i in range(N-1):
  if li[i+1] >= li[i]+2:
    print("No")
    sys.exit()
    
  elif li[i+1] == li[i]+1:
    li[i+1] = li[i]
    
  else: continue
    
print("Yes")
Problem p02958 (python)

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

num_sort = sorted(num)
ans = 0

for i in range(N):
  if num[i] == num_sort[i]:
    continue
  else:
    ans += 1
    
if ans <= 2:
  print("YES")
else:
  print("NO")

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

num_sort = num.sorted()
ans = 0

for i in range(N):
  if num[i] == num_sorted[i]:
    continue
  else:
    ans += 1
    
if ans <= 2:
  print("YES")
else:
  print("NO")

Buggy submission (verdict: Runtime Error):
N = int(input())
 
p = list()
 
p = map(int, input().split())
 
k = 0
 
for i in range(0, len(p)-1 ):
  if (p[i] > p[ i + 1 ]):
    k += 1
    
    
if ( k <= 1 ):
  print("YES")
else:
  print("NO")

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

p = list()

p = map(int, input().split())

k = 0

for i,number in enumerate(p):
  if (number > p[ i + 1 ]):
    k += 1

if ( k <= 1 ):
  print("YES")
else:
  print("NO")
Problem p02971 (python)

Fixed submission:
N = int(input())
li = [int(input()) for _ in range(N)]

lis = sorted(li)
for i in range(N):
  if lis[-1] == li[i]:
    print(lis[-2])
  else: print(lis[-1])

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

lis = sorted(li)
for i in range(N):
  if lis[-1] == li[i]:
    print(lis[-2])
  else: print(lis[-1])

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

lis = sorted(li)
for i in range(N):
  if lis[-1] == li[i]:
    print(lis[-2])
  else: print(lis[-1])

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

lis = li.sorted()
for i in range(N):
  if lis[-1] == li[i]:
    print(lis[-2])
  else: print(lis[-1])

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

number = list()

for i in range( N - 1 ):
  number.append(int(input()))

for i in range( N - 1 ):
  del number[i]
  print( max( number ) )
Problem p03029 (python)

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

P += 3*A
print(P//2)

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

P += 3*A
print(P//2)
Problem p03044 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10**7)

n = int(input())
G = [[] for _ in range(n)]
for i in range(n-1):
  uvw = list(map(int, input().split()))
  u = uvw[0]-1
  v = uvw[1]-1
  w = uvw[2]
  G[u].append([v, w])
  G[v].append([u, w])
  
color = [-1]*n
def dfs(G, v, cur = 0):
  if color[v] == -1:
    
    color[v] = cur
    for next_v, w in G[v]:
     
      if color[next_v]==-1:
        if (w % 2 != 0):
          dfs(G, next_v, 1-cur)
        if (w% 2 == 0):
          dfs(G, next_v, cur)
        continue
      


        

for v in range(n):
  if color[v] != -1:
    continue
  else:
    dfs(G, v)


print(*color, sep='\n')

Buggy submission (verdict: Runtime Error):
n = int(input())
G = [[] for _ in range(n)]
for i in range(n-1):
  uvw = list(map(int, input().split()))
  u = uvw[0]-1
  v = uvw[1]-1
  w = uvw[2]
  G[u].append([v, w])
  G[v].append([u, w])
  
color = [-1]*n
def dfs(G, v, cur = 0):
  if color[v] == -1:
    
    color[v] = cur
    for next_v, w in G[v]:
     
      if color[next_v]==-1:
        if (w % 2 != 0):
          dfs(G, next_v, 1-cur)
        if (w% 2 == 0):
          dfs(G, next_v, cur)
        continue
      


        

for v in range(n):
  if color[v] != -1:
    continue
  else:
    dfs(G, v)


print(*color, sep='\n')
Problem p03102 (python)

Fixed submission:
N, M, K =map(int,input().split())
bases = list(map(int,input().split()))
ans=0

for i in range(N):
  a= list(map(int,input().split()))
  tmp=0
  for j in range(M):
    tmp+= bases[j]*a[j]
  
  if tmp+K>0:
    ans+=1
    
print(ans)

Buggy submission (verdict: Runtime Error):
N, M, K =map(int,input().aplit())
bases = list(map(int,input().split()))
ans=0

for i in range(M):
  A = list(map(int,input().split()))
  tmp=0
  for j in range(3):
    tmp+= bases[j]*A[j]
  if tmp>0:
    ans+=1
    
print(ans)

Buggy submission (verdict: Runtime Error):
N, M, K =map(int,input().aplit())
bases = list(map(int,input()))
ans=0

for i in range(M):
  A = list(map(int,input().split()))
  tmp=0
  for j in range(3):
    tmp+= bases[j]*A[j]
  if tmp>0:
    ans+=1
    
print(ans)

Buggy submission (verdict: Runtime Error):
N, M, K =map(int().input().aplit())
bases = list(map(int,input()))
ans=0

for i in range(M):
  A = list(map(int,input().split()))
  tmp=0
  for j in range(3):
    tmp+= bases[j]*A[j]
  if tmp>0:
    ans+=1
    
print(ans)
Problem p03106 (python)

Fixed submission:
A,B,K = map(int,input().split())
li = []

for i in range(1,min(A,B)+1):
  if A % i == 0 and B % i == 0:
    li.append(i)

print(li[len(li)-K])

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

for i in range(1,min(A,B)):
  if A % i == 0 and B % i == 0:
    li.append(i)
    
print(li[K-1])
Problem p03160 (python)

Fixed submission:
N = int(input())

cost = [int(i) for i in input().split()]

dp = [0]*N

dp[1] = abs(cost[0] - cost[1])

for i in range(2,N):
  dp[i] = min (dp[i-1] + abs(cost[i] - cost[i-1]), dp[i-2] + abs(cost[i-2] - cost[i]))
  
print(dp[-1])

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

cost = [int(input()) for _ in range(N)]

Sum = list(0,abs(cost[0]-cost[1]))

for i in range(2,N):
  Sum[i] = min(Sum[i-1] + abs(cost[i]-cost[i-1]), Sum[i-2] + abs(Sum[i-2] - Sum[i]))
  
print(Sum[N-1])
Problem p03161 (python)

Fixed submission:
import numpy as np

N,K = map(int, input().split())
h = np.array(list(map(int,input().split())))

dp = np.zeros(N, dtype = int)

for i in range(1,N):
  s = max(i-K,0)
  dp[i] = np.min(dp[s:i]+ np.abs(h[s:i] - h[i]))
  
print(dp[-1])

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

N,K = map(int, input().split())
h = np.array(list(map(int,input().split())))

dp = np.zeros(N, dtype = int)

for i in range(1,N):
  s = max(i-k,0)
  dp[i] = np.min(dp[s:i]+ np.abs(h[s:i] - h[i]))
  
print(dp[-1])

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

N,K = map(int, input().split())
h = np.array(list(map(int,input().split())))

dp = np.zeros(N, dtype = int)

for i in range(1,N):
  s = max(i-k,0)
  dp[i] = np.min(dp[s:i]+ np.abs(h[s:i] - h[i]))
  
print(dp[-1])

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

dp = [float('inf') for i in range(N-1)]

for i in range(N-1):
  for j in range(1,K+1):
    if i+j>N: continue
    dp[i+j] = min(dp[i+j], dp[i]+abs(h[i]-h[i+j]))
    
print(dp[-1])

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

dp = [[] for i in range(N)]

for i in range(N-1):
  for j in range(1,K+1):
    dp[i+j] = min(dp[i] + abs(h[i] - h[i+j]), dp[i+j])
    
print(dp[-1])
Problem p03162 (python)

Fixed submission:
N = int(input())
li = [list(map(int,input().split())) for _ in range(N)]

dp = [[0,0,0] for _ in range(N)]
dp[0] = li[0]

for i in range(N-1):
  for j in range(3):
    for k in range(3):
      if j == k: continue
      dp[i+1][j] = max(dp[i+1][j], dp[i][k] + li[i+1][j])
print(max(dp[-1]))

Buggy submission (verdict: Runtime Error):
N = int(input())
li = [list(map(int,input().split())) for _ in range(N)]

dp = [0,0,0]*N
dp[0] = li[0]

for i in range(N-1):
  for j in range(3):
    for k in range(3):
      if j == k: continue
      dp[i+1][j] = dp[i][k] + li[i+1][j]
print(max(dp[-1]))

Buggy submission (verdict: Runtime Error):
N = int(input())
A = B = C = 0

for i in range(N):
  a,b,c = map(int,input())
  A,B,C = max(B + a,C+a),max(A+b,C+b),max(A+c,B+c)
 
print(max(A,B,C))
Problem p03163 (python)

Fixed submission:
import numpy as np

N,W = map(int,input().split())

item = [list(map(int,input().split())) for _ in range(N)]

val = np.zeros(W+1,dtype = int)

for i in range(N):
  item_weight = item[i][0]
  val[item_weight :] = np.maximum(val[item_weight :], val[:-item_weight] + item[i][1])
  
print(max(val))

Buggy submission (verdict: Runtime Error):
N,W = map(int,input().split())
li = [list(map(int,input().split())) for _ in range(N)]

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

for i in range(N):
  for j in range(W+1):
    if j < li[i][0]: continue
    
    dp[i+1][j] = max(dp[i+1][j], dp[i][j-li[i][0]] + li[i+1][1])
    
print(dp[-1][-1])
Problem p03244 (python)

Fixed submission:
from collections import Counter

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

v1 = []
v2 = []

for i, v in enumerate(V):
    if i % 2 == 0:
       v1.append(v)
    else:
        v2.append(v)

v1c = Counter(v1).most_common()
v2c = Counter(v2).most_common()

k1, v1 = v1c[0][0], v1c[0][1]
k2, v2 = v2c[0][0], v2c[0][1]

if k1 == k2:
    ans -= v2
    m = 0
    if len(v1c) >= 2:
        m = max(m, v1c[1][1])
    if len(v2c) >= 2:
        m = max(m, v2c[1][1])
    ans -= m
else:
    ans -= v1 + v2

print(ans)

Buggy submission (verdict: Runtime Error):
import collections

N = int(input())
li = list(map(int,input().split()))
even = [li[i] for i in range(N) if i%2==0]
odd =[ li[i] for i in range(N) if i%2!=0]

e = collections.Counter(even).most_common()
o = collections.Counter(odd).most_common()

ec=e[0][1]
oc=o[0][1]

if e[0][0]==o[0][0]:
  if e[0][1] > o[0][1]:
    oc=o[1][1]
  else:
    ec=e[1][1]
    
ans = N-(ec+oc)
print(ans)

Buggy submission (verdict: Runtime Error):
import collections

N = int(input())
even = [input() for i in range(N) if i%2==0]
odd =[ input() for i in range(N) if i%2!=0]

e = collections.Counter(even)
o = collections.Counter(odd)

ec=e[0][1]
oc=o[0][1]

if e[0][0]==o[0][0]:
  if e[0][1] > o[0][1]:
    oc=o[1][1]
  else:
    ec=e[1][1]
    
ans = N-(ec+oc)
print(ans)
Problem p03292 (python)

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

print(max(a)-min(a))

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

print(max(a)-min(a))
Problem p03316 (python)

Fixed submission:
N = int(input())
S = 0
n = N

while n != 0:
  S += n % 10
  n //= 10
  
if N % S == 0:
  print("Yes")
else: print("No")

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

while n != 1:
  S += n % 10
  n //= 10
  
if N % S == 0:
  print("Yes")
else: print("No")

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

while n > 1:
  S += n % 10
  n //= 10
  
if N % S == 0:
  print("Yes")
else: print("No")
Problem p03399 (python)

Fixed submission:
A,B,C,D = [int(input()) for _ in range(4)]

print(min(A,B)+min(C,D))

Buggy submission (verdict: Runtime Error):
A,B,C,D = [int(input) for _ in range(4)]

print(min(A,B)+min(C,D))

Buggy submission (verdict: Runtime Error):
A,B,C,D = [int(input) for _ in range(4)]

print(min(A,B)+min(C,D)
Problem p03408 (python)

Fixed submission:
s = [input() for _ in range(int(input()))]
t = [input() for _ in range(int(input()))]

l = list(set(s))

print(max(0, max(s.count(l[i]) - t.count(l[i]) for i in range(len(l)))))

Buggy submission (verdict: Runtime Error):
s = [input() for _ in range(int(input))]
t = [input() for _ in range(int(input))]

l = list(set(s))

print(max(0, max(s.count(l[i]) - t.count(l[i]) for i in range(len(l)))))
Problem p03433 (python)

Fixed submission:
N = int(input())
A = int(input())

if (N >= 500):
    amari = N % 500
    if ( A >= amari):
        print("Yes")
    else:
        print("No")

else:
    if ( A >= N):
        print("Yes")
    else:
        print("No")

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

amari =　N % 500

if ( A >= amari):
    print("Yes")
else:
    print("No")
Problem p03470 (python)

Fixed submission:
N = int(input())
num = list()

for i in range (N):
  d = int (input())
  num.append(d)
  
print(len(set(num)))

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

for i in range(0,N-1):
  d = int(input())
  num[d] = 1
  
res = 0
for i in range (0,101):
  res += num[i]
  
print(res)

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

for i in range(0,N-1):
  d = int(input())
  num[d] = 1
  
res = 0
for i in range (0,N-1):
  res += num[i]
  
print(res)
Problem p03478 (python)

Fixed submission:
def findSUM(n):
    sum = 0
    while (n > 0):
        sum += n % 10
        n //= 10
    return sum

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

total = 0
for i in range(N+1):
    sum = findSUM(i)
    if (sum >= A and sum <= B):
        total += i

print(total)

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

for i in range(N):
  temp = 0
  
  while (a >= 10):
  
  	temp += i % 10
  	a = i // 10
  temp += a
  
  if (temp >= A and temp <= B):
    res += temp
    
print(res)
Problem p03494 (python)

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

ans=0
while all(a%2==0 for a in A):
  A = [a/2 for a in A]
  ans+=1
  
print(ans)

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

ans=0
while all(a%2==0 for a in A):
  A = [a/2 for a in A]
  ans+=1
  
print(ans)

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

ans=0
while all(a%2==0 for a in A):
  A = [a/2 for a in A]
  ans+=1
  
print(ans)
Problem p03502 (python)

Fixed submission:
def findSUM(n):
  sum = 0
  while( n > 0 ):
    sum += n % 10
    n //= 10
  return sum

N = int(input())

f = findSUM(N)
if (N % f == 0):
  print("Yes")
else:
  print("No")

Buggy submission (verdict: Runtime Error):
def findSUM(n):
  sum = 0
  while( n > 0 ):
    sum += n % 10
    n //= 10
  return sum

N = int(input().split())

f = findSUM(N)
if (N % f == 0):
  print("Yes")
else:
  print("No")
Problem p03636 (python)

Fixed submission:
s = input()

a = s[0]
b = str(len(s) -2)
c = s[-1]

ans = [a,b,c]
res = "".join(ans)
print(res)

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

print({}{}{}).format(s[0],len(s)-2,s[-1])
Problem p03693 (python)

Fixed submission:
r, g, b = map(int , input().split())

rgb = 100*r + 10*g + b

if (rgb % 4 == 0):
    print("YES")
else:
    print("NO")

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

if (rgb % 4 == 0):
    print("YES")
else:
    print("NO")
Problem p04030 (python)

Fixed submission:
s = list(input())
ans=[]

for i in s:
  if i == "0":
    ans.append("0")
  elif i == "1":
    ans.append("1")
  else:
    if len(ans) == 0: continue
    else: ans.pop()
    
print(*ans,sep ="")

Buggy submission (verdict: Runtime Error):
s = list(input())
ans=[]

for i in s:
  if i == "0":
    ans.append("0")
  elif i == "1":
    ans.append("1")
  else:
    ans.pop()
    
print(ans,sep ="")
Problem p04031 (python)

Fixed submission:
def cul(li,s):
  a = 0
  for i in li:
    a += (i - s)**2
  
  return a

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

s1 = sum(li)//len(li)
s2 = s1 + 1

ans1 = cul(li,s1)
ans2 = cul(li,s2)

print(min(ans1,ans2))

Buggy submission (verdict: Runtime Error):
def cul(li,s):
  for i in li:
    a += (i - s)^2
  return a

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

s1 = sum(li)//len(li)
s2 = s1 + 1

ans1 = cul(li,s1)
ans2 = cul(li,s2)

print(min(ans1,ans2))
Problem p04044 (python)

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

words = list()
for i in range(N):
  words.append(input())
  
words.sort()

print(*words,sep ="")

Buggy submission (verdict: Runtime Error):
N,L = map(str,input().split())

words = list()
for i in range(N):
  words.append(input())
  
words.sort()

print(*words,sep ="")

Buggy submission (verdict: Runtime Error):
N,L = map(str,input().split())

words = list()
for i in range(N):
  words.append(input())
  
words = words.sort()

print(*words,sep ="")

Buggy submission (verdict: Runtime Error):
N,L = map(str,input().split())

words = list()
for i in range(N):
  words.append(input())
  
words.sort()

print(*words,seq ="")

Buggy submission (verdict: Runtime Error):
N,L = map(str,input().split())

words = list()
for i in range(N):
  words.append(input())
  
words = words.sort()

print(*words,seq ="")
Problem p02802 (python)

Fixed submission:
from sys import stdin as s
n,m=map(int,s.readline().split())
l=[0]*n
wa=[0]*n
cor,pen=0,0
for i in range(m):
  x,y=s.readline().split()
  x=int(x)-1
  if y=="AC":
    l[x]=1
  elif not l[x]:
    wa[x]+=1
for i in range(n):
  if l[i]:
    cor+=1
    pen+=wa[i]
print(cor,pen)

Buggy submission (verdict: Runtime Error):
from sys import stdin as s
n,m=map(int,s.readline().split())
l=[0]*n
wa=[0]*n
cor,pen=0
for i in range(m):
  x,y=s.readline().split()
  x=int(x)-1
  if y=="AC":
    l[x]=1
  elif not l[x]:
    wa[x]+=1
for i in range(n):
  if l[i]:
    cor+=1
    pen+=wa[i]
print(cor,pen)
Problem p02865 (python)

Fixed submission:
n=int(input())
print((n-1)//2)

Buggy submission (verdict: Runtime Error):
n=int(input())
t=tuple(map(int,input().split()))
while True:
  if t[0]!=0:
    print(0)
    break
  m=max(t)
  a=tuple(t.count(i) for i in range(m+1))
  if a[0]!=1:
    print(0)
    break
  s=1
  for i in range(m):
    s=(s*(a[i]**a[i+1]))%998244353
  print(s)
  break
Problem p02885 (python)

Fixed submission:
l = list(map(int, input().split()))
a = l[0]
b = l[1]
s = a - 2*b
if s < 0:
  print(0)
else:
  print(s)

Buggy submission (verdict: Runtime Error):
n=int(input())
l=list(map(int,input().split()))
d={i:l.count(i) for i in set(l)}
t=tuple(l.keys())
m=len(t)
T=0
for i in range(m-2):
  a=t[i]
  for j in range(m-i-1):
    b=t[i+j+1]
    for k in range(m-i-j-2):
      c=t[i+j+k+2]
      if a<b+c and b<c+a and c<a+b:
        T+=d{a}*d{b}*d{c}
print(T)

Buggy submission (verdict: Runtime Error):
n = int(input())
t = tuple(map(int, input().split()))
T = 0
for i in range(n-2):
  a = t[i]
  for j in range(n-i-1):
    b = t[i+j+1]
    for k in range(n-i-j-2):
      c = t[i+j+k+2]
      m = max(a,b,c)
      if m < a+b+c-m :
        T += 1
print(T)
Problem p02909 (python)

Fixed submission:
WeatherToday = input()
if WeatherToday == "Sunny":
  print("Cloudy")
elif WeatherToday == "Cloudy":
  print("Rainy")
else:
  print("Sunny")

Buggy submission (verdict: Runtime Error):
WeatherToady = input()
if WeatherToday == "Sunny":
  print("Cloudy")
elif WeatherToday == "Cloudy":
  print("Rainy")
else:
  print("Sunny")

Buggy submission (verdict: Runtime Error):
WeatherToady = input("")
if WeatherToday == "Sunny":
  return "Cloudy"
elif WeatherToday == "Cloudy":
  return "Rainy"
else:
  return "Sunny"

Buggy submission (verdict: Runtime Error):
WeatherToady = input()
if WeatherToday == "Sunny":
  return "Cloudy"
elif WeatherToday == "Cloudy":
  return "Rainy"
else:
  return "Sunny"

Buggy submission (verdict: Runtime Error):
WeatherToady = input()
if WeatherToday == "Sunny":
  return("Cloudy")
elif WeatherToday == "Cloudy":
  return("Rainy")
else:
  return("Sunny")
Problem p02921 (python)

Fixed submission:
A = input()
B = input()
x = 0
for i in range(3):
  if A[i] == B[i]:
    x += 1
print(x)

Buggy submission (verdict: Runtime Error):
A = input()
B = input()
x = 0
for i in range(3):
  if a(i) == b(i):
    x += 1
print(x)
Problem p02945 (python)

Fixed submission:
a, b = map(int, input().split())
print(max(a+b, a-b, a*b))

Buggy submission (verdict: Runtime Error):
a, b = int(input().split())
print(max(a+b, a-b, a*b))

Buggy submission (verdict: Runtime Error):
a = int(input())
b = int(input())
print(max(a+b, a-b, a*b))
Problem p02628 (python)

Fixed submission:
n, k = map(int, input().split())
a = sorted(list(map(int, input().split())))
print(sum(a[:k]))

Buggy submission (verdict: Runtime Error):
n, k = map(int, input().split())
a = list(map(int, input().split())).sort()
print(sum(a[:k]))

Buggy submission (verdict: Runtime Error):
n, k = map(int, input().split())
a = list(map(int, input().split()))
sorted(a)
print(sum(a[:k])
Problem p02996 (python)

Fixed submission:
N = int(input())

task = []
M = 0
for _ in range(N):
    a, b = map(int, input().split())
    task.append((b, a))

task.sort()

s = 0
ans = 'Yes'
for a, b in task:
    s += b
    if s > a:
        ans = 'No'
        break
print(ans)

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

task = [0] * (10 ** 9 + 1)
M = 0
for _ in range(N):
    a, b = map(int, input().split())
    task[b] += a
    if b > M:
        M = b

t = 0
ans = 'Yes'
for i in range(M+1):
    t += task[i]
    if t > i:
        ans = 'No'
        break

print(ans)
Problem p03032 (python)

Fixed submission:
N, K = map(int, input().split())
V = [int(i) for i in input().split()]
L = [0] * (N+1)
R = [0] * (N+1)
L_m = [[] for _ in range(N+1)]
R_m = [[] for _ in range(N+1)]

for i in range(1, N+1):
    L[i] = L[i-1] + V[i-1]
    R[i] = R[i-1] + V[-i]
    L_m[i] = L_m[i-1].copy()
    R_m[i] = R_m[i-1].copy()
    if V[i-1] < 0:
        L_m[i].append(V[i-1])
    if V[-i] < 0:
        R_m[i].append(V[-i])

ans = 0

for i in range(K+1):
    for l in range(K+1-i):
        r = K - i - l
        if l + r >= N:
            ans = max(ans, R[-1] - sum(R_m[-1]))
            break
        if r < 0:
            break
        M = L_m[l] + R_m[r]
        M.sort()
        if len(M) >= i:
            m = sum(M[:i])
        else:
            m = sum(M)
        a = L[l] + R[r] - m
        ans = max(ans, a)

print(ans)

Buggy submission (verdict: Runtime Error):
N, K = map(int, input().split())
V = [int(i) for i in input().split()]
L = [0] * (N+1)
R = [0] * (N+1)
L_m = [[] for _ in range(N+1)]
R_m = [[] for _ in range(N+1)]

for i in range(1, N+1):
    L[i] = L[i-1] + V[i-1]
    R[i] = R[i-1] + V[-i]
    L_m[i] = L_m[i-1].copy()
    R_m[i] = R_m[i-1].copy()
    if V[i-1] < 0:
        L_m[i].append(V[i-1])
    if V[-i] < 0:
        R_m[i].append(V[-i])

ans = 0

for i in range(K+1):
    for l in range(K+1-i):
        r = K - i - l
        if l + r >= N:
            ans = max(ans, R[-1] - sum(R_m[-1]))
            break
        if r < 0:
            break
        M = L_m[l] + R_m[r]
        M.sort()
        if len(M) >= i:
            m = sum(M[:i])
        else:
            m = sum(M)
        a = L[l] + R[r] - m
        ans = max(ans, a)

print(ans)

Buggy submission (verdict: Runtime Error):
N, K = map(int, input().split())
V = [int(i) for i in input().split()]
L = [0] * (N+1)
R = [0] * (N+1)
L_m = [[] for _ in range(N+1)]
R_m = [[] for _ in range(N+1)]

for i in range(1, N+1):
    L[i] = L[i-1] + V[i-1]
    R[i] = R[i-1] + V[-i]
    L_m[i] = L_m[i-1].copy()
    R_m[i] = R_m[i-1].copy()
    if V[i-1] < 0:
        L_m[i].append(V[i-1])
    if V[-i] < 0:
        R_m[i].append(V[-i])

ans = 0

for i in range(K+1):    # 消せるマイナスの数
    for l in range(K+1-i):
        r = K - i - l
        if l + r > N or r < 0:
            break
        M = L_m[l] + R_m[r]
        M.sort()
        if len(M) >= i:
            m = sum(M[:i])
            a = L[l] + R[r] - m
            ans = max(ans, a)

print(ans)