Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
n = int(input())
h = list(map(int, input().split()))
max_h = 0
ans = 0
for a in h:
  if max <= a:
    ans += 1
  max_h = max(a, max_h)
  
print(ans)

Fixed submission:
n = int(input())
h = list(map(int, input().split()))
max_h = 0
ans = 0
for a in h:
  if max_h <= a:
    ans += 1
  max_h = max(a, max_h)
  
print(ans)
Buggy python submission (verdict: Runtime Error):
n,m,c = map(int, input().split())
b = list(map(int,input().split()))
a = []

def mul(x, y):
  ret = 0
  for i in range(len(x)):
    ret += x[i]*y[i]

ans = 0
for i in range(n):
  a = list(map(int, input().split()))
  if mul(a, b) + c > 0:
    ans += 1

print(ans)

Fixed submission:
n,m,c = map(int, input().split())
b = list(map(int,input().split()))
a = []

def mul(x, y):
  ret = 0
  for i in range(len(x)):
    ret += x[i]*y[i]
  return ret
    
ans = 0
for i in range(n):
  a = list(map(int, input().split()))
  if mul(a, b) + c > 0:
    ans += 1

print(ans)
Buggy python submission (verdict: Runtime Error):
n,m = map(int,input().split())
l = [map(int, input().split()) for i in range(n)]
ans = 0
l.sort()
for a,b in l:
  if b >= m:
    ans += a * m
    break
  else:
    ans += a*b
    m -= b
print(ans)

Fixed submission:
n,m = map(int,input().split())
l = []
for i in range(n):
    a,b = map(int, input().split())
    l.append((a,b))
ans = 0
l.sort()
for a,b in l:
  if b >= m:
    ans += a * m
    break
  else:
    ans += a*b
    m -= b
print(ans)
Buggy python submission (verdict: Runtime Error):
n = int(input())
dic = {"JPY": 1, "BTC": 380000}
ans = 0
for i in range(n):
  x,u = input().split()
  ans += int(x) * dic[u]
print(ans)  

Fixed submission:
n = int(input())
dic = {"JPY": 1, "BTC": 380000}
ans = 0
for i in range(n):
  x,u = input().split()
  ans += float(x) * dic[u]
print(ans)
Buggy python submission (verdict: Runtime Error):
n,a,b,c = map(int,input().split())
l = [int(input()) for _ in range(n)]
ans = 10000
for i in range(2 ** (2*n)):
  v = [0,0,0,0]
  assign = [(i>>(2*j)) & 3 for j in range(n)]
  cost = 0
  for j in range(n):
    is v[assign[j]] > 0:
      cost += 10
    v[assign[j]] += l[j]
  if v[1] == 0 or v[2] == 0 or v[3] == 0:
    continue
  ans = min(ans, cost + abs(v[1]-a) + abs(v[2]-b) + abs(v[3]-c))
print(ans)

Fixed submission:
n,a,b,c = map(int,input().split())
l = [int(input()) for _ in range(n)]
ans = 10000
for i in range(2 ** (2*n)):
  v = [0,0,0,0]
  assign = [(i>>(2*j)) & 3 for j in range(n)]
  cost = 0
  for j in range(n):
    if assign[j] > 0 and v[assign[j]] > 0:
      cost += 10
    v[assign[j]] += l[j]
  if v[1] == 0 or v[2] == 0 or v[3] == 0:
    continue
  ans = min(ans, cost + abs(v[1]-a) + abs(v[2]-b) + abs(v[3]-c))
print(ans)
Buggy python submission (verdict: Runtime Error):
n,m = map(int, input().split())
ans = 0
buf = [0]*m
for i in range(n):
  a = list(map(int, input().split()))[1:]
  for j in a:
    buf[j] += 1

for a in buf:
  if a == n:
    ans += 1

print(ans)    

Fixed submission:
n,m = map(int, input().split())
ans = 0
buf = [0]*m
for i in range(n):
  a = list(map(int, input().split()))[1:]
  for j in a:
    buf[j-1] += 1

for a in buf:
  if a == n:
    ans += 1

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
h = list(map(int,input().split()))
ans = 0
while True:
  water = False
  for i in range(n):
    if h[i] > 0:
      h[i] -= 1
      water = True
    elif water:
      ans += 1
      water = False
  if water:
    ans += 1
print(ans)

Fixed submission:
n = int(input())
h = list(map(int,input().split()))
ans = 0
while True:
  water = False
  finish = True
  for i in range(n):
    if h[i] > 0:
      h[i] -= 1
      water = True
      finish = False
    elif water:
      ans += 1
      water = False
  if water:
    ans += 1
  if finish:
    break
print(ans)
Buggy python submission (verdict: Runtime Error):
n,k = map(int,input())
h = [int(input()) for i in range(n)].sort()
ans = 1000000000
for i in range(n-k):
  ans = min(ans, h[i+k-1]-h[i])
print(ans)

Fixed submission:
n,k = map(int,input().split())
h = sorted([int(input()) for i in range(n)])
ans = 1000000000
for i in range(n-k+1):
  ans = min(ans, h[i+k-1]-h[i])
print(ans)

Buggy python submission (verdict: Runtime Error):
n,k = map(int,input())
h = [int(input()) for i in range(n)].sort()
ans = 1000000000
for i in range(n-k+1):
  ans = min(ans, h[i+k-1]-h[i])
print(ans)

Fixed submission:
n,k = map(int,input().split())
h = sorted([int(input()) for i in range(n)])
ans = 1000000000
for i in range(n-k+1):
  ans = min(ans, h[i+k-1]-h[i])
print(ans)

Buggy python submission (verdict: Runtime Error):
n,k = map(int,input())
h = [int(input()) for i in range(n)].sort()
ans = 1000000000
for i in range(n-k):
  ans = min(ans, h[i+k]-h[i])
print(ans)

Fixed submission:
n,k = map(int,input().split())
h = sorted([int(input()) for i in range(n)])
ans = 1000000000
for i in range(n-k+1):
  ans = min(ans, h[i+k-1]-h[i])
print(ans)
Buggy python submission (verdict: Runtime Error):
n = int(input())

def bfs(s):
  if int(s) >= n:
    return 0
  return ('3' in s and '5' in s and '7' in s) + bfs(s+'3') + bfs(s+'5') + bfs(s+'7')

print(bfs(''))

Fixed submission:
n = int(input())
 
def bfs(s):
  if int(s) > n:
    return 0
  return ('3' in s and '5' in s and '7' in s) + bfs(s+'3') + bfs(s+'5') + bfs(s+'7')
 
print(bfs('0'))
Buggy python submission (verdict: Runtime Error):
x,y = map(int, input())
print(x + int(y/2))

Fixed submission:
x,y = map(int, input().split())
print(x + int(y/2))
Buggy python submission (verdict: Runtime Error):
n,m = map(int, input().split())
py = []
for i in rante(m):
  a,b = map(int, input.split())
  py.append([a,b,i])
py.sort()
p = 1
y = 1
for i in range(m):
  if py[i][0] == p:
    py[i][1] = y
    y += 1
  else:
    py[i][1] = 1
    y = 1
    p = py[i][0]
py = sorted(py, key=lambda x:x[2])
for p,y,i in py:
  print("{06}{06}".format(p,y))



Fixed submission:
n,m = map(int, input().split())
py = []
for i in range(m):
  a,b = map(int, input().split())
  py.append([a,b,i])
py.sort()
p = py[0][0]
y = 1
for i in range(m):
  if py[i][0] == p:
    py[i][1] = y
    y += 1
  else:
    py[i][1] = 1
    y = 2
    p = py[i][0]
py = sorted(py, key=lambda x:x[2])
for p,y,i in py:
  print("{:0=6}{:0=6}".format(p,y))

Buggy python submission (verdict: Runtime Error):
n,m = map(int, input().split())
py = []
for i in rante(m):
  a,b = map(int, input.split())
  py.append([a,b,i])
py.sort()
p = 1
y = 1
for i in range(m):
  if py[i][0] == p:
    py[i][1] = y
    y += 1
  else:
    py[i][1] = 1
    y = 1
    p = py[i][0]
py.sort(key=lambda x:x[2])
for p,y,i in py:
  print("{06}{06}".format(p,y))



Fixed submission:
n,m = map(int, input().split())
py = []
for i in range(m):
  a,b = map(int, input().split())
  py.append([a,b,i])
py.sort()
p = py[0][0]
y = 1
for i in range(m):
  if py[i][0] == p:
    py[i][1] = y
    y += 1
  else:
    py[i][1] = 1
    y = 2
    p = py[i][0]
py = sorted(py, key=lambda x:x[2])
for p,y,i in py:
  print("{:0=6}{:0=6}".format(p,y))
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = int(input())
b = int(input())
if n == 1:
  print("Hello World")
if n == 2:
  print(a+b)

Fixed submission:
n = int(input())
if n == 1:
  print("Hello World")
elif n == 2:
  a = int(input())
  b = int(input())
  print(a+b)
Buggy python submission (verdict: Runtime Error):
n,T = map(int, input())
ans = 1000
for i in range(n):
  c,t = map(int, input())
  if t <= T:
    ans = min(ans, c)
print(ans)

Fixed submission:
n,T = map(int, input().split())
ans = 1001
for i in range(n):
  c,t = map(int, input().split())
  if t <= T:
    ans = min(ans, c)

if ans == 1001:
  print("TLE")
else:
  print(ans)
Buggy python submission (verdict: Runtime Error):
n = int(input())
v = list(map(int, input().split()))
even = dict()
odd = dict()
for i in range(n//2):
  a = v[2*i]
  if a in even:
    even[a] += 1
  else:
    even[a] = 1
  a = v[2*i + 1]
  if a in odd:
    odd[a] += 1
  else:
    odd[a] = 1

even_sorted = sorted(even.items(), key=lambda x:x[1], reverse=True)
odd_sorted = sorted(odd.items(), key=lambda x:x[1], reverse=True)

if even_sorted[0][0] == odd_sorted[0][0]:
  print(n - max(even_sorted[0][1]+odd_sorted[1][1], even_sorted[1][1]+odd_sorted[0][1]))
else:
  print(n - even_sorted[0][1] - odd_sorted[0][1])

Fixed submission:
n = int(input())
v = list(map(int, input().split()))
even = dict()
odd = dict()
even[0] = 0
odd[0] = 0
for i in range(n//2):
  a = v[2*i]
  if a in even:
    even[a] += 1
  else:
    even[a] = 1
  a = v[2*i + 1]
  if a in odd:
    odd[a] += 1
  else:
    odd[a] = 1

even_sorted = sorted(even.items(), key=lambda x:x[1], reverse=True)
odd_sorted = sorted(odd.items(), key=lambda x:x[1], reverse=True)

if even_sorted[0][0] == odd_sorted[0][0]:
  print(n - max(even_sorted[0][1]+odd_sorted[1][1], even_sorted[1][1]+odd_sorted[0][1]))
else:
  print(n - even_sorted[0][1] - odd_sorted[0][1])
Buggy python submission (verdict: Runtime Error):
s = input()
t = input()
d_s = dict()
d_t = dict()
for i in range(len(s)):
  if not s[i] in d:
    d_s[s[i]] = t[i]
  elif d_s[s[i]] != t[i]:
    print('No')
    exit()
  if not t[i] in d:
    d_t[t[i]] = s[i]
  elif d_t[t[i]] != s[i]:
    print('No')
    exit()
print('Yes')

Fixed submission:
s = input()
t = input()
d_s = dict()
d_t = dict()
for i in range(len(s)):
  if not s[i] in d_s:
    d_s[s[i]] = t[i]
  elif d_s[s[i]] != t[i]:
    print('No')
    exit()
  if not t[i] in d_t:
    d_t[t[i]] = s[i]
  elif d_t[t[i]] != s[i]:
    print('No')
    exit()
print('Yes')
Buggy python submission (verdict: Runtime Error):
n = int(input())
w = [input() for i in range(n)]

def is_shiritori():
  if len(set(w)) != n:
    return 'No'
  for i in range(n-1):
    if w[n][-1] != w[n+1][0]:
      return 'No'
  return 'Yes'
print(is_shiritori())

Fixed submission:
n = int(input())
w = [input() for i in range(n)]

def is_shiritori():
  if len(set(w)) != n:
    return 'No'
  for i in range(n-1):
    if w[i][-1] != w[i+1][0]:
      return 'No'
  return 'Yes'

print(is_shiritori())
Buggy python submission (verdict: Runtime Error):
import math
n,X = map(int, input().split())
x = list(map(int,input().split()))
x.append(X)
x.sort()
Y = []
for i in range(n):
  Y.append(x[i+1]-x[i])

ans = Y[0]
for y in Y:
  ans = math.gcd(ans,y)
print(ans)

Fixed submission:
n,X = map(int, input().split())
x = list(map(int,input().split()))
x.append(X)
x.sort()
Y = []
for i in range(n):
  Y.append(x[i+1]-x[i])

def gcd(a,b):
    if b == 0:
        return a
    return gcd(b, a % b)

ans = Y[0]
for y in Y:
  ans = gcd(ans,y)
print(ans)

Buggy python submission (verdict: Runtime Error):
import math
n,X = map(int, input().split())
x = list(map(int,input().split()))
x.append(X)
x.sort()
y = []
for i in range(n):
  y.append(x[i+1]-x[i])

ans = y[0]
for i in range(1,n):
  ans = math.gcd(ans,y[i])
print(ans)

Fixed submission:
n,X = map(int, input().split())
x = list(map(int,input().split()))
x.append(X)
x.sort()
Y = []
for i in range(n):
  Y.append(x[i+1]-x[i])

def gcd(a,b):
    if b == 0:
        return a
    return gcd(b, a % b)

ans = Y[0]
for y in Y:
  ans = gcd(ans,y)
print(ans)
Buggy python submission (verdict: Runtime Error):
h,w = map(int,input().split())
a = list()

for i in range(h):
  a.append(list(map(int, input().split())))

h_blank = [False]*h
w_blank = [False]*w
for i in range(h):
  blank = True
  for j in range(w):
    if a[i][j] == '#':
      blank = False
      break
  if blank:
    h_blank[i] = True

for i in range(w):
  blank = True
  for j in range(h):
    if a[j][i] == '#':
      blank = False
      break
  if blank:
    w_blank[i] = True

for i in range(h):
  for j in range(w):
    if h_blank[i] or w_blank[j]:
      continue
    print(a[i][j])

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

for i in range(h):
  a.append(input())

h_blank = [False]*h
w_blank = [False]*w
for i in range(h):
  blank = True
  for j in range(w):
    if a[i][j] == '#':
      blank = False
      break
  if blank:
    h_blank[i] = True

for i in range(w):
  blank = True
  for j in range(h):
    if a[j][i] == '#':
      blank = False
      break
  if blank:
    w_blank[i] = True

for i in range(h):
  if h_blank[i]:
    continue
  for j in range(w):
    if w_blank[j]:
      continue
    print(a[i][j], end='')
  print('')

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

for i in range(h):
  a.append(list(map(int, input().split())))

h_blank = [False]*h
w_blank = [False]*w
for i in range(h):
  blank = True
  for j in range(w):
    if a[i][j] == '#':
      blank = False
      break
  if blank:
    h_blank[i] = True

for i in range(w):
  blank = True
  for j in range(h):
    if a[j][i] == '#':
      blank = False
      break
  if blank:
    w_blank[i] = True

for i in range(h):
  for j in range(w):
    if h_blank[i] or w_blank[j]:
      continue
    print(a[i][]j)

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

for i in range(h):
  a.append(input())

h_blank = [False]*h
w_blank = [False]*w
for i in range(h):
  blank = True
  for j in range(w):
    if a[i][j] == '#':
      blank = False
      break
  if blank:
    h_blank[i] = True

for i in range(w):
  blank = True
  for j in range(h):
    if a[j][i] == '#':
      blank = False
      break
  if blank:
    w_blank[i] = True

for i in range(h):
  if h_blank[i]:
    continue
  for j in range(w):
    if w_blank[j]:
      continue
    print(a[i][j], end='')
  print('')
Buggy python submission (verdict: Runtime Error):
s = input()
for c in s:
  if c.isupper():
    count += 1

if count == 2 and s[0] == 'A' and 'C' in s[2:-1]:
  print('AC')
else:
  print('WA')

Fixed submission:
s = input()
count = 0
for c in s:
  if c.isupper():
    count += 1

if count == 2 and s[0] == 'A' and 'C' in s[2:-1]:
  print('AC')
else:
  print('WA')
Buggy python submission (verdict: Runtime Error):
import math
d, g = map(int, input().split())
p = []
c = []
su = []
ans = 1000
for i in range(d):
  a,b = map(int, input().split())
  p.append(a)
  c.append(b)
  su.append(a*100*(i+1)+b)
bit = [1,2,4,8,16,32,64,128,256,512]
for i in range(1024):
  count = 0
  for j in range(d):
    if i & bit[j] == 0:
      continue
    score += su[j]
    count += p[j]
  if score < g:
    continue
  for j in range(d):
    if i & bit[j] == 0 or score - su[j] >= g:
      continue
    rest = g - (score - su[j])
    count_tmp = count - p[j] + math.ceil(rest / ((d+i)*100))
    ans = min(ans, count_tmp)
print(ans)

Fixed submission:
import math
d, g = map(int, input().split())
p = []
c = []
su = []
ans = 1000
for i in range(d):
  a,b = map(int, input().split())
  p.append(a)
  c.append(b)
  su.append(a*100*(i+1)+b)
bit = [1,2,4,8,16,32,64,128,256,512]
for i in range(int(math.pow(2,d))):
  count = 0
  score = 0
  for j in range(d):
    if i & bit[j] == 0:
      continue
    score += su[j]
    count += p[j]
  if score < g:
    continue
  for j in range(d):
    if i & bit[j] == 0 or score - su[j] >= g:
      continue
    rest = g - (score - su[j])
    count_tmp = min(count , count - p[j] + math.ceil(rest / ((j+1)*100)))
    ans = min(ans, count_tmp)
print(ans)

Buggy python submission (verdict: Runtime Error):
d, g = map(int, input().split())
p = []
c = []
su = []
ans = 1000
for i in range(d):
  a,b = map(int, input().split())
  p.append(a)
  c.append(b)
  su.append(a*100*(i+1)+b)
bit = [1,2,4,8,16,32,64,128,256,512]
for i in range(1024):
  count = 0
  for j in range(d):
    if i & bit[j] == 0:
      continue
    score += su[j]
    count += p[j]
  if score < g:
    continue
  for j in range(d):
    if i & bit[j] == 0 or score - su[j] >= g:
      continue
    rest = g - (score - su[j])
    count_tmp = count - p[j] + math.ceil(rest / ((d+i)*100))
    ans = min(ans, count_tmp)
print(ans)

Fixed submission:
import math
d, g = map(int, input().split())
p = []
c = []
su = []
ans = 1000
for i in range(d):
  a,b = map(int, input().split())
  p.append(a)
  c.append(b)
  su.append(a*100*(i+1)+b)
bit = [1,2,4,8,16,32,64,128,256,512]
for i in range(int(math.pow(2,d))):
  count = 0
  score = 0
  for j in range(d):
    if i & bit[j] == 0:
      continue
    score += su[j]
    count += p[j]
  if score < g:
    continue
  for j in range(d):
    if i & bit[j] == 0 or score - su[j] >= g:
      continue
    rest = g - (score - su[j])
    count_tmp = min(count , count - p[j] + math.ceil(rest / ((j+1)*100)))
    ans = min(ans, count_tmp)
print(ans)
Buggy python submission (verdict: Runtime Error):
a = list(map(int, input().split()))
b = [abs(a[0]-a[i]), abs(a[1]-a[2]), abs(a[2]-a[0])]
b.sort()
print(b[0]+b[1])

Fixed submission:
a = list(map(int, input().split()))
b = [abs(a[0]-a[1]), abs(a[1]-a[2]), abs(a[2]-a[0])]
b.sort()
print(b[0]+b[1])
Buggy python submission (verdict: Runtime Error):
n,m = map(int, input().split())
a = []
for i in range(m):
  x,y = map(int, input().split())
  a.append((x,y))
a.sort()
ans = 1
l,r = a[0][]
for x,y in a[1:]:
  if r <= x:
    ans += 1
    r = x
    l = y
  else:
    r = max(r, y)
print(ans)

Fixed submission:
n,m = map(int, input().split())
a = []
for i in range(m):
  x,y = map(int, input().split())
  a.append((x,y))
a.sort(key=lambda x:x[1])
ans = 1
l,r = a[0]
for x,y in a[1:]:
  if r <= x:
    ans += 1
    l = x
    r = y

print(ans)

Buggy python submission (verdict: Runtime Error):
n,m = map(int, input().split())
a = []
for i in range(n):
  x,y = map(int, input().split())
  a.append((x,y))
a.sort()
ans = 1
l,r = a[0]
for x,y in a[1:]:
  if r <= x:
    ans += 1
    r = x
    l = y
  else:
    r = max(r, y)
print(ans)

Fixed submission:
n,m = map(int, input().split())
a = []
for i in range(m):
  x,y = map(int, input().split())
  a.append((x,y))
a.sort(key=lambda x:x[1])
ans = 1
l,r = a[0]
for x,y in a[1:]:
  if r <= x:
    ans += 1
    l = x
    r = y

print(ans)
Buggy python submission (verdict: Runtime Error):
n = int(input().split())
if n < 1000:
  print('ABC')
else:
  print('ABD')

Fixed submission:
n = int(input())
if n < 1000:
  print('ABC')
else:
  print('ABD')
Buggy python submission (verdict: Runtime Error):
n = int(input())
if n < 1000:
  print('ABC')
else:
  print('ABD')

Fixed submission:
a,b = map(int, input().split())
print((b-a)*(b-a-1)//2 - a)
Buggy python submission (verdict: Runtime Error):
n = int(input())
s = input()
t1 = [0]*n
t2 = [0]*n
for i in range(1, n):
  t1[i] = t1[i-1] + s[i-1] == 'W'
  t2[n-i-1] = t2[n-i] + s[n-i] == 'E'
ans = n
for i in range(n):
  ans = min(ans, t1[i] + t2[i])
print(ans)

Fixed submission:
n = int(input())
s = input()
t1 = [0]*n
t2 = [0]*n
for i in range(1, n):
  t1[i] = t1[i-1] + (s[i-1] == 'W')
  t2[n-i-1] = t2[n-i] + (s[n-i] == 'E')
ans = n
for i in range(n):
  ans = min(ans, t1[i] + t2[i])
print(ans)
Buggy python submission (verdict: Runtime Error):
n, x = map(int,input())
m = [int(input()) for i in range(n)]
print(n + (x - sum(m)) // min(m))

Fixed submission:
n, x = map(int,input().split())
m = [int(input()) for i in range(n)]
print(n + (x - sum(m)) // min(m))
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = list(map(int,input().split()))
ans1 = max(a)
diff = min(ans1//2, ans1//2 + 1)
ans2 = ans1
for x in a:
  if x == ans1:
      continue
  d = min(abs(ans1//2 - x), abs(ans1//2 + 1 - x))
  if d <= diff:
    diff = d
    ans2 = x
print('{} {}'.format(ans1, ans2)

Fixed submission:
n = int(input())
a = list(map(int,input().split()))
ans1 = max(a)
diff = min(ans1//2, ans1//2 + 1)
ans2 = ans1
for x in a:
  if x == ans1:
    continue
  d = min(abs(ans1//2 - x), abs(ans1//2 + 1 - x))
  if d <= diff:
    diff = d
    ans2 = x
print('{} {}'.format(ans1, ans2))
Buggy python submission (verdict: Runtime Error):
n = int(input())
count = [0]*5
d = {'M': 0, 'A': 1, 'R': 2, 'C':3, 'H': 4}

for i in range(n):
  s = input()
  if s[0] in 'MARCH':
    count[d[s[0]]] += 1

ans = 0
for i in range(5):
  for j in range(i+1, 5):
    for k in range(j+1, 5):
      ans += count[i] * count[j] * count[k]]
print(ans)

Fixed submission:
n = int(input())
count = [0]*5
d = {'M': 0, 'A': 1, 'R': 2, 'C':3, 'H': 4}

for i in range(n):
  s = input()
  if s[0] in 'MARCH':
    count[d[s[0]]] += 1

ans = 0
for i in range(5):
  for j in range(i+1, 5):
    for k in range(j+1, 5):
      ans += count[i] * count[j] * count[k]
print(ans)
Buggy python submission (verdict: Runtime Error):
h,w,d = map(int,input().split())
p = [(0,0)] * (h*w)
c = [0] * (h*w)
for i in range(h):
  a = list(map(int,input().split()))
  for j in range(w):
    p[a[j]-1] = (i,j)

for i in range(d, h*w):
  c[i] = c[i-d] + abs(p[i][0] - p[i-d][0]) + abs(p[i][1] - p[i-d][1])

q = int(input())
ans = 0
for i in range(q):
  l,r = map(int,input().split())
  ans += c[r] - c[l]
print(ans)

Fixed submission:
h,w,d = map(int,input().split())
p = [(0,0)] * (h*w)
c = [0] * (h*w)
for i in range(h):
  a = list(map(int,input().split()))
  for j in range(w):
    p[a[j]-1] = (i,j)

for i in range(d, h*w):
  c[i] = c[i-d] + abs(p[i][0] - p[i-d][0]) + abs(p[i][1] - p[i-d][1])

q = int(input())
ans = 0
for i in range(q):
  l,r = map(int,input().split())
  print(c[r-1] - c[l-1])
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = int(input())
if n % 500 =< a:
  print('Yes')
else:
  print('No')

Fixed submission:
n = int(input())
a = int(input())
if a >= n % 500:
  print('Yes')
else:
  print('No')
Buggy python submission (verdict: Time Limit Exceeded):
import copy
from datetime import datetime

#print(datetime.now())
n,k = map(int ,input().split())
p = [[0] * (2*k) for i in range(2*k)]
ans = 0
for i in range(n):
  x,y,c = input().split()
  x = int(x)
  y = int(y)
  if c == 'B':
    x += k
  p[x%(2*k)][y%(2*k)] += 1
#[print(p[i]) for i in range(2*k)]
#print()
#print(datetime.now())

csum1 = copy.deepcopy(p)
for i in range(2*k):
    for j in range(1, k):
        csum1[i][0] += p[i][j]
    for j in range(1, 2*k):
        csum1[i][j] = csum1[i][j-1] - p[i][j-1] + p[i][(j+k-1)%(2*k)]
#print(datetime.now())
#[print(csum1[i]) for i in range(2*k)]
#print()

csum2 = copy.deepcopy(csum1)
#print(datetime.now())
for j in range(2*k):
    for i in range(1, k):
        csum2[0][j] += csum1[i][j]
    for i in range(1, 2*k):
        csum2[i][j] = csum2[i-1][j] - csum1[i-1][j] + csum1[(i+k-1)%(2*k)][j]

#[print(csum2[i]) for i in range(2*k)]
#print(datetime.now())
for i in range(2*k):
    for j in range(2*k):
        ans = max(ans, csum2[i][j] + csum2[(i+k)%(2*k)][(j+k)%(2*k)])

print(ans)

Fixed submission:
import copy
from datetime import datetime

#print(datetime.now())
n,k = map(int ,input().split())
p = [[0] * (2*k) for i in range(2*k)]
ans = 0
for i in range(n):
  x,y,c = input().split()
  x = int(x)
  y = int(y)
  if c == 'B':
    x += k
  p[x%(2*k)][y%(2*k)] += 1
#[print(p[i]) for i in range(2*k)]
#print()
#print(datetime.now())

csum1 = [[0]*(2*k) for i in range(2*k)]
#csum1 = copy.deepcopy(p)
for i in range(2*k):
    for j in range(0, k):
        csum1[i][0] += p[i][j]
    for j in range(1, 2*k):
        csum1[i][j] = csum1[i][j-1] - p[i][j-1] + p[i][(j+k-1)%(2*k)]
#print(datetime.now())
#[print(csum1[i]) for i in range(2*k)]
#print()

csum2 = [[0]*(2*k) for i in range(2*k)]
#csum2 = copy.deepcopy(csum1)
#print(datetime.now())
for j in range(2*k):
    for i in range(0, k):
        csum2[0][j] += csum1[i][j]
    for i in range(1, 2*k):
        csum2[i][j] = csum2[i-1][j] - csum1[i-1][j] + csum1[(i+k-1)%(2*k)][j]

#[print(csum2[i]) for i in range(2*k)]
#print(datetime.now())
for i in range(2*k):
    for j in range(2*k):
        ans = max(ans, csum2[i][j] + csum2[(i+k)%(2*k)][(j+k)%(2*k)])

print(ans)
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = sorted([int(input()) for i in range(n)])

pre = a[0]
ans = 1
for i in range(1,n):
  if pre < a[n]:
    ans += 1
  pre = a[i]
print(ans)

Fixed submission:
n = int(input())
a = sorted([int(input()) for i in range(n)])

pre = a[0]
ans = 1
for i in range(1,n):
  if pre < a[i]:
    ans += 1
  pre = a[i]
print(ans)