#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const long long MOD2 = 998244353;
const long long N = 2e5 + 5;
const long double pi = 3.14159265359;
long long a[N], b[N], ans, n, vis[N];
map<long long, long long> cnt;
vector<long long> v;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  for (long long i = 0; i < n; i++) cin >> a[i], cnt[a[i]]++;
  for (long long i = 0; i < n; i++) cin >> b[i];
  for (long long i = 0; i < n; i++)
    if (cnt[a[i]] > 1) ans += b[i], vis[i] = 1, v.push_back(a[i]);
  for (long long i = 0; i < n; i++)
    if (!vis[i])
      for (auto j : v)
        if ((a[i] & j) == a[i]) {
          ans += b[i];
          break;
        }
  cout << ans << "\n";
  return 0;
}
