$best = Float::INFINITY
def search(a, n, i, min, max, cur)
    return Float::INFINITY if max - min >= $best
    if i >= n - 1
        max = cur if cur > max
        min = cur if cur < min
        ans = max - min
        $best = ans if ans < $best
        return
    end
    search(a, n, i+1, min, max, cur+a[i+1])
    max = cur if cur > max
    min = cur if cur < min
    search(a, n, i+1, min, max, a[i+1])
end

n = gets.to_i
a = (1..n).map { gets.to_i }
s = 0
(0..n-2).each {|i|
    s += a[i]
    search(a, n, i+1, s, s, a[i+1])
}
p $best
