#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
map<long long, vector<long long> > M;
long long a[maxn], b[maxn];
int n;
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = 1; i <= n; i++) cin >> b[i], M[a[i]].push_back(b[i]);
  vector<long long> ok;
  long long ans = 0;
  for (auto A : M) {
    if (A.second.size() >= 2) {
      ok.push_back(A.first);
      for (int i = 0; i < A.second.size(); i++) ans += A.second[i];
    }
  }
  for (auto B : M) {
    if (B.second.size() == 1) {
      for (auto A : ok) {
        if ((A & B.first) == B.first) {
          ans += B.second[0];
          break;
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}
