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

Fixed submission:
data = input().rstrip().split(" ")
tele = input().rstrip().split(" ")
telepo = [int(i) for i in tele]

max = int(data[1])
limit = max
times = 0
pos = 1
experience = [1]
check = {1}
before = 0
while max > 0:
    pos = telepo[pos - 1]
    max -= 1
    times += 1
    before = len(check)
    check.add(pos)
    if before == len(check):
        length = len(experience) - experience.index(pos)
        max = max % length
        if max == 0:
            break
        while max > 0:
            pos = telepo[pos - 1]
            max -= 1
            times += 1
            #print(pos)
        break
    experience.append(pos)
print(pos)

Buggy submission (verdict: Runtime Error):
max = int(data[1])
limit = max
times = 0
pos = 1
experience = [1]
while max > 0:
    pos = telepo[pos - 1]
    max -= 1
    times += 1
    #print(pos)
    if pos in experience:
        length = len(experience) - experience.index(pos)
        max = max % length
        if max == 0:
            break
        while max > 0:
            pos = telepo[pos - 1]
            max -= 1
            times += 1
            #print(pos)
        break
    experience.append(pos)
print(pos)
Problem p02705 (python)

Fixed submission:
r = int(input())
print(r*2*3.14)

Buggy submission (verdict: Runtime Error):
r = input()
print(r*2*3.14)

Buggy submission (verdict: Runtime Error):
r = input()
print(r*2*3.14)
Problem p03311 (python)

Fixed submission:
import numpy as np
N = int(input())
num = list(map(int,input().split()))
for i in range(1, N+1):
    num[i-1] -= i
numbers = np.array(num)
b = int(round(np.median(numbers)))
numbers-= b
number = np.abs(numbers)
print(number.sum())

Buggy submission (verdict: Runtime Error):
import numpy as np
N = int(input())
num = list(map(int,input().split()))
for i in range(1, N+1):
    num[i-1] -= i
numbers = np.array(num)
b = round(np.median(numbers))
numbers-= b
number = np.abs(numbers)
print(number.sum())

Buggy submission (verdict: Runtime Error):
import numpy as np
N = int(input())
num = list(map(int,input().split()))
for i in range(1, N+1):
    num[i-1] -= i
numbers = np.array(num)
b = round(np.median(numbers))
numbers-= b
print(numbers.sum())
Problem p02651 (python)

Fixed submission:
T = int(input())

def hakidasi(L):
  n = len(bin(max(L))) - 2
  k, end = 0, len(L)
  for i in range(n - 1, -1, -1):
    for j in range(k, end):
      if (L[j] >> i) & 1:
        L[k], L[j] = L[j], L[k]
        break
    else:
      continue
    k += 1
    for j in range(end):
      if j == k - 1: continue
      if (L[j] >> i) & 1:
        L[j] ^= L[k - 1]
  return L

def judge(L, x):
  if L == []:
    return False
  n = len(bin(max(L))) - 2
  m = len(L)
  for i in range(m):
    a = len(bin(x))
    b = len(bin(L[i]))
    if a == b:
      x ^= L[i]
    elif a > b:
      return False
    if x == 0:
      return True
  return False

def main():
  N = int(input())
  A = list(map(int, input().split()))
  S = input()
  U = 60
  
  L = []
  for i in range(N - 1, -1, -1):
    if A[i] == 0:
      continue
    n = int(S[i])
    if n == 0:
      L.append(A[i])
      L = hakidasi(L)
      if L[-1] == 0:
        L.pop()
    else:
      m = judge(L, A[i])
      if m == False:
        return 1
  return 0

for i in range(T):
  print(main())

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

def hakidasi(L):
  n = len(bin(max(L))) - 2
  k, end = 0, len(L)
  for i in range(n - 1, -1, -1):
    for j in range(k, end):
      if (L[j] >> i) & 1:
        L[k], L[j] = L[j], L[k]
        break
    else:
      continue
    k += 1
    for j in range(end):
      if j == k - 1: continue
      if (L[j] >> i) & 1:
        L[j] ^= L[k - 1]
  return L

def judge(L, x):
  n = len(bin(max(L))) - 2
  m = len(L)
  for i in range(m):
    a = len(bin(x))
    b = len(bin(L[i]))
    if a == b:
      x ^= L[i]
    elif a > b:
      return False
    if x == 0:
      return True
  return False

def main():
  N = int(input())
  A = list(map(int, input().split()))
  S = input()
  U = 60
  
  L = []
  for i in range(N - 1, -1, -1):
    n = int(S[i])
    if n == 0:
      L.append(A[i])
      L = hakidasi(L)
      if L[-1] == 0:
        L.pop()
    else:
      m = judge(L, A[i])
      if m == False:
        return 1
  return 0

for i in range(T):
  print(main())
Problem p02678 (python)

Fixed submission:
class Dijkstra:
  R = {}
  import heapq
  pop = heapq.heappop
  push = heapq.heappush
  
  def __init__(s, N):
    s.N = N

  def add(s, a, b, x):
    if a not in s.R: s.R[a] = {b: x}
    else: s.R[a][b] = x
    if b not in s.R: s.R[b] = {a: x}
    else: s.R[b][a] = x

  def exe(s, start):
    D = [-1] * s.N 
    q  = []
    s.push(q, [0, start])
    cnt = 0
    while cnt < s.N:
      if len(q) == 0:
        return None
      d, x = s.pop(q)
      if D[x] != -1: continue
      D[x] = d
      cnt += 1
      for i in s.R[x]:
        if D[i] != -1: continue
        j = s.R[x][i]
        s.push(q, [d + j, i])
    return D


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

D = Dijkstra(N)

for a, b in AB:
  D.add(a - 1, b - 1, 1)

L = D.exe(0)

if L == None:
  print("No")
  exit()

R = {}

for i in range(N):
  if L[i] in R:
    R[L[i]].append(i)
  else:
    R[L[i]] = [i]

Ans = [0] * N
for i in R.keys():
  for j in R[i]:
    for k in D.R[j].keys():
      if L[k] == L[j] + 1:
        Ans[k] = j + 1

print("Yes")
for i in range(1, N):
  print(Ans[i])

Buggy submission (verdict: Runtime Error):
class Dijkstra:
  R = {}
  import heapq
  pop = heapq.heappop
  push = heapq.heappush
  
  def __init__(s, N):
    s.N = N

  def add(s, a, b, x):
    if a not in s.R: s.R[a] = {b: x}
    else: s.R[a][b] = x
    if b not in s.R: s.R[b] = {a: x}
    else: s.R[b][a] = x

  def exe(s, start):
    D = [-1] * s.N 
    q  = []
    s.push(q, [0, start])
    cnt = 0
    while cnt < s.N:
      if len(q) == 0:
        return None
      d, x = s.pop(q)
      if D[x] != -1: continue
      D[x] = d
      cnt += 1
      for i in s.R[x]:
        if D[i] != -1: continue
        j = s.R[x][i]
        s.push(q, [d + j, i])
    return D


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

D = Dijkstra(N)

for a, b in AB:
  D.add(a - 1, b - 1, 1)

L = D.exe(0)

if L == None:
  print("No")
  exit()

R = {}

for i in range(N):
  if L[i] in R:
    R[L[i]].append(i)
  else:
    R[L[i]] = [i]

Ans = [0] * N
for i in R.keys():
  for j in R[i]:
    for k in D.R[j].keys():
      if L[k] == L[j] + 1:
        Ans[k] = j + 1

print("Yes")
for i in range(1, N):
  print(Ans[i])
Problem p02756 (python)

Fixed submission:
S = list(input())
Q = int(input())
Qu= [list(input().split()) for _ in range(Q)]

r = 0

B = []
A = []

for i in range(Q):
  if int(Qu[i][0]) == 1:
    r = 1 - r
  else:
    F = int(Qu[i][1])
    C = Qu[i][2]
    F -= 1
    if F == r:
      B.append(C)
    else:
      A.append(C)

if r == 0:
  B.reverse()
  print("".join(B + S + A))
else:
  A.reverse()
  S.reverse()
  print("".join(A + S + B))

Buggy submission (verdict: Runtime Error):
S = list(input())
Q = int(input())
Qu= [list(input().split()) for _ in range(Q)]

r = 0

B = []
A = []

for i in range(Q):
  if int(Qu[i][0]) == 1:
    r = 1 - r
  else:
    F = int(Qu[i][1])
    C = Qu[i][2]
    F -= 1
    if F == r:
      B.append(C)
    else:
      A.append(C)

if r == 0:
  B.reverse()
  print("".join(B + S + A))
else:
  A.reverse()
  print("".join(A + S.reverse() + B))
Problem p02787 (python)

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

inf = 10 ** 10
DP = [[inf] * (H + 1) for _ in range(N)]

for i in range(N):
  a, b = AB[i]
  if a >= H:
    for j in range(H + 1):
      if i == 0:
        DP[i][j] = b
      else:
        DP[i][j] = min(DP[i - 1][j], b)
    continue
  for j in range(1, a + 1):
    if i == 0:
      DP[i][j] = b
    else:
      DP[i][j] = min(DP[i - 1][j], b)
  for j in range(a + 1, H + 1):
    if i == 0:
      DP[i][j] = DP[i][j - a] + b
    else:
      DP[i][j] = min(DP[i - 1][j], DP[i][j - a] + b)

print(DP[-1][H])

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

inf = 10 ** 10
DP = [[inf] * (H + 1) for _ in range(N)]

for i in range(N):
  a, b = AB[i]
  for j in range(1, a + 1):
    if i == 0:
      DP[i][j] = b
    else:
      DP[i][j] = min(DP[i - 1][j], b)
  for j in range(a + 1, H + 1):
    if i == 0:
      DP[i][j] = DP[i][j - a] + b
    else:
      DP[i][j] = min(DP[i - 1][j], DP[i][j - a] + b)

print(DP[-1][H])
Problem p02803 (python)

Fixed submission:
H, W = list(map(int, input().split()))
S = [list(input()) for _ in range(H)]
import queue
import copy
class gridMan:
  def __init__(s, L):
    s.L = L
  def makeWall(s, x):
    w = len(s.L[0]) + 2
    s.L = [[x] * w] + [[x] + i + [x] for i in s.L] + [[x] * w]
  def dist(s, S):
    T = copy.deepcopy(s.L)
    T[S[0] + 1][S[1] + 1] = 1
    q = queue.Queue()
    q.put([S[0] + 1, S[1] + 1])
    ans = 0
    while not q.empty():
      h, w = q.get()
      k = T[h][w]
      ans = max(ans, k)
      for i, j in [[1, 0], [-1, 0], [0, 1], [0, -1]]:
        hh = h + i
        ww = w + j
        if T[hh][ww] == -1:
          continue
        t = T[hh][ww]
        if t == 0:
          q.put([hh, ww])
          T[hh][ww] = k + 1
    return ans - 1

for i in range(H):
  for j in range(W):
    if S[i][j] == "#":
      S[i][j] = -1
    else:
      S[i][j] = 0

g = gridMan(S)
g.makeWall(-1)
ans = 0
for sx in range(H):
  for sy in range(W):
    if S[sx][sy] == -1:
      continue
    ans = max(ans, g.dist([sx, sy]))

print(ans)

Buggy submission (verdict: Runtime Error):
H, W = list(map(int, input().split()))
S = [list(input()) for _ in range(H)]
import queue
import copy
class gridMan:
  def __init__(s, L):
    s.L = L
  def makeWall(s, x):
    w = len(s.L[0]) + 2
    s.L = [[x] * w] + [[x] + i + [x] for i in s.L] + [[x] * w]
  def dist(s, S, G):
    T = copy.deepcopy(s.L)

    T[S[0] + 1][S[1] + 1] = 1
    q = queue.Queue()
    q.put([S[0] + 1, S[1] + 1])
    while not q.empty():
      h, w = q.get()
      k = T[h][w]
      for i, j in [[1, 0], [-1, 0], [0, 1], [0, -1]]:
        hh = h + i
        ww = w + j
        if T[hh][ww] == -1:
          continue
        t = T[hh][ww]
        if t == 0:
          q.put([hh, ww])
          T[hh][ww] = k + 1
    return T[G[0] + 1][G[1] + 1] - 1

for i in range(H):
  for j in range(W):
    if S[i][j] == "#":
      S[i][j] = -1
    else:
      S[i][j] = 0

g = gridMan(S)
g.makeWall(-1)
ans = 0
for sx in range(H):
  for sy in range(W):
    if S[sx][sy] == -1:
      continue
    for gx in range(sx, H):
      for gy in range(W):
        if S[sx][sy] == -1:
          continue
        if sx == gx and sy == gy: continue
        ans = max(ans, g.dist([sx, sy], [gx, gy]))

g.dist([0, 0], [2, 2])
print(ans)
Problem p02840 (python)

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

if D == 0:
  if X == 0:
    print(1)
  else:
    print(N + 1)
  exit()

if D < 0:
  D *= -1
  X *= -1

R = {}
R[0] = [[0, 0]]
d, m, l, r = 0, 0, 0, 0

for i in range(N):
  d += (m + X) // D
  m = (m + X) % D
  l += i
  r += N - i - 1
  if m not in R:
    R[m] = [[d + l, d + r]]
  else:
    R[m].append([d + l, d + r])
  
ans = 0
for i in R:
  t = R[i]
  t.sort()
  l, r = t[0]
  for j in range(1, len(t)):
    if r < t[j][0]:
      ans += abs(r - l) + 1
      l, r = t[j]
    else:
      r = max(r, t[j][1])
  ans += abs(r - l) + 1

print(ans)

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

R = {}
R[0] = [[0, 0]]
d, m, l, r = 0, 0, 0, 0

for i in range(N):
  d += (m + X) // D
  m = (m + X) % D
  l += i
  r += N - i - 1
  if m not in R:
    R[m] = [[d + l, d + r]]
  else:
    R[m].append([d + l, d + r])
  
ans = 0
for i in R:
  t = R[i]
  t.sort()
  l, r = t[0]
  for j in range(1, len(t)):
    if r < t[j][0]:
      ans += abs(r - l) + 1
      l, r = t[j]
    else:
      r = t[j][1]
  ans += abs(r - l) + 1

print(ans)
Problem p02963 (python)

Fixed submission:
import math
S = int(input())

if S == 10 ** 18:
  print(0, 0, 0, 10 ** 9, 10 ** 9, 0)
  exit()

t = math.floor(math.sqrt(S))
if t * (t + 1) < S:
  x1 = t + 1
  y2 = t + 1
else:
  x1 = t
  y2 = t + 1
x2 = 1
y1 = x1 * y2 - S

print(0, 0, x1, y1, x2, y2)

Buggy submission (verdict: Runtime Error):
import math
S = int(input())

t = math.floor(math.sqrt(S))
if t * (t + 1) < S:
  x1 = t + 1
  y2 = t + 1
else:
  x1 = t
  x2 = t + 1
x2 = 1
y1 = x1 * y2 - S

print(0, 0, x1, y1, x2, y2)

Buggy submission (verdict: Runtime Error):
import math
S = int(input())

t = math.floor(math.sqrt(S))
if t * t + 1 < S:
  x1 = t + 1
  y2 = t + 1
else:
  x1 = t
  x2 = t + 1
x2 = 1
y1 = x1 * y2 - S

print(0, 0, x1, y1, x2, y2)
Problem p02992 (python)

Fixed submission:
def hersCode(l, r, n, N):
  ok = l
  ng = r + 1
  while abs(ok - ng) > 1:
    mid = abs(ok + ng) // 2
    if mid * n <= N:
      ok = mid
    else:
      ng = mid
  return ng


N, K = list(map(int, input().split()))
MOD = 10 ** 9 + 7

if N == 1:
  print(1)
  exit()

L = []
t = 1
n = N
while t <= N:
  L.append(t)
  t = hersCode(t, N, N // t ,N)

D = [0] * len(L)
L.append(N + 1)
for i in range(len(L) - 1):
  D[i] = (L[i + 1] - L[i]) % MOD
DP = [[0] * (len(D)) for _ in range(K)]
for i in range(len(D)):
  DP[0][i] = D[i]

for i in range(1, K):
  S = [0] * len(D)
  S[0] = DP[i - 1][0]
  for j in range(1, len(D)):
    S[j] = S[j - 1] + DP[i - 1][j]
  for j in range(len(D)):
    DP[i][j] = S[-1 -j] * D[j] % MOD

print(sum(DP[K - 1]) % MOD)

Buggy submission (verdict: Runtime Error):
def hersCode(l, r, n, N):
  ok = l
  ng = r + 1
  while abs(ok - ng) > 1:
    mid = abs(ok + ng) // 2
    if mid * n <= N:
      ok = mid
    else:
      ng = mid
  return ng


N, K = list(map(int, input().split()))
MOD = 10 ** 9 + 7

L = []
t = 1
n = N
while t < N:
  L.append(t)
  t = hersCode(t, N, N // t ,N)

D = [0] * len(L)
L.append(N + 1)
for i in range(len(L) - 1):
  D[i] = (L[i + 1] - L[i]) % MOD

DP = [[0] * (len(D)) for _ in range(K)]
for i in range(len(D)):
  DP[0][i] = D[i]

for i in range(1, K):
  S = [0] * len(D)
  S[0] = DP[i - 1][0]
  for j in range(1, len(D)):
    S[j] = S[j - 1] + DP[i - 1][j]
  for j in range(len(D)):
    DP[i][j] = S[-1 -j] * D[j] % MOD

print(sum(DP[K - 1]) % MOD)
Problem p03040 (python)

Fixed submission:
Q = int(input())
Query = [list(map(int, input().split())) for _ in range(Q)]
import heapq

L = []
R = []
pop = heapq.heappop
push = heapq.heappush
A, B, C = 0, 0, 0

def nasu(a):
  global A
  global C
  if len(R) == 0:
    push(R, a)
    C = a
    return
  if len(L) == 0:
    r = pop(R)
    push(L, -min(a, r))
    push(R, max(a, r))
    A += abs(a - r)
    C = min(a, r)
    return
  if len(L) < len(R):
    r = pop(R)
    l = -pop(L)
    push(L, -l)
    push(L, -min(a, r))
    push(R, max(a, r))
    A += abs(a - r)
    if a < l:
      C = l
    elif a < r:
      C = a
    return
  l = -pop(L)
  r = pop(R)
  if l <= a and a <= r:
    push(L, -l)
    push(R, r)
    push(R, a)
    C = a
  elif a < l:
    push(L, -a)
    push(R, r)
    push(R, l)
    A += abs(a - l)
    C = l
  else:
    push(L, -l)
    push(R, a)
    push(R, r)
    A += abs(a - r)
    C = r

for q in Query:
  if q[0] == 1:
    nasu(q[1])
    B += q[2]
  if q[0] == 2:
    print(C, A + B)

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

def addT(n):
  k = 0
  while True:
    if T[k][0] >= n:
      T[k][1][1] += 1
      if T[k][1][0] == -1:
        T.append([n, [-1, 0], [-1, 0]])
        T[k][1][0] = t
        break
      else:
       k = T[k][1][0]
    else:
      T[k][2][1] += 1
      if T[k][2][0] == -1:
        T.append([n, [-1, 0], [-1, 0]])
        T[k][2][0] = t
        break
      else:
        k = T[k][2][0]

def getTmed(x, n):
  if T[x][1][1] == n - 1:
    return x
  elif T[x][1][1] > n - 1:
    return getTmed(T[x][1][0], n)
  else:
    return getTmed(T[x][2][0], n - (T[x][1][1] + 1))


T = []
b = 0
su = 0
for i in q:
  if T == []:
    T.append([i[1], [-1, 0], [-1, 0]])
    t = 1
    rk = i[1]
    b = i[2]
  elif i[0] == 2:
    k = getTmed(0, (t + 1) // 2)
    print(T[k][0], su + b)
  else:
    addT(i[1])
    k = getTmed(0, (t + 1) // 2)
    su += abs(T[k][0] - rk)
    rk = T[k][0]
    t += 1
    b += i[2]
Problem p03078 (python)

Fixed submission:
X, Y, Z, K = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

A.sort(reverse = True)
B.sort(reverse = True)
C.sort(reverse = True)
A += [-1e10]
B += [-1e10]
C += [-1e10]

memo = [A[i] + B[0] + C[0] for i in range(X + 1)]
L = [[0 for i in range(Y + 1)] for j in range(X + 1)]

for i in range(K):
  ma = 0
  for j in range(X):
    if memo[ma] < memo[j]:
      ma = j
  print(memo[ma])
  mb = 0
  mn = 0
  for j in range(Y):
    x = B[j] + C[L[ma][j]]
    if mb < x:
      mb = x
      mn = j
  L[ma][mn] += 1
  n = 0
  for j in range(Y):
    n = max(n, B[j] + C[L[ma][j]])
  memo[ma] = A[ma] + n

Buggy submission (verdict: Runtime Error):
X, Y, Z, K = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

A.sort(reverse = True)
B.sort(reverse = True)
C.sort(reverse = True)
A += [-1e10]
B += [-1e10]
C += [-1e10]

memo = [A[i] + B[0] + C[0] for i in range(X + 1)]
L = [[0 for i in range(Y + 1)] for j in range(X + 1)]

for i in range(K):
  ma = 0
  for j in range(X):
    if memo[ma] < memo[j]:
      ma = j
  print(memo[ma])
  mb = 0
  mn = 0
  for j in range(Y):
    x = B[j] + C[L[ma][j]]
    if mb < x:
      mb = x
      mn = j
  L[ma][mn] += 1
  n = 0
  for j in range(Y):
    n = max(n, B[j] + C[L[ma][j]])
  memo[ma] = A[ma] + n
X, Y, Z, K = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

A.sort(reverse = True)
B.sort(reverse = True)
C.sort(reverse = True)
A += [-1e10]
B += [-1e10]
C += [-1e10]

memo = [A[i] + B[0] + C[0] for i in range(X + 1)]
L = [[0 for i in range(Y + 1)] for j in range(X + 1)]

for i in range(K):
  ma = 0
  for j in range(X):
    if memo[ma] < memo[j]:
      ma = j
  print(memo[ma])
  mb = 0
  mn = 0
  for j in range(Y):
    x = B[j] + C[L[ma][j]]
    if mb < x:
      mb = x
      mn = j
  L[ma][mn] += 1
  n = 0
  for j in range(Y):
    n = max(n, B[j] + C[L[ma][j]])
  memo[ma] = A[ma] + n
Problem p03081 (python)

Fixed submission:
N, Q = list(map(int, input().split()))
s = input()
td = [input().split() for i in range(Q)]

td.reverse()

nl = 0
nr = N - 1
L = []
R = []
for i in td:
  if i[1] == "L":
    if nl < N:
      if s[nl] == i[0]:
        L.append(i[0])
        nl += 1
    if len(R) != 0:
      if R[-1] == i[0]:
        R.pop()
        nr += 1
  else:
    if nr >= 0:
      if s[nr] == i[0]:
        R.append(i[0])
        nr -= 1
    if len(L) != 0:
      if L[-1] == i[0]:
        L.pop()
        nl -= 1

print(N - len(L) - len(R))

Buggy submission (verdict: Runtime Error):
N, Q = list(map(int, input().split()))
s = input()
td = [input().split() for i in range(Q)]

td.reverse()

nl = 0
nr = N - 1
L = []
R = []
for i in td:
  if i[1] == "L":
    if s[nl] == i[0]:
      L.append(i[0])
      nl += 1
    if len(R) == 0:
      continue
    if R[-1] == i[0]:
      R.pop()
      nr += 1
  else:
    if s[nr] == i[0]:
      R.append(i[0])
      nr -= 1
    if len(L) == 0:
      continue
    if L[-1] == i[0]:
      L.pop()
      nl -= 1

print(N - len(L) - len(R))
Problem p03095 (python)

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

MOD = 1e9 + 7
L = {}
for i in S:
  if i in L:
    L[i] += 1
  else:
    L[i] = 1

Ans = 1
for i in L.values():
  Ans = Ans * (i + 1) % MOD

Ans -= 1
if Ans < 0:
  Ans += MOD

print(int(Ans))

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

MOD = 1e9 + 7
L = {}
for i in S:
  if i in L:
    L[i] += 1
  else:
    L[i] = 1

Ans = 1
for i in range(N):
  Ans = (Ans * 2) % MOD
Ans -= 1

t = 0
k = 1
for i in L.values():
  N -= i
  if i != 1:
    t += (k * (2 ** N) * ((2 ** i) - (i + 1))) % MOD
  k *= i + 1

Ans -= t

print(int(Ans % MOD))

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

MOD = 1e9 + 7
L = {}
for i in S:
  if i in L:
    L[i] += 1
  else:
    L[i] = 1

Ans = (2 ** N - 1) % MOD
t = 0
k = 1
for i in L.values():
  N -= i
  if i != 1:
    t += (k * (2 ** N) * ((2 ** i) - (i + 1))) % MOD
  k *= i + 1

Ans -= t % MOD

print(int(Ans % MOD))

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

MOD = 1e9 + 7
L = {}
for i in S:
  if i in L:
    L[i] += 1
  else:
    L[i] = 1

Ans = (2 ** N - 1) % MOD
t = 0
k = 1
for i in L.values():
  N -= i
  if i != 1:
    t += (k * (2 ** N)) % MOD
  k *= i + 1

Ans -= t % MOD

print(int(Ans % MOD))

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

MOD = 1e9 + 7
L = {}
for i in S:
  if i in L:
    L[i] += 1
  else:
    L[i] = 1

Ans = (2 ** N - 1) % MOD
t = 0
k = 1
for i in L.values():
  N -= i
  if i != 1:
    t += k * (2 ** N)
  k *= i + 1

Ans -= t

print(int(Ans % MOD))

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

MOD = 1e9 + 7
L = {}
for i in S:
  if i in L:
    L[i] += 1
  else:
    L[i] = 1

Ans = 2 ** N - 1
t = 0
k = 1
for i in L.values():
  N -= i
  if i != 1:
    t += k * (2 ** N)
  k *= i + 1

Ans -= t

print(int(Ans % MOD))
Problem p03096 (python)

Fixed submission:
N = int(input())
C = [input() for i in range(N)]

MOD = 1e9 + 7

C2 = []
re = ""
L = {}
LL = [-1] * N
for i in C:
  if i != re:
    if i in L:
      LL[L[i]] = len(C2)
      L[i] = len(C2)
    else:
      L[i] = len(C2)
    C2.append(i)
  re = i


DP = [-1] * (len(C2) + 1)

DP[-1] = 1
for i in range(len(C2) - 1, -1, -1):
  DP[i] = DP[i + 1]
  if LL[i] != -1:
    DP[i] += DP[LL[i]] % MOD
print(int(DP[0] % MOD))

Buggy submission (verdict: Runtime Error):
import copy

N = int(input())
C = [input() for i in range(N)]

C2 = []
re = ""
L = {}
for i in C:
  if i != re:
    if i in L:
      L[i].append(len(C2))
    else:
      L[i] = []
    C2.append(i)
  re = i

LL = [-1] * len(C2)
for i in L:
  t = i
  for j in L[t]:
    LL[int(t)] = j
    t = j

DP = [-1] * (len(C2) + 1)

DP[-1] = 1
for i in range(len(C2) - 1, -1, -1):
  DP[i] = DP[i + 1]
  if LL[i] != -1:
    DP[i] += DP[LL[i]]

print(DP[0])
Problem p03142 (python)

Fixed submission:
def main():
  N, M = list(map(int, input().split()))
  inN = [0 for i in range(N)]
  outN = [[] for i in range(N)]
  
  for i in range(N + M - 1):
    Data = list(map(int, input().split()))
    inN[Data[1] - 1] += 1
    outN[Data[0] - 1].append(Data[1] - 1)
  
  D = []
  for i in range(N):
    if inN[i] == 0:
      D.append(i)
      
  L = []
  while D != []:
    t = D.pop()
    L.append(t)
    for i in outN[t]:
      inN[i] -= 1
      if inN[i] == 0:
        D.append(i)
   
  Ans = [0 for i in range(N)]
  for i in L:
    for j in outN[i]:
      Ans[j] = i + 1
      
  for i in Ans:
    print(i)
main()

Buggy submission (verdict: Runtime Error):
N, M = list(map(int, input().split()))
L = {}
D = [[0, i] for i in range(N+1)]

for i in range(N + M - 1):
  Data = list(map(int, input().split()))
  if Data[0] in L:
    L[Data[0]].append(Data[1])
  else:
    L[Data[0]] = [Data[1]]
  D[Data[1]][0] += 1

for i in range(1, N+1):
  if D[i][0] == 0:
    s = D[i][1]
    break

P = [[0, 0] for i in range(N + 1)]
S = []
t = L[s]
for i in t:
  S.append([s, i])
  P[i] = [1, s]

cnt = 0
print(P)
while True:
  j = S[cnt][1]
  if j not in L:
    cnt += 1
    continue
  t = L[j]
  for i in t:
    if P[i][0] != 0:
      if P[i][0] < P[j][0] + 1:
        #削除
        L[P[i][1]].remove(i)
        #更新
        P[i] = [P[j][0] + 1, j] 
        M -= 1
      else:
        # 削除
        L[P[j][1]].remove(j)
        M -= 1
  print(P)
  print(L)
  if M == 0:
    break
  cnt += 1