PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#GL0000366. Đếm tập con có tích là số chính phương (Square Subsets)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Đếm tập con có tích là số chính phương (Square Subsets)

Square Subsets

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

Given nn positive integers a1,…,ana_1,\ldots,a_n, choose a nonempty subset of indices and multiply the corresponding values. A selection is valid when its product is a perfect square k2k^2 for a positive integer kk. Two selections differ if their index sets differ, even if the selected values are equal.

Count the valid selections modulo 109+710^9+7.

Input

  • Line 1: the integer nn.
  • Line 2: the nn integers a1,…,ana_1,\ldots,a_n.

Output

Print the number of nonempty index subsets with a perfect-square product, modulo 109+710^9+7.

Subtasks

  • Subtask 1 (20 points): 1≤n≤161\le n\le16; 1≤ai≤701\le a_i\le70.
  • Subtask 2 (30 points): 1≤n≤25001\le n\le2500; 1≤ai≤351\le a_i\le35.
  • Subtask 3 (50 points): 1≤n≤1000001\le n\le100000; 1≤ai≤701\le a_i\le70.

Examples

Example 1

Input

4
1 1 1 1

Output

15

Explanation

Every product equals 1=121=1^2. Among 24=162^4=16 subsets of four positions, exclude the empty subset: 1515 remain.

Example 2

Input

4
2 2 2 2

Output

7

Explanation

The number of selected 22s must be even. There are (42)=6\binom{4}{2}=6 ways to select two positions and (44)=1\binom{4}{4}=1 way to select all four, giving 77.

Example 3

Input

5
1 2 4 5 8

Output

7

Explanation

Value 55 must be excluded. Among 1,2,4,81,2,4,8, the entries 22 and 88 must either both be selected or both omitted, while 11 and 44 are independent choices. This gives 2⋅2⋅2=82\cdot2\cdot2=8 subsets including the empty one, hence 77.