{-# LANGUAGE ScopedTypeVariables #-}
import Control.Applicative
import Control.Monad
import Data.List
import Text.Printf
sumarr :: [Int] -> [Int]
sumarr [x] = []
sumarr (x:y:ys) = x+y : sumarr (x+y:ys)

solin :: [Int] -> Int
solin w = solsc (sumarr (0:w))

solsc :: [Int] -> Int
solsc x = solve x (last x)

solve :: [Int] -> Int -> Int
solve (x:y:ys) z
    | abs (z-x*2) < abs (z-y*2) = abs (z-x*2)
    | otherwise = solve (y:ys) z

main = do
    _ <- getLine
    w <- map read . words <$> getLine
    let answer = solin w
    print answer

