def inp() a=gets.chomp.split(" ").map(&:to_i);(a.size<2)? a[0]:a end def copy(a) Marshal.load(Marshal.dump(a)) end def kaizyo(n)(n < 2)? 1 : (2..n).inject(:*) end def scount(a,b) a.each{|n|b[n]+=1} end n = inp a = inp dp = Array.new(102){Array.new(100001,0)} dp[0][0] = 1 n.times do |d| 100000.times do |f| if(dp[d][f] != nil) if(dp[d][f] == 1) dp[d+1][f+a[d]] = 2 dp[d+1][f] = 1 elsif(dp[d][f] == 2) dp[d+1][f] = 1 end end end end if(n == 1) p a exit end p [100000 - dp[n].reverse.index(2)].max