#B4126. Rhythmic Finger Tapping

    ID: 11783 Type: Default 1000ms 256MiB

Rhythmic Finger Tapping

Rhythmic Finger Tapping

Little Y tapped on the table with his fingers. He found the rhythm exquisite and recorded it as a string.

He uses only four fingers: left index (L), left middle (L'), right index (R), and right middle (R'). When only one finger taps at a time, he writes down the finger in the order of time. For example, LRR'L indicates that the left index taps first, followed by the right index, then the right middle, and finally the left index.

Sometimes, to indicate the intensity of the sound, multiple fingers tap simultaneously. In that case he encloses the tapping fingers in parentheses (it is guaranteed that no finger appears twice in the same pair of parentheses). For example, (LL')RR(LR)(RR') means:

  • The first beat: left index and left middle tap simultaneously once.
  • The second beat: right index taps once.
  • The third beat: right index taps once.
  • The fourth beat: left index and right index tap simultaneously once.
  • The fifth beat: right index and right middle tap simultaneously once.

A beat is defined as a moment when one or more fingers tap. In the above example there are 5 beats. In some test cases, you are additionally required to calculate, for each of the four fingers, the maximum number of consecutive beats in which that finger appears.

More formally, let the beats be numbered \(1,2,\dots,n\) in order. For each finger, find the maximum \(k\) such that the finger appears in beats \(i,i+1,\dots,i+k-1\) for some valid \(i\).

inputFormat

The input consists of a single line containing the record string S. S contains characters L, L', R, R' and parentheses ( and ). In the case of parentheses, the characters enclosed represent simultaneous taps.

outputFormat

Output two lines:

  1. The first line contains a single integer, the total number of beats.
  2. The second line contains four integers separated by a space. They represent the maximum consecutive beat counts for L, L', R, and R' respectively.

sample

LRR'L
4

1 0 1 1

</p>