atcoder#AGC052E. [AGC052E] 3 Letters
[AGC052E] 3 Letters
Score : points
Problem Statement
A string, consisting of letters A
, B
, and C
, is called good, if every two consecutive letters are different. For example, strings ABABAB
and ABC
are good, while ABBA
and AABBCC
aren't.
You are given two good strings and of length .
In one operation, you can choose any letter of , and change it to another letter among A
, B
, and C
, so that remains good.
What's the smallest number of operations needed to transform into ? We can prove that it can always be done in a finite number of operations.
Constraints
- is a good string of length consisting of
A
,B
, andC
- is a good string of length consisting of
A
,B
, andC
Input
Input is given from Standard Input in the following format:
Output
Output the smallest number of operations needed to transform into .
4
CABC
CBAC
6
Here is one possible sequence of operations of length :
CABC
BABC
BCBC
BCAC
ACAC
ABAC
CBAC
It can be shown that operations are necessary for this case.
10
ABABABABAB
BABABABABA
15