#include <bits/stdc++.h>
using namespace std;
const int maxn = 7e3 + 1;
map<long long, long long> p;
set<int> s;
long long a[maxn], b[maxn], ans;
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) scanf("%lld", &a[i]), p[a[i]]++;
  for (int i = 1; i <= n; ++i) scanf("%lld", &b[i]);
  for (auto it : p) {
    if (it.second <= 1) continue;
    for (int i = 1; i <= n; ++i)
      if ((it.first & a[i]) == a[i]) s.insert(i);
  }
  for (auto it : s) ans += b[it];
  printf("%lld\n", ans);
}
