#include <bits/stdc++.h>
using namespace std;
int a, ans = 360;
vector<int> an;
int main() {
  cin >> a;
  an.push_back(0);
  for (int i = 1; i <= a; i++) {
    int x;
    cin >> x;
    an.push_back(x);
    an[i] += an[i - 1];
  }
  for (int i = 1; i < a; i++)
    for (int j = 0; j < i; j++)
      if (abs(an[i] - an[j] - 180) * 2 < ans)
        ans = abs(an[i] - an[j] - 180) * 2;
  cout << ans;
}
