#include <bits/stdc++.h>
using namespace std;
int n, a[370], ans = 400;
int main() {
  ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < n; i++) {
    int cnt = i, res = 0;
    while (res + a[cnt] <= 180) res += a[cnt], cnt = (cnt + 1) % n;
    ans = min(ans, 360 - 2 * res);
  }
  cout << ans << '\n';
  return 0;
}
