#include <bits/stdc++.h>
using namespace std;
bool check(string s, string t) {
  for (int i = 0; i < 60; i++) {
    if (s[i] == '0' && t[i] == '1') return false;
  }
  return true;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  int64_t a[n], b[n];
  map<int64_t, int64_t> times;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    times[a[i]]++;
  }
  for (int i = 0; i < n; i++) cin >> b[i];
  vector<string> bin;
  for (int i = 0; i < n; i++) {
    int64_t x = a[i];
    string s = "";
    while (x) {
      int64_t temp = x & 1;
      x = x >> 1;
      s += char(temp + '0');
    }
    int64_t sz = s.size();
    for (int64_t i = sz; i < 60; i++) s += '0';
    reverse(s.begin(), s.end());
    bin.push_back(s);
  }
  int64_t ans = 0;
  vector<int64_t> p;
  for (int i = 0; i < n; i++) {
    if (times[a[i]] > 1) {
      p.push_back(i);
    }
  }
  for (int i = 0; i < n; i++) {
    if (times[a[i]] > 1) {
      ans += b[i];
      continue;
    }
    bool flag = 0;
    for (int j = 0; j < p.size(); j++) {
      if (check(bin[p[j]], bin[i])) {
        flag = 1;
        break;
      }
    }
    if (flag) ans += b[i];
  }
  cout << ans;
  return 0;
}
