All problems

Problem 984

Remove Colored Pieces if Both Neighbors are the Same Color

Medium · 20 pts · String, Greedy, Game Theory

Problem

A line of pieces is coloured A or B. Alice and Bob alternate, Alice first. Alice may remove an A piece whose two neighbours are both A, and Bob may remove a B piece whose two neighbours are both B; pieces at the ends cannot be removed. The player who cannot move loses. Moves never affect the other player's options, so count each player's available moves: a run of k equal letters gives k - 2 moves. Alice wins exactly when she has more moves than Bob.

Input

A single string of the letters A and B.

Output

Print YES if Alice wins, otherwise NO.

Constraints

1 <= length <= 100000

Example input

AAABABB

Example output

YES

Explanation

In AAABABB, Alice can remove the middle A of AAA (1 move) and Bob has no BBB run, so Bob is stuck after Alice's move. Alice wins, so the answer is YES.

Every problem here can be used in a RelayTrixCode team match. Create a room.

Previous: Smallest String With A Given Numeric Value Next: Score After Flipping Matrix