2025 XVII Donald Knuth Annual Programming Contest by ESCOM-IPN
A. A Non-Prime Number
time limit per test
1 second
memory limit per test
1024 megabytes
input
standard input
output
standard output

The 17th Annual Donald Knuth Programming Contest has just begun, and the very first challenge, the problem A, sets the tone for the event. The problemsetters wanted to test not only algorithmic skill but also a deep intuition about numbers.

This year's opening problem comes with a playful story: Miguel, an enthusiast of mathematics, prepared a mysterious box containing slips of paper with numbers from $$$1$$$ to $$$n$$$. The task is simple at first glance: you may take any subset of these slips and add them together.

But there is a twist — Miguel was not interested in prime numbers. He believed primes were already "too famous," so he asked contestants to ignore them.

A number is called prime if it is greater than $$$1$$$ and has no positive divisors other than $$$1$$$ and itself. In particular, $$$1$$$ is not considered prime.

The question Miguel posed is: among all possible subset sums, what is the largest number that is not prime?

Input

The input consists of a single integer $$$n$$$ ($$$1 \leq n \leq 10^9$$$).

Output

Print the maximum subset sum that is not prime.

Examples
Input
1
Output
1
Input
3
Output
6
Input
1000000000
Output
500000000500000000

B. Beautiful Trees
time limit per test
3 seconds
memory limit per test
1024 megabytes
input
standard input
output
standard output

As everyone knows, the Legendary Huron loves playing with magnetic sticks of many colors. After finishing his colorful polygon constructions last Saturday, he now wants to store his sticks in boxes.

Legendary Huron owns $$$m$$$ magnetic sticks. Each stick has a color, represented by an integer in the range $$$[0, m-1]$$$. Sticks of the same color are indistinguishable.

He plans to store these sticks in $$$n$$$ distinct boxes. Each stick must be placed in exactly one box.

Once the sticks are distributed, Legendary Huron will hang the boxes in the form of a colorful rooted tree:

  • One box will be chosen as the root and hung directly from the ceiling.
  • Every other box will be hung directly from exactly one parent box, forming a tree structure with $$$n$$$ nodes (the boxes).

Legendary Huron defines the beauty of his arrangement as follows:

  • Beauty of a box: the MEX of the colors inside that box. Recall that the MEX of a multiset of integers is the smallest non-negative integer that does not belong to the multiset. For example, if a box contains sticks of colors $$$\{0,2,2,5\}$$$, its beauty is $$$1$$$.
  • Beauty of a path: the product of the beauties of all boxes along that path.
  • Beauty of the tree: the sum of the beauties of all $$$n^2$$$ simple paths in the tree (including single-box paths).

Legendary Huron is still undecided about two things:

  1. How to distribute the $$$m$$$ sticks among the $$$n$$$ boxes.
  2. How to hang the boxes as a rooted tree.

He wants to know the total sum of beauties of the trees over all possible valid configurations. Two configurations are considered different if:

  • The tree structures differ (different root or different set of edges), or
  • There exists at least one box whose multiset of colors differs.

Note: The boxes are distinct (labeled), but the sticks of the same color are indistinguishable.

Input

The file contains multiple test cases. The first line contains an integer $$$t$$$ $$$(1 \leq t \leq 10^5)$$$ — the number of test cases.

The first line of each test case description contains two integers $$$n$$$ and $$$m$$$ $$$(1 \leq n, m \leq 10^6)$$$.

The following line contains $$$m$$$ integers between $$$0$$$ and $$$m-1$$$, representing the colors of each magnetic stick.

It is guaranteed that the sum of all values of $$$m$$$ over the input does not exceed $$$10^6$$$.

Output

For each test case, answer modulo $$$998244353$$$ — the total sum of beauties of the trees over all possible ways of distributing the sticks and constructing the colorful rooted tree.

Examples
Input
3
1 3
0 1 2
2 3
0 1 2
3 3
0 1 2
Output
3
28
351
Input
1
10 7
3 0 1 2 0 3 1
Output
335613770

C. Chained Training
time limit per test
2 s
memory limit per test
1024 megabytes
input
standard input
output
standard output

After retiring from competitive programming, May decided to become a Pokémon trainer. She has $$$N$$$ Pokémon, and each Pokémon is described by three values: defense ($$$d$$$), health ($$$h$$$), and attack ($$$a$$$).

May is creating a training plan called Chained Training. Her Pokémon are arranged in a line, and the Pokémon at index $$$i$$$ can only fight a Pokémon at index $$$j$$$ such that $$$j \lt i$$$.

When Pokémon $$$i$$$ battles Pokémon $$$j$$$, Pokémon $$$i$$$ gains experience according to the following formula:

$$$$$$ \text{experience}(i, j) = d_j \cdot a_i + \frac{h_j}{d_i} $$$$$$

May has a gym battle soon, so she wants her Pokémon to gain as much experience as possible by fighting against a single Pokémon. For each Pokémon, determine the maximum amount of experience it can gain if she chooses its rival optimally.

Input

The first line contains a single integer $$$N$$$ ($$$1 \leq N \leq 10^6$$$) — the number of Pokémon.

The next $$$N$$$ lines each contain three integers $$$d_i$$$, $$$h_i$$$, and $$$a_i$$$ ($$$1 \leq d_i, h_i, a_i \leq 10^6$$$) — the defense, health, and attack of the $$$i$$$-th Pokémon.

Output

Print $$$N$$$ lines. For each Pokémon $$$i$$$, output two integers — the numerator and denominator of the irreducible fraction representing the maximum experience that the $$$i$$$-th Pokémon can gain.

Examples
Input
5
4 3 17
5 2 5
4 1 30
1 2 2
8 1 10
Output
0 1
103 5
301 2
12 1
201 4
Input
5
1 2 10
3 3 21
8 2 34
1 1 16
4 2 53
Output
0 1
65 3
819 8
130 1
849 2
Input
1
1 2 3
Output
0 1

D. Drone Kaleidoscope
time limit per test
3 seconds
memory limit per test
1024 megabytes
input
standard input
output
standard output

Welcome to the XVII Annual Drone Kaleidoscope (DK for short)! A one-lane track is written as a string $$$s$$$ of $$$n$$$ lowercase characters.

During the annual DK, several teams, one by one, perform a show as follow:

  • Each team picks a different palindrome that actually appears somewhere on the track.
  • Each team selects some subset of occurrences of their chosen palindrome, and places a drone in the leftmost character of the selected occurrences.
  • To avoid radio noise within the team performance, that team's drone starting positions must be at least $$$k$$$ characters apart.
  • Finally, the team flies their drones over the selected occurrences of the chosen palindrome.

A team's show value is $$$$$$ \text{(length of its palindrome)} \times \text{(number of drones it places)}. $$$$$$

Choose how many teams to field (each using a distinct palindrome) and, for each chosen team, pick the starting positions of its drones so as to maximize the total show value across all shows.

For example, if we have $$$s=abaaba$$$ and k=3, a valid show configuration is to field $$$3$$$ teams as follows:

  1. The first team chooses the palindrome $$$aba$$$ and launches $$$2$$$ drones with initial positions $$$\{1,4\}$$$. This team's show value is $$$3 \times 2=6$$$.
  2. The second team chooses the palindrome $$$baab$$$ and launches $$$1$$$ drones with initial position $$$\{2\}$$$. This team's show value is $$$4 \times 1=4$$$.
  3. The third team chooses the palindrome $$$a$$$ and launches $$$2$$$ drones with initial positions $$$\{1,6\}$$$. This team's show value is $$$1 \times 2=2$$$. Note that launching $$$3$$$ drones with initial positions $$$\{1,3,6\}$$$ is invalid, since starting positions should be at least $$$k=3$$$ characters apart.

The total show value in this example is $$$6+4+2=12$$$. Note that this is not the configuration that maximizes the total show value.

Input

Each test contains multiple test cases. The first line contains $$$t$$$ ($$$1 \le t \le 10^5$$$) — the number of test cases.

The first line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$1\leq n \leq 10^5$$$ and $$$1 \leq k \leq n$$$) — the length of string $$$s$$$ and the parameter $$$k$$$ described in the statements.

The following line contains a string $$$s$$$ of length $$$n$$$ consisting only of English lowercase characters.

The sum of $$$n$$$ over all test cases is guaranteed to be at most $$$10^5$$$.

Output

Print one integer for each test case — the maximum total show value you can achieve.

Example
Input
4
7 2
abacaba
7 4
abacaba
7 6
abacaba
6 3
abaaba
Output
28
26
22
22

E. Esoteric Computer Architecture 2
time limit per test
2 seconds
memory limit per test
1024 megabytes
input
standard input
output
standard output

During the Segunda Fecha del Gran Premio de México, Ángel built his unusual computer prototype. Thanks to your help, he was able to complete his assignment, but a new defect has now appeared.

This time, the problem lies in the rotation instruction. Ángel wants to transform an array $$$A = [a_1, a_2, \dots, a_n]$$$ into another array $$$B = [b_1, b_2, \dots, b_n]$$$. He can perform the following operation any number of times:

  • Choose indices $$$l,r$$$ with $$$1 \le l \le r \le n$$$, and an integer $$$k$$$ with $$$0 \leq k \leq 10^6$$$. Rotate the subarray $$$A[l,r]$$$ to the left at the digit level exactly $$$k$$$ times.

For example, if $$$A = [12, 345, 67, 8, 9]$$$ and you apply the operation on the subarray $$$A[2,4]$$$ with $$$k=2$$$, the result is $$$[12, 567, 83, 4, 9]$$$.

Decide whether it is possible to transform $$$A$$$ into $$$B$$$ using a sequence of such operations. If it is possible, you must also output one valid sequence.

Input

The file contains multiple test cases. The first line contains an integer $$$t$$$ $$$(1 \leq t \leq 5 \cdot 10^4)$$$ — the number of test cases.

The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 5 \cdot 10^4$$$) — the size of the arrays $$$A$$$ and $$$B$$$.

The second line of each test case contains $$$n$$$ integers $$$A_1,A_2,\dots,A_n$$$ ($$$1 \leq A_i \lt 10^4$$$) — the array $$$A$$$.

The third lin of each test casee contains $$$n$$$ integers $$$B_1,B_2,\dots,B_n$$$ ($$$1 \leq B_i \lt 10^4$$$) — the array $$$B$$$.

It is guaranteed that no element of the arrays contains the digit $$$0$$$.

It is guaranteed that the sum of all values of $$$n$$$ over the input does not exceed $$$5 \cdot 10^4$$$.

Output

For each test case, print an integer $$$m$$$ ($$$0 \leq m \leq 16n$$$) in the first line of your output if it is possible to transform array $$$A$$$ in array $$$B$$$; otherwise print $$$-1$$$.

If it is possible, then print $$$m$$$ lines with the operations. Each operation should be indicated with three integers $$$l$$$, $$$r$$$, and $$$k$$$ ($$$1 \leq l \leq r \leq n$$$ and $$$0 \leq k \leq 10^6$$$) — the parameters of each operation.

Example
Input
1
4
123 45 6 78
345 26 7 81
Output
2
1 2 2
2 4 1

F. Fifth Commandment
time limit per test
3 seconds
memory limit per test
1024 megabytes
input
standard input
output
standard output

The coaches of TCMX 2025 are preparing the fifth contest. Racso came up with the idea of stealing the samples of the problems. Abraham and Ivan want to stop him, so they have protected the samples with laser beams. Each laser beam can be represented as a line segment from $$$(x_1,y_1)$$$ to $$$(x_2,y_2)$$$ parallel to one of the axis.

To verify how safe the test cases are, they will check $$$Q$$$ scenarios.

In each scenario, the initial position of Racso and the position of the samples are given. Racso will succeed in stealing the samples if he can move from his starting position to the place where the samples are located. Racso is represented as a point in the plane and fails if he touches any laser beam at any moment, even if it happens at the beginning or at the end of his path.

For each scenario, determine whether Racso can succeed.

Input

The first line contains two integers $$$n$$$ and $$$Q$$$ ($$$1 \leq n \leq 1000$$$, $$$1 \leq Q \leq 10^6$$$) — the number of laser beams and the number of scenarios.

Each of the next $$$n$$$ lines contains four integers $$$x_1, y_1, x_2, y_2$$$ ($$$|x_1|, |y_1|, |x_2|, |y_2|\leq 10^9$$$), describing a laser beam represented by the segment between $$$(x_1,y_1)$$$ and $$$(x_2,y_2)$$$. Each beam is either vertical or horizontal (i.e. it has either $$$x_1=x_2$$$ or $$$y_1=y_2$$$).

Then follow $$$Q$$$ lines. Each line contains four integers $$$x_s, y_s, x_t, y_t$$$ ($$$|x_s|,|y_s|,|x_t|,|y_t|\leq 10^9$$$), indicating that the starting position of Racso is $$$(x_s,y_s)$$$ and the position of the samples is $$$(x_t,y_t)$$$.

Output

For each scenario, print YES if Racso can succeed in reaching the samples, or NO otherwise.

Example
Input
4 3
0 0 0 5
4 0 4 5
-1 1 5 1
-1 4 5 4
2 2 5 5
2 2 4 4
2 2 3 3
Output
NO
NO
YES

G. Galactic Reassigment
time limit per test
1 second
memory limit per test
1024 megabytes
input
standard input
output
standard output

The Galactic Empire has organized its planets in a strict chain of command. At the very top lies Coruscant, the capital of the system. The planets are numbered from $$$1$$$ to $$$n$$$ according to their closeness to Coruscant (being Coruscat the planet with number $$$1$$$). Every other planet $$$u$$$ has a direct supervisor $$$p_u$$$ with $$$1 \le p_u \lt u$$$, forming a rooted tree with root in planet Coruscant.

Emperor Palpatine has decreed that all planets must be directly supervised by Coruscant, eliminating intermediate overseers (i.e., in the end every $$$u \ge 2$$$ must satisfy $$$p_u=1$$$).

You are granted the following operation:

  • Choose a planet $$$u$$$. For every planet $$$v$$$ on the chain of command from $$$u$$$ up to Coruscant (including $$$u$$$ but excluding Coruscant), reassign its supervisor to be the planet immediately closer to Coruscant; that is, decrement $$$p_v$$$ by one (set $$$p_u \leftarrow p_v - 1$$$). This gradual decrement by one is required to avoid instability within the Empire, since sudden jumps in authority could trigger rebellion and chaos.

Your task is to determine the minimum number of operations required so that, after applying them, every planet reports directly to Coruscant.

Input

The first line contains an integer $$$t$$$ ($$$1 \le t \le 2 \cdot 10^5$$$) — the number of test cases.

Each test case begins with a line containing an integer $$$n$$$ ($$$2 \le n \le 2 \cdot 10^5$$$) — the number of planets. The second line contains $$$n-1$$$ integers $$$p_2, p_3, \dots, p_n$$$ ($$$1 \le p_i \lt i$$$).

It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.

Output

For each test case, print a single integer: the minimum number of operations needed so that $$$p_u = 1$$$ for all $$$u = 2,3,\dots,n$$$.

Example
Input
3
4
1 2 1
4
1 2 2
4
1 2 3
Output
1
2
2

H. Hive Revenge
time limit per test
1 second
memory limit per test
1024 megabytes
input
standard input
output
standard output

In a previous Concurso Anual de Programación "Donald Knuth", Rem faced a peculiar problem: counting the number of different ways to travel across a hive-shaped grid.

The grid is formed by columns of hexagonal cells:

  • The first column has exactly 1 cell.
  • The second column has 2 cells.
  • The third column has 3 cells.
  • $$$\dots$$$
  • The $$$(n+1)$$$-th column has $$$n+1$$$ cells.
  • After that, each subsequent column has one fewer cell than the previous, until the final $$$(2n+1)$$$-th column which has exactly 1 cell.

Thus, the grid consists of $$$2n+1$$$ columns of hexagonal cells, forming the shape of a "diamond hive." The entry cell is the single hexagon in the first column, and the storage cell is the single hexagon in the last column.

Below is an example of the grid with size $$$n=3$$$ with the valid set of movements for a single cell:

Rem solved the original challenge: finding how many paths exist from the entry to the storage without visiting the same hexagonal cell twice.

Later, he wondered: "If someone naïvely tried to simulate every single path with a brute-force depth-first search, how many total steps would such an algorithm actually take?"

In this brute-force simulation, for each valid path, a DFS would traverse the entire path from beginning to end. Therefore, the total cost of this approach equals the sum of the lengths of all distinct paths, where the length of a path is the number of hexagonal cells it visits.

Your task is to compute the sum of the lengths of all distinct paths.

Input

The file contains multiple test cases. The first line contains an integer $$$t$$$ $$$(1 \leq t \leq 10^5)$$$ — the number of test cases.

Each test case contains a single integer $$$n$$$ ($$$1 \leq n \leq 10^6$$$) — the size of the hive.

Output

For each test case, print a single integer — the answer to the problem, modulo $$$998244353$$$.

Example
Input
4
1
2
3
10
Output
14
432
24704
214063417

I. In Search of Soles
time limit per test
1.5 seconds
memory limit per test
1024 megabytes
input
standard input
output
standard output

You are given $$$n$$$ identical biased coins. In each toss, every coin shows sol with probability $$$\tfrac{p}{q}$$$ and águila with probability $$$1 - \tfrac{p}{q}$$$. Initially, none of the coins has shown sol.

You perform the following process:

  • In each round, you toss all coins that have not shown sol yet.
  • Once a coin shows sol for the first time, it is removed from further tosses.
  • The process continues until every coin has shown sol at least once.

Let $$$T$$$ denote the number of rounds until this happens. Your task is to compute the expected value of $$$T$$$.

Input

The input consists of three integers $$$n$$$, $$$p$$$, and $$$q$$$ ($$$1 \leq n \leq 10^7$$$, $$$1 \leq p \leq q \lt 998244353$$$), where $$$\tfrac{p}{q}$$$ is the probability that a coin shows heads in a single toss.

Output

Print a single integer: the expected number of rounds until all $$$n$$$ coins have shown sol, modulo $$$998244353$$$.

Examples
Input
1 1 2
Output
2
Input
2 1 2
Output
665496238

J. Just an integer
time limit per test
7 seconds
memory limit per test
1024 megabytes
input
standard input
output
standard output

You are given a directed graph $$$G = (V,E)$$$ with $$$n$$$ nodes. The set of vertices is $$$V = \{1,2,\dots,n\}$$$. For every node $$$u \in V$$$, there is a directed edge from $$$u$$$ to each of its proper divisors. Formally: $$$$$$ (u,v) \in E \quad \text{iff} \quad v \mid u \quad \text{and} \quad 1 \leq v \lt u. $$$$$$

For each node $$$u$$$, define:

  • $$$I(u)$$$: the length of the longest directed path in $$$G$$$ that ends at $$$u$$$.
  • $$$O(u)$$$: the length of the longest directed path in $$$G$$$ that starts at $$$u$$$.

The length of a path is the number of edges it contains.

Your task is to compute the following sum: $$$$$$ S(n) = \sum_{u=1}^{n} \max\big(I(u), O(u)\big). $$$$$$

Input

The input consists of a single integer $$$n$$$ ($$$1 \leq n \leq 10^{10}$$$).

Output

Output a single integer — the value of $$$S(n)$$$.

Examples
Input
1
Output
0
Input
3
Output
3
Input
4
Output
6
Input
5
Output
7

K. Kadane's Algorithm?
time limit per test
5 seconds
memory limit per test
1024 megabytes
input
standard input
output
standard output

José is practicing graph and tree problems on the HuronCoder platform, and he came across the following challenge.

You are given a tree with $$$n$$$ nodes, rooted at node $$$1$$$. The parent of each node $$$u$$$ is $$$p_u$$$, with $$$1 \le p_u \lt u$$$. Each node $$$u$$$ has an associated value $$$a_u$$$.

You need to process queries of three types:

  1. Assign $$$k$$$ to the value of node $$$u$$$: $$$a_u \leftarrow k$$$.
  2. Given $$$u, v$$$, consider the unique path between $$$u$$$ and $$$v$$$. Select a non-empty contiguous subsequence of nodes along that path such that the sum of their values is maximized, and report that sum.
  3. For every $$$i$$$ in the range $$$[l, r]$$$, update $$$p_i \leftarrow \max(1,\; p_i - k)$$$, where $$$k$$$ is given in the query.

José needs your help.

Input

The first line contains two integers $$$n$$$ and $$$q$$$ ($$$2 \leq n \leq 2 \cdot 10^5$$$ and $$$1 \leq q \leq 2 \cdot 10^5$$$) — the number of nodes in the tree and the number of queries.

The second line contains $$$n-1$$$ integers $$$p_2,p_2,\dots,p_n$$$ ($$$1 \leq p_i \lt i$$$) — the parent of each node.

The third line contains $$$n$$$ integers $$$a_1,a_2\dots,a_n$$$ ($$$|a_i| \leq 10^9$$$) — the initial values of each node.

The next $$$q$$$ lines describe the queries:

  1. If the operation type is $$$1$$$, the line contains three integers $$$1$$$, $$$u$$$, and $$$x$$$ ($$$1 \leq u \leq n$$$ and $$$|x| \leq 10^9$$$).
  2. If the operation type is $$$2$$$, the line contains three integers $$$2$$$, $$$u$$$, and $$$v$$$ ($$$1\leq u, v \leq n$$$).
  3. If the operation type is $$$3$$$, the line contains four integers $$$3$$$, $$$l$$$, $$$r$$$ and $$$k$$$ ($$$1\leq l \leq r \leq n$$$ and $$$1 \leq k \lt n$$$).
Output

For each query of type $$$2$$$, print an integer representing the answer to this query.

Example
Input
5 7
1 1 3 3
3 -5 2 -1 -3
2 4 5
3 2 5 1
2 4 5
1 2 1
2 4 5
3 4 5 2
2 4 2
Output
2 -1 1 4 

L. Leo's Daily Training (2025 version)
time limit per test
1 second
memory limit per test
1024 megabytes
input
standard input
output
standard output

Leo is now training for the ICPC 2025 Regional Finals. As part of his preparation, he uses the popular site HuronCoder, which contains many problems with different tags.

The site has $$$N$$$ problems numbered from $$$1$$$ to $$$N$$$ and $$$M$$$ tags numbered from $$$1$$$ to $$$M$$$. Each problem can be tagged with any subset of tags (including the empty subset or the full set of tags).

Leo wonders if it is possible to pick a subset of problems so that, when combined, they cover all tags.

Input

The first line contains two integers $$$N, M$$$ ($$$1 \le N \le 20$$$ and $$$1 \le M \le 20$$$) — the number of problems and the number of tags.

Each of the next $$$N$$$ lines contains $$$M$$$ integers, where the $$$j$$$-th integer is $$$1$$$ if the problem has tag $$$j$$$, and $$$0$$$ otherwise.

Output

Print "Yes" if it is possible to choose a subset of problems that covers all $$$M$$$ tags. Otherwise, print "No".

Examples
Input
4 4
1 0 0 0
0 1 0 0
0 0 1 0
0 0 0 1
Output
Yes
Input
3 4
1 0 0 0
0 1 0 0
0 0 1 0
Output
No
Input
3 2
0 0
0 1
1 1
Output
Yes
Input
3 3
0 1 0
1 1 1
0 1 0
Output
Yes

M. Matrix operations
time limit per test
1 second
memory limit per test
1024 megabytes
input
standard input
output
standard output

Okarun is studying alien art. Alien art is represented by a square matrix that contains blank characters, digits from $$$1$$$ to $$$9$$$, the symbol '$$$+$$$', or the symbol '$$$*$$$'. We call such square matrix an art matrix, and it is defined recursively as follows:

  • A matrix of size $$$1 \times 1$$$ that contains a single digit $$$d$$$ different from $$$0$$$.
  • A matrix of size $$$N \times N$$$ ($$$N \gt 1$$$) that has the same character $$$c$$$ ($$$c \in \{+, *\}$$$) in its four corners, and $$$0$$$ or more non-adjacent art matrices placed inside its inner submatrix.

The inner submatrix is obtained by removing the leftmost and rightmost columns, as well as the top and bottom rows. Two art matrices are considered non-adjacent if there is at least one blank character adjacent to every cell on their borders.

Each art matrix has an associated beauty value $$$b$$$, defined as:

  • If $$$N = 1$$$, then $$$b = d$$$, where $$$d$$$ is the digit contained in the matrix.
  • If $$$N \gt 1$$$ and $$$c = +$$$, then $$$b = \sum\limits_{m \in M} b_m$$$, where $$$M$$$ is the set of art matrices in the inner submatrix. If $$$M$$$ is empty, $$$b = 0$$$.
  • If $$$N \gt 1$$$ and $$$c = *$$$, then $$$b = \prod\limits_{m \in M} b_m$$$, where $$$M$$$ is the set of art matrices in the inner submatrix. If $$$M$$$ is empty, $$$b = 1$$$.

Given an art matrix, tell Okarun the beauty of the matrix.

Input

The first line contains a single integer $$$N$$$ ($$$1 \leq N \leq 1000$$$) — the size of the matrix.

The next $$$N$$$ lines each contain a string of $$$N$$$ characters representing the $$$i$$$-th row of the matrix. Blank cells are represented by the '.' character.

Output

Print a single integer $$$b$$$ — the beauty of the Alien art matrix modulo $$$10^9 + 7$$$.

Examples
Input
6
+....+
.3.4..
..1...
....2.
.1.1..
+....+
Output
12
Input
11
+.........+
.*...*.....
..3.3..+.+.
...2....5..
..3.3..+.+.
.*...*.....
...........
...+.+.*.*.
....1...4..
...+.+.*.*.
+.........+
Output
172
Input
2
**
**
Output
1
Input
1
2
Output
2