Disclaimer: there are lots of untranslateable puns in the Russian version of the statement, so there is one more reason for you to learn Russian :)

Rick and Morty like to go to the ridge High Cry for crying loudly — there is an extraordinary echo. Recently they discovered an interesting acoustic characteristic of this ridge: if Rick and Morty begin crying simultaneously from different mountains, their cry would be heard between these mountains up to the height equal the bitwise OR of mountains they've climbed and all the mountains between them. 

Bitwise OR is a binary operation which is determined the following way. Consider representation of numbers *x* and *y* in binary numeric system (probably with leading zeroes) *x* = *x*<sub class="lower-index">*k*</sub>... *x*<sub class="lower-index">1</sub>*x*<sub class="lower-index">0</sub> and *y* = *y*<sub class="lower-index">*k*</sub>... *y*<sub class="lower-index">1</sub>*y*<sub class="lower-index">0</sub>. Then *z* = *x* | *y* is defined following way: *z* = *z*<sub class="lower-index">*k*</sub>... *z*<sub class="lower-index">1</sub>*z*<sub class="lower-index">0</sub>, where *z*<sub class="lower-index">*i*</sub> = 1, if *x*<sub class="lower-index">*i*</sub> = 1 or *y*<sub class="lower-index">*i*</sub> = 1, and *z*<sub class="lower-index">*i*</sub> = 0 otherwise. In the other words, digit of bitwise OR of two numbers equals zero if and only if digits at corresponding positions is both numbers equals zero. For example bitwise OR of numbers 10 = 1010<sub class="lower-index">2</sub> and 9 = 1001<sub class="lower-index">2</sub> equals 11 = 1011<sub class="lower-index">2</sub>. In programming languages C/C++/Java/Python this operation is defined as «|», and in Pascal as «or».

Help Rick and Morty calculate the number of ways they can select two mountains in such a way that if they start crying from these mountains their cry will be heard above these mountains and all mountains between them. More formally you should find number of pairs *l* and *r* (1 ≤ *l* &lt; *r* ≤ *n*) such that bitwise OR of heights of all mountains between *l* and *r* (inclusive) is larger than the height of any mountain at this interval.
The first line contains integer *n* (1 ≤ *n* ≤ 200 000), the number of mountains in the ridge.

Second line contains *n* integers *a*<sub class="lower-index">*i*</sub> (0 ≤ *a*<sub class="lower-index">*i*</sub> ≤ 10<sup class="upper-index">9</sup>), the heights of mountains in order they are located in the ridge.
In the first test case all the ways are pairs of mountains with the numbers (numbering from one):

In the second test case there are no such pairs because for any pair of mountains the height of cry from them is 3, and this height is equal to the height of any mountain.
5
3 2 1 6 5
8
4
3 3 3 3
0
1
0
0
1
1
0
1
1000000000
0
1
6
0
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
0
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
0
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
3239
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
2262
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
3630
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
3081
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
2997
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
2691
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
1010
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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1 1 1
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
4950
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
4500
import java.util.*;

public class Main {
	public static void main(String[] args) {

		Scanner scanner = new Scanner(System.in);

		int N = scanner.nextInt();
		scanner.nextLine();

		A = Arrays.stream(scanner.nextLine().split(" ")).mapToInt(x -> Integer.parseInt(x)).toArray();

//		int N = 20;
//		A = new int[]{68, 80, 20, 20, 77, 86, 53, 68, 17, 35, 71, 94, 33, 68, 27, 63, 2, 43, 64, 92};
//		A = new int[N];
//		for (int i = 0; i < N; i++) {
//			A[i] = new Random().nextInt(100)+1;
//		}

//		System.out.println(N);
//		System.out.println(Arrays.stream(A).mapToObj(x -> String.valueOf(x)).reduce((a, b) -> a+" "+b).orElse(""));

		Date t0 = new Date();

		int[][] left = new int[32][];
		int[][] right = new int[32][];
		for (int i = 0; i < 32; i++) {
			int idx = -1;
			left[i] = new int[N];
			for (int j = 0; j < N; j++) {
				if (((A[j] >> i) & 1) > 0) {
					idx = j;
				}
				left[i][j] = idx;
			}

			idx = N;
			right[i] = new int[N];
			for (int j = N-1; j >= 0; j--) {
				if (((A[j] >> i) & 1) > 0) {
					idx = j;
				}
				right[i][j] = idx;
			}
		}
		initRMQ();
//		System.out.println(String.format("Init TIme %.2f s", (new Date().getTime() - t0.getTime())/1000.0));
		System.out.println(solve(A, new HashMap<Pair, Integer>(), 0, N-1, left, right));
//		System.out.println(RMQT);
//		System.out.println((new Date().getTime() - t0.getTime()) / 1000.0);

	}
	static Double RMQT = 0.0;

	public static int solve(int[] A, HashMap<Pair, Integer> memo, int l, int r, int[][] left, int[][] right) {
		if (l >= r) {
			return 0;
		}

		Date ts = new Date();
//		int m = rmq(A, memo, l, r);
		int m = RMQ(l, r+1);
		if (m == - 1){
			System.out.println(String.format("-1, in range %d, %d", l, r));
			return 0;
		}
		RMQT += (new Date().getTime() - ts.getTime()) / 1000.0;
		int v = A[m];
		int a = -1;
		int b = Integer.MAX_VALUE;
		for (int i = 0; i < 32; i++) {
			if (((v >> i) & 1) == 0) {
				a = Math.max(a, left[i][m]);
				b = Math.min(b, right[i][m]);
			}
		}

		int ans = 0;
		if (l <= a && a < m && m < b && b <= r) {
			ans = (a-l+1)*(r-m+1) + (r-b+1)*(m-l+1) - (a-l+1)*(r-b+1);
		} else if(l <= a && a < m) {
			ans = (a-l+1) * (r-m+1);
		} else if(m < b && b <= r) {
			ans = (m-l+1) * (r-b+1);
		}

		return ans + solve(A, memo, l, m-1, left, right) + solve(A, memo, m+1, r, left, right);
	}


	static int[][] M;
	static int[] A;

	public static void initRMQ() {
		M = new int[A.length][];
		int D = 1;
		while ((1<<D) <= A.length) {
			D += 1;
		}
		for (int i = 0; i < A.length; i++) {
			M[i] = new int[D];
			Arrays.fill(M[i], -1);
		}

		for (int i = 0; i < A.length; i++) {
			M[i][0] = i;
		}
		for (int i = 1; i < D; i++) {
			for (int j = 0; j < A.length-(1<<i)+1; j++) {
				int a = M[j][i/2];
				int b = M[j+(1<<(i/2))][i/2];
				if (A[a] >= A[b]) {
					M[j][i] = a;
				} else {
					M[j][i] = b;
				}
			}
		}
	}

	// [l, r)
	public static int RMQ(int l, int r) {
		if (l >= r) {
			return -1;
		}

		int i = 0;
		while ((l + (1 << i)) <= r) {
			i += 1;
		}
		i -= 1;


		int a = M[l][i];
		int b = RMQ(l+(1<<i), r);

		if (a >= 0 && b >= 0) {
			return A[a] > A[b] ? a : b;
		} else if (a >= 0) {
			return a;
		} else if (b >= 0) {
			return b;
		}

		return -1;
	}


	public static int rmq(int[] A, HashMap<Pair, Integer> memo, int l, int r) {
		if (l > r) {
			return -1;
		}

		if (l == r) {
			return l;
		}

		Pair key = new Pair(l, r);
		if (memo.containsKey(key)) {
			return memo.get(key);
		}

		int m = (l+r) / 2;
		int a = rmq(A, memo, l, m);
		int b = rmq(A, memo, m+1, r);

		int ans = A[a] > A[b] ? a : b;
		memo.put(key, ans);

		return ans;
	}

	public static class Pair {
		public long x;
		public long y;

		public Pair(long x, long y) {
			this.x = x;
			this.y = y;
		}

		@Override
		public boolean equals(Object o) {
			if (this == o) return true;
			if (o == null || getClass() != o.getClass()) return false;

			Pair pair = (Pair) o;

			if (x != pair.x) return false;
			return y == pair.y;
		}

		@Override
		public int hashCode() {
			int result = (int) (x ^ (x >>> 32));
			result = 31 * result + (int) (y ^ (y >>> 32));
			return result;
		}

		@Override
		public String toString() {
			return "Pair{" +
					"x=" + x +
					", y=" + y +
					'}';
		}
	}
}