#include <bits/stdc++.h>
using namespace std;
const int N = 410;
int a[N << 1], qz[N << 1];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) scanf("%d", &a[i]), a[i + n] = a[i];
  for (int i = 1; i <= 2 * n; ++i) qz[i] = qz[i - 1] + a[i];
  int maxn = 360;
  for (int i = 1; i <= n; ++i)
    for (int j = i; j <= i + n - 1; ++j) {
      int pos = qz[j] - qz[i - 1];
      maxn = min(maxn, abs(2 * pos - 360));
    }
  printf("%d\n", maxn);
  return 0;
}
