#include <bits/stdc++.h>
using namespace std;
long long a[10000], b[10000];
long long res[10000];
int val[10000];
map<long long, int> mp;
int main() {
  int n;
  long long ans = 0;
  int len = 0;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    mp[a[i]]++;
    if (mp[a[i]] == 2) res[++len] = a[i];
  }
  for (int i = 1; i <= n; i++) {
    cin >> b[i];
  }
  for (int i = 1; i <= len; i++) {
    for (int j = 1; j <= n; j++) {
      if ((res[i] & a[j]) == a[j]) val[j] = 1;
    }
  }
  for (int i = 1; i <= n; i++) {
    ans += val[i] * b[i];
  }
  cout << ans << endl;
  return 0;
}
