import std.algorithm,
       std.string,
       std.array,
       std.stdio,
       std.range,
       std.conv;

long abs(long x) {
  return x * (x < 0 ? -1 : 1);
}

void main() {
  long   N = readln.chomp.to!long;
  long[] a = readln.chomp.split.to!(long[]);
  long ans = long.max;

  long[] dp1,
         dp2;
  dp1.length = N;
  dp2.length = N;

  for (size_t i = 0; i < N - 1; i++) {
    if (i == 0) {
      dp1[i] = a[i];
      dp2[i] = a[1..$].sum;
    } else {
      dp1[i] = dp1[i-1] + a[i];
      dp2[i] = dp2[i-1] - a[i];
    }

    long x = dp1[i],
         y = dp2[i];
    long z = abs(x - y);
    if (z < ans) {
      ans = z;
    }
  }

  writeln(ans);
}
