#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  long long a[n], b[n], sum = 0;
  map<long long, long long> m;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    m[a[i]]++;
  }
  for (int i = 0; i < n; i++) {
    cin >> b[i];
  }
  vector<long long> v;
  for (auto i : m) {
    if (i.second >= 2) v.push_back(i.first);
  }
  for (int i = 0; i < n; i++) {
    if (m[a[i]] >= 2) {
      sum += b[i];
    } else {
      for (auto j : v) {
        if ((j | a[i]) == j) {
          sum += b[i];
          break;
        }
      }
    }
  }
  cout << sum;
}
