#include <bits/stdc++.h>
using namespace std;
int part[10000], a;
int main() {
  int n, ans = 360;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &part[i]), part[n + i] = part[i];
  for (int i = 1; i <= n; i++) {
    a = 0;
    for (int j = i; j <= n + i; j++) {
      a += part[j];
      if (abs(360 - 2 * a) < ans) ans = abs(360 - 2 * a);
    }
  }
  cout << ans;
}
