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

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

print("Yes" if a <= c <= b else "No")

Buggy submission (verdict: Runtime Error):
a, b, c = map(int, input().split())

print("Yes" if a <= c <= b else "No)
Problem p03731 (python)

Fixed submission:
n, time = map(int, input().split())
 
arr = list(map(int, input().split())) + [float("inf")]
 
left, temp, sum_time = 0, 0, 0
 
for t in arr[1:]:
  if t <= temp + time:
    temp = t
  else:
    sum_time += (temp + time - left)
    left, temp = t, t
 
print(sum_time)

Buggy submission (verdict: Runtime Error):
n, time = map(int, input().split())
 
arr = list(map(int, input().split())) + [float("inf")]
 
left, temp, sum_time = 0, 0, 0
 
for t in arr[1:]:
  if t <= temp + time:
    temp = t
  else:
    sum_time += (temp + time - left)
    left, temp = t
 
print(sum_time)

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

arr = list(map(int, input().split())) + [float("inf")]

left, temp, sum_time = 0, 0, 0

for t in arr[1:]:
  if t <= left + time:
    temp = t
  else:
    sum_time += (temp + time - left)
    left, temp = t

print(sum_time)
Problem p03759 (python)

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

print("YES" if b - a == c - b else "NO")

Buggy submission (verdict: Runtime Error):
a, b, c = map(int, input().split())

print("YES" if b - a = c - b else "NO")
Problem p03944 (python)

Fixed submission:
w, h, n = map(int, input().split())

x1, x2, y3, y4 = [0], [w], [0], [h]

for _ in range(n):
    x, y, a = map(int, input().split())
    if a == 1:
        x1.append(x)
    elif a == 2:
        x2.append(x)
    elif a == 3:
        y3.append(y)
    else:
        y4.append(y)

print(max(min(x2) - max(x1), 0) * max(min(y4) - max(y3), 0))

Buggy submission (verdict: Runtime Error):
w, h, n = map(int, input().split())

x1, x2, y3, y4 = [], [], [], []

for _ in range(n):
  x, y, a = map(int, input().split())
  if a == 1:
    x1.append(x)
  elif a == 2:
    x2.append(x)
  elif a == 3:
    y3.append(y)
  else:
    y4.append(y)

print(max(min(w, min(x2)) - max(max(x1), 0), 0) * max(min(h, min(y4)) - max(max(y3), 0), 0))
Problem p03962 (python)

Fixed submission:
x = list(map(int, input().split()))
 
print(len(set(x)))

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

print(len(set(x))
Problem p03998 (python)

Fixed submission:
import sys

p = ["A", "B", "C"]
p_dic = {"a": 0, "b": 1, "c": 2}

def card(cards, player):
  if len(cards[player]) == 0:
    print(p[player])
    sys.exit()
  else:
    x = cards[player][0]
    cards[player] = cards[player][1:]
    card(cards, p_dic[x])

cards = [input() for i in range(3)]
card(cards, 0)

Buggy submission (verdict: Runtime Error):

S = {c: input() for c in "abc"}

s = "a"

while S[s]:
  s = S[s].pop(0)

print(s.upper())

Buggy submission (verdict: Runtime Error):
import sys

p = ["A", "B", "C"]
p_dic = {"a": 0, "b": 1, "c": 2}

def card(cards, player):
  if len(cards[player]) == 1:
    print(p[player])
    sys.exit()
  else:
    x = cards[player][0]
    cards[player] = cards[player][1:]
    def card(cards, p_dic[x])

cards = [input() for i in range(3)]
card(cards, 0)
Problem p04012 (python)

Fixed submission:
w = input()

import collections

c = collections.Counter(w)

b = True
for i in c.values():
  if i % 2 == 1:
    b = False

print("Yes" if b else "No")

Buggy submission (verdict: Runtime Error):
w = input()

import collections

c = collections.Counter(w)

b = True
for i in c.values:
  if i % 2 == 1:
    b = False

print("Yes" if b else "No")
Problem p02717 (python)

Fixed submission:
#!/usr/bin/python3

import sys
# input = sys.stdin.readline
sys.setrecursionlimit(100000)
INF = float('inf')
MOD = 10**9+7
EPS = 10**-7

#N = int(input())
#A = [int(x) for x in input().split()]
#V = [[0] * 100 for _ in range(100)]

A, B, C = [x for x in input().split()]
print("{} {} {}".format(C,A,B))

Buggy submission (verdict: Runtime Error):
#!/usr/bin/python3

import sys
# input = sys.stdin.readline
sys.setrecursionlimit(100000)
INF = float('inf')
MOD = 10**9+7
EPS = 10**-7

#N = int(input())
#A = [int(x) for x in input().split()]
#V = [[0] * 100 for _ in range(100)]

A, B, C = [x for x in input().split()]
print(f"{C} {A} {B}")
Problem p02936 (python)

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

sys.setrecursionlimit(10000000)

N, Q = [int(x) for x in input().split()]
# V = [set() for _ in range(N)]
V = [[] for _ in range(N)]
for _ in range(N - 1):
    a, b = [int(x) for x in input().split()]
    a -= 1
    b -= 1
    # V[a].add(b)
    V[a].append(b)

C = [0] * N

for _ in range(Q):
    p, x = [int(x) for x in input().split()]
    p -= 1
    C[p] += x

ANS = [0] * N


def dfs(n, val):
    ANS[n] += (val + C[n])
    for next in V[n]:
        dfs(next, val + C[n])


def main():
    dfs(0, 0)
    print(" ".join([str(x) for x in ANS]))


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
N, Q = [int(x) for x in input().split()]

V = [set() for _ in range(N)]
for _ in range(N - 1):
    a, b = [int(x) for x in input().split()]
    a -= 1
    b -= 1
    V[a].add(b)

C = [0] * N

for _ in range(Q):
    p, x = [int(x) for x in input().split()]
    p -= 1
    C[p] += x

ANS = [0] * N


def dfs(n, val):
    ANS[n] += (val + C[n])
    for next in V[n]:
        dfs(next, val + C[n])


dfs(0, 0)

print(" ".join([str(x) for x in ANS]))
Problem p02937 (python)

Fixed submission:
import sys
import bisect

# 10倍速いらしい
input = sys.stdin.readline

INF = float('inf')
MOD = 10 ** 9 + 7
EPS = 10 ** -7
sys.setrecursionlimit(1000000)

S = input().rstrip()
T = input().rstrip()

sn = len(S)
d = dict()
for i, s in enumerate(S):
    d[s] = d.get(s, [])
    d[s].append(i)

nowidx = -1
loop = 0
for t in T:
    l = d.get(t, [])
    if len(l) == 0:
        print(-1)
        sys.exit()
    j = bisect.bisect_right(l, nowidx)
    if len(l) <= j:
        nowidx = l[0]
        loop += 1
    else:
        nowidx = l[j]

# print(loop, nowidx)
print(loop * sn + nowidx + 1)

Buggy submission (verdict: Runtime Error):
import sys, math, itertools, bisect, copy, re
from collections import Counter, deque, defaultdict
from itertools import accumulate, permutations, combinations, takewhile, compress, cycle
from functools import reduce
from math import ceil, floor, log10, log2, factorial
from pprint import pprint

# 10倍速いらしい
input = sys.stdin.readline

INF = float('inf')
MOD = 10 ** 9 + 7
EPS = 10 ** -7
sys.setrecursionlimit(1000000)

S = input().rstrip()
T = input().rstrip()

sn = len(S)
M = [dict() for _ in range(sn)]
for i, s in enumerate(S):
    for j in range(sn):
        M[(i - j + sn) % sn][s] = min(M[(i - j + sn) % sn].get(s, INF), j)
    for j in range(sn):
        if M[(i - j + sn) % sn][s] == 0:
            M[(i - j + sn) % sn][s] = M[(i - j + sn + 1) % sn][s] + 1


ans = 0
idx = sn - 1
for t in T:
    if M[idx].get(t, INF) == INF:
        print(-1)
        sys.exit()
    ans += M[idx][t]
    idx = (idx + M[idx][t]) % sn

print(ans)
Problem p02991 (python)

Fixed submission:
import sys
from collections import Counter, deque, defaultdict
from itertools import accumulate, permutations, combinations, takewhile, compress, cycle
from functools import reduce
from math import ceil, floor, log10, factorial
import math

sys.setrecursionlimit(1000000)

MOD = 10 ** 9 + 7

INF = float('inf')
# N = int(input())
# A = [int(x) for x in input().split()]
# A = [int(input()) for _ in range(N)]
# dp = [[0] * 100 for _ in range(100)]
# dp = defaultdict(lambda: float('inf'))
# print('hoge', file=sys.stderr)

N, M = [int(x) for x in input().split()]

# E = {set() for _ in range(N + 1)}
E = defaultdict(lambda: set())

for i in range(M):
    u, v = [int(x) for x in input().split()]
    u -= 1
    v -= 1
    E[3 * u].add(3 * v + 1)
    E[3 * u + 1].add(3 * v + 2)
    E[3 * u + 2].add(3 * v)

S, T = [int(x) for x in input().split()]
S = 3 * (S - 1)
T = 3 * (T - 1)


def bfs(e, start, end):
    open = deque([start])
    w = dict()
    w[start] = 0
    while len(open) != 0:
        target = open.popleft()
        for next in E[target]:
            if not next in w:
                open.append(next)
                w[next] = w[target] + 1

    return w[end] // 3 if end in w else -1


print(bfs(E, S, T))

Buggy submission (verdict: Runtime Error):
import sys
from collections import Counter, deque, defaultdict
from itertools import accumulate, permutations, combinations, takewhile, compress, cycle
from functools import reduce
from math import ceil, floor, log10, log2, factorial
import math

sys.setrecursionlimit(1000000)

MOD = 10 ** 9 + 7

INF = float('inf')
# N = int(input())
# A = [int(x) for x in input().split()]
# A = [int(input()) for _ in range(N)]
# dp = [[0] * 100 for _ in range(100)]
# dp = defaultdict(lambda: float('inf'))
# print('hoge', file=sys.stderr)

N, M = [int(x) for x in input().split()]

# T = [[0] * N for _ in range(N)]
E = [set() for _ in range(N + 1)]

for i in range(M):
    u, v = [int(x) for x in input().split()]
    E[u].add(v)

S, T = [int(x) for x in input().split()]


def f(startSet, n):
    if n == 0:
        return startSet
    ret = set()
    for s in startSet:
        for t in E[s]:
            ret.add(t)
    return f(ret, n - 1)


# print(f({1}, 3))
# print(f({2}, 3))
# print(f({3}, 3))
# print(f({4}, 3))

E2 = [f({i}, 3) for i in range(N + 1)]

openNodes = {S}
closeedNodes = {}
mi = [INF] * (N + 1)
mi[S] = 0

while len(openNodes) != 0:
    curNode = -1
    curW = INF
    for on in openNodes:
        if mi[on] < curW:
            curNode = on
    openNodes.remove(curNode)

    for nn in E2[curNode]:
        if mi[nn] == INF:
            openNodes.add(nn)
            mi[nn] = mi[on] + 1

print(mi[T] if mi[T] != INF else -1)
Problem p03032 (python)

Fixed submission:
# N = int(input())
# A = [int(x) for x in input().split()]
# V = [[0] * 100 for _ in range(100)]

N, K = [int(x) for x in input().split()]
V = [int(x) for x in input().split()]

ans = 0
# 左からl個(0..K)
for l in range(K + 1):
    # 右からはr個(0..K-l)
    for r in range(K - l + 1):
        # N個よりは取れない
        if l + r > N:
            continue
        # 残りの操作数
        d = max(0, K - (l + r))

        # 合計値
        s = sum(V[:l]) + sum(V[N - r:])
        # 手元のマイナス
        neg = filter(lambda x: x < 0, V[:l] + V[N - r:])
        neg = list(neg)
        neg.sort()
        for i in range(d):
            if i < len(neg):
                s -= neg[i]

        # print(s)
        ans = max(ans,s)

print(ans)

Buggy submission (verdict: Runtime Error):
# N = int(input())
# A = [int(x) for x in input().split()]
# V = [[0] * 100 for _ in range(100)]

N, K = [int(x) for x in input().split()]
V = [int(x) for x in input().split()]

import itertools

RV = list(itertools.accumulate(V))

# 左から最大でl個とる
# for l in range(K + 1):
#     # 右からは最大でk-l個
#     for r in range(K + 1 - l):
#         print("l:{}, r:{}".format(l, r))


# heapq.heappush(Q,)
import heapq

from collections import defaultdict


def f(k):
    ret = -99999999999999999999999
    dd = defaultdict(lambda: 0)
    s = 0
    for i in range(k):
        s += V[-k + i]
        dd[V[-k + i]] += 1

    ret = max(ret, s - neg(dd, K - k))

    for i in range(k):
        rm = V[-k + i]
        ad = V[-k + i + k]
        dd[rm] -= 1
        dd[ad] += 1
        s -= rm
        s += ad
        ret = max(ret, s - neg(dd, K - k))
        # print(ret)

    return ret


def neg(d, n):
    L = sorted(d.items())
    ret = 0

    for l in L:
        v, cnt = l[0], l[1]
        if n <= 0 or v >= 0:
            break

        if n >= cnt:
            ret += (v * cnt)
        else:
            ret += (v * n)
        n -= cnt
    return ret


ans = 0
for i in range(1, K + 1):
    ans = max(ans, f(i))
print(ans)
Problem p03157 (python)

Fixed submission:
# N = int(input())
# A = [int(x) for x in input().split()]
# V = [[0] * 100 for _ in range(100)]

import sys

# input = sys.stdin.readline
sys.setrecursionlimit(400*400*10)
MOD = 10 ** 9 + 7

H, W = [int(x) for x in input().split()]
S = []
for _ in range(H):
    S.append(input())

T = [[0] * W for _ in range(H)]

t = 1


def f(h, w):
    cb = cw = 0
    dh = [1, -1, 0, 0]
    dw = [0, 0, 1, -1]

    for i in range(4):
        h2 = h + dh[i]
        w2 = w + dw[i]
        if h2 >= 0 and h2 < H and w2 >= 0 and w2 < W:
            # 未調査 かつ 色違い
            if T[h2][w2] == 0:
                if S[h][w] != S[h2][w2]:
                    T[h2][w2] = 1
                    if S[h2][w2] == "#":
                        cb += 1
                    if S[h2][w2] == ".":
                        cw += 1
                    cb2, cw2 = f(h2, w2)
                    cb += cb2
                    cw += cw2
    return cb, cw


area = []
for h in range(H):
    for w in range(W):
        if S[h][w] == "#" and T[h][w] == 0:
            tmp = f(h, w)
            if tmp[0]*tmp[1] != 0:
                area.append(tmp)

ans = 0
for a in area:
    ans += a[0]*a[1]

print(ans)

Buggy submission (verdict: Runtime Error):
# N = int(input())
# A = [int(x) for x in input().split()]
# V = [[0] * 100 for _ in range(100)]

H, W = [int(x) for x in input().split()]
S = []
for _ in range(H):
    S.append(input())

T = [[0] * W for _ in range(H)]

t = 1


def f(h, w):
    cb = cw = 0
    dh = [1, -1, 0, 0]
    dw = [0, 0, 1, -1]

    for i in range(4):
        h2 = h + dh[i]
        w2 = w + dw[i]
        if h2 >= 0 and h2 < H and w2 >= 0 and w2 < W:
            # 未調査 かつ 色違い
            if T[h2][w2] == 0:
                if S[h][w] != S[h2][w2]:
                    T[h2][w2] = 1
                    if S[h2][w2] == "#":
                        cb += 1
                    if S[h2][w2] == ".":
                        cw += 1
                    cb2, cw2 = f(h2, w2)
                    cb += cb2
                    cw += cw2
    return cb, cw


area = []
for h in range(H):
    for w in range(W):
        if S[h][w] == "#" and T[h][w] == 0:
            tmp = f(h, w)
            if tmp[0]*tmp[1] != 0:
                area.append(tmp)

ans = 0
for a in area:
    ans += a[0]*a[1]

print(ans)
Problem p03164 (python)

Fixed submission:
import sys
from collections import Counter, deque, defaultdict
from itertools import accumulate, permutations, combinations, takewhile, compress, cycle
from functools import reduce
from math import ceil, floor, log10, log2, factorial
from pprint import pprint

sys.setrecursionlimit(1000000)
# MOD = 10 ** 9 + 7
# N = int(input())
# A = [int(x) for x in input().split()]
# V = [[0] * 100 for _ in range(100)]
# A = [int(input()) for _ in range(N)]

N, W = [int(x) for x in input().split()]

dp = [float('inf')] * 1000 * 100*10
vs = set()
vs.add(0)
dp[0] = 0

for i in range(N):
    w, v = [int(x) for x in input().split()]

    tmpDP = dp.copy()
    for vv in list(vs):
        if dp[vv + v] > dp[vv] + w:
            tmpDP[vv + v] = dp[vv] + w
            vs.add(vv + v)
    dp = tmpDP


ans = 0
for v in list(vs):
    if dp[v] <= W:
        ans = max(ans, v)
print(ans)

Buggy submission (verdict: Runtime Error):
import sys
from collections import Counter, deque, defaultdict
from itertools import accumulate, permutations, combinations, takewhile, compress, cycle
from functools import reduce
from math import ceil, floor, log10, log2, factorial
from pprint import pprint

sys.setrecursionlimit(1000000)
# MOD = 10 ** 9 + 7
# N = int(input())
# A = [int(x) for x in input().split()]
# V = [[0] * 100 for _ in range(100)]
# A = [int(input()) for _ in range(N)]

N, W = [int(x) for x in input().split()]

dp = [float('inf')] * 1000 * 100
vs = set()
vs.add(0)
dp[0] = 0

for i in range(N):
    w, v = [int(x) for x in input().split()]

    tmpDP = dp.copy()
    for vv in list(vs):
        if dp[vv + v] > dp[vv] + w:
            # print(
            #     "(w,v)=({0},{1}): dp[{2}]:{3} dp[{4}]:{5} --> {6}".format(w, v, vv, dp[vv], vv + v, dp[vv + v],
            #                                                                dp[vv] + w))
            tmpDP[vv + v] = dp[vv] + w
            vs.add(vv + v)
    dp = tmpDP

# for i in range(len(dp)):
#     if dp[i] < float('inf'):
#         print("{}, {}".format(i, dp[i]))

ans = 0
for v in list(vs):
    # print("{}, {}".format(v, dp[v]))
    if dp[v] <= W:
        ans = max(ans, v)
print(ans)
Problem p03214 (python)

Fixed submission:
import sys
import collections
import itertools
import math
import re
from collections import Counter
from collections import deque
from collections import defaultdict

MOD = 10 ** 9 + 7

N = int(input())
A = [int(x) for x in input().split()]
# V = [[0] * 100 for _ in range(100)]

ave = sum(A)/N

d = [abs(a - ave) for a in A]
mi = min(d)

for i in range(N):
    if d[i] == mi:
        print(i)
        sys.exit(0)

sys.exit(0)

Buggy submission (verdict: Runtime Error):



import sys
import collections
import itertools
import math
import re
from collections import Counter
from collections import deque
from collections import defaultdict

N = int(input())
S = input()
Q = int(input())
K = [int(x) for x in input().split()]


for k in K:
    ret = 0
    d = 0
    m = 0
    dm = 0

    for i in range(N):
        s = S[i]

        if s == "C":
            ret += dm

        if s == "D":
            d += 1
        elif s == "M":
            m += 1
            dm += d

        j = i - k + 1
        if j >= 0:
            s2 = S[j]
            if s2 == "D":
                d -= 1
                dm -= m
            elif s2 == "M":
                m -= 1
    print(ret)



sys.exit(0)
Problem p03245 (python)

Fixed submission:
import sys


# 一つ前の座標と、方向を返す
def f(x, y, i):
    d = 1 << i
    if y > x and y > -x:
        return x, y - d, "U"
    elif y < x and y > -x:
        return x - d, y, "R"
    elif y < x and y < -x:
        return x, y + d, "D"
    else:
        return x + d, y, "L"


N = int(input())
X = []
Y = []
mx = 0
for i in range(N):
    x, y = [int(x) for x in input().split()]
    mx = max(abs(x) + abs(y), mx)
    X.append(x)
    Y.append(y)

s = (X[0] + Y[0]) % 2
for i in range(N):
    if s != (X[i] + Y[i]) % 2:
        print(-1)
        sys.exit(0)

# s == 1 のとき：D:[1,2,4,8,...]
# s == 0 のとき：D:[1,1,2,4,8,...]

if s == 0:
    X = [x - 1 for x in X]

D = []
d = 1
while d < mx:
    D.append(d)
    d = d * 2

m = len(D)
print(m if s != 0 else m + 1)
if s == 0:
    D = [1] + D
print(" ".join([str(d) for d in D]))

for i in range(N):
    x, y = X[i], Y[i]
    dirs = []
    for j in range(m - 1, -1, -1):
        x, y, dir = f(x, y, j)
        dirs.append(dir)
    if s == 0:
        dirs.append("R")
    print("".join(dirs[::-1]))

Buggy submission (verdict: Runtime Error):
import sys
import collections
import itertools
import math
import re
from collections import Counter
from collections import deque

MOD = 10 ** 9 + 7

N = int(input())

XY = []
for _ in range(N):
    X, Y = [int(x) for x in input().split()]
    XY.append((X, Y))


ma = 0
even = odd = 0
for xy in XY:
    s = xy[0] + xy[1]
    ma = max(s, ma)
    if s % 2:
        even += 1
    else:
        odd += 1

if not (even == N or odd == N):
    print(-1)
    sys.exit(0)

print(ma)
print(" ".join(map(str, [1] * ma)))

for xy in XY:
    x = xy[0]
    y = xy[1]

    cu = cd = cr = cl = 0
    if x < 0:
        cl = abs(x)
    else:
        cr = abs(x)
    if y < 0:
        cd = abs(y)
    else:
        cu = abs(y)
    s = ma - sum([cl, cr, cd, cu])
    cl = cl + s // 2
    cr = cr + s // 2

    print("{}{}{}{}".format("L"*cl, "R"*cr, "D"*cd, "U"*cu))

sys.exit(0)
Problem p03263 (python)

Fixed submission:

def next(i, j):
    nextI = i
    nextJ = j
    if i % 2 == 0:
        nextJ = j + 1
    else:
        nextJ = j - 1
    if nextJ < 0 or nextJ >= W:
        nextJ = j
        nextI = i+1
    return nextI, nextJ


H, W = [int(x) for x in input().split()]
a = []
for n in range(0, H):
    a.append([int(x) for x in input().split()])


isFinded = (a[0][0] % 2 == 1)
cI, cJ = 0, 0

list = []
for n in range(0, H*W-1):
    nextI, nextJ = next(cI, cJ)
    if (isFinded):
        # print("{},{},{},{}".format(cI+1, cJ+1, nextI+1, nextJ+1))
        list.append("{} {} {} {}".format(cI+1, cJ+1, nextI+1, nextJ+1))
    if (a[nextI][nextJ] % 2 == 1):
        isFinded = not (isFinded)
    cI = nextI
    cJ = nextJ

print(len(list))
for l in list:
    print(l)

Buggy submission (verdict: Runtime Error):

def next(i, j):
    nextI = i
    nextJ = j
    if i % 2 == 0:
        nextJ = j + 1
    else:
        nextJ = j - 1
    if nextJ < 0 or nextJ >= W:
        nextJ = J
        nextI = i+1
    return nextI, nextJ


H, W = [int(x) for x in input().split()]
a = []
for n in range(0, H):
    a.append([int(x) for x in input().split()])


isFinded = (a[0][0] % 2 == 1)

cI, cJ = 0, 0
for n in range(0, H*W-1):
    nextI, nextJ = next(cI, cJ)
    if (isFinded):
        print("{},{},{},{}".format(cI, cJ, nextI, nextJ))
    if (a[nextI][nextJ] % 2 == 1):
        isFinded = not (isFinded)
    cI, nJ = nextI, nextJ


'''
print(next(0, 0))
print(next(0, 2))
print(next(1, 1))
print(next(1, 0))
print(next(2, 2))
'''
Problem p03311 (python)

Fixed submission:
import sys
import math

N = int(input())
A = [int(x) for x in input().split()]
A2 = [a - i - 1 for i, a in enumerate(A)]

B = sorted(A2)

b = B[int(N/2)]


A3 = [abs(a - b) for a in A2]

print(sum(A3))


sys.exit(0)

Buggy submission (verdict: Runtime Error):
import sys
import math

N = int(input())
A = [int(x) for x in input().split()]

A2 = [a - i - 1 for i, a in enumerate(A)]

B = sorted(A2)

i1 = math.floor(N / 2)
i2 = math.ceil(N / 2)


b1 = B[i1]
b2 = B[i2]


def calcSad(A2, b):
    sum = 0
    for i in A2:
        sum += abs(i - b)
    return sum


sum = 99999999999999999999999
for b in range(b1, b2+1):
    s = calcSad(B, b)
    sum = min(sum, s)

print(sum)


sys.exit(0)
Problem p03559 (python)

Fixed submission:
N = int(input())
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]
C = [int(x) for x in input().split()]

A = sorted(A)
B = sorted(B)
C = sorted(C)

BB = [0] * N

cidx = 0
for i in range(N):
    while cidx < N and C[cidx] <= B[i]:
        cidx += 1
    BB[i] = N - cidx

BBB = [0] * N
for i in range(N - 1, -1, -1):
    if (i == N - 1):
        BBB[i] = BB[i]
    else:
        BBB[i] = BB[i] + BBB[i+1]

sum = 0
bidx = 0
for i in range(N):
    while bidx < N and B[bidx] <= A[i]:
        bidx += 1
    if bidx != N:
        sum += BBB[bidx]

print(sum)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]
C = [int(x) for x in input().split()]

A = sorted(A)
B = sorted(B)
C = sorted(C)

BB = [0] * N

cidx = 0
for i in range(N):
    while cidx < N and C[cidx] <= B[i]:
        cidx += 1
    BB[i] = N - cidx

BBB = [0] * N
for i in range(N - 1, -1, -1):
    if (i == N - 1):
        BBB[i] = BB[i]
    else:
        BBB[i] = BB[i] + BBB[i+1]

sum = 0
bidx = 0
for i in range(N):
    while B[bidx] <= A[i]:
        bidx += 1
        if bidx == N:
            break
    if bidx != N:
        sum += BBB[bidx]

print(sum)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]
C = [int(x) for x in input().split()]

A = sorted(A)
B = sorted(B)
C = sorted(C)

BB = [0] * N

cidx = 0
for i in range(N):
    while C[cidx] <= B[i]:
        cidx += 1
        if cidx == N:
            break
    BB[i] = N - cidx

BBB = [0] * N
for i in range(N - 1, -1, -1):
    if (i == N - 1):
        BBB[i] = BB[i]
    else:
        BBB[i] = BB[i] + BBB[i+1]

sum = 0
bidx = 0
for i in range(N):
    while B[bidx] <= A[i]:
        bidx += 1
        if bidx == N:
            break
    if bidx != N:
        sum += BBB[bidx]

print(sum)
pass