Hello, Codeforces!
I’m excited to introduce to you Neowise Labs. We’re going to host an upcoming Neowise Labs Contest 1 (Codeforces Round 1018, Div. 1 + Div. 2) and have prepared presents for you. Neowise Labs was founded by Max (dark_ai), Igor (Igor_Kudryashov) and me, and here is our story.
Igor_Kudryashov and I have been in the same ACM ICPC team for many years while studying at the Saratov State University. dark_ai was in the Saint Petersburg State University team so we were competitors back then :) Those years in the university we were doing the same as all other competitive programmers: solve problems, make contests, practice, practice and practice again (and sometimes study). I’ve even enjoyed being a Codeforces platform developer in my final year of study.







, where the last equation can be solved by extended Euclid algorithm and
and
. The values 
contains the number of ones in binary presentation that is multiple of three. Otherwise let 
. To learn more about floor/ceil functions I reccomend the book of authors Graham, Knuth, Patashnik "Concrete Mathematics". There is a chapter there about that functions and their properties.
.
.
blocks. Consider the lines added before the current block and that will not deleted in the current block. Let's build the lower envelope by that lines. Now to calculate the answer to the query we should get maximum over the lines from the envelope and the lines from the block before the current query that is not deleted yet. There are no more than
.

characters in the segment to remove all the pairs of equal consecutive letters. On the other hand we can simply change the second, the fourth etc. symbols to letter that is not equal to the letters before and after the segment.
is used for the binary operation for bitwise exclusive or.
. Let's iterate over
, because all the leaves in the subtree of tha vertex correspond to the values
and recalculate the value
, where
. So for fixed
.
, for all
. Then
values of
.
, and it is the heaviest part of the computation. Choosing optimal
, we obtain the complexity
.
:
. Let's calculate the value
.
choices to do that (it's simply binomial coefficient with allowed repititions). The number of sequences
. Easy to transform the last sum to the sum
. Note the last inner sum can be calculating using the formula for parallel summing:
. So the answer equals to
. Also we can get the closed formula for the last sum to get logarithmic solution, but it is not required in the problem.
,
) we will try to write the score of interval 

because we sort by
in advance because it's equivalent to sorting by
is possible this way — anybody implemented it?
.
be the number of even positions in
times.
). Consider an optimal answer with two strings in reverse order by that operator. Because of the transitivity of operator we can assume that pair of strings are neighbouring. But then we can swap them and get the better answer.
. The last is simply the relation between real numbers. So we proved the transitivity of the relation
and
.
, where 
in position
. To update the next state we should increase it: 
.
.
. In our case 
. The values
.
. Note that the last sum can be accumulated to only value
or
. Let's carefully accumulate both cases. The first sum can be simply calculated by iterating over all
. Firstly we should determine for which values
. Easy to see that for the values
. Also we can note that the sum of the second factors in
with fixed first factor can be calculaed in constant time — it's simply a sum of arithmetic progression
. So we have solution with complexity 
