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. Turing Tapetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputINTERCAL is the oldest of esoteric programming languages. One of its many weird features is the method of character-based output, known as Turing Tape method. It converts an array of unsigned 8-bit intege...
InputHello, World!
Output23810811206419448262441682416162
2 seconds
256 megabytes
['implementation', '*1300']
F. Present to Momtime limit per test5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputHow many stars are there in the sky? A young programmer Polycarpus can't get this question out of his head! He took a photo of the starry sky using his digital camera and now he analyzes the resulting ...
Input4 6 2111000111100011011000111
Output6
5 seconds
256 megabytes
['binary search', 'two pointers', '*2000']
E. Yet Another Task with Queenstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputA queen is the strongest chess piece. In modern chess the queen can move any number of squares in any horizontal, vertical or diagonal direction (considering that there're no other pieces...
Input8 44 34 86 51 6
Output0 3 0 1 0 0 0 0 0
2 seconds
256 megabytes
['sortings', '*1700']
D. Subwaytime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputA subway scheme, classic for all Berland cities is represented by a set of n stations connected by n passages, each of which connects exactly two stations and does not pass through any others. Besides, in the ...
Input41 34 34 21 2
Output0 0 0 0
2 seconds
256 megabytes
['dfs and similar', 'graphs', '*1600']
C. The World is a Theatretime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere are n boys and m girls attending a theatre club. To set a play "The Big Bang Theory", they need to choose a group containing exactly t actors containing no less than 4 boys and no less th...
Input5 2 5
Output10
2 seconds
256 megabytes
['combinatorics', 'math', '*1400']
B. Opposites Attracttime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputEverybody knows that opposites attract. That is the key principle of the "Perfect Matching" dating agency. The "Perfect Matching" matchmakers have classified each registered customer by his interest...
Input5-3 3 0 0 3
Output3
2 seconds
256 megabytes
['implementation', 'math', '*1200']
A. cAPS lOCKtime limit per test0.5 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputwHAT DO WE NEED cAPS LOCK FOR?Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like th...
InputcAPS
OutputCaps
0.5 second
256 megabytes
['implementation', 'strings', '*1000']
J. Date calculationtime limit per test2 secondsmemory limit per test64 megabytesinputstandard inputoutputstandard outputIn Gregorian calendar a typical year consists of 365 days and 12 months. The numbers of days in the months are: 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31. If year index is divisible by 400, or di...
Input2011324
Output20 11
2 seconds
64 megabytes
['*special problem', '*1800']
I. Array sortingtime limit per test2 secondsmemory limit per test64 megabytesinputstandard inputoutputstandard outputSorting arrays is traditionally associated with high-level languages. How hard can it be in Befunge? Sort the given array in non-descending order.InputThe first line of input contains an integer n (1 ≤ n...
Input571973
Output1 3 7 7 9
2 seconds
64 megabytes
['*special problem', 'sortings', '*2300']
H. Balanced bracketstime limit per test2 secondsmemory limit per test64 megabytesinputstandard inputoutputstandard outputA sequence of brackets is called balanced if one can turn it into a valid math expression by adding characters «+» and «1». For example, sequences «(())()», «()» and «(()(()))» are balanced, while «)...
Input(()(()))()
OutputYES
2 seconds
64 megabytes
['*special problem', '*1600']
G. CAPS LOCK ONtime limit per test2 secondsmemory limit per test64 megabytesinputstandard inputoutputstandard outputYou are given a string which consists of letters and other characters. Convert it to uppercase, i.e., replace all lowercase letters with corresponding uppercase ones. Keep the rest of characters unchanged...
InputcOdEfOrCeS
OutputCODEFORCES
2 seconds
64 megabytes
['*special problem', '*1700']
F. Prime factorizationtime limit per test2 secondsmemory limit per test64 megabytesinputstandard inputoutputstandard outputYou are given an integer n. Output its prime factorization.If n = a1b1a2b2 ... akbk, where ak are prime numbers, the output of your program should look as follows: a1 a1 ... a1 a2 a2 ... a2 ... ak ...
Input245
Output5 7 7
2 seconds
64 megabytes
['*special problem', '*1600']
E. Tribonacci numberstime limit per test2 secondsmemory limit per test64 megabytesinputstandard inputoutputstandard outputTribonacci numbers are a sequence of numbers, defined as follows: t0 = t1 = 0, t2 = 1, ti = ti - 1 + ti - 2 + ti - 3.You are given n; calculate n-th tribonacci number modulo 26.InputThe only line of...
Input4
Output2
2 seconds
64 megabytes
['*special problem', '*1600']
D. Exponentiationtime limit per test2 secondsmemory limit per test64 megabytesinputstandard inputoutputstandard outputYou are given integers a, b and c. Calculate ab modulo c.InputInput data contains numbers a, b and c, one number per line. Each number is an integer between 1 and 100, inclusive.OutputOutput ab mod c.Ex...
Input2540
Output32
2 seconds
64 megabytes
['*special problem', '*1500']
C. Decimal sumtime limit per test2 secondsmemory limit per test64 megabytesinputstandard inputoutputstandard outputYou are given an array of integer numbers. Calculate the sum of its elements.InputThe first line of the input contains an integer n (1 ≤ n ≤ 100) — the size of the array. Next n lines contain the elements ...
Input512345
Output15
2 seconds
64 megabytes
['*special problem', '*1500']
B. Gnikool Ssalgtime limit per test2 secondsmemory limit per test64 megabytesinputstandard inputoutputstandard outputYou are given a string. Reverse its characters.InputThe only line of input contains a string between 1 and 100 characters long. Each character of the string has ASCII-code between 33 (exclamation mark) a...
Inputsecrofedoc
Outputcodeforces
2 seconds
64 megabytes
['*special problem', 'implementation', 'strings', '*1400']
A. Hexagonal numberstime limit per test2 secondsmemory limit per test64 megabytesinputstandard inputoutputstandard outputHexagonal numbers are figurate numbers which can be calculated using the formula hn = 2n2 - n. You are given n; calculate n-th hexagonal number.InputThe only line of input contains an integer n (1 ≤ ...
Input2
Output6
2 seconds
64 megabytes
['*special problem', 'implementation', '*900']
B. Students and Shoelacestime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputAnna and Maria are in charge of the math club for junior students. When the club gathers together, the students behave badly. They've brought lots of shoe laces to the club and got tied with ea...
Input3 31 22 33 1
Output0
2 seconds
256 megabytes
['brute force', 'dfs and similar', 'graphs', 'implementation', '*1200']
A. Cookiestime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputOlga came to visit the twins Anna and Maria and saw that they have many cookies. The cookies are distributed into bags. As there are many cookies, Olga decided that it's no big deal if she steals a bag. Howev...
Input11
Output1
2 seconds
256 megabytes
['implementation', '*900']
E. Birthdaytime limit per test4 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputAnna's got a birthday today. She invited many guests and cooked a huge (nearly infinite) birthday cake decorated by n banana circles of different sizes. Maria's birthday is about to start in 7 minutes too, a...
Input1 10 0 1
Output2
4 seconds
256 megabytes
['geometry', 'math', '*2900']
D. Numberstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputOne day Anna got the following task at school: to arrange several numbers in a circle so that any two neighboring numbers differs exactly by 1. Anna was given several numbers and arranged them in a circle to ...
Input41 2 3 2
OutputYES
2 seconds
256 megabytes
['constructive algorithms', 'implementation', '*2000']
C. Games with Rectangletime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputIn this task Anna and Maria play the following game. Initially they have a checkered piece of paper with a painted n × m rectangle (only the border, no filling). Anna and Maria move in turns and ...
Input3 3 1
Output1
2 seconds
256 megabytes
['combinatorics', 'dp', '*2000']
B. Stringtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputOne day in the IT lesson Anna and Maria learned about the lexicographic order.String x is lexicographically less than string y, if either x is a prefix of y (and x ≠ y), or there exists such i (1 ≤ i ≤ min(|x|...
Inputaa2
Outputa
2 seconds
256 megabytes
['brute force', 'constructive algorithms', 'hashing', 'implementation', 'string suffix structures', 'strings', '*2100']
A. Statuestime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputIn this task Anna and Maria play a game with a very unpleasant rival. Anna and Maria are in the opposite squares of a chessboard (8 × 8): Anna is in the upper right corner, and Maria is in the lower left one....
Input.......A................................................M.......
OutputWIN
2 seconds
256 megabytes
['dfs and similar', '*1500']
B. Canvas Framestime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputNicholas, a painter is going to paint several new canvases. Nicholas is sure that the canvases will turn out so great that each one will need framing and being hung on the wall. Frames are what Nicholas ...
Input52 4 3 2 3
Output1
1 second
256 megabytes
['implementation', '*1000']
A. Wasted Timetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputMr. Scrooge, a very busy man, decided to count the time he wastes on all sorts of useless stuff to evaluate the lost profit. He has already counted the time he wastes sleeping and eating. And now Mr. Scro...
Input2 10 010 0
Output0.200000000
2 seconds
256 megabytes
['geometry', '*900']
E. Pillstime limit per test1.5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputDoctor prescribed medicine to his patient. The medicine is represented by pills. Each pill consists of a shell and healing powder. The shell consists of two halves; each half has one of four colors — blue, re...
InputWWWBBWWWWWWBBWWWYYWBBWWWYYWBBWRRYYWBBWRRYYWBBWRRYYWBBWRR0 0 0 80 1 51 105
Output53W.W.W.B.B.W.W.W|.|.|.|.|.|.|.|W.W.W.B.B.W.W.W...............Y.Y.W.B.B.W.W-W|.|.|.|.|.|....Y.Y.W.B.B.W.R.R............|.|Y.Y.W.B.B.R.R.R|.|.|.|.|.|....Y.Y.W.B.B.W.R.R............|.|Y-Y.B-B.B-B.R.R
1.5 seconds
256 megabytes
['brute force', 'flows', '*2900']
D. Fibonacci Sumstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputFibonacci numbers have the following form:F1 = 1,  F2 = 2,  Fi = Fi - 1 + Fi - 2, i > 2.Let's consider some non-empty set S = {s1, s2, ..., sk}, consisting of different Fibonacci numbers. Let's find the...
Input21316
Output34
1 second
256 megabytes
['dp', 'math', '*2300']
C. E-reader Displaytime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputAfter years of hard work scientists invented an absolutely new e-reader display. The new display has a larger resolution, consumes less energy and its production is cheaper. And besides, one can bend...
Input50111010010100011001111110
Output4
2 seconds
256 megabytes
['constructive algorithms', 'greedy', '*2000']
B. Passwordtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputAsterix, Obelix and their temporary buddies Suffix and Prefix has finally found the Harmony temple. However, its doors were firmly locked and even Obelix had no luck opening them.A little later they found a ...
Inputfixprefixsuffix
Outputfix
2 seconds
256 megabytes
['binary search', 'dp', 'hashing', 'string suffix structures', 'strings', '*1700']
A. Hot Bathtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputBob is about to take a hot bath. There are two taps to fill the bath: a hot water tap and a cold water tap. The cold water's temperature is t1, and the hot water's temperature is t2. The cold water tap can t...
Input10 70 100 100 25
Output99 33
2 seconds
256 megabytes
['binary search', 'brute force', 'math', '*1900']
E. MST Companytime limit per test8 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe MST (Meaningless State Team) company won another tender for an important state reform in Berland.There are n cities in Berland, some pairs of the cities are connected by roads. Each road has its price...
Input4 5 21 2 12 3 13 4 11 3 31 4 2
Output31 5 2
8 seconds
256 megabytes
['binary search', 'graphs', '*2400']
D. Two progressionstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputAn arithmetic progression is such a non-empty sequence of numbers where the difference between any two successive numbers is constant. This constant number is called common difference. For example, th...
Input64 1 2 7 3 10
Output1 2 3 4 7 10
1 second
256 megabytes
['constructive algorithms', 'greedy', '*2200']
C. Hobbits' Partytime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputEveryone knows that hobbits love to organize all sorts of parties and celebrations. There are n hobbits living in the Shire. They decided to organize the Greatest Party (GP) that would last for several...
Input4
Output31 2 1 3 2 3
2 seconds
256 megabytes
['constructive algorithms', 'greedy', '*1600']
B. Simple XMLtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputLet's define a string <x> as an opening tag, where x is any small letter of the Latin alphabet. Each opening tag matches a closing tag of the type </x>, where x is the same letter.Tegs can be nested into e...
Input<a><b><c></c></b></a>
Output<a> <b> <c> </c> </b></a>
2 seconds
256 megabytes
['implementation', '*1000']
A. Measuring Lengths in Badentime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputLengths are measures in Baden in inches and feet. To a length from centimeters it is enough to know that an inch equals three centimeters in Baden and one foot contains 12 inches.You are gi...
Input42
Output1 2
2 seconds
256 megabytes
['math', '*1400']
B. Permutationstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given n k-digit integers. You have to rearrange the digits in the integers so that the difference between the largest and the smallest number was minimum. Digits should be rearranged by the same r...
Input6 4523727537523572353272537
Output2700
1 second
256 megabytes
['brute force', 'combinatorics', 'implementation', '*1400']
A. The number of positionstime limit per test0.5 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputPetr stands in line of n people, but he doesn't know exactly which position he occupies. He can say that there are no less than a people standing in front of him and no more than b people sta...
Input3 1 1
Output2
0.5 second
256 megabytes
['math', '*1000']
E. Mazetime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputA maze is represented by a tree (an undirected graph, where exactly one way exists between each pair of vertices). In the maze the entrance vertex and the exit vertex are chosen with some probability. The exit fr...
Input21 20 11 0
Output1.00000000000000000000
1 second
256 megabytes
['dfs and similar', 'dp', 'probabilities', 'trees', '*2500']
D. Stringtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a string s. Each pair of numbers l and r that fulfill the condition 1 ≤ l ≤ r ≤ |s|, correspond to a substring of the string s, starting in the position l and ending in the position r (inclusive)...
Inputaaaa
Output20
2 seconds
256 megabytes
['string suffix structures', '*2300']
C. Bracketstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputA two dimensional array is called a bracket array if each grid contains one of the two possible brackets — "(" or ")". A path through the two dimensional array cells is called monotonous if any two consecutiv...
Input1 2 11 2
Output()
1 second
256 megabytes
['combinatorics', 'dp', 'greedy', '*2300']
B. Squarestime limit per test0.5 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given an infinite checkered field. You should get from a square (x1; y1) to a square (x2; y2). Using the shortest path is not necessary. You can move on the field squares in four directions. That is,...
Input2 2 1 0 0 1
Output1
0.5 second
256 megabytes
['math', '*1800']
A. Prime Permutationtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a string s, consisting of small Latin letters. Let's denote the length of the string as |s|. The characters in the string are numbered starting from 1. Your task is to find out if it is...
Inputabc
OutputYESabc
1 second
256 megabytes
['implementation', 'number theory', 'strings', '*1300']
B. Lucky Substringtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputPetya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5...
Input047
Output4
2 seconds
256 megabytes
['brute force', 'implementation', '*1000']
A. Lucky Divisiontime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputPetya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5,...
Input47
OutputYES
2 seconds
256 megabytes
['brute force', 'number theory', '*1000']
E. Lucky Arraytime limit per test4 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputPetya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17...
Input3 62 3 4count 1 3count 1 2add 1 3 2count 1 3add 2 3 3count 1 3
Output1011
4 seconds
256 megabytes
['data structures', '*2400']
D. Lucky Segmentstime limit per test4 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputPetya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5,...
Input4 71 46 94 73 5
Output1
4 seconds
256 megabytes
['binary search', 'implementation', 'two pointers', '*2500']
C. Lucky Permutationtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputPetya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and...
Input7 4
Output1
2 seconds
256 megabytes
['brute force', 'combinatorics', 'number theory', '*1900']
B. Lucky Transformationtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputPetya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky ...
Input7 44727447
Output4427477
2 seconds
256 megabytes
['strings', '*1500']
A. Lucky Sumtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputPetya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, ...
Input2 7
Output33
2 seconds
256 megabytes
['implementation', '*1100']
J. Minimum Sumtime limit per test2 secondsmemory limit per test256 megabytesinputinput.txtoutputoutput.txtYou are given a set of n vectors on a plane. For each vector you are allowed to multiply any of its coordinates by -1. Thus, each vector vi = (xi, yi) can be transformed into one of the following four vectors: vi1...
Input5-7 -39 0-8 67 -84 -5
Output3 2 4 2
2 seconds
256 megabytes
['divide and conquer', 'geometry', 'sortings', '*1900']
I. Luck is in Numberstime limit per test1 secondmemory limit per test256 megabytesinputinput.txtoutputoutput.txtVasya has been collecting transport tickets for quite a while now. His collection contains several thousands of tram, trolleybus and bus tickets. Vasya is already fed up with the traditional definition of wha...
Input13
Output20
1 second
256 megabytes
['greedy', '*2200']
H. Brevity is Soul of Wittime limit per test2 secondsmemory limit per test256 megabytesinputinput.txtoutputoutput.txtAs we communicate, we learn much new information. However, the process of communication takes too much time. It becomes clear if we look at the words we use in our everyday speech.We can list many simple...
Input6privetspasibocodeforcesjavamarmeladnormalno
Outputpretspscdfsjavamamanorm
2 seconds
256 megabytes
['graph matchings', '*1800']
G. Boomtime limit per test1 secondmemory limit per test256 megabytesinputinput.txtoutputoutput.txtLet's consider the famous game called Boom (aka Hat) with simplified rules.There are n teams playing the game. Each team has two players. The purpose of the game is to explain the words to the teammate without using any wo...
Input2 21 1 1 11 1 1 13home1car1brother1
Output2 home car 1 brother
1 second
256 megabytes
['implementation', '*1800']
F. Spiderstime limit per test1 secondmemory limit per test256 megabytesinputinput.txtoutputoutput.txtOne day mum asked Petya to sort his toys and get rid of some of them. Petya found a whole box of toy spiders. They were quite dear to him and the boy didn't want to throw them away. Petya conjured a cunning plan: he wil...
Input13 1 2 2 3
Output2
1 second
256 megabytes
['dp', 'greedy', 'trees', '*1400']
E. Put Knight!time limit per test1 secondmemory limit per test256 megabytesinputinput.txtoutputoutput.txtPetya and Gena play a very interesting game "Put a Knight!" on a chessboard n × n in size. In this game they take turns to put chess pieces called "knights" on the board so that no two knights could threat each othe...
Input221
Output10
1 second
256 megabytes
['games', 'math', '*1400']
D. Three Sonstime limit per test1 secondmemory limit per test256 megabytesinputinput.txtoutputoutput.txtThree sons inherited from their father a rectangular corn fiend divided into n × m squares. For each square we know how many tons of corn grows on it. The father, an old farmer did not love all three sons equally, wh...
Input3 31 1 11 1 11 1 13 3 3
Output2
1 second
256 megabytes
['brute force', '*1400']
C. Winnie-the-Pooh and honeytime limit per test1 secondmemory limit per test256 megabytesinputinput.txtoutputoutput.txtAs we all know, Winnie-the-Pooh just adores honey. Ones he and the Piglet found out that the Rabbit has recently gotten hold of an impressive amount of this sweet and healthy snack. As you may guess, W...
Input3 315 8 10
Output9
1 second
256 megabytes
['implementation', 'math', '*1100']
B. Quiz Leaguetime limit per test1 secondmemory limit per test256 megabytesinputinput.txtoutputoutput.txtA team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks...
Input5 50 1 0 1 0
Output2
1 second
256 megabytes
['implementation', '*1100']
A. Elevatortime limit per test1 secondmemory limit per test256 megabytesinputinput.txtoutputoutput.txtA sky scraper with 1000 floors has been built in the city of N. It has modern superfast elevators to help to travel from one floor to another. Each elevator has two doors, the front one and the back one. If one goes in...
Inputfront1
OutputL
1 second
256 megabytes
['brute force', 'implementation', 'math', '*1000']
E. Alternative Realitytime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputIn the year of 3000 travelling around parallel realities became a routine thing. However one has to take into consideration that travelling like that is highly dangerous as you never know beforeha...
Input4 10 0 00 1 01 0 01 1 00 0 1
Output0.7071067812
2 seconds
256 megabytes
['geometry', '*2400']
D. String Transformationtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputLet s be a string whose length equals n. Its characters are numbered from 0 to n - 1, i and j are integers, 0 ≤ i < j < n. Let's define function f as follows:f(s, i, j) = s[i + 1... j - 1] + r(s...
InputDie Polizei untersucht eine Straftat im IT-Bereich.untersucht eine Straftat.hciereB-TI mi ieziloP eiD
Output11 36
2 seconds
256 megabytes
['hashing', 'strings', '*2500']
C. Education Reformtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYet another education system reform has been carried out in Berland recently. The innovations are as follows:An academic year now consists of n days. Each day pupils study exactly one of m subjects, b...
Input4 5 21 10 11 10 21 10 31 20 41 100 5
OutputYES2 83 104 205 40
1 second
256 megabytes
['dp', '*2000']
B. Before Examtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputVasya is about to take his first university exam in about several minutes. And it's not just some ordinary exam, it's on mathematical analysis. Of course, right now Vasya can only think of one thing: what...
Input7 37 15 0 19 10 5 1221 67 4
Output5.0000000000 15.5000000000
2 seconds
256 megabytes
['constructive algorithms', 'implementation', 'sortings', '*1900']
A. Epic Gametime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputSimon and Antisimon play a game. Initially each player receives one fixed positive integer that doesn't change throughout the game. Simon receives number a and Antisimon receives number b. They also have a ...
Input3 5 9
Output0
2 seconds
256 megabytes
['implementation', '*800']
E. Bertown roadstime limit per test5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputBertown has n junctions and m bidirectional roads. We know that one can get from any junction to any other one by the existing roads. As there were more and more cars in the city, traffic jams started t...
Input6 81 22 31 34 54 65 62 43 5
Output1 22 33 14 55 66 44 23 5
5 seconds
256 megabytes
['dfs and similar', 'graphs', '*2000']
D. Caesar's Legionstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputGaius 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 the...
Input2 1 1 10
Output1
2 seconds
256 megabytes
['dp', '*1700']
C. Fancy Numbertime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputA car number in Berland consists of exactly n digits. A number is called beautiful if it has at least k equal digits. Vasya wants to change the digits in his car's number so that the number became beauti...
Input6 5898196
Output4888188
2 seconds
256 megabytes
['brute force', 'greedy', 'sortings', 'strings', '*1900']
B. Present from Lenatime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputVasya's birthday is approaching and Lena decided to sew a patterned handkerchief to him as a present. Lena chose digits from 0 to n as the pattern. The digits will form a rhombus. The largest digit ...
Input2
Output 0 0 1 00 1 2 1 0 0 1 0 0
2 seconds
256 megabytes
['constructive algorithms', 'implementation', '*1000']
A. String Tasktime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputPetya started to attend programming lessons. On the first lesson his task was to write a simple program. The program was supposed to do the following: in the given string, consisting if uppercase and lowe...
Inputtour
Output.t.r
2 seconds
256 megabytes
['implementation', 'strings', '*1000']
E. Tree or not Treetime limit per test5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given an undirected connected graph G consisting of n vertexes and n edges. G contains no self-loops or multiple edges. Let each edge has two states: on and off. Initially all edges are switc...
Input5 22 14 32 42 54 15 41 5
Output33
5 seconds
256 megabytes
['data structures', 'divide and conquer', 'implementation', 'trees', '*2900']
D. Not Quick Transformationtime limit per test6 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputLet a be an array consisting of n numbers. The array's elements are numbered from 1 to n, even is an array consisting of the numerals whose numbers are even in a (eveni = a2i, 1 ≤ 2i ≤ n), od...
Input4 5 100002 3 4 52 4 1 31 2 2 42 3 3 51 3 3 4
Output05333
6 seconds
256 megabytes
['divide and conquer', 'math', '*2500']
C. Cycletime limit per test2.5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputA tournament is a directed graph without self-loops in which every pair of vertexes is connected by exactly one directed edge. That is, for any two vertexes u and v (u ≠ v) exists either an edge going from u ...
Input50010010000010011110111000
Output1 3 2
2.5 seconds
256 megabytes
['dfs and similar', 'graphs', '*2000']
B. Very Interesting Gametime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputIn a very ancient country the following game was popular. Two people play the game. Initially first player writes a string s1, consisting of exactly nine digits and representing a number that do...
Input1 10 7
Output2
2 seconds
256 megabytes
['brute force', 'number theory', '*1800']
A. Elevatortime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputAnd now the numerous qualifying tournaments for one of the most prestigious Russian contests Russian Codec Cup are over. All n participants who have made it to the finals found themselves in a huge m-floored ...
Input7 42 4 31 2 02 2 01 2 14 3 51 2 24 2 0
Output91071075
1 second
256 megabytes
['implementation', 'math', '*1300']
B. Little Pigs and Wolvestime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputOnce upon a time there were several little pigs and several wolves on a two-dimensional grid of size n × m. Each cell in this grid was either empty, containing one little pig, or containing one...
Input2 3PPWW.P
Output2
2 seconds
256 megabytes
['greedy', 'implementation', '*1100']
A. Tramtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputLinear Kingdom has exactly one tram line. It has n stops, numbered from 1 to n in the order of tram's movement. At the i-th stop ai passengers exit the tram, while bi passengers enter it. The tram is empty befor...
Input40 32 54 24 0
Output6
2 seconds
256 megabytes
['implementation', '*800']
E. Linear Kingdom Racestime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are a car race organizer and would like to arrange some races in Linear Kingdom.Linear Kingdom has n consecutive roads spanning from left to right. The roads are numbered from 1 to n from lef...
Input7 432321231 2 52 3 53 5 37 7 5
Output4
3 seconds
256 megabytes
['data structures', 'dp', '*2400']
D. Unambiguous Arithmetic Expressiontime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputLet's define an unambiguous arithmetic expression (UAE) as follows. All non-negative integers are UAE's. Integers may have leading zeroes (for example, 0000 and 0010 are considered...
Input1+2*3
Output2
2 seconds
256 megabytes
['dp', 'expression parsing', '*2600']
C. Plumbertime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputLittle John aspires to become a plumber! Today he has drawn a grid consisting of n rows and m columns, consisting of n × m square cells.In each cell he will draw a pipe segment. He can only draw four types of...
Input2 213..
Output2
3 seconds
256 megabytes
['math', '*2200']
B. Lawnmowertime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou have a garden consisting entirely of grass and weeds. Your garden is described by an n × m grid, with rows numbered 1 to n from top to bottom, and columns 1 to m from left to right. Each cell is identif...
Input4 5GWGGWGGWGGGWGGGWGGGG
Output11
2 seconds
256 megabytes
['greedy', 'sortings', '*1500']
A. Partytime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputA company has n employees numbered from 1 to n. Each employee either has no immediate manager or exactly one immediate manager, who is another employee with a different number. An employee A is said to be the s...
Input5-1121-1
Output3
3 seconds
256 megabytes
['dfs and similar', 'graphs', 'trees', '*900']
B. PFAST Inc.time limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputWhen little Petya grew up and entered the university, he started to take part in АСМ contests. Later he realized that he doesn't like how the АСМ contests are organised: the team could only have three memb...
Input3 1PetyaVasyaMashaPetya Vasya
Output2MashaPetya
2 seconds
256 megabytes
['bitmasks', 'brute force', 'graphs', '*1500']
A. Ciferatime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputWhen Petya went to school, he got interested in large numbers and what they were called in ancient times. For instance, he learned that the Russian word "tma" (which now means "too much to be counted") used to...
Input525
OutputYES1
2 seconds
256 megabytes
['math', '*1000']
E. Sleepingtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputOne day Vasya was lying in bed watching his electronic clock to fall asleep quicker.Vasya lives in a strange country, where days have h hours, and every hour has m minutes. Clock shows time in decimal number...
Input5 5 24 42 1
Output3
2 seconds
256 megabytes
['combinatorics', 'implementation', 'math', '*2700']
D. Museumtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputOne day as Petya and his friend Vasya were having one of their numerous trips, they decided to visit a museum castle. The museum has a specific shape: it consists of n rooms connected with m corridors so that ...
Input2 1 1 21 20.50.5
Output0.5000000000 0.5000000000
2 seconds
256 megabytes
['math', 'matrices', 'probabilities', '*2700']
C. Double Happinesstime limit per test3 secondsmemory limit per test128 megabytesinputstandard inputoutputstandard outputOn the math lesson a teacher asked each pupil to come up with his own lucky numbers. As a fan of number theory Peter chose prime numbers. Bob was more original. He said that number t is his lucky num...
Input3 5
Output1
3 seconds
128 megabytes
['brute force', 'math', 'number theory', '*2200']
B. Petr#time limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputLong ago, when Petya was a schoolboy, he was very much interested in the Petr# language grammar. During one lesson Petya got interested in the following question: how many different continuous substrings starti...
Inputroundroou
Output1
2 seconds
256 megabytes
['brute force', 'data structures', 'hashing', 'strings', '*2000']
A. Grammar Lessonstime limit per test5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputPetya got interested in grammar on his third year in school. He invented his own language called Petya's. Petya wanted to create a maximally simple language that would be enough to chat with friends, ...
Inputpetr
OutputYES
5 seconds
256 megabytes
['implementation', 'strings', '*1600']
B. Petya and Squaretime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputLittle Petya loves playing with squares. Mum bought him a square 2n × 2n in size. Petya marked a cell inside the square and now he is solving the following task.The task is to draw a broken line that...
Input4 1 1
OutputYES
2 seconds
256 megabytes
['implementation', 'math', '*1200']
A. Petya and Stringstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputLittle Petya loves presents. His mum bought him two strings of the same size for his birthday. The strings consist of uppercase and lowercase Latin letters. Now Petya wants to compare those two stri...
InputaaaaaaaA
Output0
2 seconds
256 megabytes
['implementation', 'strings', '*800']
E. Petya and Rectangletime limit per test5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputLittle Petya loves playing with rectangles. Mom bought Petya a rectangle divided into cells n × m in size (containing n rows, m columns). Petya marked two different cells of the rectangle and now ...
Input4 42 23 3
Output152 21 21 12 13 14 14 24 34 43 42 41 41 32 33 3
5 seconds
256 megabytes
['*2900']
D. Petya and Coloringtime limit per test5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputLittle Petya loves counting. He wants to count the number of ways to paint a rectangular checkered board of size n × m (n rows, m columns) in k colors. Besides, the coloring should have the followi...
Input2 2 1
Output1
5 seconds
256 megabytes
['combinatorics', 'dp', '*2300']
C. Petya and Spiderstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputLittle Petya loves training spiders. Petya has a board n × m in size. Each cell of the board initially has a spider sitting on it. After one second Petya chooses a certain action for each spider, an...
Input1 1
Output0
2 seconds
256 megabytes
['bitmasks', 'dp', 'dsu', '*2100']
B. Petya and Divisorstime limit per test5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputLittle Petya loves looking for numbers' divisors. One day Petya came across the following problem:You are given n queries in the form "xi yi". For each query Petya should count how many divisors of...
Input64 03 15 26 218 410000 3
Output3112222
5 seconds
256 megabytes
['binary search', 'data structures', 'number theory', '*1900']
A. Petya and Inequiationstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputLittle Petya loves inequations. Help him find n positive integers a1, a2, ..., an, such that the following two conditions are satisfied: a12 + a22 + ... + an2 ≥ x a1 + a2 + ... + an ≤ yInputThe...
Input5 15 15
Output44112
2 seconds
256 megabytes
['greedy', '*1400']
B. Lucky Stringtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputPetya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 1...
Input5
Outputabcda
2 seconds
256 megabytes
['constructive algorithms', 'strings', '*1100']
A. Nearly Lucky Numbertime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputPetya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky a...
Input40047
OutputNO
2 seconds
256 megabytes
['implementation', '*800']
E. Lucky Intervaltime limit per test4 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputPetya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5,...
Input7 4
Output17
4 seconds
512 megabytes
['brute force', 'math', '*2700']
D. Lucky Sortingtime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputPetya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, ...
Input24 7
Output0
3 seconds
256 megabytes
['constructive algorithms', 'sortings', '*2000']