question
large_stringlengths
265
13.2k
Solve the programming task below in a Python markdown code block. La Confiserie d'ABC sells cakes at 4 dollars each and doughnuts at 7 dollars each. Determine if there is a way to buy some of them for exactly N dollars. You can buy two or more doughnuts and two or more cakes, and you can also choose to buy zero doughn...
Solve the programming task below in a Python markdown code block. We have a tree with N vertices. The vertices are numbered 0 through N - 1, and the i-th edge (0 ≀ i < N - 1) comnnects Vertex a_i and b_i. For each pair of vertices u and v (0 ≀ u, v < N), we define the distance d(u, v) as the number of edges in the pat...
Solve the programming task below in a Python markdown code block. Snuke signed up for a new website which holds programming competitions. He worried that he might forget his password, and he took notes of it. Since directly recording his password would cause him trouble if stolen, he took two notes: one contains the c...
Solve the programming task below in a Python markdown code block. Takahashi is playing with N cards. The i-th card has an integer X_i on it. Takahashi is trying to create as many pairs of cards as possible satisfying one of the following conditions: * The integers on the two cards are the same. * The sum of the int...
Solve the programming task below in a Python markdown code block. You are given circle $A$ with radius $r_a$ and with central coordinate $(x_a, y_a)$ and circle $B$ with radius $r_b$ and with central coordinate $(x_b, y_b)$. Write a program which prints: * "2" if $B$ is in $A$, * "-2" if $A$ is in $B$, * "1" if circ...
Solve the programming task below in a Python markdown code block. The brothers Hiroshi and Kenjiro came to Lake Inawashiro for fishing. The two decided to score as follows and compete with the total score of the fish they caught. * One char is a point * One yamame trout b points * Add c points for every 10 chars * Ad...
Solve the programming task below in a Python markdown code block. My arm is stuck and I can't pull it out. I tried to pick up something that had rolled over to the back of my desk, and I inserted my arm while illuminating it with the screen of my cell phone instead of a flashlight, but I accidentally got caught in so...
Solve the programming task below in a Python markdown code block. During a voyage of the starship Hakodate-maru (see Problem A), researchers found strange synchronized movements of stars. Having heard these observations, Dr. Extreme proposed a theory of "super stars". Do not take this term as a description of actors o...
Solve the programming task below in a Python markdown code block. Example Input crc 1 Output crc The input will be give Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
Solve the programming task below in a Python markdown code block. Problem Yamano Mifune Gakuen's 1st grade G group is a class where female students carrying misfortune gather. They face various challenges every day with the goal of being happy. In their class, they can take practical happiness courses as part of the...
Solve the programming task below in a Python markdown code block. Find places where a string P is found within a text T. Print all indices of T where P found. The indices of T start with 0. Constraints * 1 ≀ length of T ≀ 1000000 * 1 ≀ length of P ≀ 10000 * The input consists of alphabetical characters and digits I...
Solve the programming task below in a Python markdown code block. In the online judge system, a judge file may include multiple datasets to check whether the submitted program outputs a correct answer for each test case. This task is to practice solving a problem with multiple datasets. Write a program which reads an...
Solve the programming task below in a Python markdown code block. You are given two strings s and t. Both strings have length n and consist of lowercase Latin letters. The characters in the strings are numbered from 1 to n. You can successively perform the following move any number of times (possibly, zero): * swa...
Solve the programming task below in a Python markdown code block. You are given a binary string s. Find the number of distinct cyclical binary strings of length n which contain s as a substring. The cyclical string t contains s as a substring if there is some cyclical shift of string t, such that s is a substring of...
Solve the programming task below in a Python markdown code block. You came to the exhibition and one exhibit has drawn your attention. It consists of n stacks of blocks, where the i-th stack consists of a_i blocks resting on the surface. The height of the exhibit is equal to m. Consequently, the number of blocks in e...
Solve the programming task below in a Python markdown code block. The Fair Nut is going to travel to the Tree Country, in which there are n cities. Most of the land of this country is covered by forest. Furthermore, the local road system forms a tree (connected graph without cycles). Nut wants to rent a car in the cit...
Solve the programming task below in a Python markdown code block. You are policeman and you are playing a game with Slavik. The game is turn-based and each turn consists of two phases. During the first phase you make your move and during the second phase Slavik makes his move. There are n doors, the i-th door initial...
Solve the programming task below in a Python markdown code block. Alice lives on a flat planet that can be modeled as a square grid of size n Γ— n, with rows and columns enumerated from 1 to n. We represent the cell at the intersection of row r and column c with ordered pair (r, c). Each cell in the grid is either land...
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 ≀ m ≀ n) special items of them. These n items are marked with indic...
Solve the programming task below in a Python markdown code block. This is an easier version of the next problem. The difference is only in constraints. You are given a rectangular n Γ— m matrix a. In one move you can choose any column and cyclically shift elements in this column. You can perform this operation as many...
Solve the programming task below in a Python markdown code block. This problem is interactive. We have hidden an array a of n pairwise different numbers (this means that no two numbers are equal). You can get some information about this array using a new device you just ordered on Amazon. This device can answer que...
Solve the programming task below in a Python markdown code block. [3R2 - Standby for Action](https://www.youtube.com/watch?v=P2ZVC9aoiKo) Our dear Cafe's owner, JOE Miller, will soon take part in a new game TV-show "1 vs. n"! The game goes in rounds, where in each round the host asks JOE and his opponents a common q...
Solve the programming task below in a Python markdown code block. Nikolay has only recently started in competitive programming, but already qualified to the finals of one prestigious olympiad. There going to be n participants, one of whom is Nikolay. Like any good olympiad, it consists of two rounds. Tired of the trad...
Solve the programming task below in a Python markdown code block. The only difference between easy and hard versions is constraints. You are given a sequence a consisting of n positive integers. Let's define a three blocks palindrome as the sequence, consisting of at most two distinct elements (let these elements ar...
Solve the programming task below in a Python markdown code block. Maria is the most active old lady in her house. She was tired of sitting at home. She decided to organize a ceremony against the coronavirus. She has n friends who are also grannies (Maria is not included in this number). The i-th granny is ready to at...
Solve the programming task below in a Python markdown code block. You are given a tree with n vertices. You are allowed to modify the structure of the tree through the following multi-step operation: 1. Choose three vertices a, b, and c such that b is adjacent to both a and c. 2. For every vertex d other than b ...
Solve the programming task below in a Python markdown code block. There are n people who want to participate in a boat competition. The weight of the i-th participant is w_i. Only teams consisting of two people can participate in this competition. As an organizer, you think that it's fair to allow only teams with the ...
Solve the programming task below in a Python markdown code block. Let's call a sequence b_1, b_2, b_3 ..., b_{k - 1}, b_k almost increasing if $$$min(b_1, b_2) ≀ min(b_2, b_3) ≀ ... ≀ min(b_{k - 1}, b_k).$$$ In particular, any sequence with no more than two elements is almost increasing. You are given a sequence of i...
Solve the programming task below in a Python markdown code block. Once Bob took a paper stripe of n squares (the height of the stripe is 1 square). In each square he wrote an integer number, possibly negative. He became interested in how many ways exist to cut this stripe into two pieces so that the sum of numbers fro...
Solve the programming task below in a Python markdown code block. You've decided to carry out a survey in the theory of prime numbers. Let us remind you that a prime number is a positive integer that has exactly two distinct positive integer divisors. Consider positive integers a, a + 1, ..., b (a ≀ b). You want to f...
Solve the programming task below in a Python markdown code block. Roma (a popular Russian name that means 'Roman') loves the Little Lvov Elephant's lucky numbers. Let us remind you that lucky numbers are positive integers whose decimal representation only contains lucky digits 4 and 7. For example, numbers 47, 744, 4...
Solve the programming task below in a Python markdown code block. A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. You...
Solve the programming task below in a Python markdown code block. Currently Tiny is learning Computational Geometry. When trying to solve a problem called "The Closest Pair Of Points In The Plane", he found that a code which gave a wrong time complexity got Accepted instead of Time Limit Exceeded. The problem is the ...
Solve the programming task below in a Python markdown code block. Berland scientists know that the Old Berland language had exactly n words. Those words had lengths of l1, l2, ..., ln letters. Every word consisted of two letters, 0 and 1. Ancient Berland people spoke quickly and didn’t make pauses between the words, b...
Solve the programming task below in a Python markdown code block. Inna likes sweets and a game called the "Candy Matrix". Today, she came up with the new game "Candy Matrix 2: Reload". The field for the new game is a rectangle table of size n Γ— m. Each line of the table contains one cell with a dwarf figurine, one ce...
Solve the programming task below in a Python markdown code block. Your city has n junctions. There are m one-way roads between the junctions. As a mayor of the city, you have to ensure the security of all the junctions. To ensure the security, you have to build some police checkposts. Checkposts can only be built in ...
Solve the programming task below in a Python markdown code block. There are n children in Jzzhu's school. Jzzhu is going to give some candies to them. Let's number all the children from 1 to n. The i-th child wants to get at least ai candies. Jzzhu asks children to line up. Initially, the i-th child stands at the i-t...
Solve the programming task below in a Python markdown code block. One way to create a task is to learn from life. You can choose some experience in real life, formalize it and then you will get a new task. Let's think about a scene in real life: there are lots of people waiting in front of the elevator, each person w...
Solve the programming task below in a Python markdown code block. Mike is the president of country What-The-Fatherland. There are n bears living in this country besides Mike. All of them are standing in a line and they are numbered from 1 to n from left to right. i-th bear is exactly ai feet high. <image> A group o...
Solve the programming task below in a Python markdown code block. Pasha has recently bought a new phone jPager and started adding his friends' phone numbers there. Each phone number consists of exactly n digits. Also Pasha has a number k and two sequences of length n / k (n is divisible by k) a1, a2, ..., an / k and ...
Solve the programming task below in a Python markdown code block. Calculate the value of the sum: n mod 1 + n mod 2 + n mod 3 + ... + n mod m. As the result can be very large, you should print the value modulo 109 + 7 (the remainder when divided by 109 + 7). The modulo operator a mod b stands for the remainder after ...
Solve the programming task below in a Python markdown code block. Bad news came to Mike's village, some thieves stole a bunch of chocolates from the local factory! Horrible! Aside from loving sweet things, thieves from this area are known to be very greedy. So after a thief takes his number of chocolates for himself...
Solve the programming task below in a Python markdown code block. ZS the Coder and Chris the Baboon are travelling to Udayland! To get there, they have to get on the special IOI bus. The IOI bus has n rows of seats. There are 4 seats in each row, and the seats are separated into pairs by a walkway. When ZS and Chris c...
Solve the programming task below in a Python markdown code block. A new innovative ticketing systems for public transport is introduced in Bytesburg. Now there is a single travel card for all transport. To make a trip a passenger scan his card and then he is charged according to the fare. The fare is constructed in t...
Solve the programming task below in a Python markdown code block. During the lesson small girl Alyona works with one famous spreadsheet computer program and learns how to edit tables. Now she has a table filled with integers. The table consists of n rows and m columns. By ai, j we will denote the integer located at t...
Solve the programming task below in a Python markdown code block. Your search for Heidi is over – you finally found her at a library, dressed up as a human. In fact, she has spent so much time there that she now runs the place! Her job is to buy books and keep them at the library so that people can borrow and read the...
Solve the programming task below in a Python markdown code block. It's well known that the best way to distract from something is to do one's favourite thing. Job is such a thing for Leha. So the hacker began to work hard in order to get rid of boredom. It means that Leha began to hack computers all over the world. F...
Solve the programming task below in a Python markdown code block. Polycarp plans to conduct a load testing of its new project Fakebook. He already agreed with his friends that at certain points in time they will send requests to Fakebook. The load testing will last n minutes and in the i-th minute friends will send ai...
Solve the programming task below in a Python markdown code block. β€” This is not playing but duty as allies of justice, Nii-chan! β€” Not allies but justice itself, Onii-chan! With hands joined, go everywhere at a speed faster than our thoughts! This time, the Fire Sisters β€” Karen and Tsukihi β€” is heading for somewhere...
Solve the programming task below in a Python markdown code block. While Vasya finished eating his piece of pizza, the lesson has already started. For being late for the lesson, the teacher suggested Vasya to solve one interesting problem. Vasya has an array a and integer x. He should find the number of different order...
Solve the programming task below in a Python markdown code block. Jamie has recently found undirected weighted graphs with the following properties very interesting: * The graph is connected and contains exactly n vertices and m edges. * All edge weights are integers and are in range [1, 109] inclusive. * The...
Solve the programming task below in a Python markdown code block. Valya and Tolya are an ideal pair, but they quarrel sometimes. Recently, Valya took offense at her boyfriend because he came to her in t-shirt with lettering that differs from lettering on her pullover. Now she doesn't want to see him and Tolya is seati...
Solve the programming task below in a Python markdown code block. To make a paper airplane, one has to use a rectangular piece of paper. From a sheet of standard size you can make s airplanes. A group of k people decided to make n airplanes each. They are going to buy several packs of paper, each of them containing p...
Solve the programming task below in a Python markdown code block. Nastya owns too many arrays now, so she wants to delete the least important of them. However, she discovered that this array is magic! Nastya now knows that the array has the following properties: * In one second we can add an arbitrary (possibly neg...
Solve the programming task below in a Python markdown code block. Chandu and Kundu are bored of dramatic games around. As they are very good friends and scholars they decided to discover a new game. In total they had N number of marbles with value inscribed on each of them from 1 to N. Chandu being from royal famil...
Solve the programming task below in a Python markdown code block. Little Jhool was was the most intelligent kid of his school. But he did NOT like his class teacher, his school, and the way he was taught things in school. Well, he was a rebel, to say the least. Like most of us, he hated being punished by his teacher ...
Solve the programming task below in a Python markdown code block. Samu is playing a shooting game in play station. There are two apples to aim in this shooting game. Hitting first apple will provide her X points and hitting second apple will provide her Y points. And if she misses the apple she chose to hit, she wont...
Solve the programming task below in a Python markdown code block. Sunny, Arpit and Kunal are playing a game. All three of them are standing on a number line, each occupying a different integer. The rules are as follows: Two of them cannot be at the same integer at same time. In one move, one of them, who is not bet...
Solve the programming task below in a Python markdown code block. You have to go on a trip in your car which can hold a limited amount of fuel. You know how many liters of fuel your car uses per hour for certain speeds and you have to find out how far a certain amount of fuel will take you when travelling at the optim...
Solve the programming task below in a Python markdown code block. Given are strings S and T. Consider changing S to T by repeating the operation below. Find the minimum number of operations required to do so. Operation: Choose one character of S and replace it with a different character. Constraints * S and T have ...
Solve the programming task below in a Python markdown code block. In AtCoder City, there are three stations numbered 1, 2, and 3. Each of these stations is operated by one of the two railway companies, A and B. A string S of length 3 represents which company operates each station. If S_i is `A`, Company A operates St...
Solve the programming task below in a Python markdown code block. Takahashi has N sticks that are distinguishable from each other. The length of the i-th stick is L_i. He is going to form a triangle using three of these sticks. Let a, b, and c be the lengths of the three sticks used. Here, all of the following condit...
Solve the programming task below in a Python markdown code block. Given an integer N not less than 3, find the sum of the interior angles of a regular polygon with N sides. Print the answer in degrees, but do not print units. Constraints * 3 \leq N \leq 100 Input Input is given from Standard Input in the followin...
Solve the programming task below in a Python markdown code block. A prime number is an integer that is greater than 1 and can only be divided by itself or 1. For example, 2 is a prime number because it is divisible only by 2 and 1, but 12 is not a prime number because it is divisible by 2, 3, 4, 6 in addition to 12 an...
Solve the programming task below in a Python markdown code block. Taro, who aims to become a web designer, is currently training. My senior at the office tells me that the background color of this page is # ffe085, which is a color number peculiar to web design, but I can't think of what kind of color it is. This col...
Solve the programming task below in a Python markdown code block. The "Western calendar" is a concept imported from the West, but in Japan there is a concept called the Japanese calendar, which identifies the "era name" by adding a year as a method of expressing the year on the calendar. For example, this year is 2016...
Solve the programming task below in a Python markdown code block. IOI Real Estate rents condominiums. The apartment room handled by this company is 1LDK, and the area is 2xy + x + y as shown in the figure below. However, x and y are positive integers. Figure_Madori In the IOI real estate catalog, the areas of cond...
Solve the programming task below in a Python markdown code block. Travelling by train is fun and exciting. But more than that indeed. Young challenging boys often tried to purchase the longest single tickets and to single ride the longest routes of various railway systems. Route planning was like solving puzzles. Howe...
Solve the programming task below in a Python markdown code block. Meikyokan University is very famous for its research and education in the area of computer science. This university has a computer center that has advanced and secure computing facilities including supercomputers and many personal computers connected to...
Solve the programming task below in a Python markdown code block. Problem F Pizza Delivery Alyssa is a college student, living in New Tsukuba City. All the streets in the city are one-way. A new social experiment starting tomorrow is on alternative traffic regulation reversing the one-way directions of street section...
Solve the programming task below in a Python markdown code block. Bamboo Blossoms The bamboos live for decades, and at the end of their lives, they flower to make their seeds. Dr. ACM, a biologist, was fascinated by the bamboos in blossom in his travel to Tsukuba. He liked the flower so much that he was tempted to ma...
Solve the programming task below in a Python markdown code block. curtain Summer is coming soon. You decide to redecorate your room for the summer. It is expected that the sun will be very strong this summer, and it will be a difficult season for you who are not good at dazzling. So you thought about installing a cur...
Solve the programming task below in a Python markdown code block. Proof of knowledge The entrance door of the apartment you live in has a password-type lock. This password consists of exactly four digits, ranging from 0 to 9, and you always use the password P given to you by the apartment manager to unlock this door....
Solve the programming task below in a Python markdown code block. Problem There are $ N $ Amidakuji with 3 vertical lines. No matter which line you start from, the Amidakuji that ends at the starting line is considered a good Amidakuji. You can select one or more Amidakuji and connect them vertically in any order. Ou...
Solve the programming task below in a Python markdown code block. Write a program which counts and reports the number of each alphabetical letter. Ignore the case of characters. Constraints * The number of characters in the sentence < 1200 Input A sentence in English is given in several lines. Output Prints the ...
Solve the programming task below in a Python markdown code block. The faculty of application management and consulting services (FAMCS) of the Berland State University (BSU) has always been popular among Berland's enrollees. This year, N students attended the entrance exams, but no more than K will enter the universit...
Solve the programming task below in a Python markdown code block. Vasya came up with a password to register for EatForces β€” a string s. The password in EatForces should be a string, consisting of lowercase and uppercase Latin letters and digits. But since EatForces takes care of the security of its users, user passwo...
Solve the programming task below in a Python markdown code block. Vasya has got n books, numbered from 1 to n, arranged in a stack. The topmost book has number a_1, the next one β€” a_2, and so on. The book at the bottom of the stack has number a_n. All numbers are distinct. Vasya wants to move all the books to his bac...
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_{i = 1}^{n} a_i - min_{i = 1}^{n} a_i. You have to remove exactly one element from this array to minimize instability of the resulting (...
Solve the programming task below in a Python markdown code block. The number "zero" is called "love" (or "l'oeuf" to be precise, literally means "egg" in French), for example when denoting the zero score in a game of tennis. Aki is fond of numbers, especially those with trailing zeros. For example, the number 9200 h...
Solve the programming task below in a Python markdown code block. Gildong is experimenting with an interesting machine Graph Traveler. In Graph Traveler, there is a directed graph consisting of n vertices numbered from 1 to n. The i-th vertex has m_i outgoing edges that are labeled as e_i[0], e_i[1], …, e_i[m_i-1], ea...
Solve the programming task below in a Python markdown code block. Happy new year! The year 2020 is also known as Year Gyeongja (κ²½μžλ…„, gyeongja-nyeon) in Korea. Where did the name come from? Let's briefly look at the Gapja system, which is traditionally used in Korea to name the years. There are two sequences of n stri...
Solve the programming task below in a Python markdown code block. Polycarp wants to assemble his own keyboard. Layouts with multiple rows are too complicated for him β€” his keyboard will consist of only one row, where all 26 lowercase Latin letters will be arranged in some order. Polycarp uses the same password s on a...
Solve the programming task below in a Python markdown code block. You are given a colored permutation p_1, p_2, ..., p_n. The i-th element of the permutation has color c_i. Let's define an infinite path as infinite sequence i, p[i], p[p[i]], p[p[p[i]]] ... where all elements have same color (c[i] = c[p[i]] = c[p[p[i]...
Solve the programming task below in a Python markdown code block. Gottfried learned about binary number representation. He then came up with this task and presented it to you. You are given a collection of n non-negative integers a_1, …, a_n. You are allowed to perform the following operation: choose two distinct ind...
Solve the programming task below in a Python markdown code block. You are given n segments [l_1, r_1], [l_2, r_2], ..., [l_n, r_n]. Each segment has one of two colors: the i-th segment's color is t_i. Let's call a pair of segments i and j bad if the following two conditions are met: * t_i β‰  t_j; * the segments ...
Solve the programming task below in a Python markdown code block. As meticulous Gerald sets the table and caring Alexander sends the postcards, Sergey makes snowmen. Each showman should consist of three snowballs: a big one, a medium one and a small one. Sergey's twins help him: they've already made n snowballs with r...
Solve the programming task below in a Python markdown code block. You are given a directed acyclic graph (a directed graph that does not contain cycles) of n vertices and m arcs. The i-th arc leads from the vertex x_i to the vertex y_i and has the weight w_i. Your task is to select an integer a_v for each vertex v, a...
Solve the programming task below in a Python markdown code block. You are given a sequence a, initially consisting of n integers. You want to transform this sequence so that all elements in it are equal (i. e. it contains several occurrences of the same element). To achieve this, you choose some integer x that occur...
Solve the programming task below in a Python markdown code block. Nezzar has n balls, numbered with integers 1, 2, …, n. Numbers a_1, a_2, …, a_n are written on them, respectively. Numbers on those balls form a non-decreasing sequence, which means that a_i ≀ a_{i+1} for all 1 ≀ i < n. Nezzar wants to color the balls ...
Solve the programming task below in a Python markdown code block. Input The input contains two integers N, M (1 ≀ N ≀ 1024, 2 ≀ M ≀ 16), separated by a single space. Output Output "YES" or "NO". Examples Input 2 3 Output YES Input 3 2 Output NO Input 33 16 Output YES Input 26 5 Outpu...
Solve the programming task below in a Python markdown code block. There are n cities in Shaazzzland, numbered from 0 to n-1. Ghaazzzland, the immortal enemy of Shaazzzland, is ruled by AaParsa. As the head of the Ghaazzzland's intelligence agency, AaParsa is carrying out the most important spying mission in Ghaazzzla...
Solve the programming task below in a Python markdown code block. There are n stone quarries in Petrograd. Each quarry owns mi dumpers (1 ≀ i ≀ n). It is known that the first dumper of the i-th quarry has xi stones in it, the second dumper has xi + 1 stones in it, the third has xi + 2, and the mi-th dumper (the last ...
Solve the programming task below in a Python markdown code block. This problem's actual name, "Lexicographically Largest Palindromic Subsequence" is too long to fit into the page headline. You are given string s consisting of lowercase English letters only. Find its lexicographically largest palindromic subsequence. ...
Solve the programming task below in a Python markdown code block. A film festival is coming up in the city N. The festival will last for exactly n days and each day will have a premiere of exactly one film. Each film has a genre β€” an integer from 1 to k. On the i-th day the festival will show a movie of genre ai. We ...
Solve the programming task below in a Python markdown code block. Ksusha is a beginner coder. Today she starts studying arrays. She has array a1, a2, ..., an, consisting of n positive integers. Her university teacher gave her a task. Find such number in the array, that all array elements are divisible by it. Help her...
Solve the programming task below in a Python markdown code block. In mathematics, a subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements. For example, the sequence BDF is a subsequence of ABCDEF. A substring of a string is a ...
Solve the programming task below in a Python markdown code block. It's holiday. Mashmokh and his boss, Bimokh, are playing a game invented by Mashmokh. In this game Mashmokh writes sequence of n distinct integers on the board. Then Bimokh makes several (possibly zero) moves. On the first move he removes the first an...
Solve the programming task below in a Python markdown code block. Prof. Vasechkin wants to represent positive integer n as a sum of addends, where each addends is an integer number containing only 1s. For example, he can represent 121 as 121=111+11+–1. Help him to find the least number of digits 1 in such sum. Input ...
Solve the programming task below in a Python markdown code block. As you know, an undirected connected graph with n nodes and n - 1 edges is called a tree. You are given an integer d and a tree consisting of n nodes. Each node i has a value ai associated with it. We call a set S of tree nodes valid if following condi...