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
import heapq
import re
from itertools import permutations
from bisect import bisect_left, bisect_right
from collections import Counter, deque
from fractions import gcd
from math import factorial, sqrt, ceil
from functools import lru_cache, reduce
INF = 1 << 60
MOD = 1000000007
sys.setrecursionlimit(10 ** 7)

# UnionFind
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

# ダイクストラ
def dijkstra_heap(s, edge, n):
    #始点sから各頂点への最短距離
    d = [10**20] * n
    used = [True] * n #True:未確定
    d[s] = 0
    used[s] = False
    edgelist = []
    for a,b in edge[s]:
        heapq.heappush(edgelist,a*(10**6)+b)
    while len(edgelist):
        minedge = heapq.heappop(edgelist)
        #まだ使われてない頂点の中から最小の距離のものを探す
        if not used[minedge%(10**6)]:
            continue
        v = minedge%(10**6)
        d[v] = minedge//(10**6)
        used[v] = False
        for e in edge[v]:
            if used[e[1]]:
                heapq.heappush(edgelist,(e[0]+d[v])*(10**6)+e[1])
    return d

# 素因数分解
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

# 2数の最小公倍数
def lcm(x, y):
    return (x * y) // gcd(x, y)

# リストの要素の最小公倍数
def lcm_list(numbers):
    return reduce(lcm, numbers, 1)

# リストの要素の最大公約数
def gcd_list(numbers):
    return reduce(gcd, numbers)

# 素数判定
def is_prime(n):
    if n <= 1:
        return False
    p = 2
    while True:
        if p ** 2 > n:
            break
        if n % p == 0:
            return False
        p += 1
    return True


# limit以下の素数を列挙
def eratosthenes(limit):
    A = [i for i in range(2, limit+1)]
    P = []

    while True:
        prime = min(A)
        
        if prime > sqrt(limit):
            break
            
        P.append(prime)
            
        i = 0
        while i < len(A):
            if A[i] % prime == 0:
                A.pop(i)
                continue
            i += 1
            
    for a in A:
        P.append(a)
            
    return P

# 同じものを含む順列
def permutation_with_duplicates(L):

    if L == []:
        return [[]]

    else:
        ret = []

        # set（集合）型で重複を削除、ソート
        S = sorted(set(L))

        for i in S:

            data = L[:]
            data.remove(i)

            for j in permutation_with_duplicates(data):
                ret.append([i] + j)

        return ret


# ここから書き始める
n = int(input())
s = input()
t = input()
all_different = True
for i in range(n):
    if s[i : ] == t[: n - i]:
        all_different = False
        print(2 * n - n + i)
        break
if all_different:
    print(2 * n)

Submission status: Accepted

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

count = 0
for i in range(len(s)):
    if s[i:] != (t[:~i+1] if i > 0 else t):
        count += 1
    else:
        break

print(n + count)

Submission status: Accepted

Solution code:
import sys

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


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

    res = n
    for i in range(n):
        for j in range(n):
            if i + j < n:
                if s[i + j] != t[j]:
                    break
        else:
            res = i
            break

    print(res + n)


if __name__ == '__main__':
    resolve()

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

Submission status: Accepted

Solution code:
n = int(input())
s = input()
t = input()
# print(s + t)
st = s + t
same = 0
for i in range(n):
    ok = True
    for j in range(i+1):
        if s[n-i+j-1] != t[j]:
            ok = False
        # print(i, j, ok)
    if ok:
        same = i+1
# print(same)
print(2*n - same)

Submission status: Accepted

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

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:
def myAnswer(N:int,s:str,t:str) -> int:
   if(s == t): return N
   if(N == 1): return 2
   total = N * 2
   # sとtを比較して重なった文字数をtotalから引く
   for i in range(N):
      if(s[i:] == t[:N-i]):
         total -= len(s[i:])
         break
   return total

def modelAnswer():
   return
def main():
   N = int(input())
   s = input()
   t = input()
   print(myAnswer(N,s,t))
if __name__ == '__main__':
   main()

Submission status: Accepted

Solution code:
# from math import factorial,sqrt,ceil,gcd
# from itertools import permutations as permus
# from collections import deque,Counter
# import re
# from functools import lru_cache # 簡単メモ化 @lru_cache(maxsize=1000)
# from decimal import Decimal, getcontext
# # getcontext().prec = 1000
# # eps = Decimal(10) ** (-100)

# import numpy as np
# import networkx as nx
# from scipy.sparse.csgraph import shortest_path, dijkstra, floyd_warshall, bellman_ford, johnson
# from scipy.sparse import csr_matrix
# from scipy.special import comb

# slist = "abcdefghijklmnopqrstuvwxyz"
N = int(input())
S = input()
T = input()
ans = 2*N
for i in range(N,-1,-1):
    ST = S[:i] + T
    # print(ST,ST[:i],ST[i:])
    if ST[:N]==S and ST[-N:]==T:
        ans = min(len(ST),ans)

print(ans)
# print(*ans)   # unpackして出力。間にスペースが入る
# for row in board:
#     print(*row,sep="")    #unpackして間にスペース入れずに出力する
# print("{:.10f}".format(ans))
# print("{:0=10d}".format(ans))

Submission status: Accepted

Solution code:

def myAnswer(N:int,s:str,t:str) -> int:
   if(s == t): return N
   if(N == 1): return 2
   total = N * 2
   for i in range(N):
      counter = 0
      n = i
      for j in range(N-i):
         # print(s[n],t[j])
         if(s[n] == t[j]):
            n += 1
            counter += 1
         else:
            break
      else:
         total -= counter
         break
   return total

def modelAnswer():
   return
def main():
   N = int(input())
   s = input()
   t = input()
   print(myAnswer(N,s,t))
if __name__ == '__main__':
   main()

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:

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

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

Submission status: Accepted

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

common = 0

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

print(N * 2 - common)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/agc006/tasks/agc006_a

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

string = s + t
ans = len(string)

for i in range(len(string)):
    for j in range(i, len(string)):
        sub = string[:i] + string[j:]
        if len(sub) >= n:
            if sub[:n] == s and sub[-n:] == t:
                ans = min(ans, len(sub))
print(ans)

Submission status: Accepted

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

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

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input()) 
s = input()
t = input()
# i = nのときs[i:], t[:n-i]は空
for i in range(n+1):
    if s[i:] == t[:n-i]:
        # n - i  + i*2 = n+i
        print(n+i)
        break

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))
def ism():return map(str,input().split())
def isl():return list(map(str,input().split()))

n = ii()
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()

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()
p=True
for i in range(n):
    if a[:i]+b[:n-i]==a:
        print(i+n)
        p=False
        break
if p:print(2*n)

Submission status: Accepted

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

ans=""
for i in range(N):
    ans=ans+s[i]

count=0

for i in range(N):
    flag=True
    for j in range(i+1):
        #print(s[N-1-i+j])
        if s[N-1-i+j]==t[j]:
            pass
        else:
            flag=False
    if flag:
        count=i+1
#print(count)
for i in range(count,N):
    ans=ans+t[i]

print(len(ans))

Submission status: Accepted

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

for start in range(N):
    point=0
    check=False
    for i in range(start,N):
        if s[i] != t[point]:
            check=True
            break
        point+=1
    if not check:
        common=N-start
        break

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

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()
    ans +=1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def solve(n, s, t):
    if s == t:
        return n
    for common in range(n - 1, 0, -1):
        if s[-common:] == t[:common]:
            return 2 * n - common
    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()

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# import string
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()

def resolve():
    N=int(input())
    s=str(input())
    t=str(input())
    ans=2*N
    for i in range(1,N+1):
        #print(s[-i:])
        #print(t[:i])
        if s[-i:]==t[:i]:
            ans=2*N-i
    print(ans)



resolve()

Submission status: Accepted

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

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

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

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

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(0, 101):
    temp = s[:i] + t
    if temp[:N] == s:
        print(N + i)
        break

Submission status: Accepted

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

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

ans = len(s + t)
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()

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
#AGC006-A
n = int(input())
s = input()
t = input()

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

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
sys.setrecursionlimit(10 ** 7)

n = int(readline())
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())
s = list(input())
t = list(input())
ans = n
for i in range(2 * n, n - 1, -1):
    c = 1
    x = ["?"] * i
    y = ["?"] * i
    for j in range(n):
        x[j] = s[j]
        y[i - j - 1] = t[n - j - 1]
    #print(x, y)
    for j in range(i):
        if x[j] != "?" and y[j] != "?":
            if not x[j] == y[j]:
                c = 0
    if c == 1:
        ans = i
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n = int(input())
sl = list(input())
tl = list(input())

ans = 0
for i in range(n+1):
    if sl[-i:] == tl[:i]:
        ans = i

print(2 * n - ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

print((N-cnt)+N)

Submission status: Accepted

Solution code:
N=int(input())
S=input()
T=input()
s=[str(c) for c in (S)]
t=[str(c) for c in (T)]
flag=0
score=N
for i in range (N,2*N):
  flag=0
  for j in range(N+N-i):
    if s[i-N+j]!=t[j]:
      flag=1
  if flag==0:
    score=i
    flag=2
  if flag==2:
    break
if flag==1:
  score=2*N
print(score)

Submission status: Accepted

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

best = float('inf')
for i in range(len(T)+1):
    s = S + T[i:]
    if s[::-1][:N][::-1] == T:
        best = min(best, len(s))

print(best)

Submission status: Accepted

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

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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N = int(input())
s = input()
t = input()
ans = -1
for i in range(N):
    j = 0
    while i+j < N:
        if s[i+j] == t[j]:
            j += 1
        else:
            break
        
        if i+j == N:
            ans = i
            break
    
    if ans != -1:
        break

if ans != -1:
    print(len(s[:ans]+t))
else:
    print(len(s+t))

Submission status: Accepted

Solution code:
N = int(input())
s = input()
t = input()
for i in range(N):
    tmp_s = ''
    tmp_t = ''
    for k in range(i,N):
        tmp_s += s[k]
    for k in range(0,N-i):
        tmp_t += t[k]
    if tmp_s == tmp_t:
        print(2*N-len(tmp_s))
        exit()
print(2*N)

Submission status: Accepted

Solution code:
#coding utf-8

N = int(input())
s = list(input())
t = list(input())
Flg = True
for i in range(N,-1,-1):
    if s[N-i:N] == t[:i]:
        ans = 2 * N - i
        Flg = False
        break

if Flg:
    ans = 2 * N
    if s[-1] == t[0]:
        ans = 2 * N - 1
print(ans)

Submission status: Accepted

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

for i in range(N):
    is_match = True
    for j in range(N-i):
        if s[i+j] != t[j]:
            is_match = False
            break
    if is_match:
        print N+i
        exit()

print 2*N

Submission status: Accepted

Solution code:
import math
import fractions
import bisect
import collections
import itertools
import heapq
import string
import sys
import copy
from decimal import *
from collections import deque
sys.setrecursionlimit(10**7)
MOD = 10**9+7
INF = float('inf') #無限大
def gcd(a,b):return fractions.gcd(a,b) #最大公約数
def lcm(a,b):return (a*b) // fractions.gcd(a,b) #最小公倍数
def iin(): return int(sys.stdin.readline()) #整数読み込み
def ifn(): return float(sys.stdin.readline()) #浮動小数点読み込み
def isn(): return sys.stdin.readline().split() #文字列読み込み
def imn(): return map(int, sys.stdin.readline().split()) #整数map取得
def imnn(): return map(lambda x:int(x)-1, sys.stdin.readline().split()) #整数-1map取得
def fmn(): return map(float, sys.stdin.readline().split()) #浮動小数点map取得
def iln(): return list(map(int, sys.stdin.readline().split())) #整数リスト取得
def iln_s(): return sorted(iln()) # 昇順の整数リスト取得
def iln_r(): return sorted(iln(), reverse=True) # 降順の整数リスト取得
def fln(): return list(map(float, sys.stdin.readline().split())) # 浮動小数点リスト取得
def join(l, s=''): return s.join(l) #リストを文字列に変換
def perm(l, n): return itertools.permutations(l, n) # 順列取得
def perm_count(n, r): return math.factorial(n) // math.factorial(n-r) # 順列の総数
def comb(l, n): return itertools.combinations(l, n) # 組み合わせ取得
def comb_count(n, r): return math.factorial(n) // (math.factorial(n-r) * math.factorial(r)) #組み合わせの総数
def two_distance(a, b, c, d): return ((c-a)**2 + (d-b)**2)**.5 # 2点間の距離
def m_add(a,b): return (a+b) % MOD
def print_list(l): print(*l, sep='\n')

def sieves_of_e(n):
    is_prime = [True] * (n+1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5)+1):
        if not is_prime[i]: continue
        for j in range(i * 2, n+1, i): is_prime[j] = False
    return is_prime

N = iin()
s = input()
t = input()

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

Submission status: Accepted

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

Submission status: Accepted

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

idx = 0
ct = 0

for i in s:
    if i == t[idx]:
        ct += 1
        idx += 1
        
print(n*2 - ct)

Submission status: Accepted

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

Submission status: Accepted

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

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

ans = len(s) + len(t)
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()

ans = 2*N
for i in range(N) :
    flg = True
    for j in range(N-i) :
        if s[i+j] != t[j] :
            flg = False
    if flg == True :
        ans = N+i
        break

print(ans)

Submission status: Accepted

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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N=int(input())
S=input()
T=input()
dup=0
for d in range(N+1):
  # print(d)
  flag=True
  for i in range(N-d):
    
    if T[i]!=S[d+i]:
      # print(T[i],S[d+i])
      flag=False
      break
  if flag:
    dup=N-d
    break
print(2*N-dup)

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    S = input()
    T = input()
    if S == T:
        return print(len(S))
    ans = len(S) + len(T)
    if len(S) > len(T):
        for i in range(len(S) - len(T), len(S)):
            if S[i:] == T[:len(S[i:])]:
                ans -= len(S[i:])
                break
    else:
        for i in range(len(S), 0, -1):
            if T[:i] == S[len(S) - i:]:
                ans -= i
                break
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

ans = s + t[idx:]
#print(ans)
print(len(ans))

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
# input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return map(int,input().split())
def LI(): return list(map(int,input().split()))

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

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

    return

if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

print(2 * n - i)

Submission status: Accepted

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

same = 0
for i in range(n):
    
    judge = 1
    for j in range(i+1):
        if not t[j]==s[n-1-i+j]:
            judge = 0
            break
    
    if judge==1:
        same = i+1

print(2*n - same)

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]:
        cnt += n - i
        break
print(2 * n - cnt)

Submission status: Accepted

Solution code:
import sys
f=1;k=0
N=int(input())
s=list(input())
t=list(input())
for i in range(N):
  for j in range(i,N):
    #print(s[j],t[k],i,j,k,f)
    if s[j]==t[k]:
      f=f*1
    else:
      f=f*0
    k=k+1
  if f!=0:
    print(N+i)
    sys.exit()
  f=1
  k=0
print(N*2)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    s = input().rstrip()
    t = input().rstrip()
    ans = 2*n
    for i in range(n):
        f = True
        for j in range(n-i):
            if s[i+j] != t[j]:
                f = False
                break
        if f:
            ans = i + n
            break
    print(ans)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
#bがaの末尾にあうかチェック
def check(a, b):
    a = list(a)
    b = list(b)
    while b and a[-len(b):] != b:
        b.pop(-1)
    return len(b)
N = int(input())
A = input()
B = input()
print(N*2-check(A, B))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

res = 0
s_ = s[::-1]
for i in range(n+1):
    tmp = s_[:i]
    tmp = tmp[::-1]
    
    cnt = 0
    for j in range(len(tmp)):
        if tmp[j] == t[j]:
            cnt += 1
    res = max(res, cnt)
print(2*n - res)

Submission status: Accepted

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


ans = []

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

    #else:
    ans.append(s[i])
#        print(s[i],end="")
else:
    ans+=t
    #print(t)
#print(ans)
print(len(ans))

Submission status: Accepted

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

c = None
# i文字一致している
for i in range(N+1):
    sp = s[i:]
    tp = t[:N-i]
    # print(sp, tp)
    if sp == tp:
        c = i
        break

match = N - c
ans = 2 * N - match
# print(c, match, ans)
print(ans)

Submission status: Accepted

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

c = -1
# i文字一致している
for i in range(N):
    sp = s[i:]
    tp = t[:N-i]
    # print(sp, tp)
    if sp == tp:
        c = i
        break

if c == -1:
    print(2*N)
else:
    match = N - c
    ans = 2 * N - match
    # print(':', match)
    print(ans)

Submission status: Accepted

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

pos = 0
# スタートを一文字ずつずらして全探索
for i in range(N):
    c = 0
    for j in range(N-i):
        # print('::', i, j)
        # print('!!', s[i+j], t[j])
        if s[i+j] == t[j]:
            c += 1
        else:
            break
    else:
        pos = max(pos, c)

# print(pos)
ans = 2 * N - pos
print(ans)