#include <bits/stdc++.h>
using namespace std;
int main() {
  long long t, i, j, n, m, x;
  cin >> n;
  long long a[n + 5], sm[n + 5], sum = 0;
  sm[0] = 0;
  for (i = 1; i <= n; i++) {
    cin >> a[i];
    sum += a[i];
    sm[i] = sum;
  }
  long long ans = 360;
  for (i = 1; i < n; i++) {
    long long x = sm[i];
    long long y = 360 - sm[i];
    ans = min(ans, abs(x - y));
    for (j = i + 1; j <= n; j++) {
      y = (360 - (sm[j] - sm[i]));
      x = abs(360 - y);
      ans = min(ans, abs(x - y));
    }
  }
  cout << ans << endl;
  return 0;
}
