Conference
시간 제한2초메모리 제한2048 MB
각 날짜의 공연장 정보가 A, B, C, ?로 주어지고, 물음표를 A, B, C로 각각 몇 개씩 배정하는 질의마다 이웃한 날의 공연장이 달라지는 횟수의 최솟값을 구한다.
문제
Chairman K is going to host a series of conferences over days. Each day, exactly one conference is held, and it takes place in one of the three venues: the main venue A or one of the sub-venues B and C.
The venue information for each conference is given as a string consisting of ‘A’, ‘B’, ‘C’, and ‘?’. For the -th day (), if the -th character of is ‘A’, the conference is held in venue A. If it is ‘B’, it is held in venue B. If it is ‘C’, it is held in venue C. If it is ‘?’, the venue for the -th day has not been decided yet. However, since the conferences on the first and -th days are expected to have many participants, it has already been determined that venue A will be used on those days.
Chairman K now needs to assign a venue to each undecided conference, choosing one of A, B, or C for each. Additionally, in order to minimize the burden of moving between venues, he wants to minimize the number of indices () such that the venue for the -th day differs from the venue for the -th day.
There are scenarios to consider regarding the assignment of venues. The -th scenario () and the corresponding question are as follows:
- Chairman K has to assign undecided conferences to venue A, to venue B, and to venue C. Determine the minimum possible number of indices such that the venue for the -th day differs from the venue for the -th day.
Given the information about the venues and scenarios to consider, write a program to answer the questions.
입력
Read the following data from the standard input.
출력
Write lines to the standard output. In the -th line (), output the minimum number of indices such that the venue for the -th day differs from the venue for the -th day, under the condition that Chairman K assigns undecided conferences to venue A, to venue B, and to venue C.
제한
- .
- is a string of length consisting of ‘
A’, ‘B’, ‘C’, and ‘?’. - The first and -th characters of are ‘
A’. - .
- ().
- ().
- ().
- is equal to the number of ‘
?’ in (). - , , , , are all integers.