#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e9 + 7;
long long a[7003], b[7003];
signed main() {
  std::ios::sync_with_stdio(0);
  std::cin.tie(0);
  ;
  long long n;
  cin >> n;
  set<long long> s1, s2;
  for (long long i = 0; i < n; i++) cin >> a[i];
  for (long long i = 0; i < n; i++) cin >> b[i];
  for (long long i = 0; i < n; i++) {
    if (s1.count(a[i]))
      s2.insert(a[i]);
    else
      s1.insert(a[i]);
  }
  vector<long long> v;
  for (auto s : s2) v.push_back(s);
  long long ans = 0;
  for (long long i = 0; i < n; i++) {
    for (auto x : v) {
      if ((a[i] | x) == x) {
        ans += b[i];
        break;
      }
    }
  }
  cout << ans << endl;
}
