#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int n;
  cin >> n;
  vector<long long> a(n), b(n);
  for (auto& i : a) cin >> i;
  for (auto& i : b) cin >> i;
  map<long long, int> m;
  for (int i = 0; i < n; i++) m[a[i]]++;
  vector<pair<long long, long long>> p1, p2;
  for (int i = 0; i < n; i++)
    if (m[a[i]] > 1)
      p1.push_back(make_pair(a[i], b[i]));
    else
      p2.push_back(make_pair(a[i], b[i]));
  for (int i = 0; i < p2.size(); i++)
    for (int j = 0; j < p1.size(); j++)
      if (p1[j].first > p2[i].first &&
          p1[j].first - (p1[j].first ^ p2[i].first) == p2[i].first) {
        p1.push_back(p2[i]);
        break;
      }
  long long sum = 0;
  for (auto p : p1) sum += p.second;
  cout << sum << endl;
  return 0;
}
