Choose a domino placement rule so that the resulting chain is maximized according to the problem’s scoring condition.
You are given a sequence of dominoes. Each domino can be oriented or chosen according to the rules of the problem, and the task is to determine the best possible result over the whole sequence.
In particular, the solution requires tracking how the effect of one domino influences the next ones and computing the maximum achievable score/length under the allowed transitions. A correct approach usually involves carefully modeling the process, then using efficient counting or prefix-based reasoning to avoid recomputing overlapping states.
Print the maximum achievable value required by the problem statement.
Example 1
Input
5 1 2 2 1 3
Output
3
Explanation
This is a small illustrative example showing a chain-based computation. The best result comes from selecting the longest valid progression under the allowed rule.
Premium problem context
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.