#include <bits/stdc++.h>
template <class T>
class _Fenwick {
 private:
  std::vector<T> sum;
  int _size;

 public:
  _Fenwick() { _size = 0; }
  void reset(int n) {
    _size = n;
    sum.clear();
    sum.resize(n + 1);
  }
  void add(int x, T y) {
    while (x <= _size) {
      sum[x] += y;
      x += x & -x;
    }
  }
  T query(int x, T y) {
    T ans = y;
    while (x) {
      ans += sum[x];
      x -= x & -x;
    };
    return ans;
  }
  void build(T *a, int n) {
    reset(n);
    for (int i = 1; i <= n; ++i) add(i, a[i]);
  }
};
template <typename T>
void read(T &x);
template <typename T>
void read(T &x, T &y);
template <typename T>
void read(T &x, T &y, T &z);
template <typename T>
void write(T x);
template <typename T>
void writeC(T x);
template <typename T>
void writeN(T x);
template <typename T>
void _binary(T x, int len);
long long _qpow(long long a, long long b, long long M);
long long _inv(long long x, long long M);
long long ans;
int n, a[200005], b[200005][31], R[200005][31], L[200005][31], pre[35];
signed main() {
  read(n);
  for (int i = 1; i <= (n); ++i) read(a[i]);
  ;
  long long ans = (long long)n * (n + 1) / 2;
  for (int i = 1; i <= n; ++i)
    for (int j = 0; j <= 30; ++j) b[i][j] = (a[i] >> j) & 1;
  for (int i = 1; i <= n; ++i) {
    for (int j = 0; j <= 30; ++j) {
      L[i][j] = pre[j];
      if (b[i][j]) pre[j] = i;
    }
  }
  for (int i = 0; i <= 30; ++i) pre[i] = n + 1;
  for (int i = n; i >= 1; i--) {
    for (int j = 0; j <= 30; ++j) {
      R[i][j] = pre[j];
      if (b[i][j]) pre[j] = i;
    }
  }
  std::map<int, int> last;
  for (int i = 1; i <= n; ++i) {
    int l = last[a[i]] + 1, r = n;
    for (int j = 0; j <= 30; ++j)
      if (!b[i][j]) {
        l = std::max(l, L[i][j] + 1);
        r = std::min(r, R[i][j] - 1);
      }
    ans -= (long long)(i - l + 1) * (r - i + 1);
    last[a[i]] = i;
  }
  printf("%lld", ans);
}
template <typename T>
void read(T &x) {
  x = 0;
  char c = getchar();
  T flag = 1;
  while (c < '0' || c > '9') {
    if (c == '-') flag = -flag;
    c = getchar();
  }
  while ('0' <= c && c <= '9') {
    x = x * 10 + c - '0';
    c = getchar();
  }
  x *= flag;
}
template <typename T>
void read(T &x, T &y) {
  read(x);
  read(y);
}
template <typename T>
void read(T &x, T &y, T &z) {
  read(x);
  read(y);
  read(z);
}
template <typename T>
void writeC(T x) {
  if (x < 0) x = ~x + 1, putchar('-');
  if (x > 9) writeC(x / 10);
  putchar(x % 10 + '0');
}
template <typename T>
void write(T x) {
  writeC(x);
  putchar(' ');
}
template <typename T>
void writeN(T x) {
  writeC(x);
  puts("");
}
template <typename T>
void _binary(T x, int len) {
  for (int i = len - 1; i >= 0; --i) writeC((x >> i) & 1);
}
long long _inv(long long x, long long M) {
  assert(x != 0);
  return x == 1 ? 1 : (M - M / x) * _inv(M % x, M) % M;
}
long long _qpow(long long a, long long b, long long M) {
  long long res = 1;
  while (b > 0) {
    if (b & 1) res = res * a % M;
    a = a * a % M;
    b >>= 1;
  }
  return res;
}
