#include <bits/stdc++.h>
using namespace std;
const int N = 4e5 + 50;
int main() {
  int mi = 10000;
  int a[500];
  int n;
  cin >> n;
  int j = 0;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  int sum = 0;
  int i = 0;
  for (int k = 0; k < 2 * n; ++k) {
    sum += a[i];
    mi = min(mi, abs(180 - sum) * 2);
    while (sum > 180) {
      sum -= a[j];
      j = (j + 1) % n;
    }
    mi = min(mi, abs(180 - sum) * 2);
    i = (i + 1) % n;
  }
  cout << mi;
}
