question
large_stringlengths
265
13.2k
Solve the programming task below in a Python markdown code block. You are given $n$ rectangles, each of height $1$. Each rectangle's width is a power of $2$ (i. e. it can be represented as $2^x$ for some non-negative integer $x$). You are also given a two-dimensional box of width $W$. Note that $W$ may or may not be ...
Solve the programming task below in a Python markdown code block. A social network for dogs called DH (DogHouse) has k special servers to recompress uploaded videos of cute cats. After each video is uploaded, it should be recompressed on one (any) of the servers, and only after that it can be saved in the social netwo...
Solve the programming task below in a Python markdown code block. Everybody knows that the $m$-coder Tournament will happen soon. $m$ schools participate in the tournament, and only one student from each school participates. There are a total of $n$ students in those schools. Before the tournament, all students put t...
Solve the programming task below in a Python markdown code block. # Pythagorean Triples A Pythagorean triplet is a set of three numbers a, b, and c where `a^2 + b^2 = c^2`. In this Kata, you will be tasked with finding the Pythagorean triplets whose product is equal to `n`, the given argument to the function `pythago...
Solve the programming task below in a Python markdown code block. One very experienced problem writer decided to prepare a problem for April Fools Day contest. The task was very simple - given an arithmetic expression, return the result of evaluating this expression. However, looks like there is a bug in the reference...
Solve the programming task below in a Python markdown code block. Recently Lynyrd and Skynyrd went to a shop where Lynyrd bought a permutation p of length n, and Skynyrd bought an array a of length m, consisting of integers from 1 to n. Lynyrd and Skynyrd became bored, so they asked you q queries, each of which has ...
Solve the programming task below in a Python markdown code block. # Task Your task is to find the smallest number which is evenly divided by all numbers between `m` and `n` (both inclusive). # Example For `m = 1, n = 2`, the output should be `2`. For `m = 2, n = 3`, the output should be `6`. For `m = 3, n = ...
Solve the programming task below in a Python markdown code block. Petya and Vasya are tossing a coin. Their friend Valera is appointed as a judge. The game is very simple. First Vasya tosses a coin x times, then Petya tosses a coin y times. If the tossing player gets head, he scores one point. If he gets tail, nobody ...
Solve the programming task below in a Python markdown code block. You are given an array of N integers a1, a2, ..., aN and an integer K. Find the number of such unordered pairs {i, j} that - i β‰  j - |ai + aj - K| is minimal possible Output the minimal possible value of |ai + aj - K| (where i β‰  j) and the number of...
Solve the programming task below in a Python markdown code block. Ksusha the Squirrel is standing at the beginning of a straight road, divided into n sectors. The sectors are numbered 1 to n, from left to right. Initially, Ksusha stands in sector 1. Ksusha wants to walk to the end of the road, that is, get to sector...
Solve the programming task below in a Python markdown code block. Vasya has a sequence a consisting of n integers a_1, a_2, ..., a_n. Vasya may pefrom the following operation: choose some number from the sequence and swap any pair of bits in its binary representation. For example, Vasya can transform number 6 (... 000...
Solve the programming task below in a Python markdown code block. Please notice the unusual memory limit of this problem. Orac likes games. Recently he came up with the new game, "Game of Life". You should play this game on a black and white grid with n rows and m columns. Each cell is either black or white. For ea...
Solve the programming task below in a Python markdown code block. The only difference between the two versions is that this version asks the maximal possible answer. Homer likes arrays a lot. Today he is painting an array $a_1, a_2, \dots, a_n$ with two kinds of colors, white and black. A painting assignment for $a_1...
Solve the programming task below in a Python markdown code block. Palindrome Problem Statement Find the number of palindromes closest to the integer n. Note that the non-negative integer x is the number of palindromes, which means that the character string in which x is expressed in decimal notation and the charact...
Solve the programming task below in a Python markdown code block. Your Goal is to create a function that takes two strings, a guess and a phone number. Based on the guess, the function should display a portion of the phone number: guess_my_number('052', '123-451-2345') would return the string: '#2#-#5#-2##...
Solve the programming task below in a Python markdown code block. A and B are preparing themselves for programming contests. An important part of preparing for a competition is sharing programming knowledge from the experienced members to those who are just beginning to deal with the contests. Therefore, during the n...
Solve the programming task below in a Python markdown code block. As the first step in algebra, students learn quadratic formulas and their factorization. Often, the factorization is a severe burden for them. A large number of students cannot master the factorization; such students cannot be aware of the elegance of a...
Solve the programming task below in a Python markdown code block. It's a Pokemon battle! Your task is to calculate the damage that a particular move would do using the following formula (not the actual one from the game): Where: * attack = your attack power * defense = the opponent's defense * effectiveness = the ef...
Solve the programming task below in a Python markdown code block. Polycarp plays a well-known computer game (we won't mention its name). In this game, he can craft tools of two types β€” shovels and swords. To craft a shovel, Polycarp spends two sticks and one diamond; to craft a sword, Polycarp spends two diamonds and ...
Solve the programming task below in a Python markdown code block. Heidi has finally found the mythical Tree of Life – a legendary combinatorial structure which is said to contain a prophecy crucially needed to defeat the undead armies. On the surface, the Tree of Life is just a regular undirected tree well-known from...
Solve the programming task below in a Python markdown code block. A popular reality show is recruiting a new cast for the third season! $n$ candidates numbered from $1$ to $n$ have been interviewed. The candidate $i$ has aggressiveness level $l_i$, and recruiting this candidate will cost the show $s_i$ roubles. The s...
Solve the programming task below in a Python markdown code block. Polycarp plays a computer game (yet again). In this game, he fights monsters using magic spells. There are two types of spells: fire spell of power $x$ deals $x$ damage to the monster, and lightning spell of power $y$ deals $y$ damage to the monster an...
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. In Aizuwakamatsu Village, which is located far north of Aizuwakamatsu City, a bridge called "Yabashi" is the only way to move to the surrounding villages. Despite the large number of passers-by, the bridge is so old that it is almost broken. <image> ...
Solve the programming task below in a Python markdown code block. Valera loves to participate in competitions. Especially in programming contests. Today he has participated in the contest with his team, consisting of n students (including Valera). This contest was an individual competition, so each student in the team...
Solve the programming task below in a Python markdown code block. Assume we take a number `x` and perform any one of the following operations: ```Pearl a) Divide x by 3 (if it is divisible by 3), or b) Multiply x by 2 ``` After each operation, we write down the result. If we start with `9`, we can get a sequence such ...
Solve the programming task below in a Python markdown code block. We have weather records at AtCoder Town for some consecutive three days. A string of length 3, S, represents the records - if the i-th character is S, it means it was sunny on the i-th day; if that character is R, it means it was rainy on that day. Find...
Solve the programming task below in a Python markdown code block. You are given a marine area map that is a mesh of squares, each representing either a land or sea area. Figure B-1 is an example of a map. <image> Figure B-1: A marine area map You can walk from a square land area to another if they are horizontally, ...
Solve the programming task below in a Python markdown code block. Vova again tries to play some computer card game. The rules of deck creation in this game are simple. Vova is given an existing deck of n cards and a magic number k. The order of the cards in the deck is fixed. Each card has a number written on it; num...
Solve the programming task below in a Python markdown code block. Your job is to build a function which determines whether or not there are double characters in a string (including whitespace characters). For example ```aa```, ``!!`` or ``` ```. You want the function to return true if the string contains double ch...
Solve the programming task below in a Python markdown code block. The beauty of a sequence a of length n is defined as a_1 \oplus \cdots \oplus a_n, where \oplus denotes the bitwise exclusive or (XOR). You are given a sequence A of length N. Snuke will insert zero or more partitions in A to divide it into some number...
Solve the programming task below in a Python markdown code block. On a circle lie $2n$ distinct points, with the following property: however you choose $3$ chords that connect $3$ disjoint pairs of points, no point strictly inside the circle belongs to all $3$ chords. The points are numbered $1, \, 2, \, \dots, \, 2n$...
Solve the programming task below in a Python markdown code block. You are given a string s consisting only of characters 0 and 1. A substring [l, r] of s is a string s_{l}s_{l} + 1s_{l} + 2... s_{r}, and its length equals to r - l + 1. A substring is called balanced if the number of zeroes (0) equals to the number of ...
Solve the programming task below in a Python markdown code block. There is a square matrix n Γ— n, consisting of non-negative integer numbers. You should find such a way on it that * starts in the upper left cell of the matrix; * each following cell is to the right or down from the current cell; * the way end...
Solve the programming task below in a Python markdown code block. Pavel made a photo of his favourite stars in the sky. His camera takes a photo of all points of the sky that belong to some rectangle with sides parallel to the coordinate axes. Strictly speaking, it makes a photo of all points with coordinates $(x, y)...
Solve the programming task below in a Python markdown code block. In fact, the problems E1 and E2 do not have much in common. You should probably think of them as two separate problems. You are given an integer array $a[1 \ldots n] = [a_1, a_2, \ldots, a_n]$. Let us consider an empty deque (double-ended queue). A de...
Solve the programming task below in a Python markdown code block. Hiroshi:? D-C'KOPUA Peter: What's wrong, Dr. David? I'm used to shouting something I don't understand, but I'm not even writing it today. Hiroshi: Here. <image> Peter: What? This table ... oh, there was something like this in the qualifying questio...
Solve the programming task below in a Python markdown code block. Let’s try a dice puzzle. The rules of this puzzle are as follows. 1. Dice with six faces as shown in Figure 1 are used in the puzzle. <image> Figure 1: Faces of a die 2. With twenty seven such dice, a 3 Γ— 3 Γ— 3 cube is built as shown in Figure 2. <...
Solve the programming task below in a Python markdown code block. Implement a function which creates a **[radix tree](https://en.wikipedia.org/wiki/Radix_tree)** (a space-optimized trie [prefix tree]) in which each node that is the only child is merged with its parent [unless a word from the input ends there]) from...
Solve the programming task below in a Python markdown code block. Implement a function to calculate the sum of the numerical values in a nested list. For example : ```python sum_nested([1, [2, [3, [4]]]]) -> 10 ``` Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on t...
Solve the programming task below in a Python markdown code block. Consider the numbers `6969` and `9116`. When you rotate them `180 degrees` (upside down), these numbers remain the same. To clarify, if we write them down on a paper and turn the paper upside down, the numbers will be the same. Try it and see! Some numb...
Solve the programming task below in a Python markdown code block. Polycarp has spent the entire day preparing problems for you. Now he has to sleep for at least $a$ minutes to feel refreshed. Polycarp can only wake up by hearing the sound of his alarm. So he has just fallen asleep and his first alarm goes off in $b$ ...
Solve the programming task below in a Python markdown code block. Takahashi and Aoki will play a game. They will repeatedly play it until one of them have N wins in total. When they play the game once, Takahashi wins with probability A %, Aoki wins with probability B %, and the game ends in a draw (that is, nobody wi...
Solve the programming task below in a Python markdown code block. You are given three strings $a$, $b$ and $c$ of the same length $n$. The strings consist of lowercase English letters only. The $i$-th letter of $a$ is $a_i$, the $i$-th letter of $b$ is $b_i$, the $i$-th letter of $c$ is $c_i$. For every $i$ ($1 \leq ...
Solve the programming task below in a Python markdown code block. Palo Alto is an unusual city because it is an endless coordinate line. It is also known for the office of Lyft Level 5. Lyft has become so popular so that it is now used by all $m$ taxi drivers in the city, who every day transport the rest of the city ...
Solve the programming task below in a Python markdown code block. There is a sequence of length N: A_1, A_2, ..., A_N. Initially, this sequence is a permutation of 1, 2, ..., N. On this sequence, Snuke can perform the following operation: * Choose K consecutive elements in the sequence. Then, replace the value of ea...
Solve the programming task below in a Python markdown code block. Do you know Just Odd Inventions? The business of this company is to "just odd inventions". Here, it is abbreviated as JOI. JOI is conducting research to confine many microorganisms in one petri dish alive. There are N microorganisms to be investigated,...
Solve the programming task below in a Python markdown code block. Peter wrote on the board a strictly increasing sequence of positive integers a_1, a_2, ..., a_{n}. Then Vasil replaced some digits in the numbers of this sequence by question marks. Thus, each question mark corresponds to exactly one lost digit. Restor...
Solve the programming task below in a Python markdown code block. Example Input 3 Output 1 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. You're given an array $a$ of $n$ integers, such that $a_1 + a_2 + \cdots + a_n = 0$. In one operation, you can choose two different indices $i$ and $j$ ($1 \le i, j \le n$), decrement $a_i$ by one and increment $a_j$ by one. If $i < j$ this operation i...
Solve the programming task below in a Python markdown code block. problem Cryptography is all the rage at xryuseix's school. Xryuseix, who lives in a grid of cities, has come up with a new cryptography to decide where to meet. The ciphertext consists of the $ N $ character string $ S $, and the $ S_i $ character det...
Solve the programming task below in a Python markdown code block. Pinkie Pie has bought a bag of patty-cakes with different fillings! But it appeared that not all patty-cakes differ from one another with filling. In other words, the bag contains some patty-cakes with the same filling. Pinkie Pie eats the patty-cakes ...
Solve the programming task below in a Python markdown code block. At the foot of Liyushan Mountain, n tents will be carefully arranged to provide accommodation for those who are willing to experience the joy of approaching nature, the tranquility of the night, and the bright starry sky. The i-th tent is located at th...
Solve the programming task below in a Python markdown code block. # Task Initially a number `1` is written on a board. It is possible to do the following operations with it: ``` multiply the number by 3; increase the number by 5.``` Your task is to determine that using this two operations step by step, is it possible...
Solve the programming task below in a Python markdown code block. Recall that a binary search tree is a rooted binary tree, whose nodes each store a key and each have at most two distinguished subtrees, left and right. The key in each node must be greater than any key stored in the left subtree, and less than any key ...
Solve the programming task below in a Python markdown code block. This is an interactive problem. Refer to the Interaction section below for better understanding. Ithea and Chtholly want to play a game in order to determine who can use the kitchen tonight. <image> Initially, Ithea puts n clear sheets of paper in a ...
Solve the programming task below in a Python markdown code block. In Finite Encyclopedia of Integer Sequences (FEIS), all integer sequences of lengths between 1 and N (inclusive) consisting of integers between 1 and K (inclusive) are listed. Let the total number of sequences listed in FEIS be X. Among those sequences,...
Solve the programming task below in a Python markdown code block. William has a favorite bracket sequence. Since his favorite sequence is quite big he provided it to you as a sequence of positive integers $c_1, c_2, \dots, c_n$ where $c_i$ is the number of consecutive brackets "(" if $i$ is an odd number or the number...
Solve the programming task below in a Python markdown code block. A recently found Ancient Prophesy is believed to contain the exact Apocalypse date. The prophesy is a string that only consists of digits and characters "-". We'll say that some date is mentioned in the Prophesy if there is a substring in the Prophesy ...
Solve the programming task below in a Python markdown code block. In some game by Playrix it takes t minutes for an oven to bake k carrot cakes, all cakes are ready at the same moment t minutes after they started baking. Arkady needs at least n cakes to complete a task, but he currently don't have any. However, he has...
Solve the programming task below in a Python markdown code block. β€” Oh my sweet Beaverette, would you fancy a walk along a wonderful woodland belt with me? β€” Of course, my Smart Beaver! Let us enjoy the splendid view together. How about Friday night? At this point the Smart Beaver got rushing. Everything should be...
Solve the programming task below in a Python markdown code block. Little chief has his own restaurant in the city. There are N workers there. Each worker has his own salary. The salary of the i-th worker equals to W_{i} (i = 1, 2, ..., N). Once, chief decided to equalize all workers, that is, he wants to make salaries...
Solve the programming task below in a Python markdown code block. Takahashi and Aoki are playing a stone-taking game. Initially, there are N piles of stones, and the i-th pile contains A_i stones and has an associated integer K_i. Starting from Takahashi, Takahashi and Aoki take alternate turns to perform the followin...
Solve the programming task below in a Python markdown code block. Automatons, or Finite State Machines (FSM), are extremely useful to programmers when it comes to software design. You will be given a simplistic version of an FSM to code for a basic TCP session. The outcome of this exercise will be to return the corre...
Solve the programming task below in a Python markdown code block. The research center Q has developed a new multi-core processor. The processor consists of n cores and has k cells of cache memory. Consider the work of this processor. At each cycle each core of the processor gets one instruction: either do nothing, or...
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. Little Egor likes to play with positive integers and their divisors. Bigger the number to play with, more the fun! The boy asked you to come up with an algorithm, that could ...
Solve the programming task below in a Python markdown code block. You are given a string S of length N consisting of A, B and C, and an integer K which is between 1 and N (inclusive). Print the string S after lowercasing the K-th character in it. -----Constraints----- - 1 ≀ N ≀ 50 - 1 ≀ K ≀ N - S is a string of le...
Solve the programming task below in a Python markdown code block. When you want to get the square of a binomial of two variables x and y, you will have: `$(x+y)^2 = x^2 + 2xy + y ^2$` And the cube: `$(x+y)^3 = x^3 + 3x^2y + 3xy^2 +y^3$` It is known from many centuries ago that for an exponent n, the result of a bi...
Solve the programming task below in a Python markdown code block. problem In the area where Kazakhstan is now located, there used to be a trade route called the "Silk Road". There are N + 1 cities on the Silk Road, numbered from west as city 0, city 1, ..., city N. The distance between city i -1 and city i (1 ≀ i ≀ ...
Solve the programming task below in a Python markdown code block. There was a big bank robbery in Tablecity. In order to catch the thief, the President called none other than Albert – Tablecity’s Chief of Police. Albert does not know where the thief is located, but he does know how he moves. Tablecity can be represen...
Solve the programming task below in a Python markdown code block. Your task is to write a function which counts the number of squares contained in an ASCII art picture. The input pictures contain rectangles---some of them squares---drawn with the characters `-`, `|`, and `+`, where `-` and `|` are used to represent h...
Solve the programming task below in a Python markdown code block. Note that the memory limit is unusual. You are given an integer n and two sequences a_1, a_2, ..., a_n and b_1, b_2, ..., b_n. Let's call a set of integers S such that S βŠ† \{1, 2, 3, ..., n\} strange, if, for every element i of S, the following condit...
Solve the programming task below in a Python markdown code block. You are given a colored permutation $p_1, p_2, \dots, 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]]] \dots$ where all elements have same color ($c[i] = c[p[i...
Solve the programming task below in a Python markdown code block. Professor Vasechkin is studying evolution of worms. Recently he put forward hypotheses that all worms evolve by division. There are n forms of worms. Worms of these forms have lengths a1, a2, ..., an. To prove his theory, professor needs to find 3 diffe...
Solve the programming task below in a Python markdown code block. Ichihime is the current priestess of the Mahjong Soul Temple. She claims to be human, despite her cat ears. These days the temple is holding a math contest. Usually, Ichihime lacks interest in these things, but this time the prize for the winner is her...
Solve the programming task below in a Python markdown code block. JAG mock qualifying practice session The ACM-ICPC OB / OG Association (Japanese Alumni Group; JAG) has N questions in stock of questions to be asked in the mock contest, and each question is numbered with an integer from 1 to N. Difficulty evaluation a...
Solve the programming task below in a Python markdown code block. Vasya wants to turn on Christmas lights consisting of m bulbs. Initially, all bulbs are turned off. There are n buttons, each of them is connected to some set of bulbs. Vasya can press any of these buttons. When the button is pressed, it turns on all th...
Solve the programming task below in a Python markdown code block. Digory Kirke and Polly Plummer are two kids living next door to each other. The attics of the two houses are connected to each other through a passage. Digory's Uncle Andrew has been secretly doing strange things in the attic of his house, and he always...
Solve the programming task below in a Python markdown code block. Ringo is giving a present to Snuke. Ringo has found out that Snuke loves yakiniku (a Japanese term meaning grilled meat. yaki: grilled, niku: meat). He supposes that Snuke likes grilled things starting with `YAKI` in Japanese, and does not like other t...
Solve the programming task below in a Python markdown code block. Write a program which reads two integers x and y, and prints them in ascending order. Constraints * 0 ≀ x, y ≀ 10000 * the number of datasets ≀ 3000 Input The input consists of multiple datasets. Each dataset consists of two integers x and y separat...
Solve the programming task below in a Python markdown code block. Today, Yasser and Adel are at the shop buying cupcakes. There are $n$ cupcake types, arranged from $1$ to $n$ on the shelf, and there are infinitely many of each type. The tastiness of a cupcake of type $i$ is an integer $a_i$. There are both tasty and ...
Solve the programming task below in a Python markdown code block. Gildong was hiking a mountain, walking by millions of trees. Inspired by them, he suddenly came up with an interesting idea for trees in data structures: What if we add another edge in a tree? Then he found that such tree-like graphs are called 1-trees...
Solve the programming task below in a Python markdown code block. A common problem in number theory is to find x given a such that: a * x = 1 mod [n] Then x is called the inverse of a modulo n. Your goal is to code a function inverseMod wich take a and n as parameters and return x. You may be interested by these...
Solve the programming task below in a Python markdown code block. Imagine a city with n horizontal streets crossing m vertical streets, forming an (n - 1) Γ— (m - 1) grid. In order to increase the traffic flow, mayor of the city has decided to make each street one way. This means in each horizontal street, the traffic ...
Solve the programming task below in a Python markdown code block. When l is an odd number, the median of l numbers a_1, a_2, ..., a_l is the (\frac{l+1}{2})-th largest value among a_1, a_2, ..., a_l. You are given N numbers X_1, X_2, ..., X_N, where N is an even number. For each i = 1, 2, ..., N, let the median of X_...
Solve the programming task below in a Python markdown code block. An NBA game runs 48 minutes (Four 12 minute quarters). Players do not typically play the full game, subbing in and out as necessary. Your job is to extrapolate a player's points per game if they played the full 48 minutes. Write a function that takes t...
Solve the programming task below in a Python markdown code block. Childan is making up a legendary story and trying to sell his forgery β€” a necklace with a strong sense of "Wu" to the Kasouras. But Mr. Kasoura is challenging the truth of Childan's story. So he is going to ask a few questions about Childan's so-called ...
Solve the programming task below in a Python markdown code block. Petya and Vasya decided to play a little. They found n red cubes and m blue cubes. The game goes like that: the players take turns to choose a cube of some color (red or blue) and put it in a line from left to right (overall the line will have n + m cub...
Solve the programming task below in a Python markdown code block. Let's denote that some array $b$ is bad if it contains a subarray $b_l, b_{l+1}, \dots, b_{r}$ of odd length more than $1$ ($l < r$ and $r - l + 1$ is odd) such that $\forall i \in \{0, 1, \dots, r - l\}$ $b_{l + i} = b_{r - i}$. If an array is not bad...
Solve the programming task below in a Python markdown code block. In the 17th century, Fermat wrote that he proved for any integer $n \geq 3$, there exist no positive integers $x$, $y$, $z$ such that $x^n + y^n = z^n$. However he never disclosed the proof. Later, this claim was named Fermat's Last Theorem or Fermat's ...
Solve the programming task below in a Python markdown code block. You are solving the crossword problem K from IPSC 2014. You solved all the clues except for one: who does Eevee evolve into? You are not very into pokemons, but quick googling helped you find out, that Eevee can evolve into eight different pokemons: Vap...
Solve the programming task below in a Python markdown code block. Sig has built his own keyboard. Designed for ultimate simplicity, this keyboard only has 3 keys on it: the 0 key, the 1 key and the backspace key. To begin with, he is using a plain text editor with this keyboard. This editor always displays one string ...
Solve the programming task below in a Python markdown code block. Kolya Gerasimov loves kefir very much. He lives in year 1984 and knows all the details of buying this delicious drink. One day, as you probably know, he found himself in year 2084, and buying kefir there is much more complicated. Kolya is hungry, so he...
Solve the programming task below in a Python markdown code block. In this Kata you are a game developer and have programmed the #1 MMORPG(Massively Multiplayer Online Role Playing Game) worldwide!!! Many suggestions came across you to make the game better, one of which you are interested in and will start working on a...
Solve the programming task below in a Python markdown code block. ## Task Given a positive integer `n`, calculate the following sum: ``` n + n/2 + n/4 + n/8 + ... ``` All elements of the sum are the results of integer division. ## Example ``` 25 => 25 + 12 + 6 + 3 + 1 = 47 ``` Read the inputs from stdin solv...
Solve the programming task below in a Python markdown code block. You are given strings S and T consisting of lowercase English letters. You can perform the following operation on S any number of times: Operation: Choose two distinct lowercase English letters c_1 and c_2, then replace every occurrence of c_1 with c_2,...
Solve the programming task below in a Python markdown code block. As bad weather continues and vegetable prices soar, Seven-Eleven is offering customers bulk purchase sales of vegetables. The store is very busy, as you can get vegetables that are hard to find in stores at reasonable prices. One day, a group of three ...
Solve the programming task below in a Python markdown code block. A piece of paper contains an array of n integers a1, a2, ..., an. Your task is to find a number that occurs the maximum number of times in this array. However, before looking for such number, you are allowed to perform not more than k following operati...
Solve the programming task below in a Python markdown code block. Two neighboring kingdoms decided to build a wall between them with some gates to enable the citizens to go from one kingdom to another. Each time a citizen passes through a gate, he has to pay one silver coin. The world can be represented by the first ...
Solve the programming task below in a Python markdown code block. Little boy Gerald studies at school which is quite far from his house. That's why he has to go there by bus every day. The way from home to school is represented by a segment of a straight line; the segment contains exactly n + 1 bus stops. All of them ...