Santa is sad today, and to cure his sadness, he has decided to gamble his troubles away in a game of dice. The casino attendant rolls a huge 1000-sided dice which has numbers from $$$1$$$ to $$$1000$$$; if the number that comes up on top has only odd digits, the player wins, otherwise, the house wins. Santa is naturally happier when winning at games of chance, and he becomes happy if and only if the number $$$n$$$ that is rolled is a winning number for him. Given $$$n$$$, will Santa be happy?
The first line of input will contain $$$n (1 \le n \le 1000)$$$, the number that Santa rolled.
Output "HAPPY" if Santa will become happy, and "SAD" if Santa stays sad.
13
HAPPY
21
SAD
Santa has gotten quite old and is entering retirement. To get ready, he'd like to practice playing some bingo.
Santa plays a special type of bingo on a $$$N \times N$$$ grid, where each cell contains a unique number between $$$1$$$ and $$$N^2$$$. Some permutations of these numbers are called out successively. When a full row or column is called out, Santa wins!
Given Santa's board and the order in which the numbers are called, determine which number Santa will win with.
A single integer, $$$2 \leq N \leq 100$$$.
An $$$N \times N$$$ grid with numbers $$$1...N^2$$$, showing the board
The $$$N^2$$$ numbers, in the order they're called
The number that will cause Santa to win
3 2 7 9 8 3 1 6 5 4 4 6 8 7 5 3 2 9 1
5
Note that the first row/column to fill up is the bottom row.
Santa needs to deliver gifts to all the inhabitants of Speedway! Unfortunately, as it doesn't snow on Speedway (mostly), his sleigh will damage the nice brickwork!
As we all know, Speedway is built in a line, conveniently segmented into $$$N$$$ locations. Although speedy, Santa's delivery system hasn't been fully optimized, so he travels back-and-forth to deliver these gifts.
Beginning at the first provided location, Santa will travel between all $$$N$$$ of these locations. When Santa travels between a location $$$A$$$ and $$$B$$$, he creates one unit of damage at each location between $$$A$$$ and $$$B$$$ (including $$$A$$$, not including $$$B$$$).
To help the UT Maintenance team, please determine how much total damage is caused by Santa's sleigh.
The first line of input contains a single integer $$$N$$$, where $$$2 \leq N \leq 1000$$$.
Then $$$N$$$ more lines follow, each containing a single integer, representing all the buildings in the order in which he visits them.
A single integer, the total damage that Santa's sleigh creates on Speedway.
2 2 1
1
3 3 1 2
3
Santa has decided he wants to be lazy this year. Instead of delivering his presents himself, he has decided that he wants his elves to do it. Fortunately, Santa has an infinite number of elves at his disposal, and fortunately, $$$k$$$ elves volunteered to deliver presents to the $$$k$$$ houses that need presents to be delivered to.
There are $$$n + 1$$$ total locations in the world that Santa's elves can travel to, with location $$$0$$$ being the North Pole, where Santa and his elves currently reside. There are $$$k$$$ locations such that houses exist, and there are $$$m$$$ bidirectional pathways that connect two locations $$$m_u, m_v$$$ with a travel time of $$$m_c$$$ seconds. If two locations are not connected by any series of pathways, then trying to travel between them is infeasible. There may be multiple pathways between two houses, but it is guaranteed that all houses are reachable from location 0.
Given that each elf is assigned to one house and takes the most optimal route to and from their designated house, Santa is curious about two things. First, Santa wants to know the total travel time for all elves. Second, Santa wants to know the maximum travel time for any elf. Help Santa find the answer to his two questions!
The first line of the input will contain three space separated integers $$$n (1 \le n \le 10^4), k (1 \le k \le n), m (1 \le m \le 10^5)$$$, where $$$n + 1$$$ is the number of locations, $$$k$$$ is the number of houses, and $$$m$$$ is the number of pathways.
The next $$$k$$$ lines of input will each contain a number $$$k_i$$$ ($$$1 \leq k_i \leq n$$$) representing a house at location $$$k_i$$$. It is guaranteed all house locations are unique.
The next $$$m$$$ lines of input after that will each contain 3 space separated integers $$$m_u, m_v, m_c$$$, where $$$0 \le m_u, m_v \le n$$$, $$$m_u \neq m_v$$$, and $$$1 \le m_c \le 10^3$$$.
Output two space separated integers, the first being the total travel time for all the elves, and the second being the longest travel time of any elf.
5 3 6 3 5 4 2 3 5 4 2 2 0 4 2 2 1 6 1 5 9 5 1 4
50 28
The winter season fills Meredith's heart with joy and warmth, and there is no better outlet for her to express her appreciation apart from constructing the most magnificent holiday wreath! In fact, Meredith wants to make as large a wreath as possible, given her materials. She has plucked two branches from a tree and will construct her wreath by attaching the two branches together, using two small and flexible twigs. Help Meredith make the biggest wreath possible!
The first line of input will contain an integer $$$V_1$$$ ($$$1 \leq V_1 \leq 10^6$$$) denoting the number of vertices in Meredith's first branch. $$$V_1 - 1$$$ lines follow, each containing two space-separated integers $$$u$$$ and $$$v$$$ which represent endpoints for an edge in the tree. (Observe that, in general, any tree with $$$n$$$ vertices has exactly $$$n - 1$$$ edges). Then the next line of input contains $$$V_2$$$ ($$$1 \leq V_2 \leq 10^6$$$), the number of the vertices in the second branch. $$$V_2 - 1$$$ lines follow after that, containing the edges for the second tree. You are guaranteed that the depth of either tree (from any root) will not exceed $$$50$$$.
Print the length of the longest simple cycle Meredith could create by connecting her two branches (trees) with two edges.
7 4 6 2 3 1 7 7 2 5 1 4 7 5 3 2 2 4 5 3 3 1
9
Recently, Santa's elves went rogue and commandeered his sleigh! Rather than dropping off presents to where they are supposed to go, the elves are randomly tossing presents off the sleigh random times.
Fortunately, through a double-agent elf, Santa has determined the locations and times where the presents will be dropped. Unfortunately, the presents will be stolen by angry Canadian children (who happened to not get gifts this year) exactly 5 minutes after they are initially dropped, so Santa must be quick to pick up as many presents as he can to be delivered correctly later. The elves also want to spread out their present drops over a longer period of time, so it is guaranteed that any two present drops will be at least 5 minutes apart.
You are given a 2D square grid representing the area where elves are dropping presents and a list of present drop times and coordinate locations. In one minute, Santa can take a single step in one of the four cardinal directions or stay in place. Figure out Santa's optimal path to pick up as many presents as possible before the presents are taken and output the maximum number of presents that Santa can get.
The first line consists of $$$4$$$ integers, $$$N$$$ ($$$1 \leq N \leq 750$$$), $$$P$$$ ($$$1 \leq P \leq 1000$$$), $$$s_x$$$, $$$s_y$$$ ($$$1 \leq s_x, s_y \leq N$$$). This gives the size of the 2D square grid, number of presents that the elves will drop, and Santa's starting $$$x$$$ and $$$y$$$ coordinate, respectively. The next $$$P$$$ lines consist of three integers, $$$t_i, x_i, y_i$$$ ($$$1 \leq t_i \leq 10^6$$$), ($$$1 \leq x_i, y_i \leq N$$$), which give the time (in minutes) and location of a present drop.
Output a single integer giving the maximum number of presents that Santa can successfully collect.
5 3 1 1 1 1 1 6 5 5 11 1 1
2
10 5 1 1 23 10 3 13 10 1 18 9 1 28 10 7 8 1 10
4
In the first sample, Santa can collect the first present at time $$$1$$$, the second present at time $$$9$$$, but does not have time to get back to collect the final gift (which disappears at time $$$16$$$)
Santa is delivering presents and has one last stop tonight at the coordinates $$$(x, y)$$$ - we are representing the world as a 2D plane for simplicity. He takes a quick break at the coordinates $$$(0,0)$$$ where he decides to update the steering software on his sled. Unfortunately, the update has messed up the steering software and Santa finds out that the sled will only follow the directions in the order specified by a string $$$s$$$ which consists of the characters U, L, D, and R.
Given that the sled will perform these operations from $$$s$$$ left to right and repeat that an infinite number of times, figure out if Santa will ever end up reaching his destination at $$$(x, y)$$$.
The first line of input contains two space-separated integers $$$x$$$ and $$$y$$$ representing the coordinates that Santa is trying to get to ($$$-10^{18} \leq x, y \leq 10^{18}$$$).
The second and last line of input contains a string $$$s$$$ ($$$1 \leq |s| \leq 10^{5}$$$) representing the series of directions that Santa's sled will go ($$$s$$$ will only contain the characters U, L, D, and R).
Output Yes if the sled will ever reach the coordinates $$$(x, y)$$$ and No otherwise.
2 2 UR
Yes
1 2 RU
No
-1 1000000000000000000 LRRLU
Yes
In example 1, after going through UR once, Santa is at (1,1) and then going through that again gets Santa at (2,2) which is the goal.
The elves are creating an ID label for a toy part but their supervisor has a very weird, specific rule. The supervisor has a favorite number, and the ID label the elves must create must be divisible by this special number. The supervisor also hates the numbers 2 and 5, and his favorite number will not be divisible by either.
However, the label printer was recently used by a nefarious being to try to sabotage Christmas, and is freshly out of ink! The only thing the elves have is a printed label of a GINORMOUS integer. The label printer also does not have a 0 digit.
The elves realize that there might be ways to cut the label such that they can create a label with an ID divisible by the supervisor's favorite number, and would like to know how many ways they can do so. The resulting label must be a contiguous portion of the original, and the elves only need one label.
In other words, find the number of ways to remove some (possibly zero) digits from the front and back such that the resulting (nonempty) label is divisible by the supervisor's favorite number.
First line with $$$N$$$, the ginormous integer printed by the nefarious being $$$1 \leq N \leq 10^{10^6}$$$. No digit in $$$N$$$ is 0.
Second line with K, the supervisor's favorite integer $$$1 \leq K \leq 5000$$$, where $$$K$$$ is not divisible by 2 or 5.
One integer denoting the number of ways to cut the label.
72476 3
3
19987589742315 19
6
61413 4553
0