#include <bits/stdc++.h>
using namespace std;
const int maxN = 2e5, bitSize = 31;
int readInt() {
  bool minus = false;
  int result = 0;
  char ch;
  ch = getchar();
  while (true) {
    if (ch == '-') break;
    if (ch >= '0' && ch <= '9') break;
    ch = getchar();
  }
  if (ch == '-')
    minus = true;
  else
    result = ch - '0';
  while (true) {
    ch = getchar();
    if (ch < '0' || ch > '9') break;
    result = result * 10 + (ch - '0');
  }
  if (minus)
    return -result;
  else
    return result;
}
int a[maxN + 1], st[maxN + 1][bitSize], Log2[maxN + 1],
    lastBitPos[maxN + 1][bitSize];
void build_ST(int a[], int n) {
  for (int i = 2; i <= n; i++) Log2[i] = Log2[i / 2] + 1;
  for (int i = 1; i <= n; i++) st[i][0] = a[i];
  int cnt = 1;
  for (int len = 2; len <= n; len <<= 1, cnt++)
    for (int j = 1; j + len - 1 <= n; j++)
      st[j][cnt] = max(st[j][cnt - 1], st[j + len / 2][cnt - 1]);
}
int getRMQ(int L, int R) {
  int lg2 = Log2[R - L + 1];
  int res = max(st[L][lg2], st[R - (1 << lg2) + 1][lg2]);
  return res;
}
int get(int lf, int rg, int x) {
  int i = rg;
  rg++;
  while (rg - lf > 1) {
    int mid = (lf + rg) >> 1;
    if (getRMQ(mid, i) >= x)
      lf = mid;
    else
      rg = mid;
  }
  return rg;
}
int main() {
  int n = readInt();
  for (int i = 1; i <= n; i++) a[i] = readInt();
  build_ST(a, n);
  long long ans = 0;
  a[0] = (1 << bitSize) - 1;
  for (int i = 0; i <= n; i++) {
    int curOr = a[i], curId = i;
    for (int j = 0; j < 30; j++) {
      if ((a[i] & (1 << j)))
        lastBitPos[i][j] = i;
      else
        lastBitPos[i][j] = lastBitPos[i - 1][j];
    }
    while (curId >= 1) {
      int maxPos = 0;
      for (int j = 0; j < 30; j++)
        if (!(curOr & (1 << j))) maxPos = max(maxPos, lastBitPos[curId][j]);
      int nextId = maxPos;
      int gtCurOr = get(nextId, curId, curOr);
      ans += curId - gtCurOr + 1;
      curId = nextId;
      curOr |= a[maxPos];
    }
  }
  printf("%I64d", ans);
}
