import std.algorithm, std.array, std.container, std.range, std.bitmanip; import std.numeric, std.math, std.bigint, std.random, core.bitop; import std.string, std.conv, std.stdio, std.typecons; void main() { auto n = readln.chomp.to!int; auto di = readln.split.map!(to!int); auto b = 0; foreach (i; 0..n) if (di[i] < 0) b |= (1 << i); int calcMaxHp(int i) { return 100 + (b & i).popcnt * 100; } int calcHp(int hp, int i, int j) { auto d = di[j]; if (d > 0) { return min(calcMaxHp(i), hp + d); } else return max(0, hp + d); } auto memo = new int[](1 << n); memo[0] = 100; foreach (i; 1..1 << n) { auto maxHp = 0; foreach (j; 0..n) { if (i & (1 << j)) { auto k = i ^ (1 << j); if (memo[k] > 0) { auto hp = calcHp(memo[k], k, j); maxHp = max(maxHp, hp); } } } memo[i] = maxHp; } writeln(memo[$ - 1]); }