#include <bits/stdc++.h>
using namespace std;
void fre() {
  freopen("c://test//input.in", "r", stdin);
  freopen("c://test//output.out", "w", stdout);
}
template <class T1, class T2>
inline void gmax(T1 &a, T2 b) {
  if (b > a) a = b;
}
template <class T1, class T2>
inline void gmin(T1 &a, T2 b) {
  if (b < a) a = b;
}
const int N = 2e5 + 10, M = 0, Z = 1e9 + 7, inf = 0x3f3f3f3f;
template <class T1, class T2>
inline void gadd(T1 &a, T2 b) {
  a = (a + b) % Z;
}
int casenum, casei;
int n;
int a[N];
int BF() {
  int ans = 0;
  for (int l = 1; l <= n; ++l) {
    int val = 0;
    for (int r = l; r <= n; ++r) {
      val |= a[r];
      bool flag = 1;
      for (int i = l; i <= r; ++i)
        if (val <= a[i]) {
          flag = 0;
          break;
        }
      ans += flag;
    }
  }
  printf("%d\n", ans);
  return ans;
}
int first[N][32];
int b[24];
int f[24][N];
void RMQinit() {
  int L = log(n + 0.5) / log(2.0);
  for (int j = 1; j <= n; ++j) f[0][j] = a[j];
  for (int i = 1; i <= L; ++i) {
    int len = b[i - 1] - 1;
    for (int j = 1; j + len <= n; ++j) {
      f[i][j] = max(f[i - 1][j], f[i - 1][j + len + 1]);
    }
  }
}
int lg2[N];
inline int check(int l, int r) {
  int k = lg2[r - l + 1];
  return max(f[k][l], f[k][r - b[k] + 1]);
}
int main() {
  for (int i = 1; i <= 200000; ++i) {
    lg2[i] = log(i + 0.5) / log(2.0);
  }
  for (int i = 0; i < 24; ++i) b[i] = 1 << i;
  while (~scanf("%d", &n)) {
    for (int i = 1; i <= n; ++i) {
      scanf("%d", &a[i]);
    }
    RMQinit();
    for (int j = 0; j < 30; ++j) {
      first[n + 1][j] = n + 1;
    }
    for (int i = n; i >= 1; --i) {
      for (int j = 0; j < 30; ++j) {
        first[i][j] = first[i + 1][j];
        if (a[i] >> j & 1) first[i][j] = i;
      }
    }
    long long ans = 0;
    for (int i = 1; i <= n; ++i) {
      int p = i;
      int now = a[i];
      while (p <= n) {
        int rgt = n + 1;
        for (int j = 0; j < 30; ++j)
          if (~now >> j & 1) {
            gmin(rgt, first[p][j]);
          }
        int can = 0;
        if (now > check(i, p)) {
          int l = p;
          int r = rgt - 1;
          while (l <= r) {
            int mid = (l + r >> 1);
            int val = check(i, mid);
            if (now > val) {
              can = mid - p + 1;
              l = mid + 1;
            } else {
              r = mid - 1;
            }
          }
        }
        ans += can;
        now |= a[rgt];
        p = rgt;
      }
    }
    printf("%lld\n", ans);
  }
  return 0;
}
