#include <bits/stdc++.h>
using namespace std;
int a[1000];
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  int ans = 360;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      int ed = j;
      if (ed < i) ed += n;
      int sum = 0;
      for (int k = i; k < ed; k++) {
        sum += a[k % n];
      }
      ans = min(ans, abs(2 * sum - 360));
    }
  }
  cout << ans << endl;
}
