The Brand New Function

Polycarpus has a sequence, consisting of n non-negative integers: a 1, a 2, …, a n.

Let’s define function f(l, r) ( l, r are integer, 1 ≤ l ≤ r ≤ n) for sequence a as an operation of bitwise OR of all the sequence elements with indexes from l to r. Formally: f(l, r) = a l | a l + 1 | …  | a r.

Polycarpus took a piece of paper and wrote out the values of function f(l, r) for all l, r ( l, r are integer, 1 ≤ l ≤ r ≤ n). Now he wants to know, how many distinct values he’s got in the end.

Help Polycarpus, count the number of distinct values of function f(l, r) for the given sequence a.

Expression x | y means applying the operation of bitwise OR to numbers x and y. This operation exists in all modern programming languages, for example, in language C++ and Java it is marked as “|”, in Pascal — as “or”.

Input

The first line contains integer n (1 ≤ n ≤ 105) — the number of elements of sequence a. The second line contains n space-separated integers a 1, a 2, …, a n (0 ≤ a i ≤ 106) — the elements of sequence a.

Output

Print a single integer — the number of distinct values of function f(l, r) for the given sequence a.

Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier.

Examples

input

3
1 2 0

output

4

input

10
1 2 3 4 5 6 1 2 9 10

output

11

Note

In the first test case Polycarpus will have 6 numbers written on the paper: f(1, 1) = 1, f(1, 2) = 3, f(1, 3) = 3, f(2, 2) = 2, f(2, 3) = 2, f(3, 3) = 0. There are exactly 4 distinct numbers among them: 0, 1, 2, 3.

Solution:

#include <iostream>
#include <iomanip>
#include <stdio.h>
#include <set>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#include <memory.h>
#include <string>
#include <sstream>

using namespace std;

int can[1111111];
int a[111111], next[111111][33];
int x[33], y[33];
int n, i, j, k;

int main() {
//  freopen("in", "r", stdin);
//  freopen("out", "w", stdout);
scanf("%d", &n);
for (i=0;i<n;i++) scanf("%d", a+i);
  for (j=0;j<20;j++) {
    int last = n;
    for (i=n-1;i>=0;i--) {
if (a[i] & (1 << j)) last = i;
      next[i][j] = last;
    }
  }
  for (i=0;i<(1<<20);i++) can[i] = 0;
  for (i=0;i<n;i++) {
    for (j=0;j<20;j++) {
      x[j] = next[i][j];
      y[j] = (1 << j);
    }
    for (j=0;j<20;j++)
      for (k=j+1;k<20;k++)
        if (x[j] > x[k]) {
int tmp;
tmp = x[j]; x[j] = x[k]; x[k] = tmp;
tmp = y[j]; y[j] = y[k]; y[k] = tmp;
}
int cur = 0;
j = 0;
while (j < 20) {
      if (x[j] == n) break;
      k = j;
      while (k < 20 && x[j] == x[k]) k++;
      for (int u=j;u<k;u++) cur += y[u];
      can[cur] = 1;
      j = k;
    }
  }
  for (i=0;i<n;i++) can[a[i]] = 1;
  int ans = 0;
  for (i=0;i<(1<<20);i++) ans += can[i];
  printf("%d\n", ans);
  return 0;
}