#include <bits/stdc++.h>
using namespace std;
int arr[400];
int num;
int sum[400];
int main(void) {
  scanf("%d", &num);
  for (int i = 1; i <= num; i++) scanf("%d", arr + i);
  int s = 0;
  for (int i = 1; i <= num; i++) {
    s = 0;
    for (int j = i; j <= num; j++) {
      s += arr[j];
      sum[s]++;
    }
  }
  int ans = 360;
  for (int i = 0; i <= 360; i++) {
    if (sum[i]) ans = min(ans, abs(180 - i) * 2);
  }
  printf("%d", ans);
  return 0;
}
