Harryxun/stf_run huggingface dataset:
import numpy as np
A, B = map(int, input().split())

# ans = A
# for i in range(A+1,B+1,1):
#     ans = ans^i
# print(ans)
# counter = 0

# list = np.zeros(50)
# for i in range(A,B+1,1):
#     list += np.array(list(map(int, str(i))).reverse())
# for i in range(len(list)):
#     list[i] = list[i]%2
# list.reverse()
# print(list)

l = [0]*100
s = ''
for i in range(A,B+1,1):
    bi = bin(i)[2:]
    # print(bi)
    for j in range(1,len(bi)+1):
        if bi[-j] == '1':
            l[j] = (l[j]+1)%2

for i in range(len(l)):
    s = s + str(l[-i])
print(int(s, 2))


### FIXED CODE ###

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

def XOR(A):
    # 0からAまでの排他的論理和を求める
    if A%4 == 0:
        return A
    elif A%4 == 2:
        return A+1
    elif A%4 == 1:
        return 1
    else:
        return 0

fA = XOR(A-1)
fB = XOR(B)
print(fB^fA)
n,k= map(int,(input().split()))
b= input()
LRn=len(re.findall('LR',b))
RLn=len(re.findall('RL',b))

if min(LRn,RLn)>=k:
    ans=k*2
elif min(LRn,RLn)<=k and max(LRn,RLn)>=k:
    ans=k+min(LRn,RLn)
else:
    ans=LRn+RLn

a= list(b)
for i in range(len(a)-1):
    if a[i]==a[i+1]:
        ans +=1

print(ans)

### FIXED CODE ###

import re

n,k= map(int,(input().split()))
b= input()
LRn=len(re.findall('LR',b))
RLn=len(re.findall('RL',b))

if min(LRn,RLn)>=k:
    ans=k*2
elif min(LRn,RLn)<=k and max(LRn,RLn)>=k:
    ans=k+min(LRn,RLn)
else:
    ans=LRn+RLn

a= list(b)
for i in range(len(a)-1):
    if a[i]==a[i+1]:
        ans +=1

print(ans)
import math
N, D = list(map(int, input().split()))
X = []
for i in range(N):
  X.append(list(map(int, input().split())))

count = 0
for a in range(N):
  for b in range(a+1, N):
  sumX = 0
    for c in range(D):
      sumX += (X[a][c]-X[b][c])**2
    if math.sqrt(sumX)%1 == 0:
      count += 1
print(count)

### FIXED CODE ###

import math
N, D = list(map(int, input().split()))
X = []
for i in range(N):
  X.append(list(map(int, input().split())))

count = 0
for a in range(N):
  for b in range(a+1, N):
    sumX = 0
    for c in range(D):
      sumX += (X[a][c]-X[b][c])**2
    if math.sqrt(sumX)%1 == 0:
      count += 1
print(count)
N, W = map(int, input().split())
w = []
v = []
for i in range(N):
	wi, vi = map(int, input().split())
	w.append(wi)
	v.append(vi)

dp = [0] * (W + 1)
dp[w[0]] = v[1]

for i in range(1, N):
	for j in range(W, -1, -1):
		if j - w[i] >= 0 and dp[j - w[i]] + v[i] > dp[j]:
			dp[j] = max(dp[j], dp[j - w[i]] + v[i])
print(max(dp))

### FIXED CODE ###

N,W=map(int,input().split())
wv=[[0,0]]+[list(map(int,input().split())) for _ in range(N)]

dp=[[0 for i in range(W+1)] for j in range(N+1)]

for i in range(1,N+1):
    for j in range(W+1):
        dp[i][j]=dp[i-1][j]
        if j - wv[i][0] >= 0:
            dp[i][j]=max(dp[i][j],dp[i-1][j-wv[i][0]]+wv[i][1])

            
print(max(dp[N]))
a = input()
b = input()

if a>b:
    print(a-1)
else:
    print(a)

### FIXED CODE ###

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

if a>b:
    print(a-1)
else:
    print(a)
n,x=map(int,input().split())
m=[int(input) for _ in range(n)]
m.sort()
num=x-sum(m)
print(n+(num//(min(m))))


### FIXED CODE ###

n,x=map(int,input().split())
m=[int(input()) for _ in range(n)]
m.sort()
num=x-sum(m)
print(n+(num//(min(m))))
s,t=input().split()
if(t[0:-1]==s):
  print("Yes")
else:
  print("No")

### FIXED CODE ###

s=input()
t=input()
if(t[0:-1]==s):
  print("Yes")
else:
  print("No")
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

N, W = map(int, input().split())
items = [list(map(int, input().split())) for _ in range(N)]


def solve():
    dp = [[0]*(W+1) for _ in range(N+1)]

    # init
    # update
    for i in range(1, N+1):
        for w in range(W+1):
            if w-items[i-1][0] >= 0:
                dp[i][w] = max(dp[i-1][w], dp[i-1]
                               [w-items[i-1][0]]+items[i-1][1])
            else:
                dp[i][w] = dp[i-1][w]

    print(max(dp[N]))


def solve2():
    dp = [0]*(W+1)
    for i in range(N):
        for w in reversed(range(W+1)):  # revにしないと、更新済みの値を使って更新しちゃう
            if w-items[i][0] >= 0:
                dp[w] = max(dp[w], dp[w-items[i][0]]+items[i][1])
    print(dp[-1])


solve2()


### FIXED CODE ###

# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

N, W = map(int, input().split())
items = [list(map(int, input().split())) for _ in range(N)]


def solve():
    MaxV = 10**3*N+1
    dp = [[float('inf')]*MaxV for _ in range(N+1)]
    dp[0][0] = 0

    for i in range(1, N+1):
        for v in range(MaxV):
            if items[i-1][1] <= v:
                dp[i][v] = min(dp[i-1][v], dp[i-1]
                               [v-items[i-1][1]]+items[i-1][0])
            else:
                dp[i][v] = dp[i-1][v]
    ans = 0
    for i, v in enumerate(dp[N]):
        if v <= W:
            ans = i

    print(ans)


solve()
import numpy as np
import math
import sys
readline = sys.stdin.buffer.readline
MOD = 10**9+7

N = int(readline())
x = np.array(readline().split(), dtype=np.int64)
# print(N, x)

dif = x[1:] - x[:N-1]
# print(dif)

cnt = np.zeros(N-1, dtype=np.int64)
sm = math.factorial(N-1)
for i in range(N-1):
    if i == 0:
        cnt[i] = sm
        tmp = sm
    else:
        tmp = tmp * i // (i+1)
        cnt[i] = cnt[i-1] + tmp
# print(cnt)

sums = np.mod((dif * cnt), MOD)
# print(sms)
ans = 0
for i in range(N-1):
    ans += sums[i]
    ans %= MOD
print(ans)

### FIXED CODE ###

MOD = 10**9+7

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

ans = 0
mul = 0
for i in range(N-1):
    mul += pow(i+1, MOD-2, MOD)
    ans += (x[i+1] - x[i]) * mul % MOD
    ans %= MOD
for i in range(2, N):
    ans *= i
    ans %= MOD
print(ans)
import bisect

N,K=map(int,input().split())
A=[int(x) for x in input().split()]
A.sort()

def solve(a,K):
  if A[a]>=K:
    return False
  bits=1
  for i in range(len(A)):
    if i!=a:
      bits|= bits<<A[i]
  cnt = (1<<A[a])-1
  bits >>= (K-A[a])
  if bits&cnt:
    return False
  else:
    return True

for i in range(N-1,-1,-1):
  if solve(i,K):
    ans=bisect.bisect_right(A, A[i])
    break
print(ans)

### FIXED CODE ###

N,K=map(int,input().split())
A=[int(x) for x in input().split()]
A.sort(reverse=True)
su=0
ans=0
for a in A:
  if su+a < K:
    su+=a
    ans+=1
  else:
    ans=0
print(ans)
n = int(input())
h = [int(x) for x in input().split()]
memo = [-1]*n

def dp(i):
    if i == 0:
        return 0
    if i < 0:
        return 10**10
    if memo[i] != -1:
        return memo[i]
    if i == 1:
        memo[i] = abs(h[i] - h[i-1])
        return memo[i]
    memo[i] = min(dp(i-1)+abs(h[i]-h[i-1]), dp(i-2)+abs(h[i]-h[i-2]))
    return memo[i]

print(dp(n-1))

### FIXED CODE ###

# importing the sys module 
import sys 
  
# the setrecursionlimit function is 
# used to modify the default recursion 
# limit set by python. Using this,  
# we can increase the recursion limit 
# to satisfy our needs 
  
sys.setrecursionlimit(10**6) 
n = int(input())
h = [int(x) for x in input().split()]
memo = [-1]*n

def dp(i):
    if i == 0:
        return 0
    if i < 0:
        return 10**10
    if memo[i] != -1:
        return memo[i]
    if i == 1:
        memo[i] = abs(h[i] - h[i-1])
        return memo[i]
    memo[i] = min(dp(i-1)+abs(h[i]-h[i-1]), dp(i-2)+abs(h[i]-h[i-2]))
    return memo[i]

print(dp(n-1))
import math

K = int(input())

sum = 0
for a in range(1, K+1):
    for b in range(1, K+1):
        n = math.gcd(a, b)
        for c in range(1, K+1):
            sum += np.gcd(n, c)
print(sum)

### FIXED CODE ###

from math import gcd

k = int(input())
ans = 0
for a in range(1,k+1):
    for b in range(1,k+1):
        p = gcd(a,b)
        for c in range(1,k+1):
            ans += gcd(p,c)
print(ans)
N = int(input())
X = list(map(int, input().split()))

ans = 100000
for i in range(100):
  s = 0
  for j in range(N):
    s += (X[i]-i)**2
    
  ans = min(ans, s)
  
print(ans)

### FIXED CODE ###

N = int(input())
X = list(map(int, input().split()))
 
ans = 10000000000
for i in range(100):
  s = 0
  for j in range(N):
    s += (X[j]-i)**2
    
  ans = min(ans, s)
  
print(ans)
S = int(input())
if S[0] == S[1] or S[1] == S[2] or S[2] == S[3]:
    print('Bad')

else:
    print('Good')

### FIXED CODE ###

S = input()
if S[0] == S[1] or S[1] == S[2] or S[2] == S[3]:
    print('Bad')

else:
    print('Good')
if input() in 'qwertyuiopasdfghjklzxcvbnm':
  print 'a'
else:
  print 'A'

### FIXED CODE ###

if input() in 'qwertyuiopasdfghjklzxcvbnm':
  print('a')
else:
  print('A')
s = input()
c = ''
for t in s:
  if t == '0' or t == '1':
    c += t
  elif t == 'B':
    if c != '':
      k = c[-1]
      c -= k
print(c)


### FIXED CODE ###

s = input()
l = []
for t in s:
  if t == '0' or t == '1':
    l.append(t)
  elif t == 'B':
    if l != []:
      l.pop()
for r in l:
  print(r, end='')
import numpy as np
n,m,k=map(int,input().split())
a=list(map(int, input().split()))
b=list(map(int, input().split()))
A=np.cumsum(np.array(a))
B=np.cumsum(np.array(b))
ans=0
t=0
i=0 #a
j=0 #b
while t<=k:
    if i<n and A[i]<B[j]:
        t+=a[i]
        i+=1
    elif j<m:
        t+=b[j]
        j+=1
    else:
        break
    if t<=k:
        ans+=1
print(ans)


### FIXED CODE ###

import numpy as np
import bisect
n,m,k=map(int,input().split())
a=list(map(int, input().split()))
b=list(map(int, input().split()))
A=np.cumsum(np.array([0]+a))
B=np.cumsum(np.array(b))
ans=0
for i in range(n+1):
    if A[i]>k:
        break
    t=k-A[i]
    tmp=bisect.bisect_right(B,t)
    ans=max(ans, i+tmp)
print(ans)
import math
N, D = [int(i) for i in input().split()]
print(math.ceil(N / ((2 * D) + 1)

### FIXED CODE ###

import math

N, D = [int(i) for i in input().split()]
print(math.ceil(N / ((2 * D) + 1)))
n,d = map(int, input().split())
x = [[0 for x in range(2)] for y in range(3)]

for i in range(n):
    x[i] = list(map(int, input().split()))

cnt = 0
for i in itertools.combinations(x, 2):
    y = i[0]
    z = i[1]
    res = 0
    for j in range(d):
        res +=(y[j]-z[j])**2

    res = math.sqrt(res)
    if res.is_integer():
        cnt+=1

print (cnt)


### FIXED CODE ###

import itertools
import math
 
n,d = map(int, input().split())
x = [[0 for x in range(d)] for y in range(n)]

for i in range(n):
    x[i] = list(map(int, input().split()))

cnt = 0
for i in itertools.combinations(x, 2):
    y = i[0]
    z = i[1]
    res = 0
    for j in range(d):
        res +=(y[j]-z[j])**2

    res = math.sqrt(res)
    if res.is_integer():
        cnt+=1

print (cnt)
n=int(input())
s=input()
c=[]
cnt=1
for i in range(n-1):
    if s[i] = s[i+1]:
        cnt += 1
    else:
        c.append(cnt)
        cnt=1
if s[n-2]==s[n-1]:
    c.append(cnt)
else:
    c.append(1)
print(min(c))


### FIXED CODE ###

n=int(input())
s=input()
c=s[1:].count('E')
a=c
for i in range(1,n):
    if s[i-1]=='W':
        c+=1
    if s[i]=='E':
        c-=1
    a=min(a,c)
print(a)
m = int(input())
n = int(input())

x = max(m, n)
y = min(m, n)
if x % y == 0:
  print(x)
else:
  while x%y!=0:
    z = x % y
    x = y
    y = z
  
print(int(m * n / z))

### FIXED CODE ###

def lcm(a):
    from fractions import gcd
    x = a[0]
    for i in range(1, len(a)):
        x = (x * a[i]) // gcd(x, a[i])
    return x

a =  (input().split())
b = [1, 1]
b[0] = int(a[0])
b[1] = int(a[1])
print(lcm(b))
# -*- coding:utf-8 -*-
a,b = map(str,input().split())
H1 = "1"
D1= "-1"
H = int(H)
D = int(D)
if H * D == 1:
  print("H")
else:
  print("D")

### FIXED CODE ###

# -*- coding: utf-8 -*-
a,b = map(str,input().split())
if (a == "H" and b == "H")or(a =="D" and b == "D"):
  print("H")
else:
  print("D")
from collections import Counter
n = int(input())
xy = [tuple([int(_) for _ in input().split()]) for i in range(n)]
if n == 1:                                                     range(stop)
    result = 1
else:
    xy.sort()
    dxy = [(xy[i][0]-xy[j][0], xy[i][1]-xy[j][1])
           for i in range(n)
           for j in range(i+1, n)]
    cdxy = Counter(dxy)
    result = n - max(cdxy.values())
print(result)

### FIXED CODE ###

from collections import Counter
n = int(input())
xy = [tuple([int(_) for _ in input().split()]) for i in range(n)]
if n == 1:
    result = 1
else:
    xy.sort()
    dxy = [(xy[i][0]-xy[j][0], xy[i][1]-xy[j][1])
           for i in range(n)
           for j in range(i+1, n)]
    cdxy = Counter(dxy)
    result = n - max(cdxy.values())
print(result)
import math
a,b,c=map(int,input().split())
if c%math.gcd(a,b):
    print("NO")
else:
    print("YES")
    

### FIXED CODE ###

import fractions
a,b,c=map(int,input().split())
if c%fractions.gcd(a,b):
    print("NO")
else:
    print("YES")
K = int(input())
S = input().strip()

MOD = 10 ** 9 + 7

ans = 0

fact = [1, 1]
factinv = [1, 1]
inv = [0, 1]


def cmb(n, k, p):
    global fact, factinv
    if (k < 0) or (n < k):
        return 0
    r = min(k, n - k)
    return fact[n] * factinv[k] * factinv[n - k] % p


N = 10 ** 6
for i in range(2, N + 10):
    fact.append((fact[-1] * i) % MOD)
    inv.append((-inv[MOD % i] * (MOD // i)) % MOD)
    factinv.append((factinv[-1] * inv[-1]) % MOD)


for i in range(K + 1):
    ans += pow(25, i, MOD) * cmb(i + len(S) - 1, len(S) - 1, MOD) * pow(26, K - i, MOD)
    ans %= MOD

print(ans)

### FIXED CODE ###

import sys
import math
import collections

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline


def main():
    K = int(input())
    S = input().strip()

    MOD = 10 ** 9 + 7

    fact = [1, 1]
    factinv = [1, 1]
    inv = [0, 1]

    def cmb(n, k, p):
        if (k < 0) or (n < k):
            return 0
        r = min(k, n - k)
        return fact[n] * factinv[k] * factinv[n - k] % p

    N = 10 ** 6 * 2
    for i in range(2, N + 1):
        fact.append((fact[-1] * i) % MOD)
        inv.append((-inv[MOD % i] * (MOD // i)) % MOD)
        factinv.append((factinv[-1] * inv[-1]) % MOD)

    ans = 0
    for i in range(K + 1):
        if len(S) == 1:
            ans += pow(25, i, MOD) * pow(26, K - i, MOD)
        else:
            ans += pow(25, i, MOD) * cmb(i + len(S) - 1, len(S) - 1, MOD) * pow(26, K - i, MOD)

    print(ans % MOD)


if __name__ == '__main__':
    main()
N = int(input())
a=0
for i in range(1,n+1):
  x,y=i,(n//i)*i
  a+=((n//i)*(x+y)//2)
print(a)

### FIXED CODE ###

n=int(input())
ans=0
for i in range(1,n+1):
    x,y=i,(n//i)*i
    ans+=((n//i)*(x+y)//2)
print(ans)
N, K = map(int, input().split())
P = list(map(lambda s: int(s) - 1, input().split()))
C = list(map(int, input().split()))

visited = [False] * N
ans = []
for i in range(N):
    if visited[i]:
        continue
    visited[i] = True
    S = [C[i]]
    p = P[i]
    while p != i:
        visited[p] = True
        S.append(C[p])
        p = P[p]
    s = sum(S)
    n = len(S)
    SS = S + S
    if s <= 0 or K <= n:
        a = max(sum(SS[j:j + c + 1])
                for j in range(n) for c in range(min(K, n)))
    else:
        M = max(sum(SS[j:j + c + 1]) for j in range(n) for c in range(K % n))
        a = s * (K // n) + M
    ans.append(a)

print(max(ans))


### FIXED CODE ###

N, K = map(int, input().split())
P = list(map(lambda s: int(s) - 1, input().split()))
C = list(map(int, input().split()))

ans = -1_000_000_000
for i in range(N):
    S = [C[i]]
    p = P[i]
    while p != i:
        S.append(C[p])
        p = P[p]
    s = sum(S)
    n = len(S)
    acc = 0
    for i in range(min(n, K + 2)):
        acc += S[i]
        a = acc
        if s > 0:
            a += s * ((K - (i + 1)) // n)
        ans = max(a, ans)

print(ans)
#N円の商品を1000円札で支払う時のおつり。

price=int(print())
surpus=price%1000
return surpus

### FIXED CODE ###

#N円の商品を1000円札で支払う時のおつり。

price=int(input())
surpus=price%1000
print((1000-surpus)%1000)
s=input()
list=["A","C","G","T"]
new=[]
a=0
for i in s:
  if i in list:
    a+=1
  if i not in list:
    new.append(a)
    a=0
print(max(new))

### FIXED CODE ###

s=input()
n=len(s)
list=["A","C","G","T"]
new=[]
a=0
for i in range(n):
  if s[i] in list:
    a+=1
    if i == n-1:
      new.append(a)
  if s[i] not in list:
    new.append(a)
    a=0
print(max(new))
count = int(input())
l = []
m = 0
c = 0
for i in range(count):
  val = int(input())
  m = max(m, val)
  if val >= m:
    c = c + 1
print(c)
           

### FIXED CODE ###

count = int(input())
m = 0
c = 0
vals = input().split(" ")
for i in vals:
  val = int(i)
  m = max(m, val)
  if val >= m:
    c = c + 1
print(c)
input()
s=input()
n,m=0

for i in range(len(s)):
  if s[i]=="I":
    n+=1
    m=max(n,m)
  if s[i]=="D":
    n=n-1
    m=max(n,m)
print(m)

### FIXED CODE ###

input()
s=input()
n,m=0,0

for i in range(len(s)):
  if s[i]=="I":
    n+=1
    m=max(n,m)
  if s[i]=="D":
    n=n-1
    m=max(n,m)
print(m)
A, B, C, K = map(int, input().split()) 
import numpy as np
arr = np.concatenate([np.ones(A, int), np.zeros(B, int), np.ones(C, int)*-1])
print(arr[:K].sum())

### FIXED CODE ###

A, B, C, K = map(int, input().split()) 

if K < A:
    print(K)
elif K < A+B:
    print(A)
else:
    print(A-(K-A-B))
a,b=map(int, input())
if 1 <= a <= 9 and 1<= b <= 9:
    print(a*b)
else:
    print(-1)


### FIXED CODE ###

a,b=map(int, input().split())
if (1 <= a and a <= 9) and (1<= b and b <= 9):
    print(a*b)
else:
    print(-1)
l,r = map(int,(input().split()))
if r-l>=2018:
    print(0)
    sys.exit()

else:
    if l%2019>r%2019:
        l=l%2019
        r=r%2019+2019
    else:
        l=l%2019
        r=r%2019

    m=2018
    for i in range(l,r):
        for j in range(i+1,r+1):
            a =i*j%2019
            m =min(m,a)

    print(m)


### FIXED CODE ###

import sys
l,r = map(int,(input().split()))
if r-l>=2018:
    print(0)
    sys.exit()

else:
    if l%2019>r%2019:
        l=l%2019
        r=r%2019+2019
    else:
        l=l%2019
        r=r%2019

    m=2018
    for i in range(l,r):
        for j in range(i+1,r+1):
            a =i*j%2019
            m =min(m,a)

    print(m)
x = input()
if x >= 30:
    print("Yes")
else:
    print("No")


### FIXED CODE ###

x = input()
if int(x) >= 30:
    print("Yes")
else:
    print("No")
import numpy as np 
N,W=map(int,input().split())
w,v=[],[]
for i in range(N):
    a,b=map(int,input().split())
    w+=[a]
    v+=[b]
DP=np.zeros(W+1,dtype=int)
for i in range(N):
    DP[w[i]:]=np.maximum(DP[:-w[i]]+v[i],DP[w[i]:])
print(max(DP))

### FIXED CODE ###

import numpy as np 
N,W=map(int,input().split())
w,v=[],[]
for i in range(N):
    a,b=map(int,input().split())
    w+=[a]
    v+=[b]
DP=np.ones(N*1000+1,dtype=int)*(W+1)
DP[0]=0
for i in range(N):
    DP[v[i]:]=np.minimum(DP[:-v[i]]+w[i],DP[v[i]:])
ans=0
for k in range(N*1000+1):
    if DP[k]<=W:
        ans=k
print(ans)
INF = 10**9 + 7


def main():
    N, W = (int(i) for i in input().split())
    A = [[int(i) for i in input().split()] for j in range(N)]

    dp = [[INF]*(10**4+1) for _ in range(N+1)]
    dp[0][0] = 0
    for i in range(N):
        for j in range(10**4 + 1):
            dp[i+1][j] = min(dp[i+1][j], dp[i][j])
            if 0 <= j - A[i][1] and dp[i][j - A[i][1]] + A[i][0] <= W:
                dp[i+1][j] = min(dp[i+1][j], dp[i][j - A[i][1]] + A[i][0])
    ans = 0
    for j in range(10**4+1)[::-1]:
        if dp[N][j] <= W:
            ans = break
    print(ans)


if __name__ == '__main__':
    main()


### FIXED CODE ###

def main():
    N, W_MAX = (int(i) for i in input().split())
    W = []
    V = []
    for _ in range(N):
        w, v = (int(i) for i in input().split())
        W.append(w)
        V.append(v)
    V_SUM = sum(V)
    INF = (1 << 60)
    dp = [INF] * (V_SUM + 1)
    dp[0] = 0
    for i in range(N):
        for j in range(V[i], V_SUM + 1)[::-1]:
            dp[j] = min(dp[j], dp[j - V[i]] + W[i])
    print(max(j for j in range(V_SUM+1) if dp[j] <= W_MAX))


if __name__ == '__main__':
    main()
n = int(input())

a = list(int(i) for i in input().split())
b = []
for i in range(0,len(a)):
    b.append(a[i])


def solve(cnt,A,N):
    for i in xrange(1, N):
        if sum(A[0:i])>0:
            if sum(A[0:i+1])>=0:
                r = A[i]
                A[i]=-sum(A[0:i])-1
                cnt+=abs(r-A[i])
        else:
            if sum(A[0:i+1])<=0:
                r = A[i]
                A[i]=-sum(A[0:i])+1
                cnt+=abs(r-A[i])
    return cnt

cnt1=0
if b[0]<=0:
    ini=b[0]
    b[0]=1
    cnt1=abs(1-ini)


ans1=solve(cnt1,b,n)
cnt2=0
if a[0]>=0:
    ini=a[0]
    a[0]=-1
    cnt2=abs(-1-ini)


ans2=solve(cnt2,a,n)
print(min(ans1,ans2))


### FIXED CODE ###

n = int(input())

a = list(map(int,input().split()))
b = [i for i in a]


def solve(cnt,A,N):
    sumA=A[0]
    for i in range(1, N):
        if sumA>0:
            if sumA+A[i]>=0:
                r = A[i]
                A[i]=-sumA-1
                cnt+=abs(r-A[i])
        else:
            if sumA+A[i]<=0:
                r = A[i]
                A[i]=-sumA+1
                cnt+=abs(r-A[i])

        sumA+=A[i]
    return cnt

cnt1=0
if b[0]<=0:
    ini=b[0]
    b[0]=1
    cnt1=abs(1-ini)


ans1=solve(cnt1,b,n)
cnt2=0
if a[0]>=0:
    ini=a[0]
    a[0]=-1
    cnt2=abs(-1-ini)


ans2=solve(cnt2,a,n)

print(min(ans1,ans2))
import sys
# gcd
from fractions import gcd
# 切り上げ，切り捨て
# from math import ceil, floor
# リストの真のコピー（変更が伝播しない）
# from copy import deepcopy
# 累積和。list(accumulate(A))としてAの累積和
from itertools import accumulate
# l = ['a', 'b', 'b', 'c', 'b', 'a', 'c', 'c', 'b', 'c', 'b', 'a']
# S = Counter(l)  # カウンタークラスが作られる。S=Counter({'b': 5, 'c': 4, 'a': 3})
# print(S.most_common(2))  # [('b', 5), ('c', 4)]
# print(S.keys())  # dict_keys(['a', 'b', 'c'])
# print(S.values())  # dict_values([3, 5, 4])
# print(S.items())  # dict_items([('a', 3), ('b', 5), ('c', 4)])
# from collections import Counter
# import math
# from functools import reduce
#
# input関係の定義
fin = open('in_4.txt', 'r')
sys.stdin = fin
input = sys.stdin.readline
def ii(): return int(input())
def mi(): return map(int, input().rstrip().split())
def lmi(): return list(map(int, input().rstrip().split()))
def li(): return list(input().rstrip())
# template


def iterate_tokens():
    for line in sys.stdin:
        for word in line.split():
            yield word


if __name__ == '__main__':

    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    Z = int(next(tokens))  # type: int
    W = int(next(tokens))  # type: int
    a = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"

    # write code
    # †私は証明のない決め打ちを提出しました†
    if N == 1:
        print(abs(a[-1]-W))
    elif abs(a[-1] - W) > abs(a[-1] - a[-2]):
        print(abs(a[-1] - W))
    else:
        print(abs(a[-1] - a[-2]))

### FIXED CODE ###

import sys
# gcd
from fractions import gcd
# 切り上げ，切り捨て
# from math import ceil, floor
# リストの真のコピー（変更が伝播しない）
# from copy import deepcopy
# 累積和。list(accumulate(A))としてAの累積和
from itertools import accumulate
# l = ['a', 'b', 'b', 'c', 'b', 'a', 'c', 'c', 'b', 'c', 'b', 'a']
# S = Counter(l)  # カウンタークラスが作られる。S=Counter({'b': 5, 'c': 4, 'a': 3})
# print(S.most_common(2))  # [('b', 5), ('c', 4)]
# print(S.keys())  # dict_keys(['a', 'b', 'c'])
# print(S.values())  # dict_values([3, 5, 4])
# print(S.items())  # dict_items([('a', 3), ('b', 5), ('c', 4)])
# from collections import Counter
# import math
# from functools import reduce
#
# input関係の定義
# fin = open('in_4.txt', 'r')
# sys.stdin = fin
input = sys.stdin.readline
def ii(): return int(input())
def mi(): return map(int, input().rstrip().split())
def lmi(): return list(map(int, input().rstrip().split()))
def li(): return list(input().rstrip())
# template


def iterate_tokens():
    for line in sys.stdin:
        for word in line.split():
            yield word


if __name__ == '__main__':

    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    Z = int(next(tokens))  # type: int
    W = int(next(tokens))  # type: int
    a = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"

    # write code
    # †私は証明のない決め打ちを提出しました†
    if N == 1:
        print(abs(a[-1]-W))
    elif abs(a[-1] - W) > abs(a[-1] - a[-2]):
        print(abs(a[-1] - W))
    else:
        print(abs(a[-1] - a[-2]))