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

#SP0000151. Ada và biển số nguyên tố (Ada and Prime)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Ada và biển số nguyên tố (Ada and Prime)

Ada and Prime

Source: SPOJ — ADAPRIME

Version: Phước Hưng OJ Extended; one input file per judge run.

Problem Statement

Given a multiset of DD digits, count distinct primes obtainable by permuting all digits, with no leading zero. A single multiset is provided per PHOJ run.

Input

First line contains DD, second line the DD digits in [0,9][0,9].

Output

Print the number of distinct primes.

Subtask

  • Subtask 1 (20 points): 1≤D≤41\le D\le4, 0≤di≤90\le d_i\le9.
  • Subtask 2 (30 points): 1≤D≤71\le D\le7, 0≤di≤90\le d_i\le9.
  • Subtask 3 (50 points): 1≤D≤91\le D\le9, 0≤di≤90\le d_i\le9.

Example

Input

5
1 2 0 8 9

Output

11

Explanation

The example follows the mathematical conditions and the specified output format.