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

Fixed submission:
# ワ―シャルフロイドで解くよ
def main():
    import sys
    input = sys.stdin.readline  # 1行ごとの入力を繰り返し扱う場合の高速化
    N, M, L = map(int, input().split())
    # distanceを格納(未到達は無限遠として初期化)
    d = [[10 ** 12] * N for _ in range(N)]  
    # input-edges
    for i in range(M):
        a, b, c = map(int, input().split())
        if L >= c: # 距離がLより大きいのは無視
            d[a - 1][b - 1] = d[b - 1][a - 1] = c
    for i in range(N):
        d[i][i] = 0  # 自己ループ無
    
    # ワ―シャルフロイド法適用
    # 町間の最短距離を一度求める。
    for k in range(N):
        for i in range(N):
            for j in range(N):
                d[i][j] = min(d[i][k] + d[k][j], d[i][j])
    
    # 先ほど求めた町間の内、最短距離がL以下のものを距離1で結ぶ。
    edge = [[10 ** 12] * N for _ in range(N)]
    for i in range(N):
        for j in range(N):
            if d[i][j] <= L:
                edge[i][j] = 1
    
    # もう一度ワ―シャルフロイド法適用
    for k in range(N):
        for i in range(N):
            for j in range(N):
                edge[i][j] = min(edge[i][k] + edge[k][j], edge[i][j])
    
    # input-query
    Q = int(input())
    for _ in range(Q):
        s, t = map(int, input().split())
        if edge[s - 1][t - 1] >= 10 ** 12:
            print(-1)
        else:
            print(edge[s - 1][t - 1] - 1)  # 最初に燃料Lがある分、マイナス1をする。
    
if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
# ワ―シャルフロイドで解くよ
def main():
    import sys
    input = sys.stdin.readline  # 1行ごとの入力を繰り返し扱う場合の高速化
    N, M, L = map(int, input().split())
    # distanceを格納(未到達は無限遠として初期化)
    d = [[10 ** 12] * N for _ in range(N)]  
    # input-edges
    for i in range(M):
        a, b, c = map(int, input().split())
        if L >= c: # 距離がLより大きいのは無視
            d[a - 1][b - 1] = d[b - 1][a - 1] = c
    for i in range(N):
        d[i][i] = 0  # 自己ループ無
    
    # ワ―シャルフロイド法適用
    # 町間の最短距離を一度求める。
    for k in range(N):
        for i in range(N):
            for j in range(N):
                d[i][j] = min(d[i][k] + d[k][j], d[i][j])
    
    # 先ほど求めた町間の内、最短距離がL以下のものを距離1で結ぶ。
    edge = [[10 ** 12] * N for _ in range(N)]
    for i in range(N):
        for j in range(N):
            if d[i][j] <= L:
                edge[i][j] = 1
    
    # もう一度ワ―シャルフロイド法適用
    for k in range(N):
        for i in range(N):
            for j in range(N):
                edge[i][j] = min(edge[i][k] + edge[k][j], edge[i][j])
    
    # input-query
    Q = int(input())
    for _ in range(N):
        s, t = map(int, input().split())
        if edge[s - 1][t - 1] >= 10 ** 12:
            print(-1)
        else:
            print(edge[s - 1][t - 1] - 1)  # 最初に燃料Lがある分、マイナス1をする。
    
if __name__ == "__main__":
    main()
Problem p02900 (python)

Fixed submission:
# 1と素因数の個数の和が答え
# つまりAの素因数を求めて、その中でBの約数となっているものを数えればよい。

def p_factors(x): # prime_factors
    ret = [1]
    check = 2
    while (True):
        if x % check == 0:
            ret.append(check)
            while x % check == 0:
                x = x // check
        check += 1
        if x == 1 or check > int(x**0.5)+1:
            break
    if x != 1:
        ret.append(x)
    return ret

def main():
    A, B = map(int, input().split())
    factors = p_factors(A)
    cnt = 0
    for f in factors:
        if B % f == 0:
            cnt += 1
    print(cnt)

if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
import sys

sys.setrecursionlimit(10**6)

def gcd(a, b):
    if a % b == 0:
        return b
    else:
        return gcd(b, a%b)

A, B = map(int, input().split())
g = gcd(A, B)


def primes(n):
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    return [i for i in range(n + 1) if is_prime[i]]

def main():
    cnt = 1  # 1は必ず含まれるので
    data = primes(g)
    for d in data:
        if g % d == 0:
            cnt += 1
    print(cnt)

if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
def gcd(a, b):
    if a % b == 0:
        return b
    else:
        return gcd(b, a%b)

A, B = map(int, input().split())
g = gcd(A, B)

cnt = 1  # 1は必ず含まれるので

def primes(n):
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    return [i for i in range(n + 1) if is_prime[i]]

data = primes(g)

for d in data:
    if g % d == 0:
        cnt += 1

print(cnt)

Buggy submission (verdict: Runtime Error):
def gcd(a, b):
    if a % b == 0:
        return b
    else:
        return gcd(b, a%b)

A, B = map(int, input().split())
g = gcd(A, B)

cnt = 1  # 1は必ず含まれるので

def primes(n):
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    return [i for i in range(n + 1) if is_prime[i]]

data = primes(g)

for d in data:
    if g % d == 0:
        cnt += 1

print(cnt)
Problem p02917 (python)

Fixed submission:
N = int(input())
B = list(map(int, input().split()))
res = B[0]
for i in range(1, N-1):
    res += min(B[i - 1], B[i])
res += B[-1]
print(res)

Buggy submission (verdict: Runtime Error):
N = int(input())
B = list(map(int, input().split()))
res = B[0]
for i in range(1, N):
    res += min(B[i - 1], B[i])

print(res)
Problem p02924 (python)

Fixed submission:
N = int(input())
res = N * (N - 1) // 2
print(res)

Buggy submission (verdict: Runtime Error):
N = int(input())
res = sum(list(range(N)))
print(res)
Problem p02937 (python)

Fixed submission:
import bisect
S = input()
T = input()
OUT = 10**5

N = len(S)
M = len(T)
indice = [0]*M
# 素直にやるとO(NM)かかるので工夫が必要
A = [[] for _ in range(26)]
for i in range(N):
    A[ord(S[i]) - ord('a')].append(i + 1)

res = 0
b = 0
for j in range(M):
    tj = ord(T[j]) - ord('a')
    if len(A[tj]) == 0:
        print(-1)
        exit()
    r = bisect.bisect_right(A[tj], b)
    if len(A[tj]) > r:
        res += A[tj][r] - b
        b = A[tj][r]
    else:
        res += N - b + A[tj][0]
        b = A[tj][0]

print(res)

Buggy submission (verdict: Runtime Error):
import bisect
S = input()
T = input()
OUT = 10**5

N = len(S)
M = len(T)
indice = [0]*M
# 素直にやるとO(NM)かかるので工夫が必要
A = [[] for _ in range(26)]
for i in range(N):
    A[ord(S[i]) - ord('a')].append(i + 1)

res = 0
b = 0
for j in range(M):
    tj = ord(T[j]) - ord('a')
    if len(A[tj]) == 0:
        print(-1)
        exit()
    r = bisect.bisect_right(A[tj], b)
    if len(A[tj]) > r:
        res += A[tj][r] - b
        b = A{tj}[r]
    else:
        res += N - b + A[tj][0]
        b = A[tj][0]

print(res)
Problem p02947 (python)

Fixed submission:
def main():
    N = int(input())
    S = []
    for i in range(N):
        s = input()
        s = sorted(s)
        s = ''.join(s)
        S.append(s)
    S.sort()
    SS = sorted(list(set(S)))
    SN = []
    M = len(SS)
    l = 0
    r = len(S)
    for i in range(M):
        for j in range(l, r):
            if S[j] != SS[i]:
                r = j
                break
        SN.append(r - l)
        l = r
        r = len(S)        

    res = 0
    for sn in SN:
        res += sn * (sn - 1) // 2

    print(res)
if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
from collections import defaultdict as dd
N = int(input())
S = []
for i in range(N):
    s = input()
    s = sorted(s)
    s = ''.join(s)
    S.append(s)

SS = sorted(list(set(S)))
SN = []
for i in range(len(SS)):
    SN.append(S.count(SS[i]))
    if i < len(SS) - 1:
        j = S.index(SS[i+1])
        S = S[j:]


res = 0
for sn in SN:
    res += sn * (sn - 1) // 2

print(res)
Problem p02996 (python)

Fixed submission:
def main():
    N = int(input())
    A, B = [], []
    AB = []
    for i in range(N):
        a, b = map(int, input().split())
        A.append(a)
        B.append(b)
        AB.append([a, b])

    AB.sort(key=lambda x: x[1])

    time = 0
    count = 0
    for i in range(N):
        flag = True
        a, b = AB[i]
        if time + a <= b:
            time += a
            count += 1
            flag = False
        if flag:
            break

    if count == N:
        print('Yes')
    else:
        print('No')    

if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
def main():
    N = int(input())
    A, B = [], []
    AB = []
    for i in range(N):
        a, b = map(int, input().split())
        A.append(a)
        B.append(b)
        AB.append([a, b])

    AB.sort(key=lambda x: x[1])

    time = 0
    while (len(AB) > 0):
        flag = True
        a, b = AB
        if time + a <= b:
            time += a
            AB.pop(0)
            flag = False
        if flag:
            break
    if len(AB) == 0:
        print('Yes')
    else:
        print('No')

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

Fixed submission:
n, m = map(int, input().split())
s = []
for i in range(m):
    inputs = list(map(int, input().split()))
    k = inputs[0]
    s.append(inputs[1:])

p = list(map(int, input().split()))

res = 0
for i in range(2 ** n):
    flag = True
    bit_i = bin(i)[2:].zfill(n)
    for j in range(m):
        sum_s = 0
        for idx in s[j]:
            sum_s += int(bit_i[idx-1])
        if sum_s % 2 != p[j]:
            flag = False
            break
    if flag:
        res += 1

print(res)

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
S = []
for _ in range(M):
    ks = list(map(int, input().split()))
    S.append(ks[1:])
P = list(map(int, input().split()))

ans = 0
for i in range(2**M):
    bi = str(bin(i))[2:]
    bi = bi.zfill(M)
    isAddable = True
    for j in range(M):
        s_sum = 0
        for s in S[j]:
            if bi[s-1] == '1':
                s_sum += 1
        if s_sum % 2 != P[j]:
            isAddable = False
            break
    if isAddable:
        ans += 1
print(ans)
Problem p03037 (python)

Fixed submission:
n, m = map(int, input().split())
res = [0,10**5]
for i in range(m):
    l, r = map(int, input().split())
    res[0] = max(res[0], l)
    res[1] = min(res[1], r)

print(max(res[1]-res[0]+1,0))

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
res = [0,10**5]
for i in ragne(m):
    l, r = map(int, input().split())
    res[0] = max(res[0], l)
    res[1] = min(res[1], r)

print(max(res[1]-res[0]+1,0))

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
res = [0,10**5]
for i in ragne(m):
    l, r = map(int, input().split())
    res[0] = max(res[0], l)
    res[1] = min(res[1], r)

print(max(res[1]-res[0]+1),0)
Problem p03048 (python)

Fixed submission:
def main():
    r,g,b,n = map(int, input().split())
    tmp = [r,g,b]
    r,g,b = sorted(tmp, reverse=True)
    res = 0
    for i in range(n//r + 1):
        if i*r > n:
            break
        for j in range(n//g + 1):
            if r*i + g*j > n:
                break
            if (n-(r*i + g*j)) % b==0:
                res += 1           
    print(res)

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
def main():
    r,g,b,n = map(int, input().split())
    for i in range(n + 1):
      if i*r > n:
        break
        for j in range(n + 1):
            if r*i + g*j <= n:
                if (n-(r*i + g*j)) % b==0:
                    res += 1           
    print(res)

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
def main():
    r,g,b,n = map(int, input().split())
    tmp = [r,g,b]
    r,g,b = tmp.sort(reverse=True)
    res = 0
    for i in range(n//r + 1):
        for j in range(n//g + 1):
            if r*i + g*j <= n:
                if (n-(r*i + g*j)) % b==0:
                    res += 1           
    print(res)

if __name__ == '__main__':
    main()
Problem p03074 (python)

Fixed submission:
n, k = map(int, input().split())
s = input()
s += '0'
s = '0' + s

t = []
l = r = 0

for i in range(1, n + 1):
    if s[i - 1] == '0' and s[i] == '1':
        l = i
    if s[i] == '1' and s[i + 1] == '0':
        r = i
        t.append((l, r))

if len(t) > 0:
    res = 0

    if k < len(t):
        for i in range(len(t) - k):
            tmp = t[i + k][1] - t[i][0]
            res = max(res, tmp)
        if t[0][0] != 1:
            tmp = t[k - 1][1] - 1
            res = max(res, tmp)
        if t[-1][1] != n:
            tmp = n - t[-k][0]
            res = max(res, tmp)
    else:
        for i in range(len(t)):
            res = t[-1][1] - t[0][0]
        if t[0][0] != 1:
            tmp = t[min(k, len(t))-1][1] - 1
            res = max(res, tmp)
        if t[-1][1] != n:
            tmp = n - t[-min(k,len(t))][0]
            res = max(res, tmp)

    print(res + 1)
else:
    print(n)

Buggy submission (verdict: Runtime Error):
n, k = map(int, input().split())
s = input()
s += '0'
s = '0' + s

t = []
accum_mode = False
l = r = 0

for i in range(1, n + 1):
    if s[i - 1] == '0' and s[i] == '1':
        l = i
    if s[i] == '1' and s[i + 1] == '0':
        r = i
        t.append((l, r))

res = 0

if k < len(t):
    for i in range(len(t) - k):
        tmp = t[i + k][1] - t[i][0]
        res = max(res, tmp)
    if t[0][0] != 1:
        tmp = t[k - 1][1] - 1
        res = max(res, tmp)
else:
    for i in range(len(t)):
        res = t[-1][1] - t[0][0]
    if t[0][0] != 1:
        tmp = t[min(k, len(t))-1][1] - 1
        res = max(res, tmp)

print(res + 1)

Buggy submission (verdict: Runtime Error):
n, k = map(int, input().split())
s = input()
s += '0'
s = '0' + s

t = []
accum_mode = False
l = r = 0

for i in range(1, n + 1):
    if s[i - 1] == '0' and s[i] == '1':
        l = i
    if s[i] == '1' and s[i + 1] == '0':
        r = i
        t.append((l, r))

res = 0

if k < len(t):
    for i in range(len(t) - k):
        tmp = t[i + k][1] - t[i][0]
        res = max(res, tmp)
    if t[0][0] != 1:
        tmp = t[k - 1][1]
        res = max(res, tmp)
else:
    for i in range(len(t)):
        res = t[-1][1] - t[0][0]
    if t[0][0] != 1:
        tmp = t[min(k, len(t))-1][1]
        res = max(res, tmp)

print(res)
Problem p03087 (python)

Fixed submission:
N, Q = map(int, input().split())
S = input()
L,R = [], []
for i in range(Q):
    l, r = map(int, input().split())
    L.append(l)
    R.append(r)

AC = [0] * N

for i in range(1,N):
    if S[i - 1] == 'A' and S[i] == 'C':
        AC[i] = AC[i - 1] + 1
    else:
        AC[i] = AC[i - 1]

for l, r in zip(L, R):
    print(AC[r-1]-AC[l-1])

Buggy submission (verdict: Runtime Error):
import bisect
n, q = (int(i) for i in input().split())
s = input()
l,r = [],[]
for i in range(q):
    tmp = [int(i) for i in input().split()]
    l.append(tmp[0]-1)
    r.append(tmp[1]-1)
AC_index = []
while 'AC' in s:
    index = s.index('AC')
    AC_index.append(index + len(AC_index) * 2)
    if index < (len(s) - 1):
        s = s[:index] + s[index + 2:]
    else:
        s = s[:index]

for i in range(q):
    left_index = bisect.bisect_left(AC_index, l[i])
    right_index = bisect.bisect_right(AC_index, r[i])
    if AC_index[right_index - 1] == r[i]:
        right_index -= 1
        
    print(right_index-left_index)
Problem p03102 (python)

Fixed submission:
N, M, C = map(int, input().split())
b = [int(i) for i in input().split()]
a = []
for i in range(N):
    a.append([int(i) for i in input().split()])

count = 0
for i in range(N):
    tmp = 0
    for j in range(M):
        tmp += b[j] * a[i][j]
    if tmp + C > 0:
        count += 1

print(count)

Buggy submission (verdict: Runtime Error):
N, M, C = map(int, input().split())
b = [(int(i) for i in input().split())]
a = []
for i in range(N):
    a.append([int(i) for i in input().split()])

count = 0
for i in range(N):
    tmp = 0
    for j in range(M):
        tmp += b[j] * a[i][j]
    if tmp + C > 0:
        count += 1

print(count)

Buggy submission (verdict: Runtime Error):
N, M, C = map(int, input().split())
b = [map(int, input().split())]
a = []
for i in range(N):
    a.append([int(i) for i in input().split()])

count = 0
for i in range(N):
    tmp = 0
    for j in range(M):
        tmp += b[j] * a[i][j]
    if tmp + C > 0:
        count += 1

print(count)
Problem p03125 (python)

Fixed submission:
a,b = (int(i) for i in input().split())
if b%a==0:
    print(a+b)
else:
    print(b-a)

Buggy submission (verdict: Runtime Error):
#include <iostream>
using namespace std;
int main(void){
	int a,b;
	cin >> a >> b;
	if (b%a==0) {
		cout << a+b << endl;
	}else {
		cout << b-a << endl;
	}
	return 0;
}
Problem p03206 (python)

Fixed submission:
d = int(input())
if d==25:
    print("Christmas")
if d==24:
    print("Christmas Eve")
if d==23:
    print("Christmas Eve Eve")
if d==22:
    print("Christmas Eve Eve Eve")

Buggy submission (verdict: Runtime Error):
d = int(input())
if d==25:
    print(Christmas)
if d==24:
    print(Christmas Eve)
if d==23:
    print(Christmas Eve Eve)
if d==22:
    print(Christmas Eve Eve Eve)
Problem p03211 (python)

Fixed submission:
s = input()
dif = list(1000 for i in range(len(s)-2))
for i in range(len(s)-2):
    tmp = s[i:i+3]
    dif[i] = abs(int(tmp)-753)
print(min(dif))

Buggy submission (verdict: Runtime Error):
s = input()
for i in range(len(s)):
  s = input()
dif = list(1000 for i in range(len(s)-2))
for i in range(len(s)-2):
    tmp = s[i:i+3]
    dif[i] = abs(int(tmp)-753)
print(min(dif))
Problem p03238 (python)

Fixed submission:
N = int(input())
if N == 1:
    print("Hello World")
else:
    a = int(input())
    b = int(input())
    print(a+b)

Buggy submission (verdict: Runtime Error):
N = int(input())
a = int(input())
b = int(input())
if N == 1:
    print("Hello World")
else:
    print(a+b)

Buggy submission (verdict: Runtime Error):
int N = int(input())
int a = int(input())
int b = int(input())
if N == 1:
    print("Hello World")
else:
    print(a+b)

Buggy submission (verdict: Runtime Error):
int N = int(input())
int a = int(input())
int b = int(input())
print(N==1 ? "hello World" : a+b)
Problem p03262 (python)

Fixed submission:
n,s = (int(i) for i in input().split())
x = list(int(i) for i in input().split())
x = sorted(x)
if n>1:
    dif = []
    for i in range(n-1):
        dif.append(x[i+1]-x[i])

    difs = []
    for i in range(n):
        difs.append(abs(s-x[i]))
    res = min(min(dif),min(difs))
    for i in range(res):
        flag = True
        for j in range(n-1):
            if dif[j]%(res-i)!=0:
                flag = False
                break
        if flag:
            res -= i
            break
                
    print(res)
else:
    print(abs(x[0]-s))

Buggy submission (verdict: Runtime Error):
n,s = (int(i) for i in input().split())
x = list(int(i) for i in input().split())
x = sorted(x)
if n>1:
    dif = []
    for i in range(n-1):
        dif.append(x[i+1]-x[i])

    difs = []
    for i in range(n):
        difs.append(abs(s-x[i]))

    for i in range(res):
        flag = True
        for j in range(n-1):
            if dif[j]%(res-i)!=0:
                flag = False
                break
        if flag:
            res -= i
            break
                
    print(res)
else:
    print(abs(x[0]-s))

Buggy submission (verdict: Runtime Error):
n,s = (int(i) for i in input().split())
x = list(int(i) for i in input().split())
x = sorted(x)
if n>1:
    dif = []
    for i in range(n-1):
        dif.append(x[i+1]-x[i])

    difs = []
    for i in range(n):
        difs.append(abs(s-x[i]))

    print(res)
    for i in range(res):
        flag = True
        for j in range(n-1):
            if dif[j]%(res-i)!=0:
                flag = False
                break
        if flag:
            res -= i
            break
                
    print(res)
else:
    print(abs(x[0]-s))

Buggy submission (verdict: Runtime Error):
n,s = (int(i) for i in input().split())
x = list(int(i) for i in input().split())
x = sorted(x)
dif = []
for i in range(n-1):
    dif.append(x[i+1]-x[i])


difs = []
for i in range(n):
    difs.append(abs(s-x[i]))

res = min(min(dif),min(difs))
for i in range(res):
    flag = True
    for j in range(n-1):
        if dif[j]%(res-i)!=0:
            flag = False
            break
    if flag:
        res -= i
        break
            
print(res)
Problem p03276 (python)

Fixed submission:
n,k = (int(i) for i in input().split())
x = list(int(i) for i in input().split())
res = 1000000000
for i in range(n-k+1):
    xl = x[i]
    xr = x[i+k-1]
    tmp = min(abs(xl)+abs(xr-xl), abs(xr)+abs(xr-xl))
    res = min(res,tmp)
print(res)

Buggy submission (verdict: Runtime Error):
n,k = (int(i) for i in input().split())
x = list(int(i) for i in input().split())
px=[]
mx=[]
for i in range(n):
    if x[i]>=0:
        px = x[i:]
        mx = x[:i]
        break
res = 1000000000
p = len(px)
m = len(mx)
if p>0 and m>0:
    for i in range(1,min(m,k)+1):
        if p>=k-i:
            res = min(res,2*abs(mx[-i])+px[k-i-1])
    for j in range(1,min(p,k)+1):
        if m>=k-j:
            res = min(res,2*px[j-1]+abs(mx[-k+j]))
elif p>0:
    res = px[k-1]
else:
    res = abs(mx[-k])
print(res)
Problem p03282 (python)

Fixed submission:
s = str(input())
k = int(input())
c = 0
for i in range(len(s)):
    if s[i] == "1":
        c += 1
    else:
        break

if c >= k:
    print("1")
else:
    for i in range(len(s)):
        if s[i] != "1":
            print(s[i])
            break

Buggy submission (verdict: Runtime Error):
s = str(input())
k = int(input())
c = 0
for i in range(len(s)):
    if s[i] == "1":
        c += 1
    else:
        continue
if c >= k:
    print(1)
    break
for i in range(len(s)):
    if s[i] != "1":
        print(s[i])
        break
Problem p03294 (python)

Fixed submission:
n = int(input())
a = list(int(i) for i in input().split())
print(sum(a)-len(a))

Buggy submission (verdict: Runtime Error):
n = int(input())
a = (int(i) for i in input().split())
print(sum(a)-len(a))
Problem p03309 (python)

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
A = [x - i - 1 for i, x in enumerate(A)]
A.sort()
mid = A[N // 2]
res1 = 0
for a in A:
    res1 += abs(a - mid)

mid += 1
res2 = 0
for a in A:
    res2 += abs(a - mid)


print(min(res1, res2))

Buggy submission (verdict: Runtime Error):
N = int(input())
a = list(int(i) for i in input().split())
for i in range(N):
  a[i] = a[i]-i
a.sort()
if N%2==0:
  b=int((a[int(N/2)]+a[int(N/2+1)])/2)
else:
  b=a[int((N+1)/2)]
sum_1=0
sum_2=0
sum_3=0
for i in range(N):
  sum_1 += abs(a[i]-b)
b-=1
for i in range(N):
  sum_2 += abs(a[i]-b)
b+=2
for i in range(N):
  sum_3 += abs(a[i]-b)
print(min(sum_1,sum_2,sum_3))

Buggy submission (verdict: Runtime Error):
N = int(input())
a = list(int(i) for i in input().split())
for i in range(N):
  a[i] = a[i]-i
a.sort()
if N%2==0:
  b=int((a[int(N/2)]+a[int(N/2+1)])/2)
else:
  b=a[int((N+1)/2)]
sum_1=0
sum_2=0
for i in range(N):
  sum_1 += abs(a[i]-b)
b-=1
for i in range(N):
  sum_2 += abs(a[i]-b)
print(min(sum_1,sum_2))