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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | none | [
"none"
] | null | null | It is a balmy spring afternoon, and Farmer John's *n* cows are ruminating about link-cut cacti in their stalls. The cows, labeled 1 through *n*, are arranged so that the *i*-th cow occupies the *i*-th stall from the left. However, Elsie, after realizing that she will forever live in the shadows beyond Bessie's limeligh... | The first line of the input contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=100<=000) — the number of cows and the length of Farmer John's nap, respectively. | Output a single integer, the maximum messiness that the Mischievous Mess Makers can achieve by performing no more than *k* swaps. | [
"5 2\n",
"1 10\n"
] | [
"10\n",
"0\n"
] | In the first sample, the Mischievous Mess Makers can swap the cows in the stalls 1 and 5 during the first minute, then the cows in stalls 2 and 4 during the second minute. This reverses the arrangement of cows, giving us a total messiness of 10.
In the second sample, there is only one cow, so the maximum possible mess... | [
{
"input": "5 2",
"output": "10"
},
{
"input": "1 10",
"output": "0"
},
{
"input": "100000 2",
"output": "399990"
},
{
"input": "1 1",
"output": "0"
},
{
"input": "8 3",
"output": "27"
},
{
"input": "7 1",
"output": "11"
},
{
"input": "1000... | 62 | 0 | 0 | 10,958 | |
888 | Maximum Subsequence | [
"bitmasks",
"divide and conquer",
"meet-in-the-middle"
] | null | null | You are given an array *a* consisting of *n* integers, and additionally an integer *m*. You have to choose some sequence of indices *b*1,<=*b*2,<=...,<=*b**k* (1<=≤<=*b*1<=<<=*b*2<=<<=...<=<<=*b**k*<=≤<=*n*) in such a way that the value of is maximized. Chosen sequence can be empty.
Print the maximum possibl... | The first line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=35, 1<=≤<=*m*<=≤<=109).
The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=109). | Print the maximum possible value of . | [
"4 4\n5 2 4 1\n",
"3 20\n199 41 299\n"
] | [
"3\n",
"19\n"
] | In the first example you can choose a sequence *b* = {1, 2}, so the sum <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/c856546022c2feee13d02a4ec9cd1d361ab3a756.png" style="max-width: 100.0%;max-height: 100.0%;"/> is equal to 7 (and that's 3 after taking it modulo 4).
In the second example... | [
{
"input": "4 4\n5 2 4 1",
"output": "3"
},
{
"input": "3 20\n199 41 299",
"output": "19"
},
{
"input": "5 10\n47 100 49 2 56",
"output": "9"
},
{
"input": "5 1000\n38361 75847 14913 11499 8297",
"output": "917"
},
{
"input": "10 10\n48 33 96 77 67 59 35 15 14 86"... | 46 | 5,529,600 | 0 | 10,959 | |
626 | Block Towers | [
"brute force",
"greedy",
"math",
"number theory"
] | null | null | Students in a class are making towers of blocks. Each student makes a (non-zero) tower by stacking pieces lengthwise on top of each other. *n* of the students use pieces made of two blocks and *m* of the students use pieces made of three blocks.
The students don’t want to use too many blocks, but they also want to be ... | The first line of the input contains two space-separated integers *n* and *m* (0<=≤<=*n*,<=*m*<=≤<=1<=000<=000, *n*<=+<=*m*<=><=0) — the number of students using two-block pieces and the number of students using three-block pieces, respectively. | Print a single integer, denoting the minimum possible height of the tallest tower. | [
"1 3\n",
"3 2\n",
"5 0\n"
] | [
"9\n",
"8\n",
"10\n"
] | In the first case, the student using two-block pieces can make a tower of height 4, and the students using three-block pieces can make towers of height 3, 6, and 9 blocks. The tallest tower has a height of 9 blocks.
In the second case, the students can make towers of heights 2, 4, and 8 with two-block pieces and tower... | [
{
"input": "1 3",
"output": "9"
},
{
"input": "3 2",
"output": "8"
},
{
"input": "5 0",
"output": "10"
},
{
"input": "4 2",
"output": "9"
},
{
"input": "0 1000000",
"output": "3000000"
},
{
"input": "1000000 1",
"output": "2000000"
},
{
"in... | 46 | 0 | 0 | 10,966 | |
687 | TOF | [
"dfs and similar",
"graphs"
] | null | null | Today Pari gave Arya a cool graph problem. Arya wrote a non-optimal solution for it, because he believes in his ability to optimize non-optimal solutions. In addition to being non-optimal, his code was buggy and he tried a lot to optimize it, so the code also became dirty! He keeps getting Time Limit Exceeds and he is ... | The first line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=5000) — the number of vertices and then number of directed edges in the input graph.
Each of the next *m* lines contains a pair of integers *u**i* and *v**i* (1<=<=≤<=<=*u**i*,<=<=*v**i*<=<=≤<=<=*n*), meaning there is a directed edge i... | Print a single integer — the minimum possible number of dfs calls that can be achieved with permuting the edges. | [
"3 3\n1 2\n2 3\n3 1\n",
"6 7\n1 2\n2 3\n3 1\n3 4\n4 5\n5 6\n6 4\n"
] | [
"2998\n",
"3001\n"
] | none | [] | 30 | 0 | 0 | 11,010 | |
401 | Roman and Numbers | [
"bitmasks",
"brute force",
"combinatorics",
"dp",
"number theory"
] | null | null | Roman is a young mathematician, very famous in Uzhland. Unfortunately, Sereja doesn't think so. To make Sereja change his mind, Roman is ready to solve any mathematical problem. After some thought, Sereja asked Roma to find, how many numbers are close to number *n*, modulo *m*.
Number *x* is considered close to number... | The first line contains two integers: *n* (1<=≤<=*n*<=<<=1018) and *m* (1<=≤<=*m*<=≤<=100). | In a single line print a single integer — the number of numbers close to number *n* modulo *m*. | [
"104 2\n",
"223 4\n",
"7067678 8\n"
] | [
"3\n",
"1\n",
"47\n"
] | In the first sample the required numbers are: 104, 140, 410.
In the second sample the required number is 232. | [
{
"input": "104 2",
"output": "3"
},
{
"input": "223 4",
"output": "1"
},
{
"input": "7067678 8",
"output": "47"
},
{
"input": "202 10",
"output": "1"
},
{
"input": "1306432 9",
"output": "0"
},
{
"input": "9653092 9",
"output": "0"
},
{
"i... | 4,000 | 243,916,800 | 0 | 11,048 | |
883 | Palindromic Cut | [
"brute force",
"implementation",
"strings"
] | null | null | Kolya has a string *s* of length *n* consisting of lowercase and uppercase Latin letters and digits.
He wants to rearrange the symbols in *s* and cut it into the minimum number of parts so that each part is a palindrome and all parts have the same lengths. A palindrome is a string which reads the same backward as forw... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=4·105) — the length of string *s*.
The second line contains a string *s* of length *n* consisting of lowercase and uppercase Latin letters and digits. | Print to the first line an integer *k* — minimum number of palindromes into which you can cut a given string.
Print to the second line *k* strings — the palindromes themselves. Separate them by a space. You are allowed to print palindromes in arbitrary order. All of them should have the same length. | [
"6\naabaac\n",
"8\n0rTrT022\n",
"2\naA\n"
] | [
"2\naba aca ",
"1\n02TrrT20 ",
"2\na A \n"
] | none | [
{
"input": "6\naabaac",
"output": "2\naba aca "
},
{
"input": "8\n0rTrT022",
"output": "1\n02TrrT20 "
},
{
"input": "2\naA",
"output": "2\na A "
},
{
"input": "1\ns",
"output": "1\ns "
},
{
"input": "10\n6IIC6CCIIC",
"output": "1\n6CCIIIICC6 "
},
{
"in... | 61 | 5,529,600 | 0 | 11,075 | |
412 | E-mail Addresses | [
"implementation"
] | null | null | One of the most important products of the R1 company is a popular @r1.com mail service. The R1 mailboxes receive and send millions of emails every day.
Today, the online news thundered with terrible information. The R1 database crashed and almost no data could be saved except for one big string. The developers assume ... | The first and the only line contains the sequence of characters *s*1*s*2... *s**n* (1<=≤<=*n*<=≤<=106) — the saved string. It is guaranteed that the given string contains only small English letters, digits and characters '.', '_', '@'. | Print in a single line the number of substrings that are valid e-mail addresses. | [
"[email protected]\n",
"[email protected]@[email protected]\n",
"[email protected]\n",
".asd123__..@\n"
] | [
"18\n",
"8\n",
"1\n",
"0\n"
] | In the first test case all the substrings that are correct e-mail addresses begin from one of the letters of the word agapov and end in one of the letters of the word com.
In the second test case note that the e-mail [[email protected]](/cdn-cgi/l/email-protection) is considered twice in the answer. Note that in this ... | [
{
"input": "gerald.agapov1991@gmail.com",
"output": "18"
},
{
"input": "x@x.x@x.x_e_@r1.com",
"output": "8"
},
{
"input": "a___@1.r",
"output": "1"
},
{
"input": ".asd123__..@",
"output": "0"
},
{
"input": "@",
"output": "0"
},
{
"input": ".",
"out... | 1,000 | 18,022,400 | 0 | 11,099 | |
474 | Ant colony | [
"data structures",
"math",
"number theory"
] | null | null | Mole is hungry again. He found one ant colony, consisting of *n* ants, ordered in a row. Each ant *i* (1<=≤<=*i*<=≤<=*n*) has a strength *s**i*.
In order to make his dinner more interesting, Mole organizes a version of «Hunger Games» for the ants. He chooses two numbers *l* and *r* (1<=≤<=*l*<=≤<=*r*<=≤<=*n*) and each... | The first line contains one integer *n* (1<=≤<=*n*<=≤<=105), the size of the ant colony.
The second line contains *n* integers *s*1,<=*s*2,<=...,<=*s**n* (1<=≤<=*s**i*<=≤<=109), the strengths of the ants.
The third line contains one integer *t* (1<=≤<=*t*<=≤<=105), the number of test cases.
Each of the next *t* l... | Print to the standard output *t* lines. The *i*-th line contains number of ants that Mole eats from the segment [*l**i*,<=*r**i*]. | [
"5\n1 3 2 4 2\n4\n1 5\n2 5\n3 5\n4 5\n"
] | [
"4\n4\n1\n1\n"
] | In the first test battle points for each ant are *v* = [4, 0, 2, 0, 2], so ant number 1 is freed. Mole eats the ants 2, 3, 4, 5.
In the second test case battle points are *v* = [0, 2, 0, 2], so no ant is freed and all of them are eaten by Mole.
In the third test case battle points are *v* = [2, 0, 2], so ants number ... | [
{
"input": "5\n1 3 2 4 2\n4\n1 5\n2 5\n3 5\n4 5",
"output": "4\n4\n1\n1"
}
] | 514 | 11,264,000 | 0 | 11,101 | |
109 | Lucky Sorting | [
"constructive algorithms",
"sortings"
] | D. Lucky Sorting | 3 | 256 | 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 got an array consisting of *n* numbers, it is the gift for his birthday. Now he wants to sort ... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=105) — the number of elements in the array. The second line contains *n* positive integers, not exceeding 109 — the array that needs to be sorted in the non-decreasing order. | On the first line print number *k* (0<=≤<=*k*<=≤<=2*n*) — the number of the swaps in the sorting. On the following *k* lines print one pair of distinct numbers (a pair per line) — the indexes of elements to swap. The numbers in the array are numbered starting from 1. If it is impossible to sort the given sequence, prin... | [
"2\n4 7\n",
"3\n4 2 1\n",
"7\n77 66 55 44 33 22 11\n"
] | [
"0\n",
"1\n1 3\n",
"7\n1 7\n7 2\n2 6\n6 7\n3 4\n5 3\n4 5\n"
] | none | [
{
"input": "2\n4 7",
"output": "0"
},
{
"input": "3\n4 2 1",
"output": "1\n1 3"
},
{
"input": "7\n77 66 55 44 33 22 11",
"output": "9\n4 7\n1 7\n1 6\n2 6\n2 5\n3 5\n2 3\n1 2\n1 4"
},
{
"input": "7\n1 2 3 4 5 6 7",
"output": "0"
},
{
"input": "4\n47 1 7 2",
"ou... | 280 | 0 | 0 | 11,126 |
261 | Maxim and Discounts | [
"greedy",
"sortings"
] | null | null | Maxim always goes to the supermarket on Sundays. Today the supermarket has a special offer of discount systems.
There are *m* types of discounts. We assume that the discounts are indexed from 1 to *m*. To use the discount number *i*, the customer takes a special basket, where he puts exactly *q**i* items he buys. Unde... | The first line contains integer *m* (1<=≤<=*m*<=≤<=105) — the number of discount types. The second line contains *m* integers: *q*1,<=*q*2,<=...,<=*q**m* (1<=≤<=*q**i*<=≤<=105).
The third line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of items Maxim needs. The fourth line contains *n* integers: *a*1,<=*a*... | In a single line print a single integer — the answer to the problem. | [
"1\n2\n4\n50 50 100 100\n",
"2\n2 3\n5\n50 50 50 50 50\n",
"1\n1\n7\n1 1 1 1 1 1 1\n"
] | [
"200\n",
"150\n",
"3\n"
] | In the first sample Maxim needs to buy two items that cost 100 and get a discount for two free items that cost 50. In that case, Maxim is going to pay 200.
In the second sample the best strategy for Maxim is to buy 3 items and get 2 items for free using the discount. In that case, Maxim is going to pay 150. | [
{
"input": "1\n2\n4\n50 50 100 100",
"output": "200"
},
{
"input": "2\n2 3\n5\n50 50 50 50 50",
"output": "150"
},
{
"input": "1\n1\n7\n1 1 1 1 1 1 1",
"output": "3"
},
{
"input": "60\n7 4 20 15 17 6 2 2 3 18 13 14 16 11 13 12 6 10 14 1 16 6 4 9 10 8 10 15 16 13 13 9 16 11 5 ... | 404 | 9,420,800 | 3 | 11,136 | |
40 | Repaintings | [
"math"
] | B. Repaintings | 2 | 256 | A chessboard *n*<=×<=*m* in size is given. During the zero minute we repaint all the black squares to the 0 color. During the *i*-th minute we repaint to the *i* color the initially black squares that have exactly four corner-adjacent squares painted *i*<=-<=1 (all such squares are repainted simultaneously). This proce... | The first line contains integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=5000). The second line contains integer *x* (1<=≤<=*x*<=≤<=109). | Print how many squares will be painted exactly *x* times. | [
"3 3\n1\n",
"3 3\n2\n",
"1 1\n1\n"
] | [
"4\n",
"1\n",
"1\n"
] | none | [
{
"input": "3 3\n1",
"output": "4"
},
{
"input": "3 3\n2",
"output": "1"
},
{
"input": "1 1\n1",
"output": "1"
},
{
"input": "8 8\n8",
"output": "0"
},
{
"input": "9 10\n1",
"output": "17"
},
{
"input": "9 9\n3",
"output": "8"
},
{
"input":... | 0 | 0 | -1 | 11,165 |
0 | none | [
"none"
] | null | null | You are given a sequence *a*1,<=*a*2,<=...,<=*a**n* consisting of different integers. It is required to split this sequence into the maximum number of subsequences such that after sorting integers in each of them in increasing order, the total sequence also will be sorted in increasing order.
Sorting integers in a sub... | The first line of input data contains integer *n* (1<=≤<=*n*<=≤<=105) — the length of the sequence.
The second line of input data contains *n* different integers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=109<=≤<=*a**i*<=≤<=109) — the elements of the sequence. It is guaranteed that all elements of the sequence are distinct. | In the first line print the maximum number of subsequences *k*, which the original sequence can be split into while fulfilling the requirements.
In the next *k* lines print the description of subsequences in the following format: the number of elements in subsequence *c**i* (0<=<<=*c**i*<=≤<=*n*), then *c**i* integ... | [
"6\n3 2 1 6 5 4\n",
"6\n83 -75 -49 11 37 62\n"
] | [
"4\n2 1 3\n1 2\n2 4 6\n1 5\n",
"1\n6 1 2 3 4 5 6\n"
] | In the first sample output:
After sorting the first subsequence we will get sequence 1 2 3 6 5 4.
Sorting the second subsequence changes nothing.
After sorting the third subsequence we will get sequence 1 2 3 4 5 6.
Sorting the last subsequence changes nothing. | [
{
"input": "6\n3 2 1 6 5 4",
"output": "4\n2 1 3\n1 2\n2 4 6\n1 5"
},
{
"input": "6\n83 -75 -49 11 37 62",
"output": "1\n6 1 2 3 4 5 6"
},
{
"input": "1\n1",
"output": "1\n1 1"
},
{
"input": "2\n1 2",
"output": "2\n1 1\n1 2"
},
{
"input": "2\n2 1",
"output": "... | 436 | 21,606,400 | 3 | 11,177 | |
456 | Fedya and Maths | [
"math",
"number theory"
] | null | null | Fedya studies in a gymnasium. Fedya's maths hometask is to calculate the following expression:
for given value of *n*. Fedya managed to complete the task. Can you? Note that given number *n* can be extremely large (e.g. it can exceed any integer type of your programming language). | The single line contains a single integer *n* (0<=≤<=*n*<=≤<=10105). The number doesn't contain any leading zeroes. | Print the value of the expression without leading zeros. | [
"4\n",
"124356983594583453458888889\n"
] | [
"4\n",
"0\n"
] | Operation *x* *mod* *y* means taking remainder after division *x* by *y*.
Note to the first sample:
<img align="middle" class="tex-formula" src="https://espresso.codeforces.com/825f244180bb10323db01645118c3cfdb312fa89.png" style="max-width: 100.0%;max-height: 100.0%;"/> | [
{
"input": "4",
"output": "4"
},
{
"input": "124356983594583453458888889",
"output": "0"
},
{
"input": "2",
"output": "0"
},
{
"input": "7854",
"output": "0"
},
{
"input": "584660",
"output": "4"
},
{
"input": "464",
"output": "4"
},
{
"inp... | 30 | 0 | -1 | 11,179 | |
808 | Anthem of Berland | [
"dp",
"strings"
] | null | null | Berland has a long and glorious history. To increase awareness about it among younger citizens, King of Berland decided to compose an anthem.
Though there are lots and lots of victories in history of Berland, there is the one that stand out the most. King wants to mention it in the anthem as many times as possible.
H... | The first line contains string of small Latin letters and question marks *s* (1<=≤<=|*s*|<=≤<=105).
The second line contains string of small Latin letters *t* (1<=≤<=|*t*|<=≤<=105).
Product of lengths of strings |*s*|·|*t*| won't exceed 107. | Output the maximum number of occurrences of string *t* you can achieve by replacing all the question marks in string *s* with small Latin letters. | [
"winlose???winl???w??\nwin\n",
"glo?yto?e??an?\nor\n",
"??c?????\nabcab\n"
] | [
"5\n",
"3\n",
"2\n"
] | In the first example the resulting string *s* is "winlosewinwinlwinwin"
In the second example the resulting string *s* is "glorytoreorand". The last letter of the string can be arbitrary.
In the third example occurrences of string *t* are overlapping. String *s* with maximal number of occurrences of *t* is "abcabcab"... | [
{
"input": "winlose???winl???w??\nwin",
"output": "5"
},
{
"input": "glo?yto?e??an?\nor",
"output": "3"
},
{
"input": "??c?????\nabcab",
"output": "2"
},
{
"input": "ddddd\nd",
"output": "5"
},
{
"input": "ww?ww\nw",
"output": "5"
},
{
"input": "?????\... | 296 | 7,782,400 | 0 | 11,210 | |
635 | Orchestra | [
"brute force",
"implementation"
] | null | null | Paul is at the orchestra. The string section is arranged in an *r*<=×<=*c* rectangular grid and is filled with violinists with the exception of *n* violists. Paul really likes violas, so he would like to take a picture including at least *k* of them. Paul can take a picture of any axis-parallel rectangle in the orchest... | The first line of input contains four space-separated integers *r*, *c*, *n*, *k* (1<=≤<=*r*,<=*c*,<=*n*<=≤<=10, 1<=≤<=*k*<=≤<=*n*) — the number of rows and columns of the string section, the total number of violas, and the minimum number of violas Paul would like in his photograph, respectively.
The next *n* lines ea... | Print a single integer — the number of photographs Paul can take which include at least *k* violas. | [
"2 2 1 1\n1 2\n",
"3 2 3 3\n1 1\n3 1\n2 2\n",
"3 2 3 2\n1 1\n3 1\n2 2\n"
] | [
"4\n",
"1\n",
"4\n"
] | We will use '*' to denote violinists and '#' to denote violists.
In the first sample, the orchestra looks as follows
In the second sample, the orchestra looks as follows
In the third sample, the orchestra looks the same as in the second sample. | [
{
"input": "2 2 1 1\n1 2",
"output": "4"
},
{
"input": "3 2 3 3\n1 1\n3 1\n2 2",
"output": "1"
},
{
"input": "3 2 3 2\n1 1\n3 1\n2 2",
"output": "4"
},
{
"input": "1 1 1 1\n1 1",
"output": "1"
},
{
"input": "10 10 10 10\n6 1\n3 8\n10 6\n10 3\n10 4\n8 9\n2 3\n5 7\n... | 62 | 0 | 3 | 11,219 | |
0 | none | [
"none"
] | null | null | Two participants are each given a pair of distinct numbers from 1 to 9 such that there's exactly one number that is present in both pairs. They want to figure out the number that matches by using a communication channel you have access to without revealing it to you.
Both participants communicated to each other a set ... | The first line contains two integers $n$ and $m$ ($1 \le n, m \le 12$) — the number of pairs the first participant communicated to the second and vice versa.
The second line contains $n$ pairs of integers, each between $1$ and $9$, — pairs of numbers communicated from first participant to the second.
The third line c... | If you can deduce the shared number with certainty, print that number.
If you can with certainty deduce that both participants know the shared number, but you do not know it, print $0$.
Otherwise print $-1$. | [
"2 2\n1 2 3 4\n1 5 3 4\n",
"2 2\n1 2 3 4\n1 5 6 4\n",
"2 3\n1 2 4 5\n1 2 1 3 2 3\n"
] | [
"1\n",
"0\n",
"-1\n"
] | In the first example the first participant communicated pairs $(1,2)$ and $(3,4)$, and the second communicated $(1,5)$, $(3,4)$. Since we know that the actual pairs they received share exactly one number, it can't be that they both have $(3,4)$. Thus, the first participant has $(1,2)$ and the second has $(1,5)$, and at... | [
{
"input": "2 2\n1 2 3 4\n1 5 3 4",
"output": "1"
},
{
"input": "2 2\n1 2 3 4\n1 5 6 4",
"output": "0"
},
{
"input": "2 3\n1 2 4 5\n1 2 1 3 2 3",
"output": "-1"
},
{
"input": "2 1\n1 2 1 3\n1 2",
"output": "1"
},
{
"input": "4 4\n1 2 3 4 5 6 7 8\n2 3 4 5 6 7 8 1",... | 93 | 102,400 | 3 | 11,274 | |
239 | Easy Tape Programming | [
"brute force",
"implementation"
] | null | null | There is a programming language in which every program is a non-empty sequence of "<" and ">" signs and digits. Let's explain how the interpreter of this programming language works. A program is interpreted using movement of instruction pointer (IP) which consists of two parts.
- Current character pointer (CP);... | The first line of input contains two integers *n* and *q* (1<=≤<=*n*,<=*q*<=≤<=100) — represents the length of the sequence *s* and the number of queries.
The second line contains *s*, a sequence of "<", ">" and digits (0..9) written from left to right. Note, that the characters of *s* are not separated with sp... | For each query print 10 space separated integers: *x*0,<=*x*1,<=...,<=*x*9 where *x**i* equals the number of times the interpreter prints *i* while running the corresponding program. Print answers to the queries in the order they are given in input. | [
"7 4\n1>3>22<\n1 3\n4 7\n7 7\n1 7\n"
] | [
"0 1 0 1 0 0 0 0 0 0 \n2 2 2 0 0 0 0 0 0 0 \n0 0 0 0 0 0 0 0 0 0 \n2 3 2 1 0 0 0 0 0 0 \n"
] | none | [
{
"input": "7 4\n1>3>22<\n1 3\n4 7\n7 7\n1 7",
"output": "0 1 0 1 0 0 0 0 0 0 \n2 2 2 0 0 0 0 0 0 0 \n0 0 0 0 0 0 0 0 0 0 \n2 3 2 1 0 0 0 0 0 0 "
},
{
"input": "5 2\n>>>>>\n1 5\n1 2",
"output": "0 0 0 0 0 0 0 0 0 0 \n0 0 0 0 0 0 0 0 0 0 "
},
{
"input": "1 3\n9\n1 1\n1 1\n1 1",
"outpu... | 186 | 307,200 | 0 | 11,285 | |
769 | k-Interesting Pairs Of Integers | [
"*special",
"bitmasks",
"brute force",
"meet-in-the-middle"
] | null | null | Vasya has the sequence consisting of *n* integers. Vasya consider the pair of integers *x* and *y* k-interesting, if their binary representation differs from each other exactly in *k* bits. For example, if *k*<==<=2, the pair of integers *x*<==<=5 and *y*<==<=3 is k-interesting, because their binary representation *x*=... | The first line contains two integers *n* and *k* (2<=≤<=*n*<=≤<=105, 0<=≤<=*k*<=≤<=14) — the number of integers in Vasya's sequence and the number of bits in which integers in k-interesting pair should differ.
The second line contains the sequence *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=104), which Vasya has. | Print the number of pairs (*i*, *j*) so that *i*<=<<=*j* and the pair of integers *a**i* and *a**j* is k-interesting. | [
"4 1\n0 3 2 1\n",
"6 0\n200 100 100 100 200 200\n"
] | [
"4\n",
"6\n"
] | In the first test there are 4 k-interesting pairs:
- (1, 3), - (1, 4), - (2, 3), - (2, 4).
In the second test *k* = 0. Consequently, integers in any k-interesting pair should be equal to themselves. Thus, for the second test there are 6 k-interesting pairs:
- (1, 5), - (1, 6), - (2, 3), - (2, 4), - (3, 4), ... | [
{
"input": "4 1\n0 3 2 1",
"output": "4"
},
{
"input": "6 0\n200 100 100 100 200 200",
"output": "6"
},
{
"input": "2 0\n1 1",
"output": "1"
},
{
"input": "2 0\n0 0",
"output": "1"
},
{
"input": "2 0\n10000 10000",
"output": "1"
},
{
"input": "2 0\n0 1... | 2,000 | 9,216,000 | 0 | 11,306 | |
196 | Infinite Maze | [
"dfs and similar",
"graphs"
] | null | null | We've got a rectangular *n*<=×<=*m*-cell maze. Each cell is either passable, or is a wall (impassable). A little boy found the maze and cyclically tiled a plane with it so that the plane became an infinite maze. Now on this plane cell (*x*,<=*y*) is a wall if and only if cell is a wall.
In this problem is a remainde... | The first line contains two space-separated integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=1500) — the height and the width of the maze that the boy used to cyclically tile the plane.
Each of the next *n* lines contains *m* characters — the description of the labyrinth. Each character is either a "#", that marks a wall, a ... | Print "Yes" (without the quotes), if the little boy can walk infinitely far from the starting point. Otherwise, print "No" (without the quotes). | [
"5 4\n##.#\n##S#\n#..#\n#.##\n#..#\n",
"5 4\n##.#\n##S#\n#..#\n..#.\n#.##\n"
] | [
"Yes\n",
"No\n"
] | In the first sample the little boy can go up for infinitely long as there is a "clear path" that goes vertically. He just needs to repeat the following steps infinitely: up, up, left, up, up, right, up.
In the second sample the vertical path is blocked. The path to the left doesn't work, too — the next "copy" of the m... | [] | 2,000 | 123,392,000 | 0 | 11,311 | |
883 | Lost in Transliteration | [
"implementation"
] | null | null | There are some ambiguities when one writes Berland names with the letters of the Latin alphabet.
For example, the Berland sound u can be written in the Latin alphabet as "u", and can be written as "oo". For this reason, two words "ulyana" and "oolyana" denote the same name.
The second ambiguity is about the Berland s... | The first line contains integer number *n* (2<=≤<=*n*<=≤<=400) — number of the words in the list.
The following *n* lines contain words, one word per line. Each word consists of only lowercase Latin letters. The length of each word is between 1 and 20 letters inclusive. | Print the minimal number of groups where the words in each group denote the same name. | [
"10\nmihail\noolyana\nkooooper\nhoon\nulyana\nkoouper\nmikhail\nkhun\nkuooper\nkkkhoon\n",
"9\nhariton\nhkariton\nbuoi\nkkkhariton\nboooi\nbui\nkhariton\nboui\nboi\n",
"2\nalex\nalex\n"
] | [
"4\n",
"5\n",
"1\n"
] | There are four groups of words in the first example. Words in each group denote same name:
1. "mihail", "mikhail" 1. "oolyana", "ulyana" 1. "kooooper", "koouper" 1. "hoon", "khun", "kkkhoon"
There are five groups of words in the second example. Words in each group denote same name:
1. "hariton", "kkkhariton", "... | [
{
"input": "10\nmihail\noolyana\nkooooper\nhoon\nulyana\nkoouper\nmikhail\nkhun\nkuooper\nkkkhoon",
"output": "4"
},
{
"input": "9\nhariton\nhkariton\nbuoi\nkkkhariton\nboooi\nbui\nkhariton\nboui\nboi",
"output": "5"
},
{
"input": "2\nalex\nalex",
"output": "1"
},
{
"input": ... | 62 | 5,529,600 | 3 | 11,325 | |
35 | Parade | [
"data structures",
"sortings"
] | E. Parade | 2 | 64 | No Great Victory anniversary in Berland has ever passed without the war parade. This year is not an exception. That’s why the preparations are on in full strength. Tanks are building a line, artillery mounts are ready to fire, soldiers are marching on the main square... And the air forces general Mr. Generalov is in tr... | The first input line contains integer *n* (1<=≤<=*n*<=≤<=100000). Then follow *n* lines, each containing three integers *h**i*, *l**i*, *r**i* (1<=≤<=*h**i*<=≤<=109,<=<=-<=109<=≤<=*l**i*<=<<=*r**i*<=≤<=109). | In the first line output integer *m* — amount of vertices of the enveloping polyline. The next *m* lines should contain 2 integers each — the position and the height of the polyline’s vertex. Output the coordinates of each vertex in the order of traversing the polyline from west to east. Remember that the first and the... | [
"2\n3 0 2\n4 1 3\n",
"5\n3 -3 0\n2 -1 1\n4 2 4\n2 3 7\n3 6 8\n"
] | [
"6\n0 0\n0 3\n1 3\n1 4\n3 4\n3 0\n",
"14\n-3 0\n-3 3\n0 3\n0 2\n1 2\n1 0\n2 0\n2 4\n4 4\n4 2\n6 2\n6 3\n8 3\n8 0\n"
] | none | [
{
"input": "2\n3 0 2\n4 1 3",
"output": "6\n0 0\n0 3\n1 3\n1 4\n3 4\n3 0"
},
{
"input": "5\n3 -3 0\n2 -1 1\n4 2 4\n2 3 7\n3 6 8",
"output": "14\n-3 0\n-3 3\n0 3\n0 2\n1 2\n1 0\n2 0\n2 4\n4 4\n4 2\n6 2\n6 3\n8 3\n8 0"
},
{
"input": "7\n5 -5 -4\n3 -3 0\n2 -1 1\n1 0 1\n4 2 4\n2 3 7\n3 6 8",... | 46 | 0 | 0 | 11,330 |
166 | Median | [
"greedy",
"math",
"sortings"
] | null | null | A median in an array with the length of *n* is an element which occupies position number after we sort the elements in the non-decreasing order (the array elements are numbered starting with 1). A median of an array (2,<=6,<=1,<=2,<=3) is the number 2, and a median of array (0,<=96,<=17,<=23) — the number 17.
We defi... | The first input line contains two space-separated integers *n* and *x* (1<=≤<=*n*<=≤<=500, 1<=≤<=*x*<=≤<=105) — the initial array's length and the required median's value. The second line contains *n* space-separated numbers — the initial array. The elements of the array are integers from 1 to 105. The array elements a... | Print the only integer — the minimum number of elements Petya needs to add to the array so that its median equals *x*. | [
"3 10\n10 20 30\n",
"3 4\n1 2 3\n"
] | [
"1\n",
"4\n"
] | In the first sample we can add number 9 to array (10, 20, 30). The resulting array (9, 10, 20, 30) will have a median in position <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/7dd92241318a531b780c7783dfa446a3e413115e.png" style="max-width: 100.0%;max-height: 100.0%;"/>, that is, 10.
In t... | [
{
"input": "3 10\n10 20 30",
"output": "1"
},
{
"input": "3 4\n1 2 3",
"output": "4"
},
{
"input": "2 2\n3 2",
"output": "0"
},
{
"input": "5 1\n1 1 2 1 2",
"output": "0"
},
{
"input": "5 4\n5 5 4 3 5",
"output": "1"
},
{
"input": "10 2\n2 2 1 3 2 1 2 ... | 156 | 6,758,400 | 3 | 11,333 | |
519 | A and B and Interesting Substrings | [
"data structures",
"dp",
"two pointers"
] | null | null | A and B are preparing themselves for programming contests.
After several years of doing sports programming and solving many problems that require calculating all sorts of abstract objects, A and B also developed rather peculiar tastes.
A likes lowercase letters of the Latin alphabet. He has assigned to each letter a ... | The first line contains 26 integers *x**a*,<=*x**b*,<=...,<=*x**z* (<=-<=105<=≤<=*x**i*<=≤<=105) — the value assigned to letters *a*,<=*b*,<=*c*,<=...,<=*z* respectively.
The second line contains string *s* of length between 1 and 105 characters, consisting of Lating lowercase letters— the string for which you need to... | Print the answer to the problem. | [
"1 1 -1 1 1 1 1 1 1 1 1 1 1 1 1 7 1 1 1 8 1 1 1 1 1 1\nxabcab\n",
"1 1 -1 1 1 1 1 1 1 1 1 1 1 1 1 7 1 1 1 8 1 1 1 1 1 1\naaa\n"
] | [
"2\n",
"2\n"
] | In the first sample test strings satisfying the condition above are *abca* and *bcab*.
In the second sample test strings satisfying the condition above are two occurences of *aa*. | [
{
"input": "1 1 -1 1 1 1 1 1 1 1 1 1 1 1 1 7 1 1 1 8 1 1 1 1 1 1\nxabcab",
"output": "2"
},
{
"input": "1 1 -1 1 1 1 1 1 1 1 1 1 1 1 1 7 1 1 1 8 1 1 1 1 1 1\naaa",
"output": "2"
},
{
"input": "1 1 -1 1 1 1 1 1 1 1 1 1 1 1 1 7 1 1 1 8 1 1 1 1 1 1\naabbccdd",
"output": "4"
},
{
... | 77 | 0 | 0 | 11,353 | |
889 | Mod Mod Mod | [
"binary search",
"dp",
"math"
] | null | null | You are given a sequence of integers *a*1,<=*a*2,<=...,<=*a**n*. Let , and for 1<=≤<=*i*<=<<=*n*. Here, denotes the modulus operation. Find the maximum value of *f*(*x*,<=1) over all nonnegative integers *x*. | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=200000) — the length of the sequence.
The second lines contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1013) — the elements of the sequence. | Output a single integer — the maximum value of *f*(*x*,<=1) over all nonnegative integers *x*. | [
"2\n10 5\n",
"5\n5 4 3 2 1\n",
"4\n5 10 5 10\n"
] | [
"13\n",
"6\n",
"16\n"
] | In the first example you can choose, for example, *x* = 19.
In the second example you can choose, for example, *x* = 3 or *x* = 2. | [] | 2,000 | 0 | 0 | 11,426 | |
255 | Mr. Bender and Square | [
"binary search",
"implementation",
"math"
] | null | null | Mr. Bender has a digital table of size *n*<=×<=*n*, each cell can be switched on or off. He wants the field to have at least *c* switched on squares. When this condition is fulfilled, Mr Bender will be happy.
We'll consider the table rows numbered from top to bottom from 1 to *n*, and the columns — numbered from left ... | The first line contains four space-separated integers *n*,<=*x*,<=*y*,<=*c* (1<=≤<=*n*,<=*c*<=≤<=109; 1<=≤<=*x*,<=*y*<=≤<=*n*; *c*<=≤<=*n*2). | In a single line print a single integer — the answer to the problem. | [
"6 4 3 1\n",
"9 3 8 10\n"
] | [
"0\n",
"2\n"
] | Initially the first test has one painted cell, so the answer is 0. In the second test all events will go as is shown on the figure. <img class="tex-graphics" src="https://espresso.codeforces.com/51bd695513bdc59c6ded01f0d34daa5361285209.png" style="max-width: 100.0%;max-height: 100.0%;"/>. | [
{
"input": "6 4 3 1",
"output": "0"
},
{
"input": "9 3 8 10",
"output": "2"
},
{
"input": "9 4 3 10",
"output": "2"
},
{
"input": "9 8 2 10",
"output": "2"
},
{
"input": "1 1 1 1",
"output": "0"
},
{
"input": "10 7 2 7",
"output": "2"
},
{
... | 60 | 0 | 0 | 11,443 | |
309 | Memory for Arrays | [
"binary search",
"bitmasks",
"greedy"
] | null | null | You get to work and turn on the computer. You start coding and give little thought to the RAM role in the whole process. In this problem your task is to solve one of the problems you encounter in your computer routine.
We'll consider the RAM as a sequence of cells that can contain data. Some cells already contain some... | The first line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=106). The next line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109). The next line contains *m* integers *b*1,<=*b*2,<=...,<=*b**m* (1<=≤<=2*b**i*<=≤<=109). | Print a single integer — the answer to the problem. | [
"5 3\n8 4 3 2 2\n3 2 2\n",
"10 6\n1 1 1 1 1 1 1 1 1 1\n0 0 0 0 0 0\n"
] | [
"2\n",
"6\n"
] | In the first example you are given memory clusters with sizes 8, 4, 3, 2, 2 and arrays with sizes 8, 4, 4. There are few ways to obtain an answer equals 2: you can locate array with size 8 to the cluster with size 8, and one of the arrays with size 4 to the cluster with size 4. Another way is to locate two arrays with ... | [
{
"input": "5 3\n8 4 3 2 2\n3 2 2",
"output": "2"
},
{
"input": "10 6\n1 1 1 1 1 1 1 1 1 1\n0 0 0 0 0 0",
"output": "6"
},
{
"input": "5 10\n4 4 3 3 3\n0 0 0 0 0 2 0 2 0 0",
"output": "10"
},
{
"input": "5 10\n3 4 5 4 3\n1 2 1 0 1 2 1 0 2 0",
"output": "9"
},
{
"i... | 92 | 0 | 0 | 11,445 | |
463 | Caisa and Tree | [
"brute force",
"dfs and similar",
"math",
"number theory",
"trees"
] | null | null | Caisa is now at home and his son has a simple task for him.
Given a rooted tree with *n* vertices, numbered from 1 to *n* (vertex 1 is the root). Each vertex of the tree has a value. You should answer *q* queries. Each query is one of the following:
- Format of the query is "1 *v*". Let's write out the sequence of v... | The first line contains two space-separated integers *n*, *q* (1<=≤<=*n*,<=*q*<=≤<=105).
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=2·106), where *a**i* represent the value of node *i*.
Each of the next *n*<=-<=1 lines contains two integers *x**i* and *y**i* (1<=≤<=*x**i*,<=*y... | For each query of the first type output the result of the query. | [
"4 6\n10 8 4 3\n1 2\n2 3\n3 4\n1 1\n1 2\n1 3\n1 4\n2 1 9\n1 4\n"
] | [
"-1\n1\n2\n-1\n1\n"
] | *gcd*(*x*, *y*) is greatest common divisor of two integers *x* and *y*. | [
{
"input": "4 6\n10 8 4 3\n1 2\n2 3\n3 4\n1 1\n1 2\n1 3\n1 4\n2 1 9\n1 4",
"output": "-1\n1\n2\n-1\n1"
},
{
"input": "4 46\n1826622 227609 1815373 691816\n4 1\n3 1\n1 2\n1 2\n1 3\n2 3 1226461\n1 2\n2 2 329857\n1 4\n1 2\n1 2\n1 3\n1 3\n1 1\n1 4\n1 1\n1 3\n1 3\n1 2\n1 4\n1 4\n1 3\n1 2\n1 2\n2 3 106992... | 1,777 | 123,289,600 | 0 | 11,451 | |
250 | Paper Work | [
"greedy"
] | null | null | Polycarpus has been working in the analytic department of the "F.R.A.U.D." company for as much as *n* days. Right now his task is to make a series of reports about the company's performance for the last *n* days. We know that the main information in a day report is value *a**i*, the company's profit on the *i*-th day. ... | The first line contains integer *n* (1<=≤<=*n*<=≤<=100), *n* is the number of days. The second line contains a sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (|*a**i*|<=≤<=100), where *a**i* means the company profit on the *i*-th day. It is possible that the company has no days with the negative *a**i*. | Print an integer *k* — the required minimum number of folders. In the second line print a sequence of integers *b*1, *b*2, ..., *b**k*, where *b**j* is the number of day reports in the *j*-th folder.
If there are multiple ways to sort the reports into *k* days, print any of them. | [
"11\n1 2 3 -4 -5 -6 5 -5 -6 -7 6\n",
"5\n0 -1 100 -1 0\n"
] | [
"3\n5 3 3 ",
"1\n5 "
] | Here goes a way to sort the reports from the first sample into three folders:
In the second sample you can put all five reports in one folder. | [
{
"input": "11\n1 2 3 -4 -5 -6 5 -5 -6 -7 6",
"output": "3\n5 3 3 "
},
{
"input": "5\n0 -1 100 -1 0",
"output": "1\n5 "
},
{
"input": "1\n0",
"output": "1\n1 "
},
{
"input": "1\n-1",
"output": "1\n1 "
},
{
"input": "2\n0 0",
"output": "1\n2 "
},
{
"inp... | 122 | 6,963,200 | 0 | 11,454 | |
489 | Special Matrices | [
"combinatorics",
"dp"
] | null | null | An *n*<=×<=*n* square matrix is special, if:
- it is binary, that is, each cell contains either a 0, or a 1; - the number of ones in each row and column equals 2.
You are given *n* and the first *m* rows of the matrix. Print the number of special *n*<=×<=*n* matrices, such that the first *m* rows coincide with the ... | The first line of the input contains three integers *n*, *m*, *mod* (2<=≤<=*n*<=≤<=500, 0<=≤<=*m*<=≤<=*n*, 2<=≤<=*mod*<=≤<=109). Then *m* lines follow, each of them contains *n* characters — the first rows of the required special matrices. Each of these lines contains exactly two characters '1', the rest characters are... | Print the remainder after dividing the required value by number *mod*. | [
"3 1 1000\n011\n",
"4 4 100500\n0110\n1010\n0101\n1001\n"
] | [
"2\n",
"1\n"
] | For the first test the required matrices are:
In the second test the required matrix is already fully given, so the answer is 1. | [
{
"input": "3 1 1000\n011",
"output": "2"
},
{
"input": "4 4 100500\n0110\n1010\n0101\n1001",
"output": "1"
},
{
"input": "2 0 1000",
"output": "1"
},
{
"input": "2 1 1000\n11",
"output": "1"
},
{
"input": "5 0 13",
"output": "12"
},
{
"input": "5 3 19... | 171 | 18,227,200 | 3 | 11,468 | |
176 | Word Cut | [
"dp"
] | null | null | Let's consider one interesting word game. In this game you should transform one word into another through special operations.
Let's say we have word *w*, let's split this word into two non-empty parts *x* and *y* so, that *w*<==<=*xy*. A split operation is transforming word *w*<==<=*xy* into word *u*<==<=*yx*. For ex... | The first line contains a non-empty word *start*, the second line contains a non-empty word *end*. The words consist of lowercase Latin letters. The number of letters in word *start* equals the number of letters in word *end* and is at least 2 and doesn't exceed 1000 letters.
The third line contains integer *k* (0<=≤<... | Print a single number — the answer to the problem. As this number can be rather large, print it modulo 1000000007 (109<=+<=7). | [
"ab\nab\n2\n",
"ababab\nababab\n1\n",
"ab\nba\n2\n"
] | [
"1\n",
"2\n",
"0\n"
] | The sought way in the first sample is:
ab → a|b → ba → b|a → ab
In the second sample the two sought ways are:
- ababab → abab|ab → ababab - ababab → ab|abab → ababab | [
{
"input": "ab\nab\n2",
"output": "1"
},
{
"input": "ababab\nababab\n1",
"output": "2"
},
{
"input": "ab\nba\n2",
"output": "0"
},
{
"input": "aaa\naaa\n0",
"output": "1"
},
{
"input": "hi\nhi\n1",
"output": "0"
},
{
"input": "abcd\ncbad\n5",
"outp... | 186 | 2,252,800 | 3 | 11,519 | |
52 | Circular RMQ | [
"data structures"
] | C. Circular RMQ | 1 | 256 | You are given circular array *a*0,<=*a*1,<=...,<=*a**n*<=-<=1. There are two types of operations with it:
- *inc*(*lf*,<=*rg*,<=*v*) — this operation increases each element on the segment [*lf*,<=*rg*] (inclusively) by *v*; - *rmq*(*lf*,<=*rg*) — this operation returns minimal value on the segment [*lf*,<=*rg*] (in... | The first line contains integer *n* (1<=≤<=*n*<=≤<=200000). The next line contains initial state of the array: *a*0,<=*a*1,<=...,<=*a**n*<=-<=1 (<=-<=106<=≤<=*a**i*<=≤<=106), *a**i* are integer. The third line contains integer *m* (0<=≤<=*m*<=≤<=200000), *m* — the number of operartons. Next *m* lines contain one operat... | For each *rmq* operation write result for it. Please, do not use %lld specificator to read or write 64-bit integers in C++. It is preffered to use cout (also you may use %I64d). | [
"4\n1 2 3 4\n4\n3 0\n3 0 -1\n0 1\n2 1\n"
] | [
"1\n0\n0\n"
] | none | [
{
"input": "4\n1 2 3 4\n4\n3 0\n3 0 -1\n0 1\n2 1",
"output": "1\n0\n0"
},
{
"input": "1\n-1\n10\n0 0 -1\n0 0\n0 0 1\n0 0\n0 0 1\n0 0\n0 0 0\n0 0\n0 0 -1\n0 0 1",
"output": "-2\n-1\n0\n0"
},
{
"input": "2\n-1 -1\n10\n0 0\n0 0\n0 0 1\n0 0\n1 1\n0 0 -1\n0 0 0\n0 0 1\n1 1 0\n0 0 -1",
"ou... | 826 | 36,044,800 | 3.519861 | 11,585 |
51 | Three Base Stations | [
"binary search",
"greedy"
] | C. Three Base Stations | 1 | 256 | The New Vasjuki village is stretched along the motorway and that's why every house on it is characterized by its shift relative to some fixed point — the *x**i* coordinate. The village consists of *n* houses, the *i*-th house is located in the point with coordinates of *x**i*.
TELE3, a cellular communication provider ... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=2·105) which represents the number of houses in the village. The second line contains the coordinates of houses — the sequence *x*1,<=*x*2,<=...,<=*x**n* of integer numbers (1<=≤<=*x**i*<=≤<=109). It is possible that two or more houses are located on one point. The ... | Print the required minimal power *d*. In the second line print three numbers — the possible coordinates of the base stations' location. Print the coordinates with 6 digits after the decimal point. The positions of the stations can be any from 0 to 2·109 inclusively. It is accepted for the base stations to have matching... | [
"4\n1 2 3 4\n",
"3\n10 20 30\n",
"5\n10003 10004 10001 10002 1\n"
] | [
"0.500000\n1.500000 2.500000 3.500000\n",
"0\n10.000000 20.000000 30.000000\n",
"0.500000\n1.000000 10001.500000 10003.500000\n"
] | none | [
{
"input": "4\n1 2 3 4",
"output": "0.500000\n1.500000 2.500000 3.500000"
},
{
"input": "3\n10 20 30",
"output": "0\n10.000000 20.000000 30.000000"
},
{
"input": "5\n10003 10004 10001 10002 1",
"output": "0.500000\n1.000000 10001.500000 10003.500000"
},
{
"input": "1\n1",
... | 2,000 | 16,486,400 | 0 | 11,602 |
575 | Bulbo | [
"dp",
"greedy"
] | null | null | Bananistan is a beautiful banana republic. Beautiful women in beautiful dresses. Beautiful statues of beautiful warlords. Beautiful stars in beautiful nights.
In Bananistan people play this crazy game – Bulbo. There’s an array of bulbs and player at the position, which represents one of the bulbs. The distance between... | The first line contains number of turns *n* and initial position *x*. Next *n* lines contain two numbers *l**start* and *l**end*, which represent that all bulbs from interval [*l**start*,<=*l**end*] are shining this turn.
- 1<=≤<=*n*<=≤<=5000 - 1<=≤<=*x*<=≤<=109 - 1<=≤<=*l**start*<=≤<=*l**end*<=≤<=109 | Output should contain a single number which represents the best result (minimum cost) that could be obtained by playing this Bulbo game. | [
"5 4\n2 7\n9 16\n8 10\n9 17\n1 6\n"
] | [
"8\n"
] | Before 1. turn move to position 5
Before 2. turn move to position 9
Before 5. turn move to position 8 | [] | 46 | 0 | 0 | 11,649 | |
372 | Drawing Circles is Fun | [
"combinatorics",
"geometry"
] | null | null | There are a set of points *S* on the plane. This set doesn't contain the origin *O*(0,<=0), and for each two distinct points in the set *A* and *B*, the triangle *OAB* has strictly positive area.
Consider a set of pairs of points (*P*1,<=*P*2),<=(*P*3,<=*P*4),<=...,<=(*P*2*k*<=-<=1,<=*P*2*k*). We'll call the set good ... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of points in *S*. Each of the next *n* lines contains four integers *a**i*,<=*b**i*,<=*c**i*,<=*d**i* (0<=≤<=|*a**i*|,<=|*c**i*|<=≤<=50; 1<=≤<=*b**i*,<=*d**i*<=≤<=50; (*a**i*,<=*c**i*)<=≠<=(0,<=0)). These integers represent a point .
No two... | Print a single integer — the answer to the problem modulo 1000000007 (109<=+<=7). | [
"10\n-46 46 0 36\n0 20 -24 48\n-50 50 -49 49\n-20 50 8 40\n-15 30 14 28\n4 10 -4 5\n6 15 8 10\n-20 50 -3 15\n4 34 -16 34\n16 34 2 17\n",
"10\n30 30 -26 26\n0 15 -36 36\n-28 28 -34 34\n10 10 0 4\n-8 20 40 50\n9 45 12 30\n6 15 7 35\n36 45 -8 20\n-16 34 -4 34\n4 34 8 17\n",
"10\n0 20 38 38\n-30 30 -13 13\n-11 11 1... | [
"2\n",
"4\n",
"10\n"
] | none | [] | 0 | 0 | -1 | 11,652 | |
1,006 | Xor-Paths | [
"bitmasks",
"brute force",
"dp",
"meet-in-the-middle"
] | null | null | There is a rectangular grid of size $n \times m$. Each cell has a number written on it; the number on the cell ($i, j$) is $a_{i, j}$. Your task is to calculate the number of paths from the upper-left cell ($1, 1$) to the bottom-right cell ($n, m$) meeting the following constraints:
- You can move to the right or to ... | The first line of the input contains three integers $n$, $m$ and $k$ ($1 \le n, m \le 20$, $0 \le k \le 10^{18}$) — the height and the width of the grid, and the number $k$.
The next $n$ lines contain $m$ integers each, the $j$-th element in the $i$-th line is $a_{i, j}$ ($0 \le a_{i, j} \le 10^{18}$). | Print one integer — the number of paths from ($1, 1$) to ($n, m$) with xor sum equal to $k$. | [
"3 3 11\n2 1 5\n7 10 0\n12 6 4\n",
"3 4 2\n1 3 3 3\n0 3 3 2\n3 0 1 1\n",
"3 4 1000000000000000000\n1 3 3 3\n0 3 3 2\n3 0 1 1\n"
] | [
"3\n",
"5\n",
"0\n"
] | All the paths from the first example:
- $(1, 1) \rightarrow (2, 1) \rightarrow (3, 1) \rightarrow (3, 2) \rightarrow (3, 3)$; - $(1, 1) \rightarrow (2, 1) \rightarrow (2, 2) \rightarrow (2, 3) \rightarrow (3, 3)$; - $(1, 1) \rightarrow (1, 2) \rightarrow (2, 2) \rightarrow (3, 2) \rightarrow (3, 3)$.
All the path... | [
{
"input": "3 3 11\n2 1 5\n7 10 0\n12 6 4",
"output": "3"
},
{
"input": "3 4 2\n1 3 3 3\n0 3 3 2\n3 0 1 1",
"output": "5"
},
{
"input": "3 4 1000000000000000000\n1 3 3 3\n0 3 3 2\n3 0 1 1",
"output": "0"
},
{
"input": "1 1 1000000000000000000\n1000000000000000000",
"outpu... | 77 | 204,800 | -1 | 11,658 | |
11 | Jumping Jack | [
"math"
] | B. Jumping Jack | 1 | 64 | Jack is working on his jumping skills recently. Currently he's located at point zero of the number line. He would like to get to the point *x*. In order to train, he has decided that he'll first jump by only one unit, and each subsequent jump will be exactly one longer than the previous one. He can go either left or ri... | The input data consists of only one integer *x* (<=-<=109<=≤<=*x*<=≤<=109). | Output the minimal number of jumps that Jack requires to reach *x*. | [
"2\n",
"6\n",
"0\n"
] | [
"3\n",
"3\n",
"0\n"
] | none | [
{
"input": "2",
"output": "3"
},
{
"input": "6",
"output": "3"
},
{
"input": "0",
"output": "0"
},
{
"input": "-1000000000",
"output": "44723"
},
{
"input": "999961560",
"output": "44720"
},
{
"input": "999961561",
"output": "44721"
},
{
"i... | 122 | 30,310,400 | 3.71317 | 11,689 |
954 | String Typing | [
"implementation",
"strings"
] | null | null | You are given a string *s* consisting of *n* lowercase Latin letters. You have to type this string using your keyboard.
Initially, you have an empty string. Until you type the whole string, you may perform the following operation:
- add a character to the end of the string.
Besides, at most once you may perform one... | The first line of the input containing only one integer number *n* (1<=≤<=*n*<=≤<=100) — the length of the string you have to type. The second line containing the string *s* consisting of *n* lowercase Latin letters. | Print one integer number — the minimum number of operations you need to type the given string. | [
"7\nabcabca\n",
"8\nabcdefgh\n"
] | [
"5\n",
"8\n"
] | The first test described in the problem statement.
In the second test you can only type all the characters one by one. | [
{
"input": "7\nabcabca",
"output": "5"
},
{
"input": "8\nabcdefgh",
"output": "8"
},
{
"input": "100\nmhnzadklojbuumkrxjayikjhwuxihgkinllackcavhjpxlydxcmhnzadklojbuumkrxjayikjhwuxihgkinllackcavhjpxlydxc",
"output": "51"
},
{
"input": "99\ntrolnjmzxxrfxuexcqpjvefndwuxwsukxwmjh... | 61 | 1,536,000 | 3 | 11,698 | |
794 | Cutting Carrot | [
"geometry",
"math"
] | null | null | Igor the analyst has adopted *n* little bunnies. As we all know, bunnies love carrots. Thus, Igor has bought a carrot to be shared between his bunnies. Igor wants to treat all the bunnies equally, and thus he wants to cut the carrot into *n* pieces of equal area.
Formally, the carrot can be viewed as an isosceles tri... | The first and only line of input contains two space-separated integers, *n* and *h* (2<=≤<=*n*<=≤<=1000, 1<=≤<=*h*<=≤<=105). | The output should contain *n*<=-<=1 real numbers *x*1,<=*x*2,<=...,<=*x**n*<=-<=1. The number *x**i* denotes that the *i*-th cut must be made *x**i* units away from the apex of the carrot. In addition, 0<=<<=*x*1<=<<=*x*2<=<<=...<=<<=*x**n*<=-<=1<=<<=*h* must hold.
Your output will be considered correc... | [
"3 2\n",
"2 100000\n"
] | [
"1.154700538379 1.632993161855\n",
"70710.678118654752\n"
] | Definition of isosceles triangle: [https://en.wikipedia.org/wiki/Isosceles_triangle](https://en.wikipedia.org/wiki/Isosceles_triangle). | [
{
"input": "3 2",
"output": "1.154700538379 1.632993161855"
},
{
"input": "2 100000",
"output": "70710.678118654752"
},
{
"input": "1000 100000",
"output": "3162.277660168379 4472.135954999579 5477.225575051661 6324.555320336759 7071.067811865475 7745.966692414834 8366.600265340755 8... | 140 | 1,843,200 | 3 | 11,702 | |
631 | Messenger | [
"data structures",
"hashing",
"implementation",
"string suffix structures",
"strings"
] | null | null | Each employee of the "Blake Techologies" company uses a special messaging app "Blake Messenger". All the stuff likes this app and uses it constantly. However, some important futures are missing. For example, many users want to be able to search through the message history. It was already announced that the new feature ... | The first line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=200<=000) — the number of blocks in the strings *t* and *s*, respectively.
The second line contains the descriptions of *n* parts of string *t* in the format "*l**i*-*c**i*" (1<=≤<=*l**i*<=≤<=1<=000<=000) — the length of the *i*-th part... | Print a single integer — the number of occurrences of *s* in *t*. | [
"5 3\n3-a 2-b 4-c 3-a 2-c\n2-a 2-b 1-c\n",
"6 1\n3-a 6-b 7-a 4-c 8-e 2-a\n3-a\n",
"5 5\n1-h 1-e 1-l 1-l 1-o\n1-w 1-o 1-r 1-l 1-d\n"
] | [
"1",
"6",
"0"
] | In the first sample, *t* = "aaabbccccaaacc", and string *s* = "aabbc". The only occurrence of string *s* in string *t* starts at position *p* = 2.
In the second sample, *t* = "aaabbbbbbaaaaaaacccceeeeeeeeaa", and *s* = "aaa". The occurrences of *s* in *t* start at positions *p* = 1, *p* = 10, *p* = 11, *p* = 12, *p* =... | [
{
"input": "5 3\n3-a 2-b 4-c 3-a 2-c\n2-a 2-b 1-c",
"output": "1"
},
{
"input": "6 1\n3-a 6-b 7-a 4-c 8-e 2-a\n3-a",
"output": "6"
},
{
"input": "5 5\n1-h 1-e 1-l 1-l 1-o\n1-w 1-o 1-r 1-l 1-d",
"output": "0"
},
{
"input": "9 3\n1-h 1-e 2-l 1-o 1-w 1-o 1-r 1-l 1-d\n2-l 1-o 1-w... | 2,000 | 8,908,800 | 0 | 11,710 | |
358 | Dima and Containers | [
"constructive algorithms",
"greedy",
"implementation"
] | null | null | Dima has a birthday soon! It's a big day! Saryozha's present to Dima is that Seryozha won't be in the room and won't disturb Dima and Inna as they celebrate the birthday. Inna's present to Dima is a stack, a queue and a deck.
Inna wants her present to show Dima how great a programmer he is. For that, she is going to g... | The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of Inna's commands. Then *n* lines follow, describing Inna's commands. Each line consists an integer:
1. Integer *a* (1<=≤<=*a*<=≤<=105) means that Inna gives Dima a command to add number *a* into one of containers. 1. Integer 0 shows that Inna ask... | Each command of the input must correspond to one line of the output — Dima's action.
For the command of the first type (adding) print one word that corresponds to Dima's choice:
- pushStack — add to the end of the stack; - pushQueue — add to the end of the queue; - pushFront — add to the beginning of the deck; - ... | [
"10\n0\n1\n0\n1\n2\n0\n1\n2\n3\n0\n",
"4\n1\n2\n3\n0\n"
] | [
"0\npushStack\n1 popStack\npushStack\npushQueue\n2 popStack popQueue\npushStack\npushQueue\npushFront\n3 popStack popQueue popFront\n",
"pushStack\npushQueue\npushFront\n3 popStack popQueue popFront\n"
] | none | [
{
"input": "10\n0\n1\n0\n1\n2\n0\n1\n2\n3\n0",
"output": "0\npushStack\n1 popStack\npushStack\npushQueue\n2 popStack popQueue\npushStack\npushQueue\npushFront\n3 popStack popQueue popFront"
},
{
"input": "4\n1\n2\n3\n0",
"output": "pushStack\npushQueue\npushFront\n3 popStack popQueue popFront"
... | 31 | 204,800 | 0 | 11,732 | |
0 | none | [
"none"
] | null | null | Helen works in Metropolis airport. She is responsible for creating a departure schedule. There are *n* flights that must depart today, the *i*-th of them is planned to depart at the *i*-th minute of the day.
Metropolis airport is the main transport hub of Metropolia, so it is difficult to keep the schedule intact. Thi... | The first line contains two integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=300<=000), here *n* is the number of flights, and *k* is the number of minutes in the beginning of the day that the flights did not depart.
The second line contains *n* integers *c*1,<=*c*2,<=...,<=*c**n* (1<=≤<=*c**i*<=≤<=107), here *c**i* is the... | The first line must contain the minimum possible total cost of delaying the flights.
The second line must contain *n* different integers *t*1,<=*t*2,<=...,<=*t**n* (*k*<=+<=1<=≤<=*t**i*<=≤<=*k*<=+<=*n*), here *t**i* is the minute when the *i*-th flight must depart. If there are several optimal schedules, print any of ... | [
"5 2\n4 2 1 10 2\n"
] | [
"20\n3 6 7 4 5 \n"
] | Let us consider sample test. If Helen just moves all flights 2 minutes later preserving the order, the total cost of delaying the flights would be (3 - 1)·4 + (4 - 2)·2 + (5 - 3)·1 + (6 - 4)·10 + (7 - 5)·2 = 38 burles.
However, the better schedule is shown in the sample answer, its cost is (3 - 1)·4 + (6 - 2)·2 + (7 ... | [
{
"input": "5 2\n4 2 1 10 2",
"output": "20\n3 6 7 4 5 "
},
{
"input": "3 2\n3 1 2",
"output": "11\n3 5 4 "
},
{
"input": "5 5\n5 5 9 100 3",
"output": "321\n9 8 7 6 10 "
},
{
"input": "1 1\n1",
"output": "1\n2 "
},
{
"input": "1 1\n10000000",
"output": "10000... | 46 | 0 | 0 | 11,738 | |
301 | Yaroslav and Algorithm | [
"constructive algorithms"
] | null | null | Yaroslav likes algorithms. We'll describe one of his favorite algorithms.
1. The algorithm receives a string as the input. We denote this input string as *a*. 1. The algorithm consists of some number of command. Сommand number *i* looks either as *s**i* >> *w**i*, or as *s**i* <> *w**i*, where *s**i* and... | The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of elements in the set. The next *n* lines contains one positive integer each. All the given numbers are less than 1025. | Print the algorithm which can individually increase each number of the set. In the *i*-th line print the command number *i* without spaces.
Your algorithm will be launched for each of these numbers. The answer will be considered correct if:
- Each line will a correct algorithm command (see the description in the ... | [
"2\n10\n79\n"
] | [
"10<>11\n79<>80\n"
] | none | [
{
"input": "2\n10\n79",
"output": "10<>11\n79<>80"
},
{
"input": "5\n9\n99\n999\n9999\n99999",
"output": "0??<>1\n1??<>2\n2??<>3\n3??<>4\n4??<>5\n5??<>6\n6??<>7\n7??<>8\n8??<>9\n9??>>??0\n??<>1\n?0>>0?\n?1>>1?\n?2>>2?\n?3>>3?\n?4>>4?\n?5>>5?\n?6>>6?\n?7>>7?\n?8>>8?\n?9>>9?\n?>>??\n>>?"
},
{
... | 248 | 0 | 3 | 11,741 | |
638 | Making Genome in Berland | [
"*special",
"dfs and similar",
"strings"
] | null | null | Berland scientists face a very important task - given the parts of short DNA fragments, restore the dinosaur DNA! The genome of a berland dinosaur has noting in common with the genome that we've used to: it can have 26 distinct nucleotide types, a nucleotide of each type can occur at most once. If we assign distinct En... | The first line of the input contains a positive integer *n* (1<=≤<=*n*<=≤<=100) — the number of genome fragments.
Each of the next lines contains one descriptions of a fragment. Each fragment is a non-empty string consisting of distinct small letters of the English alphabet. It is not guaranteed that the given fragmen... | In the single line of the output print the genome of the minimum length that contains all the given parts. All the nucleotides in the genome must be distinct. If there are multiple suitable strings, print the string of the minimum length. If there also are multiple suitable strings, you can print any of them. | [
"3\nbcd\nab\ncdef\n",
"4\nx\ny\nz\nw\n"
] | [
"abcdef\n",
"xyzw\n"
] | none | [
{
"input": "3\nbcd\nab\ncdef",
"output": "abcdef"
},
{
"input": "4\nx\ny\nz\nw",
"output": "xyzw"
},
{
"input": "25\nef\nfg\ngh\nhi\nij\njk\nkl\nlm\nmn\nno\nab\nbc\ncd\nde\nop\npq\nqr\nrs\nst\ntu\nuv\nvw\nwx\nxy\nyz",
"output": "abcdefghijklmnopqrstuvwxyz"
},
{
"input": "1\nf... | 62 | 4,608,000 | 0 | 11,745 | |
665 | Four Divisors | [
"data structures",
"dp",
"math",
"number theory",
"sortings",
"two pointers"
] | null | null | If an integer *a* is divisible by another integer *b*, then *b* is called the divisor of *a*.
For example: 12 has positive 6 divisors. They are 1, 2, 3, 4, 6 and 12.
Let’s define a function *D*(*n*) — number of integers between 1 and *n* (inclusive) which has exactly four positive divisors.
Between 1 and 10 only the... | The only line contains integer *n* (1<=≤<=*n*<=≤<=1011) — the parameter from the problem statement. | Print the only integer *c* — the number of integers between 1 and *n* with exactly four divisors. | [
"10\n",
"20\n"
] | [
"3\n",
"5\n"
] | none | [
{
"input": "10",
"output": "3"
},
{
"input": "20",
"output": "5"
},
{
"input": "1",
"output": "0"
},
{
"input": "27",
"output": "9"
},
{
"input": "100",
"output": "32"
},
{
"input": "1000",
"output": "292"
},
{
"input": "10000",
"output... | 4,726 | 13,516,800 | 3 | 11,757 | |
990 | Post Lamps | [
"brute force",
"greedy"
] | null | null | Adilbek's house is located on a street which can be represented as the OX axis. This street is really dark, so Adilbek wants to install some post lamps to illuminate it. Street has $n$ positions to install lamps, they correspond to the integer numbers from $0$ to $n - 1$ on the OX axis. However, some positions are bloc... | The first line contains three integer numbers $n$, $m$ and $k$ ($1 \le k \le n \le 10^6$, $0 \le m \le n$) — the length of the segment of the street Adilbek wants to illuminate, the number of the blocked positions and the maximum power of the post lamp available.
The second line contains $m$ integer numbers $s_1, s_2,... | Print the minimal total cost of the post lamps of exactly one type Adilbek can buy to illuminate the entire segment $[0; n]$ of the street.
If illumintaing the entire segment $[0; n]$ is impossible, print -1. | [
"6 2 3\n1 3\n1 2 3\n",
"4 3 4\n1 2 3\n1 10 100 1000\n",
"5 1 5\n0\n3 3 3 3 3\n",
"7 4 3\n2 4 5 6\n3 14 15\n"
] | [
"6\n",
"1000\n",
"-1\n",
"-1\n"
] | none | [
{
"input": "6 2 3\n1 3\n1 2 3",
"output": "6"
},
{
"input": "4 3 4\n1 2 3\n1 10 100 1000",
"output": "1000"
},
{
"input": "5 1 5\n0\n3 3 3 3 3",
"output": "-1"
},
{
"input": "7 4 3\n2 4 5 6\n3 14 15",
"output": "-1"
},
{
"input": "1 0 1\n\n1000000",
"output": ... | 2,000 | 108,236,800 | 0 | 11,771 | |
58 | Coins | [
"greedy"
] | B. Coins | 2 | 256 | In Berland a money reform is being prepared. New coins are being introduced. After long economic calculations was decided that the most expensive coin should possess the denomination of exactly *n* Berland dollars. Also the following restriction has been introduced for comfort: the denomination of each coin should be d... | The first and only line contains an integer *n* (1<=≤<=*n*<=≤<=106) which represents the denomination of the most expensive coin. | Print the denominations of all the coins in the order of decreasing. The number of coins must be the largest possible (with the given denomination *n* of the most expensive coin). Also, the denomination of every coin must be divisible by the denomination of any cheaper coin. Naturally, the denominations of all the coin... | [
"10\n",
"4\n",
"3\n"
] | [
"10 5 1\n",
"4 2 1\n",
"3 1\n"
] | none | [
{
"input": "10",
"output": "10 5 1"
},
{
"input": "4",
"output": "4 2 1"
},
{
"input": "3",
"output": "3 1"
},
{
"input": "2",
"output": "2 1"
},
{
"input": "5",
"output": "5 1"
},
{
"input": "6",
"output": "6 3 1"
},
{
"input": "7",
"o... | 154 | 0 | 3.9615 | 11,788 |
0 | none | [
"none"
] | null | null | Petya learned a new programming language CALPAS. A program in this language always takes one non-negative integer and returns one non-negative integer as well.
In the language, there are only three commands: apply a bitwise operation AND, OR or XOR with a given constant to the current integer. A program can contain an... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=5·105) — the number of lines.
Next *n* lines contain commands. A command consists of a character that represents the operation ("&", "|" or "^" for AND, OR or XOR respectively), and the constant *x**i* 0<=≤<=*x**i*<=≤<=1023. | Output an integer *k* (0<=≤<=*k*<=≤<=5) — the length of your program.
Next *k* lines must contain commands in the same format as in the input. | [
"3\n| 3\n^ 2\n| 1\n",
"3\n& 1\n& 3\n& 5\n",
"3\n^ 1\n^ 2\n^ 3\n"
] | [
"2\n| 3\n^ 2\n",
"1\n& 1\n",
"0\n"
] | You can read about bitwise operations in [https://en.wikipedia.org/wiki/Bitwise_operation](https://en.wikipedia.org/wiki/Bitwise_operation).
Second sample:
Let *x* be an input of the Petya's program. It's output is ((*x*&1)&3)&5 = *x*&(1&3&5) = *x*&1. So these two programs always give the ... | [
{
"input": "3\n| 3\n^ 2\n| 1",
"output": "2\n| 3\n^ 2"
},
{
"input": "3\n& 1\n& 3\n& 5",
"output": "1\n& 1"
},
{
"input": "3\n^ 1\n^ 2\n^ 3",
"output": "0"
},
{
"input": "2\n| 999\n^ 689",
"output": "2\n| 999\n^ 689"
},
{
"input": "3\n& 242\n^ 506\n^ 522",
"ou... | 124 | 0 | 0 | 11,823 | |
268 | Wall Bars | [
"dp"
] | null | null | Manao is working for a construction company. Recently, an order came to build wall bars in a children's park. Manao was commissioned to develop a plan of construction, which will enable the company to save the most money.
After reviewing the formal specifications for the wall bars, Manao discovered a number of controv... | A single line contains two space-separated integers, *n* and *h* (1<=≤<=*n*<=≤<=1000, 1<=≤<=*h*<=≤<=*min*(*n*,<=30)). | In a single line print the remainder after dividing the number of designs by 1000000009 (109<=+<=9). | [
"5 1\n",
"4 2\n",
"4 3\n",
"5 2\n"
] | [
"4\n",
"148\n",
"256\n",
"376\n"
] | Consider several designs for *h* = 2. A design with the first bar sticked out in direction *d*<sub class="lower-index">1</sub>, the second — in direction *d*<sub class="lower-index">2</sub> and so on (1 ≤ *d*<sub class="lower-index">*i*</sub> ≤ 4) is denoted as string *d*<sub class="lower-index">1</sub>*d*<sub class="l... | [] | 122 | 0 | 0 | 11,830 | |
59 | Title | [
"expression parsing"
] | C. Title | 2 | 256 | Vasya has recently finished writing a book. Now he faces the problem of giving it the title. Vasya wants the title to be vague and mysterious for his book to be noticeable among others. That's why the title should be represented by a single word containing at least once each of the first *k* Latin letters and not conta... | The first line contains an integer *k* (1<=≤<=*k*<=≤<=26) which is the number of allowed alphabet letters. The second line contains *s* which is the given template. In *s* only the first *k* lowercase letters of Latin alphabet and question marks can be present, the length of *s* is from 1 to 100 characters inclusively. | If there is no solution, print IMPOSSIBLE. Otherwise, a single line should contain the required title, satisfying the given template. The title should be a palindrome and it can only contain the first *k* letters of the Latin alphabet. At that, each of those *k* letters must be present at least once. If there are sever... | [
"3\na?c\n",
"2\na??a\n",
"2\n?b?a\n"
] | [
"IMPOSSIBLE\n",
"abba\n",
"abba\n"
] | none | [
{
"input": "3\na?c",
"output": "IMPOSSIBLE"
},
{
"input": "2\na??a",
"output": "abba"
},
{
"input": "2\n?b?a",
"output": "abba"
},
{
"input": "3\n????",
"output": "IMPOSSIBLE"
},
{
"input": "2\n????",
"output": "abba"
},
{
"input": "1\n?",
"output"... | 154 | 512,000 | 3.960546 | 11,859 |
413 | Jeopardy! | [
"greedy",
"math"
] | null | null | 'Jeopardy!' is an intellectual game where players answer questions and earn points. Company Q conducts a simplified 'Jeopardy!' tournament among the best IT companies. By a lucky coincidence, the old rivals made it to the finals: company R1 and company R2.
The finals will have *n* questions, *m* of them are auction q... | The first line contains two space-separated integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100; *m*<=≤<=*min*(*n*,<=30)) — the total number of questions and the number of auction questions, correspondingly. The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=107) — the prices o... | In the single line, print the answer to the problem — the maximum points the R2 company can get if it plays optimally well. It is guaranteed that the answer fits into the integer 64-bit signed type. | [
"4 1\n1 3 7 5\n3\n",
"3 2\n10 3 8\n2 3\n",
"2 2\n100 200\n1 2\n"
] | [
"18\n",
"40\n",
"400\n"
] | none | [
{
"input": "4 1\n1 3 7 5\n3",
"output": "18"
},
{
"input": "3 2\n10 3 8\n2 3",
"output": "40"
},
{
"input": "2 2\n100 200\n1 2",
"output": "400"
},
{
"input": "1 1\n1\n1",
"output": "1"
},
{
"input": "2 2\n1 5\n1 2",
"output": "10"
},
{
"input": "5 3\n... | 202 | 2,457,600 | -1 | 11,868 | |
24 | Broken robot | [
"dp",
"math",
"probabilities"
] | D. Broken robot | 2 | 256 | You received as a gift a very clever robot walking on a rectangular board. Unfortunately, you understood that it is broken and behaves rather strangely (randomly). The board consists of *N* rows and *M* columns of cells. The robot is initially at some cell on the *i*-th row and the *j*-th column. Then at every step the... | On the first line you will be given two space separated integers *N* and *M* (1<=≤<=*N*,<=*M*<=≤<=1000). On the second line you will be given another two space separated integers *i* and *j* (1<=≤<=*i*<=≤<=*N*,<=1<=≤<=*j*<=≤<=*M*) — the number of the initial row and the number of the initial column. Note that, (1,<=1) ... | Output the expected number of steps on a line of itself with at least 4 digits after the decimal point. | [
"10 10\n10 4\n",
"10 14\n5 14\n"
] | [
"0.0000000000\n",
"18.0038068653\n"
] | none | [
{
"input": "10 10\n10 4",
"output": "0.0000000000"
},
{
"input": "10 14\n5 14",
"output": "18.0038068653"
},
{
"input": "126 125\n115 22",
"output": "43.9999127943"
},
{
"input": "755 51\n205 12",
"output": "2178.8368031733"
},
{
"input": "385 978\n344 18",
"o... | 92 | 0 | 0 | 11,870 |
489 | Hiking | [
"binary search",
"dp"
] | null | null | A traveler is planning a water hike along the river. He noted the suitable rest points for the night and wrote out their distances from the starting point. Each of these locations is further characterized by its picturesqueness, so for the *i*-th rest point the distance from the start equals *x**i*, and its picturesque... | The first line of the input contains integers *n*,<=*l* (1<=≤<=*n*<=≤<=1000,<=1<=≤<=*l*<=≤<=105) — the number of rest points and the optimal length of one day path.
Then *n* lines follow, each line describes one rest point as a pair of integers *x**i*,<=*b**i* (1<=≤<=*x**i*,<=*b**i*<=≤<=106). No two rest points have t... | Print the traveler's path as a sequence of the numbers of the resting points he used in the order he used them. Number the points from 1 to *n* in the order of increasing *x**i*. The last printed number must be equal to *n*. | [
"5 9\n10 10\n20 10\n30 1\n31 5\n40 10\n"
] | [
"1 2 4 5 "
] | In the sample test the minimum value of relative total frustration approximately equals 0.097549. This value can be calculated as <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/bad16faba2aa8ac4e81ca909b5e927a7f644c23f.png" style="max-width: 100.0%;max-height: 100.0%;"/>. | [
{
"input": "5 9\n10 10\n20 10\n30 1\n31 5\n40 10",
"output": "1 2 4 5 "
},
{
"input": "1 20\n9 1",
"output": "1 "
},
{
"input": "2 7\n1 9\n5 6",
"output": "2 "
},
{
"input": "3 2\n2 6\n3 9\n6 8",
"output": "1 2 3 "
},
{
"input": "4 3\n1 6\n5 10\n9 9\n10 6",
"o... | 30 | 0 | 0 | 11,879 | |
464 | The Classic Problem | [
"data structures",
"graphs",
"shortest paths"
] | null | null | You are given a weighted undirected graph on *n* vertices and *m* edges. Find the shortest path from vertex *s* to vertex *t* or else state that such path doesn't exist. | The first line of the input contains two space-separated integers — *n* and *m* (1<=≤<=*n*<=≤<=105; 0<=≤<=*m*<=≤<=105).
Next *m* lines contain the description of the graph edges. The *i*-th line contains three space-separated integers — *u**i*, *v**i*, *x**i* (1<=≤<=*u**i*,<=*v**i*<=≤<=*n*; 0<=≤<=*x**i*<=≤<=105). That... | In the first line print the remainder after dividing the length of the shortest path by 1000000007 (109<=+<=7) if the path exists, and -1 if the path doesn't exist.
If the path exists print in the second line integer *k* — the number of vertices in the shortest path from vertex *s* to vertex *t*; in the third line pri... | [
"4 4\n1 4 2\n1 2 0\n2 3 0\n3 4 0\n1 4\n",
"4 3\n1 2 4\n2 3 5\n3 4 6\n1 4\n",
"4 2\n1 2 0\n3 4 1\n1 4\n"
] | [
"3\n4\n1 2 3 4 \n",
"112\n4\n1 2 3 4 \n",
"-1\n"
] | A path from vertex *s* to vertex *t* is a sequence *v*<sub class="lower-index">0</sub>, ..., *v*<sub class="lower-index">*k*</sub>, such that *v*<sub class="lower-index">0</sub> = *s*, *v*<sub class="lower-index">*k*</sub> = *t*, and for any *i* from 0 to *k* - 1 vertices *v*<sub class="lower-index">*i*</sub> and *v*<s... | [] | 61 | 512,000 | 0 | 11,880 | |
297 | Mystic Carvings | [
"data structures"
] | null | null | The polar bears have discovered a gigantic circular piece of floating ice with some mystic carvings on it. There are *n* lines carved on the ice. Each line connects two points on the boundary of the ice (we call these points endpoints). The endpoints are numbered 1,<=2,<=...,<=2*n* counter-clockwise along the circumfer... | The first line contains integer *n*(3<=≤<=*n*<=≤<=105) — the number of lines.
Each of the following *n* lines contains two integers *a**i*,<=*b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=2*n*), which means that there is a line carved on the ice connecting the *a**i*–th and *b**i*–th endpoint.
It's guaranteed that each endpoints... | Print the number of ways to build the caves.
Please, do not write the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier. | [
"4\n5 4\n1 2\n6 7\n8 3\n",
"8\n1 7\n2 4\n3 9\n5 11\n6 8\n10 16\n13 15\n14 12\n"
] | [
"2\n",
"6\n"
] | The second sample corresponds to the figure in the problem statement. | [] | 60 | 0 | 0 | 11,890 | |
960 | Subsequence Counting | [
"bitmasks",
"constructive algorithms",
"greedy",
"implementation"
] | null | null | Pikachu had an array with him. He wrote down all the non-empty subsequences of the array on paper. Note that an array of size *n* has 2*n*<=-<=1 non-empty subsequences in it.
Pikachu being mischievous as he always is, removed all the subsequences in which Maximum_element_of_the_subsequence <=-<= Minimum_element_of_su... | The only line of input consists of two space separated integers *X* and *d* (1<=≤<=*X*,<=*d*<=≤<=109). | Output should consist of two lines.
First line should contain a single integer *n* (1<=≤<=*n*<=≤<=10<=000)— the number of integers in the final array.
Second line should consist of *n* space separated integers — *a*1,<=*a*2,<=... ,<=*a**n* (1<=≤<=*a**i*<=<<=1018).
If there is no answer, print a single integer -1.... | [
"10 5\n",
"4 2\n"
] | [
"6\n5 50 7 15 6 100",
"4\n10 100 1000 10000"
] | In the output of the first example case, the remaining subsequences after removing those with Maximum_element_of_the_subsequence - Minimum_element_of_subsequence ≥ 5 are [5], [5, 7], [5, 6], [5, 7, 6], [50], [7], [7, 6], [15], [6], [100]. There are 10 of them. Hence, the array [5, 50, 7, 15, 6, 100] is valid.
Simil... | [
{
"input": "10 5",
"output": "6\n1 1 1 7 13 19 "
},
{
"input": "4 2",
"output": "3\n1 1 4 "
},
{
"input": "4 1",
"output": "3\n1 1 3 "
},
{
"input": "1 1",
"output": "1\n1 "
},
{
"input": "63 1",
"output": "21\n1 1 1 1 1 3 3 3 3 5 5 5 7 7 9 11 13 15 17 19 21 "... | 77 | 0 | 0 | 11,913 | |
30 | Codeforces World Finals | [
"implementation"
] | B. Codeforces World Finals | 2 | 256 | The king Copa often has been reported about the Codeforces site, which is rapidly getting more and more popular among the brightest minds of the humanity, who are using it for training and competing. Recently Copa understood that to conquer the world he needs to organize the world Codeforces tournament. He hopes that a... | The first line contains the date *DD*.*MM*.*YY*, the second line contains the date *BD*.*BM*.*BY*. It is guaranteed that both dates are correct, and *YY* and *BY* are always in [01;99].
It could be that by passport Bob was born after the finals. In this case, he can still change the order of numbers in date. | If it is possible to rearrange the numbers in the date of birth so that Bob will be at least 18 years old on the *DD*.*MM*.*YY*, output YES. In the other case, output NO.
Each number contains exactly two digits and stands for day, month or year in a date. Note that it is permitted to rearrange only numbers, not digit... | [
"01.01.98\n01.01.80\n",
"20.10.20\n10.02.30\n",
"28.02.74\n28.02.64\n"
] | [
"YES\n",
"NO\n",
"NO\n"
] | none | [
{
"input": "01.01.98\n01.01.80",
"output": "YES"
},
{
"input": "20.10.20\n10.02.30",
"output": "NO"
},
{
"input": "28.02.74\n28.02.64",
"output": "NO"
},
{
"input": "05.05.25\n06.02.71",
"output": "NO"
},
{
"input": "19.11.54\n29.11.53",
"output": "NO"
},
... | 60 | 0 | 0 | 11,925 |
535 | Tavas and Malekas | [
"greedy",
"hashing",
"string suffix structures",
"strings"
] | null | null | Tavas is a strange creature. Usually "zzz" comes out of people's mouth while sleeping, but string *s* of length *n* comes out from Tavas' mouth instead.
Today Tavas fell asleep in Malekas' place. While he was sleeping, Malekas did a little process on *s*. Malekas has a favorite string *p*. He determined all positions ... | The first line contains two integers *n* and *m*, the length of *s* and the length of the subsequence Malekas wrote down (1<=≤<=*n*<=≤<=106 and 0<=≤<=*m*<=≤<=*n*<=-<=|*p*|<=+<=1).
The second line contains string *p* (1<=≤<=|*p*|<=≤<=*n*).
The next line contains *m* space separated integers *y*1,<=*y*2,<=...,<=*y**m*,... | In a single line print the answer modulo 1000<=000<=007. | [
"6 2\nioi\n1 3\n",
"5 2\nioi\n1 2\n"
] | [
"26\n",
"0\n"
] | In the first sample test all strings of form "ioioi?" where the question mark replaces arbitrary English letter satisfy.
Here |*x*| denotes the length of string x.
Please note that it's possible that there is no such string (answer is 0). | [
{
"input": "6 2\nioi\n1 3",
"output": "26"
},
{
"input": "5 2\nioi\n1 2",
"output": "0"
},
{
"input": "173700 6\nbcabcbcbcbaaacaccaacaccaabacabaacbcacbbccaccbcacbabcaccccccaacacabbbbbacabbaaacbcbbaccaccabbbbaabbacacbabccaabcabbbcacaaccbabbcaaaaaabccbbcabcacbcbcabcbcbbaabacaaccccabacaaacc... | 483 | 59,904,000 | -1 | 11,945 | |
616 | Sum of Remainders | [
"implementation",
"math",
"number theory"
] | null | null | Calculate the value of the sum: *n* mod 1 + *n* mod 2 + *n* mod 3 + ... + *n* mod *m*. As the result can be very large, you should print the value modulo 109<=+<=7 (the remainder when divided by 109<=+<=7).
The modulo operator *a* mod *b* stands for the remainder after dividing *a* by *b*. For example 10 mod 3 = 1. | The only line contains two integers *n*,<=*m* (1<=≤<=*n*,<=*m*<=≤<=1013) — the parameters of the sum. | Print integer *s* — the value of the required sum modulo 109<=+<=7. | [
"3 4\n",
"4 4\n",
"1 1\n"
] | [
"4\n",
"1\n",
"0\n"
] | none | [
{
"input": "3 4",
"output": "4"
},
{
"input": "4 4",
"output": "1"
},
{
"input": "1 1",
"output": "0"
},
{
"input": "20000000 10000000",
"output": "176305083"
},
{
"input": "10000000000000 10000000000000",
"output": "869957328"
},
{
"input": "1 1000000... | 2,000 | 1,843,200 | 0 | 11,948 | |
862 | Mahmoud and Ehab and the binary string | [
"binary search",
"divide and conquer",
"interactive"
] | null | null | Mahmoud and Ehab are in the fourth stage now.
Dr. Evil has a hidden binary string of length *n*. He guarantees that there is at least one '0' symbol and at least one '1' symbol in it. Now he wants Mahmoud and Ehab to find a position of any '0' symbol and any '1' symbol. In order to do this, Mahmoud and Ehab can ask Dr... | The first line of input will contain a single integer *n* (2<=≤<=*n*<=≤<=1000) — the length of the hidden binary string. | To print the final answer, print "! pos0 pos1" (without quotes), where *pos*0 and *pos*1 are positions of some '0' and some '1' in the string (the string is 1-indexed). Don't forget to flush the output after printing the answer! | [
"3\n2\n1\n3\n2\n1\n0"
] | [
"? 000\n? 001\n? 010\n? 011\n? 100\n? 101\n! 2 1"
] | Hamming distance definition: [https://en.wikipedia.org/wiki/Hamming_distance](https://en.wikipedia.org/wiki/Hamming_distance)
In the first test case the hidden binary string is 101, The first query is 000, so the Hamming distance is 2. In the second query the hidden string is still 101 and query is 001, so the Hamming... | [
{
"input": "101",
"output": "3"
},
{
"input": "0011001100",
"output": "4"
},
{
"input": "01",
"output": "2"
},
{
"input": "0010100101101100001101110001110011000010011011001110010011101010011010100101101001111010111001000100",
"output": "8"
},
{
"input": "010101010... | 109 | 0 | 0 | 11,994 | |
886 | Restoration of string | [
"constructive algorithms",
"graphs",
"implementation"
] | null | null | A substring of some string is called the most frequent, if the number of its occurrences is not less than number of occurrences of any other substring.
You are given a set of strings. A string (not necessarily from this set) is called good if all elements of the set are the most frequent substrings of this string. Res... | The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of strings in the set.
Each of the next *n* lines contains a non-empty string consisting of lowercase English letters. It is guaranteed that the strings are distinct.
The total length of the strings doesn't exceed 105. | Print the non-empty good string with minimum length. If several good strings exist, print lexicographically minimum among them. Print "NO" (without quotes) if there are no good strings. | [
"4\nmail\nai\nlru\ncf\n",
"3\nkek\npreceq\ncheburek\n"
] | [
"cfmailru\n",
"NO\n"
] | One can show that in the first sample only two good strings with minimum length exist: "cfmailru" and "mailrucf". The first string is lexicographically minimum. | [
{
"input": "4\nmail\nai\nlru\ncf",
"output": "cfmailru"
},
{
"input": "3\nkek\npreceq\ncheburek",
"output": "NO"
},
{
"input": "1\nz",
"output": "z"
},
{
"input": "2\nab\nba",
"output": "NO"
},
{
"input": "2\nac\nbc",
"output": "NO"
},
{
"input": "2\nc... | 2,000 | 307,200 | 0 | 12,010 | |
909 | Colorful Points | [
"data structures",
"greedy",
"implementation"
] | null | null | You are given a set of points on a straight line. Each point has a color assigned to it. For point *a*, its neighbors are the points which don't have any other points between them and *a*. Each point has at most two neighbors - one from the left and one from the right.
You perform a sequence of operations on this set ... | Input contains a single string of lowercase English letters 'a'-'z'. The letters give the points' colors in the order in which they are arranged on the line: the first letter gives the color of the leftmost point, the second gives the color of the second point from the left etc.
The number of the points is between 1 a... | Output one line containing an integer - the number of operations which can be performed on the given set of points until there are no more points to delete. | [
"aabb\n",
"aabcaa\n"
] | [
"2\n",
"1\n"
] | In the first test case, the first operation will delete two middle points and leave points "ab", which will be deleted with the second operation. There will be no points left to apply the third operation to.
In the second test case, the first operation will delete the four points in the middle, leaving points "aa". No... | [
{
"input": "aabb",
"output": "2"
},
{
"input": "aabcaa",
"output": "1"
},
{
"input": "abbcccbba",
"output": "1"
},
{
"input": "aaaaaaaaaaa",
"output": "0"
},
{
"input": "aaaaaaaaabbbbbaaaabaaaaaaaaaaaaaaaaabaaaaaabbbbbbbaaabbbbbbbbbbbbbbbbbbbbbaaaaaaaaaaaaaaaaaaaa... | 2,000 | 9,625,600 | 0 | 12,064 | |
377 | Preparing for the Contest | [
"binary search",
"data structures",
"greedy",
"sortings"
] | null | null | Soon there will be held the world's largest programming contest, but the testing system still has *m* bugs. The contest organizer, a well-known university, has no choice but to attract university students to fix all the bugs. The university has *n* students able to perform such work. The students realize that they are ... | The first line contains three space-separated integers: *n*, *m* and *s* (1<=≤<=*n*,<=*m*<=≤<=105, 0<=≤<=*s*<=≤<=109) — the number of students, the number of bugs in the system and the maximum number of passes the university is ready to give the students.
The next line contains *m* space-separated integers *a*1, *a*2,... | If the university can't correct all bugs print "NO".
Otherwise, on the first line print "YES", and on the next line print *m* space-separated integers: the *i*-th of these numbers should equal the number of the student who corrects the *i*-th bug in the optimal answer. The bugs should be corrected as quickly as possib... | [
"3 4 9\n1 3 1 2\n2 1 3\n4 3 6\n",
"3 4 10\n2 3 1 2\n2 1 3\n4 3 6\n",
"3 4 9\n2 3 1 2\n2 1 3\n4 3 6\n",
"3 4 5\n1 3 1 2\n2 1 3\n5 3 6\n"
] | [
"YES\n2 3 2 3\n",
"YES\n1 3 1 3\n",
"YES\n3 3 2 3\n",
"NO\n"
] | Consider the first sample.
The third student (with level 3) must fix the 2nd and 4th bugs (complexities 3 and 2 correspondingly) and the second student (with level 1) must fix the 1st and 3rd bugs (their complexity also equals 1). Fixing each bug takes one day for each student, so it takes 2 days to fix all bugs (the ... | [
{
"input": "3 4 9\n1 3 1 2\n2 1 3\n4 3 6",
"output": "YES\n2 3 2 3"
},
{
"input": "3 4 10\n2 3 1 2\n2 1 3\n4 3 6",
"output": "YES\n1 3 1 3"
},
{
"input": "3 4 9\n2 3 1 2\n2 1 3\n4 3 6",
"output": "YES\n3 3 2 3"
},
{
"input": "3 4 5\n1 3 1 2\n2 1 3\n5 3 6",
"output": "NO"
... | 61 | 2,867,200 | -1 | 12,100 | |
325 | Square and Rectangles | [
"implementation"
] | null | null | You are given *n* rectangles. The corners of rectangles have integer coordinates and their edges are parallel to the *Ox* and *Oy* axes. The rectangles may touch each other, but they do not overlap (that is, there are no points that belong to the interior of more than one rectangle).
Your task is to determine if the ... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=5). Next *n* lines contain four integers each, describing a single rectangle: *x*1, *y*1, *x*2, *y*2 (0<=≤<=*x*1<=<<=*x*2<=≤<=31400,<=0<=≤<=*y*1<=<<=*y*2<=≤<=31400) — *x*1 and *x*2 are *x*-coordinates of the left and right edges of the rectangle, and *y*... | In a single line print "YES", if the given rectangles form a square, or "NO" otherwise. | [
"5\n0 0 2 3\n0 3 3 5\n2 0 5 2\n3 2 5 5\n2 2 3 3\n",
"4\n0 0 2 3\n0 3 3 5\n2 0 5 2\n3 2 5 5\n"
] | [
"YES\n",
"NO\n"
] | none | [
{
"input": "5\n0 0 2 3\n0 3 3 5\n2 0 5 2\n3 2 5 5\n2 2 3 3",
"output": "YES"
},
{
"input": "4\n0 0 2 3\n0 3 3 5\n2 0 5 2\n3 2 5 5",
"output": "NO"
},
{
"input": "5\n0 0 10000 20000\n10000 0 15000 19999\n10000 19999 14999 20000\n0 20000 15000 31400\n15000 0 31400 31400",
"output": "NO... | 62 | 0 | -1 | 12,114 | |
978 | Mentors | [
"binary search",
"data structures",
"implementation"
] | null | null | In BerSoft $n$ programmers work, the programmer $i$ is characterized by a skill $r_i$.
A programmer $a$ can be a mentor of a programmer $b$ if and only if the skill of the programmer $a$ is strictly greater than the skill of the programmer $b$ $(r_a > r_b)$ and programmers $a$ and $b$ are not in a quarrel.
You are... | The first line contains two integers $n$ and $k$ $(2 \le n \le 2 \cdot 10^5$, $0 \le k \le \min(2 \cdot 10^5, \frac{n \cdot (n - 1)}{2}))$ — total number of programmers and number of pairs of programmers which are in a quarrel.
The second line contains a sequence of integers $r_1, r_2, \dots, r_n$ $(1 \le r_i \le 10^{... | Print $n$ integers, the $i$-th number should be equal to the number of programmers, for which the $i$-th programmer can be a mentor. Programmers are numbered in the same order that their skills are given in the input. | [
"4 2\n10 4 10 15\n1 2\n4 3\n",
"10 4\n5 4 1 5 4 3 7 1 2 5\n4 6\n2 1\n10 8\n3 5\n"
] | [
"0 0 1 2 \n",
"5 4 0 5 3 3 9 0 2 5 \n"
] | In the first example, the first programmer can not be mentor of any other (because only the second programmer has a skill, lower than first programmer skill, but they are in a quarrel). The second programmer can not be mentor of any other programmer, because his skill is minimal among others. The third programmer can b... | [
{
"input": "4 2\n10 4 10 15\n1 2\n4 3",
"output": "0 0 1 2 "
},
{
"input": "10 4\n5 4 1 5 4 3 7 1 2 5\n4 6\n2 1\n10 8\n3 5",
"output": "5 4 0 5 3 3 9 0 2 5 "
},
{
"input": "2 0\n3 1",
"output": "1 0 "
},
{
"input": "2 0\n1 1",
"output": "0 0 "
},
{
"input": "10 35... | 0 | 0 | -1 | 12,133 | |
498 | Array and Operations | [
"flows",
"graph matchings",
"number theory"
] | null | null | You have written on a piece of paper an array of *n* positive integers *a*[1],<=*a*[2],<=...,<=*a*[*n*] and *m* good pairs of integers (*i*1,<=*j*1),<=(*i*2,<=*j*2),<=...,<=(*i**m*,<=*j**m*). Each good pair (*i**k*,<=*j**k*) meets the following conditions: *i**k*<=+<=*j**k* is an odd number and 1<=≤<=*i**k*<=<<=*j**... | The first line contains two space-separated integers *n*, *m* (2<=≤<=*n*<=≤<=100, 1<=≤<=*m*<=≤<=100).
The second line contains *n* space-separated integers *a*[1],<=*a*[2],<=...,<=*a*[*n*] (1<=≤<=*a*[*i*]<=≤<=109) — the description of the array.
The following *m* lines contain the description of good pairs. The *k*-t... | Output the answer for the problem. | [
"3 2\n8 3 8\n1 2\n2 3\n",
"3 2\n8 12 8\n1 2\n2 3\n"
] | [
"0\n",
"2\n"
] | none | [
{
"input": "3 2\n8 3 8\n1 2\n2 3",
"output": "0"
},
{
"input": "3 2\n8 12 8\n1 2\n2 3",
"output": "2"
},
{
"input": "6 4\n35 33 46 58 7 61\n4 5\n3 6\n5 6\n1 6",
"output": "0"
},
{
"input": "10 25\n262144 262144 64 64 16 134217728 32 512 32 8192\n1 2\n3 10\n5 8\n9 10\n2 5\n5 1... | 186 | 2,150,400 | -1 | 12,151 | |
818 | Sofa Thief | [
"brute force",
"implementation"
] | null | null | Yet another round on DecoForces is coming! Grandpa Maks wanted to participate in it but someone has stolen his precious sofa! And how can one perform well with such a major loss?
Fortunately, the thief had left a note for Grandpa Maks. This note got Maks to the sofa storehouse. Still he had no idea which sofa belongs ... | The first line contains one integer number *d* (1<=≤<=*d*<=≤<=105) — the number of sofas in the storehouse.
The second line contains two integer numbers *n*, *m* (1<=≤<=*n*,<=*m*<=≤<=105) — the size of the storehouse.
Next *d* lines contains four integer numbers *x*1, *y*1, *x*2, *y*2 (1<=≤<=*x*1,<=*x*2<=≤<=*n*, 1<=≤... | Print the number of the sofa for which all the conditions are met. Sofas are numbered 1 through *d* as given in input. If there is no such sofa then print -1. | [
"2\n3 2\n3 1 3 2\n1 2 2 2\n1 0 0 1\n",
"3\n10 10\n1 2 1 1\n5 5 6 5\n6 4 5 4\n2 1 2 0\n",
"2\n2 2\n2 1 1 1\n1 2 2 2\n1 0 0 0\n"
] | [
"1\n",
"2\n",
"-1\n"
] | Let's consider the second example.
- The first sofa has 0 to its left, 2 sofas to its right ((1, 1) is to the left of both (5, 5) and (5, 4)), 0 to its top and 2 to its bottom (both 2nd and 3rd sofas are below). - The second sofa has *cnt*<sub class="lower-index">*l*</sub> = 2, *cnt*<sub class="lower-index">*r*</su... | [
{
"input": "2\n3 2\n3 1 3 2\n1 2 2 2\n1 0 0 1",
"output": "1"
},
{
"input": "3\n10 10\n1 2 1 1\n5 5 6 5\n6 4 5 4\n2 1 2 0",
"output": "2"
},
{
"input": "2\n2 2\n2 1 1 1\n1 2 2 2\n1 0 0 0",
"output": "-1"
},
{
"input": "1\n1 2\n1 1 1 2\n0 0 0 0",
"output": "1"
},
{
... | 498 | 17,305,600 | 3 | 12,192 | |
506 | Mr. Kitayuta's Colorful Graph | [
"brute force",
"dfs and similar",
"dsu",
"graphs"
] | null | null | Mr. Kitayuta has just bought an undirected graph with *n* vertices and *m* edges. The vertices of the graph are numbered from 1 to *n*. Each edge, namely edge *i*, has a color *c**i*, connecting vertex *a**i* and *b**i*.
Mr. Kitayuta wants you to process the following *q* queries.
In the *i*-th query, he gives you tw... | The first line of the input contains space-separated two integers - *n* and *m*(2<=≤<=*n*<=≤<=105,<=1<=≤<=*m*<=≤<=105), denoting the number of the vertices and the number of the edges, respectively.
The next *m* lines contain space-separated three integers - *a**i*, *b**i*(1<=≤<=*a**i*<=<<=*b**i*<=≤<=*n*) and *c**i... | For each query, print the answer in a separate line. | [
"4 5\n1 2 1\n1 2 2\n2 3 1\n2 3 3\n2 4 3\n3\n1 2\n3 4\n1 4\n",
"5 7\n1 5 1\n2 5 1\n3 5 1\n4 5 1\n1 2 2\n2 3 2\n3 4 2\n5\n1 5\n5 1\n2 5\n1 5\n1 4\n"
] | [
"2\n1\n0\n",
"1\n1\n1\n1\n2\n"
] | Let's consider the first sample.
- Vertex 1 and vertex 2 are connected by color 1 and 2. - Vertex 3 and vertex 4 are connected by color 3. - Vertex 1 and vertex 4 are not connected by any single color. | [
{
"input": "4 5\n1 2 1\n1 2 2\n2 3 1\n2 3 3\n2 4 3\n3\n1 2\n3 4\n1 4",
"output": "2\n1\n0"
},
{
"input": "5 7\n1 5 1\n2 5 1\n3 5 1\n4 5 1\n1 2 2\n2 3 2\n3 4 2\n5\n1 5\n5 1\n2 5\n1 5\n1 4",
"output": "1\n1\n1\n1\n2"
},
{
"input": "2 1\n1 2 1\n1\n1 2",
"output": "1"
},
{
"input... | 0 | 0 | -1 | 12,214 | |
0 | none | [
"none"
] | null | null | You are given *n* integers *a*1,<=*a*2,<=...,<=*a**n*. Denote this list of integers as *T*.
Let *f*(*L*) be a function that takes in a non-empty list of integers *L*.
The function will output another integer as follows:
- First, all integers in *L* are padded with leading zeros so they are all the same length as t... | The first line contains the integer *n* (1<=≤<=*n*<=≤<=1<=000<=000) — the size of list *T*.
The next line contains *n* space-separated integers, *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=999<=999) — the elements of the list. | Output a single integer, the answer to the problem. | [
"3\n123 321 555\n",
"1\n999999\n",
"10\n1 1 1 1 1 1 1 1 1 1\n"
] | [
"292711924\n",
"997992010006992\n",
"28160\n"
] | For the first sample, the nonzero values of *G* are *G*(121) = 144 611 577, *G*(123) = 58 401 999, *G*(321) = 279 403 857, *G*(555) = 170 953 875. The bitwise XOR of these numbers is equal to 292 711 924.
For example, <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/53a1c46c7cd2d3d56e89fe99... | [
{
"input": "3\n123 321 555",
"output": "292711924"
},
{
"input": "1\n999999",
"output": "997992010006992"
},
{
"input": "10\n1 1 1 1 1 1 1 1 1 1",
"output": "28160"
},
{
"input": "3\n534185 663311 372491",
"output": "1081839767962341"
},
{
"input": "10\n595436 647... | 3,000 | 11,980,800 | 0 | 12,219 | |
955 | Scissors | [
"brute force",
"strings"
] | null | null | Jenya has recently acquired quite a useful tool — *k*-scissors for cutting strings. They are generally used for cutting out two non-intersecting substrings of length *k* from an arbitrary string *s* (its length should be at least 2·*k* in order to perform this operation) and concatenating them afterwards (preserving th... | The first line contains three integers *n*, *m*, *k* (2<=≤<=*m*<=≤<=2·*k*<=≤<=*n*<=≤<=5·105) — length of *s*, length of *t* and the aforementioned scissors' parameter correspondingly.
The next two lines feature *s* and *t* consisting of lowercase latin letters. | If there is no answer, print «No».
Otherwise print «Yes» and two integers *L* and *R* denoting the indexes where cutted substrings start (1-indexed). If there are several possible answers, output any. | [
"7 4 3\nbaabaab\naaaa\n",
"6 3 2\ncbcbcb\nbcc\n",
"7 5 3\naabbaaa\naaaaa\n"
] | [
"Yes\n1 5\n",
"Yes\n2 5\n",
"No\n"
] | In the first sample case you can cut out two substrings starting at 1 and 5. The resulting string baaaab contains aaaa as a substring.
In the second sample case the resulting string is bccb. | [
{
"input": "7 4 3\nbaabaab\naaaa",
"output": "Yes\n1 5"
},
{
"input": "6 3 2\ncbcbcb\nbcc",
"output": "Yes\n2 5"
},
{
"input": "7 5 3\naabbaaa\naaaaa",
"output": "No"
},
{
"input": "16 6 4\nabcdcadbbbcacdca\ndcadbc",
"output": "Yes\n4 10"
},
{
"input": "81 5 3\nac... | 78 | 6,963,200 | 0 | 12,240 | |
433 | Ryouko's Memory Note | [
"implementation",
"math",
"sortings"
] | null | null | Ryouko is an extremely forgetful girl, she could even forget something that has just happened. So in order to remember, she takes a notebook with her, called Ryouko's Memory Note. She writes what she sees and what she hears on the notebook, and the notebook became her memory.
Though Ryouko is forgetful, she is also bo... | The first line of input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=105).
The next line contains *m* integers separated by spaces: *a*1,<=*a*2,<=...,<=*a**m* (1<=≤<=*a**i*<=≤<=*n*). | Print a single integer — the minimum number of pages Ryouko needs to turn. | [
"4 6\n1 2 3 4 3 2\n",
"10 5\n9 4 3 8 8\n"
] | [
"3\n",
"6\n"
] | In the first sample, the optimal solution is to merge page 4 to 3, after merging sequence *a* becomes {1, 2, 3, 3, 3, 2}, so the number of pages Ryouko needs to turn is |1 - 2| + |2 - 3| + |3 - 3| + |3 - 3| + |3 - 2| = 3.
In the second sample, optimal solution is achieved by merging page 9 to 4. | [
{
"input": "4 6\n1 2 3 4 3 2",
"output": "3"
},
{
"input": "10 5\n9 4 3 8 8",
"output": "6"
},
{
"input": "5 10\n2 5 2 2 3 5 3 2 1 3",
"output": "7"
},
{
"input": "10 20\n6 3 9 6 1 9 1 9 8 2 7 6 9 8 4 7 1 2 4 2",
"output": "52"
},
{
"input": "100 100\n28 28 28 28 ... | 78 | 512,000 | 0 | 12,281 | |
959 | Mahmoud and Ehab and the xor-MST | [
"bitmasks",
"dp",
"graphs",
"implementation",
"math"
] | null | null | Ehab is interested in the bitwise-xor operation and the special graphs. Mahmoud gave him a problem that combines both. He has a complete graph consisting of *n* vertices numbered from 0 to *n*<=-<=1. For all 0<=≤<=*u*<=<<=*v*<=<<=*n*, vertex *u* and vertex *v* are connected with an undirected edge that has weight... | The only line contains an integer *n* (2<=≤<=*n*<=≤<=1012), the number of vertices in the graph. | The only line contains an integer *x*, the weight of the graph's minimum spanning tree. | [
"4\n"
] | [
"4"
] | In the first sample: <img class="tex-graphics" src="https://espresso.codeforces.com/20e1655a0ec8e8d788bd2f5af92f93c968c65f3c.png" style="max-width: 100.0%;max-height: 100.0%;"/> The weight of the minimum spanning tree is 1+2+1=4. | [
{
"input": "4",
"output": "4"
},
{
"input": "10",
"output": "21"
},
{
"input": "2",
"output": "1"
},
{
"input": "1000000000000",
"output": "20140978692096"
},
{
"input": "999999999999",
"output": "20140978692095"
},
{
"input": "23131234",
"output":... | 46 | 0 | -1 | 12,320 | |
32 | Flea | [
"math"
] | C. Flea | 2 | 256 | It is known that fleas in Berland can jump only vertically and horizontally, and the length of the jump is always equal to *s* centimeters. A flea has found herself at the center of some cell of the checked board of the size *n*<=×<=*m* centimeters (each cell is 1<=×<=1 centimeters). She can jump as she wishes for an a... | The first line contains three integers *n*, *m*, *s* (1<=≤<=*n*,<=*m*,<=*s*<=≤<=106) — length of the board, width of the board and length of the flea's jump. | Output the only integer — the number of the required starting positions of the flea. | [
"2 3 1000000\n",
"3 3 2\n"
] | [
"6\n",
"4\n"
] | none | [
{
"input": "2 3 1000000",
"output": "6"
},
{
"input": "3 3 2",
"output": "4"
},
{
"input": "1 2 3",
"output": "2"
},
{
"input": "4 5 6",
"output": "20"
},
{
"input": "9 8 7",
"output": "8"
},
{
"input": "1000 1000 1000",
"output": "1000000"
},
... | 92 | 0 | 3.977 | 12,358 |
87 | Trains | [
"implementation",
"math"
] | A. Trains | 2 | 256 | Vasya the programmer lives in the middle of the Programming subway branch. He has two girlfriends: Dasha and Masha, who live at the different ends of the branch, each one is unaware of the other one's existence.
When Vasya has some free time, he goes to one of his girlfriends. He descends into the subway at some time,... | The first line contains two integers *a* and *b* (*a*<=≠<=*b*,<=1<=≤<=*a*,<=*b*<=≤<=106). | Print "Dasha" if Vasya will go to Dasha more frequently, "Masha" if he will go to Masha more frequently, or "Equal" if he will go to both girlfriends with the same frequency. | [
"3 7\n",
"5 3\n",
"2 3\n"
] | [
"Dasha\n",
"Masha\n",
"Equal\n"
] | Let's take a look at the third sample. Let the trains start to go at the zero moment of time. It is clear that the moments of the trains' arrival will be periodic with period 6. That's why it is enough to show that if Vasya descends to the subway at a moment of time inside the interval (0, 6], he will go to both girls ... | [
{
"input": "3 7",
"output": "Dasha"
},
{
"input": "5 3",
"output": "Masha"
},
{
"input": "2 3",
"output": "Equal"
},
{
"input": "31 88",
"output": "Dasha"
},
{
"input": "8 75",
"output": "Dasha"
},
{
"input": "32 99",
"output": "Dasha"
},
{
... | 124 | 0 | 3.969 | 12,385 |
999 | Reachability from the Capital | [
"dfs and similar",
"graphs",
"greedy"
] | null | null | There are $n$ cities and $m$ roads in Berland. Each road connects a pair of cities. The roads in Berland are one-way.
What is the minimum number of new roads that need to be built to make all the cities reachable from the capital?
New roads will also be one-way. | The first line of input consists of three integers $n$, $m$ and $s$ ($1 \le n \le 5000, 0 \le m \le 5000, 1 \le s \le n$) — the number of cities, the number of roads and the index of the capital. Cities are indexed from $1$ to $n$.
The following $m$ lines contain roads: road $i$ is given as a pair of cities $u_i$, $v_... | Print one integer — the minimum number of extra roads needed to make all the cities reachable from city $s$. If all the cities are already reachable from $s$, print 0. | [
"9 9 1\n1 2\n1 3\n2 3\n1 5\n5 6\n6 1\n1 8\n9 8\n7 1\n",
"5 4 5\n1 2\n2 3\n3 4\n4 1\n"
] | [
"3\n",
"1\n"
] | The first example is illustrated by the following:
For example, you can add roads ($6, 4$), ($7, 9$), ($1, 7$) to make all the cities reachable from $s = 1$.
The second example is illustrated by the following:
In this example, you can add any one of the roads ($5, 1$), ($5, 2$), ($5, 3$), ($5, 4$) to make all the ci... | [
{
"input": "9 9 1\n1 2\n1 3\n2 3\n1 5\n5 6\n6 1\n1 8\n9 8\n7 1",
"output": "3"
},
{
"input": "5 4 5\n1 2\n2 3\n3 4\n4 1",
"output": "1"
},
{
"input": "5000 0 2956",
"output": "4999"
},
{
"input": "2 0 2",
"output": "1"
},
{
"input": "2 1 1\n1 2",
"output": "0"... | 46 | 204,800 | 0 | 12,388 | |
883 | Downloading B++ | [
"binary search",
"implementation"
] | null | null | Only *T* milliseconds left before the start of well-known online programming contest Codehorses Round 2017.
Polycarp needs to download B++ compiler to take part in the contest. The size of the file is *f* bytes.
Polycarp's internet tariff allows to download data at the rate of one byte per *t*0 milliseconds. This tar... | The first line contains three integer numbers *f*, *T* and *t*0 (1<=≤<=*f*,<=*T*,<=*t*0<=≤<=107) — size of the file to download (in bytes), maximal time to download the file (in milliseconds) and number of milliseconds to download one byte using the regular internet tariff.
The second line contains a description of th... | Print the minimum amount of money that Polycarp needs to pay to download B++ compiler no more than in *T* milliseconds. If there is no solution, print the only integer -1. | [
"120 964 20\n26 8 8\n13 10 4\n",
"10 200 20\n1 1 1\n2 2 3\n",
"8 81 11\n4 10 16\n3 10 12\n",
"8 79 11\n4 10 16\n3 10 12\n"
] | [
"40\n",
"0\n",
"28\n",
"-1\n"
] | In the first example Polycarp has to buy the first additional package 5 times and do not buy the second additional package. He downloads 120 bytes (of total 26·5 = 130 bytes) in 120·8 = 960 milliseconds (960 ≤ 964). He spends 8·5 = 40 burles on it.
In the second example Polycarp has enough time to download 10 bytes. I... | [
{
"input": "120 964 20\n26 8 8\n13 10 4",
"output": "40"
},
{
"input": "10 200 20\n1 1 1\n2 2 3",
"output": "0"
},
{
"input": "8 81 11\n4 10 16\n3 10 12",
"output": "28"
},
{
"input": "8 79 11\n4 10 16\n3 10 12",
"output": "-1"
},
{
"input": "62 10000 209\n95 106 ... | 46 | 0 | 0 | 12,395 | |
436 | Dungeons and Candies | [
"dsu",
"graphs",
"greedy",
"trees"
] | null | null | During the loading of the game "Dungeons and Candies" you are required to get descriptions of *k* levels from the server. Each description is a map of an *n*<=×<=*m* checkered rectangular field. Some cells of the field contain candies (each cell has at most one candy). An empty cell is denoted as "." on the map, but if... | The first line contains four integers *n*,<=*m*,<=*k*,<=*w* (1<=≤<=*n*,<=*m*<=≤<=10; 1<=≤<=*k*,<=*w*<=≤<=1000). Then follows the description of *k* levels. Each level is described by *n* lines, each line contains *m* characters. Each character is either a letter of the English alphabet or a dot ("."). Please note that ... | In the first line print the required minimum number of transferred bytes.
Then print *k* pairs of integers *x*1,<=*y*1,<=*x*2,<=*y*2,<=...,<=*x**k*,<=*y**k*, describing the way to transfer levels. Pair *x**i*, *y**i* means that level *x**i* needs to be transferred by way *y**i*. If *y**i* equals 0, that means that the... | [
"2 3 3 2\nA.A\n...\nA.a\n..C\nX.Y\n...\n",
"1 1 4 1\nA\n.\nB\n.\n",
"1 3 5 2\nABA\nBBB\nBBA\nBAB\nABB\n"
] | [
"14\n1 0\n2 1\n3 1\n",
"3\n1 0\n2 0\n4 2\n3 0\n",
"11\n1 0\n3 1\n2 3\n4 2\n5 1\n"
] | none | [
{
"input": "1 1 4 1\nA\n.\nB\n.",
"output": "3\n1 0\n2 0\n4 2\n3 0"
},
{
"input": "1 3 5 2\nABA\nBBB\nBBA\nBAB\nABB",
"output": "11\n1 0\n3 1\n2 3\n4 2\n5 1"
},
{
"input": "2 2 5 1\n..\nBA\n.A\nB.\n..\nA.\nAB\n.B\n..\n..",
"output": "12\n1 0\n2 1\n3 1\n5 3\n4 5"
},
{
"input":... | 108 | 307,200 | 0 | 12,421 | |
237 | Young Table | [
"implementation",
"sortings"
] | null | null | You've got table *a*, consisting of *n* rows, numbered from 1 to *n*. The *i*-th line of table *a* contains *c**i* cells, at that for all *i* (1<=<<=*i*<=≤<=*n*) holds *c**i*<=≤<=*c**i*<=-<=1.
Let's denote *s* as the total number of cells of table *a*, that is, . We know that each cell of the table contains a sing... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=50) that shows the number of rows in the table. The second line contains *n* space-separated integers *c**i* (1<=≤<=*c**i*<=≤<=50; *c**i*<=≤<=*c**i*<=-<=1) — the numbers of cells on the corresponding rows.
Next *n* lines contain table *а*. The *i*-th of them ... | In the first line print a single integer *m* (0<=≤<=*m*<=≤<=*s*), representing the number of performed swaps.
In the next *m* lines print the description of these swap operations. In the *i*-th line print four space-separated integers *x**i*,<=*y**i*,<=*p**i*,<=*q**i* (1<=≤<=*x**i*,<=*p**i*<=≤<=*n*; 1<=≤<=*y**i*<=≤<=*... | [
"3\n3 2 1\n4 3 5\n6 1\n2\n",
"1\n4\n4 3 2 1\n"
] | [
"2\n1 1 2 2\n2 1 3 1\n",
"2\n1 1 1 4\n1 2 1 3\n"
] | none | [
{
"input": "3\n3 2 1\n4 3 5\n6 1\n2",
"output": "2\n1 1 2 2\n2 1 3 1"
},
{
"input": "1\n4\n4 3 2 1",
"output": "2\n1 1 1 4\n1 2 1 3"
},
{
"input": "5\n4 4 3 3 1\n14 13 4 15\n11 1 2 5\n7 6 10\n8 9 3\n12",
"output": "13\n1 1 2 2\n1 2 2 3\n1 3 4 3\n1 4 4 3\n2 1 2 4\n2 2 3 2\n2 3 3 1\n2 ... | 248 | 0 | 0 | 12,423 | |
393 | Three matrices | [] | null | null | Chubby Yang is studying linear equations right now. He came up with a nice problem. In the problem you are given an *n*<=×<=*n* matrix *W*, consisting of integers, and you should find two *n*<=×<=*n* matrices *A* and *B*, all the following conditions must hold:
- *A**ij*<==<=*A**ji*, for all *i*,<=*j* (1<=≤<=*i*,<=*... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=170). Each of the following *n* lines contains *n* integers. The *j*-th integer in the *i*-th line is *W**ij* (0<=≤<=|*W**ij*|<=<<=1717). | The first *n* lines must contain matrix *A*. The next *n* lines must contain matrix *B*. Print the matrices in the format equal to format of matrix *W* in input. It is guaranteed that the answer exists. If there are multiple answers, you are allowed to print any of them.
The answer will be considered correct if the ab... | [
"2\n1 4\n3 2\n",
"3\n1 2 3\n4 5 6\n7 8 9\n"
] | [
"1.00000000 3.50000000\n3.50000000 2.00000000\n0.00000000 0.50000000\n-0.50000000 0.00000000\n",
"1.00000000 3.00000000 5.00000000\n3.00000000 5.00000000 7.00000000\n5.00000000 7.00000000 9.00000000\n0.00000000 -1.00000000 -2.00000000\n1.00000000 0.00000000 -1.00000000\n2.00000000 1.00000000 0.00000000\n"
] | none | [
{
"input": "2\n1 4\n3 2",
"output": "1.00000000 3.50000000\n3.50000000 2.00000000\n0.00000000 0.50000000\n-0.50000000 0.00000000"
},
{
"input": "3\n1 2 3\n4 5 6\n7 8 9",
"output": "1.00000000 3.00000000 5.00000000\n3.00000000 5.00000000 7.00000000\n5.00000000 7.00000000 9.00000000\n0.00000000 -1... | 233 | 3,481,600 | 3 | 12,425 | |
682 | Alyona and Strings | [
"dp",
"strings"
] | null | null | After returned from forest, Alyona started reading a book. She noticed strings *s* and *t*, lengths of which are *n* and *m* respectively. As usual, reading bored Alyona and she decided to pay her attention to strings *s* and *t*, which she considered very similar.
Alyona has her favourite positive integer *k* and bec... | In the first line of the input three integers *n*, *m*, *k* (1<=≤<=*n*,<=*m*<=≤<=1000, 1<=≤<=*k*<=≤<=10) are given — the length of the string *s*, the length of the string *t* and Alyona's favourite number respectively.
The second line of the input contains string *s*, consisting of lowercase English letters.
The thi... | In the only line print the only non-negative integer — the sum of the lengths of the strings in a desired sequence.
It is guaranteed, that at least one desired sequence exists. | [
"3 2 2\nabc\nab\n",
"9 12 4\nbbaaababb\nabbbabbaaaba\n"
] | [
"2\n",
"7\n"
] | The following image describes the answer for the second sample case: | [
{
"input": "3 2 2\nabc\nab",
"output": "2"
},
{
"input": "9 12 4\nbbaaababb\nabbbabbaaaba",
"output": "7"
},
{
"input": "11 11 4\naaababbabbb\nbbbaaaabaab",
"output": "7"
},
{
"input": "15 9 4\nababaaabbaaaabb\nbbaababbb",
"output": "8"
},
{
"input": "2 7 1\nbb\nb... | 467 | 307,200 | 0 | 12,439 | |
774 | Stepan's Series | [
"*special",
"dp"
] | null | null | Well, the series which Stepan watched for a very long time, ended. In total, the series had *n* episodes. For each of them, Stepan remembers either that he definitely has watched it, or that he definitely hasn't watched it, or he is unsure, has he watched this episode or not.
Stepan's dissatisfaction is the maximum n... | The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=100, 0<=≤<=*k*<=≤<=*n*) — the number of episodes in the series and the dissatisfaction which should be checked.
The second line contains the sequence which consists of *n* symbols "Y", "N" and "?". If the *i*-th symbol equals "Y", Stepan remembers that h... | If Stepan's dissatisfaction can be exactly equal to *k*, then print "YES" (without qoutes). Otherwise print "NO" (without qoutes). | [
"5 2\nNYNNY\n",
"6 1\n????NN\n"
] | [
"YES\n",
"NO\n"
] | In the first test Stepan remembers about all the episodes whether he has watched them or not. His dissatisfaction is 2, because he hasn't watch two episodes in a row — the episode number 3 and the episode number 4. The answer is "YES", because *k* = 2.
In the second test *k* = 1, Stepan's dissatisfaction is greater th... | [
{
"input": "5 2\nNYNNY",
"output": "YES"
},
{
"input": "6 1\n????NN",
"output": "NO"
},
{
"input": "100 8\nNYNNY?YNNNNNN?NNNNNYNY?YYNYNN?NNNY??NNYNYNNNYNNNYNNNNNNNNY?NNNYNYN?NNNY?YY?NNYNN?NNNYNNYNNYN?NNYNYNN",
"output": "YES"
},
{
"input": "10 1\nNY???NY?Y?",
"output": "Y... | 62 | 5,529,600 | 0 | 12,452 | |
55 | Smallest number | [
"brute force"
] | B. Smallest number | 2 | 256 | Recently, Vladimir got bad mark in algebra again. To avoid such unpleasant events in future he decided to train his arithmetic skills. He wrote four integer numbers *a*, *b*, *c*, *d* on the blackboard. During each of the next three minutes he took two numbers from the blackboard (not necessarily adjacent) and replaced... | First line contains four integers separated by space: 0<=≤<=*a*,<=*b*,<=*c*,<=*d*<=≤<=1000 — the original numbers. Second line contains three signs ('+' or '*' each) separated by space — the sequence of the operations in the order of performing. ('+' stands for addition, '*' — multiplication) | Output one integer number — the minimal result which can be obtained.
Please, do not use %lld specificator to read or write 64-bit integers in C++. It is preffered to use cin (also you may use %I64d). | [
"1 1 1 1\n+ + *\n",
"2 2 2 2\n* * +\n",
"1 2 3 4\n* + +\n"
] | [
"3\n",
"8\n",
"9\n"
] | none | [
{
"input": "1 1 1 1\n+ + *",
"output": "3"
},
{
"input": "2 2 2 2\n* * +",
"output": "8"
},
{
"input": "1 2 3 4\n* + +",
"output": "9"
},
{
"input": "15 1 3 1\n* * +",
"output": "18"
},
{
"input": "8 1 7 14\n+ + +",
"output": "30"
},
{
"input": "7 17 3... | 62 | 0 | 0 | 12,482 |
53 | Little Frog | [
"constructive algorithms"
] | C. Little Frog | 2 | 256 | Once upon a time a little frog whose name was Vasya decided to travel around his home swamp. Overall there are *n* mounds on the swamp, located on one line. The distance between the neighboring mounds is one meter. Vasya wants to visit all the mounds in one day; besides, he wants to visit each one exactly once. For tha... | The single line contains a number *n* (1<=≤<=*n*<=≤<=104) which is the number of mounds. | Print *n* integers *p**i* (1<=≤<=*p**i*<=≤<=*n*) which are the frog's route plan.
- All the *p**i*'s should be mutually different. - All the |*p**i*–*p**i*<=+<=1|'s should be mutually different (1<=≤<=*i*<=≤<=*n*<=-<=1).
If there are several solutions, output any. | [
"2\n",
"3\n"
] | [
"1 2 ",
"1 3 2 "
] | none | [
{
"input": "2",
"output": "1 2 "
},
{
"input": "3",
"output": "1 3 2 "
},
{
"input": "4",
"output": "1 4 2 3 "
},
{
"input": "5",
"output": "1 5 2 4 3 "
},
{
"input": "6",
"output": "1 6 2 5 3 4 "
},
{
"input": "1",
"output": "1 "
},
{
"inp... | 92 | 0 | 0 | 12,509 |
1,005 | Median on Segments (Permutations Edition) | [
"sortings"
] | null | null | You are given a permutation $p_1, p_2, \dots, p_n$. A permutation of length $n$ is a sequence such that each integer between $1$ and $n$ occurs exactly once in the sequence.
Find the number of pairs of indices $(l, r)$ ($1 \le l \le r \le n$) such that the value of the median of $p_l, p_{l+1}, \dots, p_r$ is exactly t... | The first line contains integers $n$ and $m$ ($1 \le n \le 2\cdot10^5$, $1 \le m \le n$) — the length of the given sequence and the required value of the median.
The second line contains a permutation $p_1, p_2, \dots, p_n$ ($1 \le p_i \le n$). Each integer between $1$ and $n$ occurs in $p$ exactly once. | Print the required number. | [
"5 4\n2 4 5 3 1\n",
"5 5\n1 2 3 4 5\n",
"15 8\n1 15 2 14 3 13 4 8 12 5 11 6 10 7 9\n"
] | [
"4\n",
"1\n",
"48\n"
] | In the first example, the suitable pairs of indices are: $(1, 3)$, $(2, 2)$, $(2, 3)$ and $(2, 4)$. | [
{
"input": "5 4\n2 4 5 3 1",
"output": "4"
},
{
"input": "5 5\n1 2 3 4 5",
"output": "1"
},
{
"input": "15 8\n1 15 2 14 3 13 4 8 12 5 11 6 10 7 9",
"output": "48"
},
{
"input": "1 1\n1",
"output": "1"
},
{
"input": "2 1\n1 2",
"output": "2"
},
{
"input... | 77 | 3,072,000 | -1 | 12,519 | |
0 | none | [
"none"
] | null | null | We'll call an array of *n* non-negative integers *a*[1],<=*a*[2],<=...,<=*a*[*n*] interesting, if it meets *m* constraints. The *i*-th of the *m* constraints consists of three integers *l**i*, *r**i*, *q**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*) meaning that value should be equal to *q**i*.
Your task is to find any inte... | The first line contains two integers *n*, *m* (1<=≤<=*n*<=≤<=105, 1<=≤<=*m*<=≤<=105) — the number of elements in the array and the number of limits.
Each of the next *m* lines contains three integers *l**i*, *r**i*, *q**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*, 0<=≤<=*q**i*<=<<=230) describing the *i*-th limit. | If the interesting array exists, in the first line print "YES" (without the quotes) and in the second line print *n* integers *a*[1],<=*a*[2],<=...,<=*a*[*n*] (0<=≤<=*a*[*i*]<=<<=230) decribing the interesting array. If there are multiple answers, print any of them.
If the interesting array doesn't exist, print "NO... | [
"3 1\n1 3 3\n",
"3 2\n1 3 3\n1 3 2\n"
] | [
"YES\n3 3 3\n",
"NO\n"
] | none | [
{
"input": "3 1\n1 3 3",
"output": "YES\n3 3 3"
},
{
"input": "3 2\n1 3 3\n1 3 2",
"output": "NO"
},
{
"input": "3 2\n1 2 536870912\n2 3 536870911",
"output": "YES\n536870912 1073741823 536870911"
},
{
"input": "1 1\n1 1 10",
"output": "YES\n10"
},
{
"input": "1 2... | 77 | 1,843,200 | 0 | 12,561 | |
140 | New Year Contest | [
"greedy",
"sortings"
] | null | null | As Gerald sets the table, Alexander sends the greeting cards, and Sergey and his twins create an army of clone snowmen, Gennady writes a New Year contest.
The New Year contest begins at 18:00 (6.00 P.M.) on December 31 and ends at 6:00 (6.00 A.M.) on January 1. There are *n* problems for the contest. The penalty time ... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of the problems. The next line contains *n* space-separated integers *a**i* (1<=≤<=*a**i*<=≤<=720) — each number shows how much time in minutes Gennady will spend writing a solution to the problem. | Print two integers — the number of problems Gennady will solve and the total penalty time considering that he chooses the optimal strategy. | [
"3\n30 330 720\n"
] | [
"2 10\n"
] | In the sample, one of Gennady's possible optimal strategies is as follows. At 18:10 (6:10 PM) he begins to write the first problem and solves it in 30 minutes (18:40 or 6.40 P.M.). At 18:40 (6.40 P.M.) he begins to write the second problem. There are 320 minutes left before the New Year, so Gennady does not have the ti... | [
{
"input": "3\n30 330 720",
"output": "2 10"
},
{
"input": "1\n720",
"output": "0 0"
},
{
"input": "5\n100 200 300 400 500",
"output": "3 250"
},
{
"input": "7\n120 110 100 110 120 120 50",
"output": "6 420"
},
{
"input": "3\n350 340 360",
"output": "2 340"
... | 92 | 0 | 0 | 12,582 | |
909 | AND-permutations | [
"constructive algorithms"
] | null | null | Given an integer *N*, find two permutations:
1. Permutation *p* of numbers from 1 to *N* such that *p**i*<=≠<=*i* and *p**i*<=&<=*i*<==<=0 for all *i*<==<=1,<=2,<=...,<=*N*. 1. Permutation *q* of numbers from 1 to *N* such that *q**i*<=≠<=*i* and *q**i*<=&<=*i*<=≠<=0 for all *i*<==<=1,<=2,<=...,<=*N*.
&... | The input consists of one line containing a single integer *N* (1<=≤<=*N*<=≤<=105). | For each subtask, if the required permutation doesn't exist, output a single line containing the word "NO"; otherwise output the word "YES" in the first line and *N* elements of the permutation, separated by spaces, in the second line. If there are several possible permutations in a subtask, output any of them. | [
"3\n",
"6\n"
] | [
"NO\nNO\n",
"YES\n6 5 4 3 2 1 \nYES\n3 6 2 5 1 4\n"
] | none | [
{
"input": "3",
"output": "NO\nNO"
},
{
"input": "6",
"output": "YES\n6 5 4 3 2 1 \nYES\n3 6 2 5 1 4"
},
{
"input": "100000",
"output": "YES\n30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 32 31 94 93 92 91 90 89 88 87 86 85 84 83 82 81 80 79 78 77 7... | 62 | 5,529,600 | -1 | 12,586 | |
915 | Physical Education Lessons | [
"data structures",
"implementation",
"sortings"
] | null | null | This year Alex has finished school, and now he is a first-year student of Berland State University. For him it was a total surprise that even though he studies programming, he still has to attend physical education lessons. The end of the term is very soon, but, unfortunately, Alex still hasn't attended a single lesson... | The first line contains one integer *n*, and the second line — one integer *q* (1<=≤<=*n*<=≤<=109, 1<=≤<=*q*<=≤<=3·105) — the number of days left before the end of the term, and the number of orders, respectively.
Then *q* lines follow, *i*-th line containing three integers *l**i*, *r**i* and *k**i* representing *i*-t... | Print *q* integers. *i*-th of them must be equal to the number of working days left until the end of the term after the first *i* orders are published. | [
"4\n6\n1 2 1\n3 4 1\n2 3 2\n1 3 2\n2 4 1\n1 4 2\n"
] | [
"2\n0\n2\n3\n1\n4\n"
] | none | [
{
"input": "4\n6\n1 2 1\n3 4 1\n2 3 2\n1 3 2\n2 4 1\n1 4 2",
"output": "2\n0\n2\n3\n1\n4"
},
{
"input": "3\n8\n2 2 1\n3 3 2\n1 1 1\n1 3 2\n2 3 2\n3 3 1\n1 2 1\n2 2 2",
"output": "2\n2\n1\n3\n3\n2\n0\n1"
},
{
"input": "7\n10\n5 7 1\n5 6 2\n7 7 2\n6 7 2\n5 5 1\n3 6 2\n1 3 2\n5 6 1\n1 3 1\n... | 31 | 0 | 0 | 12,605 | |
845 | Shortest Path Problem? | [
"dfs and similar",
"graphs",
"math"
] | null | null | You are given an undirected graph with weighted edges. The length of some path between two vertices is the bitwise xor of weights of all edges belonging to this path (if some edge is traversed more than once, then it is included in bitwise xor the same number of times). You have to find the minimum length of path betwe... | The first line contains two numbers *n* and *m* (1<=≤<=*n*<=≤<=100000, *n*<=-<=1<=≤<=*m*<=≤<=100000) — the number of vertices and the number of edges, respectively.
Then *m* lines follow, each line containing three integer numbers *x*, *y* and *w* (1<=≤<=*x*,<=*y*<=≤<=*n*, 0<=≤<=*w*<=≤<=108). These numbers denote an e... | Print one number — the minimum length of path between vertices 1 and *n*. | [
"3 3\n1 2 3\n1 3 2\n3 2 0\n",
"2 2\n1 1 3\n1 2 3\n"
] | [
"2\n",
"0\n"
] | none | [
{
"input": "3 3\n1 2 3\n1 3 2\n3 2 0",
"output": "2"
},
{
"input": "2 2\n1 1 3\n1 2 3",
"output": "0"
},
{
"input": "10 20\n8 5 64\n5 6 48\n4 5 91\n10 1 2\n3 4 51\n8 2 74\n6 1 98\n3 10 24\n2 10 35\n8 7 52\n10 5 72\n5 9 25\n2 9 65\n7 4 69\n5 7 26\n7 2 44\n6 8 61\n3 5 43\n10 7 33\n4 2 28",... | 30 | 0 | 0 | 12,619 | |
0 | none | [
"none"
] | null | null | Родители Васи хотят, чтобы он как можно лучше учился. Поэтому если он получает подряд три положительные оценки («четвёрки» или «пятёрки»), они дарят ему подарок. Соответственно, оценки «единица», «двойка» и «тройка» родители Васи считают плохими. Когда Вася получает подряд три хорошие оценки, ему сразу вручают подарок,... | В первой строке входных данных следует целое положительное число *n* (3<=≤<=*n*<=≤<=1000) — количество оценок, полученных Васей.
Во второй строке входных данных следует последовательность из *n* чисел *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=5) — оценки, полученные Васей. Оценки заданы в том порядке, в котором Вас... | Выведите одно целое число — количество подарков, полученных Васей. | [
"6\n4 5 4 5 4 4\n",
"14\n1 5 4 5 2 4 4 5 5 4 3 4 5 5\n"
] | [
"2\n",
"3\n"
] | В первом примере Вася получит два подарка — за первые три положительные оценки и за следующую тройку положительных оценок соответственно. | [
{
"input": "6\n4 5 4 5 4 4",
"output": "2"
},
{
"input": "14\n1 5 4 5 2 4 4 5 5 4 3 4 5 5",
"output": "3"
},
{
"input": "3\n4 5 4",
"output": "1"
},
{
"input": "3\n4 5 1",
"output": "0"
},
{
"input": "4\n5 4 3 5",
"output": "0"
},
{
"input": "10\n4 4 5... | 30 | 4,608,000 | -1 | 12,637 | |
988 | Substrings Sort | [
"sortings",
"strings"
] | null | null | You are given $n$ strings. Each string consists of lowercase English letters. Rearrange (reorder) the given strings in such a way that for every string, all strings that are placed before it are its substrings.
String $a$ is a substring of string $b$ if it is possible to choose several consecutive letters in $b$ in su... | The first line contains an integer $n$ ($1 \le n \le 100$) — the number of strings.
The next $n$ lines contain the given strings. The number of letters in each string is from $1$ to $100$, inclusive. Each string consists of lowercase English letters.
Some strings might be equal. | If it is impossible to reorder $n$ given strings in required order, print "NO" (without quotes).
Otherwise print "YES" (without quotes) and $n$ given strings in required order. | [
"5\na\naba\nabacaba\nba\naba\n",
"5\na\nabacaba\nba\naba\nabab\n",
"3\nqwerty\nqwerty\nqwerty\n"
] | [
"YES\na\nba\naba\naba\nabacaba\n",
"NO\n",
"YES\nqwerty\nqwerty\nqwerty\n"
] | In the second example you cannot reorder the strings because the string "abab" is not a substring of the string "abacaba". | [
{
"input": "5\na\naba\nabacaba\nba\naba",
"output": "YES\na\nba\naba\naba\nabacaba"
},
{
"input": "5\na\nabacaba\nba\naba\nabab",
"output": "NO"
},
{
"input": "3\nqwerty\nqwerty\nqwerty",
"output": "YES\nqwerty\nqwerty\nqwerty"
},
{
"input": "1\nwronganswer",
"output": "Y... | 31 | 0 | 0 | 12,646 | |
267 | Berland Traffic | [
"math",
"matrices"
] | null | null | Berland traffic is very different from traffic in other countries. The capital of Berland consists of *n* junctions and *m* roads. Each road connects a pair of junctions. There can be multiple roads between a pair of junctions. For each road we know its capacity: value *c**i* is the maximum number of cars that can driv... | The first line contains a positive integer *n* — the number of junctions (2<=≤<=*n*<=≤<=100). The second line contains integer *m* (1<=≤<=*m*<=≤<=5000) — the number of roads. Next *m* lines contain the roads' descriptions. Each road contains a group of three numbers *a**i*, *b**i*, *c**i*, where *a**i*,<=*b**i* are the... | In the first line print the required largest traffic across the city. Then print *m* lines, on each line print the speed, at which the traffic moves along the corresponding road. If the direction doesn't match the order of the junctions, given in the input, then print the traffic with the minus sign. Print the numbers ... | [
"2\n3\n1 2 2\n1 2 4\n2 1 1000\n",
"7\n11\n1 2 7\n1 2 7\n1 3 7\n1 4 7\n2 3 7\n2 5 7\n3 6 7\n4 7 7\n5 4 7\n5 6 7\n6 7 7\n"
] | [
"6.00000\n2.00000\n2.00000\n-2.00000\n",
"13.00000\n2.00000\n2.00000\n3.00000\n6.00000\n1.00000\n3.00000\n4.00000\n7.00000\n1.00000\n2.00000\n6.00000\n"
] | none | [] | 62 | 0 | 0 | 12,651 | |
671 | Ultimate Weirdness of an Array | [
"data structures",
"number theory"
] | null | null | Yasin has an array *a* containing *n* integers. Yasin is a 5 year old, so he loves ultimate weird things.
Yasin denotes weirdness of an array as maximum *gcd*(*a**i*,<=<=*a**j*) value among all 1<=≤<=*i*<=<<=*j*<=≤<=*n*. For *n*<=≤<=1 weirdness is equal to 0, *gcd*(*x*,<=<=*y*) is the greatest common divisor of int... | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of elements in *a*.
The next line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=200<=000), where the *i*-th number is equal to the *i*-th element of the array *a*. It is guaranteed that all *a**i* are distinct. | Print a single line containing the value of ultimate weirdness of the array *a*. | [
"3\n2 6 3\n"
] | [
"6\n"
] | Consider the first sample.
- *f*(1, 1) is equal to 3. - *f*(2, 2) is equal to 1. - *f*(3, 3) is equal to 2. - *f*(1, 2), *f*(1, 3) and *f*(2, 3) are equal to 0. | [] | 0 | 0 | -1 | 12,698 | |
0 | none | [
"none"
] | null | null | Currently Tiny is learning Computational Geometry. When trying to solve a problem called "The Closest Pair Of Points In The Plane", he found that a code which gave a wrong time complexity got Accepted instead of Time Limit Exceeded.
The problem is the follows. Given *n* points in the plane, find a pair of points betwe... | A single line which contains two space-separated integers *n* and *k* (2<=≤<=*n*<=≤<=2000, 1<=≤<=*k*<=≤<=109). | If there doesn't exist such a data which let the given code get TLE, print "no solution" (without quotes); else print *n* lines, and the *i*-th line contains two integers *x**i*,<=*y**i* (|*x**i*|,<=|*y**i*|<=≤<=109) representing the coordinates of the *i*-th point.
The conditions below must be held:
- All the point... | [
"4 3\n",
"2 100\n"
] | [
"0 0\n0 1\n1 0\n1 1\n",
"no solution\n"
] | none | [
{
"input": "4 3",
"output": "0 0\n0 1\n1 0\n1 1"
},
{
"input": "2 100",
"output": "no solution"
},
{
"input": "5 6",
"output": "0 0\n0 1\n0 2\n0 3\n0 4"
},
{
"input": "8 20",
"output": "0 0\n0 1\n0 2\n0 3\n0 4\n0 5\n0 6\n0 7"
},
{
"input": "6 15",
"output": "n... | 124 | 512,000 | 3 | 12,708 | |
126 | Hot Bath | [
"binary search",
"brute force",
"math"
] | null | null | Bob is about to take a hot bath.
There are two taps to fill the bath: a hot water tap and a cold water tap. The cold water's temperature is *t*1, and the hot water's temperature is *t*2. The cold water tap can transmit any integer number of water units per second from 0 to *x*1, inclusive. Similarly, the hot water ta... | You are given five integers *t*1, *t*2, *x*1, *x*2 and *t*0 (1<=≤<=*t*1<=≤<=*t*0<=≤<=*t*2<=≤<=106, 1<=≤<=*x*1,<=*x*2<=≤<=106). | Print two space-separated integers *y*1 and *y*2 (0<=≤<=*y*1<=≤<=*x*1, 0<=≤<=*y*2<=≤<=*x*2). | [
"10 70 100 100 25\n",
"300 500 1000 1000 300\n",
"143 456 110 117 273\n"
] | [
"99 33",
"1000 0",
"76 54"
] | In the second sample the hot water tap shouldn't be opened, but the cold water tap should be opened at full capacity in order to fill the bath in the quickest way possible. | [
{
"input": "10 70 100 100 25",
"output": "99 33"
},
{
"input": "300 500 1000 1000 300",
"output": "1000 0"
},
{
"input": "143 456 110 117 273",
"output": "76 54"
},
{
"input": "10 20 5 5 13",
"output": "4 2"
},
{
"input": "1 3 1999 3444 2",
"output": "1999 199... | 216 | 1,536,000 | 0 | 12,712 | |
382 | Arithmetic Progression | [
"implementation",
"sortings"
] | null | null | Everybody knows what an arithmetic progression is. Let us remind you just in case that an arithmetic progression is such sequence of numbers *a*1,<=*a*2,<=...,<=*a**n* of length *n*, that the following condition fulfills:
For example, sequences [1, 5], [10], [5, 4, 3] are arithmetic progressions and sequences [1, 3, ... | The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of cards. The next line contains the sequence of integers — the numbers on Alexander's cards. The numbers are positive integers, each of them doesn't exceed 108. | If Arthur can write infinitely many distinct integers on the card, print on a single line -1.
Otherwise, print on the first line the number of integers that suit you. In the second line, print the numbers in the increasing order. Note that the numbers in the answer can exceed 108 or even be negative (see test samples)... | [
"3\n4 1 7\n",
"1\n10\n",
"4\n1 3 5 9\n",
"4\n4 3 4 5\n",
"2\n2 4\n"
] | [
"2\n-2 10\n",
"-1\n",
"1\n7\n",
"0\n",
"3\n0 3 6\n"
] | none | [
{
"input": "3\n4 1 7",
"output": "2\n-2 10"
},
{
"input": "1\n10",
"output": "-1"
},
{
"input": "4\n1 3 5 9",
"output": "1\n7"
},
{
"input": "4\n4 3 4 5",
"output": "0"
},
{
"input": "2\n2 4",
"output": "3\n0 3 6"
},
{
"input": "4\n1 3 4 5",
"outpu... | 109 | 0 | 0 | 12,713 | |
460 | Little Dima and Equation | [
"brute force",
"implementation",
"math",
"number theory"
] | null | null | Little Dima misbehaved during a math lesson a lot and the nasty teacher Mr. Pickles gave him the following problem as a punishment.
Find all integer solutions *x* (0<=<<=*x*<=<<=109) of the equation:
where *a*, *b*, *c* are some predetermined constant values and function *s*(*x*) determines the sum of all digi... | The first line contains three space-separated integers: *a*,<=*b*,<=*c* (1<=≤<=*a*<=≤<=5; 1<=≤<=*b*<=≤<=10000; <=-<=10000<=≤<=*c*<=≤<=10000). | Print integer *n* — the number of the solutions that you've found. Next print *n* integers in the increasing order — the solutions of the given equation. Print only integer solutions that are larger than zero and strictly less than 109. | [
"3 2 8\n",
"1 2 -18\n",
"2 2 -1\n"
] | [
"3\n10 2008 13726 ",
"0\n",
"4\n1 31 337 967 "
] | none | [
{
"input": "3 2 8",
"output": "3\n10 2008 13726 "
},
{
"input": "1 2 -18",
"output": "0"
},
{
"input": "2 2 -1",
"output": "4\n1 31 337 967 "
},
{
"input": "1 1 0",
"output": "9\n1 2 3 4 5 6 7 8 9 "
},
{
"input": "1 37 963",
"output": "16\n1000 1111 1222 1333 ... | 46 | 0 | 3 | 12,750 | |
700 | Cool Slogans | [
"string suffix structures",
"strings"
] | null | null | Bomboslav set up a branding agency and now helps companies to create new logos and advertising slogans. In term of this problems, slogan of the company should be a non-empty substring of its name. For example, if the company name is "hornsandhoofs", then substrings "sand" and "hor" could be its slogans, while strings "... | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=200<=000) — the length of the company name that asks Bomboslav to help. The second line contains the string *w* of length *n*, that consists of lowercase English letters. | Print a single integer — the maximum possible length of the sequence of slogans of the company named *w*, such that any slogan in the sequence (except the first one) is cooler than the previous | [
"3\nabc\n",
"5\nddddd\n",
"11\nabracadabra\n"
] | [
"1\n",
"5\n",
"3\n"
] | none | [] | 31 | 0 | 0 | 12,778 | |
978 | Petya's Exams | [
"greedy",
"implementation",
"sortings"
] | null | null | Petya studies at university. The current academic year finishes with $n$ special days. Petya needs to pass $m$ exams in those special days. The special days in this problem are numbered from $1$ to $n$.
There are three values about each exam:
- $s_i$ — the day, when questions for the $i$-th exam will be published, -... | The first line contains two integers $n$ and $m$ $(2 \le n \le 100, 1 \le m \le n)$ — the number of days and the number of exams.
Each of the following $m$ lines contains three integers $s_i$, $d_i$, $c_i$ $(1 \le s_i < d_i \le n, 1 \le c_i \le n)$ — the day, when questions for the $i$-th exam will be given, the da... | If Petya can not prepare and pass all the exams, print -1. In case of positive answer, print $n$ integers, where the $j$-th number is:
- $(m + 1)$, if the $j$-th day is a day of some exam (recall that in each day no more than one exam is conducted), - zero, if in the $j$-th day Petya will have a rest, - $i$ ($1 \le... | [
"5 2\n1 3 1\n1 5 1\n",
"3 2\n1 3 1\n1 2 1\n",
"10 3\n4 7 2\n1 10 3\n8 9 1\n"
] | [
"1 2 3 0 3 \n",
"-1\n",
"2 2 2 1 1 0 4 3 4 4 \n"
] | In the first example Petya can, for example, prepare for exam $1$ in the first day, prepare for exam $2$ in the second day, pass exam $1$ in the third day, relax in the fourth day, and pass exam $2$ in the fifth day. So, he can prepare and pass all exams.
In the second example, there are three days and two exams. So, ... | [
{
"input": "5 2\n1 3 1\n1 5 1",
"output": "1 2 3 0 3 "
},
{
"input": "3 2\n1 3 1\n1 2 1",
"output": "-1"
},
{
"input": "10 3\n4 7 2\n1 10 3\n8 9 1",
"output": "2 2 2 1 1 0 4 3 4 4 "
},
{
"input": "2 1\n1 2 1",
"output": "1 2 "
},
{
"input": "3 1\n1 2 2",
"outp... | 62 | 0 | 3 | 12,797 | |
930 | Coins Exhibition | [
"data structures",
"dp",
"math"
] | null | null | Arkady and Kirill visited an exhibition of rare coins. The coins were located in a row and enumerated from left to right from 1 to *k*, each coin either was laid with its obverse (front) side up, or with its reverse (back) side up.
Arkady and Kirill made some photos of the coins, each photo contained a segment of neig... | The first line contains three integers *k*, *n* and *m* (1<=≤<=*k*<=≤<=109, 0<=≤<=*n*,<=*m*<=≤<=105) — the total number of coins, the number of photos made by Arkady, and the number of photos made by Kirill, respectively.
The next *n* lines contain the descriptions of Arkady's photos, one per line. Each of these lines... | Print the only line — the number of ways to choose the side for each coin modulo 109<=+<=7<==<=1000000007. | [
"5 2 2\n1 3\n3 5\n2 2\n4 5\n",
"5 3 2\n1 3\n2 2\n3 5\n2 2\n4 5\n",
"60 5 7\n1 3\n50 60\n1 60\n30 45\n20 40\n4 5\n6 37\n5 18\n50 55\n22 27\n25 31\n44 45\n"
] | [
"8\n",
"0\n",
"732658600\n"
] | In the first example the following ways are possible ('O' — obverse, 'R' — reverse side):
- OROOR, - ORORO, - ORORR, - RROOR, - RRORO, - RRORR, - ORROR, - ORRRO.
In the second example the information is contradictory: the second coin should have obverse and reverse sides up at the same time, that is impossib... | [] | 30 | 0 | 0 | 12,804 | |
198 | About Bacteria | [
"implementation",
"math"
] | null | null | Qwerty the Ranger took up a government job and arrived on planet Mars. He should stay in the secret lab and conduct some experiments on bacteria that have funny and abnormal properties. The job isn't difficult, but the salary is high.
At the beginning of the first experiment there is a single bacterium in the test tub... | The first line contains four space-separated integers *k*, *b*, *n* and *t* (1<=≤<=*k*,<=*b*,<=*n*,<=*t*<=≤<=106) — the parameters of bacterial growth, the time Qwerty needed to grow *z* bacteria in the first experiment and the initial number of bacteria in the second experiment, correspondingly. | Print a single number — the minimum number of seconds Qwerty needs to grow at least *z* bacteria in the tube. | [
"3 1 3 5\n",
"1 4 4 7\n",
"2 2 4 100\n"
] | [
"2",
"3",
"0"
] | none | [
{
"input": "3 1 3 5",
"output": "2"
},
{
"input": "1 4 4 7",
"output": "3"
},
{
"input": "2 2 4 100",
"output": "0"
},
{
"input": "1 2 3 100",
"output": "0"
},
{
"input": "10 10 10 123456",
"output": "6"
},
{
"input": "847 374 283 485756",
"output"... | 280 | 1,331,200 | 3 | 12,843 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.