SanSi Cup 2026 Qualification round
A. Do I Know You?
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

At the door of the algorithms club lab there is an automatic greeter. Every time two names enter in a row, it greets. If the two names are equal, it is the same person who entered twice, and it greets them again. If they are different, it greets both people, in the order in which they entered.

Given the two names $$$S$$$ and $$$T$$$, in the order in which they entered, print the greeting.

Input

A single line with two names $$$S$$$ and $$$T$$$, separated by a space. Each name contains only letters of the English alphabet, uppercase or lowercase: the 26 letters, from A to Z and from a to z.

Constraints

  • Each name has between $$$1$$$ and $$$20$$$ letters of the English alphabet.
  • The first letter of each name is uppercase and the rest are lowercase.
  • Two names are equal if they have exactly the same letters in the same order.
Output

If $$$S$$$ and $$$T$$$ are equal, print Hola de nuevo, S!. If they are different, print Hola, S y T!. In both cases, replace S and T with the names.

Follow the format exactly: capitalization, spaces, the comma and the exclamation mark.

Examples
Input
Oliver Kike
Output
Hola, Oliver y Kike!
Input
Pacha Pacha
Output
Hola de nuevo, Pacha!
Input
Pollo Desquiciado
Output
Hola, Pollo y Desquiciado!
Note

Example 1. Oliver entered first and then Kike, so it greets both of them in that order.

Example 2. Pacha entered twice in a row.

B. The Accepted Streak
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

After a lot of insisting, Cindy convinced Samir to train together for the SanSi Cup. Their coach, Joaquín Morales, sent them a list of $$$n$$$ problems, and both try each one very carefully: Joaquín promised a special prize to whoever has the longest streak of Accepteds.

Each of them got one verdict per problem, in the order of the list: A (Accepted), W (Wrong Answer) or T (Time Limit Exceeded). A streak of Accepteds is a stretch of consecutive problems with verdict A.

If Cindy's longest streak is longer than Samir's, Cindy wins. If it is the other way around, Samir wins. If both have the same length, nobody gets the prize. Who wins?

Input

The first line contains an integer $$$t$$$, the number of test cases.

Each case has three lines:

  • an integer $$$n$$$, the number of problems;
  • a string of $$$n$$$ letters with Cindy's verdicts;
  • a string of $$$n$$$ letters with Samir's verdicts.

Each letter is A, W or T.

Constraints

  • $$$1 \le t \le 10$$$
  • $$$1 \le n \le 1000$$$
Output

For each case, print on one line C if Cindy wins, S if Samir wins, or F if nobody gets the prize.

Examples
Input
3
6
AAWAAA
AATAAW
4
WATA
AAWT
3
WTW
TTW
Output
C
S
F
Input
2
5
AWAWA
AATWW
5
TAAWA
AAWAA
Output
S
F
Note

Example 1. In the first case, Cindy's longest streak is the last three problems and Samir's has length $$$2$$$. In the second, Cindy has streaks of length $$$1$$$ and Samir one of length $$$2$$$. In the third, neither has any Accepted: both streaks have length $$$0$$$.

Example 2. In the first case, Cindy has three Accepteds, but none right after another, so her longest streak has length $$$1$$$. Samir's has length $$$2$$$. In the second, both longest streaks have length $$$2$$$.

C. I Love You Claude
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Mateo uses Claude for everything, even for programming. One night he dreams that he is back at university and wakes up in the middle of the second midterm of Low-Level Programming, the course that scared him the most. He reads the statement and tries to ask Claude, but back then Claude did not exist. A true nightmare!

In the first midterm Mateo got $$$X$$$. Exam grades are integers between $$$0$$$ and $$$Z$$$, inclusive. If he gets $$$N$$$ in the second midterm, his average is $$$\dfrac{X + N}{2}$$$, without rounding, and he passes the course if that average is at least $$$W$$$.

Mateo does not want to compute it by hand, so this time you will be his Claude: tell him the minimum grade $$$N$$$ he needs in the second midterm to pass.

Input

The first line contains an integer $$$t$$$, the number of test cases.

Each of the following $$$t$$$ lines contains three integers $$$X$$$, $$$W$$$ and $$$Z$$$: the grade of the first midterm, the minimum average to pass and the maximum grade of an exam.

Constraints

  • $$$1 \le t \le 1000$$$
  • $$$1 \le Z \le 100$$$
  • $$$0 \le X \le Z$$$
  • $$$1 \le W \le Z$$$
Output

For each case, print on one line the minimum grade $$$N$$$, with $$$0 \le N \le Z$$$, that lets Mateo pass. If he cannot pass even by getting $$$Z$$$, print $$$-1$$$.

Examples
Input
4
40 51 100
80 30 100
10 60 100
0 50 100
Output
62
0
-1
100
Input
3
7 5 10
0 1 1
1 1 1
Output
3
-1
1
Note

Example 1. In the first case, with $$$62$$$ the average is $$$\frac{40 + 62}{2} = 51$$$, and with $$$61$$$ it would be $$$50.5$$$. In the second, Mateo already passes even if he gets $$$0$$$, because $$$\frac{80 + 0}{2} = 40$$$. In the third, even with $$$100$$$ the average is $$$55$$$, less than $$$60$$$. In the fourth, he needs exactly the maximum grade.

Example 2. In the first case, with $$$3$$$ the average is $$$\frac{7 + 3}{2} = 5$$$. In the second, the highest possible average is $$$\frac{0 + 1}{2} = 0.5$$$, less than $$$1$$$. In the third, with $$$1$$$ the average is $$$1$$$.

D. Knights at Peace
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Niquillo el Pillo is, among all competitive programmers of Bolivia in all of history, the best, but the best at chess. Now he coaches the Agusstinos team and decides to give them a chess problem. The problem is the following:

There is an $$$n \times n$$$ chessboard. A knight attacks the squares it can jump to: two squares in one direction (horizontal or vertical) and one in the perpendicular direction, as long as they are inside the board.

What is the maximum number of knights that can be placed on the board, at most one per square, so that no knight attacks another?

Input

The first line contains an integer $$$t$$$, the number of test cases.

Each of the following $$$t$$$ lines contains an integer $$$n$$$, the size of the board.

Constraints

  • $$$1 \le t \le 1000$$$
  • $$$1 \le n \le 10^9$$$
Output

For each case, print on one line the maximum number of knights.

Example
Input
3
1
3
8
Output
1
5
32
Note

On the $$$3 \times 3$$$ board, $$$5$$$ knights can be placed: in the four corners and in the center.

E. No Geometry, No PDA
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Pacha is tired of teaching geometry to the team "Gatos Coprimos", and he knows they did not check or solve the problems he left them, so here is one more.

Test case 1: the parallelogram of the first case of the example.

Given two vectors $$$A = (x_1, y_1)$$$ and $$$B = (x_2, y_2)$$$ with origin at $$$(0, 0)$$$, compute the area of the parallelogram they form: the one with vertices $$$(0, 0)$$$, $$$A$$$, $$$A + B$$$ and $$$B$$$. If the vectors are parallel, or one of them is $$$(0, 0)$$$, the parallelogram flattens and its area is $$$0$$$.

Input

The first line contains an integer $$$t$$$, the number of test cases.

Each of the following $$$t$$$ lines contains four integers $$$x_1$$$, $$$y_1$$$, $$$x_2$$$ and $$$y_2$$$: the coordinates of $$$A$$$ and of $$$B$$$.

Constraints

  • $$$1 \le t \le 1000$$$
  • $$$-10^5 \le x_1, y_1, x_2, y_2 \le 10^5$$$
Output

For each case, print on one line the area of the parallelogram. It can be shown that it is always an integer.

Warning: the answer may not fit in a 32-bit integer.

Examples
Input
3
3 1 1 2
1 2 3 1
2 4 1 2
Output
5
5
0
Input
1
100000 100000 -100000 100000
Output
20000000000
Note

Example 1. In the first case, $$$A = (3, 1)$$$ and $$$B = (1, 2)$$$ form the parallelogram in the figure, with area $$$5$$$. In the second, the same vectors in the other order form the same parallelogram. In the third, $$$B = (1, 2)$$$ is half of $$$A = (2, 4)$$$, so both vectors lie on the same line and the area is $$$0$$$.

Example 2. In this case the coordinates are maximal, and the area is $$$2 \cdot 10^{10}$$$.

F. Felipe the Bandit
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Felipe is a bandit: he has two special lady friends and, every time he goes on a trip, he likes to bring gifts to both. But he has a favorite, and he always gives her the best gifts.

In the store there are $$$n$$$ different gifts, and the $$$i$$$-th costs $$$a_i$$$ Bs. Each gift can be bought only once. On each trip, Felipe buys like this:

  1. For the favorite he spends at most $$$X$$$ Bs. While he can afford the most expensive gift left in the store, he buys it. When he cannot afford the most expensive one left, he stops buying for her.
  2. For the second one he spends at most $$$Y$$$ Bs, among the gifts that are left. While he can afford the cheapest gift left, he buys it. When he cannot afford the cheapest one left, he stops buying for her.

Felipe makes $$$q$$$ trips. Each trip is independent: the store always starts with the $$$n$$$ gifts. For each trip, how many gifts does each of them receive?

Input

The first line contains two integers $$$n$$$ and $$$q$$$: the number of gifts and the number of trips.

The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$: the prices of the gifts.

Each of the following $$$q$$$ lines contains two integers $$$X$$$ and $$$Y$$$: what Felipe is willing to spend on the favorite and on the second one on that trip.

Constraints

  • $$$1 \le n, q \le 10^5$$$
  • $$$1 \le a_i \le 10^4$$$
  • $$$1 \le X, Y \le 10^9$$$
Output

For each trip, print on one line two integers separated by a space: the number of gifts the favorite receives and the number the second one receives.

Examples
Input
5 3
5 1 4 2 3
10 2
5 100
9 3
Output
2 1
1 4
2 2
Input
3 2
7 7 7
20 7
7 14
Output
2 1
1 2
Note

Example 1. On the first trip, Felipe buys the gifts of $$$5$$$ and $$$4$$$ Bs for the favorite and has $$$1$$$ Bs left, which is not enough for the one of $$$3$$$. For the second one, the gifts of $$$1$$$, $$$2$$$ and $$$3$$$ are left: he buys the one of $$$1$$$, and the remaining $$$1$$$ Bs is not enough for the one of $$$2$$$. On the second trip, the favorite receives the one of $$$5$$$ and he spends everything, and for the second one he buys the four that are left for $$$10$$$ Bs. On the third, the favorite receives the ones of $$$5$$$ and $$$4$$$, which add up to exactly $$$9$$$, and the second one the ones of $$$1$$$ and $$$2$$$, which add up to exactly $$$3$$$.

Example 2. On the first trip, the favorite receives two gifts of $$$7$$$ Bs, because a third one would make $$$21 \gt 20$$$, and the second one receives the one that is left.

G. Armando and the Mines
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Armando had been through a lot. He had known defeat, survived questionable decisions and learned, almost always the hard way, that not all roads lead to happiness.

After so many experiences, he decided to leave chaos behind. He meditated, found inner peace and reached a deep state of zen. Then, with the serenity of someone who finally understands the universe, he thought: "A true man cannot step on any mine."

But fate still had one last test for him: crossing the dreaded battlefield known as Parque Lincoln. Reaching enlightenment does not include knowing the exact location of the explosives: all Armando has is a map with the regions where they might be. And, true to his new philosophy, Armando never steps back: he only moves right or up.

Fictional illustration; it does not depict a real situation in the park.

Parque Lincoln is a grid of $$$H$$$ rows and $$$W$$$ columns. Cell $$$(x, y)$$$ is in column $$$x$$$, counted from left to right, and in row $$$y$$$, counted from bottom to top. The bottom-left corner is $$$(1, 1)$$$.

The map marks $$$K$$$ rectangles that do not share cells. Each rectangle has exactly one mine, in one of its $$$S$$$ cells, chosen at random: each cell has probability $$$1/S$$$, independently of the other rectangles. Outside the rectangles there are no mines.

Armando goes from $$$A = (x_A, y_A)$$$ to $$$B = (x_B, y_B)$$$, and in each step he moves from $$$(x, y)$$$ to $$$(x + 1, y)$$$ or to $$$(x, y + 1)$$$. Before leaving, without knowing where the mines are, he chooses his whole path. The number of mines of a path is the number of mines in its cells, counting $$$A$$$ and $$$B$$$.

Help Armando: what is the minimum expected value of the number of mines on his path?

Input

The first line contains three integers $$$H$$$, $$$W$$$ and $$$K$$$.

The second line contains four integers $$$x_A$$$, $$$y_A$$$, $$$x_B$$$ and $$$y_B$$$.

Each of the following $$$K$$$ lines contains four integers $$$x_1$$$, $$$y_1$$$, $$$x_2$$$ and $$$y_2$$$: the rectangle formed by the cells $$$(x, y)$$$ with $$$x_1 \le x \le x_2$$$ and $$$y_1 \le y \le y_2$$$. Its number of cells is $$$S = (x_2 - x_1 + 1)(y_2 - y_1 + 1)$$$.

Constraints

  • $$$1 \le H, W \le 1000$$$
  • $$$0 \le K \le \min(10^5, H \cdot W)$$$
  • $$$1 \le x_A \le x_B \le W$$$ and $$$1 \le y_A \le y_B \le H$$$
  • $$$1 \le x_1 \le x_2 \le W$$$ and $$$1 \le y_1 \le y_2 \le H$$$
  • $$$1 \le S \le 20$$$
  • No cell belongs to more than one rectangle.
Output

The minimum expected value is an irreducible fraction $$$a/b$$$. Print $$$a \cdot b^{-1} \bmod (10^9 + 7)$$$, where $$$b^{-1}$$$ is the integer such that $$$b \cdot b^{-1} \equiv 1 \pmod{10^9 + 7}$$$. It can be shown that it always exists.

The minimum is taken over the real values, not over their remainders modulo $$$10^9 + 7$$$.

Examples
Input
3 4 3
1 1 4 3
2 1 2 3
3 1 3 2
3 3 3 3
Output
833333340
Input
1 3 2
1 1 3 1
1 1 2 1
3 1 3 1
Output
2
Note

Example 1. The rectangles have $$$3$$$, $$$2$$$ and $$$1$$$ cells. The path $$$(1, 1) \to (2, 1) \to (3, 1) \to (4, 1) \to (4, 2) \to (4, 3)$$$ goes through one cell of the first and one of the second, and its expected value is $$$\frac{1}{3} + \frac{1}{2} = \frac{5}{6}$$$. No path has a smaller expected value. Since $$$5 \cdot 6^{-1} \bmod (10^9 + 7) = 833\,333\,340$$$, that is the answer.

Example 2. There is only one path and it goes through all the cells of both rectangles, so it has exactly $$$2$$$ mines.

H. The Sabrosso Cleaner
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Pache is in a bad mood and ordered Dilon, el Sabrosso, to clean the training area. The area is a straight hallway, which we see as a number line. Dilon starts sweeping at position $$$0$$$ and moves to the right at a constant speed of one unit per second.

Pache watches $$$N$$$ points of the hallway. Point $$$i$$$ is at position $$$x_i$$$. At each point, Pache is angry or calm: at the beginning he is angry if $$$s_i = 1$$$ and calm if $$$s_i = 0$$$.

Dilon starts at position $$$0$$$ and walks to the right. Every time he reaches a point, Pache's mood at that point decides what happens, and then that mood changes:

  • If Pache is angry, with his powers he instantly teleports Dilon to position $$$0$$$, and Dilon walks to the right again from there. Then Pache becomes calm at that point.
  • If Pache is calm, Dilon keeps walking and Pache becomes angry at that point.

Dilon finishes cleaning when he reaches position $$$x_N + 1$$$. How many seconds does it take him to get there? Since the answer can be huge, print it modulo $$$998\,244\,353$$$.

It can be shown that Dilon always finishes.

Input

The first line contains an integer $$$N$$$, the number of points.

Each of the following $$$N$$$ lines contains two integers $$$x_i$$$ and $$$s_i$$$: the position of point $$$i$$$ and Pache's initial mood at that point.

Constraints

  • $$$1 \le N \le 2 \cdot 10^5$$$
  • $$$1 \le x_1 \lt x_2 \lt \dots \lt x_N \le 10^9$$$
  • $$$s_i \in \{0, 1\}$$$
Output

Print one integer: the time, in seconds, it takes Dilon to reach position $$$x_N + 1$$$, modulo $$$998\,244\,353$$$.

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

Example 1. In the first example, Dilon passes $$$3$$$ at second $$$3$$$ (Pache becomes angry there) and reaches $$$6$$$ at second $$$6$$$, where Pache is angry and sends him back to $$$0$$$. At second $$$9$$$ he reaches $$$3$$$ again, where Pache is now angry, and goes back to $$$0$$$. Then he passes $$$3$$$ (second $$$12$$$), $$$6$$$ (second $$$15$$$) and $$$7$$$ (second $$$16$$$), leaving Pache angry at all three, and at second $$$17$$$ point $$$8$$$ sends him back to $$$0$$$. From there he still has seven more rounds before finally reaching position $$$9$$$ at second $$$57$$$.

Example 2. In the second example Pache starts calm at every point, so Dilon never starts over and reaches position $$$10$$$ at second $$$10$$$.

I. Cancelled
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

The Gossip Club 2880 was founded and its $$$n$$$ members are furious. So furious that each of them is going to try to cancel ("funar") one person of the club, chosen at random. They are so crazy that they can even cancel themselves.

Each of the $$$n$$$ members chooses whom to cancel among the $$$n$$$ members, including themselves, with the same probability for each one. Each cancel attempt has a $$$p\%$$$ probability of being effective, regardless of what happens with the others. A person ends up cancelled ("funado") if at least one cancel attempt against them is effective. If there are several cancel attempts against a person, it is more likely that they end up cancelled.

What is the probability that exactly $$$k$$$ people end up cancelled?

Input

The first line contains an integer $$$T$$$, the number of test cases.

Each of the following $$$T$$$ lines contains three integers $$$n$$$, $$$k$$$ and $$$p$$$.

Constraints

  • $$$1 \le T \le 10^5$$$
  • $$$1 \le n \le 10^5$$$
  • $$$0 \le k \le n$$$
  • $$$0 \le p \le 100$$$
  • The sum of $$$n$$$ over all cases is at most $$$10^5$$$.
Output

For each case, the probability is an irreducible fraction $$$a/b$$$. Print on one line $$$a \cdot b^{-1} \bmod (998244353)$$$, where $$$b^{-1}$$$ is the integer such that $$$b \cdot b^{-1} \equiv 1 \pmod{998244353}$$$. It can be shown that it always exists.

Examples
Input
3
1 1 50
3 2 100
2 0 50
Output
499122177
665496236
748683265
Input
2
3 1 50
4 2 30
Output
928921829
435601081