#include <bits/stdc++.h>
using namespace std;
int a[400], cs[400];
int main() {
  int i, j, n, x = 0, y, f = 0, s = 0, mn = 361;
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> a[i];
    if (i > 0)
      cs[i] = a[i] + cs[i - 1];
    else
      cs[i] = a[i];
  }
  if (n == 1)
    cout << "360";
  else if (n == 2)
    cout << abs(a[0] - a[1]);
  else {
    for (i = 0; i < n - 1; i++) {
      for (j = i + 1; j < n; j++) {
        x = cs[j] - cs[i];
        mn = min(abs(180 - x), mn);
      }
    }
    cout << 2 * mn;
  }
}
