cswork / OAOpen practice workspace

TeslaOA #3

Maximum Number of Workers with Equal Left and Right Shoes

Estimated EasyJudge-ready

Topics (AI-labelled)GreedyPrefix & Ranges

Partition all the shoes into contiguous, non-overlapping segments, each with the same number of L and R, and find the maximum number of segments. Every shoe must belong to a segment.

Input

One line containing a string of L/R of length 2 to 100000; the numbers of L and R are guaranteed to be equal.

Output

Output the maximum number of segments.

Example 1

Input:

LRLR

Output:

2

Example 2

Input:

LLRR

Output:

1

Example 3

Input:

RLLRRL

Output:

3

Example notes

LRLR splits into LR and LR; LLRR can only form one segment; RLLRRL splits into three segments: RL, LR, RL.

Editorial

Loading solution…