import std.algorithm, std.conv, std.range, std.stdio, std.string; void main() { auto n = readln.chomp.to!size_t; auto di = readln.split.to!(int[]); auto dp = new int[int][][](1 << n, n + 1); int calc(int s, int lv, int hp) { if (hp in dp[s][lv]) { return dp[s][lv][hp]; } else if (s == 0) { return dp[s][lv][hp] = hp; } else { auto maxHp = 0; foreach (j; 0..n) { if (bitTest(s, j)) { auto ns = bitReset(s, j); auto nhp = 0; if (di[j] > 0) { nhp = calc(ns, lv, min(hp + di[j], lv * 100)); } else { if (hp <= -di[j]) nhp = 0; else nhp = calc(ns, lv + 1, hp + di[j]); } maxHp = max(maxHp, nhp); } } return dp[s][lv][hp] = maxHp; } } writeln(calc((1 << n) - 1, 1, 100)); } bool bitTest(T)(T n, size_t i) { return (n & (1.to!T << i)) != 0; } T bitReset(T)(T n, size_t i) { return n & ~(1.to!T << i); }