local band = bit.band local n = io.read("*n") local a = {} for i = 1, n do a[i] = io.read("*n") end local asum = {a[1]} for i = 2, n do asum[i] = asum[i - 1] + a[i] end local all = {} for i = 1, 1024 * n do all[i] = false end local dp1, dp2 = {}, {} dp1 = {true} dp2 = {false} for i = 2, 1024 do dp1[i] = false dp2[i] = false end -- print(collectgarbage("count")) local ret = 1 all[asum[n] + 1] = true local dpd1, dpd2 = {}, {} for i = 1, n do for j = 1, 1024 do dpd1[j] = false dpd2[j] = false end local ai = a[i] for j = 1, 1024 do if dp1[j] or dp2[j] then local dst1 = band(j - 1, ai) + 1 local dst2 = ((j - 1 + ai) % 1024) + 1 dpd1[dst1] = true dpd2[dst2] = true end end for j = 1, 1024 do dp1[j] = dpd1[j] dp2[j] = dpd2[j] end for j = 1, 1024 do local v = j + asum[n] - asum[i] if dp1[j] and not all[v] then ret = ret + 1 all[v] = true end end print(ret) end