text and two numbers ab_points and ba_points. As many times as you like, you may do either of these:
- delete a substring "ab" (two adjacent letters) and earn ab_points points;
- delete a substring "ba" and earn ba_points points.
After a deletion the remaining parts are joined together, which may create new pairs.
Return the most points you can earn.text='xbabyab', ab_points=3, ba_points=1 → 6
In "bab" you can delete either "ba" or "ab"; take "ab" for 3 points. Then delete the trailing "ab" for 3 more. Total 6.
text='bbaa', ab_points=10, ba_points=1 → 2
There is no "ab" here. Delete the middle "ba", which leaves "ba", and delete that too: 1 + 1 = 2.
text.length ≤ 10⁵text consists of lowercase English lettersab_points, ba_points ≤ 10⁴text='xbabyab', ab_points=3, ba_points=1
6
Run checks the first 3 tests in your browser. Submit checks all 153 tests on the server, hidden ones included.