#include #include using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rrep(i, n) for (int i = (int)(n)-1; i >= 0; i--) #define rep2(i, a, b) for (int i = (int)a; i < (int)(b); i++) #define rrep2(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--) bitset<65536> dp[2]; int main(){ int N; scanf("%d", &N); if(N >= 16) printf("65535\n"); else{ dp[0].flip(0); rep(i, N){ int A; scanf("%d", &A); dp[(i&1)^1] = 0; rep(j, 16){ rep(k, 65535) if(dp[i&1][k]) dp[(i&1)^1].set(k | A); A = (A>>1) | ((A&1)<<15); } } int now = 65535; while(true){ if(dp[N&1][now]){ printf("%d\n", now); return 0; } now--; } } }