#include <iostream>
#include <algorithm>
using namespace std;
int n;
int sum;
int l, r;
int ans = 360;
int a[360];
int main()
{
cin >> n;
for (int i = 0; i < n; i++)
cin >> a[i];
while (r < n)
{
sum += a[r];
while (sum >= 180)
{
ans = min(ans, 2 * abs(180 - sum));
sum -= a[l];
l++;
}
ans = min(ans, 2 * abs(180 - sum));
r++;
}
cout << ans << endl;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8YWxnb3JpdGhtPgoKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCmludCBuOwppbnQgc3VtOwppbnQgbCwgcjsKaW50IGFucyA9IDM2MDsKaW50IGFbMzYwXTsKCmludCBtYWluKCkKewoJY2luID4+IG47Cglmb3IgKGludCBpID0gMDsgaSA8IG47IGkrKykKCQljaW4gPj4gYVtpXTsKCXdoaWxlIChyIDwgbikKCXsKCQlzdW0gKz0gYVtyXTsKCQl3aGlsZSAoc3VtID49IDE4MCkKCQl7CgkJCWFucyA9IG1pbihhbnMsIDIgKiBhYnMoMTgwIC0gc3VtKSk7CgkJCXN1bSAtPSBhW2xdOwoJCQlsKys7CgkJfQoJCWFucyA9IG1pbihhbnMsIDIgKiBhYnMoMTgwIC0gc3VtKSk7CgkJcisrOwoJfQoJY291dCA8PCBhbnMgPDwgZW5kbDsKfQ==