def read_data(): N = int(input()) Ds = list(map(int, input().split())) return N, Ds def solve(N, Ds): global memo, best_score, upper memo = [dict() for i in range(1 << N)] best_score = -1 remain = (1 << N) - 1 level = 100 power = 100 good = [d for d in Ds if d > 0] bad = [d for d in Ds if d < 0] good.sort() bad.sort(reverse=True) upper = upper_limit(level, power, remain, Ds) return dfs(level, power, remain, bad + good) def upper_limit(level, power, remain, Ds): Dds = [d for i, d in enumerate(Ds) if remain & (1 << i)] n_bad = len([1 for d in Dds if d < 0]) return min(power + sum(Dds), level + 100 * n_bad), n_bad def dfs(level, power, remain, Ds): global memo, best_score, upper if power in memo[remain]: return memo[remain][power] if remain == 0: return power if best_score == upper: return best_score limit, n_bad = upper_limit(level, power, remain, Ds) if limit <= best_score: return 0 if n_bad == 0: memo[remain][power] = limit return limit record = 0 for i, d in enumerate(Ds): idx = 1 << i if not (remain & idx) or power + d <= 0: continue if d > 0: if level == power: continue new_power = min(level, power + d) result = dfs(level, new_power, remain - idx, Ds) if result > record: record = result elif d < 0: result = dfs(level + 100, power + d, remain - idx, Ds) if result > record: record = result memo[remain][power] = record if record > best_score: best_score = record return record if __name__ == '__main__': N, Ds = read_data() print(solve(N, Ds))