problem_statement
stringlengths
147
8.53k
input
stringlengths
1
771
output
stringlengths
1
592
time_limit
stringclasses
32 values
memory_limit
stringclasses
21 values
tags
stringlengths
6
168
A. Points on Linetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputLittle Petya likes points a lot. Recently his mom has presented him n points lying on the line OX. Now Petya is wondering in how many ways he can choose three distinct points so that the distance betwe...
Input4 31 2 3 4
Output4
2 seconds
256 megabytes
['binary search', 'combinatorics', 'two pointers', '*1300']
E. Mad Joetime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputJoe has been hurt on the Internet. Now he is storming around the house, destroying everything in his path.Joe's house has n floors, each floor is a segment of m cells. Each cell either contains nothing (it is ...
Input3 5..+.##+..++.#+.
Output14
1 second
256 megabytes
['brute force', '*2000']
D. Building Bridgetime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputTwo villages are separated by a river that flows from the north to the south. The villagers want to build a bridge across the river to make it easier to move across the villages.The river banks can be ...
Input3 2 3 5-2 -1 4-1 27 3
Output2 2
1 second
256 megabytes
['geometry', 'ternary search', 'two pointers', '*1900']
C. Movie Criticstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputA film festival is coming up in the city N. The festival will last for exactly n days and each day will have a premiere of exactly one film. Each film has a genre — an integer from 1 to k.On the i-th da...
Input10 31 1 2 3 2 3 3 1 1 3
Output3
2 seconds
256 megabytes
['greedy', '*1600']
B. Restoring IPv6time limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputAn IPv6-address is a 128-bit number. For convenience, this number is recorded in blocks of 16 bits in hexadecimal record, the blocks are separated by colons — 8 blocks in total, each block has four hex...
Input6a56f:d3:0:0124:01:f19a:1000:00a56f:00d3:0000:0124:0001::a56f::0124:0001:0000:1234:0ff0a56f:0000::0000:0001:0000:1234:0ff0::0ea::4d:f4:6:0
Outputa56f:00d3:0000:0124:0001:f19a:1000:0000a56f:00d3:0000:0124:0001:0000:0000:0000a56f:0000:0000:0124:0001:0000:1234:0ff0a56f:0000:0000:0000:0001:0000:1234:0ff00000:0000:0000:0000:0000:0000:0000:000000ea:0000:0000:0000:004d:00f4:0006:0000
2 seconds
256 megabytes
['implementation', 'strings', '*1500']
A. Paper Worktime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputPolycarpus has been working in the analytic department of the "F.R.A.U.D." company for as much as n days. Right now his task is to make a series of reports about the company's performance for the last n da...
Input111 2 3 -4 -5 -6 5 -5 -6 -7 6
Output35 3 3
2 seconds
256 megabytes
['greedy', '*1000']
E. Endless Matrixtime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputA Russian space traveller Alisa Selezneva, like any other schoolgirl of the late 21 century, is interested in science. She has recently visited the MIT (Moscow Institute of Time), where its chairman an...
Input51 1 1 12 2 3 32 3 5 6100 87 288 20024 2 5 4
Output124300...5679392764111
3 seconds
256 megabytes
['math', '*2600']
D. Donkey and Starstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputIn the evenings Donkey would join Shrek to look at the stars. They would sit on a log, sipping tea and they would watch the starry sky. The sky hung above the roof, right behind the chimney. Shrek's ...
Input151/3 2/13 16 24 22 54 56 63 41 62 17 49 35 31 315 512 4
Output4
2 seconds
256 megabytes
['data structures', 'dp', 'geometry', 'math', 'sortings', '*2700']
E. Piglet's Birthdaytime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputPiglet has got a birthday today. His friend Winnie the Pooh wants to make the best present for him — a honey pot. Of course Winnie realizes that he won't manage to get the full pot to Piglet. In fac...
Input32 2 351 2 12 1 21 2 23 1 13 2 2
Output0.0000000000000.3333333333331.0000000000001.0000000000002.000000000000
2 seconds
256 megabytes
['dp', 'math', 'probabilities', '*2600']
D. Sweets for Everyone!time limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputFor 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 ...
Input6 6HSHSHS
Output1
2 seconds
256 megabytes
['binary search', 'greedy', 'implementation', '*2300']
C. Robo-Footballertime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputIt's a beautiful April day and Wallace is playing football with his friends. But his friends do not know that Wallace actually stayed home with Gromit and sent them his robotic self instead. Robo-Wall...
Input4 10 13 10 3 1
Output4.3750000000
2 seconds
256 megabytes
['binary search', 'geometry', '*2000']
B. Chilly Willytime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputChilly Willy loves playing with numbers. He only knows prime numbers that are digits yet. These numbers are 2, 3, 5 and 7. But Willy grew rather bored of such numbers, so he came up with a few games that...
Input1
Output-1
2 seconds
256 megabytes
['math', 'number theory', '*1400']
A. Cupboardstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputOne foggy Stockholm morning, Karlsson decided to snack on some jam in his friend Lillebror Svantenson's house. Fortunately for Karlsson, there wasn't anybody in his friend's house. Karlsson was not going to...
Input50 11 00 11 10 1
Output3
2 seconds
256 megabytes
['implementation', '*800']
E. Blood Cousins Returntime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputPolycarpus got hold of a family tree. The found tree describes the family relations of n people, numbered from 1 to n. Every person in this tree has at most one direct ancestor. Also, each person...
Input6pasha 0gerald 1gerald 1valera 2igor 3olesya 151 11 21 33 16 1
Output22010
3 seconds
256 megabytes
['binary search', 'data structures', 'dfs and similar', 'dp', 'sortings', '*2400']
D. Colorful Graphtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou've got an undirected graph, consisting of n vertices and m edges. We will consider the graph's vertices numbered with integers from 1 to n. Each vertex of the graph has a color. The color of the i-...
Input6 61 1 2 3 5 81 23 21 44 34 54 6
Output3
2 seconds
256 megabytes
['brute force', 'dfs and similar', 'graphs', '*1600']
C. Beauty Pageanttime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputGeneral Payne has a battalion of n soldiers. The soldiers' beauty contest is coming up, it will last for k days. Payne decided that his battalion will participate in the pageant. Now he has choose the ...
Input3 31 2 3
Output1 11 22 3 2
2 seconds
256 megabytes
['brute force', 'constructive algorithms', 'greedy', '*1600']
B. Increase and Decreasetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputPolycarpus has an array, consisting of n integers a1, a2, ..., an. Polycarpus likes it when numbers in an array match. That's why he wants the array to have as many equal numbers as possible. Fo...
Input22 1
Output1
2 seconds
256 megabytes
['greedy', 'math', '*1300']
A. Buggy Sortingtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputLittle boy Valera studies an algorithm of sorting an integer array. After studying the theory, he went on to the practical tasks. As a result, he wrote a program that sorts an array of n integers a1, a2...
Input1
Output-1
2 seconds
256 megabytes
['constructive algorithms', 'greedy', 'sortings', '*900']
H. Queries for Number of Palindromestime limit per test5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou've got a string s = s1s2... s|s| of length |s|, consisting of lowercase English letters. There also are q queries, each query is described by two integers li, ri (1 ≤ li ≤ ri ≤ |...
Inputcaaaba51 11 42 34 64 5
Output17342
5 seconds
256 megabytes
['dp', 'hashing', 'strings', '*1800']
G. Suggested Friendstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputPolycarpus works as a programmer in a start-up social network. His boss gave his a task to develop a mechanism for determining suggested friends. Polycarpus thought much about the task and came to t...
Input5Mike GeraldKate MikeKate TankGerald TankGerald David
Output5Mike 1Gerald 1Kate 1Tank 1David 2
2 seconds
256 megabytes
['brute force', 'graphs', '*2200']
F. Log Stream Analysistime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou've got a list of program warning logs. Each record of a log stream is a string in this format: "2012-MM-DD HH:MM:SS:MESSAGE" (without the quotes). String "MESSAGE" consists of spaces, upperca...
Input60 32012-03-16 16:15:25: Disk size is2012-03-16 16:15:25: Network failute2012-03-16 16:16:29: Cant write varlog2012-03-16 16:16:42: Unable to start process2012-03-16 16:16:43: Disk size is too small2012-03-16 16:16:53: Timeout detected
Output2012-03-16 16:16:43
2 seconds
256 megabytes
['binary search', 'brute force', 'implementation', 'strings', '*2000']
E. Mishap in Clubtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputPolycarpus just has been out of luck lately! As soon as he found a job in the "Binary Cat" cafe, the club got burgled. All ice-cream was stolen.On the burglary night Polycarpus kept a careful record of...
Input+-+-+
Output1
2 seconds
256 megabytes
['greedy', 'implementation', '*1400']
D. Restoring Tabletime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputRecently Polycarpus has learned the "bitwise AND" operation (which is also called "AND") of non-negative integers. Now he wants to demonstrate the school IT teacher his superb manipulation with the le...
Input1-1
Output0
2 seconds
256 megabytes
['constructive algorithms', 'greedy', '*1500']
C. Game with Coinstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputTwo pirates Polycarpus and Vasily play a very interesting game. They have n chests with coins, the chests are numbered with integers from 1 to n. Chest number i has ai coins. Polycarpus and Vasily mov...
Input11
Output-1
2 seconds
256 megabytes
['greedy', '*1700']
B. Internet Addresstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputVasya is an active Internet user. One day he came across an Internet resource he liked, so he wrote its address in the notebook. We know that the address of the written resource has format: <protocol...
Inputhttpsunrux
Outputhttp://sun.ru/x
2 seconds
256 megabytes
['implementation', 'strings', '*1100']
A. System Administratortime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputPolycarpus is a system administrator. There are two servers under his strict guidance — a and b. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b...
Input21 5 52 6 4
OutputLIVELIVE
2 seconds
256 megabytes
['implementation', '*800']
B. Undoubtedly Lucky Numberstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputPolycarpus loves lucky numbers. Everybody knows that lucky numbers are positive integers, whose decimal representation (without leading zeroes) contain only the lucky digits x and y. For exa...
Input10
Output10
2 seconds
256 megabytes
['bitmasks', 'brute force', 'dfs and similar', '*1600']
A. Dividing Orangetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputOne day Ms Swan bought an orange in a shop. The orange consisted of n·k segments, numbered with integers from 1 to n·k. There were k children waiting for Ms Swan at home. The children have recently le...
Input2 24 1
Output2 4 1 3
2 seconds
256 megabytes
['implementation', '*900']
E. Matrixtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputLet's consider an n × n square matrix, consisting of digits one and zero.We'll consider a matrix good, if it meets the following condition: in each row of the matrix all ones go in one group. That is, each row...
Input6100010110110011001010010000100011001
OutputYES011000111100000111001100100000000111
2 seconds
256 megabytes
['data structures', '*3000']
D. Cubestime limit per test5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputOne day Petya got a set of wooden cubes as a present from his mom. Petya immediately built a whole city from these cubes.The base of the city is an n × n square, divided into unit squares. The square's sides ar...
Input5 -1 25 0 0 0 10 0 0 0 20 0 0 1 20 0 0 0 22 2 2 2 3
Output20
5 seconds
256 megabytes
['data structures', 'dp', 'geometry', 'two pointers', '*2700']
C. Colorado Potato Beetletime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputOld MacDonald has a farm and a large potato field, (1010 + 1) × (1010 + 1) square meters in size. The field is divided into square garden beds, each bed takes up one square meter.Old McDonald k...
Input5R 8U 9L 9D 8L 2
Output101
2 seconds
256 megabytes
['dfs and similar', 'implementation', '*2200']
B. Hydratime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputOne day Petya got a birthday present from his mom: a book called "The Legends and Myths of Graph Theory". From this book Petya learned about a hydra graph.A non-oriented graph is a hydra, if it has a structure,...
Input9 12 2 31 22 31 31 42 54 54 66 56 77 58 79 1
OutputYES4 15 6 9 3 2
2 seconds
256 megabytes
['graphs', 'sortings', '*2000']
A. The Brand New Functiontime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputPolycarpus has a sequence, consisting of n non-negative integers: a1, a2, ..., an.Let's define function f(l, r) (l, r are integer, 1 ≤ l ≤ r ≤ n) for sequence a as an operation of bitwise OR of...
Input31 2 0
Output4
2 seconds
256 megabytes
['bitmasks', '*1600']
E. XOR on Segmenttime limit per test4 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou've got an array a, consisting of n integers a1, a2, ..., an. You are allowed to perform two operations on this array: Calculate the sum of current array elements on the segment [l, r], that is, co...
Input54 10 3 13 781 2 42 1 3 31 2 41 3 32 2 5 51 1 52 1 2 101 2 3
Output262203411
4 seconds
256 megabytes
['bitmasks', 'data structures', '*2000']
D. Disputetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputValera has n counters numbered from 1 to n. Some of them are connected by wires, and each of the counters has a special button.Initially, all the counters contain number 0. When you press a button on a certai...
Input5 52 34 11 55 32 11 1 2 0 2
Output21 2
2 seconds
256 megabytes
['dfs and similar', 'graphs', 'greedy', '*2100']
C. King's Pathtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe black king is standing on a chess field consisting of 109 rows and 109 columns. We will consider the rows of the field numbered with integers from 1 to 109 from top to bottom. The columns are similarl...
Input5 7 6 1135 3 86 7 115 2 5
Output4
2 seconds
256 megabytes
['dfs and similar', 'graphs', 'hashing', 'shortest paths', '*1800']
B. Big Segmenttime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputA coordinate line has n segments, the i-th segment starts at the position li and ends at the position ri. We will denote such a segment as [li, ri].You have suggested that one of the defined segments cove...
Input31 12 23 3
Output-1
2 seconds
256 megabytes
['implementation', 'sortings', '*1100']
A. Heads or Tailstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputPetya and Vasya are tossing a coin. Their friend Valera is appointed as a judge. The game is very simple. First Vasya tosses a coin x times, then Petya tosses a coin y times. If the tossing player gets...
Input3 2 1 1
Output32 13 13 2
2 seconds
256 megabytes
['brute force', 'implementation', '*1100']
F. Racetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe Old City is a rectangular city represented as an m × n grid of blocks. This city contains many buildings, straight two-way streets and junctions. Each junction and each building is exactly one block. All the...
Input3 10 12###########z1a1111b###########2 3 ab 2 8
Output2 8
2 seconds
256 megabytes
['brute force', 'implementation', '*2300']
E. Flightstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputLiLand is a country, consisting of n cities. The cities are numbered from 1 to n. The country is well known because it has a very strange transportation system. There are many one-way flights that make it pos...
Input3 31 22 31 3
OutputYes112
2 seconds
256 megabytes
['graphs', 'shortest paths', '*2600']
D. Numberstime limit per test4 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou have a sequence of n distinct integers a1, a2, ..., an (1 ≤ ai ≤ n). You want to remove some integers in such a way that the resulting sequence of integers satisfies the following three conditions: the r...
Input3 31 2 3
OutputYes31 2 3
4 seconds
256 megabytes
['*2900']
C. Mirror Boxtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputMirror Box is a name of a popular game in the Iranian National Amusement Park (INAP). There is a wooden box, 105 cm long and 100 cm high in this game. Some parts of the box's ceiling and floor are covered ...
Input50 50 710 F 1 8000020 T 1 8000030 T 81000 8200040 T 83000 8400050 T 85000 8600060 T 87000 8800070 F 81000 89000
Output100
2 seconds
256 megabytes
['geometry', 'implementation', '*2000']
B. Friendstime limit per test6 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou have n friends and you want to take m pictures of them. Exactly two of your friends should appear in each picture and no two pictures should contain the same pair of your friends. So if you have n = 3 fri...
Input3 11 2 3
Output3
6 seconds
256 megabytes
['binary search', 'bitmasks', 'data structures', 'math', '*2700']
A. Old Peykantime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere are n cities in the country where the Old Peykan lives. These cities are located on a straight line, we'll denote them from left to right as c1, c2, ..., cn. The Old Peykan wants to travel from city ...
Input4 61 2 5 22 3 3 4
Output10
2 seconds
256 megabytes
['greedy', '*1300']
F. TorCodertime limit per test3 secondsmemory limit per test256 megabytesinputinput.txtoutputoutput.txtA boy named Leo doesn't miss a single TorCoder contest round. On the last TorCoder round number 100666 Leo stumbled over the following problem. He was given a string s, consisting of n lowercase English letters, and m...
Input7 2aabcbaa1 35 7
Outputabacaba
3 seconds
256 megabytes
['data structures', '*2600']
E. Road Repairstime limit per test2 secondsmemory limit per test256 megabytesinputinput.txtoutputoutput.txtA country named Berland has n cities. They are numbered with integers from 1 to n. City with index 1 is the capital of the country. Some pairs of cities have monodirectional roads built between them. However, not ...
Input3 21 3 03 2 1
Output12
2 seconds
256 megabytes
['dfs and similar', 'graphs', 'greedy', '*2800']
B. Easy Tape Programmingtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere is a programming language in which every program is a non-empty sequence of "<" and ">" signs and digits. Let's explain how the interpreter of this programming language works. A program is...
Input7 41>3>22<1 34 77 71 7
Output0 1 0 1 0 0 0 0 0 0 2 2 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 3 2 1 0 0 0 0 0 0
2 seconds
256 megabytes
['brute force', 'implementation', '*1500']
A. Two Bags of Potatoestime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputValera had two bags of potatoes, the first of these bags contains x (x ≥ 1) potatoes, and the second — y (y ≥ 1) potatoes. Valera — very scattered boy, so the first bag of potatoes (it contains x ...
Input10 1 10
Output-1
1 second
256 megabytes
['greedy', 'implementation', 'math', '*1200']
E. Meeting Hertime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputUrpal lives in a big city. He has planned to meet his lover tonight. The city has n junctions numbered from 1 to n. The junctions are connected by m directed streets, all the roads have equal length. Urpa...
Input7 8 1 71 21 32 43 44 64 56 75 732 71 45 7
Output2
2 seconds
256 megabytes
['dp', 'graphs', 'shortest paths', '*2600']
D. Tape Programmingtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere is a programming language in which every program is a non-empty sequence of "<" and ">" signs and digits. Let's explain how the interpreter of this programming language works. A program is inte...
Input7 41>3>22<1 34 77 71 7
Output0 1 0 1 0 0 0 0 0 02 2 2 0 0 0 0 0 0 00 0 0 0 0 0 0 0 0 02 3 2 1 0 0 0 0 0 0
2 seconds
256 megabytes
['data structures', 'implementation', '*2900']
C. World Eater Brotherstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou must have heard of the two brothers dreaming of ruling the world. With all their previous plans failed, this time they decided to cooperate with each other in order to rule the world. As you ...
Input42 13 14 1
Output1
2 seconds
256 megabytes
['dfs and similar', 'dp', 'greedy', 'trees', '*2100']
B. Boring Partitiontime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThis problem is the most boring one you've ever seen. Given a sequence of integers a1, a2, ..., an and a non-negative integer h, our goal is to partition the sequence into two subsequences (not neces...
Input3 21 2 3
Output11 2 2
2 seconds
256 megabytes
['constructive algorithms', '*1800']
A. Not Wool Sequencestime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputA sequence of non-negative integers a1, a2, ..., an of length n is called a wool sequence if and only if there exists two integers l and r (1 ≤ l ≤ r ≤ n) such that . In other words each wool sequen...
Input3 2
Output6
1 second
256 megabytes
['constructive algorithms', 'math', '*1300']
E. Build Stringtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou desperately need to build some string t. For that you've got n more strings s1, s2, ..., sn. To build string t, you are allowed to perform exactly |t| (|t| is the length of string t) operations on th...
Inputbbaze3bzb 2aeb 3ba 10
Output8
2 seconds
256 megabytes
['flows', 'graphs', '*2000']
D. T-decompositiontime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou've got a undirected tree s, consisting of n nodes. Your task is to build an optimal T-decomposition for it. Let's define a T-decomposition as follows.Let's denote the set of all nodes s as v. Let'...
Input21 2
Output12 1 2
2 seconds
256 megabytes
['dfs and similar', 'graphs', 'greedy', 'trees', '*2000']
C. Primes on Intervaltime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou've decided to carry out a survey in the theory of prime numbers. Let us remind you that a prime number is a positive integer that has exactly two distinct positive integer divisors.Consider posi...
Input2 4 2
Output3
1 second
256 megabytes
['binary search', 'number theory', 'two pointers', '*1600']
B. Young Tabletime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou've got table a, consisting of n rows, numbered from 1 to n. The i-th line of table a contains ci cells, at that for all i (1 < i ≤ n) holds ci ≤ ci - 1. Let's denote s as the total number of cells of ...
Input33 2 14 3 56 12
Output21 1 2 22 1 3 1
2 seconds
256 megabytes
['implementation', 'sortings', '*1500']
A. Free Cashtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputValera 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 s...
Input48 08 108 108 45
Output2
2 seconds
256 megabytes
['implementation', '*1000']
B. Easy Number Challengetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputLet's denote d(n) as the number of divisors of a positive integer n. You are given three integers a, b and c. Your task is to calculate the following sum:Find the sum modulo 1073741824 (230).Inp...
Input2 2 2
Output20
2 seconds
256 megabytes
['implementation', 'number theory', '*1300']
A. Boy or Girltime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThose days, many boys use beautiful girls' photos as avatars in forums. So it is pretty hard to tell the gender of a user at the first glance. Last year, our hero went to a forum and had a nice chat with a...
Inputwjmzbmr
OutputCHAT WITH HER!
1 second
256 megabytes
['brute force', 'implementation', 'strings', '*800']
E. Number Challengetime limit per test3 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputLet's denote d(n) as the number of divisors of a positive integer n. You are given three integers a, b and c. Your task is to calculate the following sum:Find the sum modulo 1073741824 (230).InputThe...
Input2 2 2
Output20
3 seconds
512 megabytes
['combinatorics', 'dp', 'implementation', 'math', 'number theory', '*2600']
D. Graph Gametime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputIn computer science, there is a method called "Divide And Conquer By Node" to solve some hard problems about paths on a tree. Let's desribe how this method works by function:solve(t) (t is a tree): Chose...
Input53 42 32 40 41 2
Output13.166666666666666
2 seconds
256 megabytes
['graphs', '*3000']
C. Cyclical Questtime limit per test3 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputSome days ago, WJMZBMR learned how to answer the query "how many times does a string x occur in a string s" quickly by preprocessing the string s. But now he wants to make it harder.So he wants to ask ...
Inputbaabaabaaa5ababaaaabaaaaba
Output75735
3 seconds
512 megabytes
['data structures', 'string suffix structures', 'strings', '*2700']
B. Let's Play Osu!time limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou're playing a game called Osu! Here's a simplified version of it. There are n clicks in a game. For each click there are two outcomes: correct or bad. Let us denote correct as "O", bad as "X", then...
Input30.5 0.5 0.5
Output2.750000000000000
2 seconds
256 megabytes
['dp', 'math', 'probabilities', '*2000']
A. LCM Challengetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputSome days ago, I learned the concept of LCM (least common multiple). I've played with it for several times and I want to make a big number with it.But I also don't want to use many numbers, so I'll choo...
Input9
Output504
2 seconds
256 megabytes
['number theory', '*1600']
H. Merging Two Deckstime limit per test2 secondsmemory limit per test256 megabytesinputinput.txtoutputoutput.txtThere are two decks of cards lying on the table in front of you, some cards in these decks lay face up, some of them lay face down. You want to merge them into one deck in which each card is face down. You're...
Input31 0 141 1 1 1
Output1 4 5 6 7 2 335 6 7
2 seconds
256 megabytes
['constructive algorithms', 'greedy', '*2000']
G. Practicetime limit per test1 secondmemory limit per test256 megabytesinputinput.txtoutputoutput.txtLittle time is left before Berland annual football championship. Therefore the coach of team "Losewille Rangers" decided to resume the practice, that were indefinitely interrupted for uncertain reasons. Overall there a...
Input2
Output11 1
1 second
256 megabytes
['constructive algorithms', 'divide and conquer', 'implementation', '*1600']
F. Fencetime limit per test2 secondsmemory limit per test256 megabytesinputinput.txtoutputoutput.txtVasya should paint a fence in front of his own cottage. The fence is a sequence of n wooden boards arranged in a single row. Each board is a 1 centimeter wide rectangle. Let's number the board fence using numbers 1, 2, ....
Input45 73 3 4 1
Output3
2 seconds
256 megabytes
['dp', '*1800']
E. Champions' Leaguetime limit per test1 secondmemory limit per test256 megabytesinputinput.txtoutputoutput.txtIn the autumn of this year, two Russian teams came into the group stage of the most prestigious football club competition in the world — the UEFA Champions League. Now, these teams have already started to play...
Input81 3 1 7Barcelona 158Milan 90Spartak 46Anderlecht 48Celtic 32Benfica 87Zenit 79Malaga 16
OutputGroup A:BarcelonaBenficaSpartakCelticGroup B:MilanZenitAnderlechtMalaga
1 second
256 megabytes
['implementation', '*1600']
D. Cinematime limit per test1 secondmemory limit per test256 megabytesinputinput.txtoutputoutput.txtOverall there are m actors in Berland. Each actor has a personal identifier — an integer from 1 to m (distinct actors have distinct identifiers). Vasya likes to watch Berland movies with Berland actors, and he has k favo...
Input5 31 2 36firstfilm30 0 0secondfilm40 0 4 5thirdfilm12fourthfilm15fifthfilm14sixthfilm21 0
Output221112
1 second
256 megabytes
['implementation', '*1600']
C. Weathertime limit per test1 secondmemory limit per test256 megabytesinputinput.txtoutputoutput.txtScientists say a lot about the problems of global warming and cooling of the Earth. Indeed, such natural phenomena strongly influence all life on our planet.Our hero Vasya is quite concerned about the problems. He decid...
Input4-1 1 -2 1
Output1
1 second
256 megabytes
['dp', 'implementation', '*1300']
B. Readingtime limit per test1 secondmemory limit per test256 megabytesinputinput.txtoutputoutput.txtVasya is going to the Olympics in the city Ntown by train. The boy wants to read the textbook to prepare for the Olympics. He counted that he needed k hours for this. He also found that the light in the train changes ev...
Input5 320 10 30 40 10
Output201 3 4
1 second
256 megabytes
['sortings', '*1000']
A. Lefthanders and Righthanders time limit per test1 secondmemory limit per test256 megabytesinputinput.txtoutputoutput.txtOne fine October day a mathematics teacher Vasily Petrov went to a class and saw there n pupils who sat at the desks, two people at each desk. Vasily quickly realized that number n is even. Like a...
Input6LLRLLL
Output1 42 56 3
1 second
256 megabytes
['implementation', '*1200']
B. Non-square Equationtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputLet's consider equation:x2 + s(x)·x - n = 0,  where x, n are positive integers, s(x) is the function, equal to the sum of digits of number x in the decimal number system.You are given an integer n,...
Input2
Output1
1 second
256 megabytes
['binary search', 'brute force', 'math', '*1400']
A. Perfect Permutationtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputA permutation is a sequence of integers p1, p2, ..., pn, consisting of n distinct positive integers, each of them doesn't exceed n. Let's denote the i-th element of permutation p as pi. We'll call...
Input1
Output-1
2 seconds
256 megabytes
['implementation', 'math', '*800']
E. Quick Tortoisetime limit per test3 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputJohn Doe has a field, which is a rectangular table of size n × m. We assume that the field rows are numbered from 1 to n from top to bottom, and the field columns are numbered from 1 to m from left to ...
Input3 3....##.#.51 1 3 31 1 1 31 1 3 11 1 1 21 1 2 1
OutputNoYesYesYesYes
3 seconds
512 megabytes
['bitmasks', 'divide and conquer', 'dp', '*3000']
D. Fencetime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputJohn Doe has a crooked fence, consisting of n rectangular planks, lined up from the left to the right: the plank that goes i-th (1 ≤ i ≤ n) (from left to right) has width 1 and height hi. We will assume that th...
Input101 2 2 1 100 99 99 100 100 10061 41 23 41 59 1010 10
Output122029
3 seconds
256 megabytes
['binary search', 'data structures', 'string suffix structures', '*2900']
C. Doe Graphstime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputJohn Doe decided that some mathematical object must be named after him. So he invented the Doe graphs. The Doe graphs are a family of undirected graphs, each of them is characterized by a single non-negati...
Input10 51 21 31 41 52 32 42 53 43 54 5
Output1112123121
3 seconds
256 megabytes
['constructive algorithms', 'divide and conquer', 'dp', 'graphs', 'shortest paths', '*2600']
B. Tabletime limit per test4 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputJohn Doe has an n × m table. John Doe can paint points in some table cells, not more than one point in one table cell. John Doe wants to use such operations to make each square subtable of size n × n have exact...
Input5 6 1
Output45
4 seconds
256 megabytes
['bitmasks', 'combinatorics', 'dp', 'math', '*1900']
A. Cyclestime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputJohn Doe started thinking about graphs. After some thought he decided that he wants to paint an undirected graph, containing exactly k cycles of length 3. A cycle of length 3 is an unordered group of three dist...
Input1
Output3011101110
1 second
256 megabytes
['binary search', 'constructive algorithms', 'graphs', 'greedy', '*1600']
E. Cactustime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputA connected undirected graph is called a vertex cactus, if each vertex of this graph belongs to at most one simple cycle.A simple cycle in a undirected graph is a sequence of distinct vertices v1, v2, ..., vt ...
Input10 111 22 33 41 43 55 68 68 77 67 99 1061 23 56 99 29 39 10
Output222441
2 seconds
256 megabytes
['data structures', 'dfs and similar', 'dp', 'graphs', 'trees', '*2100']
D. Magic Boxtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputOne day Vasya was going home when he saw a box lying on the road. The box can be represented as a rectangular parallelepiped. Vasya needed no time to realize that the box is special, as all its edges are pa...
Input2 2 21 1 11 2 3 4 5 6
Output12
2 seconds
256 megabytes
['brute force', 'geometry', '*1600']
C. To Add or Not to Addtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputA piece of paper contains an array of n integers a1, a2, ..., an. Your task is to find a number that occurs the maximum number of times in this array.However, before looking for such number, you ...
Input5 36 3 4 0 2
Output3 4
2 seconds
256 megabytes
['binary search', 'sortings', 'two pointers', '*1600']
B. Magic, Wizardry and Wonderstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputVasya the Great Magician and Conjurer loves all kinds of miracles and wizardry. In one wave of a magic wand he can turn an object into something else. But, as you all know, there is no bet...
Input3 3 2
Output2 1 2
2 seconds
256 megabytes
['constructive algorithms', 'greedy', '*1500']
A. Teamtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputOne day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the star...
Input31 1 01 1 11 0 0
Output2
2 seconds
256 megabytes
['brute force', 'greedy', '*800']
B. T-primestime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputWe know that prime numbers are positive integers that have exactly two distinct positive divisors. Similarly, we'll call a positive integer t Т-prime, if t has exactly three distinct positive divisors.You ar...
Input34 5 6
OutputYESNONO
2 seconds
256 megabytes
['binary search', 'implementation', 'math', 'number theory', '*1300']
A. Dragonstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputKirito is stuck on a level of the MMORPG he is playing now. To move on in the game, he's got to defeat all n dragons that live on this level. Kirito and the dragons have strength, which is represented by an i...
Input2 21 99100 0
OutputYES
2 seconds
256 megabytes
['greedy', 'sortings', '*1000']
E. Giftstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputOnce upon a time an old man and his wife lived by the great blue sea. One day the old man went fishing and caught a real live gold fish. The fish said: "Oh ye, old fisherman! Pray set me free to the ocean and I...
Input3 13 10 20 30
Output1.000000000
2 seconds
256 megabytes
['combinatorics', 'dp', 'math', 'probabilities', '*2600']
D. Towerstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe city of D consists of n towers, built consecutively on a straight line. The height of the tower that goes i-th (from left to right) in the sequence equals hi. The city mayor decided to rebuild the city to ...
Input58 2 7 3 1
Output3
2 seconds
256 megabytes
['dp', 'greedy', 'two pointers', '*2100']
C. Trianglestime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputAlice and Bob don't play games anymore. Now they study properties of all sorts of graphs together. Alice invented the following task: she takes a complete undirected graph with n vertices, chooses some m ed...
Input5 51 21 32 32 43 4
Output3
2 seconds
256 megabytes
['combinatorics', 'graphs', 'math', '*1900']
B. Planetstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputGoa'uld Apophis captured Jack O'Neill's team again! Jack himself was able to escape, but by that time Apophis's ship had already jumped to hyperspace. But Jack knows on what planet will Apophis land. In order...
Input4 61 2 21 3 31 4 82 3 42 4 53 4 301 32 3 40
Output7
2 seconds
256 megabytes
['binary search', 'data structures', 'graphs', 'shortest paths', '*1700']
A. Shiftstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a table consisting of n rows and m columns. Each cell of the table contains a number, 0 or 1. In one move we can choose some row of the table and cyclically shift its values either one cell to th...
Input3 6101010000100100000
Output3
2 seconds
256 megabytes
['brute force', 'two pointers', '*1500']
E. The Road to Berland is Paved With Good Intentionstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputBerland has n cities, some of them are connected by bidirectional roads. For each road we know whether it is asphalted or not.The King of Berland Valera II wants to as...
Input4 41 2 12 4 04 3 13 2 0
Output43 2 1 3
1 second
256 megabytes
['2-sat', 'dfs and similar', 'dsu', 'graphs', '*1900']
D. Zigzagtime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe court wizard Zigzag wants to become a famous mathematician. For that, he needs his own theorem, like the Cauchy theorem, or his sum, like the Minkowski sum. But most of all he wants to have his sequence, l...
Input52 3 1 5 542 2 3 22 1 5 31 3 52 1 5 3
Output52638
3 seconds
256 megabytes
['data structures', '*2100']
C. Fractal Detectortime limit per test4 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputLittle Vasya likes painting fractals very much.He does it like this. First the boy cuts out a 2 × 2-cell square out of squared paper. Then he paints some cells black. The boy calls the cut out square...
Input6 11......*.****.*.*....**.***....*.*..***.*.....*.*.....**......*.*..
Output3
4 seconds
256 megabytes
['dp', 'hashing', '*2000']
B. Two Tablestime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou've got two rectangular tables with sizes na × ma and nb × mb cells. The tables consist of zeroes and ones. We will consider the rows and columns of both tables indexed starting from 1. Then we will def...
Input3 20110002 3001111
Output0 1
2 seconds
256 megabytes
['brute force', 'implementation', '*1400']
A. Is your horseshoe on the other hoof?time limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputValera the Horse is going to the party with friends. He has been following the fashion trends for a while, and he knows that it is very popular to wear all horseshoes of different...
Input1 7 3 3
Output1
2 seconds
256 megabytes
['implementation', '*800']
B. Effective Approachtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputOnce at a team training Vasya, Petya and Sasha got a problem on implementing linear search in an array.According to the boys, linear search works as follows. The array elements in a pre-selected or...
Input21 211
Output1 2
2 seconds
256 megabytes
['implementation', '*1100']
A. Where do I Turn?time limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputTrouble came from the overseas lands: a three-headed dragon Gorynych arrived. The dragon settled at point C and began to terrorize the residents of the surrounding villages.A brave hero decided to pu...
Input0 00 11 1
OutputRIGHT
2 seconds
256 megabytes
['geometry', '*1300']
E. Noble Knight's Pathtime limit per test4 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputIn Berland each feudal owns exactly one castle and each castle belongs to exactly one feudal.Each feudal, except one (the King) is subordinate to another feudal. A feudal can have any number of va...
Input30 1 252 1 3 1 01 22 1 3 1 02 1 3 1 12 1 3 1 2
Output2-1-12
4 seconds
256 megabytes
['data structures', 'trees', '*2900']