#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  ios_base::sync_with_stdio(false);
  int64_t n;
  cin >> n;
  vector<int64_t> v(n);
  int64_t sum = 0;
  for (int64_t i = 0; i < n; ++i) {
    cin >> v[i];
    sum += v[i];
  }
  if (n == 1) {
    cout << sum;
    return 0;
  }
  if (n == 2) {
    cout << abs(v[0] - v[1]);
    return 0;
  }
  int64_t ans = INT_MAX;
  for (int64_t i = 0; i < n; ++i) {
    int64_t s = v[i];
    for (int64_t j = (i + 1) % n; j != i; j = (j + 1) % n) {
      s += v[j];
      ans = min(ans, abs(s * 2 - sum));
    }
  }
  cout << ans;
}
