#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int test[213456];
int main() {
	long long n, k, sum = 0, num = 1234567891230, a = 0; cin >> n;
	for(int h=0;h<n;h++){
      cin>>k;sum+=k;test[h]=k;
    }
    for(int h=0;h<n;h++){
       num = min(abs(a-(sum - a)), num);
       a+=test[h];
    }
    cout<<num<<endl;
	return 0;
}