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

Fixed submission:
import sys
sys.setrecursionlimit(202020)

N = int(input())
won = [[] for i in range(N)]
for i in range(1,N):
    a = int(input()) - 1
    won[a].append(i)

def height(v):
    if not won[v]: return 0
    hs = [height(op) for op in won[v]]
    ret = 0
    for i,h in enumerate(sorted(hs)):
        ret = max(ret, h + len(hs) - i)
    return ret

print(height(0))

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(101010)

N = int(input())
won = [[] for i in range(N)]
for i in range(1,N):
    a = int(input()) - 1
    won[a].append(i)

def height(v):
    if not won[v]: return 0
    hs = [height(op) for op in won[v]]
    ret = 0
    for i,h in enumerate(sorted(hs)):
        ret = max(ret, h + len(hs) - i)
    return ret

print(height(0))
Problem p02546 (python)

Fixed submission:
s = input()
if s[-1] == 's':
  print(s + 'es')
else:
  print(s + 's')

Buggy submission (verdict: Runtime Error):
n,k = map(int,input().split())
lr = []
for _ in range(k):
  lr.append(list(map(int,input().split())))
#print(lr)
imos = [0 for _ in range(n)]
imos[0] = 1
imos[1] = -1
now = 0
mod = 998244353
for i in range(n):
    now += imos[i]
    now %= mod
    #print(now)
    for j in range(k):
        try:
            imos[i+lr[j][0]] += now
            imos[i+lr[j][0]] %= mod
        except:
            pass
        try:
            imos[i+lr[j][1]+1] -= now
            imos[i+lr[j][1]+1] %= mod
        except:
            pass
    #print(imos)
print(now)
Problem p02557 (python)

Fixed submission:
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
b.reverse()
c = []
cs = -1
e = -1
for i in range(n):
  if a[i] > b[i]:
    c.append(1)
  elif a[i] == b[i]:
    c.append(0)
    e = a[i]
    if cs == -1:
      cs = i
  else:
    c.append(-1)
#print(a)
#print(b)
#print(c)
ans = 0
db = 0
for i in range(n):
  if a[i] == e:
    ans += 1
  if b[i] == e:
    ans += 1
  if a[i] == b[i]:
    db += 1
if ans > n:
  print('No')
  exit()
print('Yes')
cnt = 0
#print(b)
#print(cs,db)
for i in range(n):
  if cnt == db:
    break
  #print(i,a[i],b[i])
  if a[i] != e and b[i] != e:
    b[i],b[cs+cnt] = b[cs+cnt],b[i]
    cnt += 1
    #print(b)
print(' '.join(map(str,b)))

Buggy submission (verdict: Runtime Error):
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
b.reverse()
c = []
cs = -1
for i in range(n):
  if a[i] > b[i]:
    c.append(1)
  elif a[i] == b[i]:
    c.append(0)
    e = a[i]
    if cs == -1:
      cs = i
  else:
    c.append(-1)
#print(a)
#print(b)
#print(c)
ans = 0
for i in range(n):
  if a[i] == e:
    ans += 1
  if b[i] == e:
    ans += 1
if ans*2 > n:
  print('No')
else:
  print('Yes')
cnt = 0
for i in range(n):
  if cnt == ans:
    break
  if a[i] != e and b[i] != e:
    b[i],b[cs+cnt] = b[cs+cnt],b[i]
print(' '.join(map(str,b)))
Problem p02659 (python)

Fixed submission:
a,b = input().split()
a = int(a)
c,d = b.split('.')
c = int(c)
d = int(d)
print(a*c+a*d//100)

Buggy submission (verdict: Runtime Error):
a,b = map(int,input())
print(int(a*b))
Problem p02679 (python)

Fixed submission:
mod = 10**9+7
n = int(input())
inf = 10**20
fish = {}
rish = {}
att = 0
raw = []
raz = []
def lon(a,b,p):
  return p*10**40 + a*10**20 + b
def rev(z):
  p,a,b = z//(10**40),(z//(10**20))%(10**20),z%(10**20)
  return lon(b,a,1-p)
for _ in range(n):
  a,b = map(int,input().split())
  r = 1
  if a*b == 0:
    if a == b == 0:
      att += 1
    elif a == 0:
      raw.append(lon(0,1,1))
      raz.append(lon(1,0,0))
      fish[lon(0,1,1)] = [0,0]
      fish[lon(1,0,0)] = [0,0]
    else:
      raw.append(lon(1,0,0))
      raz.append(lon(0,1,1))
      fish[lon(1,0,0)] = [0,0]
      fish[lon(0,1,1)] = [0,0]
    continue
  if a*b < 0:
    r = 0
  a = abs(a)
  b = abs(b)
  big = int(a)
  sml = int(b)
  while sml != 0:
    big,sml = sml,big%sml
  a //= big
  b //= big
  raw.append(lon(a,b,r))
  raz.append(lon(b,a,1-r))
  fish[lon(a,b,r)] = [0,0]
  fish[lon(b,a,1-r)] = [0,0]
for x in raw:
  fish[x][0] += 1
for x in raz:
  fish[x][1] += 1
double = [1]
for _ in range(3*10**5):
  double.append(double[-1]*2%mod)
ans = 1
#print(fish)
for x in fish:
  re = rev(x)
  #print(x,fish[x][0],fish[x][1])
  #print(re)
  ans *= double[fish[x][0]] + double[fish[x][1]] - 1
  ans %= mod
  fish[x] = [0,0]
  fish[re] = [0,0]
ans -= 1
ans += att
ans %= mod
print(ans)

Buggy submission (verdict: Runtime Error):
mod = 10**9+7
n = int(input())
fish = {}
rish = {}
att = 0
for _ in range(n):
  a,b = map(int,input().split())
  if a*b != 0:
    try:
      fish[a/b] += 1
    except:
      fish[a/b] = 1
    rish[-b/a] = 1
  elif a == 0 and b == 0:
    att += 1
  elif a == 0:
    try:
      fish[0] = 1
    except:
      fish[0] = 1
    rish[10**20] = 1
  else:
    try:
      fish[10**20] = 1
    except:
      fish[10**20] = 1
    rish[0] = 1
#print(fish)
#print(rish)
double = [1]
for _ in range(3*10**5):
  double.append(double[-1]*2%mod)
ans = 1
for x in fish:
  if not fish[x]:
    #print('#',x)
    continue
  if x in rish:
    ans *= double[fish[x]] + double[fish[-1/x]] - 1
    ans %= mod
    fish[x] = 0
    fish[-1/x] = 0
  else:
    ans *= double[fish[x]]
    ans %= mod
  #print(ans)
ans = ans-1+att
ans %= mod
print(ans)
Problem p02685 (python)

Fixed submission:
n,m,k = map(int,input().split())
mod = 998244353
if m == 1:
  if k == n-1:
    print(1)
  else:
    print(0)
  exit()
def inv(x):
  y = 1
  while x != 1:
    y *= mod // x + 1
    y %= mod
    x -= mod % x
  return y
#print(inv(2))
now = int(m)
for _ in range(n-1):
  now *= m-1
  now %= mod
ans = int(now)
for i in range(k):
  now *= inv(m-1)
  now *= n-1-i
  now *= inv(i+1)
  now %= mod
  #print(now)
  ans += now
  ans %= mod
print(ans)

Buggy submission (verdict: Runtime Error):
n,m,k = map(int,input().split())
mod = 998244353
def inv(x):
  y = 1
  while x != 1:
    y *= mod // x + 1
    y %= mod
    x -= mod % x
  return y
#print(inv(2))
now = m
for _ in range(n-1):
  now *= m-1
  now %= mod
ans = int(now)
for i in range(k):
  now *= inv(m-1)
  now *= n-1-i
  now *= inv(i+1)
  now %= mod
  #print(now)
  ans += now
  ans %= mod
print(ans)
Problem p02759 (python)

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

Buggy submission (verdict: Runtime Error):
n,m,k = map(int,input().split())
num = [1 for _ in range(n)]
pre = [i for i in range(n)]
for _ in range(m):
  a,b = map(int,input().split())
  a -= 1
  b -= 1
  num[a] += 1
  num[b] += 1
  A = [a]
  B = [b]
  la = 1
  lb = 1
  while a != pre[a]:
    a = pre[a]
    A.append(a)
    la += 1
  while b != pre[b]:
    b = pre[b]
    B.append(b)
    lb += 1
  #print(a,b)
  if a != b:
    if la > lb:
      pre[b] = a
      for aa in A:
        pre[aa] = a
      for bb in B:
        pre[bb] = a
    else:
      pre[a] = b
      for aa in B:
        pre[aa] = b
      for bb in B:
        pre[bb] = b
root = []
cnt = [0 for _ in range(n)]
for i in range(n):
  I = int(i)
  while I != pre[I]:
    I = pre[I]
  root.append(I)
  cnt[I] += 1
#print(pre)
#print(root)
#print(cnt)
ans = []
for i in range(n):
  ans.append(cnt[root[i]]-num[i])
#print(ans)
for _ in range(k):
  a,b = map(int,input().split())
  a -= 1
  b -= 1
  if root[a] == root[b]:
    ans[a] -= 1
    ans[b] -= 1
print(' '.join(map(str,ans)))
Problem p02891 (python)

Fixed submission:
s = input()
k = int(input())
l = len(s)
s = s * 3
dp = [0,0]
check = []
for i in range(3*l-1):
  if s[i+1] != s[i]:
    dp.append(dp[-1])
  else:
    dp.append(dp[-2]+1)
  if (i+2) % l == 0:
    check.append(dp[-1])
if l == 1:
  ans =  k // 2
elif k % 2 == 0:
  ans = check[1] + (k-2) // 2 * (check[2]-check[0])
else:
  ans = check[0] + (k-1) // 2 * (check[2]-check[0])
print(ans)

Buggy submission (verdict: Runtime Error):
s = input()
k = int(input())
l = len(s)
s = s * 3
dp = [0,0]
check = []
for i in range(3*l-1):
  if s[i+1] != s[i]:
    dp.append(dp[-1])
  else:
    dp.append(dp[-2]+1)
  if (i+2) % l == 0:
    check.append(dp[-1])
if k % 2 == 0:
  ans = check[1] + (k-2) // 2 * (check[2]-check[0])
else:
  ans = check[0] + (k-1) // 2 * (check[2]-check[0])
print(ans)
Problem p02954 (python)

Fixed submission:
s = input()
n = len(s)
up = []
down = []
parity = 0
for i in range(1,n):
  if s[i] != s[i-1]:
    if parity == 0:
      down.append(i)
    else:
      up.append(i)
    parity = 1 - parity
ans = [0 for i in range(n)]
#print(up,down)
for i in range(n):
  if s[i] == 'R':
    diff = down[0] - i
    if diff % 2 == 1:
      ans[down[0]-1] += 1
    else:
      ans[down[0]] += 1
  else:
    diff = i - down[0]
    if diff % 2 == 1:
      ans[down[0]-1] += 1
    else:
      ans[down[0]] += 1
  if up != []:
    if i+1 == up[0]:
      del down[0]
      del up[0]
ANS = list(map(str,ans))
print(' '.join(ANS))

Buggy submission (verdict: Runtime Error):
s = input()
n = len(s)
up = []
down = []
for i in range(1,n):
  if s[i] != s[i-1]:
    if s[i] == 'L':
      down.append(i)
    else:
      up.append(i)
ans = [0 for _ in range(n)]
try:
  top = up[0]
except:
  top = n
bottom = down[0]
count = 0
for i in range(n):
  diff = i - bottom
  if diff % 2 == 0:
    ans[bottom] += 1
  else:
    ans[bottom-1] += 1
  #print(ans)
  if i+1 == top:
    count += 1
    try:
      top = up[count]
    except:
      pass
    bottom = down[count]
print(' '.join(map(str,ans)))

Buggy submission (verdict: Runtime Error):
s = input()
n = len(s)
up = []
down = []
for i in range(1,n):
  if s[i] != s[i-1]:
    if s[i] == 'L':
      down.append(i)
    else:
      up.append(i)
ans = [0 for _ in range(n)]
top = up[0]
bottom = down[0]
count = 0
for i in range(n):
  diff = i - bottom
  if diff % 2 == 0:
    ans[bottom] += 1
  else:
    ans[bottom-1] += 1
  #print(ans)
  if i+1 == top:
    count += 1
    try:
      top = up[count]
    except:
      pass
    bottom = down[count]
print(' '.join(map(str,ans)))

Buggy submission (verdict: Runtime Error):
s = input()
n = len(s)
up = []
down = []
parity = 0
for i in range(1,n):
  if s[i] != s[i-1]:
    if parity == 0:
      down.append(i)
    else:
      up.append(i)
    parity = 1 - parity
ans = [0 for i in range(n)]
count = 0
top = up[0]
bottom = down[0]
for i in range(n):
  diff = down[0] - i
  if diff % 2 == 1:
    ans[bottom-1] += 1
  else:
    ans[bottom] += 1
  if len(up) > count + 1:
    if i+1 == top:
      count += 1
      top = up[count]
      bottom = down[count]
ANS = list(map(str,ans))
print(' '.join(ANS))
Problem p03011 (python)

Fixed submission:
A = list(map(int,input().split()))
print(sum(A)-max(A))

Buggy submission (verdict: Runtime Error):
#23:39
a = map(int,input().split())
print( sum(a) - max(a) )
Problem p03038 (python)

Fixed submission:
n,m= map(int,input().split())
AA = list(map(int,input().split()))
A = [(AA[i],1) for i in range(n)]
for _ in range(m):
  b,c = map(int,input().split())
  A += [(c,b)]
A.sort()
A.reverse()
rest = n
score = 0
for (cc,bb) in A:
  use = min(bb,rest)
  rest -= use
  score += use*cc
print(score)

Buggy submission (verdict: Runtime Error):
n,m= map(int,input().split())
A = list(map(int,input().split()))
B = []
for _ in range(m):
  b,c = map(int,input().split())
  B += [c]*b
A.sort()
B.sort(reverse=True)
B += [0]*n
mark = 0
i = 0
while True:
  if A[i] > B[i]:
    mark = i
    break
  else:
    i += 1
print(sum(B[:i])+sum(A[i:n+1]))
Problem p03045 (python)

Fixed submission:
#解説チラ見
n,m = map(int,input().split())
ans = n
pre = [i for i in range(n)]
for _ in range(m):
  x,y,z = map(lambda x: int(x)-1, input().split())
  X = [x]
  while pre[x] != x:
    x = pre[x]
    X.append(x)
  Y = [y]
  while pre[y] != y:
    y = pre[y]
    Y.append(y)
  if x != y:
    ans -= 1
    for xx in X:
      pre[xx] = y
    for yy in Y:
      pre[yy] = y
    pre[x] = y
print(ans)

Buggy submission (verdict: Runtime Error):
#17:11
n,m = map(int,input().split())
pre = [-1 for i in range(n)]
for _ in range(m):
  x,y,z = map(int,input().split())
  x -= 1
  y -= 1
  while pre[x] != -1:
    x = pre[x]
  while pre[y] != -1:
    y = pre[y]
  if x != y:
    if len(X) > len(Y):
      pre[x] = y
    else:
      pre[y] = x
father = set()
ans = 0
for i in range(n):
  if pre[i] == -1:
    ans += 1
#print(pre)
print(ans)

Buggy submission (verdict: Runtime Error):
#17:11
n,m = map(int,input().split())
pre = [-1 for i in range(n)]
for _ in range(m):
  x,y,z = map(int,input().split())
  x -= 1
  y -= 1
  X = []
  Y = []
  while pre[x] != -1:
    X.append(x)
    x = pre[x]
  while pre[y] != -1:
    Y.append(Y)
    y = pre[y]
  if x != y:
    if len(X) > len(Y):
      pre[x] = y
      for xx in X:
        pre[xx] = y
      for yy in Y:
        pre[yy] = y
    else:
      pre[y] = x
      for xx in X:
        pre[xx] = x
      for yy in Y:
        pre[yy] = x
father = set()
ans = 0
for i in range(n):
  if pre[i] == -1:
    ans += 1
#print(pre)
print(ans)
Problem p03135 (python)

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

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

Fixed submission:
#14:22
n,k = map(int,input().split())
whole = [1]
patty = [1]
for _ in range(n):
  whole.append(whole[-1] * 2 + 3)
  patty.append(patty[-1] * 2 + 1)
ans = 0
rest = k
for i in range(n,-1,-1):
  if i == 0:
    ans += [0,1,2,3,3][rest]
    rest = 0
  elif rest <= whole[i] - (i-1):
    rest -= 1
  elif rest <= whole[i]:
    rest = 0
    ans += patty[i]
  elif rest == whole[i] + 1:
    rest -= whole[i] + 1
    ans += patty[i] + 1
  else:
    rest -= whole[i] + 2
    ans += patty[i] + 1
  if rest == 0:
    print(ans)
    break

Buggy submission (verdict: Runtime Error):
#14:22
n,k = map(int,input().split())
whole = [1]
patty = [1]
for _ in range(n):
  whole.append(whole[-1] * 2 + 3)
  patty.append(patty[-1] * 2 + 1)
ans = 0
rest = k
for i in range(n,-1,-1):
  if i == 0:
    ans += [0,1,2,3,3][rest]
    rest = 0
  elif rest < whole[i]:
    rest -= 1
  elif rest == whole[i]:
    rest -= whole[i]
    ans += patty[i]
  elif rest == whole[i] + 1:
    rest -= whole[i] + 1
    ans += patty[i] + 1
  else:
    rest -= whole[i] + 2
    ans += patty[i] + 1
  if rest == 0:
    print(ans)
    break

Buggy submission (verdict: Runtime Error):
#14:22
n,k = map(int,input().split())
whole = [1]
patty = [1]
for _ in range(n):
  whole.append(whole[-1] * 2 + 3)
  patty.append(patty[-1] * 2 + 1)
ans = 0
rest = k
for i in range(n,-1,-1):
  if i == 0:
    ans += [0,0,1,2,3][rest]
    rest = 0
  elif rest < whole[i]:
    rest -= 1
  elif rest == whole[i]:
    rest -= whole[i]
    ans += patty[i]
  elif rest == whole[i] + 1:
    rest -= whole[i] + 1
    ans += patty[i] + 1
  else:
    rest -= whole[i] + 2
    ans += patty[i] + 1
  if rest == 0:
    print(ans)
    break
Problem p02623 (python)

Fixed submission:
import bisect

def main():
    N,M,K = map(int, input().split())
    A_list = list(map(int, input().split()))
    B_list = list(map(int, input().split()))

    # cumsum
    A_cum = [0] * (N+1)
    B_cum = [0] * (M)
    ap = 0
    for i, a in enumerate(A_list):
        A_cum[i+1] = ap + a
        ap += a
    bp = 0
    for i, b in enumerate(B_list):
        B_cum[i] = bp + b
        bp += b

    max_cnt = 0
    for i in range(N+1):
        a = A_cum[i]
        if a > K:
            break
        bi = bisect.bisect_right(B_cum, K-a)
        max_cnt = max(max_cnt, i+bi)

    print(max_cnt)

if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):


N,M,K = map(int, input().split())
A_list = list(map(int, input().split()))
B_list = list(map(int, input().split()))

ai = 0
bi = 0
cnt = 0
while True:
    if ai == N and bi == M:
        break
    elif ai == N:
        if B_list[bi] <= K:
            cnt += 1
            K -= B_list[bi]
            bi += 1
        else:
            break
    elif bi == N:
        if A_list[ai] <= K:
            cnt += 1
            K -= A_list[ai]
            ai += 1
        else:
            break

    elif A_list[ai] < B_list[bi]:
        if A_list[ai] <= K:
            cnt += 1
            K -= A_list[ai]
            ai += 1
        else:
            break
    else:
        if B_list[bi] <= K:
            cnt += 1
            K -= B_list[bi]
            bi += 1
        else:
            break
print(cnt)
Problem p02685 (python)

Fixed submission:

N,M,K = map(int, input().split())
MOD = 998244353

fact = [0] * (N+1)
inv = [0] * (N+1)

fact[0] = fact[1]  = 1
inv[1] = 1

for i in range(2, N+1):
    fact[i] = fact[i-1] * i % MOD
    inv[i] = MOD - inv[MOD%i] * (MOD//i) % MOD # //で良いのかな?

def main():
    if N == 1:
        print(M)
        return 
    num = M
    nums = [M]
    for i in reversed(range(1,N)):
        num *= i*(M-1)
        num *= inv[N-i]
        num %= MOD
        nums.append(num)
    nums.reverse()
    print(sum(nums[:K+1])%MOD)

    
if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
def main():
    N,M,K = map(int, input().split())
    MOD = 998244353

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

    for i in range(1,N):
        dp[0][i] = (dp[0][i-1] * (M-1)) % MOD

        for k in range(1, K+1):
            dp[k][i] = (dp[k][i-1] * (M-1) + dp[k-1][i-1]) % MOD
        
    res = 0
    for k in range(K+1):
        res += dp[k][-1]
    print(res)


if __name__ == "__main__":
    main()
Problem p02777 (python)

Fixed submission:
S,T = input().split()
N,M = list(map(int, input().split()))
s = input()
if s == S:
  print(N-1, M)
else:
  print(N, M-1)

Buggy submission (verdict: Runtime Error):
S,T = input().split()
N,M = list(map(int, input().split()))
s = input()
print(f"{N-1} {M}" if s == S else f"{N} {M-1}")
Problem p02891 (python)

Fixed submission:

def func():
    if len(S) == 1:
        return int(K/2)
    
    cnt = 1
    pre_s = S[0]
    tup_list = []
    for s in S[1:]:
        if pre_s == s:
            cnt += 1
        else:
            tup_list.append([pre_s, cnt])
            cnt = 1
        pre_s = s
    else:
        tup_list.append([pre_s, cnt])

    if len(tup_list) == 1:
        return int(cnt* K/2)
    
    ext = 0
    if tup_list[0][0] == tup_list[-1][0]:
        a = tup_list.pop()[1]
        b = tup_list[0][1]
        ext = int(a/2) + int(b/2) - int((a+b)/2)
        tup_list[0][1] += a
        
    res = 0
    for _,cnt in tup_list:
        res += int(cnt/2) * K
    return res + ext
    
S = input()
K = int(input())
print(func())

Buggy submission (verdict: Runtime Error):

def func():
    if len(S) == 1:
        return int(K/2)
    
    cnt = 1
    pre_s = S[0]
    tup_list = []
    for s in S[1:]:
        if pre_s == s:
            cnt += 1
        else:
            tup_list.append([pre_s, cnt])
            cnt = 1
        pre_s = s
    else:
        tup_list.append([pre_s, cnt])

    if len(tup_list) == 1:
        return int(cnt* K/2)
    
    if tup_list[0][0] == tup_list[-1][0]:
        pre_tup = tup_list.pop()[1]
        tup_list[0][1] += pre_tup
    res = -1 if pre_tup % 2 == 1 else 0
    for _,cnt in tup_list:
        res += int(cnt/2) * K
    return max(0,res) 

S = input()
K = int(input())
print(func())
Problem p02948 (python)

Fixed submission:
import heapq
n,m = input().split(" ")
n = int(n)
m = int(m)

arr = [[] for _ in range(m)]

for i in range(n):
  a,b = input().split(" ")
  a = int(a)
  b = - int(b) # for heap
  
  if a > m:
    continue
    
  arr[a-1].append(b)

vs = []
heapq.heapify(vs)

res = 0
for item in arr:
  for v in item:
	  heapq.heappush(vs, v)
  
  if len(vs) == 0:
    continue
    
  maxi = heapq.heappop(vs)
  res += (-1* maxi)
  
print(res)

Buggy submission (verdict: Runtime Error):
n,m = input().split(" ")
n = int(n)
m = int(m)

arr = [[] for _ in range(m)]

for i in range(n):
  a,b = input().split(" ")
  a = int(a) -1
  b = int(b)
  
  if a > m:
    continue
  arr[a].append(b)

vs = []
res = 0
for item in arr:
  vs[len(vs):len(vs)] = item
  if len(vs) == 0:
    continue
    
  vs.sort()
  maxi = vs.pop(-1)
  res += maxi
  
print(res)
Problem p03013 (python)

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

MOD = 10**9+7

dp = [0] * (10**5 + 3)
dp[1] = 0
dp[2] = 1
dp[3] = 2
for i in range(3, len(dp)):
    dp[i] = dp[i-1] + dp[i-2] 

res = 1
bef = -1
if M > 0:
    for a in a_list:
        res *= dp[a-bef]
        res %= MOD
        bef = a
res *= dp[N-bef+1]
res %= MOD

print(res)

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

MOD = 10**9+7

dp = [0] * (N+1)
dp[1] = 0
dp[2] = 1
dp[3] = 2
for i in range(3, N+1):
    dp[i] = dp[i-1] + dp[i-2]

res = 1
bef = -1
for a in a_list:
    res *= dp[a-bef]
    res %= MOD
    bef = a

res *= dp[N-bef+1]
res %= MOD

print(res)
Problem p03295 (python)

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

arr = [[] for i in range(n)]

for i in range(m):
	a, b = list(map(int, input().split()))
	arr[a-1].append(b)	

cnt = 0	
sting = n+1
for i,isl in enumerate(arr):
	isl.sort()
	if sting == i+1:
		cnt += 1
		sting = n+1

	if len(isl) == 0:
		continue
		
	if isl[0] < sting:
		sting = isl[0]
print(cnt)

Buggy submission (verdict: Runtime Error):
nm = input()
n, m = nm.split()
n = int(n)
m = int(m)

arr = [[] for i in range(n)]

for i in range(m):
	ab = input()
	a, b = ab.split()
	a = int(a)
	b = int(b)
	arr[a-1].append(b)	

cnt = 0	
sting = 0
for i,isl in enumerate(arr):
	sting = isl[0]
	for j in arr[i:sting]:
		if (i == sting):
			cnt += 1
print(cnt)

Buggy submission (verdict: Runtime Error):
nm = input()
n, m = nm.split()
n = int(n)
m = int(m)

arr = [[] for i in range(n)]

for i in range(m):
	ab = input()
	a, b = ab.split()
	a = int(a)
	b = int(b)
	arr[a-1].append(b)	

cnt = 0	
sting = 0
for i,isl in enumerate(arr):
	sting = isl[0]
	for j in arr[i:sting]:
		if (i == sting):
			cnt += 1
print(cnt)

Buggy submission (verdict: Runtime Error):
nm = input()
n, m = nm.split()
n = int(n)
m = int(m)

arr = [[] for i in range(n)]

for i in range(m):
	ab = input()
	a, b = ab.split()
	a = int(a)
	b = int(b)
	arr[a-1].append(b)	

cnt = 0	
sting = 0
for i,isl in enumelate(arr):
	sting = isl[0]
	for j in arr[i:sting]:
		if (i == sting):
			cnt += 1
print(cnt)
Problem p03631 (python)

Fixed submission:
s= input()
print("Yes" if s[0]==s[-1] else "No")

Buggy submission (verdict: Runtime Error):
s=map(int, input().split())
print("Yes" if s[0]==s[-1] else "No")
Problem p02589 (python)

Fixed submission:
import sys
input = sys.stdin.readline

base = 1999849216943526259
mod = (1 << 61) - 1

N = int(input())
S = [input().rstrip()[::-1] for _ in range(N)]
S.sort(key=lambda s: -len(s))
cnt = {}
ans = 0
one = [0] * 26
for s in S:
    n = len(s)
    if n == 1:
        ans += one[ord(s[0]) - ord('a')]
        continue
    hashes = [0] * (n - 1)
    hashes[0] = ord(s[0])
    for i in range(1, n - 1):
        hashes[i] = (hashes[i-1] * base + ord(s[i])) % mod
    if hashes[-1] in cnt:
        ans += cnt[hashes[-1]][ord(s[-1]) - ord('a')]
    found = [0] * 26
    found[ord(s[-1]) - ord('a')] = 1
    for i in range(n - 2, 0, -1):
        found[ord(s[i]) - ord('a')] = 1
        if hashes[i-1] not in cnt:
            cnt[hashes[i-1]] = [0] * 26
        for c in range(26):
            cnt[hashes[i-1]][c] += found[c]
    found[ord(s[0]) - ord('a')] = 1
    for c in range(26):
        one[c] += found[c]
print(ans)

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

M = 10**6
child = [[-1] * 26]
is_end = [False] * M

N = int(input())
S = [input().rstrip()[::-1] for _ in range(N)]
paths = [[] for _ in range(N)]
for i, s in enumerate(S):
    node = 0
    for c in s:
        c = ord(c) - ord('a')
        paths[i].append(node)
        if child[node][c] == -1:
            child[node][c] = len(child)
            child[node].append([-1] * 26)
        node = child[node][c]
    is_end[node] = True

ans = 0
for i, s in enumerate(S):
    suffix = set()
    for j in range(len(s) - 1, -1, -1):
        suffix.add(ord(s[j]) - ord('a'))
        node = paths[i][j]
        for c in suffix:
            ans += is_end[child[node][c]]
print(ans - N)