2022-2023 ACM-ICPC German Collegiate Programming Contest (GCPC 2022)
A. Alternative Architecture
time limit per test
1 second
memory limit per test
512 megabytes
input
standard input
output
standard output

In his free time, Thomas greatly enjoys working on the extensive Lego project that he has built in his attic, adding house after house to his miniature city. However, he has become a bit bored with the completely rectangular layout that is enforced by the little studs of the huge base plate that his city is built on.

After an exchange with some other Lego creators he came across a technique that will allow him to place his buildings at different angles. Each building rests on a rectangular ground plate, to the underside of which he attaches four round $$$1\times 1$$$-plates in the corners. These $$$1\times 1$$$-plates are then placed on four studs of the base plate, like in Figure 1 above.

If the ground plate of the building is $$$a\times b$$$ studs, what is the number of orientations it can be placed in using this technique, so that all the corner plates exactly fit on studs of the base plate?

Input

The input consists of:

  • One line with two integers $$$a$$$ and $$$b$$$ ($$$2 \le a,b \le 10^6$$$), the dimensions of the ground plate the building is resting on.
Output

Output one integer, the number of different orientations the ground plate can be placed in.

Examples
Input
6 11
Output
6
Input
26 26
Output
5
Input
123 456
Output
2
Input
3 3
Output
1

B. Breeding Bugs
time limit per test
1 second
memory limit per test
512 megabytes
input
standard input
output
standard output

This year is a good year for North America. 2022 is one of the few years where no brood of the periodical cicada is hatching and thus, no swarms will destroy the crops on the fields.

Those periodical cicadas have a somewhat strange property: They have highly synchronized life cycles, which means that almost all individuals in a local population emerge in the same year, resulting in periodical cicada plagues. Even odder is the fact that the periodicities of those life cycles appear to be prime, for example 13 or 17 years. The best theory for this so far is that a prime periodicity lets them avoid predators with shorter population cycles since a brood emergence of cicadas will rarely coincide with a predator's population boost.

But nobody likes cicada plagues, so this prime periodicity is now your problem. Your hope is that cicadas with non-prime periodicity will not be able to avoid predators anymore and that there will be fewer cicada plagues as a result. So, to prevent the next plague, you forge a plan to breed different cicada types to get a new type with non-prime periodicity. If you mate a cicada of a type with periodicity $$$a$$$ with another cicada of a type with periodicity $$$b$$$, you assume to get a cicada of a type with periodicity $$$a+b$$$. You have already captured $$$n$$$ cicadas to breed but you don't know which will mate. Therefore, you decided to set some cicadas free such that the remaining ones can mate this year in any way they want without producing a cicada of a type with prime periodicity. How many of your cicadas can you keep at most?

Input

The input consists of:

  • One line with a single integer $$$n$$$ ($$$1\leq n \lt 750$$$), the number of cicadas.
  • One line with $$$n$$$ integers $$$p_1, \ldots, p_n$$$ ($$$1\leq p_i \lt 10^7$$$), where $$$p_i$$$ denotes the periodicity of the $$$i$$$th cicada.
Output

Output a single integer, the maximum number of cicadas you can keep.

Examples
Input
8
1 2 3 4 5 6 7 8
Output
4
Input
5
7 13 2 2 4
Output
4

C. Chaotic Construction
time limit per test
2 seconds
memory limit per test
512 megabytes
input
standard input
output
standard output

The city Gircle has only one street, and that street is cyclic. This was very convenient in times when people didn't carry a device with compass, GPS and detailed maps around in their pockets, because you only have to walk in one direction and will certainly arrive at your destination. Since Gircle's founding a lot of time has passed. Civil engineers now know a lot more about road network design and most people have immediate access to reliable and accurate navigation systems. However, the passage of time also affected the old street surface and more and more cracks and potholes appeared.

The local government has finally decided to improve the situation, but preserving the city's historic appeal and building new streets are unfortunately mutually exclusive. Because tourism is vital for Gircle's economy, the government's only viable option for improving the situation is to renovate segments of the street when necessary. Gircle's street is very narrow, so a construction site at a street segment makes it impossible for citizens to pass that segment or even leave or enter it.

As a member of the Gircle Construction and Planning Commission (GCPC), you always know when one of the $$$n$$$ street segments is closed or reopened. Naturally, the citizens expect you to tell them whether the trips they want to do are currently possible.

Figure 1. Depiction of the query "? 9 7" in the sample input.
Input

The input consists of:

  • One line with two integers $$$n$$$ ($$$2 \leq n \leq 10^5$$$) and $$$q$$$ ($$$1 \leq q \leq 10^5$$$), the number of street segments and the number of events. No street segment is initially closed.
  • $$$q$$$ lines, each describing an event. Each event is described in one of the following ways:
    • "- a": Segment $$$a$$$ ($$$1 \leq a \leq n$$$) is closed. It is guaranteed that segment $$$a$$$ was open before.
    • "+ a": Segment $$$a$$$ ($$$1 \leq a \leq n$$$) is reopened. It is guaranteed that segment $$$a$$$ was closed before.
    • "? a b": A person asks you if it is possible to go from segment $$$a$$$ to segment $$$b$$$ ($$$1 \leq a, b \leq n \text{ and } a\neq b$$$).
Output

For each event of the form "? a b", print one line containing the word "possible", if it is possible to move from segment $$$a$$$ to segment $$$b$$$, or "impossible" otherwise. If $$$a$$$ or $$$b$$$ are currently closed, the answer is "impossible".

Example
Input
10 12
? 1 5
- 2
- 8
? 9 2
? 9 8
? 9 7
? 6 7
? 3 7
? 1 9
? 9 1
+ 8
? 10 3
Output
possible
impossible
impossible
impossible
possible
possible
possible
possible
possible

D. Diabolic Doofenshmirtz
time limit per test
1 second
memory limit per test
512 megabytes
input
standard input
output
standard output

Each year, the fastest platypuses of the world come together for the Great Crawling Platypus Cup (GCPC) to crawl a single lap in the platypus arena. Of course, Perry the platypus wants to take part in this great event. Perry's arch enemy Dr. Doofenshmirtz got wind of it and plans to capture Perry right when he crosses the finish line at the GCPC. To carry out his evil plan successfully, he needs to find out how long Perry needs to finish the lap. He knows that Perry takes the preparation for the GCPC very seriously and trains by crawling lap after lap in the arena at a constant speed of $$$1\,\frac{\text{m}}{\text{s}}$$$. Perry's training starts this Saturday and Dr. Doofenshmirtz knows that he will run at least $$$10^{18}$$$ seconds. To determine the exact length of one lap, Dr. Doofenshmirtz invented the Measurinator which can measure the exact distance Perry has already crawled in his current lap. Unfortunately, the Measurinator will break after too many measurements, so Dr. Doofenshmirtz has to carefully plan when to use it in order to determine the length of one lap.

Interaction

Your submission can print "? t" where $$$t$$$ ($$$0\leq t \lt 10^{18}$$$) is the point in time when you want to use the Measurinator. The time $$$t=0$$$ marks the point in time where Perry starts practicing i.e. where he starts his first lap at the start and finish line. The Measurinator responds with a single integer $$$x$$$ which is the current position of Perry in his current lap. Note that the Measurinator will not respond with the number of meters Perry has already crawled in total! Thus, whenever Perry reaches the start and finish line, the Measurinator will respond with $$$0$$$. Further note that you recently lost your Timetravellinator and therefore, the values of $$$t$$$ must be strictly increasing.

If you determined the length $$$x$$$ of one lap, print "! x". After this, your program should immediately terminate.

All interactions must be ended by a newline. Further note that you additionally need to flush the standard output to ensure that the query is sent. For example, you can use:

  • std::cout <{}< std::flush in C++
  • fflush(stdout) in C
  • System.out.flush() in Java
  • sys.stdout.flush() in Python

Your submission is considered correct if you followed these rules, found the correct length of one lap, and used no more than $$$42$$$ queries. Note that giving the answer is also counted as a query.

It is guaranteed that one lap has integer length, is at least one meter long, and at most $$$10^{12}$$$ meters long.

A testing tool is provided to help you develop your solution. It can be downloaded from the DOMjudge problems overview page.

Examples
Input

1

2

3

4

16
Output
? 1

? 2

? 3

? 4

? 100

! 42
Input

10

20

30

40

641
Output
? 10

? 20

? 30

? 40

? 10000

! 1337

E. Enjoyable Entree
time limit per test
1 second
memory limit per test
512 megabytes
input
standard input
output
standard output

For many days now, the canteen in Hilbert's Hotel has been offering its famous Fibonacci Soup. Today is the $$$n$$$th day that they offer the soup, and the recipe changes every day:

  • On the first day, it is a $$$\pi$$$-tato soup, made from a blend of local potato varieties, and served with onion strips and celery.
  • On the second day, it is a $$$\tau$$$-mato soup, consisting of pur'eed tomatoes, together with carrots, onions, garlic, and basil leaves on top.
  • On every day after that, the soup is made from two ingredients, the soup of the previous day and the soup of the day before that, mixed together in equal parts.

Find the composition of today's Fibonacci Soup.

Input

The input consists of:

  • One line with a single integer $$$n$$$ ($$$1 \le n \le 10^{18}$$$), the current day.
Output

Output two real numbers $$$\pi$$$ and $$$\tau$$$ ($$$0 \le \pi,\tau \le 100$$$), giving the percentages of $$$\pi$$$-tato soup and $$$\tau$$$-mato soup in the $$$n$$$th day's Fibonacci soup. Your answer will be accepted if the absolute or relative error is at most $$$10^{-6}$$$.

Examples
Input
1
Output
100 0
Input
3
Output
50 50
Input
7
Output
34.375 65.625

F. Formula Flatland
time limit per test
3 seconds
memory limit per test
512 megabytes
input
standard input
output
standard output

Flatland is happy to announce that this year – for the first time ever – the Formula One comes to Flatland to arrange the Grand Prix of Flatland. As with many other cities, Flatland is not able to build a dedicated circuit for the race. Therefore, Flatland decided to close off some of its normal streets and crossings to form a circuit. After your excellent work as an organizer of last year's Flatland Olympics, you were hired to find a suitable circuit. Since closed off streets are annoying to the people who live there, you would like to minimize the number of crossings that need to be closed off for the race.

Visualization of the second sample. One possible optimal circuit would be: $$$(4,5,7,6)$$$.

Your job only consists of selecting some road segments which form a circle but are connected by as few crossings as possible. Note that even though all roads in Flatland are bidirectional, they can only be used in one direction during the race for safety reasons.

Input

The input consists of:

  • One line with two integers $$$n$$$ and $$$m$$$ ($$$4\leq n \leq10^5\text{ and }5\leq m\leq3\cdot10^5$$$), the number of crossings and the number of road segments in Flatland.
  • $$$n$$$ lines, each with two integers $$$x$$$ and $$$y$$$ ($$$0\leq x,y\leq10^9$$$), the $$$i$$$th line describes the position of the $$$i$$$th crossing on a map of Flatland. No two crossings are at the same position.
  • $$$m$$$ lines, each with two integers $$$a$$$ and $$$b$$$ ($$$1\leq a,b\leq n\text{ and }a\neq b$$$), describing that the $$$a$$$th and $$$b$$$th crossing are connected by a road segment. Two crossings are connected by at most one road segment.
It is guaranteed that two road segments only intersect in a crossing they both start or end at. Further, it is guaranteed that each crossing on the map corresponds to an actual crossing in the sense that at least three road segments intersect.
Output

Output a single integer, the minimum number of crossings the racetrack must contain.

Examples
Input
4 6
0 0
3 0
0 3
1 1
1 2
1 3
1 4
2 3
2 4
3 4
Output
3
Input
10 15
1 5
2 1
3 4
4 2
5 3
6 2
7 3
8 1
9 4
11 5
1 2
1 3
1 10
2 4
3 5
4 5
4 6
5 7
6 7
6 8
7 9
8 10
9 10
2 8
3 9
Output
4

G. Guessing Game
time limit per test
3 seconds
memory limit per test
512 megabytes
input
standard input
output
standard output

Every year, the top gardeners of the cities Greenville and Tomatown compete against each other in the Grand Gardening Competition. The competition consists of some number of examinations which take place over the course of one week from Monday to Sunday. In each examination, one gardener from Greenville and one gardener from Tomatown present their products to a neutral jury. A few days in advance, both gardeners officially announce how many products of each type of vegetable, fruit or berry they plan to present. During the examination, the jury then evaluates the size, weight, diversity, beauty and taste of the presented products. After careful consideration, the jury finally declares one of the two competing gardeners to be the winner of the examination.

Alan and his friends are all enthusiastic gardeners, but since they do not live in Greenville or Tomatown, they can not submit their own vegetables to the competition. However, they have started their own private contest, where they try to predict the results of the single examinations. In this contest, each participant is allowed to pick one examination from each of the seven competition days and predict its winner. If this prediction turns out to be correct, the participant is awarded one point. To keep their guessing game interesting, Alan and his friends agreed that a prediction for an examination can not be handed in after the competing gardeners have announced which products they are going to present.

By using his connections to the gardening scenes of Greenville and Tomatown, Alan has consistently managed to score more points than all of his friends in the previous years. However, when he woke up this year on Monday, the first day of the competition, Alan realized that he had completely forgotten to submit his predictions! Of course, he immediately sprinted towards his computer and tried to submit his bets. Unfortunately, all gardeners which were scheduled to present their products between Monday and Friday had already announced their selections, so Alan could only submit his predictions for two examinations on Saturday and Sunday. He then hastily grabbed the competition schedule and started to compare the announced examinations to the predictions made by him and his friends.

Help Alan to determine whether there still remains a tiny chance that he can once more win the Gardening Competition Prediction Contest.

Input

The input consists of:

  • One line with a single integer $$$n$$$ ($$$1 \leq n \leq 5 \cdot 10^4$$$), the number of Alan's friends.
  • One line with seven positive integers $$$d_1, \ldots, d_7$$$ ($$$d_1 + \dots + d_7 \leq 10^5$$$), indicating that exactly $$$d_i$$$ examinations will take place on the $$$i$$$th competition day.
  • $$$n$$$ lines, each describing the predictions of one of Alan's friends. Each line consists of seven integers $$$b_{1}, \ldots, b_{7}$$$ ($$$1 \leq |b_i| \leq d_i$$$). If $$$b_{i}$$$ is positive, the $$$|b_{i}|$$$-th examination on day $$$i$$$ is predicted to be won by the gardener from Greenville. If it is negative, the gardener from Tomatown is predicted to win the examination.
  • One line with two non-zero integers $$$b_{6}, b_{7}$$$ ($$$1 \leq |b_i| \leq d_i$$$), encoding Alan's predictions for Saturday and Sunday in the same manner as the predictions of his friends.
Output

If it is possible for Alan to score more points than any of his friends, output possible . Otherwise, output impossible.

Examples
Input
3
4 4 4 4 4 4 4
1 1 1 1 4 -2 1
2 2 2 2 -4 1 -1
3 3 3 3 -3 3 3
-2 -1
Output
impossible
Input
3
4 4 4 4 4 4 4
4 3 2 1 4 1 1
2 4 4 2 2 4 2
2 3 3 4 1 3 2
-2 -1
Output
possible

H. Hardcore Hangman
time limit per test
2 seconds
memory limit per test
512 megabytes
input
standard input
output
standard output

You have probably heard about the game called hangman (and played it as a child). You try to guess a word with as few guesses as possible. In each guess, you suggest a letter, for example an a, and you get all the positions in the word, where an a appears.

That can take quite a few guesses, in particular, if a difficult word was chosen. So, let's change the game a bit. Instead of guessing just a single letter, any set of letters can be guessed in one turn. As a result you get all positions which contain one of the guessed letters.

If the word is 'hangman' and you guess the letters h, z and a in the first turn, you get the positions 1, 2 and 6. Of course, you still don't know whether there is an h, z or a at these positions, but it has to be one of those three letters.

Your task is to find the hidden word (it is not always a proper English word, but can be any string consisting of lowercase English letters) using at most 7 guesses.

Interaction

This is an interactive problem. Your submission will be run against an interactor, which reads the standard output of your submission and writes to the standard input of your submission. This interaction needs to follow a specific protocol:

Your submission repeatedly sends one of two query types:

  • "? s", where $$$s$$$ is a string of pairwise distinct lowercase letters. The interactor replies with an integer $$$n$$$ followed by $$$n$$$ integers $$$i_1, i_2, \dots, i_n$$$, the indices of the positions (1-indexed) in the hidden string, which contain a character in $$$s$$$.
  • "! x", where $$$x$$$ ($$$1 \leq |x| \leq 10^4$$$) is a string of lower case letters. The interactor replies with "correct" in case $$$x$$$ is the hidden string, else it replies with "incorrect". After the answer "correct", your program should terminate.

All interactions must be ended by a newline. Further note that you additionally need to flush the standard output to ensure that the query is sent. For example, you can use:

  • std::cout <{}< std::flush in C++
  • fflush(stdout) in C
  • System.out.flush() in Java
  • sys.stdout.flush() in Python

The hidden word has length at most $$$10^4$$$. You may use at most $$$7$$$ queries.

A testing tool is provided to help you develop your solution. It can be downloaded from the DOMjudge problems overview page.

Example
Input

3 2 4 6

3 1 3 5

4 1 2 4 6

3 1 3 5

correct
Output
? aeiou

? bcdfghjklmnpqrstvwxyz

? abcd

? bn

! banana

I. Improving IT
time limit per test
2 seconds
memory limit per test
512 megabytes
input
standard input
output
standard output

Your best friend is part of the business team at the Global Center for Parallel Computing (GCPC). She is responsible for buying and selling the hardware that is powering the system that will be in use for the next $$$n$$$ months. Currently, she is planning the CPU replacement cycle for a single CPU. To ensure that the system is always up-to-date, the CPU must be replaced at least every $$$m$$$ months. Fortunately, she can sell the replaced CPU to lower the overall costs to operate the new system. However, storage capacity is pricey, and she has to accept the resale value the CPU has in the month it is replaced. That means, when a CPU that was used for $$$j$$$ months is replaced in month $$$i$$$, you need to sell the current CPU for the value it has after $$$j$$$ months of usage and buy a new CPU for the price of the $$$i$$$th month. She already compiled a list of CPU prices for the next $$$n$$$ months including their resale value after $$$1$$$ to $$$m$$$ months. Note that you definitely need to buy a CPU in month $$$1$$$ and you need to sell the last CPU in month $$$n + 1$$$. How much money does the system cost at least over the $$$n$$$ months?

Input

The input consists of:

  • One line with two integers $$$n$$$ and $$$m$$$ ($$$1\leq n,m\text{ and } n \cdot m \leq 5 \cdot 10^5$$$).
  • $$$n$$$ lines; the $$$i$$$th line has an integer $$$c$$$ ($$$0 \leq c \leq 10^9$$$), the cost of a CPU in month $$$i$$$, followed by $$$\min(m, n - i + 1)$$$ integers $$$c_j$$$ ($$$0 \leq c_j \leq 10^9$$$), the money you earn by selling this CPU after $$$j \gt 0$$$ months.
Output

Output a single integer, the minimum total cost. Note that this number can be negative if reselling CPUs was profitable.

Examples
Input
4 3
1000 900 800 900
700 600 500 400
1200 1200 1300
600 500
Output
100
Input
3 2
200 300 400
400 300 200
300 500
Output
-400

J. Jesting Jabberwocky
time limit per test
2 seconds
memory limit per test
512 megabytes
input
standard input
output
standard output
In Sample 1, Alice has to move at least two cards to sort her hand.
The famous card game manufacturer Greatest Cards Production Company (GCPC) has just created the brand new card game Jabberwocky. In this game, everyone gets the same amount of cards – which might be quite a lot – and each card belongs to one of four different suits: hearts, diamonds, clubs, or spades.

As huge card game nerds, Alice and her friends are very hyped about meeting up and trying out the card game everybody seems to talk about these days. Due to a traffic jam, Alice is a bit late to the party and her friends are impatiently waiting for her. They have already distributed all cards and everybody is ready to go, except for Alice. She has just picked up her cards and insists on sorting them by suit first. For that, she repeatedly picks one card from her hand and inserts it somewhere else until her cards are grouped by suit. Her friends are getting increasingly annoyed with Alice and she wants to sort her cards as quickly as possible. How many cards does Alice need to move before they can start playing?

Input

The input consists of:

  • One line with a string $$$s$$$ ($$$1\leq|s|\leq 10^5$$$), representing the suits of Alice's cards as they are initially ordered. The string consists of the characters h, d, c, and s (hearts, diamonds, clubs and spades).
Output

Output a single integer, the minimum number of cards Alice has to move in order to sort the cards by suit.

Examples
Input
hccdhcd
Output
2
Input
cchhdshcdshdcsh
Output
7

K. K.O. Kids
time limit per test
1 second
memory limit per test
512 megabytes
input
standard input
output
standard output

On his birthday party, Glen wants to play the most exciting game. It is called Splash Game. For this, his parents built a bridge, which goes over the full length of the family pool and can be seen as a $$$2 \times n$$$ grid: it consists of $$$n$$$ steps and at each step, there are two plates. The players go over the bridge one after the other in a fixed order. At each of the $$$n$$$ steps, one of the two plates is fake and the player will fall into the pool with a big Splaaaaash when she steps onto it.

Of course, a participant can be lucky and guess the real plate and will not fall (she might still fall later). Also the first player really has a tough time. To make it to the other side, she would need to guess the real plate at every step. The later players have the advantage that they can see what the others are doing and hence know for the already entered steps, which plate is the real one (if a player guesses the real plate, everybody sees it; if she guesses the fake one and falls, everybody knows that the other plate is the real one).

The players proceed by a simple strategy. The first player starts by choosing the left plate on the first step. If she is correct, she switches to the right side and she will keep switching the side at every step (it is common knowledge that switching is a good idea). Every other player, once it is her turn, follows the correct choices as far as they are known and, afterwards, applies the switching strategy as well, i. e., if she stepped on the left plate on the previous step, she now steps on the right one and vice versa.

Of course, the game is only fun if at least a few kids make it to the other side of the bridge. But it shouldn't be too many either, since everybody has a great laugh when somebody is falling into the water. Given the number of kids and the planned layout of fake and real plates, output how many kids make it to the other side of the bridge.

The bridge layout for Sample Input 4 (cracked squares indicate the fake plates). The first player will guess the first step correctly, but fall on the second step. The second player thus knows the correct choices for the first two steps and guesses the third and fourth one correctly by switching. In the end, three of the seven kids make it to the other side.

Input

The input consists of:

  • One line with integers $$$n, k$$$ ($$$1 \leq n,k \leq 10^3$$$), the length of the bridge and the number of kids.
  • One string $$$s$$$ of length $$$n$$$ consisting of characters L and R. An L on position $$$i$$$ indicates that the real plate at step $$$i$$$ is the left one, an R indicates the right plate is the real one.
Output

Output a single integer, the number of kids who make it to the other side of the bridge.

Examples
Input
3 5
LRL
Output
5
Input
3 2
RRR
Output
0
Input
3 5
LLL
Output
3
Input
8 7
LLRLLLRR
Output
3

L. Lots of Land
time limit per test
1 second
memory limit per test
512 megabytes
input
standard input
output
standard output

Farmer Robert has been running a very successful cereal farm for many years. Now he wants to diversify his business and get into growing potatoes. To this end, he has bought a new plot of land on which he plans to plant the potatoes. This field is a rectangle and is exactly $$$\ell$$$ metres long and $$$w$$$ metres wide.

Since Robert is new to the potato business, he has initially purchased $$$n$$$ different potato varieties to try out in the first year. He plans to divide his plot of land into $$$n$$$ parts of equal area and plant one of the varieties on each. To make it easier for him to work the fields with his tractor, each new piece of land should itself be a rectangle and have integer side lengths. Help Robert to find a suitable division of his field.

Input

The input consists of:

  • One line with three integers $$$\ell, w, n$$$ ($$$1 \le \ell,w \le 100$$$, $$$1 \le n \le 26$$$), the length and width of Robert's field and the number of potato varieties.
Output

If there is no solution, output impossible. Otherwise output $$$\ell$$$ lines, each with $$$w$$$ uppercase letters, describing a possible division of Robert's field. There should be the same number of occurrences of each of the first $$$n$$$ letters of the English alphabet, and for each letter, its occurrences should form a single rectangular region. If there is more than one solution, any one of them will be accepted.

Examples
Input
4 4 4
Output
AAAA
BBCC
BBCC
DDDD
Input
6 15 9
Output
GGGGGBBBBBBBBBB
GGGGGAAAAAAAAAA
IIIIIIIIIIEEEEE
FFFFFFFFFFEEEEE
CCCCCDDDDDHHHHH
CCCCCDDDDDHHHHH
Input
100 100 26
Output
IMPOSSIBLE

M. Mirror Madness
time limit per test
3 seconds
memory limit per test
512 megabytes
input
standard input
output
standard output

Yesterday, a new attraction was opened at the local funfair: a hall of mirrors. This is a labyrinth in which all the walls are covered with mirrors so that visitors lose their sense of direction in a sea of reflections. The layout of the labyrinth can be described by a polygon with all sides parallel to either the x-axis or y-axis.

On the opening day, many visitors got so lost that the ride operators had to intervene and help them find their way out. To better understand where visitors get lost the most, the operators decided to install a monitoring system. This system involves an invisible laser beam running through the hall of mirrors at foot level, so that the movement of the visitors can be tracked by observing when and where the laser beam gets interrupted.

The laser beam starts at some boundary point of the polygon at an angle of $$$45$$$ degrees to the wall. Whenever it hits a mirror, it bounces off in a $$$90$$$ degree angle. To get their monitoring system to work, the operators are planning to install sensors at each of the first $$$m$$$ bouncing points of the laser beam. Find the locations where the sensors need to be installed.

Illustration of the second sample case.
Input

The input consists of:

  • One line with two integers $$$n$$$ and $$$m$$$ ($$$1 \le n,m \le 5\cdot 10^5$$$), the number of vertices of the polygon and the number of bounces.
  • $$$n$$$ lines, each with two integers $$$x$$$ and $$$y$$$ giving the coordinates of one vertex.
  • One line with integers $$$x_s$$$ and $$$y_s$$$, the coordinates of the starting point.

Additionally, the input satisfies the following constraints:

  • The vertices of the polygon are given in counterclockwise order.
  • The edges of the polygon do not touch or intersect each other, except for consecutive edges, which share their endpoints.
  • The edges of the polygon alternate between horizontal and vertical.
  • The perimeter (the total length of all sides) of the polygon does not exceed $$$10^6$$$.
  • All coordinates in the input have absolute value at most $$$10^6$$$.
  • All coordinates of the vertices of the polygon and exactly one coordinate of the starting point are even (so the laser never hits a vertex of the polygon).
  • The starting point is on the boundary of the polygon.
  • The initial direction of the laser beam is $$$(1,1)$$$, and this points inside the polygon.
Output

Output $$$m$$$ lines, each with two integers $$$x$$$ and $$$y$$$, giving the coordinates of the bounce locations in order.

Examples
Input
4 6
0 0
10 0
10 10
0 10
1 0
Output
10 9
9 10
0 1
1 0
10 9
9 10
Input
10 10
-2 -2
8 -2
8 8
4 8
4 0
2 0
2 6
-4 6
-4 2
-2 2
4 1
Output
8 5
5 8
4 7
8 3
3 -2
-4 5
-3 6
2 1
-1 -2
-2 -1