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 ≤ 10^5) — the number of elements of sequence a. The second line contains n space-separated integers a_1, a_2, ..., a_{n} (0 ≤ a_{i} ≤ 10^6) — 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.

Difficulty: MEDIUM_HARD
Tags: Bit manipulation
Skill types: Bit manipulation

Starter code:

Solutions:
(n, p, q) = (input(), set(), set())
for i in map(int, input().split()):
	q = set((i | j for j in q))
	q.add(i)
	p.update(q)
print(len(p))


n = int(input())
a = list(map(int, input().split()))
(s1, s2) = (set(), set())
for each in a:
	st = set()
	st.add(each)
	for i in s1:
		st.add(each | i)
	s1 = st
	s2.update(s1)
print(len(s2))


import sys, os
from io import BytesIO, IOBase
mod = 10 ** 9 + 7
Mod = 998244353
INF = float('inf')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
inp = lambda : list(map(int, sys.stdin.readline().rstrip('\r\n').split()))
from collections import defaultdict as dd
tc = 1
for test in range(1, tc + 1):
	n = int(input())
	a = inp()
	s = [[n] * 20 for i in range(n + 1)]
	for i in range(n - 1, -1, -1):
		for j in range(20):
			s[i][j] = s[i + 1][j]
			if a[i] & 1 << j:
				s[i][j] = i
	ans = set()
	for i in range(n):
		num = a[i]
		ans.add(num)
		d = dd(list)
		for j in range(20):
			if s[i][j] < n and s[i][j] != i:
				d[s[i][j]].append(j)
		for key in sorted(d.keys()):
			for j in d[key]:
				num += 1 << j
			ans.add(num)
	print(len(ans))


import sys
input = sys.stdin.readline
n = int(input())
a = list(map(int, input().split()))
s = set()
t = set()
for aa in a:
	s = {aa | j for j in s}
	s.add(aa)
	t.update(s)
print(len(t))


n = input()
r = set()
s = set()
l = list(map(int, input().split(' ')))
for i in l:
	s = {i | a for a in s}
	s.add(i)
	r |= s
print(len(r))


input()
(a, b) = (set(), set())
for i in map(int, input().split()):
	a = {i | j for j in a}
	a.add(i)
	b.update(a)
print(len(b))


import sys, math, os
from io import BytesIO, IOBase
from collections import defaultdict as dd, deque, Counter

def data():
	return sys.stdin.readline().strip()

def mdata():
	return list(map(int, data().split()))

def outl(var):
	sys.stdout.write(' '.join(map(str, var)) + '\n')

def out(var):
	sys.stdout.write(str(var) + '\n')
sys.setrecursionlimit(100000)
INF = float('inf')
mod = int(1000000000.0) + 7

def main():
	n = int(data())
	A = mdata()
	s = set()
	ans = set()
	for i in A:
		s = set((i | j for j in s))
		s.add(i)
		ans.update(s)
	print(len(ans))
main()


import copy
n = int(input())
a = list(map(int, input().split()))
ans = set()
s = set()
s.add(a[0])
ans.add(a[0])
for i in range(1, len(a)):
	pres = set()
	for x in s:
		pres.add(x | a[i])
	pres.add(a[i])
	for y in pres:
		ans.add(y)
	s = copy.deepcopy(pres)
print(len(ans))


n = input()
arr = list(map(int, input().split()))
res = set()
temp = set()
for i in arr:
	temp = {i | j for j in temp}
	temp.add(i)
	res.update(temp)
print(len(res))


def R():
	return map(int, input().split())

def I():
	return int(input())

def S():
	return str(input())

def L():
	return list(R())
from collections import Counter
import math
import sys
from itertools import permutations
import bisect
n = I()
a = L()
s1 = set()
s2 = set()
for i in range(n):
	s1 = {a[i] | j for j in s1}
	s1.add(a[i])
	s2.update(s1)
print(len(s2))


n = int(input())
a = list(map(int, input().split()))
b = set()
c = set()
for i in a:
	b = set((i | j for j in b))
	b.add(i)
	c.update(b)
print(len(c))


import sys
In = sys.stdin
n = int(In.readline().strip())
arr = [int(x) for x in In.readline().split()]
(res, m) = (set(), set())
for i in range(n):
	s = set()
	s.add(arr[i])
	s.update([x | arr[i] for x in m])
	m = s
	res.update(s)
print(len(res))


def brand(arr):
	ans = set()
	temp = set()
	for i in arr:
		temp = {i | j for j in temp}
		temp.add(i)
		ans.update(temp)
	return len(ans)
a = input()
lst = list(map(int, input().strip().split()))
print(brand(lst))


from bisect import bisect_right
import heapq
n = int(input())
arr = list(map(int, input().split()))
ans = set()
s = set()
for i in range(n):
	s = {arr[i] | j for j in s}
	s.add(arr[i])
	ans.update(s)
print(len(ans))


def subarrayBitwiseOR(A):
	res = set()
	pre = {0}
	for x in A:
		pre = {x | y for y in pre} | {x}
		res |= pre
	return len(res)
n = int(input())
arr = list(map(int, input().split()))
print(subarrayBitwiseOR(arr))