#include <bits/stdc++.h>
using namespace std;
const long long inf = (1LL << 60) - 1;
int dx[] = {-1, 1, 0, 0};
int dy[] = {0, 0, -1, 1};
char temp[2010];
long long n, m, k;
long long sumR[2010][2010], sumC[2010][2010], mat[2010][2010];
void solve() {
  int n, sum = 0, ans = 360;
  cin >> n;
  vector<int> piz(n);
  for (int i = 0; i < n; i++) {
    cin >> piz[i];
  }
  for (int i = 0; i < n; i++) {
    sum = 0;
    for (int j = 0; j < n; j++) {
      sum += piz[(i + j) % n];
      ans = min(ans, 2 * abs(180 - sum));
    }
  }
  cout << ans << "\n";
}
int main() {
  ios::sync_with_stdio(0);
  cout.tie(0);
  ;
  solve();
  return 0;
}
