#include <bits/stdc++.h>
using namespace std;
bool cmp(int x, int y) { return x > y; }
int main() {
  int n;
  int a[364];
  int sum[364];
  sum[0] = 0;
  while (cin >> n) {
    int i;
    int inf = 0x3f3f3f3f;
    for (i = 1; i <= n; i++) {
      cin >> a[i];
      sum[i] = sum[i - 1] + a[i];
    }
    for (i = 0; i < n; i++) {
      for (int j = i + 1; j <= n; j++)
        inf = min(inf, 2 * abs(sum[j] - sum[i] - 180));
    }
    cout << inf << endl;
  }
  return 0;
}
