Harryxun/stf_run huggingface dataset:
import itertools as it
import collections as col
import heapq as hq
import sys
import copy as cp
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

N = int(input())
A = [0] + list(map(int, input().split())) + [0]
B = cp.deepcopy(A)
C = cp.deepcopy(A)
for i in range(1, len(A)):
    B[i] = B[i-1] + abs(A[i]-A[i-1])
for i in range(len(A)-2, -1, step=-1):
    C[i] = C[i+1] + abs(A[i]-A[i+1])
for i in range(1, N+1):
    print(B[i-1] + C[i+1] + abs(A[i-1]-A[i+1]))


### FIXED CODE ###

import itertools as it
import collections as col
import heapq as hq
import sys
import copy as cp
sys.setrecursionlimit(10**9)
input = sys.stdin.readline


def dump(*objects):
    print(*objects, file=sys.stderr)


N = int(input())
A = [0] + list(map(int, input().split())) + [0]
# dump(N, A)
B = cp.deepcopy(A)
C = cp.deepcopy(A)
for i in range(1, len(A)):
    # dump(i)
    B[i] = B[i-1] + abs(A[i]-A[i-1])
for i in range(len(A)-2, -1, step=-1):
    # dump(i)
    C[i] = C[i+1] + abs(A[i]-A[i+1])
# dump(A, B, C)
for i in range(1, N+1):
    # dump(i, B[i-1] + B[N+1] - B[i+1] + abs(A[i-1]-A[i+1]))
    print(B[i-1] + C[i+1] + abs(A[i-1]-A[i+1]))

exit(0)
import math
from collections import Counter


N = int(input())
points = [tuple(map(int, input().split())) for _ in range(N)]
vecs = {}
counter = Counter()

for i, p in enumerate(points):
    for j in range(i, N):
        if j == i:
            continue
        q = points[j]
        a = min(p, q)
        b = max(p, q)
        dx = b[0] - a[0]
        dy = b[1] - a[1]
        gcd = math.gcd(dx, dy)
        if gcd != 0:
            dx //= gcd
            dy //= gcd
        vecs[(i, j)] = (dx, dy)
        counter[(dx, dy)] += 1

vec, _ = counter.most_common()[0]
dx, dy = vec
visited = set()
cost = 0

for i, p in enumerate(points):
    if i in visited:
        continue
    cost += 1
    for j in range(i, N):
        if j == i:
            continue
        if vecs[(i, j)] == (dx, dy):
            visited.add(j)

print(cost)


### FIXED CODE ###

from collections import Counter


def main():
    N = int(input())
    points = [tuple(map(int, input().split())) for _ in range(N)]
    counter = Counter()

    if N == 1:
        print(1)
        return

    for i in range(N):
        for j in range(N):
            if j == i:
                continue
            a = points[i]
            b = points[j]
            dx = b[0] - a[0]
            dy = b[1] - a[1]
            counter[(dx, dy)] += 1

    vec, _ = counter.most_common()[0]
    dx, dy = vec
    visited = set()
    pointset = set(points)
    cost = 0

    for p in points:
        if p in visited:
            continue
        visited.add(p)
        x, y = p
        cost += 1

        i = 1
        while True:
            n = (x + i * dx, y + i * dy)
            i += 1
            if n in pointset:
                visited.add(n)
            else:
                break
        i = 1
        while True:
            n = (x - i * dx, y - i * dy)
            i += 1
            if n in pointset:
                visited.add(n)
            else:
                break

    print(cost)


main()
N = int(input())
A = list(map(int,input().split()))
S = []
T = []
for i in range(1,N+1):
    S.append(i+A[i-1])
    T.append(i-A[i-1])

L = [0]*max(S)
for i in range(N):
    L[S[i]-1]+=1

out = 0
for i in range(N):
    if (T[i]-1>=0)and(len(L)-1>=T[i]-1):
        out += L[T[i]-1]
        if T[i]==S[i]:
            out += -1
print(out)

### FIXED CODE ###

N = int(input())
A = list(map(int,input().split()))
S = []
T = []
for i in range(1,N+1):
    S.append(i+A[i-1])
    T.append(i-A[i-1])

L = []
for i in range(N):
    L.append(S[i]-1)

from collections import Counter
M = Counter(L)
out = 0
for i in range(N):
    if (T[i]-1>=0)and(len(L)-1>=T[i]-1):
        out += M[T[i]-1]
        if T[i]==S[i]:
            out += -1
print(out)
import sys,queue,copy
sys.setrecursionlimit(10**8)
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())


def frog(i, now_cost):
    if dp[i][now_cost] != 10**5:
        dp[i][now_cost] = min(dp[i][now_cost], now_cost)
    else:
        dp[i][now_cost] = now_cost
        if i+1 < N:
            frog(i+1,now_cost+abs(hlist[i+1]-hlist[i]))
        if i+2 < N:
            frog(i+2,now_cost+abs(hlist[i+2]-hlist[i]))


N = int(input())
hlist = inpl()
dp=list()
for _ in range(N):
    dp.append([10 ** 5] * sum(hlist))

frog(0,0)

print(min(dp[N-1]))



### FIXED CODE ###

import sys,queue,copy
sys.setrecursionlimit(10**8)
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())
INF = float('inf')

N = int(input())

hlist = inpl()

dp = [INF]*N

for i in range(N):
    if i == 0 :
        dp[i] = 0
    elif i < 2:
        dp[i] = dp[i-1]+abs(hlist[i]-hlist[i-1])
    elif i < N:
        dp[i] = min(dp[i-1]+abs(hlist[i]-hlist[i-1]),dp[i-2]+abs(hlist[i]-hlist[i-2]))

print(dp[N-1])
N=int(input())
l=[]
for x in range(0,N):
    l.append(input())
for x in range(0,N):
    l[x]=sorted(list(l[x]))
l=sorted[l]
x=0
y=0
for i in range(0,N):
    for j in range(i+1,N):
        if l[i]==l[j]:
            x=x+1
        else:
            y=y+sum(range(1,x+1))
            i=i+x+1
            break
print(y)

### FIXED CODE ###

N=int(input())
l=[]
for x in range(0,N):
    l.append(input())
for x in range(N):
    k=list(l[x])
    k.sort()
    k=''.join(k)
    l[x]=k
l.sort()
k=1
ans=0
for i in range(N-1):
    if l[i]==l[i+1]:
        k+=1
    else:
        ans+=k*(k-1)//2
        k=1
ans+=k*(k-1)//2
print(ans)
while True:
  h,w=map(int,input().split())
  for i in range(h):
    if h==w==0:
      break
    else:
      print("#"*w)



### FIXED CODE ###

while True:
    H, W = list(map(int, input().split()))
    if H == W == 0:
        break
    for i in range(H):
        print("#" * W)
    print()
all_match = [2,5,5,4,5,6,3,7,6]

n,m = map(int,input().split())
a = list(map(int,input().split()))
a.sort(reverse=True)
match = []
for num in a:
    match.append(all_match[num-1])

dp = [-10**7 for i in range(n+1)] #桁数
dp[0] = 0

for i in range(1,n+1):
    possible = []
    for honsu in match:
        if i >= honsu:
            possible.append(dp[i-honsu] + 1)
    if len(possible)>0:
        dp[i] = max(possible)

length = dp[n]
ans = 0
now = n
for i in range(length):
    for j in range(m):
        if dp[now-match[j]] == dp[now]-1:
            ans += a[j]*10**(length-i-1)
            now -= match[j]
            break

print(ans)

### FIXED CODE ###

all_match = [2,5,5,4,5,6,3,7,6]

n,m = map(int,input().split())
a = list(map(int,input().split()))
a.sort(reverse=True)
match = []
for num in a:
    match.append(all_match[num-1])

dp = [-10**7 for i in range(n+1)] #桁数
dp[0] = 0

for i in range(1,n+1):
    possible = []
    for honsu in match:
        if i >= honsu:
            possible.append(dp[i-honsu] + 1)
    if len(possible)>0:
        dp[i] = max(possible)

length = dp[n]
ans = 0
now = n
for i in range(length):
    for j in range(m):
        if now >= match[j]:
            if dp[now-match[j]] == dp[now]-1:
                ans += a[j]*10**(length-i-1)
                now -= match[j]
                break

print(ans)
#!/usr/bin/env python3
import sys

def dfs(idx, visited, conn, d, cur):
    visited[idx] = True
    for nex in conn[idx]:
        if not visited[nex[0]]:
            d[nex[0]] = cur + nex[1]
            d = dfs(nex[0], visited, conn, d, cur + nex[1])
    return d


def solve(N: int, A: "List[int]", B: "List[int]", C: "List[int]", Q: int, K: int, x: "List[int]", y: "List[int]"):

    conn = [[] for _ in range(N)]
    for j in range(N - 1):
        a = A[j] - 1
        b = B[j] - 1
        conn[a].append([b, C[j]])
        conn[b].append([a, C[j]])
    visited = [False] * N
    d = [0] * N
    d = dfs(K - 1, visited, conn, d, 0)
    for q in range(Q):
        s = x[q] - 1
        t = y[q] - 1
        ret = d[s] + d[t]
        print(ret)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    a = [int()] * (N-1)  # type: "List[int]" 
    b = [int()] * (N-1)  # type: "List[int]" 
    c = [int()] * (N-1)  # type: "List[int]" 
    for i in range(N-1):
        a[i] = int(next(tokens))
        b[i] = int(next(tokens))
        c[i] = int(next(tokens))
    Q = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    x = [int()] * (Q)  # type: "List[int]" 
    y = [int()] * (Q)  # type: "List[int]" 
    for i in range(Q):
        x[i] = int(next(tokens))
        y[i] = int(next(tokens))
    solve(N, a, b, c, Q, K, x, y)

if __name__ == '__main__':
    main()


### FIXED CODE ###

#!/usr/bin/env python3
import sys

sys.setrecursionlimit(300000)

def dfs(idx, visited, conn, d, cur):
    visited[idx] = True
    for nex in conn[idx]:
        if not visited[nex[0]]:
            d[nex[0]] = cur + nex[1]
            d = dfs(nex[0], visited, conn, d, cur + nex[1])
    return d


def solve(N: int, A: "List[int]", B: "List[int]", C: "List[int]", Q: int, K: int, x: "List[int]", y: "List[int]"):

    conn = [[] for _ in range(N)]
    for j in range(N - 1):
        a = A[j] - 1
        b = B[j] - 1
        conn[a].append([b, C[j]])
        conn[b].append([a, C[j]])
    visited = [False] * N
    d = [0] * N
    d = dfs(K - 1, visited, conn, d, 0)
    for q in range(Q):
        s = x[q] - 1
        t = y[q] - 1
        ret = d[s] + d[t]
        print(ret)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    a = [int()] * (N-1)  # type: "List[int]" 
    b = [int()] * (N-1)  # type: "List[int]" 
    c = [int()] * (N-1)  # type: "List[int]" 
    for i in range(N-1):
        a[i] = int(next(tokens))
        b[i] = int(next(tokens))
        c[i] = int(next(tokens))
    Q = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    x = [int()] * (Q)  # type: "List[int]" 
    y = [int()] * (Q)  # type: "List[int]" 
    for i in range(Q):
        x[i] = int(next(tokens))
        y[i] = int(next(tokens))
    solve(N, a, b, c, Q, K, x, y)

if __name__ == '__main__':
    main()
shio = string(raw_input())
counter = 0
for i in 2:
  if shio[i] == "1":
    counter +=1
print(counter)

### FIXED CODE ###

shio = str(raw_input())
counter = 0
i=0
while i < 3:
  if shio[i] == "1":
    counter +=1
  i +=1
print(counter)
n=int(input())
k=100000000000000000000000000000000000000000
for i in range(n):
  j=0
  a=int(input())
  while a%2==0:
    a=a/2
    j+=1
  k=min(j,k)
  
print(k)


### FIXED CODE ###

n=int(input())
k=10000000000000000000000000000000000000000
a=list(map(int,input().split()))
for i in range(n):
  j=0
  while a[i]%2==0:
    a[i]=a[i]/2
    j+=1
  k=min(j,k)
  
print(k)
import sys
sys.recursionlimit(10**5)

N,u,v=map(int,input().split())

du,dv=[0]*-~N,[0]*-~N
T=[list() for i in range(-~N)]

def dfs(p,t,v,d):
  d[v]=t
  for i in T[v]:
    if i!=p:
      dfs(v,t+1,i,d)

for i in range(N-1):
  a,b=map(int,input().split())
  T[a].append(b)
  T[b].append(a)

dfs(0,0,u,du)
dfs(0,0,v,dv)

c=0
for i in range(1,-~N):
  if len(T[i])==1 and i!=v:
    if du[i]<dv[i]:
      c=max(c,~-dv[i])

print(c)


### FIXED CODE ###

import sys
sys.setrecursionlimit(10**5)
N,u,v=map(int,input().split())

du,dv=[0]*-~N,[0]*-~N
T=[list() for i in range(-~N)]

def dfs(p,t,v,d):
  d[v]=t
  for i in T[v]:
    if i!=p:
      dfs(v,t+1,i,d)

for i in range(N-1):
  a,b=map(int,input().split())
  T[a].append(b)
  T[b].append(a)

dfs(0,0,u,du)
dfs(0,0,v,dv)

c=0
for i in range(1,-~N):
  if len(T[i])==1 and i!=v:
    if du[i]<dv[i]:
      c=max(c,~-dv[i])

print(c)
n, k = map(int, input().split())

pow2 = [1]
for i in range(1, k):
    pow2.append(pow2[i-1]*2)
win = 0
for i in range(1, n+1):
    for j, x in enumerate(pow2):
        if x > k/i:
            index = j
            break
    win += pow(1/2, index)
print(win/n)

### FIXED CODE ###

n, k = map(int, input().split())
win = 0
for i in range(1, n+1):
    index = 0
    while pow(2, index) < k/i:
        index += 1
    win += pow(0.5, index)/n
print(win)
import math
data = list(map(int,input().split()))
a = data[0]
b = data[1]
x = data[2]

c = a*a*b/2
d = a*a*b-x
if d=0:
  print(0)
else:
  if x>c:
    e = ((d/a)*2)/a
    t = a/e
    print(90-math.degrees(math.atan(t)))
  else:
    f = ((x/a)*2)/b
    t = f/b
    print(90-math.degrees(math.atan(t)))

### FIXED CODE ###

import math
data = list(map(int,input().split()))
a = data[0]
b = data[1]
x = data[2]

c = a*a*b/2
d = a*a*b-x
if d==0:
  print(0)
else:
  if x>c:
    e = ((d/a)*2)/a
    t = a/e
    print(90-math.degrees(math.atan(t)))
  else:
    f = ((x/a)*2)/b
    t = f/b
    print(90-math.degrees(math.atan(t)))
import math
from functools import reduce

def main():

    N,X= map(int,input().split())
    targetList = list(map(int,input().split()))
    targetList.append(X)
    targetList.sort()
    diffList = []

    if N !=1:

        for i in range(N-1):
            diffList.append(targetList[i+1] - targetList[i])
    else:
        print(abs(targetList[0]-targetList[1]))
        exit()


    print(reduce(math.gcd,diffList))

        
    
if __name__== "__main__":
    main() 


### FIXED CODE ###

import fractions
from functools import reduce

def main():

    N,X= map(int,input().split())
    targetList = list(map(int,input().split()))
    targetList.append(X)
    targetList.sort()
    diffList = []

    if N > 2:
        for i in range(N-1):
            diffList.append(targetList[i+1] - targetList[i])

    elif N==2:
        for i in targetList:
            diffList.append(i)
    else:
        print(abs(targetList[0]-targetList[1]))
        exit()

    print(reduce(fractions.gcd,diffList))

        
    
if __name__== "__main__":
    main()
X = input().split()
N = int(X[0])
M = int(X[1])
sc = []
 
 #リストscの[偶数]には桁、[奇数]には数字
for r in range(M):
  sc += input().split()

#scをint化
insect = [int(i) for i in sc]

k = 1
for r in range(N-1):
	k *= 10 
	ans = -1
#10^N以下について調べる
for r in range(k, k*10, 1):
	U = list(str(r))
	t = 0
	for s in range(M):
		if U[insect[2*s]-1] == str(insect[2*s+1]):
			t += 1
	if t == M:
		ans = r
		break
if(M==0):
	print("0")
else:
	print(ans)

### FIXED CODE ###

X = input().split()
N = int(X[0])
M = int(X[1])
sc = []
 
 #リストscの[偶数]には桁、[奇数]には数字
for r in range(M):
  sc += input().split()

#scをint化
insect = [int(i) for i in sc]

#ループ開始の数字を10^(N-1)にセット
k = 1
for r in range(N-1):
	k = k*10

l = 10*k
ans = -1

if k == 1:
	k = 0
	
#k～10*k - 1について
for r in range(k, l, 1):

	#１文字ずつ見たいのでとりあえずリスト化
	U = list(str(r))
	t = 0

	#左から●番目の文字が▲と一致していれば t をインクリメント
	for s in range(M):
		if U[insect[2*s]-1] == str(insect[2*s+1]):
			t += 1
	#tが条件の数と一致したらansにそのときのrを代入し、ループから抜ける
	if t == M:
		ans = r
		break



#そのときのansの値を出力

print(ans)
n = int(input())
for s in range(1,10) :
    if n <= s*1000 :
       x = s*1000 - n 
       break()
print(x)

### FIXED CODE ###

n = int(input())
 
if n % 1000 == 0 :
    a = n / 1000
else :
    a = int(n / 1000 + 1)
 
b = a * 1000
answer = int(b - n)
 
print(answer)
num=int(input())
fig=list(map(int,input().split()))
 
Even_flag=0
count=0
 
while Even_flag=0:
  for i in range(num):
    if fig[num]%2==1:
      Even_flag==1:
      break
    else:
      fig[num]=fing[num]/2
      if i==num-1:
        count+=1
  
print(count)

### FIXED CODE ###

num=int(input())
fig=list(map(int,input().split()))
 
Even_flag=0
count=0
 
while Even_flag==0:
  for i in range(num):
    if fig[i]%2==1:
      Even_flag=1
      break
    else:
      fig[i]=fig[i]/2
      if i==num-1:
        count+=1
        
print(count)
def calc_inverse_polish_notation_string(s):
    tokens = [token for token in s.split(' ') if token != '']
    stack = []
    for token in tokens:
        if token in ['+', '-', '*', '/']:
            val2 = stack.pop()
            val1 = stack.pop()
            result = eval("%s %s %s" % (val1, token, val2))
            stack.append(result)
        else:
            stack.append(token)

    return stack[0]  # if len(stack) != 1, it should throw an exception


def main():
    for line in sys.stdin.readlines():
        print(calc_inverse_polish_notation_string(line))

if __name__ == "__main__":
    main()

### FIXED CODE ###

import sys


def calc_inverse_polish_notation_string(s):
    tokens = [token for token in s.split(' ') if token != '']
    stack = []
    for token in tokens:
        if token in ['+', '-', '*', '/']:
            val2 = stack.pop()
            val1 = stack.pop()
            result = eval("%s %s %s" % (val1, token, val2))
            stack.append(result)
        else:
            stack.append(token)

    return stack[0]  # if len(stack) != 1, it should throw an exception


def main():
    for line in sys.stdin.readlines():
        print(calc_inverse_polish_notation_string(line.strip()))

if __name__ == "__main__":
    main()
N = input()
p = []
max = 0
for i in range(N):
  p.append(int(input()))
  if(p[i]>max):
    maxi = i
sum = 0
for i in range(N):
  if(i == maxi):
    sum += p[i]/2
  else:
    sum += p[i]
print(sum)

### FIXED CODE ###

N = int(input())
p = []
max = 0
for i in range(N):
  p.append(int(input()))
p.sort()
sum = 0
for i in range(N-1):
  sum += p[i]
sum += p[N-1]/2
print(int(sum))
import itertools

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

D=list(range(1,N+1))
dict=[]

for i,j in enumerate(itertools.permutations(D)):
    P,Q,j=[*P],[*Q],[*j]
    if j==P:
        p=i
    if j==Q:
        q=i
print(abs(p-q))

### FIXED CODE ###

import itertools

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

D=list(range(1,N+1))
dict=[]

for i,j in enumerate(itertools.permutations(D)):
    j=list(j)
    if j==P:
        p=i
    if j==Q:
        q=i
print(abs(p-q))
N,K=map(int,input().split())
S=input()
if S[K-1]=A:
  S[K-1]=a
if S[K-1]=B:
  S[K-1]=b
else:
  S[K-1]=c
print(S)

### FIXED CODE ###

N,K=map(int,input().split())
S=input()
print(S[:K-1]+S[K-1].lower()+S[K:N+1])
import sys

dict = {}
l = []
line = map(lambda x: x.split(), sys.stdin.readlines())
s = ""
for (c, arg) in line:
    if c == "insert":
        dict[arg] = 0
    elif c == "find":
        if arg in dict:
            s += "yes\n"
        else:
            s += "no\n"
print(s, end="")

### FIXED CODE ###

n = int(input())
dic = set()

for i in range(n):
    o = input().split()
    if o[0] == 'insert':
        dic.add(o[1])
    elif o[1] in dic:
        print('yes')
    else:
        print('no')
# import itertools
# import pprint
from collections import deque

gem,ope = map(int,input().split())
vlist = deque(map(int,input().split()))

ans = 0

for l in range(ope+1):
  for r in range(ope-l+1):
    if l+r>ope:
      break

    x   = ope-l-r
    now = []
    deq = vlist.copy() 

    for i in range(l):
      now.append(deq.popleft())
    for j in range(r):
      now.append(deq.pop())
    for k in range(x):
      if now==[]:
        break
      if min(now)<0:
        now.remove(min(now))
    
    if ans<sum(now):
      ans = sum(now)

print(ans)

### FIXED CODE ###

# import itertools
# import pprint
import copy
from collections import deque

gem,ope = map(int,input().split())
vlist = deque(map(int,input().split()))

ans = 0

for l in range(ope+1):
  for r in range(ope-l+1):
    if l+r>ope or l+r>gem:
      break

    x   = ope-l-r
    now = []
    deq = copy.copy(vlist) 

    for i in range(l):
      now.append(deq.popleft())
    for j in range(r):
      now.append(deq.pop())
    for k in range(x):
      if now==[]:
        break
      if min(now)<0:
        now.remove(min(now))
    
    if ans<sum(now):
      ans = sum(now)

print(ans)
n = int(input())
g = [[] for _ in range(n)]

for _ in range(n-1):
    u,v,w = map(int,input().split())
    g[u-1].append((v-1,w))
    g[v-1].append((u-1,w))
    
ans = [0] * n

def dfs(v,p,c):
    ans[v] = c
    for i in g[v]:
        if i[0] != p:
            if i[1] % 2 ==0:
                dfs(i[0],v,c)
            else:
                dfs(i[0],v,1-c)

dfs(0,-1,0)

for i in ans:
    print(i)

### FIXED CODE ###

import sys
sys.setrecursionlimit(10**7)
n = int(input())
g = [[] for _ in range(n)]

for _ in range(n-1):
    u,v,w = map(int,input().split())
    g[u-1].append((v-1,w))
    g[v-1].append((u-1,w))
    
ans = [0] * n

def dfs(v,p,c):
    ans[v] = c
    for i in g[v]:
        if i[0] != p:
            if i[1] % 2 ==0:
                dfs(i[0],v,c)
            else:
                dfs(i[0],v,1-c)

dfs(0,-1,0)

for i in ans:
    print(i)
s = input()
ans = 0
if s == 'RSR':
  ans == 1
else:
  for i in s:
  if i == 'R':
    ans +=1

print(ans)

### FIXED CODE ###

s = input()

if 'RRR' in s:
  print(3)
elif 'RR' in s:
  print(2)
elif 'R' in s:
  print(1)
else:
  print(0)
def f(a,p1,p2):
    if p1>p2:
        return 0
   
    return max(a[p1]+min(f(a,p1+2,p2),f(a,p1+1,p2-1))
                      ,a[p2]+min(f(a,p1+1,p2-1),f(a,p1,p2-2)))
n=int(input())
a=list(map(int,input().split()))
s=sum(a)
p1=0
p2=n-1
first=f(a,n,0,p1,p2,2)
print(first-(s-first))
                             


### FIXED CODE ###

def f(a,i,j,dp):
    if dp[i][j]==-1:
        if i>j:
            return 0

        dp[i][j]=max(a[i]+min(f(a,i+2,j,dp),f(a,i+1,j-1,dp)),
                                a[j]+min(f(a,i+1,j-1,dp),f(a,i,j-2,dp)))
    return dp[i][j]
        
n=int(input())
dp=[[-1 for i in range(n)] for j in range(n)]
a=list(map(int,input().split()))
for i in range(n):
    dp[i][i]=a[i]

for i in range(n-1):
    dp[i][i+1]=max(a[i],a[i+1])

s1=f(a,0,n-1,dp)

print(s1-sum(a)+s1)
def f(x):
    if x == 1:
        return 1
    return x + f(x - 1)

a, b = map(int, input().split())
x = b - a
ans = f(x) - b

print(ans)

### FIXED CODE ###

a, b = map(int, input().split())
n = b - a

ans = 0
for i in range(1, n + 1):
    ans += i
    
print(ans - b)
def canbuy(n):
    if n%7==0 or n%4==0:
        return 'Yes'
    else:
        if n<4:
            return 'No'
        else:
            if canbuy(n-7)=='Yes':
                return 'Yes'
            else:
                if canbuy(n-4)=='Yes':
                    return 'Yes'
                else:
                    return 'No'

n=input()
print(canbuy(n))


### FIXED CODE ###

def canbuy(n):
    for i in range(int(100/7)):
        tmp = n-7*i
        if tmp==0 or (tmp>3 and tmp%4==0):
            return 'Yes'
    return 'No'

n=int(input())
print(canbuy(n))
import bisect
n = int(input())
b = sorted(list(map(int, input().split())))
c = sorted(list(map(int, input().split())))
count = 0
for i in a:
  for j in range(bisect.bisect_right(b, i), n):
    count += n - bisect.bisect_right(c, b[j])

print(count)

### FIXED CODE ###

import bisect
from itertools import accumulate
n = int(input())
A = sorted(list(map(int, input().split())))
B = sorted(list(map(int, input().split())))
C = sorted(list(map(int, input().split())))
ans = 0
b_to_c = [0]*n
for i in range(n):
  b_to_c[i] = n - bisect.bisect_right(C, B[i])
Q = list(accumulate(b_to_c[::-1]))[::-1]
  
for i in A:
  t = bisect.bisect_right(B, i)
  if t < n:
    ans += Q[t]
print(ans)
from numpy import argmax as mode
from numpy import bincount as bc
N = int(input())
V = list(map(int, input().split()))
a = [V[2 * i] for i in range(N // 2)]
b = [V[2 * i + 1] for i in range(N // 2 + N % 2)]
bca = bc(a)
bcb = bc(b)
#print(bca, bcb)
if mode(bca) == mode(bcb):
  print(N - a.count(mode(bca)) - max(sorted(bca)[-2], sorted(bcb)[-2]))
else:
  print(N - a.count(mode(bca)) - b.count(mode(bcb)))

### FIXED CODE ###

from numpy import argmax as mode
from numpy import bincount as bc
N = int(input())
V = list(map(int, input().split()))
a = [V[2 * i] for i in range(N // 2)]
b = [V[2 * i + 1] for i in range(N // 2 + N % 2)]
bca = bc(a)
bcb = bc(b)
#print(bca, bcb)
if mode(bca) == mode(bcb):
  print(N - a.count(mode(bca)) - max(sorted(bca)[-2], sorted(bcb)[-2]))
else:
  print(N - a.count(mode(bca)) - b.count(mode(bcb)))