func_code_string: #include <bits/stdc++.h>   using namespace std;   inline long long read() {     long long x = 0, f = 1;     char ch;     for (ch = getchar(); (ch <  0  || ch >  9 ) && ch !=  - ; ch = getchar())       ;     if (ch ==  - ) f = 0, ch = getchar();     while (ch >=  0  && ch <=  9 ) {       x = (x << 1) + (x << 3) + ch -  0 ;       ch = getchar();     }     return f ? x : -x;   }   long long n, res;   long long a[500010], l[500010], r[500010];   long long fl[500010][21];   long long fr[500010][21];   long long st[500010], top;   signed main() {     n = read();     a[0] = a[n + 1] = 1e9 + 7;     for (long long i = 1; i <= n; ++i) {       a[i] = read();       fl[i][0] = fr[i][0] = a[i];       while (a[i] >= a[st[top]] && top) --top;       l[i] = st[top] + 1;       st[++top] = i;     }     top = 0;     st[top] = n + 1;     for (long long i = n; i >= 1; --i) {       while (a[i] > a[st[top]] && top) --top;       r[i] = st[top] - 1;       st[++top] = i;     }     for (long long i = 1; i <= 18; ++i) {       for (long long j = 1; j <= n; ++j) {         fl[j][i] = fl[j][i - 1] | fl[j + (1 << (i - 1))][i - 1];       }       for (long long j = n; j >= 1; --j) {         fr[j][i] = fr[j][i - 1];         if (j >= (1 << (i - 1)))           fr[j][i] = fr[j][i - 1] | fr[j - (1 << (i - 1))][i - 1];       }     }     for (long long i = 1; i <= n; ++i) {       if (i - l[i] <= r[i] - i) {         for (long long k = l[i]; k <= i; ++k) {           long long now = k;           long long sum = a[k];           for (long long d = 18; d >= 0; --d) {             if (now + (1 << d) <= r[i] && (sum | fl[now + 1][d]) <= a[i]) {               sum |= fl[now + 1][d];               now += (1 << d);             }           }           if (now >= i) res += (now - i + 1);         }       } else {         for (long long k = i; k <= r[i]; ++k) {           long long now = k;           long long sum = a[k];           for (long long d = 18; d >= 0; --d) {             if (now - (1 << d) >= l[i] && (sum | fr[now - 1][d]) <= a[i]) {               sum |= fr[now - 1][d];               now -= (1 << d);             }           }           if (now <= i) res += (i - now + 1);         }       }     }     printf( %lld n , (n) * (n + 1) / 2 - res);     return 0;   }   