#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, a[724], i, j, min_diff, sum = 0;
  cin >> n;
  for (i = 1; i <= n; i++) {
    cin >> a[i];
    a[n + i] = a[i];
  }
  if (n == 1) {
    cout << a[1];
    return 0;
  }
  min_diff = 1000;
  j = 1;
  for (i = 1; i <= 2 * n; i++) {
    sum += a[i];
    while (j < i && sum > 180) {
      sum -= a[j];
      j++;
    }
    min_diff = min(min_diff, abs(180 - sum));
  }
  min_diff *= 2;
  cout << min_diff;
  return 0;
}
