#include <bits/stdc++.h>
const int MAXN = 200005, MAXLOGN = 19, INFTY = 0x3fffffff;
int N, a[MAXN], s[MAXN], orL[MAXN][MAXLOGN], orR[MAXN][MAXLOGN],
    leftBound[MAXN], rightBound[MAXN];
void work() {
  a[0] = a[N + 1] = INFTY;
  int p = 0, q;
  s[p++] = 0;
  for (int i = 1; i <= N; ++i) {
    while (a[s[p - 1]] < a[i]) --p;
    leftBound[i] = s[p - 1];
    s[p++] = i;
  }
  p = 0;
  s[p++] = N + 1;
  for (int i = N; i >= 1; --i) {
    while (a[s[p - 1]] <= a[i]) --p;
    rightBound[i] = s[p - 1];
    s[p++] = i;
  }
  for (int i = 1; i < MAXLOGN; ++i)
    for (int j = 1; j <= N; ++j) {
      if (j - (1 << (i - 1)) > 0)
        orL[j][i] = orL[j][i - 1] | orL[j - (1 << (i - 1))][i - 1];
      else
        orL[j][i] = orL[j][i - 1];
      if (j + (1 << (i - 1)) <= N)
        orR[j][i] = orR[j][i - 1] | orR[j + (1 << (i - 1))][i - 1];
      else
        orR[j][i] = orR[j][i - 1];
    }
  long long ans = ((long long)N) * (N + 1) >> 1;
  for (int i = 1; i <= N; ++i) {
    p = q = i;
    int t = 0;
    for (int j = MAXLOGN - 1; j >= 0; --j)
      if (p - (1 << j) >= leftBound[i] && (t | orL[p][j]) <= a[i])
        t |= orL[p][j], p -= (1 << j);
    t = 0;
    for (int j = MAXLOGN - 1; j >= 0; --j)
      if (q + (1 << j) <= rightBound[i] && (t | orR[q][j]) <= a[i])
        t |= orR[q][j], q += (1 << j);
    ans -= ((long long)(i - p)) * (q - i);
  }
  printf("%I64d\n", ans);
}
int main() {
  scanf("%d", &N);
  for (int i = 1; i <= N; ++i) scanf("%d", a + i), orL[i][0] = orR[i][0] = a[i];
  work();
  return 0;
}
