#include <bits/stdc++.h>
using namespace std;
long long power(long long x, long long y, long long p) {
  long long res = 1;
  x = x % p;
  while (y > 0) {
    if (y & 1) res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
const long long mod = 1e9 + 7;
bool is(long long n) { return (ceil(log2(n)) == floor(log2(n))); }
bool q(const pair<long long, long long> &a,
       const pair<long long, long long> &b) {
  if (a.second == b.second) return a.first < b.first;
  return a.second < b.second;
}
bool q2(const pair<long long, long long> &a,
        const pair<long long, long long> &b) {
  if (a.first == b.first) return a.second > b.second;
  return a.first > b.first;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long n;
  cin >> n;
  long long a[n], b[n];
  map<long long, long long> m;
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
    m[a[i]]++;
  }
  for (long long i = 0; i < n; i++) cin >> b[i];
  vector<long long> v, v2;
  if (n == 1) {
    cout << 0;
    return 0;
  }
  for (long long i = 0; i < n; i++) {
    if (m[a[i]] > 1) v.push_back(i);
  }
  for (auto i : m) {
    if (i.second > 1) v2.push_back(i.first);
  }
  long long x = 0;
  for (long long i = 0; i < n; i++) {
    if (m[a[i]] == 1) {
      for (auto x : v2) {
        if ((a[i] & (a[i] ^ x)) == 0) {
          v.push_back(i);
          break;
        }
      }
    }
  }
  long long ans = 0;
  for (auto i : v) {
    ans += b[i];
  }
  cout << ans << endl;
  return 0;
}
