#include <bits/stdc++.h>
using namespace std;
const int MAXN = 7007;
const int INF = 0x3f3f3f3f;
map<long long, int> cnt;
long long a[MAXN];
int b[MAXN];
int vis[MAXN];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
    cnt[a[i]]++;
  }
  for (int i = 1; i <= n; ++i) {
    cin >> b[i];
  }
  long long ans = 0;
  for (auto &u : cnt) {
    if (u.second >= 2) {
      for (int i = 1; i <= n; ++i) {
        if (!vis[i]) {
          if ((u.first | a[i]) == u.first) {
            ans += b[i];
            vis[i] = 1;
          }
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}
