# Here your code ! n = gets.to_i S = 1 << n D = gets.split.map(&:to_i) HP = Array.new(S, 0) HPMAX = Array.new(S, 100) HP[0] = 100 # HP[s]はsのモンスターに出会った後の残HP HPMAX[0] = 100 # HPMAX[s]はsのモンスターに出会った後の最大HP S.times do |s| n.times do |i| mask = 1 << i if s & mask > 0 && D[i] < 0 HPMAX[s] += 100 end end next if HP[s] <= 0 n.times do |i| mask = 1 << i if s & mask == 0 if D[i] > 0 hp = HP[s] + D[i] < HPMAX[s] ? HP[s] + D[i] : HPMAX[s] other = HP[s | mask] HP[s | mask] = [hp, other].max else hp = HP[s] + D[i] other = HP[s | mask] HP[s | mask] = [hp, other].max end end end end puts HP[S - 1]