#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:134217728")
using namespace std;
const long long MOD = 998244353;
const long long MAXN = 100000 + 100;
int main() {
  int n;
  cin >> n;
  vector<long long> vec(n);
  vector<long long> b(n);
  map<long long, int> cnt;
  vector<int> used(n);
  for (int i = 0; i < n; ++i) {
    scanf("%lld", &vec[i]);
    cnt[vec[i]]++;
  }
  for (int i = 0; i < n; ++i) {
    scanf("%lld", &b[i]);
  }
  for (int i = 0; i < n; ++i) {
    if (cnt[vec[i]] == 1) {
      continue;
    }
    used[i] = 1;
    for (int j = 0; j < n; ++j) {
      if (i == j) {
        continue;
      }
      if ((vec[i] & vec[j]) == vec[j]) {
        used[j] = 1;
      }
    }
  }
  long long res = 0;
  for (int i = 0; i < n; ++i) {
    res += b[i] * used[i];
  }
  cout << res;
  return 0;
}
