Paris has been called "ville lumière" (city of lights) since the 17th century. It earned this nickname in part because of the many city lights illuminating famous sites such as monuments, statues, churches, or fountains.
Those public lights in Paris are numbered from $$$1$$$ to $$$N$$$ and are all on by default. A group of hackers has gained the capability to toggle groups of lights. Every time the hackers use their program, they cause a number $$$i$$$ (that they cannot control) to be sent to the system controlling the city lights. The lights numbered $$$i$$$, $$$2i$$$, $$$3i$$$, and so on (up to $$$N$$$) then change state instantly: lights that were on go off, and lights that were off go on.
During the night, the hackers use their programs $$$k$$$ times. What is the greatest number of lights that are simultaneously off at the same time?
The input comprises several lines, each consisting of a single integer:
The output should consist of a single line, whose content is an integer, the greatest number of lights that are simultaneously off at the same time.
10
4
6
2
1
3
6
Sample Explanation:
We start with a group of 10 lights which are all on.
Damon loves to take photos of the places he visits during his travels, to put them into frames. All of his photos are in a square format of $$$N \times N$$$ pixels. He brought back beautiful pictures of the many monuments in Paris, such as the Eiffel Tower or the Louvre, but unfortunately, when he got back home, he realized that all his pictures were blurred on the edges. Looking closely, Damon realizes that he can easily distinguish the blurred pixels from the "good" (i.e., non-blurred) ones and that, luckily, all the non-blurred pixels are connected in such a way that any horizontal or vertical line drawn between two non-blurred pixels goes only through non-blurred pixels. In order to get the best from his failed pictures, he decides to cut out the biggest possible picture without any blurred pixel from each of his photos. And since his frames are all squares, for aesthetic reasons, the cut-out pictures have to be squares too. Damon does not want his pictures to be tilted so he wants the sides of the cut-outs to be parallel to the sides of the original picture.
The input comprises several lines, each consisting of integers separated with single spaces:
The output should consist of a single line, whose content is an integer, the length of the largest square composed of non-blurred pixels inside the picture.
3 1 1 0 2 1 1
1
8 2 4 2 4 1 4 0 7 0 3 1 2 1 2 1 1
3
On a given facade, windows are organized on a rectangular grid with $$$N$$$ rows and $$$M$$$ columns. Anne has gathered a list of size $$$A$$$ of $$$N$$$-letter words and a list of size $$$B$$$ of $$$M$$$-letter words. She is wondering how many ways there are to display simultaneously $$$N$$$ words of length $$$M$$$ horizontally and $$$M$$$ words of length $$$N$$$ vertically on that grid.
The input consists of the following:
Limits
The input satisfies $$$2 \le N$$$, $$$M \le 4$$$ and $$$1 \le A \times B \le 1008016$$$.
Words are taken from the English dictionary. Each of the two lists contains no repetition. Words consist of lowercase letters between 'a' (ASCII code 97) and 'z' (ASCII code 122).
Words from the first list will be displayed vertically, from top to bottom. Words from the second list will be displayed horizontally, from left to right. The same word can be used several times to build a grid, i.e., in several columns (resp., rows) if it belongs to the first (resp., second) list of words.
When $$$N = M$$$, it is not allowed to use words from the first list horizontally (unless they appear in the second list as well), or words from the second list vertically (unless they appear in the first list as well).
The output should consist of a single line, whose content is an integer, the total number of distinct word grids.
3 4 4 5 war are yes sat says area test ways rest
2
3 7 3 7 ran age now its the set ago ran age now its the set ago
2
Sample Explanation 1
The solutions are:
Sample Explanation 2
The solutions are:
A tour operator proposes itineraries consisting of visits of $$$N$$$ monuments and museums in Paris, modeled as a grid. The way the tour operates is the following: The bus enters the city from the west (on any street) and traverses the city, taking a left or a right turn to visit monuments when needed, returning to the same eastbound road it used to enter the city, and so on until it exits the city via the east.
A tour in a $$$6\times 5$$$ grid city might look like the figure above. On the figure, the bus enters the city at coordinate $$$(0,2)$$$ (we consider $$$(0,0)$$$ to be the northwest corner of the city), first visits the monument at $$$(1,2)$$$ (already on the main road), takes a left turn and visits the monument at $$$(1,0)$$$, returns to the main road and moves east, takes a right turn and visits the monument at $$$(2,4)$$$, returns to the main road, visits the monument at $$$(4,2)$$$ (again on the main road), and then exits the city at coordinate $$$(5,2)$$$ .
The bus operator counts that the traversal of one block costs 1 unit of gas. For the example above, the cost is thus $$$5 + 2 \times 2 + 2 \times 2 = 13$$$ units of gas.
Your task is to help the tour operator choose which eastbound road the bus should travel through, so that the cost of the tour is minimized while visiting all $$$N$$$ monuments.
The input comprises several lines, each consisting of integers separated with single spaces:
The output should consist of a single line, whose content is an integer, representing the minimal cost of a tour.
6 5 4 1 0 1 2 2 4 4 2
13
5 7 9 0 0 0 2 0 3 2 2 2 3 3 2 4 3 4 4 4 6
20
You decided to stay an extra day in Paris visiting favorite places of Parisians around T'el'ecom ParisTech. You want to collect information about these favorite places, but asking people to fill in surveys is less fun than coding. For this reason, you asked the Parisian Agency for Really Imprecise Surveys to do it for you. You sent them a list of the P places you were interested in.
After surveying exactly 10 000 persons and asking them their favorite place (among these P places), the agency has just sent you the results. All persons surveyed answered the question. Unfortunately, the agency rounded the percentage results to the nearest integer, using the following formula: $$$result = \lfloor original\_value + \frac 12\rfloor$$$. In particular, decimal values of $$$.50$$$ are rounded up.
But since $$$10000$$$ persons were surveyed, you should have been able to get percentage values precise to the second decimal. What a loss of precision! You want to know the range in which each original result could be.
The input comprises several lines:
Limits
If the results given by the agency are not consistent, print a single line with the word IMPOSSIBLE. Otherwise the output should consist of P lines, each of them should consist of the name of a place followed by a single space and two numbers, the smallest and the largest percentage values that place could have had in the original results, as floating-point numbers with two decimals separated with a single space (each number must have at least one digit before the decimal point, even if it is 0, and exactly 2 decimals, even if the trailing ones are 0). The places must be in the same order as in the input.
4 Catacombes 32 Cite_Universitaire 22 Arenes_de_Lutece 26 Observatoire 19
Catacombes 31.53 32.49 Cite_Universitaire 21.53 22.49 Arenes_de_Lutece 25.53 26.49 Observatoire 18.53 19.49
7 Aqueduc_Medicis 11 Parc_Montsouris 40 Place_Denfert 10 Hopital_Sainte_Anne 4 Butte_aux_cailles 20 Cite_florale 12 Prison_de_la_Sante 0
Aqueduc_Medicis 11.06 11.49 Parc_Montsouris 40.06 40.49 Place_Denfert 10.06 10.49 Hopital_Sainte_Anne 4.06 4.49 Butte_aux_cailles 20.06 20.49 Cite_florale 12.06 12.49 Prison_de_la_Sante 0.06 0.49
2 Catacombes 50 Arenes_de_Lutece 49
IMPOSSIBLE
Hence, she will proceed as follows. She chooses two monuments, that we will call the boundary monuments, and asks the balloon pilot to go between these monuments. From there, she takes two $$$180^\circ$$$ pictures: each picture shows one side of Paris, both sides being delimited by the two boundary monuments. Each picture receives a grade, which is the sum of the grades of the monuments that it shows, including the boundary monuments on both pictures. Finally, if the pictures have grades A and B, the goal of Morgane is to minimize the difference between A and B (in absolute value).
The visibility from the balloon is such that all monuments can be seen in either of the two photographs.
You must assist Morgane in choosing appropriate boundary monuments. In order to do this, you are given a list of the monuments. For every monument visited by Morgane, this list contains a line which indicates the Cartesian coordinates of the monument location, along with the monument's grade. You should give the minimal possible difference, among all pairs of pictures that Morgane may take, between the grades of the two pictures.
Important Note
Morgane was so precise at locating every monument that no three monuments are on a same straight line.
The input comprises several lines, each consisting of integers separated with single spaces:
Limits
The output should consist of a single line, whose content is an integer, the minimal difference (in absolute value) between the grades of a pair of photographs that Morgane may take.
8 0 0 10 1 1 2 2 1 3 3 2 7 2 3 8 5 2 5 1 5 12 4 5 14
2
Once Gustave is happy with the final string he gets, he contacts a company to have the string printed on a strip of fabric. Being meticulous, Gustave does not want the company to make a single mistake. He thus computes a checksum out of his string and has the company do the same computation as a verification.
The input consists of the following lines:
Limits
The output should consist of a single line, whose content is an integer, the sum of all ASCII codes of the characters of the final string $$$S( N - 1)$$$ , modulo $$$1000000007$$$.
3 foobar SUB 0 0 3 APP 1 1
648
You are employed by a travel agency and your manager Anna wants to prepare a list of hotels to include in her new travel guide. Her guide contains one entry per station of the metropolitan network. Anna notices that some stations do not have a convenient location with respect to the distance to the three POIs and therefore her guide should not contain a hotel section for such "useless" stations.
Anna considers that a station is useless when another station is closer to all the POIs. Formally a station A is useless when there exists another station B such that B is at least as close to the three POIs as A is and B is strictly closer than A to at least one of those POIs. A station is useful if it is not useless.
Anna asks you how many stations in her guide will have a hotel section. To compute this list you are given the plan of the metropolitan network. The plan of the metropolitan network is an undirected weighted graph. In this graph, each node corresponds to a station (note that each POI is also a station); each edge links two stations and takes a certain time to be traversed in either direction. This graph is connected and the distance between any two stations is the lowest total time of a path between the two nodes.
The input comprises several lines, each consisting of integers separated with single spaces:
In the graph:
Limits
The output should consist of a single line, whose content is an integer, the number of useful stations.
5 4 0 3 1 1 3 1 2 3 1 4 3 1
4
5 6 0 3 1 1 3 1 2 3 1 4 3 1 0 1 1 0 2 1
3
Explanation of Sample 1:
Explanation of Sample 2:
In this graph (depicted on the bottom), three stations are useful: Orly, Disneyland, and Notre-Dame. The stations corresponding to Orly, Disneyland, Notre-Dame are the closest stations to themselves. All stations have a POI at distance 2 except for Gare du Nord, which is at distance 1 to all POIs, and Orly which is at distance 1 to all POIs but at a distance of 0 to itself. Therefore Gare du Nord is useless.
You are given a rectangular matrix representing a picture made by Peter. The '#' character represents a black pixel and the '.' character a white pixel. You should count how many stones are on the picture with the respective letters A, B, and C.
The first line contains two integers $$$W$$$ and $$$H$$$. The next $$$H$$$ lines each contain a string of length $$$W$$$. The strings are composed of '.' and '#'.
Limits
The output should consist of a single line, whose content is three integers $$$A$$$, $$$B$$$, and $$$C$$$ separated with single spaces, indicating the number of stones with the respective marks A, B, and C.
26 15 ########################## ##........######......#..# #...###....#####..#......# #...#.#....####.........## #...###.....##....#####..# #...#.#.....#.....#####..# #...###.....#.....##.##..# #........#..#.#...#####..# #..###......#.....#####..# #..#........#...#.##.##..# #..#........#.....##.##..# #..#...#.#..#...#.##.##..# #..###......#............# ###....#....##....##.....# ##########################
1 1 0
Sample Explanation
There are black pixels forming a letter C. These pixels, however, belong to the region around the stones and do not form a mark since they are not surrounded by white pixels.
The painting is enclosed in a rock-solid glass chamber that can only be opened with 4 secret codes that need to be entered on 4 different keypads. The head of the museum thinks that this system is unbreakable, and your task is to prove her wrong.
To help you, a friend reverse-engineered the system. When a code (represented by a positive integer $$$C$$$) is entered on a keypad, the keypad sends the $$$C$$$-th value produced by a random number generator to a central computer. The central computer only considers the N least significant bits of the 4 pseudo-random values it receives from the 4 keypads. It computes their bitwise XOR (exclusive or) and opens the glass chamber if the result is 0. The pseudo-random number generator is described at the end of the problem statement.
Another friend found the pseudo-random seeds used by each keypad. With all this information, you think that you can retrieve the 4 secret codes unlocking Mona Lisa.
The input comprises two lines, each consisting of integers separated with single spaces:
Limits
The output should consist of a single line, whose content is 4 integers, the 4 secret codes, separated with single spaces. Each code must be less than $$$100000000$$$. It is guaranteed that at least one solution will exist. Multiple solutions may exist, in which case they will all be accepted.
50 3641603982383516983 445363681616962640 868196408185819179 1980241222855773941
287 17609 122886 59914
Pseudo-Random Generator The pseudo-random generator is described next in each programming language. You can expect that this pseudo-random generator is not biased in any way.
C/C++
The i-th value of the pseudo-random sequence is the result of the i-th application of xoroshiro128plus on 'state'.
typedef unsigned long long uint64;
uint64 state[2] = { seed, seed ^ 0x7263d9bd8409f526 };
uint64 xoroshiro128plus(uint64 s[2]) {
uint64 s0 = s[0];
uint64 s1 = s[1];
uint64 result = s0 + s1;
s1 ^= s0;
s[0] = ((s0 « 55) | (s0 » 9)) ^ s1 ^ (s1 « 14);
s[1] = (s1 « 36) | (s1 » 28);
return result;
}
Java
long[] state = { seed, seed ^ 0x7263d9bd8409f526L };
long xoroshiro128plus(long[] s) {
long s0 = s[0];
long s1 = s[1];
long result = s0 + s1;
s1 ^= s0;
s[0] = ((s0 « 55) | (s0 »> 9)) ^ s1 ^ (s1 « 14);
s[1] = (s1 « 36) | (s1 »> 28);
return result;
}
The i-th value of the pseudo-random sequence is the result of the i-th application of xoroshiro128plus on 'state'.
Python 2 / Python 3
The following loop yields the pseudo-random sequence starting from its first value:
state = [seed, seed ^ 0x7263d9bd8409f526]
def xoroshiro128plus(s):
s0, s1 = s
result = (s0 + s1) % 2**64
s1 ^= s0;
new_state = [(((s0 « 55) | (s0 » 9)) ^ s1 ^ (s1 « 14)) % 2**64,
((s1 « 36) | (s1 » 28)) % 2**64]
return result, new_state
while True:
result, state = xoroshiro128plus(state)
yield result
You noticed the scam because you were traveling several times by the same place: indeed, you have such a good memory that you can remember very well the path you followed, including each of the loops that your scammer forced you to take.
Now, you are at the police station to file a complaint against this driver and an officer asks you to tell your story. She even asks you to give all the details of the path you took. Because you do not want to lose yet another couple of hours in doing so, you decide to give a compressed version of it.
Suppose you remember you traveled through places A, B, C, D, A, B, C, D. In this case, you prefer telling the officer "I followed twice the path ABCD", rather than "I followed the path ABCDABCD". Given that your path repeated the same sequence of places, this will significantly shorten your statement, without missing any detail.
More precisely, you have to write a program that takes as input the list of places you traveled through, and which returns the size of the shortest compressed form of this path. Such a compressed path can either be:
The input consists of two lines:
Limits
$$$0 \lt N \le 700$$$.
The output should consist of a single line, whose content is an integer, the size of the shortest compressed path.
22 aaabaaabccdaaabaaabccd
4
4 aaba
3
Sample Explanation 1
The shortest compressed form of the path is $$$(((a)^3 b)^2 (c)^2 d)^2$$$. The atomic paths it contains are $$$a$$$, $$$b$$$, $$$c$$$ and $$$d$$$. Hence, it has size 4.
Sample Explanation 2
The shortest compressed form of the path is $$$(a)^2 ba$$$. The atomic paths it contains are $$$a$$$, $$$b$$$, and $$$a$$$. Hence, it has size 3.