#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
const long long mod = (1e+9) + 7;
const long long sz = 2e5 + 9;
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long power(long long a, long long b, long long m = mod) {
  long long res = 1;
  while (b > 0) {
    if (b & 1) res = (res * a) % m;
    b = b >> 1;
    a = (a * a) % m;
  }
  return res;
}
void solve() {
  long long n;
  cin >> n;
  map<long long, long long> m;
  long long a[n], b[n];
  for (long long i = 0; i < n; i++) cin >> a[i], m[a[i]]++;
  for (long long i = 0; i < n; i++) cin >> b[i];
  long long ans = 0;
  set<long long> s;
  for (long long i = 0; i < n; i++) {
    if (m[a[i]] > 1) ans += b[i], s.insert(a[i]);
  }
  for (long long i = 0; i < n; i++) {
    if (m[a[i]] == 1) {
      long long c = 0;
      for (auto xx : s) {
        long long cc = 1;
        for (long long j = 60; j >= 0; j--) {
          if (((a[i] >> j) & 1LL) == 1 && ((xx >> j) & 1LL) == 0) {
            cc = 0;
            break;
          }
        }
        if (cc) {
          c = 1;
          break;
        }
      }
      if (c) {
        ans += b[i];
      }
    }
  }
  cout << ans << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  clock_t beg = clock();
  solve();
  clock_t end = clock();
  fprintf(stderr, "%.3f sec, Copyright %c 2019 Skyscraper. \n",
          double(end - beg) / CLOCKS_PER_SEC, 184);
  return 0;
}
