Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
from collections import Counter
N = int(input())

SS = []
for i in range(N):
  s = list(input())
  s.sort()
  SS.append(s)
  
SS.sort()

ans = 0
prev = None
for i in range(N):
  s = S[i]
  if s == prev:
    ans += 1
  prev = s
  
print(ans)
  

Fixed submission:
N = int(input())

SS = []
for i in range(N):
  s = list(input())
  s.sort()
  SS.append(s)
  
SS.sort()

ans = 0
prev = None
cnt = 0
for i in range(N):
  s = SS[i]
  if s == prev:
    if not cnt:
      cnt = 2
    else:
      cnt += 1
  else:
    ans += cnt * (cnt - 1) // 2
    cnt = 0
  prev = s
  
ans += cnt * (cnt - 1) // 2
print(ans)

Buggy python submission (verdict: Runtime Error):
from collections import Counter
N = int(input())
SS = [input() for _ in range(N)]

STR_IN_S = [[[] for _ in range(11)] for _ in range(26)]

for i in range(N):
  S = SS[i]
  c = Counter(S)
  for j in range(26):
    s = chr(97+j)
    STR_IN_S[j][c[s]].append(i)
    
SAME = [set(range(N)) for _ in range(N)]

for i in range(26):
  for j in range(11):
    l = STR_IN_S[i][j]
	nl = set(l)
    for x in l:
      SAME[x] &= nl
  
ans = 0
for i in range(N):
  ans += len(SAME[i]) - 1
  
print(ans)


Fixed submission:
N = int(input())

SS = []
for i in range(N):
  s = list(input())
  s.sort()
  SS.append(s)
  
SS.sort()

ans = 0
prev = None
cnt = 0
for i in range(N):
  s = SS[i]
  if s == prev:
    if not cnt:
      cnt = 2
    else:
      cnt += 1
  else:
    ans += cnt * (cnt - 1) // 2
    cnt = 0
  prev = s
  
ans += cnt * (cnt - 1) // 2
print(ans)

Buggy python submission (verdict: Runtime Error):
from collections import Counter
N = int(input())
SS = [input() for _ in range(N)]

STR_IN_S = [[[] for _ in range(11)] for _ in range(26)]

for i in range(N):
  S = SS[i]
  c = Counter(S)
  for j in range(26):
    s = chr(97+j)
    STR_IN_S[j][c[s]].append(i)
    
SAME = [set(range(N)) for _ in range(N)]

for i in range(26):
  for j in range(11):
    l = STR_IN_S[i][j]
    for x in l:
      SAME[x] &= l
  
ans = 0
for i in range(N):
  ans += len(SAME[i]) - 1
  
print(ans)

Fixed submission:
N = int(input())

SS = []
for i in range(N):
  s = list(input())
  s.sort()
  SS.append(s)
  
SS.sort()

ans = 0
prev = None
cnt = 0
for i in range(N):
  s = SS[i]
  if s == prev:
    if not cnt:
      cnt = 2
    else:
      cnt += 1
  else:
    ans += cnt * (cnt - 1) // 2
    cnt = 0
  prev = s
  
ans += cnt * (cnt - 1) // 2
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10 ** 7)

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N, M, P = map(int, readline().split())
ABC = [[int(x) for x in readline().split()] for _ in range(M)]

'''
PATH = [[] for _ in range(N+1)]
for _ in range(M):
    a, b, c = map(int, readline().split())
    PATH[a].append((b, c))
'''

INF = 10 ** 12
POINT = [INF] * (N + 1)

POINT[1] = 0

for i in range(N):
    update = False
    for j in range(M):
        a, b, c = ABC[j]
        pt = P - c
        if POINT[a] != INF and POINT[a] + pt < POINT[b]:
            POINT[b] = POINT[a] + pt
            update = True

            if i == N - 1 and b == N:
                print(-1)
                exit()

    if not update:
        break

pt = -POINT[N]

ans = pt if pt > 0 else 0
print(ans)


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

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines


N, M, P = map(int, readline().split())

EDGES = []
TO = [[] for _ in range(N + 1)]
RTO = [[] for _ in range(N + 1)]

for _ in range(M):
    a, b, c = map(int, readline().split())
    EDGES.append((a, b, c))
    TO[a].append(b)
    RTO[b].append(a)

# 1から到達可能な点
REACH_FROM_1 = [False] * (N+1)
q = [1]
while q:
    u = q.pop()
    if REACH_FROM_1[u]:
        continue
    REACH_FROM_1[u] = True
    for v in TO[u]:
        q.append(v)

# Nから到達可能な点
REACH_TO_N = [False] * (N + 1)
q = [N]
while q:
    u = q.pop()
    if REACH_TO_N[u]:
        continue
    REACH_TO_N[u] = True
    for v in RTO[u]:
        q.append(v)

STATE = [REACH_FROM_1[i] & REACH_TO_N[i] for i in range(N + 1)]


INF = 10 ** 12
POINT = [INF] * (N + 1)

POINT[1] = 0

for i in range(N):
    update = False
    for j in range(M):
        a, b, c = EDGES[j]
        if not STATE[a]:
            continue
        pt = - (c - P)
        if POINT[a] != INF and POINT[a] + pt < POINT[b]:
            POINT[b] = POINT[a] + pt
            update = True

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

    if not update:
        break

# print(POINT)
pt = -POINT[N]

ans = pt if pt > 0 else 0
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
#from collections import deque
import numpy as np
import sys
sys.setrecursionlimit(10 ** 7)

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N, K = map(int, input().split())
A = np.array(input().split(), dtype=np.int64)


S = sum(A)
divisors = []

for i in range(1, S):
    if S < i * i:
        break

    if S % i == 0:
        divisors.append(i)
        divisors.append(S // i)


def check(x):
    modX = A % x
    modX = np.sort(modX)
    modX = modX[modX > 0]

    L = len(modX)
    rtn = False

    for i in range(L):
        cnt = 0
        minus = modX[:i]
        plus = modX[i:]

        cnt_minus = sum(minus - 0)
        cnt_plus = sum(x - plus)

        if cnt_minus <= K and cnt_plus <= K:
            rest = abs(cnt_minus - cnt_plus)
            if rest % x == 0:
                rtn = True
                break

    return rtn


ans = 1
for x in divisors:
    if check(x):
        ans = max(x, ans)

print(ans)


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

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N, K = map(int, input().split())
#A = np.array(input().split(), dtype=np.int64)
A = list(map(int, input().split()))


S = sum(A)
divisors = []

for i in range(1, S):
    if S < i * i:
        break

    if S % i == 0:
        divisors.append(i)
        divisors.append(S // i)


def check(x):
    modX = [a % x for a in A if a % x != 0]
    modX.sort()

    L = len(modX)
    rtn = False

    for i in range(L):
        cnt = 0
        minus = modX[:i]
        plus = modX[i:]

        cnt_minus = sum(minus)
        cnt_plus = x * (L - i) - sum(plus)

        if cnt_minus <= K and cnt_plus <= K:
            rest = abs(cnt_minus - cnt_plus)
            if rest % x == 0:
                rtn = True
                break

    return rtn


ans = 1
for x in divisors:
    if check(x):
        ans = max(x, ans)

print(ans)
Buggy python submission (verdict: Runtime Error):
import itertools
L,R = map(int,input().split())
if 2019 <= (R - L) + 1:
  print(0)
  exit()
  
lst = list(range(L,R+1))
md = [x * y % 2019 for x,y in itertools.combination(lst,2)]
md.sort()
print(md[0])

Fixed submission:
import itertools
L,R = map(int,input().split())
if 2019 <= (R - L) + 1:
  print(0)
  exit()
  
lst = list(range(L,R+1))
md = [x * y % 2019 for x,y in itertools.combinations(lst,2)]
md.sort()
print(md[0])
Buggy python submission (verdict: Runtime Error):
import sys
import numpy as np
sys.setrecursionlimit(10 ** 7)

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N, K = map(int, input().split())

MOD = 10 ** 9 + 7


# 階乗、Combinationコンビネーション(numpyを使う)
def cumprod(arr, MOD):
    L = len(arr)
    Lsq = int(L**.5+1)
    arr = np.resize(arr, Lsq**2).reshape(Lsq, Lsq)
    for n in range(1, Lsq):
        arr[:, n] *= arr[:, n-1]
        arr[:, n] %= MOD
    for n in range(1, Lsq):
        arr[n] *= arr[n-1, -1]
        arr[n] %= MOD
    return arr.ravel()[:L]


def make_fact(U, MOD):
    x = np.arange(U, dtype=np.int64)
    x[0] = 1
    fact = cumprod(x, MOD)
    x = np.arange(U, 0, -1, dtype=np.int64)
    x[0] = pow(int(fact[-1]), MOD-2, MOD)
    fact_inv = cumprod(x, MOD)[::-1]
    return fact, fact_inv


U = 10**3
fact, fact_inv = make_fact(U, MOD)
fact, fact_inv = fact.tolist(), fact_inv.tolist()


def mod_comb_k(n, k, mod):
    return fact[n] * fact_inv[k] % mod * fact_inv[n - k] % mod


ans = []

# i回操作する方法
for i in range(1, K + 1):
    #print("i=", i)
    res = 1

    # i分割する
    # i-1箇所に置く
    pat_split = 1
    pat_split *= mod_comb_k(K - 1, i - 1, MOD)

    #print("pat_split", pat_split)

    # 残りの玉を置く
    pat_rest = i - 1 + 2
    bal_rest = N - (i - 1) - K
    res *= mod_comb_k(pat_rest + bal_rest - 1, bal_rest, MOD)
    #print("res", res)
    res *= pat_split
    res %= MOD

    ans.append(str(res))

print("\n".join(ans))


Fixed submission:
import sys
import numpy as np
sys.setrecursionlimit(10 ** 7)

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N, K = map(int, input().split())

MOD = 10 ** 9 + 7


# 階乗、Combinationコンビネーション(numpyを使う)
def cumprod(arr, MOD):
    L = len(arr)
    Lsq = int(L**.5+1)
    arr = np.resize(arr, Lsq**2).reshape(Lsq, Lsq)
    for n in range(1, Lsq):
        arr[:, n] *= arr[:, n-1]
        arr[:, n] %= MOD
    for n in range(1, Lsq):
        arr[n] *= arr[n-1, -1]
        arr[n] %= MOD
    return arr.ravel()[:L]


def make_fact(U, MOD):
    x = np.arange(U, dtype=np.int64)
    x[0] = 1
    fact = cumprod(x, MOD)
    x = np.arange(U, 0, -1, dtype=np.int64)
    x[0] = pow(int(fact[-1]), MOD-2, MOD)
    fact_inv = cumprod(x, MOD)[::-1]
    return fact, fact_inv


U = 10**4
fact, fact_inv = make_fact(U, MOD)
fact, fact_inv = fact.tolist(), fact_inv.tolist()


def mod_comb_k(n, k, mod):
    return fact[n] * fact_inv[k] % mod * fact_inv[n - k] % mod


ans = []
red = N - K

# i回操作する方法
for i in range(1, K + 1):
    #print("i=", i)
    res = 1

    # i分割するためには、i-1個ボールが必要
    if red < (i - 1):
        ans.append(str(0))
        continue

    # i分割する
    # i-1箇所に置く
    pat_split = 1
    pat_split *= mod_comb_k(K - 1, i - 1, MOD)

    #print("pat_split", pat_split)

    # 残りの玉を置く
    pat_rest = i - 1 + 2
    bal_rest = N - (i - 1) - K
    res *= mod_comb_k(pat_rest + bal_rest - 1, bal_rest, MOD)
    #print("res", res)
    res *= pat_split
    res %= MOD

    ans.append(str(res))

print("\n".join(ans))
Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10 ** 7)

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N,M = map(int,readline().split())
A = [True] * (N+10)
MOD = 10 ** 9 + 7
for _ in range(M):
  x = int(readline())
  A[x] = False


DP = [0] * (N+10)
DP[0] = 1

for i in range(N):
  if not A[i]:
    continue
  
  if A[i+1]:
    DP[i+1] += DP[i]
    DP[i+1] %= MOD
  if A[i+2]:
    DP[i+2] += DP[i]
    DP[i+2]: %= MOD
       
print(DP[N]%MOD)
      
  




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

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N,M = map(int,readline().split())
A = [True] * (N+10)
MOD = 10 ** 9 + 7
for _ in range(M):
  x = int(readline())
  A[x] = False


DP = [0] * (N+10)
DP[0] = 1

for i in range(N):
  if not A[i]:
    continue
  
  if A[i+1]:
    DP[i+1] += DP[i]
    DP[i+1] %= MOD
  if A[i+2]:
    DP[i+2] += DP[i]
    DP[i+2] %= MOD
       
print(DP[N]%MOD)

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

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N,M = map(int,readline().split())
A = [True] * (N+10)
MOD = 10 ** 9 + 7
for _ in range(M):
  x = int(readline())
  A[x] = False


DP = [0] * (N+1)
DP[0] = 1

for i in range(N):
  if not A[i]:
    continue
  
  if A[i+1]:
    DP[i+1] += DP[i]
    DP[i+1] %= MOD
  if A[i+2]:
    DP[i+2] += DP[i]
    DP[i+2]: %= MOD
       
print(DP[N]%MOD)
      
  




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

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N,M = map(int,readline().split())
A = [True] * (N+10)
MOD = 10 ** 9 + 7
for _ in range(M):
  x = int(readline())
  A[x] = False


DP = [0] * (N+10)
DP[0] = 1

for i in range(N):
  if not A[i]:
    continue
  
  if A[i+1]:
    DP[i+1] += DP[i]
    DP[i+1] %= MOD
  if A[i+2]:
    DP[i+2] += DP[i]
    DP[i+2] %= MOD
       
print(DP[N]%MOD)
Buggy python submission (verdict: Runtime Error):
import itertools
S = input()
L = len(S)

ans = 0
for i,j in itertools.combination(range(L),2):
  ss = S[i:j]
  ok = True
  for s in list(ss):
    if not(s == 'A' or s == 'C' or s == 'G' or s == 'T'):
      ok = False
      break
      
  if ok:
    ans = max(ans,j-i)
    
print(ans)
                                 



Fixed submission:
import itertools
S = input()
L = len(S)

ans = 0
for i,j in itertools.combinations(range(L+1),2):
  ss = S[i:j]
  ok = True
  for s in list(ss):
    if not(s == 'A' or s == 'C' or s == 'G' or s == 'T'):
      ok = False
      break
      
  if ok:
    ans = max(ans,j-i)
    
print(ans)
Buggy python submission (verdict: Runtime Error):
N,M = map(int,input().split())
LIKE = set()

for i in range(N):
  AK = list(map(int,input().split()))
  LIKE |= AK[1:]

print(len(LIKE))
            

Fixed submission:
N,M = map(int,input().split())
LIKE = [True] * M

for i in range(N):
  KA = list(map(int,input().split()))
  A = KA[1:]
  
  for i in range(M):
    if not (i+1) in A:
      LIKE[i] = False
      
print(LIKE.count(True))
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = list(map(int,input().split()))

A.sort()
stack = A[1:]
m = A[0]

while stack:
  stack = list(stack)
  l = []
  for x in stack:
    if x % m == 0:
      continue
    l.append(x % m)
  
  m = min(l)
  stack = set(l)

print(m)






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

A.sort()
stack = A[1:]
m = A[0]

while stack:
  stack = list(stack)
  l = []
  for x in stack:
    if x % m == 0:
      continue
    l.append(x % m)
  
  if not l:
    break
  l.append(m)
  m = min(l)
  stack = set(l)

print(m)
Buggy python submission (verdict: Runtime Error):
N,M = map(int,input().split())
X = list(map(int,input().split()))

D = [abs(X[i] - X[i+1]) for i in range(N-1)]
D.sort(reverse=True)

print(sum(D[M+1:]))

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

D = [abs(X[i] - X[i+1]) for i in range(M-1)]
D.sort(reverse=True)

print(sum(D[N-1:]))
Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict
a = int(input())
idxs = defaultdict(int)
idxs[a] = 1
i = 1
ans = None
while True:
  i += 1
  if a % 2 == 0:
    a //= 2
  else:
    a = 3 * a + 1
    
  if not idxs[a]:
    idxs[a] = i
  else:
    ans = i

print(ans)
    
    



Fixed submission:
from collections import defaultdict
a = int(input())
idxs = defaultdict(int)
idxs[a] = 1
i = 1
ans = None
while True:
  i += 1
  if a % 2 == 0:
    a //= 2
  else:
    a = 3 * a + 1
    
  if not idxs[a]:
    idxs[a] = i
  else:
    ans = i
    break

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10 ** 7)

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N, K = map(int, input().split())
H = list(map(int, input().split()))

INF = 10 ** 10
dp = [INF] * (10 ** 5 + 10)
H += [H[-1] * K]

dp[0] = 0

for i in range(N):
    for k in range(1, K + 1):
        if i + k <= N:
            dp[i + k] = min(dp[i + k], dp[i] + abs(H[i + k] - H[i]))


print(dp[N-1])


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

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N, K = map(int, input().split())
H = list(map(int, input().split()))

INF = 10 ** 10
dp = [INF] * (10 ** 5 + 10)
H += [H[-1] * K]

dp[0] = 0

for i in range(N):
    for k in range(1, K + 1):
        if i + k <= N:
            dp[i + k] = min(dp[i + k], dp[i] + abs(H[i + k] - H[i]))


print(dp[N-1])

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

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N, K = map(int, input().split())
H = list(map(int, input().split()))

INF = 10 ** 10
dp = [INF] * 10 ** 5
H += [H[-1] * K]

dp[0] = 0

for i in range(N):
    for k in range(1, K + 1):
        if i + k <= N:
            dp[i + k] = min(dp[i + k], dp[i] + abs(H[i + k] - H[i]))


print(dp[N-1])


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

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N, K = map(int, input().split())
H = list(map(int, input().split()))

INF = 10 ** 10
dp = [INF] * (10 ** 5 + 10)
H += [H[-1] * K]

dp[0] = 0

for i in range(N):
    for k in range(1, K + 1):
        if i + k <= N:
            dp[i + k] = min(dp[i + k], dp[i] + abs(H[i + k] - H[i]))


print(dp[N-1])
Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10 ** 7)

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N = int(readline())
ABC = [[int(x) for x in readline().split()] for _ in range(N)]

dp = [[0] * 3 for _ in range(10 * 5 + 10)]

for i in range(N):
    for j in range(3):
        for k in range(3):
            if j != k:
                dp[i + 1][j] = max(dp[i + 1][j], dp[i][k] + ABC[i][k])

ans = max(dp[N])
print(ans)


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

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N = int(readline())
ABC = [[int(x) for x in readline().split()] for _ in range(N)]

dp = [[0] * 3 for _ in range(10 ** 5 + 10)]

for i in range(N):
    for j in range(3):
        for k in range(3):
            if j != k:
                dp[i + 1][j] = max(dp[i + 1][j], dp[i][k] + ABC[i][k])

ans = max(dp[N])
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10 ** 7)

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines


def solve():

    S = input()
    T = input()

    LS = len(S)
    LT = len(T)

    dp = [[0] * (LT + 1) for _ in range(LS + 1)]
    pre = [[None] * (LT + 1) for _ in range(LS + 1)]
    for i in range(LS):
        for j in range(LT):
            now = 0
            if S[i] == T[j]:
                dp[i + 1][j + 1] = dp[i][j] + 1
                pre[i+1][j+1] = 1
            else:
                if dp[i + 1][j] < dp[i][j + 1]:
                    dp[i + 1][j + 1] = dp[i][j + 1]
                    pre[i+1][j+1] = 2
                else:
                    dp[i + 1][j + 1] = dp[i + 1][j]
                    pre[i+1][j+1] = 3

    # print(dp)

    # for p in pre:
        # print(p)

    si = LS
    ti = LT
    ans = []

    while not ((si == 0) and (ti == 0)):
        frm = pre[si][ti]
        if frm == 1:
            si -= 1
            ti -= 1
            ans.append(S[si])
        elif frm == 2:
            si -= 1
        elif frm == 3:
            ti -= 1
        elif frm == None:
            break

    return ans[::-1]


ans = solve()
print("".join(ans))


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

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines


def solve():

    S = input()
    T = input()

    LS = len(S)
    LT = len(T)

    dp = [[0] * (LT + 1) for _ in range(LS + 1)]
    pre = [[None] * (LT + 1) for _ in range(LS + 1)]
    for i in range(LS):
        for j in range(LT):
            now = 0
            if S[i] == T[j]:
                dp[i + 1][j + 1] = dp[i][j] + 1
                pre[i+1][j+1] = 1
            else:
                if dp[i + 1][j] < dp[i][j + 1]:
                    dp[i + 1][j + 1] = dp[i][j + 1]
                    pre[i+1][j+1] = 2
                else:
                    dp[i + 1][j + 1] = dp[i + 1][j]
                    pre[i+1][j+1] = 3

    # print(dp)

    # for p in pre:
        # print(p)

    si = LS
    ti = LT
    ans = []

    while not ((si == 0) and (ti == 0)):
        frm = pre[si][ti]
        if frm == 1:
            si -= 1
            ti -= 1
            ans.append(S[si])
        elif frm == 2:
            si -= 1
        elif frm == 3:
            ti -= 1
        elif frm == None:
            break

    return ans[::-1]


ans = solve()
print("".join(ans))
Buggy python submission (verdict: Runtime Error):
S = list(input())

ans = 1000
L = len(S)
for i in range(L):
  if L - 1 < i + 2:
    break
  
  s = int(S[i:i+3])
  ans = min(ans,753-s)

print(ans)

Fixed submission:
S = list(input())

ans = 1000
L = len(S)
for i in range(L):
  if L - 1 < i + 2:
    break
  
  s = int("".join(S[i:i+3]))
  ans = min(ans,abs(753-s))

print(ans)
Buggy python submission (verdict: Runtime Error):
import itertools
import bisect
N,x = map(int,input().split())
A = list(map(int,input().split()))
A.sort()
cumsum = list(itertools.accumulate(A))
ans = bisect.bisect_right(cumsum,x)

if ans == N:
  rest = cumsum[N] - x
  if rest != 0:
    ans -= 1

print(ans)


Fixed submission:
import itertools
import bisect
N,x = map(int,input().split())
A = list(map(int,input().split()))
A.sort()
cumsum = list(itertools.accumulate(A))
ans = bisect.bisect_right(cumsum,x)

if ans == N:
  rest = cumsum[-1] - x
  if rest != 0:
    ans -= 1

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
from collections import defaultdict
from collections import deque
import numpy as np

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 7)


N, M, S, T = map(int, input().split())
PATH = [[] for _ in range(N+1)]


for _ in range(M):
    u, v, a, b = map(int, input().split())
    PATH[u].append((v, a, b))
    PATH[v].append((u, a, b))

INF = 10 ** 15

da = [INF] * (N+1)
db = [INF] * (N+1)

usedA = [False] * (N+1)
usedB = [False] * (N+1)

da[S] = 0
for _ in range(N+2):
    d = -1
    v = -1
    for i in range(1, N+1):
        if not usedA[i]:
            if d == -1 or da[i] < d:
                v = i
                d = da[i]

    if d == -1:
        break

    usedA[v] = True

    for u, a, _ in PATH[v]:
        da[u] = min(da[u], da[v]+a)

db[T] = 0
for _ in range(N+2):
    d = -1
    v = -1
    for i in range(1, N+1):
        if not usedB[i]:
            if d == -1 or db[i] < d:
                v = i
                d = db[i]

    if d == -1:
        break

    usedB[v] = True

    for u, _, b in PATH[v]:
        db[u] = min(db[u], db[v]+b)

dist = [(i, da[i]+db[i]) for i in range(1, N+1)]
dist.sort(key=lambda x: x[1])
idx = 0

for i in range(N):
    while(dist[idx][0] <= i):
        idx += 1

    print(10**15 - dist[idx][1])


Fixed submission:
import sys
from collections import defaultdict
from collections import deque
import numpy as np
import heapq
from heapq import heappop, heappush

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 7)


N, M, S, T = map(int, input().split())
PATH = [[] for _ in range(N+1)]


for _ in range(M):
    u, v, a, b = map(int, input().split())
    PATH[u].append((v, a, b))
    PATH[v].append((u, a, b))


def dijkstra(s, mode):
    INF = 10 ** 15
    dist = [INF] * (N+1)
    dist[s] = 0
    que = [(0, s)]

    while que:
        d, v = heappop(que)
        if dist[v] < d:
            continue

        for u, *a in PATH[v]:
            dv = d + a[mode]

            if dv < dist[u]:
                dist[u] = dv
                heappush(que, (dv, u))

    return dist


da = dijkstra(S, 0)
db = dijkstra(T, 1)

score = [10**15 - (da[i]+db[i]) for i in range(1, N+1)]

ans = [10**15] * N
ans[-1] = score[-1]

for i in range(N-2, -1, -1):
    ans[i] = max(ans[i+1], score[i])

for i in range(N):
    print(ans[i])
Buggy python submission (verdict: Runtime Error):
N,K = map(int,input().split())
A = list(map(int,input().split()))

one = A.index(1)

ans = None
if one == 0 or one == N-1:
  ans = -(-(N-1) // (K-1))
else:
  left = -(-i // (K-1))
  right = -(-(N - i - 1 - (i % (K-1)))//(K-1))
  ans = left + right
  
print(ans)
  
  

Fixed submission:
N,K = map(int,input().split())
A = list(map(int,input().split()))

ans = -(-(N-1) // (K-1))
  
print(ans)