question
large_stringlengths
265
13.2k
Solve the programming task below in a Python markdown code block. Given n integers a1, a2,…, an and n integers p1, p2,…, pn, integer m. The operation of selecting the kth integer ak with a probability of pk [%] is performed for each k (1 ≀ k ≀ n), and 0 or more and n or less integers are selected. Find the expected nu...
Solve the programming task below in a Python markdown code block. Ikta loves fast programs. Recently, I'm trying to speed up the division program. However, it doesn't get much faster, so I thought it would be better to make it faster only for "common sense and typical" inputs. The problem Ikta is trying to solve is as...
Solve the programming task below in a Python markdown code block. Problem You brought a flat, holeless donut with a $ W $ horizontal $ H $ vertical $ H $ rectangle for ACPC. Place this donut on the $ 2 $ dimension plane coordinate $ (0,0) $ with the center of the donut so that the side of length H and the $ y $ axis ...
Solve the programming task below in a Python markdown code block. You are given a set $T$, which is a subset of $S$. The set $S$ consists of $0, 1, ... n-1$. Print all subsets of $T$. Note that we represent $0, 1, ... n-1$ as 00...0001, 00...0010, 00...0100, ..., 10...0000 in binary respectively and the integer repres...
Solve the programming task below in a Python markdown code block. Tanechka is shopping in the toy shop. There are exactly n toys in the shop for sale, the cost of the i-th toy is i burles. She wants to choose two toys in such a way that their total cost is k burles. How many ways to do that does she have? Each toy ap...
Solve the programming task below in a Python markdown code block. You are given n points on the plane. The polygon formed from all the n points is strictly convex, that is, the polygon is convex, and there are no three collinear points (i.e. lying in the same straight line). The points are numbered from 1 to n, in clo...
Solve the programming task below in a Python markdown code block. Someone give a strange birthday present to Ivan. It is hedgehog β€” connected undirected graph in which one vertex has degree at least 3 (we will call it center) and all other vertices has degree 1. Ivan thought that hedgehog is too boring and decided to ...
Solve the programming task below in a Python markdown code block. The kingdom of Lazyland is the home to n idlers. These idlers are incredibly lazy and create many problems to their ruler, the mighty King of Lazyland. Today k important jobs for the kingdom (k ≀ n) should be performed. Every job should be done by one...
Solve the programming task below in a Python markdown code block. The only difference between easy and hard versions is a number of elements in the array. You are given an array a consisting of n integers. The value of the i-th element of the array is a_i. You are also given a set of m segments. The j-th segment is ...
Solve the programming task below in a Python markdown code block. Polycarp is a head of a circus troupe. There are n β€” an even number β€” artists in the troupe. It is known whether the i-th artist can perform as a clown (if yes, then c_i = 1, otherwise c_i = 0), and whether they can perform as an acrobat (if yes, then a...
Solve the programming task below in a Python markdown code block. You are given a tree (an undirected connected acyclic graph) consisting of n vertices and n - 1 edges. A number is written on each edge, each number is either 0 (let's call such edges 0-edges) or 1 (those are 1-edges). Let's call an ordered pair of ver...
Solve the programming task below in a Python markdown code block. You are given a connected undirected weighted graph consisting of n vertices and m edges. You need to print the k-th smallest shortest path in this graph (paths from the vertex to itself are not counted, paths from i to j and from j to i are counted as...
Solve the programming task below in a Python markdown code block. Andrew was very excited to participate in Olympiad of Metropolises. Days flew by quickly, and Andrew is already at the airport, ready to go home. He has n rubles left, and would like to exchange them to euro and dollar bills. Andrew can mix dollar bills...
Solve the programming task below in a Python markdown code block. New Year is coming! Vasya has prepared a New Year's verse and wants to recite it in front of Santa Claus. Vasya's verse contains n parts. It takes a_i seconds to recite the i-th part. Vasya can't change the order of parts in the verse: firstly he recit...
Solve the programming task below in a Python markdown code block. Wu got hungry after an intense training session, and came to a nearby store to buy his favourite instant noodles. After Wu paid for his purchase, the cashier gave him an interesting task. You are given a bipartite graph with positive integers in all ve...
Solve the programming task below in a Python markdown code block. On February 14 Denis decided to give Valentine to Nastya and did not come up with anything better than to draw a huge red heart on the door of the length k (k β‰₯ 3). Nastya was very confused by this present, so she decided to break the door, throwing it ...
Solve the programming task below in a Python markdown code block. Shubham has a binary string s. A binary string is a string containing only characters "0" and "1". He can perform the following operation on the string any amount of times: * Select an index of the string, and flip the character at that index. This...
Solve the programming task below in a Python markdown code block. This is an interactive problem. Consider a fixed positive integer n. Two players, First and Second play a game as follows: 1. First considers the 2n numbers 1, 2, ..., 2n, and partitions them as he wants into n disjoint pairs. 2. Then, Second choo...
Solve the programming task below in a Python markdown code block. Vasya goes to visit his classmate Petya. Vasya knows that Petya's apartment number is n. There is only one entrance in Petya's house and the distribution of apartments is the following: the first floor contains 2 apartments, every other floor contains...
Solve the programming task below in a Python markdown code block. There are n cities in Berland. The city numbered 1 is the capital. Some pairs of cities are connected by a one-way road of length 1. Before the trip, Polycarp for each city found out the value of d_i β€” the shortest distance from the capital (the 1-st c...
Solve the programming task below in a Python markdown code block. You are given a string s, consisting only of characters '0' or '1'. Let |s| be the length of s. You are asked to choose some integer k (k > 0) and find a sequence a of length k such that: * 1 ≀ a_1 < a_2 < ... < a_k ≀ |s|; * a_{i-1} + 1 < a_i fo...
Solve the programming task below in a Python markdown code block. Dima overslept the alarm clock, which was supposed to raise him to school. Dima wonders if he will have time to come to the first lesson. To do this, he needs to know the minimum time it will take him to get from home to school. The city where Dima li...
Solve the programming task below in a Python markdown code block. Two players play a game. The game is played on a rectangular board with n Γ— m squares. At the beginning of the game two different squares of the board have two chips. The first player's goal is to shift the chips to the same square. The second player ai...
Solve the programming task below in a Python markdown code block. The Little Elephant has got a problem β€” somebody has been touching his sorted by non-decreasing array a of length n and possibly swapped some elements of the array. The Little Elephant doesn't want to call the police until he understands if he could ha...
Solve the programming task below in a Python markdown code block. Polycarpus 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 example, if x = 4, and y = 7, then numbers 47, 744, 4 are lucky. ...
Solve the programming task below in a Python markdown code block. This problem uses a simplified network topology model, please read the problem statement carefully and use it as a formal document as you develop the solution. Polycarpus continues working as a system administrator in a large corporation. The computer ...
Solve the programming task below in a Python markdown code block. George woke up and saw the current time s on the digital clock. Besides, George knows that he has slept for time t. Help George! Write a program that will, given time s and t, determine the time p when George went to bed. Note that George could have g...
Solve the programming task below in a Python markdown code block. Piegirl was asked to implement two table join operation for distributed database system, minimizing the network traffic. Suppose she wants to join two tables, A and B. Each of them has certain number of rows which are distributed on different number of...
Solve the programming task below in a Python markdown code block. Imagine that you are in a building that has exactly n floors. You can move between the floors in a lift. Let's number the floors from bottom to top with integers from 1 to n. Now you're on the floor number a. You are very bored, so you want to take the ...
Solve the programming task below in a Python markdown code block. Leonid wants to become a glass carver (the person who creates beautiful artworks by cutting the glass). He already has a rectangular w mm Γ— h mm sheet of glass, a diamond glass cutter and lots of enthusiasm. What he lacks is understanding of what to c...
Solve the programming task below in a Python markdown code block. Kyoya Ootori has a bag with n colored balls that are colored with k different colors. The colors are labeled from 1 to k. Balls of the same color are indistinguishable. He draws balls from the bag one by one until the bag is empty. He noticed that he dr...
Solve the programming task below in a Python markdown code block. You are given a rooted tree with root in vertex 1. Each vertex is coloured in some colour. Let's call colour c dominating in the subtree of vertex v if there are no other colours that appear in the subtree of vertex v more times than colour c. So it's ...
Solve the programming task below in a Python markdown code block. Bessie the cow and her best friend Elsie each received a sliding puzzle on Pi Day. Their puzzles consist of a 2 Γ— 2 grid and three tiles labeled 'A', 'B', and 'C'. The three tiles sit on top of the grid, leaving one grid cell empty. To make a move, Bess...
Solve the programming task below in a Python markdown code block. Ted has a pineapple. This pineapple is able to bark like a bulldog! At time t (in seconds) it barks for the first time. Then every s seconds after it, it barks twice with 1 second interval. Thus it barks at times t, t + s, t + s + 1, t + 2s, t + 2s + 1,...
Solve the programming task below in a Python markdown code block. You are given two strings a and b. You have to remove the minimum possible number of consecutive (standing one after another) characters from string b in such a way that it becomes a subsequence of string a. It can happen that you will not need to remov...
Solve the programming task below in a Python markdown code block. As you probably know, Anton goes to school. One of the school subjects that Anton studies is Bracketology. On the Bracketology lessons students usually learn different sequences that consist of round brackets (characters "(" and ")" (without quotes)). ...
Solve the programming task below in a Python markdown code block. Vasya and Petya take part in a Codeforces round. The round lasts for two hours and contains five problems. For this round the dynamic problem scoring is used. If you were lucky not to participate in any Codeforces round with dynamic problem scoring, he...
Solve the programming task below in a Python markdown code block. Vasily has a deck of cards consisting of n cards. There is an integer on each of the cards, this integer is between 1 and 100 000, inclusive. It is possible that some cards have the same integers on them. Vasily decided to sort the cards. To do this, h...
Solve the programming task below in a Python markdown code block. One day Alex was creating a contest about his friends, but accidentally deleted it. Fortunately, all the problems were saved, but now he needs to find them among other problems. But there are too many problems, to do it manually. Alex asks you to write...
Solve the programming task below in a Python markdown code block. You have a fraction <image>. You need to find the first occurrence of digit c into decimal notation of the fraction after decimal point. Input The first contains three single positive integers a, b, c (1 ≀ a < b ≀ 105, 0 ≀ c ≀ 9). Output Print posit...
Solve the programming task below in a Python markdown code block. Hacker Zhorik wants to decipher two secret messages he intercepted yesterday. Yeah message is a sequence of encrypted blocks, each of them consists of several bytes of information. Zhorik knows that each of the messages is an archive containing one or ...
Solve the programming task below in a Python markdown code block. The busses in Berland are equipped with a video surveillance system. The system records information about changes in the number of passengers in a bus after stops. If x is the number of passengers in a bus just before the current bus stop and y is the ...
Solve the programming task below in a Python markdown code block. Let's introduce a number system which is based on a roman digits. There are digits I, V, X, L which correspond to the numbers 1, 5, 10 and 50 respectively. The use of other roman digits is not allowed. Numbers in this system are written as a sequence o...
Solve the programming task below in a Python markdown code block. Task is simple. You are provided with a string of curly brackets and you have to do the following - Print 0 if the brackets are balanced. Print k if it is unbalanced, where k is the number of actions performed to balance it. Print -1 if it cannot be ba...
Solve the programming task below in a Python markdown code block. There are N integers X_1, X_2, \cdots, X_N, and we know that A_i \leq X_i \leq B_i. Find the number of different values that the median of X_1, X_2, \cdots, X_N can take. Constraints * 2 \leq N \leq 2 \times 10^5 * 1 \leq A_i \leq B_i \leq 10^9 * All ...
Solve the programming task below in a Python markdown code block. Given are 1-digit positive integers a and b. Consider these two strings: the concatenation of b copies of the digit a, and the concatenation of a copies of the digit b. Which of these is lexicographically smaller? Constraints * 1 \leq a \leq 9 * 1 \le...
Solve the programming task below in a Python markdown code block. E869120 is initially standing at the origin (0, 0) in a two-dimensional plane. He has N engines, which can be used as follows: * When E869120 uses the i-th engine, his X- and Y-coordinate change by x_i and y_i, respectively. In other words, if E869120...
Solve the programming task below in a Python markdown code block. There are N integers, A_1, A_2, ..., A_N, written on the blackboard. You will choose one of them and replace it with an integer of your choice between 1 and 10^9 (inclusive), possibly the same as the integer originally written. Find the maximum possib...
Solve the programming task below in a Python markdown code block. You are given a positive integer X. Find the largest perfect power that is at most X. Here, a perfect power is an integer that can be represented as b^p, where b is an integer not less than 1 and p is an integer not less than 2. Constraints * 1 ≀ X ≀ ...
Solve the programming task below in a Python markdown code block. Consider an infinite sequence a_1, a_2, … Initially, the values of all the terms are 0, and from this state we will sequentially perform Q operations. The i-th operation (1 ≀ i ≀ Q) is as follows: * For every positive integer j, add x_i to the value of...
Solve the programming task below in a Python markdown code block. You are given an integer N. Find the number of the positive divisors of N!, modulo 10^9+7. Constraints * 1≀N≀10^3 Input The input is given from Standard Input in the following format: N Output Print the number of the positive divisors of N!, mo...
Solve the programming task below in a Python markdown code block. Create a program that converts the date expressed in the Christian era to the Japanese calendar using the era name and outputs the date. The input is three integers, as shown in the example, in the order year, month, and day. Convert this as shown in th...
Solve the programming task below in a Python markdown code block. A popular game in a certain country, Pachimon Creature, has been remade and released in Japan. If you love games, after playing this game many times, you've come to think about how you can clear it the fastest. However, no matter how much you think abou...
Solve the programming task below in a Python markdown code block. In Japan, temperature is usually expressed using the Celsius (℃) scale. In America, they used the Fahrenheit (℉) scale instead. $20$ degrees Celsius is roughly equal to $68$ degrees Fahrenheit. A phrase such as "Today’s temperature is $68$ degrees" is c...
Solve the programming task below in a Python markdown code block. The fundamental idea in the JPEG compression algorithm is to sort coeffi- cient of given image by zigzag path and encode it. In this problem, we don’t discuss about details of the algorithm, but you are asked to make simple pro- gram. You are given sing...
Solve the programming task below in a Python markdown code block. You have a computer literacy course in your university. In the computer system, the login/logout records of all PCs in a day are stored in a file. Although students may use two or more PCs at a time, no one can log in to a PC which has been logged in by...
Solve the programming task below in a Python markdown code block. On a small planet named Bandai, a landing party of the starship Tadamigawa discovered colorful cubes traveling on flat areas of the planet surface, which the landing party named beds. A cube appears at a certain position on a bed, travels on the bed for...
Solve the programming task below in a Python markdown code block. Problem I chose creature observation as the theme of my free study during the summer vacation and purchased a creature observation kit. This creature prefers to live in a three-dimensional grid-like space. Only one animal can be placed in each cell. I...
Solve the programming task below in a Python markdown code block. Mr. Bill is shopping at the store. There are some coins in his wallet (10-yen coins, 50-yen coins, 100-yen coins, 500-yen coins), but he is now trying to consume as much of this coin as possible. In other words, by paying for the goods with an appropria...
Solve the programming task below in a Python markdown code block. Twin adventurers Rin and Len are searching for treasure in the Mirror Cave. The cave has two pairs of rooms, the Hall of Mirrors, and an expensive treasure lies behind the door of the room. For convenience, each of the two rooms is considered to have W...
Solve the programming task below in a Python markdown code block. Sunake is in the form of a polygonal line consisting of n vertices (without self-intersection). First, Sunake-kun's i-th vertex is at (xi, yi). You can move continuously by translating or rotating, but you cannot deform (change the length of the polygon...
Solve the programming task below in a Python markdown code block. J: City Santa decides to deliver a present to a city. The city has a rectangular shape divided into north-south $ H $ parcels x east-west $ W $ parcels, with one house delivering gifts to each parcel. The $ X $ th section from the north and the $ Y $...
Solve the programming task below in a Python markdown code block. Problem Given a permutation of length $ N $ $ P = \\ {P_1, P_2, \ ldots, P_N \\} $ and the integer $ K $. Determine if the permutation $ P $ can be monotonically increased by repeating the following operation any number of times $ 0 $ or more. * Choos...
Solve the programming task below in a Python markdown code block. Write a program which prints the central coordinate ($cx$,$cy$) and the radius $r$ of a circumscribed circle of a triangle which is constructed by three points ($x_1$, $y_1$), ($x_2$, $y_2$) and ($x_3$, $y_3$) on the plane surface. Constraints * $-100...
Solve the programming task below in a Python markdown code block. For a set $S$ of integers, perform a sequence of the following operations. Note that each value in $S$ must be unique. * insert($x$): Insert $x$ to $S$ and report the number of elements in $S$ after the operation. * find($x$): Report the number of $x$ ...
Solve the programming task below in a Python markdown code block. A bracket sequence is a string containing only characters "(" and ")". A regular bracket sequence is a bracket sequence that can be transformed into a correct arithmetic expression by inserting characters "1" and "+" between the original characters of t...
Solve the programming task below in a Python markdown code block. Ivan places knights on infinite chessboard. Initially there are n knights. If there is free cell which is under attack of at least 4 knights then he places new knight in this cell. Ivan repeats this until there are no such free cells. One can prove that...
Solve the programming task below in a Python markdown code block. You are given an undirected weighted connected graph with n vertices and m edges without loops and multiple edges. The i-th edge is e_i = (u_i, v_i, w_i); the distance between vertices u_i and v_i along the edge e_i is w_i (1 ≀ w_i). The graph is conne...
Solve the programming task below in a Python markdown code block. Dora loves adventures quite a lot. During some journey she encountered an amazing city, which is formed by n streets along the Eastern direction and m streets across the Southern direction. Naturally, this city has nm intersections. At any intersection ...
Solve the programming task below in a Python markdown code block. You are given a permutation p of n integers 1, 2, ..., n (a permutation is an array where each element from 1 to n occurs exactly once). Let's call some subsegment p[l, r] of this permutation special if p_l + p_r = max _{i = l}^{r} p_i. Please calculat...
Solve the programming task below in a Python markdown code block. Let's denote a k-step ladder as the following structure: exactly k + 2 wooden planks, of which * two planks of length at least k+1 β€” the base of the ladder; * k planks of length at least 1 β€” the steps of the ladder; Note that neither the base ...
Solve the programming task below in a Python markdown code block. There are b boys and g girls participating in Olympiad of Metropolises. There will be a board games tournament in the evening and n participants have accepted the invitation. The organizers do not know how many boys and girls are among them. Organizers...
Solve the programming task below in a Python markdown code block. Your favorite music streaming platform has formed a perfectly balanced playlist exclusively for you. The playlist consists of n tracks numbered from 1 to n. The playlist is automatic and cyclic: whenever track i finishes playing, track i+1 starts playin...
Solve the programming task below in a Python markdown code block. Long is a huge fan of CFC (Codeforces Fried Chicken). But the price of CFC is increasing, so he decides to breed the chicken on his own farm. His farm is presented by a rectangle grid with r rows and c columns. Some of these cells contain rice, others ...
Solve the programming task below in a Python markdown code block. Santa has to send presents to the kids. He has a large stack of n presents, numbered from 1 to n; the topmost present has number a_1, the next present is a_2, and so on; the bottom present has number a_n. All numbers are distinct. Santa has a list of m...
Solve the programming task below in a Python markdown code block. A popular reality show is recruiting a new cast for the third season! n candidates numbered from 1 to n have been interviewed. The candidate i has aggressiveness level l_i, and recruiting this candidate will cost the show s_i roubles. The show host rev...
Solve the programming task below in a Python markdown code block. Ayush and Ashish play a game on an unrooted tree consisting of n nodes numbered 1 to n. Players make the following move in turns: * Select any leaf node in the tree and remove it together with any edge which has this node as one of its endpoints. A ...
Solve the programming task below in a Python markdown code block. Masha has n types of tiles of size 2 Γ— 2. Each cell of the tile contains one integer. Masha has an infinite number of tiles of each type. Masha decides to construct the square of size m Γ— m consisting of the given tiles. This square also has to be a sy...
Solve the programming task below in a Python markdown code block. A Ministry for Defense sent a general to inspect the Super Secret Military Squad under the command of the Colonel SuperDuper. Having learned the news, the colonel ordered to all n squad soldiers to line up on the parade ground. By the military charter ...
Solve the programming task below in a Python markdown code block. You have an array a_1, a_2, ..., a_n. All a_i are positive integers. In one step you can choose three distinct indices i, j, and k (i β‰  j; i β‰  k; j β‰  k) and assign the sum of a_j and a_k to a_i, i. e. make a_i = a_j + a_k. Can you make all a_i lower o...
Solve the programming task below in a Python markdown code block. Let's say you are standing on the XY-plane at point (0, 0) and you want to reach point (n, n). You can move only in two directions: * to the right, i. e. horizontally and in the direction that increase your x coordinate, * or up, i. e. verticall...
Solve the programming task below in a Python markdown code block. Let's call an array a consisting of n positive (greater than 0) integers beautiful if the following condition is held for every i from 1 to n: either a_i = 1, or at least one of the numbers a_i - 1 and a_i - 2 exists in the array as well. For example: ...
Solve the programming task below in a Python markdown code block. You've got a rectangular table with length a and width b and the infinite number of plates of radius r. Two players play the following game: they take turns to put the plates on the table so that the plates don't lie on each other (but they can touch ea...
Solve the programming task below in a Python markdown code block. The Little Elephant loves playing with arrays. He has array a, consisting of n positive integers, indexed from 1 to n. Let's denote the number with index i as ai. Additionally the Little Elephant has m queries to the array, each query is characterised...
Solve the programming task below in a Python markdown code block. A number is called almost prime if it has exactly two distinct prime divisors. For example, numbers 6, 18, 24 are almost prime, while 4, 8, 9, 42 are not. Find the amount of almost prime numbers which are between 1 and n, inclusive. Input Input contai...
Solve the programming task below in a Python markdown code block. Iahub and his friend Floyd have started painting a wall. Iahub is painting the wall red and Floyd is painting it pink. You can consider the wall being made of a very large number of bricks, numbered 1, 2, 3 and so on. Iahub has the following scheme of...
Solve the programming task below in a Python markdown code block. George decided to prepare a Codesecrof round, so he has prepared m problems for the round. Let's number the problems with integers 1 through m. George estimates the i-th problem's complexity by integer bi. To make the round good, he needs to put at lea...
Solve the programming task below in a Python markdown code block. It's that time of the year when the Russians flood their countryside summer cottages (dachas) and the bus stop has a lot of people. People rarely go to the dacha on their own, it's usually a group, so the people stand in queue by groups. The bus stop q...
Solve the programming task below in a Python markdown code block. A triangular number is the number of dots in an equilateral triangle uniformly filled with dots. For example, three dots can be arranged in a triangle; thus three is a triangular number. The n-th triangular number is the number of dots in a triangle wit...
Solve the programming task below in a Python markdown code block. Let's define a forest as a non-directed acyclic graph (also without loops and parallel edges). One day Misha played with the forest consisting of n vertices. For each vertex v from 0 to n - 1 he wrote down two integers, degreev and sv, were the first in...
Solve the programming task below in a Python markdown code block. The clique problem is one of the most well-known NP-complete problems. Under some simplification it can be formulated as follows. Consider an undirected graph G. It is required to find a subset of vertices C of the maximum size such that any two of them...
Solve the programming task below in a Python markdown code block. Let's define the permutation of length n as an array p = [p1, p2, ..., pn] consisting of n distinct integers from range from 1 to n. We say that this permutation maps value 1 into the value p1, value 2 into the value p2 and so on. Kyota Ootori has just...
Solve the programming task below in a Python markdown code block. It is a balmy spring afternoon, and Farmer John's n cows are ruminating about link-cut cacti in their stalls. The cows, labeled 1 through n, are arranged so that the i-th cow occupies the i-th stall from the left. However, Elsie, after realizing that sh...
Solve the programming task below in a Python markdown code block. Barney is standing in a bar and starring at a pretty girl. He wants to shoot her with his heart arrow but he needs to know the distance between him and the girl to make his shot accurate. <image> Barney asked the bar tender Carl about this distance va...
Solve the programming task below in a Python markdown code block. Cowboy Beblop is a funny little boy who likes sitting at his computer. He somehow obtained two elastic hoops in the shape of 2D polygons, which are not necessarily convex. Since there's no gravity on his spaceship, the hoops are standing still in the ai...
Solve the programming task below in a Python markdown code block. You are given a rectangular table 3 Γ— n. Each cell contains an integer. You can move from one cell to another if they share a side. Find such path from the upper left cell to the bottom right cell of the table that doesn't visit any of the cells twice,...
Solve the programming task below in a Python markdown code block. Smith wakes up at the side of a dirty, disused bathroom, his ankle chained to pipes. Next to him is tape-player with a hand-written message "Play Me". He finds a tape in his own back pocket. After putting the tape in the tape-player, he sees a key hangi...
Solve the programming task below in a Python markdown code block. One day Nikita found the string containing letters "a" and "b" only. Nikita thinks that string is beautiful if it can be cut into 3 strings (possibly empty) without changing the order of the letters, where the 1-st and the 3-rd one contain only letter...
Solve the programming task below in a Python markdown code block. You are given a permutation p of length n. Remove one element from permutation to make the number of records the maximum possible. We remind that in a sequence of numbers a1, a2, ..., ak the element ai is a record if for every integer j (1 ≀ j < i) the...
Solve the programming task below in a Python markdown code block. Oleg writes down the history of the days he lived. For each day he decides if it was good or bad. Oleg calls a non-empty sequence of days a zebra, if it starts with a bad day, ends with a bad day, and good and bad days are alternating in it. Let us deno...