#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 1;
const int maxbit = 30;
int n, a[maxn], cnt[maxn][maxbit];
int L[maxn], R[maxn];
stack<int> Stack;
void Input() {
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < maxbit; j++)
      cnt[i][j] = cnt[i - 1][j] + ((a[i] >> j) & 1);
  }
}
void Prepare() {
  while (!Stack.empty()) Stack.pop();
  for (int i = 1; i <= n; i++) {
    while (!Stack.empty() && a[Stack.top()] <= a[i]) Stack.pop();
    if (Stack.empty())
      L[i] = 0;
    else
      L[i] = Stack.top();
    Stack.push(i);
  }
  while (!Stack.empty()) Stack.pop();
  for (int i = n; i >= 1; i--) {
    while (!Stack.empty() && a[Stack.top()] < a[i]) Stack.pop();
    if (Stack.empty())
      R[i] = n + 1;
    else
      R[i] = Stack.top();
    Stack.push(i);
  }
}
bool Check(int l, int r, int x) {
  for (int i = 0; i < maxbit; i++)
    if (((x >> i) & 1) == 0) {
      if (cnt[r][i] - cnt[l - 1][i] > 0) return true;
    }
  return false;
}
int GetLow(int x) {
  int low = L[x], high = x, res = low;
  while (low <= high) {
    int mid = (low + high) / 2;
    if (Check(mid, x, a[x]))
      res = max(res, mid), low = mid + 1;
    else
      high = mid - 1;
  }
  return res;
}
int GetHigh(int x) {
  int low = x, high = R[x], res = high;
  while (low <= high) {
    int mid = (low + high) / 2;
    if (Check(x, mid, a[x]))
      res = min(res, mid), high = mid - 1;
    else
      low = mid + 1;
  }
  return res;
}
void Solve() {
  long long res = 0;
  for (int i = 1; i <= n; i++) {
    int low = GetLow(i), high = GetHigh(i);
    res += (i - low) * ((long long)R[i] - high) +
           (low - L[i]) * ((long long)R[i] - i);
  }
  cout << res;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  Input();
  Prepare();
  Solve();
}
