UTPC Contest 10-11-24 Div. 1 (Advanced)
C. Egg Order
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Eggo has $$$n$$$ eggs, one of each size from $$$1$$$ to $$$n$$$. He wants to figure out what order to place the eggs. A powerful subarray is one where each element is one size greater than the previous. More formally, if $$$b_1, b_2, \dots, b_k$$$ are the sizes of the eggs in the subarray, then the subarray is powerful if $$$b_i - b_{i - 1} = 1$$$ for $$$2 \leq i \leq k$$$. The power of a configuration of eggs is the size of the largest powerful subarray.

You want the power of the configuration to exactly equal $$$k$$$. Can you place the eggs such that the power equal $$$k$$$? If multiple answers exist, print any.

An array $$$b$$$ is a subarray of an array $$$a$$$ if $$$b$$$ can be obtained from $$$a$$$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. Note that an array is a subarray of itself.

Input

The first and only line of input consists of two integers $$$n$$$ and $$$k$$$ ($$$1 \leq k \leq n \leq 2 \cdot 10^5$$$) — the number of eggs and the desired power, respectively.

Output

Print $$$n$$$ space-separated integers $$$a_1, a_2, \dots, a_n$$$ — the order of eggs that gives the desired power.

Example
Input
5 3
Output
5 2 3 4 1

D. Scrambled!
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Oh goodness... Sean accidentally mixed up his eggs with a can of alphabet soup, and now everything's all scrambled together! Now he needs your help to rearrange the letters in the alphabet soup and restore peace to the egg-iverse.

Sean's suspicious egg-soup mixture can be represented as a series of $$$n$$$ spaghetti letters. He knows that two conditions used to be true of his letters before they got scrambled into the eggs:

  1. When put in a row, his letters would form a palindrome, a string which is read the same forwards and backwards. Put more formally, if his letters were labelled $$$s_1, s_2, \dots, s_n$$$, then it is the case that $$$s_i = s_{n - i + 1}$$$ for each $$$i \in \{1, 2, \dots, n\}$$$.
  2. Of all possible palindromes, his letters would form the lexicographically smallest one.

Sean knows for certain that it is possible for him to arrange the scrambled up spaghetti letters to fulfill both constraints simultaneously, but he's busy at the moment researching possible egg-spaghetti hybrids, and needs your help to unscramble his soup!

Input

The input will consist of a single line containing a single string of length $$$n$$$ ($$$1 \leq n \leq 10^5$$$) consisting exclusively of lowercase English letters — the scrambled-up spaghetti letters found in Sean's egg soup.

Output

The output should consist of a single line containing a single string representing the unscrambled contents of Sean's egg soup as described by the rules above.

Examples
Input
racecar
Output
acrerca
Input
aabbccdde
Output
abcdedcba
Input
ajcvoiwqnexajcvoiwqnex
Output
aceijnoqvwxxwvqonjieca
Note
  • In the first sample test case, "racecar" itself is a palindrome, but not the lexicographically smallest palindrome which can be created using the same set of letters.
  • In the second sample test case, the letters are already arranged in lexicographical order, but they do not immediately form a palindrome.

E. Yodel Yolk
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Sierra lives in the mountains where it occasionally rains egg yolk. During these storms, yolk pools in the valleys between mountain peaks. Sierra is curious about these pools and would like to know the total volume of the pool with the highest surface elevation.

The topology of the mountain range can be represented by $$$n$$$ integers, where $$$h_i$$$ describes the elevation of the $$$i$$$th location in this range. Some space above a location is considered "part of a pool" if there exist locations to the left and the right of the space with higher or equal elevations. A pool's surface height is defined by the minimum elevation of its immediate neighbors. In cases where there are ties, return the sum of the volumes of all highest pools.

Input

The first line contains a single integer $$$n$$$ ($$$1 \leq n \leq 10^5$$$) — the number of locations in the range.

The next line contains the array $$$h_1, h_2, \dots, h_n$$$ ($$$1 \leq h_i \leq 10^9$$$) — the heights of the locations in the range.

Output

Output the volume of the highest pool. If there are multiple pools at the same height, print the sum of their volumes.

Example
Input
8
1 4 8 2 2 8 1 7
Output
12
Note

There are two pools in the input: one above locations 4 and 5 at a height of 8, and one above location 7 with a height of 7. The first pool is higher, and it has a volume of 12.

F. Incubation Line
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Eggward is working on a hobby project and recently acquired $$$n$$$ eggs that he wants to try and hatch that are stuck at fixed positions along a number line. He has some heat lamps, and he wants to keep the eggs close to the heat lamps in order to ensure they receive the warmth they need. Unfortunately, he only has $$$k$$$ heat lamps to incubate these eggs with. His goal is to minimize the maximum distance from any egg to its nearest heat lamp. Help him find this distance. The lamps are hung above the eggs so they can be at the same position on the number line, and all lamps must be at integer positions.

Input

The first line will contain two space-separated integers $$$n$$$ and $$$k$$$ ($$$1 \leq n \leq 5 \cdot 10^5$$$, $$$1 \leq k \leq n$$$) — the number of eggs and the number of heat lamps respectively.

The following line will contain $$$n$$$ integers $$$a_i$$$ ($$$-10^9 \leq a_i \leq 10^9$$$) indicating the position of the $$$i^{\text{th}}$$$ egg. Furthermore, the $$$a_i$$$ are guaranteed to be distinct, that is, if $$$i \neq j$$$, then $$$a_i \neq a_j$$$.

Output

Output one integer indicating the minimal possible max distance from any egg to its nearest heat lamp.

Examples
Input
3 2
0 5 7
Output
1
Input
5 2
-2 1 0 -1 4
Output
2
Note

Sample 1 Explanation: We can place one heat lamp at 0, and another at 6. The distance from the 0 egg to its nearest lamp is 0. The distance from the 5 and 7 eggs to their nearest lamp is 1. Thus, the minimum max distance we can achieve is 1.

Sample 2 Explanation: We can place one heat lamp at 0, and one heat lamp at 2. Then every egg is at most 2 away from the nearest lamp.

G. The Chicken and the Egg
time limit per test
3 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

What came first, the chicken or the egg? This is one of life's biggest mysteries, but your friend Chris thinks he can solve it.

He hypothesizes that whichever came first should have had more time to evolve and should thus be faster.

To test this, he has made a maze. The maze can be represented as a directed graph with $$$n$$$ nodes and $$$m$$$ edges. Among these $$$n$$$ nodes, there are $$$a$$$ entrances and $$$b$$$ exits. Because chickens and eggs are shaped differently, they take $$$c_i$$$ and $$$e_i$$$ time to traverse edge $$$i$$$, respectively.

First, Chris will test a chicken. He will uniformly randomly pick an entrance to place the chicken and time how long it takes for the chicken to reach any exit. He will then similarly pick a random entrance for the egg and time it. He plans to let the chicken and egg study the maze beforehand so that they both take their respective fastest routes to any exit.

If a chicken or egg starts at a node that can't reach an exit, it can never finish. If they both never finish, it is a tie.

Knowing you are a mathematician, Chris wants to know who you think will win.

Input

The first line contains 4 space-separated integers $$$n$$$, $$$m$$$, $$$a$$$, and $$$b$$$ ($$$1 \leq n,m \leq 2 \cdot 10^5$$$, $$$1 \leq a, b \leq n$$$, $$$2 \leq a + b \leq n$$$) — the number of nodes, number of edges, the number of entrances, and the number of exits, respectively.

The following $$$m$$$ lines each contain four integers $$$u$$$, $$$v$$$, $$$c$$$, and $$$e$$$ ($$$1 \leq u, v \leq n$$$, $$$1 \leq c, e \leq 10^9$$$) – denoting a directed edge between nodes $$$u$$$ and $$$v$$$ that will take chickens and eggs time $$$c$$$ and $$$e$$$ to traverse, respectively.

The next line contains $$$a$$$ distinct space-separated integers $$$s_1, \dots, s_a$$$ ($$$1 \leq s_i \leq n$$$) – the nodes that are entrances.

The next line contains $$$b$$$ distinct space-separated integers $$$t_1, \dots, t_b$$$ ($$$1 \leq t_i \leq n$$$) – the nodes that are exits.

It is guaranteed that no node is both an entrance and an exit. There can be double edges.

Output

Output "chicken" if it is more likely for the chicken to win, "egg" if it is more likely for the egg to win, and "tie" if they have equal probability of winning.

Examples
Input
3 3 1 1
2 1 1 1
1 3 2 1
2 3 3 3
2
3
Output
egg
Input
5 6 3 2
1 2 1 2
1 3 3 1
2 3 2 2
1 4 1 10
3 4 3 2
3 5 1 3
1 2 3
4 5
Output
chicken
Input
4 2 2 2
1 3 2 1
2 4 1 2
1 2
3 4
Output
tie

H. Chicken Farm
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Alice is playing a popular block game, and has $$$n$$$ days to collect as many eggs as she can. Alice initially has 1 chicken that lays an egg every day and needs 1 night of sleep. Every day, she can throw as many eggs as she wants to hatch more chickens.

Alice knows the seed of her game generated world, which gives her some additional information. In fact, she knows how many eggs she must throw to hatch another chicken, and how many nights of sleep each chicken needs before laying an egg. In fact, these values follow a predictable pattern. Help Alice find the maximum amount of eggs that she can have in $$$n$$$ days.

Note that throwing an egg requires that you have at least 1 egg, and the act of throwing an egg decreases the amount of eggs you have by 1.

Input

The first line of input will contain the integers $$$n$$$ ($$$1 \leq n \leq 60$$$) and $$$m$$$ ($$$1 \leq m \leq 10^4$$$), the number of days Alice has to collect eggs and the length of the arrays containing each chicken's information.

The second line of input will contain $$$m$$$ integers $$$c_1, c_2, ..., c_m$$$ ($$$1 \leq c_i \leq n$$$), where $$$c_i$$$ represents the hatching cost of chickens $$$i, i + m, i + 2m, ...$$$.

The third line of input will contain $$$m$$$ integers $$$r_1, r_2, ..., r_m$$$ ($$$1 \leq r_i \leq n$$$), where $$$r_i$$$ represents the number of nights of sleep needed by chickens $$$i, i + m, i + 2m...$$$ beforing laying an egg.

Note that Alice may hatch more than $$$m$$$ chickens. The pattern repeats once the $$$m-th$$$ chicken is hatched, and the $$$m+1th$$$ chicken has the same hatching cost and sleep requirement as the first hatched chicken.

Examples
Input
8 3
1 2 1
1 2 3
Output
23
Input
7 1
1
1
Output
64
Input
10 2
1 2
2 1
Output
37

I. Rolling Egg
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Rocq the rooster owns a single egg. One day, he came back home and noticed his egg was missing! The egg is rolling around in a field — in fact, the field $$$\mathbb{Z}_p$$$, where $$$p$$$ is a prime. His egg has been studying number theory, and he knows that his egg used the following procedure to determine what path to roll away with:

  1. Pick some (uniformly) random starting location $$$x_0 \in \mathbb{Z}_p$$$.
  2. Pick some (uniformly) random polynomial $$$f \in \mathbb{Z}_p[x]$$$.
  3. For times $$$t \gt 0$$$, the egg will roll from $$$x_{t - 1}$$$ to $$$x_t := f(x_{t - 1})$$$.

It is guaranteed the egg will eventually roll in a cycle between different locations. If Rocq can find out the expected length of the cycle, he can somehow catch the egg. Given the prime $$$p$$$, help him by finding this expectation! He doesn't like decimals, so output the answer mod $$$998244353$$$.

More formally, let $$$P = 998244353$$$. It can be shown that the answer can be represented as an irreducible fraction $$$\frac{a}{b}$$$, where $$$a$$$ and $$$b$$$ are integers and $$$b \not\equiv 0 \pmod P$$$. Output the integer $$$x$$$ such that $$$0 \leq x \lt P$$$ and $$$x \equiv a \cdot b^{-1} \pmod P$$$.

Input

The input will consist of a single integer $$$p$$$ ($$$1 \leq p \leq 2 \cdot 10^5$$$) — the size of field the egg travels in. It is guaranteed that $$$p$$$ is a prime.

Output

Output the expected length of the cycle the egg ends up in, mod $$$998244353$$$.

Examples
Input
2
Output
748683266
Input
5
Output
760262901
Note

The answer for the $$$p = 2$$$ is $$$\frac{5}{4}$$$, and $$$5 \cdot 4^{-1} \bmod 998244353 = 748683266$$$.

J. Egg Placement
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Beggsie the chicken needs you to solve a problem in Farmer John's farm. The farm can be represented as a two dimensional grid. Further, there are $$$n$$$ eggs on the farm, where the $$$i$$$th egg is at position $$$(x_i, y_i)$$$.

The compactness of the farm can be represented by the sum of Manhattan distances between each pair of eggs. Formally, if $$$(x_i', y_i')$$$ is the current position of the $$$i$$$th egg, then the compactness given by $$$\sum\limits_{i=1}^n \sum\limits_{j=i+1}^n (|x_i' - x_j'| + |y_i' - y_j'|)$$$.

There are $$$d$$$ days, and during the $$$i$$$th day there are $$$s_i$$$ seconds. During each second, Beggsie can choose to move a single egg in one of the four cardinal directions, or to not move anything. Now, let $$$c_i$$$ be the compactness of the farm after day $$$i$$$. Farmer John wants Beggsie to minimize the value of $$$\sum\limits_{i=1}^d c_i$$$. Please help Beggsie by finding the minimum such value!

Input

The first line of input will contain $$$n$$$, $$$d$$$. ($$$1 \leq n, d \leq 2 \cdot 10^5$$$) — the number of eggs in the farm, and the number of days during which Beggsie can move eggs.

The $$$i$$$th of the next $$$n$$$ lines of input will contain $$$x_i$$$ and $$$y_i$$$ ($$$1 \leq x_i, y_i \leq 10^6$$$) — the position of the $$$i$$$th egg in the farm.

The last line of input will contain $$$d$$$ space-separated integers $$$s_1, s_2, \cdots, s_n$$$ ($$$1 \leq s_i \leq 10^6$$$) — the number of seconds in each day.

Output

Output a single integer, denoting the minimum value of $$$\sum\limits_{i=1}^d c_i$$$. Since this integer may be extremely large, output it modulo $$$998244353$$$.

Examples
Input
2 3
1 1
4 3
1 1 1
Output
9
Input
3 3
3 1
2 1
5 1
2 1 1
Output
2
Input
5 3
1 1
4 5
6 3
2 3
9 8
3 4 7
Output
126