#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5, B = 18;
int a[N], f[N][B], p[N];
int ask(int l, int r) {
  int d = p[r - l + 1];
  return max(f[l][d], f[r - (1 << d) + 1][d]);
}
int main() {
  for (int i = 2; i < N; ++i) p[i] = p[i / 2] + 1;
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &a[i]);
    f[i][0] = a[i];
  }
  for (int j = 1; (1 << j) <= n; ++j) {
    for (int i = 1; i + (1 << j) - 1 <= n; ++i)
      f[i][j] = max(f[i][j - 1], f[i + (1 << j - 1)][j - 1]);
  }
  vector<pair<int, int>> L;
  long long ans = 0;
  for (int R = 1; R <= n; ++R) {
    L.push_back({R, a[R]});
    for (auto &x : L) x.second |= a[R];
    vector<pair<int, int>> LL;
    for (auto x : L) {
      if (LL.empty() || LL.back().second != x.second) LL.push_back(x);
    }
    L.swap(LL);
    int las = R + 1;
    for (int i = L.size() - 1; i >= 0; --i) {
      auto x = L[i];
      int v = x.second;
      int cur = x.first;
      int len = 0;
      for (int i = B - 1; i >= 0; --i) {
        if (las - (len + (1 << i)) < cur) continue;
        len += (1 << i);
        if (ask(las - len, R) >= v) len -= (1 << i);
      }
      ans += len;
      las = cur;
    }
  }
  cout << ans << endl;
}
