Problem:
Score : 200 points

Problem Statement

Snuke is interested in strings that satisfy the following conditions:

The length of the string is at least N.

The first N characters equal to the string s.

The last N characters equal to the string t.

Find the length of the shortest string that satisfies the conditions.

Constraints

1≤N≤100

The lengths of s and t are both N.

s and t consist of lowercase English letters.

Input

The input is given from Standard Input in the following format:

N
s
t

Output

Print the length of the shortest string that satisfies the conditions.

Sample Input 1

3
abc
cde

Sample Output 1

5

The shortest string is abcde.

Sample Input 2

1
a
z

Sample Output 2

2

The shortest string is az.

Sample Input 3

4
expr
expr

Sample Output 3

4

The shortest string is expr.

Solution in C++14 (GCC 5.4.1) (judge verdict: Wrong Answer)

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,i,j,x,y,p,q,c=0,f=0,t;
    string s1,s2;
    cin>>n;
    cin>>s1>>s2;
    for(i=n-1;i>=0;i--){
        for(j=n-1;j>=0;j--){
            if(s1[i]==s2[j]){
                f++;
                if(f==1){
                    c++;
                    x=i;
                    y=j;
                }
                else{
                    break;
                }
            }
        }
    }
    for(p=x-1,q=y-1;p>=0,q>=0;p--,q--){
        if(s1[p]==s2[q]){
            c++;
        }
        else{
            break;
        }
    }
    t=2*n-c;
    cout<<t<<endl;
    return 0;
}