Arranging Books | 프로그래밍의 벗 PivotOJ
PivotOJ

Arranging Books

시간 제한: 1000ms메모리 제한: 1024MB출처: CCC 2021 JuniorBOJ 21615

문제

Valentina wants books on a shelf to be arranged in a particular way. Every time she sees a shelf of books, she rearranges the books so that all the large books appear on the left, followed by all the medium-sized books, and then all the small books on the right. She does this by repeatedly choosing any two books and exchanging their locations. Exchanging the locations of two books is called a swap.

Help Valentina determine the fewest number of swaps needed to arrange a shelf of books as she wishes.

입력

The input will consist of exactly one line containing at most 500 000 characters. Each character will be L, M, or S.

출력

Output a single integer which is equal to the minimum possible number of swaps needed to arrange the books so that all occurrences of L come first, followed by all occurrences of M, and then all occurrences of S.

예제

예제 1

입력
LMMMS
출력
0

예제 2

입력
LLSLM
출력
2
코드를 제출하려면 로그인하세요.