#include <bits/stdc++.h>
using namespace std;
long long int n, a[400];
long long int pre[400], post[400];
int main() {
  scanf("%lld", &n);
  for (int i = 1; i <= n; i++) scanf("%lld", &a[i]);
  for (int i = 1; i <= n; i++) pre[i] = a[i] + pre[i - 1];
  for (int i = n; i >= 1; i--) post[i] = post[i + 1] + a[i];
  long long int sum = pre[n];
  long long int ans = 1e18;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      long long int x = 0;
      if (j - i < 0)
        x = pre[j] + post[n - (i - j) + 1];
      else
        x = pre[j] - pre[j - i];
      ans = min(ans, abs(x - (sum - x)));
    }
  }
  printf("%lld\n", ans);
  return 0;
}
