#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
const int MOD = 1e9;
const int N = 1e6 + 5;
const ll oo = 9e18;
const int M = 501;
ll a[N];
map<ll, int> cnt;
ll b[N];
bool used[N];
void solve() {
  int n;
  cin >> n;
  ll ind = -1;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
    cnt[a[i]]++;
  }
  for (int i = 1; i <= n; ++i) {
    cin >> b[i];
  }
  for (auto x : cnt) {
    if (x.second <= 1) continue;
    for (int i = 1; i <= n; ++i) {
      if ((x.first | a[i]) == x.first) used[i] = 1;
    }
  }
  ll ans = 0;
  for (int i = 1; i <= n; ++i) {
    if (used[i]) ans += b[i];
  }
  cout << ans;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  while (t--) solve();
}
