#include <bits/stdc++.h>
using namespace std;
map<long long int, long long int> m;
vector<long long int> visited(7007, 0), v;
int main() {
  long long int n;
  cin >> n;
  long long int a[n], b[n];
  for (long long int i = 0; i < n; i++) {
    cin >> a[i];
    m[a[i]]++;
  }
  for (long long int i = 0; i < n; i++) cin >> b[i];
  long long int sum = 0;
  for (long long int i = 0; i < n; i++) {
    if (m[a[i]] >= 2) {
      sum += b[i];
      visited[i] = 1;
      v.push_back(a[i]);
    }
  }
  for (long long int i = 0; i < v.size(); i++) {
    for (long long int j = 0; j < n; j++) {
      if (!visited[j]) {
        if ((a[j] | v[i]) == v[i]) {
          sum += b[j];
          visited[j] = 1;
        }
      }
    }
  }
  cout << sum << endl;
  return 0;
}
