source int64 2 2 | difficulty int64 7 25 | name stringlengths 9 60 | description stringlengths 164 7.12k | public_tests dict | private_tests dict | cf_rating int64 0 3.5k | cf_points float64 0 4k |
|---|---|---|---|---|---|---|---|
2 | 11 | 818_E. Card Game Again | Vova again tries to play some computer card game.
The rules of deck creation in this game are simple. Vova is given an existing deck of n cards and a magic number k. The order of the cards in the deck is fixed. Each card has a number written on it; number ai is written on the i-th card in the deck.
After receiving th... | {
"input": [
"3 4\n6 2 8\n",
"3 6\n9 1 14\n"
],
"output": [
"4\n",
"1\n"
]
} | {
"input": [
"7 8\n4 4 2 4 2 5 3\n",
"5 1\n5 5 5 5 5\n",
"1 1000000000\n1\n",
"3 1\n1 1 1\n",
"2 7\n1 4\n",
"9 3\n1 1 1 2 2 1 1 2 1\n",
"1 1\n1\n",
"6 1\n1 1 1 1 1 1\n",
"10 3\n2 2 1 1 2 2 2 2 1 2\n",
"1 8\n3\n",
"1 9\n5\n",
"100 1\n3 3 2 1 1 2 1 2 3 4 1 5 2 4 5 1 1 3 2... | 1,900 | 0 |
2 | 7 | 844_A. Diversity | Calculate the minimum number of characters you need to change in the string s, so that it contains at least k different letters, or print that it is impossible.
String s consists only of lowercase Latin letters, and it is allowed to change characters only to lowercase Latin letters too.
Input
First line of input con... | {
"input": [
"yahoo\n5\n",
"google\n7\n",
"yandex\n6\n"
],
"output": [
"1\n",
"impossible\n",
"0\n"
]
} | {
"input": [
"abcde\n3\n",
"zzzzzz\n2\n",
"smaxpqplaqqbxuqxalqmbmmgubbpspxhawbxsuqhhegpmmpebqmqpbbeplwaepxmsahuepuhuhwxeqmmlgqubuaxehwuwasgxpqmugbmuawuhwqlswllssueglbxepbmwgs\n1\n",
"aaabbbccc\n1\n",
"yandex\n4\n",
"abcdefg\n4\n",
"abcd\n2\n",
"cuguccgcugcugucgggggcgcgucgucugcuuuccccuu... | 1,000 | 500 |
2 | 10 | 864_D. Make a Permutation! | Ivan has an array consisting of n elements. Each of the elements is an integer from 1 to n.
Recently Ivan learned about permutations and their lexicographical order. Now he wants to change (replace) minimum number of elements in his array in such a way that his array becomes a permutation (i.e. each of the integers fr... | {
"input": [
"4\n3 2 2 3\n",
"6\n4 5 6 3 2 1\n",
"10\n6 8 4 6 7 1 6 3 4 5\n"
],
"output": [
"2\n1 2 4 3 \n",
"0\n4 5 6 3 2 1 \n",
"3\n2 8 4 6 7 1 9 3 10 5 \n"
]
} | {
"input": [
"50\n48 37 47 50 46 43 42 46 36 40 45 41 40 50 35 49 37 42 44 45 49 44 31 47 45 49 48 41 45 45 48 20 34 43 43 41 47 50 41 48 38 48 43 48 46 48 32 37 47 45\n",
"50\n1 1 2 1 1 1 1 1 1 1 1 1 2 1 2 1 1 2 1 1 1 1 1 1 1 1 1 2 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n",
"50\n11 3 15 13 1 10 27 4... | 1,500 | 2,000 |
2 | 9 | 88_C. Trains | 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,... | {
"input": [
"5 3\n",
"2 3\n",
"3 7\n"
],
"output": [
"Masha\n",
"Equal\n",
"Dasha\n"
]
} | {
"input": [
"716249 716248\n",
"99087 99090\n",
"929061 929052\n",
"8 75\n",
"461363 256765\n",
"4982 2927\n",
"999983 999979\n",
"782250 782252\n",
"9886 8671\n",
"20393 86640\n",
"52 53\n",
"419 430\n",
"397 568\n",
"996219 996216\n",
"91560 91550\n",
... | 1,500 | 500 |
2 | 7 | 913_A. Modular Exponentiation | The following problem is well-known: given integers n and m, calculate
<image>,
where 2n = 2·2·...·2 (n factors), and <image> denotes the remainder of division of x by y.
You are asked to solve the "reverse" problem. Given integers n and m, calculate
<image>.
Input
The first line contains a single integer n (1 ... | {
"input": [
"98765432\n23456789\n",
"4\n42\n",
"1\n58\n"
],
"output": [
"23456789\n",
"10\n",
"0\n"
]
} | {
"input": [
"67108864\n12345678\n",
"128\n64\n",
"11\n65535\n",
"25\n92831989\n",
"26\n67108864\n",
"3\n98391849\n",
"100000000\n100000000\n",
"26\n92831989\n",
"100\n100000\n",
"1\n1\n",
"2\n2\n",
"32\n92831989\n",
"2\n4\n",
"30\n92831989\n",
"25\n67108864... | 900 | 500 |
2 | 7 | 935_A. Fafa and his Company | Fafa owns a company that works on huge projects. There are n employees in Fafa's company. Whenever the company has a new project to start working on, Fafa has to divide the tasks of this project among all the employees.
Fafa finds doing this every time is very tiring for him. So, he decided to choose the best l employ... | {
"input": [
"10\n",
"2\n"
],
"output": [
"3",
"1"
]
} | {
"input": [
"12345\n",
"4\n",
"161\n",
"10007\n",
"98765\n",
"99990\n",
"56789\n",
"65536\n",
"11\n",
"1000\n",
"83160\n",
"3\n",
"40000\n",
"30030\n",
"13579\n",
"97531\n",
"4096\n",
"121\n",
"13\n",
"6\n",
"777\n",
"100000\n",
... | 800 | 500 |
2 | 11 | 988_E. Divisibility by 25 | You are given an integer n from 1 to 10^{18} without leading zeroes.
In one move you can swap any two adjacent digits in the given number in such a way that the resulting number will not contain leading zeroes. In other words, after each move the number you have cannot contain any leading zeroes.
What is the minimum ... | {
"input": [
"705\n",
"1241367\n",
"5071\n"
],
"output": [
"1\n",
"-1\n",
"4\n"
]
} | {
"input": [
"1000000000000000000\n",
"521\n",
"50267\n",
"50272\n",
"500044444444442\n",
"1002\n",
"52\n",
"213716413141380147\n",
"25\n",
"5284691\n",
"123456789987654321\n",
"50011111112\n",
"20029292929292929\n",
"227782777298772774\n",
"2227722772896244... | 2,100 | 0 |
2 | 9 | 1056_C. Pick Heroes | Don't you tell me what you think that I can be
If you say that Arkady is a bit old-fashioned playing checkers, you won't be right. There is also a modern computer game Arkady and his friends are keen on. We won't discuss its rules, the only feature important to this problem is that each player has to pick a distinct h... | {
"input": [
"3 1\n1 2 3 4 5 6\n2 6\n1\n\n2\n\n4\n\n1\n",
"3 1\n1 2 3 4 5 6\n1 5\n2\n6\n\n1\n\n3\n"
],
"output": [
"6\n5\n3\n",
"5\n4\n2\n"
]
} | {
"input": [
"6 0\n73 766 748 111 544 978 381 864 195 952 558 970\n1\n12 2 8 9 3 10 4 6 7 11 5 1\n",
"6 0\n73 766 748 111 544 978 381 864 195 952 558 970\n1\n6 12 10 8 2 3 11 5 7 9 4 1\n",
"3 1\n1 2 3 4 5 6\n2 6\n1\n6 5 4 3 2 1\n",
"3 1\n1 2 3 4 5 6\n1 5\n2\n6 5 4 3 2 1\n",
"6 0\n917 319 226 173 8... | 1,700 | 1,500 |
2 | 10 | 1099_D. Sum in the tree | Mitya has a rooted tree with n vertices indexed from 1 to n, where the root has index 1. Each vertex v initially had an integer number a_v ≥ 0 written on it. For every vertex v Mitya has computed s_v: the sum of all values written on the vertices on the path from vertex v to the root, as well as h_v — the depth of vert... | {
"input": [
"3\n1 2\n2 -1 1\n",
"5\n1 2 3 1\n1 -1 2 -1 -1\n",
"5\n1 1 1 1\n1 -1 -1 -1 -1\n"
],
"output": [
"-1\n",
"2\n",
"1\n"
]
} | {
"input": [
"5\n1 2 3 4\n5 -1 5 -1 7\n",
"25\n1 2 1 4 4 4 1 2 8 5 1 8 1 6 9 6 10 10 7 10 8 17 14 6\n846 -1 941 -1 1126 1803 988 -1 1352 1235 -1 -1 864 -1 -1 -1 -1 -1 -1 -1 -1 1508 1802 1713 -1\n",
"10\n1 1 1 1 2 3 4 5 1\n3 -1 -1 -1 -1 3 3 3 3 -1\n",
"10\n1 1 2 4 4 5 6 3 3\n0 -1 -1 0 -1 -1 1 2 3 4\n",... | 1,600 | 500 |
2 | 7 | 1168_A. Increasing by Modulo | Toad Zitz has an array of integers, each integer is between 0 and m-1 inclusive. The integers are a_1, a_2, …, a_n.
In one operation Zitz can choose an integer k and k indices i_1, i_2, …, i_k such that 1 ≤ i_1 < i_2 < … < i_k ≤ n. He should then change a_{i_j} to ((a_{i_j}+1) mod m) for each chosen integer i_j. The i... | {
"input": [
"5 3\n0 0 0 1 2\n",
"5 7\n0 6 1 3 2\n"
],
"output": [
"0\n",
"1\n"
]
} | {
"input": [
"10 300000\n111862 91787 271781 182224 260248 142019 30716 102643 141870 19206\n",
"6 4\n1 3 0 2 1 0\n",
"10 10\n5 0 5 9 4 6 4 5 0 0\n",
"100 10\n8 4 4 9 0 7 9 5 1 1 2 3 7 1 8 4 8 8 6 0 8 7 8 3 7 0 6 4 8 4 2 7 0 0 3 8 4 4 2 0 0 4 7 2 4 7 9 1 3 3 6 2 9 6 0 6 3 5 6 5 5 3 0 0 8 7 1 4 2 4 1 3... | 1,700 | 500 |
2 | 10 | 1186_D. Vus the Cossack and Numbers | Vus the Cossack has n real numbers a_i. It is known that the sum of all numbers is equal to 0. He wants to choose a sequence b the size of which is n such that the sum of all numbers is 0 and each b_i is either ⌊ a_i ⌋ or ⌈ a_i ⌉. In other words, b_i equals a_i rounded up or down. It is not necessary to round to the ne... | {
"input": [
"4\n4.58413\n1.22491\n-2.10517\n-3.70387\n",
"5\n-6.32509\n3.30066\n-0.93878\n2.00000\n1.96321\n"
],
"output": [
"5\n2\n-3\n-4\n",
"-6\n4\n-1\n2\n1\n"
]
} | {
"input": [
"3\n40.00000\n-21.00003\n-18.99997\n",
"5\n648.85642\n-922.00000\n78.88625\n578.45284\n-384.19551\n",
"1\n0.00000\n",
"5\n-0.50000\n0.50000\n0.50000\n0.50000\n-1.00000\n",
"8\n576.00000\n109.75914\n-748.15193\n770.46814\n-463.83905\n-106.11231\n184.08357\n-322.20756\n",
"9\n-2723.... | 1,500 | 1,750 |
2 | 9 | 1205_C. Palindromic Paths | This is an interactive problem
You are given a grid n× n, where n is odd. Rows are enumerated from 1 to n from up to down, columns are enumerated from 1 to n from left to right. Cell, standing on the intersection of row x and column y, is denoted by (x, y).
Every cell contains 0 or 1. It is known that the top-left ce... | {
"input": [
"3\n0\n1\n0\n1\n1\n1\n1"
],
"output": [
"? 1 1 1 3\n? 1 1 2 2\n? 1 1 3 1\n? 1 2 2 3\n? 1 2 3 2\n? 2 1 3 2\n? 1 1 3 2\n!\n110\n111\n010\n"
]
} | {
"input": [
"11\n11010011011\n00011100100\n11001011101\n10001111011\n01110100000\n01011101111\n01101001100\n10011000110\n00100111011\n01011000110\n01011000110\n",
"9\n100000110\n001101101\n001001011\n011011101\n011100011\n011000101\n011010100\n011001110\n011111110\n",
"5\n10000\n01000\n11010\n10111\n1110... | 2,400 | 1,250 |
2 | 10 | 1248_D1. The World Is Just a Programming Task (Easy Version) | This is an easier version of the problem. In this version, n ≤ 500.
Vasya is an experienced developer of programming competitions' problems. As all great minds at some time, Vasya faced a creative crisis. To improve the situation, Petya gifted him a string consisting of opening and closing brackets only. Petya believe... | {
"input": [
"12\n)(()(()())()\n",
"10\n()()())(()\n",
"6\n)))(()\n"
],
"output": [
"4\n1 2\n",
"5\n7 8\n",
"0\n1 1\n"
]
} | {
"input": [
"100\n)()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()(\n",
"498\n)())()(()()))())())()((()())((((()))()((()())()))())())))((()(()())))())())(()()(())())(((()))()))))(((((()())(()))(()((()(((()()()(()((()()))(((((((())((())((())(()(((()))())(((((... | 2,000 | 750 |
2 | 9 | 1288_C. Two Arrays | You are given two integers n and m. Calculate the number of pairs of arrays (a, b) such that:
* the length of both arrays is equal to m;
* each element of each array is an integer between 1 and n (inclusive);
* a_i ≤ b_i for any index i from 1 to m;
* array a is sorted in non-descending order;
* array b ... | {
"input": [
"723 9\n",
"2 2\n",
"10 1\n"
],
"output": [
"157557417\n",
"5\n",
"55\n"
]
} | {
"input": [
"1 2\n",
"678 7\n",
"1 10\n",
"398 8\n",
"526 2\n",
"1 1\n",
"1000 2\n",
"1000 1\n",
"1000 10\n"
],
"output": [
"1\n",
"778650919\n",
"1\n",
"725195161\n",
"226076855\n",
"1\n",
"917124963\n",
"500500\n",
"414070642\n"
]
} | 1,600 | 0 |
2 | 12 | 1331_F. Elementary! |
Input
The input consists of a single string of uppercase letters A-Z. The length of the string is between 1 and 10 characters, inclusive.
Output
Output "YES" or "NO".
Examples
Input
GENIUS
Output
YES
Input
DOCTOR
Output
NO
Input
IRENE
Output
YES
Input
MARY
Output
NO
Input
SMARTP... | {
"input": [
"DOCTOR\n",
"SMARTPHONE\n",
"REVOLVER\n",
"GENIUS\n",
"HOLMES\n",
"IRENE\n",
"MARY\n",
"WATSON\n"
],
"output": [
"NO",
"NO",
"NO",
"NO",
"NO",
"NO",
"NO",
"NO"
]
} | {
"input": [
"AID\n",
"TEASE\n",
"SUM\n",
"KHAKI\n",
"WURM\n",
"MUG\n",
"WEEVIL\n",
"WORD\n",
"PRODUCT\n",
"BRIGHT\n",
"SOURPUSS\n",
"AI\n",
"CUP\n",
"SUSHI\n",
"JUROR\n",
"WAYS\n",
"HELP\n",
"SOLAR\n",
"CROUP\n",
"NEAT\n",
"WET\n",
... | 0 | 0 |
2 | 7 | 1352_A. Sum of Round Numbers | A positive (strictly greater than zero) integer is called round if it is of the form d00...0. In other words, a positive integer is round if all its digits except the leftmost (most significant) are equal to zero. In particular, all numbers from 1 to 9 (inclusive) are round.
For example, the following numbers are roun... | {
"input": [
"5\n5009\n7\n9876\n10000\n10\n"
],
"output": [
"2\n5000 9\n1\n7\n4\n9000 800 70 6\n1\n10000\n1\n10\n"
]
} | {
"input": [
"2\n954\n18\n",
"5\n5009\n7\n9876\n10000\n10\n",
"2\n9999\n52\n",
"2\n999\n52\n",
"7\n1\n1\n1\n1\n1\n1\n1\n"
],
"output": [
"3\n900 50 4\n2\n10 8\n",
"2\n5000 9\n1\n7\n4\n9000 800 70 6\n1\n10000\n1\n10\n",
"4\n9000 900 90 9\n2\n50 2\n",
"3\n900 90 9\n2\n50 2\n",
... | 800 | 0 |
2 | 11 | 1371_E2. Asterism (Hard Version) | This is the hard version of the problem. The difference between versions is the constraints on n and a_i. You can make hacks only if all versions of the problem are solved.
First, Aoi came up with the following idea for the competitive programming problem:
Yuzu is a girl who collecting candies. Originally, she has x ... | {
"input": [
"4 3\n2 3 5 6\n",
"3 2\n1000000000 1 999999999\n",
"3 2\n3 4 5\n",
"4 3\n9 1 1 1\n"
],
"output": [
"2\n3 4 \n",
"1\n999999998 \n",
"1\n3 \n",
"0\n"
]
} | {
"input": [
"5 5\n292213182 292213182 292213182 292213183 292213182\n",
"6 5\n459714880 459714883 459714884 459714882 459714878 459714881\n",
"5 5\n324179187 95333719 583067898 217640575 166623692\n",
"2 2\n603532654 463735162\n",
"4 2\n45597639 501553165 412214228 678482810\n",
"3 2\n9948298... | 2,300 | 1,250 |
2 | 7 | 1419_A. Digit Game | Everyone knows that agents in Valorant decide, who will play as attackers, and who will play as defenders. To do that Raze and Breach decided to play t matches of a digit game...
In each of t matches of the digit game, a positive integer is generated. It consists of n digits. The digits of this integer are numerated f... | {
"input": [
"4\n1\n2\n1\n3\n3\n102\n4\n2069\n"
],
"output": [
"2\n1\n1\n2\n"
]
} | {
"input": [
"1\n33\n200000000000000000000000000000022\n",
"1\n3\n222\n",
"1\n4\n1212\n",
"1\n3\n101\n",
"1\n4\n2323\n",
"1\n2\n39\n",
"1\n2\n13\n",
"1\n4\n2121\n",
"4\n1\n2\n1\n3\n4\n2068\n4\n2069\n",
"1\n2\n21\n",
"2\n3\n212\n2\n11\n",
"1\n4\n2169\n",
"1\n3\n212\n... | 900 | 500 |
2 | 7 | 1437_A. Marketing Scheme | You got a job as a marketer in a pet shop, and your current task is to boost sales of cat food. One of the strategies is to sell cans of food in packs with discounts.
Suppose you decided to sell packs with a cans in a pack with a discount and some customer wants to buy x cans of cat food. Then he follows a greedy str... | {
"input": [
"3\n3 4\n1 2\n120 150\n"
],
"output": [
"YES\nNO\nYES\n"
]
} | {
"input": [
"10\n335544320 671088640\n335544322 671088639\n335544321 671088639\n335544325 671088637\n335544319 671088640\n335544319 671088641\n335544319 671088639\n335544318 671088639\n335544317 671088637\n335544319 671088643\n",
"3\n335544322 671088639\n335544320 671088640\n20971520 41943040\n",
"2\n499... | 800 | 0 |
2 | 11 | 1461_E. Water Level | In recent years John has very successfully settled at his new job at the office. But John doesn't like to idly sit around while his code is compiling, so he immediately found himself an interesting distraction. The point of his distraction was to maintain a water level in the water cooler used by other zebras.
<image>... | {
"input": [
"9 1 10 9 2 9\n",
"8 1 10 2 6 5\n",
"8 1 10 2 6 4\n",
"20 15 25 3 5 7\n"
],
"output": [
"\nNo\n",
"\nYes\n",
"\nNo\n",
"\nYes\n"
]
} | {
"input": [
"39438548848582980 11012410395558518 55950951412984721 44 535353 28994364452506991\n",
"512151145295769976 499588189546311526 513794826978301613 1000000000000000000 504656 89379401\n",
"500513922321119562 493336857305103088 791470671358459292 799086667807007415 509850 401293\n",
"5 1 10 4... | 2,200 | 2,250 |
2 | 8 | 1538_B. Friends and Candies | Polycarp has n friends, the i-th of his friends has a_i candies. Polycarp's friends do not like when they have different numbers of candies. In other words they want all a_i to be the same. To solve this, Polycarp performs the following set of actions exactly once:
* Polycarp chooses k (0 ≤ k ≤ n) arbitrary friends... | {
"input": [
"5\n4\n4 5 2 5\n2\n0 4\n5\n10 8 5 1 4\n1\n10000\n7\n1 1 1 1 1 1 1\n"
],
"output": [
"\n2\n1\n-1\n0\n0\n"
]
} | {
"input": [
"1\n52\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n",
"1\n2\n1 691\n",
"1\n3\n1 1 67\n",
"1\n52\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n"
],
"output": [
... | 0 | 0 |
2 | 10 | 207_D1. The Beaver's Problem - 3 | The Smart Beaver from ABBYY came up with another splendid problem for the ABBYY Cup participants! This time the Beaver invites the contest participants to check out a problem on sorting documents by their subjects. Let's describe the problem:
You've got some training set of documents. For each document you know its su... | {
"input": [],
"output": []
} | {
"input": [
"36000\nU.K. MONEY MARKET DEFICIT REMOVED\nLONDON, April 9 - The Bank of England said it has satisfied\nits revised estimate of today's shortfall in the money market,\nproviding 261 mln stg assistance in afternoon operations.\nThe Bank bought in band one, 60 mln stg bank bills at 9-7/8\npct and in ba... | 1,800 | 10 |
2 | 10 | 231_D. Magic Box | One day Vasya was going home when he saw a box lying on the road. The box can be represented as a rectangular parallelepiped. Vasya needed no time to realize that the box is special, as all its edges are parallel to the coordinate axes, one of its vertices is at point (0, 0, 0), and the opposite one is at point (x1, y1... | {
"input": [
"2 2 2\n1 1 1\n1 2 3 4 5 6\n",
"0 0 10\n3 2 3\n1 2 3 4 5 6\n"
],
"output": [
"12\n",
"4\n"
]
} | {
"input": [
"5 5 0\n3 1 3\n832224 636838 995053 211585 505442 341920\n",
"34271 -17508 -6147\n456 567 112\n804178 307516 306399 18981 989216 228388\n",
"967 -1346 2551\n769 331 28\n458319 885170 877010 533360 723416 248230\n",
"-263980 -876063 613611\n2 3 14\n63640 300066 460766 222639 51956 412622\n... | 1,600 | 2,000 |
2 | 9 | 257_C. View Angle | Flatland has recently introduced a new type of an eye check for the driver's licence. The check goes like that: there is a plane with mannequins standing on it. You should tell the value of the minimum angle with the vertex at the origin of coordinates and with all mannequins standing inside or on the boarder of this a... | {
"input": [
"2\n2 0\n0 2\n",
"2\n2 1\n1 2\n",
"4\n2 0\n0 2\n-2 0\n0 -2\n",
"3\n2 0\n0 2\n-2 2\n"
],
"output": [
"90.000000000000",
"36.869897645844",
"270.000000000000",
"135.000000000000"
]
} | {
"input": [
"10\n-1 -29\n-1 -26\n1 -26\n-1 -22\n-1 -24\n-1 -21\n1 -24\n-1 -20\n-1 -23\n-1 -25\n",
"20\n-45 147\n-240 784\n-135 441\n-60 196\n-105 343\n-285 931\n-195 637\n-300 980\n-165 539\n-210 686\n-75 245\n-15 49\n-30 98\n-270 882\n-120 392\n-90 294\n-150 490\n-180 588\n-255 833\n-225 735\n",
"5\n2 1... | 1,800 | 1,500 |
2 | 9 | 280_C. Game on Tree | Momiji has got a rooted tree, consisting of n nodes. The tree nodes are numbered by integers from 1 to n. The root has number 1. Momiji decided to play a game on this tree.
The game consists of several steps. On each step, Momiji chooses one of the remaining tree nodes (let's denote it by v) and removes all the subtre... | {
"input": [
"3\n1 2\n1 3\n",
"2\n1 2\n"
],
"output": [
"2.0000000000",
"1.5000000000"
]
} | {
"input": [
"10\n1 2\n2 3\n3 4\n1 5\n2 6\n6 7\n4 8\n6 9\n9 10\n",
"6\n1 3\n2 4\n5 6\n3 6\n5 4\n"
],
"output": [
"3.8166666667",
"2.4500000000"
]
} | 2,200 | 1,500 |
2 | 8 | 303_B. Rectangle Puzzle II | You are given a rectangle grid. That grid's size is n × m. Let's denote the coordinate system on the grid. So, each point on the grid will have coordinates — a pair of integers (x, y) (0 ≤ x ≤ n, 0 ≤ y ≤ m).
Your task is to find a maximum sub-rectangle on the grid (x1, y1, x2, y2) so that it contains the given point (... | {
"input": [
"100 100 52 50 46 56\n",
"9 9 5 5 2 1\n"
],
"output": [
"17 8 86 92\n",
"1 3 9 7\n"
]
} | {
"input": [
"71265727 62692710 12444778 3479306 21442685 5463351\n",
"81460 7041354 53032 1297536 41496 5748697\n",
"99373741 10548319 82293354 9865357 58059929 5328757\n",
"1000000000 1000000000 839898171 196274842 131921537 865789406\n",
"6561833 24532010 2773123 457562 6225818 23724637\n",
... | 1,700 | 500 |
2 | 9 | 32_C. Flea | 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 arbitrary n... | {
"input": [
"3 3 2\n",
"2 3 1000000\n"
],
"output": [
"4",
"6\n"
]
} | {
"input": [
"694117 431924 737\n",
"1000000 1000000 12345\n",
"1 2 3\n",
"391814 220151 3756\n",
"40224 890892 54\n",
"242366 216591 4\n",
"9 8 7\n",
"1000000 1000000 2\n",
"38614 941895 999986\n",
"402841 635488 997633\n",
"43496 179847 327622\n",
"933241 558702 1\n",... | 1,700 | 1,500 |
2 | 7 | 351_A. Jeff and Rounding | Jeff got 2n real numbers a1, a2, ..., a2n as a birthday present. The boy hates non-integer numbers, so he decided to slightly "adjust" the numbers he's got. Namely, Jeff consecutively executes n operations, each of them goes as follows:
* choose indexes i and j (i ≠ j) that haven't been chosen yet;
* round elemen... | {
"input": [
"3\n0.000 0.500 0.750 1.000 2.000 3.000\n",
"3\n4469.000 6526.000 4864.000 9356.383 7490.000 995.896\n"
],
"output": [
"0.250\n",
"0.279\n"
]
} | {
"input": [
"9\n5528.947 205.031 5245.169 8832.592 385.656 7126.360 3988.000 9542.000 3044.042 5288.000 9342.837 9979.021 7096.022 5159.200 9400.485 4996.735 1698.000 5403.939\n",
"1\n6418.669 157.986\n",
"9\n5528.000 205.000 5245.000 8832.000 385.000 7126.000 3988.538 9542.484 3044.000 5288.351 9342.000... | 1,800 | 1,000 |
2 | 8 | 375_B. Maximum Submatrix 2 | You are given a matrix consisting of digits zero and one, its size is n × m. You are allowed to rearrange its rows. What is the maximum area of the submatrix that only consists of ones and can be obtained in the given problem by the described operations?
Let's assume that the rows of matrix a are numbered from 1 to n ... | {
"input": [
"4 3\n100\n011\n000\n101\n",
"1 1\n1\n",
"2 2\n10\n11\n"
],
"output": [
"2\n",
"1\n",
"2\n"
]
} | {
"input": [
"13 19\n0000111111111111011\n0111000001110001101\n1110100110111011101\n0001101011100001110\n1101100100010000101\n1010100011110011010\n1010011101010000001\n1011101000001111000\n1101110001101011110\n0110101010001111100\n0001011010100111001\n1111101000110001000\n0010010000011100010\n",
"1 1\n0\n",
... | 1,600 | 1,000 |
2 | 10 | 397_D. On Sum of Fractions | Let's assume that
* v(n) is the largest prime number, that does not exceed n;
* u(n) is the smallest prime number strictly greater than n.
Find <image>.
Input
The first line contains integer t (1 ≤ t ≤ 500) — the number of testscases.
Each of the following t lines of the input contains integer n (2 ≤ n ≤ ... | {
"input": [
"2\n2\n3\n"
],
"output": [
"1/6\n7/30\n"
]
} | {
"input": [
"5\n72\n72\n30\n75\n11\n",
"5\n79\n149\n136\n194\n124\n",
"6\n885\n419\n821\n635\n63\n480\n",
"1\n1000000000\n",
"5\n3\n6\n9\n10\n5\n",
"5\n5\n8\n18\n17\n17\n",
"1\n649580447\n",
"5\n7\n40\n37\n25\n4\n"
],
"output": [
"71/146\n71/146\n29/62\n5615/11534\n119/286\n",... | 0 | 1,000 |
2 | 11 | 41_E. 3-cycles | During a recent research Berland scientists found out that there were n cities in Ancient Berland, joined by two-way paths. Any two cities are joined by no more than one path. No path joins a city with itself. According to a well-known tradition, the road network was built so that it would be impossible to choose three... | {
"input": [
"4\n",
"3\n"
],
"output": [
"4\n1 3\n1 4\n2 3\n2 4\n",
"2\n1 2\n1 3\n"
]
} | {
"input": [
"29\n",
"18\n",
"3\n",
"31\n",
"1\n",
"18\n",
"15\n",
"15\n",
"9\n",
"6\n",
"16\n",
"23\n",
"33\n",
"23\n",
"10\n",
"31\n",
"33\n",
"19\n",
"5\n",
"12\n",
"7\n",
"2\n",
"13\n",
"8\n",
"19\n",
"22\n",
... | 1,900 | 2,500 |
2 | 10 | 490_D. Chocolate | Polycarpus likes giving presents to Paraskevi. He has bought two chocolate bars, each of them has the shape of a segmented rectangle. The first bar is a1 × b1 segments large and the second one is a2 × b2 segments large.
Polycarpus wants to give Paraskevi one of the bars at the lunch break and eat the other one himself... | {
"input": [
"36 5\n10 16\n",
"3 5\n2 1\n",
"2 6\n2 3\n"
],
"output": [
"3\n16 5\n5 16\n",
"-1",
"1\n1 6\n2 3\n"
]
} | {
"input": [
"261578849 307610920\n636335376 399859678\n",
"199999978 2\n599999934 3\n",
"894 197\n325 232\n",
"60 1080\n60 45\n",
"720005688 725594112\n816293376 960007584\n",
"1 1\n918330048 918330048\n",
"22295873 586964387\n4736819 472714349\n",
"378462721 734062076\n42554822 37423... | 1,900 | 2,000 |
2 | 10 | 514_D. R2D2 and Droid Army | An army of n droids is lined up in one row. Each droid is described by m integers a1, a2, ..., am, where ai is the number of details of the i-th type in this droid's mechanism. R2-D2 wants to destroy the sequence of consecutive droids of maximum length. He has m weapons, the i-th weapon can affect all the droids in the... | {
"input": [
"5 2 4\n4 0\n1 2\n2 1\n0 2\n1 3\n",
"3 2 4\n1 2\n1 3\n2 2\n"
],
"output": [
"2 2 \n",
"1 3 \n"
]
} | {
"input": [
"4 5 33\n2 10 2 3 2\n10 6 4 5 0\n3 1 7 3 2\n4 4 2 1 5\n",
"4 5 40\n0 10 9 0 4\n10 5 5 7 4\n9 9 5 5 2\n6 7 9 4 3\n",
"31 2 1913\n845 576\n862 325\n914 283\n431 837\n193 171\n30 248\n290 488\n810 552\n463 74\n765 469\n785 119\n107 267\n528 761\n583 395\n359 45\n840 559\n147 510\n882 830\n267 39... | 2,000 | 2,000 |
2 | 11 | 540_E. Infinite Inversions | There is an infinite sequence consisting of all positive integers in the increasing order: p = {1, 2, 3, ...}. We performed n swap operations with this sequence. A swap(a, b) is an operation of swapping the elements of the sequence on positions a and b. Your task is to find the number of inversions in the resulting seq... | {
"input": [
"3\n1 6\n3 4\n2 5\n",
"2\n4 2\n1 4\n"
],
"output": [
"15",
"4"
]
} | {
"input": [
"5\n2 5\n6 3\n4 6\n5 4\n2 5\n",
"30\n1 200000\n2 199999\n3 199998\n4 199997\n5 199996\n200001 399996\n200002 399997\n200003 399998\n200004 399999\n200005 400000\n400001 599998\n400002 599999\n400003 600000\n400004 599996\n400005 599995\n600001 800000\n600002 799999\n600003 799998\n600004 799997\n... | 2,100 | 2,500 |
2 | 7 | 569_A. Music | Little Lesha loves listening to music via his smartphone. But the smartphone doesn't have much memory, so Lesha listens to his favorite songs in a well-known social network InTalk.
Unfortunately, internet is not that fast in the city of Ekaterinozavodsk and the song takes a lot of time to download. But Lesha is quite ... | {
"input": [
"5 2 2\n",
"6 2 3\n",
"5 4 7\n"
],
"output": [
"2\n",
"1\n",
"1\n"
]
} | {
"input": [
"100000 1 10000\n",
"64 1 8\n",
"100000 1 2\n",
"100000 1 4\n",
"12326 6163 2\n",
"100000 1 5\n",
"12351 1223 6\n",
"2 1 3\n",
"100000 1 3\n",
"6562 1 3\n",
"10033 3 8\n",
"100000 99999 3\n",
"12628 1804 7\n",
"50 2 2\n",
"10000 2500 4\n",
"... | 1,500 | 500 |
2 | 10 | 58_D. Calendar | BerOilGasDiamondBank has branches in n cities, at that n is an even number. The bank management wants to publish a calendar with the names of all those cities written in two columns: the calendar should consist of exactly n / 2 lines of strictly equal length, each of which contains exactly two names and exactly one sep... | {
"input": [
"4\nb\naa\nhg\nc\n.\n",
"2\naa\na\n!\n",
"2\naa\na\n|\n"
],
"output": [
"aa.b\nc.hg\n",
"a!aa\n",
"aa|a\n"
]
} | {
"input": [
"4\nqhcivbxotj\nirgxzzxvw\npxdmcyszvk\nyyaevcdal\n~\n",
"34\nobseknnnqk\ncvyvvbcgb\nxvmhfzfl\ngrtp\nhbcbhj\nknnnqk\ncyud\nkuaeui\naeui\nlhpdobsekn\ncxmigej\ncvyvvbcgbs\nuwuu\nnnqk\npzcftfrrqp\nnwsyrgqa\nxvmhfzflku\nndcis\nxhaznwqsgk\ncftfrrqp\nkakdggegew\njjzvokhh\nlhpdobse\nxjjzvokhh\nlhpd\nsuwu... | 2,000 | 2,000 |
2 | 9 | 631_C. Report | Each month Blake gets the report containing main economic indicators of the company "Blake Technologies". There are n commodities produced by the company. For each of them there is exactly one integer in the final report, that denotes corresponding revenue. Before the report gets to Blake, it passes through the hands o... | {
"input": [
"3 1\n1 2 3\n2 2\n",
"4 2\n1 2 4 3\n2 3\n1 2\n"
],
"output": [
"2 1 3 ",
"2 4 1 3 "
]
} | {
"input": [
"6 2\n3 1 2 6 4 5\n1 6\n2 3\n",
"100 30\n65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 74 57 115 16 55 88 79 97 21 80 41 56 49 103 61 66 1 36 44 43 82 37 38 106 27 114 51 112 55 87 41 69 31 86 ... | 1,700 | 1,500 |
2 | 7 | 660_A. Co-prime Array | You are given an array of n elements, you must make it a co-prime array in as few moves as possible.
In each move you can insert any positive integral number you want not greater than 109 in any place in the array.
An array is co-prime if any two adjacent numbers of it are co-prime.
In the number theory, two integer... | {
"input": [
"3\n2 7 28\n"
],
"output": [
"1\n2 7 1 28 "
]
} | {
"input": [
"3\n999999937 999999937 2\n",
"2\n3257 3257\n",
"7\n1 982451653 982451653 1 982451653 982451653 982451653\n",
"2\n999999733 999999733\n",
"20\n2 1000000000 2 1000000000 2 1000000000 2 1000000000 2 1000000000 2 1000000000 2 1000000000 2 1000000000 2 1000000000 2 1000000000\n",
"3\n... | 1,200 | 0 |
2 | 10 | 706_D. Vasiliy's Multiset | Author has gone out of the stories about Vasiliy, so here is just a formal task description.
You are given q queries and a multiset A, initially containing only integer 0. There are three types of queries:
1. "+ x" — add integer x to multiset A.
2. "- x" — erase one occurrence of integer x from multiset A. It's g... | {
"input": [
"10\n+ 8\n+ 9\n+ 11\n+ 6\n+ 1\n? 3\n- 8\n? 3\n? 8\n? 11\n"
],
"output": [
"11\n10\n14\n13\n"
]
} | {
"input": [
"7\n? 1\n+ 941492387\n+ 72235422\n+ 449924898\n+ 783332532\n- 941492387\n- 72235422\n",
"1\n? 4\n",
"10\n? 1\n+ 1\n+ 8\n- 1\n+ 2\n+ 7\n+ 4\n+ 7\n+ 3\n? 7\n",
"3\n? 5\n? 4\n? 3\n",
"12\n+ 4\n+ 4\n+ 5\n? 3\n- 4\n? 3\n- 4\n? 3\n? 3\n- 5\n+ 10\n? 1\n",
"14\n+ 4\n+ 4\n+ 4\n+ 4\n? 3\n- ... | 1,800 | 2,000 |
2 | 8 | 74_B. Train | A stowaway and a controller play the following game.
The train is represented by n wagons which are numbered with positive integers from 1 to n from the head to the tail. The stowaway and the controller are initially in some two different wagons. Every minute the train can be in one of two conditions — moving or idle... | {
"input": [
"5 3 2\nto head\n0001001\n",
"3 2 1\nto tail\n0001\n"
],
"output": [
"Stowaway\n",
"Controller 2\n"
]
} | {
"input": [
"50 4 12\nto tail\n00000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000001000100000000000000000000000000000000000000010000000010000000000000000000000000000000000000000001\n",
"3 1 3\nto head\n10111111111111111011110110111111110111011111111111111111... | 1,500 | 1,000 |
2 | 7 | 773_A. Success Rate | You are an experienced Codeforces user. Today you found out that during your activity on Codeforces you have made y submissions, out of which x have been successful. Thus, your current success rate on Codeforces is equal to x / y.
Your favorite rational number in the [0;1] range is p / q. Now you wonder: what is the s... | {
"input": [
"4\n3 10 1 2\n7 14 3 8\n20 70 2 7\n5 6 1 1\n"
],
"output": [
"4\n10\n0\n-1\n"
]
} | {
"input": [
"1\n3 999999990 1 1000000000\n",
"1\n2 2 1 1\n",
"5\n1 982449707 1 2\n1 982449707 1 2\n1 982449707 1 2\n1 982449707 1 2\n1 982449707 1 2\n",
"1\n0 1000000000 999999999 1000000000\n",
"5\n1000000000 1000000000 1 2\n1000000000 1000000000 1 2\n1000000000 1000000000 1 2\n1000000000 100000... | 1,700 | 500 |
2 | 8 | 818_B. Permutation Game | n children are standing in a circle and playing a game. Children's numbers in clockwise order form a permutation a1, a2, ..., an of length n. It is an integer sequence such that each integer from 1 to n appears exactly once in it.
The game consists of m steps. On each step the current leader with index i counts out ai... | {
"input": [
"3 3\n3 1 2\n",
"4 5\n2 3 1 4 4\n"
],
"output": [
"-1\n",
"3 1 2 4 "
]
} | {
"input": [
"4 5\n1 4 1 3 2\n",
"4 6\n1 1 2 4 4 4\n",
"20 15\n11 19 1 8 17 12 3 1 8 17 12 3 1 8 17\n",
"4 6\n2 3 1 4 4 1\n",
"3 4\n1 3 1 1\n",
"5 7\n4 3 4 3 3 4 5\n",
"2 9\n1 1 1 1 2 1 1 1 1\n",
"4 4\n1 4 1 3\n",
"20 20\n1 20 2 19 3 18 4 17 5 16 6 15 7 14 8 13 9 12 10 11\n",
"... | 1,600 | 0 |
2 | 7 | 864_A. Fair Game | Petya and Vasya decided to play a game. They have n cards (n is an even number). A single integer is written on each card.
Before the game Petya will choose an integer and after that Vasya will choose another integer (different from the number that Petya chose). During the game each player takes all the cards with num... | {
"input": [
"2\n6\n6\n",
"6\n1\n1\n2\n2\n3\n3\n",
"4\n11\n27\n27\n11\n",
"6\n10\n20\n30\n20\n10\n20\n"
],
"output": [
"NO",
"NO",
"YES\n11 27",
"NO"
]
} | {
"input": [
"100\n29\n29\n29\n29\n29\n29\n29\n29\n29\n29\n29\n29\n29\n29\n29\n29\n29\n29\n29\n29\n29\n29\n29\n29\n29\n29\n29\n29\n29\n29\n29\n29\n29\n29\n29\n29\n29\n29\n29\n29\n29\n29\n29\n29\n29\n29\n29\n29\n29\n29\n43\n43\n43\n43\n43\n43\n43\n43\n43\n43\n43\n43\n43\n43\n43\n43\n43\n43\n43\n43\n43\n43\n43\n43\... | 1,000 | 500 |
2 | 9 | 934_C. A Twisty Movement | A dragon symbolizes wisdom, power and wealth. On Lunar New Year's Day, people model a dragon with bamboo strips and clothes, raise them with rods, and hold the rods high and low to resemble a flying dragon.
A performer holding the rod low is represented by a 1, while one holding it high is represented by a 2. Thus, th... | {
"input": [
"4\n1 2 1 2\n",
"10\n1 1 2 2 2 1 1 2 2 1\n"
],
"output": [
"4\n",
"9\n"
]
} | {
"input": [
"6\n2 2 2 1 1 1\n",
"2\n1 2\n",
"200\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1... | 1,800 | 500 |
2 | 8 | 988_B. Substrings Sort | 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 such a way... | {
"input": [
"3\nqwerty\nqwerty\nqwerty\n",
"5\na\naba\nabacaba\nba\naba\n",
"5\na\nabacaba\nba\naba\nabab\n"
],
"output": [
"YES\nqwerty\nqwerty\nqwerty\n",
"YES\na\nba\naba\naba\nabacaba\n",
"NO\n"
]
} | {
"input": [
"3\nab\ncd\nabcd\n",
"2\naabaa\naba\n",
"2\nab\naab\n",
"5\nekgetterherforme\ner\nter\nher\ntter\n",
"4\na\nb\nc\nabc\n",
"4\na\nba\nabacabac\nb\n",
"3\na\nb\nab\n",
"3\naa\nab\naab\n",
"3\nababc\nabababc\nab\n",
"3\nbc\nbca\na\n",
"3\na\nbcd\nabcd\n",
"7\n... | 1,100 | 0 |
2 | 8 | 1000_B. Light It Up | Recently, you bought a brand new smart lamp with programming features. At first, you set up a schedule to the lamp. Every day it will turn power on at moment 0 and turn power off at moment M. Moreover, the lamp allows you to set a program of switching its state (states are "lights on" and "lights off"). Unfortunately, ... | {
"input": [
"2 7\n3 4\n",
"2 12\n1 10\n",
"3 10\n4 6 7\n"
],
"output": [
"6\n",
"9\n",
"8\n"
]
} | {
"input": [
"1 10\n2\n",
"2 5\n1 3\n",
"1 8\n1\n",
"3 90591\n90579 90580 90581\n",
"1 10000000\n1\n",
"9 20\n5 9 11 12 14 15 16 17 19\n",
"3 4\n1 2 3\n",
"5 16\n1 2 3 4 5\n",
"7 17\n1 5 9 10 11 14 16\n",
"2 4\n1 3\n",
"7 9863\n65 96 97 98 101 112 1115\n",
"3 5\n1 3 4\n... | 1,500 | 0 |
2 | 9 | 1025_C. Plasticine zebra | Is there anything better than going to the zoo after a tiresome week at work? No wonder Grisha feels the same while spending the entire weekend accompanied by pretty striped zebras.
Inspired by this adventure and an accidentally found plasticine pack (represented as a sequence of black and white stripes), Grisha now ... | {
"input": [
"bwwwbwwbw\n",
"bwwbwwb\n"
],
"output": [
"5\n",
"3\n"
]
} | {
"input": [
"bwbw\n",
"www\n",
"wbwbwbwbwb\n",
"bwbwbbbbwb\n",
"bww\n",
"bwb\n",
"bwbwwwwwwwwbwb\n",
"wbwbwb\n",
"wbwb\n",
"bwwwwwbbbbbw\n",
"bwbwbw\n",
"wbbwbw\n",
"bbbbwbwwbbwwwwwbbbwb\n",
"wwwwb\n",
"bw\n",
"bwbwbwbwbwbw\n",
"wbb\n",
"wbwbwbw... | 1,600 | 1,500 |
2 | 11 | 1068_E. Multihedgehog | Someone give a strange birthday present to Ivan. It is hedgehog — connected undirected graph in which one vertex has degree at least 3 (we will call it center) and all other vertices has degree 1. Ivan thought that hedgehog is too boring and decided to make himself k-multihedgehog.
Let us define k-multihedgehog as fol... | {
"input": [
"3 1\n1 3\n2 3\n",
"14 2\n1 4\n2 4\n3 4\n4 13\n10 5\n11 5\n12 5\n14 5\n5 13\n6 7\n8 6\n13 6\n9 6\n"
],
"output": [
"No\n",
"Yes\n"
]
} | {
"input": [
"2 1\n1 2\n",
"8 1\n8 2\n2 5\n5 1\n7 2\n2 4\n3 5\n5 6\n",
"5 1\n4 1\n3 1\n5 1\n1 2\n",
"25 2\n1 2\n1 3\n1 4\n2 5\n2 6\n2 7\n3 8\n3 9\n3 10\n4 11\n4 12\n4 13\n4 14\n14 15\n14 16\n14 17\n4 18\n18 19\n18 20\n18 21\n1 22\n22 23\n22 24\n22 25\n",
"33 2\n3 13\n17 3\n2 6\n5 33\n4 18\n1 2\n31... | 1,800 | 1,000 |
2 | 10 | 1090_D. Similar Arrays | Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results of the comparisons to another sheet of paper. For each pair he wrote either "great... | {
"input": [
"4 3\n1 2\n1 3\n2 4\n",
"3 1\n1 2\n",
"1 0\n"
],
"output": [
"YES\n1 3 4 2 \n1 3 4 1 ",
"YES\n1 3 2 \n1 3 1 ",
"NO\n"
]
} | {
"input": [
"3 0\n",
"5 10\n4 2\n1 5\n5 2\n1 4\n2 3\n4 3\n1 2\n5 3\n5 4\n3 1\n",
"2 1\n2 1\n",
"10 40\n8 3\n6 8\n7 1\n9 10\n1 3\n2 8\n3 7\n1 8\n8 10\n4 5\n5 1\n10 3\n9 7\n4 6\n5 3\n2 3\n3 9\n9 8\n7 8\n4 1\n1 6\n4 7\n7 6\n6 10\n6 9\n2 6\n5 10\n10 4\n7 2\n5 9\n2 4\n3 6\n9 2\n1 10\n5 8\n5 7\n4 8\n1 9\n6... | 1,800 | 0 |
2 | 7 | 110_A. Nearly Lucky Number | 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.
Unfortunately, not all numbers are lucky. Petya calls a number nearly lucky if the number of lucky d... | {
"input": [
"40047\n",
"7747774\n",
"1000000000000000000\n"
],
"output": [
"NO\n",
"YES\n",
"NO\n"
]
} | {
"input": [
"34777745021000000\n",
"9847745885202111\n",
"123456789123456789\n",
"444444444444444444\n",
"777777777777777\n",
"7777777\n",
"4444000111222333\n",
"1\n",
"7777\n",
"4744000695826\n",
"400000000474\n",
"999999999999994744\n",
"4700\n",
"44648641678... | 800 | 500 |
2 | 10 | 1139_D. Steps to One | Vivek initially has an empty array a and some integer constant m.
He performs the following algorithm:
1. Select a random integer x uniformly in range from 1 to m and append it to the end of a.
2. Compute the greatest common divisor of integers in a.
3. In case it equals to 1, break
4. Otherwise, return to... | {
"input": [
"4\n",
"2\n",
"1\n"
],
"output": [
"333333338\n",
"2\n",
"1\n"
]
} | {
"input": [
"677\n",
"9\n",
"30238\n",
"7635\n",
"47539\n",
"14\n",
"2048\n",
"5714\n",
"20\n",
"78088\n",
"93378\n",
"11\n",
"8\n",
"91402\n",
"86632\n",
"64444\n",
"80555\n",
"91568\n",
"75232\n",
"2864\n",
"64\n",
"91286\n",
... | 2,300 | 2,250 |
2 | 10 | 1157_D. N Problems During K Days | Polycarp has to solve exactly n problems to improve his programming skill before an important programming competition. But this competition will be held very soon, most precisely, it will start in k days. It means that Polycarp has exactly k days for training!
Polycarp doesn't want to procrastinate, so he wants to sol... | {
"input": [
"9 4\n",
"8 3\n",
"1 1\n",
"26 6\n"
],
"output": [
"NO\n",
"NO\n",
"YES\n1 ",
"YES\n1 2 4 5 6 8 "
]
} | {
"input": [
"3 4\n",
"2 4\n",
"2 3\n",
"800019998 40000\n",
"77792 2\n",
"123456789 13456\n",
"147268968 2\n",
"4 3\n",
"7 2\n",
"2 1\n",
"7 3\n",
"999961559 44720\n",
"3 2\n",
"3 3\n",
"20492 2\n",
"1000000000 10\n",
"5 2\n",
"1 3\n",
"3398... | 1,900 | 0 |
2 | 7 | 117_A. Elevator | And now the numerous qualifying tournaments for one of the most prestigious Russian contests Russian Codec Cup are over. All n participants who have made it to the finals found themselves in a huge m-floored 108-star hotel. Of course the first thought to come in a place like this is "How about checking out the elevator... | {
"input": [
"5 5\n1 5 4\n1 3 1\n1 3 4\n3 1 5\n4 2 5\n",
"7 4\n2 4 3\n1 2 0\n2 2 0\n1 2 1\n4 3 5\n1 2 2\n4 2 0\n"
],
"output": [
"12\n10\n10\n8\n7\n",
"9\n1\n0\n7\n10\n7\n5\n"
]
} | {
"input": [
"3 4\n2 4 7\n3 3 1\n2 2 9\n",
"8 5\n2 2 91\n5 1 97\n5 1 36\n5 4 19\n2 5 50\n4 2 1\n1 4 9\n3 2 32\n",
"2 100000000\n2 1 3\n99999999 100000000 100000000\n",
"5 5\n1 3 4\n4 4 2\n3 2 1\n2 4 0\n1 5 3\n",
"5 2\n1 2 0\n2 1 1\n2 2 0\n2 2 5\n2 1 4\n",
"7 5\n2 2 85\n4 3 76\n4 1 17\n5 4 70\n... | 1,300 | 500 |
2 | 8 | 1198_B. Welfare State | There is a country with n citizens. The i-th of them initially has a_{i} money. The government strictly controls the wealth of its citizens. Whenever a citizen makes a purchase or earns some money, they must send a receipt to the social services mentioning the amount of money they currently have.
Sometimes the governm... | {
"input": [
"4\n1 2 3 4\n3\n2 3\n1 2 2\n2 1\n",
"5\n3 50 2 1 10\n3\n1 2 0\n2 8\n1 3 20\n"
],
"output": [
"3 2 3 4 ",
"8 8 20 8 10 "
]
} | {
"input": [
"10\n1 2 3 4 5 6 7 8 9 10\n10\n2 1\n2 2\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n2 9\n2 10\n",
"10\n7 9 4 4 7 6 3 7 9 8\n10\n1 3 2\n1 10 5\n1 5 3\n1 5 2\n1 2 9\n1 2 9\n1 2 10\n1 5 7\n1 6 10\n1 10 9\n",
"4\n1 2 3 4\n2\n2 3\n2 2\n",
"1\n1\n3\n2 4\n1 1 2\n2 10\n",
"5\n1 2 3 4 5\n10\n1 1 0\n2 1\n1 ... | 1,600 | 750 |
2 | 7 | 1215_A. Yellow Cards | The final match of the Berland Football Cup has been held recently. The referee has shown n yellow cards throughout the match. At the beginning of the match there were a_1 players in the first team and a_2 players in the second team.
The rules of sending players off the game are a bit different in Berland football. If... | {
"input": [
"3\n1\n6\n7\n25\n",
"2\n3\n5\n1\n8\n",
"6\n4\n9\n10\n89\n"
],
"output": [
"4 4\n",
"0 4\n",
"5 9\n"
]
} | {
"input": [
"8\n4\n1\n2\n9\n",
"398\n235\n999\n663\n552924\n",
"8\n8\n3\n7\n61\n",
"4\n7\n1\n10\n60\n",
"421\n702\n250\n334\n339096\n",
"1000\n1000\n1000\n1000\n1542000\n",
"1000\n1000\n1000\n1000\n2000000\n",
"69\n50\n425\n358\n47212\n",
"1\n8\n6\n1\n11\n",
"10\n6\n5\n3\n56\n... | 1,000 | 500 |
2 | 9 | 1238_C. Standard Free2play | You are playing a game where your character should overcome different obstacles. The current problem is to come down from a cliff. The cliff has height h, and there is a moving platform on each height x from 1 to h.
Each platform is either hidden inside the cliff or moved out. At first, there are n moved out platforms... | {
"input": [
"4\n3 2\n3 1\n8 6\n8 7 6 5 3 2\n9 6\n9 8 5 4 3 1\n1 1\n1\n"
],
"output": [
"0\n1\n2\n0\n"
]
} | {
"input": [
"1\n3 2\n3 2\n",
"28\n8 4\n8 7 6 3\n8 5\n8 7 6 3 1\n8 5\n8 7 6 3 2\n8 6\n8 7 6 3 2 1\n8 4\n8 7 6 4\n8 5\n8 7 6 4 1\n8 5\n8 7 6 4 2\n8 6\n8 7 6 4 2 1\n8 5\n8 7 6 4 3\n8 6\n8 7 6 4 3 1\n8 6\n8 7 6 4 3 2\n8 7\n8 7 6 4 3 2 1\n8 4\n8 7 6 5\n8 5\n8 7 6 5 1\n8 5\n8 7 6 5 2\n8 6\n8 7 6 5 2 1\n8 5\n8 7 6 ... | 1,600 | 0 |
2 | 10 | 1256_D. Binary String Minimizing | You are given a binary string of length n (i. e. a string consisting of n characters '0' and '1').
In one move you can swap two adjacent characters of the string. What is the lexicographically minimum possible string you can obtain from the given one if you can perform no more than k moves? It is possible that you do ... | {
"input": [
"3\n8 5\n11011010\n7 9\n1111100\n7 11\n1111100\n"
],
"output": [
"01011110\n0101111\n0011111\n"
]
} | {
"input": [
"2\n8 5\n11011010\n7 9\n1111100\n",
"1\n2 1\n00\n"
],
"output": [
"01011110\n0101111\n",
"00\n"
]
} | 1,500 | 0 |
2 | 10 | 127_D. Password | Asterix, Obelix and their temporary buddies Suffix and Prefix has finally found the Harmony temple. However, its doors were firmly locked and even Obelix had no luck opening them.
A little later they found a string s, carved on a rock below the temple's gates. Asterix supposed that that's the password that opens the t... | {
"input": [
"abcdabc\n",
"fixprefixsuffix\n"
],
"output": [
"Just a legend",
"fix"
]
} | {
"input": [
"aba\n",
"aaaaabaaaa\n",
"papapapap\n",
"aaa\n",
"abc\n",
"kwuaizneqxfflhmyruotjlkqksinoanvkyvqptkkntnpjdyzicceelgooajdgpkneuhyvhdtmasiglplajxolxovlhkwuaizneqx\n",
"aab\n",
"btbdpnzdenxueteteytvkwnegodyhmdwhmrmbftrifytzudumzlacwytsuzefqfpjesdblxhpcsidgksisjdmhyxmmugrjmtfcg... | 1,700 | 1,000 |
2 | 9 | 12_C. Fruits | The spring is coming and it means that a lot of fruits appear on the counters. One sunny day little boy Valera decided to go shopping. He made a list of m fruits he wanted to buy. If Valera want to buy more than one fruit of some kind, he includes it into the list several times.
When he came to the fruit stall of Ash... | {
"input": [
"5 3\n4 2 1 10 5\napple\norange\nmango\n",
"6 5\n3 5 1 6 8 1\npeach\ngrapefruit\nbanana\norange\norange\n"
],
"output": [
"7 19\n",
"11 30\n"
]
} | {
"input": [
"3 1\n14 26 22\naag\n",
"3 3\n4 2 3\nwivujdxzjm\nawagljmtc\nwivujdxzjm\n",
"1 4\n1\nu\nu\nu\nu\n",
"12 18\n42 44 69 16 81 64 12 68 70 75 75 67\nfm\nqamklzfmrjnqgdspwfasjnplg\nqamklzfmrjnqgdspwfasjnplg\nqamklzfmrjnqgdspwfasjnplg\nl\nl\nl\nfm\nqamklzfmrjnqgdspwfasjnplg\nl\nnplgwotfm\np\nl\n... | 1,100 | 0 |
2 | 11 | 1323_E. Instant Noodles | Wu got hungry after an intense training session, and came to a nearby store to buy his favourite instant noodles. After Wu paid for his purchase, the cashier gave him an interesting task.
You are given a bipartite graph with positive integers in all vertices of the right half. For a subset S of vertices of the left ha... | {
"input": [
"3\n2 4\n1 1\n1 1\n1 2\n2 1\n2 2\n\n3 4\n1 1 1\n1 1\n1 2\n2 2\n2 3\n\n4 7\n36 31 96 29\n1 2\n1 3\n1 4\n2 2\n2 4\n3 1\n4 3\n"
],
"output": [
"2\n1\n12\n"
]
} | {
"input": [
"1\n100 27\n10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 1... | 2,300 | 1,500 |
2 | 10 | 1342_D. Multiple Testcases | So you decided to hold a contest on Codeforces. You prepared the problems: statements, solutions, checkers, validators, tests... Suddenly, your coordinator asks you to change all your tests to multiple testcases in the easiest problem!
Initially, each test in that problem is just an array. The maximum size of an array... | {
"input": [
"6 10\n5 8 1 10 8 7\n6 6 4 4 3 2 2 2 1 1\n",
"5 1\n1 1 1 1 1\n5\n",
"5 1\n1 1 1 1 1\n1\n",
"4 3\n1 2 2 3\n4 1 1\n"
],
"output": [
"2\n3 10 8 5\n3 8 7 1\n",
"1\n5 1 1 1 1 1 \n",
"5\n1 1 \n1 1 \n1 1 \n1 1 \n1 1 \n",
"3\n2 3 1\n1 2\n1 2\n"
]
} | {
"input": [
"1 10\n10\n1 1 1 1 1 1 1 1 1 1\n",
"1 1\n1\n1\n",
"10 2\n1 2 2 2 2 2 2 2 2 2\n10 1\n",
"10 20\n20 1 15 17 11 2 15 3 16 3\n10 9 9 9 8 8 8 7 7 7 7 6 6 4 4 4 3 3 3 2\n",
"4 3\n1 2 2 3\n4 1 1\n",
"10 5\n2 2 4 4 3 1 1 2 3 2\n9 6 6 4 1\n",
"100 50\n20 13 10 38 7 22 40 15 27 32 37 44... | 1,900 | 0 |
2 | 10 | 1364_D. Ehab's Last Corollary | Given a connected undirected graph with n vertices and an integer k, you have to either:
* either find an independent set that has exactly ⌈k/2⌉ vertices.
* or find a simple cycle of length at most k.
An independent set is a set of vertices such that no two of them are connected by an edge. A simple cycle is a... | {
"input": [
"4 5 3\n1 2\n2 3\n3 4\n4 1\n2 4\n",
"5 4 5\n1 2\n1 3\n2 4\n2 5\n",
"4 4 3\n1 2\n2 3\n3 4\n4 1\n",
"4 6 3\n1 2\n2 3\n3 4\n4 1\n1 3\n2 4\n"
],
"output": [
"2\n3\n4 3 2 \n",
"1\n1 4 5\n",
"1\n1 3 \n",
"2\n3\n3 2 1 "
]
} | {
"input": [
"6 8 5\n1 6\n2 3\n2 4\n2 5\n3 4\n3 5\n4 5\n5 6\n",
"3 3 3\n1 2\n2 3\n3 1\n",
"5 6 5\n1 2\n2 3\n3 1\n3 4\n4 5\n5 3\n",
"6 15 3\n4 5\n4 6\n4 1\n4 3\n4 2\n5 6\n5 1\n5 3\n5 2\n6 1\n6 3\n6 2\n1 3\n1 2\n3 2\n",
"5 6 4\n1 2\n2 3\n3 4\n4 5\n3 1\n5 1\n",
"8 9 3\n8 1\n8 7\n8 6\n7 2\n2 4\n2 ... | 2,100 | 2,000 |
2 | 8 | 1406_B. Maximum Product | You are given an array of integers a_1,a_2,…,a_n. Find the maximum possible value of a_ia_ja_ka_la_t among all five indices (i, j, k, l, t) (i<j<k<l<t).
Input
The input consists of multiple test cases. The first line contains an integer t (1≤ t≤ 2 ⋅ 10^4) — the number of test cases. The description of the test cases ... | {
"input": [
"4\n5\n-1 -2 -3 -4 -5\n6\n-1 -2 -3 1 2 -1\n6\n-1 0 0 0 -1 -1\n6\n-9 -7 -5 -3 -2 1\n"
],
"output": [
"-120\n12\n0\n945\n"
]
} | {
"input": [
"1\n5\n-3000 -3000 -3000 3000 3000\n"
],
"output": [
"-243000000000000000\n"
]
} | 1,200 | 1,000 |
2 | 9 | 1427_C. The Hard Work of Paparazzi | You are a paparazzi working in Manhattan.
Manhattan has r south-to-north streets, denoted by numbers 1, 2,…, r in order from west to east, and r west-to-east streets, denoted by numbers 1,2,…,r in order from south to north. Each of the r south-to-north streets intersects each of the r west-to-east streets; the interse... | {
"input": [
"500 10\n69 477 122\n73 186 235\n341 101 145\n372 77 497\n390 117 440\n494 471 37\n522 300 498\n682 149 379\n821 486 359\n855 157 386\n",
"10 4\n1 2 1\n5 10 9\n13 8 8\n15 9 9\n",
"6 9\n1 2 6\n7 5 1\n8 5 5\n10 3 1\n12 4 4\n13 6 2\n17 6 6\n20 1 4\n21 5 4\n",
"10 1\n11 6 8\n"
],
"output"... | {
"input": [
"500 3\n2002 1 1\n2003 500 500\n2004 500 500\n",
"2 3\n1 1 1\n100 2 2\n10000 1 1\n",
"500 2\n950 500 500\n3000 1 1\n",
"500 1\n26969 164 134\n",
"4 3\n851 4 3\n1573 1 4\n2318 3 4\n",
"500 2\n2000 1 1\n4000 1 1\n",
"10 3\n26 10 9\n123 2 2\n404 5 6\n"
],
"output": [
"2\n... | 2,000 | 1,000 |
2 | 9 | 1450_C1. Errich-Tac-Toe (Easy Version) | The only difference between the easy and hard versions is that tokens of type O do not appear in the input of the easy version.
Errichto gave Monogon the following challenge in order to intimidate him from taking his top contributor spot on Codeforces.
In a Tic-Tac-Toe grid, there are n rows and n columns. Each cell ... | {
"input": [
"3\n3\n.X.\nXXX\n.X.\n6\nXX.XXX\nXXXXXX\nXXX.XX\nXXXXXX\nXX.X.X\nXXXXXX\n5\nXXX.X\n.X..X\nXXX.X\n..X..\n..X..\n"
],
"output": [
"\n.X.\nXOX\n.X.\nXX.XXO\nXOXXOX\nOXX.XX\nXOOXXO\nXX.X.X\nOXXOXX\nXOX.X\n.X..X\nXXO.O\n..X..\n..X..\n"
]
} | {
"input": [
"1\n6\nXXXXXX\nXXXXXX\nXX..XX\nXX..XX\nXXXXXX\nXXXXXX\n",
"3\n3\n.X.\nXXX\n.X.\n6\nXX.XXX\nXXXXXX\nXXX.XX\nXXXXXX\nXX.X.X\nXXXXXX\n5\nXXX.X\n.X..X\nXXX.X\n..X..\n..X..\n"
],
"output": [
"XXOXXO\nXOXXOX\nOX..XX\nXX..XO\nXOXXOX\nOXXOXX\n",
".X.\nXOX\n.X.\nXX.XXO\nXOXXOX\nOXX.XX\nXXOXXO\... | 2,100 | 1,000 |
2 | 9 | 149_C. Division into Teams | Petya loves football very much, especially when his parents aren't home. Each morning he comes to the yard, gathers his friends and they play all day. From time to time they have a break to have some food or do some chores (for example, water the flowers).
The key in football is to divide into teams fairly before the ... | {
"input": [
"5\n2 3 3 1 1\n",
"3\n1 2 1\n"
],
"output": [
"3\n4 1 3 \n2\n5 2 \n",
"2\n1 2 \n1\n3 \n"
]
} | {
"input": [
"100\n85 50 17 89 65 89 5 20 86 26 16 21 85 14 44 31 87 31 6 2 48 67 8 80 79 1 48 36 97 1 5 30 79 50 78 12 2 55 76 100 54 40 26 81 97 96 68 56 87 14 51 17 54 37 52 33 69 62 38 63 74 15 62 78 9 19 67 2 60 58 93 60 18 96 55 48 34 7 79 82 32 58 90 67 20 50 27 15 7 89 98 10 11 15 99 49 4 51 77 52\n",
... | 1,500 | 1,500 |
2 | 9 | 1523_C. Compression and Expansion | <image>
William is a huge fan of planning ahead. That is why he starts his morning routine by creating a nested list of upcoming errands.
A valid nested list is any list which can be created from a list with one item "1" by applying some operations. Each operation inserts a new item into the list, on a new line, just... | {
"input": [
"2\n4\n1\n1\n2\n3\n9\n1\n1\n1\n2\n2\n1\n2\n1\n2\n"
],
"output": [
"\n1\n1.1\n1.2\n1.3\n1\n1.1\n1.1.1\n1.1.2\n1.2\n1.2.1\n2\n2.1\n2.2\n"
]
} | {
"input": [
"2\n4\n1\n1\n2\n3\n9\n1\n1\n1\n2\n2\n1\n2\n1\n2\n",
"7\n1\n1\n2\n1\n1\n2\n1\n2\n3\n1\n1\n1\n3\n1\n1\n2\n3\n1\n2\n1\n3\n1\n2\n3\n",
"10\n4\n1\n1\n1\n1\n4\n1\n1\n1\n2\n4\n1\n1\n2\n1\n4\n1\n1\n2\n2\n4\n1\n1\n2\n3\n4\n1\n2\n1\n1\n4\n1\n2\n1\n2\n4\n1\n2\n1\n3\n4\n1\n2\n3\n1\n4\n1\n2\n3\n4\n"
],
... | 1,600 | 1,500 |
2 | 8 | 155_B. Combination | Ilya plays a card game by the following rules.
A player has several cards. Each card contains two non-negative integers inscribed, one at the top of the card and one at the bottom. At the beginning of the round the player chooses one of his cards to play it. If the top of the card contains number ai, and the bottom co... | {
"input": [
"2\n1 0\n2 0\n",
"3\n1 0\n2 0\n0 2\n"
],
"output": [
"2\n",
"3\n"
]
} | {
"input": [
"2\n0 10000\n1 0\n",
"1\n2 9999\n",
"1\n10 1\n",
"100\n0 1\n0 1\n0 1\n0 1\n0 1\n0 1\n0 1\n0 1\n0 1\n0 1\n0 1\n0 1\n0 1\n0 1\n0 1\n0 1\n0 1\n0 1\n0 1\n0 1\n0 1\n0 1\n0 1\n0 1\n0 1\n0 1\n0 1\n0 1\n0 1\n0 1\n0 1\n0 1\n0 0\n0 1\n0 1\n0 1\n0 1\n0 1\n0 1\n0 1\n0 1\n0 1\n0 1\n0 1\n0 1\n0 1\n0 1\... | 1,100 | 1,000 |
2 | 9 | 177_C2. Party | To celebrate the second ABBYY Cup tournament, the Smart Beaver decided to throw a party. The Beaver has a lot of acquaintances, some of them are friends with each other, and some of them dislike each other. To make party successful, the Smart Beaver wants to invite only those of his friends who are connected by friends... | {
"input": [
"9\n8\n1 2\n1 3\n2 3\n4 5\n6 7\n7 8\n8 9\n9 6\n2\n1 6\n7 9\n"
],
"output": [
"3\n"
]
} | {
"input": [
"7\n8\n1 2\n1 3\n1 4\n1 5\n2 4\n2 5\n3 4\n5 6\n3\n2 6\n5 7\n6 7\n",
"14\n0\n0\n",
"13\n78\n11 1\n10 6\n6 2\n10 1\n11 6\n11 3\n5 3\n8 1\n12 11\n4 2\n10 3\n13 8\n9 8\n11 7\n7 5\n11 2\n7 1\n4 1\n11 10\n8 3\n13 11\n9 6\n13 9\n12 7\n12 8\n12 9\n10 2\n5 2\n12 10\n9 2\n9 7\n3 2\n7 4\n11 4\n13 1\n10 ... | 1,500 | 70 |
2 | 10 | 221_D. Little Elephant and Array | The Little Elephant loves playing with arrays. He has array a, consisting of n positive integers, indexed from 1 to n. Let's denote the number with index i as ai.
Additionally the Little Elephant has m queries to the array, each query is characterised by a pair of integers lj and rj (1 ≤ lj ≤ rj ≤ n). For each query ... | {
"input": [
"7 2\n3 1 2 2 3 3 7\n1 7\n3 4\n"
],
"output": [
"3\n1\n"
]
} | {
"input": [
"6 6\n1 2 2 3 3 3\n1 2\n2 2\n1 3\n2 4\n4 6\n1 6\n",
"1 2\n1\n1 1\n1 1\n",
"1 1\n1000000000\n1 1\n"
],
"output": [
"1\n0\n2\n1\n1\n3\n",
"1\n1\n",
"0\n"
]
} | 1,800 | 1,000 |
2 | 11 | 245_E. Mishap in Club | Polycarpus just has been out of luck lately! As soon as he found a job in the "Binary Cat" cafe, the club got burgled. All ice-cream was stolen.
On the burglary night Polycarpus kept a careful record of all club visitors. Each time a visitor entered the club, Polycarpus put down character "+" in his notes. Similarly, ... | {
"input": [
"+-+-+\n",
"---"
],
"output": [
"1\n",
"3\n"
]
} | {
"input": [
"++\n",
"-+-\n",
"+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++... | 1,400 | 0 |
2 | 9 | 270_C. Magical Boxes | Emuskald is a well-known illusionist. One of his trademark tricks involves a set of magical boxes. The essence of the trick is in packing the boxes inside other boxes.
From the top view each magical box looks like a square with side length equal to 2k (k is an integer, k ≥ 0) units. A magical box v can be put inside a... | {
"input": [
"2\n0 3\n1 5\n",
"2\n1 10\n2 2\n",
"1\n0 4\n"
],
"output": [
"3\n",
"3\n",
"1\n"
]
} | {
"input": [
"1\n0 17\n",
"5\n1 1000000\n100 100\n101 9\n102 4\n103 8\n",
"16\n1296 2\n1568 1\n7435 2\n3660 1\n6863 2\n886 2\n2596 1\n7239 1\n6146 1\n5634 1\n3119 2\n1166 2\n7610 2\n5992 1\n630 2\n8491 2\n",
"3\n0 20\n1 18\n2 4\n",
"1\n1 1000000000\n",
"1\n0 1\n",
"2\n100 52\n101 4\n",
... | 1,600 | 500 |
2 | 9 | 317_C. Balance | A system of n vessels with water is given. Several pairs of vessels are connected by tubes with transfusion mechanisms. One may transfer an integer amount of liters of water between two vessels connected by such tube (tube works in both directions). There might be multiple tubes between two vessels. Total number of tub... | {
"input": [
"2 10 1\n1 9\n5 5\n1 2\n",
"2 10 0\n5 2\n4 2\n",
"2 10 0\n4 2\n4 2\n"
],
"output": [
"1\n2 1 4 \n",
"NO",
"0\n"
]
} | {
"input": [
"2 1000000000 2\n1000000000 999999999\n999999999 1000000000\n1 2\n2 1\n",
"1 1000000000 0\n999999999\n1000000000\n",
"1 1000000000 0\n1000000000\n1000000000\n",
"10 1 3\n0 1 0 1 0 1 0 1 0 1\n1 0 1 0 0 1 0 1 1 0\n1 2\n9 10\n3 4\n",
"5 1000000000 4\n1000000000 1000000000 1000000000 1000... | 2,500 | 2,500 |
2 | 9 | 341_C. Iahub and Permutations | Iahub is so happy about inventing bubble sort graphs that he's staying all day long at the office and writing permutations. Iahubina is angry that she is no more important for Iahub. When Iahub goes away, Iahubina comes to his office and sabotage his research work.
The girl finds an important permutation for the resea... | {
"input": [
"5\n-1 -1 4 3 -1\n"
],
"output": [
"2\n"
]
} | {
"input": [
"6\n-1 -1 -1 -1 -1 -1\n",
"10\n4 10 -1 1 6 8 9 2 -1 -1\n",
"7\n-1 -1 4 -1 7 1 6\n",
"2\n-1 -1\n",
"8\n2 4 5 3 -1 8 -1 6\n",
"20\n-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1\n"
],
"output": [
"265\n",
"4\n",
"4\n",
"1\n",
"1\n",
"92779975... | 2,000 | 3,000 |
2 | 10 | 388_D. Fox and Perfect Sets | Fox Ciel studies number theory.
She thinks a non-empty set S contains non-negative integers is perfect if and only if for any <image> (a can be equal to b), <image>. Where operation xor means exclusive or operation (http://en.wikipedia.org/wiki/Exclusive_or).
Please calculate the number of perfect sets consisting of ... | {
"input": [
"2\n",
"4\n",
"1\n",
"3\n"
],
"output": [
"3\n",
"6\n",
"2\n",
"5\n"
]
} | {
"input": [
"102513046\n",
"685146646\n",
"11\n",
"10\n",
"752887969\n",
"341796022\n",
"585325539\n",
"930971393\n",
"802030518\n",
"18\n",
"702209411\n",
"7\n",
"0\n",
"536870912\n",
"335521569\n",
"13\n",
"985629174\n",
"5\n",
"16\n",
... | 2,700 | 2,000 |
2 | 8 | 409_B. Mysterious Language | You are given a mysterious language (codenamed "Secret") available in "Custom Invocation" tab. Figure out what this language is and write a program which prints its name. Note that the program must be written in this language.
Input
This program has only one test (your program doesn't have to read anything).
Output
... | {
"input": [],
"output": []
} | {
"input": [
"1\n"
],
"output": [
"INTERCAL\n"
]
} | 1,700 | 0 |
2 | 9 | 436_C. Dungeons and Candies | 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 a cell ... | {
"input": [
"1 1 4 1\nA\n.\nB\n.\n",
"1 3 5 2\nABA\nBBB\nBBA\nBAB\nABB\n",
"2 3 3 2\nA.A\n...\nA.a\n..C\nX.Y\n...\n"
],
"output": [
"3\n1 0\n2 0\n4 2\n3 0\n",
"11\n1 0\n3 1\n2 3\n4 2\n5 1\n",
"14\n1 0\n2 1\n3 1\n"
]
} | {
"input": [
"2 3 10 2\nABB\nABA\nAAB\nBAB\nAAA\nBBA\nBBB\nBAA\nBBB\nABB\nABA\nBBA\nBBB\nAAB\nABA\nABB\nBBA\nBAB\nBBB\nBBB\n",
"3 2 10 1\nAB\nBA\nAB\nAA\nAA\nBA\nAA\nAA\nAB\nAB\nAB\nBA\nBA\nAB\nAA\nBB\nAB\nBA\nBB\nBB\nBA\nAA\nAA\nAB\nAB\nAB\nBA\nBB\nAB\nAA\n",
"3 3 10 2\nBA.\n..A\n.BB\nB..\n..B\n.AA\nB..\... | 1,800 | 1,500 |
2 | 10 | 459_D. Pashmak and Parmida's problem | Parmida is a clever girl and she wants to participate in Olympiads this year. Of course she wants her partner to be clever too (although he's not)! Parmida has prepared the following test problem for Pashmak.
There is a sequence a that consists of n integers a1, a2, ..., an. Let's denote f(l, r, x) the number of indic... | {
"input": [
"3\n1 1 1\n",
"5\n1 2 3 4 5\n",
"7\n1 2 1 1 2 2 1\n"
],
"output": [
"1\n",
"0\n",
"8\n"
]
} | {
"input": [
"2\n1 1\n",
"1\n1\n",
"4\n1 1 2 2\n",
"24\n1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4\n",
"5\n1 1 2 2 2\n",
"2\n1 2\n"
],
"output": [
"0\n",
"0\n",
"1\n",
"114\n",
"2\n",
"0\n"
]
} | 1,800 | 2,000 |
2 | 9 | 480_C. Riding in a Lift | Imagine that you are in a building that has exactly n floors. You can move between the floors in a lift. Let's number the floors from bottom to top with integers from 1 to n. Now you're on the floor number a. You are very bored, so you want to take the lift. Floor number b has a secret lab, the entry is forbidden. Howe... | {
"input": [
"5 2 4 1\n",
"5 2 4 2\n",
"5 3 4 1\n"
],
"output": [
"2\n",
"2\n",
"0"
]
} | {
"input": [
"5000 2314 1234 5000\n",
"3 2 3 1\n",
"4988 3629 4106 4488\n",
"300 1 300 300\n",
"2 1 2 1\n",
"4999 1 2 4999\n",
"3999 2 10 5000\n",
"10 1 4 4999\n",
"22 9 18 3\n",
"10 1 10 2\n",
"5 3 2 2\n",
"50 5 2 50\n",
"5000 2 5000 5000\n",
"5 1 2 1\n",
"... | 1,900 | 2,500 |
2 | 8 | 529_B. Group Photo 2 (online mirror version) | Many years have passed, and n friends met at a party again. Technologies have leaped forward since the last meeting, cameras with timer appeared and now it is not obligatory for one of the friends to stand with a camera, and, thus, being absent on the photo.
Simply speaking, the process of photographing can be describ... | {
"input": [
"3\n10 1\n20 2\n30 3\n",
"1\n5 10\n",
"3\n3 1\n2 2\n4 3\n"
],
"output": [
"180\n",
"50\n",
"21\n"
]
} | {
"input": [
"4\n573 7\n169 9\n447 7\n947 3\n",
"10\n489 685\n857 870\n736 221\n687 697\n166 360\n265 200\n738 519\n393 760\n66 176\n798 160\n",
"3\n203 145\n780 692\n992 713\n",
"3\n627 286\n37 65\n53 490\n",
"3\n475 487\n41 20\n368 236\n",
"3\n7 612\n3 259\n3 895\n",
"3\n99 768\n477 885\... | 1,900 | 500 |
2 | 10 | 554_D. Kyoya and Permutation | Let's define the permutation of length n as an array p = [p1, p2, ..., pn] consisting of n distinct integers from range from 1 to n. We say that this permutation maps value 1 into the value p1, value 2 into the value p2 and so on.
Kyota Ootori has just learned about cyclic representation of a permutation. A cycle is a... | {
"input": [
"10 1\n",
"4 3\n"
],
"output": [
"1 2 3 4 5 6 7 8 9 10\n",
"1 3 2 4\n"
]
} | {
"input": [
"31 1899100\n",
"16 747\n",
"44 863791309\n",
"25 121393\n",
"15 463\n",
"36 7074882\n",
"50 20365011074\n",
"34 2412850\n",
"39 68773650\n",
"24 47430\n",
"18 1809\n",
"19 859\n",
"10 89\n",
"6 10\n",
"32 1314567\n",
"2 2\n",
"23 45599\... | 1,900 | 500 |
2 | 9 | 580_C. Kefa and Park | Kefa decided to celebrate his first big salary by going to the restaurant.
He lives by an unusual park. The park is a rooted tree consisting of n vertices with the root at vertex 1. Vertex 1 also contains Kefa's house. Unfortunaely for our hero, the park also contains cats. Kefa has already found out what are the ver... | {
"input": [
"7 1\n1 0 1 1 0 0 0\n1 2\n1 3\n2 4\n2 5\n3 6\n3 7\n",
"4 1\n1 1 0 0\n1 2\n1 3\n1 4\n"
],
"output": [
"2\n",
"2\n"
]
} | {
"input": [
"5 2\n1 1 0 1 1\n1 2\n2 3\n3 4\n4 5\n",
"6 1\n1 0 1 1 0 0\n1 2\n1 3\n1 4\n1 5\n1 6\n",
"2 1\n1 1\n2 1\n",
"3 2\n1 1 1\n1 2\n2 3\n",
"12 3\n1 0 1 0 1 1 1 1 0 0 0 0\n6 7\n12 1\n9 7\n1 4\n10 7\n7 1\n11 8\n5 1\n3 7\n5 8\n4 2\n",
"15 2\n1 0 1 0 1 0 0 0 0 0 0 0 0 0 0\n1 2\n1 3\n2 4\n2 5... | 1,500 | 1,500 |
2 | 8 | 602_B. Approximating a Constant Range | When Xellos was doing a practice course in university, he once had to measure the intensity of an effect that slowly approached equilibrium. A good way to determine the equilibrium intensity would be choosing a sufficiently large number of consecutive data points that seems as constant as possible and taking their aver... | {
"input": [
"5\n1 2 3 3 2\n",
"11\n5 4 5 5 6 7 8 8 8 7 6\n"
],
"output": [
"4\n",
"5\n"
]
} | {
"input": [
"2\n99999 100000\n",
"4\n4 3 2 3\n",
"3\n1 2 3\n",
"4\n10 9 10 9\n",
"3\n1 2 2\n",
"2\n3 2\n",
"3\n99998 99999 100000\n",
"18\n10 9 8 7 6 5 4 3 2 1 2 3 4 5 6 7 8 9\n",
"3\n1 2 1\n",
"15\n1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000\n",... | 1,400 | 1,000 |
2 | 8 | 673_B. Problems for Round | There are n problems prepared for the next Codeforces round. They are arranged in ascending order by their difficulty, and no two problems have the same difficulty. Moreover, there are m pairs of similar problems. Authors want to split problems between two division according to the following rules:
* Problemset of ... | {
"input": [
"3 2\n3 1\n3 2\n",
"3 3\n1 2\n2 3\n1 3\n",
"5 2\n1 4\n5 2\n"
],
"output": [
"1\n",
"0\n",
"2\n"
]
} | {
"input": [
"3 1\n1 2\n",
"4 2\n3 4\n1 2\n",
"5 1\n1 5\n",
"5 2\n3 5\n1 2\n",
"2 1\n1 2\n",
"3 1\n1 3\n",
"7 2\n1 5\n5 2\n",
"100000 0\n",
"4 2\n1 2\n3 4\n",
"4 2\n1 4\n3 2\n",
"100000 1\n100000 1\n",
"3 2\n1 2\n2 3\n",
"4 2\n1 2\n1 3\n",
"10 11\n1 10\n1 9\n1 8... | 1,300 | 750 |
2 | 9 | 719_C. Efim and Strange Grade | Efim just received his grade for the last test. He studies in a special school and his grade can be equal to any positive decimal fraction. First he got disappointed, as he expected a way more pleasant result. Then, he developed a tricky plan. Each second, he can ask his teacher to round the grade at any place after th... | {
"input": [
"6 2\n10.245\n",
"3 100\n9.2\n",
"6 1\n10.245\n"
],
"output": [
"10.3",
"9.2",
"10.25"
]
} | {
"input": [
"13 1\n761.044449428\n",
"35 8\n984227318.2031144444444444494637612\n",
"31 15\n2707786.24030444444444444724166\n",
"3 1\n0.1\n",
"9 2\n23999.448\n",
"12 5\n872.04488525\n",
"320 142\n2704701300865535.4322233122334341141300111132201024201313230103441442011243031444444444444444... | 1,700 | 500 |
2 | 7 | 740_A. Alyona and copybooks | Little girl Alyona is in a shop to buy some copybooks for school. She study four subjects so she wants to have equal number of copybooks for each of the subjects. There are three types of copybook's packs in the shop: it is possible to buy one copybook for a rubles, a pack of two copybooks for b rubles, and a pack of t... | {
"input": [
"1 1 3 4\n",
"999999999 1000000000 1000000000 1000000000\n",
"6 2 1 1\n",
"4 4 4 4\n"
],
"output": [
"3\n",
"1000000000\n",
"1\n",
"0\n"
]
} | {
"input": [
"3 1000000000 1 1000000000\n",
"561775796 937657403 280013594 248004555\n",
"7 12 6 1\n",
"1000000000 1000000000 1000000000 1000000000\n",
"4448 2 3 6\n",
"19 4 3 1\n",
"7 9 2 7\n",
"505246946 439473295 30527185 869771841\n",
"432392275 216296044 751173719 109054817\n"... | 1,300 | 500 |
2 | 8 | 787_B. Not Afraid | Since the giant heads have appeared in the sky all humanity is in danger, so all Ricks and Mortys from all parallel universes are gathering in groups to find a solution to get rid of them.
There are n parallel universes participating in this event (n Ricks and n Mortys). I. e. each of n universes has one Rick and one... | {
"input": [
"5 2\n5 3 -2 1 -1 5\n3 -5 2 5\n",
"4 2\n1 -3\n4 -2 3 2 -3\n",
"7 2\n3 -1 6 7\n7 -5 4 2 4 7 -3 4\n"
],
"output": [
"NO\n",
"YES\n",
"YES\n"
]
} | {
"input": [
"10 1\n2 4 4\n",
"5 1\n2 -1 -1\n",
"3 1\n3 1 1 2\n",
"10000 1\n1 2550\n",
"1 1\n1 1\n",
"2 1\n2 2 2\n",
"4 1\n3 1 1 -1\n",
"4 2\n2 1 -1\n1 1\n",
"1 2\n2 1 -1\n2 -1 -1\n",
"10000 1\n2 -6748 6748\n",
"4 1\n4 3 3 3 3\n",
"1 1\n2 1 1\n",
"10000 1\n2 -3 -3\n... | 1,300 | 1,000 |
2 | 8 | 924_B. Three-level Laser | An atom of element X can exist in n distinct states with energies E1 < E2 < ... < En. Arkady wants to build a laser on this element, using a three-level scheme. Here is a simplified description of the scheme.
Three distinct states i, j and k are selected, where i < j < k. After that the following process happens:
... | {
"input": [
"3 1\n2 5 10\n",
"10 8\n10 13 15 16 17 19 20 22 24 25\n",
"4 4\n1 3 5 7\n"
],
"output": [
"-1",
"0.875",
"0.5"
]
} | {
"input": [
"5 2\n4 6 8 9 10\n",
"20 17\n104 107 121 131 138 140 143 144 178 192 193 198 201 206 238 242 245 248 255 265\n",
"8 2\n1 3 7 9 15 17 23 25\n",
"50 64\n257 258 350 375 1014 1017 1051 1097 1169 1177 1223 1836 1942 1983 2111 2131 2341 2418 2593 2902 2948 3157 3243 3523 3566 4079 4499 4754 50... | 1,600 | 1,000 |
2 | 10 | 952_D. I'm Feeling Lucky! | <image>
You have one chip and one chance to play roulette. Are you feeling lucky?
Output
Print your bet. Your chip must be placed entirely within some square (not on an edge or a corner shared by adjacent squares). | {
"input": [],
"output": []
} | {
"input": [
"1\n",
"2\n"
],
"output": [
"red\n",
"red"
]
} | 1,800 | 0 |
2 | 7 | 99_A. Help Far Away Kingdom | In a far away kingdom lived the King, the Prince, the Shoemaker, the Dressmaker and many other citizens. They lived happily until great trouble came into the Kingdom. The ACMers settled there.
Most damage those strange creatures inflicted upon the kingdom was that they loved high precision numbers. As a result, the Ki... | {
"input": [
"0.0\n",
"1.50\n",
"12345678901234567890.1\n",
"2.71828182845904523536\n",
"1.49\n",
"3.14159265358979323846\n",
"123456789123456789.999\n"
],
"output": [
"0",
"2",
"12345678901234567890",
"3",
"1",
"3",
"GOTO Vasilisa."
]
} | {
"input": [
"7.6\n",
"1950583094879039694852660558765931995628486712128191844305265555887022812284005463780616067.500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000... | 800 | 500 |
2 | 8 | 1011_B. Planning The Expedition | Natasha is planning an expedition to Mars for n people. One of the important tasks is to provide food for each participant.
The warehouse has m daily food packages. Each package has some food type a_i.
Each participant must eat exactly one food package each day. Due to extreme loads, each participant must eat the sam... | {
"input": [
"4 10\n1 5 2 1 1 1 2 5 7 2\n",
"2 5\n5 4 3 2 1\n",
"3 9\n42 42 42 42 42 42 42 42 42\n",
"100 1\n1\n"
],
"output": [
"2\n",
"1\n",
"3\n",
"0\n"
]
} | {
"input": [
"50 100\n2 37 74 32 99 75 73 86 67 33 62 30 15 21 51 41 73 75 67 39 90 10 56 74 72 26 38 65 75 55 46 99 34 49 92 82 11 100 15 71 75 12 22 56 47 74 20 98 59 65 14 76 1 40 89 36 43 93 83 73 75 100 50 95 27 10 72 51 25 69 15 3 57 60 84 99 31 44 12 61 69 95 51 31 28 36 57 35 31 52 44 19 79 12 27 27 7 81 ... | 1,200 | 1,000 |
2 | 8 | 1059_B. Forgery | Student Andrey has been skipping physical education lessons for the whole term, and now he must somehow get a passing grade on this subject. Obviously, it is impossible to do this by legal means, but Andrey doesn't give up. Having obtained an empty certificate from a local hospital, he is going to use his knowledge of ... | {
"input": [
"4 3\n###\n###\n###\n###\n",
"5 7\n.......\n.#####.\n.#.#.#.\n.#####.\n.......\n",
"3 3\n###\n###\n###\n",
"3 3\n###\n#.#\n###\n"
],
"output": [
"YES\n",
"YES\n",
"NO\n",
"YES\n"
]
} | {
"input": [
"3 4\n####\n#.##\n####\n",
"5 8\n........\n.######.\n.######.\n.######.\n........\n",
"5 7\n.......\n.######\n.#.#.##\n.######\n.......\n",
"8 8\n.#.#.#.#\n#.#.#.#.\n.#.#.#.#\n#.#.#.#.\n.#.#.#.#\n#.#.#.#.\n.#.#.#.#\n#.#.#.#.\n",
"3 3\n...\n...\n...\n"
],
"output": [
"NO\n",
... | 1,300 | 1,000 |
2 | 10 | 1080_D. Olya and magical square | Recently, Olya received a magical square with the size of 2^n× 2^n.
It seems to her sister that one square is boring. Therefore, she asked Olya to perform exactly k splitting operations.
A Splitting operation is an operation during which Olya takes a square with side a and cuts it into 4 equal squares with side a/2. ... | {
"input": [
"3\n1 1\n2 2\n2 12\n"
],
"output": [
"YES 0\nYES 1\nNO\n"
]
} | {
"input": [
"1\n3 10\n",
"1\n30 660981744053648874\n",
"19\n1 2\n2 1\n2 2\n2 3\n2 4\n2 5\n2 6\n1 1000000000000000000\n1000000000 1000000000000000000\n64 64\n64 3\n4 4\n2 100\n3 6\n3 7\n4 10000\n4 100000\n4 71\n4 70\n"
],
"output": [
"YES 1\n",
"NO\n",
"NO\nYES ... | 2,000 | 1,750 |
2 | 9 | 10_C. Digital Root | Not long ago Billy came across such a problem, where there were given three natural numbers A, B and C from the range [1, N], and it was asked to check whether the equation AB = C is correct. Recently Billy studied the concept of a digital root of a number. We should remind you that a digital root d(x) of the number x ... | {
"input": [
"4\n",
"5\n"
],
"output": [
"2\n",
"6\n"
]
} | {
"input": [
"127\n",
"987572\n",
"600000\n",
"16\n",
"8\n",
"6\n",
"983242\n",
"783472\n",
"99999\n",
"729761\n",
"10\n",
"498138\n",
"50\n",
"15\n",
"571\n",
"20\n",
"312433\n",
"600\n",
"653451\n",
"202\n",
"828282\n",
"1000000... | 2,000 | 0 |
2 | 8 | 1121_B. Mike and Children | Mike decided to teach programming to children in an elementary school. He knows that it is not an easy task to interest children in that age to code. That is why he decided to give each child two sweets.
Mike has n sweets with sizes a_1, a_2, …, a_n. All his sweets have different sizes. That is, there is no such pair ... | {
"input": [
"7\n3 1 7 11 9 2 12\n",
"8\n1 8 3 11 4 9 2 7\n"
],
"output": [
"2\n",
"3\n"
]
} | {
"input": [
"6\n99997 99995 100000 99992 99994 99999\n",
"5\n99905 99931 99902 99909 99984\n",
"2\n2 1\n",
"20\n43 48 38 34 23 18 8 22 12 7 47 1 13 20 3 15 49 6 10 26\n",
"2\n100000 99999\n"
],
"output": [
"2\n",
"1\n",
"1\n",
"5\n",
"1\n"
]
} | 1,200 | 1,000 |
2 | 10 | 1148_D. Dirty Deeds Done Dirt Cheap | You are given n pairs of integers (a_1, b_1), (a_2, b_2), …, (a_n, b_n). All of the integers in the pairs are distinct and are in the range from 1 to 2 ⋅ n inclusive.
Let's call a sequence of integers x_1, x_2, …, x_{2k} good if either
* x_1 < x_2 > x_3 < … < x_{2k-2} > x_{2k-1} < x_{2k}, or
* x_1 > x_2 < x_3 >... | {
"input": [
"3\n5 4\n3 2\n6 1\n",
"5\n1 7\n6 4\n2 10\n9 8\n3 5\n"
],
"output": [
"3\n3 2 1 ",
"3\n3 1 5 "
]
} | {
"input": [
"2\n1 3\n2 4\n",
"2\n1 2\n4 3\n",
"5\n1 7\n6 4\n2 10\n9 8\n3 5\n",
"3\n1 4\n2 5\n3 6\n",
"1\n1 2\n"
],
"output": [
"2\n2 1 ",
"1\n2\n",
"3\n3 1 5 ",
"3\n3 2 1 ",
"1\n1 "
]
} | 1,800 | 1,750 |
2 | 7 | 116_A. Tram | Linear Kingdom has exactly one tram line. It has n stops, numbered from 1 to n in the order of tram's movement. At the i-th stop ai passengers exit the tram, while bi passengers enter it. The tram is empty before it arrives at the first stop. Also, when the tram arrives at the last stop, all passengers exit so that it ... | {
"input": [
"4\n0 3\n2 5\n4 2\n4 0\n"
],
"output": [
"6\n"
]
} | {
"input": [
"5\n0 0\n0 0\n0 0\n0 0\n0 0\n",
"10\n0 1\n1 0\n0 0\n0 0\n0 0\n0 1\n1 1\n0 1\n1 0\n1 0\n",
"2\n0 1000\n1000 0\n",
"100\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n... | 800 | 500 |
2 | 7 | 1188_A1. Add on a Tree | Note that this is the first problem of the two similar problems. You can hack this problem only if you solve both problems.
You are given a tree with n nodes. In the beginning, 0 is written on all edges. In one operation, you can choose any 2 distinct leaves u, v and any real number x and add x to values written on al... | {
"input": [
"3\n1 2\n2 3\n",
"6\n1 2\n1 3\n1 4\n2 5\n2 6\n",
"5\n1 2\n1 3\n1 4\n2 5\n",
"2\n1 2\n"
],
"output": [
"NO",
"YES",
"NO\n",
"YES"
]
} | {
"input": [
"3\n1 2\n1 3\n",
"4\n2 4 8896\n2 3 3064\n2 1 2256\n",
"2\n1 2 3182\n",
"10\n4 8 9750\n5 8 9292\n6 3 6168\n7 3 3314\n9 2 5924\n10 2 7624\n8 1 3046\n3 1 9450\n2 1 7286\n",
"5\n5 1\n5 2\n5 3\n5 4\n",
"5\n1 2\n1 5\n1 3\n1 4\n",
"10\n9 5\n7 1\n9 10\n7 2\n5 4\n9 6\n2 9\n10 8\n1 3\n"... | 1,600 | 250 |
2 | 7 | 1207_A. There Are Two Types Of Burgers | There are two types of burgers in your restaurant — hamburgers and chicken burgers! To assemble a hamburger you need two buns and a beef patty. To assemble a chicken burger you need two buns and a chicken cutlet.
You have b buns, p beef patties and f chicken cutlets in your restaurant. You can sell one hamburger for ... | {
"input": [
"3\n15 2 3\n5 10\n7 5 2\n10 12\n1 100 100\n100 100\n"
],
"output": [
"40\n34\n0\n"
]
} | {
"input": [
"1\n18 6 4\n3 4\n",
"7\n1 1 1\n1 1\n100 100 100\n100 100\n1 100 100\n100 100\n100 1 1\n100 100\n100 50 50\n100 99\n100 51 51\n100 99\n99 51 51\n100 99\n"
],
"output": [
"31\n",
"0\n5000\n0\n200\n5000\n5000\n4900\n"
]
} | 800 | 0 |
2 | 10 | 1249_D2. Too Many Segments (hard version) | The only difference between easy and hard versions is constraints.
You are given n segments on the coordinate axis OX. Segments can intersect, lie inside each other and even coincide. The i-th segment is [l_i; r_i] (l_i ≤ r_i) and it covers all integer points j such that l_i ≤ j ≤ r_i.
The integer point is called bad... | {
"input": [
"5 1\n29 30\n30 30\n29 29\n28 30\n30 30\n",
"7 2\n11 11\n9 11\n7 8\n8 9\n7 8\n9 11\n7 9\n",
"6 1\n2 3\n3 3\n2 3\n2 2\n2 3\n2 3\n"
],
"output": [
"3\n4 1 5 ",
"3\n7 4 6 ",
"4\n1 3 5 6 "
]
} | {
"input": [
"16 3\n181 182\n183 184\n179 181\n178 178\n182 185\n177 184\n179 184\n176 184\n177 184\n176 176\n176 185\n183 185\n175 177\n179 183\n184 184\n175 176\n",
"15 2\n4 4\n16 18\n16 18\n6 9\n3 14\n8 11\n3 13\n3 6\n14 16\n5 17\n7 14\n11 14\n4 4\n10 11\n13 17\n",
"11 3\n144 145\n143 143\n143 143\n145... | 1,800 | 0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.