Hi Codeforces

I'd like to announce 18th HourRank round! The contest will be held on 16:00 UTC Thursday, March 2 2017. Contestants will be given 4 problems and 1 hour to solve. You can sign up for the contest here. Top 10 winners will receive a HackerRank T-Shirt.

HourRank 18 is prepared by me(svanidz1). I want to thank whole Hackerrank team, especially Shafaet for coordinating and Wild_Hamster for testing the tasks.

The contestants are ranked by score. If two contestants gets same score, the person who reached the score first is ranked higher

Wish you good luck.

**UPD1:** Score distribution : 15-30-50-75. Contest starts in less than 2.5 hours. All problems will have partial scores.

**UPD2:** Contest is over. Congratulations to winners:

Thank you for participation.

Interesting problems, thanks!

In problem "C" I used binary search with sparse tables and thought, that it's too straitforward, until reading the editorial — the solution was simple and nice :)

In problem B, how are we moving from state f(i,m) to f(i+1,(m+x)%3). shouldn't it be f(i,m) to f(i+1,(m-x)%3) ?

In the current state, the mod value is m. If we get a "x" and go to next state, the new mod value will be (m+x)%3.

f(i,m) denotes number of substrings start at i and have m mod under 3. So, lets say we have a substring i.......k which has m mod under 3. So we can write,

(str[i] + str[i+1] + ...... + str[k])%3 = m%3

or

(str[i+1]+ ........ + str[k])%3 = (m — str[i])%3

So for solving f(i,m) if we remove first position letter the remaining substring should have mod = (m — x)%3. So, how come it becomes (m+x)%3. I even checked with (m-x)%3 code and it works as well:

Yes it can be f(i, m) --> f(i+1, (m — (x%3) + 3)%3) )

since (a-b)%m = (a-b+m)%m

Code

But, (m-x)%3 != (m+x)%3. Plus here m takes values from 0 to 2.