P16248 [Lanqiao Cup 2026 NOI Qualifier Graduate Group] Number of Occurrences of 2026

Description

You are given a string $S$ that contains only the digits $0$, $2$, and $6$. You may perform the following operation any number of times: find a contiguous substring $202$ in the string and replace it with $6$. Your goal is: by performing some operations, make the number of occurrences of the contiguous substring $2026$ in the final string as large as possible. Now, output this maximum number of occurrences.

Input Format

Input one line containing a string $S$ consisting only of digits $0$, $2$, and $6$.

Output Format

Output one integer, representing the maximum number of occurrences of the contiguous substring $2026$ in the final string.

Explanation/Hint

### Constraints For $40\%$ of the testdata, the length of the string $S$, $|S|$, satisfies $1 \leq |S| \leq 500$. For all testdata, the length of the string $S$, $|S|$, satisfies $1 \leq |S| \leq 10^5$, and all input characters are restricted to the set $\{0,2,6\}$. Translated by ChatGPT 5