#include <bits/stdc++.h>
using namespace std;
signed main() {
  long long n;
  cin >> n;
  long long a[n];
  long long b[n];
  unordered_map<long long, long long> mpp, mp;
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
    mp[a[i]]++;
  }
  for (long long i = 0; i < n; i++) {
    cin >> b[i];
  }
  for (long long i = 0; i < n; i++) {
    mpp[a[i]] += b[i];
  }
  long long ans = 0;
  vector<long long> v1, v2;
  for (auto i : mpp) {
    if (mp[i.first] == 1) {
      v1.push_back(i.first);
    } else {
      ans += (i.second);
      v2.push_back(i.first);
    }
  }
  sort(v1.begin(), v1.end());
  reverse(v1.begin(), v1.end());
  for (long long i = 0; i < (v1.size()); i++) {
    for (long long j = 0; j < (v2.size()); j++) {
      long long tt = v1[i] & v2[j];
      if (tt == v1[i]) {
        ans += (mpp[v1[i]]);
        v2.push_back(v1[i]);
        break;
      }
    }
  }
  cout << ans << '\n';
}
