#pragma GCC optimization ("unroll-loops")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4")
//based on blog about count A[i] & A[j] = 0
#include <bits/stdc++.h>
using namespace std;
const int N = 100002 /** enough?! **/, K = 30, L = 10, MOD = 1000000007;
void solve() {
int n = 8;
scanf("%d", &n);
vector <int> a(n);
vector <bitset <N> > bit(K);
vector <vector <bitset <N> > > pre(K/L+1, vector <bitset<N> > (1 << L));
//for (int i = 0; i < K; ++i) {
// bit[i].reset();
//}
for (int i = 0; i < n; ++i) {
// a[i] = i + 1;
scanf("%d", &a[i]);
for (int b = 0; b < K; ++b) {
if ((a[i] >> b) & 1) {
bit[b].set(i);
}
}
}
vector <int> idx(1 << L, -1);
for (int i = 0; i < L; ++i) {
idx[1 << i] = i;
}
for (int i = 0; i < K; i += L) {
int S = i, E = min(K, i + L);
for (int j = 1; j < 1 << (E - S); ++j) {
//assert (idx[j & -j] != -1);
pre[i / L][j] = pre[i / L][j - (j & -j)] | bit[S + idx[j & -j]];
/* for (int k = 0; k < E - S; ++k) {
if (j & (1 << k)) {
pre[i / L][j] |= bit[S + k];
}
}*/
}
}
long long what = 0;
for (int w = 0; w < n; ++w) {
bitset <N> cur;
for (int i = 0; i < K; i += L) {
cur |= pre[i / L][(a[w] >> i) & ((1 << L) - 1)];
}
what += n - cur.count();
}
cout << what / 2 << '\n'; //can get rid of /2 by updating pre online and check bitsets till w-th index, but that does not really improve
return;
//O(N*D/L*N/Word+2^L*N/Word*(D/L)) -> L = 10 -> 512*10^5
if (0) { int ans = 0, tmp = 0;
for (int i = 0; i < n; ++i) {
bitset <N> all;
for (int b = 0; b < K; ++b) { //b += L
if ((a[i] >> b) & 1) {
all |= bit[b];
}
}
tmp += n - all.count();
for (int j = i + 1; j < n; ++j) {
if ((a[i] & a[j]) == 0) {
++ans;
}
}
}
cout << ' ' << ans << ' ' << tmp / 2 << '\n'; }
}
int main() {
// freopen("input.txt", "r", stdin);
// freopen("ipn.inp", "r", stdin); freopen("ipn.out", "w", stdout);
// ios::sync_with_stdio(false); cin.tie(0);
int t = 1;
//scanf("%d", &t);
while (t --> 0) {
solve();
}
return 0;
}
I3ByYWdtYSBHQ0Mgb3B0aW1pemF0aW9uICgidW5yb2xsLWxvb3BzIikKI3ByYWdtYSBHQ0Mgb3B0aW1pemUoIk9mYXN0IikKI3ByYWdtYSBHQ0MgdGFyZ2V0KCJzc2Usc3NlMixzc2UzLHNzc2UzLHNzZTQiKQovL2Jhc2VkIG9uIGJsb2cgYWJvdXQgY291bnQgQVtpXSAmIEFbal0gPSAwCiNpbmNsdWRlIDxiaXRzL3N0ZGMrKy5oPgoKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCmNvbnN0IGludCBOID0gMTAwMDAyIC8qKiBlbm91Z2g/ISAqKi8sIEsgPSAzMCwgTCA9IDEwLCBNT0QgPSAxMDAwMDAwMDA3OwoKdm9pZCBzb2x2ZSgpIHsKICAgIGludCBuID0gODsKICAgIHNjYW5mKCIlZCIsICZuKTsKICAgIHZlY3RvciA8aW50PiBhKG4pOwogICAgdmVjdG9yIDxiaXRzZXQgPE4+ID4gYml0KEspOwogICAgdmVjdG9yIDx2ZWN0b3IgPGJpdHNldCA8Tj4gPiA+IHByZShLL0wrMSwgdmVjdG9yIDxiaXRzZXQ8Tj4gPiAoMSA8PCBMKSk7CiAgICAvL2ZvciAoaW50IGkgPSAwOyBpIDwgSzsgKytpKSB7CiAgICAvLyAgICBiaXRbaV0ucmVzZXQoKTsKICAgIC8vfQogICAgZm9yIChpbnQgaSA9IDA7IGkgPCBuOyArK2kpIHsKICAgICAgIC8vIGFbaV0gPSBpICsgMTsKICAgICAgICBzY2FuZigiJWQiLCAmYVtpXSk7CiAgICAgICAgZm9yIChpbnQgYiA9IDA7IGIgPCBLOyArK2IpIHsKICAgICAgICAgICAgaWYgKChhW2ldID4+IGIpICYgMSkgewogICAgICAgICAgICAgICAgYml0W2JdLnNldChpKTsKICAgICAgICAgICAgfQogICAgICAgIH0KICAgIH0KICAgIHZlY3RvciA8aW50PiBpZHgoMSA8PCBMLCAtMSk7CiAgICBmb3IgKGludCBpID0gMDsgaSA8IEw7ICsraSkgewogICAgICAgIGlkeFsxIDw8IGldID0gaTsKICAgIH0KICAgIGZvciAoaW50IGkgPSAwOyBpIDwgSzsgaSArPSBMKSB7CiAgICAgICAgaW50IFMgPSBpLCBFID0gbWluKEssIGkgKyBMKTsKICAgICAgICBmb3IgKGludCBqID0gMTsgaiA8IDEgPDwgKEUgLSBTKTsgKytqKSB7CiAgICAgICAgICAgIC8vYXNzZXJ0IChpZHhbaiAmIC1qXSAhPSAtMSk7CiAgICAgICAgICAgIHByZVtpIC8gTF1bal0gPSBwcmVbaSAvIExdW2ogLSAoaiAmIC1qKV0gfCBiaXRbUyArIGlkeFtqICYgLWpdXTsKICAgICAgICAgICAvKiBmb3IgKGludCBrID0gMDsgayA8IEUgLSBTOyArK2spIHsKICAgICAgICAgICAgICAgIGlmIChqICYgKDEgPDwgaykpIHsKICAgICAgICAgICAgICAgICAgICBwcmVbaSAvIExdW2pdIHw9IGJpdFtTICsga107CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0qLwogICAgICAgIH0KICAgIH0KICAgIGxvbmcgbG9uZyB3aGF0ID0gMDsKICAgIGZvciAoaW50IHcgPSAwOyB3IDwgbjsgKyt3KSB7CiAgICAgICAgYml0c2V0IDxOPiBjdXI7CiAgICAgICAgZm9yIChpbnQgaSA9IDA7IGkgPCBLOyBpICs9IEwpIHsKICAgICAgICAgICAgY3VyIHw9IHByZVtpIC8gTF1bKGFbd10gPj4gaSkgJiAoKDEgPDwgTCkgLSAxKV07CiAgICAgICAgfQogICAgICAgIHdoYXQgKz0gbiAtIGN1ci5jb3VudCgpOwogICAgfQogICAgY291dCA8PCB3aGF0IC8gMiA8PCAnXG4nOyAvL2NhbiBnZXQgcmlkIG9mIC8yIGJ5IHVwZGF0aW5nIHByZSBvbmxpbmUgYW5kIGNoZWNrIGJpdHNldHMgdGlsbCB3LXRoIGluZGV4LCBidXQgdGhhdCBkb2VzIG5vdCByZWFsbHkgaW1wcm92ZQogICAgcmV0dXJuOwogICAgLy9PKE4qRC9MKk4vV29yZCsyXkwqTi9Xb3JkKihEL0wpKSAtPiBMID0gMTAgLT4gNTEyKjEwXjUKICAgIGlmICgwKSB7IGludCBhbnMgPSAwLCB0bXAgPSAwOwogICAgZm9yIChpbnQgaSA9IDA7IGkgPCBuOyArK2kpIHsKICAgICAgICBiaXRzZXQgPE4+IGFsbDsKICAgICAgICBmb3IgKGludCBiID0gMDsgYiA8IEs7ICsrYikgeyAvL2IgKz0gTAogICAgICAgICAgICBpZiAoKGFbaV0gPj4gYikgJiAxKSB7CiAgICAgICAgICAgICAgICBhbGwgfD0gYml0W2JdOwogICAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIHRtcCArPSBuIC0gYWxsLmNvdW50KCk7CiAgICAgICAgZm9yIChpbnQgaiA9IGkgKyAxOyBqIDwgbjsgKytqKSB7CiAgICAgICAgICAgIGlmICgoYVtpXSAmIGFbal0pID09IDApIHsKICAgICAgICAgICAgICAgICsrYW5zOwogICAgICAgICAgICB9CiAgICAgICAgfQogICAgfQogICAgY291dCA8PCAnICcgPDwgYW5zIDw8ICcgJyA8PCB0bXAgLyAyIDw8ICdcbic7IH0KfQoKaW50IG1haW4oKSB7Ci8vICAgIGZyZW9wZW4oImlucHV0LnR4dCIsICJyIiwgc3RkaW4pOwovLyAgICBmcmVvcGVuKCJpcG4uaW5wIiwgInIiLCBzdGRpbik7IGZyZW9wZW4oImlwbi5vdXQiLCAidyIsIHN0ZG91dCk7Ci8vICAgIGlvczo6c3luY193aXRoX3N0ZGlvKGZhbHNlKTsgY2luLnRpZSgwKTsKICAgIGludCB0ID0gMTsKICAgIC8vc2NhbmYoIiVkIiwgJnQpOwogICAgd2hpbGUgKHQgLS0+IDApIHsKICAgICAgICBzb2x2ZSgpOwogICAgfQogICAgcmV0dXJuIDA7Cn0K