#include <bits/stdc++.h>
using namespace std;
const int maxn = 370;
int n, k, A[maxn];
int sum[maxn], ans = 360;
int32_t main() {
  cin >> n;
  for (int i = int(0); i < int(n); i++) {
    cin >> A[i];
    sum[i + 1] = sum[i] + A[i];
  }
  for (int i = int(0); i < int(n); i++) {
    for (int j = int(i); j < int(n + 1); j++) {
      int x = sum[j] - sum[i];
      if (x > 180) x = 360 - x;
      ans = min(ans, 360 - (2 * x));
    }
  }
  cout << ans << endl;
}
