#include <bits/stdc++.h>
using namespace std;
long long n;
long long a[365], sum[365];
int main(void) {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  for (long long(i) = (1); (i) <= (n); (i)++)
    cin >> a[i], sum[i] = sum[i - 1] + a[i];
  long long ans = 1e18;
  for (long long(i) = (1); (i) <= (n); (i)++) {
    for (long long(j) = (1); (j) <= (n); (j)++) {
      if (i > j) continue;
      long long x = sum[j] - sum[i - 1];
      (ans) = min((ans), (abs(x - (360 - x))));
    }
  }
  cout << ans << endl;
  return 0;
}
