#include <bits/stdc++.h>
using namespace std;
const long long N = 11234;
void scan(long long &n) { scanf("%lld", &n); }
void scan(long long &n, long long &m) { scanf("%lld%lld", &n, &m); }
void scan(vector<long long> &v) {
  long long n = v.size();
  for (long long i = 0; i < n; i++) scanf("%lld", &v[i]);
}
vector<long long> adj[N];
long long vis[N], lvl[N], lvl1[N], vis1[N];
void edge(long long u, long long v) {
  adj[u].push_back(v);
  adj[v].push_back(u);
}
long long good[N];
int main() {
  long long n;
  scan(n);
  long long i, res = 0, cnt = 0;
  vector<long long> a(n), b(n);
  scan(a);
  scan(b);
  map<long long, long long> mp, last;
  vector<pair<long long, long long> > v;
  for (i = 0; i < n; i++) {
    if (mp[a[i]]) {
      good[last[a[i]]] = 1;
      good[i] = 1;
    }
    mp[a[i]]++;
    last[a[i]] = i;
  }
  for (i = 0; i < n; i++) {
    for (long long j = 0; j < n; j++) {
      if (i == j) continue;
      if (good[j] and (a[j] & a[i]) == a[i]) {
        res += b[i];
        break;
      }
    }
  }
  cout << res << endl;
  return 0;
}
