question stringlengths 29 1.88k | test_input listlengths 0 10 | test_output listlengths 0 10 | test_time_limit int64 1 1 | test_method stringclasses 1
value |
|---|---|---|---|---|
Pasha has a wooden stick of some positive integer length n. He wants to perform exactly three cuts to get four parts of the stick. Each part must have some positive integer length and the sum of these lengths will obviously be n.
Pasha likes rectangles but hates squares, so he wonders, how many ways are there to spli... | [
"6\n",
"20\n",
"1\n",
"2\n",
"3\n",
"4\n",
"2000000000\n",
"1924704072\n",
"73740586\n",
"1925088820\n"
] | [
"1\n",
"4\n",
"0\n",
"0\n",
"0\n",
"0\n",
"499999999\n",
"481176017\n",
"18435146\n",
"481272204\n"
] | 1 | stdio |
A sweet little monster Om Nom loves candies very much. One day he found himself in a rather tricky situation that required him to think a bit in order to enjoy candies the most. Would you succeed with the same task if you were on his place? [Image]
One day, when he came to his friend Evan, Om Nom didn't find him at h... | [
"10 3 5 2 3\n",
"5 3 1 6 7\n",
"982068341 55 57 106 109\n",
"930064129 32726326 25428197 83013449 64501049\n",
"927155987 21197 15994 54746 41309\n",
"902303498 609628987 152407246 8 2\n",
"942733698 9180 9072 1020 1008\n",
"951102310 39876134 24967176 70096104 43888451\n",
"910943911 107 105 60 59\... | [
"16\n",
"0\n",
"513558662\n",
"363523396\n",
"358983713\n",
"68758795931537065\n",
"8484603228\n",
"539219654\n",
"1624516635\n",
"518210503\n"
] | 1 | stdio |
You are given a non-negative integer n, its decimal representation consists of at most 100 digits and doesn't contain leading zeroes.
Your task is to determine if it is possible in this case to remove some of the digits (possibly not remove any digit at all) so that the result contains at least one digit, forms a non-... | [
"3454\n",
"10\n",
"111111\n",
"8996988892\n",
"5555555555\n",
"1\n",
"8147522776919916277306861346922924221557534659480258977017038624458370459299847590937757625791239188\n",
"8\n",
"14\n",
"2363\n"
] | [
"YES\n344\n",
"YES\n0\n",
"NO\n",
"YES\n8\n",
"NO\n",
"NO\n",
"YES\n8\n",
"YES\n8\n",
"NO\n",
"NO\n"
] | 1 | stdio |
Bishwock is a chess figure that consists of three squares resembling an "L-bar". This figure can be rotated by 90, 180 and 270 degrees so it can have four possible states:
XX XX .X X.
X. .X XX XX
Bishwocks don't attack any squares and can even occupy on the adjacent squares as long as they don't oc... | [
"00\n00\n",
"00X00X0XXX0\n0XXX0X00X00\n",
"0X0X0\n0X0X0\n",
"0XXX0\n00000\n",
"0\n0\n",
"0\nX\n",
"X\n0\n",
"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX... | [
"1",
"4",
"0",
"2",
"0",
"0",
"0",
"0",
"18",
"0"
] | 1 | stdio |
Polycarp loves lowercase letters and dislikes uppercase ones. Once he got a string s consisting only of lowercase and uppercase Latin letters.
Let A be a set of positions in the string. Let's call it pretty if following conditions are met: letters on positions from A in the string are all distinct and lowercase; the... | [
"11\naaaaBaabAbA\n",
"12\nzACaAbbaazzC\n",
"3\nABC\n",
"1\na\n",
"2\naz\n",
"200\nXbTJZqcbpYuZQEoUrbxlPXAPCtVLrRExpQzxzqzcqsqzsiisswqitswzCtJQxOavicSdBIodideVRKHPojCNHmbnrLgwJlwOpyrJJIhrUePszxSjJGeUgTtOfewPQnPVWhZAtogRPrJLwyShNQaeNsvrJwjuuBOMPCeSckBMISQzGngfOmeyfDObncyeNsihYVtQbSEh\n",
"2\nAZ\n",
"28\... | [
"2\n",
"3\n",
"0\n",
"1\n",
"2\n",
"8\n",
"0\n",
"3\n",
"17\n",
"1\n"
] | 1 | stdio |
You are given a sequence a consisting of n integers. You may partition this sequence into two sequences b and c in such a way that every element belongs exactly to one of these sequences.
Let B be the sum of elements belonging to b, and C be the sum of elements belonging to c (if some of these sequences is empty, the... | [
"3\n1 -2 0\n",
"6\n16 23 16 15 42 8\n",
"1\n-1\n",
"100\n-100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -10... | [
"3\n",
"120\n",
"1\n",
"10000\n",
"6\n",
"3\n",
"94\n",
"4\n",
"400\n",
"17\n"
] | 1 | stdio |
You are given the string s of length n and the numbers p, q. Split the string s to pieces of length p and q.
For example, the string "Hello" for p = 2, q = 3 can be split to the two strings "Hel" and "lo" or to the two strings "He" and "llo".
Note it is allowed to split the string s to the strings only of length p or... | [
"5 2 3\nHello\n",
"10 9 5\nCodeforces\n",
"6 4 5\nPrivet\n",
"8 1 1\nabacabac\n",
"1 1 1\n1\n",
"10 8 1\nuTl9w4lcdo\n",
"20 6 4\nfmFRpk2NrzSvnQC9gB61\n",
"30 23 6\nWXDjl9kitaDTY673R5xyTlbL9gqeQ6\n",
"40 14 3\nSOHBIkWEv7ScrkHgMtFFxP9G7JQLYXFoH1sJDAde\n",
"50 16 3\nXCgVJUu4aMQ7HMxZjNxe3XARNiahK303g9... | [
"2\nHe\nllo\n",
"2\nCodef\norces\n",
"-1\n",
"8\na\nb\na\nc\na\nb\na\nc\n",
"1\n1\n",
"10\nu\nT\nl\n9\nw\n4\nl\nc\nd\no\n",
"5\nfmFR\npk2N\nrzSv\nnQC9\ngB61\n",
"5\nWXDjl9\nkitaDT\nY673R5\nxyTlbL\n9gqeQ6\n",
"6\nSOHBIkWEv7Scrk\nHgMtFFxP9G7JQL\nYXF\noH1\nsJD\nAde\n",
"8\nXCgVJUu4aMQ7HMxZ\njNxe3XARN... | 1 | stdio |
Two positive integers a and b have a sum of s and a bitwise XOR of x. How many possible values are there for the ordered pair (a, b)?
-----Input-----
The first line of the input contains two integers s and x (2 ≤ s ≤ 10^12, 0 ≤ x ≤ 10^12), the sum and bitwise xor of the pair of positive integers, respectively.
---... | [
"9 5\n",
"3 3\n",
"5 2\n",
"6 0\n",
"549755813887 549755813887\n",
"2 0\n",
"2 2\n",
"433864631347 597596794426\n",
"80 12\n",
"549755813888 549755813886\n"
] | [
"4\n",
"2\n",
"0\n",
"1\n",
"549755813886\n",
"1\n",
"0\n",
"0\n",
"4\n",
"274877906944\n"
] | 1 | stdio |
One day, the Grasshopper was jumping on the lawn and found a piece of paper with a string. Grasshopper became interested what is the minimum jump ability he should have in order to be able to reach the far end of the string, jumping only on vowels of the English alphabet. Jump ability is the maximum possible length of ... | [
"ABABBBACFEYUKOTT\n",
"AAA\n",
"A\n",
"B\n",
"AEYUIOAEIYAEOUIYOEIUYEAOIUEOEAYOEIUYAEOUIYEOIKLMJNHGTRWSDZXCVBNMHGFDSXVWRTPPPLKMNBXIUOIUOIUOIUOOIU\n",
"AEYUIOAEIYAEOUIYOEIUYEAOIUEOEAYOEIUYAEOUIYEOIAEYUIOAEIYAEOUIYOEIUYEAOIUEOEAYOEIUYAEOUIYEOI\n",
"KMLPTGFHNBVCDRFGHNMBVXWSQFDCVBNHTJKLPMNFVCKMLPTGFHNBVCDRFG... | [
"4",
"1",
"1",
"2",
"39",
"1",
"85",
"18",
"11",
"12"
] | 1 | stdio |
Today, hedgehog Filya went to school for the very first time! Teacher gave him a homework which Filya was unable to complete without your help.
Filya is given an array of non-negative integers a_1, a_2, ..., a_{n}. First, he pick an integer x and then he adds x to some elements of the array (no more than once), subtra... | [
"5\n1 3 3 2 1\n",
"5\n1 2 3 4 5\n",
"2\n1 2\n",
"3\n1 2 3\n",
"3\n1 1 1\n",
"2\n1 1000000000\n",
"4\n1 2 3 4\n",
"10\n1 1 1 1 1 2 2 2 2 2\n",
"2\n4 2\n",
"4\n1 1 4 7\n"
] | [
"YES\n",
"NO\n",
"YES\n",
"YES\n",
"YES\n",
"YES\n",
"NO\n",
"YES\n",
"YES\n",
"YES\n"
] | 1 | stdio |
There is unrest in the Galactic Senate. Several thousand solar systems have declared their intentions to leave the Republic. Master Heidi needs to select the Jedi Knights who will go on peacekeeping missions throughout the galaxy. It is well-known that the success of any peacekeeping mission depends on the colors of th... | [
"5 2\n1 1 2 2 1\n1 2\n",
"1 1\n1\n1\n",
"2 1\n1 1\n1\n",
"2 1\n1 1\n2\n",
"2 2\n1 2\n1 1\n",
"3 3\n1 1 3\n0 1 2\n",
"4 4\n2 3 3 2\n0 0 1 0\n",
"2 2\n2 2\n0 2\n",
"3 3\n1 1 3\n0 1 1\n",
"4 4\n2 4 4 3\n1 1 1 1\n"
] | [
"YES\n",
"YES\n",
"YES\n",
"YES\n",
"YES\n",
"NO\n",
"YES\n",
"YES\n",
"NO\n",
"NO\n"
] | 1 | stdio |
A necklace can be described as a string of links ('-') and pearls ('o'), with the last link or pearl connected to the first one. $0$
You can remove a link or a pearl and insert it between two other existing links or pearls (or between a link and a pearl) on the necklace. This process can be repeated as many times as ... | [
"-o-o--\n",
"-o---\n",
"-o---o-\n",
"ooo\n",
"---\n",
"--o-o-----o----o--oo-o-----ooo-oo---o--\n",
"-o--o-oo---o-o-o--o-o----oo------oo-----o----o-o-o--oo-o--o---o--o----------o---o-o-oo---o--o-oo-o--\n",
"-ooo--\n",
"---o--\n",
"oo-ooo\n"
] | [
"YES\n",
"YES\n",
"NO\n",
"YES\n",
"YES\n",
"YES\n",
"NO\n",
"YES\n",
"YES\n",
"NO\n"
] | 1 | stdio |
n hobbits are planning to spend the night at Frodo's house. Frodo has n beds standing in a row and m pillows (n ≤ m). Each hobbit needs a bed and at least one pillow to sleep, however, everyone wants as many pillows as possible. Of course, it's not always possible to share pillows equally, but any hobbit gets hurt if h... | [
"4 6 2\n",
"3 10 3\n",
"3 6 1\n",
"3 3 3\n",
"1 1 1\n",
"1 1000000000 1\n",
"100 1000000000 20\n",
"1000 1000 994\n",
"100000000 200000000 54345\n",
"1000000000 1000000000 1\n"
] | [
"2\n",
"4\n",
"3\n",
"1\n",
"1\n",
"1000000000\n",
"10000034\n",
"1\n",
"10001\n",
"1\n"
] | 1 | stdio |
You are given a rectangular grid of lattice points from (0, 0) to (n, m) inclusive. You have to choose exactly 4 different points to build a polyline possibly with self-intersections and self-touching. This polyline should be as long as possible.
A polyline defined by points p_1, p_2, p_3, p_4 consists of the line seg... | [
"1 1\n",
"0 10\n",
"10 10\n",
"100 100\n",
"10 100\n",
"20 1000\n",
"1000 20\n",
"100 10\n",
"2 2\n",
"3 3\n"
] | [
"1 1\n0 0\n1 0\n0 1\n",
"0 1\n0 10\n0 0\n0 9\n",
"10 9\n0 0\n10 10\n1 0\n",
"0 1\n100 100\n0 0\n99 100\n",
"9 100\n0 0\n10 100\n1 0\n",
"1 0\n20 1000\n0 0\n19 1000\n",
"0 1\n1000 20\n0 0\n1000 19\n",
"100 9\n0 0\n100 10\n0 1\n",
"2 2\n0 0\n2 0\n0 2\n",
"3 3\n0 0\n3 0\n0 3\n"
] | 1 | stdio |
Mr. Santa asks all the great programmers of the world to solve a trivial problem. He gives them an integer m and asks for the number of positive integers n, such that the factorial of n ends with exactly m zeroes. Are you among those great programmers who can solve this problem?
-----Input-----
The only line of inpu... | [
"1\n",
"5\n",
"2\n",
"3\n",
"7\n",
"12\n",
"15\n",
"18\n",
"38\n",
"47\n"
] | [
"5\n5 6 7 8 9 ",
"0",
"5\n10 11 12 13 14 ",
"5\n15 16 17 18 19 ",
"5\n30 31 32 33 34 ",
"5\n50 51 52 53 54 ",
"5\n65 66 67 68 69 ",
"5\n75 76 77 78 79 ",
"5\n155 156 157 158 159 ",
"5\n195 196 197 198 199 "
] | 1 | stdio |
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 rectan... | [
"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",
"5\n0 0 10000 20000\n10000 0 15000 19999\n10000 19999 14999 20000\n0 20000 15000 31400\n15000 0 31400 31400\n",
"5\n0 0 10000 20000\n10000 0 15000 19999\n10000 19999 15000 20000\n0 20000 15000 31400\n15000 0 31400 3... | [
"YES\n",
"NO\n",
"NO\n",
"YES\n",
"YES\n",
"NO\n",
"NO\n",
"YES\n",
"YES\n",
"YES\n"
] | 1 | stdio |
Ivan likes to learn different things about numbers, but he is especially interested in really big numbers. Ivan thinks that a positive integer number x is really big if the difference between x and the sum of its digits (in decimal representation) is not less than s. To prove that these numbers may have different speci... | [
"12 1\n",
"25 20\n",
"10 9\n",
"300 1000\n",
"500 1000\n",
"1000 2000\n",
"10000 1000\n",
"1000000000000000000 1000000000000000000\n",
"1000000000000000000 100000000000000000\n",
"1000000000000000000 10000000000000000\n"
] | [
"3\n",
"0\n",
"1\n",
"0\n",
"0\n",
"0\n",
"8991\n",
"0\n",
"899999999999999991\n",
"989999999999999991\n"
] | 1 | stdio |
You are given a string $s$ of length $n$ consisting of lowercase Latin letters. You may apply some operations to this string: in one operation you can delete some contiguous substring of this string, if all letters in the substring you delete are equal. For example, after deleting substring bbbb from string abbbbaccdd ... | [
"5\nabaca\n",
"8\nabcddcba\n",
"1\nx\n",
"500\nbbababaabaabaabbbbbbaabbabbabbaabababababbbbabaaabbbbaaabbbbbbbabababaaaaabbbbabaababbababbaaaaaabbaaabbaabaaababbbbbabbaabaabaabbbaaabaabbaaabbaabababbaaabaaabaaaaabbbababaabbbbabbbbbababbbaabaabbabaabbabbababbbbbaababbaabbbbbbbbaabbabbbabababaaaaaaaaaabababaaab... | [
"3\n",
"4\n",
"1\n",
"121\n",
"174\n",
"196\n",
"217\n",
"228\n",
"246\n",
"261\n"
] | 1 | stdio |
The Berland State University is hosting a ballroom dance in celebration of its 100500-th anniversary! n boys and m girls are already busy rehearsing waltz, minuet, polonaise and quadrille moves.
We know that several boy&girl pairs are going to be invited to the ball. However, the partners' dancing skill in each pair m... | [
"4\n1 4 6 2\n5\n5 1 5 7 9\n",
"4\n1 2 3 4\n4\n10 11 12 13\n",
"5\n1 1 1 1 1\n3\n1 2 3\n",
"1\n1\n1\n1\n",
"2\n1 10\n1\n9\n",
"4\n4 5 4 4\n5\n5 3 4 2 4\n",
"1\n2\n1\n1\n",
"1\n3\n2\n3 2\n",
"1\n4\n3\n4 4 4\n",
"1\n2\n4\n3 1 4 2\n"
] | [
"3\n",
"0\n",
"2\n",
"1\n",
"1\n",
"4\n",
"1\n",
"1\n",
"1\n",
"1\n"
] | 1 | stdio |
One day, after a difficult lecture a diligent student Sasha saw a graffitied desk in the classroom. She came closer and read: "Find such positive integer n, that among numbers n + 1, n + 2, ..., 2·n there are exactly m numbers which binary representation contains exactly k digits one".
The girl got interested in the t... | [
"1 1\n",
"3 2\n",
"3 3\n",
"1 11\n",
"4 20\n",
"45902564 24\n",
"330 8\n",
"10 10\n",
"0 2\n",
"1000000 55\n"
] | [
"1\n",
"5\n",
"7\n",
"1024\n",
"983040\n",
"6406200698\n",
"2033\n",
"1023\n",
"1\n",
"504262282264444927\n"
] | 1 | stdio |
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes.
-----Input-----
The single line of the input co... | [
"2 15\n",
"3 0\n",
"2 1\n",
"3 10\n",
"100 100\n",
"1 900\n",
"1 9\n",
"1 0\n",
"1 1\n",
"1 2\n"
] | [
"69 96\n",
"-1 -1\n",
"10 10\n",
"109 910\n",
"1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000099999999999 9999999999910000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n",
"-1 -1\n",
"9 9\n",
"0 0\n",
"1 1\n",
"2 2\n"... | 1 | stdio |
Vasya has a non-negative integer n. He wants to round it to nearest integer, which ends up with 0. If n already ends up with 0, Vasya considers it already rounded.
For example, if n = 4722 answer is 4720. If n = 5 Vasya can round it to 0 or to 10. Both ways are correct.
For given n find out to which integer will Vasy... | [
"5\n",
"113\n",
"1000000000\n",
"5432359\n",
"999999994\n",
"10\n",
"9\n",
"1\n",
"0\n",
"3\n"
] | [
"0\n",
"110\n",
"1000000000\n",
"5432360\n",
"999999990\n",
"10\n",
"10\n",
"0\n",
"0\n",
"0\n"
] | 1 | stdio |
The preferred way to generate user login in Polygon is to concatenate a prefix of the user's first name and a prefix of their last name, in that order. Each prefix must be non-empty, and any of the prefixes can be the full name. Typically there are multiple possible logins for each person.
You are given the first and ... | [
"harry potter\n",
"tom riddle\n",
"a qdpinbmcrf\n",
"wixjzniiub ssdfodfgap\n",
"z z\n",
"ertuyivhfg v\n",
"asdfghjkli ware\n",
"udggmyop ze\n",
"fapkdme rtzxovx\n",
"mybiqxmnqq l\n"
] | [
"hap\n",
"tomr\n",
"aq\n",
"wis\n",
"zz\n",
"ertuv\n",
"asdfghjkliw\n",
"udggmyopz\n",
"fapkdmer\n",
"ml\n"
] | 1 | stdio |
You took a peek on Thanos wearing Infinity Gauntlet. In the Gauntlet there is a place for six Infinity Gems: the Power Gem of purple color, the Time Gem of green color, the Space Gem of blue color, the Soul Gem of orange color, the Reality Gem of red color, the Mind Gem of yellow color.
Using colors of Gems you... | [
"4\nred\npurple\nyellow\norange\n",
"0\n",
"6\npurple\nblue\nyellow\nred\ngreen\norange\n",
"1\npurple\n",
"3\nblue\norange\npurple\n",
"2\nyellow\nred\n",
"1\ngreen\n",
"2\npurple\ngreen\n",
"1\nblue\n",
"2\npurple\nblue\n"
] | [
"2\nTime\nSpace\n",
"6\nReality\nTime\nMind\nSpace\nPower\nSoul\n",
"0\n",
"5\nMind\nSpace\nReality\nSoul\nTime\n",
"3\nReality\nMind\nTime\n",
"4\nTime\nPower\nSoul\nSpace\n",
"5\nReality\nSpace\nMind\nPower\nSoul\n",
"4\nSpace\nReality\nSoul\nMind\n",
"5\nMind\nSoul\nTime\nPower\nReality\n",
"4\... | 1 | stdio |
PolandBall is a young, clever Ball. He is interested in prime numbers. He has stated a following hypothesis: "There exists such a positive integer n that for each positive integer m number n·m + 1 is a prime number".
Unfortunately, PolandBall is not experienced yet and doesn't know that his hypothesis is incorrect. Co... | [
"3\n",
"4\n",
"10\n",
"153\n",
"1000\n",
"1\n",
"2\n",
"5\n",
"6\n",
"7\n"
] | [
"1",
"2",
"2",
"1",
"1",
"3",
"4",
"1",
"4",
"1"
] | 1 | stdio |
Tonio has a keyboard with only two letters, "V" and "K".
One day, he has typed out a string s with only these two letters. He really likes it when the string "VK" appears, so he wishes to change at most one letter in the string (or do no changes) to maximize the number of occurrences of that string. Compute the maximu... | [
"VK\n",
"VV\n",
"V\n",
"VKKKKKKKKKVVVVVVVVVK\n",
"KVKV\n",
"VKKVVVKVKVK\n",
"VKVVKVKVVKVKKKKVVVVVVVVKVKVVVVVVKKVKKVKVVKVKKVVVVKV\n",
"VVKKVKKVVKKVKKVKVVKKVKKVVKKVKVVKKVKKVKVVKKVVKKVKVVKKVKVVKKVVKVVKKVKKVKKVKKVKKVKVVKKVKKVKKVKKVKKVVKVK\n",
"KVVKKVKVKVKVKVKKVKVKVVKVKVVKVVKVKKVKVKVKVKVKVKVKVKVKVKVKVKVK... | [
"1\n",
"1\n",
"0\n",
"3\n",
"1\n",
"5\n",
"14\n",
"32\n",
"32\n",
"21\n"
] | 1 | stdio |
Spongebob is already tired trying to reason his weird actions and calculations, so he simply asked you to find all pairs of n and m, such that there are exactly x distinct squares in the table consisting of n rows and m columns. For example, in a 3 × 5 table there are 15 squares with side one, 8 squares with side two a... | [
"26\n",
"2\n",
"8\n",
"1\n",
"5005\n",
"17284\n",
"151618\n",
"360700\n",
"500500500\n",
"200200\n"
] | [
"6\n1 26\n2 9\n3 5\n5 3\n9 2\n26 1\n",
"2\n1 2\n2 1\n",
"4\n1 8\n2 3\n3 2\n8 1\n",
"1\n1 1\n",
"12\n1 5005\n5 335\n6 240\n10 94\n13 59\n14 52\n52 14\n59 13\n94 10\n240 6\n335 5\n5005 1\n",
"2\n1 17284\n17284 1\n",
"2\n1 151618\n151618 1\n",
"8\n1 360700\n4 36071\n5 24048\n24 1210\n1210 24\n24048 5\n36... | 1 | stdio |
Vasya has got three integers $n$, $m$ and $k$. He'd like to find three integer points $(x_1, y_1)$, $(x_2, y_2)$, $(x_3, y_3)$, such that $0 \le x_1, x_2, x_3 \le n$, $0 \le y_1, y_2, y_3 \le m$ and the area of the triangle formed by these points is equal to $\frac{nm}{k}$.
Help Vasya! Find such points (if it's possib... | [
"4 3 3\n",
"4 4 7\n",
"3 4 2\n",
"3 4 3\n",
"3 4 12\n",
"16904235 79092881 127345237\n",
"1000000000 999999937 1024\n",
"229999981 1000000000 2048\n",
"1 1 2\n",
"1000000000 1000000000 2\n"
] | [
"YES\n0 0\n0 2\n4 0\n",
"NO\n",
"YES\n0 0\n0 4\n3 0\n",
"YES\n0 0\n0 4\n2 0\n",
"YES\n0 0\n0 2\n1 0\n",
"YES\n0 0\n0 699937\n30 0\n",
"YES\n0 0\n0 999999937\n1953125 0\n",
"NO\n",
"YES\n0 0\n0 1\n1 0\n",
"YES\n0 0\n0 1000000000\n1000000000 0\n"
] | 1 | stdio |
It's one more school day now. Sasha doesn't like classes and is always bored at them. So, each day he invents some game and plays in it alone or with friends.
Today he invented one simple game to play with Lena, with whom he shares a desk. The rules are simple. Sasha draws n sticks in a row. After that the players tak... | [
"1 1\n",
"10 4\n",
"251656215122324104 164397544865601257\n",
"963577813436662285 206326039287271924\n",
"1000000000000000000 1\n",
"253308697183523656 25332878317796706\n",
"669038685745448997 501718093668307460\n",
"116453141993601660 87060381463547965\n",
"766959657 370931668\n",
"2557874224228... | [
"YES\n",
"NO\n",
"YES\n",
"NO\n",
"NO\n",
"YES\n",
"YES\n",
"YES\n",
"NO\n",
"YES\n"
] | 1 | stdio |
Given 2 integers $u$ and $v$, find the shortest array such that bitwise-xor of its elements is $u$, and the sum of its elements is $v$.
-----Input-----
The only line contains 2 integers $u$ and $v$ $(0 \le u,v \le 10^{18})$.
-----Output-----
If there's no array that satisfies the condition, print "-1". Otherwise:... | [
"2 4\n",
"1 3\n",
"8 5\n",
"0 0\n",
"1 1\n",
"5 8\n",
"0 10\n",
"0 1\n",
"10 2\n",
"38795264078389352 381146357267900812\n"
] | [
"2\n3 1",
"3\n1 1 1",
"-1",
"0",
"1\n1",
"-1",
"2\n5 5",
"-1",
"-1",
"2\n209970810673145082 171175546594755730"
] | 1 | stdio |
Prof. Vasechkin wants to represent positive integer n as a sum of addends, where each addends is an integer number containing only 1s. For example, he can represent 121 as 121=111+11+–1. Help him to find the least number of digits 1 in such sum.
-----Input-----
The first line of the input contains integer n (1 ≤ n <... | [
"121\n",
"10\n",
"72\n",
"1\n",
"2\n",
"3\n",
"4\n",
"5\n",
"6\n",
"7\n"
] | [
"6\n",
"3\n",
"15\n",
"1\n",
"2\n",
"3\n",
"4\n",
"5\n",
"6\n",
"6\n"
] | 1 | stdio |
Given an integer $x$. Your task is to find out how many positive integers $n$ ($1 \leq n \leq x$) satisfy $$n \cdot a^n \equiv b \quad (\textrm{mod}\;p),$$ where $a, b, p$ are all known constants.
-----Input-----
The only line contains four integers $a,b,p,x$ ($2 \leq p \leq 10^6+3$, $1 \leq a,b < p$, $1 \leq x \leq... | [
"2 3 5 8\n",
"4 6 7 13\n",
"233 233 10007 1\n",
"338792 190248 339821 152634074578\n",
"629260 663548 739463 321804928248\n",
"656229 20757 818339 523535590429\n",
"1000002 1000002 1000003 1000000000000\n",
"345 2746 1000003 5000000\n",
"802942 824238 836833 605503824329\n",
"1 1 2 880336470888\n"... | [
"2\n",
"1\n",
"1\n",
"449263\n",
"434818\n",
"639482\n",
"999998\n",
"4\n",
"723664\n",
"440168235444\n"
] | 1 | stdio |
Recently Anton found a box with digits in his room. There are k_2 digits 2, k_3 digits 3, k_5 digits 5 and k_6 digits 6.
Anton's favorite integers are 32 and 256. He decided to compose this integers from digits he has. He wants to make the sum of these integers as large as possible. Help him solve this task!
Each dig... | [
"5 1 3 4\n",
"1 1 1 1\n",
"10 2 1 5\n",
"4 2 7 2\n",
"489 292 127 263\n",
"9557 5242 1190 7734\n",
"1480320 1969946 1158387 3940412\n",
"0 0 0 0\n",
"5000000 5000000 5000000 5000000\n",
"1048576 256 1048576 1048576\n"
] | [
"800\n",
"256\n",
"320\n",
"576\n",
"41856\n",
"472384\n",
"306848928\n",
"0\n",
"1280000000\n",
"268435456\n"
] | 1 | stdio |
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 to right f... | [
"6 4 3 1\n",
"9 3 8 10\n",
"9 4 3 10\n",
"9 8 2 10\n",
"1 1 1 1\n",
"10 7 2 7\n",
"8 2 6 10\n",
"8 1 2 10\n",
"6 1 4 10\n",
"1000000 951981 612086 60277\n"
] | [
"0\n",
"2\n",
"2\n",
"2\n",
"0\n",
"2\n",
"2\n",
"3\n",
"3\n",
"174\n"
] | 1 | stdio |
While playing with geometric figures Alex has accidentally invented a concept of a $n$-th order rhombus in a cell grid.
A $1$-st order rhombus is just a square $1 \times 1$ (i.e just a cell).
A $n$-th order rhombus for all $n \geq 2$ one obtains from a $n-1$-th order rhombus adding all cells which have a common side ... | [
"1\n",
"2\n",
"3\n",
"11\n",
"21\n",
"31\n",
"41\n",
"51\n",
"100\n",
"34\n"
] | [
"1",
"5",
"13",
"221",
"841",
"1861",
"3281",
"5101",
"19801",
"2245"
] | 1 | stdio |
A word or a sentence in some language is called a pangram if all the characters of the alphabet of this language appear in it at least once. Pangrams are often used to demonstrate fonts in printing or test the output devices.
You are given a string consisting of lowercase and uppercase Latin letters. Check whether thi... | [
"12\ntoosmallword\n",
"35\nTheQuickBrownFoxJumpsOverTheLazyDog\n",
"1\na\n",
"26\nqwertyuiopasdfghjklzxcvbnm\n",
"26\nABCDEFGHIJKLMNOPQRSTUVWXYZ\n",
"48\nthereisasyetinsufficientdataforameaningfulanswer\n",
"30\nToBeOrNotToBeThatIsTheQuestion\n",
"30\njackdawslovemybigsphinxofquarz\n",
"31\nTHEFIVEB... | [
"NO\n",
"YES\n",
"NO\n",
"YES\n",
"YES\n",
"NO\n",
"NO\n",
"NO\n",
"YES\n",
"NO\n"
] | 1 | stdio |
You are given the current time in 24-hour format hh:mm. Find and print the time after a minutes.
Note that you should find only the time after a minutes, see the examples to clarify the problem statement.
You can read more about 24-hour format here https://en.wikipedia.org/wiki/24-hour_clock.
-----Input-----
The f... | [
"23:59\n10\n",
"20:20\n121\n",
"10:10\n0\n",
"12:34\n10000\n",
"00:00\n10000\n",
"00:00\n1440\n",
"23:59\n8640\n",
"10:01\n0\n",
"04:05\n0\n",
"02:59\n1\n"
] | [
"00:09\n",
"22:21\n",
"10:10\n",
"11:14\n",
"22:40\n",
"00:00\n",
"23:59\n",
"10:01\n",
"04:05\n",
"03:00\n"
] | 1 | stdio |
You have n distinct points on a plane, none of them lie on OY axis. Check that there is a point after removal of which the remaining points are located on one side of the OY axis.
-----Input-----
The first line contains a single positive integer n (2 ≤ n ≤ 10^5).
The following n lines contain coordinates of the poi... | [
"3\n1 1\n-1 -1\n2 -1\n",
"4\n1 1\n2 2\n-1 1\n-2 2\n",
"3\n1 2\n2 1\n4 60\n",
"10\n1 1\n2 2\n3 3\n4 4\n5 5\n6 6\n7 7\n8 8\n9 9\n-1 -1\n",
"2\n1000000000 -1000000000\n1000000000 1000000000\n",
"23\n-1 1\n-1 2\n-2 4\n-7 -8\n-3 3\n-9 -14\n-5 3\n-6 2\n-7 11\n-4 4\n-8 5\n1 1\n-1 -1\n-1 -2\n-2 -4\n-7 8\n-3 -3\n-... | [
"Yes",
"No",
"Yes",
"Yes",
"Yes",
"Yes",
"No",
"Yes",
"No",
"Yes"
] | 1 | stdio |
Holidays have finished. Thanks to the help of the hacker Leha, Noora managed to enter the university of her dreams which is located in a town Pavlopolis. It's well known that universities provide students with dormitory for the period of university studies. Consequently Noora had to leave Vičkopolis and move to Pavlopo... | [
"4 3\n",
"10 399603090\n",
"6 973151934\n",
"2 841668075\n",
"7 415216919\n",
"3 283733059\n",
"11 562314608\n",
"3 990639260\n",
"11 859155400\n",
"1 1\n"
] | [
"6\n",
"3628800\n",
"720\n",
"2\n",
"5040\n",
"6\n",
"39916800\n",
"6\n",
"39916800\n",
"1\n"
] | 1 | stdio |
Let's call a positive integer composite if it has at least one divisor other than $1$ and itself. For example:
the following numbers are composite: $1024$, $4$, $6$, $9$; the following numbers are not composite: $13$, $1$, $2$, $3$, $37$.
You are given a positive integer $n$. Find two composite integers $a,b$ suc... | [
"1\n",
"512\n",
"10000000\n",
"2\n",
"3\n",
"4\n",
"8958020\n",
"6\n",
"7\n",
"8\n"
] | [
"9 8\n",
"4608 4096\n",
"90000000 80000000\n",
"18 16\n",
"27 24\n",
"36 32\n",
"80622180 71664160\n",
"54 48\n",
"63 56\n",
"72 64\n"
] | 1 | stdio |
Since Grisha behaved well last year, at New Year's Eve he was visited by Ded Moroz who brought an enormous bag of gifts with him! The bag contains n sweet candies from the good ol' bakery, each labeled from 1 to n corresponding to its tastiness. No two candies have the same tastiness.
The choice of candies has a direc... | [
"4 3\n",
"6 6\n",
"2 2\n",
"1022 10\n",
"415853337373441 52\n",
"75 12\n",
"1000000000000000000 1000000000000000000\n",
"1 1\n",
"1000000000000000000 2\n",
"49194939 22\n"
] | [
"7\n",
"7\n",
"3\n",
"1023\n",
"562949953421311\n",
"127\n",
"1152921504606846975\n",
"1\n",
"1152921504606846975\n",
"67108863\n"
] | 1 | stdio |
There are $n$ points on the plane, $(x_1,y_1), (x_2,y_2), \ldots, (x_n,y_n)$.
You need to place an isosceles triangle with two sides on the coordinate axis to cover all points (a point is covered if it lies inside the triangle or on the side of the triangle). Calculate the minimum length of the shorter side of the tri... | [
"3\n1 1\n1 2\n2 1\n",
"4\n1 1\n1 2\n2 1\n2 2\n",
"1\n233 666\n",
"5\n7 7\n5 8\n8 5\n4 9\n9 4\n",
"10\n100 34\n27 17\n17 73\n12 60\n53 25\n46 31\n61 86\n22 91\n82 91\n8 41\n",
"2\n5 5\n7 2\n",
"2\n5 5\n2 7\n",
"2\n5 1\n3 4\n",
"2\n2 3\n5 1\n",
"2\n6 1\n4 4\n"
] | [
"3",
"4",
"899",
"14",
"173",
"10",
"10",
"7",
"6",
"8"
] | 1 | stdio |
Alice likes word "nineteen" very much. She has a string s and wants the string to contain as many such words as possible. For that reason she can rearrange the letters of the string.
For example, if she has string "xiineteenppnnnewtnee", she can get string "xnineteenppnineteenw", containing (the occurrences marked) tw... | [
"nniinneetteeeenn\n",
"nneteenabcnneteenabcnneteenabcnneteenabcnneteenabcii\n",
"nineteenineteen\n",
"nssemsnnsitjtihtthij\n",
"eehihnttehtherjsihihnrhimihrjinjiehmtjimnrss\n",
"rrrteiehtesisntnjirtitijnjjjthrsmhtneirjimniemmnrhirssjnhetmnmjejjnjjritjttnnrhnjs\n",
"mmrehtretseihsrjmtsenemniehssnisijmsnn... | [
"2",
"2",
"2",
"0",
"1",
"2",
"2",
"1",
"2",
"0"
] | 1 | stdio |
While Mahmoud and Ehab were practicing for IOI, they found a problem which name was Longest common subsequence. They solved it, and then Ehab challenged Mahmoud with another problem.
Given two strings a and b, find the length of their longest uncommon subsequence, which is the longest string that is a subsequence of o... | [
"abcd\ndefgh\n",
"a\na\n",
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaacccccccccccccccccccccccccccccccccccccccccccccccccc\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaadddddddddddddddddddddddddddddddddddddddddddddddddd\n",
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa... | [
"5\n",
"-1\n",
"100\n",
"199\n",
"99\n",
"5\n",
"5\n",
"5\n",
"5\n",
"8\n"
] | 1 | stdio |
A monster is chasing after Rick and Morty on another planet. They're so frightened that sometimes they scream. More accurately, Rick screams at times b, b + a, b + 2a, b + 3a, ... and Morty screams at times d, d + c, d + 2c, d + 3c, .... [Image]
The Monster will catch them if at any point they scream at the same tim... | [
"20 2\n9 19\n",
"2 1\n16 12\n",
"39 52\n88 78\n",
"59 96\n34 48\n",
"87 37\n91 29\n",
"11 81\n49 7\n",
"39 21\n95 89\n",
"59 70\n48 54\n",
"87 22\n98 32\n",
"15 63\n51 13\n"
] | [
"82\n",
"-1\n",
"1222\n",
"1748\n",
"211\n",
"301\n",
"3414\n",
"1014\n",
"718\n",
"-1\n"
] | 1 | stdio |
Little C loves number «3» very much. He loves all things about it.
Now he has a positive integer $n$. He wants to split $n$ into $3$ positive integers $a,b,c$, such that $a+b+c=n$ and none of the $3$ integers is a multiple of $3$. Help him to find a solution.
-----Input-----
A single line containing one integer $n$... | [
"3\n",
"233\n",
"4\n",
"5\n",
"1234\n",
"387420489\n",
"1000000000\n",
"6\n",
"7\n",
"8\n"
] | [
"1 1 1",
"1 2 230",
"1 1 2",
"1 2 2",
"1 1 1232",
"1 1 387420487",
"1 1 999999998",
"1 1 4",
"1 1 5",
"1 2 5"
] | 1 | stdio |
JATC's math teacher always gives the class some interesting math problems so that they don't get bored. Today the problem is as follows. Given an integer $n$, you can perform the following operations zero or more times: mul $x$: multiplies $n$ by $x$ (where $x$ is an arbitrary positive integer). sqrt: replaces $n$ wi... | [
"20\n",
"5184\n",
"1000000\n",
"999979\n",
"559872\n",
"256\n",
"279936\n",
"1\n",
"786432\n",
"531441\n"
] | [
"10 2",
"6 4",
"10 4",
"999979 0",
"6 4",
"2 3",
"6 4",
"1 0\n",
"6 6",
"3 5"
] | 1 | stdio |
Vitya has just started learning Berlanese language. It is known that Berlanese uses the Latin alphabet. Vowel letters are "a", "o", "u", "i", and "e". Other letters are consonant.
In Berlanese, there has to be a vowel after every consonant, but there can be any letter after any vowel. The only exception is a consonant... | [
"sumimasen\n",
"ninja\n",
"codeforces\n",
"auuaoonntanonnuewannnnpuuinniwoonennyolonnnvienonpoujinndinunnenannmuveoiuuhikucuziuhunnnmunzancenen\n",
"n\n",
"necnei\n",
"nternn\n",
"aucunuohja\n",
"a\n",
"b\n"
] | [
"YES\n",
"YES\n",
"NO\n",
"YES\n",
"YES\n",
"NO\n",
"NO\n",
"NO\n",
"YES\n",
"NO\n"
] | 1 | stdio |
We all know that a superhero can transform to certain other superheroes. But not all Superheroes can transform to any other superhero. A superhero with name $s$ can transform to another superhero with name $t$ if $s$ can be made equal to $t$ by changing any vowel in $s$ to any other vowel and any consonant in $s$ to an... | [
"a\nu\n",
"abc\nukm\n",
"akm\nua\n",
"u\nd\n",
"aaaaaeeeeeiiiiiooooouuuuu\naeiouaeiouaeiouaeiouaeiou\n",
"aaaaaeeeeeiiiiiooooouuuuu\nqwrtysdfghjklzxcvbnmplmjk\n",
"zenudggmyopddhszhrbmftgzmjorabhgojdtfnzxjkayjlkgczsyshczutkdchiytqlfsevymipufxkxojlvkkqxvjhpjmcxeiluua\nblcdiwjphlpzwvknsyvbcodpyktizgatrlie... | [
"Yes\n",
"Yes\n",
"No\n",
"No\n",
"Yes\n",
"No\n",
"No\n",
"No\n",
"No\n",
"Yes\n"
] | 1 | stdio |
One day Alex was creating a contest about his friends, but accidentally deleted it. Fortunately, all the problems were saved, but now he needs to find them among other problems.
But there are too many problems, to do it manually. Alex asks you to write a program, which will determine if a problem is from this contest ... | [
"Alex_and_broken_contest\n",
"NikitaAndString\n",
"Danil_and_Olya\n",
"Slava____and_the_game\n",
"Olya_and_energy_drinks\n",
"Danil_and_part_time_job\n",
"Ann_and_books\n",
"Olya\n",
"Nikita\n",
"Slava\n"
] | [
"NO",
"YES",
"NO",
"YES",
"YES",
"YES",
"YES",
"YES",
"YES",
"YES"
] | 1 | stdio |
You've decided to carry out a survey in the theory of prime numbers. Let us remind you that a prime number is a positive integer that has exactly two distinct positive integer divisors.
Consider positive integers a, a + 1, ..., b (a ≤ b). You want to find the minimum integer l (1 ≤ l ≤ b - a + 1) such that for any int... | [
"2 4 2\n",
"6 13 1\n",
"1 4 3\n",
"5 8 2\n",
"8 10 3\n",
"1 5 2\n",
"6 8 3\n",
"21 29 2\n",
"17 27 3\n",
"1 1000000 10000\n"
] | [
"3\n",
"4\n",
"-1\n",
"4\n",
"-1\n",
"3\n",
"-1\n",
"9\n",
"11\n",
"137970\n"
] | 1 | stdio |
You are given a regular polygon with $n$ vertices labeled from $1$ to $n$ in counter-clockwise order. The triangulation of a given polygon is a set of triangles such that each vertex of each triangle is a vertex of the initial polygon, there is no pair of triangles such that their intersection has non-zero area, and th... | [
"3\n",
"4\n",
"5\n",
"6\n",
"7\n",
"8\n",
"9\n",
"10\n",
"100\n",
"101\n"
] | [
"6\n",
"18\n",
"38\n",
"68\n",
"110\n",
"166\n",
"238\n",
"328\n",
"333298\n",
"343398\n"
] | 1 | stdio |
Vanya got an important task — he should enumerate books in the library and label each book with its number. Each of the n books should be assigned with a number from 1 to n. Naturally, distinct books should be assigned distinct numbers.
Vanya wants to know how many digits he will have to write down as he labels the bo... | [
"13\n",
"4\n",
"100\n",
"99\n",
"1000000000\n",
"1000000\n",
"999\n",
"55\n",
"222222222\n",
"8\n"
] | [
"17\n",
"4\n",
"192\n",
"189\n",
"8888888899\n",
"5888896\n",
"2889\n",
"101\n",
"1888888896\n",
"8\n"
] | 1 | stdio |
You have unlimited number of coins with values $1, 2, \ldots, n$. You want to select some set of coins having the total value of $S$.
It is allowed to have multiple coins with the same value in the set. What is the minimum number of coins required to get sum $S$?
-----Input-----
The only line of the input contains... | [
"5 11\n",
"6 16\n",
"14 28\n",
"5 29\n",
"10 24\n",
"1 30\n",
"14969 66991573\n",
"1 1000000000\n",
"100000 1\n",
"10 46\n"
] | [
"3",
"3",
"2",
"6",
"3",
"30",
"4476",
"1000000000",
"1",
"5"
] | 1 | stdio |
A string is called palindrome if it reads the same from left to right and from right to left. For example "kazak", "oo", "r" and "mikhailrubinchikkihcniburliahkim" are palindroms, but strings "abb" and "ij" are not.
You are given string s consisting of lowercase Latin letters. At once you can choose any position in th... | [
"aabc\n",
"aabcd\n",
"u\n",
"ttttt\n",
"xxxvvvxxvv\n",
"wrwrwfrrfrffrrwwwffffwrfrrwfrrfrwwfwfrwfwfwffwrrwfrrrwwwfrrrwfrrfwrwwrwrrrffffwrrrwrwfffwrffrwwwrwww\n",
"aabbcccdd\n",
"baaab\n",
"aaabbbhhlhlugkjgckj\n",
"aabcc\n"
] | [
"abba\n",
"abcba\n",
"u\n",
"ttttt\n",
"vvvxxxxvvv\n",
"fffffffffffffffrrrrrrrrrrrrrrrrrrwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwrrrrrrrrrrrrrrrrrrfffffffffffffff\n",
"abcdcdcba\n",
"ababa\n",
"aabbghjklclkjhgbbaa\n",
"acbca\n"
] | 1 | stdio |
You are given two circles. Find the area of their intersection.
-----Input-----
The first line contains three integers x_1, y_1, r_1 ( - 10^9 ≤ x_1, y_1 ≤ 10^9, 1 ≤ r_1 ≤ 10^9) — the position of the center and the radius of the first circle.
The second line contains three integers x_2, y_2, r_2 ( - 10^9 ≤ x_2, y_2 ... | [
"0 0 4\n6 0 4\n",
"0 0 5\n11 0 5\n",
"0 0 10\n9 0 1\n",
"0 0 2\n2 2 2\n",
"0 0 10\n5 0 5\n",
"-9 8 7\n-9 8 5\n",
"-60 -85 95\n-69 -94 95\n",
"159 111 998\n161 121 1023\n",
"6008 8591 6693\n5310 8351 7192\n",
"-13563 -6901 22958\n-19316 -16534 18514\n"
] | [
"7.25298806364175601379\n",
"0.00000000000000000000\n",
"3.14159265358979311600\n",
"2.28318530717958647659\n",
"78.53981633974482789995\n",
"78.53981633974482789995\n",
"25936.37843115316246844770\n",
"3129038.84934604830277748988\n",
"138921450.46886559338599909097\n",
"868466038.832951162708923... | 1 | stdio |
Chouti was doing a competitive programming competition. However, after having all the problems accepted, he got bored and decided to invent some small games.
He came up with the following game. The player has a positive integer $n$. Initially the value of $n$ equals to $v$ and the player is able to do the following op... | [
"8\n",
"1\n",
"4\n",
"3\n",
"158260522\n",
"2\n",
"1000000000\n",
"5\n",
"7\n",
"9\n"
] | [
"1\n",
"1\n",
"1\n",
"1\n",
"1\n",
"2\n",
"1\n",
"1\n",
"1\n",
"1\n"
] | 1 | stdio |
Analyzing the mistakes people make while typing search queries is a complex and an interesting work. As there is no guaranteed way to determine what the user originally meant by typing some query, we have to use different sorts of heuristics.
Polycarp needed to write a code that could, given two words, check whether t... | [
"7\nreading\ntrading\n",
"5\nsweet\nsheep\n",
"3\ntoy\ntry\n",
"5\nspare\nspars\n",
"1\na\nb\n",
"1\nz\ny\n",
"2\nab\nac\n",
"2\nba\nca\n",
"2\nac\ncb\n",
"100\neebdeddddbecdbddaaecbbaccbecdeacedddcaddcdebedbabbceeeadecadbbeaecdaeabbceacbdbdbbdacebbbccdcbbeedbe\ndacdeebebeaeaacdeedadbcbaedcbdddddd... | [
"1\n",
"0\n",
"2\n",
"2\n",
"2\n",
"2\n",
"2\n",
"2\n",
"1\n",
"0\n"
] | 1 | stdio |
There are three points marked on the coordinate plane. The goal is to make a simple polyline, without self-intersections and self-touches, such that it passes through all these points. Also, the polyline must consist of only segments parallel to the coordinate axes. You are to find the minimum number of segments this p... | [
"1 -1\n1 1\n1 2\n",
"-1 -1\n-1 3\n4 3\n",
"1 1\n2 3\n3 2\n",
"1000000000 -1000000000\n1000000000 1000000000\n-1000000000 -1000000000\n",
"-510073119 -991063686\n583272581 -991063686\n623462417 -991063686\n",
"-422276230 -422225325\n-422276230 -544602611\n-282078856 -544602611\n",
"127447697 -311048187\n... | [
"1\n",
"2\n",
"3\n",
"2\n",
"1\n",
"2\n",
"2\n",
"3\n",
"3\n",
"3\n"
] | 1 | stdio |
An undirected graph is called k-regular, if the degrees of all its vertices are equal k. An edge of a connected graph is called a bridge, if after removing it the graph is being split into two connected components.
Build a connected undirected k-regular graph containing at least one bridge, or else state that such gra... | [
"1\n",
"3\n",
"10\n",
"2\n",
"4\n",
"5\n",
"6\n",
"7\n",
"8\n",
"12\n"
] | [
"YES\n2 1\n1 2\n",
"YES\n10 15\n1 6\n1 2\n1 3\n2 4\n2 5\n3 4\n3 5\n4 5\n6 7\n6 8\n7 9\n7 10\n8 9\n8 10\n9 10\n",
"NO\n",
"NO\n",
"NO\n",
"YES\n14 35\n1 8\n1 2\n1 3\n1 4\n1 5\n2 6\n2 7\n2 4\n2 5\n3 6\n3 7\n3 4\n3 5\n4 6\n4 7\n5 6\n5 7\n6 7\n8 9\n8 10\n8 11\n8 12\n9 13\n9 14\n9 11\n9 12\n10 13\n10 14\n10 11... | 1 | stdio |
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
each vertex has exactly k children; each edge has some weight; if we look at the edges that goes from some ... | [
"3 3 2\n",
"3 3 3\n",
"4 3 2\n",
"4 5 2\n",
"28 6 3\n",
"5 100 1\n",
"50 6 3\n",
"10 13 6\n",
"20 16 14\n",
"1 10 1\n"
] | [
"3\n",
"1\n",
"6\n",
"7\n",
"110682188\n",
"16\n",
"295630102\n",
"48\n",
"236\n",
"1\n"
] | 1 | stdio |
You are given $a$ uppercase Latin letters 'A' and $b$ letters 'B'.
The period of the string is the smallest such positive integer $k$ that $s_i = s_{i~mod~k}$ ($0$-indexed) for each $i$. Note that this implies that $k$ won't always divide $a+b = |s|$.
For example, the period of string "ABAABAA" is $3$, the period of ... | [
"2 4\n",
"5 3\n",
"1 1\n",
"1 2\n",
"2 1\n",
"1000000000 1\n",
"1 1000000000\n",
"1000000000 1000000000\n",
"49464524 956817411\n",
"917980664 839933539\n"
] | [
"4\n",
"5\n",
"1\n",
"2\n",
"2\n",
"500000001\n",
"500000001\n",
"1999936805\n",
"1006177186\n",
"1757835091\n"
] | 1 | stdio |
Two little greedy bears have found two pieces of cheese in the forest of weight a and b grams, correspondingly. The bears are so greedy that they are ready to fight for the larger piece. That's where the fox comes in and starts the dialog: "Little bears, wait a little, I want to make your pieces equal" "Come off it fox... | [
"15 20\n",
"14 8\n",
"6 6\n",
"1 1\n",
"1 1024\n",
"1024 729\n",
"1024 1048576\n",
"36 30\n",
"100 10\n",
"21 35\n"
] | [
"3\n",
"-1\n",
"0\n",
"0\n",
"10\n",
"16\n",
"10\n",
"3\n",
"2\n",
"2\n"
] | 1 | stdio |
You are given a cube of size k × k × k, which consists of unit cubes. Two unit cubes are considered neighbouring, if they have common face.
Your task is to paint each of k^3 unit cubes one of two colours (black or white), so that the following conditions must be satisfied: each white cube has exactly 2 neighbouring c... | [
"1\n",
"2\n",
"3\n",
"4\n",
"5\n",
"6\n",
"7\n",
"9\n",
"11\n",
"13\n"
] | [
"-1\n",
"bb\nww\n\nbb\nww\n",
"-1\n",
"bbbb\nbwwb\nbwwb\nbbbb\n\nwwww\nwbbw\nwbbw\nwwww\n\nbbbb\nbwwb\nbwwb\nbbbb\n\nwwww\nwbbw\nwbbw\nwwww\n",
"-1\n",
"bbbbbb\nbwwwwb\nbwbbwb\nbwbbwb\nbwwwwb\nbbbbbb\n\nwwwwww\nwbbbbw\nwbwwbw\nwbwwbw\nwbbbbw\nwwwwww\n\nbbbbbb\nbwwwwb\nbwbbwb\nbwbbwb\nbwwwwb\nbbbbbb\n\nwww... | 1 | stdio |
Duff is in love with lovely numbers! A positive integer x is called lovely if and only if there is no such positive integer a > 1 such that a^2 is a divisor of x. [Image]
Malek has a number store! In his store, he has only divisors of positive integer n (and he has all of them). As a birthday present, Malek wants to ... | [
"10\n",
"12\n",
"1\n",
"2\n",
"4\n",
"8\n",
"3\n",
"31\n",
"97\n",
"1000000000000\n"
] | [
"10\n",
"6\n",
"1\n",
"2\n",
"2\n",
"2\n",
"3\n",
"31\n",
"97\n",
"10\n"
] | 1 | stdio |
A positive integer is called a 2-3-integer, if it is equal to 2^{x}·3^{y} for some non-negative integers x and y. In other words, these integers are such integers that only have 2 and 3 among their prime divisors. For example, integers 1, 6, 9, 16 and 108 — are 2-3 integers, while 5, 10, 21 and 120 are not.
Print the ... | [
"1 10\n",
"100 200\n",
"1 2000000000\n",
"1088391168 1934917632\n",
"1088391167 1934917632\n",
"1088391169 1934917632\n",
"1088391168 1934917631\n",
"1088391168 1934917633\n",
"4 134217728\n",
"209952 43046722\n"
] | [
"7\n",
"5\n",
"326\n",
"17\n",
"17\n",
"16\n",
"16\n",
"17\n",
"250\n",
"112\n"
] | 1 | stdio |
Imp likes his plush toy a lot.
[Image]
Recently, he found a machine that can clone plush toys. Imp knows that if he applies the machine to an original toy, he additionally gets one more original toy and one copy, and if he applies the machine to a copied toy, he gets two additional copies.
Initially, Imp has only ... | [
"6 3\n",
"4 2\n",
"1000 1001\n",
"1000000000 999999999\n",
"81452244 81452247\n",
"188032448 86524683\n",
"365289629 223844571\n",
"247579518 361164458\n",
"424836699 793451637\n",
"602093880 930771525\n"
] | [
"Yes\n",
"No\n",
"Yes\n",
"Yes\n",
"No\n",
"Yes\n",
"No\n",
"No\n",
"No\n",
"No\n"
] | 1 | stdio |
Ivan has number $b$. He is sorting through the numbers $a$ from $1$ to $10^{18}$, and for every $a$ writes $\frac{[a, \,\, b]}{a}$ on blackboard. Here $[a, \,\, b]$ stands for least common multiple of $a$ and $b$. Ivan is very lazy, that's why this task bored him soon. But he is interested in how many different numbers... | [
"1\n",
"2\n",
"16\n",
"433494437\n",
"10000000000\n",
"169\n",
"244078129\n",
"7169516929\n",
"2147483647\n",
"2971215073\n"
] | [
"1",
"2",
"5",
"2",
"121",
"3",
"9",
"3",
"2",
"2"
] | 1 | stdio |
The Rebel fleet is afraid that the Empire might want to strike back again. Princess Heidi needs to know if it is possible to assign R Rebel spaceships to guard B bases so that every base has exactly one guardian and each spaceship has exactly one assigned base (in other words, the assignment is a perfect matching). Sin... | [
"3 3\n0 0\n2 0\n3 1\n-2 1\n0 3\n2 2\n",
"2 1\n1 0\n2 2\n3 1\n",
"1 1\n3686 4362\n-7485 5112\n",
"1 2\n1152 -7324\n-5137 -35\n-6045 -5271\n",
"1 3\n-8824 -9306\n-5646 -9767\n8123 9355\n-6203 -1643\n",
"1 5\n-8775 6730\n-3806 -6906\n-9256 -8240\n-1320 6849\n8155 746\n8284 -7317\n",
"1 8\n8741 3638\n381 -9... | [
"Yes\n",
"No\n",
"Yes\n",
"No\n",
"No\n",
"No\n",
"No\n",
"No\n",
"No\n",
"No\n"
] | 1 | stdio |
Vasya has found a strange device. On the front panel of a device there are: a red button, a blue button and a display showing some positive integer. After clicking the red button, device multiplies the displayed number by two. After clicking the blue button, device subtracts one from the number on the display. If at so... | [
"4 6\n",
"10 1\n",
"1 2\n",
"2 1\n",
"1 3\n",
"3 1\n",
"2 10\n",
"100 99\n",
"99 100\n",
"10 17\n"
] | [
"2\n",
"9\n",
"1\n",
"1\n",
"3\n",
"2\n",
"5\n",
"1\n",
"50\n",
"3\n"
] | 1 | stdio |
We get more and more news about DDoS-attacks of popular websites.
Arseny is an admin and he thinks that a website is under a DDoS-attack if the total number of requests for a some period of time exceeds $100 \cdot t$, where $t$ — the number of seconds in this time segment.
Arseny knows statistics on the number of re... | [
"5\n100 200 1 1 1\n",
"5\n1 2 3 4 5\n",
"2\n101 99\n",
"1\n41\n",
"2\n1 91\n",
"10\n58 10 43 61 64 6 39 199 46 29\n",
"10\n33 202 11 64 5 295 34 25 89 50\n",
"20\n46 291 21 20 60 47 47 43 243 78 75 44 41 54 11 79 47 93 268 3\n",
"30\n67 3 99 36 53 9 17 55 63 7 42 3 42 10 67 97 65 266 65 17 52 76 17 ... | [
"3\n",
"0\n",
"1\n",
"0\n",
"0\n",
"2\n",
"6\n",
"4\n",
"11\n",
"12\n"
] | 1 | stdio |
We have an integer sequence A of length N, where A_1 = X, A_{i+1} = A_i + D (1 \leq i < N ) holds.
Takahashi will take some (possibly all or none) of the elements in this sequence, and Aoki will take all of the others.
Let S and T be the sum of the numbers taken by Takahashi and Aoki, respectively. How many possible v... | [
"3 4 2\n",
"2 3 -3\n",
"100 14 20\n",
"17 3 -4\n",
"7 5 5\n",
"2 -5 -3\n",
"2 -7 5\n",
"3 0 -9\n",
"8 6 0\n",
"8 6 -4\n"
] | [
"8\n",
"2\n",
"49805\n",
"494\n",
"29\n",
"4\n",
"4\n",
"4\n",
"9\n",
"41\n"
] | 1 | stdio |
In the city of Saint Petersburg, a day lasts for $2^{100}$ minutes. From the main station of Saint Petersburg, a train departs after $1$ minute, $4$ minutes, $16$ minutes, and so on; in other words, the train departs at time $4^k$ for each integer $k \geq 0$. Team BowWow has arrived at the station at the time $s$ and i... | [
"100000000\n",
"101\n",
"10100\n",
"1111010010000101100100001110011101111\n",
"11110010110000101001001101010111110101101111001000100100101111011\n",
"0\n",
"10000\n",
"1000010011100010111000001101000011001010011101011001101100000001011011000000101101101011101111011011\n",
"1000\n",
"1\n"
] | [
"4\n",
"2\n",
"3\n",
"19\n",
"33\n",
"0\n",
"2\n",
"50\n",
"2\n",
"0\n"
] | 1 | stdio |
A restaurant received n orders for the rental. Each rental order reserve the restaurant for a continuous period of time, the i-th order is characterized by two time values — the start time l_{i} and the finish time r_{i} (l_{i} ≤ r_{i}).
Restaurant management can accept and reject orders. What is the maximal number of... | [
"2\n7 11\n4 7\n",
"5\n1 2\n2 3\n3 4\n4 5\n5 6\n",
"6\n4 8\n1 5\n4 7\n2 5\n1 3\n6 8\n",
"1\n1 1\n",
"2\n4 6\n4 8\n",
"3\n22 22\n14 21\n9 25\n",
"4\n20 59\n30 62\n29 45\n29 32\n",
"5\n40 124\n40 117\n67 106\n36 121\n38 102\n",
"6\n124 155\n50 93\n45 120\n54 171\n46 190\n76 179\n",
"7\n94 113\n54 248... | [
"1\n",
"3\n",
"2\n",
"1\n",
"1\n",
"2\n",
"1\n",
"1\n",
"2\n",
"2\n"
] | 1 | stdio |
Ania has a large integer $S$. Its decimal representation has length $n$ and doesn't contain any leading zeroes. Ania is allowed to change at most $k$ digits of $S$. She wants to do it in such a way that $S$ still won't contain any leading zeroes and it'll be minimal possible. What integer will Ania finish with?
-----... | [
"5 3\n51528\n",
"3 2\n102\n",
"1 1\n1\n",
"8 3\n76185080\n",
"10 9\n6605076924\n",
"17 14\n70419129275429261\n",
"1 0\n1\n",
"1 1\n0\n",
"2 1\n16\n",
"1 0\n0\n"
] | [
"10028\n",
"100\n",
"0\n",
"10085080\n",
"1000000000\n",
"10000000000000061\n",
"1\n",
"0\n",
"10\n",
"0\n"
] | 1 | stdio |
Vasya lives in a round building, whose entrances are numbered sequentially by integers from 1 to n. Entrance n and entrance 1 are adjacent.
Today Vasya got bored and decided to take a walk in the yard. Vasya lives in entrance a and he decided that during his walk he will move around the house b entrances in the direct... | [
"6 2 -5\n",
"5 1 3\n",
"3 2 7\n",
"1 1 0\n",
"1 1 -1\n",
"1 1 1\n",
"100 1 -1\n",
"100 54 100\n",
"100 37 -100\n",
"99 41 0\n"
] | [
"3\n",
"4\n",
"3\n",
"1\n",
"1\n",
"1\n",
"100\n",
"54\n",
"37\n",
"41\n"
] | 1 | stdio |
High school student Vasya got a string of length n as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequence) consisting of equal letters.
Vasya can change no more than k characters of the original string. W... | [
"4 2\nabba\n",
"8 1\naabaabaa\n",
"1 0\na\n",
"1 1\nb\n",
"1 0\nb\n",
"1 1\na\n",
"10 10\nbbbbbbbbbb\n",
"10 2\nbbbbbbbbbb\n",
"10 1\nbbabbabbba\n",
"10 10\nbbabbbaabb\n"
] | [
"4\n",
"5\n",
"1\n",
"1\n",
"1\n",
"1\n",
"10\n",
"10\n",
"6\n",
"10\n"
] | 1 | stdio |
Santa Claus has n candies, he dreams to give them as gifts to children.
What is the maximal number of children for whose he can give candies if Santa Claus want each kid should get distinct positive integer number of candies. Santa Class wants to give all n candies he has.
-----Input-----
The only line contains pos... | [
"5\n",
"9\n",
"2\n",
"1\n",
"3\n",
"1000\n",
"4\n",
"6\n",
"7\n",
"8\n"
] | [
"2\n1 4 \n",
"3\n1 2 6 \n",
"1\n2 \n",
"1\n1 \n",
"2\n1 2 \n",
"44\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 54 \n",
"2\n1 3 \n",
"3\n1 2 3 \n",
"3\n1 2 4 \n",
"3\n1 2 5 \n"
] | 1 | stdio |
The following problem is well-known: given integers n and m, calculate $2^{n} \operatorname{mod} m$,
where 2^{n} = 2·2·...·2 (n factors), and $x \operatorname{mod} y$ denotes the remainder of division of x by y.
You are asked to solve the "reverse" problem. Given integers n and m, calculate $m \operatorname{mod} 2^{... | [
"4\n42\n",
"1\n58\n",
"98765432\n23456789\n",
"8\n88127381\n",
"32\n92831989\n",
"92831989\n25\n",
"100000000\n100000000\n",
"7\n1234\n",
"1\n1\n",
"1\n100000000\n"
] | [
"10\n",
"0\n",
"23456789\n",
"149\n",
"92831989\n",
"25\n",
"100000000\n",
"82\n",
"1\n",
"0\n"
] | 1 | stdio |
Victor tries to write his own text editor, with word correction included. However, the rules of word correction are really strange.
Victor thinks that if a word contains two consecutive vowels, then it's kinda weird and it needs to be replaced. So the word corrector works in such a way: as long as there are two consec... | [
"5\nweird\n",
"4\nword\n",
"5\naaeaa\n",
"100\naaaaabbbbboyoyoyoyoyacadabbbbbiuiufgiuiuaahjabbbklboyoyoyoyoyaaaaabbbbbiuiuiuiuiuaaaaabbbbbeyiyuyzyw\n",
"69\nbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\n",
"12\nmmmmmmmmmmmm\n",
"18\nyaywptqwuyiqypwoyw\n",
"85\nbbbbbbbbbbbbbbbb... | [
"werd\n",
"word\n",
"a\n",
"abbbbbocadabbbbbifgihjabbbklbobbbbbibbbbbezyw\n",
"bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\n",
"mmmmmmmmmmmm\n",
"ywptqwuqypwow\n",
"bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\n",
"mmmmmmmmmmmmm\n",
... | 1 | stdio |
Melody Pond was stolen from her parents as a newborn baby by Madame Kovarian, to become a weapon of the Silence in their crusade against the Doctor. Madame Kovarian changed Melody's name to River Song, giving her a new identity that allowed her to kill the Eleventh Doctor.
Heidi figured out that Madame Kovarian uses a... | [
"19\n",
"16\n",
"1\n",
"2\n",
"3\n",
"4\n",
"5\n",
"6\n",
"7\n",
"8\n"
] | [
"1 8\n",
"NO\n",
"NO\n",
"NO\n",
"NO\n",
"NO\n",
"1 1\n",
"NO\n",
"1 2\n",
"NO\n"
] | 1 | stdio |
A tuple of positive integers {x_1, x_2, ..., x_{k}} is called simple if for all pairs of positive integers (i, j) (1 ≤ i < j ≤ k), x_{i} + x_{j} is a prime.
You are given an array a with n positive integers a_1, a_2, ..., a_{n} (not necessary distinct). You want to find a simple subset of the array a with the... | [
"2\n2 3\n",
"2\n2 2\n",
"3\n2 1 1\n",
"2\n83 14\n",
"10\n10 10 1 2 3 3 1 2 1 5\n",
"100\n314 905 555 526 981 360 424 104 920 814 143 872 741 592 105 573 837 962 220 692 560 493 889 824 145 491 828 960 889 87 375 486 609 423 386 323 124 830 206 446 899 522 514 696 786 783 268 483 318 261 675 445 1000 896 8... | [
"2\n3 2\n",
"1\n2\n",
"3\n1 1 2\n",
"2\n14 83\n",
"4\n1 1 10 1\n",
"2\n104 905\n",
"4\n1 1 738 1\n",
"100\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 | stdio |
Recently Luba learned about a special kind of numbers that she calls beautiful numbers. The number is called beautiful iff its binary representation consists of k + 1 consecutive ones, and then k consecutive zeroes.
Some examples of beautiful numbers: 1_2 (1_10); 110_2 (6_10); 1111000_2 (120_10); 111110000_2 (496... | [
"3\n",
"992\n",
"81142\n",
"76920\n",
"2016\n",
"1\n",
"6\n",
"32640\n",
"12096\n",
"55948\n"
] | [
"1\n",
"496\n",
"1\n",
"120\n",
"2016\n",
"1\n",
"6\n",
"32640\n",
"2016\n",
"1\n"
] | 1 | stdio |
Allen has a LOT of money. He has $n$ dollars in the bank. For security reasons, he wants to withdraw it in cash (we will not disclose the reasons here). The denominations for dollar bills are $1$, $5$, $10$, $20$, $100$. What is the minimum number of bills Allen could receive after withdrawing his entire balance?
---... | [
"125\n",
"43\n",
"1000000000\n",
"4\n",
"5\n",
"1\n",
"74\n",
"31\n",
"59\n",
"79\n"
] | [
"3\n",
"5\n",
"10000000\n",
"4\n",
"1\n",
"1\n",
"8\n",
"3\n",
"8\n",
"9\n"
] | 1 | stdio |
A continued fraction of height n is a fraction of form $a_{1} + \frac{1}{a_{2} + \frac{1}{\ldots + \frac{1}{a_{n}}}}$. You are given two rational numbers, one is represented as [Image] and the other one is represented as a finite fraction of height n. Check if they are equal.
-----Input-----
The first line contains ... | [
"9 4\n2\n2 4\n",
"9 4\n3\n2 3 1\n",
"9 4\n3\n1 2 4\n",
"39088169 24157817\n36\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 2\n",
"39088169 24157817\n36\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 4\n",
"61305790721611591 37889062373143906\n80\n1 1 1 1 1... | [
"YES\n",
"YES\n",
"NO\n",
"YES\n",
"NO\n",
"NO\n",
"YES\n",
"YES\n",
"NO\n",
"YES\n"
] | 1 | stdio |
Let us define the oddness of a permutation p = {p_1,\ p_2,\ ...,\ p_n} of {1,\ 2,\ ...,\ n} as \sum_{i = 1}^n |i - p_i|.
Find the number of permutations of {1,\ 2,\ ...,\ n} of oddness k, modulo 10^9+7.
-----Constraints-----
- All values in input are integers.
- 1 \leq n \leq 50
- 0 \leq k \leq n^2
-----Input-----... | [
"3 2\n",
"39 14\n",
"44 350\n",
"22 444\n",
"1 0\n",
"34 712\n",
"10 82\n",
"17 222\n",
"40 1062\n",
"38 716\n"
] | [
"2\n",
"74764168\n",
"15060087\n",
"0\n",
"1\n",
"0\n",
"0\n",
"0\n",
"0\n",
"810790165\n"
] | 1 | stdio |
Polycarp has interviewed Oleg and has written the interview down without punctuation marks and spaces to save time. Thus, the interview is now a string s consisting of n lowercase English letters.
There is a filler word ogo in Oleg's speech. All words that can be obtained from ogo by adding go several times to the end... | [
"7\naogogob\n",
"13\nogogmgogogogo\n",
"9\nogoogoogo\n",
"32\nabcdefogoghijklmnogoopqrstuvwxyz\n",
"100\nggogogoooggogooggoggogggggogoogoggooooggooggoooggogoooggoggoogggoogoggogggoooggoggoggogggogoogggoooo\n",
"10\nogooggoggo\n",
"20\nooggooogooogooogooog\n",
"30\ngoggogoooggooggggoggoggoogoggo\n",
... | [
"a***b\n",
"***gmg***\n",
"*********\n",
"abcdef***ghijklmn***opqrstuvwxyz\n",
"gg***oogg***oggoggoggggg******ggooooggooggooogg***ooggoggoogggo***ggogggoooggoggoggoggg***ogggoooo\n",
"***oggoggo\n",
"ooggoo***o***o***oog\n",
"gogg***ooggooggggoggoggo***ggo\n",
"oggg***oggo***oggg***o***gggoogggooggo... | 1 | stdio |
The finalists of the "Russian Code Cup" competition in 2214 will be the participants who win in one of the elimination rounds.
The elimination rounds are divided into main and additional. Each of the main elimination rounds consists of c problems, the winners of the round are the first n people in the rating list. Eac... | [
"1 10\n7 2\n1\n",
"2 2\n2 1\n2\n",
"8 9\n2 2\n3\n",
"5 5\n8 8\n7\n",
"1 8\n8 10\n8\n",
"5 7\n9 1\n8\n",
"35 28\n35 60\n44\n",
"19 76\n91 91\n87\n",
"20 38\n38 70\n58\n",
"2 81\n3 39\n45\n"
] | [
"2\n",
"0\n",
"8\n",
"40\n",
"9\n",
"5\n",
"2065\n",
"1729\n",
"1380\n",
"48\n"
] | 1 | stdio |
Let's consider equation:x^2 + s(x)·x - n = 0,
where x, n are positive integers, s(x) is the function, equal to the sum of digits of number x in the decimal number system.
You are given an integer n, find the smallest positive integer root of equation x, or else determine that there are no such roots.
-----Input--... | [
"2\n",
"110\n",
"4\n",
"8\n",
"10000000100000000\n",
"10000006999999929\n",
"172541340\n",
"172580744\n",
"10000100000\n",
"1000001000000\n"
] | [
"1\n",
"10\n",
"-1\n",
"2\n",
"100000000\n",
"99999999\n",
"13131\n",
"13132\n",
"100000\n",
"1000000\n"
] | 1 | stdio |
George woke up and saw the current time s on the digital clock. Besides, George knows that he has slept for time t.
Help George! Write a program that will, given time s and t, determine the time p when George went to bed. Note that George could have gone to bed yesterday relatively to the current time (see the second... | [
"05:50\n05:44\n",
"00:00\n01:00\n",
"00:01\n00:00\n",
"23:59\n23:59\n",
"23:44\n23:55\n",
"00:00\n13:12\n",
"12:00\n23:59\n",
"12:44\n12:44\n",
"05:55\n07:12\n",
"07:12\n05:55\n"
] | [
"00:06\n",
"23:00\n",
"00:01\n",
"00:00\n",
"23:49\n",
"10:48\n",
"12:01\n",
"00:00\n",
"22:43\n",
"01:17\n"
] | 1 | stdio |
You are given array $a_1, a_2, \dots, a_n$. Find the subsegment $a_l, a_{l+1}, \dots, a_r$ ($1 \le l \le r \le n$) with maximum arithmetic mean $\frac{1}{r - l + 1}\sum\limits_{i=l}^{r}{a_i}$ (in floating-point numbers, i.e. without any rounding).
If there are many such subsegments find the longest one.
-----Input--... | [
"5\n6 1 6 6 0\n",
"1\n1000000000\n",
"6\n1 1 0 1 1 1\n",
"5\n2 2 2 2 3\n",
"6\n3 3 2 2 2 2\n",
"2\n1 2\n",
"69\n2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68... | [
"2\n",
"1\n",
"3\n",
"1\n",
"2\n",
"1\n",
"1\n",
"3\n",
"1\n",
"5\n"
] | 1 | stdio |
A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not.
You're given a number. Determine if it is a magic number or not.
-----Input-----
The first line of inpu... | [
"114114\n",
"1111\n",
"441231\n",
"1\n",
"14\n",
"114\n",
"9\n",
"414\n",
"1000000000\n",
"144144144\n"
] | [
"YES\n",
"YES\n",
"NO\n",
"YES\n",
"YES\n",
"YES\n",
"NO\n",
"NO\n",
"NO\n",
"YES\n"
] | 1 | stdio |
Let's consider a table consisting of n rows and n columns. The cell located at the intersection of i-th row and j-th column contains number i × j. The rows and columns are numbered starting from 1.
You are given a positive integer x. Your task is to count the number of cells in a table that contain number x.
-----In... | [
"10 5\n",
"6 12\n",
"5 13\n",
"1 1\n",
"2 1\n",
"100000 1\n",
"1 1000000000\n",
"100000 1000000000\n",
"100000 362880\n",
"1 4\n"
] | [
"2\n",
"4\n",
"0\n",
"1\n",
"1\n",
"1\n",
"0\n",
"16\n",
"154\n",
"0\n"
] | 1 | stdio |
The Cybermen and the Daleks have long been the Doctor's main enemies. Everyone knows that both these species enjoy destroying everything they encounter. However, a little-known fact about them is that they both also love taking Turing tests!
Heidi designed a series of increasingly difficult tasks for them to spend the... | [
"2\n0 0\n0 1\n0 2\n1 0\n1 1\n1 2\n2 0\n2 1\n2 2\n",
"2\n0 0\n0 1\n0 2\n0 3\n1 0\n1 2\n2 0\n2 1\n2 2\n",
"2\n5 14\n5 17\n25 43\n26 43\n32 41\n33 0\n38 0\n48 17\n48 30\n",
"2\n17 44\n19 14\n19 25\n24 27\n32 1\n34 27\n38 1\n45 5\n45 12\n",
"2\n1 2\n1 27\n1 45\n10 45\n28 48\n38 1\n44 1\n45 7\n45 26\n",
"2\n2 ... | [
"1 1\n",
"0 3\n",
"32 41\n",
"17 44\n",
"28 48\n",
"12 1\n",
"31 47\n",
"4 43\n",
"44 38\n",
"9 8\n"
] | 1 | stdio |
Kurt reaches nirvana when he finds the product of all the digits of some positive integer. Greater value of the product makes the nirvana deeper.
Help Kurt find the maximum possible product of digits among all integers from $1$ to $n$.
-----Input-----
The only input line contains the integer $n$ ($1 \le n \le 2\cdo... | [
"390\n",
"7\n",
"1000000000\n",
"1\n",
"9\n",
"2000000000\n",
"4876\n",
"889878787\n",
"1382011913\n",
"999999999\n"
] | [
"216\n",
"7\n",
"387420489\n",
"1\n",
"9\n",
"387420489\n",
"2268\n",
"301327047\n",
"387420489\n",
"387420489\n"
] | 1 | stdio |
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 of p... | [
"aabb\n",
"aabcaa\n",
"abbcccbba\n",
"aaaaaaaaaaa\n",
"aaaaaaaaabbbbbaaaabaaaaaaaaaaaaaaaaabaaaaaabbbbbbbaaabbbbbbbbbbbbbbbbbbbbbaaaaaaaaaaaaaaaaaaaaaaaaaa\n",
"abc\n",
"a\n",
"ab\n",
"ba\n",
"aaabbb\n"
] | [
"2\n",
"1\n",
"1\n",
"0\n",
"12\n",
"1\n",
"0\n",
"1\n",
"1\n",
"3\n"
] | 1 | stdio |
After returning from the army Makes received a gift — an array a consisting of n positive integer numbers. He hadn't been solving problems for a long time, so he became interested to answer a particular question: how many triples of indices (i, j, k) (i < j < k), such that a_{i}·a_{j}·a_{k} is minimum possible, are t... | [
"4\n1 1 1 1\n",
"5\n1 3 2 3 4\n",
"6\n1 3 3 1 3 2\n",
"3\n1000000000 1000000000 1000000000\n",
"4\n1 1 2 2\n",
"3\n1 3 1\n",
"11\n1 2 2 2 2 2 2 2 2 2 2\n",
"5\n1 2 2 2 2\n",
"6\n1 2 2 3 3 4\n",
"8\n1 1 2 2 2 3 3 3\n"
] | [
"4\n",
"2\n",
"1\n",
"1\n",
"2\n",
"1\n",
"45\n",
"6\n",
"1\n",
"3\n"
] | 1 | stdio |
Katie, Kuro and Shiro are best friends. They have known each other since kindergarten. That's why they often share everything with each other and work together on some very hard problems.
Today is Shiro's birthday. She really loves pizza so she wants to invite her friends to the pizza restaurant near her house to cele... | [
"3\n",
"4\n",
"10\n",
"10000000000\n",
"1234567891\n",
"7509213957\n",
"99999999999999999\n",
"21\n",
"712394453192\n",
"172212168\n"
] | [
"2",
"5",
"11",
"10000000001",
"617283946",
"3754606979",
"50000000000000000",
"11",
"712394453193",
"172212169"
] | 1 | stdio |
Ilya is a very clever lion, he lives in an unusual city ZooVille. In this city all the animals have their rights and obligations. Moreover, they even have their own bank accounts. The state of a bank account is an integer. The state of a bank account can be a negative number. This means that the owner of the account ow... | [
"2230\n",
"-10\n",
"-100003\n",
"544883178\n",
"-847251738\n",
"423654797\n",
"-623563697\n",
"645894116\n",
"-384381709\n",
"437587210\n"
] | [
"2230\n",
"0\n",
"-10000\n",
"544883178\n",
"-84725173\n",
"423654797\n",
"-62356367\n",
"645894116\n",
"-38438170\n",
"437587210\n"
] | 1 | stdio |
Pasha has a positive integer a without leading zeroes. Today he decided that the number is too small and he should make it larger. Unfortunately, the only operation Pasha can do is to swap two adjacent decimal digits of the integer.
Help Pasha count the maximum number he can get if he has the time to make at most k sw... | [
"1990 1\n",
"300 0\n",
"1034 2\n",
"9090000078001234 6\n",
"1234 3\n",
"5 100\n",
"1234 5\n",
"1234 6\n",
"9022 2\n",
"66838 4\n"
] | [
"9190\n",
"300\n",
"3104\n",
"9907000008001234\n",
"4123\n",
"5\n",
"4312\n",
"4321\n",
"9220\n",
"86863\n"
] | 1 | stdio |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.