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

public class delivery_ats_slow implements Runnable {
    public static void main(String[] args) {
        new delivery_ats_slow().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 long get(long[] data, int l, int r) {
        if (l > r){
            return 0;
        }
        long ans = 0;
        for (int i = l; i <= r; i++) {
            ans += data[i];
        }
        return ans;
    }

    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[] sumLR = new long[n];
        long[] sumRL = new long[n];
        for (int i = 1; i < n; i++) {
            sumLR[i] = sumLR[i - 1] + a[i - 1];
        }

        for (int i = n - 2; i >= 0; i--) {
            sumRL[i] = sumRL[i + 1] + a[i + 1];
        }

        long minVal = Long.MAX_VALUE;
        for (int i = -1; i <= n - 1; i++) {
            long leftSum = get(sumLR, 0, i);
            long rightSum = get(sumRL, i + 1, n - 1);
            if (leftSum + rightSum < minVal) {
                minVal = leftSum + rightSum;
            }
        }
        out.println(minVal);
    }

    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);
        }
    }
}
