#include <bits/stdc++.h>
using namespace std;
map<long long, int> m;
const int maxn = 7005;
int usable[maxn], b[maxn];
long long a[maxn];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%lld", &a[i]);
    m[a[i]]++;
  }
  for (int i = 1; i <= n; i++) scanf("%d", &b[i]);
  for (auto i = m.begin(); i != m.end(); i++) {
    long long ai = i->first;
    int bi = i->second;
    if (bi > 1) {
      for (int j = 1; j <= n; j++) {
        if (!usable[j] and (a[j] | ai) == ai) usable[j] = 1;
      }
    }
  }
  long long ans = 0;
  for (int i = 1; i <= n; i++)
    if (usable[i]) ans += b[i];
  cout << ans;
}
