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


void main() {
  int n;
  readf (" %d", &n);
  auto a = new double[n];
  foreach (t; 0 .. n) {
    int x;
    readf (" %d", &x);
    a[t] = x * 2.0;
  }
  auto x = new double[n];
  double f (double x0) {
    x[0] = x0;
    foreach (i; 1 .. n) {
      x[i] = a[i-1] - x[i-1];
    }
    debug stderr.writeln (x);
    double res = abs ((a[n-1] - x[n-1]) - x0);
    debug stderr.writefln ("f(%f) = %f", x0, res);
    return res;
  }

  double x0 = 0.0;
  double x1 = 2_000_000;
  foreach (i; 0 .. 500) {
    double dx = (x1 - x0) / 3.0;
    double x2 = x0 + dx;
    double x3 = x1 - dx;
    double f1 = f (x2);
    double f2 = f (x3);
    if (f1 > f2) {
      x0 = x2;
    } else {
      x1 = x3;
    }
  }
  debug stderr.writeln (x0, ' ', x1);

  f ((x0 + x1) * 0.5);
  writefln ("%(%.0f %)", x);
}

