N = gets.to_i A = gets.split.map(&:to_i) def shift(x) x / 2 + 2 ** 15 * (x % 2) end if N >= 16 puts 2 ** 16 - 1 exit end L = 2 ** 16 dp = Array.new(N + 1) { Array.new(L, false) } dp[0][0] = true 1.upto(N) do |i| L.times do |j| next if not dp[i - 1][j] a = A[i - 1] 16.times do nv = j | a dp[i][nv] |= dp[i - 1][j] a = shift(a) end end end pp dp[N].rindex(true)