Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
N = int(input())
K = int(input())
X = int(input())
Y = int(input())

a = 0 if N<K else N-k
cost = X*K + Y*a

print(cost)

Fixed submission:
N = int(input())
K = int(input())
X = int(input())
Y = int(input())

if N<K: 
    cost = X*N
else:
    cost = X*K + Y*(N-K)

print(cost)
Buggy python submission (verdict: Runtime Error):
from collections import deque
s = input()
a = deque()
for i in s:
    if i == "B":
        a.pop()
    else:
        a.append(i)
print(''.join(a))

Fixed submission:
S = str(input())
st = ""
for i in range(len(S)):
    if S[i] == "1":
        st += "1"
    elif S[i] =="0":
        st += "0"
    else:
        st = st[:-1]
print(st)
Buggy python submission (verdict: Time Limit Exceeded):
def abc176_e():
    h, w, m = map(int, input().split())
    ch = [0]*h
    cw = [0]*w
    bs = dict()
    for _ in range(m):
        hi, wi = map(lambda x: int(x)-1, input().split())
        ch[hi] += 1
        cw[wi] += 1
        bs[(hi,wi)] = 1
    mch = max(ch)
    mcw = max(cw)
    if mch == h and mcw == w:
        ans = h + w - 1
    else:
        flag = False
        for i in [x for x in range(h) if ch[x] == mch]:
            for j in [x for x in range(w) if cw[x] == mcw]:
                if bs.get((i,j)) == None:
                    flag = True
                    break
            if flag: break
        if flag: ans = mch + mcw
        else: ans = mch + mcw - 1
    print(ans)

if __name__ == '__main__':
    abc176_e()

Fixed submission:
# https://atcoder.jp/contests/abc176/submissions/16124424
from collections import Counter
def abc176_e():
  h, w, m = map(int, input().split())
  H = []
  W = []
  for _ in range(m):
    hi, wi = map(int, input().split())
    H.append(hi)
    W.append(wi)
  mosth = Counter(H).most_common()[0]
  mostw = Counter(W).most_common()[0]
  ans1 = mosth[1]
  ans2 = mostw[1]
  wpair = []
  hpair = []
  for i, hi in enumerate(H):
    if hi == mosth[0]: continue
    wpair.append(W[i])
  for i, wi in enumerate(W):
    if wi == mostw[0]: continue
    hpair.append(H[i])
  if wpair:
    ans1 += Counter(wpair).most_common()[0][1]
  if hpair:
    ans2 += Counter(hpair).most_common()[0][1]
  ans = max(ans1, ans2)
  print(ans)

if __name__ == '__main__':
    abc176_e()

Buggy python submission (verdict: Time Limit Exceeded):
def abc176_e():
    h, w, m = map(int, input().split())
    ch = [0]*h
    cw = [0]*w
    bs = dict()
    for _ in range(m):
        hi, wi = map(lambda x: int(x)-1, input().split())
        ch[hi] += 1
        cw[wi] += 1
        bs[(hi,wi)] = 1
    mch = max(ch)
    mcw = max(cw)
    if mch == h and mcw == w:
        ans = h + w - 1
    else:
        flag = False
        for i in range(h):
            if ch[i] < mch: continue
            for j in range(w):
                if cw[j] < mcw: continue
                if bs.get((i,j)) == None:
                    flag = True
                    break
            if flag: break
        if flag: ans = mch + mcw
        else: ans = mch + mcw - 1
    print(ans)

if __name__ == '__main__':
    abc176_e()

Fixed submission:
# https://atcoder.jp/contests/abc176/submissions/16124424
from collections import Counter
def abc176_e():
  h, w, m = map(int, input().split())
  H = []
  W = []
  for _ in range(m):
    hi, wi = map(int, input().split())
    H.append(hi)
    W.append(wi)
  mosth = Counter(H).most_common()[0]
  mostw = Counter(W).most_common()[0]
  ans1 = mosth[1]
  ans2 = mostw[1]
  wpair = []
  hpair = []
  for i, hi in enumerate(H):
    if hi == mosth[0]: continue
    wpair.append(W[i])
  for i, wi in enumerate(W):
    if wi == mostw[0]: continue
    hpair.append(H[i])
  if wpair:
    ans1 += Counter(wpair).most_common()[0][1]
  if hpair:
    ans2 += Counter(hpair).most_common()[0][1]
  ans = max(ans1, ans2)
  print(ans)

if __name__ == '__main__':
    abc176_e()
Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
P = list(map(lambda x: int(x)-1, input().split()))
C = list(map(int, input().split()))
ans = -10**18
for i in range(n):  # 開始点を全通り
  x = i
  sc = []
  tot = 0
  while True:
    x = P[x]
    sc.append(C[x])
    tot += C[x]
    if x == i: break  # 開始点に戻ってきて循環に入った
  #print(i, sc, tot)
  l = len(sc)
  cum = 0
  for j in range(l):  # 何ステップ進むとよいか
    cum += sc[j]
    if j+1 > k: break  # k=1は最初の1周のみ
    val = cum  # 循環ループ考慮するスコア
    if tot > 0:
      cyc = (k-(j+1)) // l  # 残りステップで循環できる数
      val += tot * cyc
    ans = max(ans, val)
    #print(j, cum, cyc, val)
print(ans)

Fixed submission:
n, k = map(int, input().split())
P = list(map(lambda x: int(x)-1, input().split()))
C = list(map(int, input().split()))
ans = -10**18
for i in range(n):  # 開始点を全通り
  x = i
  sc = []
  tot = 0
  while True:
    x = P[x]
    sc.append(C[x])
    tot += C[x]
    if x == i: break  # 開始点に戻ってきて循環に入った
  #print(i, sc, tot)
  l = len(sc)
  cum = 0
  for j in range(l):  # 何ステップ進むとよいか
    cum += sc[j]
    if j+1 > k: break  # k=1は最初の1周のみ
    val = cum  # 循環ループ考慮するスコア
    if tot > 0:
      cyc = (k-(j+1)) // l  # 残りステップで循環できる数
      val += tot * cyc
    ans = max(ans, val)
    #print(j, cum, cyc, val)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
P = list(map(lambda x: int(x)-1, input().split()))
C = list(map(int, input().split()))
ans = -10**18
for i in range(n):  # 開始点を全通り
  x = i
  sc = []
  tot = 0
  while True:
    x = P[x]
    sc.append(C[x])
    tot += C[x]
    if x == i: break  # 開始点に戻ってきて循環に入った
  #print(i, sc, tot)
  l = len(sc)
  cum = 0
  for j in range(l):  # 何ステップ進むとよいか
    cum += sc[j]
    if j+1 > k: break  # k=1は最初の1周のみ
    val = cum  # 循環ループ考慮するスコア
    if tot > 0:
      cyc = (k-(j+1)) // l  # 残りステップで循環できる数
      val += tot * cyc
    ans = max(ans, val)
    #print(j, cum, cyc, val)
print(ans)

Fixed submission:
n, k = map(int, input().split())
P = list(map(lambda x: int(x)-1, input().split()))
C = list(map(int, input().split()))
ans = -10**18
for i in range(n):  # 開始点を全通り
  x = i
  sc = []
  tot = 0
  while True:
    x = P[x]
    sc.append(C[x])
    tot += C[x]
    if x == i: break  # 開始点に戻ってきて循環に入った
  #print(i, sc, tot)
  l = len(sc)
  cum = 0
  for j in range(l):  # 何ステップ進むとよいか
    cum += sc[j]
    if j+1 > k: break  # k=1は最初の1周のみ
    val = cum  # 循環ループ考慮するスコア
    if tot > 0:
      cyc = (k-(j+1)) // l  # 残りステップで循環できる数
      val += tot * cyc
    ans = max(ans, val)
    #print(j, cum, cyc, val)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
k = int(input())
x = 0
ans = -1
if k % 2 == 1:
    for i in range(10**7):
        x = (x + 7 * pow(10, i, k)) % k
        if x == 0:
            ans = i + 1
            break
print(ans)

Fixed submission:
k = int(input())
x = 0
ans = -1
if k % 2 == 1:
    for i in range(10**6):
        x = (x + 7 * pow(10, i, k)) % k
        if x == 0:
            ans = i + 1
            break
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
def prime_factorize(n: int) -> list:
    ''' nの素因数分解 '''
    arr = []
    while n % 2 == 0:
        arr.append(2)
        n = n // 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            arr.append(f)
            n = n // f
        else:
            f += 2
    if n != 1:
        arr.append(n)
    return arr

from collections import Counter

N = int(input())
ans = 0
for k in range(1, N+1):
    f = 1
    for _, v in Counter(prime_factorize(k)).items():
        f *= (v+1)
    ans += k * f
print(ans)

Fixed submission:
N = int(input())
ans = 0
for k in range(1, N+1):
    d = N // k
    ans += k * (d+1) * d // 2
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))
Q = int(input())
Query = [tuple(map(int, input().split())) for _ in range(Q)]
from collections import Counter
cntr = Counter(A)
keys = list(cntr.keys())
for b, c in Query:
    cntr[c] += cntr[b]
    cntr[b] = 0
    ans = 0
    for k, v in cntr.items():
        ans += k * v
    print(ans)

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
Q = int(input())
Query = [tuple(map(int, input().split())) for _ in range(Q)]
from collections import Counter
cntr = Counter(A)
ans = sum(A)
for b, c in Query:
    if cntr.get(b) == None:
        print(ans)
        continue
    diff = (c - b) * cntr[b]
    ans += diff
    print(ans)
    cntr[c] += cntr[b]
    cntr[b] = 0

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))
Q = int(input())
Query = [tuple(map(int, input().split())) for _ in range(Q)]
from collections import Counter
cntr = Counter(A)
keys = list(cntr.keys())
for b, c in Query:
    cntr[c] += cntr[b]
    cntr[b] = 0
    ans = 0
    for k, v in cntr.items():
        ans += k * v
    print(ans)

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
Q = int(input())
Query = [tuple(map(int, input().split())) for _ in range(Q)]
from collections import Counter
cntr = Counter(A)
ans = sum(A)
for b, c in Query:
    if cntr.get(b) == None:
        print(ans)
        continue
    diff = (c - b) * cntr[b]
    ans += diff
    print(ans)
    cntr[c] += cntr[b]
    cntr[b] = 0
Buggy python submission (verdict: Runtime Error):
def abc168_c():
    A, B, H, M = map(int, input().split())
    # 時針の位相
    h_angle = 30 * H + 0.5 * M
    # 分針の位相
    m_angle = 6 * M
    # x方向
    x_dist = A * math.cos(math.radians(h_angle)) - B * math.cos(math.radians(m_angle))
    # y方向
    y_dist = A * math.sin(math.radians(h_angle)) - B * math.sin(math.radians(m_angle))
    # 距離
    dist = math.sqrt(x_dist ** 2 + y_dist ** 2)
    print('{:.12f}'.format(dist))

abc168_c()

Fixed submission:
import math

def abc168_c():
    A, B, H, M = map(int, input().split())
    # 時針の位相
    h_angle = 30 * H + 0.5 * M
    # 分針の位相
    m_angle = 6 * M
    # x方向
    x_dist = A * math.cos(math.radians(h_angle)) - B * math.cos(math.radians(m_angle))
    # y方向
    y_dist = A * math.sin(math.radians(h_angle)) - B * math.sin(math.radians(m_angle))
    # 距離
    dist = math.sqrt(x_dist ** 2 + y_dist ** 2)
    print('{:.12f}'.format(dist))

abc168_c()
Buggy python submission (verdict: Runtime Error):
def abc166_d():
  x = int(input())
  for k in range(1, 56):
    cand = (x + k**5) ** 0.2
    if cand.is_integer():
      print(int(cand), k)
      return
    cand = (x - k**5) ** 0.2
    if cand.is_integer():
      print(int(cand), -k)
      return

abc166_d()

Fixed submission:
def abc166_d():
  x = int(input())
  for i in range(-126, 127):
    for j in range(-126, 127):
      if i**5 - j**5 == x:
        print('{} {}'.format(i, j))
        return

abc166_d()

Buggy python submission (verdict: Runtime Error):
def abc166_d():
  x = int(input())
  for k in range(1, 33):
    cand = (x + k**5) ** 0.2
    if cand.is_integer():
      print(int(cand), k)
      return
    cand = (x - k**5) ** 0.2
    if cand.is_integer():
      print(int(cand), -k)
      return

abc166_d()

Fixed submission:
def abc166_d():
  x = int(input())
  for i in range(-126, 127):
    for j in range(-126, 127):
      if i**5 - j**5 == x:
        print('{} {}'.format(i, j))
        return

abc166_d()
Buggy python submission (verdict: Time Limit Exceeded):
def abc164_d():
  s = str(input())
  ans = 0
  for i in range(len(s)-4):
    for j in range(i+4, len(s)+1):
      t = int(s[i:j])
      if t % 2019 == 0:
        ans += 1
  print(ans)

abc164_d()

Fixed submission:
def abc164_d():
    # 解説放送
    s = str(input())
    n = len(s)
    m = 2019
    srev = s[::-1]  # 下の位から先に見ていくために反転する
    x = 1  # 10^i ??
    total = 0  # 累積和 (mod 2019 における累積和)
    cnt = [0] * m  # cnt[k] : 累積和がkのものが何個あるか
    ans = 0
    for i in range(n):
        cnt[total] += 1
        total += int(srev[i]) * x
        total %= m
        ans += cnt[total]
        x = x*10 % m
    print(ans)

abc164_d()

Buggy python submission (verdict: Time Limit Exceeded):
def abc164_d():
  s = str(input())
  ans = 0
  for i in range(len(s)-4):
    for j in range(i+4, len(s)+1):
      t = int(s[i:j])
      if t % 2019 == 0:
        ans += 1
  print(ans)

abc164_d()

Fixed submission:
def abc164_d():
    # 解説放送
    s = str(input())
    n = len(s)
    m = 2019
    srev = s[::-1]  # 下の位から先に見ていくために反転する
    x = 1  # 10^i ??
    total = 0  # 累積和 (mod 2019 における累積和)
    cnt = [0] * m  # cnt[k] : 累積和がkのものが何個あるか
    ans = 0
    for i in range(n):
        cnt[total] += 1
        total += int(srev[i]) * x
        total %= m
        ans += cnt[total]
        x = x*10 % m
    print(ans)

abc164_d()
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
INF = 10**9

n, x, y = map(int, input().split())
x, y = x-1, y-1
ans = [0] * n

for sv in range(n):
  dist = [INF] * n
  q = deque()

  def push(v, d):
    if dist[v] != INF: return
    dist[v] = d
    q.append(v)

  push(sv, 0)

  while q:
    v = q.popleft()
    d = dist[v]
    if v-1 >= 0: push(v-1, d+1)
    if v+1 < n: push(v+1, d+1)
    if v == x: push(y, d+1)
    if v == y: push(x, d+1)

  for i in range(n):
    ans[dist[i]] += 1

for i in range(n):
  ans[i] //= 2

for i in range(1, n):
  print(ans[i])

Fixed submission:
from collections import deque
INF = 10**9

n, x, y = map(int, input().split())
x, y = x-1, y-1
ans = [0] * n

for sv in range(n):
  dist = [INF] * n
  q = deque()

  def push(v, d):
    if dist[v] != INF: return
    dist[v] = d
    q.append(v)

  push(sv, 0)

  while q:
    v = q.popleft()
    d = dist[v]
    if v-1 >= 0: push(v-1, d+1)
    if v+1 < n: push(v+1, d+1)
    if v == x: push(y, d+1)
    if v == y: push(x, d+1)

  for i in range(n):
    ans[dist[i]] += 1

for i in range(n):
  ans[i] //= 2

for i in range(1, n):
  print(ans[i])
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
K = int(input())

ans = 0
for n in range(N+1):
    cnt_zero = str(n).count('0')
    if cnt_zero == len(str(n)) - K:
        ans += 1

print(ans)

Fixed submission:
n = str(input())
k = int(input())
l = len(n)

def f(dig, under, num):
  if num > l - dig: return 0
  if num == 0: return 1
  if dig == l-1:
    if under: return int(n[dig])
    else: return 9
  if under:
    if n[dig] == '0':
      res = f(dig+1, True, num)
      #print(dig, under, num, res, 'aaa')
      return res
    else:
      res = f(dig+1, False, num)
      if int(n[dig]) > 1:
        res += (int(n[dig])-1) * f(dig+1, False, num-1)
      res += f(dig+1, True, num-1)
      #print(dig, under, num, res, 'bbb')
      return res
  else:
    res = f(dig+1, False, num)
    res += 9 * f(dig+1, False, num-1)
    #print(dig, under, num, res, 'ccc')
    return res

ans = f(0, True, k)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
def abc153_e():
    H, N = map(int, input().split())
    M = [tuple(map(int, input().split())) for _ in range(N)]

    inf = 10**18
    cost = [inf] * (H+1)
    cost[0] = 0
    for a, b in M:
        for i in range(1, H+1):
            tmp = cost[i-a] + b if i-a > 0 else b
            cost[i] = min(cost[i], tmp)
    print(cost[H])

abc153_e()

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

    inf = 10**18
    cost = [inf] * (H+1)
    cost[0] = 0
    for a, b in M:
        for i in range(1, H+1):
            tmp = cost[i-a] + b if i-a > 0 else b
            cost[i] = min(cost[i], tmp)
    print(cost[H])

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

def diverta192_b():
    N = int(input())
    P = [tuple(map(int, input().split())) for _ in range(N)]
    if len(P) == 1:
        print(1)  # 座標が1つだけ与えられる場合は即終了
        return

    dcnt = defaultdict(int)  # import忘れずに
    for i in range(N):
        xi, yi = P[i]
        for j in range(i):
            xj, yj = P[j]
            dcnt[(xi-xj, yi-yj)] += 1
            dcnt[(xj-xi, yj-yi)] += 1  # 逆向きもカウントする(都合よいほうを使う)
    most = sorted(dcnt.values(), reverse=True)[0]  # 最も多いカウントを取り出す
    ans = N - most
    print(ans)

diverta192_b()

Fixed submission:
from collections import defaultdict

def abc152_d():
    N = int(input())
    freq = defaultdict(int)
    for i in range(1, N+1):
        s = str(i)
        freq[(s[0], s[-1])] += 1  # (先頭,末尾) となる個数を数える

    ans = 0
    for i in range(1, N+1):
        s = str(i)
        ans += freq[(s[-1], s[0])]  # ペアになる (末尾, 先頭) の個数を足していく
    print(ans)

abc152_d()
Buggy python submission (verdict: Runtime Error):
def keyence20_a():
    H, W, N = map(int, readlines())
    lg = max(H, W)
    ans = (N + lg - 1) // lg
    print(ans)

keyence20_a()

Fixed submission:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

def keyence20_a():
    H, W, N = map(int, readlines())
    lg = max(H, W)
    ans = (N + lg - 1) // lg
    print(ans)

keyence20_a()
Buggy python submission (verdict: Runtime Error):
n = int(input())
A = list(map(int, input().split()))
mod = 10**9 + 7
mem = [0, 0, 0]
ans = 1
for i in range(n):
    ans *= mem.count(A[i])
    ans %= mod
    idx = mem.index(A[i])
    mem[idx] += 1
print(ans)

Fixed submission:
n = int(input())
A = list(map(int, input().split()))
mod = 10**9 + 7
mem = [0, 0, 0]
ans = 1
for i in range(n):
    ans *= mem.count(A[i])
    ans %= mod
    if ans == 0: break
    idx = mem.index(A[i])
    mem[idx] += 1
print(ans)

Buggy python submission (verdict: Runtime Error):
n = int(input())
A = list(map(int, input().split()))
mod = 10**9 + 7
mem = [1, 0, 0]
ans = 3
for i in range(1, n):
    ans *= mem.count(A[i])
    ans %= mod
    mem[mem.index(A[i])] += 1
print(ans)

Fixed submission:
n = int(input())
A = list(map(int, input().split()))
mod = 10**9 + 7
mem = [0, 0, 0]
ans = 1
for i in range(n):
    ans *= mem.count(A[i])
    ans %= mod
    if ans == 0: break
    idx = mem.index(A[i])
    mem[idx] += 1
print(ans)
Buggy python submission (verdict: Runtime Error):
def abc146_d():
    n = int(input())
    Q = [tuple(map(lambda x: int(x)-1, input().split())) for _ in range(n-1)]

    deg = [0] * n
    adj = [[] for _ in range(n)]
    color = dict()

    for a, b in Q:
        deg[a] += 1
        deg[b] += 1
        adj[a].append(b)
        adj[b].append(a)

    def dfs(s, p):
        nouse = -1
        if p > -1: nouse = color[(min(s, p), max(s, p))]
        c = 1
        for t in adj[s]:
            if t == p: continue
            if c == nouse: c += 1
            color[(min(s, t), max(s, t))] = c
            dfs(t, s)
            c += 1

    dfs(1, -1)

    print(max(deg))
    for a, b in Q:
        print(color[(a, b)])

if __name__ == '__main__':
    abc146_d()

Fixed submission:
import sys
sys.setrecursionlimit(10010010)

def abc146_d():
    n = int(input())
    Q = [tuple(map(lambda x: int(x)-1, input().split())) for _ in range(n-1)]

    deg = [0] * n
    adj = [[] for _ in range(n)]
    color = dict()

    for a, b in Q:
        deg[a] += 1
        deg[b] += 1
        adj[a].append(b)
        adj[b].append(a)

    def dfs(s, p):
        nouse = -1
        if p > -1: nouse = color[(min(s, p), max(s, p))]
        c = 1
        for t in adj[s]:
            if t == p: continue
            if c == nouse: c += 1
            color[(min(s, t), max(s, t))] = c
            dfs(t, s)
            c += 1

    dfs(1, -1)

    print(max(deg))
    for a, b in Q:
        print(color[(a, b)])

if __name__ == '__main__':
    abc146_d()
Buggy python submission (verdict: Runtime Error):
# C - Average Length

N = int(input())
arr = []
for i in range(N):
    tmp = list(map(int, input().split()))
    arr.append(tmp)

####

import math
import statistics
import itertools

table = [[0]*N for i in range(N)]
for i in range(N):
    ti = arr[i]
    for j in range(N):
        tj = arr[j]
        dist = math.sqrt((ti[0] - tj[0])**2 + (ti[1] - tj[1])**2)
        #print(i, j, ti, tj, dist)
        table[i][j] = dist

#print(table)

kumi_all = list(itertools.permutations(range(N)))
kumi_all_count = len(kumi_all)

total_dist = 0

for i in range(kumi_all_count):
    this_dist = 0
    this_kumi = kumi_all[i]

    for j in range(N-1):
        this_dist += table[this_kumi[j]][this_kumi[j+1]]

    #print("{}: {}".format(i, this_dist))
    total_dist += this_dist

#print(total_dist, stop_loop)
avr_dist = total_dist / stop_loop

print(avr_dist)


Fixed submission:
# C - Average Length

N = int(input())
arr = []
for i in range(N):
    tmp = list(map(int, input().split()))
    arr.append(tmp)

####

import math
import statistics
import itertools

table = [[0]*N for i in range(N)]
for i in range(N):
    ti = arr[i]
    for j in range(N):
        tj = arr[j]
        dist = math.sqrt((ti[0] - tj[0])**2 + (ti[1] - tj[1])**2)
        table[i][j] = dist

kumi_all = list(itertools.permutations(range(N)))
kumi_all_count = len(kumi_all)

total_dist = 0

for i in range(kumi_all_count):
    this_dist = 0
    this_kumi = kumi_all[i]

    for j in range(N-1):
        this_dist += table[this_kumi[j]][this_kumi[j+1]]

    total_dist += this_dist

avr_dist = total_dist / kumi_all_count

print(avr_dist)
Buggy python submission (verdict: Runtime Error):
# D - Knight

X, Y = map(int, input().split())
####

a = (2*Y - X) / 3
b = (2*X - Y) / 3

import math

if a%1 != 0 or b%1 != 0:
    print(0)
else:
    a = int(a)
    b = int(b)
    # 最短経路の数 nCr
    ans = (math.factorial(a + b) // (math.factorial(a) * math.factorial(b))) % (10**9 + 7)

    print(ans)


Fixed submission:
# D - Knight

X, Y = map(int, input().split())
####

a = (2*Y - X) / 3
b = (2*X - Y) / 3

# https://qiita.com/derodero24/items/91b6468e66923a87f39f
def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] % mod * g2[n-r] % mod

mod = 10**9+7 #出力の制限
N = 10**6
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

if a%1 != 0 or b%1 != 0:
    print(0)
else:
    ans = cmb(int(a+b), int(min(a,b)), mod)
    print(ans)
Buggy python submission (verdict: Runtime Error):
def nikkei19q_b():
    _ = int(input())
    D = list(map(int, input().split()))
    div = 998244353

    dmax = max(D)
    cntr = [0] * (dmax + 1)
    for d in D: cntr[d] += 1  # カウンター

    if D[0] != 0: return 0  # 最初に入力される頂点1は距離0マスト
    if cntr[0] != 1: return 0  # 距離0が無い、または2つ以上、はおかしい

    ans = 1
    for i in range(1, dmax+1):
        if cntr[i] == 0: return 0  # カウント0だとつながらないのでNG
        ans = ans * (cntr[i-1][1] ** cntr[i][1]) % div
    print(ans)

nikkei19q_b()

Fixed submission:
def nikkei19q_b():
    _ = int(input())
    D = list(map(int, input().split()))
    div = 998244353

    dmax = max(D)
    cntr = [0] * (dmax + 1)
    for d in D: cntr[d] += 1  # カウンター

    if D[0] != 0: return 0  # 最初に入力される頂点1は距離0マスト
    if cntr[0] != 1: return 0  # 距離0が無い、または2つ以上、はおかしい

    ans = 1
    for i in range(1, dmax+1):
        if cntr[i] == 0: return 0  # カウント0だとつながらないのでNG
        ans = ans * (cntr[i-1] ** cntr[i]) % div
    return ans

print(nikkei19q_b())
Buggy python submission (verdict: Time Limit Exceeded):
def abc144_e():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    F = list(map(int, input().split()))
    A.sort()
    F.sort(reverse=True)

    low = -1
    up = 10**12
    while up - low > 1:
        v = (up + low) // 2
        tk = K
        for i in range(N):
            tk -= max(0, A[i] - (v // F[i]))
            if tk < 0: break
        if tk < 0:
            low = v
        else:
            up = v
    print(up)

if __name__ == '__main__':
    abc144_e()

Fixed submission:
def abc144_e():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    F = list(map(int, input().split()))
    A.sort()
    F.sort(reverse=True)

    low = -1
    up = 10**12
    while up - low > 1:
        v = (up + low) // 2
        tk = K
        for i in range(N):
            tk -= max(0, A[i] - (v // F[i]))
            if tk < 0: break
        if tk < 0:
            low = v
        else:
            up = v
    print(up)

if __name__ == '__main__':
    abc144_e()