#include<bits/stdc++.h>
// #pragma GCC optimize("Ofast,no-stack-protector")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
using namespace std;
#define ll long long
int rangeOR(int &l , int &r, vector<vector<int>> &cnt)
{
int ans = 0;
for(int i = 0 ; i < 20 ; i++)
{
if(cnt[i][r] - cnt[i][l - 1] > 0)
ans|=(1<<i);
}
return ans;
}
void run_case()
{
int n ;
cin>>n ;
vector<ll> a(n + 1) ;
vector<int> b(n + 1);
vector<vector<int>> cnt(20 , vector<int>(n + 1));
for(int i = 1 ; i <= n ; i++)
{
cin>>a[i];
a[i]*=a[i];
a[i]+=a[i - 1];
}
for(int i = 1 ; i <= n; i++)
{
for(int j = 0 ; j < 20 ; j++)
{
cnt[j][i] = cnt[j][i - 1];
}
cin>>b[i];
for(int j = 0 ; j < 20 ; j++)
{
if((1<<j) & b[i])
{
cnt[j][i]++;
}
}
}
ll ans = 0;
vector<vector<int>> pre(20 , vector<int>(n + 1));
for(int i = 1 ;i <= n ;i++)
{
for(int j = 0 ; j < 20 ; j++)
{
pre[j][i] = upper_bound(cnt[j].begin() + i , cnt[j].end() , cnt[j][i - 1]) - cnt[j].begin() - 1;
}
}
for(int i = 1 ; i <= n ; i++)
{
int cur = i;
while(cur <= n)
{
ll val = rangeOR(i , cur , cnt);
int lo = n;
for(int j = 0 ; j <20 ;j ++)
{
if((1<<j) & val)
continue;
lo = min(lo , pre[j][i]);
}
ans+=lower_bound(a.begin() + cur , a.begin() + lo + 1 , a[i - 1] + val*val)-(a.begin() + cur);
cur = lo + 1;
}
}
cout<<ans<<'\n';
}
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t = 1;
// cin>>t;
while (t--)
{
run_case();
}
}
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KLy8gI3ByYWdtYSBHQ0Mgb3B0aW1pemUoIk9mYXN0LG5vLXN0YWNrLXByb3RlY3RvciIpCi8vICNwcmFnbWEgR0NDIHRhcmdldCgic3NlLHNzZTIsc3NlMyxzc3NlMyxzc2U0LHBvcGNudCxhYm0sbW14LGF2eCxhdngyLHR1bmU9bmF0aXZlIikKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKI2RlZmluZSBsbCBsb25nIGxvbmcKaW50IHJhbmdlT1IoaW50ICZsICwgaW50ICZyLCB2ZWN0b3I8dmVjdG9yPGludD4+ICZjbnQpCnsKICAgIGludCBhbnMgPSAwOwogICAgZm9yKGludCBpID0gMCA7IGkgPCAyMCA7IGkrKykKICAgIHsKICAgICAgICBpZihjbnRbaV1bcl0gLSBjbnRbaV1bbCAtIDFdICA+IDApCiAgICAgICAgICAgIGFuc3w9KDE8PGkpOwogICAgfQogICAgcmV0dXJuIGFuczsKfQp2b2lkIHJ1bl9jYXNlKCkKewogICAgaW50IG4gOwogICAgY2luPj5uIDsKICAgIHZlY3RvcjxsbD4gYShuICsgMSkgOwogICAgdmVjdG9yPGludD4gYihuICsgMSk7CiAgICB2ZWN0b3I8dmVjdG9yPGludD4+IGNudCgyMCAsIHZlY3RvcjxpbnQ+KG4gKyAxKSk7CiAgICBmb3IoaW50IGkgPSAxIDsgaSA8PSBuIDsgaSsrKQogICAgewogICAgICAgIGNpbj4+YVtpXTsKICAgICAgICBhW2ldKj1hW2ldOwogICAgICAgIGFbaV0rPWFbaSAtIDFdOwogICAgfQogICAgZm9yKGludCBpID0gMSA7IGkgPD0gbjsgaSsrKQogICAgewogICAgICAgIGZvcihpbnQgaiA9IDAgOyBqIDwgMjAgOyBqKyspCiAgICAgICAgewogICAgICAgICAgICBjbnRbal1baV0gPSBjbnRbal1baSAtIDFdOwogICAgICAgIH0KICAgICAgICBjaW4+PmJbaV07CiAgICAgICAgZm9yKGludCBqID0gMCA7IGogPCAyMCA7IGorKykKICAgICAgICB7CiAgICAgICAgICAgIGlmKCgxPDxqKSAmIGJbaV0pCiAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgIGNudFtqXVtpXSsrOwogICAgICAgICAgICB9CiAgICAgICAgfQogICAgfQogICAgbGwgYW5zID0gMDsKICAgIHZlY3Rvcjx2ZWN0b3I8aW50Pj4gcHJlKDIwICwgdmVjdG9yPGludD4obiArIDEpKTsKICAgIGZvcihpbnQgaSA9IDEgO2kgPD0gbiA7aSsrKQogICAgewogICAgICAgIGZvcihpbnQgaiA9IDAgOyBqIDwgMjAgOyBqKyspCiAgICAgICAgewogICAgICAgICAgICBwcmVbal1baV0gPSB1cHBlcl9ib3VuZChjbnRbal0uYmVnaW4oKSArIGkgLCBjbnRbal0uZW5kKCkgLCBjbnRbal1baSAtIDFdKSAtIGNudFtqXS5iZWdpbigpIC0gMTsKICAgICAgICB9CiAgICB9CiAgICBmb3IoaW50IGkgPSAxIDsgaSA8PSBuIDsgaSsrKQogICAgewogICAgICAgIGludCBjdXIgPSBpOwogICAgICAgIHdoaWxlKGN1ciA8PSBuKQogICAgICAgIHsKICAgICAgICAgICAgbGwgdmFsID0gcmFuZ2VPUihpICwgY3VyICwgY250KTsKICAgICAgICAgICAgaW50IGxvID0gbjsKICAgICAgICAgICAgZm9yKGludCBqID0gMCA7IGogPDIwIDtqICsrKQogICAgICAgICAgICB7CiAgICAgICAgICAgICAgICBpZigoMTw8aikgJiB2YWwpCiAgICAgICAgICAgICAgICAgICAgY29udGludWU7CiAgICAgICAgICAgICAgICBsbyA9IG1pbihsbyAsIHByZVtqXVtpXSk7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgYW5zKz1sb3dlcl9ib3VuZChhLmJlZ2luKCkgKyBjdXIgLCBhLmJlZ2luKCkgKyBsbyArIDEgLCBhW2kgLSAxXSArIHZhbCp2YWwpLShhLmJlZ2luKCkgKyBjdXIpOwogICAgICAgICAgICBjdXIgPSBsbyArIDE7CiAgICAgICAgfQogICAgfQogICAgY291dDw8YW5zPDwnXG4nOwp9CnNpZ25lZCBtYWluKCkKewogICAgaW9zOjpzeW5jX3dpdGhfc3RkaW8oMCk7CiAgICBjaW4udGllKDApOwogICAgY291dC50aWUoMCk7CiAgICBpbnQgdCA9IDE7CiAgICAvLyBjaW4+PnQ7CiAgICB3aGlsZSAodC0tKQogICAgewogICAgICAgIHJ1bl9jYXNlKCk7CiAgICB9CiAgICAKfQ==