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

#SP0000247. Tính đa dạng của phân tích thừa số nguyên tố (The Diversity of Prime Factorization)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Tính đa dạng của phân tích thừa số nguyên tố (The Diversity of Prime Factorization)

The Diversity of Prime Factorization

Source: AOJ

Version: Phuoc Hung OJ Extended

Problem Statement

A machine factorizes an integer M>1M>1 as

$$M=p_1^{e_1}p_2^{e_2}\cdots p_K^{e_K},\qquad p_1<p_2<\cdots<p_K,$$

where every pip_i is prime and every exponent ei≥1e_i\ge1. The machine outputs tokens in increasing order of ii: it outputs only pip_i when ei=1e_i=1, and outputs two consecutive tokens pi,eip_i,e_i when ei>1e_i>1.

There is no separator distinguishing primes from exponents. Different integers MM may therefore produce the same sequence. Given the printed sequence q1,…,qNq_1,\ldots,q_N, count distinct integers M>1M>1 that could produce it. Print 00 if no such integer exists, and take the result modulo 109+710^9+7.

Input

  • The first line contains NN, the number of output tokens produced by the machine, not the original integer MM.
  • The second line contains exactly NN integers q1,q2,…,qNq_1,q_2,\ldots,q_N in their output order.

Output

Print the number of distinct integers M>1M>1 producing exactly the given token sequence, modulo 109+710^9+7.

Subtasks

  • Subtask 1 (20 points): 1≤N≤201\le N\le20; 2≤qi≤1002\le q_i\le100 for all 1≤i≤N1\le i\le N.
  • Subtask 2 (30 points): 1≤N≤20001\le N\le2000; 2≤qi≤1042\le q_i\le10^4 for all 1≤i≤N1\le i\le N.
  • Subtask 3 (50 points): 1≤N≤1051\le N\le10^5; 2≤qi≤1062\le q_i\le10^6 for all 1≤i≤N1\le i\le N.

Examples

Input

3
2 3 3

Output

2

Explanation

For tokens [2,3,3][2,3,3], there are exactly two legal partitions. Split as [2,3] [3]: this encodes 23⋅3=242^3\cdot3=24. Or split as [2] [3,3]: this encodes 2⋅33=542\cdot3^3=54. Each block begins with a prime, the primes increase strictly, and the two encoded integers differ. There are no other legal partitions, so the answer is 2.