#include<bits/stdc++.h>usingnamespace std;#define _rep(i, a, b) for (int i = (a); i <= (b); ++i)#define _rev(i, a, b) for (int i = (a); i >= (b); --i)#define _for(i, a, b) for (int i = (a); i < (b); ++i)#define _rof(i, a, b) for (int i = (a); i > (b); --i)#define oo 0x3f3f3f3f#define ll long long#define db double#define eps 1e-8#define bin(x) cout << bitset<10>(x) << endl;#define what_is(x) cerr << #x << " is " << x << endl#define met(a, b) memset(a, b, sizeof(a))#define all(x) x.begin(), x.end()#define pii pair<int, int>
ll nxt(){
ll ret;scanf("%lld",&ret);return ret;}constint maxn =7000+10;struct student
{
ll a, b;booloperator<(const student &c){return a > c.a;}} q[maxn];
map<ll,int> tot, id;
set<int> res;signedmain(){int n =nxt();_rep(i,1, n) q[i].a =nxt(), tot[q[i].a]++;_rep(i,1, n) q[i].b =nxt();
ll ans =0;for(auto t: tot){if(t.second <=1)continue;_rep(i,1, n){if((q[i].a & t.first)== q[i].a)res.insert(i);}}for(auto i:res)ans += q[i].b;
cout << ans << endl;}