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.
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 𝑘 .
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.
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 .
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.
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.
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.
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.
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 𝑦 .
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.