You are given an array of integers π1,π2,β¦,ππ and a number π (2β€πβ€5 ). In one operation, you can do the following: Choose an index 1β€πβ€π , Set ππ=ππ+1 . Find the minimum number of operations needed to make the product of all the numbers in the array π1β π2β β¦β ππ divisible by π .
Galaxy Luck, a well-known casino in the entire solar system, introduces a new card game. In this game, there is a deck that consists of π cards. Each card has π numbers written on it. Each of the π players receives exactly one card from the deck. Then all players play with each other in pairs, and each pair of players plays exactly once. Thus, if there are, for example, four players in total, then six games are played: the first against the second, the first against the third, the first against the fourth, the second against the third, the second against the fourth and the third against the fourth.
You are given a string π consisting of π lowercase Latin letters. Let's define a substring as a contiguous subsegment of a string. For example, "acab" is a substring of "abacaba" (it starts in position 3 and ends in position 6 ), but "aa" or "d" aren't substrings of this string. So the substring of the string π from position π to position π is π [π;π]=π ππ π+1β¦π π . You have to choose exactly one of the substrings of the given string and reverse it (i.βe. make π [π;π]=π ππ πβ1β¦π π ) to obtain a string that is less lexicographically. Note that it is not necessary to obtain the minimum possible string.
Tema and Vika are playing the following game. First, Vika comes up with a sequence of positive integers π of length π and writes it down on a piece of paper. Then she takes a new piece of paper and writes down the sequence π according to the following rule: First, she writes down π1 . Then, she writes down only those ππ (2β€πβ€π ) such that ππβ1β€ππ . Let the length of this sequence be denoted as π .
You are given 3 integers β π , π₯ , π¦ . Let's call the score of a permutationβ π1,β¦,ππ the following value: (π1β π₯+π2β π₯+β¦+πβππ₯ββ π₯)β(π1β π¦+π2β π¦+β¦+πβππ¦ββ π¦) In other words, the score of a permutation is the sum of ππ for all indices π divisible by π₯ , minus the sum of ππ for all indices π divisible by π¦ . You need to find the maximum possible score among all permutations of length π . For example, if π=7 , π₯=2 , π¦=3 , the maximum score is achieved by the permutation [2,6β―β―,1β―β―,7β―β―,5,4β―β―β―β―,3] and is equal to (6+7+4)β(1+4)=17β5=12 .
Artem suggested a game to the girl Olya. There is a list of π arrays, where the π -th array contains ππβ₯2 positive integers ππ,1,ππ,2,β¦,ππ,ππ . Olya can move at most one (possibly 0 ) integer from each array to another array. Note that integers can be moved from one array only once, but integers can be added to one array multiple times, and all the movements are done at the same time.
We call a positive integer number fair if it is divisible by each of its nonzero digits. For example, 102 is fair (because it is divisible by 1 and 2 ), but 282 is not, because it isn't divisible by 8 . Given a positive integer π . Find the minimum integer π₯ , such that πβ€π₯ and π₯ is fair.
Monocarp is playing yet another computer game. And yet again, his character is killing some monsters. There are π monsters, numbered from 1 to π , and the π -th of them has ππ health points initially.
The company "Divan's Sofas" is planning to build π+1 different buildings on a coordinate line so that: the coordinate of each building is an integer number; no two buildings stand at the same point. Let π₯π be the coordinate of the π -th building. To get from the building π to the building π , Divan spends |π₯πβπ₯π| minutes, where |π¦| is the absolute value of π¦ .
Given an array π of length π , which elements are equal to β1 and 1 . Let's call the array π good if the following conditions are held at the same time: π1+π2+β¦+ππβ₯0 ; π1β π2β β¦β ππ=1 . In one operation, you can select an arbitrary element of the array ππ and change its value to the opposite. In other words, if ππ=β1 , you can assign the value to ππ:=1 , and if ππ=1 , then assign the value to ππ:=β1 .
Winter holidays are coming up. They are going to last for π days. During the holidays, Monocarp wants to try all of these activities exactly once with his friends: go skiing; watch a movie in a cinema; play board games. Monocarp knows that, on the π -th day, exactly ππ friends will join him for skiing, ππ friends will join him for a movie and ππ friends will join him for board games.
Recently, on the course of algorithms and data structures, Valeriy learned how to use a deque. He built a deque filled with π elements. The π -th element is ππ (π = 1,2,β¦,π ). He gradually takes the first two leftmost elements from the deque (let's call them π΄ and π΅ , respectively), and then does the following:
You are given two arrays π and π both of length π . You will mergeβ these arrays forming another array π of length 2β π . You have to find the maximum length of a subarray consisting of equal values across all arrays π that could be obtained.
Dima Vatrushin is a math teacher at school. He was sent on vacation for π days for his good work. Dima has long dreamed of going to a ski resort, so he wants to allocate several consecutive days and go skiing. Since the vacation requires careful preparation, he will only go for at least π days.
A class of students got bored wearing the same pair of shoes every day, so they decided to shuffle their shoes among themselves. In this problem, a pair of shoes is inseparable and is considered as a single object. There are π students in the class, and you are given an array π in non-decreasing order, where π π is the shoe size of the π -th student. A shuffling of shoes is valid only if no student gets their own shoes and if every student gets shoes of size greater than or equal to their size.