Teamscode Spring 2024 (Novice Division)
A. It's Time to Submit
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

It's time to submit (your ac solutions)!

Teamscode has had a history of setting problems where outputting the sample output gives AC on the first problem. Examples of past problems include "Meeting Minutes," "Best Waifu," "Are You Busy," etc.

Now, it is time to submit to this new first problem of the Spring $$$2024$$$ contest. Is outputting the sample output enough to get AC?

Input

The first and only line of input contains an integer $$$T$$$ $$$(0 \leq T \leq 10)$$$.

Output

Output "YES" (without the quotes) if it is possible to get AC by outputting the sample output or "NO" otherwise.

Example
Input
0
Output
YES
Note

Unfortunately, the sample output is not "NO". If that were the case, it would be impossible to AC at all!

Problem Idea: 3366

Problem Preparation: 3366

Occurrences: Novice 1, Advanced 1

B. A Bit of Monkeying
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
A slip of the tongue
$$$ \ $$$

Arararagi has an array $$$a$$$ of length $$$n$$$ and two monkeys. The first monkey can take an index $$$i$$$ and set $$$a_i = a_i | x$$$ where $$$x$$$ is any nonnegative integer in one step. The second monkey can take an index $$$i$$$ and set $$$a_i = a_i \& x$$$ where $$$x$$$ is any nonnegative integer in one step. Remember $$$|$$$ is bitwise OR and $$$\&$$$ is bitwise AND.

Parallegi likes arrays when the bitwise AND of all its elements is equal to the bitwise OR of all its elements. Claragi will make two copies of his array and hand one to each monkey. He will ask each monkey to turn his array into one he likes by having them repeatedly apply their operation. Rararagi likes competition and will reward the monkey that uses fewer operations with a piece of candy (but in the case of a tie he will eat the candy and both monkeys will be sad). Help Doalagi predict which monkey will win.

Input

The first line of input contains a single integer $$$T$$$ denoting the number of test cases $$$(1 \leq T \leq 10^4)$$$.

Each test case consists of two lines.

The first line contains a single integer $$$n$$$ $$$(1 \leq n \leq 10^5)$$$ denoting the length of $$$a$$$.

The following line contains $$$n$$$ spaced integers, the $$$i$$$'th of which being $$$a_i$$$ $$$(0 \leq a_i \leq 10^9)$$$.

It is guaranteed that the sum of $$$n$$$ across all test cases is at most $$$2 \cdot 10^5$$$.

Tests in subtasks are numbered from $$$1 \dots 10$$$ with samples skipped. Each test is worth $$$\frac{100}{10} = 10$$$ points.

Tests $$$1 - 5$$$ satisfy $$$0 \leq a_i \lt 4$$$.

The remaining tests do not satisfy any additional constraints.

Output

For each test case, output "or" if the first monkey wins, "and" if the second monkey wins, or "sad" if they tie.

Example
Input
6
4
0 1 2 3
5
0 1 2 3 4
4
3 3 6 6
5
1 3 5 7 4
3
1 1 3
4
3366 1234 0 0
Output
sad
and
sad
or
and
and
Note

In the first test case, the first monkey will take $$$3$$$ steps and the second monkey will also take $$$3$$$ steps.

In the second test case, the first monkey will take $$$5$$$ steps while the second monkey takes $$$4$$$ steps.

In the fourth test case, the first monkey will take $$$4$$$ steps while the second monkey takes $$$5$$$ steps.

Problem Idea: yash belani

Problem Preparation: 3366

Occurrences: Novice 2

C. Alternet is Cheating
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Disclaimer: the only part about this statement that is real is the part where I lose against all real participants. — Alternet

lethan3 is organizing a lockout tournament!

lethan3 has a tournament of $$$N$$$ participants ($$$N$$$ is a power of 2). The tournament follows a specific match format: participant 1 plays against participant 2, participant 3 plays against participant 4, and so on. After the round, the losers step out of the tournament and the winners progress to the next round in the same order. In the second round, the winner of match 1 and the winner of match 2 play against each other, and similarly, the winners of matches 3 and 4 play against each other, etc. Rounds are played until there is only one winner left.

Alternet is participating in lethan3's lockout tournament. Unfortunately for him, he has no skill and is dominated by all of the participants. Fortunately, he has many friends (also in the tournament) who will help him win. Because Alternet knows the order in which participants will solve problems, he can instruct his friends to snipe them.

Formally:

There are three types of participants: real participants, Alternet's friends, and Alternet.

When two real participants compete, the one with a lower seed wins (The $$$i$$$th participant has seed $$$i$$$).

Alternet can teach each one of his friends individually to beat exactly one real participant (they will lose to all other real participants). Alternet's friends will let Alternet win against them, and when Alternet's friends compete against each other, Alternet can decide who wins.

Alternet loses against real participants and only wins against his friends.

Alternet really wants to win the tournament. So, he asks you to determine if it's possible to win the tournament.

Input

The first line contains an integer $$$T$$$ ($$$1 \leq T \leq 1000$$$), the number of test cases.

For each test case:

The first line contains one integer $$$N$$$ ($$$2 \leq N \le 2^{10} = 1024$$$.)

The following line contains a string of length $$$N$$$. The $$$i$$$th character indicates if the $$$i$$$th participant is a real participant ("R"), one of Alternet's friends ("F"), or Alternet ("A"). It is guaranteed that there is one and only one Alternet in each test case.

There are $$$20$$$ tests (with samples skipped). Each test is worth $$$\frac{100}{20} = 5$$$ points.

Output

For each test case, print "Yes" if Alternet is able to win and "No" otherwise.

Example
Input
3
2
AR
4
RFAF
4
RRAF
Output
No
Yes
No
Note

In the first test case, Alternet immediately loses to the real participant.

In the second test case, Alternet can win if both of his friends are taught to defeat the only real participant.

In the third test case, it can be proven that Alternet cannot win the tournament.

Problem Idea: alternet

Problem Preperation: alternet

Occurrences: Novice 3

D. Haagendaz is Justice
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

In the Araragi household, there is a fridge that contains an infinite amount of Haagendaz numbered $$$1, 2, 3, \dots $$$. Koyomi and Tsukihi both love Haagendaz but have some level of guilt ($$$K$$$ for Koyomi and $$$T$$$ for Tsukihi) that dictates the maximum amount of Haagendaz they can eat in one sitting. Both Koyomi's and Tsukihi's guilt levels start at $$$1$$$ and will increase when they see the other person eating Haagendaz. In particular, whenever someone sees the other person eats $$$x$$$ Haagendaz in one sitting, they will increase their own guilt level by $$$x$$$. Tsukihi will eat the maximum number of Haagendaz her guilt level allows, the following day, Koyomi will eat the maximum number of Haagendaz his guilt level allows, then the next day Tsukihi will eat the maximum number of Haagendaz, etc.

Handle $$$n$$$ questions of the form $$$x$$$, where you must determine who will eat the $$$x$$$'th Haagendaz.

Input

The first line contains a singular integer $$$n$$$ $$$(1 \leq n \leq 10^5)$$$.

The second line contains $$$n$$$ spaced integers $$$x_{1 \dots n}$$$, the $$$i$$$'th denoting a question about the $$$x_i$$$'th Haagendaz $$$(1 \leq x_i \leq 10^{18})$$$.

Tests are numbered from $$$1 \dots 10$$$ with samples skipped. Each test is worth $$$\frac{100}{10} = 10$$$ points.

Tests $$$1 - 5$$$ satisfy $$$x_i \leq 10^6$$$.

The remaining tests do not satisfy any additional constraints.

Output

Output a string of length $$$n$$$, the $$$i$$$'th character being $$$T$$$ if Tsukihi eats $$$x_i$$$'th Haagendaz or $$$K$$$ otherwise (Koyomi eats it).

Example
Input
11
1 2 3 4 5 6 7 8 9 10 3366
Output
TKKTTTKKKKK
Note

Initially, $$$T = 1$$$ and $$$K = 1$$$.

Tsukihi will eat $$$1$$$ Haagendaz (the $$$1$$$st) on day $$$1$$$. Then Koyomi, seeing Tsuhiki eat that Haagendaz, will increase his guilt level by $$$1$$$.

Now $$$T = 1$$$ and $$$K = 2$$$.

Koyomi will eat the next $$$2$$$ Haagendaz (the $$$2$$$nd and $$$3$$$rd). Then Tsuhiki, seeing Koyomi eat $$$2$$$ Haagendaz, will increase her guilt level by $$$2$$$.

Now $$$T = 3$$$ and $$$K = 2$$$.

Tsuhiki will eat the next $$$3$$$ Haagendaz (the $$$4$$$th, $$$5$$$th, and $$$6$$$th). Then Koyomi, seeing Tsuhiki eat $$$3$$$ Haagendaz will increase his guilt level by $$$3$$$.

Now $$$T = 3$$$ and $$$K = 5$$$.

Koyomi will eat the next $$$5$$$ Haagendaz (the $$$7$$$th, $$$8$$$th, $$$9$$$th, $$$10$$$th, and $$$11$$$th). And so on.

Unfortunately, I do not have the space to explain why Koyomi eats the $$$3366$$$th Haagendaz.

Problem Idea: Helen

Problem Preparation: 3366

Occurrences: Novice 4

E. Richard Lore
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Jinshi loves his toys, and his two favorite toys are an array $$$a$$$ of length $$$n$$$ and a sequence of $$$m$$$ pairs of integers, the $$$i$$$'th being $$$x_i$$$ and $$$y_i$$$ $$$(1 \leq x_i, y_i \leq n)$$$. Whenever Jinshi is bored, he likes to try and sort $$$a$$$ with his $$$m$$$ pairs of integers. Jinshi will loop over the pairs in order from $$$1$$$ to $$$m$$$, and swap $$$a_{x_i}$$$ and $$$a_{y_i}$$$. He will be happy if after all $$$m$$$ swaps, $$$a$$$ becomes sorted in increasing order. Afterward, Jinshi will restore $$$a$$$ to what it was before all the swaps happened.

Maomao will mess with Jinshi over the following $$$q$$$ days, where on the $$$i$$$'th day, she will swap $$$a_{l_i}$$$ and $$$a_{r_i}$$$ $$$(1 \leq l_i, r_i \leq n)$$$. Without knowing Maomao has messed with his array, Jinshi will try to sort it every day after Maomao does the swap. Maomao will not restore $$$a$$$ after doing the swap. On each day, find out if Jinshi will successfully sort his array.

Input

The first line of input contains three integers $$$n \ m \ q$$$ denoting the length of the array, the number of pairs, and the number of days Maomao will mess with Jinshi $$$(1 \leq n, m, q \leq 10^5)$$$.

The following line contains $$$n$$$ spaced integers, the $$$i$$$'th being $$$a_i$$$, denoting Jinshi's array $$$(1 \leq a_i \leq n)$$$.

The following $$$m$$$ lines contain two integers each, the $$$i$$$'th line containing $$$x_i \ y_i$$$ denoting the $$$i$$$'th pair of integers in Jinshi's $$$m$$$ pairs $$$(1 \leq x_i, y_i \leq n)$$$.

The following $$$q$$$ lines contain two integers each, the $$$i$$$'th line containing $$$l_i \ r_i$$$ denoting the pair of elements Maomao swaps on the $$$i$$$'th day $$$(1 \leq l_i, r_i \leq n)$$$.

Tests are numbered $$$1 - 20$$$ with samples skipped. Each test is worth $$$\frac{100}{20} = 5$$$ points.

All odd-numbered tests satisfy that $$$a$$$ is a permutation. In other words, all the elements in $$$a$$$ will be unique.

Tests $$$1 - 10$$$ satisfy $$$n, m, q \leq 1000$$$.

The remaining tests do not satisfy any additional constraints.

Output

Output a string of length $$$q$$$, the $$$i$$$'th character being $$$Y$$$ if Jinshi can sort his array on the $$$i$$$'th day or $$$N$$$ otherwise.

Examples
Input
5 3 6
1 4 2 3 5
3 4
1 2
4 1
1 3
1 4
3 4
3 1
3 4
5 5
Output
YNNNYY
Input
5 1 7
1 2 1 2 4
2 3
2 4
1 2
2 3
3 4
4 1
1 2
2 3
Output
YNNNNNY
Note

On the first day, the array becomes $$$[2, 4, 1, 3, 5]$$$ after Maomao swaps $$$a_{1}$$$ and $$$a_{3}$$$. Jinshi will then attempt to sort his array, which changes as follows:

$$$[2, 4, 1, 3, 5] \rightarrow [2, 4, 3, 1, 5] \rightarrow [4, 2, 3, 1, 5] \rightarrow [1, 2, 3, 4, 5]$$$

Since Jinshi's array is sorted, the first character in the output string is $$$Y$$$.

Problem Idea: 3366

Problem Preparation: 3366

Occurrences: Novice 5, Advanced 2

F. Unique Subsequences
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

You are given a string $$$s$$$ of length $$$n$$$. Determine if all subsequences of $$$s$$$ that have length $$$k$$$ are unique.

A subsequence of $$$s$$$ is defined as a sequence that can be obtained from $$$s$$$ by deleting some elements (possibly none), without changing the order of the remaining elements.

For instance, the subsequences of $$$trust$$$ of length $$$4$$$ are $$$trus$$$, $$$trut$$$, $$$trst$$$, and $$$rust$$$, all of which are unique.

But when considering subsequences of $$$threes$$$ of length $$$4$$$. The subsequence $$$tres$$$ occurs twice ($$$\underline{t}h\underline{re}e\underline{s}$$$ and $$$\underline{t}h\underline{r}e\underline{es}$$$).

Input

The first line of input contains a single integer $$$T$$$ denoting the number of test cases $$$(1 \leq T \leq 10^3)$$$.

The first line of each test case contains two integers $$$n \ k$$$ denoting the length of the string and the length of subsequences to consider $$$(1 \leq k \leq n \leq 10^5)$$$.

The second line contains a string $$$s$$$ of length $$$n$$$ consisting only of lowercase English letters.

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

Tests in subtasks are numbered from $$$1 - 10$$$ with samples skipped. Each test is worth $$$\frac{100}{10} = 10$$$ points.

Tests $$$1 - 3$$$ satisfy $$$n \leq 10$$$.

Tests $$$4 - 5$$$ satisfy that the sum of $$$n$$$ across all test cases does not exceed $$$3366$$$.

The remaining tests do not satisfy any additional constraints.

Output

For each test case, output "Yes" (without the quotes) if all subsequences of length $$$k$$$ are unique or "No" (without the quotes) otherwise.

Example
Input
11
5 4
trust
6 4
threes
6 4
abcdba
8 4
sendhelp
9 8
imtrapped
7 6
inabase
9 5
mentuntil
7 1
ifinish
9 7
preparing
8 3
problems
8 8
heeeeelp
Output
Yes
No
Yes
No
No
Yes
No
No
Yes
Yes
Yes
Note

It can be proven that all $$$15$$$ subsequences of length $$$4$$$ of $$$abcdba$$$ are unique (by listing them out and reading over them carefully). Also I'm trapped in Tho$$$[$$$deleted$$$]$$$

Problem Idea: dutin

Problem Preperation: 3366

Occurrences: Novice 6, Advanced 3

G. Sleepy Pandas
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

You received a shipment of $$$N$$$ pandas labelled with numbers $$$x_1, x_2, \ldots, x_N$$$ from Mars ($$$N \leq 10^5$$$, $$$1 \leq x_i \leq 10^9$$$). Additionally, you have a magical zookeeper who has a favorite number $$$K$$$ ($$$K \leq 10^9$$$). The zookeeper will do the following exactly once:

  1. Pick two distinct pandas, say panda $$$i$$$ and panda $$$j$$$, and puts them to sleep.
  2. Concatenate the numbers on the labels of panda $$$i$$$ and panda $$$j$$$ to form a new number $$$y$$$.
  3. If $$$y$$$ is not divisible by $$$K$$$, then the zookeeper ships pandas $$$i$$$ and $$$j$$$ back to Mars.

Your task is to find the number of ordered pairs $$$(i, j)$$$ such that after performing the operation above, the zookeeper does not ship pandas $$$i$$$ and $$$j$$$ back to Mars.

Note: $$$i$$$ is not necessarily less than $$$j$$$. Also, the concatenation of $$$i$$$ and $$$j$$$ is different from the concatenation of $$$j$$$ and $$$i$$$.

A concatenation of numbers $$$x$$$ and $$$y$$$ is the number that is obtained by writing down numbers $$$x$$$ and $$$y$$$ one right after another without changing the order. For example, a concatenation of numbers $$$12$$$ and $$$3456$$$ is a number $$$123456$$$.

Input

The first line contains an integer $$$T$$$ ($$$T \leq 100$$$), the number of test cases.

For each test case:

The first line contains two integers $$$N$$$ and $$$K$$$ ($$$1 \leq N \leq 10^5$$$, $$$1 \leq K \leq 10^9$$$) representing the number of pandas and the zookeeper's favorite number.

The second line contains $$$N$$$ space-separated integers $$$x_1, x_2, \ldots, x_N$$$ ($$$1 \leq x_i \leq 10^9$$$) representing the labels on the pandas.

It is guaranteed that the sum of $$$N$$$ over all test cases does not exceed $$$10^5$$$.

Tests in subtasks are numbered from $$$1 - 20$$$ with samples skipped. Each test is worth $$$\frac{100}{20} = 5$$$ points.

Tests $$$1 - 5$$$ satisfy $$$N \leq 1000$$$, and the sum of $$$N$$$ over all test cases does not exceed $$$10^4$$$.

The remaining tests do not satisfy any additional constraints.

Output

For each test case, output a single integer representing the number of ordered pairs $$$(i, j)$$$ such that after performing the operation, the zookeeper does not ship pandas $$$i$$$ and $$$j$$$ back to Mars. Output each testcase on a new line.

Example
Input
2
4 11
1 4 3 4
3 2
1 2 3
Output
2
2
Note

For the first test case, pairs $$$(2, 4)$$$ and $$$(4, 2)$$$ result in $$$y=44$$$ which is divisible by $$$11$$$.

For the second test case, pairs $$$(1, 2)$$$ and $$$(3, 2)$$$ work.

Problem Idea: yash belani

Problem Preparation: jay_jayjay

Occurrences: Novice 7, Advanced 4

H. Afterimages
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Korosensei has decided to hold a dance for Class E. Unfortunately, no one showed up, so he is forced to dance with himself. He has created two lines of $$$n$$$ afterimages each (where $$$n$$$ is even), the $$$i$$$'th in the first line having height $$$a_i$$$ and the $$$i$$$'th in the second line having height $$$b_i$$$. Korosensei will then have all his afterimages sing $$$k$$$ songs and dance to them.

Every time a song starts, for all $$$i$$$ from $$$1 \dots n$$$, the $$$i$$$'th afterimage in the first line will dance with the $$$i$$$'th afterimage in the second line. Every time a song ends, all the afterimages in the first line will cyclically shift to the right by $$$1$$$, and the $$$n$$$'th afterimage will go to the front of the line ($$$a_2 = a_1, a_3 = a_2 \dots a_{n} = a_{n-1}, a_1 = a_n)$$$. At the same time, all the afterimages in the second line will cyclically shift to the left by $$$1$$$, and the first afterimage will go to the back of the line ($$$b_1 = b_2, b_2 = b_3 \dots b_{n-1} = b_{n}, b_n = b_1)$$$.

Even though he can travel at Mach 20, even Korosensei has trouble dancing with someone taller (or shorter) than him. The awkwardness of a dance between two afterimages with heights $$$x$$$ and $$$y$$$ is $$$abs(x - y)$$$ where $$$abs$$$ denotes the absolute value function. For each afterimage (in both lines), determine the maximum awkwardness of any dance they are a part of. As you, the participant, cannot write at Mach 20 (but can probably add at Mach 20?), you are only required to find the total sum of awkwardness for each afterimage.

Input

The first line of input contains a single integer $$$T$$$, denoting the number of test cases $$$(1 \leq T \leq 10^4)$$$.

Each test case consists of three lines.

The first line of each test case contains two integers $$$n$$$ $$$k$$$, denoting the lengths of the lines and the number of songs the afterimages sing $$$(2 \leq n \leq 2 \cdot 10^5, 1 \leq k \leq 10^{18})$$$. It is guaranteed that $$$n$$$ is even.

The second line of each test case contains $$$n$$$ spaced integers $$$a_{1 \dots n}$$$, the $$$i$$$'th being $$$a_i$$$ $$$(1 \leq a_i \leq 10^9)$$$. In case you are curious, the units to measure height here are football fields.

The third line of each test case contains $$$n$$$ spaced integers $$$b_{1 \dots n}$$$, the $$$i$$$'th being $$$b_i$$$ $$$(1 \leq b_i \leq 10^9)$$$. The units are still football fields (consistency is important).

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

Tests in subtasks are numbered from $$$1 \dots 20$$$ with samples skipped. Each test is worth $$$\frac{100}{20} = 5$$$ points.

Tests $$$1 - 5$$$ satisfy $$$n, k \leq 10$$$

Tests $$$6 - 10$$$ satisfy $$$n \leq 1000, T \leq 10$$$

The remaining tests do not satisfy any additional constraints.

Output

For each test case, output a single integer $$$S$$$ on a new line, denoting the sum of the maximum awkwardness of all dances of every afterimage.

Example
Input
6
6 2
1 2 3 4 5 6
7 8 9 10 11 12
6 3
1 3 5 7 9 11
12 8 3 4 2 1
4 3
3 3 6 6
1 2 3 4
4 10
1000000000 1 1 1000000000
1 1000000000 1000000000 1
2 10
1 2
1 2
6 2
4 6 4 8 4 6
3 7 2 3 7 2
Output
88
92
26
7999999992
0
39
Note

An explanation of the first sample is as follows:

After the first song starts playing, the heights in the first line are $$$[1, 2, 3, 4, 5, 6]$$$ and the heights in the second line are $$$[7, 8, 9, 10, 11, 12]$$$.

After the second song starts playing (and the first song stops playing), the heights are $$$[6, 1, 2, 3, 4, 5]$$$ and the heights in the second line are $$$[8, 9, 10, 11, 12, 7]$$$.

The sum of maximum awkwardness for dances of afterimages in the first line are $$$abs(1 - 9) + abs(2 - 10) + abs(3 - 11) + abs(4 - 12) + abs(5 - 11) + abs(6 - 12) = 44$$$

The sum of maximum awkwardness for dances of afterimages in the second line are $$$abs(7 - 1) + abs(8 - 2) + abs(9 - 1) + abs(10 - 2) + abs(11 - 3) + abs(12 - 4) = 44$$$

Then the total sum is $$$44 + 44 = 88$$$.

Problem idea: yash belani

Problem Preparation: 3366

Occurrences: Novice 8

I. Another Bitwise Problem
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

You are given $$$n$$$ numbers $$$a_1, a_2, \dots, a_n$$$. How many numbers between $$$l$$$ and $$$r$$$ can be expressed in the form $$$\displaystyle\sum_{i=1}^{n} (a_i \oplus x)$$$, where $$$x$$$ is a nonnegative integer, and $$$\oplus$$$ denotes the bitwise XOR operation?

Input

The first line consists of three integers $$$n$$$, $$$l$$$, and $$$r$$$ $$$(1 \leq n \leq 10^{5}, 0 \le l \le r \le 10^{18})$$$.

The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ $$$(0 \le a_i \le 10^5)$$$.

The first $$$5$$$ test cases (not including the sample) satisfy $$$n \le 100$$$, $$$a_i \le 100$$$, $$$0 \le l \le r \le 10^5$$$.

Output

Print a single integer $$$-$$$ the number of reachable integers in the range $$$[l, r]$$$.

Example
Input
3 0 12
1 2 3
Output
4
Note

$$$x = 0$$$ gives a sum of $$$6$$$.

$$$x = 1$$$ gives a sum of $$$5$$$.

$$$x = 2$$$ gives a sum of $$$4$$$.

$$$x = 3$$$ gives a sum of $$$3$$$.

Problem Idea: thehunterjames

Problem Preparation: thehunterjames

Occurrences: Novice 9, Advanced 6

J. Everyone Loves Threes Magic (Easy Version)
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

The difference between the Easy and Hard versions is the constraints on $$$T$$$ and $$$R$$$.

Utena really likes the number $$$3$$$. Let $$$f(x)$$$ count the number of $$$3$$$'s in the base-$$$10$$$ representation of $$$x$$$.

Given two integers $$$l$$$ and $$$r$$$ where $$$l \leq r$$$, compute $$$g(l, r)$$$, the sum of $$$f(x)$$$ for all $$$x$$$ such that $$$l \leq x \leq r$$$ and $$$0 \equiv x \pmod{3}$$$ (note that $$$0 \equiv x \pmod{3}$$$ means that $$$x$$$ is divisible by $$$3$$$). That would have been the problem but Utena forgot what $$$l$$$ and $$$r$$$ were.

So given $$$L$$$ and $$$R$$$, compute the sum of $$$g(l, r)$$$ for $$$L \leq l \leq r \leq R$$$. Since this number may be very large, please find it modulo $$$998244353$$$.

Input

The first line of input contains a single integer $$$T$$$, denoting the number of test cases $$$(1 \leq T \leq 10^5)$$$.

Each test case consists of two lines. The first line contains an integer $$$L$$$ and the second line contains an integer $$$R$$$ $$$(1 \leq L \leq R \leq {10^6})$$$.

Tests in subtasks are numbered from $$$1 - 20$$$ with samples skipped. Each test is worth $$$\frac{100}{20} = 5$$$ points.

Test $$$1 - 2$$$ satisfies $$$T \leq 10, R \leq 100$$$.

Test $$$3 - 5$$$ satisfies $$$T \leq 10, R \leq 1000$$$.

Tests $$$5 - 10$$$ satisfies $$$T \leq 10, R \leq 10^5$$$.

Tests $$$11 - 13$$$ satisfy $$$L = 1$$$.

The remaining tests do not satisfy any additional constraints.

Output

For each test case, output a new line containing a single integer $$$S$$$, denoting the desired sum modulo $$$998244353$$$.

Example
Input
5
1
10
1
100
30
40
33
66
3366
6633
Output
24
14808
130
512
767342710
Note

Problem Idea: 3366

Problem Preparation: 3366

Occurrences: Novice 10

K. Another Ordering Problem
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Kyousuke is ordering sushi for Kirino. Sushi is free, but toppings cost money. The menu has $$$n$$$ toppings, each represented with a number $$$i$$$, where $$$i$$$ is a number from $$$1$$$ to $$$n$$$. Each topping has some price $$$a_i$$$. However, Kirino has a rule for each topping, where if Kyousuke orders some topping $$$i$$$ on the sushi he can't put some other topping $$$b_i$$$ on the sushi, because Kirino will slap him. What is the most expensive sushi Kyousuke can order that can satisfy Kirino?

Input

The first line contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$).

The $$$i$$$-th of the next $$$n$$$ lines contains two integers $$$a_i$$$ and $$$b_i$$$ ($$$1 \le a_i \le 10^9$$$, $$$1 \le b_i \le n$$$) $$$-$$$ the price and the topping that doesn't go with the $$$i$$$th sushi, respectively.

There are $$$20$$$ tests. Each test is worth $$$\frac{100}{20}$$$ points.

Output

Print one integer $$$-$$$ the most expensive sushi Kyousuke can order.

Example
Input
4
9 3
9 1
9 1
9 3
Output
18
Note

photographer: Hoshinomiya Yuna

Problem Idea: thehunterjames

Problem Preparation: thehunterjames

Occurrences: Novice 11, Advanced 5

L. Gaslighting
time limit per test
5 seconds
memory limit per test
512 megabytes
input
standard input
output
standard output

Waymo and Brian are discussing the winter 2023 seasonsals a string $$$s$$$ and will have $$$q$$$ different conversations. In some conversation, Brian will start talking about $$$s_{l \dots r}$$$, but Waymo will attempt to gaslight him into thinking he was talking about $$$s_{l' \dots r'}$$$ where $$$s_{l \dots r}$$$ and $$$s_{l' \dots r'}$$$ differ by exactly 1 element. Waymo loves to gaslight but he doesn't know the string well enough, so he asks you to construct an $$$l'$$$ and $$$r'$$$ for each $$$l \ r$$$ Brian talks about. Note that $$$r' - l' + 1 = r - l + 1$$$.

Note that two strings $$$a$$$ and $$$b$$$ of the same length differ by exactly $$$1$$$ element if and only if there exists some index $$$i$$$ such that $$$a_i \neq b_i$$$ and for all $$$j \neq i$$$, $$$a_j = b_j$$$.

Input

The first line of input contains two integers $$$n$$$ and $$$q$$$ denoting the length of the string and the number of conversations $$$(1 \leq n \leq 7000, 1 \leq q \leq 10^6)$$$.

The second line of input contains the string $$$s$$$ of length $$$n$$$ and consists only of lowercase English letters.

The following $$$q$$$ lines each contain two integers $$$l$$$ and $$$r$$$, denoting the substring Waymo and Brian are talking about $$$(1 \leq l \leq r \leq n)$$$.

Tests in subtasks are numbered from $$$1 - 20$$$ with samples skipped. Each test is worth $$$\frac{100}{20} = 5$$$.

Tests $$$1 - 3$$$ satisfy $$$n, q \leq 100$$$.

Tests $$$4 - 7$$$ satisfy $$$n \leq 2000$$$.

Tests $$$8 - 10$$$ satisfy $$$q = n, l = 1$$$.

The remaining tests do not satisfy any additional constraints.

Output

For each of the $$$q$$$ conversations, output a line containing two integers $$$l' \ r'$$$ denoting some valid answer as defined in the statement or $$$0$$$ $$$0$$$ if no such $$$l'$$$ and $$$r'$$$ exist. In the case that multiple valid $$$l'$$$ and $$$r'$$$ exist, output any of them.

Example
Input
7 6
abaacba
1 2
1 3
1 4
2 5
2 3
7 7
Output
4 5
5 7
0 0
0 0
3 4
5 5
Note

$$$s_{1 \dots 2} = ab$$$ and $$$s_{4 \dots 5} = ac$$$ differ by exactly $$$1$$$ element.

$$$s_{1 \dots 3} = aba$$$ and $$$s_{5 \dots 7} = cba$$$ differ by exactly $$$1$$$ element.

There exists no valid $$$l'$$$ and $$$r'$$$ that denote a substring that differs from $$$s_{1 \dots 4} = abaa$$$ by exactly $$$1$$$ element.

Problem Idea: 3366

Problem Preparation: 3366

Occurrences: Novice 12, Advanced 8