#P2133. Finding Xiaohong's Suitability Degree
Finding Xiaohong's Suitability Degree
Finding Xiaohong's Suitability Degree
In Xiaoming's school, every girl is associated with a unique 6-digit string that is a permutation of the digits \(1,2,3,4,5,6\). Xiaoming has an ideal girl whose feature string is \(A\). Two feature strings \(X\) and \(Y\) are defined to be similar if \(Y\) can be obtained from \(X\) by swapping two consecutive digits.
Initially, Xiaoming starts with his deskmate whose feature string is \(S\). Then, in each step, he searches for a girl whose feature string is similar to the current one until he finds a girl who is suitable for him. A girl is considered suitable if her feature string is either identical to \(A\) or similar to \(A\) (i.e. she can be obtained from \(A\) by one adjacent swap).
The suitability degree of a girl is defined as the minimum number of girls Xiaoming needs to encounter (including his deskmate and the girl herself) in order to reach her by a sequence of allowed moves. Thus, if the minimum number of moves (each move is one adjacent swap) required is \(d\), then the suitability degree is \(d+1\). Clearly, a lower suitability degree means the girl is more appropriate for Xiaoming.
However, Xiaoming believes that fate will not allow him to have the most suitable girl. Consequently, he chooses as his partner (Xiaohong) the girl with the second smallest suitability degree among all suitable girls.
Your task is: Given \(A\) and \(S\), compute the suitability degree of Xiaohong.
Note: The set of all suitable girls consists of the girl with feature string \(A\) and all girls whose feature string can be obtained by a single adjacent swap from \(A\).
inputFormat
The input consists of two lines. The first line contains the ideal feature string \(A\) which is a permutation of \(1,2,3,4,5,6\). The second line contains the starting feature string \(S\), another permutation of \(1,2,3,4,5,6\>.
outputFormat
Output a single integer representing the suitability degree of Xiaohong.
sample
123456
132456
2