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:
import sys
input = sys.stdin.readline
from collections import *

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

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

print(2*N)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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:
import sys

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline


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

    x = 0
    for i in range(N):
        if S[i:] == T[:N - i]:
            x = N - i
            break

    print(N * 2 - x)


    

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

if s == t:
    print(len(s))
    exit(0)

ind = 0
mx = min(len(s), len(t))
mx_len = 0
while ind < mx:
    pre_i = s[-(ind + 1):]
    suf_i = t[:(ind + 1)]
    if pre_i == suf_i:
        mx_len = ind + 1

    ind += 1

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

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

Submission status: Accepted

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

Submission status: Accepted

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

if s == t:
    print(N)
else:
    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()

if s == t:
    print(n)
else:
    for i in range(0, 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()
overlap=N
for i in range(N):
    if s[i:]==t[:N-i]:
        overlap=i
        break
print(N+overlap)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import collections
import itertools as it
import math
#import numpy as np
 
n = int(input())
s = input()
t = input()
#  = map(int, input().split())
#  = list(map(int, input().split()))
#  = [int(input()) for i in range(N)]
#
# c = collections.Counter()

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

Submission status: Accepted

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

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


ans = S + T
end = N
for i in range(N):
    if S[i:] == T[:end]:
        ans = S + T[end:]
        break

    end -= 1

print(len(ans))

Submission status: Accepted

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

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

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]:
    break
else:
  i += 1
print(2 * i + (N - i))

Submission status: Accepted

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

Submission status: Accepted

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

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

print(N * 2 - cnt)

Submission status: Accepted

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

u = n
for i in range(n):
    if s[i:] == t[:(n-i)]:
        u = i
        break

print(u+n)

Submission status: Accepted

Solution code:
N = int(input())
S = input()
T = input()
kaburi = 0
for i in range(N):
    #sの末尾とtの先頭を比べる
    #print("sの末尾"+str(i+1)+"文字目"+S[-(i+1):])
    #print("Tの先頭"+str(i+1)+"文字目"+T[0:i+1])
    if S[-(i+1):] == T[0:i+1]:
        kaburi = len(S[-(i+1):])
print(2*N-kaburi)

Submission status: Accepted

Solution code:
N = int(input())
S = input()
T = input()
kaburi = 0
for i in range(N):
    #sの末尾とtの先頭を比べる
    #print("sの末尾"+str(i+1)+"文字目"+S[-(i+1):])
    #print("Tの先頭"+str(i+1)+"文字目"+T[0:i+1])
    if S[-(i+1):] == T[0:i+1]:
        kaburi = len(S[-(i+1):])
print(2*N-kaburi)

Submission status: Accepted

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

Submission status: Accepted

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

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

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys
def I(): return int(sys.stdin.readline().rstrip())
def S(): return sys.stdin.readline().rstrip()
N = I()
s,t = S(),S()
ans = 2*N
for i in range(N,0,-1):
    if s[-i:]==t[:i]:
        ans -= i
        break
print(ans)

Submission status: Accepted

Solution code:
import sys
def I(): return int(sys.stdin.readline().rstrip())
def S(): return sys.stdin.readline().rstrip()
N = I()
s,t = S(),S()
ans = 2*N
minus = 0
for i in range(1,N+1):
    if s[-i:]==t[:i]:
        minus = max(minus,i)
print(ans-minus)

Submission status: Accepted

Solution code:
import itertools,sys
def I(): return int(sys.stdin.readline().rstrip())
def S(): return sys.stdin.readline().rstrip()
N = I()
s,t = S(),S()
ans = 2*N
minus = 0
for i in range(1,N+1):
    if s[-i:]==t[:i]:
        minus = max(minus,i)
print(ans-minus)

Submission status: Accepted

Solution code:
import itertools,sys
def I(): return int(sys.stdin.readline().rstrip())
def S(): return sys.stdin.readline().rstrip()
N = I()
s,t = S(),S()
ans = len(s)+len(t)
t_accumulate = list(itertools.accumulate(t))
for x in t_accumulate[::-1]:
    if x in s:
        ans -= len(x)
        break
print(ans)

Submission status: Accepted

Solution code:
import itertools,sys
def I(): return int(sys.stdin.readline().rstrip())
def S(): return sys.stdin.readline().rstrip()
N = I()
s,t = S(),S()
ans = len(s)+len(t)
t_accumulate = list(itertools.accumulate(t))
for x in t_accumulate[::-1]:
    if x in s:
        ans -= len(x)
        break
if ans>=N:
    print(ans)
else:
    print(max(N,len(s)+len(t)))

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 = max(n-i,ans)
print(2*n-ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

print(N * 2)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
N=int(input())
A=input()
B=input()
for i in range(N+1):
  if A[i:N]==B[0:N-i]:
    print(N+i)
    sys.exit()

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 = str(input())
T = str(input())

res = 0
for i in range(N):
    if S[i:] == T[:N-i]:
        res = N-i
        break

print(2 * N - res)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
s = list(input())
t = list(input())
N2 = N * 2
ans = 0
for i in range(N):
    temp = 0
    ns = s[i:]
    for j, k in zip(ns, t):
        if j == k:
            temp += 1
        else:
            break
    else:
        ans = max(ans, temp)

print(N2 - ans)

Submission status: Accepted

Solution code:
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,sqrt,factorial,hypot,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from fractions import gcd
from random import randint
def ceil(a,b): return (a+b-1)//b
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N=I()
    S=ST()
    T=ST()
    ans = 2*N
    for i in range(1,N+1): # 何文字被るか
        if(S[-i:] == T[:i]):
            ans = min(ans, 2*N-i)
    print(ans)
if __name__ == '__main__':
    main()

Submission status: Accepted

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

if t in s:
  print(N)
  quit()

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

Submission status: Accepted

Solution code:

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

print(ans)

Submission status: Accepted

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

ans = N + N
for i in range(N):
  w = S + T[-(i+1):]
  if w[:N] == S and w[-N:] == T:
    ans = min(ans,i+N+1)

if S == T:
  ans = N
    
print(ans)

Submission status: Accepted

Solution code:
N = int(input())

s = input()
t = input()

i = 0

while i < N:
    if s[i:] == t[:N-i]:
        break
    else:
        i+=1

print(N+i)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# s,tの重なりがN 全部から徐々にずらす O(N**2)
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:
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    import math
    #from math import gcd

    #inf = 10**17
    #mod = 10**9 + 7

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

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N = int(input())
s = input()
t = input()
l = 2*N
kouho = []

for i in range(N):
    ns = s[i:]
    res = 0
    for j, k in zip(ns, t):
        if j == k:
            res += 1
        else:
            break
    kouho.append(res)

print(l - max(kouho))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input());d,s=input(),input()
for i in range(n,2*n):
    kaburi=2*n-i
    if d[-kaburi:]==s[:kaburi]:print(i);exit()
print(2*n)

Submission status: Accepted

Solution code:
N = int(input())
S = input()
T = input()
if S == T:
    print(len(S))
    exit()
for i in range(len(T)):
    tmp = S+''.join(T[-i-1:])
    if tmp[i+1:] == T:
        print(len(tmp))
        exit()

Submission status: Accepted

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

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

print(N + cnt)

Submission status: Accepted

Solution code:
N = int(input())
s = input()[::-1]
T = list(input()[::-1])

index = len(T)
for i, t in enumerate(T):
    if t == s[0]:
        j = 0
        while j < len(T) - i:
            if s[j] != T[i + j]:
                break
            j += 1
        else:
            index = i
            break

res = s[::-1] + "".join((T[:index])[::-1])
print(len(res))

Submission status: Accepted

Solution code:
n = int(input())
s = input()
t = input()
a = 0
for i in range(n+1):
    if s[len(s)-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):
    if t.startswith(s[i:]):
        ans = s[:i]+t
        break
    else:
        ans = s+t

print(len(ans))

Submission status: Accepted

Solution code:
# A - Prefix and Suffix
n = int(input())
s = input()
t = input()

if len(s) + len(t) <= n:
	print(n)
elif s == t and len(s) >= n:
	print(len(s))
else:
	min_len = min(len(s), len(t))
	ans = len(s) + len(t)
	
	for i in range(1, min_len + 1):
		if s[-i:] == t[:i]:
			ans = len(s) + len(t) - i
	
	if ans < n:
		ans = n
	
	print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

print(2*N-temp)

Submission status: Accepted

Solution code:
# A - Prefix and Suffix

N = int(input())
s, t = [input() for i in range(2)]
delta = N

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

print(N+delta)

Submission status: Accepted

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

Submission status: Accepted

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

answer = 2*N

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

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]:
    print(ans - N + i)
    exit()
print(ans)

Submission status: Accepted

Solution code:
# Prefix and Suffix
N = int(input())
s = input()
t = input()

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

print(2*N - max)

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]:
    print(ans - N + i)
    exit()
print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sun May 10 17:43:29 2020

@author: shinba
"""

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

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

print(2*n-l)

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

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

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

else:
  print(2*n)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

if len(s)+len(t)<= n:
  print(n)
  exit()
  
dup = min(len(s)+ len(t)-n, len(s), len(t))
for i in range(dup, 0 , -1):
  if s[-i:] == t[:i]:
    print(len(t)+len(s) - i)
    break
else:
  print(len(s)+len(t))

Submission status: Accepted

Solution code:
n=int(input())

s1=list(input())

s2=list(input())

ans = n*2

flag = False

for i in range(n):
    for j in range(n):
        if s1[i:n]==s2[j:n-i]:
            ans -= len(s1[i:n])
            flag = True
            break
    if flag:
        break

print(ans)

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline

def main():
    ans = 0
    n = int(input())
    s = input().rstrip('\n')
    t = input().rstrip('\n')
    for i in range(n):
        if s[i:] == t[:n-i]:
            print(n+i)
            break
    else:
        print(n*2)
        
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline

def checkSpell(s, t):
    return s == t

def main():
    n = int(input())
    s = input()
    t = input()
    for i in range(n):
        ans = 0
        for j in range(n):
            if s[i] == t[j]:
                while checkSpell(s[i], t[j]):
                    ans += 1
                    i += 1
                    j += 1
                    if i == n or j == n:
                        print(n*2 - ans)
                        sys.exit()
    print(n*2)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

n_s=len(s)
n_t=len(t)
l=[]
for i in range(n_s):
    for j in range(n_t):
        l.append(s[:i]+t[j:])
ans=s+t
for c in l:
    if c[:n_s]==s and c[len(c)-n_t:]==t:
        if len(ans)>len(c):
            ans=c

print(len(ans))

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

main()

Submission status: Accepted

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

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

Submission status: Accepted

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

# In[39]:


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


# In[40]:


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


# In[ ]:

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    s = input()
    t = input()
    ss = tt = ''
    l = 0
    for i in range(N):
        ss = s[-1-i] + ss
        tt = tt + t[i]
        if ss == tt:
            l = len(ss)
    print(2 * N - l)
    return

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def resolve():
    '''
    code here
    '''
    N = int(input())
    s = input()
    t = input()

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

if __name__ == "__main__":
    resolve()

Submission status: Accepted

Solution code:
N = int(input())
s = input()
t = input()
index = 0
for i in s:
    if i == t[index]:
        index += 1
    else:
        continue
print(len(s + t[index:]))

Submission status: Accepted

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


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

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


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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


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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7


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

if __name__ == '__main__':
    main()

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]:
     print(ans)
     exit()
  else:
    ans += 1
  
print(ans)

Submission status: Accepted

Solution code:
# Problem A - Prefix and Suffix

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

# initialization
ans_str = 't'*3*N

# count
for i in range(N+1):
    is_ok = True
    tmp_str = ['']*2*N
    for j in range(N):
        tmp_str[j] = s[j]
    for j in range(N):
        if tmp_str[i+j]=='':
            tmp_str[i+j] = t[j]
        elif not tmp_str[i+j]==t[j]:
            is_ok = False
            break
    if is_ok:
        if len(tmp_str)<len(ans_str):
            ans_str = "".join(tmp_str)

# output
print(len(ans_str))

Submission status: Accepted

Solution code:
import math
import sys

n = int(sys.stdin.readline().rstrip())
s = sys.stdin.readline().rstrip()
v = sys.stdin.readline().rstrip()

# s = s[:3]
# v = v[-3:]
ans = 0

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

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

Submission status: Accepted

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

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

print(r)

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

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

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline

n = int(input())
s = input() #sys.stdin.readlineは最後が改行
t = input() #sys.stdin.readlineは最後が改行

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

print(2*n)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    N = int( input())
    s = input()
    t = input()
    for i in range(N):
        check = True
        for j in range(N-i):
            if not s[i+j]  == t[j]:
                check = False
                break
        if check:
            print(i+N)
            return
    print(N*2)
if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

maxl = 0
for i in range(n):
	sub_s = s[n-i-1:]
	sub_t = t[:i+1]
	if sub_s == sub_t:
		maxl = max(maxl, i + 1)

print(2 * n - maxl)