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