Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
if __name__ == '__main__':
    N = int(input())
    a = input()
    a = a.split(' ')
    a = list(map(int, a))

    min_a = min(a)
    max_a = max(a)

    num = []

    for i in range(max_a+1):
        num.append(0)

    for i in a:
        num[i-2] += 1
        num[i-1] += 1
        num[i] += 1

    c = max(num)
    print(c)

Fixed submission:
if __name__ == '__main__':
    N = int(input())
    a = input()
    a = a.split(' ')
    a = list(map(int, a))

    min_a = min(a)
    max_a = max(a)

    num = []

    for i in range(max_a+1):
        num.append(0)

    for i in a:
        if i-2 >= 0:
            num[i-2] += 1
        if i-1 >= 0:
            num[i-1] += 1
        num[i] += 1

    c = max(num)
    print(c)

Buggy python submission (verdict: Time Limit Exceeded):
if __name__ == '__main__':
    N = int(input())
    a = input()
    a = a.split(' ')
    a = list(map(int, a))

    a.sort()

    min = a[0]
    max = a[-1]

    i = min
    j = 0
    k = 0
    num = 0
    max_num = 0

    while i <= max + 1:
        if i - 1 <= a[j] and a[j] <= i + 1:
            num += 1
        elif i + 1 < a[j]:
            if max_num < num:
                max_num = num
            num = 0
            # j = k
            i += 1
            j = 0
            continue
        j += 1
        if j == len(a):
            if max_num < num:
                max_num = num
            num = 0;
            # j = k
            i += 1
            j = 0
            continue
            
    print(max_num)

Fixed submission:
if __name__ == '__main__':
    N = int(input())
    a = input()
    a = a.split(' ')
    a = list(map(int, a))

    min_a = min(a)
    max_a = max(a)

    num = []

    for i in range(max_a+1):
        num.append(0)

    for i in a:
        if i-2 >= 0:
            num[i-2] += 1
        if i-1 >= 0:
            num[i-1] += 1
        num[i] += 1

    c = max(num)
    print(c)
Buggy python submission (verdict: Runtime Error):
import math
n = int(input())
i = 0
list = []
while i < n:
   list.append(input().split())
   i += 1
h = 0
th = 1.0
ah = 1.0
while h < n:
     listh = list[h]
     x = int(listh[0])
     y = int(listh[1])
     m = max(math.ceil(th/x)),math.ceil(ah/y)))
     th = m*x
     ah = m*y
     h += 1
print(long(th+ah))

Fixed submission:
import math
from decimal import Decimal
n = int(input())
i = 0
list = []
while i < n:
   list.append(input().split())
   i += 1
h = 0
th = 1
ah = 1
while h < n:
     listh = list[h]
     x = int(listh[0])
     y = int(listh[1])
     m = max(math.ceil(th/x),math.ceil(ah/y))
     th = Decimal(m*x)
     ah = Decimal(m*y)
     h += 1
print(th+ah)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = [int(i) for i in input().split()]
for i, left in enumerate(s[0:-1]):
	for right in s[i+1:]:
		if left == right:
			print('NO')
			exit()
print('YES')

Fixed submission:
n = int(input())
s = sorted([int(i) for i in input().split()])
for i, v in enumerate(s[0:-1]):
	if v == s[i+1]:
		print('NO')
		exit()
print('YES')
Buggy python submission (verdict: Runtime Error):
from functools import reduce
n, k = [int(i) for i in input().split()]
p = [int(i) for i in input().split()]
max = sum(p[0:k])
tmp = max
idx = 0
for i in range(1, len(p) - k + 1):
	tmp -= p[i - 1]
	if i + k - 1 < len(p):
	    tmp += p[i + k - 1]
	if tmp > max:
		max = tmp
		idx = i
lst = p[idx:idx+k]

total_tasu = 0
total_kake = reduce(lambda a, b: a*b, lst)
for i, v in enumerate(lst):
	kake = total_kake / v
	total_tasu += sum([k for k in range(1, v + 1)]) * kake
print(total_tasu/total_kake)


Fixed submission:
from functools import reduce
n, k = [int(i) for i in input().split()]
p = [int(i) for i in input().split()]
tmp_max = sum([i / 2 + 0.5 for i in p[0:k]])
tmp = tmp_max
idx = 0
for i in range(1, len(p) - k + 1):
	tmp -= p[i - 1] / 2 + 0.5
	if i + k - 1 < len(p):
		tmp += p[i + k - 1] / 2 + 0.5
	tmp_max = max(tmp_max, tmp)
print(tmp_max)

Buggy python submission (verdict: Time Limit Exceeded):
from functools import reduce
n, k = [int(i) for i in input().split()]
p = [int(i) for i in input().split()]
max = 0
idx = 0
for i in range(len(p) - k + 1):
	if sum(p[i:i+k]) > max:
		max = sum(p[i:i+k])
		idx = i
lst = p[idx:idx+k]

total_tasu = 0
total_kake = reduce(lambda a, b: a*b, lst)
for i, v in enumerate(lst):
	kake = total_kake / v
	for j in range(1, v + 1):
		total_tasu += j * kake
print(total_tasu/total_kake)

Fixed submission:
from functools import reduce
n, k = [int(i) for i in input().split()]
p = [int(i) for i in input().split()]
tmp_max = sum([i / 2 + 0.5 for i in p[0:k]])
tmp = tmp_max
idx = 0
for i in range(1, len(p) - k + 1):
	tmp -= p[i - 1] / 2 + 0.5
	if i + k - 1 < len(p):
		tmp += p[i + k - 1] / 2 + 0.5
	tmp_max = max(tmp_max, tmp)
print(tmp_max)

Buggy python submission (verdict: Time Limit Exceeded):
from functools import reduce
n, k = [int(i) for i in input().split()]
p = [int(i) for i in input().split()]
max = 0
idx = 0
for i in range(len(p) - k + 1):
	if sum(p[i:i+k]) > max:
		max = sum(p[i:i+k])
		idx = i
lst = p[idx:idx+k]

total = 0
shokei = 0
for i, v in enumerate(lst):
	kake = lst[0:i]
	if i != k - 1:
		kake += lst[i+1:i+k+1]
	shokei = reduce(lambda a, b: a*b, kake, 1)
	for j in range(1, v + 1):
		total += j * shokei
waru = reduce(lambda a, b: a*b, lst)
print(total/waru)

Fixed submission:
from functools import reduce
n, k = [int(i) for i in input().split()]
p = [int(i) for i in input().split()]
tmp_max = sum([i / 2 + 0.5 for i in p[0:k]])
tmp = tmp_max
idx = 0
for i in range(1, len(p) - k + 1):
	tmp -= p[i - 1] / 2 + 0.5
	if i + k - 1 < len(p):
		tmp += p[i + k - 1] / 2 + 0.5
	tmp_max = max(tmp_max, tmp)
print(tmp_max)
Buggy python submission (verdict: Time Limit Exceeded):
h = int(input())
cnt = 0
while(True):
	if h / 2 > 0:
		cnt += 1
		h = int(h / 2)
	if h == 1:
		break
print(2 ** (cnt + 1) - 1)

Fixed submission:
h = int(input())
cnt = 1
if h == 1:
	print(1)
	exit()
    
while(True):
	cnt += 1
	h = int(h / 2)
	if h == 1:
		break
print(2 ** cnt - 1)
Buggy python submission (verdict: Time Limit Exceeded):
n, m = [int(i) for i in input().split()]
prices = sorted([int(i) for i in input().split()], reverse=True)
for i in range(m):
	prices[0] = prices[0] // 2
	prices = sorted(prices, reverse=True)
print (sum(prices))

Fixed submission:
n, m = [int(i) for i in input().split()]
prices = sorted([int(i) for i in input().split()], reverse=True)
d = 1
while(True):
	d *= 2
	if d * 2 > 10 ** 9:
		break
while(d > 0):
	for i, price in enumerate(prices):
		if price >= d:
			prices[i] = prices[i] // 2
			m -= 1
			if m == 0:
				d = 0
				break
	prices = sorted(prices, reverse=True)
	d /= 2
print (sum(prices))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
lst = []
pair = 0
for i in range(n):
	st = ''.join(sorted(list(input())))
	for j in lst:
		if st == j:
			pair += 1
	lst.append(st)
print (pair)

Fixed submission:
n = int(input())
lst = []
pair = 0
for i in range(n):
	st = ''.join(sorted(list(input())))
	lst.append(st)
lst = sorted(lst)
lst += ['end']
pre = ''
tmp_cnt = 0
cnt = 0
for i in lst:
	if i == pre:
		tmp_cnt += 1
	else:
		cnt += sum([j for j in range(tmp_cnt + 1)])
		tmp_cnt = 0
	pre = i
print (cnt)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
lst = []
pair = 0
for i in range(n):
	st = sorted(list(input()))
	for j in lst:
		if st == j:
			pair += 1
	lst.append(st)
print (pair)

Fixed submission:
n = int(input())
lst = []
pair = 0
for i in range(n):
	st = ''.join(sorted(list(input())))
	lst.append(st)
lst = sorted(lst)
lst += ['end']
pre = ''
tmp_cnt = 0
cnt = 0
for i in lst:
	if i == pre:
		tmp_cnt += 1
	else:
		cnt += sum([j for j in range(tmp_cnt + 1)])
		tmp_cnt = 0
	pre = i
print (cnt)
Buggy python submission (verdict: Time Limit Exceeded):
n, k = [int(i) for i in input().split()]
s = input() + 'E'
top = int(s[0])
now = s[0]
idx = 0
ranges = []
for i, v in enumerate(s):
	if now != v:
		ranges.append(i - idx)
		idx = i
		now = v
zero = (k * 2) * [0]
ranges = zero + ranges + zero
targetIdx = 1 if top % 2 == 0 else 0 
ret = 0
for i, v in enumerate(ranges):
	if i % 2 == targetIdx:
		ret = max(sum(ranges[i:i+(k*2)+1]), ret)
print(ret)

Fixed submission:
n, k = [int(i) for i in input().split()]
s = input() + 'E'
top = int(s[0])
now = s[0]
idx = 0
ranges = []
for i, v in enumerate(s):
	if now != v:
		ranges.append(i - idx)
		idx = i
		now = v
zero = (k * 2) * [0]
ranges = zero + ranges + zero
targetIdx = 1 if top % 2 == 0 else 0 
ret = 0
tmp = 0
for i, v in enumerate(ranges):
	tmp += v
	if i > (k * 2 + 1):
		tmp -= ranges[i - (k * 2 + 1)]
	if i % 2 == targetIdx:
		ret = max(tmp, ret)
print(ret)
Buggy python submission (verdict: Time Limit Exceeded):
n, q = [int(i) for i in input().split()]
st = input() + '-'
table = []
for i, v in enumerate(st):
	if st[i: i+2] == 'AC':
		table.append(1)
	else:
		table.append(0)

for j in range(q):
	l, r = [int(k) for k in input().split()]
	tmp = table[l-1: r-1]
	print (sum(tmp))

Fixed submission:
n, q = [int(i) for i in input().split()]
st = input() + '-'
table = []
cnt = 0
for i, v in enumerate(st):
	if st[i: i+2] == 'AC':
		cnt += 1
	table.append(cnt)
table = [0] + table

for j in range(q):
	l, r = list(map(int, input().split()))
	print (table[r-1] - table[l-1])

Buggy python submission (verdict: Runtime Error):
n, q = [int(i) for i in input().split()]
s = input()
for j in range(n):
	l, r = [int(k) for k in input().split()]
	tmp = s[l-1: r]
	print (tmp.count('AC'))

Fixed submission:
n, q = [int(i) for i in input().split()]
st = input() + '-'
table = []
cnt = 0
for i, v in enumerate(st):
	if st[i: i+2] == 'AC':
		cnt += 1
	table.append(cnt)
table = [0] + table

for j in range(q):
	l, r = list(map(int, input().split()))
	print (table[r-1] - table[l-1])
Buggy python submission (verdict: Time Limit Exceeded):
s = input()
cnt = 0
tmp = ''
hit = True
while(hit):
	hit = False
	for i in range(1, len(s)):
		if s[i-1:i+1] == '01' or s[i-1:i+1] == '10':
			tmp = s[0:i-1] + s[i+1: ]
			cnt += 2
			hit = True
			s = tmp
			break
            
print (cnt)

Fixed submission:
s = input()
cnt = 0
idx = 1
tmp = ''
hit = True
while(hit):
	hit = False
	for i in range(idx, len(s)):
		if s[i-1:i+1] == '01' or s[i-1:i+1] == '10':
			tmp = s[0:i-1] + s[i+1: ]
			cnt += 2
			idx = i - 1 if i > 1 else 1
			hit = True
			s = tmp
			break
            
print (cnt)
Buggy python submission (verdict: Time Limit Exceeded):
def gcd(a, b):
    if (b == 0):
        return a
    return gcd(b, a % b);

n, start = [int(a) for a in input().split()]
x = [int(b) for b in input().split()]
x = x + [start]
x = [c - min(x) for c in x]
DifferenceList = list()
for i, v in enumerate(x):
    if (i > 0):
        DifferenceList.append(abs(x[i] - x[i - 1]))

g = DifferenceList[0]
for d in DifferenceList:
    g = gcd(g, d)

print (g)

Fixed submission:
def gcd(a, b):
    if (b == 0):
        return a
    return gcd(b, a % b);

n, start = [int(a) for a in input().split()]
x = [int(b) for b in input().split()]
x = x + [start]
mi = min(x)

g = abs((x[1] - mi) - (x[0] - mi))
for i, v in enumerate(x):
    if (i > 0):
        d = abs((x[i] - mi) - (x[i - 1] - mi))
        g = gcd(g, d)
        
print (g)
Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

"""arc086_a"""

import sys
import pprint
import re

from collections import Counter

from functools import reduce

import itertools
pp = pprint.PrettyPrinter(indent=2)


def main():
    """Main function."""
    n, k = list(map(int, input().split(' ')))
    as_ = list(map(int, input().split(' ')))

    counter = Counter(as_)

    occ_list = sorted(counter.most_common(), key=lambda t: t[1], reverse=True)
    if len(occ_list) <= k:
        print(0)
    elif len(occ_list) == k + 1:
        print(occ_list[-1][1])
    else:
        print(reduce(lambda t1, t2: t1[1] + t2[1], occ_list[k:]))



if __name__ == '__main__':
    sys.exit(main())

Fixed submission:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

"""arc086_a"""

import sys
import pprint
import re

from collections import Counter

from functools import reduce

import itertools
pp = pprint.PrettyPrinter(indent=2)


def main():
    """Main function."""
    n, k = list(map(int, input().split(' ')))
    as_ = list(map(int, input().split(' ')))

    counter = Counter(as_)

    occ_list = sorted(counter.most_common(), key=lambda t: t[1], reverse=True)
    if len(occ_list) <= k:
        print(0)
    elif len(occ_list) == k + 1:
        print(occ_list[-1][1])
    else:
        print(reduce(lambda t1, t2: (0, t1[1] + t2[1]), occ_list[k:])[1])



if __name__ == '__main__':
    sys.exit(main())
Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

"""code-fes-2017-qual-c-c"""


import sys

OP_NUM = 0

def solve(s):
    """Solve."""
    global OP_NUM

    if len(s) == 0:
        return ""
    if len(s) == 1:
        return ""

    if s[0] == 'x':
        if s[-1] == 'x':
            return solve(s[1:-1])
        OP_NUM += 1
        return solve(s[1:])

    if s[0] == s[-1]:
        return solve(s[1:-1])
    if 'x' == s[-1]:
        OP_NUM += 1
        return solve(s[:-1])

    return None


def main():
    """Main function."""
    s = input()

    forward = solve(s)
    if forward is None:
        print(-1)
    else:
        print(OP_NUM)


if __name__ == '__main__':
    sys.exit(main())

Fixed submission:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

"""code-fes-2017-qual-c-c"""


import sys

OP_NUM = 0

def solve(s):
    """Solve."""
    global OP_NUM

    if len(s) == 0:
        return ""
    if len(s) == 1:
        return ""

    if s[0] == 'x':
        if s[-1] == 'x':
            return s[1:-1]
        OP_NUM += 1
        return s[1:]

    if s[0] == s[-1]:
        return s[1:-1]
    if 'x' == s[-1]:
        OP_NUM += 1
        return s[:-1]

    return None


def main():
    """Main function."""
    s = input()

    while s:
        s = solve(s)
        if s is None:
            print(-1)
            sys.exit(0)

    print(OP_NUM)

if __name__ == '__main__':
    sys.exit(main())
Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

"""042-c"""

import sys

ZERO_UNICODE = 48


def solve(dislike_digits_table, first_like_digit, number):
    """Solve."""
    if dislike_digits_table[int(number[0])]:
        while dislike_digits_table[int(number[0])]:
            number = "{0}{1}".format(chr(ord(number[0]) + 1), number[1:])
        number = number.replace(number[1:], first_like_digit * (len(number) - 1))

    return number


def main():
    """Main function."""
    dislike_digits_table = [False for _ in range(10)]

    N, _ = sys.stdin.readline().split(' ')
    digits = map(int, sys.stdin.readline().split(' '))

    for digit in digits:
        dislike_digits_table[digit] = True

    first_like_digit = str(next(i for i, v
                            in enumerate(dislike_digits_table)
                            if not v))

    for i, d in enumerate(N):
        if dislike_digits_table[int(d)]:
            N = N.replace(N[i:], solve(dislike_digits_table, first_like_digit, N[i:]))
            break

    print(N)


if __name__ == '__main__':
    sys.exit(main())

Fixed submission:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

"""042-c"""

import sys


def solve(dislike_digits_table, first_like_digit, N):
    """Solve."""
    for i, _ in enumerate(N):
        c = N[i]
        while dislike_digits_table[int(c)]:
            if c == '9':
                if i == 0:
                    return solve(dislike_digits_table,
                                 first_like_digit,
                                 '1' + '0' * len(N))
                else:
                    return solve(dislike_digits_table,
                                 first_like_digit,
                                 str(int(N[0:i+1]) + 1)
                                    + '0' * len(N[i+1:]))
            else:
                c = chr(ord(c) + 1)
            N = N[0:i] + c + '0' * len(N[i+1:])

    return N


def main():
    """Main function."""
    dislike_digits_table = [False for _ in range(10)]

    N, _ = sys.stdin.readline().split(' ')
    digits = map(int, sys.stdin.readline().split(' '))

    for digit in digits:
        dislike_digits_table[digit] = True

    first_like_digit = str(next(i for i, v
                                in enumerate(dislike_digits_table)
                                if not v))

    print(solve(dislike_digits_table, first_like_digit, N))


if __name__ == '__main__':
    sys.exit(main())
Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3
import sys

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


def main():
    N, M = map(int, readline().split())
    submit = [line.split() for line in readlines()]
    submit = [[int(p), S.decode()] for p, S in submit]
    AC_submit = [p for p, S in submit if S == 'AC']
    correct_set = set(AC_submit)
    penalty = 0
    for n in correct_set:
        p_submit = [S for p, S in submit if p == n]
        try:
            penalty += p_submit.index('AC')
        except ValueError:
            pass
    print(len(correct_set), penalty)


if __name__ == '__main__':
    main()


Fixed submission:
#!/usr/bin/env python3
import sys

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


def main():
    N, M = map(int, readline().split())
    submit = [line.split() for line in readlines()]
    submit = [[int(p), S.decode()] for p, S in submit]
    WA_count = [0] * (N + 1)
    correct_list = [False] * (N + 1)
    correct = 0
    penalty = 0
    for p, S in submit:
        if not correct_list[p]:
            if S == 'WA':
                WA_count[p] += 1
            else:
                correct += 1
                penalty += WA_count[p]
                correct_list[p] = True
    print(correct, penalty)


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3
import sys

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


def main():
    _ = int(readline())
    As = list(map(int, readline().split()))
    sorted_As = sorted(As)
    order = []
    for A in sorted_As:
        order.append(As.index(A))
    order = [str(o+1) for o in order]
    print(' '.join(order))


if __name__ == '__main__':
    main()


Fixed submission:
#!/usr/bin/env python3
import sys
import numpy as np

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


def main():
    _ = int(readline())
    As = list(map(int, readline().split()))
    order = np.argsort(As)
    order = [str(o + 1) for o in order]
    print(' '.join(order))


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3


def main():
    N = int(input())
    As = [int(input()) for _ in range(N)]
    for i in range(N):
        tmp = As[:]
        tmp.pop(i)
        print(max(tmp))


if __name__ == '__main__':
    main()


Fixed submission:
#!/usr/bin/env python3


def main():
    N = int(input())
    As = [int(input()) for _ in range(N)]
    max1 = max(As)
    max_idx = As.index(max1)
    As.remove(max1)
    max2 = max(As)
    max_list = [max1] * N
    max_list[max_idx] = max2
    for m in max_list:
        print(m)


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python3
import math


def main():
    A, B, C, D = map(int, input().split())

    num_C = B // C - (A - 1) // C
    num_D = B // D - (A - 1) // D
    lcm = C * D // math.gcd(C, D)
    num_CD = B // lcm - (A - 1) // lcm

    ans = (B - A + 1) - num_C - num_D + num_CD
    print(ans)


if __name__ == '__main__':
    main()


Fixed submission:
#!/usr/bin/env python3
import fractions


def main():
    A, B, C, D = map(int, input().split())

    num_C = B // C - (A - 1) // C
    num_D = B // D - (A - 1) // D
    lcm = C * D // fractions.gcd(C, D)
    num_CD = B // lcm - (A - 1) // lcm

    ans = (B - A + 1) - num_C - num_D + num_CD
    print(ans)


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

n = int(input())
d = list(map(int, input().split()))

a = []
for i in range(n):
    line = [0 for j in range(n)]
    line[i] = 1
    if i + 1 >= n:
        i = -1
    line[i + 1] = 1
    a.append(line)
    d[i] = d[i] * 2

b = np.array(d)

Ainv = np.linalg.inv(a)         # A の逆行列を計算
x = np.dot(Ainv, b) 

# for k in range(n):
#     p = a[k][k]

#     for j in range(k, n + 1):
#         a[k][j] = a[k][j] / p
#     for i in range(n):
#         print(a[i])
#     print("-------------")
#     for i in range(n):
#         if i != k:
#             d = a[i][k]
#             for j in range(k, n + 1):
#                 a[i][j] = a[i][j] - d * a[k][j]
ans = []
for i in range(n):
    ans.append(str(int(x[i])))
print(" ".join(ans))

Fixed submission:
n = int(input())
d = list(map(int, input().split()))
bSum = 0
h = 1
for i in range(n):
    d[i] = d[i] * 2
    bSum = bSum + (d[i] * h)
    h = h * -1
m1 = bSum / 2

ans = [int(m1)]
for i in range(n - 1):
    ans.append(int(d[i] - ans[i]))
print(" ".join(map(str, ans)))

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
d = list(map(int, input().split()))

a = []
for i in range(n):
    line = [0 for j in range(n + 1)]
    line[i] = 1
    if i + 1 >= n:
        i = -1
    line[i + 1] = 1
    line[n] = d[i] * 2
    a.append(line)
#print(a)

for k in range(n):
    p = a[k][k]
    for j in range(k, n + 1):
        a[k][j]  = a[k][j] / p
    for i in range(n):
        if i != k:
            d = a[i][k]
            for j in range(k, n + 1):
                a[i][j] = a[i][j] - d * a[k][j]
ans = []
for i in range(n):
    ans.append(str(int(a[i][-1])))
print(" ".join(ans))

Fixed submission:
n = int(input())
d = list(map(int, input().split()))
bSum = 0
h = 1
for i in range(n):
    d[i] = d[i] * 2
    bSum = bSum + (d[i] * h)
    h = h * -1
m1 = bSum / 2

ans = [int(m1)]
for i in range(n - 1):
    ans.append(int(d[i] - ans[i]))
print(" ".join(map(str, ans)))