-- Try AtCoder
-- author: Leonardone @ NEETSDKASU

main = print . solve . map read . words =<< getContents

solve (n:xs) = ans where
    snuke = head xs
    arai  = last xs
    zs = tail $ take (n-1) xs
    ys = scanl (+) 0 zs
    total = last ys
    ans = foldl f (abs $ total + arai - snuke) ys
    f a y = min a $ abs $ (total - y + arai) - (y + snuke)

