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: Accepted)

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
typedef long long ll;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
#define ios ios_base::sync_with_stdio(0) ; cin.tie(0) ; cout.tie(0)
#define so sizeof
#define pb push_back
#define vl vector<ll>
#define el endl;cout.flush()
#define be begin()
#define fi first
#define se second
#define br break
#define sz size()
#define en end()
#define ro return 0
#define br break
#define con continue;
#define um unordered_map<ll,ll>
#define ms(x) memset(x , 0, so x)
#define all(x) (x).be , (x).en
#define rall(x) (x).rbegin() , (x).rend()
#define acc(x) accumulate((x).be , (x).en , 0ll)
#define forn(i,a,b) for(ll i=a;i<=b;++i)
#define forr(i,a,b) for(ll i=a;i<b;++i)
#define rng_58 mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define vll vector<pair<ll,ll> >
#define pll pair<ll,ll>
#define plll pair<ll,pair<ll,ll>>
#define plvl pair<pair<ll,ll> ,ll>
#define mp make_pair
int main()
{
    ios;
    ll n ;
    cin >> n;
    string s , t ;
    cin >> s >> t;
    unordered_map<ll , string > suff , pref ;
    string ss = "";
    ll len = 1 ;
    for(ll i = n-1 ; i >=0 ; --i){
        if(i == n-1){
            ss = ss + s[i];
            suff[len] = ss ;
            ++len ;
            con ;
        }
        else {
            string ans = "" ;
            ans = ans + s[i] ;
            ss.insert(0 , ans) ;
        }
        suff[len] = ss ;
        ++len;
    }
    ss = "";
    len = 1 ;
    forn(i , 0 , n-1 ){
        ss = ss + t[i] ;
        pref[len] = ss ;
        ++len ;
    }
    ll maxxlen = 0;
    for(ll i = n ; i >= 1 ; --i){
        if(suff[i] == pref[i]){
            maxxlen = i ;
            br ;
        }
    }
    cerr << "maxlen is " << maxxlen << el ;
    forn(i , 1 , n ){
       cerr << suff[i] << el ;
    }
    cerr << el ;
    forn(i , 1 , n ){
        cerr << pref[i] << el ;
    }
    string anss="";
    anss = anss + s;
    forn(i , maxxlen, n -1){
       anss  = anss + t[i];
    }
    cout << anss.size() << el ;
    ro ;

}