local bor = bit.bor local n = io.read("*n") local a = {} for i = 1, n do a[i] = io.read("*n") end if 16 <= n then print(65535) os.exit() end local dp1, dp2 = {}, {} for i = 1, 65536 do dp1[i] = false end dp1[1] = true for i = 1, n do local src = i % 2 == 1 and dp1 or dp2 local dst = i % 2 == 1 and dp2 or dp1 for j = 1, 65536 do dst[j] = false end local ai = a[i] for j = 1, 65536 do if src[j] then for k = 1, 16 do local z = bor(j - 1, ai) dst[z + 1] = true ai = math.floor(ai / 2) + (ai % 2) * 32768 end end end end local tbl = n % 2 == 1 and dp2 or dp1 for j = 65536, 1, -1 do if tbl[j] then print(j - 1) os.exit() end end