#include <bits/stdc++.h>
using namespace std;
long long solve(vector<long long> &a) {
  long long sum = 0;
  for (auto u : a) sum += u;
  long long pref = 0;
  long long ans = 2e18;
  long long n = a.size();
  for (long long i = 0; i < n; i++) {
    pref += a[i];
    ans = min(ans, abs(sum - 2 * pref));
  }
  return ans;
}
signed main() {
  long long n;
  cin >> n;
  long long sum = 0;
  vector<long long> a(n);
  for (long long i = 0; i < n; i++) cin >> a[i];
  long long ans = 2e18;
  for (long long i = 0; i < n; i++) {
    vector<long long> b = a;
    rotate(b.begin(), b.begin() + i, b.end());
    ans = min(ans, solve(b));
  }
  cout << ans;
}
