question_text
stringlengths
2
3.82k
input_outputs
stringlengths
23
941
algo_tags
sequence
You are given a string s, consisting of lowercase English letters. In one operation, you are allowed to swap any two characters of the string s.A string s of length n is called an anti-palindrome, if s[i]!=s[n - i + 1] for every i (1 <= i <= n). For example, the strings "codeforces", "string" are anti-palindromes, but the strings "abacaba", "abc", "test" are not.Determine the minimum number of operations required to make the string s an anti-palindrome, or output -1, if this is not possible.
Input: ['1010codeforces3abc10taarrrataa10dcbdbdcccc4wwww12cabbaccabaac10aadaaaaddc14aacdaaaacadcdc6abccba12dcbcaebacccd'] Output:['0', '-1', '1', '1', '-1', '3', '-1', '2', '2', '2', '']
[ 2, 3 ]
A permutation is a sequence n integers, where each integer from 1 to n appears exactly once. For example, [1], [3,5,2,1,4], [1,3,2] are permutations, while [2,3,2], [4,3,1], [0] are not.Given a permutation a, we construct an array b, where b_i = (a_1 + a_2 +~...~+ a_i) \bmod n.A permutation of numbers [a_1, a_2, ..., a_n] is called a super-permutation if [b_1 + 1, b_2 + 1, ..., b_n + 1] is also a permutation of length n.Grisha became interested whether a super-permutation of length n exists. Help him solve this non-trivial problem. Output any super-permutation of length n, if it exists. Otherwise, output -1.
Input: ['41236'] Output:['1', '2 1', '-1', '6 5 2 3 4 1']
[ 3 ]
Tema loves cinnabon rolls β€” buns with cinnabon and chocolate in the shape of a "snail".Cinnabon rolls come in different sizes and are square when viewed from above. The most delicious part of a roll is the chocolate, which is poured in a thin layer over the cinnabon roll in the form of a spiral and around the bun, as in the following picture: Cinnabon rolls of sizes 4, 5, 6 For a cinnabon roll of size n, the length of the outer side of the square is n, and the length of the shortest vertical chocolate segment in the central part is one.Formally, the bun consists of two dough spirals separated by chocolate. A cinnabon roll of size n + 1 is obtained from a cinnabon roll of size n by wrapping each of the dough spirals around the cinnabon roll for another layer.It is important that a cinnabon roll of size n is defined in a unique way.Tema is interested in how much chocolate is in his cinnabon roll of size n. Since Tema has long stopped buying small cinnabon rolls, it is guaranteed that n >= 4.Answer this non-obvious question by calculating the total length of the chocolate layer.
Input: ['4456179179179'] Output:['26', '37', '50', '32105178545472401', '']
[ 3 ]
Karina has an array of n integers a_1, a_2, a_3, ..., a_n. She loves multiplying numbers, so she decided that the beauty of a pair of numbers is their product. And the beauty of an array is the maximum beauty of a pair of adjacent elements in the array.For example, for n = 4, a=[3, 5, 7, 4], the beauty of the array is \max(3 \cdot 5, 5 \cdot 7, 7 \cdot 4) = \max(15, 35, 28) = 35.Karina wants her array to be as beautiful as possible. In order to achieve her goal, she can remove some elements (possibly zero) from the array. After Karina removes all elements she wants to, the array must contain at least two elements.Unfortunately, Karina doesn't have enough time to do all her tasks, so she asks you to calculate the maximum beauty of the array that she can get by removing any number of elements (possibly zero).
Input: ['745 0 2 13-1 1 052 0 -1 -4 06-8 4 3 7 1 -960 3 -2 5 -4 -421000000000 9100000007-1 -7 -2 -5 -4 -6 -3'] Output:['10', '0', '4', '72', '16', '910000000000000000', '42', '']
[ 2, 3 ]
Mushroom Filippov cooked himself a meal and while having his lunch, he decided to watch a video on TubeTube. He can not spend more than t seconds for lunch, so he asks you for help with the selection of video.The TubeTube feed is a list of n videos, indexed from 1 to n. The i-th video lasts a_i seconds and has an entertainment value b_i. Initially, the feed is opened on the first video, and Mushroom can skip to the next video in 1 second (if the next video exists). Mushroom can skip videos any number of times (including zero).Help Mushroom choose one video that he can open and watch in t seconds. If there are several of them, he wants to choose the most entertaining one. Print the index of any appropriate video, or -1 if there is no such.
Input: ['55 91 5 7 6 63 4 7 1 94 44 3 3 21 2 3 45 75 5 5 5 52 1 3 9 74 3354 71 69 9642 24 99 12 17955 6677 88'] Output:['3', '2', '3', '-1', '2', '']
[ 0 ]
There is a beautiful alley with trees in front of a shopping mall. Unfortunately, it has to go to make space for the parking lot.The trees on the alley all grow in a single line. There are n spots for trees, index 0 is the shopping mall, index n+1 is the road and indices from 1 to n are the spots for trees. Some of them are taken β€” there grow trees of the same height k. No more than one tree grows in each spot.When you chop down a tree in the spot x, you can make it fall either left or right. If it falls to the left, it takes up spots from x-k to x, inclusive. If it falls to the right, it takes up spots from x to x+k, inclusive.Let m trees on the alley grow in some spots x_1, x_2, ..., x_m. Let an alley be called unfortunate if all m trees can be chopped down in such a way that: no tree falls on the shopping mall or the road; each spot is taken up by no more than one fallen tree. Calculate the number of different unfortunate alleys with m trees of height k. Two alleys are considered different if there is a spot y such that a tree grows in y on the first alley and doesn't grow in y on the second alley.Output the number modulo 998\,244\,353.
Input: ['6 1 4', ''] Output:['4', '']
[ 3 ]
A regular bracket sequence is a bracket sequence that can be transformed into a correct arithmetic expression by inserting characters "1" and "+" between the original characters of the sequence. For example: bracket sequences "()()" and "(())" are regular (the resulting expressions are: "(1)+(1)" and "((1+1)+1)"); bracket sequences ")(", "(" and ")" are not. You are given a regular bracket sequence. In one move, you can remove a pair of adjacent brackets such that the left one is an opening bracket and the right one is a closing bracket. Then concatenate the resulting parts without changing the order. The cost of this move is the number of brackets to the right of the right bracket of this pair.The cost of the regular bracket sequence is the smallest total cost of the moves required to make the sequence empty.Actually, you are not removing any brackets. Instead, you are given a regular bracket sequence and an integer k. You can perform the following operation at most k times: extract some bracket from the sequence and insert it back at any position (between any two brackets, at the start or at the end; possibly, at the same place it was before). After all operations are performed, the bracket sequence has to be regular. What is the smallest possible cost of the resulting regular bracket sequence?
Input: ['70()0(())1(())5()1(()()(()))2((())()(()())((())))3((())()(()())((())))'] Output:['0', '1', '0', '0', '1', '4', '2', '']
[ 0, 2 ]
You are playing with a really long strip consisting of 10^{18} white cells, numbered from left to right as 0, 1, 2 and so on. You are controlling a special pointer that is initially in cell 0. Also, you have a "Shift" button you can press and hold.In one move, you can do one of three actions: move the pointer to the right (from cell x to cell x + 1); press and hold the "Shift" button; release the "Shift" button: the moment you release "Shift", all cells that were visited while "Shift" was pressed are colored in black. (Of course, you can't press Shift if you already hold it. Similarly, you can't release Shift if you haven't pressed it.)Your goal is to color at least k cells, but there is a restriction: you are given n segments [l_i, r_i] β€” you can color cells only inside these segments, i. e. you can color the cell x if and only if l_i <= x <= r_i for some i.What is the minimum number of moves you need to make in order to color at least k cells black?
Input: ['42 31 31 44 2010 13 16 1911 14 17 202 31 31 102 499 999999999100 1000000000'] Output:['8', '-1', '7', '1000000004', '']
[ 0, 2, 3, 4 ]
You are given a string s, consisting of lowercase Latin letters.In one operation, you can select several (one or more) positions in it such that no two selected positions are adjacent to each other. Then you remove the letters on the selected positions from the string. The resulting parts are concatenated without changing their order.What is the smallest number of operations required to make all the letters in s the same?
Input: ['5abacabacodeforcesooooooooabcdefmewheniseearulhiiarul'] Output:['1', '3', '0', '2', '4', '']
[ 0, 3 ]
Monocarp had an array a consisting of n integers. He has decided to choose two integers l and r such that 1 <= l <= r <= n, and then sort the subarray a[l..r] (the subarray a[l..r] is the part of the array a containing the elements a_l, a_{l+1}, a_{l+2}, ..., a_{r-1}, a_r) in non-descending order. After sorting the subarray, Monocarp has obtained a new array, which we denote as a'.For example, if a = [6, 7, 3, 4, 4, 6, 5], and Monocarp has chosen l = 2, r = 5, then a' = [6, 3, 4, 4, 7, 6, 5].You are given the arrays a and a'. Find the integers l and r that Monocarp could have chosen. If there are multiple pairs of values (l, r), find the one which corresponds to the longest subarray.
Input: ['376 7 3 4 4 6 56 3 4 4 7 6 531 2 11 1 232 2 12 1 2'] Output:['2 5', '1 3', '2 3', '']
[ 0, 2 ]
An integer template is a string consisting of digits and/or question marks.A positive (strictly greater than 0) integer matches the integer template if it is possible to replace every question mark in the template with a digit in such a way that we get the decimal representation of that integer without any leading zeroes.For example: 42 matches 4?; 1337 matches ????; 1337 matches 1?3?; 1337 matches 1337; 3 does not match ??; 8 does not match ???8; 1337 does not match 1?7. You are given an integer template consisting of at most 5 characters. Calculate the number of positive (strictly greater than 0) integers that match it.
Input: ['8???09031??7?5?9??99'] Output:['90', '9', '0', '1', '0', '100', '90', '100', '']
[ 3 ]
Did you think there was going to be a JoJo legend here? But no, that was me, Dio!Given a binary string s of length n, consisting of characters 0 and 1. Let's build a square table of size n * n, consisting of 0 and 1 characters as follows.In the first row of the table write the original string s. In the second row of the table write cyclic shift of the string s by one to the right. In the third row of the table, write the cyclic shift of line s by two to the right. And so on. Thus, the row with number k will contain a cyclic shift of string s by k to the right. The rows are numbered from 0 to n - 1 top-to-bottom.In the resulting table we need to find the rectangle consisting only of ones that has the largest area.We call a rectangle the set of all cells (i, j) in the table, such that x_1 <= i <= x_2 and y_1 <= j <= y_2 for some integers 0 <= x_1 <= x_2 < n and 0 <= y_1 <= y_2 < n.Recall that the cyclic shift of string s by k to the right is the string s_{n-k+1} ... s_n s_1 s_2 ... s_{n-k}. For example, the cyclic shift of the string "01011" by 0 to the right is the string itself "01011", its cyclic shift by 3 to the right is the string "01101".
Input: ['501101011110101010'] Output:['0', '1', '2', '6', '1', '']
[ 3 ]
This is an interactive problem.As is well known, the city "E" has never had its roads repaired in its a thousand and a half years old history. And only recently the city administration repaired some of them.It is known that in total in the city "E" there are n intersections and m roads, which can be used in both directions, numbered with integers from 1 to m. The i-th road connects intersections with numbers a_i and b_i.Among all m roads, some subset of the roads has been repaired, but you do not know which one. The only information you could get from the city's road services is that you can get from any intersection to any other intersection by driving only on the roads that have been repaired.You are a young entrepreneur, and decided to organize a delivery service of fresh raw meat in the city "E" (in this city such meat is called "steaks", it is very popular among the locals). You have already recruited a staff of couriers, but the couriers are willing to travel only on repaired roads. Now you have to find out which roads have already been repaired.The city administration has given you the city for a period of time, so you can make different queries of one of three types: Block the road with the number x. In this case, movement on the road for couriers will be forbidden. Initially all roads are unblocked. Unblock the road with the number x. In this case, couriers will be able to move on the road x if it is repaired. Try to deliver the order to the intersection with the number y. In this case, one of your couriers will start moving from intersection with number s you don't know and deliver the order to intersection with number y if there is a path on unblocked repaired roads from intersection s to intersection y. It is guaranteed that intersection s will be chosen beforehand. Unfortunately, the city is placed at your complete disposal for a short period of time, so you can make no more than 100 \cdot m requests.
Input: ['2', '2 2', '1 2', '2 1', '', '', '1', '', '0', '', '', '', '1', '', '1', '3 3', '1 2', '2 3', '3 1', '', '', '1', '', '1', '', '', '1', '', '0', '', '', '1', '', '1', '', '1', '', '1'] Output:['', '', '', '', '- 1', '? 1', '', '? 2', '', '- 2', '+ 1', '? 1', '', '! 1 0', '', '', '', '', '', '- 1', '? 2', '', '? 1', '', '- 2', '? 3', '', '? 3', '', '+ 1', '? 3', '', '? 2', '', '? 1', '', '! 1 1 1']
[ 3 ]
Schoolboy Misha got tired of doing sports programming, so he decided to quit everything and go to the magical forest to sell magic apples.His friend Danya came to the magical forest to visit Misha. What was his surprise when he found out that Misha found a lot of friends there, the same former sports programmers. And all of them, like Misha, have their own shop where they sell magic apples. To support his friends, who have changed their lives so drastically, he decided to buy up their entire assortment.The buying process works as follows: in total there are n stalls, numbered with integers from 1 to n, and m kinds of magic apples, numbered with integers from 1 to m. Each shop sells some number of kinds of apples. Danya visits all the shops in order of increasing number, starting with the first one. Upon entering the shop he buys one magic apple of each kind sold in that shop and puts them in his backpack.However, magical apples wouldn't be magical if they were all right. The point is that when two apples of the same type end up together in the backpack, all of the apples in it magically disappear. Importantly, the disappearance happens after Danya has put the apples in the backpack and left the shop.Upon returning home, Danya realized that somewhere in the forest he had managed to lose his backpack. Unfortunately, for some shops Danya had forgotten what assortment of apples there was. Remembering only for some shops, what kinds of magical apples were sold in them, he wants to know what is the maximum number of apples he could have in his backpack after all his purchases at best.
Input: ['43 42 1 22 4 12 1 24 42 1 22 3 401 12 5005 303 1 2 32 3 101 3'] Output:['2', '1', '5', '3', '']
[ 0 ]
The fox Yae climbed the tree of the Sacred Sakura. A tree is a connected undirected graph that does not contain cycles.The fox uses her magical powers to move around the tree. Yae can jump from vertex v to another vertex u if and only if the distance between these vertices does not exceed 2. In other words, in one jump Yae can jump from vertex v to vertex u if vertices v and u are connected by an edge, or if there exists such vertex w that vertices v and w are connected by an edge, and also vertices u and w are connected by an edge.After Yae was able to get the sakura petal, she wondered if there was a cyclic route in the tree v_1, v_2, ..., v_n such that: the fox can jump from vertex v_i to vertex v_{i + 1}, the fox can jump from vertex v_n to vertex v_1, all v_i are pairwise distinct. Help the fox determine if the required traversal exists.
Input: ['5', '1 2', '1 3', '3 4', '3 5', ''] Output:['Yes', '4 5 1 2 3 ', '']
[ 3 ]
Anton plays his favorite game "Defense of The Ancients 2" for his favorite hero β€” The Butcher. Now he wants to make his own dinner. To do this he will take a rectangle of height h and width w, then make a vertical or horizontal cut so that both resulting parts have integer sides. After that, he will put one of the parts in the box and cut the other again, and so on.More formally, a rectangle of size h * w can be cut into two parts of sizes x * w and (h - x) * w, where x is an integer from 1 to (h - 1), or into two parts of sizes h * y and h * (w - y), where y is an integer from 1 to (w - 1).He will repeat this operation n - 1 times, and then put the remaining rectangle into the box too. Thus, the box will contain n rectangles, of which n - 1 rectangles were put in the box as a result of the cuts, and the n-th rectangle is the one that the Butcher has left after all n - 1 cuts.Unfortunately, Butcher forgot the numbers h and w, but he still has n rectangles mixed in random order. Note that Butcher didn't rotate the rectangles, but only shuffled them. Now he wants to know all possible pairs (h, w) from which this set of rectangles can be obtained. And you have to help him do it!It is guaranteed that there exists at least one pair (h, w) from which this set of rectangles can be obtained.
Input: ['431 23 51 331 11 11 1110 1043 25 52 28 7'] Output:['1', '4 5', '2', '1 3', '3 1', '1', '10 10', '1', '13 7', '']
[ 2 ]
As you know, any problem that does not require the use of complex data structures is considered constructive. You are offered to solve one of such problems.You are given an array a of n non-negative integers. You are allowed to perform the following operation exactly once: choose some non-empty subsegment a_l, a_{l+1}, ..., a_r of the array a and a non-negative integer k, and assign value k to all elements of the array on the chosen subsegment.The task is to find out whether \operatorname{MEX}(a) can be increased by exactly one by performing such an operation. In other words, if before the operation \operatorname{MEX}(a) = m held, then after the operation it must hold that \operatorname{MEX}(a) = m + 1.Recall that \operatorname{MEX} of a set of integers c_1, c_2, ..., c_k is defined as the smallest non-negative integer x which does not occur in the set c.
Input: ['431 2 140 2 2 043 2 0 210'] Output:['Yes', 'Yes', 'No', 'No', '']
[ 0, 2 ]
In a debate club with n members, including yourself (member 1), there are k opinions to be discussed in sequence. During each discussion, members express their agreement or disagreement with the opinion. Let's define Y as the number of members who agree and N as the number of members who disagree. After each discussion, members leave the club based on the following criteria: If more members agree than disagree (Y > N), all members who disagreed leave the club. If more members disagree than agree (Y < N), all members who agreed leave the club. If there is a tie (Y = N), all members leave the club. As the club president, your goal is to stay in the club and maximize the number of members remaining after the meeting. You have access to each member's stance on all k opinions before the meeting starts, and you can expel any number of members (excluding yourself) before the meeting begins.Determine the maximum number of members, including yourself, who can remain in the club after the meeting. You don't need to provide the specific expulsion strategy but only the maximum number of members that can stay. Ensure that you remain in the club after the meeting as well.
Input: ['52 2+++-1 3+-+4 1+--+5 4+++++--+++-++-++++++4 2++-----+'] Output:['1', '1', '2', '2', '1', '']
[ 2 ]
You're given a multiset of non-negative integers \{a_1, a_2, ..., a_n\}.In one step you take two elements x and y of the multiset, remove them and insert their mean value \frac{x + y}{2} back into the multiset.You repeat the step described above until you are left with only two numbers A and B. What is the maximum possible value of their absolute difference |A-B|?Since the answer is not an integer number, output it modulo 10^9+7.
Input: ['527 341 2 10 1131 2 3664 32 64 16 64 041 1 1 1'] Output:['4', '9', '500000005', '59', '0', '']
[ 0, 2 ]
A polynomial A(x) of degree d is an expression of the form A(x) = a_0 + a_1 x + a_2 x^2 + ... + a_d x^d, where a_i are integers, and a_d \neq 0. Two polynomials A(x) and B(x) are called similar if there is an integer s such that for any integer x it holds that B(x) \equiv A(x+s) \pmod{10^9+7}. For two similar polynomials A(x) and B(x) of degree d, you're given their values in the points x=0,1,..., d modulo 10^9+7.Find a value s such that B(x) \equiv A(x+s) \pmod{10^9+7} for all integers x.
Input: ['1', '1000000006 0', '2 3', ''] Output:['3', '']
[ 3 ]
You are given a simple undirected graph with n nodes and m edges. Note that the graph is not necessarily connected. The nodes are labeled from 1 to n.We define a graph to be a Fish Graph if it contains a simple cycle with a special node u belonging to the cycle. Apart from the edges in the cycle, the graph should have exactly 2 extra edges. Both edges should connect to node u, but they should not be connected to any other node of the cycle. Determine if the graph contains a subgraph that is a Fish Graph, and if so, find any such subgraph.In this problem, we define a subgraph as a graph obtained by taking any subset of the edges of the original graph. Visualization of example 1. The red edges form one possible subgraph that is a Fish Graph.
Input: ['37 81 22 33 44 14 54 64 26 77 76 71 22 33 44 11 33 54 41 33 44 11 2'] Output:['YES', '6', '5 4', '6 4', '4 3', '1 4', '2 1', '3 2', 'YES', '5', '5 3', '2 3', '3 1', '4 3', '1 4', 'NO', '']
[ 0 ]
A sequence is almost-increasing if it does not contain three consecutive elements x, y, z such that x>= y>= z.You are given an array a_1, a_2, ..., a_n and q queries.Each query consists of two integers 1<= l<= r<= n. For each query, find the length of the longest almost-increasing subsequence of the subarray a_l, a_{l+1}, ..., a_r. A subsequence is a sequence that can be derived from the given sequence by deleting zero or more elements without changing the order of the remaining elements.
Input: ['9 8', '1 2 4 3 3 5 6 2 1', '1 3', '1 4', '2 5', '6 6', '3 7', '7 8', '1 8', '8 8', ''] Output:['3', '4', '3', '1', '4', '2', '7', '1', '']
[ 2, 4 ]
Consider a 2 * n grid, where n is an even integer. You may place the integers 1, 2, ..., 2n on the grid, using each integer exactly once.A path is a sequence of cells achieved by starting at (1, 1), then repeatedly walking either downwards or to the right, and stopping when (2, n) is reached. The path should not extend beyond the grid.The cost of a path is the alternating sum of the numbers written on the cells in a path. That is, let the numbers written on the cells be a_1, a_2, ..., a_k (in the order that it is visited), the cost of the path is a_1 - a_2 + a_3 - a_4 + ... = \sum_{i=1}^k a_i \cdot (-1)^{i+1}.Construct a way to place the integers 1, 2, ..., 2n on the grid, such that the minimum cost over all paths from (1, 1) to (2, n) is maximized. If there are multiple such grids that result in the maximum value, output any of them.
Input: ['3246'] Output:['3 2', '1 4', '8 2 6 4', '1 5 3 7', '11 5 9 1 7 3', '6 10 2 8 4 12', '']
[ 2 ]
You are given an undirected graph with n vertices and 3m edges. The graph may contain multi-edges, but does not contain self-loops. The graph satisfies the following property: the given edges can be divided into m groups of 3, such that each group is a triangle.A triangle is defined as three edges (a,b), (b,c) and (c,a) for some three distinct vertices a,b,c (1 <=q a,b,c <=q n).Initially, each vertex v has a non-negative integer weight a_v. For every edge (u,v) in the graph, you should perform the following operation exactly once: Choose an integer x between 1 and 4. Then increase both a_u and a_v by x. After performing all operations, the following requirement should be satisfied: if u and v are connected by an edge, then a_u!=a_v.It can be proven this is always possible under the constraints of the task. Output a way to do so, by outputting the choice of x for each edge. It is easy to see that the order of operations does not matter. If there are multiple valid answers, output any.
Input: ['44 10 0 0 01 2 35 20 0 0 0 01 2 31 4 54 43 4 5 61 2 31 2 41 3 42 3 45 40 1000000 412 412 4121 2 31 4 52 4 53 4 5'] Output:['2 1 3', '2 3 3', '4 3 3', '3 1 2', '2 2 3', '2 3 4', '3 1 1', '2 3 4', '1 2 4', '4 4 3', '4 1 1']
[ 3 ]
Bosco is studying the behaviour of particles. He decided to investigate on the peculiar behaviour of the so-called "four-one-two" particle. He does the following:There is a line of length n+1, where the topmost point is position 0 and bottommost is position n+1. The particle is initially (at time t=0) at position 0 and heading downwards. The particle moves at the speed of 1 unit per second. There are n oscillators at positions 1,2,...,n.Each oscillator can be described by a binary string. The initial state of each oscillator is the first character of its binary string. When the particle hits with an oscillator, the particle reverses its direction if its current state is \texttt{1} and continues to move at the same direction if its current state is \texttt{0}, and that oscillator moves on to the next state (the next state of the last state is defined as the first state). Additionally, the particle always reverses its direction when it is at position 0 or n+1 at time t > 0.Bosco would like to know the cycle length of the movement of particle. The cycle length is defined as the minimum value of c such that for any time t >= 0, the position of the particle at time t is same as the position of the particle at time t+c. It can be proved that such value c always exists. As he realises the answer might be too large, he asks you to output your answer modulo 998244353.
Input: ['1', '00', ''] Output:['4', '']
[ 3 ]
Given two positive integers n and m. Find the sum of all possible values of a_1\bigoplus a_2\bigoplus...\bigoplus a_m, where a_1,a_2,...,a_m are non-negative integers such that a_1+a_2+...+a_m=n.Note that all possible values a_1\bigoplus a_2\bigoplus...\bigoplus a_m should be counted in the sum exactly once.As the answer may be too large, output your answer modulo 998244353.Here, \bigoplus denotes the bitwise XOR operation.
Input: ['769 15 20 10420 6912 2673 341000000000000000000 10'] Output:['69', '6', '0', '44310', '42', '1369', '216734648', '']
[ 3 ]
You are given an integer n, as well as m pairs of integers (a_i,b_i), where 1<=q a_i , b_i <=q n, a_i!=b_i.You want to construct a sequence satisfying the following requirements: All elements in the sequence are integers between 1 and n. There is exactly one element with value 1 in the sequence. For each i (1 <= i <= m), between any two elements (on different positions) in the sequence with value a_i, there is at least one element with value b_i. The sequence constructed has the maximum length among all possible sequences satisfying the above properties. Sometimes, it is possible that such a sequence can be arbitrarily long, in which case you should output "INFINITE". Otherwise, you should output "FINITE" and the sequence itself. If there are multiple possible constructions that yield the maximum length, output any.
Input: ['53 23 12 11 02 02 21 22 15 52 13 14 24 55 1'] Output:['FINITE', '5', '2 3 1 2 3 ', 'FINITE', '1', '1 ', 'INFINITE', 'FINITE', '3', '2 1 2 ', 'FINITE', '10', '4 2 3 5 4 1 3 2 5 4 ']
[ 2 ]
This is an interactive problem.There is a hidden permutation p_1, p_2, ..., p_n. Consider an undirected graph with n nodes only with no edges. You can make two types of queries: Specify an integer x satisfying 2 <= x <= 2n. For all integers i (1 <= i <= n) such that 1 <= x-i <= n, an edge between node i and node x-i will be added. Query the number of edges in the shortest path between node p_i and node p_j. As the answer to this question you will get the number of edges in the shortest path if such a path exists, or -1 if there is no such path. Note that you can make both types of queries in any order.Within 2n queries (including type 1 and type 2), guess two possible permutations, at least one of which is p_1, p_2, ..., p_n. You get accepted if at least one of the permutations is correct. You are allowed to guess the same permutation twice.A permutation of length n is an array consisting of n distinct integers from 1 to n in arbitrary order. For example, [2,3,1,5,4] is a permutation, but [1,2,2] is not a permutation (2 appears twice in the array), and [1,3,4] is also not a permutation (n=3 but there is 4 in the array).
Input: ['2', '6', '', '1', '', '1', '', '1', '', '1', '', '1', '', '2', '', '-1', '', '1', '2', '', '1', ''] Output:['', '', '+ 12', '', '+ 2', '', '+ 3', '', '? 1 3', '', '+ 5', '', '? 1 5', '', '? 4 5', '', '! 1 4 2 5 3 6 1 2 3 4 5 6', '', '', '! 1 2 2 1', '', '']
[ 0 ]
To thank Ian, Mary gifted an array a of length n to Ian. To make himself look smart, he wants to make the array in non-decreasing order by doing the following finitely many times: he chooses two adjacent elements a_i and a_{i+1} (1<= i<= n-1), and increases both of them by 1 or decreases both of them by 1. Note that, the elements of the array can become negative.As a smart person, you notice that, there are some arrays such that Ian cannot make it become non-decreasing order! Therefore, you decide to write a program to determine if it is possible to make the array in non-decreasing order.
Input: ['531 3 222 141 3 5 742 1 4 355 4 3 2 1'] Output:['YES', 'NO', 'YES', 'NO', 'YES', '']
[ 2, 3 ]
There are n communication towers, numbered from 1 to n, and m bidirectional wires between them. Each tower has a certain set of frequencies that it accepts, the i-th of them accepts frequencies from l_i to r_i.Let's say that a tower b is accessible from a tower a, if there exists a frequency x and a sequence of towers a=v_1, v_2, ..., v_k=b, where consecutive towers in the sequence are directly connected by a wire, and each of them accepts frequency x. Note that accessibility is not transitive, i. e if b is accessible from a and c is accessible from b, then c may not be accessible from a.Your task is to determine the towers that are accessible from the 1-st tower.
Input: ['6 5', '3 5', '1 2', '2 4', '2 3', '3 3', '4 6', '1 3', '6 1', '3 5', '3 6', '2 3', ''] Output:['1 3 5 6 ']
[ 0 ]
You've got a job in a game studio that developed an online shooter, and your first big task is to help to balance weapons. The game has n weapons: the i-th gun has an integer fire rate f_i and an integer damage per bullet d_i. The i-th gun's total firepower is equal to p_i = f_i \cdot d_i.You have to modify the values d_i of some guns in such a way that the new values d_i will still be integers, and the firepower of all guns will become balanced. Given an integer k, the guns are said to be balanced if \max\limits_{1 <= i <= n}{p_i} - \min\limits_{1 <= i <= n}{p_i} <= k.Since gamers that play your game don't like big changes, you need to change the values d_i for the minimum possible number of guns. What is the minimum number of guns for which you have to change these values to make the guns balanced?Note that the new values d_i must be integers greater than 0.
Input: ['54 26 3 13 71 2 1 23 2100 101 102100 99 985 01 12 4 4 312 1 3 3 42 501000 101000000000 13 51 19 1149 4 72'] Output:['2', '3', '0', '1', '2', '']
[ 0, 3, 4 ]
Suppose you have n boxes. The i-th box contains infinitely many balls of color i. Sometimes you need to get a ball with some specific color; but you're too lazy to do it yourself.You have bought two robots to retrieve the balls for you. Now you have to program them. In order to program the robots, you have to construct two lists [a_1, a_2, ..., a_k] and [b_1, b_2, ..., b_{n-k}], where the list a represents the boxes assigned to the first robot, and the list b represents the boxes assigned to the second robot. Every integer from 1 to n must be present in exactly one of these lists.When you request a ball with color x, the robots work as follows. Each robot looks through the boxes that were assigned to that robot, in the order they appear in the list. The first robot spends s_1 seconds analyzing the contents of a box; the second robot spends s_2. As soon as one of the robots finds the box with balls of color x (and analyzes its contents), the search ends. The search time is the number of seconds from the beginning of the search until one of the robots finishes analyzing the contents of the x-th box. If a robot analyzes the contents of all boxes assigned to it, it stops searching.For example, suppose s_1 = 2, s_2 = 3, a = [4, 1, 5, 3, 7], b = [2, 6]. If you request a ball with color 3, the following happens: initially, the first robot starts analyzing the box 4, and the second robot starts analyzing the box 2; at the end of the 2-nd second, the first robot finishes analyzing the box 4. It is not the box you need, so the robot continues with the box 1; at the end of the 3-rd second, the second robot finishes analyzing the box 2. It is not the box you need, so the robot continues with the box 6; at the end of the 4-th second, the first robot finishes analyzing the box 1. It is not the box you need, so the robot continues with the box 5; at the end of the 6-th second, the first robot finishes analyzing the box 5. It is not the box you need, so the robot continues with the box 3. At the same time, the second robot finishes analyzing the box 6. It is not the box you need, and the second robot has analyzed all the boxes in its list, so that robot stops searching; at the end of the 8-th second, the first robot finishes analyzing the box 3. It is the box you need, so the search ends; so, the search time is 8 seconds. You know that you are going to request a ball of color 1 r_1 times, a ball of color 2 r_2 times, and so on. You want to construct the lists a and b for the robots in such a way that the total search time over all requests is the minimum possible.
Input: ['37 3 18 6 4 4 4 1 75 1 101 1 1 1 18 1 14 5 6 8 1 7 3 2'] Output:['2 5 6', '5 1 7 2 4 3', '5 4 3 5 2 1', '0', '4 4 2 7 5', '4 6 3 1 8', '']
[ 2 ]
A robot is placed in a cell (0, 0) of an infinite grid. This robot has adjustable length legs. Initially, its legs have length 1.Let the robot currently be in the cell (x, y) and have legs of length m. In one move, it can perform one of the following three actions: jump into the cell (x + m, y); jump into the cell (x, y + m); increase the length of the legs by 1, i. e. set it to m + 1. What's the smallest number of moves robot has to make to reach a cell (a, b)?
Input: ['31 11 68 4'] Output:['2', '5', '6', '']
[ 0, 3 ]
In Berland, there are two types of coins, having denominations of 2 and k burles.Your task is to determine whether it is possible to represent n burles in coins, i. e. whether there exist non-negative integers x and y such that 2 \cdot x + k \cdot y = n.
Input: ['45 36 17 48 8'] Output:['YES', 'YES', 'NO', 'YES', '']
[ 3 ]
This is hard version of the problem, it differs from the easy one only by constraints on n and k.Vlad found a row of n tiles and the integer k. The tiles are indexed from left to right and the i-th tile has the color c_i. After a little thought, he decided what to do with it.You can start from any tile and jump to any number of tiles right, forming the path p. Let's call the path p of length m nice if: p can be divided into blocks of length exactly k, that is, m is divisible by k; c_{p_1} = c_{p_2} = ... = c_{p_k}; c_{p_{k+1}} = c_{p_{k+2}} = ... = c_{p_{2k}}; ... c_{p_{m-k+1}} = c_{p_{m-k+2}} = ... = c_{p_{m}}; Your task is to find the number of nice paths of maximum length. Since this number may be too large, print it modulo 10^9 + 7.
Input: ['55 21 2 3 4 57 21 3 1 3 3 1 311 41 1 1 1 1 1 1 1 1 1 15 21 1 2 2 25 11 2 3 4 5'] Output:['1', '4', '165', '3', '1', '']
[ 3, 4 ]
This is an easy version of the problem, it differs from the hard one only by constraints on n and k.Vlad found a row of n tiles and the integer k. The tiles are indexed from left to right and the i-th tile has the color c_i. After a little thought, he decided what to do with it.You can start from any tile and jump to any number of tiles right, forming the path p. Let's call the path p of length m nice if: p can be divided into blocks of length exactly k, that is, m is divisible by k; c_{p_1} = c_{p_2} = ... = c_{p_k}; c_{p_{k+1}} = c_{p_{k+2}} = ... = c_{p_{2k}}; ... c_{p_{m-k+1}} = c_{p_{m-k+2}} = ... = c_{p_{m}}; Your task is to find the number of nice paths of maximum length. Since this number may be too large, print it modulo 10^9 + 7.
Input: ['55 21 2 3 4 57 21 3 1 3 3 1 311 41 1 1 1 1 1 1 1 1 1 15 21 1 2 2 25 11 2 3 4 5'] Output:['1', '4', '165', '3', '1', '']
[ 3 ]
In Japan, the number 4 reads like death, so Bob decided to build a live sequence. Living sequence a contains all natural numbers that do not contain the digit 4. a = [1, 2, 3, 5, 6, 7, 8, 9, 10, 11, 12, 13, 15, 16, ...].For example, the number 1235 is part of the sequence a, but the numbers 4321, 443 are not part of the sequence a.Bob realized that he does not know how to quickly search for a particular number by the position k in the sequence, so he asks for your help.For example, if Bob wants to find the number at position k = 4 (indexing from 1), you need to answer a_k = 5.
Input: ['735221010012345827264634912'] Output:['3', '6', '25', '11', '121', '18937', '2932285320890', '']
[ 3, 4 ]
The girl Umka loves to travel and participate in math olympiads. One day she was flying by plane to the next olympiad and out of boredom explored a huge checkered sheet of paper.Denote the n-th Fibonacci number as F_n = \begin{cases} 1, & n = 0; \\ 1, & n = 1; \\ F_{n-2} + F_{n-1}, & n >= 2. \end{cases}A checkered rectangle with a height of F_n and a width of F_{n+1} is called a Fibonacci rectangle of order n.Umka has a Fibonacci rectangle of order n. Someone colored a cell in it at the intersection of the row x and the column y.It is necessary to cut this rectangle exactly into n+1 squares in such way that the painted cell was in a square with a side of 1; there was at most one pair of squares with equal sides; the side of each square was equal to a Fibonacci number. Will Umka be able to cut this rectangle in that way?
Input: ['121 1 12 1 23 1 43 3 24 4 64 3 35 6 55 4 125 2 124 2 11 1 244 758465880 1277583853'] Output:['YES', 'NO', 'YES', 'YES', 'YES', 'NO', 'YES', 'NO', 'NO', 'YES', 'YES', 'NO', '']
[ 3 ]
Kristina had an array a of length n consisting of non-negative integers.She built a new array b of length n-1, such that b_i = \max(a_i, a_{i+1}) (1 <= i <= n-1).For example, suppose Kristina had an array a = [3, 0, 4, 0, 5] of length 5. Then she did the following: Calculated b_1 = \max(a_1, a_2) = \max(3, 0) = 3; Calculated b_2 = \max(a_2, a_3) = \max(0, 4) = 4; Calculated b_3 = \max(a_3, a_4) = \max(4, 0) = 4; Calculated b_4 = \max(a_4, a_5) = \max(0, 5) = 5. As a result, she got an array b = [3, 4, 4, 5] of length 4.You only know the array b. Find any matching array a that Kristina may have originally had.
Input: ['1153 4 4 542 2 150 0 0 060 3 4 4 321043 3 354 2 5 543 3 342 1 034 468 1 3 5 10'] Output:['3 0 4 0 5', '2 2 1 1', '0 0 0 0 0', '0 0 3 4 3 3', '10 10', '3 3 3 1', '4 2 2 5 5', '3 3 3 3', '2 1 0 0', '2 4 4', '8 1 1 3 5 10']
[ 2 ]
Conveyor matrix m_n is matrix of size n * n, where n is an even number. The matrix consists of concentric ribbons moving clockwise.In other words, the conveyor matrix for n = 2 is simply a matrix 2 * 2, whose cells form a cycle of length 4 clockwise. For any natural k >= 2, the matrix m_{2k} is obtained by adding to the matrix m_{2k - 2} an outer layer forming a clockwise cycle. The conveyor matrix 8 * 8. You are standing in a cell with coordinates x_1, y_1 and you want to get into a cell with coordinates x_2, y_2. A cell has coordinates x, y if it is located at the intersection of the xth row and the yth column.Standing on some cell, every second you will move to the cell next in the direction of movement of the tape on which you are. You can also move to a neighboring cell by spending one unit of energy. Movements happen instantly and you can make an unlimited number of them at any time.Your task is to find the minimum amount of energy that will have to be spent to get from the cell with coordinates x_1, y_1 to the cell with coordinates x_2, y_2.For example, n=8 initially you are in a cell with coordinates 1,3 and you want to get into a cell with coordinates 6, 4. You can immediately make 2 movements, once you are in a cell with coordinates 3, 3, and then after 8 seconds you will be in the right cell.
Input: ['52 1 1 2 24 1 4 3 38 1 3 4 6100 10 20 50 1001000000000 123456789 987654321 998244353 500000004'] Output:['0', '1', '2', '9', '10590032', '']
[ 3 ]
You have a positive number of length n and one additional digit.You can insert this digit anywhere in the number, including at the beginning or at the end.Your task is to make the result as large as possible.For example, you have the number 76543, and the additional digit is 4. Then the maximum number you can get is 765443, and it can be obtained in two ways β€” by inserting a digit after the 3th or after the 4th digit of the number.
Input: ['115 4765431 012 5443 66665 6135795 89753119 498765432101234567895 7737378 1200000007 0705895912 1828127127732'] Output:['765443', '10', '544', '6666', '613579', '987531', '98765443210123456789', '773737', '210000000', '70589590', '8281271277321', '']
[ 2, 3 ]
You are given a multiset S. Initially, S = \{1,2,3, ..., n\}.You will perform the following operation n-1 times. Choose the largest number S_{\text{max}} in S and the smallest number S_{\text{min}} in S. Remove the two numbers from S, and add S_{\text{max}} - S_{\text{min}} into S. It's easy to show that there will be exactly one number left after n-1 operations. Output that number.
Input: ['524715177567'] Output:['1', '2', '2', '4', '33914', '']
[ 3 ]
A rooted tree is called good if every vertex of the tree either is a leaf (a vertex with no children) or has exactly m children.For a good tree, each leaf u has a positive integer c_{u} written on it, and we define the value of the leaf as c_{u} + \mathrm{dep}_{u}, where \mathrm{dep}_{u} represents the number of edges of the path from vertex u to the root (also known as the depth of u). The value of a good tree is the maximum value of all its leaves.Now, you are given an array of n integers a_{1}, a_{2}, ..., a_{n}, which are the integers that should be written on the leaves. You need to construct a good tree with n leaves and write the integers from the array a to all the leaves. Formally, you should assign each leaf u an index b_{u}, where b is a permutation of length n, and represent that the integer written on leaf u is c_u = a_{b_{u}}. Under these constraints, you need to minimize the value of the good tree.You have q queries. Each query gives you x, y and changes a_{x} to y, and after that, you should output the minimum value of a good tree based on the current array a. A permutation of length n is an array consisting of n distinct integers from 1 to n in arbitrary order. For example, [2,3,1,5,4] is a permutation, but [1,2,2] is not a permutation (2 appears twice in the array), and [1,3,4] is also not a permutation (n=3 but there is 4 in the array).
Input: ['35 3 33 3 4 4 51 42 43 55 2 43 3 4 4 51 42 53 54 57 3 41 2 2 3 3 3 41 42 15 56 6'] Output:['6 6 6', '7 7 7 8', '6 6 6 7', '']
[ 3 ]
There is an undirected graph with n vertices and m edges. Initially, for each vertex i, there is a monster with danger a_{i} on that vertex. For a monster with danger a_{i}, you can defeat it if and only if you have defeated at least a_{i} other monsters before.Now you want to defeat all the monsters. First, you choose some vertex s and defeat the monster on that vertex (since you haven't defeated any monsters before, a_{s} has to be 0). Then, you can move through the edges. If you want to move from vertex u to vertex v, then the following must hold: either the monster on vertex v has been defeated before, or you can defeat it now. For the second case, you defeat the monster on vertex v and reach vertex v.You can pass the vertices and the edges any number of times. Determine whether you can defeat all the monsters or not.
Input: ['54 32 1 0 31 22 33 46 60 1 2 3 0 11 22 33 44 54 65 64 30 1 2 01 22 31 34 61 1 1 01 23 24 32 44 11 35 50 1 3 2 01 22 33 44 53 5'] Output:['YES', 'YES', 'NO', 'YES', 'NO', '']
[ 0, 2 ]
The snails are climbing a tree. The tree height is h meters, and snails start at position 0.Each snail has two attributes a and b (a > b). Starting from the 1-st day, one snail climbs the tree like this: during the daylight hours of the day, he climbs up a meters; during the night, the snail rests, and he slides down b meters. If on the n-th day, the snail reaches position h for the first time (that is, the top of the tree), he will finish climbing, and we say that the snail spends n days climbing the tree. Note that on the last day of climbing, the snail doesn't necessarily climb up a meters, in case his distance to the top is smaller than a.Unfortunately, you don't know the exact tree height h at first, but you know that h is a positive integer. There are q events of two kinds. Event of type 1: a snail with attributes a, b comes and claims that he spent n days climbing the tree. If this message contradicts previously adopted information (i. e. there is no tree for which all previously adopted statements and this one are true), ignore it. Otherwise, adopt it. Event of type 2: a snail with attributes a, b comes and asks you how many days he will spend if he climbs the tree. You can only give the answer based on the information you have adopted so far. If you cannot determine the answer precisely, report that. You need to deal with all the events in order.
Input: ['531 3 2 52 4 12 3 231 6 5 12 3 12 6 231 4 2 21 2 1 32 10 291 7 3 61 2 1 82 5 11 10 9 71 8 1 21 10 5 81 10 7 72 7 41 9 4 291 2 1 61 8 5 61 4 2 72 9 11 5 1 41 5 2 71 7 1 91 9 1 42 10 8'] Output:['1 2 5', '1 -1 1', '1 0 1', '1 0 -1 0 0 0 1 8 0', '1 0 0 1 0 0 0 0 1', '']
[ 3, 4 ]
You have an integer array a of length n. There are two kinds of operations you can make. Remove an integer from a. This operation costs c. Insert an arbitrary positive integer x to any position of a (to the front, to the back, or between any two consecutive elements). This operation costs d.You want to make the final array a permutation of any positive length. Please output the minimum cost of doing that. Note that you can make the array empty during the operations, but the final array must contain at least one integer.A permutation of length n is an array consisting of n distinct integers from 1 to n in arbitrary order. For example, [2,3,1,5,4] is a permutation, but [1,2,2] is not a permutation (2 appears twice in the array), and [1,3,4] is also not a permutation (n=3 but there is 4 in the array).
Input: ['83 3 31 2 35 1 51 2 3 5 65 2 31 1 1 3 35 1 102 4 6 8 106 2 87 3 5 4 4 84 10 11 2 6 74 3 32 5 8 72 1000000000 11000000000 1'] Output:['0', '2', '8', '14', '20', '3', '12', '999999998', '']
[ 0, 2 ]
This problem is about candy. Initially, you only have 1 candy, and you want to have exactly n candies.You can use the two following spells in any order at most 40 times in total. Assume you have x candies now. If you use the first spell, then x candies become 2x-1 candies. Assume you have x candies now. If you use the second spell, then x candies become 2x+1 candies. Construct a sequence of spells, such that after using them in order, you will have exactly n candies, or determine it's impossible.
Input: ['423717'] Output:['-1', '1', '2 ', '2', '2 2 ', '4', '2 1 1 1 ', '']
[ 3 ]
A sequence of m integers a_{1}, a_{2}, ..., a_{m} is good, if and only if there exists at least one i (1 <= i <= m) such that a_{i} = i. For example, [3,2,3] is a good sequence, since a_{2} = 2, a_{3} = 3, while [3,1,1] is not a good sequence, since there is no i such that a_{i} = i.A sequence a is beautiful, if and only if there exists at least one subsequence of a satisfying that this subsequence is good. For example, [4,3,2] is a beautiful sequence, since its subsequence [4,2] is good, while [5,3,4] is not a beautiful sequence.A sequence b is a subsequence of a sequence a if b can be obtained from a by the deletion of several (possibly, zero or all) elements. Now you are given a sequence, check whether it is beautiful or not.
Input: ['733 2 142 4 3 552 3 5 5 623 152 4 5 2 345 6 7 866 5 4 3 2 1'] Output:['YES', 'YES', 'NO', 'YES', 'YES', 'NO', 'YES', '']
[ 0, 2 ]
Consider a tournament with n participants. The rating of the i-th participant is a_i.The tournament will be organized as follows. First of all, organizers will assign each participant an index from 1 to n. All indices will be unique. Let p_i be the participant who gets the index i.Then, n-1 games will be held. In the first game, participants p_1 and p_2 will play. In the second game, the winner of the first game will play against p_3. In the third game, the winner of the second game will play against p_4, and so on β€” in the last game, the winner of the (n-2)-th game will play against p_n.Monocarp wants to predict the results of all n-1 games (of course, he will do the prediction only after the indices of the participants are assigned). He knows for sure that, when two participants with ratings x and y play, and |x - y| > k, the participant with the higher rating wins. But if |x - y| <= k, any of the two participants may win.Among all n! ways to assign the indices to participants, calculate the number of ways to do this so that Monocarp can predict the results of all n-1 games. Since the answer can be large, print it modulo 998244353.
Input: ['4 3', '7 12 17 21', ''] Output:['24', '']
[ 3 ]
There are n cities in Berland, arranged in a circle and numbered from 1 to n in clockwise order.You want to travel all over Berland, starting in some city, visiting all the other cities and returning to the starting city. Unfortunately, you can only drive along the Berland Ring Highway, which connects all n cities. The road was designed by a very titled and respectable minister, so it is one-directional β€” it can only be traversed clockwise, only from the city i to the city (i \bmod n) + 1 (i.e. from 1 to 2, from 2 in 3, ..., from n to 1).The fuel tank of your car holds up to k liters of fuel. To drive from the i-th city to the next one, a_i liters of fuel are needed (and are consumed in the process).Every city has a fuel station; a liter of fuel in the i-th city costs b_i burles. Refueling between cities is not allowed; if fuel has run out between cities, then your journey is considered incomplete.For each city, calculate the minimum cost of the journey if you start and finish it in that city.
Input: ['43 53 4 41 2 25 71 3 2 5 12 1 1 1 24 31 2 1 32 2 2 23 22 2 21 2 1'] Output:['17 19 17 ', '13 12 12 12 14 ', '14 14 14 14 ', '8 8 8 ', '']
[ 2, 4 ]
There are two water tanks, the first one fits a liters of water, the second one fits b liters of water. The first tank has c (0 <= c <= a) liters of water initially, the second tank has d (0 <= d <= b) liters of water initially.You want to perform n operations on them. The i-th operation is specified by a single non-zero integer v_i. If v_i > 0, then you try to pour v_i liters of water from the first tank into the second one. If v_i < 0, you try to pour -v_i liters of water from the second tank to the first one.When you try to pour x liters of water from the tank that has y liters currently available to the tank that can fit z more liters of water, the operation only moves \min(x, y, z) liters of water.For all pairs of the initial volumes of water (c, d) such that 0 <= c <= a and 0 <= d <= b, calculate the volume of water in the first tank after all operations are performed.
Input: ['3 4 4', '-2 1 2', ''] Output:['0 0 0 0 0 ', '0 0 0 0 1 ', '0 0 1 1 2 ', '0 1 1 2 3 ', '1 1 2 3 4 ', '']
[ 3, 4 ]
You are given a binary string s consisting of only characters 0 and/or 1.You can perform several operations on this string (possibly zero). There are two types of operations: choose two consecutive elements and swap them. In order to perform this operation, you pay 10^{12} coins; choose any element from the string and remove it. In order to perform this operation, you pay 10^{12}+1 coins. Your task is to calculate the minimum number of coins required to sort the string s in non-decreasing order (i. e. transform s so that s_1 <= s_2 <= ... <= s_m, where m is the length of the string after applying all operations). An empty string is also considered sorted in non-decreasing order.
Input: ['61000010100101101100110111111'] Output:['1000000000001', '0', '1000000000000', '2000000000001', '2000000000002', '0', '']
[ 2 ]
For an array a = [a_1, a_2, ..., a_n], let's denote its subarray a[l, r] as the array [a_l, a_{l+1}, ..., a_r].For example, the array a = [1, -3, 1] has 6 non-empty subarrays: a[1,1] = [1]; a[1,2] = [1,-3]; a[1,3] = [1,-3,1]; a[2,2] = [-3]; a[2,3] = [-3,1]; a[3,3] = [1]. You are given two integers n and k. Construct an array a consisting of n integers such that: all elements of a are from -1000 to 1000; a has exactly k subarrays with positive sums; the rest \dfrac{(n+1) \cdot n}{2}-k subarrays of a have negative sums.
Input: ['43 22 02 24 6'] Output:['1 -3 1', '-13 -42', '-13 42', '-3 -4 10 -2', '']
[ 2, 3 ]
You are given a two-dimensional plane, and you need to place n chips on it. You can place a chip only at a point with integer coordinates. The cost of placing a chip at the point (x, y) is equal to |x| + |y| (where |a| is the absolute value of a).The cost of placing n chips is equal to the maximum among the costs of each chip.You need to place n chips on the plane in such a way that the Euclidean distance between each pair of chips is strictly greater than 1, and the cost is the minimum possible.
Input: ['4135975461057789971042'] Output:['0', '1', '2', '987654321', '']
[ 2, 3, 4 ]
This is the hard version of the problem. The only difference between the three versions is the constraints on n and k. You can make hacks only if all versions of the problem are solved.Maxim is a minibus driver on Venus.To ride on Maxim's minibus, you need a ticket. Each ticket has a number consisting of n digits. However, as we know, the residents of Venus use a numeral system with base k, rather than the decimal system. Therefore, the ticket number can be considered as a sequence of n integers from 0 to k-1, inclusive.The residents of Venus consider a ticket to be lucky if there is a digit on it that is equal to the sum of the remaining digits, modulo k. For example, if k=10, then the ticket 7135 is lucky because 7 + 1 + 5 \equiv 3 \pmod{10}. On the other hand, the ticket 7136 is not lucky because no digit is equal to the sum of the others modulo 10.Once, while on a trip, Maxim wondered: how many lucky tickets exist? At the same time, Maxim understands that this number can be very large, so he is interested only in the answer modulo some prime number m.
Input: ['3 2 1000000007', ''] Output:['4', '']
[ 0, 3 ]
Petya and his friend, the robot Petya++, have a common friend β€” the cyborg Petr#. Sometimes Petr# comes to the friends for a cup of tea and tells them interesting problems.Today, Petr# told them the following problem.A palindrome is a sequence that reads the same from left to right as from right to left. For example, [38, 12, 8, 12, 38], [1], and [3, 8, 8, 3] are palindromes.Let's call the palindromicity of a sequence a_1, a_2, ..., a_n the minimum count of elements that need to be replaced to make this sequence a palindrome. For example, the palindromicity of the sequence [38, 12, 8, 38, 38] is 1 since it is sufficient to replace the number 38 at the fourth position with the number 12. And the palindromicity of the sequence [3, 3, 5, 5, 5] is two since you can replace the first two threes with fives, and the resulting sequence [5, 5, 5, 5, 5] is a palindrome.Given a sequence a of length n, and an odd integer k, you need to find the sum of palindromicity of all subarrays of length k, i. e., the sum of the palindromicity values for the sequences a_i, a_{i+1}, ..., a_{i+k-1} for all i from 1 to n-k+1.The students quickly solved the problem. Can you do it too?
Input: ['8 5', '1 2 8 2 5 2 8 6', ''] Output:['4', '']
[ 0, 4 ]
In this problem, unlike problem A, you need to look for unluckiest number, not the luckiest one.Note that the constraints of this problem differ from such in problem A.Olympus City recently launched the production of personal starships. Now everyone on Mars can buy one and fly to other planets inexpensively.Each starship has a number β€”some positive integer x. Let's define the luckiness of a number x as the difference between the largest and smallest digits of that number. For example, 142857 has 8 as its largest digit and 1 as its smallest digit, so its luckiness is 8-1=7. And the number 111 has all digits equal to 1, so its luckiness is zero.Hateehc is a famous Martian blogger who often flies to different corners of the solar system. To release interesting videos even faster, he decided to buy himself a starship. When he came to the store, he saw starships with numbers from l to r inclusively. While in the store, Hateehc wanted to find a starship with the unluckiest number.Since there are a lot of starships in the store, and Hateehc can't program, you have to help the blogger and write a program that answers his question.
Input: ['559 6342 4948 5390 901 100'] Output:['63', '44', '53', '90', '1', '']
[ 0, 2 ]
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 n cards. Each card has m numbers written on it. Each of the n 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.Each of these games determines the winner in some way, but the rules are quite complicated, so we will not describe them here. All that matters is how many chips are paid out to the winner. Let the first player's card have the numbers a_1, a_2, ..., a_m, and the second player's card β€” b_1, b_2, ..., b_m. Then the winner of the game gets |a_1 - b_1| + |a_2 - b_2| + ... + |a_m - b_m| chips from the total pot, where |x| denotes the absolute value of x.To determine the size of the total pot, it is necessary to calculate the winners' total winnings for all games. Since there can be many cards in a deck and many players, you have been assigned to write a program that does all the necessary calculations.
Input: ['33 51 4 2 8 57 9 2 1 43 8 5 3 11 44 15 1 104 31 2 33 2 11 2 14 2 7'] Output:['50', '0', '31', '']
[ 3 ]
Olympus City recently launched the production of personal starships. Now everyone on Mars can buy one and fly to other planets inexpensively.Each starship has a number β€”some positive integer x. Let's define the luckiness of a number x as the difference between the largest and smallest digits of that number. For example, 142857 has 8 as its largest digit and 1 as its smallest digit, so its luckiness is 8-1=7. And the number 111 has all digits equal to 1, so its luckiness is zero.Hateehc is a famous Martian blogger who often flies to different corners of the solar system. To release interesting videos even faster, he decided to buy himself a starship. When he came to the store, he saw starships with numbers from l to r inclusively. While in the store, Hateehc wanted to find a starship with the luckiest number.Since there are a lot of starships in the store, and Hateehc can't program, you have to help the blogger and write a program that answers his question.
Input: ['559 6342 4915 1553 571 100'] Output:['60', '49', '15', '57', '90', '']
[ 0 ]
The only difference between the two versions is that in this version, the constraints are higher.Initially, array a contains just the number 1. You can perform several operations in order to change the array. In an operation, you can select some subsequence of a and add into a an element equal to the sum of all elements of the subsequence. You are given a final array c. Check if c can be obtained from the initial array a by performing some number (possibly 0) of operations on the initial array. A sequence b is a subsequence of a sequence a if b can be obtained from a by the deletion of several (possibly zero, but not all) elements. In other words, select k (1 <=q k <=q |a|) distinct indices i_1, i_2, ..., i_k and insert anywhere into a a new element with the value equal to a_{i_1} + a_{i_2} + ... + a_{i_k}.
Input: ['6111255 1 3 2 157 1 5 2 131 1 151 1 4 2 1'] Output:['YES', 'NO', 'YES', 'NO', 'YES', 'YES', '']
[ 2 ]
The only difference between the two versions is that in this version, the constraints are lower.Initially, array a contains just the number 1. You can perform several operations in order to change the array. In an operation, you can select some subsequence of a and add into a an element equal to the sum of all elements of the subsequence. You are given a final array c. Check if c can be obtained from the initial array a by performing some number (possibly 0) of operations on the initial array. A sequence b is a subsequence of a sequence a if b can be obtained from a by the deletion of several (possibly zero, but not all) elements. In other words, select k (1 <=q k <=q |a|) distinct indices i_1, i_2, ..., i_k and insert anywhere into a a new element with the value equal to a_{i_1} + a_{i_2} + ... + a_{i_k}.
Input: ['6111255 1 3 2 157 1 5 2 131 1 151 1 4 2 1'] Output:['YES', 'NO', 'YES', 'NO', 'YES', 'YES', '']
[ 0, 2 ]
You are given a room that can be represented by a n * m grid. There is a ball at position (i_1, j_1) (the intersection of row i_1 and column j_1), and it starts going diagonally in one of the four directions: The ball is going down and right, denoted by \texttt{DR}; it means that after a step, the ball's location goes from (i, j) to (i+1, j+1). The ball is going down and left, denoted by \texttt{DL}; it means that after a step, the ball's location goes from (i, j) to (i+1, j-1). The ball is going up and right, denoted by \texttt{UR}; it means that after a step, the ball's location goes from (i, j) to (i-1, j+1). The ball is going up and left, denoted by \texttt{UL}; it means that after a step, the ball's location goes from (i, j) to (i-1, j-1). After each step, the ball maintains its direction unless it hits a wall (that is, the direction takes it out of the room's bounds in the next step). In this case, the ball's direction gets flipped along the axis of the wall; if the ball hits a corner, both directions get flipped. Any instance of this is called a bounce. The ball never stops moving. In the above example, the ball starts at (1, 7) and goes \texttt{DL} until it reaches the bottom wall, then it bounces and continues in the direction \texttt{UL}. After reaching the left wall, the ball bounces and continues to go in the direction \texttt{UR}. When the ball reaches the upper wall, it bounces and continues in the direction \texttt{DR}. After reaching the bottom-right corner, it bounces once and continues in direction \texttt{UL}, and so on.Your task is to find how many bounces the ball will go through until it reaches cell (i_2, j_2) in the room, or report that it never reaches cell (i_2, j_2) by printing -1.Note that the ball first goes in a cell and only after that bounces if it needs to.
Input: ['65 7 1 7 2 4 DL5 7 1 7 3 2 DL3 3 1 3 2 2 UR2 4 2 1 2 2 DR4 3 1 1 1 3 UL6 4 1 2 3 4 DR'] Output:['3', '-1', '1', '-1', '4', '0', '']
[ 0 ]
This is an interactive problem. If you are unsure how interactive problems work, then it is recommended to read the guide for participants.Before the last stage of the exam, the director conducted an interview. He gave Gon n piles of stones, the i-th pile having a_i stones.Each stone is identical and weighs 1 grams, except for one special stone that is part of an unknown pile and weighs 2 grams. A picture of the first test case. Pile 2 has the special stone. The piles have weights of 1,3,3,4,5, respectively. Gon can only ask the director questions of one kind: he can choose k piles, and the director will tell him the total weight of the piles chosen. More formally, Gon can choose an integer k (1 <=q k <=q n) and k unique piles p_1, p_2, ..., p_k (1 <=q p_i <=q n), and the director will return the total weight m_{p_1} + m_{p_2} + ... + m_{p_k}, where m_i denotes the weight of pile i. Gon is tasked with finding the pile that contains the special stone. However, the director is busy. Help Gon find this pile in at most \mathbf{30} queries.
Input: ['2', '5', '1 2 3 4 5', '', '11', '', '6', '', '3', '', '7', '1 2 3 5 3 4 2', '', '12', '', '6', ''] Output:['? 4 1 2 3 4', '', '? 2 2 3', '', '? 1 2', '', '! 2', '', '? 4 2 3 5 6', '', '? 2 1 4', '', '! 7', '', '']
[ 4 ]
You are given a string s consisting of lowercase Latin characters. In an operation, you can take a character and replace all occurrences of this character with \texttt{0} or replace all occurrences of this character with \texttt{1}.Is it possible to perform some number of moves so that the resulting string is an alternating binary string? For example, consider the string \texttt{abacaba}. You can perform the following moves: Replace \texttt{a} with \texttt{0}. Now the string is \color{red}{\texttt{0}}\texttt{b}\color{red}{\texttt{0}}\texttt{c}\color{red}{\texttt{0}}\texttt{b}\color{red}{\texttt{0}}. Replace \texttt{b} with \texttt{1}. Now the string is {\texttt{0}}\color{red}{\texttt{1}}{\texttt{0}}\texttt{c}{\texttt{0}}\color{red}{\texttt{1}}{\texttt{0}}. Replace \texttt{c} with \texttt{1}. Now the string is {\texttt{0}}{\texttt{1}}{\texttt{0}}\color{red}{\texttt{1}}{\texttt{0}}{\texttt{1}}{\texttt{0}}. This is an alternating binary string. An alternating binary string is a string of \texttt{0}s and \texttt{1}s such that no two adjacent bits are equal. For example, \texttt{01010101}, \texttt{101}, \texttt{1} are alternating binary strings, but \texttt{0110}, \texttt{0a0a0}, \texttt{10100} are not.
Input: ['87abacaba2aa1y4bkpt6ninfia6banana10codeforces8testcase'] Output:['YES', 'NO', 'YES', 'YES', 'NO', 'YES', 'NO', 'NO', '']
[ 2 ]
Mihai and Bianca are playing with bags of candies. They have a row a of n bags of candies. The i-th bag has a_i candies. The bags are given to the players in the order from the first bag to the n-th bag. If a bag has an even number of candies, Mihai grabs the bag. Otherwise, Bianca grabs the bag. Once a bag is grabbed, the number of candies in it gets added to the total number of candies of the player that took it. Mihai wants to show off, so he wants to reorder the array so that at any moment (except at the start when they both have no candies), Mihai will have strictly more candies than Bianca. Help Mihai find out if such a reordering exists.
Input: ['341 2 3 441 1 1 231 4 3'] Output:['YES', 'NO', 'NO', '']
[ 2 ]
This is the hard version of the problem. The only difference between the two versions is the constraint on m. You can make hacks only if both versions of the problem are solved.You are given an array a of length n and two integers m and k. Each element in a satisfies 1<= a_i <= m.In one operation, you choose two indices i and j such that 1 <= i < j <= |a|, then append \gcd(a_i,a_j) to the back of the array and delete a_i and a_j from the array. Note that the length of the array decreases by one after this operation.Find the maximum possible sum of the array after performing exactly k operations.
Input: ['43 8 14 7 85 114514 27 2 4 1 63 1919810 22 3 33 9000000000000000000 19000000000000000000 9000000000000000000 9000000000000000000'] Output:['11', '14', '1', '18000000000000000000', '']
[ 2, 3 ]
This is the easy version of the problem. The only difference between the two versions is the constraint on m. You can make hacks only if both versions of the problem are solved.You are given an array a of length n and two integers m and k. Each element in a satisfies 1<= a_i <= m.In one operation, you choose two indices i and j such that 1 <= i < j <= |a|, then append \gcd(a_i,a_j) to the back of the array and delete a_i and a_j from the array. Note that the length of the array decreases by one after this operation.Find the maximum possible sum of the array after performing exactly k operations.
Input: ['33 8 14 7 85 114 27 2 4 1 63 514 22 3 3'] Output:['11', '14', '1', '']
[ 2, 3 ]
You are given a tree with n weighted vertices labeled from 1 to n rooted at vertex 1. The parent of vertex i is p_i and the weight of vertex i is a_i. For convenience, define p_1=0.For two vertices x and y of the same depth^, define f(x,y) as follows: Initialize \mathrm{ans}=0. While both x and y are not 0: \mathrm{ans}<=ftarrow \mathrm{ans}+a_x\cdot a_y; x<=ftarrow p_x; y<=ftarrow p_y. f(x,y) is the value of \mathrm{ans}. You will process q queries. In the i-th query, you are given two integers x_i and y_i and you need to calculate f(x_i,y_i).^ The depth of vertex v is the number of edges on the unique simple path from the root of the tree to vertex v.
Input: ['6 2', '1 5 2 3 1 1', '1 2 3 3 2', '4 5', '6 6', ''] Output:['33', '27', '']
[ 0 ]
You are given an integer n and an array a of length n-1 whose elements are either 0 or 1.Let us define the value of a permutation^ p of length m-1 (m <=q n) by the following process.Let G be a graph of m vertices labeled from 1 to m that does not contain any edges. For each i from 1 to m-1, perform the following operations: define u and v as the (unique) vertices in the weakly connected components^\ddagger containing vertices p_i and p_i+1 respectively with only incoming edges^{}; in graph G, add a directed edge from vertex v to u if a_{p_i}=0, otherwise add a directed edge from vertex u to v (if a_{p_i}=1). Note that after each step, it can be proven that each weakly connected component of G has a unique vertex with only incoming edges.Then, the value of p is the number of incoming edges of vertex 1 of G.For each k from 1 to n-1, find the sum of values of all k! permutations of length k. Since this value can be big, you are only required to compute this value under modulo 998\,244\,353. Operations when n=3, a=[0,1] and p=[1,2] ^ A permutation of length n is an array consisting of n distinct integers from 1 to n in arbitrary order. For example, [2,3,1,5,4] is a permutation, but [1,2,2] is not a permutation (2 appears twice in the array), and [1,3,4] is also not a permutation (n=3 but there is 4 in the array).^\ddagger The weakly connected components of a directed graph is the same as the components of the undirected version of the graph. Formally, for directed graph G, define a graph H where for all edges a \to b in G, you add an undirected edge a <=ftrightarrow b in H. Then the weakly connected components of G are the components of H.^{} Note that a vertex that has no edges is considered to have only incoming edges.
Input: ['230 090 1 0 0 0 1 0 0'] Output:['1 3 ', '1 2 7 31 167 1002 7314 60612 ', '']
[ 3 ]
For some positive integer m, YunQian considers an array q of 2m (possibly negative) integers good, if and only if for every possible subsequence of q that has length m, the product of the m elements in the subsequence is equal to the sum of the m elements that are not in the subsequence. Formally, let U=\{1,2,...,2m\}. For all sets S \subseteq U such that |S|=m, \prod\limits_{i \in S} q_i = \sum\limits_{i \in U \setminus S} q_i.Define the distance between two arrays a and b both of length k to be \sum\limits_{i=1}^k|a_i-b_i|.You are given a positive integer n and an array p of 2n integers.Find the minimum distance between p and q over all good arrays q of length 2n. It can be shown for all positive integers n, at least one good array exists. Note that you are not required to construct the array q that achieves this minimum distance.
Input: ['416 921 2 2 12-2 -2 2 24-3 -2 -1 0 1 2 3 4'] Output:['3', '2', '5', '13', '']
[ 0, 3 ]
You are given an array a of length n. The score of a is the MEX of [a_1+a_2,a_2+a_3,...,a_{n-1}+a_n]. Find the minimum score of a if you are allowed to rearrange elements of a in any order. Note that you are not required to construct the array a that achieves the minimum score. The MEX (minimum excluded) of an array is the smallest non-negative integer that does not belong to the array. For instance: The MEX of [2,2,1] is 0, because 0 does not belong to the array. The MEX of [3,1,0,1] is 2, because 0 and 1 belong to the array, but 2 does not. The MEX of [0,3,1,2] is 4 because 0, 1, 2, and 3 belong to the array, but 4 does not.
Input: ['320 030 0 181 0 0 0 2 0 3 0'] Output:['1', '0', '1', '']
[ 2 ]
YunQian is standing on an infinite plane with the Cartesian coordinate system on it. In one move, she can move to the diagonally adjacent point on the top right or the adjacent point on the left.That is, if she is standing on point (x,y), she can either move to point (x+1,y+1) or point (x-1,y).YunQian initially stands at point (a,b) and wants to move to point (c,d). Find the minimum number of moves she needs to make or declare that it is impossible.
Input: ['6-1 0 -1 20 0 4 5-2 -1 1 1-3 2 -3 22 -1 -1 -11 1 0 2'] Output:['4', '6', '-1', '0', '3', '3', '']
[ 2, 3 ]
This is the hard version of the problem. It differs from the easy one only in constraints on n. You can make hacks only if you lock both versions.Let a_1, a_2, ..., a_n be an array of non-negative integers. Let F(a_1, a_2, ..., a_n) be the sorted in the non-decreasing order array of n - 1 smallest numbers of the form a_i + a_j, where 1 <= i < j <= n. In other words, F(a_1, a_2, ..., a_n) is the sorted in the non-decreasing order array of n - 1 smallest sums of all possible pairs of elements of the array a_1, a_2, ..., a_n. For example, F(1, 2, 5, 7) = [1 + 2, 1 + 5, 2 + 5] = [3, 6, 7].You are given an array of non-negative integers a_1, a_2, ..., a_n. Determine the single element of the array \underbrace{F(F(F... F}_{n-1}(a_1, a_2, ..., a_n)...)). Since the answer can be quite large, output it modulo 10^9+7.
Input: ['5', '1 2 4 5 6', ''] Output:['34', '']
[ 2, 3 ]
This is the easy version of the problem. It differs from the hard one only in constraints on n. You can make hacks only if you lock both versions.Let a_1, a_2, ..., a_n be an array of non-negative integers. Let F(a_1, a_2, ..., a_n) be the sorted in the non-decreasing order array of n - 1 smallest numbers of the form a_i + a_j, where 1 <= i < j <= n. In other words, F(a_1, a_2, ..., a_n) is the sorted in the non-decreasing order array of n - 1 smallest sums of all possible pairs of elements of the array a_1, a_2, ..., a_n. For example, F(1, 2, 5, 7) = [1 + 2, 1 + 5, 2 + 5] = [3, 6, 7].You are given an array of non-negative integers a_1, a_2, ..., a_n. Determine the single element of the array \underbrace{F(F(F... F}_{n-1}(a_1, a_2, ..., a_n)...)). Since the answer can be quite large, output it modulo 10^9+7.
Input: ['5', '1 2 4 5 6', ''] Output:['34', '']
[ 0, 3, 4 ]
You are given a tree (a connected graph without cycles). Each vertex of the tree contains an integer. Let's define the \mathrm{MAD} (maximum double) parameter of the tree as the maximum integer that occurs in the vertices of the tree at least 2 times. If no number occurs in the tree more than once, then we assume \mathrm{MAD}=0.Note that if you remove an edge from the tree, it splits into two trees. Let's compute the \mathrm{MAD} parameters of the two trees and take the maximum of the two values. Let the result be the value of the deleted edge.For each edge, find its value. Note that we don't actually delete any edges from the tree, the values are to be found independently.
Input: ['5', '1 2', '2 3', '2 4', '1 5', '2 1 3 2 1', ''] Output:['0', '2', '1', '2', '']
[ 0 ]
You are given a tree (a connected graph without cycles) with n vertices. Consider a fixed integer k. Then, the graph G_k is an undirected graph with n vertices, where an edge between vertices u and v exists if and only if the distance between vertices u and v in the given tree is at least k.For each k from 1 to n, print the number of connected components in the graph G_k.
Input: ['6', '1 2', '1 3', '2 4', '2 5', '3 6', ''] Output:['1 1 2 4 6 6 ', '']
[ 2 ]
The universe is a coordinate plane. There are n space highways, each of which is a straight line y=kx passing through the origin (0, 0). Also, there are m asteroid belts on the plane, which we represent as open upwards parabolas, i. e. graphs of functions y=ax^2+bx+c, where a > 0.You want to photograph each parabola. To do this, for each parabola you need to choose a line that does not intersect this parabola and does not touch it. You can select the same line for different parabolas. Please find such a line for each parabola, or determine that there is no such line.
Input: ['51 211 -1 21 -1 32 2141 2 12 5 11 101 0 01 1100000000100000000 100000000 1000000002 3022 2 11 -2 11 -2 -1'] Output:['YES', '1', 'YES', '1', '', 'YES', '1', 'YES', '4', '', 'NO', '', 'YES', '100000000', '', 'YES', '0', 'NO', 'NO', '']
[ 3, 4 ]
You are given a string s. You can apply this operation to the string exactly once: choose index i and move character s_i to the beginning of the string (removing it at the old position). For example, if you apply the operation with index i=4 to the string "abaacd" with numbering from 1, you get the string "aabacd". What is the lexicographically minimal string you can obtain by this operation?A string a is lexicographically smaller than a string b of the same length if and only if the following holds: in the first position where a and b differ, the string a has a letter that appears earlier in the alphabet than the corresponding letter in b.
Input: ['43cba4acac5abbcb4aaba'] Output:['acb', 'aacc', 'abbcb', 'aaab', '']
[ 2 ]
There is an array a consisting of non-negative integers. You can choose an integer x and denote b_i=a_i \oplus x for all 1 <= i <= n, where \oplus denotes the bitwise XOR operation. Is it possible to choose such a number x that the value of the expression b_1 \oplus b_2 \oplus ... \oplus b_n equals 0?It can be shown that if a valid number x exists, then there also exists x such that (0 <= x < 2^8).
Input: ['531 2 531 2 340 1 2 341 2 2 311'] Output:['6', '0', '3', '-1', '1', '']
[ 0 ]
Jack has a graph of n vertices and m edges. All edges are bidirectional and of unit length. The graph is connected, i. e. there exists a path between any two of its vertices. There can be more than one edge connecting the same pair of vertices. The graph can contain self-loops, i. e. edges connecting a node to itself.The distance between vertices u and v is denoted as \rho(u, v) and equals the minimum possible number of edges on a path between u and v. The diameter of graph G is defined as the maximum possible distance between some pair of its vertices. We denote it as d(G). In other words, d(G) = \max_{1 <= u, v <= n}{\rho(u, v)}.Jack plans to consecutively apply q updates to his graph. Each update adds exactly one edge to the graph. Denote as G_i the graph after exactly i updates are made. Jack wants to calculate q + 1 values d(G_0), d(G_1), d(G_2), ..., d(G_q).However, Jack suspects that finding the exact diameters of q + 1 graphs might be a difficult task, so he is fine with approximate answers that differ from the correct answers no more than twice. Formally, Jack wants to find a sequence of positive integers a_0, a_1, a_2, ..., a_q such that <=ft\lceil \frac{d(G_i)}{2} \right\rceil <= a_i <= 2 \cdot d(G_i) for each i.HacksYou cannot make hacks in this problem.
Input: ['9 10 8', '1 2', '2 3', '2 4', '3 5', '4 5', '5 6', '5 7', '6 8', '7 8', '8 9', '3 4', '6 7', '2 8', '1 9', '1 6', '4 9', '3 9', '7 1', ''] Output:['10 6 5 6 2 4 2 2 1', '']
[ 4 ]
Ada operates a network that consists of n servers and m direct connections between them. Each direct connection between a pair of distinct servers allows bidirectional transmission of information between these two servers. Ada knows that these m direct connections allow to directly or indirectly transmit information between any two servers in this network. We say that server v is a neighbor of server u if there exists a direct connection between these two servers.Ada needs to configure her network's WRP (Weird Routing Protocol). For each server u she needs to select exactly one of its neighbors as an auxiliary server a(u). After all a(u) are set, routing works as follows. Suppose server u wants to find a path to server v (different from u). Server u checks all of its direct connections to other servers. If it sees a direct connection with server v, it knows the path and the process terminates. If the path was not found at the first step, server u asks its auxiliary server a(u) to find the path. Auxiliary server a(u) follows this process starting from the first step. After a(u) finds the path, it returns it to u. Then server u constructs the resulting path as the direct connection between u and a(u) plus the path from a(u) to v. As you can see, this procedure either produces a correct path and finishes or keeps running forever. Thus, it is critically important for Ada to configure her network's WRP properly.Your goal is to assign an auxiliary server a(u) for each server u in the given network. Your assignment should make it possible to construct a path from any server u to any other server v using the aforementioned procedure. Or you should report that such an assignment doesn't exist.
Input: ['6 7', '1 2', '2 3', '3 1', '4 5', '5 6', '4 6', '2 5', ''] Output:['Yes', '2 5 2 5 2 5', '']
[ 0 ]
Annie is an amateur photographer. She likes to take pictures of giant residential buildings at night. She just took a picture of a huge rectangular building that can be seen as a table of n * m windows. That means that the building has n floors and each floor has exactly m windows. Each window is either dark or bright, meaning there is light turned on in the room behind it.Annies knows that each apartment in this building is either one-bedroom or two-bedroom. Each one-bedroom apartment has exactly one window representing it on the picture, and each two-bedroom apartment has exactly two consecutive windows on the same floor. Moreover, the value of m is guaranteed to be divisible by 4 and it is known that each floor has exactly \frac{m}{4} two-bedroom apartments and exactly \frac{m}{2} one-bedroom apartments. The actual layout of apartments is unknown and can be different for each floor.Annie considers an apartment to be occupied if at least one of its windows is bright. She now wonders, what are the minimum and maximum possible number of occupied apartments if judged by the given picture?Formally, for each of the floors, she comes up with some particular apartments layout with exactly \frac{m}{4} two-bedroom apartments (two consecutive windows) and \frac{m}{2} one-bedroom apartments (single window). She then counts the total number of apartments that have at least one bright window. What is the minimum and maximum possible number she can get?
Input: ['5 4', '0100', '1100', '0110', '1010', '1011', ''] Output:['7 10', '']
[ 0, 2 ]
While James is gone on business, Vesper takes her time and explores what the legendary Casino Royale has to offer to people who are fond of competitive programming.Her attention was grabbed by the very new "Pull Your Luck" roulette which functions in a pretty peculiar way. The roulette's wheel consists of n sectors number from 0 to n - 1. There is no ball and the winning sector is determined by a static arrow pointing to one of the sectors. Sectors' indexes go in the natural order and the wheel always spins in the direction of indexes increment. That means that sector i + 1 goes right after sector i for all i from 0 to n - 2, and sector 0 goes right after sector n - 1.After a bet is made, the player is allowed to pull the triggering handle herself and cause the wheel to spin. If the player's initial pull is made with the force equal to positive integer f, the wheel will spin for f seconds. During the first second it will advance f sectors, the next second it will advance f - 1 sectors, then f - 2 sectors, and so on until it comes to a complete stop. After the wheel comes to a complete stop, the sector which the arrow is pointing to is the winning one.The roulette's arrow currently points at sector x. Vesper knows that she can pull the handle with any integer force from 1 to p inclusive. Note that it is not allowed to pull the handle with force 0, i. e. not pull it all. The biggest prize is awarded if the winning sector is 0. Now Vesper wonders if she can make sector 0 win by pulling the triggering handle exactly once?
Input: ['75 2 15 2 210 0 10011 7 1003 1 100031 0 10100 49 7'] Output:['No', 'Yes', 'Yes', 'Yes', 'No', 'No', 'No', '']
[ 0, 2, 3 ]
Ethan runs a vaccination station to help people combat the seasonal flu. He analyses the historical data in order to develop an optimal strategy for vaccine usage.Consider there are n patients coming to the station on a particular day. The i-th patient comes at the moment t_i. We know that each of these patients can be asked to wait for no more than w time moments. That means the i-th patient can get vaccine at moments t_i, t_i + 1, ..., t_i + w.Vaccines come in packs, each pack consists of k doses. Each patient needs exactly one dose. Packs are stored in a special fridge. After a pack is taken out of the fridge and opened, it can no longer be put back. The lifetime of the vaccine outside the fridge is d moments of time. Thus, if the pack was taken out of the fridge and opened at moment x, its doses can be used to vaccinate patients at moments x, x + 1, ..., x + d. At moment x + d + 1 all the remaining unused doses of this pack are thrown away.Assume that the vaccination station has enough staff to conduct an arbitrary number of operations at every moment of time. What is the minimum number of vaccine packs required to vaccinate all n patients?
Input: ['56 3 5 31 2 3 10 11 186 4 0 03 3 3 3 3 49 10 2 20 1 2 3 4 5 6 7 83 10 3 610 20 305 5 4 40 2 4 6 8'] Output:['2', '3', '2', '3', '1', '']
[ 2 ]
You are given a checkerboard of size 201 * 201, i. e. it has 201 rows and 201 columns. The rows of this checkerboard are numbered from -100 to 100 from bottom to top. The columns of this checkerboard are numbered from -100 to 100 from left to right. The notation (r, c) denotes the cell located in the r-th row and the c-th column.There is a king piece at position (0, 0) and it wants to get to position (a, b) as soon as possible. In this problem our king is lame. Each second, the king makes exactly one of the following five moves. Skip move. King's position remains unchanged. Go up. If the current position of the king is (r, c) he goes to position (r + 1, c). Go down. Position changes from (r, c) to (r - 1, c). Go right. Position changes from (r, c) to (r, c + 1). Go left. Position changes from (r, c) to (r, c - 1). King is not allowed to make moves that put him outside of the board. The important consequence of the king being lame is that he is not allowed to make the same move during two consecutive seconds. For example, if the king goes right, the next second he can only skip, go up, down, or left.What is the minimum number of seconds the lame king needs to reach position (a, b)?
Input: ['5-4 14 40 -6-5 -47 -8'] Output:['7', '8', '11', '9', '15', '']
[ 2, 3 ]
Dasha loves guinea pigs very much. In this regard, she decided to settle as many guinea pigs at home as possible and developed a plan for the next n days. Every day, she will either buy a new guinea pig or call a doctor to examine all her pets.Unfortunately, the store where she was going to buy guinea pigs does not understand them. Therefore, it cannot determine their gender. Dasha can't do it either. The only one who can help is a doctor. To keep guinea pigs, aviaries are needed. Dasha plans to buy them in the same store. Unfortunately, only one species is sold there β€” a double aviary. No more than two guinea pigs can live in it.Since Dasha does not want to cause moral injury to her pets β€” she will not settle two guinea pigs of different genders in one aviary.Help Dasha calculate how many aviaries in the worst case you need to buy so that you can be sure that at no moment of time do two guinea pigs of different genders live in the same aviary.As part of this task, we believe that guinea pigs have only two genders β€” male and female.
Input: ['631 1 132 2 251 1 1 2 1101 2 1 2 1 2 1 2 1 2201 2 1 1 1 1 1 2 1 2 1 2 2 1 1 1 1 1 1 1202 1 1 2 1 1 2 1 2 2 1 1 1 2 2 1 1 1 1 2'] Output:['3', '0', '3', '4', '12', '9', '']
[ 2, 3 ]
Nikita recently held a very controversial round, after which his contribution changed very quickly.The announcement hung on the main page for n seconds. In the ith second |a_i|th person either liked or removed the like (Nikita was lucky in this task and there are no dislikes). If a_i > 0, then the a_ith person put a like. If a_i < 0, then the person -a_i removed the like. Each person put and removed the like no more than once. A person could not remove a like if he had not put it before.Since Nikita's contribution became very bad after the round, he wanted to analyze how his contribution changed while the announcement was on the main page. He turned to the creator of the platform with a request to give him the sequence a_1, a_2, ..., a_n. But due to the imperfection of the platform, the sequence a was shuffled.You are given a shuffled sequence of a that describes user activity. You need to tell for each moment from 1 to n what the maximum and minimum number of likes could be on the post at that moment.
Input: ['531 2 -221 -164 3 -1 2 1 -254 2 -2 1 37-1 6 -4 3 2 4 1'] Output:['1 2 1 ', '1 0 1 ', '1 0 ', '1 0 ', '1 2 3 4 3 2 ', '1 0 1 0 1 2 ', '1 2 3 4 3 ', '1 0 1 2 3 ', '1 2 3 4 5 4 3 ', '1 0 1 0 1 2 3 ', '']
[ 2 ]
Mom bought the boy Vasya a n-dimensional chocolate bar, which is a n-dimensional cube with the length of each side equal to 1. The chocolate is planned to be divided into slices. According to the ith dimension, it can be divided by hyperplanes into a_i equal parts. Thus, the chocolate is divided in total into a_1 \cdot a_2 \cdot a_3 \cdot ... \cdot a_n slices, each slice has a length of i-th dimension equal to \frac{1}{a_i}, respectively, the volume of each slice is \frac{1}{a_1 a_2 \cdots a_n}.Vasya and his friends want to cut a chocolate bar to get at least k pieces, while Vasya wants to maximize the volume of the smallest of them. It is possible to cut the chocolate bar only at the junction of the lobules, and each incision must pass through the entire chocolate bar along some hyperplane involved in the formation of lobules. Only after making all the cuts, Vasya disassembles the chocolate into pieces.More formally, Vasya wants to choose the numbers b_1, b_2, ..., b_n (1 <= b_i <= a_i) β€” the number of parts into which Vasya will cut the chocolate bar along each dimension. The condition b_1 \cdot b_2 \cdot ... \cdot b_n >= k must be met to get at least k pieces after all cuts. It can be noted that with optimal cutting with such parameters, the minimum piece will contain \lfloor \frac{a_1}{b_1} \rfloor ...m \lfloor \frac{a_n}{b_n} \rfloor slices, and its volume will be equal to \lfloor \frac{a_1}{b_1} \rfloor ...m \lfloor \frac{a_n}{b_n} \rfloor \cdot \frac{1}{a_1 a_2 \cdots a_n}.Vasya wants to get the maximum possible value of the volume of the minimum piece multiplied by k, that is, he wants to maximize the number of \lfloor \frac{a_1}{b_1} \rfloor ...m \lfloor \frac{a_n}{b_n} \rfloor \cdot \frac{1}{a_1 a_2 \cdots a_n} \cdot k. Help him with this.
Input: ['1 2', '5', ''] Output:['0.8', '']
[ 3 ]
The famous magician Borya Budini traveled through the country X, which consists of n cities. However, an accident happened, and he was robbed in the city number 1. Now Budini will have a hard way home to the city number n.He's going to get there by plane. In total, there are m flights in the country, i-th flies from city a_i to city b_i and costs s_i coins. Note that the i-th flight is one-way, so it can't be used to get from city b_i to city a_i. To use it, Borya must be in the city a_i and have at least s_i coins (which he will spend on the flight). After the robbery, he has only p coins left, but he does not despair! Being in the city i, he can organize performances every day, each performance will bring him w_i coins. Help the magician find out if he will be able to get home, and what is the minimum number of performances he will have to organize.
Input: ['44 4 27 4 3 11 2 213 2 61 3 82 4 114 4 101 2 10 11 2 202 4 301 3 253 4 894 4 75 1 6 21 2 52 3 103 4 503 4 704 1 21 1 1 11 3 2'] Output:['4', '24', '10', '-1', '']
[ 2, 4 ]
The boy Vitya loves to listen to music very much. He knows that n albums are due to be released this Friday, i-th of which contains k_i tracks. Of course, Vitya has already listened to all the tracks, and knows that in the i-th album, the coolness of the j-th track is equal to a_{i,j}.Vitya has a friend Masha, whom he really wants to invite to the festival, where his favorite bands perform. However, in order for a friend to agree, she must first evaluate the released novelties. Vitya knows that if Masha listens to a track that was cooler than all the previous ones, she will get 1 unit of impression. Unfortunately, albums can only be listened to in their entirety, without changing the songs in them in places.Help Vitya find such an order of albums so that Masha's impression turns out to be as much as possible, and she definitely went to the festival with him.
Input: ['2454 9 4 6 81728 611423 421 822 827 9'] Output:['4', '4', '']
[ 2, 4 ]
Little Sasha has two friends, whom he wants to please with gifts on the Eighth of March. To do this, he went to the largest shopping center in the city.There are n departments in the mall, each of which has exactly two stores. For convenience, we number the departments with integers from 1 to n. It is known that gifts in the first store of the i department cost a_i rubles, and in the second store of the i department β€” b_i rubles.Entering the mall, Sasha will visit each of the n departments of the mall, and in each department, he will enter exactly one store. When Sasha gets into the i-th department, he will perform exactly one of two actions: Buy a gift for the first friend, spending a_i rubles on it. Buy a gift for the second friend, spending b_i rubles on it. Sasha is going to buy at least one gift for each friend. Moreover, he wants to pick up gifts in such a way that the price difference of the most expensive gifts bought for friends is as small as possible so that no one is offended.More formally: let m_1 be the maximum price of a gift bought to the first friend, and m_2 be the maximum price of a gift bought to the second friend. Sasha wants to choose gifts in such a way as to minimize the value of \lvert m_1 - m_2 \rvert.
Input: ['221 22 151 52 73 34 102 5'] Output:['0', '1', '']
[ 2 ]
This is a complex version of the problem. This version has no additional restrictions on the number k.The chief wizard of the Wizengamot once caught the evil wizard Drahyrt, but the evil wizard has returned and wants revenge on the chief wizard. So he stole spell s from his student Harry.The spell β€” is a n-length string of lowercase Latin letters.Drahyrt wants to replace spell with an unforgivable curse β€” string t.Dragirt, using ancient magic, can swap letters at a distance k or k+1 in spell as many times as he wants. In other words, Drahyrt can change letters in positions i and j in spell s if |i-j|=k or |i-j|=k+1.For example, if k = 3, s = "talant" and t = "atltna", Drahyrt can act as follows: swap the letters at positions 1 and 4 to get spell "aaltnt". swap the letters at positions 2 and 6 to get spell "atltna". You are given spells s and t. Can Drahyrt change spell s to t?
Input: ['76 3talantatltna7 1abacabaaaaabbc12 6abracadabraaavadakedavra5 3acciocicao5 4lumosmolus4 3uwjttwju4 3kvpxvxpk'] Output:['YES', 'YES', 'NO', 'YES', 'NO', 'YES', 'NO', '']
[ 0, 2 ]
This is an easy version of the problem. In this version, k is always 3.The chief wizard of the Wizengamot once caught the evil wizard Drahyrt, but the evil wizard has returned and wants revenge on the chief wizard. So he stole spell s from his student Harry.The spell β€” is a n-length string of lowercase Latin letters.Drahyrt wants to replace spell with an unforgivable curse β€” string t.Drahyrt, using ancient magic, can swap letters at a distance k or k+1 in spell as many times as he wants. In this version of the problem, you can swap letters at a distance of 3 or 4. In other words, Drahyrt can change letters in positions i and j in spell s if |i-j|=3 or |i-j|=4.For example, if s = "talant" and t = "atltna", Drahyrt can act as follows: swap the letters at positions 1 and 4 to get spell "aaltnt". swap the letters at positions 2 and 6 to get spell "atltna". You are given spells s and t. Can Drahyrt change spell s to t?
Input: ['76 3talantatltna7 3abacabaaaaabbc12 3abracadabraaavadakedavra5 3acciocicao5 3lumosmolus4 3uwjttwju4 3kvpxvxpk'] Output:['YES', 'YES', 'NO', 'YES', 'NO', 'YES', 'NO', '']
[ 0, 2 ]
Dmitry has a string s, consisting of lowercase Latin letters.Dmitry decided to remove two consecutive characters from the string s and you are wondering how many different strings can be obtained after such an operation.For example, Dmitry has a string "aaabcc". You can get the following different strings: "abcc"(by deleting the first two or second and third characters), "aacc"(by deleting the third and fourth characters),"aaac"(by deleting the fourth and the fifth character) and "aaab" (by deleting the last two).
Input: ['76aaabcc10aaaaaaaaaa6abcdef7abacaba6cccfff4abba5ababa'] Output:['4', '1', '5', '3', '3', '3', '1', '']
[ 2 ]
This is a hard version of the problem. It differs from the easy one only by constraints on n and t.There is a deck of n cards, each of which is characterized by its power. There are two types of cards: a hero card, the power of such a card is always equal to 0; a bonus card, the power of such a card is always positive. You can do the following with the deck: take a card from the top of the deck; if this card is a bonus card, you can put it on top of your bonus deck or discard; if this card is a hero card, then the power of the top card from your bonus deck is added to his power (if it is not empty), after that the hero is added to your army, and the used bonus discards. Your task is to use such actions to gather an army with the maximum possible total power.
Input: ['553 3 3 0 060 3 3 0 0 371 2 3 0 4 5 071 2 5 0 4 3 053 1 0 0 4'] Output:['6', '6', '8', '9', '4', '']
[ 2 ]
This is an easy version of the problem. It differs from the hard one only by constraints on n and t.There is a deck of n cards, each of which is characterized by its power. There are two types of cards: a hero card, the power of such a card is always equal to 0; a bonus card, the power of such a card is always positive. You can do the following with the deck: take a card from the top of the deck; if this card is a bonus card, you can put it on top of your bonus deck or discard; if this card is a hero card, then the power of the top card from your bonus deck is added to his power (if it is not empty), after that the hero is added to your army, and the used bonus discards. Your task is to use such actions to gather an army with the maximum possible total power.
Input: ['553 3 3 0 060 3 3 0 0 371 2 3 0 4 5 071 2 5 0 4 3 053 1 0 0 4'] Output:['6', '6', '8', '9', '4', '']
[ 2 ]
Kristina has a string s of length n, consisting only of lowercase and uppercase Latin letters. For each pair of lowercase letter and its matching uppercase letter, Kristina can get 1 burl. However, pairs of characters cannot overlap, so each character can only be in one pair.For example, if she has the string s = "aAaaBACacbE", she can get a burl for the following character pairs: s_1 = "a" and s_2 = "A" s_4 = "a" and s_6 = "A" s_5 = "B" and s_{10} = "b" s_7= "C" and s_9 = "c" Kristina wants to get more burles for her string, so she is going to perform no more than k operations on it. In one operation, she can: either select the lowercase character s_i (1 <= i <= n) and make it uppercase. or select uppercase character s_i (1 <= i <= n) and make it lowercase. For example, when k = 2 and s = "aAaaBACacbE" it can perform one operation: choose s_3 = "a" and make it uppercase. Then she will get another pair of s_3 = "A" and s_8 = "a"Find maximum number of burles Kristina can get for her string.
Input: ['511 2aAaaBACacbE2 2ab4 1aaBB6 0abBAcC5 3cbccb'] Output:['5', '0', '1', '3', '2', '']
[ 2 ]
There are n people that will participate in voting. Each person has exactly one vote.i-th person has a team t_i (1 <=q t_i <=q n) where t_i = t_j means i, j are in the same team. By the rules each person should vote for the person from the different team. Note that it automatically means that each person can't vote for himself.Each person knows the number of votes c_i he wants to get. How many possible votings exists, such that each person will get the desired number of votes? Due to this number can be big, find it by modulo 998\,244\,353.
Input: ['3', '1 1 1', '1 2 3', ''] Output:['2', '']
[ 3 ]
You have an array of positive integers a_1, a_2, ..., a_n, of length n. You are also given a positive integer b.You are allowed to perform the following operations (possibly several) times in any order: Choose some 1 <= i <= n, and replace a_i with \lceil \frac{a_i}{2} \rceil. Here, \lceil x \rceil denotes the smallest integer not less than x. Choose some 1 <= i <= n, and replace a_i with \max(a_i - b, 0). However, you must also follow these rules: You can perform at most k_1 operations of type 1 in total. You can perform at most k_2 operations of type 2 in total. For all 1 <= i <= n, you can perform at most 1 operation of type 1 on element a_i. For all 1 <= i <= n, you can perform at most 1 operation of type 2 on element a_i. The cost of an array is the sum of its elements. Find the minimum cost of a you can achieve by performing these operations.
Input: ['73 2 1 19 3 52 1 2 01000000000 15 3 1 12 8 3 19 36 9 4 21 2 3 4 5 63 10 3 31 2 35 1 0 0999999999 999999999 999999999 999999999 9999999995 5 4 35 9 10 7 4'] Output:['11', '500000001', '23', '6', '0', '4999999995', '6', '']
[ 0, 2, 4 ]
You are given n * m grid. Some cells are filled and some are empty.A city is a maximal (by inclusion) set of filled cells such that it is possible to get from any cell in the set to any other cell in the set by moving to adjacent (by side) cells, without moving into any cells not in the set. In other words, a city is a connected component of filled cells with edges between adjacent (by side) cells.Initially, there are two cities on the grid. You want to change some empty cells into filled cells so that both of the following are satisfied: There is one city on the resulting grid. The shortest path between any two filled cells, achievable only by moving onto filled cells, is equal to the Manhattan distance between them. The Manhattan distance between two cells (a, b) and (c, d) is equal to |a - c| + |b - d|.Find a way to add filled cells that satisfies these conditions and minimizes the total number of filled cells.
Input: ['111 3#.#2 2.##.4 4..##...##...##..6 6.##...##..............##.....#...###6 5.#..#.#..#.#..#.#.##.#...##...5 5######...##.#.##...######4 4.##.##.##.##.##.5 5..###....#.....#....#....5 6.##...##....#....#....##...##.6 5..##....##....##....##....##..5 4..##..#...#.#...#...'] Output:['###', '', '.#', '##', '', '..##', '..##', '###.', '##..', '', '.##...', '###...', '..#...', '..####', '...###', '...###', '', '.####', '.####', '.####', '.####', '.#...', '##...', '', '#####', '#####', '#####', '#####', '#####', '', '.##.', '####', '####', '.##.', '', '..###', '..###', '..#..', '###..', '#....', '', '.##...', '###...', '######', '...###', '...##.', '', '..##.', '..###', '..###', '###..', '###..', '.##..', '', '..##', '..#.', '..#.', '###.', '#...']
[ 2, 3 ]