1605 - Gene recombination

Time Limit : 2 Second

Memory Limit : 64 MB

Submission: 364

Solved: 83

Description
As a gene engineer of a gene engineering project, Enigma encountered a puzzle about gene recombination. It is well known that a gene can be considered as a sequence, consisting of four nucleotides, which are simply denoted by four letters, A, C, G, and T.

Enigma has gotten a gene, such as "ATCC". And he wants to reorder this gene to make a new one, like "CTCA". He can use two types of operations: (1) exchange the first two letters, or (2) move the first letter to the end of the gene. For example, "ATCC" can be changed to "TCCA" by operation (2), and then "TCCA" can be changed to "CTCA" by operation (1). Your task is to make a program to help Enigma to find out the minimum number of operations to reorder the gene.
Input
The input contains several test cases. The first line of a test case contains one integer N indicating the length of the gene (1<=N<=12). The second line contains a string indicating the initial gene. The third line contains another string which Enigma wants.

Note that the two strings have the same number for each kind of letter.
Output
For each test case, output the minimum number of operations.
sample input
4
ATCC
CTCA
4
ATCG
GCTA
4
ATCG
TAGC
sample output
2
4
6
hint
source
Problem Setter : Jian He
© 2015 HUST ACMICPC TEAM. All Right Reserved.