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:
# -*- coding: utf-8 -*-
import sys
from collections import deque, defaultdict
from math import sqrt, factorial
# def input(): return sys.stdin.readline()[:-1] # warning not \n
# def input(): return sys.stdin.buffer.readline().strip() # warning bytes
# def input(): return sys.stdin.buffer.readline().decode('utf-8')


def solve():
    n = int(input())
    s = input()
    t = input()
    for i in range(n, 0, -1):
        x = s[-i:]
        y = t[:i]
        if x == y:
            print(len(s[:n-i] + t))
            return
    print(n*2)


    

t = 1
# t = int(input())
for case in range(1,t+1):
    ans = solve()


"""



"""

Submission status: Accepted

Solution code:
n = int(input())
s = list(input())
t = list(input())
cnt = 0
for i in range(min(len(s), len(t))):
    c = 0
    for j in range(i + 1):
        if s[len(s) - 1 - i + j] == t[j]:
            c += 1
    cnt = max(cnt, c)
ans = len(s) + len(t) - cnt
if ans < n:
    ans = n
print(ans)

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()
flg=True
tmp=0
if s==t:
    print(n)
    exit()
for i in range(1,n):
    ss=s[i:]
    tt=t[:-i]
    if ss==tt:
        print(2*n-len(ss))
        exit()
print(n*2)

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

print(2 * n)

Submission status: Accepted

Solution code:
from collections import defaultdict
from collections import deque
import itertools
import math

def readInt():
  return int(input())
def readInts():
  return list(map(int, input().split()))
def readChar():
  return input()
def readChars():
  return input().split()

n = readInt()
s = input()
t = input()

if n>=len(s)+len(t):
  print(n)
  exit()

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

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

Submission status: Accepted

Solution code:
from collections import defaultdict
from collections import deque
import itertools
import math

def readInt():
  return int(input())
def readInts():
  return list(map(int, input().split()))
def readChar():
  return input()
def readChars():
  return input().split()

n = readInt()
s = input()
t = input()

if s==t and len(s)>=n:
  print(len(s))
  exit()
if n>=len(s)+len(t):
  print(n)
  exit()

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

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


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

Submission status: Accepted

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

print(n*2 - num)

Submission status: Accepted

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

    for i in range(0,n+1):
        diff = 0
        for j in range(i):
            if s[n - i :][j] == t[j]:
                diff+=1
            else:
                break
        if maxDiff < diff:
            maxDiff=diff
    print(count-maxDiff)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N=int(input())
s=input()
t=input()
ans=10**9
for i in range(N+1):
    for j in range(N+1):
        u=s[:i]+t[j:]
        if len(u)<N:
            continue
        if u[:N]==s and u[-N:]==t:
            ans=min(ans,len(u))
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:

N=int(input())
S=input()
T=input()
L=min(len(S), len(T))

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
s = input()
t = input()
f = 0
m = 0
ind = 0
for i in range(1,n+1):
      if(s[n-i:]==t[:i]):
            f=1
            if (len(t[:i])>m):
                  m = len(t[:i])
                  ind = i

print(2*n-ind) if f==1 else print(2*n)

Submission status: Accepted

Solution code:
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush
from bisect import bisect_left,bisect_right 
import sys,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
 
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:
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush
from bisect import bisect_left,bisect_right 
import sys,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

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:
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

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

for i in range(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()

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:

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

    if s == t:
        print(n)
        return

    for i in reversed(range(0, n)):
        target = s + t[i:]
        if target.startswith(s) and target.endswith(t):
            print(len(target))
            return

main()

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(N):
    tmp = 0
    while True:
        if s[i+tmp] == t[tmp]:
            pass
        else:
            break

        tmp += 1
        if not i + tmp < N:
            print(i + N)
            exit(0)
print(2*N)

Submission status: Accepted

Solution code:
N = int(input())
s = input()
t = input()
count = 0
num_s = len(s)
num_t = len(t)

for i in range(num_t):
    for j in range(i, num_s):
        if t[count] == s[j]:
            count += 1
        else:
            count = 0
            break

    if count == num_t - i:
        break
print(num_s+num_t-count)

Submission status: Accepted

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

for i in range(0,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()

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
n = int(input())
pre = input()
suf = input()
if pre==suf:
    print(n)
    sys.exit()
slicer, ans = n-1 , n*2
for xx in range(n+1):
    if suf[:slicer] in pre:
        ans = len(pre)+(len(suf)-len(suf[:slicer]))
        break
    slicer-=1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

print(len(ans))

Submission status: Accepted

Solution code:
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N, S, T = read().split()
N = int(N)

def test(n):
    overlap = N + N - n
    if overlap <= 0:
        return True
    return S[-overlap:] == T[:overlap]

for n in range(N, N + N + 10):
    if test(n):
        break
print(n)

Submission status: Accepted

Solution code:
import sys
import heapq
import math
import fractions
import bisect
import itertools
from collections import Counter
from collections import deque
from operator import itemgetter
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))

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

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(N):
    F=0
    for j in range(i,N):
        if s[j]==t[j-i]:
            continue
        else:
            F=1
            break
    if F==0:
        print(len(s[:i]+t))
        exit()
print(2*N)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
s = input()
t = input() + 'x'

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

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

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:
    print(i)
    exit(0)

Submission status: Accepted

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

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2, log
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
from decimal import Decimal
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
from decimal import *

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

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

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

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2, log
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
from decimal import Decimal
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
from decimal import *

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

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:

def resolve():
    n = int(input())
    s = input()
    t = input()
    ans = len(s) + len(t)
    for i in range(len(s)):
        pos = 0
        for ss,tt in zip(s[i:],t):
            if ss != tt:
                break
            pos += 1
        else:
            if len(s) - i > len(t) or i + len(t) < n:
                continue
            tmp = i + len(t)
            if tmp < ans:
                ans = tmp
    print(ans)
        

if __name__ == "__main__":
    resolve()

Submission status: Accepted

Solution code:
# agc006_a.py
N = int(input())
S = list(input())
T = list(input())
ans = N*2
for i in range(N):
    # print(i,S[N-1-i:] , T[:i+1])
    if S[N-1-i:] == T[:i+1]:
        # print("find")
        ans = N*2-(i+1)
print(ans)

Submission status: Accepted

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

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

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



if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())
a = input()
b = input()
ans = ''
idx1 = 0
idx2 = n
while idx1 < n and a[idx1:] != b[:idx2]:
    idx1+=1
    idx2-=1
print(2*n - idx2)

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

Submission status: Accepted

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

ans=2*N
i=N
while i:
    if S[-i:]==T[:i]:
        ans-=i
        break
    i-=1

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
#from math import gcd
import bisect
from collections import defaultdict
from collections import deque
from collections import Counter
from functools import lru_cache


#############
# Constants #
#############

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

#############
# Functions #
#############

######INPUT######
def I(): return int(input().strip())
def S(): return input().strip()
def IL(): return list(map(int,input().split()))
def SL(): return list(map(str,input().split()))
def ILs(n): return list(int(input()) for _ in range(n))
def SLs(n): return list(input().strip() for _ in range(n))
def ILL(n): return [list(map(int, input().split())) for _ in range(n)]
def SLL(n): return [list(map(str, input().split())) for _ in range(n)]

######OUTPUT######
def P(arg): print(arg); return
def Y(): print("Yes"); return
def N(): print("No"); return
def E(): exit()
def PE(arg): print(arg); exit()
def YE(): print("Yes"); exit()
def NE(): print("No"); exit()

#####Shorten#####
def DD(arg): return defaultdict(arg)


#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0: 
        cnt+=1 
        temp //= i
      arr.append([i, cnt])
  if temp!=1:
    arr.append([temp, 1])
  if arr==[]:
    arr.append([n, 1])
  return arr

#####MakeDivisors######
def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i: 
        divisors.append(n//i)
  return divisors

#####MakePrimes######
def make_primes(N):
  max = int(math.sqrt(N))
  seachList = [i for i in range(2,N+1)]
  primeNum = []
  while seachList[0] <= max:
    primeNum.append(seachList[0])
    tmp = seachList[0]
    seachList = [i for i in seachList if i % tmp != 0]
  primeNum.extend(seachList)
  return primeNum

#####GCD#####
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#####BitCount#####
def count_bit(n):
  count = 0
  while n:
    n &= n -1
    count += 1
  return count

#####ChangeBase#####
def base_10_to_n(X, n):
  if X//n:
    return base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def base_n_to_10(X, n):
  return sum(int(str(X)[-i-1])*n**i for i in range(len(str(X))))

#####IntLog#####
def int_log(n, a):
  count = 0
  while n>=a:
    n //= a
    count += 1
  return count

#############
# Main Code #
#############
N = I()
A = S()
B = S()

if A==B:
  print(len(A))
  exit()

for i in range(1,N):
  if A[i:] == B[:-i]:
    print(len(A[:i]+B))
    exit()
    
print(len(A+B))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline
ra = range
enu = enumerate


def mina(*argv, sub=1): return list(map(lambda x: x - sub, argv))
# 受け渡されたすべての要素からsubだけ引く.リストを*をつけて展開しておくこと


def read_a_int(): return int(read())


def read_ints(): return list(map(int, read().split()))


def read_col(H):
    '''H is number of rows
    A列、B列が与えられるようなとき
    ex1)A,B=read_col(H)    ex2) A,=read_col(H) #一列の場合'''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return tuple(map(list, zip(*ret)))


def read_tuple(H):
    '''H is number of rows'''
    ret = []
    for _ in range(H):
        ret.append(tuple(map(int, read().split())))
    return ret


def read_matrix(H):
    '''H is number of rows'''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return ret
    # return [list(map(int, read().split())) for _ in range(H)] # 内包表記はpypyでは遅いため


MOD = 10**9 + 7
INF = 2**31  # 2147483648 > 10**9
# default import
from collections import defaultdict, Counter, deque
from operator import itemgetter
from itertools import product, permutations, combinations
from bisect import bisect_left, bisect_right  # , insort_left, insort_right

# https://atcoder.jp/contests/agc006/tasks/agc006_a
N = read_a_int()
s = input()
t = input()
# tの先頭とsの末尾の一致具合を見る(Nが100なので全探索可能)

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

Submission status: Accepted

Solution code:
n = int(input())
s = input()
t = input()
if s==t:
    print(len(s));exit()

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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


def read():
    N = int(input().strip())
    s = input().strip()
    t = input().strip()
    return N, s, t


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


if __name__ == '__main__':
    inputs = read()
    print("%s" % solve(*inputs))

Submission status: Accepted

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

ans=2*n-c
print(ans)

Submission status: Accepted

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

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

print(n*2)

Submission status: Accepted

Solution code:
from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations # (string,3) 3回
from collections import deque
from collections import defaultdict
import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

import sys
sys.setrecursionlimit(10000000)
#mod = 10**9 + 7
mod = 9982443453
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
n = int(input())
s = input()
t = input()
cnt = 0
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 = 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=maxlen=len(s)+len(t)

for i in range(len(s)):
  if len(s[i:]) <= len(t):
    complen = len(s[i:])
    if maxlen-complen>=N and s[i:] == t[0:complen]:
      ans=maxlen-complen
      break
      
      
print(ans)

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

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

ans = 2*n-temp
print(ans)

Submission status: Accepted

Solution code:
import sys
input = lambda : sys.stdin.readline().rstrip()

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

ans = 10**10

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

if ans == 10**10:
    print(n)
else:
    print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
import numpy as np
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
s = input()
t = input()
if s == t:
	print(N)
	exit()

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

Submission status: Accepted

Solution code:
N = int(input())
s = input().strip()
t = input().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:
N = int(input())
s = input()
t = input()

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

ans = s[:N-max_i] + t
print(len(ans))