Gason and his bestie Gteve love the letter 'G', and they successfully hacked into the Villager News' director's computer where the director stores all of the news headlines to be broadcasted. Since Gason loves the letter 'G' so much, he decides to replace the first character of every single headline with the uppercase letter 'G'! Now Gason is watching the Villager News (with Gteve) and is wondering how many headlines he modified made it into the actual news broadcast.
Given the initial headlines stored on the news director's computer and the final headlines which were actually broadcasted, determine how many headlines in the news broadcast were those possibly modified by Gason and Gteve.
Everything is case-sensitive!!!
The first line contains a single integer $$$1\leq n\leq 110$$$, the number of initial news headlines on the news director's computer.
The next $$$n$$$ lines each contain a single string $$$s_i$$$: the $$$i^{th}$$$ headline stored on the news director's computer before Gason's modification ($$$1\leq |s_i| \leq 67$$$). It is guaranteed that the $$$s_i$$$'s are distinct.
The next line contains a single integer $$$1\leq m \leq 111$$$, the number of headlines which were broadcasted on the Villager News.
The last $$$m$$$ lines each contain a single string $$$t_i$$$: the $$$i^{th}$$$ headline broadcasted on the Villager News ($$$1\leq |t_i| \leq 67$$$). It is guaranteed that the $$$t_i$$$'s are distinct.
Every single character in each string is alphanumeric or an underscore.
Output a single integer, the number of headlines in the Villager News broadcast which could have been modified by Gason and Gteve.
We have provided sample input parsing scripts in C++, Java, and Python below for the first two problems.
6The_Blatant_AdvertBREAKING_NEWSCHRISTMASWARTHE_GIANT_PROBLEMTestificate_News7Ghe_Blatant_AdvertGREAKING_NEWSGHRISTMASGARGHE_GIANT_PROBLEMGestificate_NewsHacker_Messes_with_Villager_News_Headlines
6
567GasonandSteve4GGasonandGteve
3
The Potato King is plotting his next moves to bring a decisive victory in the Great Potato War! Manually planting and harvesting potatoes for $$$11$$$ hours a day is giving him carpal tunnel, so he's looking into trading with a group of $$$N$$$ ($$$2 \le N \le 1,000$$$) villagers to get potatoes. For each of the $$$N$$$ villagers, villager $$$i$$$ has an exchange rate of $$$P_i$$$ ($$$1 \le P_i \le 1,000$$$); that villager is willing to trade $$$P_i$$$ potatoes for an emerald, or one emerald for $$$P_i$$$ potatoes.
The Potato King can do some amount of trade operations. In a single trade, he first selects two villagers $$$i$$$ and $$$j$$$. Then, he spends $$$P_i$$$ potatoes to get an emerald from villager $$$i$$$, then spends that emerald to get $$$P_j$$$ potatoes from villager $$$j$$$. This results in a net gain of $$$P_j-P_i$$$ potatoes. Each villager may be selected no more than once; otherwise, the villagers may get suspicious and start to undergo mitosis. Note that the Potato King has enough potatoes initially to trade with any villager.
Given $$$N$$$ villagers where the $$$i$$$th villager buys or sells potatoes at the exchange rate of $$$P_i$$$ potatoes per emerald, find the maximum number of potatoes that the Potato King can gain!
The first line consists of integer $$$N$$$ ($$$1 \le N \le 1,000$$$): the number of villagers. The second line consists of $$$N$$$ space-separated integers $$$P_1$$$ through $$$P_N$$$ ($$$1 \le P_i \le 1,000$$$): each villager's price.
Output a single integer: the maximum amount of potatoes that the Potato King can gain after trading!
We have provided sample input parsing scripts in C++, Java, and Python below.
54 2 3 1 5
6
61 1 4 2 3 4
7
167
0
1184 69 67 72 78 79 66 76 65 68 69
54
In the first testcase, the Potato King can do two trades. First, he trades with the second and fifth villager, spending two potatoes to get five potatoes. Next, he trades with the fourth and first villagers, spending one potato to get four potatoes. In total, he gains a net $$$6$$$ potatoes. Note that this is not the only possible ordering that gains $$$6$$$ potatoes!
A horrifying new species of slime was just discovered, the "tree slime". A normal slime splits into smaller slimes when it is killed. Tree slimes work differently.
On command, a tree slime of size $$$k \gt 1$$$ will spawn 2 smaller tree slimes of size $$$k-1$$$; the larger tree slime remains unharmed in the process, though it can only do this once in its life. Those smaller tree slimes can also spawn 2 tree slimes of size $$$k-2$$$, until tree slimes of size 1 are spawned, which are the smallest possible tree slime and cannot spawn any smaller tree slimes.
Luckily, the scientists in the village have made a breakthrough. They've found that, if any of the tree slimes die, the tree slime they spawned from – the "parent" – also dies. So, if you hit a tree slime to kill it, then its parent will also die if it's still alive, and the parent's parent as well, and so on.
Suddenly, you hear a terrifying rumble. The village lookout spots a massive tree slime approaching the village. Right before your eyes, this tree slime and all of its descendants spawn all the tree slimes they possibly can. The lookout counts and says there is a line of $$$2^n$$$ size 1 tree slimes leading the charge, with all of the parent tree slimes following behind. The blacksmith has forged you a sword in a hurry, but it only has $$$h$$$ hits before it breaks. What's the maximum number of tree slimes you can kill?
NOTE: Both the input and output may be large, make sure to use 64-bit integers (C/C++: long long, C#/Java: long, Python: doesn't matter)
The first and only line contains two space-separated integers, $$$n$$$ $$$(1 \le n \le 62)$$$ and $$$h$$$ $$$(1 \le h \le 2^n)$$$. This means there are $$$2^n$$$ size 1 tree slimes with all of their parents and parents' parents, etc, and you have $$$h$$$ hits before your sword breaks.
Print a single integer: the maximum number of tree slimes you can kill with $$$h$$$ hits of your sword.
2 3
6
2 4
7
You have just invited your friend to your Minecraft server and want to play a fun game with them! You have prepared $$$n$$$ chests in a row that contain random loot. The chests are numbered from $$$1$$$ to $$$n$$$ (left to right). Chest $$$i$$$ contains loot that has value $$$v_i$$$. Your friend will start at the chest on the very left and open them in order to the right. To make the chest opening as dramatic as possible for your friend, you want the loot to generally increase in value in comparison to the loot found previously. To quantify this, we define the "drama" of chest $$$i$$$ to be how much greater its value is compared to all the previous chests opened with a smaller value. Formally, the drama of chest $$$i$$$ is $$$\sum_{j=0}^{i-1} \max(0, v_i - v_j)$$$. Then, the total drama from the chest opening would be the total sum of the drama of each chest $$$i$$$.
You have peeked ahead at all the loot in each chest, and you notice that the value of loot is nonincreasing from left to right, resulting in a total drama of $$$0$$$! That's not going to be very dramatic for your friend, so you now want to rearrange the chests. You can rearrange the chests by taking a prefix of them and moving them to the end of the row. Specifically, if your chests initially had loot with values $$$v_1, v_2, \ldots, v_{n-1}, v_n$$$ (left to right), then it can be rearranged to $$$v_l, v_{l+1},\ldots, v_n, v_1, v_2,\ldots, v_{l-1}$$$ (left to right) for any $$$1\leq l\leq n$$$. Find the maximum total drama of the chest opening over all the possible rearrangements so that your friend can have a dramatic time.
Each test contains multiple test cases. The first line of input contains the number of test cases $$$t$$$ ($$$1 \leq t \leq 10^3$$$). The description of test cases follows.
The first line of each test contains a single integer $$$n$$$ ($$$1 \leq n \leq 10^6$$$): the number of chests.
The second line contains $$$n$$$ integers $$$v_1, v_2, \ldots, v_n$$$ ($$$1\leq v_i \leq 10^6$$$ and $$$v_i \geq v_{i+1}$$$ for all $$$1\leq i \leq n -1$$$): the value of the loot in each of the chests from left to right.
It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^6$$$.
For each test case, output a single integer: the maximum total drama of the chest opening after rearranging the chests optimally.
344 3 2 151 1 1 1 153 3 2 2 1
8 0 8
For the first test case, we can observe that moving the first two chests (prefix of length $$$2$$$) and moving them to the end of the row would be optimal. This gives us the arrangement of values $$$2, 1, 4, 3$$$. Then, the drama of chest $$$1$$$ is $$$0$$$, the drama of chest $$$2$$$ is $$$0$$$, the drama of chest $$$3$$$ is $$$(4 - 2) + (4 - 1) = 5$$$, and the drama of chest $$$4$$$ is $$$(3 - 2) + (3 - 1) + 0 = 3$$$. This gives us a total drama of $$$8$$$.
For the second test case, no matter how you rearrange the chests, the total drama will be $$$0$$$.
Standard stack sizes in Minecraft are $$$2^6=64$$$ for most blocks and items, $$$2^4=16$$$ for select items, and $$$2^0=1$$$ for tools and special items. However, Mojang's latest update has a lot of bugs, forcing items to stack to exactly any integer power of $$$2$$$, including powers greater than $$$64$$$: $$$128$$$, $$$256$$$, and so on! Since you were down in your mineshaft before the update dropped, you decide to use the opportunity to start moving your supply of gems back to your base above ground.
You have diamonds and emeralds in the mineshaft's storage that you want to bring, but you can't put them in your inventory since you're carrying lots of other important items (i.e. Pigstep and deadbushes). But, you do have a bundle, a portable container that fits exactly $$$N$$$ items. Due to another bug in the update, you can only insert stacks of items in alternating order, but you can start with either diamonds or emeralds. For example, if you first insert a power-of-two stack of diamonds, the next stack you insert must be a power-of-two stack of emeralds.
For example, the bundle might be able to fit $$$4$$$ gems. There are $$$12$$$ possible ways to put them in, shown below. Note that each sequence of the same item must have a length matching some power of $$$2$$$; as such, a length of $$$3$$$ is unable to be added to the bundle.
DEDE, EDED, DDED, EEDE, DEED, EDDE, DEDD, EDEE, DDEE, EEDD, DDDD, EEEE
You're curious about how many different ways you could completely fill your bundle. Given the capacity of the bundle $$$N$$$, determine how many different ways the bundle can be filled. Assume that you have at least $$$N$$$ gems of each type.
The only line of input is integer $$$N$$$ $$$(1 \le N \le 10^5)$$$: the capacity of your bundle.
Output a single integer: the number of ways that you could fill your bundle $$$\text{mod}$$$ $$$10^9+7$$$.
4
12
5
20
67
564649932
6767
349469276
You have $$$n$$$ chicken jockeys, as one does, and you want to showcase them in your ULTIMATE ultra-secure OP hidden secret minecraft base in as square of a bounded area as possible. Each chicken jockey fills a 1 block by 1 block area on the floor. The $$$i^{th}$$$ chicken jockey has a height of $$$h_i$$$ chickens. You must lay the chicken jockeys out in a grid, where each chicken jockey is connected* to every other chicken jockey. Furthermore, every row and column must have at least one chicken jockey in it.
Finally, you MUST ensure that a chicken jockey is strictly taller than the one in front of it so that you can see each zombie's face, because otherwise what's the point (you love chickens and zombies).
Formally, if a chicken jockey $$$a$$$ is in row $$$i$$$ and column $$$j$$$ and another chicken jockey $$$b$$$ in row $$$i+k$$$ and column $$$j$$$ for $$$k \gt 0$$$, you must ensure that $$$h_a \lt h_b$$$. You can maximize the "squareness" of your minecraft base by minimizing the absolute difference between the number of rows and the number of columns used in your grid.
Given a list of chicken jockey heights, output the absolute difference of the dimensions of the most square bounded minecraft base such that you can see each zombie's face.
*Connected means you can reach any chicken jockey from another by take steps going up, down, left, or right walking on top of zombie heads.
The first line contains a single integer: $$$1\leq n \leq 10^5$$$, the number of chicken jockeys.
The next line contains $$$n$$$ integers, where $$$1\leq h_i \leq 10^9$$$ is the height of the $$$i^{th}$$$ chicken jockey.
One integer $$$d$$$, the absolute difference between the number of rows and columns of the squarest bounded base grid such that the chicken jockeys are connected and visible.
61 1 1 1 1 2
3
56 7 6 7 6
0
21 100
1
For the first test case, one valid configuration of chicken jockeys is the following:
This gives us 2 rows and 5 columns, or an absolute difference of 3.
You've invented the Armorstand Circle Placement Constructor (ACPC), a command to generate circles in Minecraft! Using repeating command blocks, ACPC generates a circle on the ground of a given radius $$$r$$$ by first spawning a central armor stand, which then repeatedly spawns another armor stand entity $$$r$$$ blocks in front of it and rotates slightly clockwise. The central armor stand then forces all the other armor stands to face inwards, creating the illusion of a circle.
You're planning to use ACPC to generate a circle as part of a house you're designing in a plains biome. You select a $$$N \times N$$$ area to place your circle, where $$$N$$$ is even, given as a 2D grid. Your circle will be centered at the middle of the grid. Within the grid, certain blocks have tall grass growing on them; you want to use this foliage as part of your design. A block without tall grass is marked as ., while a block with tall grass is marked as #.
You want to find the smallest radius $$$r$$$ to use such that the circle touches the most blocks with tall grass. Tall grass touches the circle if the circumference of the circle intersects or is tangent to the perimeter of that tile. A circle may have a radius of $$$0$$$, where it is just a point at the center of the grid. In this case, blocks with perimeters that contain this point are touching the circle. Notably, we're only considering the distance of the circle's circumference from the central point, disregarding the base areas of the individual armor stands. Additionally, the circle may extend out of the grid.
Given a $$$N \times N$$$ grid where $$$N$$$ is even, output the radius of the smallest circle centered in the middle of the grid with the circumference that touches the most tall grass!
The first line of input is even integer $$$N$$$ ($$$2 \le N \le 500, \space N \text{ is even}$$$): the length of a side of the square grid. Following this are $$$N$$$ lines of length $$$N$$$ each: the square grid.
Output a single floating-point value: the minimum radius of the circle that touches the most tall grass. Your answer will be accepted if it is within an absolute or relative error of $$$10^{-6}$$$ to the jury's answer.
4.##.#..##..#.##.
1.0
4......#.#...#...
1.4142135623730951
2.##.
0.0
14...#......#.....#........#...#..........#.#............#..####..####....#........#....####.....#....#..#.....#....#..#.....#....####.....#..#............#.#..........#...#........#.....#......#...
6.708203932499369
2....
0.0
8#......#................................................#......#
4.242640687119285
On the first testcase, the maximum possible number of tall grass touched is $$$8$$$. The minimum radius of a circle that touches $$$8$$$ tall grass tiles is $$$1$$$.
Chat, we've done it! We've made a computer... in Minecraft! The only thing is, it has a peculiar instruction set called RSC-IV, or "Redstone Computer 4". "Redstone Computer" because the logic is built with redstone, and "4" because there are only 4 values that it understands.
Because it only understands 4 values, RSC-IV only has 4 instructions that a program can contain. A program is just a 1-dimensional line of wood blocks. The only valid wood blocks are Acacia, Birch, Cherry, and Dark Oak. From here on out, we will just refer to these blocks by their first letters: A, B, C, and D.
RSC-IV has only four components.
Each block in the program is one instruction that either acts on the register, the instruction pointer, or the output. Here are the effects of the 4 program blocks:
| Block | Instruction | Effect |
| A | INC | Add 1 to the value in the register, then increment the instruction pointer |
| B | DUB | Double the value in the register, then increment the instruction pointer |
| C | JMP | Increase the instruction pointer by $$$R$$$, where $$$R$$$ is the value in the register |
| D | PUT | Put/append the value in the register into the output as a block, where 0=A, 1=B, 2=C, and 3=D, then increment the instruction pointer |
There are three caveats to note:
One fun thing computer scientists like to do is make a "quine" – a program that outputs itself. We won't have you make a quine, but we'll ask for something similar. The challenge we have for you is the following: take a given output string $$$S$$$ and make a valid RSC-IV program $$$P$$$ with the following constraints:
The first and only line contains an output string $$$S$$$ $$$(1 \le |S| \le 100)$$$ consisting only of $$$A$$$s, $$$B$$$s, $$$C$$$s, and $$$D$$$s.
Print a program string $$$P$$$ $$$(|P| \le 1000)$$$ which will print exactly $$$S$$$ and contains $$$S$$$ as a substring. Print "C" if the task is impossible.
AAAA
AAAABBBBDDDDC
ABCDA
ABCDABBBBDADBBAADBAAADADC
DADADADADA
C
There are $$$N$$$ witch huts each with a witch in it. One of these witches is evil. You want to find which witch hut has the evil witch.
To do this, you assign other players to check these witch huts. You start with $$$K$$$ (an initial value you choose) players. You can assign each player to investigate any amount of witch huts. They all disperse and take $$$C$$$ time to check the assigned witch huts and come back to you at the same time.
When the players come back to you, they either have the "Bad Luck" effect on them if they checked the evil witch hut or they have "Good Luck" effect on them if they did NOT visit the evil witch hut. The players that checked the evil witch don't know which one of the witch huts they visited gave them the "Bad Luck" effect though (the "Bad Luck" effect is the only indicator). Additionally, because the players with the "Bad Luck" effect have bad luck, one of them is chosen at random and permanently dies, meaning they can't help with the witch hut checking anymore. If no players come back with the "Bad Luck" effect, no players die.
You want to find the evil witch within $$$T$$$ time, but not very many players are willing to help out. What's the minimum number of players $$$K$$$ you need to start with to guarantee finding the evil witch?
Each test case consists of only 3 numbers $$$N$$$ ($$$1 \leq N \leq 10^{18}$$$), $$$C$$$ ($$$1 \leq C \leq 10^5$$$), and $$$T$$$ ($$$1 \leq T \leq 10^5$$$).
Print only $$$K$$$, the minimum number of players you need to start with to guarantee finding the evil witch. If no amount of players can guarantee finding the evil witch, output $$$-1$$$.
3 15 15
2
10 10 23
2
6 26 20
-1
For the first test case, you can send player 1 to check hut 1 and player 2 to check hut 2 at time 0. If either of them comes back "Bad Luck" at $$$t=15$$$, you know that hut is evil. If neither come back with "Bad Luck", you know witch hut 3 is evil.
For the second test case, you can send player 1 to check witch huts 1, 2, 3, and 4 and player 2 to check huts 1, 2, 5, 6 at time 0.
At $$$t=10$$$:
1. If only player 1 comes back with "Bad Luck", you check witch huts 3 and 4 with player 2.
2. If only player 2 comes back with "Bad Luck", you check witch huts 5 and 6 with player 1.
3. If both come back with "Bad Luck", you check witch huts 1 and 2 with one of the players.
4. If neither come back with "Bad Luck", you check witch huts 7, 8, 9, 10 with both players.
At $$$t=20$$$, you will know which witch hut is the evil one.
For the third test case, you cannot determine the evil witch hut. Thus, you return "$$$-1$$$".
You have found $$$N$$$ villages that are all connected by $$$N - 1$$$ roads so that one can start at any village and visit any other village using these roads. However, the villagers in these villages don't want to be all connected because they think there are too many people competing over trading. So they ask for your help to break the villages up by removing roads.
Each road $$$i$$$ has a time $$$t_i$$$ that it takes to remove, but you only have $$$T$$$ time before your mom tells you to stop gaming. Therefore, the total time of the roads you remove must be at most $$$T$$$. Also, after removing roads, the villages are split into smaller communities where villages within a community can still visit each other using roads, but villages in different communities cannot visit each other anymore. To keep the villagers as happy as possible, you want to minimize the number of villages in the largest community. Help the villagers out as much as possible using your limited gaming time and find the minimum number of villages in the largest community!
The first line of input contains two integers $$$N$$$ and $$$T$$$ ($$$2 \le N \le 1000$$$, $$$1\le T\le 10^9$$$): the number of villages and the amount of gaming time you have, respectively.
The $$$i$$$-th of the next $$$N - 1$$$ lines contains three integers $$$u, v, t_i$$$ ($$$1 \le u, v\le N$$$, $$$u\neq v$$$, $$$1\le t_i\leq 10^9$$$): road $$$i$$$ is between village $$$u$$$ and village $$$v$$$ and takes time $$$t_i$$$ to remove.
Output a single integer: the minimum number of villages in the largest community after removing the optimal roads using your limited gaming time.
5 61 2 22 3 43 4 24 5 2
2
5 61 2 72 3 73 4 74 5 7
5
For the first test case, you can remove roads $$$1$$$, $$$2$$$, and $$$4$$$, which takes a total time of $$$6$$$. Then, the communities would be villages $$$(1)$$$, $$$(2,3)$$$, $$$(4)$$$, and $$$(5)$$$. So, the largest community has $$$2$$$ villages, and we can show that no other removal of roads can result in a smaller size of the largest community.
For the second test case, it is impossible to remove any of the roads without going over your given gaming time. So, all the villages will remain connected and the largest community has size $$$5$$$.
You want to create a zombie farm. Luckily you've recently stumbled upon a zombie spawner. However, you can't break the spawner to move it elsewhere, so the farm needs to be built around it. Additionally, to trap the zombies in, you need to build a fence around the spawner.
However, due to the new update, the farm requires a very specific type of fence. The fence needs to be a non-degenerate triangle with vertices at 3 of $$$N$$$ pre-determined fence posts, located on a 2d grid. If needed, the spawner can lie directly on the fence.
To give the mobs more space to spawn (maximizing profits), you want to make the area enclosed by the fence as large as possible. What is the largest possible area that such a fence can enclose, if one exists?
The first line of input is the integer $$$N$$$ ($$$3 \le N \le 50000$$$): the number of fence posts in the grid. The second line has two space-separated integers, $$$g_x$$$ and $$$g_y$$$ ($$$-5000 \le g_x,g_y \le 5000$$$): the coordinates of the spawner. The next $$$N$$$ lines each contain two space-separated integers, $$$x_i$$$ and $$$y_i$$$ ($$$-5000 \le x,y \le 5000$$$): the coordinates of the $$$i^\text{th}$$$ fence posts.
Output a single floating point value: The maximum area enclosed by a triangular fence containing the spawner, and with vertices at $$$3$$$ of the given fence posts. If no such triangular fence exists, output -1.
41 10 00 310 35 0
15.000000000000