#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, a[4000] = {0}, faul = 0, ans = 1000000000;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (int i = 1; i <= n; i++) {
    int sum = 0;
    for (int j = 1; j <= n; j++) {
      for (int k = j; k <= j + faul; k++) {
        sum += a[k];
        ans = min(ans, abs(sum - (360 - sum)));
      }
      sum = 0;
    }
    faul++;
  }
  printf("%d", ans);
}
