#include <bits/stdc++.h>
using namespace std;
long long x, y, z, i, j, n, m, k, s1, s2, s3, s4, s5, s6, mod, l, r, t, maxx,
    minn, sx, so, sum, ans, puk, par, chi, sz, choc1, choc2, len, depth;
double u, v, w, x1, x2, x3, x4, z1, z2, z3, h, huh;
string s;
string q;
string p;
string sq[1045];
vector<long long> vc;
long long dp[1045][1045];
long long tmp[300045];
pair<long long, long long> aa[100045];
long long a[1000045];
long long b[200045];
map<long long, long long> mp;
int main() {
  scanf("%lld", &n);
  x = 0;
  for (i = 1; i <= n; i++) {
    scanf("%lld", &a[i]);
    mp[a[i]]++;
    if (mp[a[i]] == 2) {
      vc.push_back(a[i]);
    }
  }
  y = 0;
  for (i = 1; i <= n; i++) {
    scanf("%lld", &b[i]);
    for (j = 0; j < vc.size(); j++) {
      if ((a[i] & vc[j]) == a[i]) {
        y += b[i];
        break;
      }
    }
  }
  printf("%lld", y);
}
