#include<bits/stdc++.h>
#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
#define all(v) v.begin(), v.end()
using ll = long long;
using namespace std;

int main(){
  int n;cin>>n;
  int a;
  vector<ll> x(n+1,0);
  rep(i,n){
    cin>>a;
    x[i+1]=x[i]+a;
  }
  ll mn=1e18,y;
  rep(i,n-1){
    y=x[n]-x[i+1];
    mn=min(mn,abs(x[i+1]-y));
  }
  cout<<mn;
}