// 32351ZN #include #include #include #include #include #include #include #include #include using namespace std; typedef vector ivec_t; typedef vector imat_t; #define FOR_EACH(p,q,r) for(p=q;p!=r;p++) #define FOR_EACH_C(p,c) for(p=(c).begin();p!=(c).end();p++) ivec_t g_stone; int g_ans; void Solve(int depth,int diff=0) { if(depth == (int)g_stone.size()) { if(abs(diff) < g_ans)g_ans = abs(diff); return; } Solve(depth+1,diff+g_stone[depth]); Solve(depth+1,diff-g_stone[depth]); } int main() { int n,i; cin >> n; g_stone.assign(n,0); FOR_EACH(i,0,n){ cin >> g_stone[i]; } g_ans = INT_MAX; Solve(0); cout << g_ans << endl; return 0; }