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