source
int64
2
2
difficulty
int64
7
25
name
stringlengths
9
60
description
stringlengths
164
7.12k
public_tests
dict
private_tests
dict
cf_rating
int64
0
3.5k
cf_points
float64
0
4k
2
10
408_D. Long Path
One day, little Vasya found himself in a maze consisting of (n + 1) rooms, numbered from 1 to (n + 1). Initially, Vasya is at the first room and to get out of the maze, he needs to get to the (n + 1)-th one. The maze is organized as follows. Each room of the maze has two one-way portals. Let's consider room number i (...
{ "input": [ "2\n1 2\n", "5\n1 1 1 1 1\n", "4\n1 1 2 3\n" ], "output": [ "4\n", "62\n", "20\n" ] }
{ "input": [ "3\n1 1 3\n", "102\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n", "10\n1 1 3 2 2 1 3 4 7 5\n", "31\n1 1 1 1 1 1 1 1 1 1 1 1 1 1...
1,600
1,000
2
7
459_A. Pashmak and Garden
Pashmak has fallen in love with an attractive girl called Parmida since one year ago... Today, Pashmak set up a meeting with his partner in a romantic garden. Unfortunately, Pashmak has forgotten where the garden is. But he remembers that the garden looks like a square with sides parallel to the coordinate axes. He al...
{ "input": [ "0 0 1 2\n", "0 0 0 1\n", "0 0 1 1\n" ], "output": [ "-1\n", "1 0 1 1\n", "0 1 1 0\n" ] }
{ "input": [ "0 1 3 1\n", "66 -64 -25 -64\n", "100 100 100 -100\n", "-100 -100 100 100\n", "-1 1 1 -1\n", "0 1 1 0\n", "2 8 7 3\n", "1 3 3 1\n", "51 -36 18 83\n", "0 0 1 -1\n", "1 0 0 1\n", "6 85 -54 -84\n", "-42 84 -67 59\n", "5 6 8 3\n", "67 77 -11 -1\n", ...
1,200
500
2
11
47_E. Cannon
Bertown is under siege! The attackers have blocked all the ways out and their cannon is bombarding the city. Fortunately, Berland intelligence managed to intercept the enemies' shooting plan. Let's introduce the Cartesian system of coordinates, the origin of which coincides with the cannon's position, the Ox axis is di...
{ "input": [ "2 10\n0.7853\n0.3\n2\n4.0 2.4\n6.0 1.9\n", "2 10\n0.7853\n0.3\n3\n5.0 5.0\n4.0 2.4\n6.0 1.9\n" ], "output": [ "10.204081436 0.000000000\n4.000000000 0.378324889\n", "5.000000000 2.549499369\n4.000000000 0.378324889\n" ] }
{ "input": [ "6 417\n0.0303\n0.7536\n0.7225\n0.2404\n0.2432\n0.4583\n3\n979.9372 477.1436\n469.9804 408.1158\n923.2564 220.5522\n", "4 851\n0.3178\n0.5635\n0.1335\n0.5107\n4\n685.3785 249.6264\n681.8946 242.4571\n917.2937 600.3285\n150.5685 135.5137\n", "3 186\n0.4084\n0.4559\n0.1203\n3\n978.8435 234.6507...
2,200
2,500
2
7
554_A. Kyoya and Photobooks
Kyoya Ootori is selling photobooks of the Ouran High School Host Club. He has 26 photos, labeled "a" to "z", and he has compiled them into a photo booklet with some photos in some order (possibly with some photos being duplicated). A photo booklet can be described as a string of lowercase letters, consisting of the pho...
{ "input": [ "hi\n", "a\n" ], "output": [ "76\n", "51\n" ] }
{ "input": [ "lpfpndmjfvqejdgf\n", "jgv\n", "fykkiubdkt\n", "ydzpjhsidipricw\n", "gggggggggggggggggggg\n", "kgan\n", "lllllllllllllll\n", "e\n", "ofkvparuvjtggnmab\n", "zv\n", "xxncfutrtxcwdzwbgs\n", "kskkskkkssksssk\n", "coccoooogogcgocccmcg\n", "zsfo\n", "...
900
250
2
8
624_B. Making a String
You are given an alphabet consisting of n letters, your task is to make a string of the maximum possible length so that the following conditions are satisfied: * the i-th letter occurs in the string no more than ai times; * the number of occurrences of each letter in the string must be distinct for all the lette...
{ "input": [ "3\n2 5 5\n", "3\n1 1 2\n" ], "output": [ "11\n", "3\n" ] }
{ "input": [ "26\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000\n", "4...
1,100
1,000
2
10
672_D. Robin Hood
We all know the impressive story of Robin Hood. Robin Hood uses his archery skills and his wits to steal the money from rich, and return it to the poor. There are n citizens in Kekoland, each person has ci coins. Each day, Robin Hood will take exactly 1 coin from the richest person in the city and he will give it to t...
{ "input": [ "4 1\n1 1 4 2\n", "3 1\n2 2 2\n" ], "output": [ "2\n", "0\n" ] }
{ "input": [ "10 1000000\n307196 650096 355966 710719 99165 959865 500346 677478 614586 6538\n", "4 0\n1 4 4 4\n", "3 4\n1 2 7\n", "10 20\n6 4 7 10 4 5 5 3 7 10\n", "2 0\n182 2\n", "4 100\n1 1 10 10\n", "4 42\n1 1 1 1000000000\n", "123 54564\n38 44 41 42 59 3 95 15 45 32 44 69 35 83 94...
2,000
1,000
2
8
763_B. Timofey and rectangles
One of Timofey's birthday presents is a colourbook in a shape of an infinite plane. On the plane n rectangles with sides parallel to coordinate axes are situated. All sides of the rectangles have odd length. Rectangles cannot intersect, but they can touch each other. Help Timofey to color his rectangles in 4 different...
{ "input": [ "8\n0 0 5 3\n2 -1 5 0\n-3 -4 2 -1\n-1 -1 2 0\n-3 0 0 5\n5 2 10 3\n7 -3 10 2\n4 -2 7 -1\n" ], "output": [ "YES\n1\n2\n3\n4\n3\n3\n4\n1\n" ] }
{ "input": [ "25\n0 0 7 7\n0 18 7 29\n7 36 12 41\n7 18 12 29\n15 29 26 36\n7 7 12 18\n12 36 15 41\n15 7 26 18\n12 0 15 7\n12 7 15 18\n7 29 12 36\n12 29 15 36\n15 18 26 29\n26 18 27 29\n12 18 15 29\n26 29 27 36\n0 7 7 18\n26 0 27 7\n7 0 12 7\n15 36 26 41\n26 7 27 18\n26 36 27 41\n15 0 26 7\n0 36 7 41\n0 29 7 36\n"...
2,100
750
2
9
808_C. Tea Party
Polycarp invited all his friends to the tea party to celebrate the holiday. He has n cups, one for each of his n friends, with volumes a1, a2, ..., an. His teapot stores w milliliters of tea (w ≤ a1 + a2 + ... + an). Polycarp wants to pour tea in cups in such a way that: * Every cup will contain tea for at least hal...
{ "input": [ "2 10\n8 7\n", "3 10\n9 8 10\n", "4 4\n1 1 1 1\n" ], "output": [ "6 4 ", "-1\n", "1 1 1 1 " ] }
{ "input": [ "50 1113\n25 21 23 37 28 23 19 25 5 12 3 11 46 50 13 50 7 1 8 40 4 6 34 27 11 39 45 31 10 12 48 2 19 37 47 45 30 24 21 42 36 14 31 30 31 50 6 3 33 49\n", "11 287\n34 30 69 86 22 53 11 91 62 44 5\n", "10 21\n3 3 3 3 4 3 3 3 3 3\n", "71 1899\n23 55 58 87 69 85 100 21 19 72 81 68 20 25 29 92...
1,400
0
2
10
832_D. Misha, Grisha and Underground
Misha and Grisha are funny boys, so they like to use new underground. The underground has n stations connected with n - 1 routes so that each route connects two stations, and it is possible to reach every station from any other. The boys decided to have fun and came up with a plan. Namely, in some day in the morning M...
{ "input": [ "3 2\n1 1\n1 2 3\n2 3 3\n", "4 1\n1 2 3\n1 2 3\n" ], "output": [ "2\n3\n", "2\n" ] }
{ "input": [ "5 20\n5 5 1 4\n1 4 3\n2 4 1\n1 5 5\n5 1 4\n5 1 5\n1 5 5\n5 4 4\n2 3 3\n4 4 1\n1 4 1\n4 5 4\n1 4 5\n4 1 5\n2 4 2\n4 3 3\n2 5 5\n1 5 4\n3 3 4\n5 5 1\n3 4 1\n", "2 4\n1\n1 1 1\n1 1 2\n1 2 2\n2 2 2\n", "5 20\n4 1 1 4\n2 2 5\n3 2 5\n2 3 4\n4 2 5\n4 1 2\n5 3 1\n2 1 2\n4 3 2\n1 3 3\n4 2 5\n5 1 4\n4...
1,900
2,000
2
8
853_B. Jury Meeting
Country of Metropolia is holding Olympiad of Metrpolises soon. It mean that all jury members of the olympiad should meet together in Metropolis (the capital of the country) for the problem preparation process. There are n + 1 cities consecutively numbered from 0 to n. City 0 is Metropolis that is the meeting point for...
{ "input": [ "2 4 5\n1 2 0 5000\n2 1 0 4500\n2 1 0 3000\n8 0 1 6000\n", "2 6 5\n1 1 0 5000\n3 2 0 5500\n2 2 0 6000\n15 0 2 9000\n9 0 1 7000\n8 0 2 6500\n" ], "output": [ "-1", " 24500\n" ] }
{ "input": [ "7 10 1\n369 6 0 9\n86 7 0 9\n696 0 4 8\n953 6 0 7\n280 4 0 9\n244 0 2 9\n645 6 0 8\n598 7 0 6\n598 0 7 8\n358 0 4 6\n", "2 5 5\n1 1 0 1\n2 2 0 100\n3 2 0 10\n9 0 1 1000\n10 0 2 10000\n", "1 10 1\n278 1 0 4\n208 1 0 4\n102 0 1 9\n499 0 1 7\n159 0 1 8\n218 1 0 6\n655 0 1 5\n532 1 0 6\n318 0 1 ...
1,800
750
2
12
877_F. Ann and Books
In Ann's favorite book shop are as many as n books on math and economics. Books are numbered from 1 to n. Each of them contains non-negative number of problems. Today there is a sale: any subsegment of a segment from l to r can be bought at a fixed price. Ann decided that she wants to buy such non-empty subsegment t...
{ "input": [ "4 1\n1 1 1 2\n1 1 1 1\n4\n1 2\n1 3\n1 4\n3 4\n", "4 0\n1 2 1 2\n0 0 0 0\n1\n1 4\n" ], "output": [ "2\n3\n4\n1\n", "10\n" ] }
{ "input": [ "2 0\n1 2\n43 43\n3\n1 2\n2 2\n1 1\n", "10 -10\n1 2 1 2 1 1 2 2 2 1\n7 7 10 3 7 10 6 8 0 1\n10\n2 6\n10 10\n6 9\n5 8\n7 10\n2 7\n2 9\n2 7\n5 6\n2 8\n", "10 10\n1 1 1 1 1 2 1 2 1 2\n7 10 2 5 0 1 8 10 1 8\n10\n4 5\n1 3\n6 7\n8 10\n5 10\n1 8\n5 6\n1 5\n2 8\n9 10\n", "10 10\n2 1 1 1 1 1 1 1 1...
2,300
2,750
2
8
901_B. GCD of Polynomials
Suppose you have two polynomials <image> and <image>. Then polynomial <image> can be uniquely represented in the following way: <image> This can be done using [long division](https://en.wikipedia.org/wiki/Polynomial_long_division). Here, <image> denotes the degree of polynomial P(x). <image> is called the remainder o...
{ "input": [ "1\n", "2\n" ], "output": [ "1\n0 1\n0\n1\n", "2\n1 0 1\n1\n0 1\n" ] }
{ "input": [ "70\n", "64\n", "102\n", "141\n", "43\n", "36\n", "91\n", "50\n", "77\n", "135\n", "44\n", "59\n", "20\n", "14\n", "57\n", "34\n", "13\n", "118\n", "101\n", "96\n", "6\n", "72\n", "84\n", "133\n", "11\n", ...
2,200
1,000
2
7
952_A. Quirky Quantifiers
Input The input contains a single integer a (10 ≤ a ≤ 999). Output Output 0 or 1. Examples Input 13 Output 1 Input 927 Output 1 Input 48 Output 0
{ "input": [ "13\n", "48\n", "927\n" ], "output": [ "1\n", "0\n", "1\n" ] }
{ "input": [ "758\n", "496\n", "957\n", "835\n", "932\n", "572\n", "329\n", "694\n", "207\n", "429\n", "583\n", "309\n", "636\n", "470\n", "168\n", "550\n", "10\n", "990\n", "999\n", "288\n", "431\n", "174\n", "846\n", "14...
800
0
2
9
979_C. Kuro and Walking Route
Kuro is living in a country called Uberland, consisting of n towns, numbered from 1 to n, and n - 1 bidirectional roads connecting these towns. It is possible to reach each town from any other. Each road connects two towns a and b. Kuro loves walking and he is planning to take a walking marathon, in which he will choos...
{ "input": [ "3 1 3\n1 2\n2 3\n", "3 1 3\n1 2\n1 3\n" ], "output": [ "5\n", "4\n" ] }
{ "input": [ "31 29 20\n29 23\n29 18\n22 14\n29 20\n1 21\n29 10\n28 2\n1 17\n17 15\n1 11\n29 31\n28 6\n12 29\n12 26\n1 13\n22 4\n29 25\n28 22\n17 5\n28 30\n20 27\n29 8\n12 28\n1 12\n12 24\n22 7\n12 16\n12 3\n28 9\n1 19\n", "8 5 1\n5 8\n1 5\n1 3\n1 4\n5 6\n6 7\n1 2\n", "13 5 13\n2 5\n5 8\n1 2\n13 7\n2 3\n1...
1,600
1,250
2
10
999_D. Equalize the Remainders
You are given an array consisting of n integers a_1, a_2, ..., a_n, and a positive integer m. It is guaranteed that m is a divisor of n. In a single move, you can choose any position i between 1 and n and increase a_i by 1. Let's calculate c_r (0 ≤ r ≤ m-1) — the number of elements having remainder r when divided by ...
{ "input": [ "4 2\n0 1 2 3\n", "6 3\n3 2 0 6 10 12\n" ], "output": [ "0\n0 1 2 3 \n", "3\n3 2 0 7 10 14 " ] }
{ "input": [ "100 25\n6745 2075 7499 7517 1776 5164 2335 2745 4465 1457 7565 2232 2486 9025 8059 9646 8017 7662 9690 3352 2306 366 7422 1073 7169 8966 4506 8225 5614 8628 2908 7452 9625 9332 7097 353 1043 8118 5794 4486 626 971 6731 6618 887 6354 4814 7307 7681 6160 9351 2579 411 3436 5570 2812 2726 4433 3220 577...
1,900
0
2
10
1004_D. Sonya and Matrix
Since Sonya has just learned the basics of matrices, she decided to play with them a little bit. Sonya imagined a new type of matrices that she called rhombic matrices. These matrices have exactly one zero, while all other cells have the Manhattan distance to the cell containing the zero. The cells with equal numbers ...
{ "input": [ "20\n1 0 2 3 5 3 2 1 3 2 3 1 4 2 1 4 2 3 2 4\n", "6\n2 1 0 2 1 2\n", "18\n2 2 3 2 4 3 3 3 0 2 4 2 1 3 2 1 1 1\n" ], "output": [ "4 5\n2 2\n", "-1\n", "3 6\n2 3\n" ] }
{ "input": [ "1\n0\n", "6\n0 0 0 0 0 0\n", "7\n0 1 2 3 4 2 6\n", "4\n0 0 0 0\n" ], "output": [ "1 1\n1 1\n", "-1\n", "-1\n", "-1\n" ] }
2,300
2,000
2
10
1028_D. Order book
Let's consider a simplified version of order book of some stock. The order book is a list of orders (offers) from people that want to buy or sell one unit of the stock, each order is described by direction (BUY or SELL) and price. At every moment of time, every SELL offer has higher price than every BUY offer. In th...
{ "input": [ "6\nADD 1\nACCEPT 1\nADD 2\nACCEPT 2\nADD 3\nACCEPT 3\n", "4\nADD 1\nADD 2\nADD 3\nACCEPT 2\n", "7\nADD 1\nADD 2\nADD 3\nADD 4\nADD 5\nACCEPT 3\nACCEPT 5\n" ], "output": [ "8", "2", "0" ] }
{ "input": [ "6\nADD 10\nADD 7\nADD 13\nADD 15\nADD 12\nACCEPT 10\n", "8\nADD 10\nADD 7\nADD 13\nADD 15\nADD 12\nACCEPT 10\nADD 11\nADD 8\n", "12\nADD 85752704\nACCEPT 85752704\nADD 82888551\nADD 31364670\nACCEPT 82888551\nADD 95416363\nADD 27575237\nADD 47306380\nACCEPT 31364670\nACCEPT 47306380\nADD 223...
2,100
2,000
2
10
1092_D2. Great Vova Wall (Version 2)
Vova's family is building the Great Vova Wall (named by Vova himself). Vova's parents, grandparents, grand-grandparents contributed to it. Now it's totally up to Vova to put the finishing touches. The current state of the wall can be respresented by a sequence a of n integers, with a_i being the height of the i-th par...
{ "input": [ "2\n10 10\n", "3\n4 5 3\n", "5\n2 1 1 2 5\n" ], "output": [ "YES\n", "NO\n", "YES\n" ] }
{ "input": [ "1\n1\n", "3\n2 2 1\n", "13\n5 2 2 1 1 2 5 2 1 1 2 2 5\n", "7\n2 2 2 2 2 2 1\n", "4\n4 3 2 1\n", "7\n4 1 1 2 4 3 3\n", "2\n1 2\n", "5\n4 3 3 4 1\n", "20\n10 5 2 3 5 7 7 9 4 9 9 4 9 7 7 5 3 2 5 10\n", "6\n3 2 3 3 2 3\n", "4\n10 10 40 60\n", "10\n1 9 7 6 2 4 ...
2,200
0
2
9
1111_C. Creative Snap
Thanos wants to destroy the avengers base, but he needs to destroy the avengers along with their base. Let we represent their base with an array, where each position can be occupied by many avengers, but one avenger can occupy only one position. Length of their base is a perfect power of 2. Thanos wants to destroy the...
{ "input": [ "3 2 1 2\n1 7\n", "2 2 1 2\n1 3\n" ], "output": [ "8", "6" ] }
{ "input": [ "3 2 5 1\n7 8\n", "3 3 10000 5\n1 4 5\n", "5 3 10000 3241\n5 12 2\n", "5 1 34 241\n22\n", "3 3 5 10000\n1 4 5\n", "3 2 7 1\n7 8\n", "5 3 3521 10000\n5 12 2\n", "1 1 5 6\n1\n" ], "output": [ "12", "40", "58892", "411", "30020", "15", "58168",...
1,700
1,500
2
7
1141_A. Game 23
Polycarp plays "Game 23". Initially he has a number n and his goal is to transform it to m. In one move, he can multiply n by 2 or multiply n by 3. He can perform any number of moves. Print the number of moves needed to transform n to m. Print -1 if it is impossible to do so. It is easy to prove that any way to trans...
{ "input": [ "42 42\n", "48 72\n", "120 51840\n" ], "output": [ "0\n", "-1\n", "7\n" ] }
{ "input": [ "1 223092870\n", "18782 37565\n", "1001 1001\n", "5 7\n", "50 64800\n", "10 24\n", "139999978 419999934\n", "12 26\n", "10001 10001\n", "1 7\n", "1 512\n", "6 20\n", "1 2\n", "300000007 300000007\n", "6 21\n", "4 9\n", "203 203\n", "...
1,000
0
2
7
1260_A. Heating
Several days ago you bought a new house and now you are planning to start a renovation. Since winters in your region can be very cold you need to decide how to heat rooms in your house. Your house has n rooms. In the i-th room you can install at most c_i heating radiators. Each radiator can have several sections, but ...
{ "input": [ "4\n1 10000\n10000 1\n2 6\n4 6\n" ], "output": [ "100000000\n1\n18\n10\n" ] }
{ "input": [ "69\n2 6\n2 6\n2 6\n2 6\n2 6\n2 6\n2 6\n2 6\n2 6\n2 6\n2 6\n2 6\n2 6\n2 6\n2 6\n2 6\n2 6\n2 6\n2 6\n2 6\n2 6\n2 6\n2 6\n2 6\n2 6\n2 6\n2 6\n2 6\n2 6\n2 6\n2 6\n2 6\n2 6\n2 6\n2 6\n2 6\n2 6\n2 6\n2 6\n2 6\n2 6\n2 6\n2 6\n2 6\n2 6\n2 6\n2 6\n2 6\n2 6\n2 6\n2 6\n2 6\n2 6\n2 6\n2 6\n2 6\n2 6\n2 6\n2 6\n2...
1,000
0
2
8
1282_B1. K for the Price of One (Easy Version)
This is the easy version of this problem. The only difference is the constraint on k — the number of gifts in the offer. In this version: k=2. Vasya came to the store to buy goods for his friends for the New Year. It turned out that he was very lucky — today the offer "k of goods for the price of one" is held in store...
{ "input": [ "6\n5 6 2\n2 4 3 5 7\n5 11 2\n2 4 3 5 7\n2 10000 2\n10000 10000\n2 9999 2\n10000 10000\n5 13 2\n8 2 8 2 5\n3 18 2\n1 2 3\n" ], "output": [ "3\n4\n2\n0\n4\n3\n" ] }
{ "input": [ "8\n5 6 2\n2 4 3 5 7\n5 11 2\n2 4 3 5 7\n3 2 3\n4 2 6\n5 2 3\n10 1 3 9 2\n2 10000 2\n10000 10000\n2 9999 2\n10000 10000\n4 6 4\n3 2 3 2\n5 5 3\n1 2 2 1 2\n", "2\n2 1 2\n1 1\n2 2000000000 2\n1 1\n" ], "output": [ "3\n4\n1\n1\n2\n0\n4\n5\n", "2\n2\n" ] }
1,400
500
2
8
1326_B. Maximums
Alicia has an array, a_1, a_2, …, a_n, of non-negative integers. For each 1 ≤ i ≤ n, she has found a non-negative integer x_i = max(0, a_1, …, a_{i-1}). Note that for i=1, x_i = 0. For example, if Alicia had the array a = \{0, 1, 2, 0, 3\}, then x = \{0, 0, 1, 2, 2\}. Then, she calculated an array, b_1, b_2, …, b_n: ...
{ "input": [ "3\n1000 999999000 -1000000000\n", "5\n2 1 2 2 3\n", "5\n0 1 1 -2 1\n" ], "output": [ "1000 1000000000 0\n", "2 3 5 7 10\n", "0 1 2 0 3\n" ] }
{ "input": [ "35\n15 13 -19 -7 -28 -16 4 -10 2 -23 -6 -5 -26 -27 -24 -27 -22 1 -32 -19 -16 -15 -29 -26 -25 -17 -11 -20 -2 -11 -20 -30 -1 -7 -27\n", "3\n0 0 0\n", "3\n8 -1 0\n", "10\n10 555 394 -927 -482 18 -196 -464 -180 -98\n" ], "output": [ "15 28 9 21 0 12 32 22 34 11 28 29 8 7 10 7 12 35 3...
900
1,000
2
13
1408_G. Clusterization Counting
There are n computers in the company network. They are numbered from 1 to n. For each pair of two computers 1 ≤ i < j ≤ n you know the value a_{i,j}: the difficulty of sending data between computers i and j. All values a_{i,j} for i<j are different. You want to separate all computers into k sets A_1, A_2, …, A_k, suc...
{ "input": [ "7\n0 1 18 15 19 12 21\n1 0 16 13 17 20 14\n18 16 0 2 7 10 9\n15 13 2 0 6 8 11\n19 17 7 6 0 4 5\n12 20 10 8 4 0 3\n21 14 9 11 5 3 0\n", "4\n0 3 4 6\n3 0 2 1\n4 2 0 5\n6 1 5 0\n" ], "output": [ "1 1 2 3 4 3 1 \n", "1 0 1 1 \n" ] }
{ "input": [ "1\n0\n", "4\n0 1 2 3\n1 0 4 5\n2 4 0 6\n3 5 6 0\n", "7\n0 21 9 3 6 13 16\n21 0 11 2 14 4 18\n9 11 0 19 7 17 15\n3 2 19 0 20 8 12\n6 14 7 20 0 5 10\n13 4 17 8 5 0 1\n16 18 15 12 10 1 0\n", "2\n0 1\n1 0\n", "6\n0 12 13 2 5 11\n12 0 15 10 1 14\n13 15 0 6 8 9\n2 10 6 0 7 4\n5 1 8 7 0 3\n...
2,700
3,000
2
7
142_A. Help Farmer
Once upon a time in the Kingdom of Far Far Away lived Sam the Farmer. Sam had a cow named Dawn and he was deeply attached to her. Sam would spend the whole summer stocking hay to feed Dawn in winter. Sam scythed hay and put it into haystack. As Sam was a bright farmer, he tried to make the process of storing hay simple...
{ "input": [ "12\n", "4\n", "7\n" ], "output": [ "48 105\n", "28 41\n", "47 65\n" ] }
{ "input": [ "999999993\n", "257259713\n", "857656800\n", "573308928\n", "286736327\n", "999893387\n", "50480\n", "644972544\n", "999942949\n", "679477248\n", "4472\n", "99264891\n", "931170240\n", "821620800\n", "509607936\n", "778377600\n", "659274...
1,600
500
2
11
1452_E. Two Editorials
Berland regional ICPC contest has just ended. There were m participants numbered from 1 to m, who competed on a problemset of n problems numbered from 1 to n. Now the editorial is about to take place. There are two problem authors, each of them is going to tell the tutorial to exactly k consecutive tasks of the proble...
{ "input": [ "10 5 3\n1 3\n2 4\n6 9\n6 9\n1 8\n", "4 4 1\n3 3\n1 1\n2 2\n4 4\n", "5 4 5\n1 2\n2 3\n3 4\n4 5\n", "10 3 3\n2 4\n4 6\n3 5\n" ], "output": [ "\n14\n", "\n2\n", "\n8\n", "\n8\n" ] }
{ "input": [ "3 2 1\n1 1\n2 2\n", "1 5 1\n1 1\n1 1\n1 1\n1 1\n1 1\n", "1 6 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n", "2 9 1\n1 1\n2 2\n1 1\n1 2\n1 1\n2 2\n2 2\n1 2\n2 2\n", "2 5 1\n1 2\n1 1\n2 2\n1 2\n1 2\n", "1 2 1\n1 1\n1 1\n", "5 6 2\n1 1\n1 1\n1 1\n1 1\n1 1\n1 5\n", "1 9 1\n1 1\n1 1\n1 1...
2,500
0
2
10
1526_D. Kill Anton
After rejecting 10^{100} data structure problems, Errorgorn is very angry at Anton and decided to kill him. Anton's DNA can be represented as a string a which only contains the characters "ANTON" (there are only 4 distinct characters). Errorgorn can change Anton's DNA into string b which must be a permutation of a. ...
{ "input": [ "4\nANTON\nNAAN\nAAAAAA\nOAANTTON\n" ], "output": [ "\nNNOTA\nAANN\nAAAAAA\nTNNTAOOA\n" ] }
{ "input": [ "1\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\n", "4\nANTON\nNAAN\nAAAAAA\nOAANTTON\n" ], "output": [ "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\n", "NNOTA\nAANN\nAAAAAA\nNNOOTTAA\n" ] }
2,200
2,250
2
8
158_B. Taxi
After the lessons n groups of schoolchildren went outside and decided to visit Polycarpus to celebrate his birthday. We know that the i-th group consists of si friends (1 ≤ si ≤ 4), and they want to go to Polycarpus together. They decided to get there by taxi. Each car can carry at most four passengers. What minimum nu...
{ "input": [ "5\n1 2 4 3 3\n", "8\n2 3 4 4 2 1 3 1\n" ], "output": [ "4\n", "5\n" ] }
{ "input": [ "5\n4 4 4 4 4\n", "3\n3 4 3\n", "2\n2 1\n", "78\n2 2 2 2 3 3 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 2 2 2 2 2 1 2 2 3 2 2 2 2 2 2 2 1 1 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2\n", "7\n2 2 2 1 2 1 2\n", "3\n2 4 2\n", "3\n2 1 4\n", "10\n3 1 2 2 2...
1,100
1,000
2
9
1_C. Ancient Berland Circus
Nowadays all circuses in Berland have a round arena with diameter 13 meters, but in the past things were different. In Ancient Berland arenas in circuses were shaped as a regular (equiangular) polygon, the size and the number of angles could vary from one circus to another. In each corner of the arena there was a spec...
{ "input": [ "0.000000 0.000000\n1.000000 1.000000\n0.000000 1.000000\n" ], "output": [ "1.0\n" ] }
{ "input": [ "76.820252 66.709341\n61.392328 82.684207\n44.267775 -2.378694\n", "6.949504 69.606390\n26.139268 72.136945\n24.032442 57.407195\n", "36.856072 121.845502\n46.453956 109.898647\n-30.047767 77.590282\n", "-7.347450 36.971423\n84.498728 89.423536\n75.469963 98.022482\n", "88.653021 18.0...
2,100
0
2
10
224_D. Two Strings
A subsequence of length |x| of string s = s1s2... s|s| (where |s| is the length of string s) is a string x = sk1sk2... sk|x| (1 ≤ k1 < k2 < ... < k|x| ≤ |s|). You've got two strings — s and t. Let's consider all subsequences of string s, coinciding with string t. Is it true that each character of string s occurs in at...
{ "input": [ "abc\nba\n", "abacaba\naba\n", "abab\nab\n" ], "output": [ "No\n", "No\n", "Yes\n" ] }
{ "input": [ "babaabaabb\nbbccb\n", "aaaaaa\naaaaaaa\n", "abcdadbcd\nabcd\n", "abaaaaba\nabba\n", "aa\naaa\n", "iqqiaiiffiqlqfaaflfieflfillkkhqfolhehedqdqqfddlheifeoqeohhoadqkfiqeleeqdekhhahkaqqqiaqliiqlelkhdfodeafqfhogihlgoqafdiffkaekhqhgqfkcqiaaoodkkfeqkciqfeihkifeodhahdhddghaihkhahghlkcckic...
1,900
1,000
2
8
249_B. Sweets for Everyone!
For he knew every Who down in Whoville beneath, Was busy now, hanging a mistletoe wreath. "And they're hanging their stockings!" he snarled with a sneer, "Tomorrow is Christmas! It's practically here!" Dr. Suess, How The Grinch Stole Christmas Christmas celebrations are coming to Whoville. Cindy Lou Who and her paren...
{ "input": [ "23 50\nHHSS.......SSHHHHHHHHHH\n", "14 100\n...HHHSSS...SH\n", "6 6\nHSHSHS\n" ], "output": [ "8\n", "0\n", "1\n" ] }
{ "input": [ "336 400\nHSSHHSSHHS..S..SS..H.S.H..SSH.H.H.H.S.H.S.S.H.S..SS..H.SS.H.SS.SS..SS.H...H.H.H.HSS..H...SS..SS.H..H.S.S....S.H.SS..HS..S.S.S.H.H.S..S.H.SS.SS..SS.SS.HS.SS.HSSSSHSSSSSS.H.SS..HHH.H.H.S..H.SS.S.H..SS.HS.SS.S.H.H.H..H.SS.HS.HHHSS.SS.S.SSS.S.S.SS.HS.H.S.SS.H.SS.H.S.SS.HS.SS..SS.H.S.H.SSH.HSSS....
2,300
2,000
2
11
296_E. Greg and Friends
One day Greg and his friends were walking in the forest. Overall there were n people walking, including Greg. Soon he found himself in front of a river. The guys immediately decided to get across the river. Luckily, there was a boat by the river bank, just where the guys were standing. We know that the boat can hold pe...
{ "input": [ "1 50\n50\n", "3 100\n50 50 100\n", "2 50\n50 50\n" ], "output": [ "1\n1", "5\n2", "-1\n0" ] }
{ "input": [ "1 204\n50\n", "5 123\n50 100 50 50 50\n", "3 99\n100 50 50\n", "32 121\n100 100 100 100 100 50 100 100 50 100 50 100 50 100 50 100 50 50 50 100 100 50 100 100 100 100 50 100 50 100 100 50\n", "23 100\n50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50\n", "41 21...
2,100
1,500
2
9
31_C. Schedule
At the beginning of the new semester there is new schedule in the Berland State University. According to this schedule, n groups have lessons at the room 31. For each group the starting time of the lesson and the finishing time of the lesson are known. It has turned out that it is impossible to hold all lessons, becaus...
{ "input": [ "3\n1 5\n2 6\n3 7\n", "4\n3 10\n20 30\n1 3\n1 39\n", "3\n3 10\n20 30\n1 3\n" ], "output": [ "0\n", "1\n4 ", "3\n1 2 3 " ] }
{ "input": [ "4\n1 5\n5 7\n6 9\n9 10\n", "16\n203671 381501\n58867 59732\n817520 962123\n125391 163027\n601766 617692\n381501 444610\n761937 817520\n16 10551\n21096 38291\n718073 761937\n583868 601766\n554859 731755\n678098 718073\n962123 992003\n163027 203671\n87917 96397\n", "11\n717170 795210\n866429 9...
1,700
1,500
2
9
344_C. Rational Resistance
Mad scientist Mike is building a time machine in his spare time. To finish the work, he needs a resistor with a certain resistance value. However, all Mike has is lots of identical resistors with unit resistance R0 = 1. Elements with other resistance can be constructed from these resistors. In this problem, we will co...
{ "input": [ "1 1\n", "199 200\n", "3 2\n" ], "output": [ "1\n", "200\n", "3\n" ] }
{ "input": [ "36 316049483082136289\n", "1 923438\n", "999999999999999999 2\n", "2 999999999999999999\n", "3 1000000000000000000\n", "60236007668635342 110624799949034113\n", "4 5\n", "288565475053 662099878640\n", "8944394323791464 5527939700884757\n", "4052739537881 655747031...
1,600
500
2
7
390_A. Inna and Alarm Clock
Inna loves sleeping very much, so she needs n alarm clocks in total to wake up. Let's suppose that Inna's room is a 100 × 100 square with the lower left corner at point (0, 0) and with the upper right corner at point (100, 100). Then the alarm clocks are points with integer coordinates in this square. The morning has ...
{ "input": [ "4\n0 0\n0 1\n1 0\n1 1\n", "4\n0 0\n0 1\n0 2\n1 0\n", "4\n1 1\n1 2\n2 3\n3 3\n" ], "output": [ "2", "2", "3" ] }
{ "input": [ "42\n28 87\n26 16\n59 90\n47 61\n28 83\n36 30\n67 10\n6 95\n9 49\n86 94\n52 24\n74 9\n86 24\n28 51\n25 99\n40 98\n57 33\n18 96\n43 36\n3 79\n4 86\n38 61\n25 61\n6 100\n58 81\n28 19\n64 4\n3 40\n2 56\n41 49\n97 100\n86 34\n42 36\n44 40\n14 85\n21 60\n76 99\n64 47\n69 13\n49 37\n97 37\n3 70\n", "1\...
0
500
2
9
411_C. Kicker
Kicker (table football) is a board game based on football, in which players control the footballers' figures mounted on rods by using bars to get the ball into the opponent's goal. When playing two on two, one player of each team controls the goalkeeper and the full-backs (plays defence), the other player controls the ...
{ "input": [ "1 1\n2 2\n3 3\n2 2\n", "3 3\n2 2\n1 1\n2 2\n", "1 100\n100 1\n99 99\n99 99\n" ], "output": [ "Team 2\n", "Draw\n", "Team 1\n" ] }
{ "input": [ "21 22\n21 16\n32 14\n39 35\n", "12 29\n44 8\n18 27\n43 19\n", "10 3\n2 5\n1 10\n2 10\n", "14 47\n47 42\n21 39\n40 7\n", "6 3\n6 10\n2 5\n4 4\n", "28 46\n50 27\n23 50\n21 45\n", "46 33\n12 3\n11 67\n98 77\n", "10 10\n4 9\n8 9\n7 6\n", "63 4\n18 60\n58 76\n44 93\n", ...
1,700
0
2
8
439_B. Devu, the Dumb Guy
Devu is a dumb guy, his learning curve is very slow. You are supposed to teach him n subjects, the ith subject has ci chapters. When you teach him, you are supposed to teach all the chapters of a subject continuously. Let us say that his initial per chapter learning power of a subject is x hours. In other words he can...
{ "input": [ "3 3\n1 1 1\n", "4 2\n5 1 2 1\n", "2 3\n4 1\n" ], "output": [ "6\n", "10\n", "11\n" ] }
{ "input": [ "1 1\n1\n", "1 1\n9273\n", "20 10\n6 6 1 2 6 4 5 3 6 5 4 5 6 5 4 6 6 2 3 3\n", "1 2\n2\n", "20 4\n1 1 3 5 5 1 3 4 2 5 2 4 3 1 3 3 3 3 4 3\n", "2 1\n1 2\n", "1 2\n1\n" ], "output": [ "1\n", "9273\n", "196\n", "4\n", "65\n", "3\n", "2\n" ] }
1,200
1,000
2
10
460_D. Little Victor and Set
Little Victor adores the sets theory. Let us remind you that a set is a group of numbers where all numbers are pairwise distinct. Today Victor wants to find a set of integers S that has the following properties: * for all x <image> the following inequality holds l ≤ x ≤ r; * 1 ≤ |S| ≤ k; * lets denote the i-th...
{ "input": [ "8 30 7\n", "8 15 3\n" ], "output": [ "0\n4\n8 9 10 11\n", "1\n2\n8 9\n" ] }
{ "input": [ "999999999996 1000000000000 5\n", "1023 1536 3\n", "1 5 5\n", "1 3 3\n", "137765364256 267196143745 72414\n", "93593884958 917491772445 660\n", "842310243287 842310243288 1\n", "4294967297 12884901887 3\n", "100000000000 900000000000 5\n", "1 1000000000000 1000000\...
2,300
2,000
2
9
508_C. Anya and Ghosts
Anya loves to watch horror movies. In the best traditions of horror, she will be visited by m ghosts tonight. Anya has lots of candles prepared for the visits, each candle can produce light for exactly t seconds. It takes the girl one second to light one candle. More formally, Anya can spend one second to light one can...
{ "input": [ "1 1 3\n10\n", "1 8 3\n10\n", "2 10 1\n5 8\n" ], "output": [ "-1\n", "3\n", "1\n" ] }
{ "input": [ "21 140 28\n40 46 58 67 71 86 104 125 129 141 163 184 193 215 219 222 234 237 241 246 263\n", "100 257 21\n50 56 57 58 59 60 62 66 71 75 81 84 86 90 91 92 94 95 96 97 100 107 110 111 112 114 115 121 123 125 126 127 129 130 133 134 136 137 147 151 152 156 162 167 168 172 176 177 178 179 181 182 18...
1,600
1,500
2
10
557_D. Vitaly and Cycle
After Vitaly was expelled from the university, he became interested in the graph theory. Vitaly especially liked the cycles of an odd length in which each vertex occurs at most once. Vitaly was wondering how to solve the following problem. You are given an undirected graph consisting of n vertices and m edges, not ne...
{ "input": [ "4 4\n1 2\n1 3\n4 2\n4 3\n", "3 0\n", "3 3\n1 2\n2 3\n3 1\n" ], "output": [ "1 2", "3 1", "0 1" ] }
{ "input": [ "5 4\n1 2\n1 3\n1 4\n1 5\n", "59139 1\n10301 5892\n", "76259 0\n", "9859 1\n1721 9478\n", "25987 0\n", "9411 0\n", "6 4\n1 2\n2 3\n3 1\n4 5\n", "92387 0\n", "59139 0\n", "25539 0\n", "5 5\n1 2\n2 3\n3 4\n4 5\n5 1\n", "6 3\n1 2\n2 3\n4 5\n", "9859 0\n", ...
2,000
2,000
2
8
583_B. Robot's Task
Robot Doc is located in the hall, with n computers stand in a line, numbered from left to right from 1 to n. Each computer contains exactly one piece of information, each of which Doc wants to get eventually. The computers are equipped with a security system, so to crack the i-th of them, the robot needs to collect at ...
{ "input": [ "3\n0 2 0\n", "7\n0 3 1 0 5 2 6\n", "5\n4 2 3 0 1\n" ], "output": [ "1", "2", "3" ] }
{ "input": [ "9\n1 3 5 7 8 6 4 2 0\n", "9\n3 1 5 6 0 3 2 0 0\n", "10\n0 0 0 0 0 0 0 0 0 0\n", "9\n6 2 3 7 4 8 5 1 0\n", "10\n3 4 8 9 5 1 2 0 6 7\n", "100\n1 3 5 7 58 11 13 15 17 19 45 23 25 27 29 31 33 35 37 39 41 43 21 47 49 51 53 55 57 59 61 63 65 67 69 71 73 75 77 81 79 83 85 87 89 91 93 95...
1,200
1,000
2
8
605_B. Lazy Student
Student Vladislav came to his programming exam completely unprepared as usual. He got a question about some strange algorithm on a graph — something that will definitely never be useful in real life. He asked a girl sitting next to him to lend him some cheat papers for this questions and found there the following defin...
{ "input": [ "3 3\n1 0\n2 1\n3 1\n", "4 5\n2 1\n3 1\n4 0\n1 1\n5 0\n" ], "output": [ "-1\n", "1 3\n1 4\n2 3\n1 2\n2 4\n" ] }
{ "input": [ "10 15\n752087443 1\n537185872 1\n439895449 1\n494086747 1\n718088132 1\n93444012 0\n670136349 1\n545547453 0\n718088132 0\n853059674 0\n853059674 1\n762928724 1\n762928724 0\n853059674 0\n156495293 1\n", "3 3\n4 1\n5 1\n7 0\n", "3 2\n8 1\n9 1\n", "5 10\n1 1\n1 1\n1 0\n1 1\n2 0\n2 0\n3 1\...
1,700
1,000
2
9
627_C. Package Delivery
Johnny drives a truck and must deliver a package from his hometown to the district center. His hometown is located at point 0 on a number line, and the district center is located at the point d. Johnny's truck has a gas tank that holds exactly n liters, and his tank is initially full. As he drives, the truck consumes ...
{ "input": [ "16 5 2\n8 2\n5 1\n", "10 4 4\n3 5\n5 8\n6 3\n8 4\n" ], "output": [ "-1\n", "22\n" ] }
{ "input": [ "400000000 400000000 3\n1 139613\n19426 13509\n246298622 343529\n", "153 105 1\n96 83995\n", "229 123 2\n170 270968\n76 734741\n", "281 12 23\n178 650197\n129 288456\n34 924882\n43 472160\n207 957083\n103 724815\n167 308008\n135 906958\n74 242828\n229 146026\n85 241042\n22 39127\n62 47524...
2,200
1,500
2
9
651_C. Watchmen
Watchmen are in a danger and Doctor Manhattan together with his friend Daniel Dreiberg should warn them as soon as possible. There are n watchmen on a plane, the i-th watchman is located at point (xi, yi). They need to arrange a plan, but there are some difficulties on their way. As you know, Doctor Manhattan consider...
{ "input": [ "3\n1 1\n7 5\n1 5\n", "6\n0 0\n0 1\n0 2\n-1 1\n0 1\n1 1\n" ], "output": [ "2\n", "11\n" ] }
{ "input": [ "2\n2 1\n1 2\n", "2\n1 4\n2 1\n", "10\n46 -55\n46 45\n46 45\n83 -55\n46 45\n83 -55\n46 45\n83 45\n83 45\n46 -55\n", "2\n1 1000000000\n2 -1000000000\n", "1\n-5 -90\n", "2\n1000000000 0\n-7 1\n", "2\n1 0\n0 2333333\n", "2\n-1 1000000000\n0 -1\n", "2\n0 1000000000\n1 -7\n...
1,400
500
2
7
677_A. Vanya and Fence
Vanya and his friends are walking along the fence of height h and they do not want the guard to notice them. In order to achieve this the height of each of the friends should not exceed h. If the height of some person is greater than h he can bend down and then he surely won't be noticed by the guard. The height of the...
{ "input": [ "3 7\n4 5 14\n", "6 1\n1 1 1 1 1 1\n", "6 5\n7 6 8 9 10 5\n" ], "output": [ "4\n", "6\n", "11\n" ] }
{ "input": [ "10 561\n657 23 1096 487 785 66 481 554 1000 821\n", "10 420\n214 614 297 675 82 740 174 23 255 15\n", "46 71\n30 26 56 138 123 77 60 122 73 45 79 10 130 3 14 1 38 46 128 50 82 16 32 68 28 98 62 106 2 49 131 11 114 39 139 70 40 50 45 137 33 30 35 136 135 19\n", "1 1\n1\n", "75 940\n16...
800
500
2
7
6_A. Triangle
Johnny has a younger sister Anne, who is very clever and smart. As she came home from the kindergarten, she told his brother about the task that her kindergartener asked her to solve. The task was just to construct a triangle out of four sticks of different colours. Naturally, one of the sticks is extra. It is not allo...
{ "input": [ "3 5 9 1\n", "7 2 2 4\n", "4 2 1 3\n" ], "output": [ "IMPOSSIBLE\n", "SEGMENT\n", "TRIANGLE\n" ] }
{ "input": [ "7 7 10 7\n", "4 4 4 5\n", "50 1 50 100\n", "11 30 79 43\n", "49 51 100 1\n", "3 1 2 1\n", "27 53 7 97\n", "1 5 1 3\n", "10 20 30 40\n", "3 5 1 1\n", "22 80 29 7\n", "1 5 5 5\n", "4 4 10 10\n", "4 8 16 2\n", "49 24 9 74\n", "10 100 7 3\n", ...
900
0
2
9
721_C. Journey
Recently Irina arrived to one of the most famous cities of Berland — the Berlatov city. There are n showplaces in the city, numbered from 1 to n, and some of them are connected by one-directional roads. The roads in Berlatov are designed in a way such that there are no cyclic routes between showplaces. Initially Irina...
{ "input": [ "4 3 13\n1 2 5\n2 3 7\n2 4 8\n", "6 6 7\n1 2 2\n1 3 3\n3 6 3\n2 4 2\n4 6 2\n6 5 1\n", "5 5 6\n1 3 3\n3 5 3\n1 2 2\n2 4 3\n4 5 2\n" ], "output": [ "3\n1 2 4 ", "4\n1 2 4 6 ", "3\n1 3 5 " ] }
{ "input": [ "4 4 120\n1 2 11\n1 3 20\n2 3 10\n3 4 100\n", "4 4 1000000000\n1 2 1000000000\n2 3 1000000000\n3 4 1000000000\n1 4 1000000000\n", "12 12 8\n1 2 2\n2 3 5\n3 12 1\n4 5 1000000000\n1 7 1\n7 6 3\n6 12 1\n1 9 1\n9 10 1\n10 11 1\n11 8 1\n8 12 1\n", "12 12 9\n1 2 1\n2 3 1\n1 4 1\n4 5 1\n5 6 1\n6...
1,800
1,500
2
7
743_A. Vladik and flights
Vladik is a competitive programmer. This year he is going to win the International Olympiad in Informatics. But it is not as easy as it sounds: the question Vladik face now is to find the cheapest way to get to the olympiad. Vladik knows n airports. All the airports are located on a straight line. Each airport has uni...
{ "input": [ "4 1 4\n1010\n", "5 5 2\n10110\n" ], "output": [ "1\n", "0\n" ] }
{ "input": [ "6 1 6\n111000\n", "10 5 8\n1000001110\n", "5 1 5\n11010\n", "8 4 5\n00001111\n", "5 1 5\n10000\n", "8 1 8\n11110000\n", "10 3 3\n1001011011\n", "10 1 10\n0000011111\n", "6 1 6\n011111\n", "10 3 7\n0000011111\n", "4 1 4\n0011\n", "1 1 1\n1\n", "16 4 12\...
1,200
500
2
9
766_C. Mahmoud and a Message
Mahmoud wrote a message s of length n. He wants to send it as a birthday present to his friend Moaz who likes strings. He wrote it on a magical paper but he was surprised because some characters disappeared while writing the string. That's because this magical paper doesn't allow character number i in the English alpha...
{ "input": [ "3\naab\n2 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n", "10\nabcdeabcde\n5 5 5 5 4 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n" ], "output": [ "3\n2\n2\n", "401\n4\n3\n" ] }
{ "input": [ "10\naabaabaaba\n3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n", "10\naaaaaaaaaa\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\n", "8\naaaaaaab\n8 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n", "100\nygdbmqpyofbcoqomztbjkutjwkkxkkmoyjrqteikqxrkcgqcfrbujupiegumelsmqkd...
1,700
1,500
2
8
78_B. Easter Eggs
The Easter Rabbit laid n eggs in a circle and is about to paint them. Each egg should be painted one color out of 7: red, orange, yellow, green, blue, indigo or violet. Also, the following conditions should be satisfied: * Each of the seven colors should be used to paint at least one egg. * Any four eggs lying ...
{ "input": [ "8\n", "13\n" ], "output": [ "ROYGBIVG", "ROYGBIVGBIVGB" ] }
{ "input": [ "21\n", "24\n", "61\n", "10\n", "9\n", "17\n", "16\n", "97\n", "11\n", "29\n", "14\n", "22\n", "23\n", "34\n", "25\n", "100\n", "8\n", "7\n", "81\n", "15\n", "20\n", "95\n", "92\n", "19\n", "98\n", "96...
1,200
1,000
2
7
837_A. Text Volume
You are given a text of single-space separated words, consisting of small and capital Latin letters. Volume of the word is number of capital letters in the word. Volume of the text is maximum volume of all words in the text. Calculate the volume of the given text. Input The first line contains one integer number n ...
{ "input": [ "24\nthis is zero answer text\n", "7\nNonZERO\n", "24\nHarbour Space University\n" ], "output": [ "0\n", "5\n", "1\n" ] }
{ "input": [ "15\naAb ABCDFGRHTJS\n", "24\nHarbour Space UniversitY\n", "5\naA AA\n", "10\nas AS ASDA\n", "200\nhCyIdivIiISmmYIsCLbpKcTyHaOgTUQEwnQACXnrLdHAVFLtvliTEMlzBVzTesQbhXmcqvwPDeojglBMIjOXANfyQxCSjOJyO SIqOTnRzVzseGIDDYNtrwIusScWSuEhPyEmgQIVEzXofRptjeMzzhtUQxJgcUWILUhEaaRmYRBVsjoqgmyPIKwSa...
800
0
2
9
906_C. Party
Arseny likes to organize parties and invite people to it. However, not only friends come to his parties, but friends of his friends, friends of friends of his friends and so on. That's why some of Arseny's guests can be unknown to him. He decided to fix this issue using the following procedure. At each step he selects...
{ "input": [ "4 4\n1 2\n1 3\n1 4\n3 4\n", "5 6\n1 2\n1 3\n2 3\n2 5\n3 4\n4 5\n" ], "output": [ "1\n1 \n", "2\n2 3 \n" ] }
{ "input": [ "22 66\n15 20\n15 4\n2 22\n8 22\n2 4\n8 2\n5 7\n18 8\n10 21\n22 20\n18 7\n2 20\n5 1\n20 19\n21 4\n8 4\n20 5\n7 8\n7 4\n21 15\n21 22\n7 20\n5 22\n21 7\n5 18\n18 21\n19 7\n15 7\n21 8\n18 15\n18 16\n21 19\n19 5\n21 2\n5 15\n8 3\n7 22\n2 15\n9 2\n20 4\n15 22\n19 18\n19 15\n15 13\n7 2\n15 8\n21 5\n18 2\n5...
2,400
1,250
2
11
926_E. Merge Equal Elements
You are given a sequence of positive integers a1, a2, ..., an. While possible, you perform the following operation: find a pair of equal consecutive elements. If there are more than one such pair, find the leftmost (with the smallest indices of elements). If the two integers are equal to x, delete both and insert a s...
{ "input": [ "7\n4 10 22 11 12 5 6\n", "6\n5 2 1 1 2 2\n", "4\n1000000000 1000000000 1000000000 1000000000\n" ], "output": [ "7\n4 10 22 11 12 5 6\n", "2\n5 4\n", "1\n1000000002\n" ] }
{ "input": [ "2\n1 1\n", "3\n2 1 1\n", "7\n5 5 4 4 5 6 7\n", "4\n3 2 1 1\n" ], "output": [ "1\n2\n", "1\n3\n", "3\n7 6 7\n", "1\n4\n" ] }
1,900
0
2
9
955_C. Sad powers
You're given Q queries of the form (L, R). For each query you have to find the number of such x that L ≤ x ≤ R and there exist integer numbers a > 0, p > 1 such that x = ap. Input The first line contains the number of queries Q (1 ≤ Q ≤ 105). The next Q lines contains two integers L, R each (1 ≤ L ≤ R ≤ 1018). Ou...
{ "input": [ "6\n1 4\n9 9\n5 7\n12 29\n137 591\n1 1000000\n" ], "output": [ "2\n1\n0\n3\n17\n1111\n" ] }
{ "input": [ "20\n862 928\n758 964\n541 789\n622 943\n328 900\n14 764\n217 972\n461 847\n442 468\n900 986\n518 529\n938 993\n549 851\n690 944\n484 601\n320 910\n98 868\n816 915\n765 880\n551 770\n" ], "output": [ "1\n4\n5\n6\n14\n32\n20\n9\n0\n2\n1\n1\n6\n4\n4\n15\n26\n2\n2\n4\n" ] }
2,100
1,500
2
10
1038_D. Slime
There are n slimes in a row. Each slime has an integer value (possibly negative or zero) associated with it. Any slime can eat its adjacent slime (the closest slime to its left or to its right, assuming that this slime exists). When a slime with a value x eats a slime with a value y, the eaten slime disappears, and ...
{ "input": [ "5\n0 -1 -1 -1 -1\n", "4\n2 1 2 1\n" ], "output": [ "4\n", "4\n" ] }
{ "input": [ "2\n-4 -5\n", "10\n-20 0 3 -5 -18 15 -3 -9 -7 9\n", "2\n-2 -2\n", "8\n-1 5 -19 4 -12 20 1 -12\n", "1\n-10\n", "3\n-2 -4 -6\n", "2\n10 8\n", "9\n2 4 -4 15 1 11 15 -7 -20\n", "2\n-2 -3\n", "2\n-1 -5\n", "3\n-1 -2 -3\n", "2\n-1 -1\n", "1\n11\n", "2\n-1...
1,800
1,750
2
7
1102_A. Integer Sequence Dividing
You are given an integer sequence 1, 2, ..., n. You have to divide it into two sets A and B in such a way that each element belongs to exactly one set and |sum(A) - sum(B)| is minimum possible. The value |x| is the absolute value of x and sum(S) is the sum of elements of the set S. Input The first line of the input ...
{ "input": [ "6\n", "5\n", "3\n" ], "output": [ "1\n", "1\n", "0\n" ] }
{ "input": [ "46369\n", "1000003346\n", "4\n", "1000070102\n", "123214213\n", "999998\n", "199999998\n", "65538\n", "999\n", "1000271094\n", "1244164813\n", "1465465413\n", "1999999999\n", "999999998\n", "1234567889\n", "778778777\n", "1000080110\n",...
800
0
2
7
1130_A. Be Positive
You are given an array of n integers: a_1, a_2, …, a_n. Your task is to find some non-zero integer d (-10^3 ≤ d ≤ 10^3) such that, after each number in the array is divided by d, the number of positive numbers that are presented in the array is greater than or equal to half of the array size (i.e., at least ⌈n/2⌉). Not...
{ "input": [ "7\n0 0 1 -1 0 0 2\n", "5\n10 0 -7 2 6" ], "output": [ "0", "1" ] }
{ "input": [ "100\n-261 613 -14 965 -114 -594 516 -631 -477 -352 -481 0 -224 -524 -841 397 -138 -986 -442 -568 -417 -850 -654 -193 -344 -648 -525 -394 -730 -712 -600 0 188 248 -657 -509 -647 -878 175 -894 -557 0 -367 -458 -35 -560 0 -952 -579 -784 -286 -303 -104 -984 0 0 487 -871 223 -527 0 -776 -675 -933 -669 -4...
800
500
2
8
1150_B. Tiling Challenge
One day Alice was cleaning up her basement when she noticed something very curious: an infinite set of wooden pieces! Each piece was made of five square tiles, with four tiles adjacent to the fifth center tile: <image> By the pieces lay a large square wooden board. The board is divided into n^2 cells arranged into n ...
{ "input": [ "3\n#.#\n...\n#.#\n", "5\n#.###\n....#\n#....\n....#\n#..##\n", "4\n##.#\n#...\n####\n##.#\n", "5\n#.###\n....#\n#....\n###.#\n#####\n" ], "output": [ "YES\n", "NO\n", "NO\n", "YES\n" ] }
{ "input": [ "20\n#.##.##.##.##.##.###\n...................#\n#..#..#..#..#..#....\n#................#.#\n#..#..#..#..#......#\n....................\n#..#..#..#..#......#\n#.............#....#\n#..#..#..#......#..#\n....................\n#..#..#..#......#..#\n#..........#.......#\n#..#..#......#..#..#\n.............
900
1,000
2
9
1172_C1. Nauuo and Pictures (easy version)
The only difference between easy and hard versions is constraints. Nauuo is a girl who loves random picture websites. One day she made a random picture website by herself which includes n pictures. When Nauuo visits the website, she sees exactly one picture. The website does not display each picture with equal proba...
{ "input": [ "1 2\n1\n1\n", "2 1\n0 1\n2 1\n", "3 3\n0 1 1\n4 3 5\n" ], "output": [ "3\n", "332748119\n332748119\n", "160955686\n185138929\n974061117\n" ] }
{ "input": [ "10 10\n0 1 0 0 1 1 1 1 1 1\n12 18 6 18 7 2 9 18 1 9\n", "50 50\n0 0 0 1 0 1 0 1 0 1 0 1 0 0 1 0 0 1 0 0 0 1 1 0 0 1 1 0 1 0 1 1 1 0 0 1 1 1 1 0 1 1 1 0 0 0 1 1 0 1\n1 9 24 8 8 11 21 11 8 5 16 32 31 15 29 14 16 20 5 18 5 10 31 23 21 4 4 20 20 11 1 4 4 15 9 14 5 30 13 16 32 27 19 10 19 24 21 1 21 ...
2,300
750
2
10
118_D. Caesar's Legions
Gaius Julius Caesar, a famous general, loved to line up his soldiers. Overall the army had n1 footmen and n2 horsemen. Caesar thought that an arrangement is not beautiful if somewhere in the line there are strictly more that k1 footmen standing successively one after another, or there are strictly more than k2 horsemen...
{ "input": [ "2 1 1 10\n", "2 3 1 2\n", "2 4 1 1\n" ], "output": [ "1\n", "5\n", "0\n" ] }
{ "input": [ "12 15 7 2\n", "34 55 2 9\n", "46 51 4 5\n", "2 1 1 1\n", "10 10 5 7\n", "2 2 1 2\n", "100 99 10 10\n", "1 2 1 1\n", "24 30 5 1\n", "18 4 3 1\n", "100 100 10 10\n", "34 57 1 1\n", "56 40 3 2\n", "100 100 9 10\n", "20 4 9 4\n", "46 46 2 5\n",...
1,700
2,000
2
9
1209_C. Paint the Digits
You are given a sequence of n digits d_1d_2 ... d_{n}. You need to paint all the digits in two colors so that: * each digit is painted either in the color 1 or in the color 2; * if you write in a row from left to right all the digits painted in the color 1, and then after them all the digits painted in the color ...
{ "input": [ "5\n12\n040425524644\n1\n0\n9\n123456789\n2\n98\n3\n987\n" ], "output": [ "121212211211\n1\n111111111\n21\n-\n" ] }
{ "input": [ "5\n4\n6148\n1\n7\n5\n49522\n3\n882\n2\n51\n", "5\n1\n3\n5\n74730\n1\n4\n5\n49554\n2\n59\n" ], "output": [ "2112\n1\n-\n221\n21\n", "1\n-\n1\n-\n11\n" ] }
1,500
1,250
2
8
1228_B. Filling the Grid
Suppose there is a h × w grid consisting of empty or full cells. Let's make some definitions: * r_{i} is the number of consecutive full cells connected to the left side in the i-th row (1 ≤ i ≤ h). In particular, r_i=0 if the leftmost cell of the i-th row is empty. * c_{j} is the number of consecutive full cells ...
{ "input": [ "19 16\n16 16 16 16 15 15 0 5 0 4 9 9 1 4 4 0 8 16 12\n6 12 19 15 8 6 19 19 14 6 9 16 10 11 15 4\n", "3 4\n0 3 1\n0 2 3 0\n", "1 1\n0\n1\n" ], "output": [ "797922655\n", "2\n", "0\n" ] }
{ "input": [ "2 2\n1 1\n1 0\n", "1 1\n1\n0\n", "4 4\n2 0 3 1\n1 3 0 3\n", "3 5\n4 3 2\n3 2 2 1 0\n", "2 4\n2 2\n0 0 0 2\n", "4 5\n2 5 2 2\n4 4 0 2 2\n", "9 9\n9 9 9 9 9 9 9 9 9\n9 9 9 9 9 9 9 9 9\n", "4 4\n4 4 3 3\n4 4 4 1\n", "3 6\n0 0 0\n0 0 0 0 0 0\n", "3 4\n4 4 4\n0 3 3 3\n...
1,400
1,000
2
8
1270_B. Interesting Subarray
For an array a of integers let's denote its maximal element as max(a), and minimal as min(a). We will call an array a of k integers interesting if max(a) - min(a) ≥ k. For example, array [1, 3, 4, 3] isn't interesting as max(a) - min(a) = 4 - 1 = 3 < 4 while array [7, 3, 0, 4, 3] is as max(a) - min(a) = 7 - 0 = 7 ≥ 5. ...
{ "input": [ "3\n5\n1 2 3 4 5\n4\n2 0 1 9\n2\n2019 2020\n" ], "output": [ "NO\nYES\n1 2\nNO\n" ] }
{ "input": [ "1\n16\n1 2 3 4 4 4 2 4 4 4 4 4 5 5 5 5\n", "1\n8\n1 2 2 2 4 4 4 5\n", "1\n14\n1 2 3 4 5 4 2 3 4 5 4 3 2 1\n", "1\n11\n1 2 3 4 5 6 7 6 5 4 6\n", "1\n9\n2 4 3 2 1 2 3 4 5\n", "1\n10\n1 2 3 4 4 6 7 7 8 9\n", "1\n24\n1 1 1 1 1 1 2 2 2 2 2 2 4 4 4 4 4 4 5 5 5 5 5 5\n" ], "outp...
1,200
1,000
2
12
1292_F. Nora's Toy Boxes
[SIHanatsuka - EMber](https://soundcloud.com/hanatsuka/sihanatsuka-ember) [SIHanatsuka - ATONEMENT](https://soundcloud.com/hanatsuka/sihanatsuka-atonement) Back in time, the seven-year-old Nora used to play lots of games with her creation ROBO_Head-02, both to have fun and enhance his abilities. One day, Nora's adop...
{ "input": [ "4\n5 7 2 9\n", "3\n2 6 8\n", "5\n2 3 4 9 12\n" ], "output": [ "1\n", "2\n", "4\n" ] }
{ "input": [ "45\n41 50 11 34 39 40 9 22 48 6 31 16 13 8 20 42 27 45 15 43 32 38 28 10 46 17 21 33 4 18 35 14 37 23 29 2 49 19 12 44 36 24 30 26 3\n", "60\n51 18 41 48 9 10 7 2 34 23 31 55 28 29 47 42 14 30 60 43 16 21 1 33 6 36 58 35 50 19 40 27 26 25 20 38 8 53 22 13 45 4 24 49 56 39 15 3 57 17 59 11 52 5 4...
3,500
2,750
2
13
1312_G. Autocompletion
You are given a set of strings S. Each string consists of lowercase Latin letters. For each string in this set, you want to calculate the minimum number of seconds required to type this string. To type a string, you have to start with an empty string and transform it into the string you want to type using the followin...
{ "input": [ "10\n0 i\n1 q\n2 g\n0 k\n1 e\n5 r\n4 m\n5 h\n3 p\n3 e\n5\n8 9 1 10 6\n", "8\n0 a\n1 b\n2 a\n2 b\n4 a\n4 b\n5 c\n6 d\n5\n2 3 4 7 8\n" ], "output": [ "2 4 1 3 3 ", "1 2 2 4 4 " ] }
{ "input": [ "1\n0 z\n1\n1\n" ], "output": [ "1 " ] }
2,600
0
2
10
1335_D. Anti-Sudoku
You are given a correct solution of the sudoku puzzle. If you don't know what is the sudoku, you can read about it [here](http://tiny.cc/636xmz). The picture showing the correct sudoku solution: <image> Blocks are bordered with bold black color. Your task is to change at most 9 elements of this field (i.e. choose s...
{ "input": [ "1\n154873296\n386592714\n729641835\n863725149\n975314628\n412968357\n631457982\n598236471\n247189563\n" ], "output": [ "254873296\n386692714\n729641935\n873725149\n975324628\n412968367\n632457982\n598237471\n247189564\n" ] }
{ "input": [ "3\n154873296\n386592714\n729641835\n863725149\n975314628\n412968357\n631457982\n598236471\n247189563\n154873296\n386592714\n729641835\n863725149\n975314628\n412968357\n631457982\n598236471\n247189563\n154873296\n386592714\n729641835\n863725149\n975314628\n412968357\n631457982\n598236471\n247189563\n...
1,300
0
2
11
1375_E. Inversion SwapSort
Madeline has an array a of n integers. A pair (u, v) of integers forms an inversion in a if: * 1 ≤ u < v ≤ n. * a_u > a_v. Madeline recently found a magical paper, which allows her to write two indices u and v and swap the values a_u and a_v. Being bored, she decided to write a list of pairs (u_i, v_i) with t...
{ "input": [ "4\n1 8 1 6\n", "5\n1 1 1 2 2\n", "3\n3 1 2\n" ], "output": [ "2\n2 4\n2 3\n", "0\n", "2\n1 3\n1 2\n" ] }
{ "input": [ "1\n1\n", "20\n10 10 9 9 8 8 7 7 6 6 5 5 4 4 3 3 2 2 1 1\n", "5\n3 4 3 1 2\n", "100\n32 85 33 27 35 48 64 40 45 120 68 58 108 115 99 71 47 82 42 34 63 49 102 30 88 70 73 52 51 95 104 41 38 59 91 21 43 107 44 113 109 25 55 118 112 90 37 106 103 100 114 78 31 26 92 79 89 105 62 54 72 69 101...
2,500
2,000
2
7
1399_A. Remove Smallest
You are given the array a consisting of n positive (greater than zero) integers. In one move, you can choose two indices i and j (i ≠ j) such that the absolute difference between a_i and a_j is no more than one (|a_i - a_j| ≤ 1) and remove the smallest of these two elements. If two elements are equal, you can remove a...
{ "input": [ "5\n3\n1 2 2\n4\n5 5 5 5\n3\n1 2 4\n4\n1 3 4 4\n1\n100\n" ], "output": [ "YES\nYES\nNO\nNO\nYES\n" ] }
{ "input": [ "2\n3\n1 2 3\n4\n1 2 3 4\n", "2\n3\n1 2 2\n4\n5 5 5 5\n", "5\n2\n2 3\n4\n2 2 8 8\n3\n3 3 3\n4\n5 5 5 5\n4\n1 1 1 1\n", "1\n1\n114\n" ], "output": [ "YES\nYES\n", "YES\nYES\n", "YES\nNO\nYES\nYES\nYES\n", "YES\n" ] }
800
0
2
10
1422_D. Returning Home
Yura has been walking for some time already and is planning to return home. He needs to get home as fast as possible. To do this, Yura can use the instant-movement locations around the city. Let's represent the city as an area of n × n square blocks. Yura needs to move from the block with coordinates (s_x,s_y) to the ...
{ "input": [ "84 5\n67 59 41 2\n39 56\n7 2\n15 3\n74 18\n22 7\n", "5 3\n1 1 5 5\n1 2\n4 1\n3 3\n" ], "output": [ "42\n", "5\n" ] }
{ "input": [ "1 0\n1 1 1 1\n", "1000000000 0\n1 1000000000 1000000000 1\n", "49397978 9\n35828361 4692148 30832063 21157937\n38015170 25815246\n25302604 1245031\n35710367 30096200\n20411634 24957987\n31626304 14768886\n43944112 42021291\n14679371 40895905\n18936340 12122304\n48071293 32576660\n", "100...
2,300
1,500
2
9
1440_C1. Binary Table (Easy Version)
This is the easy version of the problem. The difference between the versions is in the number of possible operations that can be made. You can make hacks if and only if you solved both versions of the problem. You are given a binary table of size n × m. This table consists of symbols 0 and 1. You can make such operat...
{ "input": [ "5\n2 2\n10\n11\n3 3\n011\n101\n110\n4 4\n1111\n0110\n0110\n1111\n5 5\n01011\n11001\n00010\n11011\n10000\n2 3\n011\n101\n" ], "output": [ "9\n1 1 2 1 2 2 \n1 1 1 2 2 2 \n1 1 2 1 1 2 \n2 1 1 1 1 2 \n2 1 2 2 1 2 \n2 1 1 1 2 2 \n2 2 1 2 1 1 \n2 2 2 1 1 1 \n2 2 1 2 2 1 \n18\n1 2 2 2 2 3 \n1 2 1 3...
{ "input": [ "5\n2 2\n10\n11\n3 3\n011\n101\n110\n4 4\n1111\n0110\n0110\n1111\n5 5\n01011\n11001\n00010\n11011\n10000\n2 3\n011\n101\n" ], "output": [ "9\n1 1 2 1 2 2 \n1 1 1 2 2 2 \n1 1 2 1 1 2 \n2 1 1 1 1 2 \n2 1 2 2 1 2 \n2 1 1 1 2 2 \n2 2 1 2 1 1 \n2 2 2 1 1 1 \n2 2 1 2 2 1 \n18\n1 2 2 2 2 3 \n1 2 1 3...
1,500
500
2
13
1491_G. Switch and Flip
There are n coins labeled from 1 to n. Initially, coin c_i is on position i and is facing upwards ((c_1, c_2, ..., c_n) is a permutation of numbers from 1 to n). You can do some operations on these coins. In one operation, you can do the following: * Choose 2 distinct indices i and j. * Then, swap the coins on ...
{ "input": [ "5\n1 2 3 4 5\n", "3\n2 1 3\n" ], "output": [ "\n0\n", "\n3\n1 3\n3 2\n3 1\n" ] }
{ "input": [ "4\n2 1 4 3\n", "3\n2 3 1\n" ], "output": [ "4\n1 3\n1 4\n3 2\n3 1\n", "4\n1 2\n2 3\n1 3\n1 2\n" ] }
2,800
2,250
2
10
1514_D. Cut and Stick
Baby Ehab has a piece of Cut and Stick with an array a of length n written on it. He plans to grab a pair of scissors and do the following to it: * pick a range (l, r) and cut out every element a_l, a_{l + 1}, ..., a_r in this range; * stick some of the elements together in the same order they were in the array; ...
{ "input": [ "6 2\n1 3 2 3 3 2\n1 6\n2 5\n" ], "output": [ "\n1\n2\n" ] }
{ "input": [ "100 1\n1 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 1 2 1 2 1 1 1 2 2 1 2 2 2 2 1 1 2 1 1 1 2 2 1 1 1 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 1 1 2 2 2 1 1 2 2 2 1 1 2 2 2 1 2 2 2\n1 100\n", "1 1\n1\n1 1\n" ], "output": [ "46\n", "1\n" ] }
2,000
2,000
2
10
1541_D. Tree Array
You are given a tree consisting of n nodes. You generate an array from the tree by marking nodes one by one. Initially, when no nodes are marked, a node is equiprobably chosen and marked from the entire tree. After that, until all nodes are marked, a node is equiprobably chosen and marked from the set of unmarked no...
{ "input": [ "5\n1 2\n1 3\n1 4\n2 5\n", "3\n1 2\n1 3\n", "6\n2 1\n2 3\n6 1\n1 4\n2 5\n" ], "output": [ "500000007", "166666669", "500000009" ] }
{ "input": [ "4\n1 2\n2 3\n3 4\n", "2\n1 2\n" ], "output": [ "3", "500000004" ] }
2,300
1,250
2
7
18_A. Triangle
At a geometry lesson Bob learnt that a triangle is called right-angled if it is nondegenerate and one of its angles is right. Bob decided to draw such a triangle immediately: on a sheet of paper he drew three points with integer coordinates, and joined them with segments of straight lines, then he showed the triangle t...
{ "input": [ "-1 0 2 0 0 1\n", "2 3 4 5 6 6\n", "0 0 2 0 0 1\n" ], "output": [ "ALMOST\n", "NEITHER\n", "RIGHT\n" ] }
{ "input": [ "30 8 49 13 25 27\n", "-67 49 89 -76 -37 87\n", "34 74 -2 -95 63 -33\n", "-66 24 8 -29 17 62\n", "-10 -11 62 6 -12 -3\n", "49 -7 19 -76 26 3\n", "0 0 1 0 4 1\n", "-50 -1 0 50 0 -50\n", "0 0 1 0 2 1\n", "-100 -100 100 100 -100 100\n", "-100 -100 100 -100 0 73\n"...
1,500
0
2
7
213_A. Game
Furik and Rubik love playing computer games. Furik has recently found a new game that greatly interested Rubik. The game consists of n parts and to complete each part a player may probably need to complete some other ones. We know that the game can be fully completed, that is, its parts do not form cyclic dependencies....
{ "input": [ "1\n1\n0\n", "5\n2 2 1 1 3\n1 5\n2 5 1\n2 5 4\n1 5\n0\n" ], "output": [ "1\n", "7\n" ] }
{ "input": [ "25\n3 3 1 1 1 2 2 2 3 1 2 3 2 1 2 2 2 3 2 1 2 3 2 1 1\n0\n0\n0\n0\n0\n0\n1 12\n0\n1 19\n0\n2 12 21\n2 3 10\n0\n1 21\n0\n1 9\n1 3\n0\n0\n2 3 2\n0\n1 12\n0\n1 3\n2 21 9\n", "21\n1 2 1 3 3 3 1 1 2 2 3 1 3 1 3 3 1 1 1 2 2\n1 5\n0\n1 11\n0\n0\n0\n1 8\n0\n1 11\n1 1\n1 19\n0\n1 2\n0\n0\n0\n0\n1 19\n0\n...
1,700
1,000
2
7
237_A. Free Cash
Valera runs a 24/7 fast food cafe. He magically learned that next day n people will visit his cafe. For each person we know the arrival time: the i-th person comes exactly at hi hours mi minutes. The cafe spends less than a minute to serve each client, but if a client comes in and sees that there is no free cash, than ...
{ "input": [ "3\n0 12\n10 11\n22 22\n", "4\n8 0\n8 10\n8 10\n8 45\n" ], "output": [ "1\n", "2\n" ] }
{ "input": [ "1\n8 0\n", "10\n0 39\n1 35\n1 49\n1 51\n5 24\n7 40\n7 56\n16 42\n23 33\n23 49\n", "3\n0 0\n0 0\n0 0\n", "50\n0 23\n1 21\n2 8\n2 45\n3 1\n4 19\n4 37\n7 7\n7 40\n8 43\n9 51\n10 13\n11 2\n11 19\n11 30\n12 37\n12 37\n12 37\n12 37\n12 37\n12 37\n12 37\n12 37\n12 54\n13 32\n13 42\n14 29\n14 34...
1,000
500
2
10
285_D. Permutation Sum
Permutation p is an ordered set of integers p1, p2, ..., pn, consisting of n distinct positive integers, each of them doesn't exceed n. We'll denote the i-th element of permutation p as pi. We'll call number n the size or the length of permutation p1, p2, ..., pn. Petya decided to introduce the sum operation on the se...
{ "input": [ "3\n", "5\n" ], "output": [ "18\n", "1800\n" ] }
{ "input": [ "9\n", "11\n", "14\n", "7\n", "16\n", "8\n", "15\n", "6\n", "10\n", "4\n", "12\n", "1\n", "2\n", "13\n" ], "output": [ "734832000\n", "890786230\n", "0\n", "670320\n", "0\n", "0\n", "150347555\n", "0\n", "0\n"...
1,900
2,000
2
8
333_B. Chips
Gerald plays the following game. He has a checkered field of size n × n cells, where m various cells are banned. Before the game, he has to put a few chips on some border (but not corner) board cells. Then for n - 1 minutes, Gerald every minute moves each chip into an adjacent cell. He moves each chip from its original...
{ "input": [ "4 3\n3 1\n3 2\n3 3\n", "3 1\n2 2\n", "3 0\n" ], "output": [ "1\n", "0\n", "1\n" ] }
{ "input": [ "5 5\n2 2\n5 3\n2 3\n5 1\n4 4\n", "5 5\n3 2\n5 4\n3 3\n2 3\n1 2\n", "6 5\n2 1\n6 4\n2 2\n4 3\n4 1\n", "2 1\n1 1\n", "5 5\n3 2\n1 4\n5 1\n4 5\n3 1\n", "1000 0\n", "2 3\n1 2\n2 1\n2 2\n", "5 1\n3 2\n", "6 5\n2 6\n6 5\n3 1\n2 2\n1 2\n", "999 0\n", "5 1\n2 3\n", ...
1,800
1,000
2
7
37_A. Towers
Little Vasya has received a young builder’s kit. The kit consists of several wooden bars, the lengths of all of them are known. The bars can be put one on the top of the other if their lengths are the same. Vasya wants to construct the minimal number of towers from the bars. Help Vasya to use the bars in the best way ...
{ "input": [ "3\n1 2 3\n", "4\n6 5 6 7\n" ], "output": [ "1 3\n", "2 3\n" ] }
{ "input": [ "83\n246 535 994 33 390 927 321 97 223 922 812 705 79 80 977 457 476 636 511 137 6 360 815 319 717 674 368 551 714 628 278 713 761 553 184 414 623 753 428 214 581 115 439 61 677 216 772 592 187 603 658 310 439 559 870 376 109 321 189 337 277 26 70 734 796 907 979 693 570 227 345 650 737 633 701 914 1...
1,000
500
2
10
3_D. Least Cost Bracket Sequence
This is yet another problem on regular bracket sequences. A bracket sequence is called regular, if by inserting "+" and "1" into it we get a correct mathematical expression. For example, sequences "(())()", "()" and "(()(()))" are regular, while ")(", "(()" and "(()))(" are not. You have a pattern of a bracket sequenc...
{ "input": [ "(??)\n1 2\n2 8\n" ], "output": [ "4\n()()" ] }
{ "input": [ "???(?)??(??)?)(?(?????????(?()????)(????(?)????)???)??))(?(?????????))???(??)?????))???????(????????\n9 10\n6 3\n8 2\n9 10\n9 3\n6 2\n8 5\n6 7\n2 6\n7 8\n6 10\n1 7\n1 7\n10 7\n10 7\n8 4\n5 9\n9 3\n3 10\n1 10\n8 2\n8 8\n4 8\n6 6\n4 10\n4 5\n5 2\n5 6\n7 7\n7 3\n10 1\n1 4\n5 10\n3 2\n2 8\n8 9\n6 5\n8 6...
2,600
0
2
7
427_A. Police Recruits
The police department of your city has just started its journey. Initially, they don’t have any manpower. So, they started hiring new recruits in groups. Meanwhile, crimes keeps occurring within the city. One member of the police force can investigate only one crime during his/her lifetime. If there is no police offi...
{ "input": [ "11\n-1 -1 2 -1 -1 -1 -1 -1 -1 -1 -1\n", "3\n-1 -1 1\n", "8\n1 -1 1 -1 -1 1 1 1\n" ], "output": [ "8\n", "2\n", "1\n" ] }
{ "input": [ "1\n1\n", "3\n-1 5 4\n", "4\n-1 -1 1 1\n", "98\n-1 -1 1 -1 -1 -1 -1 1 -1 -1 1 -1 -1 1 -1 1 1 1 -1 1 1 1 1 1 -1 1 -1 -1 -1 -1 1 -1 -1 1 1 -1 1 1 1 -1 -1 -1 -1 -1 -1 1 -1 -1 -1 1 -1 1 -1 1 -1 1 1 1 1 1 1 1 -1 -1 1 1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 1 -1 1 1 1 -1 1 1 -1 -1 -1 1 1 1 -1 -1 -1 ...
800
500
2
15
44_I. Toys
Little Masha loves arranging her toys into piles on the floor. And she also hates it when somebody touches her toys. One day Masha arranged all her n toys into several piles and then her elder brother Sasha came and gathered all the piles into one. Having seen it, Masha got very upset and started crying. Sasha still ca...
{ "input": [ "3\n" ], "output": [ "5\n{1,2,3}\n{1,2},{3}\n{1},{2},{3}\n{1},{2,3}\n{1,3},{2}\n" ] }
{ "input": [ "8\n", "7\n", "6\n", "2\n", "1\n", "8\n", "6\n", "5\n", "4\n", "7\n", "5\n" ], "output": [ "4140\n{1,2,3,4,5,6,7,8}\n{1,2,3,4,5,6,7},{8}\n{1,2,3,4,5,6},{7},{8}\n{1,2,3,4,5,6},{7,8}\n{1,2,3,4,5,6,8},{7}\n{1,2,3,4,5,8},{6},{7}\n{1,2,3,4,5},{6,8},{7}\n{1,2...
2,300
0
2
7
496_A. Minimum Difficulty
Mike is trying rock climbing but he is awful at it. There are n holds on the wall, i-th hold is at height ai off the ground. Besides, let the sequence ai increase, that is, ai < ai + 1 for all i from 1 to n - 1; we will call such sequence a track. Mike thinks that the track a1, ..., an has difficulty <image>. In othe...
{ "input": [ "3\n1 4 6\n", "5\n1 2 3 4 5\n", "5\n1 2 3 7 8\n" ], "output": [ "5\n", "2\n", "4\n" ] }
{ "input": [ "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 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 98...
900
500
2
10
51_D. Geometrical problem
Polycarp loves geometric progressions — he collects them. However, as such progressions occur very rarely, he also loves the sequences of numbers where it is enough to delete a single element to get a geometric progression. In this task we shall define geometric progressions as finite sequences of numbers a1, a2, ...,...
{ "input": [ "4\n3 6 12 24\n", "4\n-8 -16 24 -32\n", "4\n0 1 2 3\n" ], "output": [ "0\n", "1\n", "2\n" ] }
{ "input": [ "5\n1 -10 100 -1000 -10000\n", "2\n0 -17\n", "2\n7 0\n", "5\n5 0 5 5 5\n", "14\n1 1 -2 4 -8 16 -32 64 -128 256 -512 1024 -2048 4096\n", "8\n729 243 81 27 9 9 3 1\n", "4\n-1 -1 -1 1\n", "2\n-17 -527\n", "14\n1 2 4 8 16 32 64 128 256 512 1024 2048 4096 8192\n", "3\n1...
2,200
2,000
2
11
546_E. Soldier and Traveling
In the country there are n cities and m bidirectional roads between them. Each city has an army. Army of the i-th city consists of ai soldiers. Now soldiers roam. After roaming each soldier has to either stay in his city or to go to the one of neighboring cities by at moving along at most one road. Check if is it poss...
{ "input": [ "4 4\n1 2 6 3\n3 5 3 1\n1 2\n2 3\n3 4\n4 2\n", "2 0\n1 2\n2 1\n" ], "output": [ "YES\n1 0 0 0 \n2 0 0 0 \n0 5 1 0 \n0 0 2 1 \n", "NO\n" ] }
{ "input": [ "10 20\n22 3 4 48 12 12 14 37 15 37\n57 29 35 88 6 54 100 32 91 59\n10 1\n4 3\n4 7\n2 4\n7 6\n1 3\n2 5\n5 10\n1 6\n4 9\n6 10\n8 5\n3 6\n6 5\n8 9\n3 10\n2 6\n9 10\n8 4\n8 10\n", "1 0\n2\n1\n", "10 20\n39 65 24 71 86 59 80 35 53 13\n32 41 32 97 83 67 57 26 39 51\n8 10\n5 9\n5 7\n10 2\n4 7\n10 7...
2,100
2,250
2
8
573_B. Bear and Blocks
Limak is a little bear who loves to play. Today he is playing by destroying block towers. He built n towers in a row. The i-th tower is made of hi identical blocks. For clarification see picture for the first sample. Limak will repeat the following operation till everything is destroyed. Block is called internal if i...
{ "input": [ "6\n2 1 4 6 2 2\n", "7\n3 3 3 1 3 3 3\n" ], "output": [ "3", "2" ] }
{ "input": [ "10\n1 2 2 3 5 5 5 4 2 1\n", "14\n20 20 20 20 20 20 3 20 20 20 20 20 20 20\n", "170\n1 2 1 2 1 1 1 1 2 3 2 1 1 2 2 1 2 1 2 1 1 2 3 3 2 1 1 1 1 1 1 1 1 2 1 2 3 3 2 1 2 2 1 2 3 2 1 1 2 3 2 1 2 1 1 1 2 3 3 2 1 2 1 2 1 1 1 2 1 2 1 1 2 2 1 1 2 1 2 2 1 2 1 2 2 1 2 1 2 3 2 1 1 2 3 4 4 3 2 1 2 1 2 1 ...
1,600
1,000
2
9
616_C. The Labyrinth
You are given a rectangular field of n × m cells. Each cell is either empty or impassable (contains an obstacle). Empty cells are marked with '.', impassable cells are marked with '*'. Let's call two empty cells adjacent if they share a side. Let's call a connected component any non-extendible set of cells such that a...
{ "input": [ "4 5\n**..*\n..***\n.*.*.\n*.*.*\n", "3 3\n*.*\n.*.\n*.*\n" ], "output": [ "46..3\n..732\n.6.4.\n5.4.3\n", "3.3\n.5.\n3.3\n" ] }
{ "input": [ "10 1\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n", "10 10\n*.*...*.**\n..*...*.**\n.**.***...\n....*.*.**\n***....***\n.*..*...*.\n.***.*..*.\n.*****.*.*\n*.***.*...\n..*..*....\n", "1 1\n*\n", "1 1\n.\n", "10 1\n*\n*\n*\n*\n*\n.\n*\n.\n*\n*\n", "1 10\n**********\n", "1 10\n*.***.**.*\n"...
1,600
0
2
10
635_D. Factory Repairs
A factory produces thimbles in bulk. Typically, it can produce up to a thimbles a day. However, some of the machinery is defective, so it can currently only produce b thimbles each day. The factory intends to choose a k-day period to do maintenance and construction; it cannot produce any thimbles during this time, but ...
{ "input": [ "5 4 10 1 6\n1 1 5\n1 5 5\n1 3 2\n1 5 2\n2 1\n2 2\n", "5 2 2 1 8\n1 1 2\n1 5 3\n1 2 1\n2 2\n1 4 2\n1 3 2\n2 1\n2 3\n" ], "output": [ "7\n1\n", "3\n6\n4\n" ] }
{ "input": [ "1 1 2 1 1\n2 1\n" ], "output": [ "0\n" ] }
1,700
1,000
2
9
664_C. International Olympiad
International Abbreviation Olympiad takes place annually starting from 1989. Each year the competition receives an abbreviation of form IAO'y, where y stands for some number of consequent last digits of the current year. Organizers always pick an abbreviation with non-empty string y that has never been used before. Amo...
{ "input": [ "5\nIAO'15\nIAO'2015\nIAO'1\nIAO'9\nIAO'0\n", "4\nIAO'9\nIAO'99\nIAO'999\nIAO'9999\n" ], "output": [ "2015\n12015\n1991\n1989\n1990\n", "1989\n1999\n2999\n9999\n" ] }
{ "input": [ "1\nIAO'113098\n", "1\nIAO'021113099\n", "1\nIAO'10005000\n", "1\nIAO'111111111\n", "1\nIAO'11378\n", "1\nIAO'111110\n", "1\nIAO'001\n", "1\nIAO'000000000\n", "1\nIAO'2015\n", "2\nIAO'0\nIAO'00\n", "1\nIAO'111113098\n", "1\nIAO'089\n", "1\nIAO'11100000\...
2,000
250
2
7
689_A. Mike and Cellphone
While swimming at the beach, Mike has accidentally dropped his cellphone into the water. There was no worry as he bought a cheap replacement phone with an old-fashioned keyboard. The keyboard has only ten digital equal-sized keys, located in the following way: <image> Together with his old phone, he lost all his cont...
{ "input": [ "9\n123456789\n", "3\n911\n", "3\n586\n", "2\n09\n" ], "output": [ "YES\n", "YES\n", "NO\n", "NO\n" ] }
{ "input": [ "2\n10\n", "8\n42937903\n", "7\n9454566\n", "2\n05\n", "4\n4268\n", "4\n7844\n", "2\n12\n", "3\n780\n", "7\n5740799\n", "3\n159\n", "6\n392965\n", "1\n5\n", "9\n515821866\n", "4\n7868\n", "4\n1468\n", "2\n57\n", "4\n9394\n", "1\n8\n"...
1,400
500
2
11
710_E. Generate a String
zscoder wants to generate an input file for some programming competition problem. His input is a string consisting of n letters 'a'. He is too lazy to write a generator so he will manually generate the input in a text editor. Initially, the text editor is empty. It takes him x seconds to insert or delete a letter 'a'...
{ "input": [ "8 1 10\n", "8 1 1\n" ], "output": [ "8", "4" ] }
{ "input": [ "1 1 1\n", "3768 561740421 232937477\n", "10000000 1 100\n", "7789084 807239576 813643932\n", "10000000 1 10\n", "58087 1 100000000\n", "10 62 99\n", "9999999 987654321 123456789\n", "35896 278270961 253614967\n", "1926 84641582 820814219\n", "10000000 1 1000\n...
2,000
0
2
11
731_E. Funny Game
Once upon a time Petya and Gena gathered after another programming competition and decided to play some game. As they consider most modern games to be boring, they always try to invent their own games. They have only stickers and markers, but that won't stop them. The game they came up with has the following rules. In...
{ "input": [ "3\n2 4 8\n", "4\n1 -7 -2 3\n" ], "output": [ "14\n", "-3\n" ] }
{ "input": [ "114\n46 7 39 21 44 31 49 57 26 22 86 45 66 72 96 15 77 38 92 88 50 68 30 55 20 5 15 11 26 66 94 74 43 73 35 7 11 36 26 74 86 52 14 5 91 71 3 75 22 7 10 97 42 41 52 80 97 31 45 59 53 85 87 63 42 51 98 61 26 96 65 22 47 0 36 27 35 69 81 58 9 43 7 98 27 56 101 2 31 82 48 100 77 77 42 61 6 32 69 30 102 ...
2,200
2,500
2
7
777_A. Shell Game
Bomboslav likes to look out of the window in his room and watch lads outside playing famous shell game. The game is played by two persons: operator and player. Operator takes three similar opaque shells and places a ball beneath one of them. Then he shuffles the shells by swapping some pairs and the player has to guess...
{ "input": [ "4\n2\n", "1\n1\n" ], "output": [ "1\n", "0\n" ] }
{ "input": [ "100000\n0\n", "1999999997\n1\n", "6\n0\n", "1999999995\n0\n", "4\n0\n", "7\n0\n", "6\n1\n", "3\n1\n", "123456789\n2\n", "1234567890\n0\n", "12\n0\n", "7\n2\n", "99996\n1\n", "3\n2\n", "2000000000\n2\n", "2000000000\n0\n", "123456789\n0\...
1,000
500
2
10
801_D. Volatile Kite
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 ...
{ "input": [ "6\n5 0\n10 0\n12 -4\n10 -8\n5 -8\n3 -4\n", "4\n0 0\n0 1\n1 1\n1 0\n" ], "output": [ "1.00000000\n", "0.35355339\n" ] }
{ "input": [ "4\n-100000 -100000\n-99999 -99999\n100000 99999\n0 -100\n", "4\n0 0\n1 100\n100 0\n1 -100\n", "4\n-1000000000 1000000000\n1000000000 500000000\n1000000000 -1000000000\n-500000000 -1000000000\n", "4\n-10000 -10000\n-9999 -9999\n10000 9999\n0 -1000\n", "4\n-1000000000 -1000000000\n-999...
1,800
1,000
2
7
822_A. I'm bored with life
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...
{ "input": [ "4 3\n" ], "output": [ "6\n" ] }
{ "input": [ "22 12\n", "8 9\n", "20 12\n", "12 12\n", "3 999279109\n", "11 999286606\n", "7 999228288\n", "12 22\n", "1000000000 1\n", "20 6\n", "8 3\n", "999639051 3\n", "14 10\n", "1 12\n", "1213 5\n", "12 23\n", "1 1\n", "12 13\n", "10000...
800
500
2
12
847_F. Berland Elections
The elections to Berland parliament are happening today. Voting is in full swing! Totally there are n candidates, they are numbered from 1 to n. Based on election results k (1 ≤ k ≤ n) top candidates will take seats in the parliament. After the end of the voting the number of votes for each candidate is calculated. I...
{ "input": [ "3 1 5 3\n1 3 1\n", "3 2 5 3\n1 3 1\n", "3 1 5 4\n1 2 1 3\n" ], "output": [ "2 3 2 ", "1 2 2 ", "1 3 3 " ] }
{ "input": [ "23 13 85 26\n20 21 4 10 7 20 12 23 13 20 11 19 9 13 7 21 19 21 4 10 14 9 10 5 14 7\n", "2 2 3 1\n1\n", "71 28 95 28\n17 32 47 35 34 65 44 11 32 9 34 19 34 15 68 7 42 53 67 6 7 70 18 28 45 67 10 20\n", "3 2 2 1\n3\n", "94 47 43 42\n94 50 49 41 79 89 37 90 19 85 86 79 50 74 9 21 30 55 ...
2,100
0
2
7
869_A. The Artful Expedient
Rock... Paper! After Karen have found the deterministic winning (losing?) strategy for rock-paper-scissors, her brother, Koyomi, comes up with a new game as a substitute. The game works as follows. A positive integer n is decided first. Both Koyomi and Karen independently choose n distinct positive integers, denoted ...
{ "input": [ "3\n1 2 3\n4 5 6\n", "5\n2 4 6 8 10\n9 7 5 3 1\n" ], "output": [ "Karen\n", "Karen\n" ] }
{ "input": [ "1\n1\n2000000\n", "1\n1048576\n1020000\n", "3\n9 33 69\n71 74 100\n", "30\n79656 68607 871714 1858841 237684 1177337 532141 161161 1111201 527235 323345 1979059 665353 507265 1290761 610606 1238375 743262 106355 1167830 180315 1233029 816465 752968 782570 1499881 1328457 1867240 13948 13...
1,100
500
2
7
916_A. Jamie and Alarm Snooze
Jamie loves sleeping. One day, he decides that he needs to wake up at exactly hh: mm. However, he hates waking up, so he wants to make waking up less painful by setting the alarm at a lucky time. He will then press the snooze button every x minutes until hh: mm is reached, and only then he will wake up. He wants to kno...
{ "input": [ "3\n11 23\n", "5\n01 07\n" ], "output": [ "2\n", "0\n" ] }
{ "input": [ "12\n00 06\n", "60\n00 10\n", "24\n17 51\n", "2\n18 19\n", "48\n07 11\n", "1\n12 18\n", "59\n06 18\n", "60\n03 00\n", "13\n00 00\n", "5\n08 05\n", "60\n01 24\n", "54\n16 47\n", "60\n13 29\n", "10\n03 10\n", "2\n07 00\n", "2\n10 52\n", "1...
900
500
2
8
939_B. Hamster Farm
Dima has a hamsters farm. Soon N hamsters will grow up on it and Dima will sell them in a city nearby. Hamsters should be transported in boxes. If some box is not completely full, the hamsters in it are bored, that's why each box should be completely full with hamsters. Dima can buy boxes at a factory. The factory pr...
{ "input": [ "19 3\n5 4 10\n", "28 3\n5 6 30\n" ], "output": [ "2 4\n", "1 5\n" ] }
{ "input": [ "2 1\n2\n", "1 1\n1\n", "947264836 50\n977141206 956777871 186433588 538218068 759102378 327484438 88827268 266300062 670616672 756092978 414181331 913675814 898008516 343057716 99416265 236586817 52751842 550467703 684435578 844649988 917709231 550467703 493542638 707106470 414181331 1980950...
1,000
1,000
2
11
991_E. Bus Number
This night wasn't easy on Vasya. His favorite team lost, and he didn't find himself victorious either — although he played perfectly, his teammates let him down every time. He had to win at least one more time, but the losestreak only grew longer and longer... It's no wonder he didn't get any sleep this night at all. ...
{ "input": [ "2028\n", "97\n" ], "output": [ "13\n", "2\n" ] }
{ "input": [ "10\n", "868572419889505545\n", "999999\n", "74774\n", "900008\n", "101010101\n", "234906817379759421\n", "890009800\n", "1\n", "1000000\n", "999999999\n", "987654321\n", "462534182594129378\n", "4\n", "987654321123456789\n", "47003869505473...
1,800
2,000