#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<long long int> v1(n + 1, 0);
  vector<long long int> v2(n + 1, 0);
  map<long long int, long long int> mp;
  for (int i = 1; i <= n; i++) {
    long long int a;
    cin >> a;
    v1[i] = a;
    mp[a] += 1;
  }
  for (int i = 1; i <= n; i++) {
    long long int b;
    cin >> b;
    v2[i] = b;
  }
  long long int ans = 0;
  for (int i = 1; i <= n; i++) {
    for (auto pr : mp) {
      if (pr.second > 1) {
        if ((v1[i] | pr.first) == pr.first) {
          ans += v2[i];
          break;
        }
      }
    }
  }
  cout << ans << "\n";
  return 0;
}
