#include <bits/stdc++.h>
using namespace std;
int n;
int a[410];
inline void work() {
  scanf("%d", &n);
  int mn = 360;
  for (int i = 1; i <= n; i++) scanf("%d", a + i);
  for (int i = 1; i <= n; i++) {
    int sum = 0;
    for (int j = i; j <= n; j++) sum += a[j], mn = min(mn, abs(360 - sum * 2));
  }
  printf("%d\n", mn);
}
int main() {
  int T = 1;
  while (T--) work();
}
