Simple coincidence#3688

Simple coincidence

1 second
256 megabytes
Hard

Let be a prime number. You are given digital rows, each with a length of p-1. You can perform any cyclic shift on each row and rearrange the rows in any order. Then, concatenate all the rows into a single string, which may include leading zeros, to form a number. Your task is to determine how many ways you can select these cyclic shifts and arrangements so that the resulting number is divisible by .

Input

The first line contains a prime number (2 \le p \le 23). The following lines each contain p-1 characters, which may include leading zeros. All characters are digits.

Output

Output the number of ways to select permutations of cyclic shifts such that their concatenation is divisible by . The result should be given modulo .

Examples

Example 1

Loading
Loading