Problem:


Score : 400 points

Problem Statement

There are N mountains in a circle, called Mountain 1, Mountain 2, ..., Mountain N in clockwise order. N is an odd number.

Between these mountains, there are N dams, called Dam 1, Dam 2, ..., Dam N. Dam i (1 \leq i \leq N) is located between Mountain i and i+1 (Mountain N+1 is Mountain 1).

When Mountain i (1 \leq i \leq N) receives 2x liters of rain, Dam i-1 and Dam i each accumulates x liters of water (Dam 0 is Dam N).

One day, each of the mountains received a non-negative even number of liters of rain.

As a result, Dam i (1 \leq i \leq N) accumulated a total of A_i liters of water.

Find the amount of rain each of the mountains received. We can prove that the solution is unique under the constraints of this problem.

Constraints

All values in input are integers.

3 \leq N \leq 10^5-1

N is an odd number.

0 \leq A_i \leq 10^9

The situation represented by input can occur when each of the mountains receives a non-negative even number of liters of rain.

Input

Input is given from Standard Input in the following format:

N
A_1 A_2 ... A_N

Output

Print N integers representing the number of liters of rain Mountain 1, Mountain 2, ..., Mountain N received, in this order.

Sample Input 1

3
2 2 4

Sample Output 1

4 0 4

If we assume Mountain 1, 2, and 3 received 4, 0, and 4 liters of rain, respectively, it is consistent with this input, as follows:

Dam 1 should have accumulated \frac{4}{2} + \frac{0}{2} = 2 liters of water.

Dam 2 should have accumulated \frac{0}{2} + \frac{4}{2} = 2 liters of water.

Dam 3 should have accumulated \frac{4}{2} + \frac{4}{2} = 4 liters of water.

Sample Input 2

5
3 8 7 5 5

Sample Output 2

2 4 12 2 8

Sample Input 3

3
1000000000 1000000000 0

Sample Output 3

0 2000000000 0



Sample input:
3
2 2 4


Sample output:
4 0 4

Submission status: Runtime Error

Solution code:
# (d1+d2)/2 == n1, (d2+d3)/2 == n2... が矛盾なくなるようにする
# にぶたんを使う
# なんかしらんけど3問駄目だな...

n = int(input())
dum = list(map(int, input().split()))
count = 0
l, r = 0, (10 ** 9 + 1000000) // 2

while True:
    mid = (l + r) // 2
    # print(l, r, mid)
    rain = [0 for _ in range(n)]
    rain[0] += mid * 2
    for i in range(1, n):
        next_amount = (dum[i - 1] - (rain[i - 1] // 2)) * 2
        rain[i] += next_amount
    # print(rain)

    if dum[-1] == (rain[-1] + rain[0]) // 2:
        for i in range(n):
          end = " " if i < n-1 else ""
          print(rain[i], end=end)
        print()
        exit()
    if (rain[0] + rain[-1]) // 2 < dum[-1]:
        # 最初に決めたやつが小さすぎた
        # print("{} は小さすぎた".format(rain[0]))
        l = mid + 1
    else:
        # 最初に決めたやつが大きすぎた
        # print("{} は大きすぎた".format(rain[0]))
        r = mid

    # セーフティネット 必要ないけど
    if count > 50:
        t = 5 / 0
        break
    count += 1

"""
7
110 50 53 50 11 36 88

11
38 7 15 15 9 31 23 1 5 55 81
"""

Submission status: Runtime Error

Solution code:
# (d1+d2)/2 == n1, (d2+d3)/2 == n2... が矛盾なくなるようにする
# にぶたんを使う
# なんかしらんけど3問がWAで駄目だな...

n = int(input())
dum = list(map(int, input().split()))
count = 0
l, r = -1, (10 ** 9 + 1000000) // 2

while True:
    mid = (l + r) // 2
    # print(l, r, mid)
    rain = [0 for _ in range(n)]
    rain[0] += mid * 2
    for i in range(1, n):
        next_amount = (dum[i - 1] - (rain[i - 1] // 2)) * 2
        rain[i] += next_amount
    # print(rain)

    if dum[-1] == (rain[-1] + rain[0]) // 2:
        rain = list(map(str, rain))
        print(" ".join(rain))
        exit()
    if (rain[0] + rain[-1]) // 2 < dum[-1]:
        # 最初に決めたやつが小さすぎた
        # print("{} は小さすぎた".format(rain[0]))
        l = mid + 1
    else:
        # 最初に決めたやつが大きすぎた
        # print("{} は大きすぎた".format(rain[0]))
        r = mid

    # セーフティネット 必要ないけど
    if count > 50:
        t = 5 / 0
        break
    count += 1

"""
7
110 50 53 50 11 36 88

11
38 7 15 15 9 31 23 1 5 55 81
"""

Submission status: Runtime Error

Solution code:
# (d1+d2)/2 == n1, (d2+d3)/2 == n2... が矛盾なくなるようにする
# にぶたんを使う

n = int(input())
dum = list(map(int, input().split()))
count = 0
l, r = 0, (10 ** 9 + 1000000) // 2

while True:
    mid = (l + r) // 2
    # print(l, r, mid)
    rain = [0 for _ in range(n)]
    rain[0] += mid * 2
    for i in range(1, n):
        next_amount = (dum[i - 1] - (rain[i - 1] // 2)) * 2
        if next_amount < 0:
            break
        rain[i] += next_amount
    # print(rain)
    flag = True
    for i in range(1, n):
        if dum[i - 1] != (rain[i - 1] + rain[0]) // 2:
            flag = False
    if flag and dum[-1] == (rain[-1] + rain[0]) // 2:
        rain = list(map(str, rain))
        print(" ".join(rain))
        exit()
    if (rain[0] + rain[-1]) // 2 < dum[-1]:
        # 最初に決めたやつが小さすぎた
        # print("{} は小さすぎた".format(rain[0]))
        l = mid + 1
    else:
        # 最初に決めたやつが大きすぎた
        # print("{} は大きすぎた".format(rain[0]))
        r = mid

    # セーフティネット 必要ないけど
    if count > 50:
        t = 5 / 0
        break
    count += 1

"""
7
110 50 53 50 11 36 88

11
38 7 15 15 9 31 23 1 5 55 81
"""

Submission status: Runtime Error

Solution code:
# (d1+d2)/2 == n1, (d2+d3)/2 == n2... が矛盾なくなるようにする
# にぶたんを使う

n = int(input())
dum = list(map(int, input().split()))
count = 0
l, r = 0, (10 ** 9 + 1000000) // 2

while True:
    mid = (l + r) // 2
    # print(l, r, mid)
    rain = [0 for _ in range(n)]
    rain[0] += mid * 2
    for i in range(1, n):
        next_amount = (dum[i - 1] - (rain[i - 1] // 2)) * 2
        if next_amount < 0:
            break
        rain[i] += next_amount
    # print(rain)

    if dum[-1] == (rain[-1] + rain[0]) // 2:
        rain = list(map(str, rain))
        print(" ".join(rain))
        exit()
    if (rain[0] + rain[-1]) // 2 < dum[-1]:
        # 最初に決めたやつが小さすぎた
        # print("{} は小さすぎた".format(rain[0]))
        l = mid + 1
    else:
        # 最初に決めたやつが大きすぎた
        # print("{} は大きすぎた".format(rain[0]))
        r = mid

    # セーフティネット 必要ないけど
    if count > 50:
        t = 5 / 0
        break
    count += 1

"""
7
110 50 53 50 11 36 88

11
38 7 15 15 9 31 23 1 5 55 81
"""

Submission status: Runtime Error

Solution code:
# (d1+d2)/2 == n1, (d2+d3)/2 == n2... が矛盾なくなるようにする
# にぶたんを使う

n = int(input())
dum = list(map(int, input().split()))
count = 0
l, r = 0, (10 ** 9 + 1000000) // 2

while True:
    mid = (l + r) // 2
    # print(l, r, mid)
    rain = [0 for _ in range(n)]
    rain[0] += mid * 2
    flag = True
    for i in range(1, n):
        next_amount = (dum[i - 1] - (rain[i - 1] // 2)) * 2
        if next_amount < 0:
            flag = False
            break
        rain[i] += next_amount
    # print(rain)

    if flag and dum[-1] == (rain[-1] + rain[0]) // 2:
        rain = list(map(str, rain))
        print(" ".join(rain))
        exit()
    if (rain[0] + rain[-1]) // 2 < dum[-1]:
        # 最初に決めたやつが小さすぎた
        # print("{} は小さすぎた".format(rain[0]))
        l = mid + 1
    else:
        # 最初に決めたやつが大きすぎた
        # print("{} は大きすぎた".format(rain[0]))
        r = mid

    # セーフティネット 必要ないけど
    if count > 50:
        t = 5 / 0
        break
    count += 1

"""
7
110 50 53 50 11 36 88

11
38 7 15 15 9 31 23 1 5 55 81
"""

Submission status: Runtime Error

Solution code:
# (d1+d2)/2 == n1, (d2+d3)/2 == n2... が矛盾なくなるようにする
# にぶたんを使う

n = int(input())
dum = list(map(int, input().split()))
count = 0
l, r = 0, (10 ** 9 + 1000000) // 2

while True:
    mid = (l + r) // 2
    # print(l, r, mid)
    rain = [0 for _ in range(n)]
    rain[0] += mid * 2
    flag = True
    for i in range(1, n):
        next_amount = (dum[i - 1] - (rain[i - 1] // 2)) * 2
        if next_amount < 0:
          flag = False
          break
        rain[i] += next_amount
    # print(rain)

    if flag and dum[-1] == (rain[-1] + rain[0]) // 2:
        rain = list(map(str, rain))
        print(" ".join(rain))
        exit()
    if (rain[0] + rain[-1]) // 2 < dum[-1]:
        # 最初に決めたやつが小さすぎた
        # print("{} は小さすぎた".format(rain[0]))
        l = mid + 1
    else:
        # 最初に決めたやつが大きすぎた
        # print("{} は大きすぎた".format(rain[0]))
        r = mid

    # セーフティネット 必要ないけど
    if count > 50:
        t = 5 / 0
        break
    count += 1

"""
7
110 50 53 50 11 36 88

11
38 7 15 15 9 31 23 1 5 55 81
"""

Submission status: Runtime Error

Solution code:
# (d1+d2)/2 == n1, (d2+d3)/2 == n2... が矛盾なくなるようにする
# にぶたんを使う

n = int(input())
dum = list(map(int, input().split()))
count = 0
l, r = 0, (10 ** 9 + 1000000) // 2

while True:
    mid = (l + r) // 2
    # print(l, r, mid)
    rain = [0 for _ in range(n)]
    rain[0] += mid * 2
    for i in range(1, n):
        next_amount = (dum[i - 1] - (rain[i - 1] // 2)) * 2
        rain[i] += next_amount
    # print(rain)

    if dum[-1] == (rain[-1] + rain[0]) // 2:
        rain = list(map(str, rain))
        print(" ".join(rain))
        exit()
    if (rain[0] + rain[-1]) // 2 < dum[-1]:
        # 最初に決めたやつが小さすぎた
        # print("{} は小さすぎた".format(rain[0]))
        l = mid + 1
    else:
        # 最初に決めたやつが大きすぎた
        # print("{} は大きすぎた".format(rain[0]))
        r = mid

    # セーフティネット 必要ないけど
    if count > 50:
        t = 5 / 0
        break
    count += 1

"""
7
110 50 53 50 11 36 88

11
38 7 15 15 9 31 23 1 5 55 81
"""

Submission status: Runtime Error

Solution code:
# (d1+d2)/2 == n1, (d2+d3)/2 == n2... が矛盾なくなるようにする
# にぶたんを使う

n = int(input())
dum = list(map(int, input().split()))
count = 0
l, r = 0, (10 ** 9 + 1000000) // 2

while True:
    mid = (l + r) // 2
    # print(l, r, mid)
    rain = [0 for _ in range(n)]
    rain[0] += mid * 2
    for i in range(1, n):
        next_amount = (dum[i - 1] - (rain[i - 1] // 2)) * 2
        rain[i] += next_amount
    print(rain)

    if dum[-1] == (rain[-1] + rain[0]) // 2:
        rain = list(map(str, rain))
        # print(" ".join(rain))
        exit()
    if (rain[0] + rain[-1]) // 2 < dum[-1]:
        # 最初に決めたやつが小さすぎた
        # print("{} は小さすぎた".format(rain[0]))
        l = mid + 1
    else:
        # 最初に決めたやつが大きすぎた
        # print("{} は大きすぎた".format(rain[0]))
        r = mid

    # セーフティネット 必要ないけど
    if count > 50:
        t = 5 / 0
        break
    count += 1

"""
7
110 50 53 50 11 36 88

11
38 7 15 15 9 31 23 1 5 55 81
"""

Submission status: Runtime Error

Solution code:
# (d1+d2)/2 == n1, (d2+d3)/2 == n2... が矛盾なくなるようにする
# にぶたんを使う

n = int(input())
dum = list(map(int, input().split()))
count = 0
l, r = 0, (10 ** 9 + 1000000) // 2

while True:
    mid = (l + r) // 2
    # print(l, r, mid)
    rain = [0 for _ in range(n)]
    rain[0] += mid * 2
    for i in range(1, n):
        next_amount = (dum[i - 1] - (rain[i - 1] // 2)) * 2
        rain[i] += next_amount
    # print(rain)

    if dum[-1] == (rain[-1] + rain[0]) // 2:
        rain = list(map(str, rain))
        print(" ".join(rain))
        exit()
    if (rain[0] + rain[-1]) // 2 < dum[-1]:
        # 最初に決めたやつが小さすぎた
        # print("{} は小さすぎた".format(rain[0]))
        l = mid
    else:
        # 最初に決めたやつが大きすぎた
        # print("{} は大きすぎた".format(rain[0]))
        r = mid

    # セーフティネット 必要ないけど
    if count > 50:
        t = 5 / 0
        break
    count += 1

"""
7
110 50 53 50 11 36 88

11
38 7 15 15 9 31 23 1 5 55 81
"""

Submission status: Runtime Error

Solution code:
import numpy as np

n = int(input())
d = list(map(int, input().split()))
a = np.zeros((len(d),len(d)))
for i in range(n):
  for j in range(n):
    if (i > j) ^ ((i+j) % 2 == 0):
      a[i][j] = 0.5
    else:
      a[i][j] = -0.5
# print(a)
d = np.array(d)
solved = np.dot(a, 2 * d.T)
print(' '.join(map(str, (map(int, solved)))))

Submission status: Runtime Error

Solution code:
import numpy as np
n=int(input())
A=list(map(int,input().split()))
B=np.array([[0]*n for i in range(n)])
for i in range(n-1):
	B[i,i]=B[i,i+1]=1
B[n-1,0]=B[n-1,n-1]=1
X=np.linalg.solve(B,A)
print(*[int(2*x) for x in X])

Submission status: Runtime Error

Solution code:
N=int(input())
A=list(map(int,input().split()))
S=sum(A)
B=[0]*N
B[0]=S-2*sum(A[1::2])
for i in range(n-1):
    B[i+1]=2*A[i]-B[i]
print(*B)

Submission status: Runtime Error

Solution code:
import numpy as np


def main():
    N = int(input())
    A = np.array(list(map(int, input().split())))

    B = np.zeros([N, N])
    np.fill_diagonal(B, 1)
    ps = list(range(1, N)) + [0]
    B = B[ps, :]
    np.fill_diagonal(B, 1)
    iB = np.linalg.inv(B)

    X = np.dot(iB, A) * 2
    X = X.astype(np.int32)
    print(*X)


main()

Submission status: Runtime Error

Solution code:
from itertools import accumulate
N = int(input())
A = list(map(int, input().split()))
S = sum(A)
B = list(accumulate([0] + A[1::2] + A[::2] + [A[1]]))
C = [S - 2 * (B[i+N//2] - B[i]) for i in range(N)]
print(*sum(list(map(list, zip(C[:N//2+1], C[N//2+1:]+[0]))), [])[:-1])

Submission status: Runtime Error

Solution code:
l, r = map(int, input().split())
if r-l >= 2017:
	print (0)
	exit()
else:
	for i in range(l,r+1):
		for j in range(i+1,r+1):
			a = min(a,i*j%2019)
print (a)

Submission status: Runtime Error

Solution code:
import numpy as np
N = int(input())
water = np.array(list(map(int, input().split())))
A = np.zeros((N, N))
for i in range(N):
    if i == N-1:
        A[N-1][0] = 1
        A[N-1][N-1] = 1
    else:
        A[i][i] = 1
        A[i][i+1] = 1
D = np.linalg.solve(A, water)
d = [0]*N
for i in range(N):
    d[i] = int(D[i])
print(" ".join([str(2*n) for n in d]))

Submission status: Runtime Error

Solution code:
import numpy as np
N = int(input())
a_list = np.array(list(map(int, input().split())))

a_array = np.zeros((N,N))

for i in range(N):
  a_array[i-1][i] = 0.5
  a_array[i-1][i-1] = 0.5
  
a = np.linalg.solve(a_array, a_list).astype(int)
print(*a)

Submission status: Runtime Error

Solution code:
n=int(input())
a=list(map(int,input().split()))
b=[0]*n
k=0
for i in range(n):
  if i%2==0:
    k+=a[i]
b[0]=sum(a)-k*2
for i in range(1,n):
  b[i]=2*a[i-1]-b[i-1]
  
print(' '.join(b))

Submission status: Runtime Error

Solution code:
import unittest
import numpy as np


class TestD(unittest.TestCase):
    def test_1(self):
        self.assertEqual(think([2, 2, 4]), [4, 0, 4])

    def test_2(self):
        self.assertEqual(think([3, 8, 7, 5, 5]), [2, 4, 12, 2, 8])

    def test_3(self):
        self.assertEqual(think([1000000000, 1000000000, 0]), [0, 2000000000, 0])


def solve():
    b = read()
    x = think(b)
    write(x)


def read():
    n = read_int(1)[0]
    return read_int(n)


def read_int(n):
    return list(map(lambda x: int(x), read_line().split(' ')))[:n]


def read_float(n):
    return list(map(lambda x: float(x), read_line().split(' ')))[:n]


def read_line(n=0):
    if n == 0:
        return input().rstrip()
    else:
        return input().rstrip()[:n]


def think(b):
    n = len(b)

    # (r1 + r2) * 1/2 == b1, (r2 + r3) * 1/2 == b2
    # so...
    # a = (1, 1, 0, 0, 0, ....)
    #     (0, 1, 1, 0, 0, ....)
    #     (0, 0, 1, 1, 0, ....)
    #     (               ....)
    # a * r == 2 * b
    # r == 2 * inv(a) * b

    # a[row][column]
    a = np.zeros((n, n))
    for row in range(n):
        a[row][row] = 1.0
        if row == n - 1:
            a[row][0] = 1.0
        else:
            a[row][row + 1] = 1.0

    r = np.linalg.inv(a)
    result = 2 * np.matmul(r, np.array(b))

    return list(map(int, result))


def write(result):
    print(' '.join(map(str, result)))


if __name__ == '__main__':
    # unittest.main()
    solve()

Submission status: Runtime Error

Solution code:
# ABC133D - Rain Flows into Dams
def main():
    # X_0 = sum(A) - 2 * sum(A[1::2]), X_i = 2Ai - X_{i-1}
    N, *A = map(int, open(0).read().split())
    X = [0] * N
    cur = sum(A) - 2 * sum(A[1::2])
    X[0] = cur
    for i, a in enumerate(A[:-1], 1):
        X[i] = a * 2 - cur
        cur = X[i]
    print(" ".join(map(str, ans)))


if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
import numpy as np
n = int(input())
b = 2*np.array([int(x) for x in input().split()])
A = np.eye(n)
for i in range(n-1):
    A[i, i+1] = 1
A[-1,0] = 1
print(' '.join(str(int(val)) for val in np.linalg.solve(A,b)))

Submission status: Runtime Error

Solution code:
import numpy as np
N = int(input())
P = np.array(list(map(int,input().split())))*2
A = np.array([np.zeros(N)]*N)

for i in range(N):
    if i == 0:
        A[0][0] = 1
        A[-1][0] = 1
    else:
        A[i-1][i] = 1
        A[i][i] = 1
        
ans = [int(round(one,0)) for one in np.dot(np.linalg.pinv(A),P)]

ans_s = ""
for one in ans:
    ans_s += "{} ".format(one)
ans_s = ans_s[:-1]

print(ans_s)

Submission status: Runtime Error

Solution code:
import numpy as np
N = int(input())
P = np.array(list(map(int,input().split())))*2
A = np.array([np.zeros(N)]*N)

for i in range(N):
    if i == 0:
        A[0][0] = 1
        A[-1][0] = 1
    else:
        A[i-1][i] = 1
        A[i][i] = 1
        
ans = [int(one) for one in np.dot(np.linalg.inv(A),P)]

ans_s = ""
for one in ans:
    ans_s += "{} ".format(one)
ans_s = ans_s[:-1]

print(ans_s)

Submission status: Runtime Error

Solution code:
import numpy as np

N = int(input())
A = np.array(list(map(int, input().split())))
#print(A)

b = [0.5 for _ in range(N)]
B0 = np.diag(b)
b.pop()
B1 = np.diag(b, k=1)
B = B0 + B1
B[N-1][0] = 0.5
#print(B)

#x = np.linalg.solve(B, A)
Binv = np.linalg.inv(B)
x = np.dot(Binv, A)
x = map(int, x)
ans = ' '.join(map(str, x))
print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np

N = int(input())
A = np.array(list(map(int, input().split())))
#print(A)

b = [0.5 for _ in range(N)]
B0 = np.diag(b)
b.pop()
B1 = np.diag(b, k=1)
B = B0 + B1
B[N-1][0] = 0.5
#print(B)

x = np.linalg.solve(B, A)
x = map(int, x)
ans = ' '.join(map(str, x))
print(ans)

Submission status: Runtime Error

Solution code:
[ ]
n = int(input())
B = list(map(int, input().split()))
A = [0 for _ in range(n)]
A[0] = B[0]
A[n-1] = B[n-2]
for i in range(n-2):
  A[i+1] = min(B[i], B[i+1])
print(sum(A[j]for j in range(n)))
​
[ ]
n, k = map(int, input().split())
s = input()
if s[k-1] == 'A':
  s = s[:k-1] + 'a' + s[k:]
elif s[k-1] == 'B':
  s = s[:k-1] + 'b' + s[k:]
else:
  s = s[:k-1] + 'c' + s[k:]
print(s)
[ ]
a, b, t = map(int, input().split())
print(b*(t//a))
[ ]
a, b = map(int, input().split())
c = max(a, b)
if a == b:
  print(2*a)
else:
  print(2*c - 1)
[ ]
n, m = map(int, input().split())
A = []
for i in range(n):
  A.append(list(map(int, input().split())))
cost = 0
count = 0
A.sort(key = lambda x:x[0])
for i in range(n):
  if count == m:
    break
  elif count + A[i][1] <= m:
    cost += A[i][1] * A[i][0]
    count += A[i][1]
  else:
    while count < m:
      cost += A[i][0]
      count += 1
print(cost)
  
[ ]
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
k = int(input())
if e-a <= k:
  print('Yay!')
else:
  print(':(')
​
[ ]
S = input()
A = S[0:4] + S[5:7] + S[8:10]
if int(A) <= 20190430:
  print('Heisei')
else:
  print('TBD')

[ ]
a, b = map(int, input().split())
if b%a == 0:
  print(a + b)
else:
  print(b-a)
​

[1]
n = int(input())
print(n*(n-1)//2)
n = int(input())
print(n*(n-1)//2)


[22]
LR
S = input()
n = len(S)
A = []
B = []
a = 0
b = 0
for i in range(n-1):
  if S[i:i+2] == 'LR':
    B.append([i,i+1])
    A.append([S[a:i+1]])
    a = i+1
    b += 1
A.append([S[a:]])
print(A)
print(B)
C = [0 for _ in range(n)]
for k in range(b):
  C[B[k][0]] = A[k][0].count('L')
  C[B[k][1]] = A[k][0].count('R')
print(C)


[26]
S = input()
n = len(S)
A = []
B = []
a = 0
for i in range(n-1):
  if S[i:i+2] == 'LR':
    B.append([i,i+1])
    A.append([S[a:i+1]])
    a = i+1
    b += 1
A.append([S[a:]])
print(A)
print(B)
​


[27]
n = int(input())
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
minimum = min(a, b, c, d, e)
if n%minimum == 0:
  print(4 + n//minimum)
else:
  print(5 + n//minimum)
n = int(input())
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
minimum = min(a, b, c, d, e)
if n%minimum == 0:
  print(4 + n//minimum)
else:
  print(5 + n//minimum)


[30]
n = int(input())
AB = []
for i in range(n):
  AB.append(list(map(int, input().split())))
time = 0
flag = True
AB.sort(key = lambda x:x[1])
for i in range(n):
  time += AB[i][0]
  if AB[i][1] >= time:
    continue
  else:
    flag = False
    print('No')
    break
if flag:
  print('Yes')


n = int(input())
A = list(map(int, input().split()))
B = []
rain = sum(a for a in A)
for i in range(n):
  cost = 0
  if i%2 == 0:
    C = A[:i]
    cost += sum(C[2*k] for k in range(i//2))
    D = A[i:]
    cost += sum(D[2*k+1] for k in range((n-i-1)//2))
    B.append(rain - 2*cost)
  else:
    C = A[:i]
    cost += sum(C[2*k+1] for k in range((i-1)//2))
    D = A[i+1:]
    cost += sum(D[2*k] for k in range((n-i)//2))
    B.append(rain - 2*cost)
L=[str(a) for a in B]
L=" ".join(L)
print(L)

Submission status: Runtime Error

Solution code:
import sympy
N = int(input())
A = [int(i) for i in input().split()]
ans = [x*2]

x = sympy.Symbol('x')
s = x
for i in range(1, N):
    s = A[i-1]-s
    ans.append(s*2)
    
sol = sympy.solve(A[N-1]-s-x)[0]
for i in range(N):
    ans[i] = ans[i].subs(x, sol)
    print(ans[i], end = " ")

Submission status: Runtime Error

Solution code:
import sympy
N = int(input())
A = [int(i) for i in input().split()]
ans = [x*2]

x = sympy.Symbol('x')
s = x
for i in range(1, N):
    s = A[i-1]-s
    ans.append(s*2)
    
sol = sympy.solve(A[N-1]-s-x)[0]
for i in range(N):
    ans[i] = str(ans[i].subs(x, sol))
print(' '.join(ans))

Submission status: Runtime Error

Solution code:
import sympy
N = int(input())
A = [int(i) for i in input().split()]
ans = [x*2]

x = sympy.Symbol('x')
s = x
for i in range(1, N):
    s = A[i-1]-s
    ans.append(s*2)
    
sol = sympy.solve(A[N-1]-s-x)[0]
for i in range(N):
    ans[i] = ans[i].subs(x, sol)
print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
a = [int(i) for i in input().split()]

import numpy as np
A = np.zeros((n,n))
for i in range(n): #左の行列
  if i<n-1:
    A[i][i]=1
    A[i][i+1]=1
  else:
    A[i][0]=1
    A[i][i]=1
b = np.array(a) #右辺
x = np.linalg.solve(A, b)
x_list = x.tolist()
x_list = [2*i for i in x_list]
for i in range(n):
  print(int(x_list[i]), end=" ")

Submission status: Runtime Error

Solution code:
N = int(input())
A = [int(x) for x in input().split()]
r = [0]*(N+1)
for i in range(N):
  r[i+1] = A[i]-r[i]
x = r[N]
r[1::2] = r[1::,2]-x
r[0::2] = r[1::,2]+x
r = list(map(str,r))
print(" ".join(r))

Submission status: Runtime Error

Solution code:
import sys
from bisect import *
from collections import *
from copy import deepcopy
from heapq import *
from itertools import *
from math import *
from operator import *
import numpy as np

sys.setrecursionlimit(10**8)

input = sys.stdin.readline

def main():
    """ main """
    N = int(input())
    dams = list(map(int, input().split()))
    smallest_idx = 0
    for i in range(1,N):
        if dams[i] < dams[smallest_idx]:
            smallest_idx = i
    dams = dams[smallest_idx:] + dams[:smallest_idx]

    for i in range(0, dams[0]*2+1, 2):
        mts = [0]*N
        mts[0] = i
        for j in range(1,N):
            mts[j] = (dams[j-1]-mts[j-1]//2)*2
            if mts[j] < 0:
                break
        else:
            if mts[0]//2 + mts[N-1]//2 == dams[N-1]:
                mts = mts[N-smallest_idx:] + mts[:N-smallest_idx]
                print(*mts)
                return 0

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import numpy as np
n=int(input())
a=[int(x) for x in input().split()]

matrix=np.zeros((n,n))

for i in range(n-1):
  matrix[i,i:i+2]+=1
matrix[-1,0]+=1
matrix[-1,-1]+=1

X = 2*np.linalg.solve(matrix, np.array(a)).astype(int)

print(*X)

Submission status: Runtime Error

Solution code:
import numpy as np
n=int(input())
a=[int(x) for x in input().split()]

matrix=np.zeros((n,n))

for i in range(n-1):
  matrix[i,i:i+2]+=1
matrix[-1,0]+=1
matrix[-1,-1]+=1

#A = np.array([[1.,3.] ,[4.,2.]])
#B = np.array([1.,1.])   # 行列Bの生成

X = np.linalg.solve(matrix, np.array(a)).tolist()
# 計算結果の表示
print(*[int(2*item) for item in X])

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int, input().split()))
s = sum(A)
A = A*2

ans = []
for i in range(2):
    ans.append(str(s - sum(A[i+1:N+i-1:2])*2 ))
for i in range(2,N):
    ans.append(str(int(ans[i-2])+(A[i-11]-A[N+i-2])*2))

ans = ' '.join(ans)
print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int,input().split()))
ans =[]
sum_rain = sum(a)
a_double = [i*2 for i in a]*2
for i in range(n):
  minus = sum(a_double[i+1:i+n-1:2])
  ans.append(sum_rain-minus)
  

print(' '.join(map(str,ans))

Submission status: Runtime Error

Solution code:
n=int(input())
a=list(map(int,input().split()))

fx=0
for i in range(1,n):
    if i%2==0:
        fx+=a[i]
ans=[0]*n
ans[0]=sum(a)-2*fx
for i in range(n-1):
    ans[i+1]=2a[i]-ans[i]
print(*ans)

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int, input().split()))

# m0 + m1 + m2 + m3 + m4 = d0 + d1 + d2 + d3 + d5
# d0 = (m0 + m1)//2
# d1 = (m1 + m2)//2
# d2 = (m2 + m3)//2
# d3 = (m3 + m4)//2
# d4 = (m4 + m0)//2
# m0 =  d0 - d1 + d2 - d3 + d4
# m1 =  d0 + d1 - d2 + d3 - d4
# m2 = -d0 + d1 + d2 - d3 + d4
# m3 =  d0 - d1 + d2 + d3 - d4
# m4 = -d0 + d1 - d2 + d3 + d4   

b = [a[i:]+a[:i] for i in range(n)]
print(*[sum(b[::2])-sum(b[1::2]) for i in range(n)])

Submission status: Runtime Error

Solution code:
a = list(map(int,input().split()))
x1 = sum([a[h] if h%2==0 else -a[h] for h in range(n)])
print(x1,end = ' ')

for i in range(n-1):
	if i == 0:
		b = a[i]*2 - x1
		print(b,end=' ')
	else:
		print(a[i]*2 - b,end=' ')
		b = a[i]*2 - b

Submission status: Runtime Error

Solution code:
N=int(input())
dums = list(map(int, input().split()))

M_1 = 0
for i,val in enumerate(dums):
    i+=1
    if i%2==1:
        M_1 += val
    else:
        M_1 -= val

out_dict = {i+1:0 for i in range(N)}
out_dict[1] = M_N

for i in range(1,N):
    out_dict[i+1] = 2*dums[i-1] - out_dict[i]

print(" ".join(list(map(str, out_dict.values()))))

Submission status: Runtime Error

Solution code:
import sys
n = int(input())
a = list(map(int,input().split()))
tmp = 0
for j in range(0,a[0]*2+1,2):
  ans = []
  ans.append(j)
  for i in range(n-1):
    tmp = (a[i] - ans[i]/2)*2
    if tmp >= 0:
      ans.append(int(tmp))
    else:
      break
  if (ans[0] + ans[n-1])/2 == a[n-1]:
    for i in ans:
      print(i,end=' ')
    sys.exit()

Submission status: Runtime Error

Solution code:
import sys
n = int(input())
a = list(map(int,input().split()))
tmp = 0
for j in range(a[0]*2+1):
  ans = []
  ans.append(j)
  for i in range(n-1):
    tmp = (a[i] - ans[i]/2)*2
    if tmp >= 0:
      ans.append(int(tmp))
    else:
      break
  if (ans[0] + ans[n-1])/2 == a[n-1]:
    for i in ans:
      print(i,end=' ')
    sys.exit()

Submission status: Runtime Error

Solution code:
#from heapq import nsmallest as hp
l,r = map(int,input().split())
tmp = 2019**2
tmp2 = 0
for i in range(l,r+1):
  
  for j in range(i+1,r+1):
    tmp = min(tmp,i*j%2019)
    
  if tmp == 0:
    break

print(tmp)

Submission status: Runtime Error

Solution code:
n=int(input())
a=list(map(int, input().split()))
r=[0]*n

# 平滑化
for i in range(n):
    a1,a2,a3=a[i-1], a[i], a[(i+1)%n]
    if a2 > a1:
        r[i+1]+=(a2-a1)*2
        a[i]-=(a2-a1)
        a[i+1]-=(a2-a1)
    if a2 > a3:
        r[i]+=(a2-a3)*2
        a[i]-=(a2-a3)
        a[i-1]-=(a2-a3)

b=max(a)
print(" ".join(list(map(lambda x: str(x+b), r))))

Submission status: Runtime Error

Solution code:
import math # 階乗:factorial 切り上げ:ceil 切り捨て:floor
from operator import itemgetter as ig
from collections import defaultdict as dd
# 定数
INF = math.inf
MOD = int(1e9 + 7)

def main():
    N = int(input())
    A = tuple(map(int, input().split()))

    x = sum(A[::2]) - sum(A[1::2])
    r = [x]
    for n in range(N - 1):
        r += [A[n] * 2 - r[-1]]
    print(*r)

main()

Submission status: Runtime Error

Solution code:
import numpy as np
n = int(input())
*A, = map(int, input().split())
A = np.array(A)
B = np.identity(n)
B += np.roll(B, -1, 0)
print(*map(int, np.linalg.solve(B, 2*A)))

Submission status: Runtime Error

Solution code:
import numpy as np

def rain_volume(A, N):
    X = [0]*N
    X[0] = sum(A)
    for i, a in enumerate(A):
        if i%2 != 0:
            X[0] -= 2*a
    for i, a in enumerate(A):
        if i != 0:
            X[i] = 2*A[i] - X[i-1]
    return X

if __name__ == '__main__':
    N = int(input())
    A = deque(map(int, input().split(' ')))

    print(' '.join(map(str, rain_volume(A, N))))

Submission status: Runtime Error

Solution code:
import numpy as np

N=int(input())
Rain = np.array(list(map(int,input().split())))
Rain = np.reshape(Rain,(N,1))

n1 = np.ones(N)
n2 = np.ones(N-1)


a = np.diag(n1)
print('u')
"""
b = np.diag(n2,k=1)


c = a+b


c[N-1][0] = 1
d = 0.5 * c

ans = np.linalg.solve(d,Rain)
for i in ans:
    print(int(i[0]),end=' ')
"""

Submission status: Runtime Error

Solution code:
import numpy as np

N=int(input())
Rain = np.array(list(map(int,input().split())))
Rain = np.reshape(Rain,(N,1))

n1 = np.ones(N)
n2 = np.ones(N-1)


a = np.diag(n1)
b = np.diag(n2,k=1)
print('u')
"""
c = a+b


c[N-1][0] = 1
d = 0.5 * c

ans = np.linalg.solve(d,Rain)
for i in ans:
    print(int(i[0]),end=' ')
"""

Submission status: Runtime Error

Solution code:
import numpy as np

N=int(input())
Rain = np.array(list(map(int,input().split())))
Rain = np.reshape(Rain,(N,1))

n1 = np.ones(N)
n2 = np.ones(N-1)


a = np.diag(n1)
b = np.diag(n2,k=1)
c = a+b
print('u')
"""
c[N-1][0] = 1
d = 0.5 * c

ans = np.linalg.solve(d,Rain)
for i in ans:
    print(int(i[0]),end=' ')
"""

Submission status: Runtime Error

Solution code:
import numpy as np

N=int(input())
Rain = np.array(list(map(int,input().split())))
Rain = np.reshape(Rain,(N,1))

n1 = np.ones(N)
n2 = np.ones(N-1)
a = np.diag(n1)
b = np.diag(n2,k=1)
c = a+b
c[N-1][0] = 1
d = 0.5 * c

ans = np.linalg.solve(d,Rain)
print('u')
#for i in ans:
#    print(int(i[0]),end=' ')

Submission status: Runtime Error

Solution code:
import numpy as np
 
N=int(input())
Rain = np.array(list(map(int,input().split())))
Rain = np.reshape(Rain,(N,1))
 
n1 = np.ones(N)
n2 = np.ones(N-1)
a = np.diag(n1)
b = np.diag(n2,k=1)
c = a+b
c[N-1][0] = 1
d = 0.5 * c
 
ans = np.linalg.solve(d,Rain)
for i in ans:
    print(int(i[0]),end=" ")

Submission status: Runtime Error

Solution code:
import numpy as np

N=int(input())
Rain = np.array(list(map(int,input().split())))
Rain = np.reshape(Rain,(N,1))

n1 = np.ones(N)
n2 = np.ones(N-1)
a = np.diag(n1)
b = np.diag(n2,k=1)
c = a+b
c[N-1][0] = 1
d = 0.5 * c

ans = np.linalg.solve(d,Rain)
for i in ans:
    print(int(i[0]),end=" ")

Submission status: Runtime Error

Solution code:
N = int(input())
x = list(map(int, input().split()))
y = [0] * N

odd = sum([n for i, n in enumerate(shifted_x) if i % 2 == 1])
even = sum([n for i, n in enumerate(shifted_x) if i % 2 == 0])
y[0] = even - odd

for i in range(N-1):
  y[i+1] = 2 * x[1] - y[i]


str_y = map(str, y)
output = " ".join(str_y)
print(output)

Submission status: Runtime Error

Solution code:
import numpy as np

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

if N == 1:
  print (sum(A))
else:
  C = np.zeros((N, N))

  for i in range(N-1):
    C[i][i] = 0.5
    C[i+1][i] = 0.5

  C[0][N-1] = 0.5
  C[N-1][N-1] = 0.5

  Cin = np.linalg.inv(C)
  B = np.dot(A , Cin)

  print (' '.join(map(lambda x: str(int(x)),B)))

Submission status: Runtime Error

Solution code:
import numpy as np

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

a = np.eye(N, k=0)+np.eye(N, k=1) 
a[N-1,0]=1

inv = np.linalg.inv(a)
A = np.array(A)

ans = 2*np.dot(inv, A)
ans = list(np.array(ans, dtype="int"))

ans=[str(a) for a in ans]
ans=" ".join(ans)
print(ans)