#include <bits/stdc++.h>
using namespace std;
const long long maxn = 110;
const long long mod = 1000000007;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  long long n;
  cin >> n;
  map<long long, long long> cnt;
  vector<long long> a(n), b(n);
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
    cnt[a[i]]++;
  }
  for (long long i = 0; i < n; i++) cin >> b[i];
  long long ans = 0;
  vector<long long> ans_vec;
  for (auto i : a) {
    if (cnt[i] > 1) ans_vec.push_back(i);
  }
  if (ans_vec.empty()) {
    cout << 0 << "\n";
    return 0;
  }
  for (long long i = 0; i < n; i++) {
    bool flag = false;
    for (auto j : ans_vec) {
      if ((j | a[i]) == j) flag = true;
    }
    if (flag) ans += b[i];
  }
  cout << ans << "\n";
  return 0;
}
