#include <bits/stdc++.h>
using namespace std;
pair<long long, long long> a[10000];
set<long long> s;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long i, n, ans = 0, j;
  cin >> n;
  for (i = 0; i < n; i++) cin >> a[i].first;
  for (i = 0; i < n; i++) cin >> a[i].second;
  sort(a, a + n, greater<pair<long long, long long>>());
  for (i = 1; i < n; i++)
    if (a[i].first == a[i - 1].first) s.insert(a[i].first);
  for (i = 0; i < n; i++)
    for (long long j : s)
      if (((j ^ a[i].first) & a[i].first) == 0) {
        ans += a[i].second;
        break;
      }
  cout << ans;
  return 0;
}
