#include <bits/stdc++.h>
using namespace std;
template <class T>
inline T updmax(T& a, T b) {
  return a = max(a, b);
}
template <class T>
inline T updmin(T& a, T b) {
  return a = min(a, b);
}
class Solution {
 public:
  void solve() {
    int n;
    cin >> n;
    vector<long long> a(n, 0);
    vector<long long> b(n, 0);
    for (int i = 0; i < n; i++) cin >> a[i];
    for (int i = 0; i < n; i++) cin >> b[i];
    vector<pair<long long, long long>> ab(n);
    for (int i = 0; i < n; i++) ab[i] = make_pair(a[i], b[i]);
    sort(ab.begin(), ab.end());
    vector<long long> ok;
    for (int i = 0; i < n - 1; i++)
      if (ab[i].first == ab[i + 1].first) ok.push_back(ab[i].first);
    ok.erase(unique(ok.begin(), ok.end()), ok.end());
    long long ret = 0;
    for (int i = 0; i < n; i++) {
      for (auto x : ok) {
        if ((x & a[i]) == a[i]) {
          ret += b[i];
          break;
        }
      }
    }
    cout << ret << "\n";
    return;
  };
};
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  Solution solution;
  solution.solve();
  return 0;
}
