#include <bits/stdc++.h>
using namespace std;
const int BLACK = 1, WHITE = 2;
int len_of_number(int n) {
  int len(0);
  while (n != 0) {
    ++len;
    n /= 10;
  }
  return len;
}
int sum_of_digits(int n) {
  int sod = 0;
  while (n != 0) {
    sod += (n % 10);
    n /= 10;
  }
  return sod;
}
bool isPalindrome(string str) {
  int n = str.length();
  for (int i = (0); i <= (n / 2); i++)
    if (str[i] != str[n - i - 1]) return false;
  return true;
}
long long int fast_exp(long long int x, long long int i) {
  long long int ans = 1;
  while (i > 0) {
    if (i & 1) ans = (ans * x);
    i >>= 1;
    x = (x * x);
  }
  return ans;
}
long long int fast_exp(long long int x, long long int i, long long int mod) {
  long long int ans = 1;
  while (i > 0) {
    if (i & 1) ans = (ans * x) % mod;
    i >>= 1;
    x = (x * x) % mod;
  }
  return ans;
}
long long int modInverse(long long int x, long long int mod) {
  return fast_exp(x, mod - 2, mod);
}
long long int egcd_x, egcd_y, egcd_d;
void egcd(long long int a, long long int b) {
  if (b == 0) {
    egcd_x = 1, egcd_y = 0;
    egcd_d = a;
    return;
  }
  egcd(b, a % b);
  long long int temp = egcd_x;
  egcd_x = egcd_y;
  egcd_y = temp - (a / b) * egcd_y;
}
long long int extended_gcd(long long int a, long long int b) {
  if (a >= b) {
    egcd(a, b);
    return ((egcd_x % b) + b) % b;
  } else {
    egcd(b, a);
    return ((egcd_y % b) + b) % b;
  }
}
long long int gcd(long long int x, long long int y) {
  long long int t;
  while (y != 0) {
    t = x % y;
    x = y;
    y = t;
  }
  return x;
}
vector<int> lp, pr;
void primeSieve(int n) {
  lp.resize(n + 1, 0);
  int size = 0;
  for (int i = (2); i <= (n); i++) {
    if (!lp[i]) {
      lp[i] = i;
      pr.push_back(i);
      ++size;
    }
    for (int j = 0; j < size && pr[j] <= lp[i] && (1ll * i * pr[j]) <= n; ++j)
      lp[i * pr[j]] = pr[j];
  }
}
bool isPrime(int n) {
  int root = sqrt(n);
  for (int i = (2); i <= (root); i++)
    if (n % i == 0) return 0;
  return 1;
}
vector<int> cnt;
string groupAndCnt(string str) {
  string a = "";
  int prev_count = 0;
  char prev_char = '~';
  for (auto &c : str) {
    if (c != prev_char) {
      if (prev_count) {
        a += prev_char;
        cnt.push_back(prev_count);
      }
      prev_count = 1;
      prev_char = c;
    } else
      ++prev_count;
  }
  cnt.push_back(prev_count);
  a += prev_char;
  return a;
}
vector<int> pset, pset_size;
void initSet(int _size) {
  pset.resize(_size);
  pset_size.resize(_size);
  for (int i = (0); i <= (_size - 1); i++) pset[i] = i, pset_size[i] = 1;
}
int findSet(int i) { return (pset[i] == i) ? i : (pset[i] = findSet(pset[i])); }
void unionSet(int i, int j) {
  int p1 = findSet(i);
  int p2 = findSet(j);
  pset[p1] = p2;
  if (p1 != p2) {
    pset_size[p2] += pset_size[p1];
  }
}
bool isSameSet(int i, int j) { return findSet(i) == findSet(j); }
inline void solve(int T) {
  int n;
  cin >> n;
  vector<int> a(2 * n);
  for (int i = (0); i <= (n - 1); i++) cin >> a[i];
  if (n == 1) {
    cout << 360;
    return;
  }
  for (int i = (n); i <= (2 * n - 1); i++) {
    a[i] = a[i - n];
  }
  int ans = numeric_limits<int>::max();
  int local;
  for (int i = (0); i <= (n - 1); i++) {
    local = 0;
    for (int j = (0); j <= (n - 1); j++) {
      local += a[i + j];
      ans = min(ans, abs(local - (360 - local)));
    }
  }
  cout << ans;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int test_cases;
  test_cases = 1;
  for (int T = (0); T <= (test_cases - 1); T++) {
    solve(T);
  }
  return 0;
}
