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?
The first and only line contains two integers $$$c$$$ $$$(1 \leq c \leq 10^9)$$$ and $$$m$$$ $$$(1 \leq m \leq 10^9)$$$.
Output one integer, the number of friends he can buy an Alfino for.
3 10
3
2 4
2
5 39
7
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.
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.
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.
ahmd ahmmdddmddm
39 mmmmhddddda adhm
abd abbbdddd
19 ddddbbba abd
juan juaaannnjj
36 unnnjjjaaa ajnu
abc abbcc
8 ccbba abc
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:
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.
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)$$$.
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}$$$.
1010 3 2 1 2 2 2 3
2.000000 2.000000 2.000000
00110 6 2 2 1 1 2 2 1 2 2 2 2 10
2.408889 2.520000 2.524444 2.500000
101 6 2 1 2 2 2 3 1 3 2 1 2 2
1.666667 1.444444 1.518519 1.666667 1.444444
This is the easy version of the problem. The difference is that, $$$L = \inf$$$.
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:
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)$$$.
Print $$$q$$$ lines, each line is the answer to the $$$i_{th}$$$ scenario.
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
0 0 1 1 1 0
This is the hard version of the problem. The difference is that $$$L$$$ will be in the input.
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:
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)$$$.
Print $$$q$$$ lines, each line is the answer to the $$$i_{th}$$$ scenario.
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
0 0 1 1 1 0
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.
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)$$$.
For each of the $$$q$$$ patterns, print "YES" if it can be drawn on the grid, otherwise "NO".
2 2 ab ju 4 auabj auau jbjbjbjb ajbuabu
YES YES YES YES
10 10 mpflatybop qidzzqtjqx doqoqpytaw dmoiaobarq qhatjzlcke cpssejhcck bfypoyfrbw jrfkmqlxtw bxluprfzuh jxphofitwj 4 ssejh sseja bxxjbxx bxxlkpfoo
YES YES YES NO
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.
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)$$$.
For each possible password, if it's acceptable, print "YES", otherwise print "NO".
3 ahmad abd jaun 6 jn ad acd aqd amh jan
YES YES NO NO NO YES
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:
Again, Ahmad is really busy so you should help Juan create the array or tell him it's not possible.
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$$$.
For each test case, if there is an answer print "YES" followed by the array on the next line, otherwise print "NO".
3 3 5 3 4 3 6
YES 4 3 4 YES 3 2 1 YES 1 2 5
2 3 2 4 5
NO YES 4 4 3 1
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.
The first and only line consisting of the string $$$S$$$ $$$(1 \leq |S| \leq 10^5)$$$.
Print the number of ways you can do the operation so that the resulting strings are good.
abababa
2
abracadbra
0
juuaannn
4
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$$$.
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 the answer to the problem modulo $$$10^9 + 7$$$.
3 1 2 3
9
9 8 4 16 2 1 3 5 7 49
149
4 3 7 14 8
45
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.
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)$$$.
For each of the $$$q$$$ problems, print on integer the answer to that problem.
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
0 1 5
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
2 3 2 4
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
1 4
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.
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)$$$.
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}$$$.
3 1.0 2.0 -1.0 -1.0 -2.0 2.0
9.000000
4 1.000000 1.000000 1.000000 1.500000 1.500000 1.000000 1.500000 1.500000
0.250000