#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
long long ans = 0;
int n, f[18 + 1][200000 + 5], a[200000 + 5], lg[200000 + 5];
map<int, int> mp;
int Query(int l, int r) {
  int s = lg[r - l + 1];
  return f[s][l] | f[s][r - (1 << s) + 1];
}
int main() {
  n = read();
  ans = 1LL * n * (n + 1) / 2;
  lg[0] = -1;
  for (int i = 1; i <= n; ++i) lg[i] = lg[i >> 1] + 1;
  for (int i = 1; i <= n; ++i) a[i] = f[0][i] = read();
  for (int i = 1; i <= 18; ++i)
    for (int j = 1; j <= n; ++j)
      if (j + (1 << i) - 1 <= n)
        f[i][j] = f[i - 1][j] | f[i - 1][j + (1 << i - 1)];
  for (int i = 1; i <= n; ++i) {
    int l = 1, r = i - 1, mid, L = i, R = i;
    while (l <= r) {
      mid = l + r >> 1;
      if ((Query(mid, i)) == a[i])
        L = mid, r = mid - 1;
      else
        l = mid + 1;
    }
    l = i + 1, r = n;
    while (l <= r) {
      mid = l + r >> 1;
      if ((Query(i, mid)) == a[i])
        R = mid, l = mid + 1;
      else
        r = mid - 1;
    }
    L = max(L, mp[a[i]] + 1);
    ans -= 1LL * (i - L + 1) * (R - i + 1);
    mp[a[i]] = i;
  }
  printf("%lld\n", ans);
  return 0;
}
