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

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

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

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

Submission status: Accepted

Solution code:
n = int(input())
s = input()
t = input()
k = n
for i in range(n):
  if t == s:
    print(2*n-k)
    exit()
  else:
    t = list(t)
    s = list(s)
    t.pop()
    s.pop(0)
    str(s)
    str(t)
    k -= 1
print(2*n)

Submission status: Accepted

Solution code:

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

tmp=0
for i in range(N):
    for j in range(N):
        if(s[j]==t[i]):
            for k in range(N-1,j,-1):
                tmp=0
                if(s[k]!=t[k-j]):
                    tmp=1
                    break
            if(tmp==0):
                print(N+j)
                exit()
print(N*2)

Submission status: Accepted

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

ln = 0
ch = 0
for i in range(len(s)):
    k = 0
    for j in range(i,len(s)):
        if(s[j]==t[k]):
            k += 1
            if(j==len(s)-1):
                ch = 1
                break
        else:
            if(j<len(s)-1):
                k = 0
            
    if(ch==1):
        ln = k
        break

ans  = n + (n-k)

print(ans)

Submission status: Accepted

Solution code:
n=int(input())
s=str(input())
t=str(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=str(input())
t=str(input())

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

print(solve(n,s,t))

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
N=int(input())
s=list(input())
t=list(input())

count=N
for i in range(N):
    if s==t:
        break
    else:
        s.pop(0)
        t.pop(-1)
        count+=1

print(count)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

print(N + d)

Submission status: Accepted

Solution code:
N = int(input())

s = input()
t = input()

result = 2 * N

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

print(result)

Submission status: Accepted

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

M = [[0] * n for i in range(n)]

for i in range(n):
    M[i][0] = int(s[i] == t[0])

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

Submission status: Accepted

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

Submission status: Accepted

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


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

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


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import os,sys,random
n=int(input())
A=input();B=input()
for i in range(n,-1,-1):
	if A[n-i:]==B[:i]:
		print(n+n-i)
		break

Submission status: Accepted

Solution code:
def slove():
    import sys
    input = sys.stdin.readline
    n = int(input().rstrip('\n'))
    s = str(input().rstrip('\n'))
    t = str(input().rstrip('\n'))
    l = n * 2
    for i in range(n):
        if s[-i-1:] == t[:i+1]:
            l = n * 2 - (i + 1)
    print(l)


if __name__ == '__main__':
    slove()

Submission status: Accepted

Solution code:
N=int(input())
s=input()
t=input()
ans=2*N
for i in reversed(range(1,N+1)):
    sl=s[-i:];tf=t[:i]
#    print(f'sl={sl},tf={tf}')
    if sl==tf:
        ans=2*N-i
        break
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

for start in range(N):
    for s, t in zip(S[start:], T[: N - start]):
        if s != t:
            break
    else:
        print(N + start)
        break
else:
    print(2 * N)

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

cnt=0
for i in range(N):
  if S[i:]==T[:N-i]:
    cnt=N-i
    break
print(len(S)+len(T)-cnt)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import bisect
import heapq
import itertools
import math
import operator
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter, mul, add, xor

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7

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

ans = 0
while S != T:
    S = S[1:]
    T = T[:-1]
    ans += 2
print(ans + len(S))

Submission status: Accepted

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

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

Submission status: Accepted

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

fin=1
for i in range(n):
    flag=1
    j=0
    while i+j<n:
        if t[j]!=s[i+j]:
            flag=0
        j=j+1
    if flag and fin:
        print(n-i+i*2)
        fin=0
if fin:
    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(1, N + 1):
    if s[i:] == t[:-i]:
      break
  print(2 * N - (N - i))

Submission status: Accepted

Solution code:
def slove():
    import sys
    input = sys.stdin.readline
    n = int(input().rstrip('\n'))
    s = str(input().rstrip('\n'))
    t = str(input().rstrip('\n'))
    mt = n * 2
    for i in range(n):
        ts = s[-i-1:]
        tt = t[:i+1]
        if ts == tt:
            mt = min(mt, n * 2 - (i + 1))
    print(mt)


if __name__ == '__main__':
    slove()

Submission status: Accepted

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

Submission status: Accepted

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


if __name__ == "__main__":
    resolve()

Submission status: Accepted

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

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

def main():
    for i in range(N):
        if s[i:].find(t[0:N-i]) >= 0:
            print(2*N-(N-i))
            return
    print(N*2)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
from collections import defaultdict
sys.setrecursionlimit(200000)
input = sys.stdin.readline

N,  = map(int, input().split())
A = list(input().strip())
B = list(input().strip())

for i in range(N):
    f = True
    t = A[i:i+N]
    for j in range(len(t)):
        if t[j] != B[j]:
            f = False
            break

    if f:
        print(N + i)
        exit()

print(N * 2)

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    s = list(input())
    t = list(input())
    if s == t:
        print(n)
        exit()
    ans = float("inf")
    for i in range(n):
        S = s + t[i:]
        #print(S[:n], S[2 * n - n:])
        if S[:n] == s and S[2 * n - n - i:] == t:
            ans = min(ans, len(S))
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N=int(input())
S=input()
T=input()
for i in range(N+1):
  s = S+T[::-1][:i][::-1]
  if s[-N:]==T:print(N+i);break

Submission status: Accepted

Solution code:
n=int(input())
s=list(input())
t=list(input())
s.reverse() 
s_bottom=[]
t_head=[]
val=[n*2]
for i in range(n):
	s_bottom.append(s[i])
	t_head.append(t[i])
	s_bottom.reverse()
	if s_bottom!=t_head:
		s_bottom.reverse()
		continue
	else:
		val.append(n*2-len(t_head))
		
print(min(val))

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

print(2*N-c)

Submission status: Accepted

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

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

print(2*N-c)

Submission status: Accepted

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

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

print(2*N-c)

Submission status: Accepted

Solution code:
n=int(input())
a=input()
b=input()
for i in range(n):
	cnt=0
	if a[i]==b[0]:
		j=i
		while j<n:
			if a[j]!=b[j-i]:
				break
			else:
				cnt+=1
				j+=1
	if cnt==n-i:
		print(n+i)
		exit()
print(n*2)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
s = input()
t = input()
if s == t:
  print(n)
  exit()
for i in range(1,n):
  if s[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):
    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()
num = 0

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

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

print(N * 2 - num)

Submission status: Accepted

Solution code:
def slove():
    import sys
    input = sys.stdin.readline
    n = int(input().rstrip('\n'))
    s = str(input().rstrip('\n'))
    t = str(input().rstrip('\n'))
    a = len(s) + len(t)
    for i in range(n):
        if s[-i-1:] == t[:i+1]:
            a = len(s) + len(t) - len(t[:i+1])
    print(a)


if __name__ == '__main__':
    slove()

Submission status: Accepted

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

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

print(n*2-len(s))

Submission status: Accepted

Solution code:
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

#A
def A():
    n = I()
    s = input()
    t = input()
    ans = 2*n
    for i in range(n)[::-1]:
        su = s[i:]
        pre = t[:n-i]
        if su == pre:
            ans = n+i
    print(ans)
    return

#B
def B():

    return

#C
def C():

    return

#D
def D():

    return

#E
def E():

    return

#F
def F():

    return

#Solve
if __name__ == "__main__":
    A()

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

if __name__ == '__main__':
    print(main())

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

    print(2*n-i)
    
if __name__ == "__main__":
    main()

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys, math, fractions, itertools, collections, copy, heapq


def solve(N: int, s: str, t: str):
    if t == s:
        print(N)
        return
    for i in range(1, N+1):
        S = s + t[-i:]
        if S[-N:] == t:
            print(len(S))
            break
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    s = next(tokens)  # type: str
    t = next(tokens)  # type: str
    solve(N, s, t)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# 2019/08/15

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

def solve():
    for i in range(n):
        for j in range(n):
            if s[i]!=t[j]:continue
            m=s[i:]
            if m==t[:len(m)]:
                res=len(s[:i])+n
                return res
ans=solve()
if ans:print(ans)
else:print(2*n)

Submission status: Accepted

Solution code:
I=input;n,a,b=int(I()),I(),I();print(min([n+i for i in range(n)if a[i:]==b[:n-i]]+[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())

def output(i): #i文字目以降が重なっている
    print (*s[:i], sep = '\n')
    print (*t, sep = '\n')
    return 

for i in range(N): #スタート位置
    flag = True
    for j in range(N - i):
        if s[i + j] == t[j]:
            pass
        else:
            flag = False
    if flag == True:
        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):
    if s[-i-1:]==t[0:i+1]:
        ans=min(ans,2*n-i-1)
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys, math, itertools, bisect, copy, re, heapq
from collections import Counter, deque, defaultdict
from itertools import accumulate, permutations, combinations, takewhile, compress, cycle

# from functools import reduce
# from math import ceil, floor, log10, log2, factorial
# from pprint import pprint


INF = float('inf')
MOD = 10 ** 9 + 7
EPS = 10 ** -7
sys.setrecursionlimit(1000000)

# N = int(input())
# N,M = [int(x) for x in input().split()]
# V = [[0] * 100 for _ in range(100)]
# A = [int(input()) for _ in range(N)]
# DP = [[0] * 100 for _ in range(100)]
# DP = defaultdict(lambda: float('inf'))

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

for i in range(N):
    # print("--- {} ---".format(i))
    # print(s[i:])
    # print(t[:N - i])
    ss = s[i:]
    tt = t[:N - i]
    if ss == tt:
        print(2 * N - (N - i))
        sys.exit()

print(2 * N)

Submission status: Accepted

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

import sys
import math
import bisect
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:


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

s = list(s)
t = list(t)

s.reverse()

a1 = []
a2 = []

c1 = ""
c2 = ""

for i in range(n):
    c1 += s[i]
    c2 += t[i]
    temp = c1
    a1.append(temp[::-1])
    a2.append(c2)

max = 0
for i in range(n):
    if a1[i] == a2[i]:
        max = i+1
#
# print(a1)
# print(a2)

print(2*n-max)

Submission status: Accepted

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

ans = N

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

print(N + ans)

Submission status: Accepted

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

Submission status: Accepted

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


main()

Submission status: Accepted

Solution code:
a = int(input())
b = list(input())
c = list(input())
d = a * 2
for i in range(1, a + 1):
    bb = ""
    for j in range(a-i, a):
        bb += b[j]
    cc = ""
    for j in range(0, i):
        cc += c[j]
    if bb == cc:
        d = min(d, a * 2 - i)
print(d)

Submission status: Accepted

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

for i in range(n):
        if p[i:] == s[: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(2*N)

Submission status: Accepted

Solution code:
N = int(input())

s = input()
t = input()

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

print(len(ans))

Submission status: Accepted

Solution code:
# AGC006A - Prefix and Suffix
def main():
    n = int(input())
    S, T = tuple(input().rstrip() for _ in range(2))
    for i in range(n):
        if S[i:] == T[: n - i]:  # check duplicates
            print(n + i)
            break
    else:
        print(n * 2)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
###template###
import sys
def input(): return sys.stdin.readline().rstrip()
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt, ceil, floor
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
import heapq
INF = float("inf")
MOD = 10**9 + 7
sys.setrecursionlimit(10**7)
# 4近傍（右, 下, 左, 上）
dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]
def inside(y: int, x: int, H: int, W: int) -> bool: return 0 <= y < H and 0 <= x < W
def mi(): return map(int, input().split())
def ii(): return int(input())
###template###

N = ii()
S = input()
T = input()

dupr = N
while(dupr>=0):
  if S[N-dupr:N] == T[0:dupr]:
    break
  else:
    dupr -= 1

print(N*2 - dupr)

Submission status: Accepted

Solution code:
a = int(input())
b = input()
c = input()
e = -1
for i in range(a):
    if b[-i-1:] == c[:i+1]:
        e = max(e,i)
if e == -1:
    print(len(b + c))
else:
    print(len(b + c[e+1:]))

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:n]==t[0:i+1]:
        ans.append(2*n-i-1)

print(min(ans))

Submission status: Accepted

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

p = 2*N
for i in range(N):
    if S[i:] == T[:N-i] and i+N < p:
        p = i + N

print(p)

Submission status: Accepted

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

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

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

if res == 0:
    print(len(s + t))
else:
    ans = s[:res] + t
    print(len(ans))

Submission status: Accepted

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

print(N*2)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

tmp = s + t
for i in range(N):
    if s[i:] == t[:N-i]:
        tmp = s + t[N-i:]
        if len(tmp) < N:
            continue
print(len(tmp))

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
from fractions import gcd
import math
def inverse(a):
    return pow(a, mod - 2, mod)


def usearch(x, a):
    lft = 0
    rgt = len(a) + 1
    while rgt - lft > 1:
        mid = (rgt + lft) // 2
        if a[mid] <= x:
            lft = mid
        else:
            rgt = mid
    return lft



def main():
    n=int(input())
    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)
            return
    print(2*n)
main()

Submission status: Accepted

Solution code:
import numpy as np

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

moji = s
count = 0
while True:
    if moji[len(moji)-len(t)+count:] == t[0:len(t)-count]:
        moji += t[len(t)-count:]
        print(len(moji))
        break
    else:
        count += 1

Submission status: Accepted

Solution code:
def f(s, t):
    n = len(s)
    for i in range(n):
        if s[i:] == t[:n-i]:
            return len(s[:i] + t)
    return len(s + t)

def solve(n, s, t):
    return min(f(s, t), f(t, s))

n = 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]:
        tmp = len(s[i:])
        print(len(s + t[tmp:]))
        exit()

print(len(s + t))

Submission status: Accepted

Solution code:
n = int(input())
s = input()
t = input()
ans = float("inf")
for i in range(n + 1):
    a = s + t[i:]
    if a[:n] == s and a[-n:] == t:
        ans = min(ans, n * 2 - i)
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]:
        break
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]:
        tmp = len(s[i:])
        print(len(s + t[tmp:]))
        exit()

print(len(s + t))

Submission status: Accepted

Solution code:
n=int(input())
s=input()
t=input()
ans=""
for i in range(n+1):
    s1=s[:n-i]
    s2=s[n-i:]
    t1=t[:i]
    t2=t[i:]
    if s2==t1:
        ans=s1+s2+t2
print(len(ans))

Submission status: Accepted

Solution code:
N,S,T=(input() for i in range(3))
N=int(N)
for k in range(N,-1,-1):#k文字共通
    if all([S[N-k+i]==T[i] for i in range(k)]) or k==0:
        print(N*2-k)
        break

Submission status: Accepted

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

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

a = []

for i in range(n+1):
    a.append(s+t[n-i:])

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