#include <bits/stdc++.h>
using namespace std;
class myClass {
 public:
  long long first;
  long long second;
  int bits;
};
bool myCompare(long long a, long long b) { return ((a & b) == a); }
void solve() {
  long long n;
  cin >> n;
  pair<long long, long long> p[n];
  map<long long, long long> m;
  for (int i = 0; i < n; i++) {
    cin >> p[i].first;
    m[p[i].first]++;
  }
  for (int i = 0; i < n; i++) {
    cin >> p[i].second;
    if (m[p[i].first] <= 1) m.erase(p[i].first);
  }
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    if (m.count(p[i].first)) {
      ans += p[i].second;
    } else {
      for (auto itr = m.begin(); itr != m.end(); itr++) {
        if (myCompare(p[i].first, (*itr).first)) {
          ans += p[i].second;
          m[p[i].first]++;
          break;
        }
      }
    }
  }
  cout << ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
