#include <bits/stdc++.h>
using namespace std;
int cnt, c, b[10001];
int main() {
  int n, a[10001];
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
    cnt += a[i];
  }
  for (int i = 1; i <= n; ++i) {
    b[i] = a[i];
    for (int j = i + 1; j <= n; ++j) {
      if (b[i] > 180) {
        break;
      } else if (b[i] < 180) {
        if (b[i] + a[j] == 180) {
          cout << 0;
          return 0;
        } else if (abs(b[i] + a[j] - 180) <= abs(b[i] - 180)) {
          b[i] += a[j];
          continue;
        } else {
          break;
        }
      }
    }
  }
  for (int i = 1; i <= n; ++i) {
    if ((abs(180 - b[i]) * 2) < cnt) {
      cnt = abs(180 - b[i]) * 2;
    }
  }
  cout << cnt;
}
