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 ** N dp = Array.new(L, 0) L.times do |mask| N.times do |i| next if mask[i] != 0 nmask = mask | (1 << i) a = A[i] 16.times do |j| a = shift(a) nv = dp[mask] | a dp[nmask] = nv if dp[nmask] < nv end end end pp dp[L - 1]