question
large_stringlengths
265
13.2k
Solve the programming task below in a Python markdown code block. A few years ago Sajjad left his school and register to another one due to security reasons. Now he wishes to find Amir, one of his schoolmates and good friends. There are n schools numerated from 1 to n. One can travel between each pair of them, to do ...
Solve the programming task below in a Python markdown code block. With one die of 6 sides we will have six different possible results:``` 1, 2, 3, 4, 5, 6``` . With 2 dice of six sides, we will have 36 different possible results: ``` (1,1),(1,2),(2,1),(1,3),(3,1),(1,4),(4,1),(1,5), (5,1), (1,6),(6,1),(2,2),(2,3),(3...
Solve the programming task below in a Python markdown code block. You are given an array of $n$ positive integers $a_1, a_2, \ldots, a_n$. Your task is to calculate the number of arrays of $n$ positive integers $b_1, b_2, \ldots, b_n$ such that: $1 \le b_i \le a_i$ for every $i$ ($1 \le i \le n$), and $b_i \neq b_{i...
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. You have a playlist consisting of $n$ songs. The $i$-th song is characterized by two numbers $t_i$ and $b_i$ β€” its length and beauty respectively. The pleasure of listening to set of songs is equal to the total length of the songs in the set multiplied ...
Solve the programming task below in a Python markdown code block. Filled with optimism, Hyunuk will host a conference about how great this new year will be! The conference will have $n$ lectures. Hyunuk has two candidate venues $a$ and $b$. For each of the $n$ lectures, the speaker specified two time intervals $[sa_i...
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 \ge 3$). Nastya was very confused by this present, so she decided to break the door, throwi...
Solve the programming task below in a Python markdown code block. Kode Festival is an anual contest where the hardest stone in the world is determined. (Kode is a Japanese word for "hardness".) This year, 2^N stones participated. The hardness of the i-th stone is A_i. In the contest, stones are thrown at each other ...
Solve the programming task below in a Python markdown code block. Jzzhu have n non-negative integers a1, a2, ..., an. We will call a sequence of indexes i1, i2, ..., ik (1 ≀ i1 < i2 < ... < ik ≀ n) a group of size k. Jzzhu wonders, how many groups exists such that ai1 & ai2 & ... & aik = 0 (1 ≀ k ≀ n)? Help him and ...
Solve the programming task below in a Python markdown code block. Little girl Tanya is learning how to decrease a number by one, but she does it wrong with a number consisting of two or more digits. Tanya subtracts one from a number by the following algorithm: if the last digit of the number is non-zero, she decrease...
Solve the programming task below in a Python markdown code block. You have an axis-aligned rectangle room with width $W$ and height $H$, so the lower left corner is in point $(0, 0)$ and the upper right corner is in $(W, H)$. There is a rectangular table standing in this room. The sides of the table are parallel to t...
Solve the programming task below in a Python markdown code block. Parsa has a humongous tree on $n$ vertices. On each vertex $v$ he has written two integers $l_v$ and $r_v$. To make Parsa's tree look even more majestic, Nima wants to assign a number $a_v$ ($l_v \le a_v \le r_v$) to each vertex $v$ such that the beau...
Solve the programming task below in a Python markdown code block. This problem is a complicated version of D1, but it has significant differences, so read the whole statement. Polycarp has an array of $n$ ($n$ is even) integers $a_1, a_2, \dots, a_n$. Polycarp conceived of a positive integer $k$. After that, Polycarp...
Solve the programming task below in a Python markdown code block. Ho ho! So you think you know integers, do you? Well then, young wizard, tell us what the Nth digit of the [Champernowne constant](https://en.wikipedia.org/wiki/Champernowne_constant) is! The constant proceeds like this: `0.12345678910111213141516...` ...
Solve the programming task below in a Python markdown code block. # A wolf in sheep's clothing Wolves have been reintroduced to Great Britain. You are a sheep farmer, and are now plagued by wolves which pretend to be sheep. Fortunately, you are good at spotting them. Warn the sheep in front of the wolf that it is a...
Solve the programming task below in a Python markdown code block. The phantom thief "Lupin IV" is told by the beautiful "Fujiko Mine", a descendant of the Aizu clan, that the military funds left by the Aizu clan are sleeping in Aizuwakamatsu city. According to a report by Lupine's longtime companion, "Ishikawa Koshiem...
Solve the programming task below in a Python markdown code block. Vasya is an active Internet user. One day he came across an Internet resource he liked, so he wrote its address in the notebook. We know that the address of the written resource has format: <protocol>://<domain>.ru[/<context>] where: <protocol> can e...
Solve the programming task below in a Python markdown code block. Consider the infinite sequence of integers: 1, 1, 2, 1, 2, 3, 1, 2, 3, 4, 1, 2, 3, 4, 5.... The sequence is built in the following way: at first the number 1 is written out, then the numbers from 1 to 2, then the numbers from 1 to 3, then the numbers fr...
Solve the programming task below in a Python markdown code block. Monocarp has decided to buy a new TV set and hang it on the wall in his flat. The wall has enough free space so Monocarp can buy a TV set with screen width not greater than $a$ and screen height not greater than $b$. Monocarp is also used to TV sets wit...
Solve the programming task below in a Python markdown code block. Guy-Manuel and Thomas are going to build a polygon spaceship. You're given a strictly convex (i. e. no three points are collinear) polygon P which is defined by coordinates of its vertices. Define P(x,y) as a polygon obtained by translating P by vector...
Solve the programming task below in a Python markdown code block. Lunar New Year is approaching, and you bought a matrix with lots of "crosses". This matrix $M$ of size $n \times n$ contains only 'X' and '.' (without quotes). The element in the $i$-th row and the $j$-th column $(i, j)$ is defined as $M(i, j)$, where ...
Solve the programming task below in a Python markdown code block. Input The first line of the input contains a single integer N (1 ≀ N ≀ 24). The next N lines contain 5 space-separated integers each. The first three integers will be between 0 and 2, inclusive. The last two integers will be between 0 and 3, inclusive....
Solve the programming task below in a Python markdown code block. Petya has an array of integers a_1, a_2, …, a_n. He only likes sorted arrays. Unfortunately, the given array could be arbitrary, so Petya wants to sort it. Petya likes to challenge himself, so he wants to sort array using only 3-cycles. More formally, ...
Solve the programming task below in a Python markdown code block. You are given a picture consisting of $n$ rows and $m$ columns. Rows are numbered from $1$ to $n$ from the top to the bottom, columns are numbered from $1$ to $m$ from the left to the right. Each cell is painted either black or white. You think that t...
Solve the programming task below in a Python markdown code block. Problem There are coins with front and back sides and dice with rolls from $ 1 $ to $ N $. Gacho decided to play the following games using these. The game starts with a score of $ 0 $ and proceeds as follows. 1. Roll the dice $ 1 $ and add the numbe...
Solve the programming task below in a Python markdown code block. Mad scientist Mike entertains himself by arranging rows of dominoes. He doesn't need dominoes, though: he uses rectangular magnets instead. Each magnet has two poles, positive (a "plus") and negative (a "minus"). If two magnets are put together at a clo...
Solve the programming task below in a Python markdown code block. Let's introduce some definitions that will be needed later. Let $prime(x)$ be the set of prime divisors of $x$. For example, $prime(140) = \{ 2, 5, 7 \}$, $prime(169) = \{ 13 \}$. Let $g(x, p)$ be the maximum possible integer $p^k$ where $k$ is an int...
Solve the programming task below in a Python markdown code block. Alice has just learned addition. However, she hasn't learned the concept of "carrying" fully β€” instead of carrying to the next column, she carries to the column two columns to the left. For example, the regular way to evaluate the sum $2039 + 2976$ wou...
Solve the programming task below in a Python markdown code block. A progress bar is an element of graphical interface that displays the progress of a process for this very moment before it is completed. Let's take a look at the following form of such a bar. A bar is represented as n squares, located in line. To add c...
Solve the programming task below in a Python markdown code block. On the way to Rio de Janeiro Ostap kills time playing with a grasshopper he took with him in a special box. Ostap builds a line of length n such that some cells of this line are empty and some contain obstacles. Then, he places his grasshopper to one of...
Solve the programming task below in a Python markdown code block. Given time in 24-hour format, convert it to words. ``` For example: 13:00 = one o'clock 13:09 = nine minutes past one 13:15 = quarter past one 13:29 = twenty nine minutes past one 13:30 = half past one 13:31 = twenty nine minutes to two 13:45 = qu...
Solve the programming task below in a Python markdown code block. You are an experienced Codeforces user. Today you found out that during your activity on Codeforces you have made y submissions, out of which x have been successful. Thus, your current success rate on Codeforces is equal to x / y. Your favorite rationa...
Solve the programming task below in a Python markdown code block. Student A and student B are giving each other test answers during a test. They don't want to be caught so they are sending each other coded messages. Student A is sending student B the message: `Answer to Number 5 Part b`. He starts of with a squar...
Solve the programming task below in a Python markdown code block. Vasya is sitting on an extremely boring math class. To have fun, he took a piece of paper and wrote out n numbers on a single line. After that, Vasya began to write out different ways to put pluses ("+") in the line between certain digits in the line so...
Solve the programming task below in a Python markdown code block. An eviternity number is a number which: * contains only digits 8, 5 and 3, and * the count of the digit `8` >= count of digit `5` >= count of digit `3`. The first few eviternity numbers are as follows. ```Haskell [8, 58, 85, 88, 358, 385, 538, 583, ...
Solve the programming task below in a Python markdown code block. Connect the countless points with lines, till we reach the faraway yonder. There are n points on a coordinate plane, the i-th of which being (i, y_{i}). Determine whether it's possible to draw two parallel and non-overlapping lines, such that every po...
Solve the programming task below in a Python markdown code block. Основой любой ΡΠΎΡ†ΠΈΠ°Π»ΡŒΠ½ΠΎΠΉ сСти являСтся ΠΎΡ‚Π½ΠΎΡˆΠ΅Π½ΠΈΠ΅ Π΄Ρ€ΡƒΠΆΠ±Ρ‹ ΠΌΠ΅ΠΆΠ΄Ρƒ двумя ΠΏΠΎΠ»ΡŒΠ·ΠΎΠ²Π°Ρ‚Π΅Π»ΡΠΌΠΈ Π² Ρ‚ΠΎΠΌ ΠΈΠ»ΠΈ ΠΈΠ½ΠΎΠΌ смыслС. Π’ ΠΎΠ΄Π½ΠΎΠΉ извСстной ΡΠΎΡ†ΠΈΠ°Π»ΡŒΠ½ΠΎΠΉ сСти Π΄Ρ€ΡƒΠΆΠ±Π° симмСтрична, Ρ‚ΠΎ Π΅ΡΡ‚ΡŒ Ссли a являСтся Π΄Ρ€ΡƒΠ³ΠΎΠΌ b, Ρ‚ΠΎ b Ρ‚Π°ΠΊΠΆΠ΅ являСтся Π΄Ρ€ΡƒΠ³ΠΎΠΌ a. Π’ этой ΠΆΠ΅ сСти Π΅ΡΡ‚ΡŒ функция...
Solve the programming task below in a Python markdown code block. Challenge: Given two null-terminated strings in the arguments "string" and "prefix", determine if "string" starts with the "prefix" string. Return 1 (or any other "truthy" value) if true, 0 if false. Example: ``` startsWith("hello world!", "hello"); //...
Solve the programming task below in a Python markdown code block. Absent-minded Masha got set of n cubes for her birthday. At each of 6 faces of each cube, there is exactly one digit from 0 to 9. Masha became interested what is the largest natural x such she can make using her new cubes all integers from 1 to x. To ...
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. There are $n$ cities and $m$ roads in Berland. Each road connects a pair of cities. The roads in Berland are one-way. What is the minimum number of new roads that need to be built to make all the cities reachable from the capital? New roads will also ...
Solve the programming task below in a Python markdown code block. In 1862, the lord of Aizu was ordered to serve as a guardian of Kyoto. The Kyoto Shugoshoku is an important role to protect Kyoto at the end of the Edo period when security has deteriorated. You have to patrol the city by sharing it with the shogunate a...
Solve the programming task below in a Python markdown code block. Ilya is very fond of graphs, especially trees. During his last trip to the forest Ilya found a very interesting tree rooted at vertex 1. There is an integer number written on each vertex of the tree; the number written on vertex i is equal to a_{i}. Il...
Solve the programming task below in a Python markdown code block. In Math, an improper fraction is a fraction where the numerator (the top number) is greater than or equal to the denominator (the bottom number) For example: ```5/3``` (five third). A mixed numeral is a whole number and a fraction combined into one "mi...
Solve the programming task below in a Python markdown code block. # Task A cake is sliced with `n` straight lines. Your task is to calculate the maximum number of pieces the cake can have. # Example For `n = 0`, the output should be `1`. For `n = 1`, the output should be `2`. For `n = 2`, the output should be...
Solve the programming task below in a Python markdown code block. Dolphin loves programming contests. Today, he will take part in a contest in AtCoder. In this country, 24-hour clock is used. For example, 9:00 p.m. is referred to as "21 o'clock". The current time is A o'clock, and a contest will begin in exactly B h...
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 Output ...
Solve the programming task below in a Python markdown code block. Did you ever hear about 'crossing the bridge noodle' ? Let me tell you that it's not some kind of bridge made of noodles. It's a dish, a kind of rice noodle soup. Mr.Ping makes the best noodle soup and his son Po is eagerly waiting for the user reviews ...
Solve the programming task below in a Python markdown code block. In computing, there are two primary byte order formats: big-endian and little-endian. Big-endian is used primarily for networking (e.g., IP addresses are transmitted in big-endian) whereas little-endian is used mainly by computers with microprocessors. ...
Solve the programming task below in a Python markdown code block. Takahashi has two integers X and Y. He computed X + Y and X - Y, and the results were A and B, respectively. Now he cannot remember what X and Y were. Find X and Y for him. -----Constraints----- - -100 \leq A, B \leq 100 - For the given integers A an...
Solve the programming task below in a Python markdown code block. # The die is cast! Your task in this kata is to write a "dice roller" that interprets a subset of [dice notation](http://en.wikipedia.org/wiki/Dice_notation). # Description In most role-playing games, die rolls required by the system are given in the...
Solve the programming task below in a Python markdown code block. Arkady invited Anna for a dinner to a sushi restaurant. The restaurant is a bit unusual: it offers $n$ pieces of sushi aligned in a row, and a customer has to choose a continuous subsegment of these sushi to buy. The pieces of sushi are of two types: e...
Solve the programming task below in a Python markdown code block. Peter got a new snow blower as a New Year present. Of course, Peter decided to try it immediately. After reading the instructions he realized that it does not work like regular snow blowing machines. In order to make it work, you need to tie it to some ...
Solve the programming task below in a Python markdown code block. Reducing Problems - Bug Fixing #8 Oh no! Timmy's reduce is causing problems, Timmy's goal is to calculate the two teams scores and return the winner but timmy has gotten confused and sometimes teams don't enter their scores, total the scores out of 3! ...
Solve the programming task below in a Python markdown code block. Find the minimum area of a square land on which you can place two identical rectangular $a \times b$ houses. The sides of the houses should be parallel to the sides of the desired square land. Formally, You are given two identical rectangles with sid...
Solve the programming task below in a Python markdown code block. Define a "prime prime" number to be a rational number written as one prime number over another prime number: `primeA / primeB` (e.g. `7/31`) Given a whole number `N`, generate the number of "prime prime" rational numbers less than 1, using only prime n...
Solve the programming task below in a Python markdown code block. There are N integers written on a blackboard. The i-th integer is A_i. Takahashi will repeatedly perform the following operation on these numbers: * Select a pair of integers, A_i and A_j, that have the same parity (that is, both are even or both are ...
Solve the programming task below in a Python markdown code block. problem At IOI Confectionery, rice crackers are baked using the traditional method since the company was founded. This traditional method is to bake the front side for a certain period of time with charcoal, turn it over when the front side is baked, a...
Solve the programming task below in a Python markdown code block. Everybody in Russia uses Gregorian calendar. In this calendar there are 31 days in January, 28 or 29 days in February (depending on whether the year is leap or not), 31 days in March, 30 days in April, 31 days in May, 30 in June, 31 in July, 31 in Augus...
Solve the programming task below in a Python markdown code block. Alice is visiting New York City. To make the trip fun, Alice will take photos of the city skyline and give the set of photos as a present to Bob. However, she wants to find the set of photos with maximum beauty and she needs your help. There are $n$ bu...
Solve the programming task below in a Python markdown code block. # Summary: Given a number, `num`, return the shortest amount of `steps` it would take from 1, to land exactly on that number. # Description: A `step` is defined as either: - Adding 1 to the number: `num += 1` - Doubling the number: `num *= 2` You will...
Solve the programming task below in a Python markdown code block. Given is an integer S. Find how many sequences there are whose terms are all integers greater than or equal to 3, and whose sum is equal to S. The answer can be very large, so output it modulo 10^9 + 7. -----Constraints----- - 1 \leq S \leq 2000 - Al...
Solve the programming task below in a Python markdown code block. A variation of determining leap years, assuming only integers are used and years can be negative and positive. Write a function which will return the days in the year and the year entered in a string. For example 2000, entered as an integer, will retu...
Solve the programming task below in a Python markdown code block. There is a building with 2N floors, numbered 1, 2, \ldots, 2N from bottom to top. The elevator in this building moved from Floor 1 to Floor 2N just once. On the way, N persons got on and off the elevator. Each person i (1 \leq i \leq N) got on at Floor ...
Solve the programming task below in a Python markdown code block. Mr. Square is going on a holiday. He wants to bring 2 of his favorite squares with him, so he put them in his rectangle suitcase. Write a function that, given the size of the squares and the suitcase, return whether the squares can fit inside the suitc...
Solve the programming task below in a Python markdown code block. Write a function `insertDash(num)`/`InsertDash(int num)` that will insert dashes ('-') between each two odd numbers in num. For example: if num is 454793 the output should be 4547-9-3. Don't count zero as an odd number. Note that the number will always...
Solve the programming task below in a Python markdown code block. Vasya has recently got a job as a cashier at a local store. His day at work is $L$ minutes long. Vasya has already memorized $n$ regular customers, the $i$-th of which comes after $t_{i}$ minutes after the beginning of the day, and his service consumes ...
Solve the programming task below in a Python markdown code block. Bridge Removal ICPC islands once had been a popular tourist destination. For nature preservation, however, the government decided to prohibit entrance to the islands, and to remove all the man-made structures there. The hardest part of the project is t...
Solve the programming task below in a Python markdown code block. Why would we want to stop to only 50 shades of grey? Let's see to how many we can go. Write a function that takes a number n as a parameter and return an array containing n shades of grey in hexadecimal code (`#aaaaaa` for example). The array should b...
Solve the programming task below in a Python markdown code block. You get a "text" and have to shift the vowels by "n" positions to the right. (Negative value for n should shift to the left.) "Position" means the vowel's position if taken as one item in a list of all vowels within the string. A shift by 1 would mean, ...
Solve the programming task below in a Python markdown code block. Ari the monster is not an ordinary monster. She is the hidden identity of Super M, the Byteforces’ superhero. Byteforces is a country that consists of n cities, connected by n - 1 bidirectional roads. Every road connects exactly two distinct cities, and...
Solve the programming task below in a Python markdown code block. # Task Consider the following operation: We take a positive integer `n` and replace it with the sum of its `prime factors` (if a prime number is presented multiple times in the factorization of `n`, then it's counted the same number of times in the ...
Solve the programming task below in a Python markdown code block. Takahashi recorded his daily life for the last few days as a integer sequence of length 2N, as follows: * a_1, b_1, a_2, b_2, ... , a_N, b_N This means that, starting from a certain time T, he was: * sleeping for exactly a_1 seconds * then awake fo...
Solve the programming task below in a Python markdown code block. You are given a string s of length n consisting of lowercase English letters. For two given strings s and t, say S is the set of distinct characters of s and T is the set of distinct characters of t. The strings s and t are isomorphic if their lengths ...
Solve the programming task below in a Python markdown code block. You are given an array $a$ of length $n$ that has a special condition: every element in this array has at most 7 divisors. Find the length of the shortest non-empty subsequence of this array product of whose elements is a perfect square. A sequence $a$...
Solve the programming task below in a Python markdown code block. The only difference between easy and hard versions is the constraints. Vova likes pictures with kittens. The news feed in the social network he uses can be represented as an array of $n$ consecutive pictures (with kittens, of course). Vova likes all th...
Solve the programming task below in a Python markdown code block. Yet another education system reform has been carried out in Berland recently. The innovations are as follows: An academic year now consists of n days. Each day pupils study exactly one of m subjects, besides, each subject is studied for no more than on...
Solve the programming task below in a Python markdown code block. Problem statement AOR Ika got a cabbage with $ N $ leaves. The leaves of this cabbage are numbered $ 1, \ ldots, N $ in order from the outside, and the dirtiness of the $ i $ th leaf is $ D_i $. The larger this value is, the worse the degree of dirt is...
Solve the programming task below in a Python markdown code block. She catched the thrown coin that draws parabolic curve with her sparkling fingers. She is an ESPer. Yes, she is an electro-master who has the third strongest power among more than one million ESPers in the city. Being flicked by her thumb, the coin is a...
Solve the programming task below in a Python markdown code block. The HR manager was disappointed again. The last applicant failed the interview the same way as 24 previous ones. "Do I give such a hard task?" β€” the HR manager thought. "Just raise number 5 to the power of n and get last two digits of the number. Yes, o...
Solve the programming task below in a Python markdown code block. Recently a serious bug has been found in the FOS code. The head of the F company wants to find the culprit and punish him. For that, he set up an organizational meeting, the issue is: who's bugged the code? Each of the n coders on the meeting said: 'I k...
Solve the programming task below in a Python markdown code block. A `Nice array` is defined to be an array where for every value `n` in the array, there is also an element `n-1` or `n+1` in the array. example: ``` [2,10,9,3] is Nice array because 2=3-1 10=9+1 3=2+1 9=10-1 ``` Write a function named `isNice`/`IsNice...
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. C: Only one subsequence --Unique Subsequence- problem One day Ebi-chan noticed that a text string T of length n and a pattern string P (m \ leq n) of length m were placed on the desk. Ebi-chan loves the "only one subsequence" that appears in strings, ...
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. The statement of this problem is the same as the statement of problem C2. The only difference is that, in problem C1, $n$ is always even, and in C2, $n$ is always odd. You are given a regular polygon with $2 \cdot n$ vertices (it's convex and has equal...
Solve the programming task below in a Python markdown code block. The central dogma of molecular biology is that DNA is transcribed into RNA, which is then tranlsated into protein. RNA, like DNA, is a long strand of nucleic acids held together by a sugar backbone (ribose in this case). Each segment of three bases is c...
Solve the programming task below in a Python markdown code block. We have a grid of squares with N rows and M columns. Let (i, j) denote the square at the i-th row from the top and j-th column from the left. We will choose K of the squares and put a piece on each of them. If we place the K pieces on squares (x_1, y_1)...
Solve the programming task below in a Python markdown code block. Given two integers `a` and `b`, which can be positive or negative, find the sum of all the numbers between including them too and return it. If the two numbers are equal return `a` or `b`. **Note:** `a` and `b` are not ordered! ## Examples ```python ...
Solve the programming task below in a Python markdown code block. Given a number, write a function to output its reverse digits. (e.g. given 123 the answer is 321) Numbers should preserve their sign; i.e. a negative number should still be negative when reversed. ### Examples ``` 123 -> 321 -456 -> -654 1000 -> ...
Solve the programming task below in a Python markdown code block. "Point reflection" or "point symmetry" is a basic concept in geometry where a given point, P, at a given position relative to a mid-point, Q has a corresponding point, P1, which is the same distance from Q but in the opposite direction. ## Task Given ...
Solve the programming task below in a Python markdown code block. Mad scientist Mike has just finished constructing a new device to search for extraterrestrial intelligence! He was in such a hurry to launch it for the first time that he plugged in the power wires without giving it a proper glance and started experimen...
Solve the programming task below in a Python markdown code block. Vasya is studying number theory. He has denoted a function f(a, b) such that: f(a, 0) = 0; f(a, b) = 1 + f(a, b - gcd(a, b)), where gcd(a, b) is the greatest common divisor of a and b. Vasya has two numbers x and y, and he wants to calculate f(x, y)...
Solve the programming task below in a Python markdown code block. The tycoon of a winery empire in Mondstadt, unmatched in every possible way. A thinker in the Knights of Favonius with an exotic appearance. This time, the brothers are dealing with a strange piece of wood marked with their names. This plank of wood ca...
Solve the programming task below in a Python markdown code block. A competitive eater, Alice is scheduling some practices for an eating contest on a magical calendar. The calendar is unusual because a week contains not necessarily $7$ days! In detail, she can choose any integer $k$ which satisfies $1 \leq k \leq r$, ...
Solve the programming task below in a Python markdown code block. A string is called bracket sequence if it does not contain any characters other than "(" and ")". A bracket sequence is called regular if it it is possible to obtain correct arithmetic expression by inserting characters "+" and "1" into this sequence. F...
Solve the programming task below in a Python markdown code block. Given an array of 4 integers ```[a,b,c,d]``` representing two points ```(a, b)``` and ```(c, d)```, return a string representation of the slope of the line joining these two points. For an undefined slope (division by 0), return ```undefined``` . ...
Solve the programming task below in a Python markdown code block. Masha has three sticks of length $a$, $b$ and $c$ centimeters respectively. In one minute Masha can pick one arbitrary stick and increase its length by one centimeter. She is not allowed to break sticks. What is the minimum number of minutes she needs ...
Solve the programming task below in a Python markdown code block. Let's call two strings $s$ and $t$ anagrams of each other if it is possible to rearrange symbols in the string $s$ to get a string, equal to $t$. Let's consider two strings $s$ and $t$ which are anagrams of each other. We say that $t$ is a reducible an...
Solve the programming task below in a Python markdown code block. HQ9+ is a joke programming language which has only four one-character instructions: * "H" prints "Hello, World!", * "Q" prints the source code of the program itself, * "9" prints the lyrics of "99 Bottles of Beer" song, * "+" increments the va...