#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> v(n);
  for (int i = 0; i < n; ++i) cin >> v[i];
  int res = 360;
  for (int i = 0; i < n; ++i) {
    int x = 0;
    for (int j = 0; j < n; ++j) {
      x += v[(j + i) % n];
      res = min(res, 2 * abs(180 - x));
    }
  }
  cout << res << endl;
  return 0;
}
