peterverebics/CodeNet_Python_428 huggingface dataset:
# Judge status: Wrong Answer
def Is_cyc(x):
  s = str(x)
  for i in range(len(s)):
    if s[i] != s[-i-1]:
      return False
  return True

def main():
  a,b = map(int,input().split())
  ans = 0
  for i in range(a,b+1):
    if Is_cyc(i):
      ans += 1
  print(ans)
# Judge status: Accepted
n,k = map(int,input().split())
r,s,p = map(int,input().split())
t = list(input())

win = {"r":"p","s":"r","p":"s"}
point = {"r":r,"s":s,"p":p}

ans = []
sum = 0

for i in range(k):
    ans.append(win[t[i]])
    sum+=point[win[t[i]]]

for i in range(k,n):
    if win[t[i]] == ans[i - k]:
        ans.append(-1)
    else:
        ans.append(win[t[i]])
        sum+=point[win[t[i]]]
print(sum)
# Judge status: Accepted
def solve(n, arr):
    ans_arr = [0]
    for i in range(0, n-1):
        if arr[i] > arr[i + 1]:
            diff = arr[i] - arr[i + 1]
            ans_arr.append(diff)
            arr[i + 1] += diff
        else:
            ans_arr.append(0)
    return sum(ans_arr)

if __name__ == "__main__":
    n = int(input())
    arr = list(map(int, input().split(' ')))
    print(solve(n, arr))
# Judge status: Wrong Answer
alf = {c:i for i,c in enumerate('abcdefghijklmnopqrstuvwxyz')}
a = 'abcdefghijklmnopqrstuvwxyz'
s = input()
k = int(input())
diff = [26-alf[c] for c in s]
diff[0] = 0
ans = []
for i in range(len(s)):
    if k >= diff[i]:
        ans.append('a')
        k -= diff[i]
    else:
        ans.append(s[i])
    # print(ans,k)
if k > 0:
    ans[-1] = a[(alf[ans[-1]] + k % 26)]
print(''.join(ans))
# Judge status: Accepted
from sys import stdin, stdout


def main() -> None:
    line = int(stdin.readline())
    x = line * 800
    tmp = line / 15
    y = int(tmp) * 200
    rta = x - y
    print(rta)


main()
# Judge status: Wrong Answer
n = int(input())

l0 = 2
l1 = 1
ans = 0
for i in range(n - 1):
    ans = l0 + l1
    l0 = l1
    l1 = ans

print(ans)
# Judge status: Wrong Answer
s = "101"
s = list(map(int, (s[0] + s[2])))
print(sum(s))
# Judge status: Accepted
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
def input(): return sys.stdin.readline().rstrip()

def main():
    N,R=map(int,input().split())
    print(R+100*max(0,(10-N)))

if __name__ == '__main__':
    main()
# Judge status: Accepted
A,B,C,D=map(int, input().split())
if A<C:
  if C<B:
    if D<B:
      print(D-C)
    else:
      print(B-C)
  else:
    print(0)
else:
  if A<D:
    if B<D:
      print(B-A)
    else:
      print(D-A)
  else:
    print(0)
# Judge status: Accepted
h, n = map(int, input().split())
a = []
b = []
for i in range(n):
    a_, b_ = map(int, input().split())
    a.append(a_)
    b.append(b_)

dp = [float("inf")] * (h + 10010)
dp[0] = 0

for i in range(h + 1):
    for j in range(n):
        dp[i + a[j]] = min(dp[i + a[j]], dp[i] + b[j])
print(min(dp[h:]))
# Judge status: Wrong Answer
##かっこいい実装
import numpy as np
#mod = 10**9+7
#n = int(input())
#a = np.fromstring(input(), dtype = np.int64, sep = ' ')
#
#result = 0
#for i in range(60):
#    count_one = int((a&1).sum())
#    result += count_one*(n-count_one)*(2**i)
#    a >>= 1
#print(result%mod)

N = int(input())
A = np.fromstring(input(),dtype = np.int64, sep = ' ')
Large = 10**9 + 7
ans = 0
for i in range(60):
    sum1 = np.sum(A&1)
    ans += sum1*(N-sum1) * pow(2,i,Large)
    ans %= Large
    A>>=1 # A = A>>1とする
print(ans)
# Judge status: Accepted
#!/usr/bin/env python3
import sys


def main():
    N, M = map(int, input().split())
    red = [0] * N
    red[0] = 1
    num = [1] * N

    for i in range(M):
        x, y = map(int, input().split())
        x -= 1
        y -= 1
        if red[x]:
            red[y] = 1
            
        num[x] -= 1
        num[y] += 1
        if num[x] == 0:
            red[x] = 0
    print(sum(red))

if __name__ == '__main__':
    main()
# Judge status: Accepted
s = set(list(input()))
if any(s==set(list(cand)) for cand in ['NS','EW','NEWS']):
    print('Yes')
else:
    print('No')
# Judge status: Wrong Answer
import sys
N , K = map(int,input().split())
x = list(map(int,input().split()))
m = 2* 10**8
for i in range(N - K + 1):
  r = N - i - 1
  l = N - i - K
  s1 = abs(x[r]) + abs(x[r] - x[l])
  s2 = abs(x[l]) + abs(x[r] - x[l])
  s = min([s1,s2])
  if s<m:
    m = s
print(m)
# Judge status: Accepted
from bisect import *
N = int(input())
T, A = map(int, input().split())
H = []
for i, h in enumerate(map(int, input().split())):
    H.append((T-h*0.006, i))
H.sort()
H2 = [h for h, _ in H]
i = bisect_left(H2,A)
if i==N:
    print(H[-1][1]+1)
elif abs(H[i-1][0]-A) > abs(H[i][0]-A):
    print(H[i][1]+1)
else:
    print(H[i-1][1]+1)
# Judge status: Accepted
import math
r = int(input())
p = math.pi
a = p * (r * 2)
print(a)
# Judge status: Wrong Answer
a, b = map(int, input().split())

if abs(a - b) <= 1:
  print(max(a,b)*2-1)
elif a - b == 0:
  print(a*2)
else:
  print(a*2-1)
# Judge status: Accepted
N = int(input())
L = list(map(int, input().split()))
L.sort()
result = 0
for x in range(N):
    z = x + 2
    for y in range(x+1, N):
        while z < N and L[x] + L[y] > L[z]:
            z += 1
        result += z - y - 1
print(result)
# Judge status: Accepted
s=input()

if s[0] == s[1] or s[1] == s[2] or s[2] == s[3]:
    print("Bad")
else:
    print("Good")
# Judge status: Wrong Answer
A,B,C =map(int,input().split())
print(C-A+B)
# Judge status: Wrong Answer
s = input()

ans = 'Nad'
for i in range(len(s)-1):
    if s[i] == s[i+1]:
        ans = 'Good'
        break
print(ans)
# Judge status: Wrong Answer
# import numpy as np
import sys, math
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial, gcd
from bisect import bisect_left, bisect_right

sys.setrecursionlimit(10 ** 7)
enu = enumerate
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline()[:-1]
pl = lambda x: print(*x, sep="\n")

S = list(input())
T = list(input())

S.sort()
T.sort(reverse=True)
for s, t in zip(S, T):
    if ord(s) < ord(t):
        print("Yes")
        exit()
else:
    print("No")
# Judge status: Accepted
from bisect import bisect_left
N = int(input())
L = list(map(int, input().split()))
L.sort()
ans = 0
for i in range(N):
  for j in range(i+1, N):
    A = L[i] + L[j]
    highbound = bisect_left(L, A)
    ans += highbound - j - 1    
print(ans)
# Judge status: Wrong Answer
N,A,B=map(int, input().split())
#最小がA　最大がB　その区間でN個
if A>B:
    print(0)
    exit()
elif N==1 and A!=B:
    print(0)
    exit()
MAX=A+B*(N-1)
MIN=B+A*(N-1)
print(MAX, MIN)
print(MAX-MIN+1)
# Judge status: Wrong Answer
import math
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a
def lcm(x, y):
    return (x * y) // gcd(x, y)
 
N = int(input())
T = [int(input()) for _ in range(N)]
if N == 1:
    print(T[0])
    exit()
 
ans = lcm(T[0] , T[1])
# Judge status: Wrong Answer
a = list(map(int, input().split()))
count = 0

if (a[1] - a[0]) % a[2] != 0:
  count = 0
elif (a[1] - a[0]) != 0 & a[2] == 1:
  count = a[1]
else:
  for i in range(a[1] + 1):
    if i % a[2] == 0:
      count += 1
  
  for j in range(a[0] + 1):
    if j % a[2] == 0:
      count -= 1

print(count)
# Judge status: Accepted
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

def main():
    a,b=map(int,input().split())
    if a*b%2:
        print('Odd')
    else:
        print('Even')

if __name__ == '__main__':
    main()
# Judge status: Accepted
n=input()

abc = n.split(" ")

a=abc[0]
b=abc[1]
c=abc[2]

print(c + " " + a + " " + b)
# Judge status: Accepted
import sys
stdin = sys.stdin
mod = 10**9 + 7

def ns(): return stdin.readline().rstrip()
def ni(): return int(ns())
def na(): return list(map(int, stdin.readline().split()))


n, a, b = na()
sum_min = a * (n-1) + b
sum_max = a + (n-1) * b

if n == 0 and a != b:
    print(0)
else:
    print(max(0, sum_max - sum_min + 1))
# Judge status: Accepted
a,b =map(int,input().split())
cnt =b-a+1

if a <0 and b>0 or a==0 or b==0:
    ans = "Zero"
elif (a>0 and b>0) or(a<0 and b<0 and cnt%2==0) :
    ans="Positive"
    
elif(a<0 and b<0 and cnt%2!=0):
    ans="Negative"
    
print(ans)
# Judge status: Accepted
n = int(input())

lst = [2, 1]
for i in range(100):
    lst.append(lst[-1]+lst[-2])
print(lst[n])
# Judge status: Accepted
S=lambda:input()
I=lambda:int(input())
L=lambda:list(map(int,input().split()))
LS=lambda:list(map(str,input().split()))

n,a,b=L()
s=S()
passed=0
rankbyb=0
for i in range(n):
    if s[i]=='b':
        rankbyb+=1
        
    if s[i]=='a' and passed<a+b:
        print('Yes')
        passed+=1
    elif s[i]=='b' and passed<a+b and rankbyb<=b:
        print('Yes')
        passed+=1
    else:
        print('No')
# Judge status: Accepted
N = [int(c) for c in input()]
dp = 0,1
for n in N:
  a = min(dp[0]+n,dp[1]+10-n)
  b = min(dp[0]+n+1,dp[1]+10-(n+1))
  dp = a,b
print(dp[0])
# Judge status: Wrong Answer
s = list(input())
s.append("a")
for i in range(len(s)):
    if s[i] == "?" and s[i+1] == "?":
        if s[i-1] == "P":
            s[i] = "D"
        else:
            s[i] = "P"

    elif s[i] == "?":
        if s[i-1] == "P":
            s[i] = "D"
        elif s[i+1] == "D":
            s[i] = "P"
print(*s[:-1],sep="")
# Judge status: Wrong Answer
r,g,b = map(int,input().split())
number = r*100 + g*10 + b
print("YES" if number%4==0 else "N0" )
# Judge status: Accepted
n = int(input())
s = list(input())

if n % 2 == 0 and s[0:n//2] == s[n//2:]:
    print("Yes")
else:
    print("No")
# Judge status: Accepted
s,t = input().split()
a,b = map(int,input().split())
u = input()
print(a-1, b) if u == s else print(a, b-1)
# Judge status: Accepted
n = int(input())
s = []
for i in range(n):
    s.append(input())

m = int(input())
t = []
for i in range(m):
    t.append(input())

money = []
for i in range(n):
    money.append(s.count(s[i]) - t.count(s[i]))
    
print(max(max(money), 0))
# Judge status: Wrong Answer
N,A,B = [ int(i) for i in input().split() ]
S = input()

passCount = 0
overseaPassCount = 1
for k,v in enumerate(S):
  if v == "c":
    print("No")
  elif v == "b":
    print("Yes" if passCount<A+B and overseaPassCount<=B else "No")
    overseaPassCount += 1
    passCount += 1
  elif v == "a":
    print("Yes" if passCount<A+B else "No")
    passCount += 1
  else :
    None
# Judge status: Wrong Answer
a, b, c = map(int, input().split())
if a+b==c or b+c==a or c+a==b:
	print("YES")
else:
    print("NO")
# Judge status: Accepted
x,a,b = map(int,input().split())
if b-a<=0:
    print('delicious')
elif 0<b-a<=x:
    print('safe')
else:
    print('dangerous')
# Judge status: Accepted
n, m = map(int, input().split())
req = [list(map(int, input().split())) for _ in range(m)]
for i in range(1000):
    num = str(i)
    if len(num) != n:
        continue
    ok = True
    for s, c in req:
        if int(num[s - 1]) != int(c):
            ok = False
    if ok:
        print(num)
        exit()
print(-1)
# Judge status: Accepted
S=input()
W=[0]*(len(S)+1)
W[0]=1
words=['dream','dreamer','erase','eraser' ]
for i in range(len(S)):
  if W[i]==0:
    continue
  for k in words:
    if S[i:i+len(k)]==k:
      W[i+len(k)]=1
if W[len(S)]==1:
  print("YES")
  exit()
else:
  print("NO")
# Judge status: Wrong Answer
X,Y = map(int,input().split())

if X==Y:
    print(-1)
else:
    for i in range(10**18):
        X1 = int(X*i+1)
        if X1 % Y != 0:
            print(str(X1))
            break
# Judge status: Accepted
X, Y, Z = map(int, input().split())
X -= Z
print(X//(Y+Z))
# Judge status: Wrong Answer
table = list(map(int, input()))
diff_nagomi = 1000
for i in range(len(table)-2):
    diff = abs(table[i] * 100 + table[i + 1] * 10 + table[i + 2] - 753)
    if diff_nagomi > diff:
        ans = diff
print(ans)
# Judge status: Accepted
n, y = map(int,input().split())
 
for i in range(0,n+1):
  for j in range(0, n-i+1):
    if y == 10000*i + 5000*j + 1000*(n-i-j):
      print("{0} {1} {2}".format(i, j, n-i-j))
      exit()
print("-1 -1 -1")
# Judge status: Accepted
def actual(n, P):
    count = 0

    for i in range(1, n - 1):
        a, b, c = P[i - 1], P[i], P[i + 1]

        if (a < b < c) or (a > b > c):
            count += 1

    return count

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

print(actual(n, P))
# Judge status: Accepted
x,y,z = map(int, input().split())

n = 1
while x >= (n+1)*z + n*y:
  n += 1
print(n-1)
# Judge status: Wrong Answer
S = list(input())
before = 0
last_upper = 0
count = 0
answer = 0
for i, s in enumerate(S):
  # print(answer, i, before, last_upper)
  if s == '<':
    if before < 0 and last_upper < i-1:
      answer += abs(before)*(i-last_upper)
      before = 0
    elif before > 0 and last_upper < i-1:
      answer -= before*(i-last_upper-1)
      before = 0
    before += 1
    answer += before
    last_upper = i
  else:
    before -= 1
    answer += before
# print(answer, last_upper)
if before < 0:
  answer += abs(before)*(len(S)-last_upper)
elif before > 0:
  answer -= before*(len(S)-last_upper-1)
print(answer)
# Judge status: Wrong Answer
def resolve():
    x = int(input())
    ans = 8
    low = 400
    for s in range(401, 2000):
        if s == low+200:
            low = s
            ans -= 1
        if x == s:
            break
    print(ans)
resolve()
# Judge status: Accepted
s = list(input())
a = s.count('0')
b = s.count('1')
print(2*min(a,b))
# Judge status: Accepted
x,y = map(int,input().split())
cnt = 0
cur = x
while(cur<=y):
    cur = cur *2
    cnt += 1
print(cnt)
# Judge status: Accepted
a = [list(map(int,input().split())) for i in range(3)]
n = int(input())
b = [int(input()) for j in range (n)]
ans = "No"
for k in range (n):
  for l in range(3):
    for m in range(3):
      if a[l][m] == b[k]:
        a[l][m] = 0
for o in range(3):
  if a[o][0] == a[o][1] == a[o][2] or a[0][o] == a[1][o] == a[2][o]:
    ans = "Yes"
if a[0][0] == a[1][1] == a[2][2] or a[2][0] == a[1][1] == a[0][2]:
  ans = "Yes"
print(ans)
# Judge status: Wrong Answer
a,b=map(float, input().split())
ans=(a*b)//1
print(int(ans))
# Judge status: Accepted
n = int(input())
l = list(map(int, input().split()))

ans = 0

for i in range(n):
    for j in range(i+1,n):
        for k in range(j+1,n):
            if l[i]==l[j] or l[j]==l[k] or l[k]==l[i]:
                ans+=0
            elif abs(l[i]-l[j])<l[k] and l[k]<l[i]+l[j]:
                ans+=1

print(ans)
# Judge status: Accepted
N,K = map(int,input().split())

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

for i in range(N-K):
    if A[i] < A[i+K]:
        print("Yes")
    else:
        print("No")
# Judge status: Accepted
x=[];y=[]
for _ in range(int(input())):
  a,b=map(int,input().split())
  x.append(a-b);y.append(a+b)
print(max(max(x)-min(x),max(y)-min(y)))
# Judge status: Accepted
import math as mt
N,M=list(map(int,input().split()))
if N==M:
  print(1)
  exit()
L=list(map(int,input().split()))
Z=L[0:M]
S=L[::-1]
A=S[0:M]
if len(L)%2==0:
  print(mt.floor((N-M)//(M-1))+2)
else:
  if min(L) in A or min(L) in Z:
    print(mt.floor((N-M)//(M-1))+2)
  else:
    print(mt.floor((N-M)//(M-1))+1)
# Judge status: Wrong Answer
N = int(input())
numMap = {}
answer = 0
def StartEnd(x):
    start = str(x)[0]
    end = str(x)[-1]
    return int(start), int(end)

for i in range(1, N+1):
    print('numMap:', numMap)
    pair = StartEnd(i)
    if pair in numMap:
        numMap[pair] += 1
    else:
        numMap[pair] = 1

for i in range(1, N+1):
    key = StartEnd(i)
    rev = key[::-1]
    print('rev:', rev)
    if rev in numMap:
        answer += numMap[rev]
    
print(answer)
# Judge status: Wrong Answer
import numpy as np

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

neg = np.count_nonzero(A < 0)
zero = int(0 in A)

# 負の数が奇数個のときは全部正の数にできない。sum( abs(A) ) - min(abs(A))
# 負の数が偶数個の時 or ０があるときはできる。

if zero > 0 or (neg % 2) == 0:
    ans = sum(abs(A))
else:
    ans = sum(abs(A)) - min(abs(A))
    # print(S, idx, A[idx], res)

print(ans)
# Judge status: Accepted
N = int(input())
C = list(input())
l = 0
r = N-1
ans = 0
while (r-l) > 0:
    if C[l] == "W" and C[r] == "R":
        C[l], C[r] = C[r], C[l]
        l += 1
        r -= 1
        ans += 1
        continue
    if C[l] == "R":
        l += 1
    if C[r] == "W":
        r -= 1
print(ans)
# Judge status: Accepted
from heapq import heappop, heappush
N, K = map(int, input().split())
AB = []

cnt = 0
for i in range(N):
  a, b = map(int, input().split())
  heappush(AB, (a, b))


while AB:
  a, b = heappop(AB)
  cnt += b
  
  if K <= cnt:
    print(a)
    exit()
# Judge status: Accepted
import sys
input = sys.stdin.readline
S = list(input())[: -1]
for l in range(len(S)):
  for r in range(l, len(S)):
    t = S[: l] + S[r: ]
    if "".join(t) == "keyence":
      print("YES")
      exit(0)
print("NO")
# Judge status: Wrong Answer
a=int(input())
b=[input() for i in range(a)]
print((len(b)-(len(b)-len(set(b)))*2))
# Judge status: Accepted
N,K=map(int,input().split())
S=input()
newS = S[:K-1]+S[K-1].lower()+S[K:]
print(newS)
# Judge status: Wrong Answer
N,X = map(int,input().split())
x = list(map(int,input().split()))
x.append(X)
x.sort()
d = float("inf")
for i in range(N):
    d = min(d,abs(x[i]-x[i+1]))
print(d)
# Judge status: Accepted
a = int(input())
als = [0]*(100000)
for i in range(0,10**6+2):
    als[a] = 1
    if a%2 == 0:
        a = a//2
    else:
        a = 3*a+1
    if als[a] == 1:
        print(i+2)
        exit()
# Judge status: Accepted
#!/usr/bin/env python3
import itertools
n = int(input())
l = list(map(int, input().split()))

ans = 0
for i in itertools.combinations(l, 3):
    i = sorted(list(i))
    # print(i)
    if i[0] == i[1] or i[1] == i[2]:
        continue
    if i[0]+i[1] > i[2]:
        # print(i)
        ans += 1

print(ans)
# Judge status: Wrong Answer
a,b,c = map(int,input().split())
print("YES" if a>=c and a<=b else "NO")
# Judge status: Wrong Answer
N = int(input())
ABC = []
for _ in range(N):
    ABC.append(list(map(int, input().split())))

table = [[0]*3 for i in range(N)]


for i in range(0, N):# i日目
    if i == 0:
        table[i] = ABC[i]
    else:
        for j in range(3): #a,b,c
            table[i][j] = max(
                [table[i-1][j1] + ABC[i][j1] for j1 in range(3) if  j1 != j]
                 )
        # print(table)
        
print(max(table[-1]))
# Judge status: Accepted
n = int(input())
s = input()

ans = s.count("R") * s.count("G") * s.count("B")

for i in range(n-2):
    si = s[i]
    for j in range(i+1, i+(n-i-1)//2+1):
        sj = s[j]
        k = 2*j-i
        if k < n and s[k] != si and s[k] != sj and si != sj:
            ans -= 1

print(ans)
# Judge status: Accepted
li = list(map(int,input().split()))
total = 100*li[0] + 10*li[1]+li[2]
print("YES" if total % 4 == 0 else "NO")
# Judge status: Wrong Answer
def main():
    n = int(input())
    if n == 1:
        print(1)
        return 
    a = [list(input().split()) for i in range(n)]
    s = sorted(a, key=lambda x:(x[0],-int(x[1])))
    for i in a:
        print(s.index(i)+1)

if __name__ == '__main__':
    main()
# Judge status: Accepted
S = input()
T = input()

if len(set(S)) != len(set(T)):
    print("No")
    exit()
else:
    for i in range(len(S)):
        if S.index(S[i]) != T.index(T[i]):
            print("No")
            #print(S.index(S[i]), T.index(T[i]))
            exit()
print("Yes")
# Judge status: Accepted
import sys

input = sys.stdin.readline


def main():
    a, b, c, d = map(int, input().split())

    ab = abs(a - b) <= d
    bc = abs(b - c) <= d
    ca = abs(c - a) <= d
    if ca or (ab and bc):
        ans = "Yes"
    else:
        ans = "No"

    print(ans)


if __name__ == "__main__":
    main()
# Judge status: Accepted
n = int(input())
a = n%10

if a == 3:
    print('bon')
elif str(a) in '0168':
    print('pon')
else:
    print('hon')
# Judge status: Accepted
from math import sqrt
n = int(input())
sqn_int = int(sqrt(n))
a = [0] * n
for x in range(1, 1 + sqn_int):
    for y in range(1, 1 + sqn_int):
        for z in range(1, 1 + sqn_int):
            left = x**2 + y**2 + z**2 + x*y + y*z + z*x
            if left <= n:
                a[left - 1] += 1
for i in a[:n]:
    print(i)
# Judge status: Accepted
A, B, C = map(int, input().split())
for i in range(A, B * A + 1, A) :
    if i % B == C :
        print("YES")
        exit()
    if i == B * A :
        print("NO")
# Judge status: Accepted
import math
n, m = map(int, input().split())

if abs(n-m)>1:
  print(0)
elif n-m==1:
  print(int((math.factorial(n)*math.factorial(m))%(10**9+7)))
elif m-n==1:
  print(int((math.factorial(m)*math.factorial(n))%(10**9+7)))
elif n==m:
  print(int((math.factorial(n)*math.factorial(m)*2)%(10**9+7)))
# Judge status: Accepted
import sys
from itertools import accumulate

input = sys.stdin.readline


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

    cumsum_A = list(accumulate(A))
    sum_A = sum(A)

    ans = float("inf")
    for i in range(N - 1):
        cost = abs((sum_A - cumsum_A[i]) - cumsum_A[i])
        if cost < ans:
            ans = cost

    print(ans)


if __name__ == "__main__":
    main()
# Judge status: Wrong Answer
X, Y, A, B, C = [int(i) for i in input().split()]
P = [int(i) for i in input().split()]
Q = [int(i) for i in input().split()]
R = [int(i) for i in input().split()]

P = sorted(P)
Q = sorted(Q)
R = sorted(R)

 
A= P[:X] + Q[:Y] + R
A = sorted(A)
print(sum(A[:X+Y]))
# Judge status: Accepted
n = int(input())
a = list(map(int, input().split()))

a.sort()

tmp_val = 0
pair_val = 0
for i in range(n-1, -1, -1):
  if tmp_val == a[i]:
    if pair_val != 0:
      print(pair_val * a[i])
      exit()
    else:
      pair_val = a[i]
      tmp_val = 0
  else:
    tmp_val = a[i]

print(0)
# Judge status: Accepted
import sys,math,collections,itertools
input = sys.stdin.readline

N,K=list(map(int,input().split()))
R,S,P=list(map(int,input().split()))
T = input().rstrip()
s =T.replace('r','P') #P
ss=s.replace('s','R') #R
sss=ss.replace('p','S') #S
sl = list(sss)

for i in range(K,N):
    if sl[i]==sl[i-K]:
        sl[i] = '0'

sc = collections.Counter(sl)

print(sc['R']*R + sc['P']*P + sc['S']*S)
# Judge status: Accepted
n = int(input())
h = [int(x) for x in input().split()]
ans = 0
count = 0
for i in range(n-1):
    if h[i]>=h[i+1]:
        count += 1
    else:
        ans = max(ans,count)
        count = 0
else:
    ans = max(ans,count)
print(ans)
# Judge status: Accepted
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)
 
p = int(readline())
if p % 2 == 1:
    print(0)
else:
    p //= 2
    ans = 0
    while p:
        p //= 5
        ans += p
    print(ans)
# Judge status: Wrong Answer
N,K=map(int,input().split())
S=input()
e=(S[0]=='L')+(S[-1]=='R')
i=S.count("RL")
c=max(i-K,0)*2+max(e-max(K-i,0),0)

print(N-c)
# Judge status: Accepted
a, b = map(int, input().split())
if a in range(1, 10) and b in range(1, 10):
  print(a * b)
else:
  print(-1)
# Judge status: Wrong Answer
A, B, C = map(int, input().split())

if B > A * C:
  print(C)
elif A * C > B and B > A:
  print(A)
else:
  print(0)
# Judge status: Accepted
A=int(input())
B=int(input())
C=int(input())
X=int(input())
s=0
for i in range(A+1):
  x=X-500*i
  if x<0: break
  for t in range(B+1):
    if x<0: break
    elif 50*C>=x:
      s+=1
      x-=100
    else: x-=100
print(s)
# Judge status: Accepted
import math  
def findNumberOfDigits(n, b): 
    dig = (math.floor(math.log(n) /math.log(b)) + 1) 
    return dig
n, k = map(int, input().strip().split())
print(findNumberOfDigits(n, k))
# Judge status: Wrong Answer
a, b, x = map(int, input().split())

if (b-a+1) % x == 0:
    ans = (b-a+1) // x
elif a % x == 0 or b % x == 0:
    ans = (b-a+1) // x + 1
else:
    ans = (b-a+1) // x

print(ans)
# Judge status: Wrong Answer
import sys
n=int(input())
a=list(map(int,input().split()))
g=0
k=0
i=set(a)
if len(i)==1:
  print(a[0])
  sys.exit()
j=0
while g*k==0 and j<n:
  if a[j] % 2==0:
    g=1
  else:
    k=1
  j+=1

if k==0:
  print(2)
else:
  print(1)
# Judge status: Accepted
n, m = map(int, input().split())

l = [[] for i in range(n)]
for _ in range(m):
    a, b = map(int, input().split())
    l[a-1].append(b)
    l[b-1].append(a)
    
for i in range(n):
    print(len(l[i]))