#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const double pi = acos(-1);
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long qpow(long long a, long long b, long long c) {
  long long t = 1;
  while (b) {
    if (b & 1) t = t * a % c;
    a = a * a % c;
    b >>= 1;
  }
  return t;
}
long long inv(long long x) { return qpow(x, mod - 2, mod); }
int test = 1;
const int maxn = 5 + 7000;
const int maxm = 5 + 1e6;
int n;
long long a[maxn], b[maxn];
int book[100];
map<long long, int> mp;
bool check(long long x) {
  for (int i = 0; i <= 60; i++) {
    if (x >> i & 1 == 1 && book[i] == 1) return false;
  }
  return true;
}
vector<long long> v;
int main() {
  while (test--) {
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) {
      scanf("%lld", &a[i]);
      mp[a[i]]++;
    }
    for (int i = 1; i <= n; i++) {
      scanf("%lld", &b[i]);
    }
    map<long long, int>::iterator it = mp.begin();
    while (it != mp.end()) {
      if (it->second > 1) {
        for (int j = 0; j <= 60; j++) {
          if ((it->first) >> j & 1 == 0) book[j] = 1;
        }
        v.push_back(it->first);
      }
      it++;
    }
    long long ans = 0;
    for (int i = 1; i <= n; i++) {
      bool ok = false;
      for (int j = 0; j < v.size(); j++) {
        if (a[i] == v[j]) {
          ok = true;
          break;
        }
        if ((a[i] | v[j]) <= v[j]) ok = true;
      }
      if (ok) ans += b[i];
    }
    printf("%lld\n", ans);
  }
  return 0;
}
