Bombone - Državno
Little Djole saw n sweets in a candy shop's window. The sweets are lined up and each one of them is represented with a single natural number - different numbers indicate different types of sweets, and same numbers indicate the same kind of sweets. He plans to grab some of them, eventually pay for them and later sweeten himself up.
In order to do it faster, he wants to grab only a sequence of successive sweets, i.e. he wants to select two integers i and j (1 ≤ i ≤ j ≤ n) and grab all the sweets on the positions i, i + 1, ..., j - 1, j. Also, since he doesn't like diversity, there may not be more than three different kinds of sweets in that subsequence. For example, the subsequence 12434 is not a good one because it contains 4 different kinds of candy.
Determine the amount of ways Djole can grab the sweets.
5
1 2 4 3 4Output:
13Explanation: We have 13 possible subsequences that satisfy the given constraints: (12434), (12434), (12434), (12434), (12434), (12434), (12434), (12434), (12434), (12434), (12434), (12434) and (12434).
6
10 20 10 30 20 20Output:
21Explanation: Since we have only three different kinds of sweets overall (10, 20 and 30), every subsequence of successive elements (and there are 21 of them) satisfies the constraints.
Submit solution
Coming laterThe grading service will be connected in a later migration step. You can inspect the task and your previous results now.