#include <bits/stdc++.h>
using namespace std;
const int maxn = 4e2 + 20;
int n, a[maxn], b[maxn], ans = maxn;
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  partial_sum(a, a + n, b);
  for (int i = 0; i < n; i++) {
    for (int j = i; j < n; j++) {
      ans =
          min(ans, abs((360 - (b[j] - b[i] + a[i])) - ((b[j] - b[i] + a[i]))));
    }
  }
  cout << ans;
  return 0;
}
