#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n;
  cin >> n;
  long long int a[n];
  for (int i = 0; i < n; i++) cin >> a[i];
  int sum = 0, j, y, min = 360;
  for (long long int i = 0; i < n; i++) {
    sum = 0;
    j = i;
    while (1) {
      sum = sum + a[j];
      if (sum >= 180) {
        break;
      }
      j++;
      if (j == n) {
        j = 0;
      }
      if (j == i) {
        break;
      }
    }
    y = 360 - sum;
    if (abs(y - sum) < min) {
      min = abs(y - sum);
    }
  }
  cout << min;
}
