#include <bits/stdc++.h>
using namespace std;
int main() {
  vector<int> v;
  int n;
  int a[400];
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", a + i);
  int b = 0xfffffff;
  for (int i = 0; i < n; i++) {
    int tmp = 0;
    for (int j = i, cnt = 0; cnt < n; cnt++, j++) {
      tmp += a[j % n];
      b = min(abs(tmp - 180) * 2, b);
    }
  }
  printf("%d\n", b);
}
