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

public class delivery_ats_vs implements Runnable {
    public static void main(String[] args) {
        new delivery_ats_vs().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 minVal = Long.MAX_VALUE;
        for (int i = -1; i <= n - 1; i++) {
            long left = 0;
            long right = 0;
            for (int j = 0; j <= i; j++) {
                long sum = 0;
                for (int k = 0; k < j; k++) {
                    sum += a[k];
                }
                left += sum;
            }
            for (int j = n - 1; j > i; j--) {
                long sum = 0;
                for (int k = n - 1; k > j; k--) {
                    sum += a[k];
                }
                right += sum;
            }
            if (left + right < minVal) {
                minVal = left + right;
            }
        }
        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);
        }
    }
}
