#include <bits/stdc++.h>
using namespace std;
int a[400];
int n, x;
int abs(int x) { return x < 0 ? -x : x; }
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  int ans = 360;
  for (int i = 1; i <= n; i++) {
    int temp = 0, t = n, u = i;
    while (t--) {
      temp += a[u];
      u = u % n + 1;
      ans = min(ans, abs(360 - 2 * temp));
    }
  }
  cout << ans << endl;
}
