Problem:


Score : 200 points

Problem Statement

Snuke is interested in strings that satisfy the following conditions:

The length of the string is at least N.

The first N characters equal to the string s.

The last N characters equal to the string t.

Find the length of the shortest string that satisfies the conditions.

Constraints

1≤N≤100

The lengths of s and t are both N.

s and t consist of lowercase English letters.

Input

The input is given from Standard Input in the following format:

N
s
t

Output

Print the length of the shortest string that satisfies the conditions.

Sample Input 1

3
abc
cde

Sample Output 1

5

The shortest string is abcde.

Sample Input 2

1
a
z

Sample Output 2

2

The shortest string is az.

Sample Input 3

4
expr
expr

Sample Output 3

4

The shortest string is expr.



Sample input:
3
abc
cde


Sample output:
5

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N = int(input())
A = input()
B = input()

for i in range(N):
  if A[i:] == B[0:N-i]:
    print(N+i)
    exit(0)
    
print(N*2)

Submission status: Accepted

Solution code:
import sys, math
from functools import lru_cache
from collections import defaultdict
from decimal import Decimal
sys.setrecursionlimit(10**9)
MOD = 10**9+7

def input():
    return sys.stdin.readline()[:-1]

def mi():
    return map(int, input().split())

def ii():
    return int(input())

def i2(n):
    tmp = [list(mi()) for i in range(n)]
    return [list(i) for i in zip(*tmp)]

def main():
    N = ii()
    s, t = input(), input()

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

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

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


if __name__ == "__main__":
    main()

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys
from sys import exit
from collections import deque
from bisect import bisect_left, bisect_right, insort_left, insort_right #func(リスト,値)
from heapq import heapify, heappop, heappush
from math import *

sys.setrecursionlimit(10**6)
INF = 10**20
eps = 1.0e-20
MOD = 10**9+7

def mint():
    return map(int,input().split())
def lint():
    return list(map(int,input().split()))
def ilint():
    return int(input()), list(map(int,input().split()))
def judge(x, l=['Yes', 'No']):
    print(l[0] if x else l[1])
def lprint(l, sep='\n'):
    for x in l:
        print(x, end=sep)

N = int(input())
s,t = input(),input()
i = N
while i>0 and s[N-i:]!=t[:i]:
    i -= 1
print(2*N-i)

Submission status: Accepted

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

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


print(n*2 - ans)

Submission status: Accepted

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

Submission status: Accepted

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

find = False
for i in range(N):
    mae = s[i:]
    ushiro = t[0:N-i]
    if mae == ushiro:
        find = True
        break
if find:
    print(N+i)
else:
    print(N*2)

Submission status: Accepted

Solution code:
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(i + N)
    exit()

print(N * 2)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#26 A - Prefix and Suffix
N = int(input())
s = list(input())
t = list(input())
s_rev = list(reversed(s))

cnt = 0
for i in range(1,N+1):
    # s の部分文字列を後ろから取り出す
    tgt = list(reversed(s_rev[:i]))
    if tgt == t[:i]:
        cnt = len(tgt)
    
ans = s + t[cnt:]
print(len(ans))

Submission status: Accepted

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

if s == t:
    print(n)
    sys.exit()
can = False
for i in range(n):
    if s[i:n] == t[0:(n-i)]:
        can = True
        break
if can:
    print(n + i )
else:
    print(2*n)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

tin=lambda : map(int, input().split())
lin=lambda : list(tin())
mod=1000000007

#+++++

def main():
	n = int(input())
	#b , c = tin()
	s = input()
	t = input()
	if s == t:
		return n
	for i in range(1, n+1):
		r = s + t[-i:]
		if r[-n:] == t:
			return i+n
	
	
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import bisect,collections,copy,itertools,math,string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
def main():
    n = I()
    s = S()
    t = S()

    lenth = 0

    for i in range(1,n+1):
        s_end = s[-i:]
        t_start = t[:i]

        if s_end == t_start:
            lenth = i
    
    ans = 2*n - lenth
    print(ans)
        
main()

Submission status: Accepted

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

Submission status: Accepted

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

ans = s + t
for i in range(n):
    is_same = True
    for j in range(i, n):
        if s[j] != t[j - i]:
            is_same = False
            break
    if is_same:
        ans = s[:i] + t
        break

print(len(ans))

Submission status: Accepted

Solution code:
# 3:25
N = int(input())
S = input()
T = input()

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

Submission status: Accepted

Solution code:
N = int(input())
s = input()
t = input()
ans = s
for i in range(N + 1):
    tmp_ans = s + t[i:]
    # print(tmp_ans)
    if tmp_ans[:N] == s and tmp_ans[-N:] == t:
        ans = tmp_ans
print(len(ans))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
S = input()
T = input()
kouho = []
for i in range(len(S)):
    ok = 1
    for j in range(0, len(S)-i):
        if S[i+j] == T[j]:
            continue
        ok = 0
        break
    if ok == 0:
        continue
    break
if ok == 1:
    ans = i+len(T)
else:
    ans = len(S)+len(T)
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

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

for i in range(1, n):
    s_ = s[i:n]
    t_ = t[0:n-i]
    if s_ == t_:
        ans = s[:i]+t
        print(len(ans))
        exit()
else:
    print(2*n)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 8)
ini = lambda: int(sys.stdin.readline())
inl = lambda: [int(x) for x in sys.stdin.readline().split()]
ins = lambda: sys.stdin.readline().rstrip()
debug = lambda *a, **kw: print("\033[33m", *a, "\033[0m", **dict(file=sys.stderr, **kw))


def solve():
    n = ini()
    s = ins()
    t = ins()
    for i in range(n + 1):
        if t.startswith(s[i:]):
            return len(s[:i] + t)

    return len(s + t)


print(solve())

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
s = input()
t = input()
ans = N
i = 0
if s == t:
    print(ans)
    exit()
while ans < 2 * N:
    if s[i:] == t[:-i]:
        break
    i += 1
    ans += 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):
    sub_s=s[i:]
    sub_t=t[:-i]

    if sub_s==sub_t:
        print(n+i)
        exit()

print(n*2)

Submission status: Accepted

Solution code:
#AtCoder Grand Contest 006 a
def check(moji):
    x1=""
    x2=""
    for i in range(n):
        x1+=moji[i]
        x2+=moji[len(moji)-n+i]
    if s==x1 and t==x2:
        return True
    else:
        return False
n=int(input())
s=input()
t=input()
ans=[]
ans.append(s)
for i in range(len(t)-1,-1,-1):
    ans.append(s+t[i:])
for i in ans:
    if check(i):
        print(len(i))
        break

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
f=input()
b=input()
for x in range(n):
    if f[x:]==b[:n-x]:print(n+x);break
else:print(n*2)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
s = input()
t = input()
ans = n
for i in range(n):
    f = True
    for j in range(n - i):
        f &= s[j + i] == t[j]
    if f:
        ans = i
        break
print(n+ans)

Submission status: Accepted

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

n = 0

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

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

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!

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

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

Submission status: Accepted

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

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)
        break
else:
    print(2 * N)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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


print(n + n - (tmp + 1))

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,permutations,accumulate, product # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入g
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 = I()
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+n)

Submission status: Accepted

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

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
def solve():
  N = int(input())
  S = input()
  T = input()
  for i in range(N):
    if S[i:]==T[:N-i]:
      return N+i
  return N*2
print(solve())

Submission status: Accepted

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

Submission status: Accepted

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

ans = 0
for i in range(n):
    curr_s = s[i:]
    cnt = 0
    for j in range(n-i):
        if t[j] == curr_s[j]: cnt += 1
        else: break
    ans = max(ans,cnt)

ans = n*2 - ans
print(ans)

Submission status: Accepted

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

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

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+N)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())

S = input()
T = input()
x = 0
for i in range(N, 0, -1):
    if S[-i:] == T[:i]:
        x = i
        break
        
print(N*2-x)

Submission status: Accepted

Solution code:
from sys import stdin


def main():
    input = lambda: stdin.readline()[:-1]
    N = int(input())
    S = input()
    T = input()

    for i in range(N):
        j = 0
        for k in range(i, N):
            if S[k] != T[j]:
                break
            j += 1
        else:
            print(N * 2 - j)
            return
    print(N * 2)


main()

Submission status: Accepted

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

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

Submission status: Accepted

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

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

cnt = 0
for i in range(N):
  tmp_s = s[i:]
  tmp_t = t if i == 0 else t[:-i]

  tmp_cnt = 0
  for j in range(len(tmp_s)):
    if tmp_s[j] == tmp_t[j]:
      tmp_cnt += 1

  cnt = max(cnt, tmp_cnt)

print(2 * N - cnt)

Submission status: Accepted

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

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

for i in reversed(range(n)):
    tmp = s + t[i:]
    if tmp.startswith(s) and tmp.endswith(t):
        print(len(tmp))
        exit()

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:
#!/usr/bin/env python

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

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

print(len(ans))

Submission status: Accepted

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

if (n == len(s) and (s == t)):
    print(n)
else:
    ind = [0]
    for i in range(1, len(s)):
        if s[-i:] == t[:i]:
            ind.append(i)

    ind.reverse()
    for i in ind:
        if i == 0:
            print(2*n)
        else:
            res = s[0:-i] + t
            if len(res) >= n:
                print(len(res))
                break

Submission status: Accepted

Solution code:
N=int(input())
a=input()
b=input()
ans=2*N

for i in range(1,N+1):
    if a[N-i:]==b[:i]:
        ans=2*N-i

print(ans)

Submission status: Accepted

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

    ans = 2 * N
    for i in range(N):
        s_ = s[i:]
        t_ = t[:len(t) - i]

        if s_ == t_:
            tmp = s + t[len(t) - i:]
            ans = min(ans, len(tmp))

    print(ans)

if __name__ == "__main__":
    main()

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:
n=input()
s=raw_input()
t=raw_input()
for i in xrange(0,n+1):
	if s[i:n]==t[0:n-i]:
		print n+i
		break

Submission status: Accepted

Solution code:
N = int(input())
s = input()
t = input()
idx = 0
for i in range(N):
    tmp_s = s[N - i - 1:]
    tmp_t = t[:i + 1]
    if tmp_s == tmp_t:
        idx = i + 1

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

Submission status: Accepted

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

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

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,permutations,accumulate # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入
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 = I()
s = input()
t = input()
same = 0
for i in range(n):
    #print(s[n-i-1:], t[:i+1])
    if s[n-i-1:] == t[:i+1]:
        same = i+1
print(len(s) + len(t) - same)

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(N,0,-1):
    if S[-i:] == T[:i]:
        print(N*2 - i)
        exit()
print(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(2*N - (N-i))
        exit()
print(2*N)

Submission status: Accepted

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

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

  else:
    cnt+=1
print(n*2)

Submission status: Accepted

Solution code:
# AtCoder Grand Contest 006
# A - Prefix and Suffix

def f(word,N,S,T):
    if word[:N]==S and word[-N:]==T:
        return True
    else :
        return False


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

ans = N*2

for i in range (N):
    t=T[N-i:]
    word=S+t

    if f(word,N,S,T):
        if ans>len(word):
            ans=len(word)
    else:
        pass

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:
#!/usr/bin/env python3

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


def main():
  N = int(input())
  s = input()
  t = input()
  print(solve(N,s,t))
  return

if __name__ == '__main__':
  main()

Submission status: Accepted

Solution code:
import sys
import math
def I():return int(sys.stdin.readline().replace("\n",""))
def I2():return map(int,sys.stdin.readline().replace("\n","").split())
def S():return str(sys.stdin.readline().replace("\n",""))
def L():return list(sys.stdin.readline().replace("\n",""))
def Intl():return [int(k) for k in sys.stdin.readline().replace("\n","").split()]
def Lx(k):return list(map(lambda x:int(x)*-k,sys.stdin.readline().replace("\n","").split()))

if __name__ == "__main__":
    n = I()
    s = S()
    t = S()
    cnt = 0
    for i in range(n):
        #print(s[i:n],t[:n-i])
        now = 0
        for j in range(n-i):
            if s[i:n][j] == t[:n-i][j]:now += 1
        cnt = max(cnt,now)
    print(2 * n - cnt)

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

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

if lst:
    print(min(lst))
else:
    print(n*2)

Submission status: Accepted

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

ans = n

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

print(ans)

Submission status: Accepted

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

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

print(2*n-match)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
n = int(input())
s = input()
t = input()
ans = n * 2
for i in range(n):
    if s[-i-1:] == t[:i+1]:
        ans = n * 2 - i - 1
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

import re 


ans=s

k=-1
for i in range(n):
    tmp=''.join(t[:i+1])

    if tmp in ans:
        k=i

if k<n-1:
    ans+=''.join(t[k+1:])

print(len(ans))

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

for i in range(n+1):
    check=True
    for j in range(n-i):
        if s[i+j]!=t[j]:
            check=False

    if check:
        ans=i+n
        print(ans)
        sys.exit()

Submission status: Accepted

Solution code:
n = int(input())
s = input()
t = input()
p = n * 2

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

print(p)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
N = int(input())
s = input()
t = input()
for i in range(N):
    flg = True
    for j in range(N - i):
        if s[i + j] != t[j]:
            flg = False
            break
    if flg:
        print(N + i)
        sys.exit()
print(2 * N)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


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

    for i in range(n + 1):
        flag = True
        for j in range(n - i):
            if s[i + j] != t[j]:
                flag = False
                break
        if flag:
            return print(n + i)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# 2020/07/15
# AtCoder Grand Contest 006 - A

# Input
n = int(input())
s = input()
t = input()
ans = n * 2

for i in range(n):
    j = 0
    while i + j < n :
        if s[i+j] != t[j]:
            break
        j = j + 1

    if i + j == n:
        ans = j + i * 2
        break

print(ans)

Submission status: Accepted

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

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