#include <bits/stdc++.h>
using namespace std;
void fast() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
int32_t main() {
  fast();
  long long n;
  cin >> n;
  long long arr[n], brr[n];
  for (long long i = 0; i < n; i++) cin >> arr[i];
  for (long long i = 0; i < n; i++) cin >> brr[i];
  map<long long, long long> m;
  set<long long> s;
  for (long long i = 0; i < n; i++) {
    m[arr[i]]++;
    if (m[arr[i]] >= 2) s.insert(arr[i]);
  }
  long long ans = 0;
  for (long long i = 0; i < n; i++) {
    bool flag = false;
    for (auto val : s) {
      if ((arr[i] | val) == val) {
        flag = true;
        break;
      }
    }
    if (flag) ans += brr[i];
  }
  cout << ans << "\n";
  return 0;
}
