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:
from sys import stdin
N = int(stdin.readline().rstrip())
s = (stdin.readline().rstrip())
t = (stdin.readline().rstrip())
ans = len(s)
for i in range(N,0,-1):
    if list(s)[N-i:] == list(t)[:i]:
        break
    else:
        ans += 1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

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:
import sys
N = int(input())
s = str(input())
t = str(input())

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
string_len = int(input())
prefix = input()
suffix = input()
x = 0
for i in range(1,string_len + 1):
    if prefix[-i:] == suffix[:i]:
        x = i
print((2 * string_len) - x)

Submission status: Accepted

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

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

print(len(ans))

Submission status: Accepted

Solution code:
N = int(input())
S = input()
T = input()
cnt = 0
for i in range(N,0,-1):
    if S[-i:]==T[:i]:
        cnt = i
        break
print(len(S)+len(T)-cnt)

Submission status: Accepted

Solution code:
n = int(input())
a = str(input())
b = str(input())
ans = 0
for i in range(n):
    if a[i] == b[0]:
        if a[i:]==b[:(n-i)]:
            ans = len(a[i:])
            break
    if i == n-1 and a[i] == b[0]:
        ans = 1
print(2*n - ans)

Submission status: Accepted

Solution code:
from sys import stdin

n = int(stdin.readline().rstrip())
s = stdin.readline().rstrip()
t = stdin.readline().rstrip()
# A, B, C = [int(x) for x in stdin.readline().rstrip().split()]
# data = [stdin.readline().rstrip().split() for _ in range(n)]

ans = 2 * n
for i in range(n, 0, -1):
    if s[n-i:] == t[:i]:
        ans -= i
        break
print(ans, '\n')
# print(*data, sep='\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(2*n-(n-i))
        exit()
print(2*n)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
A - Prefix and Suffix
https://atcoder.jp/contests/agc006/tasks/agc006_a

"""
import sys


def solve(N, s, t):
    for i in range(N, 0, -1):
        if s[-i:] == t[:i]:
            return N*2 - i
    return N*2


def main(args):
    N = int(input())
    s = input()
    t = input()
    ans = solve(N, s, t)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])

Submission status: Accepted

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

Submission status: Accepted

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

n = N
while 0 <= n:
    a = s[-(n+1):]
    b = t[0:n+1]
    if a == b:
        print(len(s+t[n+1:]))
        exit()
    n -= 1

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

Submission status: Accepted

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

Submission status: Accepted

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

l = N  # 答えの候補
while True:
    # s,tの長さNなので，重複の長さは2N-l
    k = 2*N-l
    if k <= 0 or s[-k:] == t[:k]: break
    l += 1
print(l)

Submission status: Accepted

Solution code:
N=int(input())
s1=input()
s2=input()
l1=len(s1)
l2=len(s2)
ans=2*N

for i in range(l1):
    if s1[i:] == s2[:N-i] and ans > N+i:
        ans = N+i
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(S[:i] + T)
		print(len(S[:i] + T))
		break
else:
	#print(S + T)
	print(len(S + T))

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
def solve():
    N = int(input())
    S, T = [input() for _ in range(2)]

    for i in range(N):
        if S[i:] == T[:N - i]:
            return (N + i)

    return 2 * N

print(solve())

Submission status: Accepted

Solution code:
def solve():
    N = int(input())
    S, T = [input() for _ in range(2)]

    i = 0
    while i < N:
        if S[i:] == T[:N - i]:
            break
        i += 1
    return (N + i)

print(solve())

Submission status: Accepted

Solution code:
N = int(input())
S, T = [input() for _ in range(2)]

for i in range(N):
    if S[i:] == T[:N - i]:
        print(N + i)
        quit()
print(2 * N)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
s=input()
t=input()
ans=0
for i in range(1,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()
for i in range(N):
    if s[i:] == t[:N-i]:
        print(N*2-(N-i))
        break
else:
    print(N*2)

Submission status: Accepted

Solution code:
N = int(input())
s = input()
t = input()
start = max(0, len(s)-len(t))
def solve():
    for i in range(start,len(s)):
        for j in range(len(t)):
            if i+j >= len(s):
                return 2*N-(len(s)-i)
            if s[i+j] != t[j]:
                break
        else:
            return 2*N-(len(s)-i)
    return 2*N
print(solve())

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

Submission status: Accepted

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

def ok(n):
  for i in range(N - n):
    if s[i+n] != t[i]: return False
  return True

for i in range(N):
  if ok(i):
    print(2 * i + N - i)
    break
else: print(2 * N)

Submission status: Accepted

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

Submission status: Accepted

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

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

print(2*N-c)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

for i in range(n):
    match = True
    for j in range(n):
        if i + j < n:
            if s[i + j] != t[j]:
                match = False
    if match:
        if i == 0:
            print(n)
        else:
            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):
    if s[i:n] == t[0:n-i]:
        print(2*n - (n-i))
        exit()
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:
N = int(input())
s = input()
t = input()

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

if s == t:
    print(n)
    exit()

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

Submission status: Accepted

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

Submission status: Accepted

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

print(2*N-dup)

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(len(s+t[N-i:]))

Submission status: Accepted

Solution code:
n = int(input())
s = input().strip()
t = input().strip()
is_match = False
for i in range(len(s)):
  if s[i:] == t[:n-i]:
    is_match = True
    break
if is_match:
  print(len(s[:i] + t))
else:
  print(len(s + t))

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#AGC006 A
'''
問題
文字列s, tが与えられる
長さN以上で, 先頭N文字がsに一致し, 末尾N文字がtに一致するような文字列として可能なものの最小の長さは？

考察
sとtが完全に等しければ答えはN
sとtが完全に違っていれば答えは2*N
sの最後の文字とtの最初の文字が同じで,sの最後から2番目の文字とtの最初から2番目の文字が違っていれば答えは2*N-1

sの最後の文字とtの最初から2文字目の文字が同じで
sの最後から2番目の文字とtの最初の文字が同じなら
答えは2*N-1

sの最後から1番目の文字とtの最初からi文字目が同じで
sの最後から2番目の文字とtの最初からi-1文字目が同じで
...
sの最後からi番目の文字とtの最初から1文字目が同じなら
答えは2*N-i

Nは1以上100以下
計算量はO(N**2)
最小の文字列の長さを求めたいのでiはNからはじめて1ずつ減らしていき条件が最初に満たされたときのiを答えとする
'''

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

m = 0

for i in range(N,0,-1): #iはN,N-1,...,1で試す
	unity = True
	for j in range(i):
		#print(s[-(j+1)],t[j])
		if s[-(j+1)] == t[i-j-1]:
			continue
		else:
			unity = False
	#print(unity)
	if unity:
		m = i
		break
	
print(str(2*N-m))

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

Submission status: Accepted

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

co = 0

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

Submission status: Accepted

Solution code:
n=int(input())
s=input()
t=input()
ans=""
for i in range(n):
    string=s[i:]
    if string==t[0:len(string)]:
        ans=s[0:i]+string+t[len(string):]
        break
else:
    ans=s+t
print(len(ans))

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N=int(input())
S=list(input())
T=list(input())
#print(S,T)
cnt=0
for i in range(N):
    if S==T:
        print(len(S)+cnt*2)
        exit()
    else:
        del S[0]
        del T[len(T)-1]
        #print(S,T)
        cnt+=1
print(cnt*2)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

print(2*n)

Submission status: Accepted

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

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

Submission status: Accepted

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

count = 0
for i in range(len(s)):
    if t[:i+1] in s[-i-1:]:
        count = i+1
    else:
        pass

print(len(s)+len(t)-count)

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:
n = int(input())
s = input()
t = input()
cnt = 0
mx = max(len(s), len(t))
for i in range(1, mx + 1):
    if s[-i:] == t[:i]:
        cnt = max(cnt, i)
print(len(s) + len(t) - cnt)

Submission status: Accepted

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

count = n

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

print(count)

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

print(2*N)

Submission status: Accepted

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

Submission status: Accepted

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

res = 2* N
k = 0
a = 0
for i in range(N):
    flag = True
    tmp = 0
    for j in range(N-i):
        if s[i+j] == t[j] and flag == True:
            tmp += 1
        else:
            flag = False
    a = max(a, tmp)

        
print(res - a)

Submission status: Accepted

Solution code:
# coding:utf-8

import sys

INF = float('inf')
MOD = 10 ** 9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()


def main():
    n = II()
    s, t = SI(), SI()

    for i in range(n + 1)[::-1]:
        if s[n - i:] == t[:i]:
            return 2 * n - i


print(main())

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n=int(input())
A=input()
B=input()
s=0

ans=n
D=[i for i in range(n)][::-1]
for i in D:
  if A[-i-1:]==B[:i+1]:
    
    print(ans)
    exit()
  else:
    ans+=1
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
s = str(input())
t = str(input())
I = []
for i in range(len(s)+1):
    if s[len(s)-i:len(s)] == t[0:i]:
        I.append(i)
s = s[0:len(s)-max(I)]
print(len(s+t))

Submission status: Accepted

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

Submission status: Accepted

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

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:
n = int(input())
s, t = [input() for _ in range(2)]
for i in range(n + 1):
    if s[i:] == t[:n - i]:
        print(n + i)
        exit()

Submission status: Accepted

Solution code:
import os
import math
import itertools
INF, MOD = float("inf"), 1e9 + 7
MAX, MIN = -INF, INF
dx1, dy1, dx2, dy2 = [-1, 0, 1, 0], [0, -1, 0, 1], [-1, 0, 1, -1, 1, -1, 0, 1], [-1, -1, -1, 0, 0, 1, 1, 1]

def get_int():
    return int(input())

def get_int_list():
    return list(map(int, input().split()))

while(True):
    try:
        n = get_int()
        s, t = [input() for _ in range(2)]
        for i in range(n + 1):
            if s[i:] == t[:n - i]:
                print(n + i)
                exit()
    except EOFError:
        exit()

Submission status: Accepted

Solution code:
import os
import math
import itertools
INF, MOD = float("inf"), 1e9 + 7
MAX, MIN = -INF, INF
dx1, dy1, dx2, dy2 = [-1, 0, 1, 0], [0, -1, 0, 1], [-1, 0, 1, -1, 1, -1, 0, 1], [-1, -1, -1, 0, 0, 1, 1, 1]

def get_int():
    return int(input())

def get_int_list():
    return list(map(int, input().split()))

while(True):
    try:
        n = get_int()
        s, t = [input() for _ in range(2)]
        for i in range(len(s)):
            if s[i:] == t[:len(s) - i]:
                print(len(s) + i)
                exit()
        print(len(s + t))
    except EOFError:
        exit()

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n = int(input())
s = input()
t = input()
tmp = 0
for i in range(n):
    # print(s[-i:], t[:len(t) if (i == 0) else i])
    if s[-i:] == t[:n if (i == 0) else i]:
        if i == 0:
            i += n
        tmp = max(tmp, i)
print(len(s) + len(t) - tmp)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
N = int(input())
s = input()
t = input()

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
N = int(input())
s = input()
t = input()

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

Submission status: Accepted

Solution code:
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**7) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

n = ni()
s = ns()
t = ns()
match = 0

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

print(len(s)+len(t)-match)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

N = int(input())
s = input()
t = input()
s = s[:-1]
t = t[:-1]

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

Submission status: Accepted

Solution code:
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

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

Submission status: Accepted

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

Submission status: Accepted

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

import sys, re
from collections import deque, defaultdict, Counter
from math import sqrt, hypot, factorial, pi, sin, cos, radians
if sys.version_info.minor >= 5: from math import gcd
else: from fractions import gcd 
from heapq import heappop, heappush, heapify, heappushpop
from bisect import bisect_left, bisect_right
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from functools import reduce, partial
from fractions import Fraction
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def ceil(a, b=1): return int(-(-a // b))
def round(x): return int((x*2+1) // 2)
def fermat(x, y, MOD): return x * pow(y, MOD-2, MOD) % MOD
def lcm(x, y): return (x * y) // gcd(x, y)
def lcm_list(nums): return reduce(lcm, nums, 1)
def gcd_list(nums): return reduce(gcd, nums, nums[0])
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N = INT()
s = input()
t = input()

mx = 0
for i in range(1, N+1):
    # sの後ろとtの前が一致する最大文字数を出す
    if s[-i:] == t[:i]:
        mx = i
# その分は重複させられるので引く
print(len(s)+len(t)-mx)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def a():return input()#s
def ai():return int(input())#a,n or k
def ma():return map(int, input().split())#a,b,c,d or n,k
def ms():return map(str, input().split())#,a,b,c,d
def lma():return list(map(int, input().split()))#x or y
def lms():return list(map(str, input().split()))#x or y
k= []
l = []
f = 0
def say(i):return print("Yes" if i == 0 else "No")
def Say(i):return print("YES" if i == 0 else "NO")

n = ai()
a = input()
b = input()
c =a
e = n
for i in range(n):
   # print(b[:n-i],c[i:])
    if b[:n-i] == c[i:]:break
    else:e-=1
print(n*2-e)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
a = input()
b = input()

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())

s = input()
t = input()

c = N

for i in range(N):
    f = 1
    for j in range(N-i):
        if not s[i+j]==t[j]:
            f = -1
    if f>0:
        K = c
        break
    else:
        c = c-1
else:
    K=0

print(2*N-K)

Submission status: Accepted

Solution code:
import re

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

answer=N

for i in range(N):
  if re.match(s[i:],t):
    print(answer+i)
    exit()
print(2*N)

Submission status: Accepted

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

import re

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

idx = 0

for i in range(len(s)-1, -1, -1):
    if re.match(s[i:], t):
        matchOB = s[i:]
        idx = len(matchOB)
        
print(len(s + t[idx:]))

Submission status: Accepted

Solution code:
n = int(input())
a = input()
b = input()
j = n
for i in range(n):
    if a[i:n] == b[0:j]:
        print(n)
        exit()
    else:
        n += 1
        j -= 1
print(len(a)+len(b))

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
import sys
from collections import deque
import copy
import math
def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline


def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [N] = [int(input_raw[0])]
    input_raw = read_func().strip().split()
    s = input_raw[0]
    input_raw = read_func().strip().split()
    t = input_raw[0]

    for i in range(N):
        all_ok = True
        for j in range(N):
            if i + j < N:
                if s[i + j] != t[j]:
                    all_ok = False
                    break
        if all_ok == True:
            break

    if all_ok == True:
        print N + i
    else:
        print N + i + 1


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N = int(input())
s = input()
t = input()
ans = 2*N
for i in range(N):
    if s[i:] == t[:N-i]:
        ans -= N - i
        break
print(ans)
#コピペです。

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# coding: utf-8
N, s, t = int(input()), input(), input()

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

Submission status: Accepted

Solution code:
# coding: utf-8
N, s, t = int(input()), input(), input()

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

Submission status: Accepted

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


def main():
    """Function."""
    n = int(input())
    s = str(input())
    t = str(input())

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

    print(len(s) + len(t) - counter)


if __name__ == "__main__":
    main()

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