ShellBeeHaken Presents Intra SUST Programming Contest 2024 - Replay
A. Monke's Favourite Function
time limit per test
4 seconds
memory limit per test
1024 megabytes
input
standard input
output
standard output

Monke likes mind-boggling functions that even a genius like him can't solve. The function is the following —

  • $$$f(0, x) = x$$$
  • $$$f(k, x) = \sum_{\substack{y \& x = y}} f(k - 1, y)$$$, in other words, summation of $$$f(k - 1, y)$$$ for all $$$y$$$ that are submask of $$$x$$$, i.e. $$$(y \& x = y)$$$.

Monke tried to write a code that finds $$$f(k, x)$$$ $$$\bmod$$$ $$$10^9 + 7$$$. When he runs that code, his computer catches on fire, he loses his mind and comes to you. Now, to calm him down (and to also prove you're more of a genius than him), you have to write a code that can calculate $$$f(k, x)$$$ $$$modulo$$$ $$$10^9 + 7$$$, which doesn't burn Monke's computer.

Input

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

Each test case contains two integers $$$k, x (1 \leq k, x \leq 3\cdot10^5)$$$.

Output

Print $$$f(k, x) \bmod 10^9+7$$$.

Example
Input
3
1 1
1952 1971
69420 42069
Output
1
537162777
817139390

B. 21—0?
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
Who let Brock Lesnar back in WWE?
— Monke

Monke is a talented but lazy programmer. He doesn't practice a lot. He lives in a weird country where every month consists of $$$n$$$ days. He also has a favorite number $$$k$$$, because he is weird. As Monke is lazy, he didn't solve any problems in the last month. But he cares about his maximum problem-solving streak. So this month, he solved some problems but lost count of how many problems he solved on each day of the month.

Luckily he maintained an array $$$a$$$ of size $$$n$$$, where for all $$$i\ (i \lt k)$$$, $$$a_i$$$ is the no of problems solved in the last $$$i$$$ days, and for all $$$i\ (i \ge k)$$$, $$$a_i$$$ is the number of problems solved in the last $$$k$$$ days on the $$$i$$$'th day of this month. Formally, $$$a_i$$$ $$$(1 \le i \le n)$$$ means the total number of problems he has solved in days $$$[i,\ i - 1,\ i - 2,...,\max{(1,i + 1 - k)}]$$$.

He wants to know the maximum streak of problem-solving he has in this month. Can you find it for him?

The maximum problem-solving streak means the maximum number of consecutive days where Monke has solved at least one problem each day.

For example, let $$$n = 5,\ k = 2$$$, and the number of problems he solved on the day $$$i$$$ is represented by the array $$$[1, 1, 0, 4, 1]$$$, then the array containing total solve count of last $$$\min(i,\ k)$$$ days will be $$$[1, 2, 1, 4, 5]$$$, and the maximum problem-solving streak will be $$$2$$$ days.

Input

The input consists of multiple test cases. The first line contains an integer $$$t\ (1 \le t \le 10^4)$$$ — the number of test cases. The description of the test cases follows.

The first line of each test case contains two integers $$$n , k\ (2 \le n \le 3\cdot10^5, 1 \le k \le n)$$$ — the number of days in a month.

The second line of each test case contains $$$n$$$ integers $$$a_1,a_2, ... ,a_n\ (0 \le a_i \le 10 ^ 9)$$$ — the elements of $$$a$$$.

It is guaranteed that each $$$a_i$$$ $$$(1 \le i \le n)$$$ is consistent with all previous $$$a_j$$$ $$$(\max(1,\ i - k) \le j \le i - 1)$$$. In other words, the given solve count is valid.

It is guaranteed that the sum of $$$n$$$ across all test cases does not exceed $$$3\cdot10^5$$$.

Output

For each test case, print one integer, the maximum problem-solving streak.

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

C. Alpha Beta
time limit per test
1 second
memory limit per test
512 megabytes
input
standard input
output
standard output

Let $$$S$$$ be a string consisting of lowercase English letters of length $$$n$$$. We want to partition $$$S$$$ into 26 sets $$$s_1, s_2, s_3, \ldots, s_{26}$$$, where each set $$$s_i$$$ represents a set of indices $$$j$$$ such that $$$S[j]$$$ is the $$$i$$$-th letter of the English alphabet ('$$$a$$$' to '$$$z$$$').

For example: Set $$$s_1$$$ contains indices $$$j$$$ ($$$1 \leq j \leq |S|$$$) where $$$S[j] = $$$ '$$$a$$$'. If $$$S = $$$ "$$$aabca$$$", then the value of $$$s_1$$$ can be $$$\{\}$$$, $$$\{1\}$$$, $$$\{2\}$$$, $$$\{5\}$$$, $$$\{1, 2\}$$$, $$$\{1, 5\}$$$, $$$\{2, 5\}$$$, or $$$\{1, 2, 5\}$$$.

The partition is considered "good" if the following two conditions are satisfied:

  • Each set $$$s_i$$$ is non-empty, i.e., $$$|s_i| \gt 0$$$ for all $$$i = 1, 2, \ldots, 26$$$.
  • For every pair of adjacent sets $$$s_i$$$ and $$$s_{i+1}$$$, all the indices in $$$s_{i+1}$$$ come after all the indices in $$$s_{i}$$$. Formally: $$$$$$\max_{x \in s_i} x \lt \min_{y \in s_{i+1}} y, \quad \forall i = 1, 2, \ldots, 25$$$$$$

The value of a good partition is: $$$$$$\sum_{i=1}^{25} \sum_{j=i+1}^{26} (|s_i| + |s_j|)^2$$$$$$ where $$$|s_i|$$$ denotes the cardinality (size) of the set $$$s_i$$$.

Your task is to find the maximum value among all possible good partitions of the given string $$$S$$$.

Input

A single line contains an integer $$$n$$$ ($$$1 \leq n \leq 2000$$$) denoting the length of the string $$$S$$$.

The next line contains the string $$$S$$$ consisting of $$$n$$$ lowercase English letters.

Output

For each test case, print the maximum value of a good partition of $$$S$$$. If there are no good partitions, output 0.

Examples
Input
26
abcdefghijklmnopqrstuvwxyz
Output
1300
Input
29
abaaacdefghijklmnopqrstuvwxyz
Output
1300
Input
30
abbaaacdefghijklmnopqrstuvwxyz
Output
1425
Input
4
abcd
Output
0
Note

For the second test case:

The only good partition is, $$$s_1 = \{1\}, s_2 = \{2\}, s_3 = \{6\}, s_4 = \{7\}, \ldots, s_{25} = \{28\}, s_{26} = \{29\}$$$. The value of this partition is $$$\sum_{i=1}^{25} \sum_{j=i+1}^{26} (1 + 1)^2 = 325 \cdot 4 = 1300$$$.

D. Geometry Class
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Every week, SUST CP Training Camp organizes classes on different topics for 3 different categories: Beginner, Intermediate, and Advanced. The topic for this week's intermediate class was $$$Basic-Geometry$$$ and the class was taken by our very own Geo Boss.

At the start of the class, Boss drew the following triangle on the board:

Illustration of Sample Input. The value of the angles A,B,C are 45, 90, 45 degrees respectively. Hence the maximum angle's value is 90 degrees

Then, he asked the students, what is the largest angle in the triangle. Upon inspecting the picture, everyone shouted, "angle B". Further, he drew some random triangles, they have to find the value of the largest angle of the triangle. But it was a piece of cake for them. So he added some twist. Instead of giving the triangle directly, he just provided the $$$Sin$$$ values of the angles. More formally, he gave the students 3 double values representing $$$Sin(A), Sin(B), Sin(C)$$$, and they were asked to find the largest angle's value. Since students had the knowledge of trigonometry and inverse trigonometry, they said the problem is too easy. Boss gave a sly smile.

We don't know whether the students could solve the problem. Can you solve it?

Note, for this problem angles' values are guaranteed to be integers.

Input

The first line contains an integer $$$t$$$ $$$(1 \leq t \leq 15931)$$$ – denoting the number of testcases.

Following $$$t$$$ lines each contain 3 double values $$$Sin(A), Sin(B), Sin(C)$$$ $$$(0 \lt Sin(A), Sin(B), Sin(C) \leq 1)$$$ each with 9 decimal digits.

It is guaranteed that all the values of $$$A, B, C$$$ are integers and represent a valid triangle.

Output

For each case, output one integer – the value of the largest angle in degrees.

Example
Input
1
0.707106781 1.000000000 0.707106781
Output
90
Note

You can use pi($$$\pi$$$) = acos(-1.0).

You can use round() function available in C++ if needed. round() function converts a double to the nearest integer.

E. Jor Shongkot
time limit per test
4 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

You have an array $$$a$$$ of length $$$n$$$ (n is odd). You can do the following operation with this array:

  • choose any positive integer $$$x,$$$ and change $$$a_i$$$ to $$$a_i$$$ $$$\oplus$$$ $$$x$$$, for all $$$ 1 \leq i \leq n$$$.

You have to tell if it is possible to transform the array into a permutation by applying the operation any number of times.

A sequence of $$$n$$$ numbers is called a $$$permutation$$$ if it contains all integers from $$$1$$$ to $$$n$$$ exactly once. For example, the sequences $$$[1,2], [4,2,1,3]$$$ are permutations, but $$$[0], [1,3], [2,1,2,4]$$$ – are not.

Input

The first line contains a single integer $$$n(1 \leq n \lt 10^6)$$$, (n is odd).

The second line contains $$$n$$$ space separated integers $$$a_1, a_2, ..., a_n$$$$$$(0 \leq a_i \leq 2\cdot10^6)$$$.

Output

Output "YES"(without quotes) if the array can be transformed into a permutation, and "NO"(without quotes) otherwise.

You can output "YES" or "NO" in any case.(For example, strings "yES", "yes" and "Yes" will be recognized as a positive response).

Examples
Input
1
3
Output
YES
Input
3
1 2 3
Output
YES
Input
5
1 2 3 4 800
Output
NO
Input
5
0 1 2 7 6
Output
YES

F. Not A Giveaway
time limit per test
2 seconds
memory limit per test
512 megabytes
input
standard input
output
standard output

Warning: Not A Giveaway.

You have a large electronic screen which can display up to $$$1000000007$$$ decimal digits. each place for a digit consists of $$$7$$$ segments which can be turned on and off to compose different digits. The following picture describes how you can display all 10 decimal digits:

As you can see, different digits may require different numbers of segments to be turned on. For example, if you want to display $$$1$$$, you have to turn on $$$2$$$ segments of the screen, and if you want to display $$$8$$$, all $$$7$$$ segments of someplace to display a digit should be turned on.

Your task is to find the minimum number you can show on display by turning exactly $$$N$$$ segments on. You can't have leading zeroes in the number, that means the first digit of your number can be $$$0$$$ if and only if the total number you're showing is $$$0$$$.

Input

The first line contains one integer $$$t (1 \leq t \leq 10^4)$$$ — the number of test cases in the input.

Then the test cases follow, each of them is represented by a separate line containing one integer $$$n (2 \leq n \leq 10^6)$$$ — the number of segments that should be turned on in the corresponding test case.

It is guaranteed that the sum of $$$n$$$ over all test cases in the input does not exceed $$$10^6$$$.

Output

For each test case, print the smallest integer that can be displayed by turning on exactly $$$n$$$ segments of the screen without leading zeores. Note that the answer may not fit in the standard $$$32$$$-bit or $$$64$$$-bit integral data type.

Example
Input
3
2
7
16
Output
1
8
188

G. Surprise Gift
time limit per test
2 seconds
memory limit per test
512 megabytes
input
standard input
output
standard output

Accidentally_Coder, a renowned coder from CSEland, is in a dilemma – she wants to give her friend, The_Author, a special gift. After thinking for a while, she went to her favorite shop at Zindabazar and bought an empty matrix $$$A$$$ of size $$$n \times n$$$. She knows that her friend loves numbers which are power of $$$2$$$. So she decided to fill the matrix in a way that the following conditions hold:

  • For each $$$1 \leq i \leq n$$$, $$$1 \leq j \leq n$$$, $$$A_{i,j}$$$ is an integer and $$$1 \leq A_{i,j} \leq 10^9$$$ holds

  • The sum of numbers in each row is a power of $$$2$$$ (that is, $$${\sum_{j=1}^n A_{i,j}}$$$ should be a power of $$$2$$$ for each $$$1 \leq i \leq n$$$)

  • The sum of numbers in each column is a power of $$$2$$$ (that is, $$${\sum_{i=1}^n A_{i,j}}$$$ should be a power of $$$2$$$ for each $$$1 \leq j \leq n$$$)

  • The sum of numbers in each of the primary and secondary diagonals is a power of $$$2$$$ (that is, $$${\sum_{i=1}^n A_{i,i}}$$$ should be a power of $$$2$$$ and $$${\sum_{i=1}^n A_{i,n + 1 - i}}$$$ should be a power of $$$2$$$)

A number $$$P$$$ is considered a power of $$$2$$$, if there is some integer $$$i$$$$$$(0 \leq i)$$$, for which $$$P = 2^i$$$

Your task is to find any matrix of size $$$n \times n$$$ satisfying these conditions or report that no such matrix exists.

Input

The only line in the input contains a single integer $$$n$$$ $$$(1 \leq n \leq 1000)$$$.

Output

If a solution exists, output $$$n$$$ lines, each containing $$$n$$$ integers in range $$$[1, 10^9]$$$, the numbers of the matrix. Otherwise, output $$$-1$$$ on a single line.

Examples
Input
8
Output
8 8 8 8 8 8 8 8
8 8 8 8 8 8 8 8
8 8 8 8 8 8 8 8
8 8 8 8 8 8 8 8
8 8 8 8 8 8 8 8
8 8 8 8 8 8 8 8
8 8 8 8 8 8 8 8
8 8 8 8 8 8 8 8
Input
4
Output
4 4 4 4
4 4 4 4
4 4 4 4
4 4 4 4

H. Stupid Game
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

In a game, a stupid prize is up for grabs, which X is very fond of. This is a two-player game. X is playing against Y.

The game consists of $$$n$$$ balls arranged in a circular manner, that is each ball has almost $$$2$$$ neighbors. For example, if there are $$$4$$$ balls, then ball $$$1$$$ is neighbor of balls $$$2$$$ and $$$4$$$, similarly ball $$$2$$$ is neighbor of balls $$$1$$$ and $$$3$$$ and so on.

Initially, each ball yields $$$1$$$ point. In a move, a player chooses a ball and removes it, and its point is added to the player's score. Additionally, if there are at least two balls remaining after the removal, the balls on either side of the removed ball will merge, and their points will be added together. For example, if the balls initially has points $$$[1,1,1,1,1]$$$ and a player removes the third ball, the new arrangement will be $$$[1,2,1]$$$. See examples below for visuals.

The game ends when the last ball is removed. Players move alternately, X goes first. The player with a higher score wins.

If X loses, being a sore loser, he will get frustrated and send an email to the organizers complaining about how stupid and unfair the game is. Your task is to help him determine who wins if both players play optimally, or report if it will be a draw.

"playing optimally" means making the best possible moves at each turn to first, maximize one's chances of winning the game, then, minimize opponent's chances of winning the game.

Input

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

Each of the following lines contains an integer $$$n$$$ ($$$1 \leq n \leq 2\cdot10^5$$$) – denoting the number of balls in the game.

Output

For each test case, in a single line, print:

  • "Beautiful game" if X wins,
  • "Never playing this again" if Y wins,
  • "No words" if it is a draw.
Example
Input
3
1
7
4
Output
Beautiful game
Never playing this again
No words
Note

For the second case, a way Y can win is:

Sample 2: It can be shown that Y can win no matter how X plays.

For the third case, the game goes as follows:

I. Optimal Tree Exploration
time limit per test
3 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Given a rooted tree consisting of $$$n$$$ nodes, where each node $$$i$$$ has an associated value $$$a_i$$$. The tree is rooted at node $$$1$$$. $$$Alice$$$ and $$$Bob$$$ are going to explore this tree multiple times, and you are going to help them by answering their queries.

In the $$$i$$$-th exploration, $$$Alice$$$ starts from node $$$x_i$$$ and $$$Bob$$$ starts from node $$$y_i$$$. Both $$$Alice$$$ and $$$Bob$$$ can move from their current node to a child node if it exists and hasn't been visited by the other player yet. Maintaining these conditions, both of them can move as many times as they want. Note that, $$$Alice$$$ and $$$Bob$$$ do not need to move simultaneously. They can move whenever they wish. Also note that, neither $$$Alice$$$ nor $$$Bob$$$ can move from their current node to any other node except the direct child nodes.

Both $$$Alice$$$ and $$$Bob$$$ want to maximize the value they see on their exploration. Your task is to find the maximum value that $$$Alice$$$ and $$$Bob$$$ can see while exploring the tree if they move optimally.

Note that, each exploration is independent. That is, in each query, they start from the given nodes and there is no relation between queries.

Input

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

The second line contains n space separated integers $$$a_1,a_2,...,a_n \; (0 \leq a_i \leq 10^9)$$$ – the array $$$a$$$

The next $$$n-1$$$ lines describe the tree. The $$$i$$$-th line contains two integers $$$u_i$$$ and $$$v_i$$$ $$$(1 \leq u_i, v_i \leq n)$$$ — the numbers of the nodes connected by the $$$i$$$-th edge.

Next $$$q$$$ lines describe the queries. The $$$i$$$-th line contains two integers $$$x_i$$$ and $$$y_i$$$ $$$(1 \leq x_i, y_i \leq n, \; x_i \neq y_i)$$$ — the starting node for $$$Alice$$$ and $$$Bob$$$ respectively in this query.

Output

For each query, output two space separated integers — the maximum value $$$Alice$$$ and $$$Bob$$$ can see while exploring the tree.

Example
Input
8 3
3 1 6 8 7 2 4 5
1 2
2 3
1 4
2 5
5 7
3 6
6 8
3 4
2 5
6 1
Output
6 8
6 7
5 8
Note

The tree for the sample test case looks like this:

Consider the first test case:

Alice starts from node $$$3$$$ and Bob starts from node $$$4$$$. Notice that whichever path Alice choose to go in its' subtree does not contain any node that can be in one of the possible path for Bob. Similarly Bob can also choose any path and it will not contain any node that can be in Alice's path. So, the maximum value Alice can observe is $$$6$$$, the value of node $$$3$$$, and maximum value Bob can observe is $$$8$$$, the value of node $$$4$$$.

In the second test case:

Alice starts from node $$$2$$$ and Bob starts from node $$$5$$$. If Alice goes to node 5, he can observe $$$7$$$, but since node $$$5$$$ is already visited by Bob, Alice can not go there. So, Alice can only go in any node of this path $$$2 \rightarrow 3 \rightarrow 6 \rightarrow 8$$$. So, the maximum value for Alice is $$$6$$$, the value of node $$$3$$$. But, Bob can go in any node of its' subtree, so the maximum value for him is $$$7$$$, the value of node $$$5$$$.

J. Monke, Potato and Their Knight Game
time limit per test
3 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Monke likes chess a lot. He has an infinite chess board and his favourite chess piece is a Knight. A knight can move two squares vertically and one square horizontally or two squares horizontally and one square vertically.

Formally, a Knight can move from $$$(x_i, y_i)$$$ to $$$(x_j, y_j)$$$ only if $$$((|x_i - x_j| = 1) \land (|y_i - y_j| = 2)) \lor ((|x_i - x_j| = 2) \land (|y_i - y_j| = 1))$$$

He's playing a game with his friend Potato. Initially Monke placed a knight on square $$$(x_1, y_1)$$$. Then Potato picks another square $$$(x_2, y_2)$$$. If Monke can move to the square selected by Potato in ODD number of moves, he wins. Otherwise, she wins. Now your task is to determine the winner of the game.

Input

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

Each test case contains $$$4$$$ integers $$$x1, y1, x2, y2$$$. ($$$1 \leq x1, y1, x2, y2 \leq 10 ^ 6$$$).

Output

For each test case, print Monke if the winner is Monke, print Potato otherwise.

Example
Input
3
1 1 4 5
100 2 9 11
1 1 1 2
Output
Monke
Potato
Monke

K. Center of Attraction?
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Once in CPLand, there was a boy named Monke. In order to impress his friend(also crush) Potato, he decided to be the center of attraction in the assembly line.

The assembly line consists of $$$b$$$ boys and $$$g$$$ girls, standing from left to right. Positions in the assembly line are numbered from $$$1$$$ to $$$b+g$$$, with $$$1$$$ being the leftmost position, $$$b+g$$$ being the rightmost.

Nanavai, the famous teacher of the school makes an arrangement of boys and girls on the assembly line. That is — he selects $$$g$$$ positions, where girls will stand in no particular order. The boys will stand in the remaining positions. Monke thinks he is the center of attraction if at least $$$x$$$ girls standing on his left, and at least $$$y$$$ girls standing on his right.

That is — let $$$i$$$ be the position of Monke on the assembly line, he thinks he is the center of attraction if there are at least $$$x$$$ girls in position from $$$1$$$ to $$$i - 1$$$, and there are at least $$$y$$$ girls in position from $$$i + 1$$$ to $$$b + g$$$. (Yeah, his idea of the center is different from others because he is a genius)

As Monke is the best coder in the town, he can select any position reserved for boys, and stand there. He doesn't yet know the selected arrangement made by Nanavai. He wonders, how many arrangements $$$\bmod 10^9+7$$$ are there for which it's possible for him to be the center of attraction. Can you help him?

Input

The input consists of multiple test cases. The first line contains an integer $$$t\ (1 \le t \le 10^5)$$$ — the number of test cases. The description of the test cases follows.

Each test case contains four integers $$$b, g, x, y \ (1 \le b,g,x,y \le \ 10^6)$$$ — the number of boys, girls, the number of girls Monke wants on his left, the number of girls Monke wants on his right.

Output

For each test case, print the number of arrangements, $$$\bmod$$$ $$$10^9+7$$$ for which it is possible for Monke to be the center of attraction.

Example
Input
2
3 5 2 1
69 420 13 37
Output
46
443945467
Note

One of the possible arrangement for the first test case can be [B, G, G, G, B, G, G, B], where B denotes the position of boys, and G denotes the position of the girls, and Monke's position is underlined. He has $$$3$$$ (at least $$$2$$$) girls on his left and $$$2$$$ (at least $$$1$$$) girls on his right.

Note that Monke can stand in any position that is selected for boys.

L. Kalopsia Sequence
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

You're given a bracket sequence $$$s$$$, or, in other words, a string $$$s$$$ of length $$$n$$$, consisting of characters '(' and ')', and should process $$$q$$$ number of queries. There are two types of queries:

  • $$$1$$$ $$$l$$$ $$$r$$$ : Flip the substring $$$s[l..r]$$$; in other words, for each $$$s_{i} (l \le i \le r)$$$, change '(' to ')' and vice versa.

  • $$$2$$$ $$$l$$$ $$$r$$$ : Check if the substring $$$s[l..r]$$$ is a regular bracket sequence$$$^1$$$ or not.

For example, if the string $$$s$$$ is ()(()) and the query is $$$t_i = 1, l_1 = 4, r_1 = 5$$$, then after flipping, we get the string $$$s$$$ is ()()(). If after that, we processed the query $$$t_i = 1, l_2 = 1, r_2 = 6$$$ then after flipping, the updated string $$$s$$$ will be )()()(.

$$$^1$$$A regular bracket sequence is a bracket sequence that can be transformed into a correct arithmetic expression by inserting the characters "1" and "+" between the original characters of the sequence. For example, bracket sequences "()()" and "(())" are regular (the resulting expressions are: "(1)+(1)" and "((1+1)+1)"), and ")(", "(" and ")" are not.

Input

The first line contains two integers $$$n$$$ and $$$q$$$ $$$(1\leq n,q\leq 2\cdot10^5)$$$ — the length of string $$$s$$$ and the number of queries, respectively.

The second line contains the string $$$s$$$ , consisting of $$$n$$$ characters. Each character of $$$s$$$ is either '(' or ')'.

Each of the next $$$q$$$ lines contains three integers: $$$t$$$, $$$l$$$ and $$$r$$$. $$$(1\le t_i\le 2, 1\le l_i \le r_i\le n)$$$.

Output

For each query of type $$$2$$$, print "YES" (without quotes) if the substring $$$s[l..r]$$$ is a regular bracket sequence. Print NO (without quotes) otherwise.

Example
Input
6 7
(()())
2 2 3
1 2 2
2 1 2
2 3 4
2 4 5
1 2 4
2 1 6
Output
YES
YES
NO
YES
YES

M. Too Easy?
time limit per test
2 seconds
memory limit per test
512 megabytes
input
standard input
output
standard output

As Intra SUST Programming Contest-2024 is approaching, problem-setters are looking for some easy but interesting problems. So, here is a problem for you. There is an infinite 2D grid. You will start from a coordinate $$$(s_x,s_y)$$$ and reach a coordinate $$$(t_x,t_y)$$$, possibly the same coordinate. In one move, you can go left, right, up, or down from your current position. You need to find the minimum number of operations to reach the target coordinate. Sounds too easy, right?

So, here is a constraint for you. You can not move more than $$$k$$$ times consecutively in the same direction. Can you solve it now?

Input

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

Following $$$t$$$ lines each contain $$$5$$$ integers $$$s_x,s_y,t_x,t_y,k (-10^9 \leq s_x,s_y,t_x,t_y \leq 10^9, 1 \leq k \leq 10^9)$$$.

Output

Output one integer for each case, the minimum number of moves required.

Example
Input
5
0 0 -5 10 100
1 1 56 57 5
-3 10 2 65 5
1000000000 -1000000000 1000000000 -1000000000 1
0 0 2 4 1
Output
15
111
66
0
8
Note

In the first test case, you can move $$$5$$$ times left and then $$$10$$$ times up to reach the destination.

In the second test case, you can move $$$5$$$ times right, then $$$5$$$ times up, then $$$5$$$ times right, then $$$5$$$ times up and so on to reach $$$(56,56)$$$ and finally move up to reach $$$(56,57)$$$.

In the fourth test case, you don't need to move at all.