#include <bits/stdc++.h>
using namespace std;
unsigned int a[200010];
vector<pair<int, int> > v1;
set<pair<int, int> > s1;
int nexthi[200010];
int prevhi[200010];
int prevset[200010][32];
int nextset[200010][32];
int main() {
  int n;
  cin >> n;
  a[0] = 1E9 + 1;
  a[n + 1] = 1E9 + 1;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    v1.push_back({-a[i], i});
  }
  s1.insert({0, a[0]});
  s1.insert({n + 1, a[n + 1]});
  sort(v1.begin(), v1.end());
  for (auto x : v1) {
    auto xhi = s1.lower_bound({x.second, -x.first});
    nexthi[x.second] = xhi->first;
    xhi--;
    prevhi[x.second] = xhi->first;
    s1.insert({x.second, -x.first});
  }
  for (int p = 0; p < 32; p++) {
    unsigned int po = (((unsigned int)1) << p);
    int last = 0;
    for (int i = 1; i <= n; i++) {
      if (po & a[i]) {
        prevset[i][p] = 0;
        last = i;
      } else {
        prevset[i][p] = last;
      }
    }
    last = n + 1;
    for (int i = n; i >= 1; i--) {
      if (po & a[i]) {
        nextset[i][p] = n + 1;
        last = i;
      } else {
        nextset[i][p] = last;
      }
    }
  }
  long long res = 0;
  for (int i = 1; i <= n; i++) {
    long long nseg =
        ((long long)(i - prevhi[i])) * ((long long)(nexthi[i] - i));
    int nextgood = nexthi[i];
    for (int p = 0; p < 32; p++) nextgood = min(nextgood, nextset[i][p]);
    int prevgood = prevhi[i];
    for (int p = 0; p < 32; p++) prevgood = max(prevgood, prevset[i][p]);
    long long nbad = ((long long)(i - prevgood)) * ((long long)(nextgood - i));
    res += nseg - nbad;
  }
  cout << res << endl;
  return 0;
}
