#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  long long x = 0, y = 0, c = getchar();
  while (!isdigit(c)) y = c, c = getchar();
  while (isdigit(c)) x = (x << 1) + (x << 3) + (c ^ '0'), c = getchar();
  return y == '-' ? -x : x;
}
inline void print(long long q) {
  if (q < 0) putchar('-'), q = -q;
  if (q >= 10) print(q / 10);
  putchar(q % 10 + '0');
}
long long s1 = 19260817, s2 = 23333333, s3 = 998244353, srd;
inline long long rd() { return srd = (srd * s1 + s2 + rand()) % s3; }
void file() {
  freopen(".in", "r", stdin);
  freopen(".out", "w", stdout);
}
int n, a[200010], ll[200010], rr[200010], st[20][200010], lgo[200010];
long long as;
int ss[200010], ft;
inline int qy(int l, int r) {
  int x = lgo[r - l + 1];
  return st[x][l] | st[x][r - (1 << x) + 1];
}
int main() {
  srand(time(0));
  rd();
  int i, j, l, r, mid, an1, an2;
  n = read();
  for (i = 1; i <= n; ++i) a[i] = st[0][i] = read();
  for (i = 2; i <= n; ++i) lgo[i] = lgo[i >> 1] + 1;
  for (i = 1; i <= 17; ++i)
    for (j = 1; j + (1 << i) - 1 <= n; ++j)
      st[i][j] = st[i - 1][j] | st[i - 1][j + (1 << i - 1)];
  for (i = 1; i <= n; ++i) {
    while (ft && a[i] >= a[ss[ft]]) --ft;
    ll[i] = ss[ft] + 1;
    ss[++ft] = i;
  }
  ft = 0;
  ss[0] = n + 1;
  for (i = n; i; --i) {
    while (ft && a[i] > a[ss[ft]]) --ft;
    rr[i] = ss[ft] - 1;
    ss[++ft] = i;
  }
  for (i = 1; i <= n; ++i) {
    l = ll[i];
    r = an1 = i;
    while (l <= r) {
      mid = l + r >> 1;
      if (qy(mid, i) == a[i])
        an1 = mid, r = mid - 1;
      else
        l = mid + 1;
    }
    l = an2 = i;
    r = rr[i];
    while (l <= r) {
      mid = l + r >> 1;
      if (qy(i, mid) == a[i])
        an2 = mid, l = mid + 1;
      else
        r = mid - 1;
    }
    as += 1ll * (i - ll[i] + 1) * (rr[i] - i + 1) -
          1ll * (i - an1 + 1) * (an2 - i + 1);
  }
  print(as);
  return 0;
}
