tests
dict
problem
stringlengths
29
13k
{ "inputs": [ "-3 -2 9 6\n3 -2 7 6\n-1 0 5 0\n2 2 -1 -1\n0 1 2 1\n-3 -1 3 1\n0 0 0 0", "-3 -2 9 6\n3 -2 7 6\n-1 0 5 0\n2 2 0 -1\n0 1 2 1\n-3 -1 3 1\n0 0 0 0", "-1 -2 8 12\n3 -2 7 6\n0 0 9 0\n2 2 0 -1\n1 1 2 1\n-3 -1 3 1\n0 0 0 0", "-1 -2 9 6\n3 -2 7 6\n-1 0 9 0\n2 2 0 -1\n1 2 2 0\n-3 -1 3 1\n0 0 0 0",...
With the motto "Creating your own path," a shrine created a fortune-telling fortune with its own hands. Ask the person who draws the lottery to throw six stones first, then the line segment connecting the first and second of the thrown stones, the line segment connecting the third and fourth, the fifth and six The fort...
{ "inputs": [ "5 2\n1 3 2 3 5\n2 3\n5 1\n3 4\n4 1\n2\n1 2\n2 3\n", "3 3\n1 3 2\n1 2\n1 3\n2\n2 3\n1 1\n", "1 1\n1\n1\n1 1\n", "3 3\n1 3 2\n1 2\n1 3\n2\n2 3\n1 0\n", "5 2\n1 3 2 3 5\n2 3\n5 2\n3 4\n4 1\n2\n1 2\n2 3\n", "5 2\n1 3 3 3 5\n2 3\n5 2\n3 4\n4 1\n2\n1 2\n2 3\n", "5 2\n1 3 3 3 2\n2 ...
You are given a rooted tree consisting of n vertices. Each vertex has a number written on it; number ai is written on vertex i. Let's denote d(i, j) as the distance between vertices i and j in the tree (that is, the number of edges in the shortest path from i to j). Also let's denote the k-blocked subtree of vertex x ...
{ "inputs": [ "4 5\n1 2 3 1\n2 1 2 8\n2 3 4 7\n1 1 3 3\n2 3 4 8\n", "4 5\n1 2 3 1\n2 1 2 8\n2 3 4 7\n1 1 3 3\n2 3 4 13\n", "4 5\n1 2 3 1\n2 1 2 8\n2 3 4 7\n1 1 3 3\n2 3 4 8\n", "1 4\n1 1 1 2\n2 1 1 6\n1 1 1 1\n2 1 1 7\n", "2 2\n2 1 2 8\n2 1 2 7\n", "97 29\n2 78 82 356152\n2 14 29 430177\n1 59 ...
Levko loves array a1, a2, ... , an, consisting of integers, very much. That is why Levko is playing with array a, performing all sorts of operations with it. Each operation Levko performs is of one of two types: 1. Increase all elements from li to ri by di. In other words, perform assignments aj = aj + di for all j ...
{ "inputs": [ "4\n0 0\n0 1\n1 1\n1 0\n", "6\n5 0\n10 0\n12 -4\n10 -8\n5 -8\n3 -4\n", "5\n0 0\n0 10\n10 10\n20 0\n10 -1\n", "4\n-1000000000 -1000000000\n-1000000000 1000000000\n1000000000 1000000000\n1000000000 -1000000000\n", "19\n449447997 711296339\n530233434 692216537\n535464528 613140435\n5355...
You are given a convex polygon P with n distinct vertices p1, p2, ..., pn. Vertex pi has coordinates (xi, yi) in the 2D plane. These vertices are listed in clockwise order. You can choose a real number D and move each vertex of the polygon a distance of at most D from their original positions. Find the maximum value ...
{ "inputs": [ "3\n1 2\n1 3\n", "2\n1 2\n", "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", "6\n1 4\n2 4\n5 6\n3 6\n5 4\n", "6\n1 3\n2 4\n5 6\n3 6\n3 4\n", "6\n1 3\n2 1\n5 6\n3 6\n3 4\n", "3\n1 2\n2 3\n", "6\n1 4\n2 5\n5 6\n3 6\n5 4\n", "6\n...
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...
{ "inputs": [ "3\n10 4 5 2\n5 1 3 4\n20 4 19 3\n", "1\n123 123 123 123\n", "1\n1000000000 5 999999999 1\n", "1\n1000000000 1 1000000000 2\n", "5\n20 10 2 9\n1000000000 2 89 4\n1000000000 2 89 8\n1000000000 89 1 1000000000\n1000000000 1000000000 2 3\n", "1\n1010 1010 1010 1010\n", "1\n11 11...
Vasya is reading a e-book. The file of the book consists of n pages, numbered from 1 to n. The screen is currently displaying the contents of page x, and Vasya wants to read the page y. There are two buttons on the book which allow Vasya to scroll d pages forwards or backwards (but he cannot scroll outside the book). F...
{ "inputs": [ "2\n0 0 100\n1 1 98", "3\n99 1 191\n100 1 192\n99 0 192", "4\n2 3 5\n2 1 5\n1 2 5\n3 2 5", "2\n-1 0 100\n2 1 98", "3\n99 1 191\n000 1 192\n99 0 192", "2\n-2 0 100\n2 2 98", "3\n99 1 191\n000 1 154\n99 0 192", "3\n99 1 191\n000 1 210\n99 0 192", "2\n-1 -1 101\n2 3 98",...
In the Ancient Kingdom of Snuke, there was a pyramid to strengthen the authority of Takahashi, the president of AtCoder Inc. The pyramid had center coordinates (C_X, C_Y) and height H. The altitude of coordinates (X, Y) is max(H - |X - C_X| - |Y - C_Y|, 0). Aoki, an explorer, conducted a survey to identify the center ...
{ "inputs": [ "3\nperfection is achieved not when there is nothing more to add but when there is nothing left to take away\nyou must be the change you wish to see in the world\nif the lessons of history teach us anything it is that nobody learns the lessons that history teaches us\n\nSAMPLE", "5 \nspecificall...
Somnath is a Grammar Nazi. He keeps pointing out others’ grammatical mistakes. However, for a given sentence, he tries to remember all the unique words only so that he can be more efficient with his annoying habit. You wish to join his team to help him with his obsession for Queen’s Language. Given a sentence S, find t...
{ "inputs": [ "7\n4 1 2 2 1 5 3\n", "4\n1 1 1 1\n", "11\n-5 -4 -3 -2 -1 0 1 2 3 4 5\n", "100\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 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 69 70 71 72 7...
This problem is given in two editions, which differ exclusively in the constraints on the number n. You are given an array of integers a[1], a[2], ..., a[n]. A block is a sequence of contiguous (consecutive) elements a[l], a[l+1], ..., a[r] (1 ≤ l ≤ r ≤ n). Thus, a block is defined by a pair of indices (l, r). Find a...
{ "inputs": [ "2\n10 2 6\n1 3\n10 3 5\n1 3 9\n\nSAMPLE", "7\n100 3 25\n25 50 75\n100 3 50\n25 50 75\n100 3 24\n25 50 75\n100 9 50\n99 88 77 66 55 44 33 22 11\n100 11 71\n67 21 90 77 19 38 85 91 23 29 42\n100 2 50\n50 51\n100 2 49\n50 51" ], "outputs": [ "1\n3", "3\n0\n3\n26\n10\n0\n1" ] }
We have a S cm long stick.It can be broken only at certain positions.Sarah wants to calculate the number of GOOD Pairs. It satisfies the following conditions A good pair consists of 2 distinct positions where the stick can be broken. When the stick is broken at these two positions there should be at least one st...
{ "inputs": [ "2\n3\n5" ], "outputs": [ "6\n15" ] }
According to folklore, the great mathematician Gauss was able to calculate the sum of the first 50 natural numbers in mere seconds. You are given a similar problem, where you have to calculate the sum of the first 'n' natural numbers. The only catch being that the the number 'n' can be really very large. You have to ca...
{ "inputs": [ "1?AA\n", "AJ\n", "???\n", "??JG?\n", "9???\n", "B?\n", "A\n", "IG5IJ\n", "5??\n", "????\n", "?\n", "???2\n", "3??\n", "?BB\n", "7\n", "H1I??\n", "HH???\n", "BC??\n", "CB\n", "?3?2\n", "?J?5?\n", "BBB?\n", "10234...
Special Agent Smart Beaver works in a secret research department of ABBYY. He's been working there for a long time and is satisfied with his job, as it allows him to eat out in the best restaurants and order the most expensive and exotic wood types there. The content special agent has got an important task: to get th...
{ "inputs": [ "1 1 100\n100 100 100\n6 4 10\n100 100 100\n106 102 102\n112 110 104\n104 116 102\n100 114 104\n92 107 100\n10 4 10\n-100 101 100\n-108 102 120\n-116 103 100\n-124 100 100\n-132 99 100\n-92 98 100\n-84 100 140\n-76 103 100\n-68 102 100\n-60 101 100\n10 4 10\n100 100 100\n108 101 100\n116 102 100\n12...
3D Printing We are designing an installation art piece consisting of a number of cubes with 3D printing technology for submitting one to Installation art Contest with Printed Cubes (ICPC). At this time, we are trying to model a piece consisting of exactly k cubes of the same size facing the same direction. First, usi...
{ "inputs": [ "8\n1\n0\n1\n1\n0\n0\n0\n0\n8\n1\n0\n1\n1\n0\n0\n0\n1\n0", "8\n1\n1\n1\n1\n0\n0\n0\n0\n8\n1\n0\n1\n1\n0\n0\n0\n1\n0", "8\n1\n1\n1\n1\n0\n0\n0\n0\n8\n1\n0\n0\n1\n0\n0\n0\n1\n0", "8\n1\n0\n1\n1\n0\n0\n0\n0\n4\n1\n0\n1\n1\n0\n0\n0\n1\n0", "8\n1\n0\n1\n1\n0\n0\n0\n0\n2\n1\n0\n1\n1\n0\n0\...
problem Play by arranging white and black stones on the table. First, place the stones on the left edge of the table. Then place the stones in the second place from the left. Repeat this n times to arrange n stones in a horizontal row. However, when placing a new i-th go stone, replace the go stone on the table accord...
{ "inputs": [ "1 5\n2 3\n", "1 2\n1000000000 1\n", "2 4\n5 2\n2 1\n", "2 5\n2 1\n1 3\n", "3 4\n7 0\n0 3\n3 3\n", "1 5\n999999999 1\n", "5 500\n87 43\n44 29\n15 58\n94 29\n65 7\n", "1 5\n0 0\n", "5 11\n3 7\n2 10\n4 7\n7 4\n9 2\n", "3 5\n1 8\n8 0\n0 8\n", "5 7\n4 0\n3 1\n1 6\...
Phoenix is picking berries in his backyard. There are n shrubs, and each shrub has a_i red berries and b_i blue berries. Each basket can contain k berries. But, Phoenix has decided that each basket may only contain berries from the same shrub or berries of the same color (red or blue). In other words, all berries in a...
{ "inputs": [ "2\n1 2 2\n1 1 1\n\nSAMPLE", "1000\n725 248 935\n139 402 325\n383 976 540\n407 152 158\n897 369 160\n913 870 150\n931 478 19\n936 641 908\n147 117 438\n378 871 144\n860 850 235\n535 929 11\n218 584 955\n944 663 353\n903 402 811\n172 147 154\n869 294 168\n408 742 333\n769 375 118\n690 796 52\n819...
Its Alice's birthday and her friend Bob gets him a birthday cake. Its nice delicious circle shaped cake of radius R. Now they need to cut and eat that cake, so Alice fetches a cutter from her kitchen. It is a rectangular cutter of length A and breadth B that would knock of the part of the cake when the cutter is place...
{ "inputs": [ "5 2\n5 3 6 5 2\n", "5 4\n2 3 5 2 5\n", "5 2\n3 6 2 2 1\n", "7 3\n7 6 7 9 7 3 9\n", "10 6\n3 4 5 5 4 8 4 2 8 3\n", "50 1\n695797968 223207386 939364234 380535445 948239846 479142231 970602012 310908190 48679131 747711359 823754073 300661463 367129258 805564870 904374869 775634910...
During the final part of fashion show all models come to the stage and stay in one row and fashion designer stays to right to model on the right. During the rehearsal, Izabella noticed, that row isn't nice, but she can't figure out how to fix it. Like many other creative people, Izabella has a specific sense of beaut...
{ "inputs": [ "8.549e3\n", "0.33e0\n", "8.549e2\n", "4.6329496401734172195e50\n", "8.1089882894234341219420177467603732503076124872188628349726911362800974096687340341040683238197289136e31\n", "8.25983e5\n", "7.0e100\n", "2.06290948075954911323062647470422439284863033847919512203620962...
Barney is standing in a bar and starring at a pretty girl. He wants to shoot her with his heart arrow but he needs to know the distance between him and the girl to make his shot accurate. <image> Barney asked the bar tender Carl about this distance value, but Carl was so busy talking to the customers so he wrote the ...
{ "inputs": [ "AA\nA\nA\n", "AJKEQSLOBSROFGZ\nOVGURWZLWVLUXTH\nOZ\n", "ABBBABABABABABBABAABAAABABAABABABABBABAAAABABABBABAABABAAABAABBAAABAABABBABBABABBABAABABABAAAAABABAB\nB\nBABBABAABABABABABABABABABBAABABBABABBAAABAAABABBAABAABBABABBABABAABBABAABABBAABAABAABABABABABBABABAB\n", "KOROXDDWEUVYWJIXSFPE...
In mathematics, a subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements. For example, the sequence BDF is a subsequence of ABCDEF. A substring of a string is a continuous subsequence of the string. For example, BCD is a substri...
{ "inputs": [ "3\n1\n5\n499993\n", "3\n5\n3005\n3005\n", "1\n69791\n", "1\n214541\n", "1\n499999\n", "1\n214145\n", "3\n5\n3005\n1983\n", "1\n203317\n", "3\n7\n3005\n3005\n", "1\n288977\n", "1\n254785\n", "1\n54111\n", "3\n7\n3005\n5103\n", "1\n151107\n", "1...
You are given a board of size n × n, where n is odd (not divisible by 2). Initially, each cell of the board contains one figure. In one move, you can select exactly one figure presented in some cell and move it to one of the cells sharing a side or a corner with the current cell, i.e. from the cell (i, j) you can move...
{ "inputs": [ "47 1024\n", "2 47\n", "1827171 232817181719384635\n", "1 1000000000000000000\n", "2 2\n", "779547115376367013 980561039207670775\n", "110 147\n", "1 10\n", "9997 87878000008\n", "458985985498001244 985458425544874008\n", "335408916782916802 416495628489807285...
The Little Elephant very much loves sums on intervals. This time he has a pair of integers l and r (l ≤ r). The Little Elephant has to find the number of such integers x (l ≤ x ≤ r), that the first digit of integer x equals the last one (in decimal notation). For example, such numbers as 101, 477474 or 9 will be inclu...
{ "inputs": [ "3 3 10\nE..\n.#.\n...\n5 5 19\n####.\n.....\n.#S#.\n...#.\n#.##.\n5 5 6\n#.#..\n#....\n##.#.\n#..S.\n#....\n5 4 35\n..##\n....\n.##.\n.#S.\n...#\n0 0 0", "3 3 10\nE..\n.#.\n...\n5 5 19\n.\n.....\n.#S#.\n...#.\n.##.\n5 5 6\n.#..\n....\n.#.\n..S.\n....\n5 4 35\n..##\n....\n.##.\n.#S.\n...#\n0 0 0...
Dr. Fukuoka has placed a simple robot in a two-dimensional maze. It moves within the maze and never goes out of the maze as there is no exit. The maze is made up of H × W grid cells as depicted below. The upper side of the maze faces north. Consequently, the right, lower and left sides face east, south and west respec...
{ "inputs": [ "4 10\n3 4 7 2\n", "10 12\n16 3 24 13 9 8 7 5 12 12\n", "10 5 12\n16 3 24 13 9 8 7 5 12 12\n", "5 50\n1 1 1 1 1\n", "5 50\n100 150 200 100 50\n", "4 3 10\n3 4 7 2\n", "2 2\n9 9\n", "2 2\n8 8\n", "10 5 12\n16 3 24 13 9 8 5 5 12 12\n", "5 50\n1 2 1 1 1\n", "5 50...
Rebel spy Heidi has just obtained the plans for the Death Star from the Empire and, now on her way to safety, she is trying to break the encryption of the plans (of course they are encrypted – the Empire may be evil, but it is not stupid!). The encryption has several levels of security, and here is how the first one lo...
{ "inputs": [ "21\n", "7\n", "2887\n", "100000000\n", "68888886\n", "2886\n", "68888885\n", "68888892\n", "1000000000000\n", "10\n", "8888888891\n", "197\n", "68888891\n", "2899\n", "200\n", "68888895\n", "68888884\n", "9900\n", "1000000\n", ...
Let's write all the positive integer numbers one after another from 1 without any delimiters (i.e. as a single string). It will be the infinite sequence starting with 123456789101112131415161718192021222324252627282930313233343536... Your task is to print the k-th digit of this sequence. Input The first and only lin...
{ "inputs": [ "2\n3 5\n", "4\n10 20 10 30\n", "8\n2 2 5 3 4 3 3 2\n", "5\n4 4 3 5 1\n", "2\n468 335\n", "6\n2 3 2 2 1 3\n", "5\n479 359 963 465 706\n", "49\n516 161 416 850 361 861 833 233 281 798 225 771 841 111 481 617 463 305 743 945 833 141 70 617 511 522 840 505 753 544 931 213 62...
Gena loves sequences of numbers. Recently, he has discovered a new type of sequences which he called an almost arithmetical progression. A sequence is an almost arithmetical progression, if its elements can be represented as: * a1 = p, where p is some integer; * ai = ai - 1 + ( - 1)i + 1·q (i > 1), where q is som...
{ "inputs": [ "1\n2 4", "2\n2 3\n3 8", "10\n2 8\n5 9\n7 20\n8 41\n23 48\n90 112\n4 5\n7 7\n2344 8923\n1 29", "1\n2 5", "2\n1 3\n3 9", "2\n1 3\n3 8", "10\n2 8\n5 9\n7 20\n8 41\n23 48\n112 112\n4 5\n7 7\n2344 8923\n1 29", "1\n2 6", "10\n2 14\n5 9\n7 20\n8 41\n23 48\n112 112\n4 5\n7 7...
Problem One day, mo3tthi and tubuann decided to play a game with magic pockets and biscuits. Now there are $ K $ pockets, numbered $ 1,2, \ ldots, K $. The capacity of the $ i $ th pocket is $ M_i $, which initially contains $ N_i $ biscuits. mo3tthi and tubuann start with mo3tthi and perform the following series of o...
{ "inputs": [ "1\n2\n3\n4\n5\n6\n7\n8\n9\n10", "1\n2\n4\n4\n5\n6\n7\n8\n9\n10", "1\n2\n8\n4\n5\n6\n7\n8\n9\n10", "1\n2\n8\n4\n3\n6\n7\n8\n9\n10", "1\n2\n8\n3\n3\n6\n7\n8\n9\n10", "1\n2\n8\n3\n3\n6\n7\n5\n9\n10", "1\n2\n8\n4\n3\n6\n7\n5\n9\n10", "1\n2\n2\n4\n3\n6\n7\n5\n9\n10", "1\n...
Welcome to PC Koshien, players. This year marks the 10th anniversary of Computer Koshien, but the number of questions and the total score will vary from year to year. Scores are set for each question according to the difficulty level. When the number of questions is 10 and the score of each question is given, create a ...
{ "inputs": [ "6\n0 0 1 2 0 0\n", "5\n0 0 1 2 0\n", "4\n0 0 0 0\n", "5\n5 3 4 2 1\n", "10\n1 0 3 0 0 6 0 8 0 0\n", "3\n0 0 1\n", "2\n0 0\n", "7\n1 4 3 2 5 6 7\n", "5\n0 2 0 4 0\n", "7\n0 0 0 0 0 0 0\n", "15\n0 4 0 0 5 12 7 0 9 10 13 0 1 0 0\n", "2\n1 2\n", "2\n2 1\n...
Two positive integers are coprime if and only if they don't have a common divisor greater than 1. Some bear doesn't want to tell Radewoosh how to solve some algorithmic problem. So, Radewoosh is going to break into that bear's safe with solutions. To pass through the door, he must enter a permutation of numbers 1 thro...
{ "inputs": [ "3\n10\n10 9 8 7 6 5 4 3 2 1\n7\n1 2 2 2 3 2 2\n3\n100 100 100\n" ], "outputs": [ "\n10\n1 6 2 7 3 8 4 9 5 10 \n4\n2 1 3 2 \n1\n100 \n" ] }
You are given the sequence a_1, a_2, ..., a_n. You can choose any subset of elements and then reorder them to create a "saw". The sequence b_1, b_2, ..., b_m is called a "saw" if the elements satisfy one of the following series of inequalities: b_1>b_2<b_3>b_4<... or b_1<b_2>b_3<b_4>.... Find the longest saw which ca...
{ "inputs": [ "4\n20\n13\n8\n4", "4\n38\n13\n8\n4", "4\n38\n14\n8\n4", "4\n38\n14\n1\n4", "4\n62\n14\n1\n4", "4\n62\n14\n1\n3", "4\n85\n14\n1\n3", "4\n40\n14\n1\n3", "4\n40\n1\n1\n3", "4\n40\n1\n2\n3", "4\n34\n13\n8\n4", "4\n38\n13\n8\n2", "4\n38\n14\n8\n3", "4\...
Our Chef is catering for a big corporate office party and is busy preparing different mouth watering dishes. The host has insisted that he serves his delicious cupcakes for dessert. On the day of the party, the Chef was over-seeing all the food arrangements as well, ensuring that every item was in its designated posi...
{ "inputs": [ "2\n1 1 2 2 3 3\n1 2 5 4 10 15\n\nSAMPLE", "10\n4 9 0 4 7 1\n5 5 4 2 8 8\n2 5 1 1 7 1\n3 2 4 1 6 7\n5 8 6 1 2 2\n2 9 8 1 6 7\n1 3 4 6 9 11\n1 1 4 3 3 2\n7 2 4 7 8 3\n8 9 1 2 0 1", "10\n4 9 0 4 7 1\n5 5 4 2 8 8\n2 5 1 1 6 1\n3 2 4 1 6 7\n5 8 6 1 2 2\n2 9 8 1 6 7\n1 3 4 6 9 11\n1 1 4 3 3 2\n7 ...
In a coordinate system,There are 3 chocolate which will be placed at three random position (x1,y1),(x2,y2) and (x3,y3).Ramesh loves Chocolates. Ramesh always moves along a straight line. your task is to find out whether he can have all the chocolates. Input Format :- The first line of the input contains an integer T d...
{ "inputs": [ "5 5 13 0 4\n0 1 5\n2 1 2\n3 2 3\n1 4 0\n4 3 4\n", "2 1 123456789 0 1\n0 1 0\n", "2 1 999999999 1 0\n0 1 1000000000\n", "7 9 999999999 0 3\n0 1 0\n1 2 0\n2 3 0\n0 4 1\n4 1 1\n1 5 499999999\n5 2 499999999\n2 6 1\n6 3 1\n", "7 9 320 0 3\n0 1 0\n1 2 0\n2 3 0\n0 4 1\n4 1 1\n1 5 100\n5 2 ...
ZS the Coder has drawn an undirected graph of n vertices numbered from 0 to n - 1 and m edges between them. Each edge of the graph is weighted, each weight is a positive integer. The next day, ZS the Coder realized that some of the weights were erased! So he wants to reassign positive integer weight to each of the edg...
{ "inputs": [ "4\n3 3 5\n0 0\n10 0\n40 40\n40 90\n4 5 10\n100 100\n50 100\n50 150\n100 50\n100 150\n4 60 10\n100 100\n90 100\n110 100\n100 90\n100 110\n4 60 10\n100 100\n80 100\n110 100\n100 80\n100 110", "4\n3 3 5\n0 0\n10 0\n40 40\n40 90\n4 5 10\n100 100\n50 100\n50 150\n100 50\n100 150\n4 60 10\n100 100\n9...
Natsume loves big cats. One day, Natsume was invited by the stray cats she was always close to to go to the mysterious bookstore where the cats were open. When I heard that the bookstore sells books with many pictures of cats, Natsume decided to follow her happily. I didn't know Natsume, but the bookstore that was tak...
{ "inputs": [ "3\n6\n1 0\n2 1\n3 1\n4 1\n5 1\n6 0\n5\n1 1\n2 0\n3 1\n1 1\n2 1\n4\n1 1\n2 1\n2 1\n3 1\n\nSAMPLE", "3\n6\n1 0\n3 1\n3 1\n4 1\n5 1\n6 0\n5\n1 1\n2 0\n3 1\n1 1\n2 1\n4\n1 1\n2 1\n2 1\n3 1\n\nSAMPLE", "3\n6\n2 0\n2 1\n3 1\n4 1\n5 1\n6 0\n5\n1 1\n2 0\n3 1\n1 1\n2 1\n4\n1 1\n2 1\n2 1\n3 1\n\nSAMP...
Roy is working on HackerEarth Profile. Right now he is working on User Statistics. One of the statistics data (Code Streak) is as follows: Given the User Activity Data, find the maximum number of continuous correct solutions submitted by any user. Seems easy eh? Here's the catch! In order to maximize this number a use...
{ "inputs": [ "7 2\n10 20 30 40 50 45 35\n-1000000000 10\n1000000000 1\n", "4 5\n6 2 8 9\n3 6\n2 1\n3 6\n4 7\n4 7\n", "6 6\n-1000000000 -999999999 -999999985 999999996 -999999990 -999999983\n999999983 2\n-999999997 1\n999999983 1\n-999999997 1\n999999992 1\n999999983 1\n", "4 4\n-8 0 -8 -1\n0 1\n-2 1\...
One day Masha came home and noticed n mice in the corridor of her flat. Of course, she shouted loudly, so scared mice started to run to the holes in the corridor. The corridor can be represeted as a numeric axis with n mice and m holes on it. ith mouse is at the coordinate xi, and jth hole — at coordinate pj. jth hole...
{ "inputs": [ "6\n1 1\n2 1\n2 2\n3 1\n3 2\n3 3\n", "6\n1 1\n2 1\n2 2\n3 1\n3 2\n2 3\n", "6\n1 1\n2 1\n2 2\n2 1\n3 2\n3 3\n", "6\n1 1\n2 1\n2 2\n3 1\n6 2\n1 3\n", "6\n1 1\n2 2\n2 2\n3 1\n3 2\n2 3\n", "6\n1 2\n2 1\n2 2\n2 1\n3 2\n3 3\n", "6\n1 1\n1 1\n2 3\n2 1\n3 2\n3 3\n", "6\n1 1\n2 1\...
The sequence of integer pairs (a1, b1), (a2, b2), ..., (ak, bk) is beautiful, if the following statements are fulfilled: * 1 ≤ a1 ≤ b1 < a2 ≤ b2 < ... < ak ≤ bk ≤ n, where n is a given positive integer; * all numbers b1 - a1, b2 - a2, ..., bk - ak are distinct. For the given number n find the number of beaut...
{ "inputs": [ "2\n2 2\n100000 20\n", "10\n50 1\n40 7\n40 6\n40 5\n40 4\n40 3\n40 2\n40 1\n49 7\n49 6\n", "10\n6 4\n6 3\n6 2\n6 1\n1 1\n2 1\n10 1\n100000 1\n100000 20\n99999 20\n", "1\n10 20\n", "10\n5 4\n5 3\n5 2\n5 1\n4 4\n4 3\n3 2\n3 1\n2 4\n2 3\n", "1\n2 3\n", "10\n49 5\n49 4\n49 3\n49 ...
Baby Badawy's first words were "AND 0 SUM BIG", so he decided to solve the following problem. Given two integers n and k, count the number of arrays of length n such that: * all its elements are integers between 0 and 2^k-1 (inclusive); * the [bitwise AND](https://en.wikipedia.org/wiki/Bitwise_operation#AND) of a...
{ "inputs": [ "100 100 0", "3 2 1", "60522 114575 7559", "100 110 0", "6 2 1", "119754 114575 7559", "100 010 0", "12 2 1", "119754 114575 8988", "100 010 -1", "11 2 1", "145188 114575 8988", "11 3 1", "145188 114575 3371", "5 3 1", "145188 114575 5625",...
There are N blocks arranged in a row. Let us paint these blocks. We will consider two ways to paint the blocks different if and only if there is a block painted in different colors in those two ways. Find the number of ways to paint the blocks under the following conditions: * For each block, use one of the M colors...
{ "inputs": [ "1 1 0\n2 2 0\n", "1 1 0\n2 -2 0\n", "1 -1 1\n0 0 0\n", "-1 0 0\n-2 1 2\n", "-1 -1 1\n1 1 0\n", "2 2 1\n1 2 0\n", "-1 1 1\n0 1 1\n", "0 -1 -1\n-2 -2 -1\n", "-2 -1 1\n-1 1 1\n", "1 0 0\n0 1 0\n", "1 1 -1\n-1 0 -1\n", "-2 -1 0\n-2 2 2\n", "1 1 -1\n0 1 0\...
You are given two set of points. The first set is determined by the equation A1x + B1y + C1 = 0, and the second one is determined by the equation A2x + B2y + C2 = 0. Write the program which finds the number of points in the intersection of two given sets. Input The first line of the input contains three integer numb...
{ "inputs": [ "3\n3 -1 4\n2 1 3", "4\n3 -1 -1 3\n1 1 1 1", "3\n3 -1 4\n2 1 5", "3\n3 -1 4\n2 1 6", "3\n3 -1 6\n1 1 5", "3\n1 2 2\n1 0 0", "4\n3 -1 -2 3\n1 1 1 1", "3\n3 -1 4\n1 1 5", "3\n3 -1 4\n1 1 6", "3\n3 0 4\n1 1 6", "3\n0 -1 6\n1 1 5", "3\n3 0 4\n1 0 6", "3\n0...
In 20XX, the owners of the ICPC (Ikuta's Computer Pollutes Community) shopping district were suffering from air pollution. In order to regain the vitality of the past, the cleanliness of the atmosphere must be kept above a certain level. The shops in the shopping district are lined up in a row and are numbered from 1 ...
{ "inputs": [ "4\n1 2 3 4\n1 2\n1 3\n1 4", "7\n-2 7 5 6 -8 3 4\n1 2\n2 3\n2 4\n1 5\n5 6\n5 7", "10\n3 4 9 6 1 5 -1 10 -10 -10\n7 4\n5 6\n8 1\n9 5\n7 1\n10 3\n2 8\n4 10\n9 2", "6\n10 -1 10 -1 10 -1\n1 2\n2 3\n3 4\n4 5\n5 6", "8\n-2 3 6 -2 -2 -5 3 2\n3 4\n7 6\n6 2\n8 2\n5 3\n1 8\n3 7", "4\n1 2 3...
The server in company A has a structure where N devices numbered 1, 2, ..., N are connected with N - 1 cables. The i-th cable connects Device U_i and Device V_i. Any two different devices are connected through some number of cables. Each device v (1 \leq v \leq N) has a non-zero integer A_v, which represents the follo...
{ "inputs": [ "qwertyuiopasdfghjklzxcvbnm\nveamhjsgqocnrbfxdtwkylupzi\nTwccpQZAvb2017\n", "mnbvcxzlkjhgfdsapoiuytrewq\nasdfghjklqwertyuiopzxcvbnm\n7abaCABAABAcaba7\n", "qwertyuiopasdfghjklzxcvbnm\nqwertyuiopasdfghjklzxcvbnm\nqwertyuiopasdfghjklzxcvbnmPOIUYTREWQLKJHGFDSAMNBVCXZ12345678900987654321ASDFGHJKL...
There are two popular keyboard layouts in Berland, they differ only in letters positions. All the other keys are the same. In Berland they use alphabet with 26 letters which coincides with English alphabet. You are given two strings consisting of 26 distinct letters each: all keys of the first and the second layouts i...
{ "inputs": [ "2\n90 10 10\n-3 0 1 45 10 90 10\n-6 0 2 30 3 180 10\n-9 0 1", "1\n90 10 20\n3 3 1 90 10 315 10\n6 0 1", "2\n90 10 10\n0 0 1 45 10 90 10\n-6 0 2 30 3 180 10\n-9 0 1", "1\n90 20 20\n3 3 1 90 10 315 10\n6 0 1", "2\n90 10 8\n0 0 1 45 10 90 10\n-6 -1 2 30 3 180 10\n-9 0 1", "1\n90 13...
Problem N circular light sources are arranged on a two-dimensional plane. When a light source receives light, the light is emitted in a fan shape from the center point of the light source as shown in the figure below. <image> The center point of the light source is represented by (x, y) and the radius is represented ...
{ "inputs": [ "50 30 10 10\n", "100 50 10 21\n", "3 2 1 1\n", "50 30 10 5\n", "50 49 5 10\n", "50 20 4 8\n", "100 50 3 1\n", "60 30 10 1\n", "99 22 13 14\n", "99 50 25 49\n", "100 40 30 40\n", "99 32 13 5\n", "40 30 20 10\n", "100 50 19 30\n", "5 4 3 1\n", ...
A family consisting of father bear, mother bear and son bear owns three cars. Father bear can climb into the largest car and he likes it. Also, mother bear can climb into the middle car and she likes it. Moreover, son bear can climb into the smallest car and he likes it. It's known that the largest car is strictly larg...
{ "inputs": [ "4\n", "3\n", "500\n", "7\n", "23\n", "496\n", "13\n", "6\n", "1\n", "14\n", "499\n", "79\n", "8\n", "4\n", "17\n", "12\n", "100\n", "256\n", "48\n", "99\n", "66\n", "9\n", "16\n", "495\n", "498\n", "...
Leo Jr. draws pictures in his notebook with checkered sheets (that is, each sheet has a regular square grid printed on it). We can assume that the sheets are infinitely large in any direction. To draw a picture, Leo Jr. colors some of the cells on a sheet gray. He considers the resulting picture beautiful if the follo...
{ "inputs": [ "6\n1 5\n3 3\n4 4\n9 2\n10 1\n12 1\n4\n1 2\n2 4\n2 5\n2 6\n", "3\n1 1000000000\n999999999 1000000000\n1000000000 1000000000\n4\n1 2\n1 2\n2 3\n1 3\n", "2\n304 54\n88203 83\n1\n1 2\n", "20\n4524 38\n14370 10\n22402 37\n34650 78\n50164 57\n51744 30\n55372 55\n56064 77\n57255 57\n58862 64\n...
Celebrating the new year, many people post videos of falling dominoes; Here's a list of them: https://www.youtube.com/results?search_query=New+Years+Dominos User ainta, who lives in a 2D world, is going to post a video as well. There are n dominoes on a 2D Cartesian plane. i-th domino (1 ≤ i ≤ n) can be represented a...
{ "inputs": [ "100000 200000\n", "3 4\n", "3 5\n", "42 1337\n", "3 3\n", "20 20\n", "3 200000\n", "2 2\n", "150000 200000\n", "200000 200000\n", "1000 200000\n", "2 3\n", "7 14\n", "2 10\n", "3 6\n", "6 200000\n", "2 1\n", "113870 200000\n", ...
Your task is to calculate the number of arrays such that: * each array contains n elements; * each element is an integer from 1 to m; * for each array, there is exactly one pair of equal elements; * for each array a, there exists an index i such that the array is strictly ascending before the i-th element a...
{ "inputs": [ "2 3\n1 2\n", "6 1\n5 1 2 3 4 1\n", "10 0\n1 1 1 1 1 1 1 1 1 1\n", "5 0\n1 1 1 1 1\n", "69 25\n68 26 8 121 96 101 106 87 103 14 86 26 76 85 70 50 4 4 97 89 44 98 33 65 76 64 98 95 30 5 93 121 97 85 47 50 66 2 46 79 46 22 68 59 75 94 104 105 91 97 121 6 32 94 101 125 32 91 76 57 110 3...
There are some beautiful girls in Arpa’s land as mentioned before. Once Arpa came up with an obvious problem: Given an array and a number x, count the number of pairs of indices i, j (1 ≤ i < j ≤ n) such that <image>, where <image> is bitwise xor operation (see notes for explanation). <image> Immediately, Mehrdad d...
{ "inputs": [ "2 2\n10 20 1\n0 10 1\n0 10\n10 0\n0 0", "2 2\n10 20 1\n0 10 1\n0 10\n18 0\n0 0", "2 2\n10 20 1\n0 10 1\n0 10\n1 0\n0 0", "2 2\n10 20 2\n0 10 1\n0 10\n1 0\n0 0", "2 2\n10 20 1\n0 10 1\n0 11\n8 0\n0 -1", "2 2\n10 20 2\n0 3 1\n1 11\n8 0\n0 -1", "2 2\n11 20 1\n0 10 1\n0 10\n1 0\...
A country Gizevom is being under a sneak and fierce attack by their foe. They have to deploy one or more troops to every base immediately in order to defend their country. Otherwise their foe would take all the bases and declare "All your base are belong to us." You are asked to write a program that calculates the min...
{ "inputs": [ "2 2 3\n0 0\n2 0\n0 0\n0 2\n0 0\n1 1\n1 1", "2 2 3\n0 0\n2 0\n0 1\n0 2\n0 0\n1 1\n1 1", "2 2 3\n0 0\n3 0\n0 1\n0 2\n0 0\n1 1\n1 1", "2 2 2\n0 0\n2 0\n0 1\n0 2\n0 -1\n1 1\n1 1", "2 2 3\n0 0\n2 0\n0 1\n0 2\n0 1\n1 1\n1 1", "2 2 5\n0 0\n3 0\n0 1\n0 2\n0 0\n1 1\n1 1", "2 2 3\n0 0...
Example Input 2 2 3 0 0 2 0 0 0 0 2 0 0 1 1 1 1 Output 3
{ "inputs": [ "4 4 6\n2 2\n3 2 \n3 2 \n4 3\n4 4\n4 3", "4 4 6\n3 2\n3 2 \n3 2 \n4 3\n4 4\n4 3", "4 4 6\n3 2\n3 2 \n3 2 \n4 3\n4 4\n4 1", "4 4 6\n3 2\n3 3 \n3 2 \n4 3\n4 4\n4 3", "4 6 6\n3 2\n2 3 \n3 2 \n4 3\n4 4\n4 3", "4 6 2\n3 2\n2 3 \n3 2 \n4 3\n4 4\n4 3", "3 6 2\n1 2\n3 0 \n6 2 \n4 3\n...
Spring is interesting season of year. Chef is thinking about different things, but last time he thinks about interesting game - "Strange Matrix". Chef has a matrix that consists of n rows, each contains m elements. Initially, the element aij of matrix equals j. (1 ≤ i ≤ n, 1 ≤ j ≤ m). Then p times some element aij is...
{ "inputs": [ "8\n1 1 2 2\n0 2\n0 0\n2 0\n2 1\n3 1\n3 3\n1 3\n1 2\n12\n-9 5 9 -9\n0 0\n0 -13\n3 -13\n3 -10\n10 -10\n10 10\n-1 10\n-1 13\n-4 13\n-4 10\n-10 10\n-10 0\n12\n3 57 53 2\n0 0\n64 0\n64 18\n47 18\n47 39\n64 39\n64 60\n0 60\n0 44\n33 44\n33 30\n0 30\n0", "8\n1 1 2 2\n0 2\n0 0\n2 0\n2 1\n3 1\n3 3\n1 3\...
NINJA GAME The new game "NINJA GAME" has finally been released. In this game, the player operates a ninja on a two-dimensional map to move. A two-dimensional map is represented by a non-self-intersecting polygon consisting of only sides parallel to either the x-axis or the y-axis. Now, we need to move from the start p...
{ "inputs": [ "5 3\n1 2\n2 3\n4 5\n2 1 2 2 1\n", "3 3\n1 2\n2 3\n3 1\n2 1 3\n", "3 3\n1 2\n2 3\n3 1\n1 1 1\n", "4 4\n1 2\n1 3\n2 4\n3 4\n1 2 2 3\n", "6 5\n1 3\n3 2\n2 4\n2 5\n5 6\n1 3 3 1 2 1\n", "5 4\n1 2\n5 2\n5 3\n1 5\n1 3 1 1 2\n", "10 20\n8 9\n2 1\n8 4\n3 4\n4 6\n10 3\n7 8\n2 3\n10 7\...
Today Johnny wants to increase his contribution. His plan assumes writing n blogs. One blog covers one topic, but one topic can be covered by many blogs. Moreover, some blogs have references to each other. Each pair of blogs that are connected by a reference has to cover different topics because otherwise, the readers ...
{ "inputs": [ "6 23\n#######################\n#%.^.^#################\n#^^^^^######^^^^^^^^^^#\n#^^^...^^^^...^^*^^..*#\n#^^^^^^^^^^^^^^^^^^^^^#\n#######################\n5 16\n################\n#^^^^^^^^^^^^^^#\n#*..^^^.%.^^..*#\n#^^#####^^^^^^^#\n################\n0 0", "6 23\n#######################\n#%.^....
Ninjas are professional spies in the Middle Age of Japan. They have been popular in movies and games as they have been described with extraordinary physical abilities and unrealistic abilities. You are absorbed in one of ninja games, Ninja Legend. In this game, you control in an exceptionally talented ninja named Mast...
{ "inputs": [ "4 3\n*..\n.*.\n..*\n...\n", "5 5\n..*..\n.....\n**...\n**...\n**...\n", "4 4\n.*..\n*...\n...*\n..*.\n", "3 4\n..**\n*...\n....\n", "3 4\n..**\n*...\n....\n", "4 3\n..*\n.*.\n..*\n...\n", "4 4\n.*..\n..*.\n...*\n..*.\n", "3 4\n..*)\n*...\n....\n", "4 3\n..*\n.*.\n-.*...
A mouse encountered a nice big cake and decided to take a walk across it, eating the berries on top of the cake on its way. The cake is rectangular, neatly divided into squares; some of the squares have a berry in them, and some don't. The mouse is in a bit of a hurry, though, so once she enters the cake from its nort...
{ "inputs": [ "2\n0 3\n1 5\n", "1\n0 4\n", "2\n1 10\n2 2\n", "10\n11 69\n7 56\n8 48\n2 56\n12 6\n9 84\n1 81\n4 80\n3 9\n5 18\n", "2\n0 16\n1 4\n", "14\n0 268435456\n1 67108864\n2 16777216\n3 4194305\n4 1048576\n5 262144\n6 65536\n7 16384\n8 4096\n9 1024\n10 256\n11 64\n12 16\n13 4\n", "1\n...
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...
{ "inputs": [ "6\n1 2\n1 3\n3 4\n3 5\n4 6\n", "4\n1 2\n1 3\n1 4\n", "2\n1 2\n", "10\n1 2\n1 3\n3 4\n2 5\n6 4\n7 4\n8 3\n9 5\n10 5\n", "10\n1 2\n2 3\n3 4\n3 5\n6 5\n7 4\n8 5\n9 1\n10 1\n", "10\n1 2\n1 3\n1 4\n4 5\n6 5\n7 1\n8 5\n9 5\n10 1\n", "10\n1 2\n1 3\n3 4\n2 5\n6 4\n7 4\n8 3\n9 5\n10 ...
Fedor runs for president of Byteland! In the debates, he will be asked how to solve Byteland's transport problem. It's a really hard problem because of Byteland's transport system is now a tree (connected graph without cycles). Fedor's team has found out in the ministry of transport of Byteland that there is money in t...
{ "inputs": [ "1\n", "2\n", "6259\n", "5987\n", "99\n", "1234\n", "15\n", "51\n", "13\n", "9411\n", "7\n", "2387\n", "7777\n", "3567\n", "5539\n", "8888\n", "4\n", "101\n", "6666\n", "3\n", "9999\n", "666\n", "5689\n", "23...
We consider a positive integer perfect, if and only if the sum of its digits is exactly 10. Given a positive integer k, your task is to find the k-th smallest perfect positive integer. Input A single line with a positive integer k (1 ≤ k ≤ 10 000). Output A single number, denoting the k-th smallest perfect integer....
{ "inputs": [ "20 5 2 20\n", "11 4 3 9\n", "32 90 31 32\n", "19 5 7 19\n", "29 5 12 27\n", "831447817 8377 549549158 577671489\n", "691 27 313 499\n", "8 3 1 1\n", "21 5 6 18\n", "410 36 109 191\n", "8 3 1 2\n", "7 3 1 5\n", "5 5 2 4\n", "8 3 5 6\n", "12 4 5...
Throughout Igor K.'s life he has had many situations worthy of attention. We remember the story with the virus, the story of his mathematical career and of course, his famous programming achievements. However, one does not always adopt new hobbies, one can quit something as well. This time Igor K. got disappointed in ...
{ "inputs": [ "2 2\n5 8\n", "1 2\n7 1\n", "1 4\n2 2 1 2\n", "1 2\n4 4\n", "1 4\n1 2 2 2\n", "8459 91\n778 338 725 1297 115 540 1452 2708 193 1806 1496 1326 2648 176 199 93 342 3901 2393 2718 800 3434 657 4037 291 690 1957 3280 73 6011 2791 1987 440 455 444 155 261 234 829 1309 1164 616 34 627 ...
Daenerys Targaryen has an army consisting of k groups of soldiers, the i-th group contains ai soldiers. She wants to bring her army to the other side of the sea to get the Iron Throne. She has recently bought an airplane to carry her army through the sea. The airplane has n rows, each of them has 8 seats. We call two s...
{ "inputs": [ "7\n1 2\n2 3\n3 1\n4 5\n5 6\n6 7\n", "2\n1 2\n", "4\n1 4\n3 1\n3 4\n", "5\n4 1\n4 3\n5 3\n2 4\n", "21\n7 15\n13 1\n14 3\n4 10\n2 3\n16 18\n17 20\n16 20\n8 4\n3 12\n2 17\n13 11\n16 1\n13 2\n13 5\n8 9\n6 14\n3 17\n16 9\n13 8\n", "3\n3 1\n3 2\n", "6\n5 2\n5 3\n1 4\n3 1\n5 6\n", ...
Berland Government decided to improve relations with neighboring countries. First of all, it was decided to build new roads so that from each city of Berland and neighboring countries it became possible to reach all the others. There are n cities in Berland and neighboring countries in total and exactly n - 1 two-way r...
{ "inputs": [ "10 3 409693891\n", "65 4 177545087\n", "5 2 433416647\n", "997 6 680633279\n", "989 8 990767311\n", "999 2 750160753\n", "1 4 904448911\n", "1000 3 750160753\n", "1000 6 970400047\n", "983 10 762763321\n", "106 9 434448163\n", "2 3 434448163\n", "102 ...
A tree is a connected graph without cycles. Two trees, consisting of n vertices each, are called isomorphic if there exists a permutation p: {1, ..., n} → {1, ..., n} such that the edge (u, v) is present in the first tree if and only if the edge (pu, pv) is present in the second tree. Vertex of the tree is called int...
{ "inputs": [ "5\n1 2\n1 3\n1 4\n1 5\n", "7\n7 2\n7 6\n1 2\n7 5\n4 7\n3 5\n", "3\n3 1\n2 1\n", "2\n2 1\n", "4\n1 3\n1 4\n4 2\n", "10\n1 2\n6 5\n2 7\n1 8\n2 10\n9 1\n3 2\n3 4\n5 1\n", "4\n1 2\n2 4\n2 3\n", "3\n3 1\n2 2\n", "4\n1 2\n2 4\n4 3\n", "4\n1 4\n2 4\n4 3\n", "4\n1 4\...
Vasya has a tree with n vertices numbered from 1 to n, and n - 1 edges numbered from 1 to n - 1. Initially each vertex contains a token with the number of the vertex written on it. Vasya plays a game. He considers all edges of the tree by increasing of their indices. For every edge he acts as follows: * If both end...
{ "inputs": [ "5\n1\n1\n2\n4 1\n3\n4 1 3\n4\n2 3 4 5\n5\n1 5 7 2 8\n", "20\n5\n4 3 2 8 1\n5\n3 2 5 1 4\n5\n5 4 2 3 1\n5\n3 1 5 9 2\n5\n4 6 2 1 3\n5\n3 5 4 2 1\n5\n5 3 7 2 1\n5\n2 5 4 1 7\n5\n6 1 3 2 7\n5\n1 5 6 2 3\n5\n1 8 6 2 4\n5\n8 1 2 7 5\n5\n3 1 2 7 5\n5\n6 2 8 3 1\n5\n2 5 1 8 3\n5\n5 3 4 1 2\n5\n5 1 2 4...
You are given a sequence b_1, b_2, …, b_n. Find the lexicographically minimal permutation a_1, a_2, …, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible. Input Each test contains one or more test cases. The first line contains the number of test cases t (1 ≤ t ≤ 100). The first line of...
{ "inputs": [ "1 1\n3 1\n3 3\n3 2\n3\n3 12\n9 3\n11 12\n8 7\n5\n15 3\n17 7\n22 5\n7 6\n4\n6 11\n8 2\n16 9\n10 8\n2\n0 0", "1 1\n3 1\n3 3\n3 2\n3\n3 12\n9 3\n11 12\n8 7\n5\n15 3\n17 7\n22 5\n7 6\n5\n6 11\n8 2\n16 9\n10 8\n2\n0 0", "2 1\n3 1\n3 3\n3 2\n3\n3 12\n9 3\n11 12\n8 7\n5\n15 3\n17 7\n22 5\n7 6\n5\n...
Create a program to determine the positional relationship between a triangle and a circle on a plane. All target figures shall include boundaries. The triangle is given the position of three vertices, and the circle is given the position of the center and the radius. The position is given by a set of two integers in a ...
{ "inputs": [ "4\n" ], "outputs": [ ".#.#\n#.#.\n.#.#\n#.#.\n" ] }
Chessboard is a board of n × n squares arranged in two alternating colors (black and white). Top left square is white. You are given board size n. Output an image of a chessboard, with black and white squares marked with '#' and '.' characters, respectively. Input The only line of input contains an integer n (1 ≤ n ≤...
{ "inputs": [ "4 2 3", "10 7 2", "1000 100 10", "15 7 2", "1000 101 10", "1100 101 10", "1100 111 10", "7 2 3", "20 7 2", "15 3 2", "1000 101 3", "1100 100 10", "1100 101 19", "7 1 3", "20 13 2", "17 3 2", "1000 111 3", "11 2 3", "20 8 2", ...
Snuke has a string x of length N. Initially, every character in x is `0`. Snuke can do the following two operations any number of times in any order: * Choose A consecutive characters in x and replace each of them with `0`. * Choose B consecutive characters in x and replace each of them with `1`. Find the number o...
{ "inputs": [ "6\n", "10\n", "999\n", "7725098\n", "3\n", "9140218\n", "9999999\n", "1\n", "2\n", "7003584\n", "7\n", "9\n", "8884001\n", "9670442\n", "9999\n", "100\n", "7767750\n", "8\n", "5\n", "99999\n", "100000\n", "999999\n"...
You are given a positive integer n. Let's build a graph on vertices 1, 2, ..., n in such a way that there is an edge between vertices u and v if and only if <image>. Let d(u, v) be the shortest distance between u and v, or 0 if there is no path between them. Compute the sum of values d(u, v) over all 1 ≤ u < v ≤ n. Th...
{ "inputs": [ "11 5\n1 1 3 3 3 4 2 7 7 6\n4 6\n4 8\n1 11\n9 11\n8 11\n", "5 4\n3 1 3 3\n4 5\n1 5\n1 2\n3 5\n", "16 4\n1 11 6 14 12 12 1 12 6 14 1 10 1 5 14\n5 7\n2 9\n6 9\n3 4\n", "2 1\n1\n1 2\n", "6 2\n1 2 1 2 4\n2 3\n1 4\n", "5 4\n3 1 3 3\n4 5\n1 5\n1 4\n3 5\n", "5 4\n3 1 3 4\n4 5\n1 5\n...
The company X has n employees numbered from 1 through n. Each employee u has a direct boss p_u (1 ≤ p_u ≤ n), except for the employee 1 who has no boss. It is guaranteed, that values p_i form a tree. Employee u is said to be in charge of employee v if u is the direct boss of v or there is an employee w such that w is i...
{ "inputs": [ "6 3\n2 6 1 10 3 2\n", "11 4\n1 0 1 0 0 4 4 2 4 3 3\n", "11 4\n1 0 1 0 0 4 4 2 4 3 3\n", "6 3\n2 6 1 10 3 2\n", "3 2\n10000 10000 10000\n", "102 7\n1459 8326 8870 2847 2774 3388 543 8688 1105 7926 857 412 6177 1883 4807 9996 7599 4095 6983 2462 8195 1560 954 7369 2160 8512 1209 8...
There are n friends living on a circular street. The friends and their houses are numbered clockwise from 0 to n-1. Initially person i has a_i stones. The friends want to make the distribution of stones among them perfectly balanced: everyone should possess the same number of stones. The only way to change the distri...
{ "inputs": [ "3\nhope\nelephant\npath", "2\nwall\nstep", "3\nhope\nelephaot\npath", "2\nllaw\nstep", "3\nhope\ntoagpele\npath", "3\nhope\nuoagpele\nhtbo", "3\nhope\nuoahpele\nhtbo", "3\nhnqe\nelephant\npbth", "3\ngopf\nuoagpelf\ngtob", "3\nhdpo\ndleqgaov\ndtip", "2\namlu\n...
Let's start from some definitions. Strings A and B are called anagrams if it's possible to rearrange the letters of string A using all the original letters exactly once and achieve string B; in other words A and B are permutations of each other. For example, remote and meteor are anagrams, race and race are anagrams a...
{ "inputs": [ "1 2 3 4 5 6\n2\n2 \n3\n\nSAMPLE" ], "outputs": [ "30\n54" ] }
You are given the following recurrences, F(n) = a * F(n - 1) * G(n - 2) + b * G(n - 1) * F(n - 2) for n ≥ 2 G(n) = c * G(n - 1) * F(n - 2) + d * (3 ^ F(n - 1) ) for n ≥2 H(n) = e * F(n) + f * G(n) for n ≥ 0 F[0] = F[1] = G[0] = 0 G[1] = 1 Input First line contains the following 6 numbers in order : a, b, c, d, ...
{ "inputs": [ "4\nCC..\nC..C\n.CC.\n.CC.\n", "3\n.CC\nC..\nC.C\n", "7\n.CC..CC\nCC.C..C\nC.C..C.\nC...C.C\nCCC.CCC\n.CC...C\n.C.CCC.\n", "3\nC..\nC..\nC..\n", "20\nC.C.CCC.C....C.CCCCC\nC.CC.C..CCC....CCCC.\n.CCC.CC...CC.CCCCCC.\n.C...CCCC..C....CCC.\n.C..CCCCCCC.C.C.....\nC....C.C..CCC.C..CCC\n.....
Door's family is going celebrate Famil Doors's birthday party. They love Famil Door so they are planning to make his birthday cake weird! The cake is a n × n square consisting of equal squares with side length 1. Each square is either empty or consists of a single chocolate. They bought the cake and randomly started t...
{ "inputs": [ "2\n6 12 10\n4 3 10\n", "4\n1 1 2\n9 36 2\n4 12 3\n3 5 4\n", "10\n10 8 5\n0 6 9\n0 7 6\n5 7 3\n7 6 8\n0 4 8\n2 6 3\n10 2 9\n6 7 9\n9 1 4\n", "1\n1 5244319080000 30030\n", "10\n10 5 3\n1 7 10\n7 5 7\n4 4 9\n6 5 2\n6 7 5\n9 9 7\n7 5 5\n6 6 4\n10 8 2\n", "1\n1 864691128455135232 2\n...
You are given several queries. Each query consists of three integers p, q and b. You need to answer whether the result of p/q in notation with base b is a finite fraction. A fraction in notation with base b is finite if it contains finite number of numerals after the decimal point. It is also possible that a fraction ...
{ "inputs": [ "2 1\n7 5\n7 6\n7 7\n76 5\n8 41\n0 0", "2 1\n7 6\n7 6\n7 7\n76 5\n8 41\n0 0", "1 1\n7 5\n7 6\n7 7\n76 5\n8 41\n0 0", "2 1\n7 6\n7 6\n7 7\n76 3\n8 41\n0 0", "2 1\n7 6\n7 6\n7 3\n76 3\n8 41\n0 0", "2 1\n7 6\n7 6\n7 3\n76 3\n11 41\n0 0", "2 1\n7 5\n14 6\n7 7\n76 5\n8 41\n0 0", ...
Koto Municipal Subway Koto Municipal Subway Koto City is a famous city whose roads are in a grid pattern, as shown in the figure below. The roads extending from north to south and the roads extending from east to west are lined up at intervals of 1 km each. Let Koto station at the southwestern intersection of Koto ci...
{ "inputs": [ "4 5 4\n4 4 5 1\n15\n9\n13\n6\n", "6 4 10\n3 1 1 1 2 2\n7\n8\n9\n10\n11\n12\n13\n14\n15\n16\n", "100 21 20\n11 17 21 14 7 15 18 6 17 11 21 3 17 21 21 7 21 17 14 21 14 14 3 6 18 21 17 17 18 14 14 21 15 13 3 15 11 11 16 11 6 10 15 17 11 15 13 13 21 16 21 13 11 14 21 21 13 18 16 3 21 16 13 16 1...
Misha was interested in water delivery from childhood. That's why his mother sent him to the annual Innovative Olympiad in Irrigation (IOI). Pupils from all Berland compete there demonstrating their skills in watering. It is extremely expensive to host such an olympiad, so after the first n olympiads the organizers int...
{ "inputs": [ "6\n4 2\nbbab\n7 5\ncceddda\n6 5\necdaed\n7 4\ndcdbdaa\n8 3\nccabbaca\n5 7\neabba\n", "6\n4 2\nbbab\n7 5\ncceddda\n6 5\necdaed\n7 8\ndcdbdaa\n8 3\nccabbaca\n5 7\neabba\n", "6\n4 2\nbbab\n7 5\ncceddda\n6 9\necdaed\n7 8\ndcdbdaa\n8 3\nccabbaca\n5 7\neabba\n", "6\n4 2\nbaab\n7 5\ncceddda\n6...
You are given a string s consisting of n characters. These characters are among the first k lowercase letters of the Latin alphabet. You have to perform n operations with the string. During the i-th operation, you take the character that initially occupied the i-th position, and perform one of the following actions wi...
{ "inputs": [ ".tweets.1\nname: shimeji\nid: shimejitan\ntweets:\n1: shimejilove\n2: azupero", ".no.such.property\nobject:\nprop1: str\nprop2: str", ".tweets.1\nname: shimeji\nid: shimejitan\ntweets:\n 1: shimejilove\n 2: azupero", ".my.obj\nmy:\nstr: string value\nobj:\na: a\nb: b\nc: c", ".a\n...
YAML (YAML Ain't Markup Language) is one of the formats for expressing an object as a character string. You will be given an object represented by a subset of YAML and a query that specifies the property, so please answer the value of the specified property. Subset of YAML A subset of YAML follows the syntax rules e...
{ "inputs": [ "3\n2 2 2 2 2 2 3 3 3 2 2 2 2 2 2 3 3 3 2 2 3 2 2 3 2 2\n", "400\n348 322 247 158 209 134 151 267 268 176 214 379 372 291 388 135 147 304 169 149 193 351 380 368 181 340\n", "4\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2\n", "200\n112 148 97 141 95 91 105 109 163 160 75 184 181 ...
You have c_1 letters 'a', c_2 letters 'b', ..., c_{26} letters 'z'. You want to build a beautiful string of length n from them (obviously, you cannot use the i-th letter more than c_i times). Each c_i is greater than n/3. A string is called beautiful if there are no palindromic contiguous substrings of odd length grea...
{ "inputs": [ "1\n0", "6\n1 0 2 3 0 4", "3\n1 0 1", "6\n1 0 2 3 0 6", "3\n2 0 1", "3\n1 1 1", "3\n0 0 0", "6\n1 0 2 5 0 6", "3\n3 0 1", "3\n1 0 2", "6\n0 0 2 3 0 6", "6\n1 0 2 0 0 6", "3\n1 0 3", "6\n-1 0 2 3 0 6", "1\n1", "3\n2 1 1", "3\n2 0 2", ...
Chef loves research! Now he is looking for subarray of maximal length with non-zero product. Chef has an array A with N elements: A1, A2, ..., AN. Subarray Aij of array A is elements from index i to index j: Ai, Ai+1, ..., Aj. Product of subarray Aij is product of all its elements (from ith to jth). Input First li...
{ "inputs": [ "3\nabcaa\n\nSAMPLE", "18\norfqxzjztvcgvzlcedwnezbwxmpobmrvxaskwvvwquudrnwhmmzheqxiwhfuxavlwftgyxxhpygspvwdnvmgnwnpkdrnznzvrkmjjmwisyrdkodoafwsjfuvmeewpdwpiymwbhoxebjibxphiefgtsawcdivtltrshjqnkkmdtjgscnozmojnhigippjemzzzbcvoyplxenffmfdzdiojuodgbulvivhtbhayeeebiactyaovqbivudydgxwsgmhlracaayipsojl...
Little Shino loves to play with coins. In the city she lives, there are 26 different types of coins. Each coin is represented with a lowercase letter a, b, c, ... , y, z. Shino has some number of coins and she placed them in some random sequence, S, on the table. She is wondering how many pairs (i, j) are there, where...
{ "inputs": [ "32\n22 31 30 29 7 17 16 3 14 9 19 11 2 5 10 1 25 18 15 24 20 0 12 21 27 4 26 28 8 6 23 13\n22 3 2 7 17 9 16 4 14 8 19 26 28 5 10 1 25 18 15 13 11 0 12 23 21 20 29 24 27 6 30 31", "4\n2 1 3 0\n0 2 3 1", "10\n0 4 5 3 7 8 2 1 9 6\n3 8 5 6 4 0 2 1 7 9", "4\n2 1 3 0\n2 0 3 1", "10\n0 4 5...
Snuke has permutations (P_0,P_1,\cdots,P_{N-1}) and (Q_0,Q_1,\cdots,Q_{N-1}) of (0,1,\cdots,N-1). Now, he will make new permutations A and B of (0,1,\cdots,N-1), under the following conditions: * For each i (0 \leq i \leq N-1), A_i should be i or P_i. * For each i (0 \leq i \leq N-1), B_i should be i or Q_i. Let u...
{ "inputs": [ "2 2\n2 1 2\n1 2 1\n", "4 1\n2 7\n7 2\n5 5\n6 4\n", "1 1\n1 1\n", "1 1\n1 1000\n", "1 1\n1000 1000\n", "1 1\n1000 1\n", "10 10\n7 5 5 5 9 10 9 8 7 5 10\n4 2 8 2 9 1 2 8 10 7 10\n9 7 7 2 5 1 5 4 7 9 7\n7 3 2 10 6 9 10 2 4 2 4\n1 4 8 6 9 2 1 3 6 2 8\n2 4 10 7 1 1 7 9 8 9 8\n8 3...
Due to atheistic Soviet past, Christmas wasn't officially celebrated in Russia for most of the twentieth century. As a result, the Russian traditions for Christmas and New Year mixed into one event celebrated on the New Year but including the tree, a Santa-like 'Grandfather Frost', presents and huge family reunions and...
{ "inputs": [ "1 0 0\n", "3 2 1\n", "1000000000000000000 0 1000000000000000000\n", "1 1 1\n", "1000000000000000000 1 1\n", "999999999999999999 999999999999999999 999999999999999999\n", "1 3 1\n", "0 1000 0\n", "117864695669097197 53280311324979856 171825292362519668\n", "999999...
Vasiliy spent his vacation in a sanatorium, came back and found that he completely forgot details of his vacation! Every day there was a breakfast, a dinner and a supper in a dining room of the sanatorium (of course, in this order). The only thing that Vasiliy has now is a card from the dining room contaning notes ho...
{ "inputs": [ "23 14567" ], "outputs": [ "12404\n" ] }
Sorry folks,, admin has no time to create a story for this problem... You have two integers n and m and you have to print value of factorial(n)%m. OUTPUT a single integer containing answer of problem. Input 23 14567 NOTE You do not need to create a program for this problem you have to write your answers of given in...
{ "inputs": [ "7 8\n0 2 3\n2 3 -20\n3 4 3\n4 1 -5\n1 5 1\n5 4 5\n1 3 2\n3 6 -2\n0 6 30\n7 8\n0 2 3\n2 3 -20\n3 4 3\n4 1 -5\n1 5 1\n5 4 5\n1 3 2\n3 6 -2\n0 6 20\n4 4\n0 1 -10\n1 2 -50\n2 1 51\n1 3 1\n0 3 20\n11 14\n0 1 -49\n1 2 1\n2 3 40\n3 1 -40\n1 4 -9\n4 5 40\n5 1 -30\n1 6 -19\n6 7 40\n7 1 -20\n1 8 -30\n8 9 40\...
Arthur C. Malory is a wandering valiant fighter (in a game world). One day, he visited a small village and stayed overnight. Next morning, the village mayor called on him. The mayor said a monster threatened the village and requested him to defeat it. He was so kind that he decided to help saving the village. The may...
{ "inputs": [ "5\n2 3 4 1 1\n2\n2 3\n", "2\n7 4\n1\n7\n", "1\n1\n3\n2 1 10\n", "3\n1 6 8\n1\n6\n", "1\n3\n1\n2\n", "1\n10\n5\n5 3 7 7 1\n", "2\n7 4\n1\n7\n", "5\n9 5 7 3 3\n1\n3\n", "2\n2 9\n5\n4 10 7 3 4\n", "1\n7\n4\n6 2 3 3\n", "4\n8 10 4 4\n3\n7 8 1\n", "5\n9 5 7 3 ...
There are n piles of stones of sizes a1, a2, ..., an lying on the table in front of you. During one move you can take one pile and add it to the other. As you add pile i to pile j, the size of pile j increases by the current size of pile i, and pile i stops existing. The cost of the adding operation equals the size of...
{ "inputs": [ "abcb\naacb\nbccc", "aca\naccc\nca", "abcb\naabb\nbccc", "caa\naccc\nca", "aaca\naabb\ncccc", "abcb\nbbaa\nbccc", "aacb\nbbaa\nbccc", "aacb\nbbaa\ncccb", "aaca\nbbaa\ncccb", "aaca\naabb\ncccb", "acaa\naabb\ncccc", "acaa\nabab\ncccc", "acaa\nabab\nbccc"...
Alice, Bob and Charlie are playing Card Game for Three, as below: * At first, each of the three players has a deck consisting of some number of cards. Each card has a letter `a`, `b` or `c` written on it. The orders of the cards in the decks cannot be rearranged. * The players take turns. Alice goes first. * If the cu...
{ "inputs": [ "3 4\n1 2 0\n1 3 1\n2 3 0\n2 3 1\n", "5 10\n1 2 0\n1 3 1\n1 4 0\n2 3 0\n2 3 1\n2 5 0\n3 4 0\n3 4 1\n4 2 1\n4 5 0\n", "4 8\n1 1 0\n1 3 0\n1 3 1\n3 2 0\n2 1 0\n3 4 1\n2 4 0\n2 4 1\n", "1 0\n", "10 40\n9 9 1\n4 10 0\n4 1 1\n6 4 1\n9 9 1\n6 4 1\n2 7 1\n3 7 1\n5 9 1\n1 9 0\n9 5 1\n1 3 0\n...
Egor is a famous Russian singer, rapper, actor and blogger, and finally he decided to give a concert in the sunny Republic of Dagestan. There are n cities in the republic, some of them are connected by m directed roads without any additional conditions. In other words, road system of Dagestan represents an arbitrary d...
{ "inputs": [ "0 1 0 0 0 0 0 0 1 1 1 2 3 4 5\n1\n13 16\n\nSAMPLE", "0 1 1 0 2 2 2 2 0 2 1 1 2 0 0\n1000\n620 999571\n626 999523\n738 999939\n1157 999335\n494 999039\n933 999280\n997 999727\n78 999899\n71 999243\n102 999229\n1042 999118\n1020 999961\n1232 999598\n63 999781\n75 999493\n935 999923\n272 999387\n1...
Traveling around the universe Benny saw some strange numbers. These numbers are called Universal numbers. Benny asks you to help her to calculate the number of Universal numbers on some segments. First of all, you are given 15 numbers called remsi. The number is Universal if and only if it satisfies the following c...
{ "inputs": [ "5 3\n4\n2\n5", "5 0\n4\n2\n5", "2 0\n4\n2\n6", "5 3\n5\n2\n5", "3 0\n4\n0\n6", "7 0\n3\n0\n6", "9 0\n3\n0\n6", "9 1\n4\n0\n6", "1 0\n10\n0\n0", "10 1\n4\n0\n6", "10 1\n8\n0\n6", "5 1\n4\n1\n5", "4 0\n4\n0\n6", "11 0\n3\n0\n6", "10 0\n4\n0\n0",...
Example Input 5 3 4 2 5 Output 5 2 4 1 3
{ "inputs": [ "3 2\n", "4 2\n", "1000000000000000000 42\n", "6 2\n", "288230376151711743 100\n", "1000000000000000000 99\n", "25 2\n", "2 5\n", "6 4\n", "1 5\n", "6 5\n", "1000000000000000000 3\n", "1000000000000000000 69\n", "7 4\n", "69 30\n", "1441151...
Reziba has many magic gems. Each magic gem can be split into M normal gems. The amount of space each magic (and normal) gem takes is 1 unit. A normal gem cannot be split. Reziba wants to choose a set of magic gems and split some of them, so the total space occupied by the resulting set of gems is N units. If a magic g...
{ "inputs": [ "4 2 100000007\n", "123456 26 330502547\n", "5 2 100000007\n", "6 3 100000007\n", "13131 14 625308461\n", "1312 25 425538233\n", "250000 26 419059819\n", "1 10 100000007\n", "249998 22 318340733\n", "250000 21 159237107\n", "232154 3 893627789\n", "250000 ...
Alice and Bob are playing a game with a string of characters, with Alice going first. The string consists n characters, each of which is one of the first k letters of the alphabet. On a player’s turn, they can either arbitrarily permute the characters in the words, or delete exactly one character in the word (if there ...
{ "inputs": [ "3\ngoogle\nbreakraekb\naman", "3\ngoogle\nbreakraekb\nnama", "3\ngoogle\nbreakraekb\naamn", "3\nelgoog\nbrebkrkeab\nbbmn", "3\nelgoog\nbrebkrleab\nbbmn", "3\ngooglf\nberbkslebb\nbmbn", "3\ngooglf\nbbelskbreb\nbmbn", "3\ngooglg\nbbelskbreb\nbmbn", "3\ngooglg\nbbblskeb...
Abhi and his friends (Shanky,Anku and Pandey) love to play with strings. Abhi invented a simple game. He will give a string S to his friends. Shanky and Anku will play the game while Pandey is just a spectator. Shanky will traverse the string from beginning (left to right) while Anku will traverse from last (right to l...
{ "inputs": [ "6\n2 2 1 2\n0 100 0 1\n12 13 25 1\n27 83 14 25\n0 0 1 0\n1000000000000000000 1000000000000000000 1000000000000000000 1000000000000000000\n", "1\n0 0 0 1\n", "1\n1 0 0 1\n", "6\n2 2 1 2\n0 100 0 1\n11 13 25 1\n27 83 14 25\n0 0 1 0\n1000000000000000000 1000000000000000000 1000000000000000...
Anna is a girl so brave that she is loved by everyone in the city and citizens love her cookies. She is planning to hold a party with cookies. Now she has a vanilla cookies and b chocolate cookies for the party. She invited n guests of the first type and m guests of the second type to the party. They will come to the ...
{ "inputs": [ "3\n0 2\n4 2\n2 0\n2 4\n1 0\n2 0\n4 0\n6 0\n1 6\n2 2\n2 5\n4 1\n", "1\n0 0\n5 5\n0 5\n5 0\n", "6\n41 77\n11 61\n31 38\n18 43\n41 77\n11 61\n18 43\n31 38\n41 77\n31 38\n11 61\n18 43\n41 77\n31 38\n18 43\n11 61\n41 77\n18 43\n11 61\n31 38\n41 77\n18 43\n31 38\n11 61\n", "1\n1 1\n1 0\n0 1\n...
You are given four different integer points p_1, p_2, p_3 and p_4 on XY grid. In one step you can choose one of the points p_i and move it in one of four directions by one. In other words, if you have chosen point p_i = (x, y) you can move it to (x, y + 1), (x, y - 1), (x + 1, y) or (x - 1, y). Your goal to move poin...
{ "inputs": [ "6 2\n5 5 6 8 3 12\n", "1 1\n5\n", "3 10\n1 100 1000\n", "5 300\n939 465 129 611 532\n", "5 1\n416 387 336 116 81\n", "2 1\n2 20\n", "3 2\n10 10 100\n", "1 1\n1\n", "3 10\n1 000 1000\n", "5 300\n939 465 246 611 532\n", "5 1\n416 387 230 116 81\n", "2 1\n0 ...
Carol is currently curling. She has n disks each with radius r on the 2D plane. Initially she has all these disks above the line y = 10100. She then will slide the disks towards the line y = 0 one by one in order from 1 to n. When she slides the i-th disk, she will place its center at the point (xi, 10100). She w...
{ "inputs": [ "2\n1 1 3 3\n1 1 3 3\n", "2\n1 1 2 3\n2 2 3 3\n", "5\n4 11 20 20\n6 11 20 16\n5 2 19 15\n11 3 18 15\n3 2 14 11\n", "1\n100 100 100 100\n", "1\n1 1 1 1\n", "5\n1 1 1 100\n1 1 1 100\n1 1 1 100\n1 1 1 100\n1 1 1 100\n", "1\n1 1 1 100\n", "3\n1 1 1 1\n1 2 1 2\n1 3 1 3\n", ...
Vanya has a table consisting of 100 rows, each row contains 100 cells. The rows are numbered by integers from 1 to 100 from bottom to top, the columns are numbered from 1 to 100 from left to right. In this table, Vanya chose n rectangles with sides that go along borders of squares (some rectangles probably occur mult...
{ "inputs": [ "5 14\n", "1 3\n", "88005553535 99999999999\n", "101 102\n", "707992299833239702 823650821768525121\n", "181925 50919323688216219\n", "31 32\n", "4 938109031727472839\n", "10 10005\n", "83 402908796418729484\n", "527941 442152825894997769\n", "100879890062...
Nazar, a student of the scientific lyceum of the Kingdom of Kremland, is known for his outstanding mathematical abilities. Today a math teacher gave him a very difficult task. Consider two infinite sets of numbers. The first set consists of odd positive numbers (1, 3, 5, 7, …), and the second set consists of even posi...
{ "inputs": [ "1000000", "15", "1100000", "16", "1110000", "23", "1110010", "3", "1111010", "1111110", "4", "8", "1", "7", "14", "19", "12", "0", "1000100", "18", "1101000", "39", "1010010", "1111111", "26", "11011...
Let us define the FizzBuzz sequence a_1,a_2,... as follows: * If both 3 and 5 divides i, a_i=\mbox{FizzBuzz}. * If the above does not hold but 3 divides i, a_i=\mbox{Fizz}. * If none of the above holds but 5 divides i, a_i=\mbox{Buzz}. * If none of the above holds, a_i=i. Find the sum of all numbers among the first...