#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int a[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  int diff = 362;
  int curr, rest;
  int ct = 0;
  for (int i = 0; i < n; i++) {
    ct = 0;
    curr = 0;
    for (int j = i;; j++) {
      j = j % n;
      curr += a[j];
      rest = 360 - curr;
      diff = min(diff, abs(rest - curr));
      ct++;
      if (ct == n) break;
    }
  }
  cout << diff;
}
