#include <bits/stdc++.h>
using namespace std;
template <typename T, typename S>
ostream &operator<<(ostream &os, const pair<T, S> &p) {
  return os << "(" << p.first << ", " << p.second << ")";
}
template <typename T, size_t N>
ostream &operator<<(ostream &os, const array<T, N> &a) {
  os << "(";
  for (int i = 0; i < (int)N; i++) {
    if (i) os << ", ";
    os << a[i];
  }
  return os << ")";
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "[";
  for (int i = 0; i < (int)v.size(); i++) {
    if (i) os << ", ";
    os << v[i];
  }
  return os << "]";
}
void debug() { cerr << "\n"; }
template <typename T, typename... Args>
void debug(T x, Args... args) {
  cerr << x << "; ";
  debug(args...);
}
int a[360];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  int ret = INT_MAX;
  for (int i = 0; i < n; i++) {
    int sum = a[i];
    ret = min(ret, abs(2 * a[i] - 360));
    for (int j = (i + 1) % n; j != i; j = (j + 1) % n) {
      sum += a[j];
      ret = min(ret, abs(2 * sum - 360));
    }
  }
  cout << ret << "\n";
  return 0;
}
