#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <sstream>
#include <queue>
#include <deque>
#define LL long long
#define MP make_pair
#define PII pair<int, int>
#define F first
#define S second
using namespace std;
int n;
int a[200010][25];
LL res=0;
inline void work(int x,int y)
{
	int t=0;
	while (x)
	{
		a[y][t]=x%2;
		x/=2;
		t++;
	}
}
int main()
{
	cin >>n;
	for (int i=0;i<n;i++)
	{
		int x;
		cin >>x;
		work(x,i+1);
	}
	for (int j=0;j<20;j++)
	{
		for (int i=2;i<=n;i++)
		    a[i][j]+=a[i-1][j];
	}
	for (int i=0;i<n;i++)
	{
		int l=0,r=i;
		while (l<r)
		{
			int mid=(l+r)/2;
			bool fl=1;
			for (int j=0;j<20;j++)
			{
				if (a[i+1][j]-a[mid][j]>1)
				{
					fl=0;
					break;
				}
			}
			if (fl) r=mid;
			else l=mid+1;
		}
		res+=i-l+1;
	}
	cout <<res;
	return 0;
}