contestId int64 0 1.01k | name stringlengths 2 58 | tags listlengths 0 11 | title stringclasses 523
values | time-limit stringclasses 8
values | memory-limit stringclasses 8
values | problem-description stringlengths 0 7.15k | input-specification stringlengths 0 2.05k | output-specification stringlengths 0 1.5k | demo-input listlengths 0 7 | demo-output listlengths 0 7 | note stringlengths 0 5.24k | test_cases listlengths 0 402 | timeConsumedMillis int64 0 8k | memoryConsumedBytes int64 0 537M | score float64 -1 3.99 | __index_level_0__ int64 0 621k |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
56 | Domino Principle | [
"binary search",
"data structures",
"sortings"
] | E. Domino Principle | 2 | 256 | Vasya is interested in arranging dominoes. He is fed up with common dominoes and he uses the dominoes of different heights. He put *n* dominoes on the table along one axis, going from left to right. Every domino stands perpendicular to that axis so that the axis passes through the center of its base. The *i*-th domino ... | The first line contains integer *n* (1<=≤<=*n*<=≤<=105) which is the number of dominoes. Then follow *n* lines containing two integers *x**i* and *h**i* (<=-<=108<=≤<=*x**i*<=≤<=108,<=2<=≤<=*h**i*<=≤<=108) each, which are the coordinate and height of every domino. No two dominoes stand on one point. | Print *n* space-separated numbers *z**i* — the number of dominoes that will fall if Vasya pushes the *i*-th domino to the right (including the domino itself). | [
"4\n16 5\n20 5\n10 10\n18 2\n",
"4\n0 10\n1 5\n9 10\n15 10\n"
] | [
"3 1 4 1 ",
"4 1 2 1 "
] | none | [
{
"input": "4\n16 5\n20 5\n10 10\n18 2",
"output": "3 1 4 1 "
},
{
"input": "4\n0 10\n1 5\n9 10\n15 10",
"output": "4 1 2 1 "
},
{
"input": "3\n6 7\n2 9\n-6 10",
"output": "1 2 3 "
},
{
"input": "4\n-6 9\n9 5\n-7 4\n0 9",
"output": "2 1 3 1 "
},
{
"input": "5\n-47... | 2,000 | 17,100,800 | 0 | 49,893 |
201 | Clear Symmetry | [
"constructive algorithms",
"dp",
"math"
] | null | null | Consider some square matrix *A* with side *n* consisting of zeros and ones. There are *n* rows numbered from 1 to *n* from top to bottom and *n* columns numbered from 1 to *n* from left to right in this matrix. We'll denote the element of the matrix which is located at the intersection of the *i*-row and the *j*-th col... | The only line contains a single integer *x* (1<=≤<=*x*<=≤<=100) — the required sharpness of the matrix. | Print a single number — the sought value of *n*. | [
"4\n",
"9\n"
] | [
"3\n",
"5\n"
] | The figure below shows the matrices that correspond to the samples: | [
{
"input": "4",
"output": "3"
},
{
"input": "9",
"output": "5"
},
{
"input": "10",
"output": "5"
},
{
"input": "12",
"output": "5"
},
{
"input": "1",
"output": "1"
},
{
"input": "19",
"output": "7"
},
{
"input": "3",
"output": "5"
},
... | 124 | 0 | 0 | 49,909 | |
847 | Noise Level | [
"dfs and similar",
"implementation",
"math"
] | null | null | The Berland's capital has the form of a rectangle with sizes *n*<=×<=*m* quarters. All quarters are divided into three types:
- regular (labeled with the character '.') — such quarters do not produce the noise but are not obstacles to the propagation of the noise; - sources of noise (labeled with an uppercase Latin ... | The first line contains four integers *n*, *m*, *q* and *p* (1<=≤<=*n*,<=*m*<=≤<=250, 1<=≤<=*q*,<=*p*<=≤<=106) — the sizes of Berland's capital, the number of noise units that a quarter 'A' produces, and the allowable noise level.
Each of the following *n* lines contains *m* characters — the description of the capital... | Print the number of quarters, in which the noise level exceeds the allowed level *p*. | [
"3 3 100 140\n...\nA*.\n.B.\n",
"3 3 2 8\nB*.\nBB*\nBBB\n",
"3 4 5 4\n..*B\n..**\nD...\n"
] | [
"3\n",
"4\n",
"7\n"
] | The illustration to the first example is in the main part of the statement. | [] | 5,000 | 5,324,800 | 0 | 49,947 | |
887 | Little Brother | [
"binary search",
"geometry",
"sortings"
] | null | null | Masha's little brother draw two points on a sheet of paper. After that, he draws some circles and gave the sheet to his sister.
Masha has just returned from geometry lesson so she instantly noticed some interesting facts about brother's drawing.
At first, the line going through two points, that brother drew, doesn't... | First line contains four integers *x*1, *y*1, *x*2, *y*2 (<=-<=105<=≤<=*x*1,<=*y*1,<=*x*2,<=*y*2<=≤<=105) — coordinates of points that brother drew. First point has coordinates (*x*1, *y*1) and second point has coordinates (*x*2, *y*2). These two points are different.
The second line contains single integer *n* (1<=≤<... | Output smallest real number, that it's possible to draw a circle with such radius through given points in such a way that it doesn't intersect other circles.
The output is considered correct if it has a relative or absolute error of at most 10<=-<=4. | [
"2 4 7 13\n3\n3 0 1\n12 4 2\n-4 14 2\n",
"-2 3 10 -10\n2\n7 0 3\n-5 -5 2\n"
] | [
"5.1478150705",
"9.1481831923"
] | <img class="tex-graphics" src="https://espresso.codeforces.com/5a8f62f2439db62d006a0959f077351937f109a0.png" style="max-width: 100.0%;max-height: 100.0%;"/> <img class="tex-graphics" src="https://espresso.codeforces.com/0500120c641e4aab8bb5490323ce5a68957a6621.png" style="max-width: 100.0%;max-height: 100.0%;"/> | [] | 46 | 0 | 0 | 50,085 | |
374 | Inna and Sequence | [
"binary search",
"data structures",
"dp",
"trees"
] | null | null | Dima's spent much time thinking what present to give to Inna and gave her an empty sequence *w*. Now they want to fill sequence *w* with numbers zero and one. For that, they decided to play an amusing game.
Before the game begins, Dima chooses *m* integers *a*1,<=*a*2,<=...,<=*a**m* (1<=≤<=*a*1<=<<=*a*2<=<<=...... | The first line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=106) showing how many events took place and how many numbers Dima chose.
The next line contains *m* distinct integers *a**i* (1<=≤<=*a**i*<=≤<=106) sorted in the increasing order.
Next *n* lines describe the events in the chronologica... | In a single line print a sequence of numbers 0 and 1 — the elements of the sequence after all events happen. Print the elements of the sequence in the order from the beginning to the end of the sequence.
If after all events the sequence ends up empty, print "Poor stack!". | [
"10 3\n1 3 6\n-1\n1\n1\n0\n0\n-1\n0\n1\n-1\n1\n",
"2 1\n1\n1\n-1\n"
] | [
"011\n",
"Poor stack!\n"
] | none | [
{
"input": "10 3\n1 3 6\n-1\n1\n1\n0\n0\n-1\n0\n1\n-1\n1",
"output": "011"
},
{
"input": "2 1\n1\n1\n-1",
"output": "Poor stack!"
},
{
"input": "2 1\n1\n-1\n0",
"output": "0"
},
{
"input": "11 2\n2 4\n1\n-1\n1\n-1\n0\n0\n-1\n1\n1\n1\n-1",
"output": "111"
},
{
"inp... | 140 | 0 | 0 | 50,253 | |
196 | Paint Tree | [
"constructive algorithms",
"divide and conquer",
"geometry",
"sortings",
"trees"
] | null | null | You are given a tree with *n* vertexes and *n* points on a plane, no three points lie on one straight line.
Your task is to paint the given tree on a plane, using the given points as vertexes.
That is, you should correspond each vertex of the tree to exactly one point and each point should correspond to a vertex. If... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=1500) — the number of vertexes on a tree (as well as the number of chosen points on the plane).
Each of the next *n*<=-<=1 lines contains two space-separated integers *u**i* and *v**i* (1<=≤<=*u**i*,<=*v**i*<=≤<=*n*, *u**i*<=≠<=*v**i*) — the numbers of tree vertexe... | Print *n* distinct space-separated integers from 1 to *n*: the *i*-th number must equal the number of the vertex to place at the *i*-th point (the points are numbered in the order, in which they are listed in the input).
If there are several solutions, print any of them. | [
"3\n1 3\n2 3\n0 0\n1 1\n2 0\n",
"4\n1 2\n2 3\n1 4\n-1 -2\n3 5\n-3 3\n2 0\n"
] | [
"1 3 2\n",
"4 2 1 3\n"
] | The possible solutions for the sample are given below. | [] | 92 | 0 | 0 | 50,265 | |
633 | Spy Syndrome 2 | [
"data structures",
"dp",
"hashing",
"implementation",
"sortings",
"string suffix structures",
"strings"
] | null | null | After observing the results of Spy Syndrome, Yash realised the errors of his ways. He now believes that a super spy such as Siddhant can't use a cipher as basic and ancient as Caesar cipher. After many weeks of observation of Siddhant’s sentences, Yash determined a new cipher technique.
For a given sentence, the ciphe... | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=10<=000) — the length of the ciphered text. The second line consists of *n* lowercase English letters — the ciphered text *t*.
The third line contains a single integer *m* (1<=≤<=*m*<=≤<=100<=000) — the number of words which will be considered wh... | Print one line — the original sentence. It is guaranteed that at least one solution exists. If there are multiple solutions, you may output any of those. | [
"30\nariksihsidlihcdnaehsetahgnisol\n10\nKira\nhates\nis\nhe\nlosing\ndeath\nchildish\nL\nand\nNote\n",
"12\niherehtolleh\n5\nHI\nHo\nthere\nHeLLo\nhello\n"
] | [
"Kira is childish and he hates losing \n",
"HI there HeLLo \n"
] | In sample case 2 there may be multiple accepted outputs, "HI there HeLLo" and "HI there hello" you may output any of them. | [
{
"input": "30\nariksihsidlihcdnaehsetahgnisol\n10\nKira\nhates\nis\nhe\nlosing\ndeath\nchildish\nL\nand\nNote",
"output": "Kira is childish and he hates losing "
},
{
"input": "12\niherehtolleh\n5\nHI\nHo\nthere\nHeLLo\nhello",
"output": "HI there HeLLo "
},
{
"input": "71\nbaaaaaaaaaaa... | 327 | 12,390,400 | -1 | 50,332 | |
7 | Defining Macros | [
"dp",
"expression parsing",
"implementation"
] | E. Defining Macros | 3 | 256 | Most C/C++ programmers know about excellent opportunities that preprocessor #define directives give; but many know as well about the problems that can arise because of their careless use.
In this problem we consider the following model of #define constructions (also called macros). Each macro has its name and value. T... | The first line contains the only number *n* (0<=≤<=*n*<=≤<=100) — the amount of #define constructions in the given program.
Then there follow *n* lines, each of them contains just one #define construction. Each construction has the following syntax:
#define name expression
where
- name — the macro name, - express... | Output "OK", if the expression is correct according to the above given criterion, otherwise output "Suspicious". | [
"1\n#define sum x + y\n1 * sum\n",
"1\n#define sum (x + y)\nsum - sum\n",
"4\n#define sum x + y\n#define mul a * b\n#define div a / b\n#define expr sum + mul * div * mul\nexpr\n",
"3\n#define SumSafe (a+b)\n#define DivUnsafe a/b\n#define DenominatorUnsafe a*b\n((SumSafe) + DivUnsafe/DivUnsafe + x/Deno... | [
"Suspicious\n",
"OK\n",
"OK\n",
"Suspicious\n"
] | none | [
{
"input": "1\n#define sum x + y\n1 * sum",
"output": "Suspicious"
},
{
"input": "1\n#define sum (x + y)\nsum - sum",
"output": "OK"
},
{
"input": "4\n#define sum x + y\n#define mul a * b\n#define div a / b\n#define expr sum + mul * div * mul\nexpr",
"output": "OK"
},
{
"... | 122 | 102,400 | 3.979476 | 50,405 |
472 | Design Tutorial: Increase the Constraints | [
"bitmasks",
"data structures",
"fft"
] | null | null | There is a simple way to create hard tasks: take one simple problem as the query, and try to find an algorithm that can solve it faster than bruteforce. This kind of tasks usually appears in OI contest, and usually involves data structures.
Let's try to create a task, for example, we take the "Hamming distance problem... | The first line contains a string *a* (1<=≤<=|*a*|<=≤<=200000). The second line contains a string *b* (1<=≤<=|*b*|<=≤<=200000). Each character of both strings is either "0" or "1".
The third line contains an integer *q* (1<=≤<=*q*<=≤<=400000) — the number of queries. Each of the following *q* lines contains three integ... | Output *q* integers — the answers for the queries. | [
"101010\n11110000\n3\n0 0 3\n2 3 4\n5 7 1\n",
"10001010101011001010100101010011010\n101010100101001010100100101010\n5\n0 0 12\n3 9 7\n6 4 15\n12 15 10\n13 3 20\n"
] | [
"1\n1\n0\n",
"5\n4\n3\n5\n13\n"
] | none | [] | 31 | 0 | 0 | 50,409 | |
939 | Cutlet | [
"data structures",
"dp"
] | null | null | Arkady wants to have a dinner. He has just returned from a shop where he has bought a semifinished cutlet. He only needs to fry it. The cutlet should be fried for 2*n* seconds, in particular, it should be fried for *n* seconds on one side and *n* seconds on the other side. Arkady has already got a frying pan and turn o... | The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=100<=000, 1<=≤<=*k*<=≤<=100) — the number of seconds the cutlet should be cooked on each side and number of periods of time in which Arkady can flip it.
The next *k* lines contain descriptions of these intervals. Each line contains two integers *l**i* and... | Output "Hungry" if Arkady won't be able to fry the cutlet for exactly *n* seconds on one side and exactly *n* seconds on the other side.
Otherwise, output "Full" in the first line, and the minimum number of times he should flip the cutlet in the second line. | [
"10 2\n3 5\n11 13\n",
"10 3\n3 5\n9 10\n11 13\n",
"20 1\n3 19\n"
] | [
"Full\n2\n",
"Full\n1\n",
"Hungry\n"
] | In the first example Arkady should flip the cutlet in time moment 3 seconds after he starts cooking and in time moment 13 seconds after he starts cooking.
In the second example, Arkady can flip the cutlet at 10 seconds after he starts cooking. | [
{
"input": "10 2\n3 5\n11 13",
"output": "Full\n2"
},
{
"input": "10 3\n3 5\n9 10\n11 13",
"output": "Full\n1"
},
{
"input": "20 1\n3 19",
"output": "Hungry"
},
{
"input": "10 1\n0 20",
"output": "Full\n1"
},
{
"input": "10 1\n0 1",
"output": "Hungry"
},
{... | 140 | 4,300,800 | 0 | 50,497 | |
468 | Permanent | [
"dp",
"graph matchings",
"math",
"meet-in-the-middle"
] | null | null | Little X has solved the #P-complete problem in polynomial time recently. So he gives this task to you.
There is a special *n*<=×<=*n* matrix *A*, you should calculate its permanent modulo 1000000007 (109<=+<=7). The special property of matrix *A* is almost all its elements equal to 1. Only *k* elements have specified... | The first line contains two space-separated integers *n*,<=*k* (1<=≤<=*n*<=≤<=105; 1<=≤<=*k*<=≤<=50).
The next *k* lines contain the description of the matrix. The *i*-th line contains three space-separated integers *x**i*,<=*y**i*,<=*w**i* (1<=≤<=*x**i*,<=<=*y**i*<=≤<=<=*n*; 0<=<=≤<=<=*w**i*<=<=≤<=109). These numbers... | Print the permanent of the matrix modulo 1000000007 (109<=<=+<=<=7). | [
"3 1\n1 1 2\n",
"10 10\n3 3 367056794\n6 2 124561273\n1 3 46718146\n6 9 415916869\n10 5 985968336\n3 1 526792265\n1 4 386357058\n10 4 349304187\n2 7 102032499\n3 6 502679075\n"
] | [
"8\n",
"233333333\n"
] | none | [] | 31 | 0 | 0 | 50,516 | |
222 | Decoding Genome | [
"dp",
"matrices"
] | null | null | Recently a top secret mission to Mars has taken place. As a result, scientists managed to obtain some information about the Martian DNA. Now we know that any Martian DNA contains at most *m* different nucleotides, numbered from 1 to *m*. Special characteristics of the Martian DNA prevent some nucleotide pairs from foll... | The first line contains three space-separated integers *n*,<=*m*,<=*k* (1<=≤<=*n*<=≤<=1015, 1<=≤<=*m*<=≤<=52, 0<=≤<=*k*<=≤<=*m*2).
Next *k* lines contain two characters each, without a space between them, representing a forbidden nucleotide pair. The first character represents the first nucleotide in the forbidden pai... | Print a single integer — the sought number modulo 1000000007 (109<=+<=7). | [
"3 3 2\nab\nba\n",
"3 3 0\n",
"2 1 1\naa\n"
] | [
"17\n",
"27\n",
"0\n"
] | In the second test case all possible three-nucleotide DNAs are permitted. Each nucleotide can take one of three values, thus in total there are 27 distinct three nucleotide DNAs.
In the third test sample we cannot make any DNA of two nucleotides — the only possible nucleotide "a" cannot occur two times consecutively. | [
{
"input": "3 3 2\nab\nba",
"output": "17"
},
{
"input": "3 3 0",
"output": "27"
},
{
"input": "2 1 1\naa",
"output": "0"
},
{
"input": "3 5 4\ncd\nce\ned\nee",
"output": "89"
},
{
"input": "100 5 4\ncd\nce\ned\nee",
"output": "537303881"
},
{
"input":... | 2,000 | 9,113,600 | 0 | 50,536 | |
676 | The Last Fight Between Human and AI | [
"math"
] | null | null | 100 years have passed since the last victory of the man versus computer in Go. Technologies made a huge step forward and robots conquered the Earth! It's time for the final fight between human and robot that will decide the faith of the planet.
The following game was chosen for the fights: initially there is a polynom... | The first line of the input contains two integers *n* and *k* (1<=≤<=*n*<=≤<=100<=000,<=|*k*|<=≤<=10<=000) — the size of the polynomial and the integer *k*.
The *i*-th of the following *n*<=+<=1 lines contain character '?' if the coefficient near *x**i*<=-<=1 is yet undefined or the integer value *a**i*, if the coeffi... | Print "Yes" (without quotes) if the human has winning strategy, or "No" (without quotes) otherwise. | [
"1 2\n-1\n?\n",
"2 100\n-10000\n0\n1\n",
"4 5\n?\n1\n?\n1\n?\n"
] | [
"Yes\n",
"Yes",
"No"
] | In the first sample, computer set *a*<sub class="lower-index">0</sub> to - 1 on the first move, so if human can set coefficient *a*<sub class="lower-index">1</sub> to 0.5 and win.
In the second sample, all coefficients are already set and the resulting polynomial is divisible by *x* - 100, so the human has won. | [
{
"input": "1 2\n-1\n?",
"output": "Yes"
},
{
"input": "2 100\n-10000\n0\n1",
"output": "Yes"
},
{
"input": "4 5\n?\n1\n?\n1\n?",
"output": "No"
},
{
"input": "68 -9959\n-3666\n-3501\n9169\n5724\n1478\n-643\n-3039\n-5537\n-4295\n-1856\n-6720\n6827\n-39\n-9509\n-7005\n1942\n-5... | 46 | 0 | 0 | 50,599 | |
377 | Cookie Clicker | [
"dp",
"geometry"
] | null | null | Kostya is playing the computer game Cookie Clicker. The goal of this game is to gather cookies. You can get cookies using different buildings: you can just click a special field on the screen and get the cookies for the clicks, you can buy a cookie factory, an alchemy lab, a time machine and it all will bring lots and ... | The first line contains two integers *n* and *s* (1<=≤<=*n*<=≤<=2·105, 1<=≤<=*s*<=≤<=1016) — the number of buildings in the game and the number of cookies Kostya wants to earn.
Each of the next *n* lines contains two integers *v**i* and *c**i* (1<=≤<=*v**i*<=≤<=108, 0<=≤<=*c**i*<=≤<=108) — the number of cookies the *i... | Output the only integer — the minimum number of seconds Kostya needs to earn at least *s* cookies. It is guaranteed that he can do it. | [
"3 9\n1 0\n2 3\n5 4\n",
"3 6\n1 0\n2 2\n5 4\n",
"3 13\n1 0\n2 2\n6 5\n",
"1 10000000000000000\n1 0\n"
] | [
"6\n",
"5\n",
"7\n",
"10000000000000000\n"
] | none | [] | 30 | 0 | 0 | 50,700 | |
193 | Hamming Distance | [
"constructive algorithms",
"greedy",
"math",
"matrices"
] | null | null | Hamming distance between strings *a* and *b* of equal length (denoted by *h*(*a*,<=*b*)) is equal to the number of distinct integers *i* (1<=≤<=*i*<=≤<=|*a*|), such that *a**i*<=≠<=*b**i*, where *a**i* is the *i*-th symbol of string *a*, *b**i* is the *i*-th symbol of string *b*. For example, the Hamming distance betwe... | The first line contains space-separated integers *h*(*s*1,<=*s*2), *h*(*s*1,<=*s*3), *h*(*s*1,<=*s*4). The second line contains space-separated integers *h*(*s*2,<=*s*3) and *h*(*s*2,<=*s*4). The third line contains the single integer *h*(*s*3,<=*s*4).
All given integers *h*(*s**i*,<=*s**j*) are non-negative and do no... | Print -1 if there's no suitable set of strings.
Otherwise print on the first line number *len* — the length of each string. On the *i*-th of the next four lines print string *s*'*i*. If there are multiple sets with the minimum length of the strings, print any of them. | [
"4 4 4\n4 4\n4\n"
] | [
"6\naaaabb\naabbaa\nbbaaaa\nbbbbbb\n"
] | none | [
{
"input": "4 4 4\n4 4\n4",
"output": "6\naaaabb\naabbaa\nbbaaaa\nbbbbbb"
},
{
"input": "10 10 8\n8 8\n10",
"output": "14\naaaabaaaabbbbb\nbaaabbbbbaaaaa\nbbbbaaaaaaaaaa\nbbbbbbbbbbbbbb"
},
{
"input": "50109 50255 50102\n50104 50011\n50085",
"output": "75234\naaaaaaaaaaaaaaaaaaaaaaaa... | 46 | 0 | 0 | 50,755 | |
559 | Randomizer | [
"combinatorics",
"geometry",
"probabilities"
] | null | null | Gerald got tired of playing board games with the usual six-sided die, and he bought a toy called Randomizer. It functions as follows.
A Randomizer has its own coordinate plane on which a strictly convex polygon is painted, the polygon is called a basic polygon. If you shake a Randomizer, it draws some nondegenerate (i... | The first line of the input contains a single integer *n* (3<=≤<=*n*<=≤<=100<=000) — the number of vertices of the basic polygon.
Next *n* lines contain the coordinates of the vertices of the basic polygon. The *i*-th of these lines contain two integers *x**i* and *y**i* (<=-<=109<=≤<=*x**i*,<=*y**i*<=≤<=109) — the c... | Print the sought expected value with absolute or relative error at most 10<=-<=9. | [
"4\n0 0\n2 0\n2 2\n0 2\n",
"5\n0 0\n2 0\n2 2\n1 3\n0 2\n"
] | [
"0.2\n",
"0.8125\n"
] | A polygon is called strictly convex if it is convex and no its vertices lie on the same line.
Let's assume that a random variable takes values *x*<sub class="lower-index">1</sub>, ..., *x*<sub class="lower-index">*n*</sub> with probabilities *p*<sub class="lower-index">1</sub>, ..., *p*<sub class="lower-index">*n*</su... | [
{
"input": "4\n0 0\n2 0\n2 2\n0 2",
"output": "0.2"
},
{
"input": "5\n0 0\n2 0\n2 2\n1 3\n0 2",
"output": "0.8125"
},
{
"input": "4\n0 0\n3 0\n2 2\n0 3",
"output": "1.2"
},
{
"input": "4\n0 0\n100 0\n67 69\n0 100",
"output": "3999.6"
},
{
"input": "20\n89100 45399... | 62 | 0 | 0 | 50,950 | |
0 | none | [
"none"
] | null | null | Nanami is an expert at playing games. This day, Nanami's good friend Hajime invited her to watch a game of baseball. Unwilling as she was, she followed him to the stadium. But Nanami had no interest in the game, so she looked around to see if there was something that might interest her. That's when she saw the digital ... | The first line contains three space-separated integers *n*, *m* and *q* (1<=≤<=*n*,<=*m*,<=*q*<=≤<=1000) — the height and width of the digital board, and the number of operations.
Then follow *n* lines, each line containing *m* space-separated integers. The *j*-th integer of the *i*-th line is *a**i*,<=*j* — the initi... | For each query, print a single line containing one integer — the answer to Nanami's query. | [
"3 4 5\n0 1 1 0\n1 0 0 1\n0 1 1 0\n2 2 2\n2 1 2\n1 2 2\n1 2 3\n2 2 2\n",
"3 3 4\n1 1 1\n1 1 1\n1 1 1\n2 2 2\n1 2 2\n2 1 1\n2 2 1\n"
] | [
"0\n2\n6\n",
"6\n3\n3\n"
] | Consider the first sample.
The first query specifies pixel (2, 2), which is dark itself, so there are no valid light blocks, thus the answer is 0.
The second query specifies pixel (1, 2). The biggest light block is the block with (1, 2) as its upper-left vertex and (1, 3) as its lower-right vertex.
The last query sp... | [] | 1,000 | 96,256,000 | 0 | 51,173 | |
0 | none | [
"none"
] | null | null | You already know that Valery's favorite sport is biathlon. Due to your help, he learned to shoot without missing, and his skills are unmatched at the shooting range. But now a smaller task is to be performed, he should learn to complete the path fastest.
The track's map is represented by a rectangle *n*<=×<=*m* in siz... | The first input line contains three integers *n*, *m* and *k* (1<=≤<=*n*,<=*m*<=≤<=50,<=*n*·*m*<=≥<=2,<=1<=≤<=*k*<=≤<=4). Then *n* lines contain the map. Each line has the length of exactly *m* characters and consists of lowercase Latin letters and characters *S* and *T*. It is guaranteed that the map contains exactly ... | If there is a path that satisfies the condition, print it as a sequence of letters — the plot types. Otherwise, print "-1" (without quotes). You shouldn't print the character *S* in the beginning and *T* in the end.
Note that this sequence may be empty. This case is present in pretests. You can just print nothing or p... | [
"5 3 2\nSba\nccc\naac\nccc\nabT\n",
"3 4 1\nSxyy\nyxxx\nyyyT\n",
"1 3 3\nTyS\n",
"1 4 1\nSxyT\n"
] | [
"bcccc\n",
"xxxx\n",
"y\n",
"-1\n"
] | none | [
{
"input": "5 3 2\nSba\nccc\naac\nccc\nabT",
"output": "bcccc"
},
{
"input": "3 4 1\nSxyy\nyxxx\nyyyT",
"output": "xxxx"
},
{
"input": "1 3 3\nTyS",
"output": "y"
},
{
"input": "1 4 1\nSxyT",
"output": "-1"
},
{
"input": "1 3 3\nSaT",
"output": "a"
},
{
... | 5,000 | 614,400 | 0 | 51,423 | |
412 | Giving Awards | [
"dfs and similar"
] | null | null | The employees of the R1 company often spend time together: they watch football, they go camping, they solve contests. So, it's no big deal that sometimes someone pays for someone else.
Today is the day of giving out money rewards. The R1 company CEO will invite employees into his office one by one, rewarding each one ... | The first line contains space-separated integers *n* and *m* — the number of employees in R1 and the number of debt relations. Each of the following *m* lines contains two space-separated integers *a**i*, *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*; *a**i*<=≠<=*b**i*), these integers indicate that the person number *a**i* o... | Print -1 if the described order does not exist. Otherwise, print the permutation of *n* distinct integers. The first number should denote the number of the person who goes to the CEO office first, the second number denote the person who goes second and so on.
If there are multiple correct orders, you are allowed to pr... | [
"2 1\n1 2\n",
"3 3\n1 2\n2 3\n3 1\n"
] | [
"2 1 \n",
"2 1 3 \n"
] | none | [
{
"input": "2 1\n1 2",
"output": "2 1 "
},
{
"input": "3 3\n1 2\n2 3\n3 1",
"output": "2 1 3 "
},
{
"input": "10 45\n10 5\n10 7\n6 1\n5 8\n3 5\n6 5\n1 2\n6 10\n2 9\n9 5\n4 1\n7 5\n1 8\n6 8\n10 9\n7 2\n7 9\n4 10\n7 3\n4 8\n10 3\n10 8\n2 10\n8 2\n4 2\n5 2\n9 1\n4 5\n1 3\n9 6\n3 8\n5 1\n6 4... | 46 | 0 | 0 | 51,427 | |
0 | none | [
"none"
] | null | null | Maxim loves to fill in a matrix in a special manner. Here is a pseudocode of filling in a matrix of size (*m*<=+<=1)<=×<=(*m*<=+<=1):
Maxim asks you to count, how many numbers *m* (1<=≤<=*m*<=≤<=*n*) are there, such that the sum of values in the cells in the row number *m*<=+<=1 of the resulting matrix equals *t*.
... | A single line contains two integers *n* and *t* (1<=≤<=*n*,<=*t*<=≤<=1012,<=*t*<=≤<=*n*<=+<=1).
Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier. | In a single line print a single integer — the answer to the problem. | [
"1 1\n",
"3 2\n",
"3 3\n",
"1000000000000 1048576\n"
] | [
"1\n",
"1\n",
"0\n",
"118606527258\n"
] | none | [
{
"input": "1 1",
"output": "1"
},
{
"input": "3 2",
"output": "1"
},
{
"input": "3 3",
"output": "0"
},
{
"input": "1000000000000 1048576",
"output": "118606527258"
},
{
"input": "35 4",
"output": "11"
},
{
"input": "70 32",
"output": "1"
},
{... | 186 | 0 | 3 | 51,580 | |
976 | Minimal k-covering | [
"flows",
"graphs"
] | null | null | You are given a bipartite graph *G*<==<=(*U*,<=*V*,<=*E*), *U* is the set of vertices of the first part, *V* is the set of vertices of the second part and *E* is the set of edges. There might be multiple edges.
Let's call some subset of its edges *k*-covering iff the graph has each of its vertices incident to at lea... | The first line contains three integers *n*1, *n*2 and *m* (1<=≤<=*n*1,<=*n*2<=≤<=2000, 0<=≤<=*m*<=≤<=2000) — the number of vertices in the first part, the number of vertices in the second part and the number of edges, respectively.
The *i*-th of the next *m* lines contain two integers *u**i* and *v**i* (1<=≤<=*u**i*<=... | For each print the subset of edges (minimal *k*-covering) in separate line.
The first integer *cnt**k* of the *k*-th line is the number of edges in minimal *k*-covering of the graph. Then *cnt**k* integers follow — original indices of the edges which belong to the minimal *k*-covering, these indices should be pairwis... | [
"3 3 7\n1 2\n2 3\n1 3\n3 2\n3 3\n2 1\n2 1\n",
"1 1 5\n1 1\n1 1\n1 1\n1 1\n1 1\n"
] | [
"0 \n3 3 7 4 \n6 1 3 6 7 4 5 \n",
"0 \n1 5 \n2 4 5 \n3 3 4 5 \n4 2 3 4 5 \n5 1 2 3 4 5 \n"
] | none | [
{
"input": "3 3 7\n1 2\n2 3\n1 3\n3 2\n3 3\n2 1\n2 1",
"output": "0 \n3 3 7 4 \n6 1 3 6 7 4 5 "
},
{
"input": "1 1 5\n1 1\n1 1\n1 1\n1 1\n1 1",
"output": "0 \n1 5 \n2 4 5 \n3 3 4 5 \n4 2 3 4 5 \n5 1 2 3 4 5 "
},
{
"input": "1 1 0",
"output": "0 "
},
{
"input": "2000 2000 1\n1... | 1,500 | 51,097,600 | 0 | 51,721 | |
618 | Hamiltonian Spanning Tree | [
"dfs and similar",
"dp",
"graph matchings",
"greedy",
"trees"
] | null | null | A group of *n* cities is connected by a network of roads. There is an undirected road between every pair of cities, so there are roads in total. It takes exactly *y* seconds to traverse any single road.
A spanning tree is a set of roads containing exactly *n*<=-<=1 roads such that it's possible to travel between any ... | The first line of the input contains three integers *n*, *x* and *y* (2<=≤<=*n*<=≤<=200<=000,<=1<=≤<=*x*,<=*y*<=≤<=109).
Each of the next *n*<=-<=1 lines contains a description of a road in the spanning tree. The *i*-th of these lines contains two integers *u**i* and *v**i* (1<=≤<=*u**i*,<=*v**i*<=≤<=*n*) — indices of... | Print a single integer — the minimum number of seconds one needs to spend in order to visit all the cities exactly once. | [
"5 2 3\n1 2\n1 3\n3 4\n5 3\n",
"5 3 2\n1 2\n1 3\n3 4\n5 3\n"
] | [
"9\n",
"8\n"
] | In the first sample, roads of the spanning tree have cost 2, while other roads have cost 3. One example of an optimal path is <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/3a11f64ac0349d4ecd3a2b4c3443aeb7ac3b28b9.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
In the second sample,... | [
{
"input": "5 2 3\n1 2\n1 3\n3 4\n5 3",
"output": "9"
},
{
"input": "5 3 2\n1 2\n1 3\n3 4\n5 3",
"output": "8"
},
{
"input": "50 23129 410924\n18 28\n17 23\n21 15\n18 50\n50 11\n32 3\n44 41\n50 31\n50 34\n5 14\n36 13\n22 40\n20 9\n9 43\n19 47\n48 40\n20 22\n33 45\n35 22\n33 24\n9 6\n13 1... | 0 | 0 | -1 | 52,042 | |
528 | Fuzzy Search | [
"bitmasks",
"brute force",
"fft"
] | null | null | Leonid works for a small and promising start-up that works on decoding the human genome. His duties include solving complex problems of finding certain patterns in long strings consisting of letters 'A', 'T', 'G' and 'C'.
Let's consider the following scenario. There is a fragment of a human DNA chain, recorded as a st... | The first line contains three integers |*S*|,<=|*T*|,<=*k* (1<=≤<=|*T*|<=≤<=|*S*|<=≤<=200<=000, 0<=≤<=*k*<=≤<=200<=000) — the lengths of strings *S* and *T* and the error threshold.
The second line contains string *S*.
The third line contains string *T*.
Both strings consist only of uppercase letters 'A', 'T', 'G' a... | Print a single number — the number of occurrences of *T* in *S* with the error threshold *k* by the given definition. | [
"10 4 1\nAGCAATTCAT\nACAT\n"
] | [
"3\n"
] | If you happen to know about the structure of the human genome a little more than the author of the problem, and you are not impressed with Leonid's original approach, do not take everything described above seriously. | [
{
"input": "10 4 1\nAGCAATTCAT\nACAT",
"output": "3"
},
{
"input": "1 1 0\nA\nA",
"output": "1"
},
{
"input": "1 1 0\nA\nT",
"output": "0"
},
{
"input": "1 1 1\nA\nT",
"output": "0"
},
{
"input": "5 3 0\nATATA\nATA",
"output": "2"
},
{
"input": "5 3 1\... | 30 | 0 | 0 | 52,059 | |
1,000 | We Need More Bosses | [
"dfs and similar",
"graphs",
"trees"
] | null | null | Your friend is developing a computer game. He has already decided how the game world should look like — it should consist of $n$ locations connected by $m$ two-way passages. The passages are designed in such a way that it should be possible to get from any location to any other location.
Of course, some passages shoul... | The first line contains two integers $n$ and $m$ ($2 \le n \le 3 \cdot 10^5$, $n - 1 \le m \le 3 \cdot 10^5$) — the number of locations and passages, respectively.
Then $m$ lines follow, each containing two integers $x$ and $y$ ($1 \le x, y \le n$, $x \ne y$) describing the endpoints of one of the passages.
It is gua... | Print one integer — the maximum number of bosses your friend can place, considering all possible choices for $s$ and $t$. | [
"5 5\n1 2\n2 3\n3 1\n4 1\n5 2\n",
"4 3\n1 2\n4 3\n3 2\n"
] | [
"2\n",
"3\n"
] | none | [
{
"input": "5 5\n1 2\n2 3\n3 1\n4 1\n5 2",
"output": "2"
},
{
"input": "4 3\n1 2\n4 3\n3 2",
"output": "3"
},
{
"input": "50 72\n35 38\n19 46\n35 12\n27 30\n23 41\n50 16\n31 6\n20 33\n38 1\n10 35\n13 43\n29 25\n25 4\n1 13\n4 20\n36 29\n13 47\n48 5\n30 21\n30 38\n28 50\n41 45\n25 43\n40 3... | 1,497 | 268,390,400 | 0 | 52,074 | |
46 | Hercule Poirot Problem | [
"dsu",
"graphs"
] | F. Hercule Poirot Problem | 2 | 256 | Today you are to solve the problem even the famous Hercule Poirot can't cope with! That's why this crime has not yet been solved and this story was never included in Agatha Christie's detective story books.
You are not informed on what crime was committed, when and where the corpse was found and other details. We onl... | The first line contains three preset integers *n*, *m* и *k* (1<=≤<=*n*,<=*m*,<=*k*<=≤<=1000) — the number of rooms, the number of doors and the number of house residents respectively. The next *m* lines contain pairs of room numbers which join the doors. The rooms are numbered with integers from 1 to *n*. There cannot... | Print "YES" (without quotes) if the second arrangement can result from the first one, otherwise, print "NO". | [
"2 1 2\n1 2\nDmitry 1 1 1\nNatalia 2 0\nNatalia 1 1 1\nDmitry 2 0\n",
"4 4 3\n1 3\n1 2\n2 3\n3 4\nArtem 1 1 4\nDmitry 1 1 2\nEdvard 4 2 1 3\nArtem 2 0\nDmitry 1 0\nEdvard 4 4 1 2 3 4\n"
] | [
"YES\n",
"NO\n"
] | none | [
{
"input": "2 1 2\n1 2\nDmitry 1 1 1\nNatalia 2 0\nNatalia 1 1 1\nDmitry 2 0",
"output": "YES"
},
{
"input": "4 4 3\n1 3\n1 2\n2 3\n3 4\nArtem 1 1 4\nDmitry 1 1 2\nEdvard 4 2 1 3\nArtem 2 0\nDmitry 1 0\nEdvard 4 4 1 2 3 4",
"output": "NO"
},
{
"input": "2 1 1\n2 1\nabsgdf 1 1 1\nabsgdf 1... | 92 | 0 | 0 | 52,120 |
367 | Sereja and the Arrangement of Numbers | [
"graphs",
"greedy",
"sortings"
] | null | null | Let's call an array consisting of *n* integer numbers *a*1, *a*2, ..., *a**n*, beautiful if it has the following property:
- consider all pairs of numbers *x*,<=*y* (*x*<=≠<=*y*), such that number *x* occurs in the array *a* and number *y* occurs in the array *a*; - for each pair *x*,<=*y* must exist some position *... | The first line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=2·106,<=1<=≤<=*m*<=≤<=105). Next *m* lines contain pairs of integers. The *i*-th line contains numbers *q**i*,<=*w**i* (1<=≤<=*q**i*,<=*w**i*<=≤<=105).
It is guaranteed that all *q**i* are distinct. | In a single line print maximum amount of money (in rubles) Sereja can pay.
Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier. | [
"5 2\n1 2\n2 3\n",
"100 3\n1 2\n2 1\n3 1\n",
"1 2\n1 1\n2 100\n"
] | [
"5\n",
"4\n",
"100\n"
] | In the first sample Sereja can pay 5 rubles, for example, if Dima constructs the following array: [1, 2, 1, 2, 2]. There are another optimal arrays for this test.
In the third sample Sereja can pay 100 rubles, if Dima constructs the following array: [2]. | [
{
"input": "5 2\n1 2\n2 3",
"output": "5"
},
{
"input": "100 3\n1 2\n2 1\n3 1",
"output": "4"
},
{
"input": "1 2\n1 1\n2 100",
"output": "100"
},
{
"input": "25 29\n82963 53706\n63282 73962\n14996 48828\n84392 31903\n96293 41422\n31719 45448\n46772 17870\n9668 85036\n36704 83... | 296 | 6,144,000 | 0 | 52,407 | |
512 | Fox And Travelling | [
"dp",
"trees"
] | null | null | Fox Ciel is going to travel to New Foxland during this summer.
New Foxland has *n* attractions that are linked by *m* undirected roads. Two attractions are called adjacent if they are linked by a road. Fox Ciel has *k* days to visit this city and each day she will visit exactly one attraction.
There is one important ... | First line contains two integers: *n*, *m* (1<=≤<=*n*<=≤<=100, ), the number of attractions and number of undirected roads.
Then next *m* lines each contain two integers *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n* and *a**i*<=≠<=*b**i*), describing a road. There is no more than one road connecting each pair of at... | Output *n*<=+<=1 integer: the number of possible travelling plans modulo 109<=+<=9 for all *k* from 0 to *n*. | [
"3 2\n1 2\n2 3\n",
"4 4\n1 2\n2 3\n3 4\n4 1\n",
"12 11\n2 3\n4 7\n4 5\n5 6\n4 6\n6 12\n5 12\n5 8\n8 9\n10 8\n11 9\n",
"13 0\n"
] | [
"1\n2\n4\n4\n",
"1\n0\n0\n0\n0\n",
"1\n6\n31\n135\n483\n1380\n3060\n5040\n5040\n0\n0\n0\n0\n",
"1\n13\n156\n1716\n17160\n154440\n1235520\n8648640\n51891840\n259459200\n37836791\n113510373\n227020746\n227020746\n"
] | In the first sample test for *k* = 3 there are 4 travelling plans: {1, 2, 3}, {1, 3, 2}, {3, 1, 2}, {3, 2, 1}.
In the second sample test Ciel can't visit any attraction in the first day, so for *k* > 0 the answer is 0.
In the third sample test Foxlands look like this: | [
{
"input": "3 2\n1 2\n2 3",
"output": "1\n2\n4\n4"
},
{
"input": "4 4\n1 2\n2 3\n3 4\n4 1",
"output": "1\n0\n0\n0\n0"
},
{
"input": "12 11\n2 3\n4 7\n4 5\n5 6\n4 6\n6 12\n5 12\n5 8\n8 9\n10 8\n11 9",
"output": "1\n6\n31\n135\n483\n1380\n3060\n5040\n5040\n0\n0\n0\n0"
},
{
"inp... | 30 | 0 | 0 | 52,523 | |
68 | Contact | [
"geometry"
] | E. Contact | 3 | 256 | Little Petya is preparing for the first contact with aliens. He knows that alien spaceships have shapes of non-degenerate triangles and there will be exactly 4 ships. Landing platform for a ship can be made of 3 special columns located at some points of a Cartesian plane such that these 3 points form a triangle equal t... | Each of 4 lines will contain 6 integers *x*1 *y*1 *x*2 *y*2 *x*3 *y*3 (0<=≤<=*x*1,<=*y*1,<=*x*2,<=*y*2,<=*x*3,<=*y*3<=≤<=20), representing 3 points that describe the shape of each of 4 ships. It is guaranteed that 3 points in each line will represent a non-degenerate triangle. | First line should contain minimum number of columns enough to land all spaceships. | [
"0 0 1 0 1 2\n0 0 0 2 2 2\n0 0 3 0 1 2\n0 0 3 0 2 2\n",
"0 0 0 1 1 1\n0 0 0 2 2 2\n0 0 0 5 5 5\n0 0 0 17 17 17\n"
] | [
"4\n",
"9\n"
] | In the first test case columns can be put in these points: (0, 0), (1, 0), (3, 0), (1, 2). Note that the second ship can land using last 3 columns.
In the second test case following points can be chosen: (0, 0), (0, 1), (1, 0), (0, 2), (2, 0), (0, 5), (5, 0), (0, 17), (17, 0). It is impossible to use less than 9 colum... | [] | 92 | 0 | 0 | 52,528 |
887 | Row of Models | [
"greedy",
"sortings"
] | null | null | During the final part of fashion show all models come to the stage and stay in one row and fashion designer stays to right to model on the right. During the rehearsal, Izabella noticed, that row isn't nice, but she can't figure out how to fix it.
Like many other creative people, Izabella has a specific sense of beaut... | In first line there are two integers *n* and *k* (1<=≤<=*n*<=≤<=5·105, 1<=≤<=*k*<=≤<=*n*) — number of models and required distance.
Second line contains *n* space-separated integers *a**i* (1<=≤<=*a**i*<=≤<=109) — height of each model. Pay attention that height of fashion designer is not given and can be less than 1. | Print «YES» (without quotes) if it's possible to make row nice using at most one exchange, and «NO» (without quotes) otherwise. | [
"5 4\n2 3 5 2 5\n",
"5 2\n3 6 2 2 1\n",
"5 2\n5 3 6 5 2\n"
] | [
"NO",
"YES",
"YES"
] | none | [] | 2,000 | 0 | 0 | 52,756 | |
113 | Petr# | [
"brute force",
"data structures",
"hashing",
"strings"
] | B. Petr# | 2 | 256 | Long ago, when Petya was a schoolboy, he was very much interested in the Petr# language grammar. During one lesson Petya got interested in the following question: how many different continuous substrings starting with the *s**begin* and ending with the *s**end* (it is possible *s**begin*<==<=*s**end*), the given string... | The input file consists of three lines. The first line contains string *t*. The second and the third lines contain the *s**begin* and *s**end* identificators, correspondingly. All three lines are non-empty strings consisting of lowercase Latin letters. The length of each string doesn't exceed 2000 characters. | Output the only number — the amount of different substrings of *t* that start with *s**begin* and end with *s**end*. | [
"round\nro\nou\n",
"codeforces\ncode\nforca\n",
"abababab\na\nb\n",
"aba\nab\nba\n"
] | [
"1\n",
"0\n",
"4\n",
"1\n"
] | In the third sample there are four appropriate different substrings. They are: ab, abab, ababab, abababab.
In the fourth sample identificators intersect. | [
{
"input": "round\nro\nou",
"output": "1"
},
{
"input": "codeforces\ncode\nforca",
"output": "0"
},
{
"input": "abababab\na\nb",
"output": "4"
},
{
"input": "aba\nab\nba",
"output": "1"
},
{
"input": "abcdefghijklmnopqrstuvwxyz\nabc\nxyz",
"output": "1"
},
... | 310 | 7,168,000 | 0 | 52,826 |
549 | Yura and Developers | [
"data structures",
"divide and conquer"
] | null | null | Yura has a team of *k* developers and a list of *n* tasks numbered from 1 to *n*. Yura is going to choose some tasks to be done this week. Due to strange Looksery habits the numbers of chosen tasks should be a segment of consecutive integers containing no less than 2 numbers, i. e. a sequence of form *l*,<=*l*<=+<=1,<=... | The first line of input contains two positive integers: *n* and *k* (1<=≤<=*n*<=≤<=300<=000,<=1<=≤<=*k*<=≤<=1<=000<=000), the number of tasks in the list and the number of developers in Yura's disposal.
The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=109). | Output a single integer — the number of pairs (*l*,<=*r*) satisfying the conditions from the statement. | [
"4 3\n1 2 3 4\n",
"4 2\n4 4 7 4\n"
] | [
"3\n",
"6\n"
] | In the first sample there are three good segments:
1. [1;3] — the hardest task requires 3 man-hours, so there are tasks left that require 1 and 2 man-hours. A solution is to make first developer work on the first task for an hour, while second and third developers work on the second task. Each developer works exactly ... | [] | 374 | 921,600 | -1 | 52,881 | |
416 | President's Path | [
"dp",
"graphs",
"shortest paths"
] | null | null | Good old Berland has *n* cities and *m* roads. Each road connects a pair of distinct cities and is bidirectional. Between any pair of cities, there is at most one road. For each road, we know its length.
We also know that the President will soon ride along the Berland roads from city *s* to city *t*. Naturally, he wil... | The first line of the input contains integers *n*,<=*m* (2<=≤<=*n*<=≤<=500, 0<=≤<=*m*<=≤<=*n*·(*n*<=-<=1)<=/<=2) — the number of cities and roads, correspondingly. Then *m* lines follow, containing the road descriptions, one description per line. Each description contains three integers *x**i*,<=*y**i*,<=*l**i* (1<=≤<=... | Print the sequence of integers *c*12,<=*c*13,<=...,<=*c*1*n*,<=*c*23,<=*c*24,<=...,<=*c*2*n*,<=...,<=*c**n*<=-<=1,<=*n*, where *c**st* is the number of roads that can lie on the shortest path from *s* to *t*. Print the elements of sequence *c* in the described order. If the pair of cities *s* and *t* don't have a path... | [
"5 6\n1 2 1\n2 3 1\n3 4 1\n4 1 1\n2 4 2\n4 5 4\n"
] | [
"1 4 1 2 1 5 6 1 2 1 "
] | none | [] | 93 | 307,200 | 0 | 52,926 | |
946 | Fibonacci String Subsequences | [
"combinatorics",
"dp",
"matrices"
] | null | null | You are given a binary string *s* (each character of this string is either 0 or 1).
Let's denote the cost of string *t* as the number of occurences of *s* in *t*. For example, if *s* is 11 and *t* is 111011, then the cost of *t* is 3.
Let's also denote the Fibonacci strings sequence as follows:
- *F*(0) is 0;- *F*(... | The first line contains two integers *n* and *x* (1<=≤<=*n*<=≤<=100, 0<=≤<=*x*<=≤<=100) — the length of *s* and the index of a Fibonacci string you are interested in, respectively.
The second line contains *s* — a string consisting of *n* characters. Each of these characters is either 0 or 1. | Print the only integer — the sum of costs of all subsequences of the string *F*(*x*), taken modulo 109<=+<=7. | [
"2 4\n11\n",
"10 100\n1010101010\n"
] | [
"14\n",
"553403224\n"
] | none | [
{
"input": "2 4\n11",
"output": "14"
},
{
"input": "10 100\n1010101010",
"output": "553403224"
},
{
"input": "10 5\n0110111100",
"output": "0"
},
{
"input": "100 100\n0001010101110010010100111011010101101111110001101101010111011101010000111000110001111010001001000001",
"o... | 452 | 11,776,000 | 3 | 52,976 | |
23 | Tetragon | [
"geometry",
"math"
] | D. Tetragon | 3 | 256 | You're given the centers of three equal sides of a strictly convex tetragon. Your task is to restore the initial tetragon. | The first input line contains one number *T* — amount of tests (1<=≤<=*T*<=≤<=5·104). Each of the following *T* lines contains numbers *x*1, *y*1, *x*2, *y*2, *x*3, *y*3 — coordinates of different points that are the centers of three equal sides (non-negative integer numbers, not exceeding 10). | For each test output two lines. If the required tetragon exists, output in the first line YES, in the second line — four pairs of numbers — coordinates of the polygon's vertices in clockwise or counter-clockwise order. Don't forget, please, that the tetragon should be strictly convex, i.e. no 3 of its points lie on one... | [
"3\n1 1 2 2 3 3\n0 1 1 0 2 2\n9 3 7 9 9 8\n"
] | [
"NO\n\nYES\n3.5 1.5 0.5 2.5 -0.5 -0.5 2.5 0.5\nNO\n\n"
] | none | [] | 124 | 819,200 | -1 | 53,120 |
856 | Eleventh Birthday | [
"combinatorics",
"dp",
"math"
] | null | null | It is Borya's eleventh birthday, and he has got a great present: *n* cards with numbers. The *i*-th card has the number *a**i* written on it. Borya wants to put his cards in a row to get one greater number. For example, if Borya has cards with numbers 1, 31, and 12, and he puts them in a row in this order, he would get... | Input data contains multiple test cases. The first line of the input data contains an integer *t* — the number of test cases (1<=≤<=*t*<=≤<=100). The descriptions of test cases follow.
Each test is described by two lines.
The first line contains an integer *n* (1<=≤<=*n*<=≤<=2000) — the number of cards in Borya's pre... | For each test case output one line: the number of ways to put the cards to the table so that the resulting big number was divisible by 11, print the number modulo 998244353. | [
"4\n2\n1 1\n3\n1 31 12\n3\n12345 67 84\n9\n1 2 3 4 5 6 7 8 9\n"
] | [
"2\n2\n2\n31680\n"
] | none | [] | 46 | 0 | 0 | 53,298 | |
534 | Handshakes | [
"binary search",
"constructive algorithms",
"data structures",
"greedy"
] | null | null | On February, 30th *n* students came in the Center for Training Olympiad Programmers (CTOP) of the Berland State University. They came one by one, one after another. Each of them went in, and before sitting down at his desk, greeted with those who were present in the room by shaking hands. Each of the students who came ... | The first line contains integer *n* (1<=≤<=*n*<=≤<=2·105) — the number of students who came to CTOP. The next line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=<<=*n*), where *a**i* is the number of students with who the *i*-th student shook hands. | If the sought order of students exists, print in the first line "Possible" and in the second line print the permutation of the students' numbers defining the order in which the students entered the center. Number *i* that stands to the left of number *j* in this permutation means that the *i*-th student came earlier th... | [
"5\n2 1 3 0 1\n",
"9\n0 2 3 4 1 1 0 2 2\n",
"4\n0 2 1 1\n"
] | [
"Possible\n4 5 1 3 2 ",
"Possible\n7 5 2 1 6 8 3 4 9",
"Impossible\n"
] | In the first sample from the statement the order of events could be as follows:
- student 4 comes in (*a*<sub class="lower-index">4</sub> = 0), he has no one to greet; - student 5 comes in (*a*<sub class="lower-index">5</sub> = 1), he shakes hands with student 4; - student 1 comes in (*a*<sub class="lower-index">1... | [
{
"input": "5\n2 1 3 0 1",
"output": "Possible\n4 5 1 3 2 "
},
{
"input": "9\n0 2 3 4 1 1 0 2 2",
"output": "Possible\n7 6 9 3 4 8 1 5 2 "
},
{
"input": "4\n0 2 1 1",
"output": "Impossible"
},
{
"input": "5\n1 0 2 1 0",
"output": "Possible\n5 4 3 2 1 "
},
{
"input... | 108 | 0 | 0 | 53,480 | |
0 | none | [
"none"
] | null | null | A couple of friends, Axel and Marston are travelling across the country of Bitland. There are *n* towns in Bitland, with some pairs of towns connected by one-directional roads. Each road in Bitland is either a pedestrian road or a bike road. There can be multiple roads between any pair of towns, and may even be a road ... | The first line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=500, 0<=≤<=*m*<=≤<=2*n*2) — the number of towns and roads in Bitland respectively.
Next *m* lines describe the roads. *i*-th of these lines contains three integers *v**i*, *u**i* and *t**i* (1<=≤<=*v**i*,<=*u**i*<=≤<=*n*, 0<=≤<=*t**i*<=≤<=1), where *v**i*... | If it is possible to find a route with length strictly greater than 1018, print -1. Otherwise, print the maximum length of a suitable path. | [
"2 2\n1 2 0\n2 2 1\n",
"2 3\n1 2 0\n2 2 1\n2 2 0\n"
] | [
"3\n",
"-1\n"
] | In the first sample we can obtain a route of length 3 by travelling along the road 1 from town 1 to town 2, and then following the road 2 twice from town 2 to itself.
In the second sample we can obtain an arbitrarily long route by travelling the road 1 first, and then choosing road 2 or 3 depending on the necessary ty... | [] | 31 | 0 | 0 | 53,562 | |
44 | BerPaint | [
"geometry",
"graphs"
] | F. BerPaint | 5 | 256 | Anfisa the monkey got disappointed in word processors as they aren't good enough at reflecting all the range of her emotions, that's why she decided to switch to graphics editors. Having opened the BerPaint, she saw a white rectangle *W*<=×<=*H* in size which can be painted on. First Anfisa learnt to navigate the drawi... | The first input line has two integers *W* and *H* (3<=≤<=*W*,<=*H*<=≤<=104) — the sizes of the initially white rectangular painting area. The second line contains integer *n* — the number of black segments (0<=≤<=*n*<=≤<=100). On the next *n* lines are described the segments themselves, each of which is given by coordi... | For every color present in the final picture print on the single line the name of the color and the total area of areas painted that color with an accuracy of 10<=-<=6. Print the colors in any order. | [
"4 5\n6\n1 1 1 3\n1 3 3 3\n3 3 3 1\n3 1 1 1\n1 3 3 1\n1 1 3 3\n2\n2 1 red\n2 2 blue\n",
"5 5\n5\n1 1 2 2\n2 2 4 2\n4 2 4 4\n4 4 2 4\n2 4 2 2\n2\n3 3 black\n3 3 green\n",
"7 4\n9\n1 2 2 3\n2 3 3 2\n3 2 2 1\n2 1 1 2\n3 2 4 2\n4 2 5 3\n5 3 6 2\n6 2 5 1\n5 1 4 2\n2\n2 2 black\n2 2 red\n"
] | [
"blue 0.00000000\nwhite 20.00000000\n",
"green 4.00000000\nwhite 21.00000000\n",
"red 2.00000000\nwhite 26.00000000\n"
] | Initially the black segments painted by Anfisa can also be painted a color if any of the chosen points lays on the segment. The segments have areas equal to 0. That is why if in the final picture only parts of segments is painted some color, then the area, painted the color is equal to 0. | [] | 124 | 0 | 0 | 53,643 |
566 | Logistical Questions | [
"dfs and similar",
"divide and conquer",
"trees"
] | null | null | Some country consists of *n* cities, connected by a railroad network. The transport communication of the country is so advanced that the network consists of a minimum required number of (*n*<=-<=1) bidirectional roads (in the other words, the graph of roads is a tree). The *i*-th road that directly connects cities *a**... | The first line of the input contains number *n* (1<=≤<=*n*<=≤<=200<=000) — the number of cities in the country.
The next line contains *n* integers *w*1,<=*w*2,<=...,<=*w**n* (0<=≤<=*w**i*<=≤<=108) — the number of finalists living in each city of the country.
Next (*n*<=-<=1) lines contain the descriptions of the rai... | Print two numbers — an integer *f* that is the number of the optimal city to conduct the competition, and the real number *c*, equal to the minimum total cost of transporting all the finalists to the competition. Your answer will be considered correct if two conditions are fulfilled at the same time:
1. The absolute... | [
"5\n3 1 2 6 5\n1 2 3\n2 3 1\n4 3 9\n5 3 1\n",
"2\n5 5\n1 2 2\n"
] | [
"3 192.0",
"1 14.142135623730951000\n"
] | In the sample test an optimal variant of choosing a city to conduct the finals of the competition is 3. At such choice the cost of conducting is <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/4219dfaeaed77b348dc7ca0c500739d1c0ff9e3f.png" style="max-width: 100.0%;max-height: 100.0%;"/> burl... | [] | 62 | 307,200 | 0 | 53,775 | |
0 | none | [
"none"
] | null | null | Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Petya wonders eagerly what minimum lucky number has the sum of digits equal to *n*. Help him cope wi... | The single line contains an integer *n* (1<=≤<=*n*<=≤<=106) — the sum of digits of the required lucky number. | Print on the single line the result — the minimum lucky number, whose sum of digits equals *n*. If such number does not exist, print -1. | [
"11\n",
"10\n"
] | [
"47\n",
"-1\n"
] | none | [
{
"input": "11",
"output": "47"
},
{
"input": "10",
"output": "-1"
},
{
"input": "64",
"output": "4477777777"
},
{
"input": "1",
"output": "-1"
},
{
"input": "4",
"output": "4"
},
{
"input": "7",
"output": "7"
},
{
"input": "12",
"outpu... | 92 | 102,400 | 3 | 53,881 | |
576 | Flights for Regular Customers | [
"dp",
"matrices"
] | null | null | In the country there are exactly *n* cities numbered with positive integers from 1 to *n*. In each city there is an airport is located.
Also, there is the only one airline, which makes *m* flights. Unfortunately, to use them, you need to be a regular customer of this company, namely, you have the opportunity to enjoy ... | The first line contains two integers, *n* and *m* (2<=≤<=*n*<=≤<=150, 1<=≤<=*m*<=≤<=150) — the number of cities in the country and the number of flights the company provides.
Next *m* lines contain numbers *a**i*, *b**i*, *d**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*, 0<=≤<=*d**i*<=≤<=109), representing flight number *i* from... | Print "Impossible" (without the quotes), if it is impossible to get from city 1 to city *n* using the airways.
But if there is at least one way, print a single integer — the minimum number of flights you need to make to get to the destination point. | [
"3 2\n1 2 0\n2 3 1\n",
"2 1\n1 2 100500\n",
"3 3\n2 1 0\n2 3 6\n1 2 0\n"
] | [
"2\n",
"Impossible\n",
"8\n"
] | none | [] | 30 | 0 | 0 | 53,965 | |
896 | Ithea Plays With Chtholly | [
"binary search",
"constructive algorithms",
"games",
"greedy",
"interactive"
] | null | null | This is an interactive problem. Refer to the Interaction section below for better understanding.
Ithea and Chtholly want to play a game in order to determine who can use the kitchen tonight.
Initially, Ithea puts *n* clear sheets of paper in a line. They are numbered from 1 to *n* from left to right.
This game wil... | The first line contains 3 integers *n*,<=*m* and *c* (, means rounded up) — the number of sheets, the number of rounds and the largest possible number Ithea can give to Chtholly respectively. The remaining parts of input are given throughout the interaction process. | none | [
"2 4 4\n2\n1\n3\n"
] | [
"1\n2\n2\n"
] | In the example, Chtholly initially knew there were 2 sheets, 4 rounds and each number was between 1 and 4. She then received a 2 and decided to write it in the 1st sheet. Then she received a 1 and wrote it in the 2nd sheet. At last, she received a 3 and replaced 1 with 3 in the 2nd sheet. At this time all the sheets we... | [
{
"input": "2 4 4\n2\n1\n3\n4",
"output": "3"
},
{
"input": "2 2 2\n1\n2",
"output": "2"
},
{
"input": "3 6 3\n1\n2\n1\n3\n1\n3",
"output": "3"
},
{
"input": "4 8 4\n4\n4\n4\n4\n4\n4\n4\n4",
"output": "4"
},
{
"input": "10 120 15\n6\n11\n9\n11\n3\n12\n11\n12\n2\n8... | 31 | 0 | 0 | 54,120 | |
524 | Возможно, вы знаете этих людей? | [
"implementation"
] | null | null | Основой любой социальной сети является отношение дружбы между двумя пользователями в том или ином смысле. В одной известной социальной сети дружба симметрична, то есть если *a* является другом *b*, то *b* также является другом *a*.
В этой же сети есть функция, которая демонстрирует множество людей, имеющих высокую ве... | В первой строке следуют два целых числа *m* и *k* (1<=≤<=*m*<=≤<=100, 0<=≤<=*k*<=≤<=100) — количество пар друзей и необходимый процент общих друзей для того, чтобы считаться предполагаемым другом.
В последующих *m* строках записано по два числа *a**i*,<=*b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=109, *a**i*<=≠<=*b**i*), обозна... | Для всех упомянутых людей в порядке возрастания id выведите информацию о предполагаемых друзьях. Информация должна иметь вид "*id*:<= *k* *id*1 *id*2 ... *id**k*", где *id* — это id самого человека, *k* — количество его предполагаемых друзей, а *id*1, *id*2, ..., *id**k* — идентификаторы его предполагаемых друзей в воз... | [
"5 51\n10 23\n23 42\n39 42\n10 39\n39 58\n",
"5 100\n1 2\n1 3\n1 4\n2 3\n2 4\n"
] | [
"10: 1 42\n23: 1 39\n39: 1 23\n42: 1 10\n58: 2 10 42\n",
"1: 0\n2: 0\n3: 1 4\n4: 1 3\n"
] | none | [
{
"input": "5 51\n10 23\n23 42\n39 42\n10 39\n39 58",
"output": "10: 1 42\n23: 1 39\n39: 1 23\n42: 1 10\n58: 2 10 42"
},
{
"input": "5 100\n1 2\n1 3\n1 4\n2 3\n2 4",
"output": "1: 0\n2: 0\n3: 1 4\n4: 1 3"
},
{
"input": "4 1\n1 2\n1 3\n2 3\n4 5",
"output": "1: 0\n2: 0\n3: 0\n4: 0\n5: ... | 93 | 0 | -1 | 54,190 | |
203 | Hit Ball | [
"geometry",
"implementation",
"math"
] | null | null | When Valera was playing football on a stadium, it suddenly began to rain. Valera hid in the corridor under the grandstand not to get wet. However, the desire to play was so great that he decided to train his hitting the ball right in this corridor. Valera went back far enough, put the ball and hit it. The ball bounced ... | The first line contains three space-separated integers *a*,<=*b*,<=*m* (1<=≤<=*a*,<=*b*,<=*m*<=≤<=100). The first two integers specify point (*a*,<=0,<=*b*), through which the ceiling and one of the corridor walls pass. The third integer is the distance at which Valera went away from the door.
The second line has thre... | Print two real numbers *x*0,<=*z*0 — the *x* and *z* coordinates of point (*x*0,<=0,<=*z*0), at which the ball hits the exit door. The answer will be considered correct, if its absolute or relative error does not exceed 10<=<=-<=6. | [
"7 2 11\n3 -11 2\n",
"7 2 11\n4 -3 3\n"
] | [
"6.5000000000 2.0000000000\n",
"4.1666666667 1.0000000000\n"
] | <img class="tex-graphics" src="https://espresso.codeforces.com/0b96c99a50a7ff8657d6301992a0fe440badfb7b.png" style="max-width: 100.0%;max-height: 100.0%;"/> | [
{
"input": "7 2 11\n3 -11 2",
"output": "6.5000000000 2.0000000000"
},
{
"input": "7 2 11\n4 -3 3",
"output": "4.1666666667 1.0000000000"
},
{
"input": "44 94 98\n-17 -64 9",
"output": "4.0312500000 13.7812500000"
},
{
"input": "41 4 58\n81 -9 65",
"output": "31.500000000... | 92 | 0 | 0 | 54,224 | |
703 | Chris and Road | [
"geometry",
"implementation"
] | null | null | And while Mishka is enjoying her trip...
Chris is a little brown bear. No one knows, where and when he met Mishka, but for a long time they are together (excluding her current trip). However, best friends are important too. John is Chris' best friend.
Once walking with his friend, John gave Chris the following proble... | The first line of the input contains four integers *n*, *w*, *v*, *u* (3<=≤<=*n*<=≤<=10<=000, 1<=≤<=*w*<=≤<=109, 1<=≤<=*v*,<=<=*u*<=≤<=1000) — the number of the bus polygon vertices, road width, bus speed and pedestrian speed respectively.
The next *n* lines describes polygon vertices in counter-clockwise order. *i*-t... | Print the single real *t* — the time the pedestrian needs to croos the road and not to be hit by the bus. The answer is considered correct if its relative or absolute error doesn't exceed 10<=-<=6. | [
"5 5 1 2\n1 2\n3 1\n4 3\n3 4\n1 4\n"
] | [
"5.0000000000"
] | Following image describes initial position in the first sample case:
<img class="tex-graphics" src="https://espresso.codeforces.com/6d0966ee3194a0c11a228fa83f19a00157de89f7.png" style="max-width: 100.0%;max-height: 100.0%;"/> | [
{
"input": "5 5 1 2\n1 2\n3 1\n4 3\n3 4\n1 4",
"output": "5.0000000000"
},
{
"input": "3 3 5 2\n3 1\n4 0\n5 1",
"output": "1.5000000000"
},
{
"input": "3 3 2 4\n0 1\n2 1\n1 2",
"output": "1.5000000000"
},
{
"input": "3 3 1 1\n0 0\n1 1\n0 2",
"output": "3.0000000000"
},
... | 62 | 0 | 3 | 54,298 | |
45 | Prime Problem | [
"number theory"
] | G. Prime Problem | 1 | 256 | In Berland prime numbers are fashionable — the respectable citizens dwell only on the floors with numbers that are prime numbers. The numismatists value particularly high the coins with prime nominal values. All the prime days are announced holidays!
Yet even this is not enough to make the Berland people happy. On the... | The single input line contains an integer *n* (2<=≤<=*n*<=≤<=6000) — the number of houses on the main streets of the capital. | Print the sequence of *n* numbers, where the *i*-th number stands for the number of color for house number *i*. Number the colors consecutively starting from 1. Any painting order is allowed. If there are several solutions to that problem, print any of them. If there's no such way of painting print the single number -1... | [
"8"
] | [
"1 2 2 1 1 1 1 2"
] | none | [
{
"input": "8",
"output": "1 1 1 1 2 1 1 1 "
},
{
"input": "2",
"output": "1 1 "
},
{
"input": "3",
"output": "1 1 2 "
},
{
"input": "4",
"output": "1 1 2 1 "
},
{
"input": "5",
"output": "1 2 1 1 1 "
},
{
"input": "6",
"output": "1 2 1 1 1 1 "
}... | 60 | 0 | 0 | 54,342 |
958 | Lightsabers (medium) | [
"binary search",
"two pointers"
] | null | null | There is unrest in the Galactic Senate. Several thousand solar systems have declared their intentions to leave the Republic. Master Heidi needs to select the Jedi Knights who will go on peacekeeping missions throughout the galaxy. It is well-known that the success of any peacekeeping mission depends on the colors of th... | The first line of the input contains *n* (1<=≤<=*n*<=≤<=2·105) and *m* (1<=≤<=*m*<=≤<=*n*). The second line contains *n* integers in the range {1,<=2,<=...,<=*m*} representing colors of the lightsabers of the subsequent Jedi Knights. The third line contains *m* integers *k*1,<=*k*2,<=...,<=*k**m* (with ) – the desired ... | Output one number: the minimum number of Jedi Knights that need to be removed from the sequence so that, in what remains, there is an interval with the prescribed counts of lightsaber colors. If this is not possible, output <=-<=1. | [
"8 3\n3 3 1 2 2 1 1 3\n3 1 1\n"
] | [
"1\n"
] | none | [
{
"input": "8 3\n3 3 1 2 2 1 1 3\n3 1 1",
"output": "1"
},
{
"input": "6 5\n1 2 4 2 4 3\n0 0 1 0 0",
"output": "0"
},
{
"input": "1 1\n1\n1",
"output": "0"
},
{
"input": "2 1\n1 1\n1",
"output": "0"
},
{
"input": "2 1\n1 1\n2",
"output": "0"
},
{
"inpu... | 436 | 40,448,000 | 3 | 54,466 | |
566 | Restoring Map | [
"bitmasks",
"constructive algorithms",
"trees"
] | null | null | Archaeologists found some information about an ancient land of Treeland. We know for sure that the Treeland consisted of *n* cities connected by the *n*<=-<=1 road, such that you can get from each city to any other one along the roads. However, the information about the specific design of roads in Treeland has been los... | The first line contains integer *n* (2<=≤<=*n*<=≤<=1000) — the number of cities in the country.
Next *n* lines describe the found lists of near cities. Each list starts from number *k* (1<=≤<=*k*<=≤<=*n*), representing the number of cities in the list followed by *k* city numbers. All numbers in each list are distinc... | Print *n*<=-<=1 pairs of numbers representing the roads of the country. The *i*-th line must contain two integers *a**i*,<=*b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*, *a**i*<=≠<=*b**i*), showing that there is a road between cities *a**i* and *b**i*.
The answer you print must satisfy the description of close cities from the... | [
"5\n4 3 2 4 1\n5 5 3 2 4 1\n5 4 2 1 5 3\n4 2 1 4 3\n3 1 4 5\n",
"6\n5 6 1 3 4 2\n5 2 1 3 4 6\n6 3 6 2 5 4 1\n6 6 1 2 5 3 4\n3 5 2 4\n5 3 1 2 4 6\n"
] | [
"1 4\n1 2\n1 3\n4 5\n",
"2 4\n1 2\n2 3\n2 6\n4 5\n"
] | none | [] | 31 | 0 | 0 | 54,473 | |
263 | Squares | [
"greedy",
"implementation",
"sortings"
] | null | null | Vasya has found a piece of paper with a coordinate system written on it. There are *n* distinct squares drawn in this coordinate system. Let's number the squares with integers from 1 to *n*. It turned out that points with coordinates (0,<=0) and (*a**i*,<=*a**i*) are the opposite corners of the *i*-th square.
Vasya wa... | The first line contains two space-separated integers *n*, *k* (1<=≤<=*n*,<=*k*<=≤<=50). The second line contains space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109).
It is guaranteed that all given squares are distinct. | In a single line print two space-separated integers *x* and *y* (0<=≤<=*x*,<=*y*<=≤<=109) — the coordinates of the point that belongs to exactly *k* squares. If there are multiple answers, you are allowed to print any of them.
If there is no answer, print "-1" (without the quotes). | [
"4 3\n5 1 3 4\n",
"3 1\n2 4 1\n",
"4 50\n5 1 10 2\n"
] | [
"2 1\n",
"4 0\n",
"-1\n"
] | none | [
{
"input": "4 3\n5 1 3 4",
"output": "2 1"
},
{
"input": "3 1\n2 4 1",
"output": "4 0"
},
{
"input": "4 50\n5 1 10 2",
"output": "-1"
},
{
"input": "3 4\n5 1 4",
"output": "-1"
},
{
"input": "1 1\n2",
"output": "2 1"
},
{
"input": "1 2\n10",
"outpu... | 92 | 0 | 3 | 54,642 | |
301 | Yaroslav and Time | [
"binary search",
"graphs",
"shortest paths"
] | null | null | Yaroslav is playing a game called "Time". The game has a timer showing the lifespan he's got left. As soon as the timer shows 0, Yaroslav's character dies and the game ends. Also, the game has *n* clock stations, station number *i* is at point (*x**i*,<=*y**i*) of the plane. As the player visits station number *i*, he ... | The first line contains integers *n* and *d* (3<=≤<=*n*<=≤<=100,<=103<=≤<=*d*<=≤<=105) — the number of stations and the constant from the statement.
The second line contains *n*<=-<=2 integers: *a*2,<=*a*3,<=...,<=*a**n*<=-<=1 (1<=≤<=*a**i*<=≤<=103). The next *n* lines contain the coordinates of the stations. The *i*-... | In a single line print an integer — the answer to the problem. | [
"3 1000\n1000\n0 0\n0 1\n0 3\n",
"3 1000\n1000\n1 0\n1 1\n1 2\n"
] | [
"2000\n",
"1000\n"
] | none | [
{
"input": "3 1000\n1000\n0 0\n0 1\n0 3",
"output": "2000"
},
{
"input": "3 1000\n1000\n1 0\n1 1\n1 2",
"output": "1000"
},
{
"input": "5 1421\n896 448 727\n-19 -40\n-87 40\n69 51\n-55 61\n-7 67",
"output": "169099"
},
{
"input": "6 1000\n142 712 254 869\n7 0\n95 38\n96 -20\n... | 0 | 0 | -1 | 54,689 | |
217 | Bitonix' Patrol | [
"bitmasks",
"brute force",
"combinatorics",
"dfs and similar",
"math"
] | null | null | Byteland is trying to send a space mission onto the Bit-X planet. Their task is complicated by the fact that the orbit of the planet is regularly patrolled by Captain Bitonix, the leader of the space forces of Bit-X.
There are *n* stations around Bit-X numbered clockwise from 1 to *n*. The stations are evenly placed o... | The first line of the input contains three integers *n* (2<=≤<=*n*<=≤<=1000) — the number of stations, *m* (1<=≤<=*m*<=≤<=120) — the distance between adjacent stations, and *t* (1<=≤<=*t*<=≤<=10000) — the number of fuel tanks owned by Captain Bitonix.
The second line of the input contains *t* space-separated integers ... | Output a single number — the number of distinct subsets of tanks that the Bytelandian space agency can destroy in order to prevent Captain Bitonix from completing a patrol, modulo 109<=+<=7. | [
"7 6 5\n5 4 12 6 5\n",
"3 60 2\n10 100\n"
] | [
"6\n",
"4\n"
] | All the fuel tanks are distinct, even if some of them have the same capacity. | [] | 30 | 0 | 0 | 54,702 | |
733 | Drivers Dissatisfaction | [
"data structures",
"dsu",
"graphs",
"trees"
] | null | null | In one kingdom there are *n* cities and *m* two-way roads. Each road connects a pair of cities, and for each road we know the level of drivers dissatisfaction — the value *w**i*.
For each road we know the value *c**i* — how many lamziks we should spend to reduce the level of dissatisfaction with this road by one. Thus... | The first line contains two integers *n* and *m* (2<=≤<=*n*<=≤<=2·105, *n*<=-<=1<=≤<=*m*<=≤<=2·105) — the number of cities and the number of roads in the kingdom, respectively.
The second line contains *m* integers *w*1,<=*w*2,<=...,<=*w**m* (1<=≤<=*w**i*<=≤<=109), where *w**i* is the drivers dissatisfaction with the ... | In the first line print *K* — the minimum possible total dissatisfaction with main roads.
In each of the next *n*<=-<=1 lines print two integers *x*,<=*v**x*, which mean that the road *x* is among main roads and the road *x*, after the reform, has the level of dissatisfaction *v**x*.
Consider that roads are numbered ... | [
"6 9\n1 3 1 1 3 1 2 2 2\n4 1 4 2 2 5 3 1 6\n1 2\n1 3\n2 3\n2 4\n2 5\n3 5\n3 6\n4 5\n5 6\n7\n",
"3 3\n9 5 1\n7 7 2\n2 1\n3 1\n3 2\n2\n"
] | [
"0\n1 1\n3 1\n6 1\n7 2\n8 -5\n",
"5\n3 0\n2 5\n"
] | none | [
{
"input": "6 9\n1 3 1 1 3 1 2 2 2\n4 1 4 2 2 5 3 1 6\n1 2\n1 3\n2 3\n2 4\n2 5\n3 5\n3 6\n4 5\n5 6\n7",
"output": "0\n1 1\n3 1\n6 1\n7 2\n8 -5"
},
{
"input": "3 3\n9 5 1\n7 7 2\n2 1\n3 1\n3 2\n2",
"output": "5\n3 0\n2 5"
},
{
"input": "7 6\n8 10 4 8 4 4\n45 51 13 13 37 26\n2 7\n7 1\n6 3\... | 93 | 0 | 0 | 54,769 | |
891 | Envy | [
"data structures",
"dsu",
"graphs"
] | null | null | For a connected undirected weighted graph *G*, MST (minimum spanning tree) is a subgraph of *G* that contains all of *G*'s vertices, is a tree, and sum of its edges is minimum possible.
You are given a graph *G*. If you run a MST algorithm on graph it would give you only one MST and it causes other edges to become jea... | The first line contains two integers *n*, *m* (2<=<=≤<=*n*,<=*m*<=<=≤<=5·105, *n*<=-<=1<=≤<=*m*) — the number of vertices and edges in the graph and the number of queries.
The *i*-th of the next *m* lines contains three integers *u**i*, *v**i*, *w**i* (*u**i*<=≠<=*v**i*, 1<=≤<=*w**i*<=≤<=5·105) — the endpoints and wei... | For each query you should print "YES" (without quotes) if there's a MST containing these edges and "NO" (of course without quotes again) otherwise. | [
"5 7\n1 2 2\n1 3 2\n2 3 1\n2 4 1\n3 4 1\n3 5 2\n4 5 2\n4\n2 3 4\n3 3 4 5\n2 1 7\n2 1 2\n"
] | [
"YES\nNO\nYES\nNO\n"
] | This is the graph of sample:
Weight of minimum spanning tree on this graph is 6.
MST with edges (1, 3, 4, 6), contains all of edges from the first query, so answer on the first query is "YES".
Edges from the second query form a cycle of length 3, so there is no spanning tree including these three edges. Thus, answer... | [
{
"input": "5 7\n1 2 2\n1 3 2\n2 3 1\n2 4 1\n3 4 1\n3 5 2\n4 5 2\n4\n2 3 4\n3 3 4 5\n2 1 7\n2 1 2",
"output": "YES\nNO\nYES\nNO"
},
{
"input": "5 8\n2 1 4\n3 1 4\n4 1 5\n5 2 3\n4 5 2\n4 5 4\n1 4 4\n3 4 2\n10\n1 1\n3 4 1 5\n1 2\n3 4 1 3\n2 4 3\n3 2 5 4\n2 2 4\n4 3 2 1 4\n1 3\n2 2 1",
"output": "Y... | 30 | 0 | 0 | 54,783 | |
653 | Paper task | [
"data structures",
"string suffix structures",
"strings"
] | null | null | Alex was programming while Valentina (his toddler daughter) got there and started asking many questions about the round brackets (or parenthesis) in the code. He explained her a bit and when she got it he gave her a task in order to finish his code on time.
For the purpose of this problem we consider only strings cons... | The first line of the input contains an integer *n* (1<=≤<=*n*<=≤<=500<=000) — the length of the string *s*.
The second line contains a string *s* of length *n* consisting of only '(' and ')'. | Print the number of distinct non-empty correct sequences that occur in *s* as substring. | [
"10\n()()()()()\n",
"7\n)(())()\n"
] | [
"5\n",
"3\n"
] | In the first sample, there are 5 distinct substrings we should count: "()", "()()", "()()()", "()()()()" and "()()()()()".
In the second sample, there are 3 distinct substrings we should count: "()", "(())" and "(())()". | [
{
"input": "10\n()()()()()",
"output": "5"
},
{
"input": "7\n)(())()",
"output": "3"
},
{
"input": "1\n(",
"output": "0"
},
{
"input": "2\n))",
"output": "0"
},
{
"input": "15\n(())(()())(()()",
"output": "5"
},
{
"input": "30\n()(())(())(())()(())()()... | 30 | 0 | -1 | 54,872 | |
804 | Ice cream coloring | [
"constructive algorithms",
"dfs and similar",
"greedy"
] | null | null | Isart and Modsart were trying to solve an interesting problem when suddenly Kasra arrived. Breathless, he asked: "Can you solve a problem I'm stuck at all day?"
We have a tree *T* with *n* vertices and *m* types of ice cream numerated from 1 to *m*. Each vertex *i* has a set of *s**i* types of ice cream. Vertices whic... | The first line contains two integer *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=3·105) — the number of vertices in *T* and the number of ice cream types.
*n* lines follow, the *i*-th of these lines contain single integer *s**i* (0<=≤<=*s**i*<=≤<=3·105) and then *s**i* distinct integers, each between 1 and *m* — the types of ice ... | Print single integer *c* in the first line — the minimum number of colors to paint the vertices in graph *G*.
In the second line print *m* integers, the *i*-th of which should be the color of the *i*-th vertex. The colors should be between 1 and *c*. If there are some answers, print any of them. | [
"3 3\n1 1\n2 2 3\n1 2\n1 2\n2 3\n",
"4 5\n0\n1 1\n1 3\n3 2 4 5\n2 1\n3 2\n4 3\n"
] | [
"2\n1 1 2 ",
"3\n1 1 1 2 3 "
] | In the first example the first type of ice cream is present in the first vertex only, so we can color it in any color. The second and the third ice cream are both presented in the second vertex, so we should paint them in different colors.
In the second example the colors of the second, the fourth and the fifth ice cr... | [
{
"input": "3 3\n1 1\n2 2 3\n1 2\n1 2\n2 3",
"output": "2\n1 1 2 "
},
{
"input": "4 5\n0\n1 1\n1 3\n3 2 4 5\n2 1\n3 2\n4 3",
"output": "3\n1 1 1 2 3 "
},
{
"input": "7 35\n3 17 20 32\n4 3 14 24 25\n4 4 10 17 26\n7 2 9 13 17 23 28 30\n9 1 2 7 8 13 16 18 33 35\n8 5 6 11 15 17 22 29 34\n5 1... | 31 | 307,200 | 0 | 54,951 | |
360 | Levko and Array Recovery | [
"greedy",
"implementation"
] | null | null | Levko loves array *a*1,<=*a*2,<=... ,<=*a**n*, consisting of integers, very much. That is why Levko is playing with array *a*, performing all sorts of operations with it. Each operation Levko performs is of one of two types:
1. Increase all elements from *l**i* to *r**i* by *d**i*. In other words, perform assignments... | The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=5000) — the size of the array and the number of operations in Levko's records, correspondingly.
Next *m* lines describe the operations, the *i*-th line describes the *i*-th operation. The first integer in the *i*-th line is integer *t**i* (1<=≤<=*t*... | In the first line print "YES" (without the quotes), if the solution exists and "NO" (without the quotes) otherwise.
If the solution exists, then on the second line print *n* integers *a*1,<=*a*2,<=... ,<=*a**n* (|*a**i*|<=≤<=109) — the recovered array. | [
"4 5\n1 2 3 1\n2 1 2 8\n2 3 4 7\n1 1 3 3\n2 3 4 8\n",
"4 5\n1 2 3 1\n2 1 2 8\n2 3 4 7\n1 1 3 3\n2 3 4 13\n"
] | [
"YES\n4 7 4 7",
"NO\n"
] | none | [
{
"input": "4 5\n1 2 3 1\n2 1 2 8\n2 3 4 7\n1 1 3 3\n2 3 4 8",
"output": "YES\n8 7 4 7 "
},
{
"input": "4 5\n1 2 3 1\n2 1 2 8\n2 3 4 7\n1 1 3 3\n2 3 4 13",
"output": "NO"
},
{
"input": "97 29\n2 78 82 356152\n2 14 29 430177\n1 59 84 3680\n1 49 89 -2247\n1 92 96 3701\n2 54 89 377271\n1 62... | 46 | 0 | 0 | 55,100 | |
142 | Help Greg the Dwarf 2 | [
"geometry"
] | null | null | Greg the Dwarf has been really busy recently with excavations by the Neverland Mountain. However for the well-known reasons (as you probably remember he is a very unusual dwarf and he cannot stand sunlight) Greg can only excavate at night. And in the morning he should be in his crypt before the first sun ray strikes. T... | The first input line contains space-separated integers *r* and *h* (1<=≤<=*r*,<=*h*<=≤<=1000) — the base radius and the cone height correspondingly. The second and third lines contain coordinates of two points on the cone surface, groups of three space-separated real numbers. The coordinates of the points are given in ... | Print the length of the shortest path between the points given in the input, with absolute or relative error not exceeding 10<=-<=6. | [
"2 2\n1.0 0.0 0.0\n-1.0 0.0 0.0\n",
"2 2\n1.0 0.0 0.0\n1.0 0.0 1.0\n",
"2 2\n1.0 0.0 1.0\n-1.0 0.0 1.0\n",
"2 2\n1.0 0.0 0.0\n0.0 1.0 1.0\n"
] | [
"2.000000000",
"2.414213562",
"2.534324263",
"3.254470198"
] | none | [
{
"input": "2 2\n1.0 0.0 0.0\n-1.0 0.0 0.0",
"output": "2.0000000000000000"
},
{
"input": "2 2\n1.0 0.0 0.0\n1.0 0.0 1.0",
"output": "2.414213562373095"
},
{
"input": "2 2\n1.0 0.0 1.0\n-1.0 0.0 1.0",
"output": "2.534324262661599"
},
{
"input": "2 2\n1.0 0.0 0.0\n0.0 1.0 1.0"... | 124 | 0 | 0 | 55,125 | |
501 | Misha and Forest | [
"constructive algorithms",
"data structures",
"greedy",
"sortings",
"trees"
] | null | null | Let's define a forest as a non-directed acyclic graph (also without loops and parallel edges). One day Misha played with the forest consisting of *n* vertices. For each vertex *v* from 0 to *n*<=-<=1 he wrote down two integers, *degree**v* and *s**v*, were the first integer is the number of vertices adjacent to vertex ... | The first line contains integer *n* (1<=≤<=*n*<=≤<=216), the number of vertices in the graph.
The *i*-th of the next lines contains numbers *degree**i* and *s**i* (0<=≤<=*degree**i*<=≤<=*n*<=-<=1, 0<=≤<=*s**i*<=<<=216), separated by a space. | In the first line print number *m*, the number of edges of the graph.
Next print *m* lines, each containing two distinct numbers, *a* and *b* (0<=≤<=*a*<=≤<=*n*<=-<=1, 0<=≤<=*b*<=≤<=*n*<=-<=1), corresponding to edge (*a*,<=*b*).
Edges can be printed in any order; vertices of the edge can also be printed in any order. | [
"3\n2 3\n1 0\n1 0\n",
"2\n1 1\n1 0\n"
] | [
"2\n1 0\n2 0\n",
"1\n0 1\n"
] | The XOR sum of numbers is the result of bitwise adding numbers modulo 2. This operation exists in many modern programming languages. For example, in languages C++, Java and Python it is represented as "^", and in Pascal — as "xor". | [
{
"input": "3\n2 3\n1 0\n1 0",
"output": "2\n1 0\n2 0"
},
{
"input": "2\n1 1\n1 0",
"output": "1\n0 1"
},
{
"input": "10\n3 13\n2 6\n1 5\n3 5\n1 3\n2 2\n2 6\n1 6\n1 3\n2 3",
"output": "9\n2 5\n4 3\n7 6\n8 3\n5 0\n6 1\n3 9\n1 0\n9 0"
},
{
"input": "10\n1 2\n1 7\n1 0\n1 8\n0 0\... | 218 | 2,252,800 | -1 | 55,216 | |
734 | Anton and Chess | [
"implementation"
] | null | null | Anton likes to play chess. Also, he likes to do programming. That is why he decided to write the program that plays chess. However, he finds the game on 8 to 8 board to too simple, he uses an infinite one instead.
The first task he faced is to check whether the king is in check. Anton doesn't know how to implement thi... | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=500<=000) — the number of black pieces.
The second line contains two integers *x*0 and *y*0 (<=-<=109<=≤<=*x*0,<=*y*0<=≤<=109) — coordinates of the white king.
Then follow *n* lines, each of them contains a character and two integers *x**i* and ... | The only line of the output should contains "YES" (without quotes) if the white king is in check and "NO" (without quotes) otherwise. | [
"2\n4 2\nR 1 1\nB 1 5\n",
"2\n4 2\nR 3 3\nB 1 5\n"
] | [
"YES\n",
"NO\n"
] | Picture for the first sample:
Picture for the second sample: | [
{
"input": "2\n4 2\nR 1 1\nB 1 5",
"output": "YES"
},
{
"input": "2\n4 2\nR 3 3\nB 1 5",
"output": "NO"
},
{
"input": "5\n-1 1\nR -10 10\nQ -9 9\nQ -2 -8\nB -6 10\nB -10 1",
"output": "YES"
},
{
"input": "20\n-321 454\nQ 967 -89\nR -811 454\nQ -404 454\nR -734 454\nQ -804 454... | 4,000 | 8,908,800 | 0 | 55,302 | |
404 | Marathon | [
"implementation",
"math"
] | null | null | Valera takes part in the Berland Marathon. The marathon race starts at the stadium that can be represented on the plane as a square whose lower left corner is located at point with coordinates (0,<=0) and the length of the side equals *a* meters. The sides of the square are parallel to coordinate axes.
As the length o... | The first line contains two space-separated real numbers *a* and *d* (1<=≤<=*a*,<=*d*<=≤<=105), given with precision till 4 decimal digits after the decimal point. Number *a* denotes the length of the square's side that describes the stadium. Number *d* shows that after each *d* meters Valera gets an extra drink.
The ... | Print *n* lines, each line should contain two real numbers *x**i* and *y**i*, separated by a space. Numbers *x**i* and *y**i* in the *i*-th line mean that Valera is at point with coordinates (*x**i*,<=*y**i*) after he covers *i*·*d* meters. Your solution will be considered correct if the absolute or relative error does... | [
"2 5\n2\n",
"4.147 2.8819\n6\n"
] | [
"1.0000000000 2.0000000000\n2.0000000000 0.0000000000\n",
"2.8819000000 0.0000000000\n4.1470000000 1.6168000000\n3.7953000000 4.1470000000\n0.9134000000 4.1470000000\n0.0000000000 2.1785000000\n0.7034000000 0.0000000000\n"
] | none | [
{
"input": "2 5\n2",
"output": "1.0000000000 2.0000000000\n2.0000000000 0.0000000000"
},
{
"input": "4.147 2.8819\n6",
"output": "2.8819000000 0.0000000000\n4.1470000000 1.6168000000\n3.7953000000 4.1470000000\n0.9134000000 4.1470000000\n0.0000000000 2.1785000000\n0.7034000000 0.0000000000"
},... | 623 | 9,216,000 | 0 | 55,336 | |
249 | Endless Matrix | [
"math"
] | null | null | A Russian space traveller Alisa Selezneva, like any other schoolgirl of the late 21 century, is interested in science. She has recently visited the MIT (Moscow Institute of Time), where its chairman and the co-inventor of the time machine academician Petrov told her about the construction of a time machine.
During the... | The first input line contains a single integer *t* (1<=≤<=*t*<=≤<=105) — the number of test sets for which you should solve the problem.
Each of the next *t* lines contains the description of a test — four positive integers *x*1,<=*y*1,<=*x*2 and *y*2 (1<=≤<=*x*1<=≤<=*x*2<=≤<=109,<=1<=≤<=*y*1<=≤<=*y*2<=≤<=109), separ... | For each query print the meaning of the expression if it contains at most 10 characters. Otherwise, print three characters "." (without the quotes), and then ten last digits of the time expression. Print the answer to each query on a single line. Follow the format, given in the sample as closely as possible. | [
"5\n1 1 1 1\n2 2 3 3\n2 3 5 6\n100 87 288 2002\n4 2 5 4\n"
] | [
"1\n24\n300\n...5679392764\n111\n"
] | none | [] | 92 | 0 | 0 | 55,338 | |
303 | Rotatable Number | [
"math",
"number theory"
] | null | null | Bike is a smart boy who loves math very much. He invented a number called "Rotatable Number" inspired by 142857.
As you can see, 142857 is a magic number because any of its rotatings can be got by multiplying that number by 1,<=2,<=...,<=6 (numbers from one to number's length). Rotating a number means putting its las... | The only line contains two space-separated integers *n*,<=*x* (1<=≤<=*n*<=≤<=5·106,<=2<=≤<=*x*<=≤<=109). | Print a single integer — the largest *b* you found. If no such *b* exists, print -1 instead. | [
"6 11\n",
"5 8\n"
] | [
"10\n",
"-1\n"
] | none | [] | 2,000 | 307,200 | 0 | 55,341 | |
545 | Paths and Trees | [
"graphs",
"greedy",
"shortest paths"
] | null | null | Little girl Susie accidentally found her elder brother's notebook. She has many things to do, more important than solving problems, but she found this problem too interesting, so she wanted to know its solution and decided to ask you about it. So, the problem statement is as follows.
Let's assume that we are given a c... | The first line contains two numbers, *n* and *m* (1<=≤<=*n*<=≤<=3·105, 0<=≤<=*m*<=≤<=3·105) — the number of vertices and edges of the graph, respectively.
Next *m* lines contain three integers each, representing an edge — *u**i*,<=*v**i*,<=*w**i* — the numbers of vertices connected by an edge and the weight of the edg... | In the first line print the minimum total weight of the edges of the tree.
In the next line print the indices of the edges that are included in the tree, separated by spaces. The edges are numbered starting from 1 in the order they follow in the input. You may print the numbers of the edges in any order.
If there are... | [
"3 3\n1 2 1\n2 3 1\n1 3 2\n3\n",
"4 4\n1 2 1\n2 3 1\n3 4 1\n4 1 2\n4\n"
] | [
"2\n1 2 \n",
"4\n2 3 4 \n"
] | In the first sample there are two possible shortest path trees:
- with edges 1 – 3 and 2 – 3 (the total weight is 3); - with edges 1 – 2 and 2 – 3 (the total weight is 2);
And, for example, a tree with edges 1 – 2 and 1 – 3 won't be a shortest path tree for vertex 3, because the distance from vertex 3 to vertex 2 i... | [
{
"input": "3 3\n1 2 1\n2 3 1\n1 3 2\n3",
"output": "2\n1 2 "
},
{
"input": "4 4\n1 2 1\n2 3 1\n3 4 1\n4 1 2\n4",
"output": "4\n2 3 4 "
},
{
"input": "4 5\n1 2 1\n1 3 1\n2 4 1\n3 4 1\n2 3 10\n1",
"output": "3\n1 2 3 "
},
{
"input": "6 8\n1 2 30\n1 3 20\n2 3 50\n4 2 100\n2 5 4... | 2,635 | 76,288,000 | 3 | 55,582 | |
989 | A Trance of Nightfall | [
"dp",
"geometry",
"matrices",
"probabilities"
] | null | null | "Flowing and passing like this, the water isn't gone ultimately; Waxing and waning like that, the moon doesn't shrink or grow eventually."
"Everything is transient in a way and perennial in another."
Kanno doesn't seem to make much sense out of Mino's isolated words, but maybe it's time that they enjoy the gentle bre... | The first line contains a positive integer $n$ ($2 \leq n \leq 200$) — the number of points in $S$.
The $i$-th of the following $n$ lines contains two space-separated integers $x_i$ and $y_i$ ($-10^4 \leq x_i, y_i \leq 10^4$) — the coordinates of the $i$-th point in $S$. The input guarantees that for all $1 \leq i \lt... | Output $q$ lines each containing a decimal number — the $i$-th among them denotes the maximum probability of staying on the $t_i$-th point after $m_i$ steps, with a proper choice of starting position $P$.
Your answer will be considered correct if each number in your output differs from the corresponding one in jury's ... | [
"5\n0 0\n1 3\n2 2\n3 1\n4 4\n10\n1 1\n2 1\n3 1\n4 1\n5 1\n3 2\n3 3\n3 4\n3 5\n3 6\n"
] | [
"0.50000000000000000000\n0.50000000000000000000\n0.33333333333333331483\n0.50000000000000000000\n0.50000000000000000000\n0.18518518518518517491\n0.15226337448559670862\n0.14494741655235482414\n0.14332164812274550414\n0.14296036624949901017\n"
] | The points in $S$ and possible candidates for line $l$ are depicted in the following figure.
For the first query, when $P = (-1, -3)$, $l$ is uniquely determined to be $3x = y$, and thus Kanno will move to $(0, 0)$ with a probability of $\frac 1 2$.
For the third query, when $P = (2, 2)$, $l$ is chosen equiprobably b... | [] | 2,000 | 614,400 | 0 | 55,793 | |
51 | bHTML Tables Analisys | [
"expression parsing"
] | B. bHTML Tables Analisys | 2 | 256 | In this problem is used an extremely simplified version of HTML table markup. Please use the statement as a formal document and read it carefully.
A string is a bHTML table, if it satisfies the grammar:
Blanks in the grammar are only for purposes of illustration, in the given data there will be no spaces. The bHTML ... | For convenience, input data can be separated into non-empty lines in an arbitrary manner. The input data consist of no more than 10 lines. Combine (concatenate) all the input lines into one, to get a text representation *s* of the specified table. String *s* corresponds to the given grammar (the root element of grammar... | Print the sizes of all the tables in the non-decreasing order. | [
"<table><tr><td></td></tr></table>\n",
"<table>\n<tr>\n<td>\n<table><tr><td></td></tr><tr><td></\ntd\n></tr><tr\n><td></td></tr><tr><td></td></tr></table&g... | [
"1 ",
"1 4 ",
"1 1 1 3 "
] | none | [
{
"input": "<table><tr><td></td></tr></table>",
"output": "1 "
},
{
"input": "<table>\n<tr>\n<td>\n<table><tr><td></td></tr><tr><td></\ntd\n></tr><tr\n><td></td></tr><tr><td></td></tr></table>\n</td>\n</tr>\n</table>",
"output": "1 4 "
},
{
"input": "<table><tr><td>\n<table><tr><td>\n<ta... | 62 | 0 | 0 | 55,942 |
833 | The Bakery | [
"binary search",
"data structures",
"divide and conquer",
"dp",
"two pointers"
] | null | null | Some time ago Slastyona the Sweetmaid decided to open her own bakery! She bought required ingredients and a wonder-oven which can bake several types of cakes, and opened the bakery.
Soon the expenses started to overcome the income, so Slastyona decided to study the sweets market. She learned it's profitable to pack ca... | The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=35000, 1<=≤<=*k*<=≤<=*min*(*n*,<=50)) – the number of cakes and the number of boxes, respectively.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*n*) – the types of cakes in the order the oven bakes them. | Print the only integer – the maximum total value of all boxes with cakes. | [
"4 1\n1 2 2 1\n",
"7 2\n1 3 3 1 4 4 4\n",
"8 3\n7 7 8 7 7 8 1 7\n"
] | [
"2\n",
"5\n",
"6\n"
] | In the first example Slastyona has only one box. She has to put all cakes in it, so that there are two types of cakes in the box, so the value is equal to 2.
In the second example it is profitable to put the first two cakes in the first box, and all the rest in the second. There are two distinct types in the first box... | [
{
"input": "4 1\n1 2 2 1",
"output": "2"
},
{
"input": "7 2\n1 3 3 1 4 4 4",
"output": "5"
},
{
"input": "8 3\n7 7 8 7 7 8 1 7",
"output": "6"
},
{
"input": "50 5\n2 39 16 20 32 36 29 42 14 23 9 4 28 17 45 16 46 1 39 33 47 15 34 43 6 6 12 15 46 11 32 16 31 12 41 33 47 35 22 3... | 2,500 | 4,608,000 | 0 | 56,169 | |
386 | Diverse Substrings | [
"dp",
"strings",
"two pointers"
] | null | null | String diversity is the number of symbols that occur in the string at least once. Diversity of *s* will be denoted by *d*(*s*). For example , *d*("aaa")=1, *d*("abacaba")=3.
Given a string *s*, consisting of lowercase Latin letters. Consider all its substrings. Obviously, any substring diversity is a number from 1 to ... | The input consists of a single line containing *s*. It contains only lowercase Latin letters, the length of *s* is from 1 to 3·105. | Print to the first line the value *d*(*s*). Print sequence *t*1,<=*t*2,<=...,<=*t**d*(*s*) to the following lines, where *t**i* is the number of substrings of *s* having diversity of exactly *i*. | [
"abca\n",
"aabacaabbad\n"
] | [
"3\n4\n3\n3\n",
"4\n14\n19\n28\n5\n"
] | Consider the first example.
We denote by *s*(*i*, *j*) a substring of "abca" with the indices in the segment [*i*, *j*].
- *s*(1, 1) = "a", *d*("a") = 1 - *s*(2, 2) = "b", *d*("b") = 1 - *s*(3, 3) = "c", *d*("c") = 1 - *s*(4, 4) = "a", *d*("a") = 1 - *s*(1, 2) = "ab", *d*("ab") = 2 - *s*(2, 3) = "bc", *d*... | [
{
"input": "abca",
"output": "3\n4\n3\n3"
},
{
"input": "aabacaabbad",
"output": "4\n14\n19\n28\n5"
},
{
"input": "a",
"output": "1\n1"
},
{
"input": "cabaccbcaa",
"output": "3\n12\n13\n30"
},
{
"input": "ccabaccbbb",
"output": "3\n15\n13\n27"
},
{
"in... | 78 | 0 | 0 | 56,210 | |
398 | Cards | [
"constructive algorithms",
"implementation"
] | null | null | User ainta loves to play with cards. He has *a* cards containing letter "o" and *b* cards containing letter "x". He arranges the cards in a row, and calculates the score of the deck by the formula below.
1. At first, the score is 0. 1. For each block of contiguous "o"s with length *x* the score increases by *x*2. 1.... | The first line contains two space-separated integers *a* and *b* (0<=≤<=*a*,<=*b*<=≤<=105; *a*<=+<=*b*<=≥<=1) — the number of "o" cards and the number of "x" cards. | In the first line print a single integer *v* — the maximum score that ainta can obtain.
In the second line print *a*<=+<=*b* characters describing the deck. If the *k*-th card of the deck contains "o", the *k*-th character must be "o". If the *k*-th card of the deck contains "x", the *k*-th character must be "x". The ... | [
"2 3\n",
"4 0\n",
"0 4\n"
] | [
"-1\nxoxox\n",
"16\noooo",
"-16\nxxxx"
] | none | [
{
"input": "2 3",
"output": "-1\nxoxox"
},
{
"input": "4 0",
"output": "16\noooo"
},
{
"input": "0 4",
"output": "-16\nxxxx"
},
{
"input": "8 6",
"output": "46\nxxxooooooooxxx"
},
{
"input": "28691 28312",
"output": "809737773\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx... | 108 | 102,400 | 0 | 56,293 | |
757 | Team Rocket Rises Again | [
"data structures",
"graphs",
"shortest paths"
] | null | null | It's the turn of the year, so Bash wants to send presents to his friends. There are *n* cities in the Himalayan region and they are connected by *m* bidirectional roads. Bash is living in city *s*. Bash has exactly one friend in each of the other cities. Since Bash wants to surprise his friends, he decides to send a Pi... | The first line contains three space separated integers *n*, *m* and *s* (2<=≤<=*n*<=≤<=2·105, , 1<=≤<=*s*<=≤<=*n*) — the number of cities and the number of roads in the Himalayan region and the city Bash lives in.
Each of the next *m* lines contain three space-separated integers *u*, *v* and *w* (1<=≤<=*u*,<=*v*<=≤<=*... | Print a single integer, the answer to the problem. | [
"4 4 3\n1 2 1\n2 3 1\n2 4 1\n3 1 1\n",
"7 11 2\n1 2 5\n1 3 5\n2 4 2\n2 5 2\n3 6 3\n3 7 3\n4 6 2\n3 4 2\n6 7 3\n4 5 7\n4 7 7\n"
] | [
"2\n",
"4\n"
] | In the first sample, on destroying the city 2, the length of shortest distance between pairs of cities (3, 2) and (3, 4) will change. Hence the answer is 2. | [] | 93 | 512,000 | 0 | 56,348 | |
581 | Three Logos | [
"bitmasks",
"brute force",
"constructive algorithms",
"geometry",
"implementation",
"math"
] | null | null | Three companies decided to order a billboard with pictures of their logos. A billboard is a big square board. A logo of each company is a rectangle of a non-zero area.
Advertisers will put up the ad only if it is possible to place all three logos on the billboard so that they do not overlap and the billboard has no e... | The first line of the input contains six positive integers *x*1,<=*y*1,<=*x*2,<=*y*2,<=*x*3,<=*y*3 (1<=≤<=*x*1,<=*y*1,<=*x*2,<=*y*2,<=*x*3,<=*y*3<=≤<=100), where *x**i* and *y**i* determine the length and width of the logo of the *i*-th company respectively. | If it is impossible to place all the three logos on a square shield, print a single integer "-1" (without the quotes).
If it is possible, print in the first line the length of a side of square *n*, where you can place all the three logos. Each of the next *n* lines should contain *n* uppercase English letters "A", "B"... | [
"5 1 2 5 5 2\n",
"4 4 2 6 4 2\n"
] | [
"5\nAAAAA\nBBBBB\nBBBBB\nCCCCC\nCCCCC\n",
"6\nBBBBBB\nBBBBBB\nAAAACC\nAAAACC\nAAAACC\nAAAACC\n"
] | none | [
{
"input": "5 1 2 5 5 2",
"output": "5\nAAAAA\nBBBBB\nBBBBB\nCCCCC\nCCCCC"
},
{
"input": "4 4 2 6 4 2",
"output": "6\nBBBBBB\nBBBBBB\nAAAACC\nAAAACC\nAAAACC\nAAAACC"
},
{
"input": "1 3 1 3 3 1",
"output": "3\nAAA\nBBB\nCCC"
},
{
"input": "2 4 1 4 1 4",
"output": "4\nAAAA\... | 93 | 0 | 3 | 56,389 | |
954 | Matrix Walk | [
"implementation"
] | null | null | There is a matrix *A* of size *x*<=×<=*y* filled with integers. For every , *A**i*,<=*j*<==<=*y*(*i*<=-<=1)<=+<=*j*. Obviously, every integer from [1..*xy*] occurs exactly once in this matrix.
You have traversed some path in this matrix. Your path can be described as a sequence of visited cells *a*1, *a*2, ..., *a**... | The first line contains one integer number *n* (1<=≤<=*n*<=≤<=200000) — the number of cells you visited on your path (if some cell is visited twice, then it's listed twice).
The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=109) — the integers in the cells on your path. | If all possible values of *x* and *y* such that 1<=≤<=*x*,<=*y*<=≤<=109 contradict with the information about your path, print NO.
Otherwise, print YES in the first line, and in the second line print the values *x* and *y* such that your path was possible with such number of lines and columns in the matrix. Remember t... | [
"8\n1 2 3 6 9 8 5 2\n",
"6\n1 2 1 2 5 3\n",
"2\n1 10\n"
] | [
"YES\n3 3\n",
"NO\n",
"YES\n4 9\n"
] | The matrix and the path on it in the first test looks like this:
Also there exist multiple correct answers for both the first and the third examples. | [
{
"input": "8\n1 2 3 6 9 8 5 2",
"output": "YES\n1000000000 3"
},
{
"input": "6\n1 2 1 2 5 3",
"output": "NO"
},
{
"input": "2\n1 10",
"output": "YES\n1000000000 9"
},
{
"input": "3\n1 2 2",
"output": "NO"
},
{
"input": "1\n1",
"output": "YES\n1000000000 1"
... | 61 | 1,945,600 | 0 | 56,401 | |
568 | Symmetric and Transitive | [
"combinatorics",
"dp",
"math"
] | null | null | Little Johnny has recently learned about set theory. Now he is studying binary relations. You've probably heard the term "equivalence relation". These relations are very important in many areas of mathematics. For example, the equality of the two numbers is an equivalence relation.
A set ρ of pairs (*a*,<=*b*) of elem... | A single line contains a single integer *n* (1<=≤<=*n*<=≤<=4000). | In a single line print the answer to the problem modulo 109<=+<=7. | [
"1\n",
"2\n",
"3\n"
] | [
"1\n",
"3\n",
"10\n"
] | If *n* = 1 there is only one such relation — an empty one, i.e. <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/8891a227c918474e5d76377d4644cd7cc01e1ffd.png" style="max-width: 100.0%;max-height: 100.0%;"/>. In other words, for a single element *x* of set *A* the following is hold: <img alig... | [
{
"input": "1",
"output": "1"
},
{
"input": "2",
"output": "3"
},
{
"input": "3",
"output": "10"
},
{
"input": "4",
"output": "37"
},
{
"input": "5",
"output": "151"
},
{
"input": "6",
"output": "674"
},
{
"input": "7",
"output": "3263"... | 77 | 2,867,200 | -1 | 56,443 | |
425 | Sereja and Sets | [
"dp"
] | null | null | Let's assume that set *S* consists of *m* distinct intervals [*l*1,<=*r*1], [*l*2,<=*r*2], ..., [*l**m*,<=*r**m*] (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*; *l**i*,<=*r**i* are integers).
Let's assume that *f*(*S*) is the maximum number of intervals that you can choose from the set *S*, such that every two of them do not inter... | The first line contains integers *n*, *k* (1<=≤<=*n*<=≤<=500; 0<=≤<=*k*<=≤<=500). | In a single line, print the answer to the problem modulo 1000000007 (109<=+<=7). | [
"3 1\n",
"3 2\n",
"2 0\n",
"2 2\n"
] | [
"23\n",
"32\n",
"1\n",
"2\n"
] | none | [] | 15 | 0 | 0 | 56,451 | |
958 | Guard Duty (medium) | [
"binary search",
"dp",
"greedy",
"sortings"
] | null | null | Princess Heidi decided to give orders to all her *K* Rebel ship commanders in person. Unfortunately, she is currently travelling through hyperspace, and will leave it only at *N* specific moments *t*1,<=*t*2,<=...,<=*t**N*. The meetings with commanders must therefore start and stop at those times. Namely, each commande... | The first line contains two integers *K*, *N* (2<=≤<=2*K*<=≤<=*N*<=≤<=500000, *K*<=≤<=5000). The second line contains *N* distinct integers *t*1,<=*t*2,<=...,<=*t**N* (1<=≤<=*t**i*<=≤<=109) representing the times when Heidi leaves hyperspace. | Output only one integer: the minimum time spent on meetings. | [
"2 5\n1 4 6 7 12\n",
"3 6\n6 3 4 2 5 1\n",
"4 12\n15 7 4 19 3 30 14 1 5 23 17 25\n"
] | [
"4\n",
"3\n",
"6\n"
] | In the first example, there are five valid schedules: [1, 4], [6, 7] with total time 4, [1, 4], [6, 12] with total time 9, [1, 4], [7, 12] with total time 8, [1, 6], [7, 12] with total time 10, and [4, 6], [7, 12] with total time 7. So the answer is 4.
In the second example, there is only 1 valid schedule: [1, 2], [3,... | [] | 3,000 | 97,280,000 | 0 | 56,453 | |
703 | Mishka and Divisors | [
"dp",
"number theory"
] | null | null | After playing with her beautiful array, Mishka decided to learn some math. After learning how to multiply, divide and what is divisibility, she is now interested in solving the following problem.
You are given integer *k* and array *a*1,<=*a*2,<=...,<=*a**n* of *n* integers. You are to find non-empty subsequence of ar... | The first line of the input contains two integers *n* and *k* (1<=≤<=*n*<=≤<=1<=000, 1<=≤<=*k*<=≤<=1012).
The second line of the input contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1012) — array elements. | Print single positive integer *m* in the first line — the number of elements in desired sequence.
In the second line print *m* distinct integers — the sequence of indices of given array elements, which should be taken into the desired sequence.
If there are more than one such subsequence (e.g. subsequence of minimum... | [
"5 60\n2 4 6 5 2\n"
] | [
"3\n4 3 1 "
] | none | [
{
"input": "5 60\n2 4 6 5 2",
"output": "3\n4 3 1 "
},
{
"input": "10 66\n93 799 19 143 1739 1403 19 1681 8513 1457",
"output": "-1"
},
{
"input": "10 78\n2473 7234 317 3793 6638 6 7789 753 1117 8243",
"output": "-1"
},
{
"input": "10 78\n19 1081 143 5 31 61 1363 319 39 589",... | 1,000 | 15,462,400 | 0 | 56,473 | |
566 | Max and Min | [
"geometry"
] | null | null | Two kittens, Max and Min, play with a pair of non-negative integers *x* and *y*. As you can guess from their names, kitten Max loves to maximize and kitten Min loves to minimize. As part of this game Min wants to make sure that both numbers, *x* and *y* became negative at the same time, and kitten Max tries to prevent ... | The first line contains two integers, *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100<=000) — the number of pairs of numbers available to Max and Min, correspondingly.
The second line contains two integers *x*, *y* (1<=≤<=*x*,<=*y*<=≤<=109) — the initial values of numbers with which the kittens are playing.
Next *n* lines conta... | Print «Max» (without the quotes), if kitten Max wins, or "Min" (without the quotes), if kitten Min wins. | [
"2 2\n42 43\n2 3\n3 2\n3 10\n10 3\n",
"1 1\n1 1\n3 4\n1 1\n"
] | [
"Min\n",
"Max\n"
] | In the first test from the statement Min can respond to move (2, 3) by move (3, 10), and to move (3, 2) by move (10, 3). Thus, for each pair of Max and Min's moves the values of both numbers *x* and *y* will strictly decrease, ergo, Min will win sooner or later.
In the second sample test after each pair of Max and Min... | [] | 514 | 10,547,200 | 0 | 56,487 | |
0 | none | [
"none"
] | null | null | In the spirit of the holidays, Saitama has given Genos two grid paths of length *n* (a weird gift even by Saitama's standards). A grid path is an ordered sequence of neighbouring squares in an infinite grid. Two squares are neighbouring if they share a side.
One example of a grid path is (0,<=0)<=→<=(0,<=1)<=→<=(0,<=2... | The first line of the input contains a single integer *n* (2<=≤<=*n*<=≤<=1<=000<=000) — the length of the paths.
The second line of the input contains a string consisting of *n*<=-<=1 characters (each of which is either 'N', 'E', 'S', or 'W') — the first grid path. The characters can be thought of as the sequence of m... | Print "YES" (without quotes) if it is possible for both marbles to be at the end position at the same time. Print "NO" (without quotes) otherwise. In both cases, the answer is case-insensitive. | [
"7\nNNESWW\nSWSWSW\n",
"3\nNN\nSS\n"
] | [
"YES\n",
"NO\n"
] | In the first sample, the first grid path is the one described in the statement. Moreover, the following sequence of moves will get both marbles to the end: NNESWWSWSW.
In the second sample, no sequence of moves can get both marbles to the end. | [
{
"input": "7\nNNESWW\nSWSWSW",
"output": "YES"
},
{
"input": "3\nNN\nSS",
"output": "NO"
},
{
"input": "3\nES\nNW",
"output": "NO"
},
{
"input": "5\nWSSE\nWNNE",
"output": "NO"
},
{
"input": "2\nE\nE",
"output": "YES"
},
{
"input": "2\nW\nS",
"out... | 2,000 | 5,836,800 | 0 | 56,517 | |
901 | Weighting a Tree | [
"constructive algorithms",
"dfs and similar",
"graphs"
] | null | null | You are given a connected undirected graph with *n* vertices and *m* edges. The vertices are enumerated from 1 to *n*.
You are given *n* integers *c*1,<=*c*2,<=...,<=*c**n*, each of them is between <=-<=*n* and *n*, inclusive. It is also guaranteed that the parity of *c**v* equals the parity of degree of vertex *v*. ... | The first line contains two integers *n* and *m* (2<=≤<=*n*<=≤<=105, *n*<=-<=1<=≤<=*m*<=≤<=105) — the number of vertices and the number of edges.
The next line contains *n* integers *c*1,<=*c*2,<=...,<=*c**n* (<=-<=*n*<=≤<=*c**i*<=≤<=*n*), where *c**i* is the required sum of weights of edges connected to vertex *i*. I... | If there is no solution, print "NO".
Otherwise print "YES" and then *m* lines, the *i*-th of them is the weight of the *i*-th edge *w**i* (<=-<=2·*n*2<=≤<=*w**i*<=≤<=2·*n*2). | [
"3 3\n2 2 2\n1 2\n2 3\n1 3\n",
"4 3\n-1 0 2 1\n1 2\n2 3\n3 4\n",
"6 6\n3 5 5 5 1 5\n1 4\n3 2\n4 3\n4 5\n3 5\n5 6\n",
"4 4\n4 4 2 4\n1 2\n2 3\n3 4\n4 1\n"
] | [
"YES\n1\n1\n1\n",
"YES\n-1\n1\n1\n",
"YES\n3\n5\n3\n-1\n-3\n5\n",
"NO"
] | none | [
{
"input": "3 3\n2 2 2\n1 2\n2 3\n1 3",
"output": "YES\n1\n1\n1"
},
{
"input": "4 3\n-1 0 2 1\n1 2\n2 3\n3 4",
"output": "YES\n-1\n1\n1"
},
{
"input": "6 6\n3 5 5 5 1 5\n1 4\n3 2\n4 3\n4 5\n3 5\n5 6",
"output": "YES\n3\n5\n3\n-1\n-3\n5"
},
{
"input": "4 4\n4 4 2 4\n1 2\n2 3\n... | 186 | 2,150,400 | -1 | 56,593 | |
523 | Mean Requests | [
"*special",
"implementation"
] | null | null | In this problem you will have to deal with a real algorithm that is used in the VK social network.
As in any other company that creates high-loaded websites, the VK developers have to deal with request statistics regularly. An important indicator reflecting the load of the site is the mean number of requests for a cer... | The first line contains integer *n* (1<=≤<=*n*<=≤<=2·105), integer *T* (1<=≤<=*T*<=≤<=*n*) and real number *c* (1<=<<=*c*<=≤<=100) — the time range when the resource should work, the length of the time range during which we need the mean number of requests and the coefficient *c* of the work of approximate algorithm... | Print *m* lines. The *j*-th line must contain three numbers *real*, *approx* and *error*, where:
- is the real mean number of queries for the last *T* seconds; - *approx* is calculated by the given algorithm and equals *mean* at the moment of time *t*<==<=*p**j* (that is, after implementing the *p**j*-th iteration ... | [
"1 1 2.000000\n1\n1\n1\n",
"11 4 1.250000\n9 11 7 5 15 6 6 6 6 6 6\n8\n4 5 6 7 8 9 10 11\n",
"13 4 1.250000\n3 3 3 3 3 20 3 3 3 3 3 3 3\n10\n4 5 6 7 8 9 10 11 12 13\n"
] | [
"1.000000 0.500000 0.500000\n",
"8.000000 4.449600 0.443800\n9.500000 6.559680 0.309507\n8.250000 6.447744 0.218455\n8.000000 6.358195 0.205226\n8.250000 6.286556 0.237993\n6.000000 6.229245 0.038207\n6.000000 6.183396 0.030566\n6.000000 6.146717 0.024453\n",
"3.000000 1.771200 0.409600\n3.000000 2.016960 0.327... | none | [
{
"input": "1 1 2.000000\n1\n1\n1",
"output": "1.000000 0.500000 0.500000"
},
{
"input": "11 4 1.250000\n9 11 7 5 15 6 6 6 6 6 6\n8\n4 5 6 7 8 9 10 11",
"output": "8.000000 4.449600 0.443800\n9.500000 6.559680 0.309507\n8.250000 6.447744 0.218455\n8.000000 6.358195 0.205226\n8.250000 6.286556 0.... | 46 | 0 | 0 | 56,597 | |
959 | Mahmoud and Ehab and the message | [
"dsu",
"greedy",
"implementation"
] | null | null | Mahmoud wants to send a message to his friend Ehab. Their language consists of *n* words numbered from 1 to *n*. Some words have the same meaning so there are *k* groups of words such that all the words in some group have the same meaning.
Mahmoud knows that the *i*-th word can be sent with cost *a**i*. For each word ... | The first line of input contains integers *n*, *k* and *m* (1<=≤<=*k*<=≤<=*n*<=≤<=105,<=1<=≤<=*m*<=≤<=105) — the number of words in their language, the number of groups of words, and the number of words in Mahmoud's message respectively.
The second line contains *n* strings consisting of lowercase English letters of l... | The only line should contain the minimum cost to send the message after replacing some words (maybe none) with some words of the same meaning. | [
"5 4 4\ni loser am the second\n100 1 1 5 10\n1 1\n1 3\n2 2 5\n1 4\ni am the second\n",
"5 4 4\ni loser am the second\n100 20 1 5 10\n1 1\n1 3\n2 2 5\n1 4\ni am the second\n"
] | [
"107",
"116"
] | In the first sample, Mahmoud should replace the word "second" with the word "loser" because it has less cost so the cost will be 100+1+5+1=107.
In the second sample, Mahmoud shouldn't do any replacement so the cost will be 100+1+5+10=116. | [
{
"input": "5 4 4\ni loser am the second\n100 1 1 5 10\n1 1\n1 3\n2 2 5\n1 4\ni am the second",
"output": "107"
},
{
"input": "5 4 4\ni loser am the second\n100 20 1 5 10\n1 1\n1 3\n2 2 5\n1 4\ni am the second",
"output": "116"
},
{
"input": "1 1 1\na\n1000000000\n1 1\na",
"output": ... | 31 | 0 | 0 | 56,600 | |
71 | Nuclear Fusion | [
"bitmasks",
"dp"
] | E. Nuclear Fusion | 1 | 256 | There is the following puzzle popular among nuclear physicists.
A reactor contains a set of *n* atoms of some chemical elements. We shall understand the phrase "atomic number" as the number of this atom's element in the periodic table of the chemical elements.
You are allowed to take any two different atoms and fuse ... | The first line contains two integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=17). The second line contains space-separated symbols of elements of *n* atoms, which are available from the start. The third line contains space-separated symbols of elements of *k* atoms which need to be the result of the fusion. The symbols of t... | If it is impossible to synthesize the required atoms, print "NO" without the quotes. Otherwise, print on the first line «YES», and on the next *k* lines print the way of synthesizing each of *k* atoms as equations. Each equation has the following form: "*x*1+*x*2+...+*x**t*->*y**i*", where *x**j* is the symbol of th... | [
"10 3\nMn Co Li Mg C P F Zn Sc K\nSn Pt Y\n",
"2 1\nH H\nHe\n",
"2 2\nBk Fm\nCf Es\n"
] | [
"YES\nMn+C+K->Sn\nCo+Zn+Sc->Pt\nLi+Mg+P+F->Y\n",
"YES\nH+H->He\n",
"NO\n"
] | The reactions from the first example possess the following form (the atomic number is written below and to the left of the element):
<img align="middle" class="tex-formula" src="https://espresso.codeforces.com/6f2ce1bed492cbe40ff1bb4600fe53aebc680ace.png" style="max-width: 100.0%;max-height: 100.0%;"/>
<img align="mi... | [
{
"input": "10 3\nMn Co Li Mg C P F Zn Sc K\nSn Pt Y",
"output": "YES\nCo+Mg->Y\nLi+P+F+Zn+Sc->Pt\nMn+C+K->Sn"
},
{
"input": "2 1\nH H\nHe",
"output": "YES\nH+H->He"
},
{
"input": "2 2\nBk Fm\nCf Es",
"output": "NO"
},
{
"input": "8 8\nTl Pb Bi Po Np Pu Am Cm\nAt Rn Fr Ra Ac ... | 342 | 9,728,000 | 3.81088 | 56,741 |
286 | Shifting | [
"implementation"
] | null | null | John Doe has found the beautiful permutation formula.
Let's take permutation *p*<==<=*p*1,<=*p*2,<=...,<=*p**n*. Let's define transformation *f* of this permutation:
where *k* (*k*<=><=1) is an integer, the transformation parameter, *r* is such maximum integer that *rk*<=≤<=*n*. If *rk*<==<=*n*, then elements *p*... | A single line contains integer *n* (2<=≤<=*n*<=≤<=106). | Print *n* distinct space-separated integers from 1 to *n* — a beautiful permutation of size *n*. | [
"2\n",
"3\n",
"4\n"
] | [
"2 1 \n",
"1 3 2 \n",
"4 2 3 1 \n"
] | A note to the third test sample:
- *f*([1, 2, 3, 4], 2) = [2, 1, 4, 3] - *f*([2, 1, 4, 3], 3) = [1, 4, 2, 3] - *f*([1, 4, 2, 3], 4) = [4, 2, 3, 1] | [] | 92 | 0 | 0 | 56,833 | |
875 | Royal Questions | [
"dsu",
"graphs",
"greedy"
] | null | null | In a medieval kingdom, the economic crisis is raging. Milk drops fall, Economic indicators are deteriorating every day, money from the treasury disappear. To remedy the situation, King Charles Sunnyface decided make his *n* sons-princes marry the brides with as big dowry as possible.
In search of candidates, the king ... | The first line contains two integers *n*, *m* (2<=≤<=*n*<=≤<=200<=000, 1<=≤<=*m*<=≤<=200<=000) — number of princes and princesses respectively.
Each of following *m* lines contains three integers *a**i*, *b**i*, *w**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*, *a**i*<=≠<=*b**i*, 1<=≤<=*w**i*<=≤<=10<=000) — number of princes, wh... | Print the only integer — the maximum number of gold coins that a king can get by playing the right weddings. | [
"2 3\n1 2 5\n1 2 1\n2 1 10\n",
"3 2\n1 2 10\n3 2 20\n"
] | [
"15",
"30"
] | none | [
{
"input": "2 3\n1 2 5\n1 2 1\n2 1 10",
"output": "15"
},
{
"input": "3 2\n1 2 10\n3 2 20",
"output": "30"
},
{
"input": "2 2\n1 2 1\n1 2 2",
"output": "3"
},
{
"input": "3 3\n1 3 4\n1 3 2\n1 3 8",
"output": "12"
},
{
"input": "2 1\n1 2 6",
"output": "6"
},
... | 124 | 0 | 0 | 56,863 | |
518 | Pasha and Pipe | [
"binary search",
"brute force",
"combinatorics",
"dp",
"implementation"
] | null | null | On a certain meeting of a ruling party "A" minister Pavel suggested to improve the sewer system and to create a new pipe in the city.
The city is an *n*<=×<=*m* rectangular squared field. Each square of the field is either empty (then the pipe can go in it), or occupied (the pipe cannot go in such square). Empty squar... | The first line of the input contains two integers *n*,<=*m* (2<=≤<=*n*,<=*m*<=≤<=2000) — the height and width of Berland map.
Each of the next *n* lines contains *m* characters — the map of the city.
If the square of the map is marked by character '.', then the square is empty and the pipe can through it.
If the s... | In the first line of the output print a single integer — the number of distinct ways to create a pipe. | [
"3 3\n...\n..#\n...\n",
"4 2\n..\n..\n..\n..\n",
"4 5\n#...#\n#...#\n###.#\n###.#\n"
] | [
"3",
"2\n",
"4"
] | In the first sample there are 3 ways to make a pipe (the squares of the pipe are marked by characters ' * '): | [] | 46 | 0 | 0 | 56,927 | |
479 | Long Jumps | [
"binary search",
"greedy",
"implementation"
] | null | null | Valery is a PE teacher at a school in Berland. Soon the students are going to take a test in long jumps, and Valery has lost his favorite ruler!
However, there is no reason for disappointment, as Valery has found another ruler, its length is *l* centimeters. The ruler already has *n* marks, with which he can make mea... | The first line contains four positive space-separated integers *n*, *l*, *x*, *y* (2<=≤<=*n*<=≤<=105, 2<=≤<=*l*<=≤<=109, 1<=≤<=*x*<=<<=*y*<=≤<=*l*) — the number of marks, the length of the ruler and the jump norms for girls and boys, correspondingly.
The second line contains a sequence of *n* integers *a*1,<=*a*2,<... | In the first line print a single non-negative integer *v* — the minimum number of marks that you need to add on the ruler.
In the second line print *v* space-separated integers *p*1,<=*p*2,<=...,<=*p**v* (0<=≤<=*p**i*<=≤<=*l*). Number *p**i* means that the *i*-th mark should be at the distance of *p**i* centimeters fr... | [
"3 250 185 230\n0 185 250\n",
"4 250 185 230\n0 20 185 250\n",
"2 300 185 230\n0 300\n"
] | [
"1\n230\n",
"0\n",
"2\n185 230\n"
] | In the first sample it is impossible to initially measure the distance of 230 centimeters. For that it is enough to add a 20 centimeter mark or a 230 centimeter mark.
In the second sample you already can use the ruler to measure the distances of 185 and 230 centimeters, so you don't have to add new marks.
In the thir... | [
{
"input": "3 250 185 230\n0 185 250",
"output": "1\n230"
},
{
"input": "4 250 185 230\n0 20 185 250",
"output": "0"
},
{
"input": "2 300 185 230\n0 300",
"output": "2\n185 230"
},
{
"input": "4 300 4 5\n0 6 7 300",
"output": "1\n11"
},
{
"input": "2 100 30 70\n0 ... | 1,000 | 13,107,200 | 0 | 57,061 | |
39 | Inverse Function | [
"implementation"
] | G. Inverse Function | 5 | 64 | Petya wrote a programme on C++ that calculated a very interesting function *f*(*n*). Petya ran the program with a certain value of *n* and went to the kitchen to have some tea. The history has no records concerning how long the program had been working. By the time Petya returned, it had completed the calculations and ... | The first line has an integer *f*(*n*) from the interval [0..32767]. The next lines have the description of the function *f*. In the description can be found extra spaces and line breaks (see the examples) which, of course, can’t break key words int, if, return and numbers. The size of input data can’t exceed 100 bytes... | Output a single number — the answer to the problem. If there’s no answer, output "-1" (without quotes). | [
"17\nint f(int n)\n{\nif (n < 100) return 17;\nif (n > 99) return 27;\n}\n",
"13\nint f(int n)\n{\nif (n == 0) return 0;\nreturn f(n - 1) + 1;\n}\n",
"144\nint f(int n)\n{\nif (n == 0) return 0;\nif (n == 1) return n;\nreturn f(n - 1) + f(n - 2);\n}"
] | [
"99\n",
"13",
"24588\n"
] | none | [
{
"input": "17\nint f(int n)\n{\nif (n < 100) return 17;\nif (n > 99) return 27;\n}",
"output": "99"
},
{
"input": "13\nint f(int n)\n{\nif (n == 0) return 0;\nreturn f(n - 1) + 1;\n}",
"output": "13"
},
{
"input": "144\nint f(int n)\n{\nif (n == 0) return 0;\nif (n == 1) return n;\nretu... | 60 | 52,428,800 | 0 | 57,147 |
794 | Choosing Carrot | [
"games",
"math"
] | null | null | Oleg the bank client and Igor the analyst are arguing again. This time, they want to pick a gift as a present for their friend, ZS the coder. After a long thought, they decided that their friend loves to eat carrots the most and thus they want to pick the best carrot as their present.
There are *n* carrots arranged in... | The first line of input contains a single integer *n* (1<=≤<=*n*<=≤<=3·105) — the total number of carrots.
The next line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109). Here *a**i* denotes the juiciness of the *i*-th carrot from the left of the line. | Output *n* space-separated integers *x*0,<=*x*1,<=...,<=*x**n*<=-<=1. Here, *x**i* denotes the juiciness of the carrot the friends will present to ZS if *k*<==<=*i*. | [
"4\n1 2 3 5\n",
"5\n1000000000 1000000000 1000000000 1000000000 1\n"
] | [
"3 3 5 5\n",
"1000000000 1000000000 1000000000 1000000000 1000000000\n"
] | For the first example,
When *k* = 0, one possible optimal game is as follows:
- Oleg eats the carrot with juiciness 1.- Igor eats the carrot with juiciness 5.- Oleg eats the carrot with juiciness 2.- The remaining carrot has juiciness 3.
When *k* = 1, one possible optimal play is as follows:
- Oleg eats the carr... | [
{
"input": "4\n1 2 3 5",
"output": "3 3 5 5"
},
{
"input": "5\n1000000000 1000000000 1000000000 1000000000 1",
"output": "1000000000 1000000000 1000000000 1000000000 1000000000"
},
{
"input": "4\n1 12 3 5",
"output": "12 3 12 12"
},
{
"input": "5\n1 3 2 2 4",
"output": "2... | 202 | 2,048,000 | -1 | 57,238 | |
403 | Beautiful Pairs of Numbers | [
"combinatorics",
"dp"
] | null | null | The sequence of integer pairs (*a*1,<=*b*1),<=(*a*2,<=*b*2),<=...,<=(*a**k*,<=*b**k*) is beautiful, if the following statements are fulfilled:
- 1<=≤<=*a*1<=≤<=*b*1<=<<=*a*2<=≤<=*b*2<=<<=...<=<<=*a**k*<=≤<=*b**k*<=≤<=*n*, where *n* is a given positive integer; - all numbers *b*1<=-<=*a*1, *b*2<=-<=*a*2, ..... | The first line contains integer *t* (1<=≤<=*t*<=≤<=<=2·105) — the number of the test data.
Each of the next *t* lines contains two integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=1000). | For each test from the input print the answer to the problem modulo 1000000007 (109<=+<=7). Print the answers to the tests in the order in which the tests are given in the input. | [
"6\n1 1\n2 1\n2 2\n3 1\n3 2\n3 3\n"
] | [
"1\n3\n0\n6\n2\n0\n"
] | In the first test sample there is exactly one beautiful sequence: (1, 1).
In the second test sample, the following sequences are beautiful:
- (1, 1); - (1, 2); - (2, 2).
In the fourth test sample, the following sequences are beautiful:
- (1, 1); - (1, 2); - (1, 3); - (2, 2); - (2, 3); - (3, 3).
In the f... | [
{
"input": "6\n1 1\n2 1\n2 2\n3 1\n3 2\n3 3",
"output": "1\n3\n0\n6\n2\n0"
}
] | 31 | 0 | 0 | 57,246 | |
868 | El Toll Caves | [
"math"
] | null | null | The prehistoric caves of El Toll are located in Moià (Barcelona). You have heard that there is a treasure hidden in one of *n* possible spots in the caves. You assume that each of the spots has probability 1<=/<=*n* to contain a treasure.
You cannot get into the caves yourself, so you have constructed a robot that can... | The first line contains the number of test cases *T* (1<=≤<=*T*<=≤<=1000).
Each of the next *T* lines contains two integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=5·108). | For each test case output the answer in a separate line. | [
"3\n1 1\n2 1\n3 2\n"
] | [
"2\n500000007\n777777786\n"
] | In the first case the robot will repeatedly search in the only spot. The expected number of days in this case is 2. Note that in spite of the fact that we know the treasure spot from the start, the robot still has to search there until he succesfully recovers the treasure.
In the second case the answer can be shown to... | [] | 31 | 0 | 0 | 57,355 | |
277 | Game | [
"games",
"implementation"
] | null | null | Two players play the following game. Initially, the players have a knife and a rectangular sheet of paper, divided into equal square grid cells of unit size. The players make moves in turn, the player who can't make a move loses. In one move, a player can take the knife and cut the paper along any segment of the grid l... | The first line contains three integers *n*, *m*, *k* (1<=≤<=*n*,<=*m*<=≤<=109,<=0<=≤<=*k*<=≤<=105) — the sizes of the piece of paper and the number of cuts. Then follow *k* lines, each containing 4 integers *xb**i*,<=*yb**i*,<=*xe**i*,<=*ye**i* (0<=≤<=*xb**i*,<=*xe**i*<=≤<=*n*,<=0<=≤<=*yb**i*,<=*ye**i*<=≤<=*m*) — the c... | If the second player wins, print "SECOND". Otherwise, in the first line print "FIRST", and in the second line print any winning move of the first player (the coordinates of the cut ends, follow input format to print them). | [
"2 1 0\n",
"2 2 4\n0 1 2 1\n0 1 2 1\n1 2 1 0\n1 1 1 2\n"
] | [
"FIRST\n1 0 1 1\n",
"SECOND\n"
] | none | [] | 92 | 819,200 | -1 | 57,386 | |
732 | Sockets | [
"greedy",
"sortings"
] | null | null | The ICM ACPC World Finals is coming! Unfortunately, the organizers of the competition were so busy preparing tasks that totally missed an important technical point — the organization of electricity supplement for all the participants workstations.
There are *n* computers for participants, the *i*-th of which has power... | The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=200<=000) — the number of computers and the number of sockets.
The second line contains *n* integers *p*1,<=*p*2,<=...,<=*p**n* (1<=≤<=*p**i*<=≤<=109) — the powers of the computers.
The third line contains *m* integers *s*1,<=*s*2,<=...,<=*s**m* (... | In the first line print two numbers *c* and *u* — the maximum number of computers which can at the same time be connected to electricity and the minimum number of adapters needed to connect *c* computers.
In the second line print *m* integers *a*1,<=*a*2,<=...,<=*a**m* (0<=≤<=*a**i*<=≤<=109), where *a**i* equals the n... | [
"2 2\n1 1\n2 2\n",
"2 1\n2 100\n99\n"
] | [
"2 2\n1 1\n1 2\n",
"1 6\n6\n1 0\n"
] | none | [
{
"input": "2 2\n1 1\n2 2",
"output": "2 2\n1 1\n1 2"
},
{
"input": "2 1\n2 100\n99",
"output": "1 6\n6\n1 0"
},
{
"input": "1 1\n1\n1",
"output": "1 0\n0\n1"
},
{
"input": "2 1\n2 570129\n753393670",
"output": "1 29\n29\n1 0"
},
{
"input": "1 2\n258\n270411237 42... | 2,000 | 1,433,600 | 0 | 57,424 | |
93 | Lostborn | [
"dp",
"math",
"number theory"
] | E. Lostborn | 2 | 256 | Igor K. very much likes a multiplayer role playing game WineAge II. Who knows, perhaps, that might be the reason for his poor performance at the university. As any person who plays the game, he is interested in equipping his hero with as good weapon and outfit as possible.
One day, as he was reading the game's forum ... | The first line contains two integers: *n* and *k* (1<=≤<=*n*<=≤<=1013, 1<=≤<=*k*<=≤<=100). They are the indicator of Igor K's hero's strength and the number of hit indicators.
The next line contains space-separated *k* integers *a**i* (1<=≤<=*a**i*<=≤<=1000). They are Lostborn sword's hit indicators. The given *k* num... | Print the single number — the damage that will be inflicted by Igor K.'s hero when he uses his new weapon.
Please, do not use the %lld specificator to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specificator. | [
"20 3\n2 3 5\n",
"50 2\n15 8\n"
] | [
"6\n",
"41\n"
] | none | [] | 2,000 | 11,571,200 | 0 | 57,431 |
387 | George and Cards | [
"binary search",
"data structures"
] | null | null | George is a cat, so he loves playing very much.
Vitaly put *n* cards in a row in front of George. Each card has one integer written on it. All cards had distinct numbers written on them. Let's number the cards from the left to the right with integers from 1 to *n*. Then the *i*-th card from the left contains number *p... | The first line contains integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=106) — the initial and the final number of cards.
The second line contains *n* distinct space-separated integers *p*1,<=*p*2,<=...,<=*p**n* (1<=≤<=*p**i*<=≤<=*n*) — the initial row of cards.
The third line contains *k* space-separated integers *b*1,... | Print a single integer — the maximum number of pieces of sausage that George can get if he acts optimally well. | [
"3 2\n2 1 3\n1 3\n",
"10 5\n1 2 3 4 5 6 7 8 9 10\n2 4 6 8 10\n"
] | [
"1\n",
"30\n"
] | none | [] | 30 | 0 | 0 | 57,437 | |
0 | none | [
"none"
] | null | null | Alyona has built *n* towers by putting small cubes some on the top of others. Each cube has size 1<=×<=1<=×<=1. A tower is a non-zero amount of cubes standing on the top of each other. The towers are next to each other, forming a row.
Sometimes Alyona chooses some segment towers, and put on the top of each tower sever... | The first line contain single integer *n* (1<=≤<=*n*<=≤<=3·105) — the number of towers.
The second line contain *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the number of cubes in each tower.
The third line contain single integer *m* (1<=≤<=*m*<=≤<=3·105) — the number of additions.
The next *m* ... | Print *m* lines. In *i*-th line print the maximum width of the hills after the *i*-th addition. | [
"5\n5 5 5 5 5\n3\n1 3 2\n2 2 1\n4 4 1\n"
] | [
"2\n4\n5\n"
] | The first sample is as follows:
After addition of 2 cubes on the top of each towers from the first to the third, the number of cubes in the towers become equal to [7, 7, 7, 5, 5]. The hill with maximum width is [7, 5], thus the maximum width is 2.
After addition of 1 cube on the second tower, the number of cubes in t... | [] | 31 | 0 | 0 | 57,449 | |
542 | Quest | [
"dp",
"greedy"
] | null | null | Polycarp is making a quest for his friends. He has already made *n* tasks, for each task the boy evaluated how interesting it is as an integer *q**i*, and the time *t**i* in minutes needed to complete the task.
An interesting feature of his quest is: each participant should get the task that is best suited for him, d... | The first line contains two integers *n* and *T* (1<=≤<=*n*<=≤<=1000, 1<=≤<=*T*<=≤<=100) — the number of tasks made by Polycarp and the maximum time a quest player should fit into.
Next *n* lines contain two integers *t**i*,<=*q**i* (1<=≤<=*t**i*<=≤<=*T*, 1<=≤<=*q**i*<=≤<=1000) each — the time in minutes needed to com... | Print a single integer — the maximum possible total interest value of all the tasks in the quest. | [
"5 5\n1 1\n1 1\n2 2\n3 3\n4 4\n",
"5 5\n4 1\n4 2\n4 3\n4 4\n4 5\n",
"2 2\n1 1\n2 10\n"
] | [
"11\n",
"9\n",
"10\n"
] | In the first sample test all the five tasks can be complemented with four questions and joined into one quest.
In the second sample test it is impossible to use all the five tasks, but you can take two of them, the most interesting ones.
In the third sample test the optimal strategy is to include only the second task... | [
{
"input": "5 5\n1 1\n1 1\n2 2\n3 3\n4 4",
"output": "11"
},
{
"input": "5 5\n4 1\n4 2\n4 3\n4 4\n4 5",
"output": "9"
},
{
"input": "2 2\n1 1\n2 10",
"output": "10"
},
{
"input": "10 1\n1 732\n1 649\n1 821\n1 756\n1 377\n1 216\n1 733\n1 420\n1 857\n1 193",
"output": "857"... | 202 | 1,843,200 | 3 | 57,454 | |
234 | Champions' League | [
"implementation"
] | null | null | In the autumn of this year, two Russian teams came into the group stage of the most prestigious football club competition in the world — the UEFA Champions League. Now, these teams have already started to play in the group stage and are fighting for advancing to the playoffs. In this problem we are interested in the dr... | The first input line contains integer *n* (4<=≤<=*n*<=≤<=64, *n* is divisible by four) — the number of teams that take part in the sorting. The second line contains four space-separated integers *x*,<=*a*,<=*b*,<=*c* (1<=≤<=*x*,<=*a*,<=*b*,<=*c*<=≤<=1000) — the parameters of the random number generator. Each of the fol... | Print the way the teams must be sorted into groups. Print the groups in the order, in which they are formed in the sorting. Number the groups by consecutive uppercase English letters, starting from letter 'A'. Inside each group print the teams' names one per line, in the order of decreasing of the teams' rating. See sa... | [
"8\n1 3 1 7\nBarcelona 158\nMilan 90\nSpartak 46\nAnderlecht 48\nCeltic 32\nBenfica 87\nZenit 79\nMalaga 16\n"
] | [
"Group A:\nBarcelona\nBenfica\nSpartak\nCeltic\nGroup B:\nMilan\nZenit\nAnderlecht\nMalaga\n"
] | In the given sample the random number generator will be executed four times:
- <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/2d76d911e7446d6db4b0be2679ce6e5ab930ab92.png" style="max-width: 100.0%;max-height: 100.0%;"/>, - <img align="middle" class="tex-formula" src="https://espresso.c... | [
{
"input": "8\n1 3 1 7\nBarcelona 158\nMilan 90\nSpartak 46\nAnderlecht 48\nCeltic 32\nBenfica 87\nZenit 79\nMalaga 16",
"output": "Group A:\nBarcelona\nBenfica\nSpartak\nCeltic\nGroup B:\nMilan\nZenit\nAnderlecht\nMalaga"
},
{
"input": "4\n777 556 763 235\nkRnl 221\nSnxtrev 981\nBAaxtAFAyfYKea 390\... | 62 | 0 | 0 | 57,563 | |
53 | Dead Ends | [
"bitmasks",
"dp"
] | E. Dead Ends | 5 | 256 | Life in Bertown has become hard. The city has too many roads and the government spends too much to maintain them. There are *n* junctions and *m* two way roads, at which one can get from each junction to any other one. The mayor wants to close some roads so that the number of roads left totaled to *n*<=-<=1 roads and i... | The first line contains three integers *n*, *m* and *k* (3<=≤<=*n*<=≤<=10,<=*n*<=-<=1<=≤<=*m*<=≤<=*n*·(*n*<=-<=1)<=/<=2,<=2<=≤<=*k*<=≤<=*n*<=-<=1) which represent the number of junctions, roads and dead ends correspondingly. Then follow *m* lines each containing two different integers *v*1 and *v*2 (1<=≤<=*v*1,<=*v*2<=... | Print a single number — the required number of ways. | [
"3 3 2\n1 2\n2 3\n1 3\n",
"4 6 2\n1 2\n2 3\n3 4\n4 1\n1 3\n2 4\n",
"4 6 3\n1 2\n2 3\n3 4\n4 1\n1 3\n2 4\n"
] | [
"3\n",
"12\n",
"4\n"
] | none | [
{
"input": "3 3 2\n1 2\n2 3\n1 3",
"output": "3"
},
{
"input": "4 6 2\n1 2\n2 3\n3 4\n4 1\n1 3\n2 4",
"output": "12"
},
{
"input": "4 6 3\n1 2\n2 3\n3 4\n4 1\n1 3\n2 4",
"output": "4"
},
{
"input": "5 4 3\n2 1\n5 3\n3 2\n1 4",
"output": "0"
},
{
"input": "5 10 2\n... | 60 | 0 | 0 | 57,612 |
195 | Analyzing Polyline | [
"geometry",
"math",
"sortings"
] | null | null | As Valeric and Valerko were watching one of the last Euro Championship games in a sports bar, they broke a mug. Of course, the guys paid for it but the barman said that he will let them watch football in his bar only if they help his son complete a programming task. The task goes like that.
Let's consider a set of fun... | The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of functions. Each of the following *n* lines contains two space-separated integer numbers *k**i*,<=*b**i* (<=-<=109<=≤<=*k**i*,<=*b**i*<=≤<=109) that determine the *i*-th function. | Print a single number — the number of angles that do not equal 180 degrees in the graph of the polyline that equals the sum of the given functions. | [
"1\n1 0\n",
"3\n1 0\n0 2\n-1 1\n",
"3\n-2 -4\n1 7\n-5 1\n"
] | [
"1\n",
"2\n",
"3\n"
] | none | [
{
"input": "1\n1 0",
"output": "1"
},
{
"input": "3\n1 0\n0 2\n-1 1",
"output": "2"
},
{
"input": "3\n-2 -4\n1 7\n-5 1",
"output": "3"
},
{
"input": "10\n9 9\n-5 2\n-2 9\n0 6\n6 7\n-1 -10\n-8 6\n3 6\n-3 -9\n0 4",
"output": "8"
},
{
"input": "10\n-4 -9\n5 9\n-4 -1\... | 1,652 | 13,312,000 | 0 | 57,662 | |
784 | Touchy-Feely Palindromes | [
"*special",
"implementation"
] | null | null | The only line of the input contains a string of digits. The length of the string is between 1 and 10, inclusive.
Output "Yes" or "No". | The only line of the input contains a string of digits. The length of the string is between 1 and 10, inclusive. | Output "Yes" or "No". | [
"373\n",
"121\n",
"436\n"
] | [
"Yes\n",
"No\n",
"Yes\n"
] | none | [
{
"input": "373",
"output": "Yes"
},
{
"input": "121",
"output": "No"
},
{
"input": "436",
"output": "Yes"
},
{
"input": "7",
"output": "Yes"
},
{
"input": "8",
"output": "No"
},
{
"input": "4357087936",
"output": "Yes"
},
{
"input": "80697... | 62 | 0 | -1 | 57,711 | |
46 | Parking Lot | [
"data structures",
"implementation"
] | D. Parking Lot | 2 | 256 | Nowadays it is becoming increasingly difficult to park a car in cities successfully. Let's imagine a segment of a street as long as *L* meters along which a parking lot is located. Drivers should park their cars strictly parallel to the pavement on the right side of the street (remember that in the country the authors ... | The first line contains three integers *L*, *b* и *f* (10<=≤<=*L*<=≤<=100000,<=1<=≤<=*b*,<=*f*<=≤<=100). The second line contains an integer *n* (1<=≤<=*n*<=≤<=100) that indicates the number of requests the program has got. Every request is described on a single line and is given by two numbers. The first number repres... | For every request of the 1 type print number -1 on the single line if the corresponding car couldn't find place to park along the street. Otherwise, print a single number equal to the distance between the back of the car in its parked position and the beginning of the parking lot zone. | [
"30 1 2\n6\n1 5\n1 4\n1 5\n2 2\n1 5\n1 4\n",
"30 1 1\n6\n1 5\n1 4\n1 5\n2 2\n1 5\n1 4\n",
"10 1 1\n1\n1 12\n"
] | [
"0\n6\n11\n17\n23\n",
"0\n6\n11\n17\n6\n",
"-1\n"
] | none | [
{
"input": "30 1 2\n6\n1 5\n1 4\n1 5\n2 2\n1 5\n1 4",
"output": "0\n6\n11\n17\n23"
},
{
"input": "30 1 1\n6\n1 5\n1 4\n1 5\n2 2\n1 5\n1 4",
"output": "0\n6\n11\n17\n6"
},
{
"input": "10 1 1\n1\n1 12",
"output": "-1"
},
{
"input": "10 1 1\n1\n1 9",
"output": "0"
},
{
... | 0 | 0 | -1 | 57,754 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.