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

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

def find(parent, i):
  t = parent[i]
  if t < 0:
    return i
  t = find(parent, t)
  parent[i] = t
  return t

def unite(parent, i, j):
  i = find(parent, i)
  j = find(parent, j)
  if i == j:
    return
  parent[j] += parent[i]
  parent[i] = j

n, m = map(int, input().split())
parent = [-1] * n
inconvenience = n * (n - 1) // 2
data = [[int(c) - 1 for c in input().split()] for _ in range(m)]
data.reverse()
result = []
for a, b in data:
  result.append(inconvenience)
  if find(parent, a) != find(parent, b):
    inconvenience -= parent[find(parent, a)] * parent[find(parent, b)]
  unite(parent, a, b)
result.reverse()
for i in result:
  print(i)

Buggy submission (verdict: Runtime Error):
def find(parent, i):
  t = parent[i]
  if t < 0:
    return i
  t = find(parent, t)
  parent[i] = t
  return t

def unite(parent, i, j):
  i = find(parent, i)
  j = find(parent, j)
  if i == j:
    return
  parent[j] += parent[i]
  parent[i] = j

n, m = map(int, input().split())
parent = [-1] * n
inconvenience = n * (n - 1) // 2
data = [[int(c) - 1 for c in input().split()] for _ in range(m)]
data.reverse()
result = []
for a, b in data:
  result.append(inconvenience)
  if find(parent, a) != find(parent, b):
    inconvenience -= parent[find(parent, a)] * parent[find(parent, b)]
  unite(parent, a, b)
result.reverse()
for i in result:
  print(i)
Problem p03137 (python)

Fixed submission:
n, m = map(int, input().split())
x = list(map(int, input().split()))
x.sort()
y = [x[i] - x[i - 1] for i in range(1, m)]
y.sort()
print(sum(y[:m-n]) if n < m else 0)

Buggy submission (verdict: Runtime Error):
from sys import sys
n, m, *x = map(int, stdin.read().split())
x.sort()
y = [x[i] - x[i - 1] for i in range(1, m)]
y.sort()
print(sum(y[:-n]) if n < m else 0)

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
x = list(map(int, input().split()))
x.sort()
y = [x[i] - x[i - 1] for i in range(1, m)]
y.sort()
print(sum(y[:m-n]) if n < m else 0)
print(result)

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
x = list(map(int, input().split()))
x.sort()
y = [x[i] - x[i - 1] for i in range(1, m)]
y.sort()
result = 0
for i in range(n - m):
  result += y[i]
print(result)
Problem p03221 (python)

Fixed submission:
from bisect import bisect_left
n, m = map(int, input().split())
data = [list(map(int, input().split())) for _ in range(m)]
t = [[] for _ in range(n)]
for p, y in data:
  t[p - 1].append(y)
for i in range(n):
  t[i].sort()
for p, y in data:
  nth = bisect_left(t[p - 1], y) + 1
  print("%06d%06d" % (p, nth))

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
data = [list(map(int, input().split())) for _ in range(n)]
t = [[] for _ in range(n)]
for p, y in data:
  t[p - 1].append(y)
for i in range(n):
  t[i].sort()
for p, y in data:
  nth = t[p - 1].index(y) + 1
  print("%06d%06d" % (p, nth))

Buggy submission (verdict: Runtime Error):
from bisect import bisect_left
n, m = map(int, input().split())
data = [list(map(int, input().split())) for _ in range(n)]
t = [[] for _ in range(n)]
for p, y in data:
  t[p - 1].append(y)
for i in range(n):
  t[i].sort()
for p, y in data:
  nth = bisect_left(t[p - 1], y) + 1
  print("%06d%06d" % (p, nth))
Problem p03250 (python)

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

t = sorted([A, B, C])
print(t[0] + t[1] + t[2] * 10)

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

print(max(A * 10 + B + C, A + N * 10 + C))
Problem p03252 (python)

Fixed submission:
S = input()
T = input()

d = {}
for i in range(len(S)):
  d[S[i]] = T[i]

t = []
for i in range(len(S)):
  t.append(d[S[i]])

if ''.join(t) != T or len(d.values()) != len(set(d.values())):
  print('No')
else:
  print('Yes')

Buggy submission (verdict: Runtime Error):
from sys import exit
S = input()
T = input()
for i in range(26):
  c = chr(i + ord('a'))
  d[c] = '\0'
for i in range(len(S)):
  if d[S[i]] != '\0' or d[T[i]] != '\0':
    if d[S[i]] != T[i] or d[T[i]] != S[i]:
      print('No')
      exit()
  d[S[i]] = T[i]
  d[T[i]] = S[i]
print('Yes')

Buggy submission (verdict: Runtime Error):
from sys import exit
S = input()
T = input()
d = {}
for i in range(len(S)):
  if S[i] in d or T[i] in d:
    if d[S[i]] != T[i] or d[T[i]] != S[i]:
      print('No')
      exit()
  d[S[i]] = T[i]
  d[T[i]] = S[i]
print('Yes')
Problem p03295 (python)

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

ab.sort(key=lambda x: x[1])

result = 0
t = -1
for a, b in ab:
    a, b = a - 1, b - 1
    if a <= t < b:
        continue
    result += 1
    t = b - 1
print(result)

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

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

dp = [0] * (N + 1)
for i in range(1, N + 1):
    dp[i] = max(dp[i], dp[i - 1])
    for j in ab[i]:
        dp[j] = max(dp[j], dp[i] + 1)

print(dp[N])
Problem p03317 (python)

Fixed submission:
from sys import stdin
n, k, *a = map(int, stdin.read().split())
print(((n - 1) + (k - 2)) // (k - 1))

Buggy submission (verdict: Runtime Error):
n, k = map(int, input())
print(((n - 1) + (k - 2)) // (k - 1))
Problem p03426 (python)

Fixed submission:
H, W, D = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(H)]

d = {}
for y in range(H):
    Ay = A[y]
    for x in range(W):
        d[Ay[x]] = (y, x)

t = [[0] * ((H * W + D - 1) // D + 1) for _ in range(D)]
for i in range(D):
    ti = t[i]
    j = 0
    if i == 0:
        j = 1
    while i + (j + 1) * D <= H * W:
        y1, x1 = d[i + j * D]
        y2, x2 = d[i + (j + 1) * D]
        ti[j + 1] = abs(y1 - y2) + abs(x1 - x2)
        j += 1
    for j in range(len(ti) - 1):
        ti[j + 1] += ti[j]

Q = int(input())
for _ in range(Q):
    L, R = map(int, input().split())
    i = L % D
    print(t[i][(R - i) // D] - t[i][(L - i) // D])

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

d = {}
for y in range(H):
    for x in range(W):
        d[A[y][x]] = (y, x)

t = [[0] * (H * W // D + 1) for _ in range(D)]
for i in range(D):
    j = 0
    if i == 0:
        j = 1
    while i + (j + 1) * D <= H * W:
        y1, x1 = d[i + j * D]
        y2, x2 = d[i + (j + 1) * D]
        t[i][j + 1] = abs(y1 - y2) + abs(x1 - x2)
        j += 1
    for j in range(len(H * W // D + 1) - 1):
        t[i][j + 1] += t[i][j]

Q = int(input())
for _ in range(Q):
    L, R = map(int, input().split())
    i = L % D
    print(t[i][(R - i) // D] - t[i][(L - i) // D])

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

d = {}
for y in range(H):
    Ay = A[y]
    for x in range(W):
        d[Ay[x]] = (y, x)

t = [[0] * ((H * W + D - 1) // D) for _ in range(D)]
for i in range(D):
    ti = t[i]
    j = 0
    if i == 0:
        j = 1
    while i + (j + 1) * D <= H * W:
        y1, x1 = d[i + j * D]
        y2, x2 = d[i + (j + 1) * D]
        ti[j + 1] = abs(y1 - y2) + abs(x1 - x2)
        j += 1
    for j in range(len(ti) - 1):
        ti[j + 1] += ti[j]

Q = int(input())
for _ in range(Q):
    L, R = map(int, input().split())
    i = L % D
    print(t[i][(R - i) // D] - t[i][(L - i) // D])
Problem p02580 (python)

Fixed submission:
from collections import defaultdict

h, w, m = map(int, input().split())
HW = [list(map(int, input().split())) for _ in range(m)]
dicHW = defaultdict(set)

for h, w in HW:
  dicHW[h].add(w)

hd = defaultdict(int)
wd = defaultdict(int)

for i, j in HW:
  hd[i] += 1
  wd[j] += 1

hd = list(hd.items())
wd = list(wd.items())

hd.sort(key=lambda x: -x[1])
wd.sort(key=lambda x: -x[1])

kouhoh = []
kouhow = []

for i, j in hd:
  if j < hd[0][1]:
    break
  else:
    kouhoh.append(i)

for i, j in wd:
  if j < wd[0][1]:
    break
  else:
    kouhow.append(i)

for i in kouhoh:
  for j in kouhow:
    if j not in dicHW[i]:
      ans = hd[0][1] + wd[0][1]
      print(ans)
      exit()

ans = hd[0][1] + wd[0][1] - 1  
print(ans)

Buggy submission (verdict: Runtime Error):
H,W,M = list(map(int,input().split()))

h = [0] * H
w = [0] * W

hw = []

for _ in range(H):
    hw.append([0] * W)

for _ in range(M):
    a,b = list(map(int,input().split()))
    h[a - 1] += 1
    w[b - 1] += 1
    hw[a - 1][b - 1] += 1
    
hm = max(h)
wm = max(w)

hp = [i for i, v in enumerate(h) if v == hm]
wp = [i for i, v in enumerate(w) if v == wm]

for x in hp:
    for y in wp:
        if hw[x][y] == 0:
            print(hm + wm)
            exit()
else:
    print(hm + wm - 1)

Buggy submission (verdict: Runtime Error):
from collections import defaultdict
H,W,M = list(map(int,input().split()))

h = [0] * H
w = [0] * W

hw = defaultdict(set)

for _ in range(H):
    hw.append([0] * W)

for _ in range(M):
    a,b = list(map(int,input().split()))
    h[a - 1] += 1
    w[b - 1] += 1
    hw[a - 1].add(b - 1)
    
hm = max(h)
wm = max(w)

hp = [i for i, v in enumerate(h) if v == hm]
wp = [i for i, v in enumerate(w) if v == wm]

for x in hp:
    for y in wp:
        if y in hw[x]:
            print(hm + wm)
            exit()
else:
    print(hm + wm - 1)

Buggy submission (verdict: Runtime Error):
H,W,M = list(map(int,input().split()))

h = [0] * H
w = [0] * W

hw = []

for _ in range(H):
    hw.append([0] * W)

for _ in range(M):
    a,b = list(map(int,input().split()))
    h[a - 1] += 1
    w[b - 1] += 1
    hw[a - 1][b - 1] += 1
    
hm = max(h)
wm = max(w)

hp = [i for i, v in enumerate(h) if v == hm]
wp = [i for i, v in enumerate(w) if v == wm]

for x in hp:
    for y in wp:
        if hw[x][y] == 0:
            print(hm + wm)
            exit()
else:
    print(hm + wm - 1)
Problem p02596 (python)

Fixed submission:
k = int(input())

def f(k):
  if k % 2 == 0 or k % 5 == 0:
    return -1    

  val = 7
  cnt = 1
  while cnt < 10 ** 6:
    val %= k
    if val % k == 0:
      break
    cnt += 1
    val = val * 10 + 7
  else:
    return -1
  return cnt
    
print(f(k))

Buggy submission (verdict: Runtime Error):
from collections import defaultdict

k = int(input())

def prime_factorize(n):
    a = defaultdict(int)
    while n % 2 == 0:
        a[2] += 1
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a[f] += 1
            n //= f
        else:
            f += 2
    if n != 1:
        a[n] += 1
    return a

def f(k):
  if k % 2 == 0 or k % 5 == 0:
    return -1    

  val = 7
  cnt = 1
  while True:
    if val % k == 0:
      break
    cnt += 1
    val = val * 10 + 7
  return cnt
    
li = prime_factorize(k)

ans = 1
for k, v in li.items():
  if k <= 10000:
    ans *= f(k) ** v
  else:
    ans *= (l - 1) ** v
    
if ans < 0:
  print(-1)
else:
  print(ans)
Problem p02679 (python)

Fixed submission:
from math import gcd
from collections import defaultdict

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

MOD = 1000000007

box = defaultdict(int)
zeros = 0
for a, b in AB:
  if a == b == 0:
    zeros += 1
  else:
    if a != 0 and b == 0:
      box[(-1, 1, 0)] += 1
    elif a == 0 and b != 0:
      box[(1, 0, 1)] += 1
    else:
      g = gcd(a, b)
      ga = a // g
      gb = b // g
      if (a // b) < 0:
        s = -1
      else:
        s = 1
      box[(s, abs(ga), abs(gb))] += 1
   
nakawaru = dict()
others = 0

for (s, i, j), v in box.items():
    if (-s, j, i) in box.keys():
        if (s, i, j) not in nakawaru.keys() and (-s, j, i) not in nakawaru.keys():    
            nakawaru[(s, i, j)] = (box[(s, i, j)], box[(-s, j, i)])
    else:
        others += v

seed = 1
for i, j in nakawaru.values():
    seed *= (pow(2, i, MOD) + pow(2, j, MOD) - 1)
    seed %= MOD

ans = zeros + pow(2, others, MOD) * seed - 1
ans %= MOD

print(ans)

Buggy submission (verdict: Runtime Error):
from math import gcd
from collections import defaultdict

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

MOD = 1000000007

box = defaultdict(int)
zeros = 0
for a, b in AB:
  if a == b == 0:
    zeros += 1
  else:
    if a != 0 and b == 0:
      box[(-1, 1, 0)] += 1
    elif a == 0 and b != 0:
      box[(1, 0, 1)] += 1
    else:
      g = gcd(a, b)
      ga = a // g
      gb = b // g
      if (a // b) < 0:
        s = -1
      else:
        s = 1
    box[(s, abs(ga), abs(gb))] += 1

nakawaru = dict()
others = 0

for (s, i, j), v in box.items():
    if (-s, j, i) in box.keys():
        if (s, i, j) not in nakawaru.keys() and (-s, j, i) not in nakawaru.keys():    
            nakawaru[(s, i, j)] = (box[(s, i, j)], box[(-s, j, i)])
    else:
        others += v

seed = 1
for i, j in nakawaru.values():
    seed *= (pow(2, i, MOD) + pow(2, j, MOD) - 1)
    seed %= MOD

ans = zeros + pow(2, others, MOD) * seed - 1
ans %= MOD

print(ans)

Buggy submission (verdict: Runtime Error):
from math import gcd
from collections import defaultdict

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

MOD = 1000000007

box = defaultdict(int)
zeros = 0
for a, b in AB:
  if a == b == 0:
    zeros += 1
  else:
    if a != 0 and b == 0:
      box[(-1, 1, 0)] += 1
    elif a == 0 and b != 0:
      box[(1, 0, 1)] += 1
    else:
      g = gcd(a, b)
      a //= g
      b //= g
      if a // b < 0:
        s = -1
      else:
        s = 1
    box[(s, abs(a), abs(b))] += 1
   
nakawaru = dict()
others = 0

for (s, i, j), v in box.items():
    if (-s, j, i) in box.keys():
        if (s, i, j) not in nakawaru.keys() and (-s, j, i) not in nakawaru.keys():    
            nakawaru[(s, i, j)] = (box[(s, i, j)], box[(-s, j, i)])
    else:
        others += v

seed = 1
for i, j in nakawaru.values():
    seed *= (pow(2, i, MOD) + pow(2, j, MOD) - 1)
    seed %= MOD

ans = zeros + pow(2, others, MOD) * seed - 1
ans %= MOD

print(ans)
Problem p02757 (python)

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

if p == 2 or p == 5:
  ans = 0
  for i, x in enumerate(S[::-1]):
    if x % p == 0:
      ans += n - i
else:
  mods = [0 for _ in range(p)]
  mods[0] = 1

  num = 0
  digit = 1
  for s in S[::-1]:
    num = (s * digit + num) % p
    mods[num] += 1
    digit = (digit * 10) % p
  
  ans = 0
  for m in mods:
    ans += m * (m - 1) // 2

print(ans)

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

MOD = p

mods = [0 for _ in range(2019)]
mods[0] = 1

num = 0
digit = 1
for s in S[::-1]:
  num = s * digit + num
  num %= MOD
  mods[num] += 1
  digit = (digit * 10) % MOD
  
ans = 0
for m in mods:
  ans += m * (m - 1) // 2

print(ans)
Problem p02781 (python)

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

from math import factorial
def comb(n, r):
  if r < 0 or r > n:
    return 0
  else:
    return factorial(n) // (factorial(n - r) * factorial(r))

# 左から i 桁目以降について、0 以外の値を残り K 個使用可能
# smaller: i 桁目までが 一致している時=False, 小さい時=True  
def solve(i, k, smaller):
  if i == n:
    if k == 0:
      return 1
    else:
      return 0
  if k == 0:
    return 1
  if smaller:
    return comb(n - i, k) * 9 ** k
  else:
    if S[i] == "0":
      return solve(i + 1, k, False)
    else:
      zero = solve(i + 1, k, True)
      aida = solve(i + 1, k - 1, True) * (int(S[i]) - 1)
      icchi = solve(i + 1, k - 1, False)
      return zero + aida + icchi

S = input()  
n = len(S)
k = int(input())
print(solve(0, k, False))

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10 ** 6)

from math import factorial
def comb(n, r):
  if r < 0 or r > n:
    return 0
  else:
    return factorial(n) // (factorial(n - r) * factorial(r))

# 左から i 桁目以降について、0 以外の値を残り K 個使用可能
# smaller: i 桁目までが 一致している時=False, 小さい時=True  
def solve(i, k, smaller):
  if i == n:
    if k == 0:
      return 1
    else:
      return 0
  if k == 0:
    return 1
  if smaller:
    return comb(n - i, k) * 9 ** k
  else:
    if S[i] == "0":
      return solve(i + 1, k, Flase)
    else:
      zero = solve(i + 1, k, True)
      aida = solve(i + 1, k - 1, True) * (int(S[i]) - 1)
      icchi = solve(i + 1, k - 1, False)
      return zero + aida + icchi

S = input()  
n = len(S)
k = int(input())
print(solve(0, k, False))

Buggy submission (verdict: Runtime Error):
from math import factorial
def comb(n, r):
  if r < 0 or r > n:
    return 0
  else:
    return factorial(n) // (factorial(n - r) * factorial(r))

# 左から i 桁目以降について、0 以外の値を残り K 個使用可能
# smaller: i 桁目までが 一致している時=False, 小さい時=True  
def solve(i, k, smaller):
  if i == n:
    if k == 0:
      return 1
    else:
      return 0
  if k == 0:
    return 1
  if smaller:
    return comb(n - i, k) * 9 ** k
  else:
    if S[i] == "0":
      return solve(i + 1, k, Flase)
    else:
      zero = solve(i + 1, k, True)
      aida = solve(i + 1, k - 1, True) * (int(S[i]) - 1)
      icchi = solve(i + 1, k - 1, False)
      return zero + aida + icchi

S = input()  
n = len(S)
k = int(input())
print(solve(0, k, False))
Problem p02831 (python)

Fixed submission:
from fractions import gcd

# 最小公倍数
def lcm(x, y):
    return (x * y) // gcd(x, y)

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

ans = lcm(A, B)

print(ans)

Buggy submission (verdict: Runtime Error):
# C - Snack
# https://atcoder.jp/contests/abc148/tasks/abc148_c

from math import gcd

def lcm(x, y):
    return (x * y) // gcd(x, y)

a, b = map(int, input().split())
print(lcm(a, b))
Problem p02835 (python)

Fixed submission:
suma = sum(list(map(int, input().split())))
if suma >= 22:
  print("bust")
else:
  print("win")

Buggy submission (verdict: Runtime Error):
ERGTHJKJKJREbv ffffffs bboiuyazxcvbnm,.,mnbvcvbnjmk,l.kjhgfxzxcbnbvcxzxcvbgvcx
Problem p02862 (python)

Fixed submission:
X, Y = map(int, input().split())
def framod(n, mod, a=1):
    for i in range(1,n+1):
        a=a * i % mod
    return a

def power(n, r, mod):
    if r == 0: return 1
    if r%2 == 0:
        return power(n*n % mod, r//2, mod) % mod
    if r%2 == 1:
        return n * power(n, r-1, mod) % mod

def comb(n, k, mod):
    a=framod(n, mod)
    b=framod(k, mod)
    c=framod(n-k, mod)
    return (a * power(b, mod-2, mod) * power(c, mod-2, mod)) % mod
  
mod = 10 ** 9 + 7
  
if (X + Y) % 3 == 0:
  n = (X + Y) // 3 
  if min(X, Y) >= n:
    s = min(X, Y) - n
    ans = comb(n, s, mod)
  else:
    ans = 0
else:
  ans = 0

print(ans)

Buggy submission (verdict: Runtime Error):
X, Y = map(int, input().split())
def framod(n, mod, a=1):
    for i in range(1,n+1):
        a=a * i % mod
    return a

def power(n, r, mod):
    if r == 0: return 1
    if r%2 == 0:
        return power(n*n % mod, r//2, mod) % mod
    if r%2 == 1:
        return n * power(n, r-1, mod) % mod

def comb(n, k, mod):
    a=framod(n, mod)
    b=framod(k, mod)
    c=framod(n-k, mod)
    return (a * power(b, mod-2, mod) * power(c, mod-2, mod)) % mod
mod = 10 ** 9 + 7
  
if (X + Y) % 3 == 0:
  n = (X + Y) // 3 
  if min(X, Y) >= n:
    s = min(X, Y) - n
    ans = comb(n, s, mod)
else:
  ans = 0

print(ans)

Buggy submission (verdict: Runtime Error):
X, Y = map(int, input().split())

def comb(n, k, p):
  # nCk mod p (組合せのmod)
  from math import factorial
  if n < 0 or k < 0 or n < k:
    return 0
  if n == 0 or k == 0:
    return 1
  a = factorial(n) % p
  b = factorial(k) % p
  c = factorial(n - k) % p
  return (a * power_func(b, p - 2, p) * power_func(c, p - 2, p)) % p

def power_func(a, b, p):
  # a ^ b mod p # (指数のmod)
  if b == 0:
    return 1
  if b % 2 == 0:
    d = power_func(a, b // 2, p)
    return d * d % p
  if b % 2 == 1:
    return (a * power_func(a, b - 1, p )) % p

mod = 10 ** 9 + 7
  
if (X + Y) % 3 == 0:
  n = (X + Y) // 3 
  if min(X, Y) >= n:
    s = min(X, Y) - n
    ans = comb(n, s, mod)
else:
  ans = 0

print(ans)
Problem p02948 (python)

Fixed submission:
import heapq

N, M = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(N)]
ABS = sorted(AB, key=lambda x: -x[1])
ABSS = sorted(ABS, key=lambda x: x[0])
# print(ABS)
# print(ABSS)

heap = []
ans = 0
chkpos = 0

for i in range(1, M + 1):
  if chkpos < N:
    while ABSS[chkpos][0] <= i:
  #    print(chkpos, len(ABSS))
      heapq.heappush(heap, -1 * ABSS[chkpos][1])
      chkpos += 1
      if chkpos >= N:
        break
  #  print(heap)
    if len(heap) > 0:
      ans -= heapq.heappop(heap)
  else:
    ans -= heapq.heappop(heap)
print(ans)

Buggy submission (verdict: Runtime Error):
import heapq

N, M = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(N)]
ABS = sorted(AB, key=lambda x: -x[1])
ABSS = sorted(ABS, key=lambda x: x[0])
# print(ABS)
# print(ABSS)

heap = []
ans = 0
chkpos = 0

for i in range(1, M+1):
  while ABSS[chkpos][0] <= i:
    heapq.heappush(heap, -1 * ABSS[chkpos][1])
    chkpos += 1
    if chkpos >= N -1:
      break
#  print(heap)
  if len(heap) > 0:
    ans -= heapq.heappop(heap)
print(ans)
Problem p02954 (python)

Fixed submission:
s = input()
# RR...RL...LLとなる文字列ssに分割して考える
import math
# len(ss) % 2 == 0 の場合は、境界にlen(ss)/2ずつ
# 奇数の場合は、ss[0]大、ss[1]小、→ss[偶数]大、ss[奇数]小
ans = [0] * len(s)
ss = []
start = 0
for i in range(len(s) - 1):
  if (s[i]=="L" and s[i+1]=="R"):
    ss.append(s[start:i+1])
    start = i+1
  elif i == len(s) - 2:
    ss.append(s[start:i+2])  
#print(ss)
# rlposはr,lの位置
sumlenj = 0
for j in ss: 
  rlpos = j.find("RL")
  if len(j) % 2 == 0:
    ans[sumlenj+rlpos] = int(len(j)/2)
    ans[sumlenj+rlpos+1] = int(len(j)/2)
  else:
    if rlpos % 2 == 0:
      ans[sumlenj+rlpos] = int(math.ceil(len(j)/2))
      ans[sumlenj+rlpos+1] = int(math.floor(len(j)/2))
    else:
      ans[sumlenj+rlpos] = int(math.floor(len(j)/2))
      ans[sumlenj+rlpos+1] = int(math.ceil(len(j)/2))
  sumlenj += len(j)
print(*ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
H = list(map(int, input().split()))
for i in range(N-1):
  if H[i] > H[i+1] + 1:
    print("No")
    exit()
  elif H[i] <= H[i+1]:
    if i > 0:
      if H[i-1] <= H[i]-1:
        H[i] -= 1        
  elif H[i] == H[i+1] + 1:
    H[i] -= 1
    if i > 0:
      if H[i-1] > H[i]:
        print("No")
        exit()
print("Yes")
Problem p02990 (python)

Fixed submission:
import math
c = 10**9+7

n, k = map(int, input().split())

def combinations_count(n, r):
  if n <= r:
    return 1
  else:
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

for i in range(1, k+1):
  a = combinations_count(k-1, i-1) 
  if n-k >= i-1:
    b = combinations_count(n-k+1, i)
  else:
    b = 0
  print(int((a*b) % c))

Buggy submission (verdict: Runtime Error):
c = 10**9+7

n, k = map(int, input().split())

def combinations_count_mod(n, r, c):
  r = min(n-r,r)
  if r == 0: return 1
  ret = 1
  for j in range(r):
    ret *= (n-j)/(r-j) % c
  return ret

for i in range(1, k+1):
  a = combinations_count_mod(k-1, i-1, c) 
  if n-k >= i-1:
    b = (combinations_count_mod(n-k+1, i, c))
  else:
    b = 0
  print(int((a*b) % c))

Buggy submission (verdict: Runtime Error):
c = 10**9+7

n, k = map(int, input().split())

def combinations_count_mod(n, r, c):
  ret = 1
  for j in range(r):
    ret *= (n-j)/(r-j) % c
  return ret

for i in range(1, k+1):
  a = combinations_count_mod(k-1, i-1, c) 
  if n-k >= i-1:
    b = (combinations_count_mod(n-k+1, i, c))
  else:
    b = 0
  print(int((a*b) % c))

Buggy submission (verdict: Runtime Error):
c = 10**9+7

n, k = map(int, input().split())

def combinations_count_mod(n, r):
  ret = 1
  for i in range(r):
    ret *= (n-i)/(r-i) % c
  return ret

for i in range(1, k+1):
  a = combinations_count_mod(k-1, i-1) 
  if n-k > i-1:
#    if n-k-i >= 1:
    b = (combinations_count_mod(n-k-1, i-1) * ((n-k-1-(i-1))/i + 2)) 
#    else:
#      b = (n-k-1) * 3
  elif n-k == i-1:
    b = 1
  else:
    b = 0
  print(int((a*b) % c))