#include <bits/stdc++.h>
using namespace std;
const int64_t infll = 9223372036854775807LL;
void calcLeftMax(int64_t n, vector<int64_t> &a, vector<int64_t> &leftMax) {
  vector<int64_t> st;
  for (int64_t i = (0); i < (n); ++i) {
    while (!st.empty() && a[i] > a[st.back()]) st.pop_back();
    if (st.empty())
      leftMax[i] = i;
    else
      leftMax[i] = i - st.back() - 1;
    st.push_back(i);
  }
}
void calcRightMax(int64_t n, vector<int64_t> &a, vector<int64_t> &rightMax) {
  vector<int64_t> st;
  for (int64_t i = n - 1; i >= 0; i--) {
    while (!st.empty() && a[i] >= a[st.back()]) st.pop_back();
    if (st.empty())
      rightMax[i] = n - 1 - i;
    else
      rightMax[i] = st.back() - i - 1;
    st.push_back(i);
  }
}
void calcLeftBoost(int64_t n, vector<int64_t> &a, vector<int64_t> &leftBoost) {
  array<int64_t, 32> mask, best;
  for (int64_t i = (0); i < (32); ++i) {
    mask[i] = 1 << i;
    best[i] = -1;
  }
  for (int64_t i = (0); i < (n); ++i) {
    int64_t ans = -1;
    for (int64_t j = (0); j < (32); ++j) {
      if ((mask[j] & a[i]) != 0) {
        best[j] = i;
      } else
        ans = max(ans, best[j]);
    }
    if (ans < 0)
      leftBoost[i] = infll;
    else
      leftBoost[i] = i - ans;
  }
}
void calcRightBoost(int64_t n, vector<int64_t> &a,
                    vector<int64_t> &rightBoost) {
  array<int64_t, 32> mask, best;
  for (int64_t i = (0); i < (32); ++i) {
    mask[i] = 1 << i;
    best[i] = infll;
  }
  for (int64_t i = n - 1; i >= 0; i--) {
    int64_t ans = infll;
    for (int64_t j = (0); j < (32); ++j) {
      if ((mask[j] & a[i]) != 0) {
        best[j] = i;
      } else
        ans = min(ans, best[j]);
    }
    if (ans > n)
      rightBoost[i] = infll;
    else
      rightBoost[i] = ans - i;
  }
}
int64_t countCase(int64_t l, int64_t r, int64_t lb, int64_t rb) {
  int64_t ans = 0;
  if (l > 0 && lb <= l) ans += (l - lb + 1) * (r + 1);
  if (r > 0 && rb <= r) ans += (r - rb + 1) * (l + 1);
  if (l > 0 && lb <= l && r > 0 && rb <= r) ans -= (l - lb + 1) * (r - rb + 1);
  return ans;
}
void solve() {
  int64_t n;
  cin >> n;
  vector<int64_t> a(n);
  for (int64_t i = (0); i < (n); ++i) {
    cin >> a[i];
  }
  vector<int64_t> leftMax(n, -1), rightMax(n, -1), leftBoost(n, -1),
      rightBoost(n, -1);
  calcLeftMax(n, a, leftMax);
  calcRightMax(n, a, rightMax);
  calcLeftBoost(n, a, leftBoost);
  calcRightBoost(n, a, rightBoost);
  int64_t ans = 0;
  for (int64_t i = (0); i < (n); ++i) {
    ans += countCase(leftMax[i], rightMax[i], leftBoost[i], rightBoost[i]);
  }
  cout << ans << endl;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cout << fixed << setprecision(15);
  solve();
  return 0;
}
