#include <bits/stdc++.h>
using namespace std;
const long long INF = 15e8;
int p[360 + 10];
int a[360 + 10];
int get(int l, int r) { return p[r] - p[l - 1]; }
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    p[i] = p[i - 1] + a[i];
  }
  int ans = INF;
  for (int i = 1; i <= n; i++) {
    for (int j = i; j <= n; j++) ans = min(ans, abs((2 * get(i, j)) - p[n]));
  }
  cout << ans;
}
