#include <bits/stdc++.h>
using namespace std;
inline void read1(int &num) {
  char in;
  bool IsN = false;
  in = getchar();
  while (in != '-' && (in < '0' || in > '9')) in = getchar();
  if (in == '-') {
    IsN = true;
    num = 0;
  } else
    num = in - '0';
  while (in = getchar(), in >= '0' && in <= '9') {
    num *= 10, num += in - '0';
  }
  if (IsN) num = -num;
}
inline void read2(int &a, int &b) {
  read1(a);
  read1(b);
}
inline void read3(int &a, int &b, int &c) {
  read1(a);
  read1(b);
  read1(c);
}
inline void read1(long long &num) {
  char in;
  bool IsN = false;
  in = getchar();
  while (in != '-' && (in < '0' || in > '9')) in = getchar();
  if (in == '-') {
    IsN = true;
    num = 0;
  } else
    num = in - '0';
  while (in = getchar(), in >= '0' && in <= '9') {
    num *= 10, num += in - '0';
  }
  if (IsN) num = -num;
}
inline void read2(long long &a, long long &b) {
  read1(a);
  read1(b);
}
inline void read3(long long &a, long long &b, long long &c) {
  read1(a);
  read1(b);
  read1(c);
}
inline void read1(double &num) {
  char in;
  double Dec = 0.1;
  bool IsN = false, IsD = false;
  in = getchar();
  while (in != '-' && in != '.' && (in < '0' || in > '9')) in = getchar();
  if (in == '-') {
    IsN = true;
    num = 0;
  } else if (in == '.') {
    IsD = true;
    num = 0;
  } else
    num = in - '0';
  if (!IsD) {
    while (in = getchar(), in >= '0' && in <= '9') {
      num *= 10;
      num += in - '0';
    }
  }
  if (in != '.') {
    if (IsN) num = -num;
    return;
  } else {
    while (in = getchar(), in >= '0' && in <= '9') {
      num += Dec * (in - '0');
      Dec *= 0.1;
    }
  }
  if (IsN) num = -num;
}
inline void read2(double &a, double &b) {
  read1(a);
  read1(b);
}
inline void read3(double &a, double &b, double &c) {
  read1(a);
  read1(b);
  read1(c);
}
class poj {
 public:
  int a[10000];
  int b[10000];
  int sum[10000];
  bool pass[10000];
  int flag;
  poj() {
    flag = 1;
    FILE *f = freopen("C:\\Users\\dell\\Desktop\\poj.txt", "r", stdin);
    sum[0] = 0;
    while (scanf("%d%d", a + flag, b + flag) != EOF) {
      sum[flag] = sum[flag - 1] + b[flag];
      pass[flag] = false;
      flag++;
    }
    fclose(f);
  }
  ~poj() {
    FILE *f = freopen("C:\\Users\\dell\\Desktop\\poj.txt", "w", stdout);
    for (int i = (1); i < (flag); i++) {
      if (pass[i]) continue;
      printf("%d %d\n", a[i], b[i]);
    }
    fclose(f);
  }
  void show_new_problem(int xxx, int yyy) {
    srand(xxx * yyy);
    int last = (int)(3262653.0 * rand() / (RAND_MAX + 1.0));
    int ind = lower_bound(sum, sum + flag, last) - sum;
    printf("%d,%d\n", a[ind], b[ind]);
  }
  void have_pass(int ind) {
    for (int i = 0; i < flag; i++)
      if (a[i] == ind) pass[i] = true;
  }
};
int main() {
  int len;
  scanf("%d", &len);
  int ans = 360;
  int num[400];
  for (int i = (0); i < (len); i++) read1(num[i]);
  for (int i = (0); i < (len); i++)
    for (int j = (i); j < (len); j++) {
      int sum = 0;
      for (int k = (i); k <= (j); k++) sum += num[k];
      ans = min(ans, abs(360 - (sum << 1)));
    }
  printf("%d\n", ans);
  return 0;
}
