#include <bits/stdc++.h>
using namespace std;
const long long N = 1e6 + 10;
const long long INF = 1e9 + 10;
const long long MOD = 1e9 + 7;
bool setBit(long long n, long long k) { return n & (1LL << k); }
void solve() {
  long long n;
  cin >> n;
  vector<long long> a(n + 1), b(n + 1);
  map<long long, long long> mp;
  for (long long i = 1; i <= n; i++) {
    cin >> a[i];
    mp[a[i]]++;
  }
  for (long long i = 1; i <= n; i++) cin >> b[i];
  long long ans = 0;
  vector<long long> v;
  for (long long i = 1; i <= n; i++) {
    if (mp[a[i]] > 1) ans += b[i];
  }
  for (auto u : mp) {
    if (u.second > 1) v.push_back(u.first);
  }
  if ((long long)v.size() == 0) {
    cout << "0\n";
    return;
  }
  for (long long i = 1; i <= n; i++) {
    if (mp[a[i]] == 1) {
      for (auto u : v) {
        long long flg = 1;
        for (long long j = 0; j < 60; j++) {
          if (setBit(u, j) == 0 && setBit(a[i], j) == 1) flg = 0;
        }
        if (flg) {
          ans += b[i];
          break;
        }
      }
    }
  }
  cout << ans;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  long long t = 1;
  while (t--) {
    solve();
  }
}
