Jason ABC
시간 제한1초메모리 제한1024 MB
길이 3n인 A, B, C 문자열에서 구간을 한 문자로 덮어쓰는 연산을 최소로 사용해 각 문자가 n번씩 나오게 만드는 최적 연산 열을 구한다.
문제
You are given a string of length , consisting of the characters A, B and C. You are allowed to perform the following operation:
- Select some subsegment of this string and a character (one of
A,BandC). Then, replace all the characters on the subsegment with .
Find the smallest number of times that you would have to apply the operation above to get a string which contains each of characters A, B and C exactly times. It can be shown that it is always possible to get such a string.
In addition, find a sequence of operations of the smallest possible length. If there are many such sequences, you can output any of them.
입력
The first line of input contains a single integer ().
The second line of the input contains a string of length , consisting of the characters A, B and C.
출력
In the first line print the minimum number of operations .
In the -th of the next lines print integers and a character (, c\_i \in \\{A, B, C\\}), denoting that in the -th operation you will replace each of the characters with .
If there is more than one solution with a minimum number of operations, you can print any one of them.
힌트
In the first sample, the string will undergo the following transformations:
AAA ABB ABC.
In the second sample, the string already contains exactly one A, one B and one C.
In the third sample, the string will undergo the following transformation:
ABABCABAB CCABCABAB. Now, it contains each letter times.