#include <bits/stdc++.h>
using namespace std;
int A[1010];
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> A[i];
  }
  int ans = INT_MAX;
  for (int i = 0; i < n; i++) {
    int cnt = 0;
    for (int j = i; j < n; j++) {
      cnt += A[j];
      int ff = cnt;
      int ss = 360 - ff;
      ans = min(ans, abs(ss - ff));
    }
  }
  cout << ans << endl;
  return 0;
}
