After years of experimentation, Kakashi has come up with the "square"-jutsu, a powerful technique that strikes lightning onto a large square area of land. Kakashi happens to be testing his jutsu on a mountain, which can be modeled by an $$$N \times N$$$ grid.
Each cell at row $$$1\leq i\leq N$$$ and column $$$1\leq j\leq N$$$ on the mountain has an elevation $$$c_{i, j}$$$. For every cell $$$(i,j)$$$ it is guaranteed that $$$c_{i,j} \leq \min \left(c_{i+1, j}, \space c_{i, j+1}, \space c_{i+1, j+1}\right)$$$ (treating cells outside the $$$N\times N$$$ grid as having infinite elevation). It is also guaranteed that $$$c_{1, 1} = 0$$$.
Kakashi's jutsu is powerful, but limited: square-jutsu can strike any $$$k\times k$$$ square block of mountain cells, but only if the entire $$$k\times k$$$ block lies within the bounds of the mountain grid and only if every cell in the block has elevation within a certain range $$$[a, b]$$$ inclusive ($$$a \leq c_{i, j} \leq b$$$ for all cells $$$(i,j)$$$ in the target square). Given the elevation of every mountain cell and the elevation range allowed by his jutsu, Kakashi wants to know the number of cells in the largest possible square block his jutsu can hit.
The first line of input contains 2 integers $$$N$$$ and $$$Q$$$ ($$$1 \leq N \leq 300, \space 1 \leq Q \leq 10^4$$$), the size of the grid and the number of test cases, respectively. Each test case uses the same mountain grid.
The next $$$N$$$ lines each contain $$$N$$$ space-separated integers. The $$$j$$$-th integer on the $$$i$$$-th line represents the elevation $$$c_{i, j}$$$ ($$$0 \leq c_{i, j} \leq N^2$$$).
The next $$$Q$$$ lines each specify one test case, and contain two space-separated integers $$$a$$$ and $$$b$$$ ($$$0 \leq a \leq b \lt N^2$$$), the minimum and maximum elevation that Kakashi's square-jutsu can hit.
For each test case, print a line with one integer: the number of mountain cells in the largest square block of land that Kakashi's square-jutsu can strike. For each test case it is guaranteed that Kakashi can target at least one cell.
5 5 0 1 2 3 4 0 1 2 4 4 0 2 3 5 6 1 3 3 5 6 1 4 4 6 7 6 7 4 4 0 6 3 4 5 7
1 1 16 4 4
10 5 0 0 0 0 0 0 1 2 3 3 1 1 1 1 1 1 2 2 3 4 1 2 2 2 2 2 3 3 3 4 2 2 2 2 2 2 3 3 3 5 2 2 2 3 3 3 3 3 3 6 3 3 3 3 3 3 4 5 5 7 4 4 4 4 5 5 6 6 6 7 4 4 5 5 5 5 7 7 7 8 5 5 6 6 6 6 8 8 9 9 5 5 6 6 6 6 8 8 10 11 4 6 2 3 3 11 3 6 2 5
16 16 36 25 25
4 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 15
16
Angels are surprisingly violent, and love beating up one another! This has lead to lots of conflict in the angel world that you have decided to fix.
To do this, each group sends one of its angels to help defend. Every angel has a combat power $$$p$$$, and the combat power of the defense is the sum of combat powers of the $$$n$$$ angels sent by the groups. However, angel combat is complicated, and it requires perfect technique. In order to successfully defend against an attack of power $$$t$$$, the lowest $$$m$$$ bits of the defense's combat power must match the lowest $$$m$$$ bits of $$$t$$$. (Note that the defense's power need not be larger than that of the attacker's power.)
As the leader of the angels, you must figure out how to successfully defend against all attacks, even as angels join and leave the various groups. Hurry, you don't have much time left before the first attack!
The first line contains two integers $$$n, m$$$ ($$$1 \leq n \leq 100, 1 \leq m \leq 16$$$). $$$n$$$ denotes the number of groups, and $$$m$$$ represents the number of bits used to determine which group wins.
The next $$$n$$$ lines begin with an integer $$$k$$$ ($$$1 \leq k \leq 10^3$$$), denoting the initial size of the group. Then, $$$k$$$ integers follow on that line, denoting the combat powers of the angels in the group. Combat powers are positive integers that do not exceed $$$2^m$$$.
Next, there is a line containing a single integer $$$q$$$ ($$$1 \leq q \leq 100$$$), representing the number of events that follow.
The last $$$q$$$ lines each represent an event. Each event has one of the following formats:
For each attack, output the number of ways to successfully defend against it, mod $$$998244353$$$. There will always be at least one attack.
4 3 4 1 2 3 4 1 5 3 2 2 3 2 6 7 10 ? 1 ? 3 ? 6 - 3 2 ? 1 + 2 4 ? 1 - 2 4 - 2 5 ? 2
6 1 2 4 7 0
For each of the attacks, the following sets of angels would work. Note that some are listed multiple times, since there are multiple angels with the same power level.
In Attack on Titans, humanity lives in fear of giant humanoid creatures called Titans. In order to defend themselves, the humans built three walls: Wall Maria, Wall Rose, and Wall Sina. Wall Maria is made up of $$$n$$$ separate sections, with the $$$i$$$th section having height $$$m_i$$$. Wall Rose and Wall Sina also have $$$n$$$ sections each, with heights $$$r_i$$$ and $$$s_i$$$ respectively.
Find the tallest section height common to all three walls: the maximum value of $$$h$$$ with $$$h = m_i = r_j = s_k$$$ for some indices $$$1 \leq i,j,k \leq n$$$. Note that for a height $$$h$$$ to be common to all three walls, each wall must have a section of height $$$h$$$, but these sections are not required to be at the same position on all three walls.
The first line of the input contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$), the number of sections in each wall. The second, third, and fourth lines each contain $$$n$$$ space-separated integers: the second line lists the heights $$$m_i$$$ of the sections in Wall Maria, the third the heights $$$r_i$$$, and the fourth the $$$s_i$$$. Each height satisfies ($$$1 \leq m_i, r_i, s_i \leq 10^5$$$).
Print a single integer: the tallest section height common to all three walls. If there is no section height common to all three walls, print $$$-1$$$ instead.
5 1 2 3 8 5 5 6 7 8 9 8 12 14 19 12
8
To determine the fate of Immanity, Sora and Shiro are playing yet another game, this time against the flügel Azriel!
They are given a string $$$s$$$ of length $$$N$$$ consisting only of lowercase and uppercase English ASCII letters. They are also given a list $$$a$$$ of $$$N$$$ integers, each in the range $$$1 \leq a_i \leq 100$$$.
Azriel carefully constructs $$$M$$$ (not necessarily distinct) strings, also consisting only of lowercase and uppercase English ASCII letters.
Sora and Shiro then choose a (possibly empty) subset of lowercase and uppercase letters. Let's denote this set $$$S$$$.
Azriel's score $$$k$$$ is calculated through the following process:
Since Shiro and Sora must beat Azriel for the sake of Immanity, they must choose a subset of characters $$$S$$$ that minimizes Azriel's score. Help them by finding the minimum possible value of Azriel's final score, and also print a string $$$t$$$ which produces this score.
The first line of input consists of two integers $$$N$$$ and $$$M$$$ ($$$1 \leq N \leq 10^5$$$, $$$1 \leq M \leq 30$$$).
The next line contains the string $$$s$$$, which consists of $$$N$$$ characters from the set $$$\{\texttt{a}-\texttt{z},\texttt{A}-\texttt{Z}\}$$$.
The next line contains $$$N$$$ space-separated integers $$$a_i$$$ ($$$1 \leq a_i \leq 100$$$).
The last $$$M$$$ lines each contain a string $$$r_i$$$ and an integer $$$c_i$$$ ($$$1 \leq c_i \leq 100$$$), separated by a space. Each $$$r_i$$$ consists of characters from the set $$$\{\texttt{a}-\texttt{z},\texttt{A}-\texttt{Z}\}$$$, and has length $$$1 \leq |r_i| \leq \min(N, 10^4)$$$.
Print two lines of output. On the first line, print an integer: Azriel's minimum possible score over all choices of characters $$$S$$$ to replace.
On the second line, print the string $$$t$$$ that achieves this minimum possible score. If there are multiple possible such strings, print any one of them.
5 4 abcdb 1 1 2 2 3 b 2 b 3 bc 1 ab 3
-8 ab..b
In the sample input, the optimal choice of $$$S$$$ is $$$S=\{\texttt{c},\texttt{d}\}$$$. With this choice, Azriel gets a score of $$$1+1+3$$$ from the non-dot letters that remain in $$$t$$$. Since $$$\texttt{b}$$$ appears twice and $$$\texttt{ab}$$$ appears once in $$$t$$$, his final score is thus $$$1+1+3-2\cdot2-2\cdot3-1\cdot3 = -8$$$.
Saitama, the One-Punch Man, is on a mission to defeat a group of monsters in order to challenge the monster boss, Centichoro. The power level of each of the $$$i$$$ monsters is stored in an array, where $$$p_i$$$ denotes the power level of the monster at index $$$i.$$$ Saitama's goal is to defeat the most powerful group of monsters by finding the maximum sum of any contiguous subarray of monster strengths. If he does so, he will be able to fight against Centichoro to save humanity. Help Saitama calculate the sum of the power levels of the corresponding subarray!
Note: The subarray of $$$a$$$ is $$$a$$$ contiguous part of the array $$$a$$$, i.e. the array $$$a_i,a_{i+1}...,a_j$$$ for some $$$1 \leq i \leq j \leq n$$$.
The first line contains a single integer, ($$$1 \leq n \leq 10^5$$$), denoting the number of monsters. The following line will contain $$$n$$$ integers denoting the power levels $$$p_i$$$ ($$$-10^9 \leq p_i \leq 10^9$$$) of each of the $$$n$$$ monsters in order.
Output a single integer representing the sum of the power levels in the maximum subarray.
9 -2 10 -3 5 -2 1 2 6 -1
19
In the sample case, the contiguous subarray with the maximum sum is $$$[10, -3, 5, -2, 1, 2, 6]$$$, which has a sum of $$$19$$$. Therefore, Saitama needs to defeat this set of monsters to achieve his goal of challenging Centichoro.
By the wind storm's blast
From Mimuro's mountain slopes
Maples leaves are torn,
Which turn Tatsuta River
Into a rich brocade.
—
Chihaya and Taichi are playing a game of Karuta. During one round, they heard the song related to the poem above, and they remembered the following problem. Please help them solve it so they can continue playing!
A category-$$$k$$$ storm is coming and will blow the leaves off of a nearby tree. During the storm, the wind speed will vary: at time $$$t$$$ seconds after the storm begins, the wind speed is $$$w_t = a_t + k \cdot d_t$$$ units per second, for some time-varying additive and multiplicative base speeds $$$a_t$$$ and $$$d_t$$$.
There are $$$n$$$ leaves attached to a tree. The $$$i$$$th leaf starts at position $$$(0, y_i)$$$ and detaches from the tree at time $$$\ell_i$$$. In between times $$$t$$$ and $$$t+1$$$, any leaf that detached from the tree at time $$$t$$$ or earlier and hasn't yet hit the ground (at $$$y=0$$$) travels 1 unit down and $$$w_t$$$ units to the right; i.e. a leaf at position $$$(x,y)$$$ moves to $$$(x+w_t, y-1)$$$. Leaves that hit the ground never move again.
After the storm, you will need to rake up all the leaves, and need to know the farthest distance along the $$$x$$$-axis that any leaf will hit the ground. You might learn more accurate information about the storm in the future, and will need to recompute this farthest distance if $$$k$$$, $$$a_t$$$, or $$$d_t$$$ change.
The first line of the input contains three space-separated integers $$$n$$$, $$$m$$$, and $$$q$$$ ($$$1 \leq n, m \leq 10^4$$$, $$$1 \leq q \leq 10^5$$$): the number of leaves, maximum height of the tree, and the number of weather updates, respectively.
The next line contains $$$n + m - 1$$$ space-separated integers $$$a_t$$$ ($$$1 \leq a_t \leq 10^6$$$), the additive component of wind speed at each second $$$t$$$.
The next line contains $$$n + m - 1$$$ space-separated integers $$$d_t$$$ ($$$1 \leq d_t \leq 10^6$$$), the multiplicative component of wind speed at each second $$$t$$$.
Each of the next $$$n$$$ lines contains two space-separated integers $$$\ell_i$$$ and $$$y_i$$$ ($$$1 \leq \ell_i \leq n, 1 \leq y_i \leq m$$$) and specifies a leaf on the tree that begins at $$$(0,y_i)$$$ and detached from the tree at second $$$\ell_i$$$.
The next $$$q$$$ lines contain the weather updates. Each update takes one of the following three forms:
It is guaranteed that there is at least one update of the first type.
Print one line for each update to the storm category $$$k$$$. On each line, print one integer: the maximum horizontal distance a leaf hits the ground given the information in the weather updates so far.
3 5 6 1 1 1 1 2 3 4 8 1 1 1 1 1 1 1 3 2 1 3 5 1 0 1 2 2 3 1 3 3 2 1 1 1 2
11 23 17 25
Sophie has found herself trapped inside Howl's Moving Castle!
Howl's Moving Castle can be represented as a connected graph of $$$N$$$ rooms and $$$N-1$$$ (bidirectional) hallways connecting rooms. However, this isn't just any old castle – this is Howl's Moving Castle. Every morning, the castle comes to life, and the rooms shift such that some of the hallways become inaccessible, disconnecting the rooms adjacent to the hallways. This creates a distinct partition of rooms – a grouping of rooms into non-empty subsets such that each room is in exactly one subset, each subset forms a connected graph, and the subsets are disconnected from each other.
Sophie has a set of possible tasks (reload the trebuchets, feed the alligators in the moat, empty the chamber pot, etc.), which requires moving between two rooms. Specifically, for the $$$t$$$th task, Sophie starts at room $$$a_t$$$, and needs the path to the second room $$$b_t$$$ to be unobstructed.
How many possible partitions of Howl's Moving Castle are there such that every task can be completed?
You can assume that Sophie can teleport between tasks, i.e. teleport from room $$$b_t$$$ to room $$$a_{t+1}$$$.
The first line contains two integers $$$N$$$, $$$T$$$ ($$$1 \le N \le 10^5$$$, $$$1 \le T \le 10^5$$$) denoting the number of rooms in the castle and the number of tasks, respectively.
The next $$$N-1$$$ lines contain two integers $$$u_i, v_i$$$ each, which means that there is a hallway connecting room $$$u_i$$$ to room $$$v_i$$$. ($$$1 \le u_i, v_i \le N, u_i \neq v_i$$$)
The final $$$T$$$ lines contain two integers $$$a_t, b_t$$$ each, which means that the $$$t$$$th task requires an unobstructed path between room $$$a_t$$$ and room $$$b_t$$$. ($$$1 \le a_t, b_t \le N$$$)
Output a single integer, the number of possible partitions of the castle (created by obstructing some hallways) such that every task can be completed. Because this number can be large, output it modulo $$$10^9 + 7$$$.
6 2 1 2 1 3 3 4 3 5 5 6 2 3 5 6
4
In the sample test case, there are four possible partitions:
Tyson is up to his beyblading ways again. In a beyblade battle, two players launch their beyblades (small spinning tops) into an arena to battle each other until one stops spinning.
This time, Tyson is up against a particularly defensive opponent, and needs to determine how close his beyblade can get to his opponent's since his own beyblade is equipped with a ranged attack. However, his opponent's beyblade has two defensive walls set up that try to keep other beyblades away.
Tyson has done some preliminary calculations and determined that the arena can be modeled as the $$$2D$$$ plane with the opponent's beyblade at the origin. The walls protecting the opponent's beyblade are both infinite lines that pass through the origin (forming an X-shape with the origin at the crossing). The first wall makes an angle of $$$\alpha$$$ degrees measured counterclockwise from the positive $$$x$$$-axis, and the second wall makes an angle of $$$\beta$$$ degrees (also measured counterclockwise from the positive $$$x$$$-axis). Tyson's beyblade begins at location $$$(p_x, p_y)$$$, and Tyson launches it at an angle of $$$\theta$$$ degrees (measured counterclockwise with respect to the vector extending from $$$(p_x,p_y)$$$ in the positive $$$x$$$ direction). When the beyblade collides with either wall, it reflects off the wall perfectly with angle of incidence equal to the angle of reflection, much like light bounces off of a mirror. Assuming that Tyson's beyblade keeps traveling for infinite time, what is the closest distance it will get to his opponent's beyblade, and how many total times will it bounce off of a wall?
It is guaranteed that $$$0 \leq \alpha \lt \beta \lt 180$$$, $$$\beta - \alpha \gt 10^{-2}, 180 - (\beta - \alpha) \gt 10^{-2}$$$, and that Tyson's beyblade starts at least distance $$$10^{-2}$$$ away from either wall. Furthermore, the minimum distance between Tyson's beyblade and the origin along its path of motion is at least $$$10^{-6}$$$ units.
The first line contains two space-separated fixed-point real numbers, $$$\alpha$$$ and $$$\beta$$$, such that $$$0 \le \alpha \lt \beta \lt 180$$$. It is guaranteed that $$$\beta - \alpha \gt 10^{-2}$$$ and $$$180 - (\beta - \alpha) \gt 10^{-2}$$$.
The second line contains two space-separated integers $$$p_x$$$ and $$$p_y$$$ $$$(-10^5 \le p_x, p_y, \le 10^5)$$$.
The third line contains one fixed-point real number $$$\theta$$$ $$$(0 \le \theta \lt 360)$$$.
All fixed-point real numbers $$$\alpha$$$, $$$\beta$$$, and $$$\theta$$$ have exactly five digits after their decimal points and will not be in scientific notation.
Print a real number and an integer, separated by a space: the closest distance Tyson's beyblade reaches to the origin along its trajectory, and the total number of times the beyblade bounces off of a wall. Your answer will be judged correct if the distance differs from the judge solution by an absolute or relative error of at most $$$10^{-6}$$$.
0.00000 90.00000 1 1 45.00000
1.414214 0
45.00000 90.00000 2 3 270.00000
2.000000 3
Umaru's older brother Taihei is off to work again, which means it is time for her to sit back, relax, play some video games, and enjoy delicious snacks including potato chips and cola. Taihei has been trying to teach Umaru the importance of sharing, so to put this into practice, she will be buying bags of chips to distribute to her friends.
The town Umaru lives in can be modeled as a set of $$$N$$$ houses and $$$N - 1$$$ roads such that there is a unique simple (no edges or nodes reused) path between any two houses. Additionally, Umaru has $$$a_i$$$ friends that live in the $$$i$$$-th house. Taihei will be gone for $$$Q$$$ hours, so Umaru plans to go on at most $$$Q$$$ "snack runs". At the $$$i$$$-th point in time (for each $$$i$$$ at most $$$Q$$$), one of two things may happen. The first possibility is that Umaru will go on a snack run. If so, Umaru travels from house $$$u_i$$$ to house $$$v_i$$$ and gives snacks to her friends along the way. If not, she tells her friends to gather at a particular house $$$w_i$$$, in which case the number of friends that live at house $$$w_i$$$ becomes multiplied by a factor of $$$f_i$$$ (these friends come from out of town, friends never leave their houses).
Umaru is having trouble figuring out how many snacks to bring with her on each snack run. Being lazy, she wants to bring the smallest positive integer number of snacks that will be evenly divisible by the number of people in each of the houses that she visits along the way (including her starting city and destination). Given information regarding each of her snack runs, can you help her figure out how many snacks to bring?
The input will begin with two integers, $$$N$$$ and $$$Q$$$ ($$$1 \leq N, Q \leq 10^3$$$), the number of houses and the number of snack runs, respectively.
The next line will contain $$$N$$$ integers, the $$$i$$$-th of which represents $$$a_i$$$ ($$$1 \leq a_i \leq 10^7$$$), the number of friends of Umaru who live in the $$$i$$$-th house.
The $$$i$$$-th of each of the next $$$N - 1$$$ lines will each contain two integers, $$$u_i$$$ and $$$v_i$$$ ($$$1 \leq u_i, v_i, \leq N, u_i \neq v_i$$$), meaning that houses $$$u_i$$$ and $$$v_i$$$ are connected by a (bidirectional) road.
The $$$i$$$th of each of the final $$$Q$$$ lines will each contain three integers, either a 1 followed by $$$u_i$$$ and $$$v_i$$$ ($$$1 \leq u_i, v_i \leq N$$$), denoting that the $$$i$$$-th snack run is between houses $$$u_i$$$ and $$$v_i$$$, or a 2 followed by $$$w_i$$$ and $$$f_i$$$ ($$$1 \leq w_i \leq N, 1 \leq f_i \leq 10^7$$$), denoting that Umaru calls friends to gather at house $$$w_i$$$ (the number of friends at house $$$w_i$$$ increases by a factor of $$$f_i$$$). It is guaranteed that there will be at least one snack run in the input.
The output should consist of as many lines as there are snack runs, the $$$i$$$-th of which denotes the minimum positive integer number of snacks that Umaru can bring from house $$$u_i$$$ to $$$v_i$$$ such that the number of snacks is divisible by the number of people living in each of the houses in the unique simple path from house $$$u_i$$$ to house $$$v_i$$$. Note that, since the answers may be quite large, print them modulo $$$10^9+7$$$.
6 3 1 6 5 3 4 3 1 2 1 3 1 4 2 5 4 6 1 1 5 2 2 4 1 1 2
12 24
For the first snack run, the houses along the way are 1, 2, and 5 which house 1, 6, and 4 people, respectively. The smallest positive integer which is divisible by 1, 6, and 4 is 12.
For the second point in time, the number of friends that live at house 2 is multiplied by a factor of 4, so now 24 friends of Umaru's live at house 2.
For the secondsnack run, the houses along the way are 1 and 2 which house 1 and 24 people, respectively. The smallest positive integer which is divisible by 1 and 24 is 24.
Light Yagami is once again playing games with the detective L. This time, L has invited Light to a fancy restaurant and has brought 3 piles of canned potato chips to the table; unknowingly, this happens to be one of Light's favorite snacks. While waiting for their order, the detective offers a game: Light and L will alternate between taking chips, where each person can take some number of chips $$$1 \leq c_i \leq p_i$$$ from one of the piles i (where $$$p_i$$$ is the number of chips in pile i), or take some number of chips $$$1 \leq c_i \leq \min\{p_i\}$$$ (where $$$\min\{p_i\}$$$ is the minimum amount of chips across all piles) from all three of the piles. Being a gentleman, L offers Light to go first. Is it possible for Light to take the last chip if both play optimally?
The input consists of three integers $$$0 \leq a,b,c \leq 50$$$, denoting the number of chips in each pile.
Please output, in one line, the case-insensitive characters "Yes" if Light can take the last chip or "No" if he cannot.
0 0 0
No
0 0 1
Yes
1 2 3
No
It's Fantastic Friday, so Izuku Midoriya goes to the local anime trading card dealership to explore the latest releases. He is currently trying to collect the entire "Plus Ultra" card set of anime characters. Unfortunately for him, he does not know how many characters are in this set. He does, however, see that each character has a unique "quirk number."
He has brought his own collection containing $$$N$$$ cards, some of which may be duplicates. His goal is to collect one of each character in a contiguous run of quirk numbers starting at $$$1$$$. More formally, he would like to collect exactly one card each with quirk number $$$1, 2, 3, \ldots K$$$ for some positive integer $$$K$$$. He does not want any duplicates or any extra character cards whose quirk numbers are not part of the contiguous run: this would ruin the collection.
Midoriya cannot bring himself to simply throw a card away; however the card dealership will allow him to trade in any character card he owns for any other card of his choice for $$$A$$$ yen. Midoriya can also buy any character card of his choice outright for $$$B$$$ yen. (It's possible that $$$A \gt B$$$: the card dealer loves anime, but may not be great at economics.) The shop has an unlimited supply of cards of every quirk number. In order to satisfy his wish of possessing a contiguous run of quirk numbers, what is the minimum amount of money Izuku Midoriya needs to spend?
The first line contains three space-separated integers $$$N$$$, $$$A$$$, and $$$B$$$ $$$(1 \leq N, A, B \leq 10^5)$$$.
The second line contains $$$N$$$ space-separated integers $$$c_i$$$ $$$(1 \leq c_i \leq 10^6)$$$, the quirk numbers of the cards that Midoriya already owns. Note that this list could contain duplicate quirk numbers.
Print a single integer: the minimum amount of yen Izuku Midoriya needs to pay so that the quirk numbers in his collection form a contiguous run $$$1, 2, \ldots, K$$$ for some $$$K$$$.
5 3 5 1 7 5 10 5
9
4 100 5 1 7 5 10
30
4 100 5 1 7 5 1000
115
In the first test case, he can trade in the card with quirk number $$$7$$$ for a new card with quirk number $$$2$$$; similarly he can trade $$$5$$$ for $$$3$$$ and $$$10$$$ for $$$4$$$. In this way he will have cards with quirk numbers $$$1$$$, $$$2$$$, $$$3$$$, $$$4$$$, and $$$5$$$. These trades cost him $$$3*3 = 9$$$ yen.
In the second test case, he can buy all of the cards with quirk numbers $$$1$$$–$$$10$$$, excluding $$$1$$$, $$$5$$$, $$$7$$$, and $$$10$$$ which he already owns. This costs him $$$6*5 = 30$$$ yen.
In the third test case, he can trade in the card with quirk number $$$1000$$$ for quirk number $$$6$$$ and then buy the characters with quirk numbers $$$2$$$, $$$3$$$, and $$$4$$$. This costs him a total of $$$100+5*3 = 115$$$ yen.
My Hero Academia (you) has taken a break from saving my grades and has now decided to help me with my burgeoning photography hobby. I have taken an image with my camera, but there are a few problems with it. Please help me fix it.
Specifically, I will provide you with my image, represented as a matrix of $$$n \times m$$$ integers. The edges of the matrix "loop around", meaning that the left-most column is considered adjacent to the right-most column, and the top-most row is considered adjacent to the bottom-most row. To fully process the image, we will apply $$$k$$$ transformations sequentially on the image. These transformations will be of the following form (where +x is to the right, +y is up):
Given the image and a list of $$$k$$$ operations, please be My Hero Photographia and provide me with the final image.
The first line of input contains two integers $$$n$$$ and $$$m$$$ $$$(3 \leq n, m \leq 100)$$$, the dimensions of the image. The following $$$n$$$ lines contain $$$m$$$ integers each (between $$$0$$$ and $$$100$$$ inclusive), representing the image.
The next line of input contains a single integer $$$k$$$ $$$(1 \leq k \leq 1000)$$$, the number of operations to be performed on the image. The following $$$k$$$ lines each contain a single operation to be performed on the image. Each operation is one of the following:
After performing all operations, output the resulting image.
The image should be formatted as $$$n$$$ lines, each containing $$$m$$$ integers separated by spaces, or $$$m$$$ lines, each containing $$$n$$$ integers separated by spaces (depending on the rotation of the image.
4 5 3 3 3 10 16 3 3 3 12 38 3 3 3 40 4 5 6 7 8 9 1 Blur
9 4 6 11 11 8 3 8 14 14 8 4 9 13 13 5 4 9 11 10
3 3 1 2 3 4 5 6 7 8 9 1 Shift 0 1
4 5 6 7 8 9 1 2 3
3 3 1 2 3 4 5 6 7 8 9 1 Sharpen
-99 2 3 4 5 6 7 8 109
3 4 1 2 3 4 5 6 7 8 9 10 11 12 2 Rotate CW Flip Horizontal
1 5 9 2 6 10 3 7 11 4 8 12
In Attack on Titan, Titans are a constant threat to humanity. These giant humanoid creatures can cause significant destruction and loss of life, and identifying them is crucial to protect civilians and defend against them.
In this fictional world, there are two primary nations, Marley and Paradis, and a number of small unnamed nations.
A long, long time ago, there were $$$N$$$ humans with the power of the Titans (initially all from different, small unnamed nations). As history progressed, smaller nations inevitably merged into the larger two nations, and many titan-transformers from the smaller nations were forced to join either Marley or Paradis.
As a historian, you are trying to recover some information about the battles between the nations, and the ultimate fates of each titan-transformer. You've collected a list of $$$Q$$$ historical records and sorted them in decreasing order of credibility. Each of the $$$Q$$$ statements describe a battle between Marley and Paradis and takes one of two forms:
Process each historical record in order. For each record $$$q_i$$$, if the information in that record contradicts facts derivable from previous records, print IMPOSSIBLE. Record $$$q_i$$$ is then discredited as potentially fake and you should ignore its information when considering all future records.
If $$$q_i$$$ does not contradict previous records, print the maximum number of titan-transformers that a single nation could have, based on the records you've processed so far. Also print the maximum number of different nations (including Marley and Paradis) that could harbor at least one of the $$$N$$$ Titans based on the records so far.
Important: a historical record might specify a battle involving the same Titan twice, where $$$a=b$$$. A record of the form 1 a a that specifies a Titan joined a different nation than themselves is a self-contradiction and automatically discredited.
The first line contains two space-separated integers $$$N$$$ and $$$Q$$$ $$$(1\leq N, Q\leq 10^5).$$$ Each of the next $$$Q$$$ lines contains information about one historical battle. The $$$i$$$th such line contains three space-separated integers $$$t_i$$$, $$$a_i$$$, and $$$b_i$$$ describing the historical record $$$q_i$$$: the type of record $$$t_i\in\{0,1\}$$$, and the two Titans involved in the battle $$$1 \leq a_i, b_i \leq N$$$. It is possible that $$$a_i = b_i$$$.
For each record $$$q_i$$$, print one line of output. If $$$q_i$$$ contradicts facts derivable from earlier (non-discredited) records or is a self-contradiction, print $$$\texttt{IMPOSSIBLE}$$$. Otherwise, print two integers: the maximum possible number of Titans that a single nation could have based on records so far, and the maximum number of nations that could have at least one Titan based on the records so far.
4 4 0 1 2 1 2 3 1 1 2 0 3 4
2 3 2 3 IMPOSSIBLE 2 2
4 3 1 1 2 1 2 3 1 3 1
1 4 2 3 IMPOSSIBLE
Misaka has recently discovered the existence of one-way magical portals that allow quick travel between cities in Japan. She wants to investigate these portals, but she is too busy fighting the Russian military, the Russian Orthodox Church, and the Roman Catholic Church. Thankfully, she can command a network of clones of herself who can investigate the portals in her stead.
The first line contains $$$n$$$ ($$$2\leq n \leq 5\times 10^4$$$), the number of cities, and $$$m$$$ ($$$1\leq m \leq 5\times 10^4$$$), the number of portals. The next $$$m$$$ lines contain two numbers, $$$a$$$ and $$$b$$$ ($$$1\leq a,b \leq n$$$), representing a one-way portal from city $$$a$$$ to city $$$b$$$. Note that there can be multiple portals between two cities, but a portal must be between two different cities ($$$a \neq b$$$).
On the first line, print out the maximum number of portals that can be investigated. On the second line, print out the minimum number of clones required to investigate the maximum number of portals that can be investigated.
18 27 1 2 1 2 2 1 1 7 1 8 3 4 4 3 3 8 5 6 6 5 6 8 15 16 16 15 16 8 7 9 8 10 8 12 8 14 8 17 9 10 10 9 11 12 12 11 13 14 14 13 17 18 18 17
17 6
6 2 1 2 3 4
0 0