QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 128 MB Total points: 100

#2097. Letters

Statistics

Little Johnny has a very long surname. Yet he is not the only such person in his milieu. As it turns out, one of his friends from kindergarten, Mary, has a surname of the same length, though different from Johnny's. Moreover, their surnames contain precisely the same number of letters of each kind - the same number of letters A, same of letters B, and so on.

Johnny and Mary took to one another and now often play together. One of their favourite games is to gather a large number of small pieces of paper, write successive letters of Johnny's surname on them, and then shift them so that they obtain Mary's surname in the end.

Since Johnny loves puzzles, he has begun to wonder how many swaps of adjacent letters are necessary to turn his surname into Mary's. For a child his age, answering such question is a formidable task. Therefore, soon he has asked you, the most skilled programmer in the kindergarten, to write a program that will help him.

Input

In the first line of the standard input there is a single integer $n$ ($2 \le n \le 1,000,000$) denoting the length of Johnny's surname. The second line contains Johnny's surname itself, i.e., contains its $n$ successive letters (without spaces). The third line contains Mary's surname in the same format: a string of $n$ letters (with no spaces either). Both strings consist only of capital (upper-case) letters of the English alphabet.

Output

Your program should print a single integer to the standard output: the minimum number of swaps of adjacent letters that transforms Johnny's surname into Mary's.

Example

Input

3
ABC
BCA

Output

2
About Issues

We understand that our problem archive is not perfect. If you find any issues with the problem, including the statement, scoring configuration, time/memory limits, test cases, etc.

You may use this form to submit an issue regarding the problem. A problem moderator will review your issue and proceed it properly.

STOP! Before you submit an issue, please READ the following guidelines:

  1. This is not a place to publish a discussion, editorial, or requests to debug your code. Your issue will only be visible by you and problem moderators. Other users will not be able to view or reply your issues.
  2. Do not submit duplicated issues. If you have already submitted one, please wait for an moderator to review it. Submitting multiple issues will not speed up the review process and might cause your account to be banned.
  3. Issues must be filed in English or Chinese only.
  4. Be sure your issue is related to this problem. If you need to submit an issue regarding another problem, contest, category, etc., you should submit it to the corresponding page.

Active Issues 0

No issues in this category.

Closed/Resolved Issues 0

No issues in this category.