#include <bits/stdc++.h>
using namespace std;
int p[360];
int main() {
  int n, i, a = 0, b, sum, ret = INT_MAX;
  scanf("%d", &n);
  for (i = 0; i < n; i++) scanf("%d", p + i);
  b = 0;
  sum = p[0];
  while (a < n) {
    while (sum < 180) {
      b = (b + 1) % n;
      sum += p[b];
    }
    ret = min(ret, 2 * sum - 360);
    sum -= p[a];
    a++;
  }
  printf("%d", ret);
  return 0;
}
