#include <bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimization("O2")
#pragma GCC optimization("unrolled-loops")
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const long long base = 1e9 + 7;
const long long oo = 1e6 + 10;
const long long gh = 1e3 + 3;
const long long inf = 1e15 + 5;
long long n, m, k, q;
long long a[oo];
long long b[oo];
long long f[oo];
long long ok[oo];
void input() {
  cin >> n;
  for (long long i = 1; i <= n; i++) cin >> a[i];
  for (long long i = 1; i <= n; i++) cin >> b[i];
}
void cre() {
  for (long long i = 1; i <= n; i++) {
    for (long long j = 1; j <= n; j++) {
      if ((a[i] & a[j]) == a[i]) {
        if (a[i] == a[j] && i != j) {
          ok[j] = 1;
        }
      }
    }
  }
}
void solve() {
  cre();
  long long ans = 0;
  for (long long i = 1; i <= n; i++) {
    for (long long j = 1; j <= n; j++) {
      if (ok[j] && (a[i] & a[j]) == a[i]) {
        ans += b[i];
        break;
      }
    }
  }
  cout << ans;
}
void ouput() {}
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  if (ifstream("test.txt")) {
    freopen("test.txt", "r", stdin);
  } else if (ifstream(""
                      ".inp")) {
    freopen(
        ""
        ".inp",
        "r", stdin);
    freopen(
        ""
        ".out",
        "w", stdout);
  }
  long long t = 1;
  while (t--) {
    input();
    solve();
    ouput();
  }
}
