#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  int n, m, k;
  cin >> n;
  vector<int> arr(n);
  int ans = 360;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  for (int start = 0; start < n; start++) {
    int sum1 = 0;
    for (int end = start;; end++) {
      if (end == n) {
        end = 0;
      }
      sum1 += arr[end];
      ans = min(ans, 2 * abs(180 - sum1));
      if (end == start - 1 || (end == n - 1 && start == 0)) {
        break;
      }
    }
  }
  cout << ans;
  return 0;
}
