CF1418G
Method 1
We can forget about \(= 3\) for a moment and instead do \(\equiv 0 \mod 3\). For this, we can compare the \(\text{cnt} \bmod 3\) and check if they are the same. For this we can use string hash.
For the equal part, we can use two-pointers to find the largest region that ends in \(r\) which doesn't have any elements appear more than \(3\) times. We can use a map to record which hashes have appeared and check.