Harryxun/stf_run huggingface dataset:
import sys
input = sys.stdin.readline

def main():
    N = int(input())
    X = int(input(),2)
    LIST = []
    ANS = [0]*N
    TEMP = [0]*N
    CHAIND = [0]*N
    bit = 1

    cnt = count_ones_by_bitmask(X)
    p = X % (cnt+1)
    m = X % (cnt-1)
    for i in range(N):
        LIST.append(X^bit)
        if LIST[i]!=0:
            ANS[i] = 1
            if (X & bit == 0):
                TEMP[i] = (p + bit % (cnt+1) ) % (cnt+1)
            else:
                TEMP[i] = (m - bit % (cnt-1) ) % (cnt-1)            
        bit = bit<<1





    CHA = list(set(TEMP))

    for i in range(len(CHA)):
        an = 0
        cha = CHA[i]
        cnt = count_ones_by_bitmask(CHA[i])
        while cnt>0:
            an += 1
            cha = cha%cnt
            cnt = count_ones_by_bitmask(cha)
        CHAIND[CHA[i]] = an

    for i in reversed(range(N)):
        print(ANS[i]+CHAIND[TEMP[i]])


def count_ones_by_bitmask(num):
    count = 0
    while num:
        count += num & 1
        num >>= 1
    return count

if __name__ == '__main__':
    main()


### FIXED CODE ###

def main():
    N = int(input())
    X = input()
    XINT = int(X,2)
    ANS = [0]*N
    TEMP = [0]*N
    CHAIND = [0]*N

    cnt = count_ones_by_bitmask(XINT)
    
    if cnt == 0:
        for i in range(N):
            print(1)
            return
    if cnt ==1:
        for i in  range(N):
            if X[i] == '1':
                print(0) #全てが0になる
            else:
                if i==N-1:
                    print((int(X[N-1])+1)%2+1) # 2の剰余の反転
                else:
                    print((int(X[N-1]))%2+1) # 2の剰余
        return

    p = XINT % (cnt+1)
    m = XINT % (cnt-1)
    pmod = 1
    mmod = 1
    for i in range(N):
        ANS[i] = 1
        if (X[N-i-1] == '0'):
            TEMP[i] = (p + pmod) % (cnt+1)
        else:
            TEMP[i] = (m - mmod) % (cnt-1)
        pmod = (pmod*2) % (cnt+1)
        mmod = (mmod*2) % (cnt-1)


    CHA = list(set(TEMP))

    for i in range(len(CHA)):
        an = 0
        cha = CHA[i]
        cnt = count_ones_by_bitmask(CHA[i])
        while cnt>0:
            an += 1
            cha = cha%cnt
            cnt = count_ones_by_bitmask(cha)
        CHAIND[CHA[i]] = an

    for i in reversed(range(N)):
        print(ANS[i]+CHAIND[TEMP[i]])


def count_ones_by_bitmask(num):
    count = 0
    while num:
        count += num & 1
        num >>= 1
    return count

if __name__ == '__main__':
    main()
a=input()
c=len(a)
d=c-7
for i in range(8):
  if a[:i]+a[-(7-i):]=="keyence" or a[:i]=="keyence" or a[-(7-i):]=="keyence":
    print("YES")
    sys.exit()
print("NO")

### FIXED CODE ###

S=input()
if S=="keyence":
  print("YES")
  exit()
for i in range(7):
  T=S[:i]+S[len(S)-7+i:]
  if T=="keyence":
    print("YES")
    exit()
print("NO")
D, T, S = map(int(),input().split())
print('YES') if T * S >= D else print('No') 

### FIXED CODE ###

D, T, S = map(int,input().split())
print('Yes') if T * S >= D else print('No')
a = list(input())
b = []
for i,j in enumerate(a):
    if j == str("0"):
        b += str("0")
    elif j == str("1"):
        b += str("1")
    elif j == str("B"):
        if a[0] == str("B"):
            pass
        else:
            del b[i-1]
        
print("".join(b))

### FIXED CODE ###

a = list(input())
b = []
for i,j in enumerate(a):
    if j == str("0"):
        b += str("0")
    elif j == str("1"):
        b += str("1")
    elif j == str("B"):
        if not b:
            pass
        else:
            del b[len(b)-1]
        
print("".join(b))
def countSol(coeff, start, end, rhs, a):
	if (rhs == 0):
		return 1
	result = 0
	for I in range(start,end+1):
		if (coeff[I]<=rhs and a[I]>=0):
			a[I]-=1
			result+=countSol(coeff, I, end, rhs - coeff[I],a)
	return result 
A=int(input())
B=int(input())
C=int(input())
X=int(input())
D=[A,B,C]
print(countSol([500,100,50],0,2,X,D))

### FIXED CODE ###

X=int(input())
A=int(input())
B=int(input())
print((X-A)%B)
from collections import deque
def main():
    X, Y, A, B, C = map(int, input().split())
    
    red = deque(sorted(map(int, input().split()), reverse=True))
    green = deque(sorted(map(int, input().split()), reverse=True))
    nocolor = deque(sorted(map(int, input().split()), reverse=True))

    INF = 10 ** 9 + 1
    times = A + B + C - (X + Y)
    for _ in range(times):
        red_num = len(red)
        green_num = len(green)
        nocolor_num = len(nocolor)

        if red_num and red_num + nocolor_num > X:
            r = red[-1]
        else:
            r = INF
        
        if green_num and green_num + nocolor_num > Y:
            g = green[-1]
        else:
            g = INF
        
        if nocolor_num:
            no = nocolor[-1]
        else:
            no = INF
        
        l = [no, r, g]
        idx = l.index(min(l))
        if idx == 0:
            red.pop()
        if idx == 1:
            green.pop()
        if idx == 2:
            nocolor.pop()

    print(sum(red) + sum(green) + sum(nocolor))
        
        

if __name__ == "__main__":
    main()

### FIXED CODE ###

from collections import deque
def main():
    X, Y, A, B, C = map(int, input().split())
    
    apple = []
    red = sorted(map(int, input().split()), reverse=True)[:X]
    green = sorted(map(int, input().split()), reverse=True)[:Y]
    nocolor = list(map(int, input().split()))
    apple.extend(red)
    apple.extend(green)
    apple.extend(nocolor)
    
    print(sum(sorted(apple, reverse=True)[:X+Y]))      
        

if __name__ == "__main__":
    main()
list1 = []
list2 = []

time = 0
for n in range(5):

    list1.append(int(input()))

for n in list1:
    q = n // 10
    mod = n % 10
    time += 10 * q
    if mod != 0:
        time += 10
        list2.append(mod)

time = time - 10 + min(list2)
print int(time)


### FIXED CODE ###

list1 = []
list2 = []

time = 0
for n in range(5):

    list1.append(int(input()))

for n in list1:
    q = n // 10
    mod = n % 10
    time += 10 * q
    if mod != 0:
        time += 10
        list2.append(mod)


if list2 != []:
    time = time - 10 + min(list2)
    print int(time)
else:
    print int(time)
a,b = map(float, raw_input().split())
d = (int) (a/b)
r = (int) (a%b)
f = float (a/b)
print ("{0} {1} {2:6f} .format(d,r,f))

### FIXED CODE ###

a,b = map(float, raw_input().split())
d = (int) (a/b)
r = (int) (a%b)
f = float (a/b)

print("{0} {1} {2:6f}".format(d,r,f))
import sys

N = int(input())

if N % 1000 == 0:
  ans = 0
elif:
  ans = N % 1000
  
print(ans)

### FIXED CODE ###

import sys
N = int(input())

ans = 0
if N % 1000 == 0:
  ans = 0
else:
  ans = 1000 - (N % 1000)

print(ans)
s=input()
ss=s.replace("A","")
print("YES" if ss="KIHBR" and "AA" not in s and "KIH" in s else "NO")

### FIXED CODE ###

s=input()
ss=s.replace("A","")
print("YES" if ss=="KIHBR" and "AA" not in s and "KIH" in s else "NO")
Alice = 'A'
Bob = 'B'
Charlie = 'C'

def answer(Sa, Sb, Sc):
    currentUser = Alice
    ai, bi, ci = (0, 0, 0)
    while(True):
        if currentUser == Alice:
            if ai == len(Sa):
                return Alice
            if Sa[ai] == 'b':
                currentUser = Bob
            if Sa[ai] == 'c':
                currentUser = Charlie
            ai += 1
            continue
        if currentUser == Bob:
            if bi == len(Sb):
                return Bob
            if Sa[bi] == 'a':
                currentUser = Alice
            if Sa[bi] == 'c':
                currentUser = Charlie
            bi += 1
            continue
        if currentUser == Charlie:
            if ci == len(Sc):
                return Charlie
            if Sa[ci] == 'a':
                currentUser = Alice
            if Sa[ci] == 'b':
                currentUser = Bob
            ci += 1
            continue
            
Sa = input()
Sb = input()
Sc = input()
print(answer(Sa, Sb, Sc))

### FIXED CODE ###

Alice = 'A'
Bob = 'B'
Charlie = 'C'

def answer(Sa, Sb, Sc):
    currentUser = Alice
    ai, bi, ci = (0, 0, 0)
    while(True):
        if currentUser == Alice:
            if ai == len(Sa):
                return Alice
            if Sa[ai] == 'b':
                currentUser = Bob
            if Sa[ai] == 'c':
                currentUser = Charlie
            ai += 1
            continue
        if currentUser == Bob:
            if bi == len(Sb):
                return Bob
            if Sb[bi] == 'a':
                currentUser = Alice
            if Sb[bi] == 'c':
                currentUser = Charlie
            bi += 1
            continue
        if currentUser == Charlie:
            if ci == len(Sc):
                return Charlie
            if Sc[ci] == 'a':
                currentUser = Alice
            if Sc[ci] == 'b':
                currentUser = Bob
            ci += 1
            continue
            
Sa = input()
Sb = input()
Sc = input()
print(answer(Sa, Sb, Sc))
N, R = map(int, input().solit())
if N>= 10:
  print(R)
else:
  print(R+1000-100*N)

### FIXED CODE ###

N, R = map(int, input().split())
if N>= 10:
  print(R)
else:
  print(R+1000-100*N)
s = input()
max_re = 0
for i in range(len(s)):
    tar_s = s[i:]
    tar_s = re.search(r'(A|T|C|G)*', tar_s).group()
    max_re = max(max_re, len(tar_s))
print(max_re)

### FIXED CODE ###

import re
s = input()
max_re = 0
for i in range(len(s)):
    tar_s = s[i:]
    tar_s = re.search(r'(A|T|C|G)*', tar_s).group()
    max_re = max(max_re, len(tar_s))
print(max_re)
N = int(input())
flag = 0
for i in range(1,54001):
    if math.floor(i*1.08) == N:
        print(i)
        flag += 1
        break
if flag == 0:
    print(":(")

### FIXED CODE ###

N = int(input())
ans = 0
k = 0
for i in range(N+1):
    if N<=i*1.08<N+1:
        print(int(i))
        ans += 1
        break
if ans == 0:
    print(":(")
a = input()
if a[2]=="2" or a[2] =="4" or a[2] =="5" or a[2] =="7" or a[2] =="9":
  print("hon")
elif a[2] =="3":
  print("bon")
else:
  print("pon")

### FIXED CODE ###

a = int(input())
a %= 10

if a==0 or a==1 or a==6 or a==8:
  print("pon")
elif a==3:
  print("bon")
else:
  print("hon")
def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

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

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

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

ans = 0
for i in range(N-K+1):
    ans += A[-1-i]*cmb(N-1-i, K-1, mod)
    ans %= mod
    ans -= A[i]*cmb(N-1-i, K-1, mod)
    ans %= mod

print(ans)

### FIXED CODE ###

def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

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

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

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

ans = 0
for i in range(N-K+1):
    ans += A[-1-i]*cmb(N-1-i, K-1, mod)
    ans %= mod
    ans -= A[i]*cmb(N-1-i, K-1, mod)
    ans %= mod

print(ans)
N,K = map(int,input().split())
ans = 0
if N == K:
  print(1)
  exit()
for _ in range(N-K):
  ans++
print(ans)

### FIXED CODE ###

N,K=map(int,input().split())
print(N-K+1)
N  = int(input())
A = list(map(int, input().split()))
status = 0 # 0 = defalt, 1 = up, 2 = down
cnt = 1
for i in range(1,N):
    if A[i-1] < A[i]: #up petern
        if status == 0 or status == 1:
            status = 1
        else:
            status = 0
            cnt += 1
    elif A[i-1] > A[i]:
        if status == 0 or status == 2
                status = 2
        else:
            status = 0
            cnt += 1
    else:
        continue
print(cnt)

### FIXED CODE ###

N  = int(input())
A = list(map(int, input().split()))
status = 0 # 0 = defalt, 1 = up, 2 = down
cnt = 1
for i in range(1,N):
    if A[i-1] < A[i]: #up petern
        if status == 0 or status == 1:
            status = 1
        else:
            status = 0
            cnt += 1
    elif A[i-1] > A[i]:
        if status == 0 or status == 2:
            status = 2
        else:
            status = 0
            cnt += 1
    else:
        continue
print(cnt)
N, X = map(int, input().split())

a = [1]
p = [1]
for i in range(1, N+1):
    a.append(2 * a[i-1] + 3)
    p.append(2 * a[i-1] + 1)

print (len(a))
def calc(N, X): #レベルNバーガーの下からX層に含まれるパティの枚数
    if N == 0: #全てパティ
        if X == 0:
            return 0
        else:
            return 1
    if X == 1:
        return 0
    # print (N - 1)
    if 1 <= X <= a[N - 1]:
        # print ('A')
        return calc(N - 1, X - 1)
    if X == 2 + a[N - 1]:
        # print ('B')
        return p[N - 1] + 1
    if 2 +a[N - 1] < X <= 2 + 2 * a[N - 1]:
        # print ('C')
        return p[N - 1] + 1 + calc(N - 1, X - 2 - a[N - 1])
    if X == 3 + 2 * 2 * a[N - 1]:
        # print ('D')
        return 2 * p[N - 1] + 1

print (calc(N, X))

### FIXED CODE ###

N, X = map(int, input().split())

a = [1]
p = [1]
for i in range(1, N+2):
    a.append(2 * a[i-1] + 3)
    p.append(2 * p[i-1] + 1)

def calc(N, X): #レベルNバーガーの下からX層に含まれるパティの枚数
    if N == 0: #全てパティ
        if X == 0:
            return 0
        else:
            return 1
    if X == 1:
        return 0
    # print (N - 1)
    if 1 < X <= 1 + a[N - 1]:
        # print ('A')
        return calc(N - 1, X - 1)
    if X == 2 + a[N - 1]:
        # print ('B')
        return p[N - 1] + 1
    if 2 + a[N - 1] < X <= 2 + 2 * a[N - 1]:
        # print ('C')
        return p[N - 1] + 1 + calc(N - 1, max(X - 2 - a[N - 1], 0))
    if X == 3 + 2 * a[N - 1]:
        # print ('D')
        return p[N]

print (calc(N, X))
a, b, c = input().sprit(" ")
temp = a
a = b
b = temp
temp = a
a = c
c = temp
print("{} {} {}".format(a, b, c)


### FIXED CODE ###

a, b, c = map(int, input().split(" "))
print(c, a, b)
H, W = map(int, input())
h, w = map(int, input())
print((H-h)*(W-w))

### FIXED CODE ###

H, W = map(int, input().split())
h, w = map(int, input().split())


print((H-h)*(W-w))
n = int(input())
a = sorted(list(map(int, input().split())))

import math
def comb(n,r):
  return math.factorial(n) / (math.factorial(r) * math.factorial(n-r))
  
max_comb = [comb(i, i // 2) for i in range(n-1)]

mid_dis = [abs(a[n-1] / 2 - a[i]) for i in range(n-1)]
arg_max_i = [i for i in range(n-1) if mid_dis[i] == min(mid_dis)][0]

print(a[n-1], a[arg_max_i])

### FIXED CODE ###

n = int(input())
a = sorted(list(map(int, input().split())))

import bisect

arg_max_i = bisect.bisect_left(a, a[n-1] // 2)

if abs(a[n-1] / 2 - a[arg_max_i]) > abs(a[n-1] / 2 - a[arg_max_i-1]):
  arg_max_i -= 1
if arg_max_i == n-1:
  arg_max_i -= 1

print(a[n-1], a[arg_max_i])
n = int(input())
s = input()
alphaList  =   ["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"]
moji = ""
for str in s:
    index = alphaList.index(str)
    addNum = 0
    if index == 24:
        addNum = 0
    elif index ==  25:
        addNum = 1
    else:
        addNum = index + n 
    moji = moji + alphaList[addNum]
print(moji)

### FIXED CODE ###

n = int(input())
s = input()
alphaList  =   ["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"]
moji = ""
for str in s:
    index = alphaList.index(str)
    addNum = index + n
    if addNum >25:
        addNum = addNum - 26 
    moji = moji + alphaList[addNum]
print(moji)
n=int(input())
a=0
for i in range(1,int(n**.5)+1):
    if i==n%(n//i-1):
        a+=n//i-1
print(a)

### FIXED CODE ###

n=int(input())
a=0
for i in range(1,int(n**.5+1)):t=n//i-1;a+=t*(t and i==n%t)
print(a)
from math import floor
A,B,N=map(int,input().split())

x=N
result=[]
for x in reversed(range(1,N+1)):
    ans=floor(A*x/B)-A*floor(x/B)
    result.append(ans)
    if len(result) == 1:
        maxr = ans 
    if len(result) > 1 max(result) == maxr:
        pass

print(max(result))


### FIXED CODE ###

from math import floor
A,B,N=map(int,input().split())

x=min(B-1,N)

print(floor(A*x/B)-A*floor(x/B))
A = [list(map(int,input().split())) for _ in range(3)]
n = int(input())
B = [int(input()) for _ in range(n)]

F = [0]*100
for b in B:
  F[b]=1

ans = 'No'  
for i in range(3):
  c = 0
  d = 0
  for j in range(3):    
    c += F[A[i][j]]
    d += F[A[j][i]]
  if c==3 or d==3:
    ans ='Yes'
if F[A[0][0]]+F[A[1][1]]+F[A[2][2]] == 3 or F[A[0][2]]+F[A[1][1]]+F[A[2][0]] == 3:
  ans ='Yes'
  
print(ans)

### FIXED CODE ###

A = [list(map(int,input().split())) for _ in range(3)]
n = int(input())
B = [int(input()) for _ in range(n)]

F = [0]*101
for b in B:
  F[b]=1

ans = 'No'  
for i in range(3):
  c = 0
  d = 0
  for j in range(3):    
    c += F[A[i][j]]
    d += F[A[j][i]]
  if c==3 or d==3:
    ans ='Yes'
if F[A[0][0]]+F[A[1][1]]+F[A[2][2]] == 3 or F[A[0][2]]+F[A[1][1]]+F[A[2][0]] == 3:
  ans ='Yes'
  
print(ans)
N = input()
List = list(map(int,input().split())

N = 7
List = [14,14,2,13,56,2,37]

ans = 10**18
def rally(p):
    n = 0
    for a in range(N):
        n += (p-List[a])**2
    return n

for i in range(1,101):
    ans = min(rally(i),ans)

print(ans)


### FIXED CODE ###

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


ans = 10**18
def rally(p):
    n = 0
    for a in range(N):
        n += (int(p)-List[a])**2
    return n

for i in range(1,101):
    ans = min(rally(i),ans)

print(ans)
a,b = map(int,input().split())
lol = [int(n) for n in input().split()]
lol.sort()
print(sum(lol[:k]))

### FIXED CODE ###

a,b = map(int,input().split())
lol = [int(n) for n in input().split()]
lol.sort()
print(sum(lol[:b]))
import sys
input = sys.stdin.buffer.readline

#sys.setrecursionlimit(10**9)
#from functools import lru_cache

def RD(): return input().rstrip().decode()
def II(): return int(input())
def FI(): return int(input())
def MI(): return map(int,input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int,input().split()))
def LF(): return list(map(float,input().split()))
def TI(): return tuple(map(int,input().split()))
# rstrip().decode()


def main():
	r1,c1,r2,c2=MI()
	m=10**9+7

	ff=[1]

	for i in range(1,10**6+5):
		ff.append(ff[-1]*i%m)


	def f(r,c):
		return (ff[r+c]*pow(ff[r],m-2,m)*pow(ff[c],m-2,m))%m

	ans=0
	ans+=f(r2+1,c2+1)
	ans+=f(r1,c1)
	ans-=f(r2+1,c1)
	ans-=f(r1,c2+1)

	print(ans%m)














if __name__ == "__main__":
	main()


### FIXED CODE ###

import sys
input = sys.stdin.buffer.readline

#sys.setrecursionlimit(10**9)
#from functools import lru_cache

def RD(): return input().rstrip().decode()
def II(): return int(input())
def FI(): return int(input())
def MI(): return map(int,input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int,input().split()))
def LF(): return list(map(float,input().split()))
def TI(): return tuple(map(int,input().split()))
# rstrip().decode()


def main():
	r1,c1,r2,c2=MI()
	m=10**9+7

	ff=[1]

	for i in range(1,2*10**6+5):
		ff.append(ff[-1]*i%m)


	def f(r,c):
		return (ff[r+c]*pow(ff[r],m-2,m)*pow(ff[c],m-2,m))%m

	ans=0
	ans+=f(r2+1,c2+1)
	ans+=f(r1,c1)
	ans-=f(r2+1,c1)
	ans-=f(r1,c2+1)

	print(ans%m)



if __name__ == "__main__":
	main()
n, x, m = map(int, input().split())
mn = min(n, m)
P = [] # (x,pre_sum)
sum_p = 0 # sum of pre + cycle
X = [-1] * m # for cycle check
for i in range(mn):
    if X[x] > -1:
        cyc_len = len(P) - X[x]
        nxt_len = (n - X[x]) % cyc_len
        pre = P[X[x]][1]
        cyc = (sum_p - pre) * ((n - X[x]) // cyc_len)
        nxt = P[X[x]+nxt_len][1] - P[X[x]][1]
        print(pre + cyc + nxt)
        exit()
    P.append([x, sum_p])
    sum_p += x
    X[x] = i
    x = x*x % m
print(sum_p)
n, x, m = map(int, input().split())
mn = min(n, m)
P = [] # (x,pre_sum)
sum_p = 0 # sum of pre + cycle
X = [-1] * m # for cycle check
for i in range(mn):
    if X[x] > -1:
        cyc_len = len(P) - X[x]
        pre = P[X[x]][1]
        cyc = (sum_p - pre) * ((n - X[x]) // cyc_len)
        nxt = P[X[x] + (n - X[x]) % cyc_len][1] - P[X[x]][1]
        print(pre + cyc + nxt)
        exit()
    P.append([x, sum_p])
    sum_p += x
    X[x] = i
    x = x*x % m
print(sum_p)


### FIXED CODE ###

n, x, m = map(int, input().split())
mn = min(n, m)
S = set()
A = []
a = x
ans = 0
for i in range(mn):
    if a in S: break
    S.add(a)
    A.append(a)
    ans += a
    a = a*a%m
    if a == 0:
        print(ans)
        exit()

# print(S)
# print(A)
# print(len(A), n, m)
if len(A) < mn:
    st_len = 0
    while st_len < len(A) and a != A[st_len]: st_len += 1
    st = sum(A[:st_len])
    cyc_sum = sum(A[st_len:])
    cyc_len = len(A) - st_len
    cyc_num = (n - st_len) // cyc_len
    # print('m {} n {} st_len {} cyc_len {} cyc_num {}'.format(m,n,st_len,cyc_len,cyc_num))
    cyc = cyc_sum * cyc_num
    ed_len = (n - st_len) % cyc_len
    ed = sum(A[st_len:][:ed_len])
    print(st + cyc + ed)
else:
    print(ans)
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=' ')
"""


### FIXED CODE ###

N=int(input())
a = list(map(int,input().split()))
S = sum(a)
S1 = 0
for i in range(N):
    if i%2 == 1:
        S1 += a[i]
b = [0 for i in range(N)]
b[0] = S - 2*S1
print(b[0],end=' ')
for j in range(1,N):
    b[j] = 2*a[j-1] - b[j-1]
    print(b[j],end=' ')
import sys
sys.setrecursionlimit(100000)
input=sys.stdin.readline
n,m=map(int,input().split())
l=[1]*n
z=n*(n-1)//2
input()
m-=1
b=[input().split() for _ in range(m)]
c=[0]*m+[z]
def r(s):
  t=l[s]
  if t>0:
    return s
  else:
    l[s]=r(t)
    return l[s]
def f(s):
  return r(int(s)-1)
for i in range(m-1,-1,-1):
  x,y=map(f,b[i])
  if x!=y:
    s,t=l[x],l[y]
    z-=s*t
    if s<t:
      l[x]=-y
      l[y]+=s
    else:
      l[y]=-x
      l[x]+=t
  c[i]=z
for x in c:
  print(x)

### FIXED CODE ###

import sys
sys.setrecursionlimit(100000)
input = sys.stdin.readline
n,m=map(int,input().split())
z=n*(n-1)//2
l=[-1]*n
a=[1]*n
b=[input().split() for _ in range(m)]
c=[0]*m+[z]
def r(s):
  t=l[s]
  if t<0:
    return s
  else:
    l[s]=r(t)
    return l[s]
def f(s):
  return r(int(s)-1)
for i in range(m-1,-1,-1):
  x,y=map(f,b[i])
  if x!=y:
    l[x]=y
    z-=a[x]*a[y]
    a[y]+=a[x]
  c[i]=z
for x in c[1:]:
  print(x)
from collections import deque
N, K = [int(i) for i in input().split()]
h = [int(i) for i in input().split()]

def g(n, k, h):
    gk = deque([0, abs(h[1] - h[0])], k)
    g = gk[1]
    for i in range(2, n):
        h_i = h[i]
        j = max(i - k, 0)
        g = min(abs(h_i - h_j) + h_k for h_j, h_k in zip(h[j:], gk))
        if i >= k:
            gk.popleft()
        gk.append(g)
    return g

print(g(N, K, h))


### FIXED CODE ###

from collections import deque
N, K = [int(i) for i in input().split()]
h = [int(i) for i in input().split()]
def g(n, k, h):
    gk = deque([abs(h[1] - h[0]), 0])
    g = gk[0]
    for i in range(2, n):
        g = min(abs(h[i] - h[i-j]) + gk[j-1] for j in range(1, min(i, k)+1))
        if i >= k:
            gk.pop()
        gk.appendleft(g)
    return g

print(g(N, K, h))
n = int(input())
alist  = list(map(int,input().split()))
list1 = alist[1::2]
list2 = alist[0::2]
from collections import Counter
dic1 = Counter(list1).most_common()
dic2 = Counter(list2).most_common()

if dic1[0][0]!=dic2[0][0]:
  print(n - dic1[0][1] - dic2[0][1]+1)
else:
  print(min(n - dic1[0][1] - dic2[1][1]+1, n -dic1[1][1] - dic2[0][1]+1))

### FIXED CODE ###

n = int(input())
alist  = list(map(int,input().split()))
list1 = alist[1::2]
list2 = alist[0::2]
from collections import Counter
dic1 = Counter(list1).most_common()
dic2 = Counter(list2).most_common()
dic1.append([0,0])
dic2.append([0,0])
if dic1[0][0]!=dic2[0][0]:
  print(n - dic1[0][1] - dic2[0][1])
else:
  print(min(n - dic1[0][1] - dic2[1][1], n -dic1[1][1] - dic2[0][1]))