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