question
large_stringlengths
265
13.2k
Solve the programming task below in a Python markdown code block. Iahub and Sorin are the best competitive programmers in their town. However, they can't both qualify to an important contest. The selection will be made with the help of a single problem. Blatnatalag, a friend of Iahub, managed to get hold of the proble...
Solve the programming task below in a Python markdown code block. There is a string S of length N consisting of characters 0 and 1. You will perform the following operation for each i = 1, 2, ..., m: - Arbitrarily permute the characters within the substring of S starting at the l_i-th character from the left and exte...
Solve the programming task below in a Python markdown code block. Gerald got a very curious hexagon for his birthday. The boy found out that all the angles of the hexagon are equal to $120^{\circ}$. Then he measured the length of its sides, and found that each of them is equal to an integer number of centimeters. Ther...
Solve the programming task below in a Python markdown code block. Squirrel Liss is interested in sequences. She also has preferences of integers. She thinks n integers a_1, a_2, ..., a_{n} are good. Now she is interested in good sequences. A sequence x_1, x_2, ..., x_{k} is called good if it satisfies the following t...
Solve the programming task below in a Python markdown code block. You are an intergalactic surgeon and you have an alien patient. For the purposes of this problem, we can and we will model this patient's body using a $2 \times (2k + 1)$ rectangular grid. The alien has $4k + 1$ distinct organs, numbered $1$ to $4k + 1$...
Solve the programming task below in a Python markdown code block. For a permutation P[1... N] of integers from 1 to N, function f is defined as follows: $f(i, j) = \left\{\begin{array}{ll}{P [ i ]} & {\text{if} j = 1} \\{f(P [ i ], j - 1)} & {\text{otherwise}} \end{array} \right.$ Let g(i) be the minimum positive ...
Solve the programming task below in a Python markdown code block. Enough is enough. Too many times it happened that Vasya forgot to dispose of garbage and his apartment stank afterwards. Now he wants to create a garbage disposal plan and stick to it. For each of next $n$ days Vasya knows $a_i$ — number of units of ga...
Solve the programming task below in a Python markdown code block. Is there anything better than going to the zoo after a tiresome week at work? No wonder Grisha feels the same while spending the entire weekend accompanied by pretty striped zebras. Inspired by this adventure and an accidentally found plasticine pack ...
Solve the programming task below in a Python markdown code block. You have a set of $n$ weights. You know that their masses are $a_1$, $a_2$, ..., $a_n$ grams, but you don't know which of them has which mass. You can't distinguish the weights. However, your friend does know the mass of each weight. You can ask your f...
Solve the programming task below in a Python markdown code block. Suppose you are given a string $s$ of length $n$ consisting of lowercase English letters. You need to compress it using the smallest possible number of coins. To compress the string, you have to represent $s$ as a concatenation of several non-empty str...
Solve the programming task below in a Python markdown code block. Molly Hooper has n different kinds of chemicals arranged in a line. Each of the chemicals has an affection value, The i-th of them has affection value a_{i}. Molly wants Sherlock to fall in love with her. She intends to do this by mixing a contiguous s...
Solve the programming task below in a Python markdown code block. In the evening Polycarp decided to analyze his today's travel expenses on public transport. The bus system in the capital of Berland is arranged in such a way that each bus runs along the route between two stops. Each bus has no intermediate stops. So ...
Solve the programming task below in a Python markdown code block. Vasya came up with his own weather forecasting method. He knows the information about the average air temperature for each of the last n days. Assume that the average air temperature for each day is integral. Vasya believes that if the average temperat...
Solve the programming task below in a Python markdown code block. Note that this is the first problem of the two similar problems. You can hack this problem only if you solve both problems. You are given a tree with $n$ nodes. In the beginning, $0$ is written on all edges. In one operation, you can choose any $2$ dis...
Solve the programming task below in a Python markdown code block. Boy Dima gave Julian a birthday present — set $B$ consisting of positive integers. However, he didn't know, that Julian hates sets, but enjoys bipartite graphs more than anything else! Julian was almost upset, but her friend Alex said, that he can buil...
Solve the programming task below in a Python markdown code block. Consider a table G of size n × m such that G(i, j) = GCD(i, j) for all 1 ≤ i ≤ n, 1 ≤ j ≤ m. GCD(a, b) is the greatest common divisor of numbers a and b. You have a sequence of positive integer numbers a_1, a_2, ..., a_{k}. We say that this sequence oc...
Solve the programming task below in a Python markdown code block. There is a square grid of size $n \times n$. Some cells are colored in black, all others are colored in white. In one operation you can select some rectangle and color all its cells in white. It costs $\min(h, w)$ to color a rectangle of size $h \times ...
Solve the programming task below in a Python markdown code block. Slime has a sequence of positive integers $a_1, a_2, \ldots, a_n$. In one operation Orac can choose an arbitrary subsegment $[l \ldots r]$ of this sequence and replace all values $a_l, a_{l + 1}, \ldots, a_r$ to the value of median of $\{a_l, a_{l + 1}...
Solve the programming task below in a Python markdown code block. Alyona's mother wants to present an array of n non-negative integers to Alyona. The array should be special. Alyona is a capricious girl so after she gets the array, she inspects m of its subarrays. Subarray is a set of some subsequent elements of the...
Solve the programming task below in a Python markdown code block. Moriarty has trapped n people in n distinct rooms in a hotel. Some rooms are locked, others are unlocked. But, there is a condition that the people in the hotel can only escape when all the doors are unlocked at the same time. There are m switches. Each...
Solve the programming task below in a Python markdown code block. User ainta loves to play with cards. He has a cards containing letter "o" and b cards containing letter "x". He arranges the cards in a row, and calculates the score of the deck by the formula below. At first, the score is 0. For each block of contigu...
Solve the programming task below in a Python markdown code block. Alice, Bob and Charlie are playing Card Game for Three, as below: - At first, each of the three players has a deck consisting of some number of cards. Alice's deck has N cards, Bob's deck has M cards, and Charlie's deck has K cards. Each card has a let...
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 interse...
Solve the programming task below in a Python markdown code block. The only difference between easy and hard versions is constraints. Nauuo is a girl who loves random picture websites. One day she made a random picture website by herself which includes $n$ pictures. When Nauuo visits the website, she sees exactly on...
Solve the programming task below in a Python markdown code block. Artem has an array of n positive integers. Artem decided to play with it. The game consists of n moves. Each move goes like this. Artem chooses some element of the array and removes it. For that, he gets min(a, b) points, where a and b are numbers that ...
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 t...
Solve the programming task below in a Python markdown code block. A monopole magnet is a magnet that only has one pole, either north or south. They don't actually exist since real magnets have two poles, but this is a programming contest problem, so we don't care. There is an $n\times m$ grid. Initially, you may plac...
Solve the programming task below in a Python markdown code block. Initially there was an array $a$ consisting of $n$ integers. Positions in it are numbered from $1$ to $n$. Exactly $q$ queries were performed on the array. During the $i$-th query some segment $(l_i, r_i)$ $(1 \le l_i \le r_i \le n)$ was selected and v...
Solve the programming task below in a Python markdown code block. The GCD table G of size n × n for an array of positive integers a of length n is defined by formula $g_{ij} = \operatorname{gcd}(a_{i}, a_{j})$ Let us remind you that the greatest common divisor (GCD) of two positive integers x and y is the greatest ...
Solve the programming task below in a Python markdown code block. There are $n$ points on the plane, the $i$-th of which is at $(x_i, y_i)$. Tokitsukaze wants to draw a strange rectangular area and pick all the points in the area. The strange area is enclosed by three lines, $x = l$, $y = a$ and $x = r$, as its left ...
Solve the programming task below in a Python markdown code block. You are an adventurer currently journeying inside an evil temple. After defeating a couple of weak zombies, you arrived at a square room consisting of tiles forming an n × n grid. The rows are numbered 1 through n from top to bottom, and the columns are...
Solve the programming task below in a Python markdown code block. As usual, Sereja has array a, its elements are integers: a[1], a[2], ..., a[n]. Let's introduce notation: $f(a, l, r) = \sum_{i = l}^{r} a [ i ] ; m(a) = \operatorname{max}_{1 \leq l \leq r \leq n} f(a, l, r)$ A swap operation is the following sequenc...
Solve the programming task below in a Python markdown code block. You are given n numbers a_1, a_2, ..., a_{n}. You can perform at most k operations. For each operation you can multiply one of the numbers by x. We want to make [Image] as large as possible, where $1$ denotes the bitwise OR. Find the maximum possible ...
Solve the programming task below in a Python markdown code block. Takahashi throws N dice, each having K sides with all integers from 1 to K. The dice are NOT pairwise distinguishable. For each i=2,3,...,2K, find the following value modulo 998244353: - The number of combinations of N sides shown by the dice such that...
Solve the programming task below in a Python markdown code block. Treeland is a country in which there are n towns connected by n - 1 two-way road such that it's possible to get from any town to any other town. In Treeland there are 2k universities which are located in different towns. Recently, the president sign...
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...
Solve the programming task below in a Python markdown code block. It's that time of the year, Felicity is around the corner and you can see people celebrating all around the Himalayan region. The Himalayan region has n gyms. The i-th gym has g_{i} Pokemon in it. There are m distinct Pokemon types in the Himalayan regi...
Solve the programming task below in a Python markdown code block. Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about max...
Solve the programming task below in a Python markdown code block. One day, little Vasya found himself in a maze consisting of (n + 1) rooms, numbered from 1 to (n + 1). Initially, Vasya is at the first room and to get out of the maze, he needs to get to the (n + 1)-th one. The maze is organized as follows. Each room ...
Solve the programming task below in a Python markdown code block. There are n types of coins in Byteland. Conveniently, the denomination of the coin type k divides the denomination of the coin type k + 1, the denomination of the coin type 1 equals 1 tugrick. The ratio of the denominations of coin types k + 1 and k equ...
Solve the programming task below in a Python markdown code block. Programmers working on a large project have just received a task to write exactly m lines of code. There are n programmers working on a project, the i-th of them makes exactly a_{i} bugs in every line of code that he writes. Let's call a sequence of n...
Solve the programming task below in a Python markdown code block. You are given a text consisting of n lines. Each line contains some space-separated words, consisting of lowercase English letters. We define a syllable as a string that contains exactly one vowel and any arbitrary number (possibly none) of consonants....
Solve the programming task below in a Python markdown code block. Emuskald is an avid horticulturist and owns the world's longest greenhouse — it is effectively infinite in length. Over the years Emuskald has cultivated n plants in his greenhouse, of m different plant species numbered from 1 to m. His greenhouse is v...
Solve the programming task below in a Python markdown code block. Alex doesn't like boredom. That's why whenever he gets bored, he comes up with games. One long winter evening he came up with a game and decided to play it. Given a sequence a consisting of n integers. The player can make several steps. In a single ste...
Solve the programming task below in a Python markdown code block. Polycarpus 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 all club visitors. Each time a visitor entered th...
Solve the programming task below in a Python markdown code block. Natasha travels around Mars in the Mars rover. But suddenly it broke down, namely — the logical scheme inside it. The scheme is an undirected tree (connected acyclic graph) with a root in the vertex $1$, in which every leaf (excluding root) is an input,...
Solve the programming task below in a Python markdown code block. Sereja has two sequences a and b and number p. Sequence a consists of n integers a_1, a_2, ..., a_{n}. Similarly, sequence b consists of m integers b_1, b_2, ..., b_{m}. As usual, Sereja studies the sequences he has. Today he wants to find the number of...
Solve the programming task below in a Python markdown code block. Hongcow is ruler of the world. As ruler of the world, he wants to make it easier for people to travel by road within their own countries. The world can be modeled as an undirected graph with n nodes and m edges. k of the nodes are home to the governmen...
Solve the programming task below in a Python markdown code block. You all know that the Library of Bookland is the largest library in the world. There are dozens of thousands of books in the library. Some long and uninteresting story was removed... The alphabet of Bookland is so large that its letters are denoted by...
Solve the programming task below in a Python markdown code block. After the war, the supersonic rocket became the most common public transportation. Each supersonic rocket consists of two "engines". Each engine is a set of "power sources". The first engine has $n$ power sources, and the second one has $m$ power sourc...
Solve the programming task below in a Python markdown code block. In Morse code, an letter of English alphabet is represented as a string of some length from $1$ to $4$. Moreover, each Morse code representation of an English letter contains only dots and dashes. In this task, we will represent a dot with a "0" and a d...
Solve the programming task below in a Python markdown code block. Mike and Ann are sitting in the classroom. The lesson is boring, so they decided to play an interesting game. Fortunately, all they need to play this game is a string $s$ and a number $k$ ($0 \le k < |s|$). At the beginning of the game, players are giv...
Solve the programming task below in a Python markdown code block. Little penguin Polo adores strings. But most of all he adores strings of length n. One day he wanted to find a string that meets the following conditions: The string consists of n lowercase English letters (that is, the string's length equals n), exac...
Solve the programming task below in a Python markdown code block. A dragon symbolizes wisdom, power and wealth. On Lunar New Year's Day, people model a dragon with bamboo strips and clothes, raise them with rods, and hold the rods high and low to resemble a flying dragon. A performer holding the rod low is represente...
Solve the programming task below in a Python markdown code block. Vasya has a graph containing both directed (oriented) and undirected (non-oriented) edges. There can be multiple edges between a pair of vertices. Vasya has picked a vertex s from the graph. Now Vasya wants to create two separate plans: to orient ea...
Solve the programming task below in a Python markdown code block. You have number a, whose decimal representation quite luckily contains digits 1, 6, 8, 9. Rearrange the digits in its decimal representation so that the resulting number will be divisible by 7. Number a doesn't contain any leading zeroes and contains d...
Solve the programming task below in a Python markdown code block. In Absurdistan, there are n towns (numbered 1 through n) and m bidirectional railways. There is also an absurdly simple road network — for each pair of different towns x and y, there is a bidirectional road between towns x and y if and only if there is ...
Solve the programming task below in a Python markdown code block. Recently, Tokitsukaze found an interesting game. Tokitsukaze had $n$ items at the beginning of this game. However, she thought there were too many items, so now she wants to discard $m$ ($1 \le m \le n$) special items of them. These $n$ items are marke...
Solve the programming task below in a Python markdown code block. It is a holiday season, and Koala is decorating his house with cool lights! He owns $n$ lights, all of which flash periodically. After taking a quick glance at them, Koala realizes that each of his lights can be described with two parameters $a_i$ and ...
Solve the programming task below in a Python markdown code block. Let $s$ be some string consisting of symbols "0" or "1". Let's call a string $t$ a substring of string $s$, if there exists such number $1 \leq l \leq |s| - |t| + 1$ that $t = s_l s_{l+1} \ldots s_{l + |t| - 1}$. Let's call a substring $t$ of string $s$...
Solve the programming task below in a Python markdown code block. As we all know Barney's job is "PLEASE" and he has not much to do at work. That's why he started playing "cups and key". In this game there are three identical cups arranged in a line from left to right. Initially key to Barney's heart is under the midd...
Solve the programming task below in a Python markdown code block. Alyona has a tree with n vertices. The root of the tree is the vertex 1. In each vertex Alyona wrote an positive integer, in the vertex i she wrote a_{i}. Moreover, the girl wrote a positive integer to every edge of the tree (possibly, different integer...
Solve the programming task below in a Python markdown code block. A group of n friends enjoys playing popular video game Toda 2. There is a rating system describing skill level of each player, initially the rating of the i-th friend is r_{i}. The friends decided to take part in the championship as a team. But they sh...
Solve the programming task below in a Python markdown code block. AtCoDeer the deer has N square tiles. The tiles are numbered 1 through N, and the number given to each tile is written on one side of the tile. Also, each corner of each tile is painted in one of the 1000 colors, which are represented by the integers 0 ...
Solve the programming task below in a Python markdown code block. You are given an unweighted tree with $n$ vertices. Recall that a tree is a connected undirected graph without cycles. Your task is to choose three distinct vertices $a, b, c$ on this tree such that the number of edges which belong to at least one of t...
Solve the programming task below in a Python markdown code block. Recently you have received two positive integer numbers $x$ and $y$. You forgot them, but you remembered a shuffled list containing all divisors of $x$ (including $1$ and $x$) and all divisors of $y$ (including $1$ and $y$). If $d$ is a divisor of both ...
Solve the programming task below in a Python markdown code block. The only difference between problems C1 and C2 is that all values in input of problem C1 are distinct (this condition may be false for problem C2). You are given a sequence $a$ consisting of $n$ integers. You are making a sequence of moves. During eac...
Solve the programming task below in a Python markdown code block. You are given a sequence $a_1, a_2, \dots, a_n$ consisting of $n$ integers. You can choose any non-negative integer $D$ (i.e. $D \ge 0$), and for each $a_i$ you can: add $D$ (only once), i. e. perform $a_i := a_i + D$, or subtract $D$ (only once), ...
Solve the programming task below in a Python markdown code block. There is a white sheet of paper lying on a rectangle table. The sheet is a rectangle with its sides parallel to the sides of the table. If you will take a look from above and assume that the bottom left corner of the table has coordinates $(0, 0)$, and ...
Solve the programming task below in a Python markdown code block. Let's denote a function $f(x)$ in such a way: we add $1$ to $x$, then, while there is at least one trailing zero in the resulting number, we remove that zero. For example, $f(599) = 6$: $599 + 1 = 600 \rightarrow 60 \rightarrow 6$; $f(7) = 8$: $7 + 1...
Solve the programming task below in a Python markdown code block. There are $n$ friends who want to give gifts for the New Year to each other. Each friend should give exactly one gift and receive exactly one gift. The friend cannot give the gift to himself. For each friend the value $f_i$ is known: it is either $f_i ...
Solve the programming task below in a Python markdown code block. You are given a huge decimal number consisting of $n$ digits. It is guaranteed that this number has no leading zeros. Each digit of this number is either 0 or 1. You may perform several (possibly zero) operations with this number. During each operation...
Solve the programming task below in a Python markdown code block. You are given three integers $a \le b \le c$. In one move, you can add $+1$ or $-1$ to any of these integers (i.e. increase or decrease any number by one). You can perform such operation any (possibly, zero) number of times, you can even perform this o...
Solve the programming task below in a Python markdown code block. You are given an array $a$ consisting of $n$ integer numbers. Let instability of the array be the following value: $\max\limits_{i = 1}^{n} a_i - \min\limits_{i = 1}^{n} a_i$. You have to remove exactly one element from this array to minimize instabil...
Solve the programming task below in a Python markdown code block. Petya studies at university. The current academic year finishes with $n$ special days. Petya needs to pass $m$ exams in those special days. The special days in this problem are numbered from $1$ to $n$. There are three values about each exam: $s_i$ — ...
Solve the programming task below in a Python markdown code block. Polycarp plays "Game 23". Initially he has a number $n$ and his goal is to transform it to $m$. In one move, he can multiply $n$ by $2$ or multiply $n$ by $3$. He can perform any number of moves. Print the number of moves needed to transform $n$ to $m$...
Solve the programming task below in a Python markdown code block. Let's call an array good if there is an element in the array that equals to the sum of all other elements. For example, the array $a=[1, 3, 3, 7]$ is good because there is the element $a_4=7$ which equals to the sum $1 + 3 + 3$. You are given an array ...
Solve the programming task below in a Python markdown code block. The only difference between the easy and the hard versions is constraints. A subsequence is a string that can be derived from another string by deleting some or no symbols without changing the order of the remaining symbols. Characters to be deleted ar...
Solve the programming task below in a Python markdown code block. You are given an undirected unweighted connected graph consisting of $n$ vertices and $m$ edges. It is guaranteed that there are no self-loops or multiple edges in the given graph. Your task is to find any spanning tree of this graph such that the degr...
Solve the programming task below in a Python markdown code block. Polycarp is going to participate in the contest. It starts at $h_1:m_1$ and ends at $h_2:m_2$. It is guaranteed that the contest lasts an even number of minutes (i.e. $m_1 \% 2 = m_2 \% 2$, where $x \% y$ is $x$ modulo $y$). It is also guaranteed that t...
Solve the programming task below in a Python markdown code block. -----Input----- The input contains a single integer a (1 ≤ a ≤ 64). -----Output----- Output a single integer. -----Examples----- Input 2 Output 1 Input 4 Output 2 Input 27 Output 5 Input 42 Output 6 Read the inputs from stdin solve the pr...
Solve the programming task below in a Python markdown code block. You are given $n$ segments on a number line; each endpoint of every segment has integer coordinates. Some segments can degenerate to points. Segments can intersect with each other, be nested in each other or even coincide. The intersection of a sequenc...
Solve the programming task below in a Python markdown code block. Vova's family is building the Great Vova Wall (named by Vova himself). Vova's parents, grandparents, grand-grandparents contributed to it. Now it's totally up to Vova to put the finishing touches. The current state of the wall can be respresented by a ...
Solve the programming task below in a Python markdown code block. The only difference between the easy and the hard versions is constraints. A subsequence is a string that can be derived from another string by deleting some or no symbols without changing the order of the remaining symbols. Characters to be deleted ar...
Solve the programming task below in a Python markdown code block. Masha has $n$ types of tiles of size $2 \times 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 \times m$ consisting of the given tiles. This square als...
Solve the programming task below in a Python markdown code block. You are given an integer sequence $1, 2, \dots, n$. You have to divide it into two sets $A$ and $B$ in such a way that each element belongs to exactly one set and $|sum(A) - sum(B)|$ is minimum possible. The value $|x|$ is the absolute value of $x$ and...
Solve the programming task below in a Python markdown code block. You are given a bracket sequence $s$ (not necessarily a regular one). 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 b...
Solve the programming task below in a Python markdown code block. You are given $n$ strings. Each string consists of lowercase English letters. Rearrange (reorder) the given strings in such a way that for every string, all strings that are placed before it are its substrings. String $a$ is a substring of string $b$ i...
Solve the programming task below in a Python markdown code block. There is an infinite board of square tiles. Initially all tiles are white. Vova has a red marker and a blue marker. Red marker can color $a$ tiles. Blue marker can color $b$ tiles. If some tile isn't white then you can't use marker of any color on it. ...
Solve the programming task below in a Python markdown code block. Find the price of a product before tax such that, when the consumption tax rate is 8 percent and 10 percent, the amount of consumption tax levied on it is A yen and B yen, respectively. (Yen is the currency of Japan.) Here, the price before tax must be ...
Solve the programming task below in a Python markdown code block. Polycarp has to solve exactly $n$ problems to improve his programming skill before an important programming competition. But this competition will be held very soon, most precisely, it will start in $k$ days. It means that Polycarp has exactly $k$ days ...
Solve the programming task below in a Python markdown code block. The only difference between easy and hard versions is that you should complete all the projects in easy version but this is not necessary in hard version. Polycarp is a very famous freelancer. His current rating is $r$ units. Some very rich customers ...
Solve the programming task below in a Python markdown code block. Let's call some square matrix with integer values in its cells palindromic if it doesn't change after the order of rows is reversed and it doesn't change after the order of columns is reversed. For example, the following matrices are palindromic: $\lef...
Solve the programming task below in a Python markdown code block. The only difference between easy and hard versions is that you should complete all the projects in easy version but this is not necessary in hard version. Polycarp is a very famous freelancer. His current rating is $r$ units. Some very rich customers ...
Solve the programming task below in a Python markdown code block. There is a river of width $n$. The left bank of the river is cell $0$ and the right bank is cell $n + 1$ (more formally, the river can be represented as a sequence of $n + 2$ cells numbered from $0$ to $n + 1$). There are also $m$ wooden platforms on a ...
Solve the programming task below in a Python markdown code block. The only difference between easy and hard versions is the length of the string. You are given a string $s$ and a string $t$, both consisting only of lowercase Latin letters. It is guaranteed that $t$ can be obtained from $s$ by removing some (possibly,...
Solve the programming task below in a Python markdown code block. $\text{A}$ -----Input----- The input contains a single floating-point number x with exactly 6 decimal places (0 < x < 5). -----Output----- Output two integers separated by a single space. Each integer should be between 1 and 10, inclusive. If sev...
Solve the programming task below in a Python markdown code block. You are given three integers $n$, $d$ and $k$. Your task is to construct an undirected tree on $n$ vertices with diameter $d$ and degree of each vertex at most $k$, or say that it is impossible. An undirected tree is a connected undirected graph with ...
Solve the programming task below in a Python markdown code block. You are given two strings $s$ and $t$ both of length $2$ and both consisting only of characters 'a', 'b' and 'c'. Possible examples of strings $s$ and $t$: "ab", "ca", "bb". You have to find a string $res$ consisting of $3n$ characters, $n$ characters...
Solve the programming task below in a Python markdown code block. An array of integers $p_1, p_2, \dots, p_n$ is called a permutation if it contains each number from $1$ to $n$ exactly once. For example, the following arrays are permutations: $[3, 1, 2]$, $[1]$, $[1, 2, 3, 4, 5]$ and $[4, 3, 1, 2]$. The following arra...