#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<pair<ll, int>> a(n);
  map<ll, int> f;
  for (auto& i : a) cin >> i.first, f[i.first]++;
  ;
  for (auto& i : a) cin >> i.second;
  ll sum = 0;
  vector<ll> v;
  for (auto& x : f)
    if (x.second > 1) {
      v.push_back(x.first);
    }
  for (int i = 0; i < n; i++) {
    for (ll& x : v)
      if ((x & a[i].first) == a[i].first) {
        sum += a[i].second;
        break;
      }
  }
  cout << sum << '\n';
  return 0;
}
