#include <bits/stdc++.h>
using namespace std;
int a[400], n;
bool f[400];
int dp[400][400];
int main(int argc, char const *argv[]) {
  int i, j, k, sum;
  cin >> n;
  for (i = 1; i <= n; i++) cin >> a[i];
  int ans = 0;
  for (i = 1; i <= n; i++) {
    sum = 0;
    for (j = i; j <= n; j++) {
      sum += a[j];
      if (abs(sum - 180) < abs(ans - 180)) ans = sum;
    }
  }
  cout << 2 * abs(ans - 180) << endl;
  return 0;
}
