#include <bits/stdc++.h>
using namespace std;
int num[725], sum[725];
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> num[i];
    num[i + n] = num[i];
  }
  sum[0] = 0;
  sum[1] = num[1];
  for (int i = 2; i <= 2 * n; i++) sum[i] = sum[i - 1] + num[i];
  int ans = 2e9;
  for (int i = 1; i <= n; i++) {
    for (int j = i; j <= i + n - 1; j++) {
      if (2 * abs(sum[j] - sum[i - 1] - 180) < ans) {
        ans = 2 * abs(sum[j] - sum[i - 1] - 180);
      }
    }
  }
  cout << ans << endl;
  return 0;
}
