#include <bits/stdc++.h>
using namespace std;
bool debug = 0;
int n, m, k;
int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
string direc = "RDLU";
long long ln, lk, lm;
void etp(bool f = 0) {
  puts(f ? "YES" : "NO");
  exit(0);
}
void addmod(int &x, int y, int mod = 1000000007) {
  assert(y >= 0);
  x += y;
  if (x >= mod) x -= mod;
  assert(x >= 0 && x < mod);
}
void et() {
  puts("-1");
  exit(0);
}
long long fastPow(long long x, long long y, int mod = 1000000007) {
  long long ans = 1;
  while (y > 0) {
    if (y & 1) ans = (x * ans) % mod;
    x = x * x % mod;
    y >>= 1;
  }
  return ans;
}
long long gcd1(long long x, long long y) {
  long long z = y;
  while (x % y != 0) {
    z = x % y;
    x = y;
    y = z;
  }
  return z;
}
int a[200105];
int nxt[33], af[200105];
map<int, int> mp;
long long ans;
void fmain(int ID) {
  scanf("%d", &n);
  for (int(i) = 1; (i) <= (int)(n); (i)++) scanf("%d", a + i);
  for (int i = n; i; i--) {
    int E = n + 1;
    for (int(j) = 0; (j) < (int)(30); (j)++)
      if (((a[i] >> j) & 1) == 0) {
        if (nxt[j] != 0) E = min(E, nxt[j]);
      }
    af[i] = E;
    for (int(j) = 0; (j) < (int)(30); (j)++)
      if (((a[i] >> j) & 1) == 1) {
        nxt[j] = i;
      }
  }
  for (int(i) = 0; (i) < (int)(31); (i)++) nxt[i] = 0;
  for (int(i) = 1; (i) <= (int)(n); (i)++) {
    int B = 0;
    for (int(j) = 0; (j) < (int)(30); (j)++)
      if (((a[i] >> j) & 1) == 0) {
        B = max(B, nxt[j]);
      }
    if (mp.find(a[i]) != mp.end()) B = max(B, mp[a[i]]);
    ans += (long long)(i - B) * (af[i] - i) - 1;
    mp[a[i]] = i;
    for (int(j) = 0; (j) < (int)(30); (j)++)
      if (((a[i] >> j) & 1) == 1) {
        nxt[j] = i;
      }
  }
  long long T = (long long)n * (n - 1) / 2;
  printf("%lld\n", T - ans);
}
int main() {
  int t = 1;
  for (int(i) = 1; (i) <= (int)(t); (i)++) {
    fmain(i);
  }
  return 0;
}
