ICPC Masters Mexico 2026
A. Alumni Pairs
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Registration has closed with $$$N$$$ former contestants signed up as individuals, and the contest is played in teams of two. The organizers have to put them into pairs.

Every participant has a rating. The registration system stores it as the difference from a fixed baseline, so the rating $$$a_i$$$ of participant $$$i$$$ is an integer that can also be negative, for somebody who has not written code in a contest for many years.

Every pair must hold exactly two different participants, and each participant may belong to at most one pair. The participants who are left over help as volunteers instead. A pair is competitive if the sum of the ratings of its two members is at least $$$X$$$.

A participant who cannot be placed in a competitive pair simply stays unpaired. Find the maximum possible number of competitive pairs.

Input

The first line contains two integers $$$N$$$ and $$$X$$$ ($$$1 \le N \le 2 \cdot 10^5$$$, $$$-10^9 \le X \le 10^9$$$) — the number of participants and the required total rating.

The second line contains $$$N$$$ integers $$$a_1,a_2,\ldots,a_N$$$ ($$$-10^9 \le a_i \le 10^9$$$) — the participants' ratings.

Output

Print one integer — the maximum possible number of competitive pairs.

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

In the first example, participants with ratings $$$3$$$ and $$$8$$$ can form one pair, and participants with ratings $$$4$$$ and $$$7$$$ can form another.

In the third example, the pairs $$$(-10,8)$$$, $$$(-1,3)$$$, and $$$(-1,3)$$$ are all competitive.

B. Building the Schedule
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Almost everything at a contest site is done by volunteers: printing, balloons, the help desk, the door of the contest hall. Before the contest starts, the organizers have to build the volunteer schedule.

There are $$$M$$$ shifts and $$$N$$$ volunteers. A shift with too few people cannot cover the hall, and a shift with too many people only creates noise, so shift $$$j$$$ needs at least $$$L_j$$$ and at most $$$U_j$$$ assigned volunteers. The volunteers have their own talks and meetings too: volunteer $$$i$$$ is available for some of the shifts and may be assigned to at most $$$c_i$$$ shifts. Writing the same person twice in the same shift helps nobody, so a volunteer can be assigned to the same shift at most once.

Find any assignment that satisfies every requirement, or determine that no such assignment exists.

Input

The first line contains two integers $$$N$$$ and $$$M$$$ ($$$1 \le N,M \le 500$$$) — the number of volunteers and shifts.

Each of the next $$$M$$$ lines contains two integers $$$L_j$$$ and $$$U_j$$$ ($$$0 \le L_j \le U_j \le N$$$) — the minimum and maximum number of volunteers for shift $$$j$$$.

Each of the next $$$N$$$ lines describes one volunteer. The line for volunteer $$$i$$$ begins with two integers $$$c_i$$$ and $$$q_i$$$ ($$$0 \le c_i,q_i \le M$$$) — the maximum number of shifts volunteer $$$i$$$ may be assigned to, and the number of shifts volunteer $$$i$$$ is available for.

The same line then contains $$$q_i$$$ integers $$$s_{i,1},s_{i,2},\ldots,s_{i,q_i}$$$ ($$$1 \le s_{i,k} \le M$$$) — the shifts for which volunteer $$$i$$$ is available. These shift numbers are distinct.

Output

If no valid assignment exists, print -1.

Otherwise, print an integer $$$Q$$$ — the number of assignments. Then print $$$Q$$$ lines, each containing two integers $$$i$$$ and $$$j$$$, meaning that volunteer $$$i$$$ is assigned to shift $$$j$$$.

The printed volunteer-shift pairs must be distinct. Every pair must be available, no volunteer may appear more than $$$c_i$$$ times, and every shift $$$j$$$ must appear between $$$L_j$$$ and $$$U_j$$$ times, inclusive.

If several valid assignments exist, print any of them. It is allowed that $$$Q=0$$$.

Examples
Input
3 2
1 2
1 2
2 2 1 2
1 1 1
2 1 2
Output
2
1 1
1 2
Input
2 2
2 2
1 2
1 1 1
1 1 2
Output
-1
Input
2 3
0 0
0 2
0 1
0 0
2 0
Output
0
Note

In the first example, volunteer $$$1$$$ takes both shifts and volunteer $$$3$$$ takes the second shift. The two shifts receive one and two volunteers.

In the second example, shift $$$1$$$ needs two volunteers, but only volunteer $$$1$$$ is available for it.

C. Carrying One Badge
time limit per test
3 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Elisa is late for the practice session, and the university building hosting the contest does not make it easy. The floor is a rectangle of rooms drawn as a grid of cells. Some cells are blocked by walls, some cells hold an access badge that a volunteer left on a table, and some cells hold a locked door. Every badge and every door has one of $$$K$$$ colours.

Elisa can carry at most one badge, because the readers accept a single card only. When she enters a cell that holds a badge, she may leave it there, or take it. If she takes it, the badge she was carrying before goes into the lost-and-found box and is gone for her. Badges never run out, because the volunteers keep a full box on every table: a cell that holds a badge still holds one after Elisa takes it, so she may come back to that cell later and take another badge of the same colour.

A locked door of colour $$$c$$$ can only be entered while carrying a badge of the same colour $$$c$$$. When Elisa enters it, that badge is swallowed by the reader and the door is propped open: from that moment, every door of colour $$$c$$$ on the floor is permanently unlocked and behaves like an ordinary empty cell.

Elisa never throws a badge away for nothing. She can only lose a badge by taking another one, or by using it on a locked door.

Elisa starts carrying no badge. In one step, she moves to one of the four cells that share a side with her current cell. She cannot leave the floor or enter a wall.

Entering a badge cell costs one step; choosing whether to take the badge costs no additional steps. Entering a locked door also costs one step. The required badge is spent during that step, and Elisa finishes the step inside the now unlocked door cell.

Find the minimum number of steps she needs to reach the team room.

Input

The first line contains three integers $$$H$$$, $$$W$$$, and $$$K$$$ ($$$1 \le H, W \le 50$$$, $$$H \cdot W \ge 2$$$, $$$0 \le K \le 8$$$) — the height and width of the floor, and the number of colours.

Each of the next $$$H$$$ lines contains a string of exactly $$$W$$$ characters describing one row of the floor. Each character is one of:

  • #: a wall;
  • .: an empty cell;
  • S: Elisa's starting cell;
  • T: the team room;
  • the $$$c$$$-th lowercase English letter, for $$$1 \le c \le K$$$: a badge of colour $$$c$$$;
  • the $$$c$$$-th uppercase English letter, for $$$1 \le c \le K$$$: a locked door of colour $$$c$$$.

There is exactly one S and exactly one T. A colour may have any number of badges and doors, including zero.

Output

Print one integer — the minimum number of steps needed to enter T, or -1 if it is impossible.

Examples
Input
1 2 0
ST
Output
1
Input
1 5 2
SabAT
Output
4
Input
1 6 1
SaA.AT
Output
5
Note

In the second example, Elisa takes a, but she must leave b on the table. Otherwise, she would no longer carry the badge needed to enter A.

In the third example, entering the first A spends the badge a and unlocks both doors A. The second door can then be entered without another badge.

D. Divided Banner
time limit per test
4 seconds
memory limit per test
512 megabytes
input
standard input
output
standard output

The sponsor banner was left outside during the night, and the wind tore it into $$$n$$$ fragments. The banner was cut along its height, so every fragment still has the full height of the original banner, from the bottom edge to the top edge.

Each fragment is a filled convex polygon. Every fragment is contained between the horizontal lines $$$y=0$$$ and $$$y=H$$$, the bottom and the top edge of the banner, and touches both lines.

The volunteers want to hang all the fragments again on the wall behind the scoreboard, and that wall is short. They may hang the fragments in any order and move each fragment to the left or to the right by any real distance. They may not move a fragment up or down, rotate it, or turn it over: every fragment hangs from the same rail, with its bottom edge on the line $$$y=0$$$.

An arrangement is valid if the interiors of every two fragments are disjoint. Their boundaries are allowed to touch, and a fragment hung exactly against its neighbour is what the volunteers want.

The length of an arrangement is the difference between the largest and smallest $$$x$$$-coordinates occupied by any fragment, that is, the piece of wall it needs. Find the minimum possible length of a valid arrangement.

Input

The first line contains two integers $$$n$$$ and $$$H$$$ ($$$1 \le n \le 18$$$, $$$1 \le H \le 10^4$$$) — the number of fragments and their common height.

The description of the $$$n$$$ fragments follows.

For each fragment, the first line contains an integer $$$k_i$$$ ($$$3 \le k_i \le 300$$$) — the number of vertices of the polygon.

Each of the next $$$k_i$$$ lines contains two integers $$$x_{i,j}$$$ and $$$y_{i,j}$$$ ($$$-10^4 \le x_{i,j} \le 10^4$$$, $$$0 \le y_{i,j} \le H$$$) — the coordinates of its $$$j$$$-th vertex.

The vertices of every polygon are given in counterclockwise order. It is guaranteed that:

  • every polygon is convex (not necessarily strictly convex) and has positive area;
  • consecutive vertices on the boundary may be collinear;
  • every polygon has at least one point on $$$y=0$$$ and at least one point on $$$y=H$$$;
  • the sum of $$$k_i$$$ over all fragments does not exceed $$$300$$$.

Coordinates belonging to different fragments are expressed in independent local coordinate systems.

Output

Print one real number — the minimum possible length of a valid arrangement.

Your answer is considered correct if its absolute or relative error does not exceed $$$10^{-6}$$$.

Examples
Input
1 2
4
0 0
3 0
3 2
0 2
Output
3.0000000000
Input
2 2
3
0 0
2 2
0 2
3
0 0
2 0
2 2
Output
2.0000000000
Input
2 4
3
0 0
4 2
0 4
4
0 0
1 0
1 4
0 4
Output
5.0000000000
Note

In the second example, the two triangular fragments can share a slanted boundary, so their projections on the $$$x$$$-axis may completely overlap.

In the third example, the first fragment reaches $$$x=4$$$ halfway up the banner. The rectangular fragment can be placed immediately to its right, touching it at that point, for a total length of $$$5$$$.

Условие недоступно на русском языке
F. Fairest Help Desk
time limit per test
3 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

The contest hall already has $$$P$$$ help desks, and $$$K$$$ teams are sitting at their tables. When a team needs paper, a printout or a new keyboard, one of its members walks to the nearest help desk. The hall is one open floor without walls, so the walk is measured with the ordinary straight-line (Euclidean) distance.

The organizers have enough volunteers to open exactly one more help desk. Its location may be any point of the hall with real-valued coordinates: it does not have to be one of the given integer points, and it is allowed to coincide with an existing help desk or with a team table.

After the new help desk is opened, every team walks to whichever help desk — an existing one or the new one — is closer to its table. The organizers are judged by the team that walks the most, so they want to choose the location of the new help desk so that the longest walk made by any team is as short as possible.

Help them find this minimum possible value.

Input

The first line contains two integers $$$P$$$ and $$$K$$$ ($$$1 \le P, K \le 10^5$$$) — the number of existing help desks and the number of teams.

Each of the next $$$P$$$ lines contains two integers $$$x$$$ and $$$y$$$ ($$$-10^6 \le x, y \le 10^6$$$) — the coordinates of an existing help desk.

Each of the next $$$K$$$ lines contains two integers $$$x$$$ and $$$y$$$ ($$$-10^6 \le x, y \le 10^6$$$) — the coordinates of a team table.

Two or more existing help desks may coincide, two or more teams may sit at the same point, and a team table may coincide with an existing help desk.

Output

Print one real number — the minimum possible value, over every choice of location for the new help desk, of the largest distance walked by any team.

Your answer is considered correct if its absolute or relative error does not exceed $$$10^{-6}$$$.

Examples
Input
2 1
0 0
10 0
3 7
Output
0.0000000000
Input
1 2
0 0
3 4
3 -4
Output
4.0000000000
Input
1 3
0 0
3 4
3 -4
1 0
Output
4.0000000000
Note

In the first example there is only one team, so the new help desk can be opened exactly at that team's table. Their walking distance becomes $$$0$$$, which is clearly the best possible value.

In the second example both teams are at distance $$$5$$$ from the only existing help desk. Opening the new help desk at $$$(3,0)$$$ puts it at distance $$$4$$$ from each of them, so both now walk $$$4$$$. No location can serve both teams with a smaller distance, because they are $$$8$$$ apart from each other, so any single point that is within some distance $$$r$$$ of both of them must have $$$r \ge 4$$$.

The third example adds a third team at $$$(1,0)$$$, already only $$$1$$$ away from the existing help desk. This team is comfortable regardless of where the new help desk is opened, so the answer is unchanged from the second example: the new help desk is still best placed at $$$(3,0)$$$, giving the same value $$$4$$$.

G. Gathering the Problem Set
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

The jury has collected $$$N$$$ candidate problems, and has only a few weeks to turn them into a contest. Problem $$$i$$$ would add $$$g_i$$$ points of quality to the set, a non-negative integer.

Preparing a problem is not only writing the statement. It also needs tests, a validator, a checker and at least two independent solutions, so one problem takes a full working day of the whole jury.

Every candidate problem also has an author who is available only for a limited time. Problem $$$i$$$ must be finished on day $$$d_i$$$ at the latest, where $$$d_i$$$ is a positive integer.

The jury works on days $$$1,2,3,\ldots$$$ and can prepare at most one problem per day, and no problem can be prepared twice. If problem $$$i$$$ is prepared on day $$$t$$$, then $$$t \le d_i$$$ must hold.

The jury may also drop any candidate problem. Find the maximum total quality of the final problem set.

Input

The first line contains one integer $$$N$$$ ($$$1 \le N \le 2 \cdot 10^5$$$) — the number of candidate problems.

Each of the next $$$N$$$ lines contains two integers $$$g_i$$$ and $$$d_i$$$ ($$$0 \le g_i \le 10^9$$$, $$$1 \le d_i \le 10^9$$$) — the quality and the last allowed day of problem $$$i$$$.

Output

Print one integer — the maximum total quality.

Examples
Input
5
20 1
2 1
10 2
100 2
8 3
Output
128
Input
4
1000000000 1000000000
1000000000 1000000000
1000000000 1000000000
1000000000 1000000000
Output
4000000000
Input
4
5 1
6 1
4 2
10 2
Output
16
Note

In the first example, the problems with quality $$$20$$$, $$$100$$$, and $$$8$$$ can be prepared on days $$$1$$$, $$$2$$$, and $$$3$$$, respectively.

In the third example, only one of the two problems with last allowed day $$$1$$$ can be prepared. Choosing the problems with quality $$$6$$$ and $$$10$$$ is optimal.

H. Handling Clarifications
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Every minute of the contest, some team decides that a statement is ambiguous and sends a clarification request. Elisa is the judge on duty at the clarification desk, and her shift lasts exactly $$$2n$$$ minutes. In that time she must take exactly $$$n$$$ requests and answer every one of them.

The jury rates a shift with an operations score. Taking a request the moment it arrives raises that score, because the team stops waiting. Answering lowers it, because a written reply has to be read by the whole jury before it goes out.

During minute $$$i$$$ Elisa must do exactly one of the following:

  • Take the request that arrived this minute. The score rises by $$$a_i$$$, and the request joins her queue, where it waits to be answered on a later minute.
  • Answer one request that she took earlier and has not answered yet. The score falls by $$$b_i$$$.

A request can only be answered after it has been taken. When the $$$2n$$$ minutes are over, Elisa must have taken exactly $$$n$$$ requests and answered all of them. Determine the highest operations score she can finish her shift with.

Input

The first line contains one integer $$$n$$$ ($$$1 \le n \le 10^5$$$) — the number of requests Elisa must take and answer.

The second line contains $$$2n$$$ integers $$$a_1,a_2,\ldots,a_{2n}$$$ ($$$1 \le a_i \le 10^9$$$) — the score gained by taking the request that arrives on minute $$$i$$$.

The third line contains $$$2n$$$ integers $$$b_1,b_2,\ldots,b_{2n}$$$ ($$$1 \le b_i \le 10^9$$$) — the score lost by answering a request on minute $$$i$$$.

Output

Print one integer — the highest operations score Elisa can finish her shift with, having taken and answered exactly $$$n$$$ requests.

Examples
Input
2
3 1 10 4
5 4 5 2
Output
7
Input
1
5 2
4 100
Output
-95

I. In the Team Photo
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

The contest ends with a long photo session. The $$$n$$$ participants sit in a single row, and each of them wears the jersey of the university they competed for years ago. Participant $$$i$$$ wears the jersey $$$a_i$$$, so the row is described by $$$a_1,a_2,\ldots,a_n$$$.

The archivist writes a caption for every group of consecutive participants that the photographer shoots. Two people from the same university look the same on the photo and cannot be separated in the caption, but a participant who is the only one wearing their jersey inside the group can always be named. Such a participant is a unique witness of that group.

Formally, take any non-empty contiguous stretch of seats $$$a_l,a_{l+1},\ldots,a_r$$$, and count jerseys using only the positions from $$$l$$$ through $$$r$$$. The stretch has a unique witness if there is at least one position $$$i$$$, $$$l \le i \le r$$$, such that the jersey $$$a_i$$$ occurs exactly once inside that stretch.

Only one such position is needed. The jersey does not have to be unique in the whole row: if it also appears in other parts of the row, it is still a witness where it appears alone inside the stretch.

Determine whether every non-empty contiguous stretch has a unique witness.

Input

The first line contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the number of participants.

The second line contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$-10^6 \le a_i \le 10^6$$$) — the jerseys worn by the participants.

The input contains exactly one instance.

Output

Print YES if every non-empty contiguous stretch contains at least one jersey whose frequency inside that stretch is exactly $$$1$$$. Otherwise, print NO.

The answer is compared as a case-sensitive token.

Examples
Input
5
1 2 1 3 2
Output
YES
Input
2
7 7
Output
NO
Input
3
1 2 2
Output
NO
Note

In the first example, the jersey $$$3$$$ witnesses the whole row. Jerseys $$$1$$$ and $$$2$$$ repeat along the row, but this does not prevent the answer from being YES.

In the second example, the stretch consisting of both seats contains the jersey $$$7$$$ twice and has no unique witness.

In the third example, the whole row has the witness $$$1$$$, but the stretch $$$[2,2]$$$ formed by the last two seats has no unique witness. Therefore checking only the complete row is not sufficient.

J. Journey of the Balloon Runner
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

One ICPC tradition never dies: every solved problem earns the team a balloon. Elisa is the one who delivers them.

The floor of the contest hall is covered with square tiles, and the organizers describe it as an infinite grid of cells. Elisa hands out the balloons. She starts at the cell $$$(0,0)$$$, where the balloon table stands, and the volunteer coordinator has already written her whole route for this round as one non-empty string of orders. Elisa follows the orders from left to right, and each order takes her to one of the four cells next to the current one:

  • U: walk one cell up;
  • D: walk one cell down;
  • L: walk one cell left;
  • R: walk one cell right.

The hall is large enough that she never reaches a wall, and her route may cross itself as many times as the coordinator wants.

After the round, the cleaning crew wants to know how much of the floor was used. Find the number of distinct cells Elisa steps on, including the cell $$$(0,0)$$$ where she starts.

Input

The only line contains a non-empty string $$$s$$$ ($$$1 \le |s| \le 2 \cdot 10^5$$$) — the route of the balloon runner. Every character of $$$s$$$ is one of U, D, L, or R.

Output

Print one integer — the number of distinct cells visited by the runner, including cell $$$(0,0)$$$.

Examples
Input
URDL
Output
4
Input
RRUULLDD
Output
8
Input
UUUDDD
Output
4
Note

In the first example, the runner visits $$$(0,0)$$$, $$$(0,1)$$$, $$$(1,1)$$$, and $$$(1,0)$$$. The last order returns her to $$$(0,0)$$$, which was already counted.

In the second example, the runner follows the boundary of a $$$2\times 2$$$ square. She returns to the initial cell after visiting eight distinct cells.