#include <bits/stdc++.h>
using namespace std;
const long long N = 2 * 1e5 + 8;
const long double pi = 3.14159265359;
const long long INF = 1e9;
long long n, a[N], ans = INF;
int main() {
  ios_base::sync_with_stdio();
  cin.tie(0);
  cout.tie(0);
  ;
  srand(time(0));
  ;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  for (int i = 1; i <= n; i++) {
    long long sum = 0;
    for (int j = i; j <= n; j++) {
      sum += a[j];
      ans = min(ans, abs(sum - (360 - sum)));
    }
  }
  cout << ans;
}
