It's the first day of summer vacation and school hasn't come along yet to end it! This time, Dr. Doofenshmirtz is up to something again, and it's up to Perry the Platypus to stop him. To get to the mad doctor's lair, Agent P needs to unlock a door that's keeping him captive.
The good news is that Agent P managed to make an imprint of a key and duplicate it. The bad news is that he doesn't know if the key he has matches the lock that's on the door.
The Flynn-Fletcher household has a total of five different locks and five different keys. The keys are numbered #1 to #5. The locks are numbered #1 to #5. In particular:
Perry has a copy of key $$$k$$$, and the door is locked by lock $$$L$$$. Output "GOOD LUCK AGENT P" if Perry can open the lock. Otherwise, output "CURSE YOU" if he can't open the lock.
Each test case contains two lines. The first line contains the integer $$$k$$$, while the second line contains the integer $$$L$$$.
Constraints
$$$1 \le k \le 5$$$
$$$1 \le L \le 5$$$
Note: In general, the constraints for each problem are guaranteed. You don't have to check them yourself; you may assume that they are always true.
Output a single line containing one of the following strings:
1 4
CURSE YOU
2 3
GOOD LUCK AGENT P
3 1
CURSE YOU
1 2
GOOD LUCK AGENT P
1 5
CURSE YOU
104 days of summer vacation and school comes along just to end it! For the rest of summer vacation, Dr. Doofenshmirtz will occasionally be doing things to take over the Greater Tri-State Area and Perry the Platypus has to stop him.
The good news is that Agent P has managed to make an imprint of a set of keys and duplicate all of them. The bad news is that each day, Perry will be locked inside a different room with a different lock. And the set of keys he has might not have a correct key to open the lock on some days.
There are a total of 104 different locks, one for each day of summer vacation, and there are 104 different keys. As before, each key can open a lock if the difference between their numbers is exactly one. To be more explicit:
You will be given the set of keys that Perry the Platypus has as well as the lock numbers on the days that Dr. Doofenshmirtz will be active.
Output how many days Perry can successfully stop the mad doctor.
Each test case consists of four lines.
The first line contains an integer $$$k$$$, the number of keys that Perry has.
The second line contains $$$k$$$ space-separated integers representing each key $$$k_i$$$.
The third line contains an integer $$$L$$$, the number of locks.
The fourth line contains $$$L$$$ space-separated integers, representing each lock $$$L_i$$$.
Constraints
$$$1 \le k \le 104$$$
$$$1 \le k_i \le 104$$$
$$$1 \le L \le 104$$$
$$$1 \le L_i \le 104$$$
No two $$$k_i$$$s are the same.
No two $$$L_i$$$s are the same.
Output a single integer, the number of days that Perry can successfully stop Dr. Doofenshmirtz.
5 2 4 6 8 10 3 1 5 102
2
Dr. Doofenshmirtz did something to the space-time continuum.
Now there are one billion days, one billion locks, and one billion keys. This is the type of thing that only happens in cartoons and math problems!!
1,000,000,000 days of summer vacation and school comes along just to end it! For the rest of summer vacation, Dr. Doofenshmirtz will occasionally be doing things to take over the Greater Tri-State Area and Perry the Platypus has to stop him.
The good news is that Agent P has managed to make an imprint of a set of keys and duplicate all of them. The bad news is that each day, Perry will be locked inside a different room with a different lock. And the set of keys he has might not have a correct key to open the lock on some days.
There are a total of 1,000,000,000 different locks, one for each day of summer vacation, and there are 1,000,000,000 different keys. As before, each key can open a lock if the difference between their numbers is exactly one. To be more explicit:
You will be given the set of keys that Perry the Platypus has as well as the lock numbers on the days that Dr. Doofenshmirtz will be active.
Output how many days Perry can successfully stop the mad doctor.
Each test case consists of four lines.
The first line contains an integer $$$k$$$, the number of keys that Perry has.
The second line contains $$$k$$$ space-separated integers representing each key $$$k_i$$$.
The third line contains an integer $$$L$$$, the number of locks.
The fourth line contains $$$L$$$ space-separated integers, representing each lock $$$L_i$$$.
Constraints
$$$1 \le k \le 10^5$$$
$$$1 \le k_i \le 10^9$$$
$$$1 \le L \le 10^5$$$
$$$1 \le L_i \le 10^9$$$
No two $$$k_i$$$s are the same.
No two $$$L_i$$$s are the same.
Output a single integer, the number of days that Perry can successfully stop Dr. Doofenshmirtz.
5 2 4 6 8 10 3 1 5 102
2
It's a new year, and there are still firecrackers every now and then. With those loud sounds as cover, you decided to use this time to test your new spy equipment!
Even spies have New Year's Resolutions. In the past year, you've spent a decent amount of your downtime playing Bomberman. Well, this year you've decided to increase your skill in handling actual explosives—not for games, but for professional use only!
And so we look at the explosives that you have, which you got from the Armory of Clingy Molotovs.
You have $$$n$$$ explosives, and you arrange them in a line. As they are clingy, they have to be with their fellow molotovs in order to detonate. Specifically, a clingy molotov will detonate and explode if and only if there is at least one clingy molotov to its left, and at least one clingy molotov to its right.
Each molotov has an Explosion Rating $$$E_i$$$, which is proportional to the amount of damage that it can cause. Now, what is the total Explosion Rating of all the clingy molotovs that will explode?
The input starts with a line containing an integer $$$n$$$, the number of explosives. The second line contains $$$n$$$ integers, $$$E_1, E_2, \ldots, E_n$$$, denoting the explosion rating of each of the clingy molotoves from left to right.
Constraints
$$$1 \leq n \leq 100$$$
$$$0 \leq E_i \leq 1000$$$
Output, in a single line, a single integer denoting the total Explosion Rating of all the clingy molotovs that will explode.
6 1 3 5 2 3 10
13
2 5 10
0
Some agents attack with knives, others use only their bare fists. Several use guns of some sort, from small pistols to long range rifles. Then there are those who use very flashy explosions.
You smirk to yourself as you think of those guys. "They could hardly call themselves Agents of Covert Missions."
As for you, you pride yourself in using herbs—special plants that you grow yourself. These plants of yours produce potent leaves which could be turned into powder and pills for different uses: causing paralysis, inducing sleep, and extracting the truth from people.
Unfortunately, the Center for Interior Architecture wasn't that meticulous when designing your headquarters. You have many plants of differing weights, but the area where you are growing your plants can only handle up to a maximum weight $$$w$$$. Will you be able to grow all of your plants?
The first line of input contains a single integer $$$t$$$ denoting the number of test cases.
Each test case is on one line, starting with an integer $$$w$$$ as described above, then a string $$$S$$$ representing your collection of plants.
Each plant is represented by an uppercase letter, from "A" to "Z". Plants denoted by "A" are of weight $$$1$$$, "B" of weight $$$2$$$, and so on until "Z" with weight $$$26$$$.
Constraints
For each test case, print a line stating if you could grow all the plants. Output only "YES" or "NO" (without the quotes).
4 130 ACMALGOLYMPICS 2020 TWENTYTWENTY 472 THEQUICKBROWNFOXJUMPSOVERTHELAZYDOG 473 THEQUICKBROWNFOXJUMPSOVERTHELAZYDOG
NO YES NO YES
During the day, your friends know you as the owner of a humble ice cream shop. Little do they know, at night you are none other than the renowned agent Gogo 31!
You have trained for more than 10,000 hours—not as much as the Great Spaitama, but a decent amount nonetheless—and can now easily shoot targets from far away. You can still only shoot in straight lines, unlike your archrival Isli Texon. Your bullet also stops when it hits an enemy or any other obstacle.
Excellent as you are, you take the night as an opportunity to train and improve your shooting skills even further. You turn your ice cream shop and backyard into a shooting range, setting up the targets and obstacles in different configurations.
Your training ground can be viewed as a grid of $$$R$$$ rows and $$$C$$$ columns. When shooting, you can only move along your ice cream shop, which takes up the whole of the bottommost row. The rest of the rows contain either obstacles, targets, or empty space.
For each given configuration, how many targets can you possibly hit?
The first line of the input contains a single integer $$$t$$$, the number of test cases.
Each case starts with integers $$$r$$$ and $$$c$$$, representing your training ground. Then follow $$$r-1$$$ lines with $$$c$$$ characters each. A "#" represents an obstacle, "X" represents a target, and "." is an empty space.
Constraints
$$$0 \le t$$$
$$$2 \le r \le 500$$$
$$$1 \le c \le 500$$$
The sum of ($$$r\times c$$$) across all test cases per file is lower than $$$1000000$$$
For each test case, print a line indicating the number of targets that you could possibly hit.
2 6 9 XX..X.#.X ..XX..X.X XX#XX..XX X.X...... .#.#.#.#. 3 3 ### ..X
10 1
The following illustrates the first sample input:
Dr. Evil is up to his evil antics again and has traveled back in time to 1975 to enact his evil schemes. The British Intelligence Agency needs someone to travel back in time as well to thwart his convoluted plot. Seeing the opportunity to be part of an adventure that involves riveting mysteries, amorous escapades, and gratuitous violence, you volunteer for the role of 007.
What the British Intelligence Agency failed to tell you was that in this iteration, not only will you be agent 007. You will also be 007 years old and do 007-year-old things. As part of your role, you will receive encrypted messages with a secret marker and you have to decode whether it's meant for Agent 003, Agent 005, or Agent 007 (you). The marker will be divisible by 3 if it's meant for Agent 003, divisible by 5 if it's meant for Agent 005, and 7 if it's meant for Agent 007.
Since you retained your mental maturity, you want to avoid doing tedious tasks equivalent to homework for 007-year-olds. You want to leave it to a computer to do the job.
The program you write must accept a number $$$m$$$ (the secret marker) and output AGENT 003 if it's divisible by 3, AGENT 005 if it's divisible by 5, and AGENT 007 if it's divisible by 7.
The first line of input contains a single integer $$$t$$$, the number of test cases.
Each test case consists of a single line containing a single integer, $$$m$$$.
Constraints
$$$1 \le t \le 10^5$$$
$$$1 \le m \le 10^{18}$$$
For each test case, output several lines. For each agent the message is meant for—AGENT 003, AGENT 005, and/or AGENT 007—output the agent's name in a single line. If the message is meant for none of you, output NONE. If the message is meant for more than one of you, output each agent in the following order: AGENT 003, AGENT 005, and/or AGENT 007. At the end of the output for each test case, output a single line containing three dashes: —
7 42 420 111 1111 2020 489 123456789012345678
AGENT 003 AGENT 007 --- AGENT 003 AGENT 005 AGENT 007 --- AGENT 003 --- NONE --- AGENT 005 --- AGENT 003 --- AGENT 003 ---
Congratulations! You have passed the preliminary screening of the Academy of Covert Missions and are now on your final test.
You have been tasked to keep track of some bops roaming around the Town Hidden in the Leaves. These bops are creatures that move very swiftly and are hard to spot, but you and your team have been successful in placing Toogly Tags around their necks. These tags allow you to know what each creature is doing, and even know where it is. Unfortunately, Nagaraiya, your examiner, tells you that you ended up putting the Toogly Tags on other creatures as well that are not bops, and now you have to sort them out! That's nuts!
Thankfully those Toogly Tags that you attached not only know what the creatures are doing, but can also record the sounds that they are making as well. You remember the age-old Covert Agent Way: "If it beeps like a bop and boops like a bop, then it must be a bop."
With this wisdom that is almost as old as Wan Puhn Seh, you now have a way to sort the bops from the other creatures! Bops can only make the sounds "BEEP" or "BOOP". Other creatures make their own sounds that are never "BEEP" or "BOOP".
You now go back to Nagaraiya and tell him which ones are bops and which ones are not!
On the first line is an integer $$$C$$$, the number of creatures that you have attached Toogly Tags on. Then follow $$$C$$$ blocks describing the sounds that each creature makes.
Each block starts with a line containing an integer $$$N_i$$$, the number of sounds that the $$$i^{th}$$$ creature made. Then follow $$$N_i$$$ strings, each on its own line, indicating a sound that the $$$i^{th}$$$ creature made.
Constraints
$$$1 \le C \le 350$$$
$$$1 \le N_i \le 350$$$
Each sound consists of uppercase letters only and has length between $$$1$$$ and $$$10$$$ (inclusive).
If the creature is a bop, print "IT'S A BOP!" (without the quotes). Otherwise, output "IT'S NOT A BOP!" (without the quotes).
3 3 BEEP BOOP BOOP 4 BOOP BEEP BEEP BOOP 4 BIP BUP QUACK BOO
IT'S A BOP! IT'S A BOP! IT'S NOT A BOP!
3 7 BEEP BOOP BEEP BOOP BOOP BOOP BEEP 5 QUACK KWAK QUACK KWAKK QUAKK 3 ARF WOOF ARFF
IT'S A BOP! IT'S NOT A BOP! IT'S NOT A BOP!
Properly sneaking into a mission is very important for spies, which is lucky for you, because the Cavalry Valet Movile Insertion Group (CVMIG) has given one of their horses to you. The problem is, you are not a knight yet! In order for the horse to follow your commands, it must deem you worthy of being a knight!
Fortunately, proving yourself worthy of knightliness is easy. All horses are part of the chess club, and love how knights move. You just need to show them that you can get to your destination just like how a knight would.
In chess, a knight moves in an L shaped pattern, moving 1 space to its side then 2 spaces forward, landing on that final square. It can hop over obstacles.
Consider the following diagram:
The knight, shown at the center, may move around in $$$8$$$ ways relative to the knight's current position, labeled 'A', 'B', ..., 'H'. The knight may do that even if the squares immediately surrounding it are obstacles.
You will be given an $$$R \times C$$$ grid of characters. Each character is one of the following:
Output "Whinny" if it's possible and "Neigh" if it is not. If it is possible, also output a string denoting the moves the knight can follow to the final spot.
Note that the knight cannot leave the grid. In other words, it is not allowed to perform a move if the desination cell is outside the grid.
The first line of the input contains a single integer $$$t$$$, the number of test cases. $$$t$$$ test cases follow.
The first line of each test case contains two integers $$$r$$$ and $$$c$$$. $$$r$$$ lines follow, each containing $$$c$$$ characters, describing the grid using the abovementioned denotations.
Constraints
$$$1 \leq t \leq 10$$$
$$$1 \leq r,c \leq 1000$$$
For each test case, output a single line containing "Whinny" if it's possible to reach F from K using knight moves, "Neigh" otherwise.
If it's possible, output an additional line containing a string denoting the series of moves the knight can follow. The string should be composed of characters 'A', 'B', ..., 'H' indicating the type of move done. If there are multiple such move-strings available, output the shortest one. If there are multiple shortest move-strings, output the lexicographically-least move-string.
3 2 3 OOF KOO 2 3 OOO KOF 4 6 OFKOOO OOXXOO OOXOOO OXOOOX
Whinny D Neigh Whinny FAFAC
You are a student of the Academy for Covert Missions, currently not doing your chemistry homework. Now, chemistry can be useful to secret agents in many ways – gunpowder, smoke bombs, poison – but you don't care about any of that. You want to be a Hacker Agent, the enigmatic guy in the hoodie watching various UI elements pop up on the screen, the guy spewing technical terms while rapidly hacking on the back of a speeding motorcycle. That's why you're going to make a computer program to do your homework for you!
An atom has one or more electron shells, and each shell itself has one or more subshells. The electrons of an atom are distributed across its different shells within the different subshells. The Aufbau Principle dictates how these electrons are distributed, which is called its electron configuration.
An example electron configuration is that of Oxygen (O), which is $$$1s^2$$$ $$$2s^2$$$ $$$2p^4$$$. This means:
As in the example, the electron configuration of an element is represented by a series of terms of the form $$$nl^e$$$, where:
The corresponding letters/labels for each subshell are:
$$$$$$\begin{array}{|r|rrrr|} \hline \ell & 0 & 1 & 2 & 3 \\ \hline l & s & p & d & f \\ \hline \end{array}$$$$$$
Each shell of an atom has a maximum number of subshells – in fact, the $$$n$$$th shell can have up to $$$n$$$ subshells (thus, $$$0 \leq \ell \lt n$$$, always).
Each subshell of an atom has a maximum "capacity" – in other words, it can only fit a specific number of electrons. This capacity is determined solely by its $$$l$$$, in particular: $$$2(2\ell + 1)$$$. Thus, the $$$3p$$$ subshell can fit $$$2(2\cdot1 + 1) = 6$$$ electrons, the $$$2p$$$ subshell can also fit $$$6$$$ electrons, while the $$$4d$$$ subshell can fit $$$2(2\cdot2 + 1) = 10$$$ electrons.
The Aufbau Principle states that the electrons of an atom fill up subshells (to their capacity) in order of increasing $$$n + \ell$$$, and in ties, by increasing $$$n$$$, as illustrated in this diagram:
For example, Hydrogen, with 1 electron, fills the zeroth subshell in the first shell with its lone electron. Thus, its electron configuration is $$$1s^1$$$. Helium, with 2 electrons, will fill the zeroth subshell with both of its electrons, making its configuration $$$1s^2$$$. Lithium, with 3 electrons, will fill up the zeroth subshell in the first shell, then fill the first subshell in the second shell, making it $$$1s^2$$$ $$$2s^1$$$. Potassium, the 19th element and thus 19 electrons, will have the following configuration: $$$1s^2$$$ $$$2s^2$$$ $$$2p^6$$$ $$$3s^2$$$ $$$3p^6$$$ $$$4s^1$$$.
Seeing this pattern, you figure out that you could make a simple program for this. You can even generalize it to the $$$10^{15}$$$th element! You hope that there are no exceptions to the Aufbau Principle. (Spoiler: there are, but you don't really care enough about chemistry to address them.) Also, for $$$\ell \gt 3$$$, you're not really sure what happens, but you are just going to assume that the rest of the alphabet after 'f' (excluding 's' and 'p') will be used. That is, we will use the following extended table of levels: $$$$$$ \begin{array}{|r|rrrrrrrrrr} \hline \ell & 0 & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & \ldots \\ \hline l & s & p & d & f & g & h & i & j & k & \ldots \\ \hline \end{array}
$$$$$$ Remember that 's' and 'p' are skipped.
Once you reach 'z', you will use two-letter labels without skipping any letters this time. Specifically, you will use all possible two-letter combinations in lexicographical order (aa, ab, ac, ..., az, ba, bb, ..., ca, ..., zz).
After 'zz', all three-letter combinations (aaa, aab, ..., zzz) will be used as labels, and so on.
You therefore "extend" the pattern as follows:
Now, given an atomic number (which is the same as its number of electrons), can you find the last electron shell, last subshell and number of electrons in the last shell in its electron configuration? In other words, what is the last "$$$nl^e$$$"? For example, if the given atomic number is $$$19$$$, then the answer should be $$$4s^1$$$.
Output the answer as $$$n$$$, $$$l$$$, $$$e$$$ in a single line NOT separated by spaces. For example, for $$$19$$$, output 4s1.
The first line of input contains $$$t$$$, the number of test cases. $$$t$$$ test cases follow.
Each test case is composed of a single line containing an integer $$$a$$$ denoting an atomic number.
Constraints
$$$1 \leq t \leq 10^5$$$
$$$1 \leq a \leq 10^{15}$$$
For each test case, output a single line containing $$$n$$$, $$$l$$$ and $$$e$$$, NOT separated by spaces. For example, for $$$19$$$, output 4s1.
3 19 103 1000000000000000
4s1 6d1 93591dzil31704
Kim Possible has infiltrated Dr. Drakken's lair and has to fight off some MOOKS and MEEKS in order to stop him from his evil schemes.
However, much to Kim's surprise, Dr. Drakken knew Team Possible was coming for him as they always have. So he prepared a magical scientific device to strengthen his army of MOOKS and MEEKS.
All the MOOKS and MEEKS form a straight line and Kim Possible has to fight them starting from the first one. The MEEKS don't fight because they are tired, but the MOOKS take Kim one minute to defeat. Whenever Kim Possible defeats a MOOK, the MOOK will use his McGuffin which drains all of his energy and throws Kim Possible back to the start of the line. All the MEEKS in front of the MOOK get re-energized and turn back into MOOKS with their McGuffin fully recharged, but the MOOK that used his McGuffin turns into a MEEK, fully drained of energy.
Given the initial line of MOOKS and MEEKS, how many minutes will it take for Kim Possible to defeat all the MOOKS and turn them into MEEKS?
The first line of input contains an integer $$$t$$$, the number of test cases. $$$t$$$ test cases follow.
The first line of each test case contains an integer $$$n$$$, the number of MOOKS/MEEKS. $$$n$$$ lines follow, each is either a MOOK or a MEEK, describing their order in their line.
Constraints
$$$1\leq t\leq 10^4$$$
$$$1\leq n\leq 50$$$
For each test case, output a single integer which is the amount of time, in minutes, before Kim possible defeats all MOOKS.
3 1 MOOK 3 MOOK MEEK MEEK 7 MOOK MEEK MEEK MOOK MEEK MOOK MEEK
1 1 41
Kim Possible has infiltrated Dr. Drakken's lair again and has to fight off some MOOKS and MEEKS in order to stop him from his evil schemes.
Like last time, Dr. Drakken knew Team Possible was coming for him as they always have. So he prepared a magical scientific device to strengthen his army of MOOKS and MEEKS.
All the MOOKS and MEEKS form a straight line and Kim Possible has to fight them starting from the first one. The MEEKS don't fight because they are tired, but the MOOKS take Kim one minute to defeat. Whenever Kim Possible defeats a MOOK, the MOOK will use his McGuffin which drains all of his energy and throws Kim Possible back to the start of the line. All the MEEKS in front of the MOOK get re-energized and turn back into MOOKS with their McGuffin fully recharged, but the MOOK that used his McGuffin turns into a MEEK, fully drained of energy.
This time however, Team Possible was more prepared and the scientific genius Wade provided Kim Possible with a device called the Swappinator. The Swappinator can swap the positions of any two distinct opponents of Kim Possible and can be used $$$k$$$ times.
Given the initial line of MOOKS and MEEKS and the optimal use of the swappinator, how many minutes will it take for Kim Possible to defeat all the MOOKS and turn them into MEEKS? Note that the Swappinator must be used exactly $$$k$$$ times and must be used before any attacks.
Output the answer mod $$$10^9$$$.
The input is composed of two lines. The first line contains two integers $$$n$$$ and $$$k$$$, the number of MOOKS/MEEKS and the number of times Team Possible can use the Swappinator, respectively. $$$n$$$ lines follow, each is either a MOOK or a MEEK, describing their order in their line.
Constraints
$$$0 \leq k \leq n$$$
$$$2 \leq n \leq 10^5$$$
For each test case, output a single integer which is the shortest amount of time, in minutes and in mod $$$10^9$$$, before Kim possible defeats all MOOKS.
3 0 MEEK MOOK MEEK
2
3 1 MEEK MOOK MEEK
1
7 1 MOOK MEEK MEEK MOOK MEEK MOOK MEEK
11
7 3 MOOK MEEK MEEK MOOK MEEK MOOK MEEK
7
Kim Possible has infiltrated Dr. Drakken's lair for the third time and has to fight off some MOOKS and MEEKS in order to stop him from his evil schemes.
Like both previous times, Dr. Drakken knew Team Possible was coming for him as they always have. So he prepared a magical scientific device to strengthen his army of MOOKS and MEEKS.
All the MOOKS and MEEKS form a straight line and Kim Possible has to fight them starting from the first one. The MEEKS don't fight because they are tired, but the MOOKS take Kim one minute to defeat. Whenever Kim Possible defeats a MOOK, the MOOK will use his McGuffin which drains all of his energy and throws Kim Possible back to the start of the line. All the MEEKS in front of the MOOK get re-energized and turn back into MOOKS with their McGuffin fully recharged, but the MOOK that used his McGuffin turns into a MEEK, fully drained of energy.
This time however, the scientific genius Wade provided Kim Possible with a new device called the Reversinator. The Reversinator can reverse the order of a section of the line, but it can only be used once. To be precise, when the reversinator is used to reverse the section from the $$$i$$$th opponent to the $$$j$$$th opponent, $$$i$$$ and $$$j$$$ swap positions, $$$i+1$$$ and $$$j-1$$$ swap positions, and so on.
Given the initial line of MOOKS and MEEKS and the optimal use of the Reversinator, how many minutes will it take for Kim Possible to defeat all the MOOKS and turn them into MEEKS, assuming the Reversinator is used exactly once before Kim starts fighting?
Since the answer may be very large, output the answer mod $$$10^9$$$.
The first line of input contains $$$t$$$, the number of test cases.
Each test case consists of a single line containing a string $$$s$$$ consisting of the letters E and O. The $$$i$$$th character of $$$s$$$ is:
Constraints
We denote the length of $$$s$$$ by $$$|s|$$$.
For each test case, output a single line containing a single integer denoting the answer for that test case modulo $$$10^9$$$.
1 EOOE
3
Your organization's arch nemesis, the Mysterious Criminal Absconder, is hiding on the very top floor of your headquarters! You know because you were just passing by the ground floor when you heard a distinct evil "I'm hiding in my enemy's HQ" cackle from the top of the building. It is now your job to get from the ground floor to the top floor and capture him.
The Absconder has also hacked all the high-security doors and elevators such that they can't open anymore. The only solution now is to cut normal doors into the walls with your high-power laser, whose battery is currently running dangerously low, and take the stairs. (Really, a rookie move; all spies know that you should have at least five spare lasers on you.)
Furthermore, taking the stairs, to say the least, is not so simple in your organization's headquarters. The layout of the entire building is designed to be confusing to those unfamiliar with it; each floor can be of different sizes, staircases are put in random places and only let you climb to certain floors. One staircase, for example, might connect only the ground floor, the 3rd floor, and the 10th floor, while another may connect only the fifth floor and the sixth.
Fortunately, as a responsible member of the organization, you have the floor plans of the headquarters $$$F$$$ burned into your brain. You remember that the headquarters has $$$n$$$ floors, and each floor layout $$$F_i$$$ can be represented as an $$$R_i \times C_i$$$ 2D grid, where $$$R_i$$$ and $$$C_i$$$ are the dimensions of the $$$i$$$th floor. Also, each floor has a wall at its borders (to stop people from falling off and killing themselves). Each cell in the grid represents a 1x1 square meter of area, and is either an empty space, a wall, or a staircase. At each cell you can do the following:
You can do all of those moves instantly. However, with your laser running low and a villain to contain, you need to find a way to the top floor soon; in three seconds, to be exact. Since you were lucky enough to be on the ground floor when the Absconder initiated the lockdown, you want to start climbing the building in the optimal spot. It doesn't matter where in the top floor you arrive in, as long as you get there quickly enough. With knowledge of the layout of all floors, what is the minimum number of doors you need to cut down with your laser to get from the ground floor to the top floor?
First line contains an integer $$$f$$$, the number of floors in your headquarters. The floor plan $$$F$$$ follows. Each floor in the format is represented by the following format below: Each $$$i-th$$$ floor layout $$$F_i$$$ starts with a line containing two space-separated integers $$$R_i$$$ and $$$C_i$$$, the number of rows and columns of the 2D grid representing the floor. $$$R_i$$$ lines follow, each containing $$$C_i$$$ characters each, representing the floor layout itself:
There are at most unique $$$52$$$ staircases (one for each uppercase/lowercase letter). If a staircase appears on another floor, it means that staircase connects those two floors together.
Constraints
$$$2 \le f \le 100$$$
$$$3 \le R_i,C_i \le 100$$$
No staircase is connected to a floor it is already in (staircases are unique per floor).
Output a single line with an integer $$$D$$$ indicating the total minimum number of walls you need to cut down into doors, counting all floors assuming you chose the optimal starting point in the ground floor.
If you cannot travel to the topmost floor (a path is impossible to make given the stairs), output the string "DAMN, THE ABSCONDER ABSCONDS AGAIN!" (without the quotes) instead.
3 8 8 ######## #.A....# #......# ######## #......# #......# #......# ######## 8 8 ######## #..#..B# #..#...# #..##### #......# #.###### #.#..A.# ######## 8 8 ######## #B#..#.# #.#..#.# ######## #......# #......# #......# ########
2
It's just another day at National Corps of Intelligence Services (NCIS), the country's biggest and most powerful espionage organization. You're enjoying your favorite drink as you read through some top secret files and type away at your computer desk to finish your report for the previous mission. Everything seems normal, but then...
"No way, I'm getting hacked!", your colleague suddenly exclaims.
"A port scan?", you ask her.
"No. No, this is major. They've already burned through the NCIS public firewall," she replies, frantically typing at her keyboard.
"Well, isolate the node and dump it on the other side of the router,'' you suggest to her.
"I'm trying! It's moving too fast."
As she says this, you notice the hacker's progress on her screen. Multiple pictures of random cats keep on popping up. Several memes from Gag-Olympics show up. It looks like someone on Hacker Typer, but you are sure that this isn't a prank this time.
Not being the type to just sit back and watch your precious colleague suffer, you heroically join her on the keyboard as she continues to type away to beat the hacker. Together, you can beat the hacker, you say.
As soon as you did this, more things popped up on the screen. CAPTCHAs? No, IQ tests! "99% of the population can't solve this," it says on the screen.
"Which cup will be filled first?"
It's a very tough and difficult logic puzzle where cups are connected via tubes, and water pours in from one of the cups. Thankfully, you always knew that you were part of that special 1% of the population that can solve this puzzle, and proceed to type with your colleague to beat the hacker.
In fact, instead of just knowing which cup will be filled first, you set yourself a more ambitious goal: to know precisely where the water is at any moment in time. But you're not willing to simulate the physics of flowing water accurately. Instead, you decide on the following approximation:
With these rules in place, you now wish to know which cells become water cells, and precisely when they turn into water cells. We denote the cell at row $$$i$$$ (from top to bottom) and column $$$j$$$ (from left to right) by $$$(i, j)$$$. If cell $$$(i, j)$$$ will eventually turn into a water cell, let $$$w(i, j)$$$ be the number of seconds since the beginning when that cell first turns into a water cell. (Note that $$$w(i, j) = 0$$$ for all cells $$$(i, j)$$$ that are initially water cells.) Your goal is to compute $$$w(i, j)$$$ for every cell $$$(i, j)$$$ that will eventually turn into a water cell.
The first line contains $$$t$$$, the number of test cases. The $$$t$$$ test cases follow.
The first line of each test case contains two space-separated integers $$$r$$$ and $$$c$$$ denoting the number of rows and columns of the puzzle grid. Each of the next $$$r$$$ lines contains a string of $$$c$$$ characters indicating a row of the initial grid. Each character is either #, . or W with the following meanings:
Constraints
$$$1 \le t \le 10^4$$$
$$$1 \le r, c \le 150000$$$
$$$rc \le 1500000$$$
The sum of the $$$rc$$$ in a single file is $$$\le 1500000$$$.
There is at least one W.
All W's appear in the first row.
No solid cells appear in the first row.
For each test case, first print a single line containing the maximum $$$w(i, j)$$$ among all cells $$$(i, j)$$$ that will eventually turn into a water cell. Then print $$$r$$$ rows, each containing a string of $$$c$$$ characters. The $$$j$$$th character in the $$$i$$$th line is:
4 23 49 .......................W......................... ................................................. ....................#....#....................... ....................#....#....................... ....................#....#############........... ..........###########................#........... ..........#..............###########.#........... ..........#.#########....#.........#.#........... ..........#.#.......#....#......#.......#........ ..........#.#.......######......#.......#........ ........#.....#.................#.......#######.. ........#.....#####.........#####.............#.. ...######.........#.........#...#.......#####.#.. ...#....#.....###.#.........#.###.......#...#.#.# ...#.####.....#.#.#.........#.#.#########.#.#.#.# ...#.#..#######.#.#.........#.#...........#.....# ...#.#..........###......#..#.#.#.........#.....# #..#.#..#.....#.....#....#......#.........#.....# #..#.#..#.....#.....#....#......#.........#.....# #.......#.....#.....#....#......#.........####.## #.......#.....#.....#....#......#................ #.......#.....#######....########................ #########........................................ 23 49 .......................W......................... ................................................. ....................#....#....................... ....................#....#....................... ....................#....#############........... ..........###########................#........... ..........#..............###########.#........... ..........#.#########....#.........#.#........... ..........#.#.......#....#......#.......#........ ..........#.#.......######......#.......#........ ........#.....#.................#.......#######.. ........#.....#####.........#####.............#.. ...######.........#.........#...........#####.#.. ...#..........###.#.........#.###.......#...#.#.# ...#.####.....#.#.#.........#.#.#########.#.#.#.# ...#.#..#######.#.#.........#.#...........#.....# ...#.#..........#.#......#..#.#.#.........#.....# #..#.#..#.....#.....#....#......#.........#.....# #..#.#..#.....#.....#....#......#.........#.....# #.......#.....#.....#....#......#.........####### #.......#.....#.....#....#......#................ #.......#.....#######....########................ #########........................................ 11 12 ...W........ ............ ..######.#.. ..#....#.#.. ..#.#..#.#.. ..#.#..#.#.. ..#.#..#.#.. ..#.####.#.. ..#......#.. ..########.. ............ 15 20 ..W................. .....############... .....#..........#... .....#.########.#... .....#.#......#.#... .....#.#............ .....#.#.....#...#.. .....#.#.....#####.. .....#.#............ .....#.#............ .....#.#............ .#...#.#.#.......... .#.......#...#...#.. .#########...#####.. ....................
87 .......................0......................... .......................1......................... ....................#..2.#....................... ....................#..3.#....................... ....................#..4.#############........... ..........###########4454567890123456#........... ..........#21098765432262###########7#........... ..........#3#########1171#.........#8#........... ..........#4#.......#0989#......#...9...#........ .......654#5#456....######......#...0...#........ .......7#33633#78901............#...1...#######.. ..321098#22722#####2........#####9992999012345#.. ..4######448445678#3........#...#8883888#####6#.. ..5#6789#33933###9#4........#.###7654567#...#7#.# ..6#5####21012#.#0#5........#.#.#########.#.#8#.# ..7#4#..#######.#1#6........#.#...........#..9..# 438#3#3345...109###790...#..#.#.#.........#..0..# #29#2#22#6...2#88888#1...#......#.........#..1..# #10#1#11#7...3#77779#2...#......#.........#4323.# #0100000#8...4#66660#3...#......#.........####4## #9299999#9...5#54321#4...#......#.............5.. #4345678#0...6#######5...########.............6.. #########1...7.......6........................7.. 159 .......................0......................... ...................21001012...................... ...................3#9929#3...................... ...................4#8838#4567890123456.......... .........54321098765#7747#############7.......... .........6###########2252345678901234#8.......... .........7#21098765432262###########5#9.......... .........8#3#########1171#.....9877#6#7789....... .........9#4#.......#0989#.....0#6667666#0....... .......432#5#234....######.....1#5558555#1234567. .......5#11611#56789.......65432#4449444#######8. ..109876#00700#####0.......7#####5550555678901#9. ..2######228223456#1.......8#09876661666#####2#67 ..3#8765433933###7#2.......9#1###5432345#765#3#5# ..4#9####21012#.#8#3.......0#2#.#########8#4#4#4# ..5#0#..#######.#9#4....8766#3#678.......9#33533# 544#1#4456...210#0#012..9#55#4#5#9.......0#22622# #33#2#33#7...3#99199#3..0#444544#0.......1#11711# #22#3#22#8...4#88288#4..1#333633#1.......2#09890# #1114111#9...5#77377#5..2#222722#2.......3####### #0005000#0...6#65456#6..3#109890#3.......4....... #9876789#1...7#######7..4########4.......5....... #########2...8.......8..5........5.......6....... 32 ...0........ .3212345690. .4######7#1. .5#3452#8#2. .6#2#61#9#3. .7#1#70#0#4. .8#0#89#1#5. .9#9####2#6. .0#876543#7. .1########8. .2........9. 54 ..0................. ..1..############... ..2..#8901234567#... ..3..#7########8#... ..4..#6#......#9#... ..5..#5#....5430345. ..6..#4#....6#212#6. ..7..#3#....7#####7. ..8..#2#....8.....8. ..9..#1#....9.....9. 10000#0#012.0.....0. 2#199#9#9#3.1.....1. 3#2345678#4.2#...#2. 4#########5.3#####3. 5.........6.4.....4.
The following are the illustrations of the state of the first test case at various points in time:
A secret agent... to be one you have pushed both your physical and intellectual capacities, immersing yourself in the art of espionage. It is now time to prove your worth.
Your name isn't Mario but you end up falling down from a pipe.
You find an elephant in a room.
It speaks.
You expect a Sphinx to give out a riddle in this scenario, but the elephant gives you no time to be confused as it tells you:
"If you want to be a spy, you must pass the test."
After a moment's hesitation, you find the words to reply. "Yes, this is what I came here for. But is there anything else that I must do?"
"No, this is the only level," the elephant assures you.
It gives you the test:
" The digital sum of an integer in base $$$b$$$ is the sum of its digits when it is written in base $$$b$$$. The digital root of an integer in base $$$b$$$ is the unique digit obtained by repeatedly computing the digital sum in base $$$b$$$ until only one digit remains.
Let $$$f_b(k)$$$ be the digital root of the integer $$$k$$$ in base $$$b$$$.
We say that the pair $$$(k,b)$$$ is cool if and only if $$$(f_b(0), f_b(k), f_b(2k), \ldots, f_b((b-1)k))$$$ is a permutation of $$$(0, 1, 2, \ldots, b-1)$$$.
Given $$$k$$$ and $$$b$$$, is $$$(k,b)$$$ a cool pair? "
The first line of input contains $$$t$$$, the number of test cases.
Each test case consists of a single line containing two space-separated integers $$$k$$$ and $$$b$$$.
Constraints
$$$1 \le t \le 10^5$$$
$$$1 \le k \le 10^{15}$$$
$$$2 \le b \le 10^{15}$$$
For each test case, output a single line containing the string:
2 10 7 7 10
NOT COOL COOL
You've proven your worth and capabilities as a spy when you passed The Only Level.
Your name isn't Mario but you fall down from a pipe.
You find an elephant in a room.
It speaks.
You are not sure if you are expecting an elephant in this scenario, but the elephant gives you no time to be confused as it tells you:
" The digital sum of an integer in base $$$b$$$ is the sum of its digits when it is written in base $$$b$$$. The digital root of an integer in base $$$b$$$ is the unique digit obtained by repeatedly computing the digital sum in base $$$b$$$ until only one digit remains.
Let $$$f_b(k)$$$ be the digital root of the integer $$$k$$$ in base $$$b$$$.
We say that the pair $$$(k,b)$$$ is cool if and only if $$$(f_b(0), f_b(k), f_b(2k), \ldots, f_b((b-1)k))$$$ is a permutation of $$$(0, 1, 2, \ldots, b-1)$$$.
Let $$$K$$$ and $$$B$$$ be two sets of integers. Find the number of distinct cool pairs $$$(k,b)$$$ such that $$$k \in K$$$ and $$$b \in B$$$. "
The first line of input contains two space-separated integers $$$|K|$$$ and $$$|B|$$$ denoting the sizes of the sets $$$K$$$ and $$$B$$$, respectively.
The second line of input contains $$$|K|$$$ space-separated integers denoting the elements of the set $$$K$$$.
The third line of input contains $$$|B|$$$ space-separated integers denoting the elements of the set $$$B$$$.
Constraints
$$$1\le |K|, |B| \le 3\cdot 10^5$$$
Every element of $$$K$$$ is a positive integer $$$\le 10^6$$$.
Every element of $$$B$$$ is a positive integer $$$\le 10^6$$$.
The elements of $$$K$$$ are distinct.
The elements of $$$B$$$ are distinct.
Output a single line containing a single integer denoting the answer.
4 3 6 9 11 24 8 16 10
6
You've passed the Only Level TOO.
Your name isn't Mario but you fall down from a pipe.
You find an elephant in a room.
It speaks.
You now know where this is going. The elephant speaks:
" The digital sum of an integer in base $$$b$$$ is the sum of its digits when it is written in base $$$b$$$. The digital root of an integer in base $$$b$$$ is the unique digit obtained by repeatedly computing the digital sum in base $$$b$$$ until only one digit remains.
Let $$$f_b(k)$$$ be the digital root of the integer $$$k$$$ in base $$$b$$$.
We say that the pair $$$(k,b)$$$ is cool if and only if $$$(f_b(0), f_b(k), f_b(2k), \ldots, f_b((b-1)k))$$$ is a permutation of $$$(0, 1, 2, \ldots, b-1)$$$.
Given two integers $$$k'$$$ and $$$b'$$$, find the number of cool pairs $$$(k,b)$$$ such that $$$1 \le k \le k'$$$ and $$$2 \le b \le b'$$$, modulo $$$10^6$$$. "
The input consists of a single line containing two space-separated integers $$$k'$$$ and $$$b'$$$.
Constraints
Output a single line containing a single integer denoting the answer.
3 5
9