#include <bits/stdc++.h>
using namespace std;
const long long N = 2 * 1e5 + 5;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  long long t;
  t = 1;
  while (t--) {
    long long n;
    cin >> n;
    long long a[2 * n];
    for (long long i = 0; i < n; i++) {
      cin >> a[i];
      a[n + i] = a[i];
    }
    long long sum = 0;
    long long maxi = 1e17;
    std::vector<long long> pref;
    pref.push_back(0);
    for (long long i = 0; i < 2 * n; i++) {
      pref.push_back(pref.back() + a[i]);
    }
    for (long long i = 0; i < n; i++) {
      for (long long j = i + 1; j <= i + n; j++) {
        long long x = pref[j] - pref[i];
        maxi = min(maxi, 2 * abs(x - 180));
      }
    }
    cout << maxi;
  }
}
