Petya was late for the lesson too. The teacher gave him an additional task. For some array a Petya should find the number of different ways to select non-empty subset of elements from it in such a way that their product is equal to a square of some integer.

Two ways are considered different if sets of indexes of elements chosen by these ways are different.

Since the answer can be very large, you should find the answer modulo 10^9 + 7.


-----Input-----

First line contains one integer n (1 ≤ n ≤ 10^5) — the number of elements in the array.

Second line contains n integers a_{i} (1 ≤ a_{i} ≤ 70) — the elements of the array.


-----Output-----

Print one integer — the number of different ways to choose some elements so that their product is a square of a certain integer modulo 10^9 + 7.


-----Examples-----
Input
4
1 1 1 1

Output
15

Input
4
2 2 2 2

Output
7

Input
5
1 2 4 5 8

Output
7



-----Note-----

In first sample product of elements chosen by any way is 1 and 1 = 1^2. So the answer is 2^4 - 1 = 15.

In second sample there are six different ways to choose elements so that their product is 4, and only one way so that their product is 16. So the answer is 6 + 1 = 7.

Source: codeforces | Difficulty: HARD
Tags: Dynamic programming

Bit manipulation

Combinatorics

Mathematics


Solutions:
from collections import defaultdict

def getmask(x):
	ans = 0
	for i in range(2, x + 1):
		while x % i == 0:
			x //= i
			ans ^= 1 << i
	return ans

def main():
	maxn = 71
	n = int(input())
	a = [int(i) for i in input().split()]
	cnt = [0] * maxn
	for i in a:
		cnt[i] += 1
	masks = defaultdict(int)
	for i in range(1, maxn):
		masks[getmask(i)] += cnt[i]
	while masks[0] != sum(masks.values()):
		fixed = max((i for i in masks if masks[i]))
		masks[0] -= 1
		for i in list(masks.keys()):
			if i ^ fixed < i:
				masks[i ^ fixed] += masks[i]
				masks[i] = 0
	print(pow(2, masks[0], 10 ** 9 + 7) - 1)
main()


from collections import *
l = int(input())
c = Counter(map(int, input().split()))
t = defaultdict(int)
p = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67]
for (k, s) in c.items():
	d = 0
	for (i, q) in enumerate(p):
		while k % q == 0:
			k //= q
			d ^= 1 << i
	t[d] += s
u = defaultdict(int)
u[0] = 1
for x in t:
	if x:
		l -= 1
	if 0 < x < 2048:
		v = u.copy()
		for y in u:
			v[x ^ y] += u[y]
		u = v
e = 1000000007
print((u[0] * pow(2, l, e) - 1) % e)


n = int(input())
arr = [0] * 71
a = map(int, input().split())
for i in a:
	arr[i] += 1
dp = [0] * 2 ** 11
dp[0] = 1
for i in range(71):
	if arr[i] == 0 or i == 37 or i == 41 or (i == 43) or (i == 47) or (i == 53) or (i == 59) or (i == 61) or (i == 67):
		continue
	cur = 0
	primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67]
	for j in range(len(primes)):
		if i > 1 and i % primes[j] == 0:
			x = i
			cnt = 0
			while x % primes[j] == 0:
				x /= primes[j]
				cnt += 1
			if cnt % 2 == 1:
				cur += 2 ** j
	ndp = [0] * 2 ** 11
	for x in range(len(dp)):
		ndp[x ^ cur] += dp[x] * pow(2, arr[i] - 1, 10 ** 9 + 7)
		ndp[x ^ cur] %= 10 ** 9 + 7
		ndp[x] += dp[x] * pow(2, arr[i] - 1, 10 ** 9 + 7)
		ndp[x] %= 10 ** 9 + 7
	dp = ndp
ans = dp[0]
for i in [37, 41, 43, 47, 53, 59, 61, 67]:
	if arr[i] > 0:
		ans *= pow(2, arr[i] - 1, 10 ** 9 + 7)
		ans %= 10 ** 9 + 7
print((ans + 10 ** 9 + 6) % (10 ** 9 + 7))


n = int(input())
s = []
p = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67]
for i in set(map(int, input().split())):
	b = 0
	for j in p:
		while i % j == 0:
			i //= j
			b ^= 1 << j
	for j in s:
		b = min(b, b ^ j)
	if b > 0:
		s.append(b)
print(pow(2, n - len(s), 10 ** 9 + 7) - 1)


n = int(input())
s = []
p = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67]
for k in set(map(int, input().split())):
	d = 0
	for q in p:
		while k % q == 0:
			k //= q
			d ^= 1 << q
	for j in s:
		d = min(d, d ^ j)
	if d:
		s.append(d)
print(pow(2, n - len(s), 1000000007) - 1)


def getmask(x):
	ans = 0
	for i in range(2, x + 1):
		while x % (i * i) == 0:
			x //= i * i
		if x % i == 0:
			ans ^= 1 << i
			x //= i
	return ans

def main():
	maxn = 71
	n = int(input())
	a = [int(i) for i in input().split()]
	cnt = [0] * maxn
	for i in a:
		cnt[i] += 1
	masks = {}
	for i in range(1, maxn):
		if cnt[i]:
			masks[getmask(i)] = masks.get(getmask(i), 0) + cnt[i]
	while len(masks) > 1 or 0 not in masks:
		if not masks:
			print(0)
			return
		fixed = max(masks.keys())
		for i in list(masks.keys()):
			if i ^ fixed < i:
				masks[i ^ fixed] = masks.get(i ^ fixed, 0) + masks[i]
				masks[i] = 0
		masks[0] = masks.get(0, 0) + masks[fixed] - 1
		masks[fixed] = 0
		masks = {i: j for (i, j) in masks.items() if j > 0}
	print(pow(2, masks[0], 10 ** 9 + 7) - 1)
main()


MOD = int(1000000000.0 + 7)

def is_prime(x):
	for i in range(2, int(x ** 0.5) + 1):
		if x % i == 0:
			return False
	return True
p = [i for i in range(2, 100) if is_prime(i)]
n = int(input())
arr = list(map(int, input().split()))
s = []
for i in set(arr):
	b = 0
	for j in p:
		while i % j == 0:
			i //= j
			b ^= 1 << j
	for j in s:
		b = min(b, b ^ j)
	if b > 0:
		s.append(b)
print(pow(2, n - len(s), MOD) - 1)


import os, sys
from io import BytesIO, IOBase
from array import array
mod = 10 ** 9 + 7
fac = array('i', [1])
for ii in range(1, 10 ** 5 + 1):
	fac.append(fac[-1] * ii % mod)
fac_in = array('i', [pow(fac[-1], mod - 2, mod)])
for ii in range(10 ** 5, 0, -1):
	fac_in.append(fac_in[-1] * ii % mod)
fac_in.reverse()

def comb(a, b):
	if a < b:
		return 0
	return fac[a] * fac_in[a - b] * fac_in[b] % mod

def main():
	n = int(input())
	a = array('i', map(int, input().split()))
	primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
	primes1 = {37: 0, 41: 0, 43: 0, 47: 0, 53: 0, 59: 0, 61: 0, 67: 0}
	new = array('i', [])
	for (ind, i) in enumerate(a):
		if primes1.get(i) != None:
			primes1[i] += 1
			continue
		(mask, num) = (1, 0)
		for j in primes:
			while not i % j:
				num ^= mask
				i //= j
			mask <<= 1
		new.append(num)
	y = 1 << len(primes)
	dp = array('i', [0] * y)
	for i in new:
		dp1 = dp[:]
		for j in range(y):
			z = i ^ j
			dp1[z] += dp[j]
			if dp1[z] >= mod:
				dp1[z] -= mod
		dp1[i] += 1
		if dp1[i] >= mod:
			dp1[i] -= mod
		dp = dp1
	ans = dp[0] + 1
	for i in primes1:
		aa = 0
		for j in range(0, primes1[i] + 1, 2):
			aa = aa + comb(primes1[i], j)
			if aa >= mod:
				aa -= mod
		ans = ans * aa % mod
	print((ans - 1) % mod)
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')
main()


from sys import stdin

def find_prime(max_value):
	assert max_value >= 2
	result = [2]
	for i in range(3, max_value):
		state = 1
		for item in result:
			if item * item > i:
				break
			elif i % item == 0:
				state = -1
				break
		if state == 1:
			result.append(i)
	return result
module = int(1000000000.0) + 7
n = int(stdin.readline())
A = list(map(int, stdin.readline().split()))
number = [0 for i in range(70)]
for item in A:
	number[item - 1] += 1
prime_list = find_prime(70)
prime_map = {}
for i in range(2, 70 + 1):
	result = 0
	for item in prime_list:
		cur = i
		num = 0
		while cur % item == 0:
			num += 1
			cur = int(cur / item)
		result = result * 2 + num % 2
	prime_map[i] = result
number_dic = {0: 1}
sum_time = 0
for i in range(2, 70 + 1):
	if number[i - 1] >= 1:
		mask = prime_map[i]
		state = 1
		new_number_dic = number_dic.copy()
		for (key, value) in list(new_number_dic.items()):
			new_key = key ^ mask
			if new_key in number_dic:
				number_dic[new_key] += value
			else:
				number_dic[new_key] = value
			number_dic[new_key] %= module
		sum_time += number[i - 1] - 1
result = number_dic[0]
for j in range(number[0] + sum_time):
	result *= 2
	result %= module
print(result - 1)


n = int(input())
(*a,) = map(int, input().split())
mod = 1000000007
d = []
primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67]
b = [0, 4, 8, 0, 32, 12, 128, 4, 0, 36, 2048, 8, 8192, 132, 40, 0, 131072, 4, 524288, 32, 136, 2052, 8388608, 12, 0, 8196, 8, 128, 536870912, 44, 2147483648, 4, 2056, 131076, 160, 0, 137438953472, 524292, 8200, 36, 2199023255552, 140, 8796093022208, 2048, 32, 8388612, 140737488355328, 8, 0, 4, 131080, 8192, 9007199254740992, 12, 2080, 132, 524296, 536870916, 576460752303423488, 40, 2305843009213693952, 2147483652, 128, 0, 8224, 2060, 147573952589676412928, 131072, 8388616, 164]
for i in set(a):
	c = b[i - 1]
	for j in d:
		c = min(c, c ^ j)
	if c > 0:
		d.append(c)
print(pow(2, n - len(d), mod) - 1)