Educational Round #2 — Editorial
One of the farming chores Farmer John dislikes the most is hauling around lots of cow manure. In order to streamline this process, he comes up with a brilliant invention: the manure teleporter! Instead of hauling manure between two points in a cart behind his tractor, he can use the manure teleporter to instantly transport manure from one location to another.
Farmer John's farm is built along a single long straight road, so any location on his farm can be described simply using its position along this road (effectively a point on the number line). A teleporter is described by two numbers and , where manure brought to location can be instantly transported to location , or vice versa.
Farmer John wants to transport manure from location to location , and he has built a teleporter that might be helpful during this process (of course, he doesn't need to use the teleporter if it doesn't help). Please help him determine the minimum amount of total distance he needs to haul the manure using his tractor.
Input. One line contains four integers: and describing the start and end locations, followed by and describing the teleporter. All positions are integers in the range , and they are not necessarily distinct from each-other.
Output. Print a single integer giving the minimum distance Farmer John needs to haul manure in his tractor.
Examples. In this example, the best strategy is to haul the manure from position to position , teleport it to position , then haul it to position . The total distance requiring the tractor is therefore 1 + 2 = 3.

beginrow
3 10 8 2 3Find a number between and (inclusive) that has the maximum number of prime factors in its factorization. If there are multiple such numbers, print the largest one.
For example, for the answer is , as it is the largest number whose prime factorization includes two factors: and .
Input. One integer n~(1 \le n \le 2^{31} - 1).
Output. Print the desired number.
beginrow
76Find the value of the function
Input. Two integers x, y~(0 \le x, y \le 50).
Output. Print the value of the function f(x, y).
2 3434 12 6One day people ( is even) met on a plaza and made two round dances. Find the number of ways people can make two round dances if each round dance consists of exactly people. Each person should belong to exactly one of these two round dances.
Round dance is a dance circle consisting of or more people. Two round dances are indistinguishable (equal) if one can be transformed to another by choosing the first participant. For example, round dances [1, 3, 4, 2], [4, 2, 1, 3] and [2, 1, 3, 4] are indistinguishable.
Input. One even integer n~(2 \le n \le 20).
Output. Print the number of ways to make two round dances. It is guaranteed that the answer fits in the -bit integer data type.
Examples. For example, for the number of ways is :
one round dance — , another — ;
one round dance — , another — ;
one round dance — , another — .
43You are given a matrix of size n \times m with special cells. You need to reach cell starting from . From any cell, you are allowed to move only to the right or down.
Each of the special cells has a certain power. The -th special cell has power p_i, and if you pass through this cell, you gain this power.
Your task is to find the total power that can be collected over all possible paths from to .
Note that:
The power of a path is the sum of the values p_i of all special cells visited along this path.
Regular cells that are not special have power equal to zero.
Input. The first line contains an integer — the number of test cases.
The first line of each test case contains three integers n, m~(1 \le n, m \le 10^5) and k~(1 \le k \le 10^6), where n \times m is the size of the grid, and is the number of special cells.
Each of the next lines contains three integers x_i, y_i~(1 \le x_i \le n, 1 \le y_i \le m) and p_i~(1 \le p_i \le 10^5), where (x_i, y_i) is the position of a special cell, and p_i is its power.
Output. For each test case, print on a separate line the total power that can be collected. Since the result may be very large, output it modulo 10^9 + 7.
1
2 2 2
1 2 4
2 1 711In the land of Smeshariki, a new season has begun! Now all the heroes are setting out on a journey. To do this, they need to gather at a single point, and from there continue their quest to conquer the world. Losyash, who coordinates the actions of the Smeshariki, knows the coordinates of all the participants. Help him determine the minimum number of seconds required for all the Smeshariki to gather together.
Initially, each Smesharik is located at a node of the integer grid. If a Smesharik is at point , then in one second they can move to one of the points (x, y + 1), (x + 1, y), (x - 1, y), (x, y - 1), or remain at .
Input. The first line contains a single integer n~(1 \le n \le 200000) — the number of Smeshariki. The next lines specify their initial positions. Each position is given by two integers x_i and y_i~(-10^{18} \le x_i, y_i \le 10^{18}).
Output. Print the minimum number of seconds required for all the Smeshariki to gather at a single point.
1
1 102
1 3
4 423
0 0
3 3
0 33Nurlashko, Nurbakyt, and Zhora are the last warriors of an ancient ninja clan fighting against the tyranny of Emperor Ren. After a crushing defeat in open battle, they decided to split their army into three camps and switch to guerrilla warfare.
However, the absurd reforms of Emperor Ren imposed strict rules: the roads between cities can only be traveled in one direction. Moreover, the directions were chosen in such a way that it is impossible, after traversing several roads, to return to the original city.
Now the clan is deciding where to place their camps. The emperor's army regularly conducts raids, checking various routes. If, during one such raid, the enemy manages to capture all three camps, the clan will be unable to regroup and will lose the war. Your task is to help choose three cities so that there is no path passing through all of them.
Input. The first line contains two integers n, m~(1 \le n, m \le 10^6) — the number of cities and roads in the empire.
The following lines each contain two integers v_i, u_i~(1 \le v_i, u_i \le n), describing a directed road from city v_i to city u_i.
Output. Print three integers — the indices of the cities where the clan should place their camps. If no such triple of cities exists, print . If there are multiple solutions, you may output any of them.

3 2
1 2
2 3-13 2
1 2
1 32 3 1Fernando was hired by the University of Waterloo to finish a development project the university started some time ago. Outside the campus, the university wanted to build its representative bungalow street for important foreign visitors and collaborators.
Currently, the street is built only partially, it begins at the lake shore and continues into the forests, where it currently ends. Fernando’s task is to complete the street at its forest end by building more bungalows there. All existing bungalows stand on one side of the street and the new ones should be built on the same side. The bungalows are of various types and painted in various colors.
The whole disposition of the street looks a bit chaotic to Fernando. He is afraid that it will look even more chaotic when he adds new bungalows of his own design. To counterbalance the chaos of all bungalow shapes, he wants to add some order to the arrangement by choosing suitable colors for the new bungalows. When the project is finished, the whole sequence of bungalow colors will be symmetric, that is, the sequence of colors is the same when observed from either end of the street.
Among other questions, Fernando wonders what is the minimum number of new bungalows he needs to build and paint appropriately to complete the project while respecting his self-imposed bungalow color constraint.
Input. The first line contains one integer n~(1 \le n \le 4 \cdot 10^5), the number of existing bungalows in the street. The next line describes the sequence of colors of the existing bungalows, from the beginning of the street at the lake. The line contains one string composed of lowercase letters ("" through ""), where different letters represent different colors.
Output. Print the minimum number of bungalows which must be added to the forest end of the street and painted appropriately to satisfy Fernando's color symmetry demand.
3
abb112
recakjenecep1115
murderforajarof
recakjenecep6Along the Almaty - Taraz highway, there are n villages, numbered from 1 to n. With the arrival of winter, m unknown traders brought knitted hats from a certain aul and began selling them in these villages. The traders follow two principles:
They do not sell in the same place for more than one day.
Each day, they increase the price of a hat.
More formally, each -th trader:
Starts selling in village l_i with an initial price of x_i per hat.
Moves to a neighboring village each day: if they sold in village yesterday, they sell in village j + 1 today.
Increases the price by each day: if the price was yesterday, today it is x + 1.
Finishes selling in village r_i (including selling in r_i on the last day).
For each village, determine the maximum price of a single hat throughout the entire trading history.
Input. The first line contains two integers n~(1 \le n \le 3 \cdot 10^5) and m~(1 \le m \le 3 \cdot 10^5) — the number of villages and the number of traders, respectively.
The next lines each contain three integers: l_i, r_i~(1 \le l_i \le r_i \le n) and x_i~(1 \le x_i \le 10^9) — the starting and ending villages, as well as the initial price of a hat for the -th trader.
Output. Print integers, where the -th number represents the maximum price of a hat throughout the entire trading history in the -th village. If no trade took place in a particular village, print .
5 2
1 3 2
2 4 62 6 7 8 06 4
4 4 3
1 2 5
5 6 1
6 6 15 6 0 3 1 2
Comments