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

Fixed submission:
A, B, C, X, Y = map(int, input().split())
cost = 0
if A + B <= 2 * C:
    cost = A * X + B * Y
elif A + B > 2 * C:
    if X > Y:
        cost = C * 2 * Y
        if 2 * C < A:
            cost += 2 * C * (X - Y)
        else:
            cost += A * (X - Y)
    elif Y >= X:
        cost = C * 2 * X
        if 2 * C < B:
            cost += 2 * C * (Y - X)
        else:
            cost += B * (Y - X)
print(cost)

Buggy submission (verdict: Runtime Error):
A, B, C, X, Y = map(int, input().split())
 
cost = 0
 
if A + B <= 2 * C:
    cost = A * X + B * Y
elif A + B > 2 * C:
    if X > Y:
        cost = C * 2 * Y
        if 2 * C < A:
            cost += 2 * C * (X - Y)
        else:
            cost += A * (X - Y)
    elif Y >= X:
        cost = C * 2 * X
        if 2 * C < B:
            cost += 2 * C * (Y - X)
        else:
            cost += B * (Y - X)
print(cost)
A, B, C, X, Y = map(int, input().split())

cost = 0

if A + B <= 2 * C:
    cost = A * X + B * Y
elif A + B > 2 * C:
    if X > Y:
        cost = C * 2 * Y
        if 2 * C < A:
            cost += 2 * C * (X - Y)
        else:
            cost += A * (X - Y)
    elif Y >= X:
        cost = C * 2 * X
        if 2 * C < B:
            cost += 2 * C * (Y - X)
        else:
            cost += B * (Y - X)
print(cost)
Problem p03485 (python)

Fixed submission:
a,b = map(int,input().split())
if (a+b)//2 == (a+b)/2:
  print((a+b)//2)
else:
  print((a+b)//2 + 1)

Buggy submission (verdict: Runtime Error):
s = input()
t = input()
ss = sorted(s)
tt = sorted(t,reverse=True)
for n, w in zip(ss,tt):
  if n < w:
    print("Yes")
    exit()
  elif n > w:
    print("No")
    exit()
if len(ss) > len(tt):
  print("No")
else:
  print("Yes")
Problem p03493 (python)

Fixed submission:
print(input().count("1"))

Buggy submission (verdict: Runtime Error):
n,k = map(int,input().split())
a = list(map(int,input().split()))
b = set(a)
c = []
for i in b:
  c.append(a.count(i))
c.sort(reverse=True)
#if len(c) == k:
  #print(0)
#else:
print(sum(c[k:]))
Problem p03597 (python)

Fixed submission:
n = int(input())
a = int(input())
print(n**2-a)

Buggy submission (verdict: Runtime Error):
A,B,C,D,E,F = map(int,input().split())
W=set()
for a in range(0,F+1,100*A):
    for b in range(0,F+1-a,100*B):
        W.add(a+b)
S=set()
for c in range(0,F+1,C):
    for d in range(0,F+1,D):
        S.add(c+d)
rate = -1
for w in W:
    for s in S:
        if 0 < w+s <= F and s <= w*E//100:
            if s/(w+s) > rate:
                rate = s/(w+s)
                ans = w+s, s
print(ans[0],ans[1])
Problem p03607 (python)

Fixed submission:
n = int(input())
a = [int(input()) for i in range(n)]
wordcount = {}
for i in a:
  if i in wordcount:
    del wordcount[i]
  else:
    wordcount[i] = 1
print(len(wordcount))

Buggy submission (verdict: Runtime Error):
n = int(input())
a = [int(input()) for i in range(n)]
A = [0]*10000000
for i in a:
  if A[i] == 0:
    A[i] = 1
  else:
    A[i] = 0
print(A.count(1))

Buggy submission (verdict: Runtime Error):
n = int(input())
a = [int(input()) for i in range(n)]
A = [0]*100000
for i in a:
  if A[i] == 0:
    A[i] = 1
  else:
    A[i] = 0
print(A.count(1))
Problem p03739 (python)

Fixed submission:
n = int(input())
a = list(map(int,input().split()))
ans1,ans2 = 0,0
sum1,sum2 = 0,0
for i in range(n):
    sum1 += a[i]
    if i%2 == 1 and sum1 >= 0:
        ans1 += sum1 + 1
        sum1 = -1
    elif i%2 == 0 and sum1 <= 0:
        ans1 += -sum1 + 1
        sum1 = 1
for i in range(n):
    sum2 += a[i]
    if i%2 == 0 and sum2 >= 0:
        ans2 += sum2 + 1
        sum2 = -1
    elif i%2 == 1 and sum2 <= 0:
        ans2 += -sum2 + 1
        sum2 = 1
print(min(ans1,ans2))

Buggy submission (verdict: Runtime Error):
a = list(map(int,input().split()))
def judge(count):
  idx = 0
  for i in range(2,n+1):
    if count == -1:
      if sum(a[0:i]) < 0:
        pass
      else:
        check = sum(a[0:i]) + 1
        j = a[i-1]
        a[i-1] = j - check
        idx += check
    elif count == 1:
      if sum(a[0:i]) > 0:
        pass
      else:
        check = 1 - sum(a[0:i])
        j = a[i-1]
        a[i-1] = check+ j
        idx += check
    count *= -1
  return idx
if a[0] > 0:
  b = judge(-1)
  print(b)
elif a[0] < 0:
  c = judge(1)
  print(c)
else:
  a[0] = 1
  b = judge(-1)
  a[0] = -1
  c = judge(1)
  print(min(b,c))
Problem p02818 (python)

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

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

if a+b<k:
  print(0,0)
elif a<k:
  print(0,b+a-k)
else:
  print(a-k,b)

print("{} {}".format(a, b))
Problem p03000 (python)

Fixed submission:
n, x = map(int, input().split())
li = list(map(int, input().split()))
res = 0
cnt = 1

for i in li:
  res += i
  if res > x:
    break

  cnt += 1

print(cnt)

Buggy submission (verdict: Runtime Error):
n, x = map(int, input().split())
li = list(map(int, input().split()))
res = 0
index = 0

while res <= x:
  res += li[index]
  index += 1

print(index)
Problem p03086 (python)

Fixed submission:
s = input()
acgt = ["A","C","G","T"]
res = []
parts = ""

for i in range(len(s)):
    parts = ""
    for c in s[i:]:
        if c in acgt:
            parts += c
        else:
            break
    res.append(len(parts))

print(max(res))

Buggy submission (verdict: Runtime Error):
s = input()
count = 0
lens = []

for i, _ in enumerate(s):
  for c in s[i:]:
    if c in ['A', 'G', 'C', 'T']:
      count += 1
  	else:
      break
  lens.append(count)
  count = 0
  
print(max(lens))

Buggy submission (verdict: Runtime Error):
s = input()
acgt = ["A","C","G","T"]
res = []
parts = ""

for i in range(len(s)):
    parts = ""
    for c in s[i:]:
        if c in acgt:
            parts += c
        else:
            res.append(len(parts))
            break

print(max(res))
Problem p02844 (python)

Fixed submission:
N = int(input())
s  = input().strip()

cnt = 0
for key in range(1000):
    key = '{:0>3}'.format(str(key))    #; print(key)
    i0 = s.find(key[0])
    if 0 <= i0 < N-2:
        i1 = s.find(key[1], i0+1)
        if 0 < i1 < N-1:
            i2 = s.find(key[2], i1+1)
            if i2 != -1:
                cnt += 1
            else:
                continue
        else:
            continue        
    else:
        continue
                                   
print(cnt)

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

S = set()
for c in combinations(range(N), N-3):
    i0 = 0; x = ''
    for i in c:
        x += s[i0:i]
        i0 = i+1
    x += s[i0:]
    S.add(x)                                  
print(len(S))   #; print(S)
Problem p02856 (python)

Fixed submission:
mat = [[[0, 0]]*10 for _ in range(10)]
def dsr(i):
    x, cnt = 0, 0
    for j in range(10):
        w = x + i
        if w > 9:
            x = w - 9
            cnt += 2
        else:
            x = w
            cnt += 1
        mat[i][j] = [x, cnt-1]
    #mat[i][0][0] = mat[i][9][0]
    x0 = mat[i][9][1] - mat[i][8][1]   #; print('x0', x0)
    for j in range(10):
        mat[i][j][1] += x0 

for i in range(10):
    dsr(i)
#print2(mat)

m = int(input())
cnt = 0; x0 = 0   
for _ in range(m):
    d, c = map(int, input().split())
    q, r = divmod(c-1, 9)
    cnt += mat[d][8][1]*q + mat[d][r][1] - mat[d][0][1] 
    x = mat[d][r][0]
    #print('x, cnt', x, cnt)
    w = x0 + x
    if w > 9:
        x0 = w - 9
        cnt += 2
    else:
        x0 = w
        cnt += 1
    #print('x0, x, cnt', x0, x,  cnt)    
print(cnt-1)

Buggy submission (verdict: Runtime Error):
m = int(input())
a = []
for _ in range(m):
    d, c = map(int, input().split())
    a.extend([d]*c)
#print(a)

cnt = 0
for i in range(len(a)-1):
    w = a[i]+a[i+1] 
    if w > 9:
        a[i+1] = w - 9
        cnt += 2
    else:
        a[i+1] = w
        cnt += 1
#print(a)
print(cnt)
Problem p02936 (python)

Fixed submission:
def dfs(u, cnt):
    cnt += point[u]
    counter[u] = cnt
    color[u] = GRAY
    for v in M[u]:
        if color[v] == WHITE:
            dfs(v, cnt)
    color[u] = BLACK

import sys
sys.setrecursionlimit(1000000)

n, q = map(int, input().split())
M = [[] for _ in range(n)]
point = [0] * n
for i in range(n-1):
    a, b = map(int, input().split())
    M[a-1].append(b-1)
    M[b-1].append(a-1)
for i in range(q):
    p, x = map(int, input().split())
    point[p-1] += x
#print(M, point)
    
WHITE, GRAY, BLACK = 0, 1, 2
color = [WHITE] * n

counter = [0] * n
dfs(0, 0)

print(*counter)

Buggy submission (verdict: Runtime Error):
def dfs(u, cnt):
    cnt += point[u]
    counter[u] = cnt
    color[u] = GRAY
    for v in M[u]:
        if color[v] == WHITE:
            dfs(v, cnt)
    color[u] = BLACK

import sys
sys.setrecursionlimit(100000)

n, q = map(int, input().split())
M = [[] for _ in range(n)]
point = [0] * n
for i in range(n-1):
    a, b = map(int, input().split())
    M[a-1].append(b-1)
    M[b-1].append(a-1)
for i in range(q):
    p, x = map(int, input().split())
    point[p-1] += x
#print(M, point)
    
WHITE, GRAY, BLACK = 0, 1, 2
color = [WHITE] * n

counter = [0] * n
dfs(0, 0)

print(*counter)

Buggy submission (verdict: Runtime Error):
def dfs(u, cnt):
    cnt += point[u]
    counter[u] = cnt
    color[u] = GRAY
    for v in M[u]:
        if color[v] == WHITE:
            dfs(v, cnt)
    color[u] = BLACK


n, q = map(int, input().split())
M = [[] for _ in range(n)]
point = [0] * n
for i in range(n-1):
    a, b = map(int, input().split())
    M[a-1].append(b-1)
    M[b-1].append(a-1)
for i in range(q):
    p, x = map(int, input().split())
    point[p-1] += x
#print(M, point)
    
WHITE, GRAY, BLACK = 0, 1, 2
color = [WHITE] * n

counter = [0] * n
dfs(0, 0)

print(*counter)

Buggy submission (verdict: Runtime Error):
def dfs(u, cnt):
    cnt += point[u]
    counter[u] = cnt
    color[u] = GRAY
    for v in M[u]:
        if color[v] == WHITE:
            dfs(v, cnt)
    color[u] = BLACK


n, q = map(int, input().split())
M = [[] for _ in range(n)]
point = [0] * n
for i in range(n-1):
    a, b = map(int, input().split())
    M[a-1].append(b-1)
for i in range(q):
    p, x = map(int, input().split())
    point[p-1] += x
#print(M, point)
    
WHITE, GRAY, BLACK = 0, 1, 2
color = [WHITE] * n

counter = [0] * n
dfs(0, 0)

print(*counter)
Problem p03044 (python)

Fixed submission:
import sys
sys.setrecursionlimit(1000000)

N = int(input())
M = [[] for _ in range(N)]
for i in range(N-1):
    u, v, w = map(int, input().split())
    u, v = u-1, v-1
    M[u].append((v, w))
    M[v].append((u, w))

visited = [False] * N
color = [0] * N

def dfs(u, c):
    visited[u] = True   #; print('u, c', u, c)
    for vw in M[u]:
        v, w = vw       #; print(vw)
        if visited[v] == False:
            if w%2 == 0:
                color[v] = c * 0b1
            else:
                color[v] = c ^ 0b1
            #print('v, c', v, c)
            dfs(v, color[v])

dfs(u, 0)
for i in range(N):
    print(color[i])

Buggy submission (verdict: Runtime Error):
N = int(input())
M = [[] for _ in range(N)]
for i in range(N-1):
    u, v, w = map(int, input().split())
    u, v = u-1, v-1
    M[u].append((v, w))
    M[v].append((u, w))

visited = [False] * N
color = [0] * N

def dfs(u, c):
    visited[u] = True   #; print('u, c', u, c)
    for vw in M[u]:
        v, w = vw       #; print(vw)
        if visited[v] == False:
            if w%2 == 0:
                color[v] = c * 0b1
            else:
                color[v] = c ^ 0b1
            #print('v, c', v, c)
            dfs(v, color[v])

dfs(u, 0)
for i in range(N):
    print(color[i])
Problem p03162 (python)

Fixed submission:
import sys
sys.setrecursionlimit(1000000)

N = int(input())
a = [[0]*3 for i in range(N)]

for i in range(N):
  a[i] = [int(i) for i in input().split()] 

def f(n, i):
  if n ==0:
    return a[0][i]
  i1 = (i+1) % 3
  i2 = (i+2) % 3
  if F[n][i]:
    return F[n][i]
  F[n][i] = max(f(n-1, i1), f(n-1, i2)) + a[n][i] 
  return F[n][i]  

F =[[None]*3 for _ in range(N)]

print(max(f(N-1, 0), f(N-1,1), f(N-1,2)))

Buggy submission (verdict: Runtime Error):
N = int(input())
a = [[0]*3 for i in range(N)]

for i in range(N):
  a[i] = [int(i) for i in input().split()] 

def f(n, i):
  if n ==0:
    return a[0][i]
  i1 = (i+1) % 3
  i2 = (i+2) % 3
  if F[n][i]:
    return F[n][i]
  F[n][i] = max(f(n-1, i1), f(n-1, i2)) + a[n][i] 
  return F[n][i]  

F =[[None]*3 for _ in range(N)]

print(max(f(N-1, 0), f(N-1,1), f(N-1,2)))
Problem p03565 (python)

Fixed submission:
def agree(s1, t1):
    for i in range(len(t1)):
        if not(s1[i] == t1[i] or s1[i] =='?'):
            return False
    return True

s = input()
t = input()  
ls, lt  = len(s), len(t)

ss =[]
for i in range(ls - lt +1):
    #print(s[i:i+lt], t)
    if agree(s[i:i+lt], t):
        ss.append( (s[:i] + t + s[i+lt:]).replace('?', 'a') )
#print(ss)

if ss:
    print(min(ss))
else:
    print('UNRESTORABLE')

Buggy submission (verdict: Runtime Error):
ef agree(s1, t1):
    for i in range(len(t1)):
        if not(s1[i] == t1[i] or s1[i] =='?'):
            return False
    return True

s = input()
t = input()  
ls, lt  = len(s), len(t)

ss =[]
for i in range(ls - lt +1):
    #print(s[i:i+lt], t)
    if agree(s[i:i+lt], t):
        ss.append( (s[:i]+t).replace('?', 'a') )
#print(ss)

if ss:
    print(min(ss))
else:
    print('UNRESTORABLE')
Problem p03854 (python)

Fixed submission:
import sys
sys.setrecursionlimit(1000000)

S = input()

T = ['dream', 'dreamer', 'erase', 'eraser']
lenT = [len(i) for i in T]

def dayDream(pin):
    global isDream               #;print('dayDream: ', pin, S[pin:])
    for i, d in enumerate(T):
        #print('d:', d)
        if S[pin:pin+lenT[i]] == d:            
            pout = pin + lenT[i] #; print(d, pout)
            if pout == len(S):                
                isDream = True   #; print('YES')
                return 
            else:
                dayDream(pout)
    #print('dayDream return', pin)
    return
    
isDream = False
dayDream(0)
if isDream:
    print('YES')
else:
    print('NO')

Buggy submission (verdict: Runtime Error):
S = input()
T = ['dream', 'dreamer', 'erase', 'eraser']
lenT = [len(i) for i in T]

def dayDream(Sres_in):
    global isDream     #;print('dayDream: ', Sres_in)
    for i, d in enumerate(T):
        #print('d:', d)
        if Sres_in[:lenT[i]] == d:            
            Sres_out = Sres_in[lenT[i]:]
            if Sres_out =='':                
                isDream = True   #; print('YES')
                return 
            else:
                dayDream(Sres_out)
    #print('return', Sres_in)
    return
    
isDream = False
dayDream(S)
if isDream:
    print('YES')
else:
    print('NO')
Problem p03043 (python)

Fixed submission:
n, k = map(int, input().split())
ans = max((n - k + 1) / n, 0)
for a in range(1, min(k, n + 1)):
    cnt = 0
    while k > a:
        a *= 2
        cnt += 1
    ans += 0.5 ** cnt / n
print('{:.12f}'.format(ans))

Buggy submission (verdict: Runtime Error):
n, k = map(int, input().split())
ans = max((n - k + 1) / n, 0)
for a in range(1, min(k, n + 1)):
    ans += 0.5 ** (k // a).bit_length() / n
print(f'{ans:.12f}')
Problem p03246 (python)

Fixed submission:
from collections import Counter
N = int(input())
A = list(map(int, input().split()))
c1 = Counter(A[::2])
c2 = Counter(A[1::2])
c1[0] = 0
c2[0] = 0
c1m = max(c1.items(), key=lambda x:x[1])
c2m = max(c2.items(), key=lambda x:x[1])
c1c2 = max(c for k,c in c2.items() if c1m[0]!=k)
c2c1 = max(c for k,c in c1.items() if c2m[0]!=k)
print(min(N - c1m[1] - c1c2, N - c2m[1] - c2c1))

Buggy submission (verdict: Runtime Error):
from collections import Counter
N = int(input())
A = list(map(int, input().split()))
c1 = Counter(A[::2])
c2 = Counter(A[1::2])
c1m = max(c1.items(), key=lambda x:x[1])
c2m = max(c2.items(), key=lambda x:x[1])
c1m[0] = 0
c2m[0] = 0
c1c2 = max(c for k,c in c2.items() if c1m[0]!=k)
c2c1 = max(c for k,c in c1.items() if c2m[0]!=k)
print(min(N - c1m[1] - c1c2, N - c2m[1] - c2c1))
Problem p03251 (python)

Fixed submission:
N, M, X, Y = map(int, input().split())
x = max(map(int, input().split()))
y = min(map(int, input().split()))

for z in range(x + 1, y + 1):
    if X < z <= Y:
        print('No War')
        exit()

print('War')

Buggy submission (verdict: Runtime Error):
#include <iostream>
#include <algorithm>
using namespace std;

int main() {
  int N, M; cin >> N >> M;
  int XMAX, YMIN; cin >> XMAX >> YMIN;
  for (int i = 0; i < N; ++i) {
    int x; cin >> x;
    XMAX = max(XMAX, x);
  }
  for (int i = 0; i < M; ++i) {
    int y; cin >> y;
    YMIN = min(YMIN, y);
  }
  cout << (XMAX < YMIN ? "No War" : "War") << endl;
}
Problem p03260 (python)

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

Buggy submission (verdict: Runtime Error):
print('YNeos'[1-'2'in input()::2])
Problem p03263 (python)

Fixed submission:
H,W=map(int,input().split())
a=[list(map(int,input().split())) for _ in[0]*H]
res=[]
for i in range(H):
    for j in range(W-1):
        if a[i][j]%2==1:
            a[i][j]-=1
            a[i][j+1]+=1
            res.append([i,j,i,j+1])
for i in range(H-1):
    if a[i][-1]%2==1:
        a[i][-1]-=1
        a[i+1][-1]+=1
        res.append([i,W-1,i+1,W-1])
print(len(res))
for a,b,c,d in res:
    print(a+1,b+1,c+1,d+1)

Buggy submission (verdict: Runtime Error):
H,W=map(int,input().split())
a=[list(map(int,input().split())) for _ in[0]*H]
res=[]
for i in range(H):
    for j in range(W-1):
        if a[i][j]%2==1:
            a[i][j]-=1
            a[i][j+1]+=1
            res.append([i,j,i,j+1])
for i in range(H-1):
    if a[i][-1]%2==1:
        a[i][-1]-=1
        a[i+1][-1]+=1
        res.append([i,j,i+1,j])
print(len(res))
for a,b,c,d in res:
    print(a+1,b+1,c+1,d+1)

Buggy submission (verdict: Runtime Error):
H,W=map(int,input().split())
a=[list(map(int,input().split())) for _ in[0]*H]
res=[]
for i in range(H):
    for j in range(W-1):
        if a[i][j]%2==1:
            a[i][j]-=1
            a[i][j+1]+=1
            res.append([i,j,i,j+1])
for i in range(H-1):
    if a[i][-1]%2==1:
        a[i][-1]-=1
        a[i+1][-1]+=1
        res.append([i,j,i+1,j])
print(len(res))
for x in res:
    print(*x)

Buggy submission (verdict: Runtime Error):
H,W=map(int,input().split())
a=[list(map(int,input().split())) for _ in[0]*H]
res=[]
for i in range(H):
    for j in range(W-1):
        if a[i][j]%2==1:
            res.append([i,j,i,j+1])
for i in range(H-1):
    if a[i][-1]%2==1:
        res.append([i,j,i+1,j])
print(len(res))
for x in res:
    print(*x)
Problem p03274 (python)

Fixed submission:
n,k=map(int,input().split())
X=list(map(int,input().split()))
ans=float('inf')
for i in range(n-k+1):
    a,b=X[i],X[i+k-1]
    if b<0:
        ans=min(ans,-a)
    elif a>0:
        ans=min(ans,b)
    else:
        tmp=min(-a,b)*2+max(-a,b)
        ans=min(ans,tmp)
print(ans)

Buggy submission (verdict: Runtime Error):
N,K,*x=map(int,open(0).read().split());print(min(min(abs(x[i]),abs(x[i+k-1]))+x[i+k-1]-x[i]for i in range(n-k+1)))
Problem p03282 (python)

Fixed submission:
S=list(input())
K=int(input())
idx=[-1]*10
for i in '123456789':
    if i in S:
        idx[int(i)] = S.index(i)+1
if idx[2:]==[-1]*8 or K < max(idx[2:]):
    print(1)
else:
    print(S[min(i for i in idx[2:]if i>0)-1])

Buggy submission (verdict: Runtime Error):
S=list(input())
K=int(input())
idx=[-1]*10
for i in '123456789':
    if i in S:
        idx[int(i)] = S.index(i)+1
if K < max(idx[2:]):
    print(1)
else:
    print(S[min(i for i in idx[2:]if i>0)-1])
Problem p03283 (python)

Fixed submission:
import sys
def main():
    s = sys.stdin.readlines()
    N, M, Q = map(int, s[0].split())
    x = [[0] * N for _ in [0] * N]
    for e in s[1:M + 1]:
        L, R = map(int, e.split())
        x[L - 1][R - 1] += 1
    for k in range(1, N):
        for i in range(N - k):
            j = i + k
            x[i][j] += x[i][j - 1] + x[i + 1][j] - x[i + 1][j - 1]
    res = []
    for e in s[M + 1:]:
        p, q = map(int, e.split())
        res.append(x[p - 1][q - 1])
    print('\n'.join(map(str, res)))
if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
import sys
import collections
e=sys.stdin.readlines()
N,M,Q=map(int,e[0].split())
dp=[[0]*-~N for _ in[0]*-~N]
for k,c in collections.Counter(e[1:M+1]).items():
    L,R=map(int,k.split())
    for i in range(1,L+1):
        for j in range(R,N+1):
            dp[i][j] += c
ans=''
for x in e[M+1:]:
    p,q=map(int,x.split())
    ans+=f'{dp[p][q]}\n'
print(ans[:-1])
Problem p03323 (python)

Fixed submission:
A,B=map(int,input().split())
print(['Yay!',':('][A>8 or B>8])

Buggy submission (verdict: Runtime Error):
A,B=map(int,input(),split())
print(['Yay!',':('][A>8 or B>8])

Buggy submission (verdict: Runtime Error):
A=int(input())
B=int(input())
print(['Yay!',':('][A>8 or B>8])
Problem p03353 (python)

Fixed submission:
s = input()
K = int(input())
sub = {s}
for d in range(1,6):
    for i in range(len(s)-d+1):
        sub |= {s[i:i+d]}
sub = list(sub)
n = len(sub)
for i in range(K):
    for j in range(n-i):
        a, b = sub[-i-1], sub[j]
        if a > b: sub[-i-1], sub[j] = b, a
print(sub[-K])

Buggy submission (verdict: Runtime Error):
s = input()
K = int(input())
sub = {}
for d in range(1,6):
    for i in range(len(s)-d+1):
        sub |= {s[i:i+d]}
print(sorted(sub)[K-1])
Problem p03361 (python)

Fixed submission:
H,W=map(int,input().split())
C=['.'*(W+2)]+['.'+input()+'.'for _ in[0]*H]+['.'*(W+2)]
for i in range(1,H+1):
    for j in range(1,W+1):
        if C[i][j]=='#'and'#'not in[C[i-1][j], C[i][j-1], C[i][j+1], C[i+1][j]]:
            print('No')
            exit()
print('Yes')

Buggy submission (verdict: Runtime Error):
H, W = map(int, input().split())
edge = '.' * (W + 2)
field = [edge]
for _ in range(H):
    field.append('.' + input() + '.')
field.append(edge)
for i in range(1, H + 1):
    for j in range(1, W + 1):
        if C[i][j] == '.':
            continue
        if '#' not in [C[i - 1][j], C[i][j - 1], C[i][j + 1], C[i + 1][j]]:
            print('No')
            exit()
print('Yes')
Problem p03387 (python)

Fixed submission:
S = list(map(int, input().split()))
M = max(S)
r = sum(M - i for i in S)
print((r + 3 * (r % 2)) // 2)

Buggy submission (verdict: Runtime Error):
a, b, c = sorted(map(int, input().split()))
diff = c - b
newa = a + diff
if (c - newa) % 2 == 0:
	print(d + (c - newa) // 2)
else:
	print(d + (c - newa + 3) // 2)

Buggy submission (verdict: Runtime Error):
A = list(map(int, input().split()))
M = max(S)
r = sum(M - a for a in A)
print((r + 3 * (r % 2)) // 2)
Problem p03389 (python)

Fixed submission:
A = list(map(int, input().split()))
M = max(A)
S = sum(A)
M += M % 2 != S % 2
print((3 * M - S) // 2)

Buggy submission (verdict: Runtime Error):
A = list(map(int, input().split()))
M = max(A)
S = sum(A)
M += M % 2 != S % 2
print((3 * M - sum) // 2)
Problem p03418 (python)

Fixed submission:
N, K = map(int, input().split())
if K == 0:
    print(N * N)
    exit()
cnt = 0
for b in range(K + 1, N + 1):
    p, r = divmod(N, b)
    cnt += p * (b - K) + max(r - K + 1, 0)
print(cnt)

Buggy submission (verdict: Runtime Error):
N,K=map(int,input().split())
print(sum(p*(b-K)+max(r-K+1,0)for p,r,b in map(lambda b:(*divmod(N,b),b),range(K+1,N+1)))if K else N*N)
Problem p03448 (python)

Fixed submission:
A,B,C,X=[int(input())for _ in[0]*4]
ans=sum(a*500+b*100+c*50==X for a in range(A+1)for b in range(B+1)for c in range(C+1))
print(ans)

Buggy submission (verdict: Runtime Error):
N, K = map(int, input().split())
if K % 2:
    print((N // K) ** 3)
else:
    print((N // K) ** 3 + ((N + K // 2) // K) ** 3)
Problem p03457 (python)

Fixed submission:
can = True
e = [[0, 0, 0]] + [list(map(int, input().split())) for _ in range(int(input()))]
for a, b in zip(e[1:], e):
    dt = a[0] - b[0]
    dist = abs(a[1] - b[1]) + abs(a[2] - b[2])
    if dt < dist: can = False; break
    if dt % 2 != dist % 2: can = False; break
print(['No', 'Yes'][can])

Buggy submission (verdict: Runtime Error):
import sys
input()
e = [[0, 0, 0]] + [list(map(int, e.split())) for e in sys.stdin]
for (t0, a0, b0), (t1, a1, b1) in zip(e, e[1:]):
    d = (t1 - t0) - abs(a1 - a0) - abs(b1 - b0)
    if d < 0 or t % 2 == 1:
        print('No')
        exit()
print('Yes')