#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e5 + 9;
const long long mod = 1e9 + 7;
vector<bool> prime(MAX, 1);
vector<int> spf(MAX, 1), primes;
void sieve() {
  prime[0] = prime[1] = 0;
  spf[2] = 2;
  for (long long i = 4; i < MAX; i += 2) {
    spf[i] = 2;
    prime[i] = 0;
  }
  primes.push_back(2);
  for (long long i = 3; i < MAX; i += 2) {
    if (prime[i]) {
      primes.push_back(i);
      spf[i] = i;
      for (long long j = i * i; j < MAX; j += i) {
        prime[j] = 0;
        if (spf[j] == 1) {
          spf[j] = i;
        }
      }
    }
  }
}
template <typename T>
void in(T &x) {
  cin >> x;
}
template <typename T, typename U>
void in(T &x, U &y) {
  cin >> x >> y;
}
template <typename T, typename U, typename V>
void in(T &x, U &y, V &z) {
  cin >> x >> y >> z;
}
template <typename T>
void ps(T x) {
  cout << x << " ";
}
template <typename T>
void ps(const vector<T> &x, int n) {
  for (int i = 0; i < n; i++) {
    cout << x[i];
    (i == n - 1) ? cout << '\n' : cout << " ";
  }
}
template <typename T>
void pl(T x) {
  cout << x << '\n';
}
template <typename T>
void pl(const vector<T> &x, int n) {
  for (int i = 0; i < n; i++) {
    cout << x[i] << "\n";
  }
}
template <typename T>
T power(T a, T b) {
  T res = 1;
  while (b) {
    if (b & 1) {
      res = res * a;
    }
    a = a * a;
    b = b >> 1;
  }
  return res;
}
template <typename T>
T power(T a, T b, T m) {
  T res = 1;
  while (b) {
    if (b & 1) {
      res = (res * a) % m;
    }
    a = (a * a) % m;
    b = b >> 1;
  }
  return res % m;
}
void virtual_main() {}
void real_main() {
  long long n, res = 0LL;
  cin >> n;
  vector<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> take_sure;
  for (auto x : m) {
    if (x.second > 1) {
      take_sure.push_back(x.first);
    }
  }
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < take_sure.size(); j++) {
      if (((a[i]) & (take_sure[j])) == a[i]) {
        res += b[i];
        break;
      }
    }
  }
  pl(res);
}
signed main() {
  ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  virtual_main();
  long long test_cases = 1;
  for (long long i = 1; i <= test_cases; i++) {
    real_main();
  }
  return 0;
}
