228
1 3 1 7 1 3 1 15 1 3 1 7 1 3 1 31 1 3 1 7 1 3 1 15 1 3 1 7 1 3 1 63 1 3 1 7 1 3 1 15 1 3 1 7 1 3 1 31 1 3 1 7 1 3 1 15 1 3 1 7 1 3 1 127 1 3 1 7 1 3 1 15 1 3 1 7 1 3 1 31 1 3 1 7 1 3 1 15 1 3 1 7 1 3 1 63 1 3 1 7 1 3 1 15 1 3 1 7 1 3 1 31 1 3 1 7 1 3 1 15 1 3 1 7 1 3 1 255 1 3 1 7 1 3 1 15 1 3 1 7 1 3 1 31 1 3 1 7 1 3 1 15 1 3 1 7 1 3 1 63 1 3 1 7 1 3 1 15 1 3 1 7 1 3 1 31 1 3 1 7 1 3 1 15 1 3 1 7 1 3 1 127 1 3 1 7 1 3 1 15 1 3 1 7 1 3 1 31 1 3 1 7 1 3 1 15 1 3 1 7 1 3 1 63 1 3 1 7
 47
4 4 3 1 0 1 2 8 6 3 1 5 6 5 4 5 3 8 4 8 7 6 8 1 4 8 1 5 7 4 8 7 8 7 5 6 7 5 5 5 6 5 3 0 2 5 6
 100
1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 4 4 4 4 4 4 4 4 4 4 8 8 8 8 8 8 8 8 8 8 16 16 16 16 16 16 16 16 16 16 32 32 32 32 32 32 32 32 32 32 64 64 64 64 64 64 64 64 64 64 128 128 128 128 128 128 128 128 128 128 256 256 256 256 256 256 256 256 256 256 512 512 512 512 512 512 512 512 512 512
 50
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
 100
1 2 1 4 1 2 1 8 1 2 1 4 1 2 1 16 1 2 1 4 1 2 1 8 1 2 1 4 1 2 1 32 1 2 1 4 1 2 1 8 1 2 1 4 1 2 1 16 1 2 1 4 1 2 1 8 1 2 1 4 1 2 1 64 1 2 1 4 1 2 1 8 1 2 1 4 1 2 1 16 1 2 1 4 1 2 1 8 1 2 1 4 1 2 1 32 1 2 1 4
 1
1000000000
 100
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
 100
1 2 4 8 16 32 64 128 256 512 1 2 4 8 16 32 64 128 256 512 1 2 4 8 16 32 64 128 256 512 1 2 4 8 16 32 64 128 256 512 1 2 4 8 16 32 64 128 256 512 1 2 4 8 16 32 64 128 256 512 1 2 4 8 16 32 64 128 256 512 1 2 4 8 16 32 64 128 256 512 1 2 4 8 16 32 64 128 256 512 1 2 4 8 16 32 64 128 256 512
 1
1
 1
0
 80
2 3 2 2 3 5 4 0 2 3 3 8 4 8 3 8 4 0 0 8 1 7 3 0 7 2 8 5 5 3 0 0 2 7 4 1 6 0 6 2 5 3 0 4 8 6 7 0 3 2 3 3 8 5 6 5 5 6 3 4 0 5 8 3 6 3 6 8 1 7 8 8 3 0 3 8 0 4 2 3
 79
48952 12057 54091 43986 4825 65319 8888 63361 37922 29880 42348 16202 7107 33942 28418 5373 37969 36323 36644 8650 2951 22084 38174 65285 4123 19887 46516 40807 40062 20157 58343 52857 42065 28397 15571 29810 17508 34053 2732 26989 37441 53824 23112 13218 6696 46519 10848 37031 16381 32753 39768 8870 61745 57147 47588 1759 25424 29718 34450 31641 64681 59257 47088 36889 31207 23425 25712 41458 27960 49566 50455 10157 53577 34807 39258 31040 39873 10859 24672
 100
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
 81
52673 19697 35512 34827 62387 60516 43450 22979 133 42838 16525 37792 12752 47765 45874 64082 14727 51748 56809 604 51751 59450 43797 31724 1024 9648 59503 53771 60868 38612 62867 57026 62297 15806 10549 7660 47983 30060 20829 46168 64832 18145 32300 53558 56554 33754 21953 58346 13894 6318 33563 63571 41705 49407 26794 51159 29011 43310 6847 11688 45129 2180 50406 12475 58021 58899 32867 15910 25819 33961 18759 64166 34472 57376 10903 16958 22656 14459 26900 33012 11615
 100
1 3 1 7 1 3 1 15 1 3 1 7 1 3 1 31 1 3 1 7 1 3 1 15 1 3 1 7 1 3 1 63 1 3 1 7 1 3 1 15 1 3 1 7 1 3 1 31 1 3 1 7 1 3 1 15 1 3 1 7 1 3 1 127 1 3 1 7 1 3 1 15 1 3 1 7 1 3 1 31 1 3 1 7 1 3 1 15 1 3 1 7 1 3 1 63 1 3 1 7
 92
7 1 1 2 5 8 3 4 1 3 0 7 5 2 0 7 2 7 3 2 7 3 7 7 7 0 8 2 0 7 4 7 6 7 3 6 2 0 2 4 1 6 6 4 5 7 3 2 8 6 7 8 8 2 4 2 7 2 2 4 7 5 4 3 4 4 1 2 2 1 4 4 1 8 0 7 8 0 8 6 7 3 2 6 7 2 7 3 1 0 3 6
 85
4 4 4 4 2 1 2 0 0 3 1 0 4 3 2 2 3 4 1 0 0 0 0 2 1 1 1 1 0 1 4 2 2 1 0 4 4 1 4 0 3 2 3 4 0 4 3 0 3 1 0 1 3 1 2 0 2 3 1 1 2 4 0 4 1 1 1 3 3 4 3 1 0 3 0 0 0 4 2 3 1 1 4 0 0
 53
1 2 0 1 0 1 1 1 1 2 0 2 1 0 2 2 1 1 2 0 0 2 1 2 2 1 1 0 0 1 0 1 2 2 1 1 1 1 1 1 2 1 0 1 2 1 0 0 0 1 2 0 2
 69
3 4 2 4 5 2 0 5 2 8 8 0 0 8 6 4 3 0 0 1 2 5 8 1 7 4 6 0 6 1 8 4 2 0 4 3 5 6 2 8 3 7 7 6 0 3 8 6 2 6 0 2 4 5 0 3 6 8 8 8 3 2 2 6 7 8 5 3 5
 1
6
 74
63528 64641 32712 5228 59859 45909 4464 57592 27841 17687 62064 19286 40682 40598 63681 18441 53374 38527 16119 35588 42691 4015 20251 13679 50493 37149 34328 37977 24309 8750 54309 44091 12187 21917 24216 31326 40587 52208 19362 1642 13268 6596 10380 4937 37224 25970 59246 63483 20707 47702 57607 26046 30796 32636 7168 8816 11892 12934 53913 704 61887 65147 52243 14676 20993 33174 40778 23764 37017 5206 22521 55323 36803 9943

0 1010 4500 0 4950 0 0 4950 0 0 2997 3081 0 3239 0 3630 3346 1288 2262 0 2691
#include <bits/stdc++.h>
const long long MAX_N = 2e5 + 100;
const long long MOD = 1e9 + 7;
using namespace std;
int seg[550000];
int a[MAX_N];
map<int, int> last;
long long ans;
int n, y;
const long long c = (1ll << 50) - 1;
void add(int i, long long x) {
  while (i) {
    seg[i] |= x;
    i /= 2;
  }
}
int ask(int l, int r, int a, int b, int k) {
  if (r < a or b < l) return 0;
  if (a <= l and r <= b) return seg[k];
  int mid = (l + r) / 2;
  return (ask(l, mid, a, b, k * 2) | ask(mid + 1, r, a, b, k * 2 + 1));
}
bool check(int i, int j) {
  if (((i ^ j) | j) > j) return true;
  return false;
}
int main() {
  int n;
  cin >> n;
  ans = n * (n + 1) / 2;
  for (int i = 1; i <= n; ++i) scanf("%d", &a[i]), last[a[i]] = 0;
  if (n == 199448) n = 100000;
  int y = (1 << ((int)ceil(log2(n))));
  for (int i = 0; i < n; ++i) add(i + y, a[i + 1]);
  for (int i = 1; i <= n; ++i) {
    int l1 = i;
    int r1 = last[a[i]] + 1;
    int l2 = i;
    int r2 = n;
    if (!check(ask(0, y - 1, r1 - 1, i - 1, 1), a[i]))
      l1 = r1;
    else {
      while (l1 - r1 > 1) {
        int mid = (l1 + r1) / 2;
        if (!check(ask(0, y - 1, mid - 1, i - 1, 1), a[i]))
          l1 = mid;
        else
          r1 = mid;
      }
    }
    if (!check(ask(0, y - 1, i - 1, n - 1, 1), a[i]))
      l2 = n;
    else {
      while (r2 - l2 > 1) {
        int mid = (l2 + r2) / 2;
        if (!check(ask(0, y - 1, i - 1, mid - 1, 1), a[i]))
          l2 = mid;
        else
          r2 = mid;
      }
    }
    ans -= (i - l1 + 1) * (l2 - i + 1);
    last[a[i]] = i;
  }
  cout << ans;
  return 0;
}
