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())
s = input()
t = input()

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

ans = ''
for i in range(n):
  ss = s[n-i-1:]
  tt = t[:i+1]
  if ss == tt:
    ans = s[:n-i-1]+ss+t[i+1:]
if len(ans) == 0:
  print(len(s+t))
else:
  print(len(ans))

Submission status: Accepted

Solution code:
N = int(input())
s = list(input())
t = list(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 = n * 2
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())
w1 = input()
w2 = input()

def joint(x,y):
    tmp = n
    tmp_x = x
    tmp_y = y
    while tmp_x != tmp_y:
        tmp_x = tmp_x[1:]
        tmp_y =  tmp_y[0:-1]
        tmp -= 1
    joi_x = x[0:n-tmp]
    return(joi_x+y)

print(len(joint(w1,w2)))

Submission status: Accepted

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

Submission status: Accepted

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

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

if w is not None:
    print(len(w))
else:
    print(2 * N)

Submission status: Accepted

Solution code:
n = int(input())
s = input()
t = input()
res = s+t
kekka = n*2
import copy
for i in range(n):
    tmp = list(res)
    del tmp[n]
    target = "".join(tmp)
    if target[:n] == s and target[-n:] == t:
        kekka = len(target)
        #print(target)
    res = copy.deepcopy(tmp)

print(kekka)

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()
for i in range(N):
    if s[i:]==t[:(N-i)]:
        print(N+i)
        exit()
print(N*2)

Submission status: Accepted

Solution code:
n = int(input())
a = input()
b = input()
if len(a) + len(b) < n:
  print(n)
else:
  result = len(a) + len(b)
  for i in range(1, min(len(a), len(b)) + 1):
    if len(a) + len(b) - i >= n and a[-i:] == b[:i]:
      result = min(result, len(a) + len(b) - i)
  print(result)

Submission status: Accepted

Solution code:
n = int(input())
s = list(str(input()))
t = list(str(input()))
p = 0
ans = n * 2

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

print(ans)

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    s = input()
    t = input()
    if s == t:
        print(N)
    else:
        count = 1
        for i in range(1,N):
            tmp = s+t[-i:]
            if s == tmp[:N] and t == tmp[-N:]:
                break
            count += 1
        print(N+count)
if __name__ == '__main__':
    main()

Submission status: Accepted

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

flag = 0

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

if i == 0 and flag == 0:
	print(len(s + t))
else:
	print(len(s[:j] + t))

Submission status: Accepted

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

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 -= len(s[i:])
    break
  
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)
    exit()
print(2*n)

Submission status: Accepted

Solution code:
import re

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

c = 0
for i in range(len(s)):
    if re.match(s[i:], t):
        c = len(s)-i
        break

print(N*2 - c)

Submission status: Accepted

Solution code:
N = int(input())
s = input()
t = input()
lcm = 0
for i in range(N):
    f = False
    c = 0
    idx = 0
    for j in range(i, N):
        if s[j] == t[idx]:
            c += 1
        else:
            break
        idx += 1
    lcm = max(lcm, c)
print(N*2-lcm)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def pin(type=int):
    return map(type,input().split())
#どっかで最悪計算量の入力データを用意する関数を作ろう？
"""
バケットで管理したかったけど数字が多いのでソートして同じ数を固めることに
"""
#solution:
#潜 影 蛇 手 ! !
N=int(input())
S=input()
T=input()
ans=""
for i in range(N):
    #print(i)
    flag=1
    for j in range(N):
        if j+i<N :
            #print(S[j],S[j+i])
            if S[i+j]!=T[j]:
                flag=0
                break
    if flag==1:
            #p#Zrint(i)
        ans+=S[0:i]+T
        break
a=len(ans) if len(ans)!=0 else 2*N
print(a)
#print(["NO","YES"][1-cond])
#print([["NA","YYMM"],["MMYY","AMBIGUOUS"]][cMMYY][cYYMM])

Submission status: Accepted

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

cw = 0
c = 1
while len(t) >= c:
    if s[len(s)-c:] == t[:c]:
        cw = c
    c += 1

print(max(n, len(s)+len(t)-cw))

Submission status: Accepted

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

ans = n * 2
chk = False

for i in range(n):
    j = 0
    while i+j < n:
        if s[i+j] == t[j]:
            ans -= 1
            j += 1
            chk = True
        else:
            ans = n * 2
            chk = False
            break
    if chk:
        break

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def solve(n, s, t):
    count = 0
    for i in range(n):
        if s[i:] == t[:n - i]:
            return 2 * n - (n - i)
    return 2 * n

_n = int(input())
_s = input()
_t = input()
print(solve(_n, _s, _t))

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

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

print(len(ans) if s != t else N)

Submission status: Accepted

Solution code:
N = int(input())
s = input()
t = input()
sr = s[::-1]
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 = str(input())
t = str(input())

for i in range(n):
  s_ = s[i:]
  t_ = t[:n-i]
  if s_ == t_:
    print(n+i)
    exit()
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*2 - (n-i))
        exit(0)
print(2*n)

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

N = int(readline())
s, t = read().decode().split()

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

print(ans)

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

N = int(readline())
s, t = read().decode().split()

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

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

print(2*n)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys
#input = sys.stdin.buffer.readline

def main():
    N = int(input())
    s = str(input())
    t = str(input())
    
    for i in range(N):
        if s[i] == t[0]:
            if s[i:] == t[:(N-i)]:
                print(len(s[:i]+s[i:]+t[(N-i):]))
                exit()
                
    print(len(s+t))

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
# sの末尾x文字とtの先頭x文字ぶんかぶってるかどうかチェック
n = int(input())
s, t = input(), input()
a = -1
for i in range(n):
    if s[-i - 1 :] == t[: i + 1]:
        a = i
print(len(s) + len(t[a + 1 :]))

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

stdin = sys.stdin

mod = 1000000007

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()
nas = lambda: stdin.readline().split()

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

ans = n * 2

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

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

Submission status: Accepted

Solution code:
N=int(input())
a=input()
b=input()
ans = N
for i in range(N):
    if a[i:] == b[:N-i]:
        break
    else:
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
from sys import stdin
n = int(stdin.readline().rstrip())
s = stdin.readline().rstrip()
t = stdin.readline().rstrip()
kaburi = 0
for i in range(n):
    if s[n-i-1:] == t[:i+1]:
        kaburi = max(i+1,kaburi)
print(n*2-kaburi)

Submission status: Accepted

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

for zurasu in range(0, n+1):
    if s[zurasu:] == t[:n-zurasu]:
        print(n+zurasu)
        exit(0)

Submission status: Accepted

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

ans = 2*n

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
from fractions import Fraction
N=int(input())
S=list(input())
T=list(input())

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

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

	#N,A,B = map(int,input().split())
	
	for i in range(N):
		if S[i:]==T[:N-i]:
			res = N+i
			break
	else:
		res = 2*N
	
	print(res)
	
main()

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def LS(): return list(map(list, input().split()))
def S(): return list(input().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = 1e10

#solve
def solve():
    n = II()
    s = S()
    t = S()
    for i in range(n):
        if s[i:] == t[: n - i]:
            print(n + i)
            return
    print(2 * n)
    return


#main
if __name__ == '__main__':
    solve()

Submission status: Accepted

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

Submission status: Accepted

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

l = 0
c = 0
for i in range(1, N+1):
    if s[-1 * i:] == t[:i]:
        l = len(t[:i])
        c = i

print(len(s + t[c:]))

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[0:N-i]:
    ans=N+i
    break
  else:
    pass

print(ans)

Submission status: Accepted

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

st = s+t
total_len = len(st)
dupl = 0
for n in range(N+1):
    if st[N-n:N] == st[N:N+n]:
        dupl = len(s[N-n:N])

total_len = total_len - dupl

print(total_len)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
readline = sys.stdin.readline

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

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:
def examA():
    N = I()
    S = SI(); T = SI()
    ans = 2*N
    for l in range(N-1,-1,-1):
        flag = True
        for i in range(l+1):
            if S[N-1-i] != T[l-i]:
                flag = False
                break
        if flag:
            ans -=(l+1)
            break
    print(ans)
    return

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

if __name__ == '__main__':
    examA()

Submission status: Accepted

Solution code:
# coding:utf-8
N = int(input())
S = input()
T = input()
ans = 0
for n in range(1,N+1):
    #print (S[-n:],T[:n])
    if (S[-n:]==T[:n]):
        ans = n
print (2*N-ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N = int(readline())
S = readline().rstrip()
T = readline().rstrip()

longest_overlap = 0
for n in range(1,N+1):
    if S[-n:] == T[:n]:
        longest_overlap = n

answer = N + N - longest_overlap
print(answer)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
s=input()
t=input()
i=0
while(i<len(t)):
	if(t[:i+1] in s):
		i+=1
	else:
		break
print(len(s+t[i:]))

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(n,0-1,-1):
  hoge=s+t[i:n]
  #print(hoge)
  if (hoge[-n:]==t):
    ans=len(hoge);
    print(ans)
    exit()

Submission status: Accepted

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

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

print(ans - min_i)

Submission status: Accepted

Solution code:
import sys
import os
if sys.platform=="darwin":
   base = os.path.dirname(os.path.abspath(__file__))
   name = os.path.normpath(os.path.join(base, '../Documents/input.txt'))
   #print(name)
   sys.stdin = open(name)

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

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

print(len(ans))

Submission status: Accepted

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

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

ans=0
for i in range(n):
	if s[i]==t[0]:
		j=0
		while j<n-i:
			if s[i+j]!=t[j]:
				break
			j+=1
		else:
			ans=n-i
			break
print(2*n-ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

ans = len(s) + len(t)
index = 0
tmp = 0
for i in range(len(s)):
    if s[-i - 1] == t[index]:
        index += 1
        for j in range(len(s) - i, len(s)):
            if s[j] == t[index]:
                index += 1
            else:
                break
        tmp = max(tmp, index)
        index = 0


print(ans - tmp)

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 = list(input())
t = list(input())

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

print(n * 2)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10000000)
INF = 1<<32


def solve(N: int, s: str, t: str):
    
    ans = 0
    for i in range(N):
        m = 0
        for j in range(N):
            if i+j < N and s[i+j] == t[j]:
                m += 1
            else:
                break
        ans = max(ans, m)

    print(2*N-ans)   

    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    s = next(tokens)  # type: str
    t = next(tokens)  # type: str
    solve(N, s, t)

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[:len(t)-i]:
        ans -= n - i
        break
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
s = input()
t = input()
cnt = [0]

for i in range(n):
        #print(t[0:n-i])
        #print(s[i:])
        if t[0:n-i] == s[i:]:
            cnt.append(len(s[i:]))
print(2 * n - max(cnt))

Submission status: Accepted

Solution code:
N = int(input())
s = input()
t = input()
w = s+t
cnt = 0
if s == t and N <= len(s):
  print(len(s))
  exit()
elif s == t and N > len(s):
  print(len(s+t))
  exit()
cnt1 = 0
for i in range(len(s)):
  if s[-i-1:] == t[:i+1]:
    cnt = i+1
while len(w) > N and cnt > 0:
  t = t[1:]
  w = s + t
  cnt -= 1
print(len(w))

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
s1 = input()
s2 = input()

for i in range(1,n+1):
    #print(s1[i-1:],s2[:n-i+1])
    if s1[i-1:] == s2[:n-i+1]:
        #print((s1[:(i-1)]+s2))
        print(len(s1[:(i-1)]+s2))
        exit()
print(len(s1+s2))

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n = int(input())
s = list(input())
t = list(input())
count = 0
if s == t:
    print(n)
    exit()
for i in range(n):
    index = 0
    while s[i + index] == t[index]:
        index += 1
        if index + i == n:
            count = max(count, n - i)
            break

print(n * 2 - count)

Submission status: Accepted

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

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(1,n+1):
  tmp=s+t[-1*i:]
  if tmp[-n:] == t:
    print(n+i)
    sys.exit()

Submission status: Accepted

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

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

print(N * 2 - (max_i))

Submission status: Accepted

Solution code:
N = int(input())
s = input()
t = input()
ans = 2*N
i = 0
while i < N:
    if s[i:] in t:
        if t.index(s[i:]) == 0:
            ans -= N-i
        break
    i += 1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,s,t = open(0).read().split()
N = int(N)
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:
# coding: utf-8
def main():
    n = int(input())
    S = input()
    T = input()
    overlap_num = 0
    for i in range(n):
        if S[i:] in T:
            overlap_num = n-i
            break
    print(n*2 - overlap_num)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
mod2 = 998244353
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

n = inp()
s = input()
t = input()
for i in range(n):
    for j in range(n-i):
        if s[i+j] != t[j]:
            break
    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+1):
    if s[i:]==t[:N-i]:
        print(N+i)
        break

Submission status: Accepted

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

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

print(n*2-len(s))

Submission status: Accepted

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

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

print(n*2)

Submission status: Accepted

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

ans = 0

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

print(2*n-ans)

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+T[-i:]).endswith(T):
        print(N+i)
        exit()
print(2*N)

Submission status: Accepted

Solution code:
def solve(n, s, t):
    match = 0
    for i in range(n):
        if s[i] == t[0]:
            for j in range(n+1):
                if i+j >= n:
                    match = j
                    break
                elif s[i+j] != t[j]:
                    match = 0
                    break
            if match > 0:
                break
    print("{}".format(n*2-match))


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


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# AGC 006: A – Prefix and Suffix
n = int(input())
s, t = [input() for _ in range(2)]

if s == t:
    print(len(s))
else:
    number_overlaps = 0

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

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:
import collections
N = int(input())
s = input()
t = input()
ans = list(s)
table = collections.defaultdict(int)
if s == t:
    print(N)
    exit(0)
for i in range(1, N):
    if (s + t[-i:]).endswith(t):

        print(N+i)
        exit(0)
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[0:n-i]:
        print(n+i)
        exit()
print(2*n)

Submission status: Accepted

Solution code:
def inpl():
    return list(map(int, input().split()))


def Check(S, T):
    for i in range(len(S)):
        if S[i] != T[i]:
            return False
    return True


N = int(input())
S = input()
T = input()

for i in range(N):
    if Check(S[i:], T) is True:
        print(N + i)
        break
else:
    print(2 * N)

Submission status: Accepted

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

Submission status: Accepted

Solution code:

ans = 0

N = int(input())

s = input()
t = input()

now = N
ans = 0

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

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

Submission status: Accepted

Solution code:
from sys import exit, stdin
N = int(stdin.readline().rstrip())
s = stdin.readline().rstrip()
t = stdin.readline().rstrip()
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()
if s==t:
    print(len(s))
    exit()
ans=s

for i in range(0,n):
    if s[i]==t[0]:
        flag=True
        for j in range(0,n-i):
            if not s[i+j]==t[0+j]:
                flag=False
        if flag:
            tmp=n-i
            ans+=t[tmp:]
            print(len(ans))
            exit()
g=True
if g:
    print(len(s+t))

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

Submission status: Accepted

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

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

Submission status: Accepted

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

N = int(input().split()[0])
s = input()
t = input()

for i in range(N):
    if s[i] == t[0]:
        is_ok = True
        for j in range(N - i):
            if s[j + i] != t[j]:
                is_ok = False
                break
        if is_ok:
            start_idx = i
            break
    else:
        is_ok = False

if is_ok:
    l = N + start_idx
else:
    l = N * 2

ans = l
print(ans)

Submission status: Accepted

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