Matrix Exponentiation
A. Random Mood
time limit per test
0.25 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

This is a training contest on matrix exponentiation. See the tutorial along with hints and video solutions here.

Limak is always either happy or sad. His mood switches with probability $$$p$$$ every second. If Limak is happy right now, what is the probability that he's happy after $$$n$$$ seconds?

Input

An integer $$$n$$$ ($$$1 \leq n \leq 10^9$$$) and a real value $$$p$$$ ($$$0 \lt p \lt 1$$$) with at most 9 digits after floating point.

Output

Print one line with the answer. The absolute error allowed is $$$10^{-6}$$$.

Examples
Input
1 0.7
Output
0.3000000000
Input
2 0.1
Output
0.8200000000
Input
11 0.06
Output
0.6225404294
Note

In the first sample test, there's probability $$$0.7$$$ that Limak changes his mood from happy to sad. Otherwise (with probability $$$0.3$$$), he stays happy.

In the second sample test, the answer is $$$0.1 \cdot 0.1 + 0.9 \cdot 0.9 = 0.82$$$ because we want Limak either to switch his mood twice or not to change the mood at all.

B. String Mood
time limit per test
0.25 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Limak can be either happy or sad. His mood changes (or stays same) when he reads an English uppercase letter. Letters S and D always make him sad, H makes him happy, and every vowel (AEIOU) flips his mood. Other letters do nothing.

Limak is happy right now. Among all $$$26^n$$$ possible strings with $$$n$$$ uppercase English letters, count such strings that Limak will be happy after reading that string. Print the answer modulo $$$10^9+7$$$.

Input

An integer $$$n$$$ ($$$1 \leq n \leq 10^{18}$$$).

Output

Print the answer modulo $$$1000000007$$$.

Examples
Input
1
Output
19
Input
2
Output
403
Input
11
Output
145418665
Note

There are 19 strings of length $$$n = 1$$$ that will leave Limak happy: B, C, F, G, H, J, K, L, M, N, P, Q, R, T, V, W, X, Y, Z. The string "O" shouldn't be counted because the mood is switched from happy to sad.

For $$$n = 2$$$, there are 403 good strings: AA, AE, AH, AI, AO, AU, BB, ..., RZ, SA, SE, SH, SI, SO, SU, TB, TC, TF, ..., YQ, YR, YT, YV, YW, YX, YY, YZ, ZB, ZC, ZF, ZG, ZH, ZJ, ZK, ZL, ZM, ZN, ZP, ZQ, ZR, ZT, ZV, ZW, ZX, ZY, ZZ. The string "AO" is counted because the mood flips twice. Similarly, the string "SO" is counted because it first makes Limak sad (letter S) and then switches his mood from sad to happy (letter O).

C. Fibonacci
time limit per test
0.25 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Find the $$$n$$$-th Fibonacci number modulo $$$10^9+7$$$.

So, you need to find $$$F_n$$$ in the sequence defined as $$$F_0 = 0$$$, $$$F_1 = 1$$$ and $$$F_i = F_{i-1} + F_{i-2}$$$ for $$$i \geq 2$$$.

Input

An integer $$$n$$$ ($$$0 \leq n \leq 10^{18}$$$).

Output

Print the answer modulo $$$1000000007$$$.

Examples
Input
3
Output
2
Input
6
Output
8
Input
50
Output
586268941
Note

The first few terms of Fibonacci sequence are $$$(0, 1, 1, 2, 3, 5, 8, 13, \ldots)$$$. In particular, we have $$$F_0 = 0$$$, $$$F_3 = 2$$$ and $$$F_6 = 8$$$. And for the last sample test:

$$$$$$F_{50} = 12586269025 \equiv 586268941 \pmod {10^9 + 7}$$$$$$

D. Count Paths
time limit per test
1.5 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

You are given a graph with $$$n$$$ vertices (numbered $$$1$$$ through $$$n$$$) and $$$m$$$ directed edges. Count paths consisting of $$$k$$$ steps (edges) and print the answer modulo $$$10^9+7$$$. A path can visit the same vertex or edge multiple times.

Input

The first line contains three integers $$$n$$$, $$$m$$$ and $$$k$$$ ($$$1 \leq n \leq 100$$$, $$$0 \leq m \leq n \cdot (n - 1)$$$, $$$1 \leq k \leq 10^9$$$) — the number of vertices, the number of edges and the length of a path.

The following $$$m$$$ lines describe edges. The $$$i$$$-th of these lines contains two integers $$$a_i$$$ and $$$b_i$$$ ($$$1 \leq a_i, b_i \leq n, a_i \neq b_i$$$), denoting a directed edge from $$$a_i$$$ to $$$b_i$$$. There are no self-loops or multiple edges.

Output

Print the answer modulo $$$1000000007$$$.

Examples
Input
3 4 2
1 2
2 3
3 1
2 1
Output
5
Input
5 10 11
2 3
4 2
2 1
2 4
1 5
5 2
3 2
3 1
3 4
1 2
Output
21305
Note

In the first sample test, we are given the following graph with $$$n = 3$$$ vertices and $$$m = 4$$$ edges.

There are 5 paths of length $$$k = 2$$$:

  • $$$1 \rightarrow 2 \rightarrow 1$$$
  • $$$1 \rightarrow 2 \rightarrow 3$$$
  • $$$2 \rightarrow 1 \rightarrow 2$$$
  • $$$2 \rightarrow 3 \rightarrow 1$$$
  • $$$3 \rightarrow 1 \rightarrow 2$$$

E. Knight Paths
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

A knight stands in the top-left corner of an $$$8 \times 8$$$ chessboard. You can move it at most $$$k$$$ times. Count such possible paths modulo $$$2^{32}$$$.

Formally, count paths of cells $$$(C_1, C_2, \ldots, C_s)$$$ such that $$$1 \leq s \leq k+1$$$ and a knight can move from $$$C_i$$$ to $$$C_{i+1}$$$ for every $$$i$$$.

(A chess knight moves to a square that is two squares away horizontally and one square vertically, or one away horizontally and two vertically.)

Input

An integer $$$k$$$ ($$$0 \leq k \leq 10^9$$$).

Output

Print the answer modulo $$$2^{32} = 4294967296$$$.

Examples
Input
1
Output
3
Input
2
Output
15
Input
6
Output
17231
Note

In the first sample test, a knight can either stay in the initial cell $$$(1, 1)$$$ or move to $$$(2, 3)$$$ or $$$(3, 2)$$$. That's 3 ways in total.

F. Min Path
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

You are given a graph with $$$n$$$ vertices (numbered $$$1$$$ through $$$n$$$) and $$$m$$$ directed weighted edges. Find the minimum possible total weight of a path with $$$k$$$ edges. A path can visit the same vertex or edge multiple times.

If there is no path with $$$k$$$ edges, print IMPOSSIBLE instead.

Input

The first line contains three integers $$$n$$$, $$$m$$$ and $$$k$$$ ($$$1 \leq n \leq 100$$$, $$$0 \leq m \leq n \cdot (n - 1)$$$, $$$1 \leq k \leq 10^9$$$) — the number of vertices, the number of edges and the length of a path.

The following $$$m$$$ lines describe edges. The $$$i$$$-th of these lines contains three integers $$$a_i$$$, $$$b_i$$$ and $$$c_i$$$ ($$$1 \leq a_i, b_i \leq n, a_i \neq b_i$$$, $$$-10^9 \leq c_i \leq 10^9$$$), denoting a directed edge from $$$a_i$$$ to $$$b_i$$$ of weight $$$c_i$$$. There are no self-loops or multiple edges.

Output

Print the minimum possible sum of weights of a path with $$$k$$$ edges, or the word IMPOSSIBLE if there is no such path.

Examples
Input
3 4 2
1 2 12
2 3 -5
3 1 20
2 1 -1
Output
7
Input
3 4 5
1 2 12
2 3 -5
3 1 20
2 1 -1
Output
17
Input
6 5 3
1 3 -50
2 4 -51
4 3 -52
3 6 -53
4 5 -54
Output
-156
Input
6 5 4
1 3 -50
2 4 -51
4 3 -52
3 6 -53
4 5 -54
Output
IMPOSSIBLE
Note

The drawing below shows the graph in two first sample tests. The optimal paths are respectively $$$1 \rightarrow 2 \rightarrow 3$$$ and $$$2 \rightarrow 1 \rightarrow 2 \rightarrow 1 \rightarrow 2 \rightarrow 3$$$.

G. Recurrence With Square
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

The formula for Fibonacci numbers $$$F_i = 1 \cdot F_{i-1} + 1 \cdot F_{i-2}$$$ is an example of a linear recurrence relation. Let's consider a more general and difficult formula, which additionally involves the current index $$$i$$$.

Consider an infinite sequence defined by its first $$$n$$$ elements $$$a_0, a_1, \ldots, a_{n-1}$$$ and coefficients $$$c_1, \ldots, c_n, p, q, r$$$. For every $$$i \geq n$$$:

$$$$$$a_i = \left(c_1 \cdot a_{i-1} + c_2 \cdot a_{i-2} + \dots + c_n \cdot a_{i-n}\right) + p + i \cdot q + i^2 \cdot r$$$$$$

Find the value $$$a_k \bmod 10^9+7$$$.

Input

The first line contains two integers $$$n$$$ $$$(1 \leq n \leq 10)$$$ and $$$k$$$ $$$(1 \leq k \leq 10^{18})$$$.

The second line contains $$$n$$$ integers $$$a_0, a_1, \dots, a_{n-1}$$$ $$$(0 \leq a_i \lt 10^9+7)$$$ — the first $$$n$$$ elements of the sequence.

The third line contains $$$n$$$ integers $$$c_1, c_2, \dots, c_{n}$$$ $$$(0 \leq c_i \lt 10^9+7)$$$.

The fourth and last line contains three integers $$$p, q, r$$$ $$$(0 \leq p, q, r \lt 10^9+7)$$$.

Output

Print one line containing the number $$$a_k$$$ modulo $$$10^9+7$$$.

Examples
Input
2 2
0 30
2 1
2 1 1
Output
68
Input
1 3
5
1
2 3 4
Output
85
Note

In the first sample, the sequence is defined as $$$a_0=0$$$, $$$a_1=30$$$, $$$a_i=(2a_{i-1} + a_{i-2}) + 2 + i + i^2$$$, so $$$a_k=a_2=(2 \cdot 30 + 0) + 2 + 2 + 4=68$$$.

In the second sample, the first few elements of the sequence are $$$(5, 14, 38, 85, 163)$$$. As $$$k = 3$$$, we print $$$a_3 = 85$$$.

H. String Mood Updates
time limit per test
2 s
memory limit per test
256 megabytes
input
standard input
output
standard output

Limak can be either happy or sad. His mood changes (or stays same) when he reads an English uppercase letter. Letters S and D always make him sad, H makes him happy, and every vowel (AEIOU) flips his mood. Other letters do nothing. Limak is happy right now and he wants to be happy after reading a string.

Let a valid character denote a question mark ? or an uppercase English letter A-Z.

You are given a pattern-string $$$s$$$ with $$$n$$$ valid characters. If there are, say, $$$x$$$ question marks, there are $$$26^x$$$ ways to replace them with uppercase letters A-Z. Your task is to count ways of replacing so that Limak would be happy after reading a new string (if he's happy before).

Additionally, there are $$$q$$$ updates of form ,,$$$i \ c$$$", each modifying one character of the pattern $$$s$$$. You need to print the answer before updates and after every update, modulo $$$10^9+7$$$.

Input

The first line contains two integers $$$n$$$ and $$$q$$$ ($$$1 \leq n, q \leq 200\,000$$$) — the length of the pattern and the number of updates.

The second line contains the initial pattern $$$s$$$ with $$$n$$$ valid characters.

Each of the following $$$q$$$ lines contains an integer $$$i$$$ ($$$1 \leq i \leq n$$$) and a valid character $$$c$$$. The update changes the $$$i$$$-th character of $$$s$$$ to $$$c$$$. No update tries to change a character into the same character.

Characters in $$$s$$$ are $$$1$$$-indexed. After you change a character, this change stays on (updates are not temporary).

Output

Print $$$q+1$$$ lines, each with the current answer modulo $$$1000000007$$$.

Example
Input
2 5
A?
2 O
1 H
1 ?
2 ?
2 H
Output
6
1
0
7
403
26
Note

The pattern-string $$$s$$$ is initially A? and then after every next update: AO, HO, ?O, ??, ?H.

For the initial pattern A?, there are six good ways to replace all question marks: AA, AE, AH, AI, AO, AU. The first letter is a vowel so it flips Limak's mood from happy to sad. The second letter must be a vowel or H.

I. Count Paths Queries
time limit per test
6 s
memory limit per test
256 megabytes
input
standard input
output
standard output

You are given a graph with $$$n$$$ vertices (numbered $$$1$$$ through $$$n$$$) and $$$m$$$ directed edges.

You need to answer $$$q$$$ queries: given $$$s, t, k$$$, count paths consisting of $$$k$$$ steps (edges) from vertex $$$s$$$ to vertex $$$t$$$, modulo $$$10^9+7$$$. A path can visit the same vertex or edge multiple times.

Input

The first line contains three integers $$$n$$$, $$$m$$$ and $$$q$$$ ($$$1 \leq n, q \leq 200$$$, $$$0 \leq m \leq n \cdot (n - 1)$$$) — respectively the number of vertices, edges and queries.

The following $$$m$$$ lines describe edges. The $$$i$$$-th of these lines contains two integers $$$a_i$$$ and $$$b_i$$$ ($$$1 \leq a_i, b_i \leq n, a_i \neq b_i$$$), denoting a directed edge from $$$a_i$$$ to $$$b_i$$$. There are no self-loops or multiple edges.

The following $$$q$$$ lines describe queries. Each line contains three integers $$$s$$$, $$$t$$$ and $$$k$$$ ($$$1 \leq s, t \leq n$$$, $$$1 \leq k \leq 10^9$$$) — the start and end of a path, and its length in edges.

Output

For each query, print a line with the answer modulo $$$1000000007$$$.

Example
Input
3 4 4
1 2
2 3
3 1
2 1
1 2 6
3 3 5
1 3 1
3 2 54
Output
2
1
0
922111
Note

In the first sample test, we are given the following graph with $$$n = 3$$$ vertices and $$$m = 4$$$ edges.

In the first query, there are 2 paths of length $$$k = 6$$$ from vertex $$$1$$$ to vertex $$$2$$$:

  • $$$1 \rightarrow 2 \rightarrow 3 \rightarrow 1 \rightarrow 2 \rightarrow 1 \rightarrow 2$$$
  • $$$1 \rightarrow 2 \rightarrow 1 \rightarrow 2 \rightarrow 3 \rightarrow 1 \rightarrow 2$$$