#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int t = 1;
  while (t--) {
    int n;
    cin >> n;
    vector<int> a(n);
    for (auto& x : a) cin >> x;
    int best = 360;
    for (int i = 0; i < n; ++i) {
      int cand = 0;
      int j = i;
      while (cand < 180) {
        cand += a[j];
        j = (j + 1) % n;
      }
      best = min(best, abs(2 * cand - 360));
    }
    cout << best << endl;
  }
  return 0;
}
