#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const int maxn = 1e6 + 5;
int a[maxn], n;
int sum[maxn];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
  }
  int ans = 360;
  for (int i = 1; i <= n; i++) {
    sum[i] = sum[i - 1] + a[i];
    if (abs(2 * sum[i] - 360) < ans) ans = abs(2 * sum[i] - 360);
  }
  for (int i = 1; i < n - 1; i++) {
    for (int j = i + 1; j < n; j++) {
      int tmp = sum[j] - sum[i];
      ans = min(abs(2 * tmp - 360), ans);
    }
  }
  printf("%d\n", ans);
}
