OMORI CONTEST
A. SUNNY
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
I have to tell you something
— Sunny, ???

Sunny has been practicing his violin a lot, preparing for his recital with his older sister Mari; his violin has $$$2\times 10^{18} +1$$$ micro-strings indexed from $$$-10^{18}$$$ to $$$10^{18}$$$ from left to right.

There are $$$n$$$ vibrations on the strings; the $$$i$$$-th vibration $$$(1 \le i \le n)$$$ is located on the string with index $$$a_i$$$. No two vibrations are located on the same string. Since Sunny has been practicing a lot, he can precisely choose one string $$$k$$$ $$$(-10^{18} \le k \le 10^{18})$$$ and play a note on it.

When Sunny plays a note on string $$$k$$$, every vibration existing to the right of this string gets shifted to the next string to its right, and every vibration to the left of this string gets shifted to the next string to its left, and if a vibration exists on string $$$k$$$, it stays on string $$$k$$$. More formally, when Sunny hits string $$$k$$$, the following happens simultaneously for each vibration $$$i$$$:

  1. If $$$a_i \gt k$$$, $$$a_i := a_i + 1$$$ (increase $$$a_i$$$ by one).
  2. Otherwise, if $$$a_i \lt k$$$, $$$a_i := a_i - 1$$$ (decrease $$$a_i$$$ by one).
  3. Otherwise, do nothing.

Now, Mari wants Sunny to make the vibrations on the violin have indices $$$b_1, b_2, ..., b_n$$$; since Sunny wants to make his sister feel proud, he wants to know if it is possible to change the initial positions $$$a$$$ of the $$$n$$$ vibrations to the desired positions $$$b$$$. Sunny can play an arbitrary number of notes (including not playing any note).

Input

The first line of input contains one integer $$$n$$$ $$$(1 \le n \le 2\times 10^5)$$$ — the number of vibrations currently on Sunny's violin.

The next line contains $$$n$$$ integers $$$a_1, a_2, ..., a_n$$$ $$$(1 \le a_1 \lt a_2 \lt ... \lt a_n \le 10^9)$$$ separated by spaces — the initial positions of the vibrations on the violin.

The next line contains $$$n$$$ integers $$$b_1, b_2, ..., b_n$$$ $$$(1 \le b_1 \lt b_2 \lt ... \lt b_n \le 10^9)$$$ separated by spaces — the desired positions of the vibrations on the violin.

Output

Output one line containing the word "YES" (without quotes) if it is possible for Sunny to convert the positions of the vibrations to the desired positions by his sister by playing notes on his violin's strings, and print "NO" (without quotes) otherwise.

Examples
Input
4
3 4 5 6
3 5 6 8
Output
YES
Input
4
3 4 5 6
3 4 7 8
Output
NO
Note

In the first example, Sunny can play the following notes to convert array $$$a$$$ into $$$b$$$:

  1. Play a note on string $$$3$$$; this will change the positions of the vibrations to $$$\{3, 5, 6, 7\}$$$
  2. Play a note on string $$$7$$$; this will change the positions of the vibrations to $$$\{2, 4, 5, 7\}$$$
  3. Play a note on string $$$1$$$; this will change the positions of the vibrations to $$$\{3, 5, 6, 8\}$$$
Sunny practicing on his violin

B. AUBREY
time limit per test
3 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
SPROUT MOLES are highly intelligent creatures, but become dangerously vicious when they are lost
— Aubrey, Prologue

School is starting, and Aubrey is excited for the activities she is going to perform at school. During the break, Aubrey enjoys her favorite hobby of hunting sprout moles.

The school yard has a tree containing $$$n$$$ nodes rooted at some node (let that node be $$$r$$$). The $$$i$$$-th $$$(1 \le i \le n)$$$ node has $$$a_i$$$ sprout moles. Aubrey starts her hunt by choosing a node $$$i$$$, and then chooses a subset of nodes in the subtree of node $$$i$$$, and starts hunting the sprout moles in each node in the chosen subset.

When Aubrey hunts a group of $$$a_i$$$ sprout moles in a single node $$$i$$$, her hunting score gets XORed by $$$a_i$$$, and Aubrey initially has a hunting score of $$$0$$$.

Now consider the set of all possible distinct final scores Aubrey can achieve by choosing a subset of nodes from the subtree of node $$$i$$$, name it $$$S_i$$$. $$$f(i)$$$ is equal to the summation of the elements of $$$S_i$$$.

Now Aubrey does not know where the tree is rooted at, so she wants to know, from every root $$$r$$$ from $$$1$$$ to $$$n$$$ inclusive, what is the summation of $$$f(i)$$$ over all nodes $$$i$$$ $$$(1 \le i \le n)$$$ assuming the tree is rooted at $$$r$$$? Since $$$\displaystyle\sum_{i=1}^n f(i)$$$ can be very large, Aubrey wants to find its value modulo $$$998244353$$$.

Input

The first line of input contains one integer $$$n$$$ $$$(1 \le n \le 2\times 10^5)$$$ — the number of nodes in the tree.

The next $$$n-1$$$ lines each contain $$$2$$$ integers $$$u_i, v_i$$$ $$$(1 \le u_i, v_i \le n)$$$ separated by a space — the edges of the tree.

The next line contains $$$n$$$ integers $$$a_1, a_2, ..., a_n$$$ $$$(0 \le a_i \lt 2^{30})$$$ separated by spaces — the number of sprout moles in each node.

Output

Output one line containing $$$n$$$ integers. The $$$r$$$-th $$$(1 \le r \le n)$$$ of them contains $$$\displaystyle\sum_{i=1}^n f(i)$$$ modulo $$$998244353$$$ when the tree is rooted at node $$$r$$$.

Examples
Input
3
1 2
1 3
1 2 3
Output
11 15 14 
Input
3
1 2
1 3
1 1 1
Output
3 3 3 
Note

In the first sample, there are three possible roots :

  1. The tree is rooted at $$$1$$$. In that case, there are $$$3$$$ possible subtrees : $$$\{\{1,2,3\}, \{2\}, \{3\}\}$$$. The sets of all possible XOR sums over all subsets in each subtree are $$$\{\{0,1,2,3\}, \{0,2\}, \{0,3\}\}$$$. Their summation is $$$0 + 1 + 2 + 3 + 0 + 2 + 0 + 3 = 11$$$.
  2. The tree is rooted at $$$2$$$. In that case, there are $$$3$$$ possible subtrees : $$$\{\{1,2,3\}, \{1,3\}, \{3\}\}$$$. The sets of all possible XOR sums over all subsets in each subtree are $$$\{\{0,1,2,3\}, \{0,1,2,3\}, \{0,3\}\}$$$. Their summation is $$$0 + 1 + 2 + 3 + 0 + 1 + 2 + 3 + 0 + 3 = 15$$$.
  3. The tree is rooted at $$$3$$$. In that case, there are $$$3$$$ possible subtrees : $$$\{\{1,2,3\}, \{1,2\}, \{2\}\}$$$. The sets of all possible XOR sums over all subsets in each subtree are $$$\{\{0,1,2,3\}, \{0,1,2,3\}, \{0,2\}\}$$$. Their summation is $$$0 + 1 + 2 + 3 + 0 + 1 + 2 + 3 + 0 + 2 = 14$$$.
Aubrey being excited to start her sprout mole hunt

C. HERO
time limit per test
5 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
Hey, I got an idea! Now that I'm a boss... Do you guys wanna work for me? I don't offer any pay, but I see a great opportunity for growth in your future!
— (Bossman) Hero, The Last Resort

After achieving the title "Employee of the Month" three times, Mr. Jawsum promoted Hero to "Manager of Cryptocurrencies" as a reward for his hard work. Hero then found an opportunity to earn money using a new coin called "NEAR".

To gain NEAR, you need to work on some tasks related to training "Artificial Intelligence" to solve problems related to "Competitive Programming"; there are $$$n$$$ types of tasks to work on, the $$$i$$$-th type of tasks $$$(1 \le i \le n)$$$ has a "Profit value" equal to $$$a_i$$$.

Since Hero is currently the "Manager of Cryptocurrencies", he has enough power to hire people to work for him. Due to "The Last Resort" policies, the employees he hires can only work in a specific range $$$[l, r]$$$, meaning they can only work on tasks of type $$$i$$$ such that $$$(l \le i \le r)$$$.

The way Hero hires employees is as follows: he first chooses a range $$$[l, r]$$$ $$$(1 \le l \le r \le n)$$$, and then hires $$$\frac{x(x+1)}{2}$$$ employees such that $$$x$$$ is equal to the size of the range $$$(r - l + 1)$$$; he hires each of the $$$\frac{x(x+1)}{2}$$$ to work on all distinct sub-ranges in the range $$$[l, r]$$$. If an employee works on a range $$$[L, R]$$$, the total amount of money he achieves after working for one day is equal to $$$\text{LCM}(a_L, a_{L+1}, a_{L+2}, ..., a_{R-1}, a_R) \times L \times R$$$ worth of NEAR, where $$$\text{LCM}$$$ is the Least Common Multiple.

At the end of the day, Hero collects all money gained from all of his hired employees. Now since Hero wants to maximize his profit, he thought that he needed to choose the whole array of types of tasks as the initial range he hires people in. But he forgot that in "Dreamspace", every bank account has a limit of $$$998244352$$$ NEAR coins. When the number of coins in an account exceeds that number, it overflows and bounces back to $$$0$$$ NEAR coins. So the actual profit Hero gets is equal to the gained profit taken under modulo $$$998244353$$$.

Hero chose $$$Q$$$ candidate ranges as initial ranges to hire people in; the $$$j$$$-th $$$(1 \le j \le Q)$$$ range is equal to $$$[l_j, r_j]$$$ , and he wants to find the final profit he gets at the end of the day if he chooses that range, modulo $$$998244353$$$.

More formally, the answer to the $$$j$$$-th query is equal to $$$\displaystyle\sum_{L = l_j}^{r_j}\sum_{R = L}^{r_j} \text{LCM}(a_L, a_{L+1}, a_{L+2}, ..., a_{R-1}, a_R) \times L \times R$$$ taken under modulo $$$998244353$$$.

Input

The first line of input contains one integer $$$n$$$ $$$(1 \le n \le 10^5)$$$ — the number of types of tasks.

The next line contains $$$n$$$ integers $$$a_1, a_2, ..., a_n$$$ $$$(1 \le a_i \le 10^6)$$$ separated by spaces — the profit values of each type of the tasks.

The next line contains one integer $$$Q$$$ $$$(1 \le Q \le 10^5)$$$ — the number of candidate ranges Hero chose.

The $$$j$$$-th line of the next $$$Q$$$ lines each contains two integers $$$l_j, r_j$$$ $$$(1 \le l_j \le r_j \le n)$$$ — the boundaries of the $$$j$$$-th candidate range.

Output

Output $$$Q$$$ lines; the $$$j$$$-th of them should contain the final profit obtained from choosing the $$$j$$$-th range taken under modulo $$$998244353$$$.

Examples
Input
3
1 2 3
3
1 2
2 3
1 3
Output
13
71
94
Input
4
2 2 3 3
4
1 1
1 2
1 3
1 4
Output
2
14
95
251
Note

In the third query of the first sample, there are $$$6$$$ subranges in $$$[1,3]$$$, which are $$$\{ \{1\}, \{2\}, \{3\}, \{1, 2\}, \{2, 3\}, \{1, 2, 3\}\}$$$; the accumulative $$$\text{LCM}$$$ of each of them is equal to $$$\{1, 2, 3, 2, 6, 6\}$$$; the sum of each subarray $$$\text{lcm}$$$ multiplied by both its boundaries is equal to : $$$1\times 1 \times 1 + 2 \times 2 \times 2 + 3 \times 3 \times 3 + 2 \times 1 \times 2 + 6 \times 2 \times 3 + 6 \times 1 \times 3 = 94$$$

Mr. Jawsum congratulating Hero after promoting him to "Manager of Cryptocurrencies"

D. KEL
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
Ewww... pink is a gross color.
— Kel, Memory Lane

Kel was sitting bored on Mari's picnic blanket as everyone else was doing something, but after sometime he had an idea how to spend his time! He asked Basil to borrow his camera, and Basil agreed.

Mari's picnic blanket consists of $$$4$$$ different rectangular pieces each of dimensions $$$L \times W$$$, linked in a way such that the whole blanket has dimensions $$$2L \times 2W$$$.

Basil's camera has a laser like technique which generates laser from both sides (frontview and back view) to take $$$1\text{D}$$$ pictures; the laser can be thought of as a straight line (even though the actual camera can not generate an infinite straight line, Kel assumes it is a straight line as the blanket's dimensions are not too big).

Kel is trying to place and orient the camera in a way such that the generated laser passes by all $$$4$$$ rectangles in the blanket. A straight line is said to pass by a rectangle if a line segment of non-zero length — which is a subset of that straight line — intersects the rectangle.

Now Kel wants to find the number of different straight lines generated from his placement and orientation that can pass by all $$$4$$$ rectangular pieces in the blanket. Since this number can be large, you are asked to output it modulo $$$10^9+7$$$.

Input

The first line of input contains two integers $$$L, W$$$ $$$(1 \le L, W \le 10^6)$$$ — The dimensions of each rectangle.

Output

Output one line containing one integer, the number of different straight lines passing through all $$$4$$$ rectangles modulo $$$10^9+7$$$.

Examples
Input
1 1
Output
2
Input
2 2
Output
2
Note
In the first example, here is a blanket of $$$L=1,$$$ $$$W=1$$$ There are two possible straight lines for this blanket

Kel trying to orient the camera to get all $$$4$$$ rectangles

E. MARI
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
So... do you need me to help you in anything? All it costs is your love
— Mari, Dreamspace

Mari is currently baking cookies for OMORI's quest (as they need a lot of juice and heart in this one). She currently has a cookie dough with nutrition value $$$a_1$$$.

There are $$$n-1$$$ ovens numbered from $$$1$$$ to $$$n-1$$$. Mari puts each cookie in every oven by order, starting from oven $$$1$$$ till oven $$$n-1$$$. Ovens in dreams are different from casual ovens; they have two modes: Heating mode and Freezing mode, and also each oven $$$i$$$ has a power value $$$a_{i+1}$$$.

When baking a cookie with nutrition $$$x$$$ in the $$$i$$$-th oven, Mari can do one of the following options :

  1. Set the $$$i$$$-th oven on heating mode; this will change the nutrition value of the cookie from $$$x$$$ to $$$\max(x,a_{i+1})$$$.
  2. Set the $$$i$$$-th oven on freezing mode; this will change the nutrition value of the cookie from $$$x$$$ to $$$\min(x,a_{i+1})$$$.

Mari will try every possible configuration of modes to all $$$n-1$$$ ovens, and she wants to find the summation of the nutrition values of all final cookies over every possible configuration of ovens. Since this sum can be large, Mari wants its value taken under modulo $$$10^9+7$$$.

Two configurations of ovens are considered different if there exists an oven $$$j$$$ $$$(1 \le j \lt n)$$$ such that oven $$$j$$$ is set on heating mode in one configuration and set on freezing mode in the other one.

Input

The first line of input contains one integer $$$n$$$ $$$(1 \le n \le 2\times 10^5)$$$ — the number of ovens $$$+ 1$$$.

The next line contains $$$n$$$ integers $$$a_1, a_2, ..., a_n$$$ $$$(1 \le a_i \le 10^9)$$$ separated by spaces — the initial nutrition value of the cookie dough and the power values of each oven.

Output

Output one line containing the summation of all final cookies' nutrition values, taken under modulo $$$10^9 + 7$$$.

Examples
Input
3
1 2 1
Output
5
Input
5
2 2 2 2 2
Output
32
Note

In the first example, there are $$$4$$$ possibilities:

  1. Mari sets both ovens on heating mode; the final nutrition value of the cookie will be $$$\max(\max(1, 2), 1) = 2$$$.
  2. Mari sets both ovens on freezing mode; the final nutrition value of the cookie will be $$$\min(\min(1, 2), 1) = 1$$$.
  3. Mari sets the first oven on heating mode and the second one on freezing mode; the final nutrition value of the cookie will be $$$\min(\max(1, 2), 1) = 1$$$.
  4. Mari sets the first oven on freezing mode and the second one on heating mode; the final nutrition value of the cookie will be $$$\max(\min(1, 2), 1) = 1$$$.

So the summation of all final nutrition values will be : $$$2+1+1+1 = 5$$$.

A poster showing Mari's pieces of advice about baking cookies

F. BASIL
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
The photos in our album... They're not just photos. They're real memories. Our memories! It's proof of our friendship! Hold those pictures close... and remember what you want to protect.
— Basil, ???

Basil wants to play a game with his best friend Sunny; he starts by explaining the rules to him.

The game is played on an array of $$$n$$$ flower pots, where the $$$i$$$-th pot $$$(1 \le i \le n)$$$ has two values $$$a_i$$$, $$$t_i$$$, denoting the number of seeds initially in the $$$i$$$-th flower pot and the type of seeds in this flower pot, respectively.

During a move, the player has to choose a flower pot which has a non-zero number of seeds; let the index of this flower pot be $$$i$$$ $$$(1 \le i \le n)$$$, then he will do two things:

  1. Pick a positive integer value $$$x$$$ $$$(1 \le x \le a_i)$$$ and decrease $$$a_i$$$ by $$$x$$$ (Choose some non-zero number of seeds from some flower pot and remove them).
  2. For every flower pot $$$j$$$ such that $$$t_j \lt t_i$$$, you can set the value of $$$a_j$$$ to any non-negative integer of your choice; it can still be the original value of $$$a_j$$$ before the move (For every flower pot that has a seed type value less than the value of the type of the seeds you removed, you can either increase, do nothing to, or decrease the number of each of those flower pots to any number of your choice as Basil has an infinite supply of seeds of every type, but the number of seeds has to be non-negative after every change in each pot).

The player who can not make a move loses, and Sunny goes first.

Sunny and Basil are going to play $$$q$$$ matches; the $$$j$$$-th match $$$(1 \le j \le q)$$$ is going to be played on the subarray from index $$$l_j$$$ to index $$$r_j$$$, inclusive.

Assuming both Sunny and Basil are playing optimally, your task is to find which player wins in each of the $$$q$$$ matches.

Input

The first line of input contains one integer $$$n$$$ $$$(1 \le n \le 2\times 10^5)$$$ — The number of flower pots.

The next line contains $$$n$$$ integers $$$a_1, a_2, ..., a_n$$$ $$$(0 \le a_i \le 10^9)$$$ separated by spaces — The number of seeds in each flower pot.

The next line contains $$$n$$$ integers $$$t_1, t_2, ..., t_n$$$ $$$(1 \le t_i \le n)$$$ separated by spaces — The type of seeds in each flower pot.

The next line contains one integer $$$q$$$ $$$(1 \le q \le 2\times 10^5)$$$ — The number of matches played.

The $$$j$$$-th of the next $$$q$$$ lines contains two integers $$$l_j, r_j$$$ $$$(1 \le l_j \le r_j \le n)$$$ — The boundaries of the subarray on which the $$$j$$$-th match will be played.

Output

For each of the $$$q$$$ matches, output one line containing the name of the winner; output "SUNNY" (without quotes) if the winner was Sunny and "BASIL" (without quotes) otherwise.

Examples
Input
6
1 2 3 3 2 1
1 1 1 1 1 1
6
3 4
2 5
1 6
1 3
4 6
5 6
Output
BASIL
BASIL
BASIL
BASIL
BASIL
SUNNY
Input
3
1 1 1
1 2 3
2
1 2
1 3
Output
SUNNY
SUNNY
Note

In the first match in the second sample, there are two flower pots each having only one seed; one of them is of type $$$1$$$ and the other is of type $$$2$$$. Sunny can choose to take the seed from the flower pot of type $$$2$$$ and then set the number of seeds in the flower pot of type $$$1$$$ to $$$0$$$, making every pot empty and thus winning as Basil will not be able to do a move after Sunny's turn.

Basil explaining the rules of the game to Sunny

G. OMORI
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
.......................................
— Omori, OMORI

OMORI is bored in white space; he has been living there for as long as he can remember... He creates a game out of boredom with his dolls.

There are $$$n$$$ dolls in the possession of OMORI, exactly one of these dolls resembles OMORI (has no emotion); the other $$$n-1$$$ dolls can be of three types:

  1. Happy dolls (These dolls resemble Kel).
  2. Angry dolls (These dolls resemble Aubrey).
  3. Sad dolls (These dolls resemble Hero).
It is guaranteed that there is at least one doll of each type.

How does the game work? Since OMORI has been living alone for a lot of time, he started to make imaginary fights with dolls; he decides the winner according to the following chart:

Happy beats Angry - Angry beats Sad - Sad beats Happy

So, when two dolls fight, OMORI decides the result according to the following rules:

  1. If one of the two dolls is emotionless, the result is a tie.
  2. Otherwise, if the two dolls are of the same emotion, the result is a tie.
  3. Otherwise, decide the winner of the two dolls based on the emotion chart described above.

After explaining, OMORI then plays the game with you; the game is as follows: OMORI shuffles the $$$n$$$ dolls and asks you to find the emotionless doll (the one that resembles OMORI). You can do up to $$$3n$$$ questions of the form i,j, $$$(1 \le i,j \le n)$$$, and OMORI will answer with either $$$0$$$ or $$$1$$$.

When you ask OMORI about two dolls i,j, he will return $$$1$$$ only if doll $$$i$$$ beats doll $$$j$$$ in a fight; otherwise, he will return $$$0$$$ (whether it was a tie or doll $$$j$$$ won).

Input

The first line of input contains a single integer $$$n$$$ $$$(4 \le n \le 20000)$$$ — the number of dolls OMORI has.

The description of the interaction follows.

Interaction

To ask OMORI a question, you can output no more than $$$3n$$$ queries of the following format:

  • "? i j", where $$$i,j$$$ are two integers satisfying $$$(1 \le i,j \le n)$$$.

In response to this query, you will receive $$$1$$$ if doll $$$i$$$ beats doll $$$j$$$ in a fight, and $$$0$$$ otherwise.

Once you have found the answer, output a query of the following format:

  • "! x", where $$$x$$$ is the index of the emotionless doll.

If you make an invalid query, you will receive $$$−1$$$ instead of a response from OMORI. If you exceed the limit of $$$3n$$$ questions, you will receive $$$−2$$$ instead of a response from OMORI. If you return an incorrect answer, you will receive $$$−3$$$ instead of a response from OMORI. In all of these cases you will get the verdict Wrong answer. In this case, your program should terminate immediately to avoid undefined verdicts.

After outputting the queries/answer, do not forget to output a newline character and flush the output buffer. Otherwise, you will receive the verdict Solution "hung" (Idleness limit exceeded). To flush the buffer, use:

  • fflush(stdout) or cout.flush() in C/C++;
  • System.out.flush() in Java;
  • flush(output) in Pascal;
  • stdout.flush() in Python;
  • refer to the documentation for other languages.
Examples
Input
4

1

0

0

0

0

1
Output

? 1 2

? 1 3

? 1 4

? 3 2

? 4 2

? 3 1

! 4
Input
4

0

0

0
Output

? 1 2

? 1 3

? 1 4

! 1
Note

In the first sample, the emotions of the dolls in order are: {"Happy", "Angry", "Sad", "Emotionless"}.

In the second sample, the emotions of the dolls in order are: {"Emotionless", "Happy", "Angry", "Sad"}.

OMORI spending time in white space thinking about a game