#include <bits/stdc++.h>
using namespace std;
int n, a[200005], v[200005];
struct rmq {
  int db[200005][21];
  void make() {
    for (int i = 1; i <= n; i++) db[i][0] = a[i];
    for (int j = 0; j < 20; j++) {
      for (int i = 1; i <= n; i++) {
        if (i + (1 << j) > n)
          db[i][j + 1] = db[i][j];
        else
          db[i][j + 1] = max(db[i][j], db[i + (1 << j)][j]);
      }
    }
  }
  int query(int a, int b, int k, int l, int r) {
    if (a > b) return -1009;
    int i = v[(b - a + 1)];
    { return max(db[a][i], db[b - (1 << i) + 1][i]); }
  }
} R;
struct rmq2 {
  int db[200005][21];
  void make() {
    for (int i = 1; i <= n; i++) db[i][0] = a[i];
    for (int j = 0; j < 20; j++) {
      for (int i = 1; i <= n; i++) {
        if (i + (1 << j) > n)
          db[i][j + 1] = db[i][j];
        else
          db[i][j + 1] = (db[i][j] | db[i + (1 << j)][j]);
      }
    }
  }
  int query(int a, int b, int k, int l, int r) {
    if (a > b) return 0;
    int i = v[(b - a + 1)];
    { return (db[a][i] | db[b - (1 << i) + 1][i]); }
  }
} O;
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
  }
  O.make();
  R.make();
  for (int i = 1; i < 200005; i++) {
    for (int j = 20; j >= 0; j--) {
      if (i >= (1 << j)) {
        v[i] = j;
        break;
      }
    }
  }
  long long ans = 1LL * n * (n + 1) / 2LL;
  for (int i = 1; i <= n; i++) {
    int lb = 0, ub = i;
    while (ub - lb > 1) {
      int mid = (lb + ub) / 2;
      int x = O.query(mid, i - 1, 0, 0, (1 << 18) - 1);
      int y = R.query(mid, i - 1, 0, 0, (1 << 18) - 1);
      if (y >= a[i]) {
        lb = mid;
      } else if ((x | a[i]) != a[i]) {
        lb = mid;
      } else {
        ub = mid;
      }
    }
    long long U = i - ub + 1;
    lb = i, ub = n + 1;
    while (ub - lb > 1) {
      int mid = (lb + ub) / 2;
      int x = O.query(i, mid, 0, 0, (1 << 18) - 1);
      int y = R.query(i, mid, 0, 0, (1 << 18) - 1);
      if (y > a[i]) {
        ub = mid;
      } else if ((x | a[i]) != a[i]) {
        ub = mid;
      } else {
        lb = mid;
      }
    }
    long long V = lb - i + 1;
    ans -= U * V;
  }
  cout << ans << endl;
}
