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

#SP0000253. Pha trà (Tea Blend)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Pha trà (Tea Blend)

Tea Blend

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

There are nn tea packs indexed 1,2,…,n1,2,\ldots,n in purchase order, with positive integer strengths aia_i.

To brew a blend, the brewer combines one portion from each of the first jj packs, then adds one more portion from pack ii. The index ii may be among the first jj; in that case pack ii is used twice. The blend strength is

F(i,j)=ai⋅∏k=1jak.F(i,j)=a_i\cdot\prod_{k=1}^{j}a_k.

A blend is capricious if F(i,j)F(i,j) has an odd number of positive divisors. Count the ordered index pairs (i,j)(i,j) with 1≤i,j≤n1\le i,j\le n producing capricious blends. Different index pairs are distinct even if they yield the same strength.

Input

The first line contains nn, the number of tea packs.

The second line contains exactly nn integers a1,a2,…,ana_1,a_2,\ldots,a_n in order.

Output

Print a single 64-bit integer: the number of pairs (i,j)(i,j) for which F(i,j)F(i,j) has an odd number of positive divisors. No modulo is applied.

Subtasks

  • Subtask 1 (20 points): 1≤n≤201\le n\le 20; 1≤ai≤10000001\le a_i\le 1000000 for every 1≤i≤n1\le i\le n.
  • Subtask 2 (30 points): 1≤n≤20001\le n\le 2000; 1≤ai≤10000001\le a_i\le 1000000 for every 1≤i≤n1\le i\le n.
  • Subtask 3 (50 points): 1≤n≤2000001\le n\le 200000; 1≤ai≤10000001\le a_i\le 1000000 for every 1≤i≤n1\le i\le n.

Examples

Input

4
2 3 6 4

Output

4

Explanation

Removing even prime exponents, the square-free signatures of the four strengths [2,3,6,4][2,3,6,4] correspond to [2,3,6,1][2,3,6,1]. The signatures of the four nonempty prefix products are [2,6,1,1][2,6,1,1].

The product ai⋅(a1⋯aj)a_i\cdot(a_1\cdots a_j) is a perfect square exactly when these two signatures coincide. The four choices of ii match respectively 1,0,1,21,0,1,2 prefixes, producing 1+0+1+2=41+0+1+2=4 valid pairs.