#include <bits/stdc++.h>
static unsigned char BakaMemoryStack[10000000];
static unsigned char *MemoryStackTop = BakaMemoryStack;
void *Allocates(unsigned long size) {
  MemoryStackTop += size;
  return MemoryStackTop - size;
}
void Releases(unsigned long size) {
  MemoryStackTop -= size;
  if (MemoryStackTop < BakaMemoryStack) {
    MemoryStackTop = BakaMemoryStack;
  }
}
void mergesort(long *ds, int (*compare)(long a, long b), long size) {
  long i, j, k, s, b, e;
  long *ms = (long *)Allocates(sizeof(long) * (size + 1));
  for (k = 1; k <= size; k = k << 1) {
    for (i = 1; i + k <= size; i += k << 1) {
      s = i;
      b = i + k;
      e = b + k - 1;
      if (e > size) {
        e = size;
      }
      for (j = 1; (s < i + k) && (b <= e); j++) {
        if (compare(ds[s], ds[b]) <= 0) {
          ms[j] = ds[s++];
        } else {
          ms[j] = ds[b++];
        }
      }
      for (b = i + k - 1; b >= s; b--) {
        ds[e--] = ds[b];
      }
      for (b = 1; b < j; b++) {
        ds[i + b - 1] = ms[b];
      }
    }
  }
  Releases(sizeof(long) * (size + 1));
}
void swap(unsigned int *a, unsigned int *b) {
  *a = *a ^ *b;
  *b = *a ^ *b;
  *a = *a ^ *b;
}
void swap64(unsigned long long *a, unsigned long long *b) {
  *a = *a ^ *b;
  *b = *a ^ *b;
  *a = *a ^ *b;
}
unsigned int bsf(unsigned int a) {
  __asm__ __volatile__("bsfl %0,%0" : "+r"(a));
  return a;
}
unsigned int bsr(unsigned int a) {
  __asm__ __volatile__("bsrl %0,%0" : "+r"(a));
  return a;
}
unsigned int imin(unsigned int a, unsigned int b) {
  __asm__ __volatile__(
      "cmpl %0,%1\n"
      "cmovll %1,%0"
      : "+&r"(a)
      : "g"(b));
  return a;
}
unsigned int imax(unsigned int a, unsigned int b) {
  __asm__ __volatile__(
      "cmpl %0,%1\n"
      "cmovgl %1,%0"
      : "+&r"(a)
      : "g"(b));
  return a;
}
unsigned int min(unsigned int a, unsigned int b) {
  __asm__ __volatile__(
      "cmpl %0,%1\n"
      "cmovbl %1,%0"
      : "+&r"(a)
      : "g"(b));
  return a;
}
unsigned int max(unsigned int a, unsigned int b) {
  __asm__ __volatile__(
      "cmpl %0,%1\n"
      "cmoval %1,%0"
      : "+&r"(a)
      : "g"(b));
  return a;
}
void print(long *a, long size) {
  long i;
  for (i = 0; i < size; i++) {
    printf("%ld ", a[i]);
  }
  printf("%ld\n", a[i]);
}
void printll(long long *a, long size) {
  long i;
  for (i = 0; i < size; i++) {
    printf("%I64d ", a[i]);
  }
  printf("%I64d\n", a[i]);
}
long stack[1000007], num[1000007], ladder[1000007][20];
long left[1000007], right[1000007], head[1000007], tail[1000007];
int main() {
  long a, b, c, i, j, k, l, r, m, n;
  long long ans, t1, t2, t3;
  scanf("%ld", &n);
  for (i = 1; i <= n; i++) {
    scanf("%ld", &num[i]);
  }
  num[n + 1] = 0x7FFFFFFF;
  *stack = 1;
  stack[1] = n + 1;
  for (i = 1; i <= n; i++) {
    for (; ((num[i] | num[stack[*stack]]) == num[i]) &&
           (num[stack[*stack]] != num[i]);
         *stack -= 1)
      ;
    if (*stack == 1) {
      left[i] = 1;
    } else {
      left[i] = stack[*stack] + 1;
    }
    stack[++(*stack)] = i;
  }
  *stack = 1;
  stack[1] = n + 1;
  for (i = n; i >= 1; i--) {
    for (; (num[i] | num[stack[*stack]]) == num[i]; *stack -= 1)
      ;
    if (*stack == 1) {
      right[i] = n;
    } else {
      right[i] = stack[*stack] - 1;
    }
    stack[++(*stack)] = i;
  }
  ans = n;
  ans = ans * (ans - 1) >> 1;
  for (i = 1; i <= n; i++) {
    t1 = i - left[i] + 1;
    t2 = right[i] - i + 1;
    ans -= t1 * t2 - 1;
  }
  printf("%lld\n", ans);
  return 0;
}
