Scientists Mike and Harvey have collected some iguanas from the nearby Amazon rainforest. They are interested in two specific traits of each iguana: the number of scales and the number of colors they can camouflage into.
After spending several weeks researching, Mike and Harvey believe that the best iguanas have more scales and fewer colors. More specifically, an iguana $$$i$$$ is "better" than iguana $$$j$$$ if the ratio of $$$i$$$'s scales to $$$j$$$'s scales is greater than the ratio of $$$i$$$'s colors to $$$j$$$'s colors. If these ratios are equal, the iguana with the higher ID is considered better.
Currently, they have given $$$N$$$ iguanas IDs from $$$1$$$ through $$$N$$$ $$$(3 \leq N \leq 10^5)$$$. Each iguana has some number of scales, denoted $$$a_i$$$ $$$(1 \leq i \leq N$$$, $$$1 \leq a_i \leq 10^9)$$$, and some number of colors, denoted $$$b_i$$$ $$$(1 \leq i \leq N$$$, $$$1 \leq b_i \leq 10^9)$$$. Please help Mike and Harvey figure out what the three "best" iguanas are.
The first line of input contains a single integer, $$$N$$$. The second line contains $$$N$$$ integers: $$$a_1, a_2, … a_N$$$ The third line contains $$$N$$$ integers, $$$b_1, b_2, … b_N$$$
Please output three lines, containing the IDs of the first, second, and third-best iguanas, respectively.
6 1 3 10 5 6 9 7 8 2 4 6 9
3 4 6
The Iguanodon, "Iggy" the Iguagua, is escaping Jurassic Park. She begins with $$$N$$$ initial XP. Attacking opponents with her "thumb spike" attack deals $$$P_1$$$ damage to her opponent and costs $$$P_2$$$ damage to her own XP, and she can use this move at most once for each opponent. She can use the "charge" attack an unlimited number of times, dealing $$$Q_1$$$ damage to her opponent with a cost of $$$Q_2$$$ to her own XP. Along her escape route is a series of $$$M$$$ small dinosaurs, each having an initial XP of $$$a_i \: (1 \leq i \leq M)$$$. A dinosaur is considered defeated when they have no positive XP left. Determine if Iggy can defeat all the dinosaurs blocking her route using her attacks without being defeated herself.
The first line contains integers $$$N (1\leq N \leq 10^9)$$$, the initial XP, and $$$M (1\leq M \leq 10^5)$$$, the total number of opponents.
The second line has integers $$$P_1 (1\leq P_1 \leq 10^9)$$$ and $$$P_2 (1\leq P_2 \leq 10^9)$$$, the cost of the "thumb spike" attack.
The third line has integers $$$Q_1 (1\leq Q_1 \leq 10^9)$$$ and $$$Q_2 (1\leq Q_2 \leq 10^9)$$$, the cost of the "charge" attack.
The last line contains $$$M$$$ integers $$$a_1, a_2, \cdots a_M (1\leq a_i \leq 10^9)$$$ denoting the XP of each opponent.
Print "YES" if Iggy can escape the park with positive remaining XP, otherwise print "NO".
8 3 5 2 3 1 5 8 6
YES
You are playing a strange card game involving undead attackers and botanical garden defenders. Your opponent is Deranged David, who plays on the side of the defenders, while you play on the side of the attackers.
This deck has 52 cards total, and would normally consist of cards like "Lizard Walker," "Sasquatch Ghoul," and "Giga-Colossus." For simplicity, let's just number the cards, turning them into a standard deck (4 copies each of $$$1, 2, 3,..., 13$$$). Note that we take the ace to be 1 and the jack, queen, and king to be 11, 12, and 13, respectively.
At the beginning of the game, the deck is shuffled an arbitrary number of times. You shuffle the deck by perfectly interleaving the first and second halves of the deck. That is, given a deck of cards $$$[a_1, a_2, …, a_{26}, a_{27}, … a_{52}]$$$, the first half of the deck is interleaved with the second half of the deck in an alternating order to form the new deck $$$[a_1, a_{27}, a_2, a_{28}, … , a_{26}, a_{52}]$$$.
This game is not fair – you know that the cards labeled 1 (the aces) are by far the strongest card. You know that you can only win if all four aces start in the first half of the deck, e.g. between positions 1 and 26 inclusive.
Luckily, David has agreed to let you shuffle the cards. Given an initial permutation of the cards, can you determine if you can shuffle the deck (an arbitrary number of times) such that all four aces are in the first half of the deck, or are you doomed to succumb to Deranged David's defense?
The first and only line of input contains 52 space-separated integers $$$a_1, a_2, ... , a_{52}$$$, denoting the initial permutation of cards. Note that each integer between 1 and 13 inclusive will occur exactly 4 times.
Output a single line: "YES" if you can guarantee all the aces wind up in the first half of the deck, or "NO" otherwise.
1 5 9 7 9 11 12 13 8 7 13 2 12 1 10 10 3 7 4 3 4 8 8 3 5 4 1 11 5 1 10 4 2 13 3 2 9 12 6 6 6 12 9 6 11 10 8 5 2 7 13 11
YES
12 11 5 8 3 2 13 6 1 3 12 3 12 5 7 10 6 7 9 4 6 4 1 13 1 9 5 10 9 2 4 9 2 8 11 8 13 2 10 7 3 7 8 4 10 1 13 5 11 11 6 12
NO
Ivan the Iguana has a strong craving for eggs. He particularly enjoys having his eggs either scrambled or fried.
Today's dinner consists of $$$N$$$ eggs.
Ivan has three options for each egg: fry it, scramble it, or not eat it at all. Ivan's appetite permits him to eat a maximum of $$$F$$$ fried eggs and $$$S$$$ scrambled eggs. The $$$i^{th}$$$ egg will give Ivan a satisfaction level of $$$f_i$$$ if fried and $$$s_i$$$ if scrambled. Ivan initially starts at a satisfaction level of $$$0$$$.
Please find the maximum amount of satisfaction that Ivan can gain from eating his eggs if he optimally picks which eggs are scrambled and which are fried.
$$$\textit{Note}: $$$ Ivan can eat less than $$$F$$$ fried eggs and $$$S$$$ scrambled eggs if he can have greater satisfaction doing so.
The first line of input contains three integers: $$$N \space F \space S$$$, the total number of eggs, the maximum number of fried eggs Ivan can eat, and the maximum number of scrambled eggs Ivan can eat. $$$(1 \leq N \leq 10,000; 0 \leq F+S \leq 100)$$$
The next $$$N$$$ lines of input contain two integers: $$$f_i \space s_i$$$, the satisfaction level of the $$$i^{th}$$$ egg when fried and scrambled respectively. $$$(-10^9 \lt f_i, s_i \lt 10^9)$$$
Please output 1 integer, the maximum amount of satisfaction that Ivan can gain from eating his eggs.
5 1 2 3 8 5 6 7 7 4 5 6 2
21
4 0 1 100 -5 5 20 -6 15 30 30
30
In the mystical land of Iguanaria, there exists a unique community of iguanas. Each iguana is designated by a distinct integer from 1 to N. Among these iguanas, Iguana 1 is considered the leader. These iguanas have a mystical connection that draws them towards Iguana 1. They embark on a journey to find their leader, guided solely by their intuition.
You are given an array $$$p$$$, where $$$p_i$$$ means that on each time step, the iguana at position $$$i$$$ will move to position $$$p_i$$$. Note that Iguana 1 will send an assistant to move for it, and will remain at position $$$1$$$ throughout the duration of the movements.
However, the journey is not without challenges. The Iguanaria is a dense rainforest filled with obstacles, and some iguanas may never reach Iguana 1 due to their wandering paths or the perils they encounter. Your task is to calculate the expected time it takes for the iguanas that can reach their leader, Iguana 1, to find him, starting from $$$t = 0$$$.
The first line contains $$$T(1\leq T\leq 2\cdot 10^5)$$$, the number of test cases.
The first line of each test case contains $$$N (1\leq N \leq 2\cdot 10^5)$$$, the total number of iguanas.
The second line of each test case contains $$$N$$$ integers: $$$p_1, p_2, \ldots, p_n (1\leq p_i\leq N)$$$ which is the array $$$p$$$.
Additionally, the sum of $$$N$$$ over all test cases does not exceed $$$2\cdot 10^5$$$
For each test case print one number, the expected time for the iguanas that can reach Iguana 1 to find him. Numbers within $$$10^{-6}$$$ of our answer will be considered correct.
3 5 5 2 3 1 4 3 1 2 3 10 2 3 4 5 6 7 8 9 10 1
1.000000000000000 0.000000000000000 4.500000000000000
Your calculation should include the expected time for Iguana 1 to reach Iguana 1.
Many people are not aware of the fact that iguanas love to play the classic board game of Go. The game is played on an $$$N \times M$$$ board where each square is initially empty. Two players take turns placing either black or white tiles on empty squares. Tiles are considered adjacent if they share a side. If a group of adjacent tiles of the same color are "surrounded" by tiles of the opposite color, they will be removed from the board and play proceeds.
Surrounded can be defined in terms of "liberties". A group of tiles of one color has a number of liberties equal to the number of empty tiles adjacent to the group. A single tile can have up to four liberties. A group of tiles is surrounded if it has exactly zero liberties.
A pair of particularly clever iguanas have been playing a long game of Go, and at some point they have become quite tired. Both sides would like to consider various candidate moves, but they would not like their own tiles to become surrounded. They each give you various positions on the board where they could make a move, and it is your job to tell them if that move will result in a group of their tiles becoming surrounded.
The input will begin with a line containing exactly three integers, $$$N\ (1 \leq N \leq 1,000)$$$, $$$M\ (1 \leq M \leq 1,000)$$$, and $$$Q\ (1 \leq Q \leq 10,000)$$$.
The next $$$N$$$ lines will each consist of $$$M$$$ characters, describing the current state of the Go board. Each of the $$$N \times M$$$ characters will be either "B", indicating a black tile, "W", indicating a white tile, or ".", indicating an empty space.
The final $$$Q$$$ lines of input will each consist of a character $$$T$$$, either "B" or "W", followed by exactly two integers, $$$X\ (1 \leq X \leq N)$$$, and $$$Y\ (1 \leq Y \leq M)$$$. Each of these $$$Q$$$ lines describes a candidate move that either the iguana playing the black tiles or white tiles would like you to consider. It is guaranteed that the square specified by the given coordinates is an empty square.
For each of the $$$Q$$$ candidate moves, output a single line. If placing a tile of color $$$T$$$ at position $$$X$$$, $$$Y$$$ (in row-major order) on the board would lead to a group of tiles of the same color as $$$T$$$ becoming surrounded, output "No go!" (without quotes). Otherwise, output "Go!" (no quotes).
The output for the queries should be in the same order as the queries themselves, though the moves are not persistent; each queried move does not persist for the duration of the test case and is instead simply a candidate move.
3 3 4 .BW B.W WWW B 1 1 B 2 2 W 1 1 W 2 2
Go! Go! No go! No go!
Ivan and Isabel are iguanas who live in the Iguana Islands. The archipelago consists of $$$N$$$ islands ($$$1 \leq N \leq 2*10^5$$$), indexed from $$$1..N$$$ and arranged in line in the order of their indices, each of which consists of a single type of fruit denoted as $$$f_i$$$. The amount of fruit on island $$$i$$$ is denoted as $$$q_i$$$. ($$$1 \leq f_i, q_i \leq 10^9$$$). The fruits on these islands are special, and can only be eaten in quantities of $$${f_i}^k$$$, where k is a non-negative integer ($$$0 \leq k$$$). During each of the next Q days ($$$1 \leq Q \leq 2*10^5$$$), the following will happen:
For each of the $$$Q$$$ days, determine which iguana will be well-fed, assuming the iguanas are very intelligent, and will always make the decision which minimizes their chance of starving at the end of the day.
The first line of input will contains integers $$$N$$$ and $$$Q$$$. ($$$1 \leq N, Q \leq 2*10^5$$$) The second line will contain $$$N$$$ space-separated integers $$$f_1 ... f_N$$$, denoting the type of fruit on each island. ($$$1 \leq f_i \leq 10^9$$$) Similarly, the third line will contain $$$N$$$ integers $$$q_1 ... q_N$$$, representing the amount of fruit on each island. ($$$1 \leq q_i \leq 10^9$$$) The next $$$Q$$$ lines will describe which islands are available on each day, which is represented by two integers $$$l_i$$$ and $$$r_i$$$. ($$$1 \leq l_i \leq r_i \leq N$$$)
For each day, output a line consisting of the word "Ivan" if Ivan will be well-fed that day, and "Isabel" otherwise.
6 5 1 1 3 2 4 6 5 8 5 6 9 6 1 2 1 3 2 4 4 5 1 6
Ivan Isabel Ivan Ivan Isabel
3 6 56 78 65 983 834 721 1 1 1 2 1 3 2 2 2 3 3 3
Isabel Isabel Ivan Isabel Ivan Ivan
Rory the Reptile Rescuer is trying to teach their iguana some new tricks!
For this trick, Rory sets up $$$n$$$ stacks of blocks on a table, where the $$$i$$$th stack contains $$$a_i$$$ blocks. The iguana will then perform a series of block moves, where it moves a block from one stack to an adjacent one. The iguana can also push a block from stack $$$1$$$ or $$$n$$$ off the table. After the iguana performs all of its moves, the $$$i$$$th stack should now contain $$$b_i$$$ blocks.
Rory is worried that training the iguana to do this will take a lot of time, and wants to minimize the number of moves the iguana must perform to transform the block display. Can you help Rory?
The first line contains $$$n$$$ ($$$1 \leq n \leq 10^5$$$), the number of stacks. The second line contains $$$n$$$ integers, $$$a_1, \ldots, a_n$$$ ($$$0 \leq a_i \leq 10^{12}$$$), the number of blocks in each stack initially. The last line contains $$$n$$$ integers, $$$b_1, \ldots, b_n$$$ ($$$0 \leq b_i \leq 10^{12}$$$), the number of blocks that each stack should have at the end of the trick.
Output a single integer, the minimum number of adjacent block moves (including pushing a block off the table) the iguana needs to achieve the desired block display, or $$$-1$$$ if it is not possible.
5 1 2 3 4 5 5 4 3 2 1
20
3 10 1 10 1 5 1
18
5 0 0 0 0 0 10 10 10 10 10
-1
10 79 94 92 29 10 81 76 31 64 33 12 46 2 14 89 90 34 51 64 13
472