import java.io.*;
import java.util.*;

public class delivery_ats_greed implements Runnable {
	public static void main(String[] args) {
		new delivery_ats_greed().run();
	}

	BufferedReader br;
	StringTokenizer in;
	PrintWriter out;

	public String nextToken() throws IOException {
		while (in == null || !in.hasMoreTokens()) {
			in = new StringTokenizer(br.readLine());
		}
		return in.nextToken();
	}

	public int nextInt() throws IOException {
		return Integer.parseInt(nextToken());
	}

	public long nextLong() throws IOException {
		return Long.parseLong(nextToken());
	}

	public double nextDouble() throws IOException {
		return Double.parseDouble(nextToken());
	}

	public void solve() throws IOException {
		int n = nextInt();
		long[] a = new long[n];
		for (int i = 0; i < n; i++) {
			a[i] = nextLong();
		}
		if (n == 1) {
			out.println(0);
			return;
		}

		long ans = 0;
		int l = 1;
		int r = n - 2;
		long left = a[0];
		long right = a[n - 1];
		while (l <= r) {
			if (left < right) {
				ans += left;
				left += a[l++];
			} else {
				ans += right;
				right += a[r--];
			}
		}
		out.println(ans);
	}

	public void run() {
		try {
			br = new BufferedReader(new FileReader("delivery.in"));
			out = new PrintWriter("delivery.out");

			solve();

			br.close();
			out.close();
		} catch (IOException e) {
			e.printStackTrace();
			System.exit(1);
		}
	}
}
