AT_agc078_a [AGC078A] Rearrange ABC
Description
You are given strings $ S $ and $ T $ of length $ 3N $ , each containing exactly $ N $ occurrences of each of `A`, `B`, and `C`.
You can perform the following operation zero or more times.
- Choose one substring of $ S $ whose characters are all distinct.
- Sort the characters of the chosen substring in ascending order.
Determine whether it is possible to make $ S $ equal to $ T $ , and if it is possible, find the minimum number of operations required.
Input Format
The input is given from Standard Input in the following format:
> $ N $ $ S $ $ T $
Output Format
Output the answer. If it is impossible to make $ S $ equal to $ T $ , output `-1`.
Explanation/Hint
### Sample Explanation 1
For example, you can make $ S $ equal to $ T $ by performing two operations as follows.
- Choose the first two characters of `CACBAB`, making it `ACCBAB`.
- Choose the $ 3 $ -rd through $ 5 $ -th characters of `ACCBAB`, making it `ACABCB`.
It is impossible to make them equal with one operation, so the answer is $ 2 $ .
### Sample Explanation 2
No matter how you perform the operations, you cannot make `ABC` equal to `CBA`.
### Constraints
- $ 1 \le N \le 100 $
- $ S $ and $ T $ are strings of length $ 3N $ consisting of `A`, `B`, and `C`.
- Each of $ S $ and $ T $ contains exactly $ N $ occurrences of each of `A`, `B`, and `C`.
- All input values are integers.