#include <bits/stdc++.h>
using namespace std;
bool submask(long long int i, long long int j) {
  long long int x = i ^ j;
  for (long long int bit = 0; bit < 60; bit++) {
    if (x & (1LL << bit)) {
      if (i & (1LL << bit))
        continue;
      else
        return false;
    }
  }
  return true;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int n;
  cin >> n;
  vector<long long int> a(n), b(n);
  map<long long int, long long int> mp;
  for (auto &i : a) {
    cin >> i;
    mp[i]++;
  }
  for (auto &i : b) cin >> i;
  vector<long long int> vis(n, 0);
  vector<long long int> v;
  for (auto i : mp) {
    if (i.second > 1) v.push_back(i.first);
  }
  long long int ans = 0;
  for (long long int i : v) {
    for (long long int j = 0; j < n; j++) {
      if (submask(i, a[j]) and !vis[j]) vis[j] = 1, ans += b[j];
    }
  }
  cout << ans << endl;
}
