Problem:
Score : 300 points

Problem Statement

Snuke and Raccoon have a heap of N cards. The i-th card from the top has the integer a_i written on it.

They will share these cards.
First, Snuke will take some number of cards from the top of the heap, then Raccoon will take all the remaining cards.
Here, both Snuke and Raccoon have to take at least one card.

Let the sum of the integers on Snuke's cards and Raccoon's cards be x and y, respectively.
They would like to minimize |x-y|.
Find the minimum possible value of |x-y|.

Constraints

2 \leq N \leq 2 \times 10^5

-10^{9} \leq a_i \leq 10^{9}

a_i is an integer.

Input

Input is given from Standard Input in the following format:

N
a_1 a_2 ... a_{N}

Output

Print the answer.

Sample Input 1

6
1 2 3 4 5 6

Sample Output 1

1

If Snuke takes four cards from the top, and Raccoon takes the remaining two cards, x=10, y=11, and thus |x-y|=1. This is the minimum possible value.

Sample Input 2

2
10 -10

Sample Output 2

20

Snuke can only take one card from the top, and Raccoon can only take the remaining one card. In this case, x=10, y=-10, and thus |x-y|=20.

Solution in Rust (1.15.1) (judge verdict: Accepted)

#![allow(dead_code)]
#![allow(non_snake_case)]
// Original macro is in https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
// Thanks @tanakh :bow:
macro_rules! input {
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = || -> String {
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}
 
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};
 
    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
    
    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}
 
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };
 
    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [$t:tt]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };
 
    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };
 
    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };
 
    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

// for adhoc read (ex. https://atcoder.jp/contests/abc112/tasks/abc112_a)
fn read_line() -> String {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

#[derive(Debug)]
struct Matrix<T=f32> {
    row: usize,
    col: usize,
    matrix: Vec<Vec<T>>,
}

impl Matrix {
    fn rank(&mut self) -> usize {
        let mut rank = 0;

        for col in 0..self.col {
            let mut pivot = 1000000;
            let mut ma = 1e-10;
            for row in rank..self.row {
                if self.matrix[row][col].abs() > ma {
                    ma = self.matrix[row][col].abs();
                    pivot = row;
                }
            }
            if pivot == 1000000 {
                continue;
            }
            self.matrix.swap(pivot, rank);

            let div = self.matrix[rank][col];
            for col2 in 0..self.col { self.matrix[rank][col2] /= div; }
            for row in 0..self.row {
                if row != rank && self.matrix[row][col].abs() > 1e-10 {
                    let fac = self.matrix[row][col];
                    for col2 in 0..self.col {
                        self.matrix[row][col2] -= self.matrix[rank][col2] * fac;
                    }
                }
            }
            rank += 1;
            // println!("---------------------");
            // println!("col {}", col);
            // println!("pivot {}, rank {}", pivot, rank);
            // println!("  swapped matrix {:?}", self.matrix);
        }
        return rank;
    }
}

#[test]
fn matrix_rank_test() {
    let mat = vec![vec![4.0, 2.0, 3.0, 4.0],
                   vec![1.0, 2.0, 3.0, 4.0],
                   vec![0.0, 0.0, 0.0, 0.0]];
    assert_eq!(2, rank(&mat, false));
}

#[test]
fn matrix_rank_test2() {
    let mat = vec![vec![1.0, 1.0],
                   vec![1.0, 0.0],
                   vec![0.0, 1.0]];
    assert_eq!(2, rank(&mat, false));
}
#[test]
fn matrix_solve_test() {
    let mat = vec![vec![4.0, 2.0, 3.0, 4.0],
                   vec![1.0, 2.0, 3.0, 4.0],
                   vec![0.0, 0.0, 0.0, 0.0]];
    let b = vec![0.0, 0.0, 0.0, 0.0];
    assert_eq!(2, solve(mat, b));
}

#[test]
fn matrix_solve_test2() {
    let mat = vec![vec![1.0, 1.0],
                   vec![1.0, 0.0],
                   vec![0.0, 1.0]];
    let b = vec![0.0, 0.0, 0.0, 0.0];
    assert_eq!(2, solve(mat, b));
}
fn gcd(a: i64, b: i64) -> i64 {
    if a < b { return gcd(b, a); }
    // let q = a/b;
    let r = a%b;
    if r == 0 { return b; }
    return gcd(b, r);
}

fn chars_to_str(v: Vec<char>) -> String {
    return v.into_iter().collect();
}

#[test]
fn test_chars_to_str() {
    let c = vec!['a','b'];
    let actual = chars_to_str(c);
    assert_eq!(actual, "ab");
}

// https://practice.contest.atcoder.jp/tasks/practice_1
fn main() {
    input! { n: usize, a: [i64; n] }

    let mut acc = vec![];
    let sum = a.iter().fold(0, |sum, v| sum + v);
    let mut l = 0;
    for (i,v) in a.iter().enumerate() {
        if i == n-1 { break; }
        l += *v;
        // println!("i {} v: {} ", i, v);
        acc.push((2*l-sum).abs());
    }
    // println!("{:?}", acc);
    println!("{}", acc.iter().min().unwrap())
}