JPC 1.0
A. Juan and Alfino
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
If you are hungry, buy yourself an Alfino
— Abd to Juan, Abd on Alfino ch. 900

Juan just recently started studying in JUST (Juan University for Sarcasm and Technology) and obviously Abd told him he should try Alfino, the most legendary sandwich on planet earth.

Juan is very social, so he already made infinitely many friends.

He wants to buy his friends Alfinos, an Alfino costs $$$c$$$ JOD. and he has $$$m$$$ JOD.

How many friends can he buy an Alfino for?

Input

The first and only line contains two integers $$$c$$$ $$$(1 \leq c \leq 10^9)$$$ and $$$m$$$ $$$(1 \leq m \leq 10^9)$$$.

Output

Output one integer, the number of friends he can buy an Alfino for.

Examples
Input
3 10
Output
3
Input
2 4
Output
2
Input
5 39
Output
7

B. Paulo's Plan
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
tis not a valorous contest, unless thee has't a string problem
— Mateo, Advices to Ahmad

Paulo is always trying to sabotage the Juan group, this time he is trying to sabotage Mateo's precious strings.

Mateo has a small string $$$T$$$ consisting of distinct characters, and a big string $$$S$$$ consisting of the same characters as $$$T$$$.

Let's say that a pair of strings $$$(A, B)$$$ is good if we can duplicate the characters of $$$B$$$ a finite number of times without changing their order so that $$$A = B$$$, e.g, $$$(aabb, ab), (aabbbbbccc, abc)$$$ are good pairs, $$$(abcccc, ab), (acccb, abc)$$$ are not.

Let's define $$$cost(A, B)$$$ as the minimum number of swaps of adjacent characters in $$$A$$$ so that $$$(A, B)$$$ becomes a good pair.

Paulo knows Mateo will do anything to make the pair a good pair, Paulo can reorder the characters in $$$S$$$ and $$$T$$$ as he wishes, tell him what is the best pair $$$(S', T')$$$ such that $$$cost(S', T')$$$ is maximum.

It's guaranteed that the $$$(S, T)$$$ can be made a good pair.

Input

The first line contains the string $$$T$$$ $$$(1 \leq |T| \leq 5)$$$, consisting of only distinct lowercase English letters.

The second line contains the string $$$S$$$ $$$(1 \leq |S| \leq 3\times10^5)$$$, consisting of only lowercase English letters.

Output

On the first line output one integer $$$cost(S', T')$$$, then on the second line output the string $$$S'$$$, then on the third line output $$$T'$$$, such that $$$cost(S', T')$$$ is maximized.

Examples
Input
ahmd
ahmmdddmddm
Output
39
mmmmhddddda
adhm
Input
abd
abbbdddd
Output
19
ddddbbba
abd
Input
juan
juaaannnjj
Output
36
unnnjjjaaa
ajnu
Input
abc
abbcc
Output
8
ccbba
abc

C. K Flips
time limit per test
2.5 seconds
memory limit per test
512 megabytes
input
standard input
output
standard output
if't be true thee wast mad, flip some tables
— Paulo, Palou's Advice to Ahmad

Paulo was teaching Ahmad that if he was ever mad he should just flip some tables, but Paulo did not listen to his own advice, and now he is in prison, so Ahmad is MAD!

You're given a binary string $$$S$$$, the $$$i_{th}$$$ character is the state of the $$$i_{th}$$$ table either $$$1$$$ flipped, or $$$0$$$ not flipped.

Every time Ahmad wants to flip some tables, he will chose some pair $$$(l, r)$$$ uniformly at random from all the pairs such that $$$(1 \leq l \leq r \leq |S|)$$$, and flip every table $$$i$$$ such that $$$(l \leq i \leq r)$$$.

You have to answer $$$Q$$$ queries:

  • $$$1$$$ $$$i$$$: flip the $$$i_{th}$$$ table.
  • $$$2$$$ $$$k$$$: Ahmad will flip some tables $$$k$$$ $$$(k \leq 200)$$$ times, what is the expected number of tables that are flipped at the end of $$$k$$$ flips?

Note: when Ahmad flips some tables, every time he flips he will choose $$$(l, r)$$$ again.

Note: only query of type $$$1$$$ will change the string, meaning Ahmad's flips will not have any effect on the string.

Input

The first line contains the string $$$S$$$ $$$(1 \leq |S| \leq 10^5)$$$ – the binary string.

The second line contains the integer $$$Q$$$ $$$(1 \leq Q \leq 10^5)$$$ – The number queries.

The next $$$Q$$$ lines contains two integers, either $$$1$$$ $$$i$$$ $$$(1 \leq i \leq |S|)$$$, or $$$2$$$ $$$k$$$ $$$(1 \leq k \leq 200)$$$.

Output

For every query of type 2 print a decimal number, the expected number of tables that will be flipped.

Your answer is considered correct if its absolute or relative error doesn't exceed $$$10^{-6}$$$. Namely, if your answer is $$$a$$$, and the jury's answer is $$$b$$$, then your answer is accepted, if $$$\frac{|a - b|}{max(1, |b|)} \leq 10^{-6}$$$.

Examples
Input
1010
3
2 1
2 2
2 3
Output
2.000000
2.000000
2.000000
Input
00110
6
2 2
1 1
2 2
1 2
2 2
2 10
Output
2.408889
2.520000
2.524444
2.500000
Input
101
6
2 1
2 2
2 3
1 3
2 1
2 2
Output
1.666667
1.444444
1.518519
1.666667
1.444444

D. Eduardo Looking for Juan (Easy Version)
time limit per test
6 s
memory limit per test
512 megabytes
input
standard input
output
standard output

This is the easy version of the problem. The difference is that, $$$L = \inf$$$.

at lasteth we meeteth mine own boss juan
— Eduardo, Eduardo Looking for Juan

Eduardo has been looking for Juan for a long time, he finally found out that Juan is on some mountain The Horse Land but before he heads looking for him there he asked Ahmad for help, but he is too busy so it's your responsibility to help him.

Eduardo knows that The Horse Land is $$$n$$$ lands connected by $$$n - 1$$$ roads and there is a unique path between every two lands.

Furthermore, each land has a height $$$a_i$$$, Eduardo will travel from $$$u$$$ to $$$v$$$, but he can only do that if the multiplication of the height of the nodes on the way is a perfect square.

In a formal way let $$$p_1, ..., p_k$$$ the lands in the simple path from $$$u$$$ to $$$v$$$, where $$$p_1 = u$$$ and $$$p_k = v$$$, $$$\prod_{i=1}^{k} a_{p_i}$$$ should be a perfect square.

Eduardo hates surprises, so he will ask you about $$$q$$$ scenarios:

  • $$$u$$$ $$$v$$$: what is the minimum number of operations so that the multiplication on the simple path from $$$u$$$ to $$$v$$$ is a perfect square? In one operation, you can choose a land $$$i$$$ and multiply its height by some number $$$1 \leq x \leq L$$$.
Input

The first line contains a single integer $$$n$$$ $$$(2 \leq n \leq 10^6)$$$ – the number of lands.

The second line contains $$$n$$$ integers $$$(1 \leq a_i \leq 70)$$$ – the heights of the lands.

The next $$$n - 1$$$ lines describes the roads, the $$$i_{th}$$$ line contains two integers $$$u$$$ $$$v$$$ meaning there is a two-way road between $$$u$$$ and $$$v$$$ $$$(1 \leq u, v \leq n)$$$.

The next line contains a single integer $$$q$$$ $$$(1 \leq q \leq 5\times10^5)$$$ – the number scenarios.

The next $$$q$$$ lines each contains two integers $$$u$$$ $$$v$$$ $$$(1 \leq u, v \leq n)$$$.

Output

Print $$$q$$$ lines, each line is the answer to the $$$i_{th}$$$ scenario.

Example
Input
6
5 4 50 40 10 2
1 5
1 2
4 3
3 2
5 6
6
2 2
1 6
6 5
3 4
3 1
4 1
Output
0
0
1
1
1
0

E. Eduardo Looking for Juan (Hard Version)
time limit per test
6 s
memory limit per test
512 megabytes
input
standard input
output
standard output

This is the hard version of the problem. The difference is that $$$L$$$ will be in the input.

at lasteth we meeteth mine own boss juan
— Eduardo, Eduardo Looking for Juan

Eduardo has been looking for Juan for a long time, he finally found out that Juan is on some mountain The Horse Land but before he heads looking for him there he asked Ahmad for help, but he is too busy so it's your responsibility to help him.

Eduardo knows that The Horse Land is $$$n$$$ lands connected by $$$n - 1$$$ roads and there is a unique path between every two lands.

Furthermore, each land has a height $$$a_i$$$, Eduardo will travel from $$$u$$$ to $$$v$$$, but he can only do that if the multiplication of the height of the nodes on the way is a perfect square.

In a formal way let $$$p_1, ..., p_k$$$ the lands in the simple path from $$$u$$$ to $$$v$$$, where $$$p_1 = u$$$ and $$$p_k = v$$$, $$$\prod_{i=1}^{k} a_{p_i}$$$ should be a perfect square.

Eduardo hates surprises, so he will ask you about $$$q$$$ scenarios:

  • $$$u$$$ $$$v$$$: what is the minimum number of operations so that the multiplication on the simple path from $$$u$$$ to $$$v$$$ is a perfect square? In one operation, you can choose a land $$$i$$$ and multiply its height by some number $$$1 \leq x \leq L$$$.
Input

The first line contains two integers $$$n$$$ $$$(2 \leq n \leq 10^6)$$$ and $$$L$$$ $$$(70 \leq L \leq 10^4)$$$ – the number of lands and the limit for $$$x$$$.

The second line contains $$$n$$$ integers $$$(1 \leq a_i \leq 70)$$$ – the heights of the lands.

The next $$$n - 1$$$ lines describes the roads, the $$$i_{th}$$$ line contains two integers $$$u$$$ $$$v$$$ meaning there is a two-way road between $$$u$$$ and $$$v$$$ $$$(1 \leq u, v \leq n)$$$.

The next line contains a single integer $$$q$$$ $$$(1 \leq q \leq 5\times10^5)$$$ – the number scenarios.

The next $$$q$$$ lines each contains two integers $$$u$$$ $$$v$$$ $$$(1 \leq u, v \leq n)$$$.

Output

Print $$$q$$$ lines, each line is the answer to the $$$i_{th}$$$ scenario.

Example
Input
6 140
5 4 50 40 10 2
1 5
1 2
4 3
3 2
5 6
6
2 2
1 6
6 5
3 4
3 1
4 1
Output
0
0
1
1
1
0

F. Maze Runner
time limit per test
5 seconds
memory limit per test
512 megabytes
input
standard input
output
standard output
A contest without a grid is like Mansaf without meat
— Hungry Abd and Ahmad, Midnight Diaries

Mateo and Juan are trapped in a maze, and they can only escape the maze if they draw a certain pattern on it, so they are desperate for your help!

The maze is represented as a grid $$$G$$$ of size $$$n \times m$$$, each cell is a lowercase English letter, you can move from a cell to any other cell adjacent to it (diagonally, horizontally and vertically), you can visit the cell more than once, but you can't move to the same cell that you are currently on.

Let's define a pattern of a path as the concatenation of the characters on the cells on that path.

In a more formal way let the cells on the path be $$$P = [(r_1, c_1), (r_2, c_2), ..., (r_k, c_k)]$$$ such that for each $$$2 \leq i \leq k$$$ $$$P_i \neq P_{i - 1}$$$ that then the pattern is $$$S = G_{r_1c_1}G_{r_2c_2}...G_{r_kc_k}$$$.

Mateo and Juan are studying $$$q$$$ patterns, for each one they ask you if they can draw that pattern on the maze.

Input

The first line contains two integers $$$n$$$ $$$(1 \leq n \leq 10)$$$ and $$$m$$$ $$$(1 \leq m \leq 10)$$$.

For the next $$$n$$$ lines, each line contains $$$m$$$ characters the $$$j_{th}$$$ character on the $$$i_{th}$$$ line describes the cell $$$G_{ij}$$$.

The next line contains one integer $$$q$$$ $$$(1 \leq q \leq 10^5)$$$.

For the next $$$q$$$ lines, each line contains a pattern $$$S$$$ $$$(1 \leq |S| \leq 13)$$$.

Output

For each of the $$$q$$$ patterns, print "YES" if it can be drawn on the grid, otherwise "NO".

Examples
Input
2 2
ab
ju
4
auabj
auau
jbjbjbjb
ajbuabu
Output
YES
YES
YES
YES
Input
10 10
mpflatybop
qidzzqtjqx
doqoqpytaw
dmoiaobarq
qhatjzlcke
cpssejhcck
bfypoyfrbw
jrfkmqlxtw
bxluprfzuh
jxphofitwj
4
ssejh
sseja
bxxjbxx
bxxlkpfoo
Output
YES
YES
YES
NO

G. Carlo's Password
time limit per test
3 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
It's a good contest if it has two problems about strings
— Carlo, Carlo with Mateo to Ahmad

Carlo is trying to escape the barn, so he must find a password to the door.

Given a list $$$s$$$ of $$$n$$$ small strings, a password is acceptable if it's a subsequence of one of the strings in the list.

Given $$$m$$$ possible password, for each password, you should tell Carlo if it's acceptable or not.

Input

The first line contains two integers $$$n$$$ $$$(1 \leq n \leq 5\times10^4)$$$.

The next $$$n$$$ lines contains the list $$$s$$$, the $$$i_{th}$$$ line contains the string $$$s_i$$$ $$$(1 \leq |s_i| \leq 6)$$$.

The next line contains one integer $$$m$$$ $$$(1 \leq m \leq 5\times10^4)$$$.

The next $$$m$$$ lines contains the possible password, each line contains a possible password $$$t$$$ $$$(1 \leq |t| \leq 6)$$$.

Output

For each possible password, if it's acceptable, print "YES", otherwise print "NO".

Example
Input
3
ahmad
abd
jaun
6
jn
ad
acd
aqd
amh
jan
Output
YES
YES
NO
NO
NO
YES

H. Juan vs. Man
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
I shall at each moment did beat thee in this game
— Juan, Juan to Man

Man is trying so hard to become the boss, so he is always trying to beat Juan in any game, this time he came up with the following game.

Man will give Juan two integers $$$n$$$ and $$$m$$$, for Juan to win he should create an array $$$a$$$ with the following constrains:

  • The length of the array is $$$n$$$.
  • For every element in the array $$$1 \leq a_i \leq m$$$ must hold.
  • There should be no subarray where the sum is divisible my $$$m$$$, in a more formal way there is no $$$i$$$ and $$$j$$$ $$$(1 \leq i \leq j \leq n)$$$ such that $$${\sum_{k = i}^j a_k} \equiv 0 \mod m$$$.

Again, Ahmad is really busy so you should help Juan create the array or tell him it's not possible.

Input

The first line is the number of test cases $$$t$$$ $$$(1 \leq t \leq 10^5)$$$.

The next $$$t$$$ lines each contains two integers $$$n$$$ $$$(1 \leq n \leq 10^5)$$$, and $$$m$$$ $$$(1 \leq m \leq 10^6)$$$.

It's guaranteed that the sum of $$$n$$$ over all test cases is not greater than $$$3\times10^5$$$.

Output

For each test case, if there is an answer print "YES" followed by the array on the next line, otherwise print "NO".

Examples
Input
3
3 5
3 4
3 6
Output
YES
4 3 4
YES
3 2 1
YES
1 2 5
Input
2
3 2
4 5
Output
NO
YES
4 4 3 1

I. Split the Stri ng
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
A contest shalt has't a questioneth about palindromes
— Man, Man to Abd

Man gave Abd a string $$$s$$$ of length $$$n$$$, and he asked him a very hard problem. Let's say that a string is good if its characters can be reordered so that it becomes a palindrome.

You must do the following operation exactly once: choose some index $$$i$$$ $$$(1 \leq i \leq n - 1)$$$ and split the string into two strings $$$A = s_1, ..., s_i$$$ and $$$B = s_{i+1}, ..., s_n$$$.

In how many ways can you do the operation such that the resulting strings are both good strings.

Input

The first and only line consisting of the string $$$S$$$ $$$(1 \leq |S| \leq 10^5)$$$.

Output

Print the number of ways you can do the operation so that the resulting strings are good.

Examples
Input
abababa
Output
2
Input
abracadbra
Output
0
Input
juuaannn
Output
4

J. JSUM
time limit per test
2.5 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
thy problem is mine but one letter is hath changed
— Juan, Juan Words to Ahmad

Juan stayed up late thinking of how to steal Ahmad's problem, and he figured if he just changed one character no one will know.

You are given an array $$$a$$$ of $$$n$$$ integers.

Let's define a function $$$JCD(l, r)$$$ as the greatest common divisor of the sub array $$$(a_l, .., a_r)$$$, i.e $$$GCD(a_l, a_{l + 1}, ..., a_r)$$$.

Calculate $$${\sum_{l = 1}^n {\sum_{r = l}^n JCD(l, r)}}$$$, since the answer can be very large output it modulo $$$10^9 + 7$$$.

Input

The first line contains one integer $$$N$$$ $$$(n \leq 10^5)$$$ – the size of the array.

The second line contains $$$N$$$ integers $$$(1 \leq a_i \leq 10^{12})$$$.

Output

Output the answer to the problem modulo $$$10^9 + 7$$$.

Examples
Input
3
1 2 3
Output
9
Input
9
8 4 16 2 1 3 5 7 49
Output
149
Input
4
3 7 14 8
Output
45

K. Pèppito.
time limit per test
4 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
Holla th're
— Pèppito, Pèppito

Pèppito is a bird stuck on a tree because he can't fly, he travels only on the tree by walking on branches.

Pèppito's tree is a tree of $$$n$$$ vertices, the $$$i_{th}$$$ node has an integer $$$a_i$$$, he gets bored sometimes, so he came up with this problem:

Given four integers $$$u$$$ $$$v$$$ $$$l$$$ $$$r$$$: let's define $$$f(x)$$$ as the number of occurrences of $$$x$$$ on the simple path between nodes $$$u$$$ and $$$v$$$, calculate $$$\sum_{x = l}^r f(x)^2$$$.

Pèppito thought that it might be too easy to solve it, so you have to answer $$$q$$$ of these problems.

Input

The first line contains two integers $$$n$$$ and $$$q$$$ $$$(1 \leq n, q \leq 10^5)$$$.

The second line contains $$$n$$$ integers $$$a_i$$$ $$$(1 \leq a_i \leq 10^5)$$$.

The next $$$q$$$ lines each contains 4 integers $$$u$$$ $$$v$$$ $$$l$$$ $$$r$$$, $$$(1 \leq u, v \leq n)$$$ $$$(1 \leq l \leq r \leq 10^5)$$$.

Output

For each of the $$$q$$$ problems, print on integer the answer to that problem.

Examples
Input
5 3
9 4 7 7 8
1 2
2 3
1 4
4 5
4 4 6 6
4 2 6 8
3 5 2 7
Output
0
1
5
Input
5 4
8 2 6 7 10
1 2
1 3
2 4
4 5
2 4 1 7
1 5 4 10
4 5 6 10
3 5 1 8
Output
2
3
2
4
Input
8 2
3 7 6 5 4 5 7 3
1 2
1 3
1 4
2 5
2 6
5 7
6 8
2 2 1 9
8 7 7 8
Output
1
4

L. Minimum Enclosing Rectangle
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
Geometry is excit'ment
— Abd, Abd's Geometry Lectures

You are given $$$N$$$ points on a 2D plane, what is the minimum area of a rectangle that covers all the points and one of its sides is parallel to the x-axis and the other to the y-axis.

Input

The first line contains one integer $$$n$$$ $$$(1 \leq n \leq 54321)$$$.

The next lines each contains two numbers $$$x$$$ and $$$y$$$ $$$(-10^9 \leq x, y \leq 10^9)$$$.

Output

Print a single number, the area of the rectangle.

Your answer is considered correct if its absolute or relative error doesn't exceed $$$10^{-6}$$$. Namely, if your answer is $$$a$$$, and the jury's answer is $$$b$$$, then your answer is accepted, if $$$\frac{|a - b|}{max(1, |b|)} \leq 10^{-6}$$$.

Examples
Input
3
1.0 2.0
-1.0 -1.0
-2.0 2.0
Output
9.000000
Input
4
1.000000 1.000000
1.000000 1.500000
1.500000 1.000000
1.500000 1.500000
Output
0.250000