func_code_string: #include <bits/stdc++.h>   using namespace std;   char getc() {     char c = getchar();     while ((c <  A  || c >  Z ) && (c <  a  || c >  z ) && (c <  0  || c >  9 ))       c = getchar();     return c;   }   int gcd(int n, int m) { return m == 0 ? n : gcd(m, n % m); }   int read() {     int x = 0, f = 1;     char c = getchar();     while (c <  0  || c >  9 ) {       if (c ==  - ) f = -1;       c = getchar();     }     while (c >=  0  && c <=  9 )       x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();     return x * f;   }   int n, a[200010], pre[200010][32], suf[200010][32], PRE[200010], SUF[200010];   long long ans;   signed main() {     n = read();     for (int i = 1; i <= n; i++) a[i] = read();     for (int i = 1; i <= n; i++) {       for (int j = 0; j < 32; j++) pre[i][j] = pre[i - 1][j];       for (int j = 0; j < 32; j++)         if (a[i - 1] & (1 << j)) pre[i][j] = i - 1;     }     for (int j = 0; j < 32; j++) suf[n + 1][j] = n + 1;     for (int i = n; i >= 1; i--) {       for (int j = 0; j < 32; j++) suf[i][j] = suf[i + 1][j];       for (int j = 0; j < 32; j++)         if (a[i + 1] & (1 << j)) suf[i][j] = i + 1;     }     a[0] = a[n + 1] = 1000000010;     for (int i = 1; i <= n; i++) {       int j = i - 1;       while (a[j] < a[i]) j = PRE[j];       PRE[i] = j;     }     SUF[n + 1] = n + 1;     for (int i = n; i >= 1; i--) {       int j = i + 1;       while (a[j] <= a[i]) j = SUF[j];       SUF[i] = j;     }     for (int i = 1; i <= n; i++) {       int x = PRE[i], y = SUF[i];       int u = PRE[i], v = SUF[i];       for (int j = 0; j < 32; j++)         if (!(a[i] & (1 << j))) u = max(u, pre[i][j]), v = min(v, suf[i][j]);       ans += 1ll * (SUF[i] - i) * (u - PRE[i]) + 1ll * (i - u) * (SUF[i] - v);     }     cout << ans;     return 0;   }   