#include <bits/stdc++.h>
using namespace std;
int a[500];
int main() {
  int n;
  scanf("%d", &n);
  int maxn;
  int minn = 2000;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
  }
  for (int i = 1; i <= n; i++) {
    int ans = 0;
    for (int j = i; j <= n; j++) {
      ans += a[j];
      minn = min(minn, abs(ans - 180));
    }
  }
  printf("%d", 2 * minn);
}
