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.



Sample input:
3
abc
cde


Sample output:
5

Submission status: Accepted

Solution code:
i=n=input()
p=raw_input
s=p()
t=p()
while(s[-i:]!=t[:i])*i:i-=1
print 2*n-i

Submission status: Accepted

Solution code:
n = int(input())
s = str(input())
t = str(input())
i = -1
while True:
   i += 1
   if t.find(s[i:n])>-1:
      print(int(n+i))
      break

Submission status: Accepted

Solution code:
N=int(input())
s=input()
t=input()

a=0
b=0

for i in range(N):
    if s[i]==t[a]:
        a+=1
        b+=1

print(len(s[0:N-b])+len(t))

Submission status: Accepted

Solution code:
n=input()
s=raw_input()
t=raw_input()
for i in xrange(0,n+1):
	if s[i:n]==t[0:n-i]:
		print n+i
		break

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
n = int(input())
s = input()
t = input()
txt = s+t
tmp = ''

for i in range(1,n):
    tmp = s+t[i:]
    if tmp[-n:]==t:
        txt = tmp

if s==t:
    print(len(s))
else :
    print(len(txt))

Submission status: Accepted

Solution code:
N=raw_input()
s=raw_input()
t=raw_input()
N=int(N)


ans=0
for i in range(1,N+1):
    if s[N-i:]==t[:i]:
        ans = i

print 2*N-ans

Submission status: Accepted

Solution code:
N = int(input())

s = input()

t = input()

temp = N
flag = True
if s==t:
    print(N)
else:
    while(temp > 0 and flag):
        temps = s[N-temp:N]
        tempt = t[:temp]
        if(temps==tempt):
            flag = False
        else:
            temp -= 1

    print(N+N-temp)

Submission status: Accepted

Solution code:
#coding:utf8

N = int(input())
s = input()
t = input()

combined = ""
a = [x for x in range(N+1)]
a.reverse()
for i in a:
	if s[N-i:] == t[:i]:
		combined = s[:]+t[i:]
		break
print(len(combined))

Submission status: Accepted

Solution code:
N = int(input())
s = input()
t = input()
mx = 0
for i in range(0,N):
    cnt = 0
    for j in range(0,N):
        if i+j >= N: break
        if s[i+j] == t[j]:
            cnt += 1
    mx = max(mx,cnt)
print(len(s+t[mx:]))

Submission status: Accepted

Solution code:


N = int(raw_input())
s = list(raw_input())
t = list(raw_input())

length = N*2

i = 1
MAX = 0
while i <= N:
   
    cs =  t[0:i]
    ct = s[N-i:N]
    #print cs , ct
    
    
    #print cs,ct,i
    if cs == ct:
        MAX = i 
    else:
        next
    i+=1

print N*2-MAX

Submission status: Accepted

Solution code:
import sys
n=input()
s=input()
t=input()
count=0
flag=True
for i in range(len(s)):
    flag=True
    j=0
    for ii in range(i,len(s)):
        if t[j]!=s[ii]:
            flag=False
            break
        j+=1
        count+=1
    if flag:
        print(len(s)+i)
        sys.exit()
print(len(s+t))

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import absolute_import
from __future__ import unicode_literals
import sys

n = int(input())
before = str(input())
after = str(input())
cnt = n

while True:
    if cnt == 0:
        print(len(before) + len(after) - cnt)
        break
    start = after[:cnt]
    last = before[-cnt:]
    if last == start:
        print(len(before) + len(after) - cnt)
        break
    cnt -= 1

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
# 整数の入力
N = int(input())
s = input()
t = input()

if s == t:
    res = N
else:
    for i in range(1, N+1):
        if s[i:] == t[:-i]: break
    res = N + i

# 出力
print(res)

Submission status: Accepted

Solution code:
N = int(raw_input())
s = raw_input()
t = raw_input()

for i in range(N+1):
    if s[i:] == t[:(N-i)]:
        break
print N + i

Submission status: Accepted

Solution code:
N = int(input())
s = input()
t = input()
ans = 0
another_t = t

if s == t:
    print(len(s))
else:
    while len(another_t) != 0:
        string = s + another_t
        if string[0:N] == s and string[len(string)-N:len(string)] == t:
            ans = len(string)
        another_t = another_t[1:len(another_t)]
    print(ans)

Submission status: Accepted

Solution code:
n=int(input())
s=input()
t=input()
for i in range(n):
    if s[i:] == t[:n-i]:
        print(n+i)
        break
else:
    print(n*2)

Submission status: Accepted

Solution code:
n = int(input())
s = input()
t = input()

for i in range(n + 1):
    sp = s[i:n]
    tp = t[0:n-i]
    if sp != tp:
        continue
    print(n+i)
    break

Submission status: Accepted

Solution code:
N = int(input())
s = list(input())
t = list(input())
for i in range(0,N):
    #print(s[i:],t[:N-i])
    if s[i:]==t[:N-i]:
        s = s[:i]
        break
s.extend(t)
print(len(s))

Submission status: Accepted

Solution code:
n = int(input())
s = str(input())
t = str(input())
s_rev = s[::-1]
count = 0

for i in range(1, n+1):
    sub_str = (s_rev[0:i])[::-1]
    if t[0:i] == sub_str and t[0:i][0] == sub_str[0]:
        count = max(count, len(sub_str))
print((2*n) - count)

# for i in range(n):
#     if list(s_rev)[i] == list(t)[i]:
#         count += 1
# if s == t:
#     print(n)
# else:
#     print((2 * n)-count)

Submission status: Accepted

Solution code:
def main():
    minLen = int(input())
    begin = list(input())
    end = list(input())

    iMax = 0

    if begin == end:
        iMax = minLen
    else:
        for i in range(minLen):
            if i == 0: continue
            if begin[-i:] == end[:i]: iMax = i
            #print(begin[-i:], end[:i])

    print(2*minLen - iMax)

    #print(lenOut)

if __name__ == '__main__':
  main()

Submission status: Accepted

Solution code:
n = input()
s = raw_input()
t = raw_input()
count = 0
while(count < n):
	if s[count:n] == t[0:n-count]:
		print n + count
		exit()
	count += 1
print n*2

Submission status: Accepted

Solution code:
n = int(raw_input())
s = raw_input().strip()
t = raw_input().strip()
ans = 2 * n
for i in xrange(n):
    if s[i:] == t[:n-i]:
        ans = min(ans, n + i)
print ans

Submission status: Accepted

Solution code:
N = int(input())
s = input()
t = input()

same_len = 0
for i in range(N):
    if s[i:] == t[:N - i]:
        same_len = N - i
        break

print(2 * N - same_len)

Submission status: Accepted

Solution code:
#input
N=int(input())
s=input()
t=input()
if s==t:
	print(len(s))
else:
	memo=0
	for i in range(1,len(s)):
		if s[len(s)-i:]==t[:i]:
			memo=i

	print(len(s)*2-memo)

Submission status: Accepted

Solution code:
N = int(input())
S = input()
T = input()
c = 0
for i in range(N):
    if S[-i-1:] == T[:i+1]:
        c = i + 1
print(N * 2 - c)

Submission status: Accepted

Solution code:
import sys

N = int(input())

a = input()
b = input()

for i in range(N):
	if a[i:N] == b[0:N-i]:
		print(N+i)
		sys.exit()
		
print(2 * N)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
# !/usr/bin/env python
# vim: set fileencoding=utf-8 :

"""
#
# Author:   Noname
# URL:      https://github.com/pettan0818
# License:  MIT License
# Created:  2016-10-29
#

# Usage
#
"""
from __future__ import division
from __future__ import unicode_literals
from __future__ import print_function
from __future__ import absolute_import

def read_input():
    min_len = int(input())
    first_str = list(input())
    end_str = list(input())

    return min_len, first_str, end_str


def check_dup(first_str, end_str, min_len):
    """

    >>> check_dup("expr", "expr", 4)
    4
    >>> check_dup("a", "z", 1)
    2
    >>> check_dup("abc", "cde", 3)
    5
    >>> check_dup("expr", "expr", 5)
    8
    """
    for char_num in range(len(end_str), 0, -1):
        sub_f = first_str[char_num * -1:]
        sub_e = end_str[: char_num]

        if sub_f == sub_e:
            result = len(sub_f) + (len(end_str) - char_num) * 2
            if result < min_len:
                continue
            else:
                return result

    return len(first_str) + len(end_str)



if __name__ == "__main__":
    #import doctest
    #doctest.testmod()

    min_len, f, e = read_input()

    print(check_dup(f, e, min_len))

Submission status: Accepted

Solution code:
def func():
 n=int(input())
 a=input()
 b=input()
 for i in range(n,0,-1):
  if(a[-i:]==b[0:i]):
   print(n*2-i)
   return
 print(n*2)

func()

Submission status: Accepted

Solution code:
# def makelist(n, m):
# 	return [[0 for i in range(m)] for j in range(n)]

# n = int(input())
# a, b = map(int, input().split())
# s = input()


n = int(input())
s = input()
t = input()

ans = 2 * n
for i in range(n):
	flag = True
	for j in range(n-i):
		if s[i+j] != t[j]:
			flag = False
			break
	if flag:
		ans = n + i
		break
print(ans)

Submission status: Accepted

Solution code:
n=int(input())
s=input()
t=input()
for i in range(len(t)+1)[::-1]:
	S=s+t[i:]
	if ((s in S) and (t in S)):
		print(max(len(s)+len(t)-i,n))
		break

Submission status: Accepted

Solution code:
n = int(input())
s = input()
t = input()
ans = 2 * n
for i in range(0,n + 1):
    if s[-i:] == t[:i]:
        ans = 2 * n - i
print(ans)

Submission status: Accepted

Solution code:
n = input()
s = raw_input()
t = raw_input()
u = s[:]
i = 1
while True:
    # print u
    if u[-n:] == t:
        break
    else:
        u = s + t[-i:]
        i += 1
print len(u)

Submission status: Accepted

Solution code:
n = input()
s = raw_input()
t = raw_input()



z = n + n
for i in range(0, n + 1):
	if s[-i:] == t[:i]:
		z = min(z, n + n - i)

print z

Submission status: Accepted

Solution code:
N = int(input())
s = input()
t = input()

k = 0
for i in range(1, N):
    if s[i:] == t[:-i]:
        k = N - i
        break

if s == t:
    print(N)
else:
    print(2 * N - k)

Submission status: Accepted

Solution code:
N = int(raw_input())
s = raw_input()
t = raw_input()

for i in xrange(2*N):
    if s in s[0:i]+t:
        print N + i
        break

Submission status: Accepted

Solution code:
N = int(input())
s = input()
t = input()
a = 0
for i in range(N):
	if s[-i-1:] == t[:i+1]:
		a = i+1
print(2*N-a)

Submission status: Accepted

Solution code:
N = input()
s = raw_input()
t = raw_input()



d = 0
for i in range(N):
    if(s[-i-1:]==t[:i+1]):d=i+1



print 2*N-d

Submission status: Accepted

Solution code:
N = input()
s = raw_input()
t = raw_input()

for i in range(N):
    flg = True
    for j in range(i,N):
        if s[j] != t[j-i]:
            flg = False
            break
    if flg:
        print N+i
        exit()
print 2*N

Submission status: Accepted

Solution code:
import re
n = int(input())
s = input()
t = input()

def calc():
    for i in range(len(s)):
        if re.match(s[i:],t):
            return n+i
    return n*2
print(calc())

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sat Oct 29 21:00:35 2016

@author: dotha
"""

def main():
    N = int(input())
    s = input()
    t = input()
    if s==t:
        return s
    for i in range(N):
        if s[i:] == t[:-i]:
            return(s[:i]+t)
    else:
        return(s+t)
    





if __name__ == "__main__":
    print(len(main()))

Submission status: Accepted

Solution code:
n=int(input())
s,t=list(input()),list(input())
if s == t:
    print(n)
    exit(0)
for i in range(n):
    if s[i:] == t[:-i]:
        print(n+i)
        exit(0)
print(2*n)

Submission status: Accepted

Solution code:
n=int(raw_input())
s=raw_input()
t=raw_input()
for i in range(n):
    if s==t:
        print n
        exit()
    elif s[i:]==t[:-i]:
        print n+i
        exit()
print 2*n

Submission status: Accepted

Solution code:
n = int(raw_input())
s = raw_input()
t = raw_input()

for i in reversed(range(n+1)):
    if s[-i:] == t[:i]:
        print 2 * n - i
        break
else:
    print 2 * n

Submission status: Accepted

Solution code:
n = int(input())
s = input()
t = input()
j = 0
for i in range(n):
    if s[i] != t[j]:
        j == 0
    if s[i] == t[j]:
        j += 1
print(2 * n - j)

Submission status: Accepted

Solution code:
#!\usr\bin\env python3


def length_of_shotest_string(n, s, t):
    for i in range(n + 1)[::-1]:
        if s.endswith(t[:i]):
            return 2 * n - i


def main():
    n = int(input())
    s = input()
    t = input()
    print(length_of_shotest_string(n, s, t))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N = int(input())
a, b = input(), input()

result = 0
for i in range(N):
    if b.startswith(a[i:]):
        break
    result += 1
print(result + N)

Submission status: Accepted

Solution code:
a, s, t = input(), raw_input(), raw_input()
for i in xrange(a):
    if s[i:] == t[:a-i]:
        print a+i
        exit()
print a*2

Submission status: Accepted

Solution code:
n=int(raw_input())
s=raw_input()
t=raw_input()

for i in xrange(n):
    if s[i:]==t[0:n-i]:
        print(n+i)
        exit()
print(n+n)

Submission status: Accepted

Solution code:
N = int(input())
s = input()
t = input()
for i in range(len(s)+1):
    if t.startswith(s[i:]):
        print(len(s[:i] + t))
        break

Submission status: Accepted

Solution code:
N = int(raw_input())                                                                        
s = raw_input()                                                                             
t = raw_input()                                                                             
                                                                                            
count = 0                                                                                   
for i in xrange(N):                                                                         
    if s[i] == t[count]:                                                                    
        count += 1                                                                          
print 2*N - count

Submission status: Accepted

Solution code:
N = int(input())
S = input()
T = input()
ans = -1
for i in range(N):
    # print(S[i:], T[:N-i])
    if S[i:] == T[:N-i]:
        ans = N + i
        break
if ans == -1:
    ans = N * 2
print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys

def s():
    return raw_input().strip()
def n():
    return int(raw_input())
def d():
    return float(raw_input())

def ls():
    return raw_input().strip().split()
def ln():
    return map(int, raw_input().strip().split())
def ld():
    return map(float, raw_input().strip().split())

def fs():
    return [raw_input().strip() for i in xrange(input())]
def fn():
    return [int(raw_input().strip()) for i in xrange(input())]
def fd():
    return [float(raw_input().strip()) for i in xrange(input())]

N = n()
S = s()
T = s()

LS = len(S)
LT = len(T)

for i in xrange(LS):
    if i + LT >= N and S[i:] == T[:LS - i]:
        print i + LT
        break
else:
    print LS + LT

Submission status: Accepted

Solution code:
n=int(raw_input())
s=raw_input()
t=raw_input()
j=0
while s[j:]!=t[:n-j]:j+=1
print n+j

Submission status: Accepted

Solution code:
# import sys; sys.stdin = open('input.txt')

n = int(raw_input())

a = raw_input()
b = raw_input()

res = n

for i in xrange(n):
    if a.endswith(b[:n-i]):
        break
    res += 1

print res

Submission status: Accepted

Solution code:
#import string,itertools,fractions,heapq,re,array,bisect
#from math import *
#from collections import Counter
def rl(s): return xrange(len(s))


INF = 2147483647


import sys
stdin = sys.stdin

N =        int( stdin.readline().strip() )
s = stdin.readline().strip()
t = stdin.readline().strip()

for offset in range(N+1):
    if t.startswith(s[offset:]):
        print N + offset
        break

Submission status: Accepted

Solution code:
n = int(input())
s = input()
t = input()

M = 0
for i in range(1, n+1):
    if s[-i:] == t[:i]:
        M = i
print(n*2 - M)

Submission status: Accepted

Solution code:
N=int(input())
S=input()
T=input()
for i in range(N,-1,-1):
    if S[N-i:] == T[:i]:
        print(2*N-i)
        break

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys,copy,math,heapq,itertools as it,fractions,re,bisect,collections as coll

N = int(raw_input())
s = raw_input()
t = raw_input()

for i in xrange(len(s)):
    for j in xrange(len(t)):
        if i + j >= len(s): continue
        if t[j] != s[i + j]:
            break
    else:
        print i + j + 1
        exit()
print len(s) + len(t)

Submission status: Accepted

Solution code:
N = input()
s = raw_input()
t = raw_input()
for i in range(N+1):
    if s[i:]==t[:N-i]:
        print N+i
        break

Submission status: Accepted

Solution code:
N, s, t = int(input()), input(), input()
m = N
while N > 0 and s[-N:] != t[:N]:
    N -= 1
print(m * 2 - N)

Submission status: Runtime Error

Solution code:
n = int(input())
s = input()
t = input()

for i in range(n):
  if t.startswith(s[i:]):
    x = n + i

print(x)

Submission status: Runtime Error

Solution code:
if (n == len(s) and (s == t)):
    print(n)
else:
    ind = [0]
    for i in range(1, len(s)):
        if s[-i:] == t[:i]:
            ind.append(i)

    ind.reverse()
    for i in ind:
        if i == 0:
            print(2*n)
        else:
            res = s[0:-i] + t
            if len(res) >= n:
                print(len(res))
                break

Submission status: Runtime Error

Solution code:
n=int(input())
s=input()
t=input()

for i in range(n,2*n-1):
    if s[:2*n-i] == t[2*n-i]:
        print(i)
        exit()
print(2*n)

Submission status: Runtime Error

Solution code:
n=input()
s=raw_input()
t=raw_input()
for i in xrange(0, n + 1):
	if s[i : n] == t[0 : n - i]:
		print n + i
		break

Submission status: Runtime Error

Solution code:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb(x) push_back(x)
#define mp(a, b) make_pair(a, b)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define lscan(x) scanf("%I64d", &x)
#define lprint(x) printf("%I64d", x)
#define rep(i, n) for (int i = 0; i < n; i++)
#define rep2(i, n) for (int i = n - 1; i >= 0; i--)
const int mod = 1000000007;
ll gcd(ll a, ll b)
{
	ll c = a % b;
	while (c != 0)
	{
		a = b;
		b = c;
		c = a % b;
	}
	return b;
}
long long extGCD(long long a, long long b, long long &x, long long &y)
{
	if (b == 0)
	{
		x = 1;
		y = 0;
		return a;
	}
	long long d = extGCD(b, a % b, y, x);
	y -= a / b * x;
	return d;
}

struct UnionFind
{
	vector<ll> data;

	UnionFind(int sz)
	{
		data.assign(sz, -1);
	}

	bool unite(int x, int y)
	{
		x = find(x), y = find(y);
		if (x == y)
			return (false);
		if (data[x] > data[y])
			swap(x, y);
		data[x] += data[y];
		data[y] = x;
		return (true);
	}

	int find(int k)
	{
		if (data[k] < 0)
			return (k);
		return (data[k] = find(data[k]));
	}

	ll size(int k)
	{
		return (-data[find(k)]);
	}
};

ll M = 1000000007;

vector<ll> fac(2000011);  //n!(mod M)
vector<ll> ifac(2000011); //k!^{M-2} (mod M)

ll mpow(ll x, ll n)
{
	ll ans = 1;
	while (n != 0)
	{
		if (n & 1)
			ans = ans * x % M;
		x = x * x % M;
		n = n >> 1;
	}
	return ans;
}
ll mpow2(ll x, ll n, ll mod)
{
	ll ans = 1;
	while (n != 0)
	{
		if (n & 1)
			ans = ans * x % mod;
		x = x * x % mod;
		n = n >> 1;
	}
	return ans;
}
void setcomb()
{
	fac[0] = 1;
	ifac[0] = 1;
	for (ll i = 0; i < 2000010; i++)
	{
		fac[i + 1] = fac[i] * (i + 1) % M; // n!(mod M)
	}
	ifac[2000010] = mpow(fac[2000010], M - 2);
	for (ll i = 2000010; i > 0; i--)
	{
		ifac[i - 1] = ifac[i] * i % M;
	}
}
ll comb(ll a, ll b)
{
	if (a == 0 && b == 0)
		return 1;
	if (a < b || a < 0)
		return 0;
	ll tmp = ifac[a - b] * ifac[b] % M;
	return tmp * fac[a] % M;
}
ll perm(ll a, ll b)
{
	if (a == 0 && b == 0)
		return 1;
	if (a < b || a < 0)
		return 0;
	return fac[a] * ifac[a - b] % M;
}
long long modinv(long long a)
{
	long long b = M, u = 1, v = 0;
	while (b)
	{
		long long t = a / b;
		a -= t * b;
		swap(a, b);
		u -= t * v;
		swap(u, v);
	}
	u %= M;
	if (u < 0)
		u += M;
	return u;
}
ll modinv2(ll a, ll mod)
{
	ll b = mod, u = 1, v = 0;
	while (b)
	{
		ll t = a / b;
		a -= t * b;
		swap(a, b);
		u -= t * v;
		swap(u, v);
	}
	u %= mod;
	if (u < 0)
		u += mod;
	return u;
}

template <int mod>
struct ModInt
{
	int x;

	ModInt() : x(0) {}

	ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}

	ModInt &operator+=(const ModInt &p)
	{
		if ((x += p.x) >= mod)
			x -= mod;
		return *this;
	}

	ModInt &operator-=(const ModInt &p)
	{
		if ((x += mod - p.x) >= mod)
			x -= mod;
		return *this;
	}

	ModInt &operator*=(const ModInt &p)
	{
		x = (int)(1LL * x * p.x % mod);
		return *this;
	}

	ModInt &operator/=(const ModInt &p)
	{
		*this *= p.inverse();
		return *this;
	}

	ModInt operator-() const { return ModInt(-x); }

	ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }

	ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }

	ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }

	ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }

	bool operator==(const ModInt &p) const { return x == p.x; }

	bool operator!=(const ModInt &p) const { return x != p.x; }

	ModInt inverse() const
	{
		int a = x, b = mod, u = 1, v = 0, t;
		while (b > 0)
		{
			t = a / b;
			swap(a -= t * b, b);
			swap(u -= t * v, v);
		}
		return ModInt(u);
	}

	ModInt pow(int64_t n) const
	{
		ModInt ret(1), mul(x);
		while (n > 0)
		{
			if (n & 1)
				ret *= mul;
			mul *= mul;
			n >>= 1;
		}
		return ret;
	}

	friend ostream &operator<<(ostream &os, const ModInt &p)
	{
		return os << p.x;
	}

	friend istream &operator>>(istream &is, ModInt &a)
	{
		int64_t t;
		is >> t;
		a = ModInt<mod>(t);
		return (is);
	}

	static int get_mod() { return mod; }
};

using mint = ModInt<mod>;

vector<vector<ll>> mul(vector<vector<ll>> a, vector<vector<ll>> b, int n)
{
	int i, j, k, t;
	vector<vector<ll>> c(n);
	for (i = 0; i < n; i++)
	{
		for (j = 0; j < n; j++)
		{
			t = 0;
			for (k = 0; k < n; k++)
				t = (t + a[i][k] * b[k][j] % M) % M;
			c[i].push_back(t);
		}
	}
	return c;
}

template <typename Monoid>
struct SegmentTree
{
	using F = function<Monoid(Monoid, Monoid)>;

	int sz;
	vector<Monoid> seg;

	const F f;
	const Monoid M1;

	SegmentTree(int n, const F f, const Monoid &M1) : f(f), M1(M1)
	{
		sz = 1;
		while (sz < n)
			sz <<= 1;
		seg.assign(2 * sz, M1);
	}

	void set(int k, const Monoid &x)
	{
		seg[k + sz] = x;
	}

	void build()
	{
		for (int k = sz - 1; k > 0; k--)
		{
			seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
		}
	}

	void update(int k, const Monoid &x)
	{
		k += sz;
		seg[k] = x;
		while (k >>= 1)
		{
			seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
		}
	}

	Monoid query(int a, int b)
	{
		Monoid L = M1, R = M1;
		for (a += sz, b += sz; a < b; a >>= 1, b >>= 1)
		{
			if (a & 1)
				L = f(L, seg[a++]);
			if (b & 1)
				R = f(seg[--b], R);
		}
		return f(L, R);
	}

	Monoid operator[](const int &k) const
	{
		return seg[k + sz];
	}

	template <typename C>
	int find_subtree(int a, const C &check, Monoid &M, bool type)
	{
		while (a < sz)
		{
			Monoid nxt = type ? f(seg[2 * a + type], M) : f(M, seg[2 * a + type]);
			if (check(nxt))
				a = 2 * a + type;
			else
				M = nxt, a = 2 * a + 1 - type;
		}
		return a - sz;
	}

	template <typename C>
	int find_first(int a, const C &check)
	{
		Monoid L = M1;
		if (a <= 0)
		{
			if (check(f(L, seg[1])))
				return find_subtree(1, check, L, false);
			return -1;
		}
		int b = sz;
		for (a += sz, b += sz; a < b; a >>= 1, b >>= 1)
		{
			if (a & 1)
			{
				Monoid nxt = f(L, seg[a]);
				if (check(nxt))
					return find_subtree(a, check, L, false);
				L = nxt;
				++a;
			}
		}
		return -1;
	}

	template <typename C>
	int find_last(int b, const C &check)
	{
		Monoid R = M1;
		if (b >= sz)
		{
			if (check(f(seg[1], R)))
				return find_subtree(1, check, R, true);
			return -1;
		}
		int a = sz;
		for (b += sz; a < b; a >>= 1, b >>= 1)
		{
			if (b & 1)
			{
				Monoid nxt = f(seg[--b], R);
				if (check(nxt))
					return find_subtree(b, check, R, true);
				R = nxt;
			}
		}
		return -1;
	}
};

template <unsigned mod>
struct RollingHash
{
	vector<unsigned> hashed, power;

	inline unsigned mul(unsigned a, unsigned b) const
	{
		unsigned long long x = (unsigned long long)a * b;
		unsigned xh = (unsigned)(x >> 32), xl = (unsigned)x, d, m;
		asm("divl %4; \n\t"
			: "=a"(d), "=d"(m)
			: "d"(xh), "a"(xl), "r"(mod));
		return m;
	}

	RollingHash(const string &s, unsigned base = 10007)
	{
		int sz = (int)s.size();
		hashed.assign(sz + 1, 0);
		power.assign(sz + 1, 0);
		power[0] = 1;
		for (int i = 0; i < sz; i++)
		{
			power[i + 1] = mul(power[i], base);
			hashed[i + 1] = mul(hashed[i], base) + s[i];
			if (hashed[i + 1] >= mod)
				hashed[i + 1] -= mod;
		}
	}

	unsigned get(int l, int r) const
	{
		unsigned ret = hashed[r] + mod - mul(hashed[l], power[r - l]);
		if (ret >= mod)
			ret -= mod;
		return ret;
	}

	unsigned connect(unsigned h1, int h2, int h2len) const
	{
		unsigned ret = mul(h1, power[h2len]) + h2;
		if (ret >= mod)
			ret -= mod;
		return ret;
	}

	int LCP(const RollingHash<mod> &b, int l1, int r1, int l2, int r2)
	{
		int len = min(r1 - l1, r2 - l2);
		int low = -1, high = len + 1;
		while (high - low > 1)
		{
			int mid = (low + high) / 2;
			if (get(l1, l1 + mid) == b.get(l2, l2 + mid))
				low = mid;
			else
				high = mid;
		}
		return (low);
	}
};

using RH = RollingHash<1000000007>;

template <typename T>
struct edge
{
	int src, to;
	T cost;

	edge(int to, T cost) : src(-1), to(to), cost(cost) {}

	edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}

	edge &operator=(const int &x)
	{
		to = x;
		return *this;
	}

	operator int() const { return to; }
};

template <typename T>
using Edges = vector<edge<T>>;
template <typename T>
using WeightedGraph = vector<Edges<T>>;
using UnWeightedGraph = vector<vector<int>>;
template <typename T>
using Matrix = vector<vector<T>>;

template <typename G>
struct DoublingLowestCommonAncestor
{
	const int LOG;
	vector<int> dep;
	const G &g;
	vector<vector<int>> table;

	DoublingLowestCommonAncestor(const G &g) : g(g), dep(g.size()), LOG(32 - __builtin_clz(g.size()))
	{
		table.assign(LOG, vector<int>(g.size(), -1));
	}

	void dfs(int idx, int par, int d)
	{
		table[0][idx] = par;
		dep[idx] = d;
		for (auto &to : g[idx])
		{
			if (to != par)
				dfs(to, idx, d + 1);
		}
	}

	void build()
	{
		dfs(0, -1, 0);
		for (int k = 0; k + 1 < LOG; k++)
		{
			for (int i = 0; i < table[k].size(); i++)
			{
				if (table[k][i] == -1)
					table[k + 1][i] = -1;
				else
					table[k + 1][i] = table[k][table[k][i]];
			}
		}
	}

	int query(int u, int v)
	{
		if (dep[u] > dep[v])
			swap(u, v);
		for (int i = LOG - 1; i >= 0; i--)
		{
			if (((dep[v] - dep[u]) >> i) & 1)
				v = table[i][v];
		}
		if (u == v)
			return u;
		for (int i = LOG - 1; i >= 0; i--)
		{
			if (table[i][u] != table[i][v])
			{
				u = table[i][u];
				v = table[i][v];
			}
		}
		return table[0][u];
	}
};

int main()
{
	int n, i, j;
	string s,t;
	cin >> n >> s >> t;
	int ans = 2 * n;
	for (i = 0; i < n;i++){
		int flag = 1;
		for (j = i; j < n;j++)
			if(s[j]!=t[j-i])
				flag = 0;
		if(flag){
			ans = n + i;
			break;
		}
	}
	cout << ans << endl;
}

Submission status: Runtime Error

Solution code:
N = int(input())
s = input()
t = input()

if s[N-3] == t[0]:
  print(len(s[:N-3] + t))
elif s == t:
  print(len(s))
else:
  print(len(s + t))

Submission status: Runtime Error

Solution code:
N = int(input())
s = input()
t = input()

if s[N-1] == t[0]:
  if s[N-2] == t[1]:
    print(len(s[:N-2] + t))
    exit()
  print(len(s[:N-1] + t))
elif s == t:
  print(len(s))
else:
  print(len(s + t))

Submission status: Runtime Error

Solution code:
n=int(input())
s=input()
t=input()
while True:
  if s==t:
    break
  s=s[1:]
  t=[:-1]
  n+=1
print(n)

Submission status: Runtime Error

Solution code:
n = int(input())
s = input()
t = input()

for i in range(n):
    if s[i:] == t[:n-i]:
        print(n + cnt)
        exit()
else:
    print(n*2)

Submission status: Runtime Error

Solution code:
n = int(input())
s = input()
t = input()
answer = n
for i in range (n + 1) :
  if answer == n :
    newstring = s[0:i] + t[:n]
  	if newstring[0:n] == s :
    	answer += i
print (answer)

Submission status: Runtime Error

Solution code:
n = int(input())
s = input()
t = input()
answer = n
for i in range (n + 1) :
  if answer == n :
  	newstring = s[0:i] + t[:n]
  	if newstring[0:n] == s :
    	answer += i
print (answer)

Submission status: Runtime Error

Solution code:
s = input()
t = input()
s1 = []
t1 = []
for i in range(0 , n):
  s1.append(s[i])
for i in range(0 , n):
  t1.append(t[i])
a = set(s1 + t1)
print(len(a))

Submission status: Runtime Error

Solution code:
import sys
import copy
import math
import bisect
import pprint
import bisect
from functools import reduce
from copy import deepcopy
from collections import deque
from decimal import *

import numpy as np

import math

if __name__ == '__main__':
    n = int(input())
    s =input()
    t = input()
    count = 2*n

    for i in range(n):
        if t[i] == s[n-i-1]:
            count-=1
        else:
            break
    if s == t:
        print(n)
    else:
        print(count)

Submission status: Runtime Error

Solution code:
N=int(input())
S=input()
T=input()
ans=S+T

while ans[-N:]==T:
    recover=ans
    if ans[N-1]==ans[N]:
        ans=ans[:N]+ans[N+1:]
    else:
        recover=ans
        break

if S in T:
    print(len(T))
elif T in S:
    print(len(S))
else:
    print(len(recover))

Submission status: Runtime Error

Solution code:
n = int(input())
s = input()
t = input()
for i in range(n):
  cnt = 0
  for j in range(i, n):
    if s[j] != t[j-i]:
      break
    cnt += 1
  if cnt == n-i:
    ans = n+i
    break
print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
s = input()
t = input()
for i in range(n):
  if s[i:] == t[:n-i]:
    ans = n + i
    break
print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
s = input()
t = input()

if s == t:
    print(n)
    return

r = 0
for i in range(0, n):
    if s[-(i + 1)] != t[i]:
        break
    r += 1

print((n * 2) - r)

Submission status: Runtime Error

Solution code:
# from math import factorial,sqrt,ceil,gcd
# from itertools import permutations as permus
# from collections import deque,Counter
# import re
# from functools import lru_cache # 簡単メモ化 @lru_cache(maxsize=1000)
# from decimal import Decimal, getcontext
# # getcontext().prec = 1000
# # eps = Decimal(10) ** (-100)

# import numpy as np
# import networkx as nx
# from scipy.sparse.csgraph import shortest_path, dijkstra, floyd_warshall, bellman_ford, johnson
# from scipy.sparse import csr_matrix
# from scipy.special import comb

# slist = "abcdefghijklmnopqrstuvwxyz"
N = int(input())
S = input()
T = input()
ans = 2*N
for i in range(N,-1,-1):
    # ST = S[:i] + T
    print(ST,ST[:i],ST[i:])
    if ST[:N]==S and ST[-N:]==T:
        ans = min(len(ST),ans)

print(ans)
# print(*ans)   # unpackして出力。間にスペースが入る
# for row in board:
#     print(*row,sep="")    #unpackして間にスペース入れずに出力する
# print("{:.10f}".format(ans))
# print("{:0=10d}".format(ans))

Submission status: Runtime Error

Solution code:
import sys
n = int(input())
s = input()
t = input()

for i in range(n):
   if s[i:] == t[:n-i]:
		print(n+i)
		exit()

print(2*n)