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:
N = int(input())
Ss = input()
Ts = input()

for k in reversed(range(1, N + 1)):
    if Ss[-k:] == Ts[:k]:
        print(2 * N - k)
        break
else:
    print(2 * N)

Submission status: Accepted

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

cnt = 0
for i in range(N):
    if s[i]==t[0]:
        for j in range(N):
            if s[i+j]!=t[j]:
                break
            if i+j>=N-1:
                cnt = max(cnt, j+1)
                break
ans = N+N-cnt
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

length = 2 * n
for i in range(len(s)):
    if s[i:len(s)] == t[0:len(s) - i]:
        length = min(length, i + n)
        # print("length:{}".format(i + n))
print(length)

Submission status: Accepted

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

Submission status: Accepted

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

res = 0
for i in range(n):
    r = 0
    c = 0
    for j in range(n-i):
        if s[i+j] == t[j] and c == 0:
            r += 1
        else:
            c = 1
    if r == n-i:
        res = n+i
        break

if res == 0:
    res = 2*n
print(res)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
try: from typing import Any, Union, List, Tuple, Dict
except ImportError: pass
sys.setrecursionlimit(10**6)
def debug(*args): print(*args, file=sys.stderr)
def exit(): sys.exit(0)


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


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

print(2*N-a)

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)
        exit()
print(2*n)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
s = input()
t = input()
for i in range(N+1):
    cat = s[0:i] + t
    if cat[:N] == s:
        print(N + i)
        exit()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys


def main() -> None:
    n = int(next_str())
    s = next_str()
    t = next_str()

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

    print(2 * n - overlap)


def next_str() -> str:
    result = ""
    while True:
        tmp = sys.stdin.read(1)
        if tmp.strip() != "":
            result += tmp
        elif tmp != '\r':
            break
    return result


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys


def main() -> None:
    n = int(next_str())
    s = next_str()
    t = next_str()

    ans = n
    for i in range(n):
        flg = False
        for j in range(n - i):
            if s[i + j] != t[j]:
                ans += 1
                flg = True
                break
        if not flg: break
    print(ans)


def next_str() -> str:
    result = ""
    while True:
        tmp = sys.stdin.read(1)
        if tmp.strip() != "":
            result += tmp
        elif tmp != '\r':
            break
    return result


if __name__ == '__main__':
    main()

Submission status: Accepted

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

S = s + t
r = len(S)
for i in range(N):
    ti = t[:(N-i)]
    index = s.find(ti)
    if index > -1:
        print(len(s)+len(t) - (len(s)-index))
        exit()
print(r)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())

s = input()
t = input()
ans = n
flag = 1
for i in range(n):
    f = 1
    for j in range(n-i):
        if s[i+j] != t[j]:
            f = 0
            break
    if f == 1:
        ans += i
        flag = 0
        break
        
if flag == 1:
    ans += n
print(ans)

Submission status: Accepted

Solution code:
N=input();s=input();t=input()
for i in range(len(t),-1,-1):
    a = s + t[i:]
    if s in a and t in a:
        print(len(a))
        exit()

Submission status: Accepted

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

x = 0

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

print(N + x)

Submission status: Accepted

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

for i in range(N):
  j = 0
  fl = True
  while j+i < N:
    if S[i+j] == T[j]:
      j += 1
      #print(i,j)
    else:
      fl = False
      break
      
  if(fl):
    print(N+i)
    exit(0)
    
print(2*N)

Submission status: Accepted

Solution code:
N = int(input())
S = list(input())
T = list(input())
counter = 0
for i in range(N) :
    if S == T :
        print(N+counter)
        break
    else :
        S.pop(0)
        T.pop(-1)
        counter += 1
        if len(S) == 0 :
            print(2*N)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n = int(input())
listS = list(input())
listT = list(input())

if listS == listT:
    print(len(listS))

else:
    count = len(listS)+ len(listT)
    index1 = 0
    while index1 < len(listS):
        if listS[index1] == listT[0]:
            index2 = 0
            while index2 < len(listS)-index1:
                if listS[index1+index2] == listT[index2]:
                    index2+=1
                else:
                    break
            if index2 == len(listS)-index1:
                count-=(len(listS)-index1)
                print(count)
                break
            else:
                index1+=1
        else:
            index1+=1
    if index1 == len(listS):
        print(count)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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)
        exit()

Submission status: Accepted

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

cnt = 0
ans = s + t
for i in range(N):
    if s[i:] == t[:N-i]:
        ans = s + t[N-i:]
        break
print(len(ans))

Submission status: Accepted

Solution code:
N = int(input())
s = input().strip()
t = input().strip()
 
i = N
while True:
    u = t[i:]
    ans = s+u
    if ans[-N:] == t:
        print(len(ans))
        break
    i -= 1

Submission status: Accepted

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


nomatch = False
place = 0
for i in range(N):
    place = i
    if t[0] == s[i]:      
        match = True
        for j in range(N-i):
            if t[j] != s[i+j]:
                match = False
        if match:
            break
        else:
            continue
    elif i == N-1:
        nomatch = True

if nomatch:
    print(2*N)
else:
    print(N+place)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
s = input()
t = 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, t = input(), input()
cnt = 0
for i in range(N, -1, -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()

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 = -1
for i in range(n + 1):
    b = s
    if i > 0:
        b += t[(-1) * i:]
    #print(b)
    if b[(-1) * n:] == t:
        ans = len(b)
        break
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

sl = list(s)
tl = list(t)

ans = s + t
for i in range(n):

    if s[i:] == t[:n-i]:     
        sp = s[:i]
        common = s[i:]
        tp = t[n-i:]
        ans = sp + common + tp
        
        break

        
print(len(ans))

Submission status: Accepted

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

def solve():
    for i in range(n):
        if s[i:] == t[:n-i]:
            return len(s+t[n-i:])
    return len(s+t)

print(solve())

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N=int(input())
a=input()
b=input()
d=0
for i in range(1,N+1):
    at=a[-i:]
    bt=b[:i]
    if(at==bt):
        d=i
print(2*N-d)

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:
N = int(input())
S = input()
T = input()

r = N
while 1:
    s, t = S[N - r:], T[:r]
    # print(s, t)
    if s == t:
        break
    r -= 1

result = N * 2 - r
print(result)

Submission status: Accepted

Solution code:
'''
最短でans == s == t
最長でans == (s + t)
'''
n = int(input())
s = input()
t = input()

ans = s
i = 0
while True:
    if ans[(-1) * n:] == t:
        break
    else:
        ans = s + t[(-1) * (i+1):]
        i += 1
        if i == n:
            break
print(len(ans))

Submission status: Accepted

Solution code:
from sys import exit, setrecursionlimit, stderr
from functools import reduce
from itertools import *
from collections import defaultdict
from bisect import bisect
from random import *

def read():
  return int(input())
 
def reads():
  return [int(x) for x in input().split()]

N = read()
s = input()
t = input()

print(2 * N - max(k for k in range(N+1) if s[N-k:] == t[:k]))

Submission status: Accepted

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

res = s+t
for num in reversed(range(n)):
    tmp = s[:num]+t
    if tmp[:n] == s and tmp[-n:] == t:
        res = tmp
print(len(res))

Submission status: Accepted

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

Submission status: Accepted

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

ans = []
for i in range(n):
	if s[-(i + 1):] == t[:i + 1]:
		ans.append(i + 1)

if ans == []:
	print(2 * n)
else:
	print(2 * n - max(ans))

Submission status: Accepted

Solution code:
n = int(input())
S1 = input().rstrip()
S2 = input().rstrip()
for i in range(n,-1,-1):
    if S1[n-i:] == S2[:i]:
        print(len(S1+S2[i:]))
        break

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    n, s, t = int(input()), input(), input()
    
    for i in range(n):
        if s[i:] == t[0:n-i]:
            print(n+i)
            break
    else:
        print(2*n)
        
        
if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

# AtCoder Grand Contest
# Problem A


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

    # See:
    # https://www.youtube.com/watch?v=VX8cGy7kNTE
    for l in range(n, 2 * n + 1):
        s_end = s[-(2 * n - l):]
        t_start = t[:2 * n - l]

        if s_end == t_start:
            print(len(s) + len(t) - len(s_end))
            exit()

    print(len(s) + len(t))

Submission status: Accepted

Solution code:
n = int(raw_input())
a = raw_input()
b = raw_input()
cur = n*2

for i in range(1, n+1):
    if (a[-i:] == b[:i]):
        cur = n*2-i

print(cur)

Submission status: Accepted

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

ans=2*N
for i in range(N):
  if s[i:N]==t[:N-i]:
    ans=2*N-(N-i)
    break
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
S = input().strip()
T = input().strip()

for j in range(N):
  if S[j:] == T[:N-j]:
    print(N + j)
    break
else:
  print(2 * N)

Submission status: Accepted

Solution code:
def sarch(n, S, T, i):
    if S[n - i:] == T[0:i]:
        i
    else:
        i = sarch(n, S, T, i - 1)
    return i

N = int(input())
s = input()
t = input()
print(N * 2 - sarch(N, s, t, N))

Submission status: Accepted

Solution code:
N = int(input())
s = input()
t = input()
ans = 2*N

for k in range(N):
    if s[N-k-1:]==t[:k+1]:
        ans = 2*N-k-1

print(ans)

Submission status: Accepted

Solution code:
n=int(input())
s=list(input().strip())
t=list(input().strip())
ans=0

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

print(n*2-ans)

Submission status: Accepted

Solution code:
n=int(input())
s=list(input())
t=list(input())
t.reverse()
ans=float("inf")
if s==t:
    print(n)
    exit()
else:
    for i in range(n):
        a=t[i:]
        a.reverse()
        if s[i:]==a:
            ans=i
    if ans==float("inf"):
        print(2*n)
        exit()
    del s[ans:]
    print(len(s+t))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

import sys, math, copy
# import fractions, itertools
# import numpy as np
# import scipy

HUGE = 2147483647
HUGEL = 9223372036854775807
ABC = "abcdefghijklmnopqrstuvwxyz"

def main():
    n = int(input())
    s = input()
    t = input()
    max_common = 0
    for i in range(1, n + 1):
        s_tail = s[-i:]
        t_head = t[:i]
        if s_tail == t_head:
            max_common = i
    print(2 * n - max_common)

main()

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# 数値読み込み
n = int(input())
s = input()
t = input()

res=len(s)
while(len(s)>0):
  if s==t:
    break
  else:
    res=res+1
    s=s[1:]
    t=t[:-1]
print(res)

Submission status: Accepted

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

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

Submission status: Accepted

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

print(ans)

Submission status: Accepted

Solution code:
def main():
    """最長: s + t

    abc
      abc

    abc
     abc

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

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

    print(len(ans))


if __name__ == '__main__':
    main()

Submission status: Accepted

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

for i in range(N+1):
    A = s[:i] + t
    if A[:N] == s and A[-N:] == t:
        print(len(A))
        exit()

Submission status: Accepted

Solution code:
import sys


n=int(input())
s=input()
t=input()
test=s+t
if(s==t):
    print(len(s))
    sys.exit()
for i in range(1,n+1)[::-1]:
    test=s[0:-i]+t
    if(test[:n]==s and test[-n:]==t):
        print(len(test))
        sys.exit()
        
print(len(s+t))

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(N):
    if s[i:] == t[:(N-i)]:
        print(2*N - (N-i))
        break
else:
    print(2*N)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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(2 * n)

Submission status: Accepted

Solution code:
def minimumLen(s, t):
    n = len(s)
    failed = [-1 for i in xrange(n)]
    pos = -1
    for i in xrange(1, n):
        while pos!=-1 and t[pos+1]!=t[i]:
            pos = failed[pos]
        if t[pos+1]==t[i]:
            pos += 1
        failed[i] = pos
    pos = -1
    for c in s:
        while pos!=-1 and t[pos+1]!=c:
            pos = failed[pos]
        if t[pos+1]==c:
            pos += 1
    return n*2-(pos+1)

def main():
    n = int(raw_input().strip())
    s = raw_input().strip()
    t = raw_input().strip()
    print minimumLen(s, t)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
class KMP:
    pattern = None
    length = -1
    failed = None
    def __init__(self, pattern):
        self.pattern = pattern
        self.length = len(pattern)
        self.failed = [-1 for i in xrange(self.length)]
        for i in xrange(1, self.length):
            prev = self.failed[i-1]
            while prev!=-1 and pattern[prev+1]!=pattern[i]:
                prev = self.failed[prev]
            if pattern[prev+1]==pattern[i]:
                prev += 1
            self.failed[i] = prev

def minimumLen(s, t):
    kmp = KMP(t)
    offset = -1
    for c in s:
        while offset!=-1 and kmp.pattern[offset+1]!=c:
            offset = kmp.failed[offset]
        if kmp.pattern[offset+1]==c:
            offset += 1
    return len(s)+len(t)-(offset+1)

def main():
    n = int(raw_input().strip())
    s = raw_input().strip()
    t = raw_input().strip()
    print minimumLen(s, t)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
N = int(input())
s = input()
t = input()

ans = 2 * N
for i in range(N):
    if s[i:] == t[:N-i]:
        ans = len(s + t[N-i:])
        break

print(ans)

Submission status: Accepted

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

for l in range(N, 2 * N + 1):
    if S[N - 2 * N + l:] == T[:2 * N - l]:
        print(l)
        exit()

Submission status: Accepted

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

k = 0

for i in range(N):
    for j in range(N):
        s = S[i:]
        t = T[:j + 1]
        if s == t:
            k = max(k, len(s))

print(2 * N - k)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-



def main():
    N = int(input())
    S = input()
    T = input()

    len_common = N
    for i in range(N):
        sub = S[i:]
        if T.startswith(sub):
            break
        len_common -= 1

    print(len(S) + len(T) - len_common)

if __name__ == "__main__": main()

Submission status: Accepted

Solution code:
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
INF = float("inf")


def main():
    N = int(input())
    s = input()
    t = input()

    for i in range(N, 0, -1):
        if s[-i:] == t[:i]:
            print(2 * N - i)
            break
    else:
        print(2 * N)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N = int(input())
s = input()
t = input()
if s == t:
    print(len(s))


else:
    ans = N * 2
    for i in range(N):
        a = s[:i] + t
        if a[:N] == s:
            ans = min(ans, len(a))

        a = s + t[i:]
        if a[N:] == t:
            ans = min(ans, len(a))

    print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import itertools
n = int(input())
s = input()
t = input()
for l in itertools.count(n):
    it = (s + 'a' * l)[: l - len(t)] + t
    if len(it) >= n and it.startswith(s) and it.endswith(t):
        break
print(len(it))

Submission status: Accepted

Solution code:
def prefix_and_suffix():
	n = int(raw_input())
	s = str(raw_input())
	t = str(raw_input())
	
	for i in range(n):
		sub_s = s[i:]
		sub_t = t[:n-i]
		if sub_s==sub_t:
			print n+i
			return
	print 2*n

if __name__ == "__main__":
	prefix_and_suffix()

Submission status: Accepted

Solution code:
N = int(input())
prefix = input()
suffix = input()


if len(prefix) + len(suffix) < N:
    d = N - len(prefix) + len(suffix)
    print(len(prefix + 'a' * d + suffix))
else:
    s = ""
    for i in range(1, N):
        # print(prefix[-i:], suffix[:i])
        if prefix[-i:] == suffix[:i]:
            s = prefix[:-i] + suffix
    if suffix == prefix:
        s = suffix
    if len(s) == 0:
        s = prefix + suffix
    print(len(s))

Submission status: Accepted

Solution code:
a,b,c=(input() for _ in range(3))
cnt=0
for i in range(1,int(a)+1):
    if(b[-i:]==c[:i]):cnt=i
print(2*int(a)-cnt)

Submission status: Accepted

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


length = len(s) + len(t)
if (N >= (length)):
  print(N)
  sys.exit()


min_a = t if (len(s) > len(t)) else s
max_b = s if (len(s) > len(t)) else t

cnt = 0
j = 0

for i in range(len(min_a)):
  touch = False
  k = 0
  for j in range(i, len(min_a)):
    #print(j, min_a[j], max_b[k])
    if (min_a[j] == max_b[k]):
      k += 1
      cnt += 1
    else:
      touch = True
      cnt = 0
      break
  if(touch == False):
      break

print(max(length - cnt, N))

Submission status: Accepted

Solution code:
import sys
if __name__ == "__main__":
    N = int(input())
    S = input()
    T = input()
    for i in range(N):
        left = 0
        ok = True
        for j in range(i, N):
            if (S[j] == T[left]):
                left += 1
            else:
                ok = False
        if (ok):
            print (N + i)
            sys.exit()
    print (2 * N)

Submission status: Accepted

Solution code:
# -*- coding:utf-8 -*-
N = int(input())
s = input()
t = input()
index = N
a = -1
for tmp in range(1,len(t)+1):
    if s[index-1:len(s)] == t[0:tmp]:
        a = index-1
    index -= 1
if a == -1:
    print(len(s+t))
else:
    for tmp in range(len(s)-a, len(t)):
        s = s+t[tmp]
    print(len(s))

Submission status: Accepted

Solution code:
import sys
if __name__ == '__main__':
    N = int(input())
    s = input()
    t = input()
    S = []
    for i in range(N+1):
        tmp = s + t[i:]
        S.append(tmp)
    mini = 1000000
    for l in S:
        if l[-N:] == t:
            mini = min(mini,len(l))
    print(mini)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
i=raw_input;N=n=int(i());s,l,j=i(),i(),0;
exec "j=max(n*(s[-n:]==l[:n]),j);n-=1;"*N;
print 2*N-j

Submission status: Accepted

Solution code:
i=input;N=int(i());s=i();l=i();n=N;j=0
exec("j=max(n*(s[-n:]==l[:n]),j);n-=1;"*N);print(2*N-j)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

ans = 2 * N
for i in range(1, N+1):
    # print(s[-i:], t[:i])
    if s[-i:] == t[:i]:
        ans = min(ans, 2 * N - i)
print(ans)

Submission status: Accepted

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

idx = 0
a = []
b = []

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

for i in range(1, n+1):
    for j in range(1, i):
        a += s[n-i+j]
        b += t[j-1]
    if(a == b): idx = i-1
    a = []
    b = []

if(s == t):
    print(n)
else:
    print(n*2-idx)

Submission status: Accepted

Solution code:
n=int(raw_input())
s=raw_input()
t=raw_input()
for i in range(n+1):
# print s[i:],t[:i]
 if s[i:]==t[:n-i]:
  print n+i
  break

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# -*- coding:utf-8 -*-

from __future__ import division, print_function, absolute_import, unicode_literals

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

correspoint_cnt = 0
for i in range(1, len(s)+1):
    # print(s[-i:], t[:i])
    if s[-i:] == t[:i]:
        correspoint_cnt = i
# print(len(s), len(t), correspoint_cnt)
if len(s) + len(t) - correspoint_cnt < N:
    print(N)
else:
    print(len(s) + len(t) - correspoint_cnt)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import itertools
n = int(input())
s = input()
t = input()
for l in itertools.count(n):
    it = (s + 'a' * l)[: l - len(t)] + t
    if len(it) >= n and it.startswith(s) and it.endswith(t):
        break
print(len(it))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def Main():
    n = int(input())
    a = input()
    b = input()
    x = 0
    y = 0
    for i in range(len(a)):
        if a[i] == b[x]:
            x += 1
            y += 1

    print(len(a[0:n - y]) + len(b))

if __name__ == '__main__':
    Main()

Submission status: Accepted

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf = 10**10
mod = 10**9 + 7


def f():
    n = int(input())
    s = input()
    t = input()
    r = len(s)+len(t)
    sl = len(s)
    tl = len(t)
    for i in range(len(s)):
        if i + tl < n:
            continue
        if s[i:] == t[:sl-i]:
            r = i + tl
            break

    return max(r,n)


print(f())

Submission status: Accepted

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

Submission status: Accepted

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