#include <bits/stdc++.h>
using namespace std;
int n;
int a[361];
int s[361];
int main() {
  int n;
  while (cin >> n) {
    int ans = 360;
    for (int i = (1), _end = (n); i <= _end; ++i) cin >> a[i];
    for (int i = (1), _end = (n); i <= _end; ++i) s[i] = s[i - 1] + a[i];
    for (int i = (1), _end = (n); i <= _end; ++i)
      for (int j = (i), _end = (n); j <= _end; ++j) {
        int x = s[j] - s[i - 1];
        ans = min(ans, abs(360 - x - x));
      }
    cout << ans << endl;
  }
  return 0;
}
