// 未解決

#include <bits/stdc++.h>

#include <iostream>
using namespace std;

#define EACH(i, a) for (auto &&i : a)
#define FOR(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define RFOR(i, a, b) for (int i = (int)b - 1; i >= (int)a; --i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) FOR(i, 1, int(n) + 1)
#define RREP(i, n) RFOR(i, 0, n)
#define RREPS(i, n) RFOR(i, 1, int(n) + 1)
#define ALL(x) (x).begin(), (x).end()
#define MEMSET(v, h) memset((v), h, sizeof(v))
#define debug(x) cout << #x << ": " << x << endl

#define pb push_back
#define mp make_pair
#define F first
#define S second

#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev
#define INF (1L << 30)
#define MOD (1000000007)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

template <class T>
void pv(T a, T b) {
  for (T i = a; i != b; ++i) cout << *i << " ";
  cout << endl;
}
template <class T>
void pvp(T a, T b) {
  for (T i = a; i != b; ++i)
    cout << "(" << i->first << ", " << i->second << ") ";
  cout << endl;
}
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
int in() {
  int x;
  scanf("%d", &x);
  return x;
}

using ll = long long;
#define int ll

template <typename Sequence, typename BinaryPredicate>
struct IndexCompareT {
  IndexCompareT(const Sequence &seq, const BinaryPredicate comp)
      : seq_(seq), comp_(comp) {}
  bool operator()(const size_t a, const size_t b) const {
    return comp_(seq_[a], seq_[b]);
  }
  const Sequence seq_;
  const BinaryPredicate comp_;
};

template <typename Sequence, typename BinaryPredicate>
IndexCompareT<Sequence, BinaryPredicate> IndexCompare(
    const Sequence &seq, const BinaryPredicate comp) {
  return IndexCompareT<Sequence, BinaryPredicate>(seq, comp);
}

template <typename Sequence, typename BinaryPredicate>
std::vector<size_t> ArgSort(const Sequence &seq, BinaryPredicate func) {
  std::vector<size_t> index(seq.size());
  for (int i = 0; i < index.size(); i++) index[i] = i;

  std::sort(index.begin(), index.end(), IndexCompare(seq, func));

  return index;
}
//**********

int convert(int x, int n) {
  int y = 0, i = 0, z;
  while (x > 0) {
    z = x % n;
    y += z * pow(10, i);
    x = x / n;
    i++;
  }
  return y;
}

vector<int> incre(vector<int> x, int n, int m) {
  REPS(i, n) {
    if (x[n - i] != m) {
      x[n - i] += 1;
      REPS(j, i) { x[n - j] = x[n - i]; }
      return x;
    }
  }
  vector<int> over(n, m + 1);

  return over;
}

signed main(void) {
  ios::sync_with_stdio(false);
  cin.tie(0);

  int n;
  cin >> n;
  int a[200010];
  REP(i, n) { cin >> a[i]; }

  vector<int> now;
  REP(i, n) { now.pb(1); }

  int bitmemo[20];
  REP(i, 20) { bitmemo[i] = -1; }

  int ans = 0;
  int seq = 0;

  REP(i, n) {
    // debug(i);
    int x = a[i];
    int j = 0;
    int dif_min = INF;  // 繰り上がってしまう最も近い要素との距離
    while (x > 0) {
      if (x % 2 == 1) {
        chmin(dif_min, i - bitmemo[j]);
        bitmemo[j] = i;
      }
      x /= 2;
      j += 1;
    }
    seq = min(seq + 1, dif_min);
    // debug(seq);
    ans += seq;
  }

  cout << ans << endl;
  return 0;
};


Measured memory_bytes: 3956