#include <bits/stdc++.h>
using namespace std;
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& p) {
  os << "[ ";
  for (T x : p) os << x << " ";
  os << "]" << endl;
  return os;
}
template <typename T>
ostream& operator<<(ostream& os, const set<T>& p) {
  os << "{ ";
  for (T x : p) os << x << " ";
  os << "}" << endl;
  return os;
}
template <typename T>
ostream& operator<<(ostream& os, const multiset<T>& p) {
  os << "{ ";
  for (T x : p) os << x << " ";
  os << "}" << endl;
  return os;
}
template <typename Tk, typename Tv>
ostream& operator<<(ostream& os, const map<Tk, Tv>& p) {
  os << "{ ";
  for (pair<Tk, Tv> x : p) os << x << " ";
  os << "}" << endl;
  return os;
}
template <typename Tk, typename Tv>
ostream& operator<<(ostream& os, const pair<Tk, Tv>& p) {
  os << "{" << p.first << ',' << p.second << "}";
  return os;
}
long long gcd(long long a, long long b) { return (a ? gcd(b % a, a) : b); }
long long power(long long a, long long n) {
  long long p = 1;
  while (n > 0) {
    if (n & 1) {
      p = p * a;
    }
    n >>= 1;
    a *= a;
  }
  return p;
}
long long power(long long a, long long n, long long mod) {
  long long p = 1;
  while (n > 0) {
    if (n & 1) {
      p = p * a;
      p %= mod;
    }
    n >>= 1;
    a *= a;
    a %= mod;
  }
  return p % mod;
}
const int N = 200005;
int a[N];
int le[N], rig[N];
int n;
void sle() {
  stack<int> st;
  st.push(1);
  le[1] = 1;
  int i;
  for (i = 2; i < n + 1; i++) {
    while (!st.empty() && a[st.top()] != a[i] && (a[st.top()] | a[i]) == a[i])
      st.pop();
    le[i] = (st.empty() ? i : i - st.top());
    st.push(i);
  }
}
void srig() {
  stack<int> st;
  st.push(n);
  rig[n] = 1;
  int i;
  for (i = n - 1; i >= 1; i--) {
    while (!st.empty() && (a[st.top()] | a[i]) == a[i]) st.pop();
    rig[i] = (st.empty() ? n - i + 1 : st.top() - i);
    st.push(i);
  }
}
int main() {
  int i, j;
  scanf("%d", &n);
  for (i = 1; i < n + 1; i++) scanf("%d", &a[i]);
  sle();
  srig();
  long long ans = ((long long)n * (n + 1)) / 2;
  for (i = 1; i < n + 1; i++) ans -= ((long long)le[i] * rig[i]);
  printf("%lld\n", (long long)ans);
  return 0;
}
