def f(n, weights) sum = weights.inject(0, :+) return false if sum.odd? dp = {} g = lambda{|i, w| return true if w == 0 return false if i >= n || w < 0 # nilは偽なのでhash||=じゃダメ return dp[[i,w]] if !dp[[i,w]].nil? dp[[i,w]] = g.(i+1, w) || g.(i+1, w-weights[i]) } g.(0, sum/2) end N = gets.to_i W = gets.split.take(N).map(&:to_i).sort puts f(N, W) ? :possible : :impossible