N = int(input())
b = input()
g = input()
bride = []
groom = []

for i in range(N):
  a = b[i]
  bride.append(a)

for i in range(N):
  a = g[i]
  groom.append(a)  

count = N

front = 0
c = 0

for i in range(N*N):
  if(len(bride) == 0):
    break
    
  if(bride[front] == groom[front]):
    bride.pop(front)
    groom.pop(front)
    count -= 1
    c = 0
    continue

  else:
    a = groom.pop(0)
    groom.append(a)
    c += 1
    
    if(c >= N):
      break

print(count)
print("\n")
a842f513f9e221d253f2693e9bd1a6fab20c1c00
<mask token>

<mask token>
for i in range(N):
    a = b[i]
    bride.append(a)
for i in range(N):
    a = g[i]
    groom.append(a)
<mask token>
for i in range(N * N):
    if len(bride) == 0:
        break
    if bride[front] == groom[front]:
        bride.pop(front)
        groom.pop(front)
        count -= 1
        c = 0
        continue
    else:
        a = groom.pop(0)
        groom.append(a)
        c += 1
        if c >= N:
            break
print(count)
print('\n')

N = int(input())
b = input()
g = input()
bride = []
groom = []
for i in range(N):
    a = b[i]
    bride.append(a)
for i in range(N):
    a = g[i]
    groom.append(a)
count = N
front = 0
c = 0
for i in range(N * N):
    if len(bride) == 0:
        break
    if bride[front] == groom[front]:
        bride.pop(front)
        groom.pop(front)
        count -= 1
        c = 0
        continue
    else:
        a = groom.pop(0)
        groom.append(a)
        c += 1
        if c >= N:
            break
print(count)
print('\n')

N = int(input())
b = input()
g = input()
bride = []
groom = []

for i in range(N):
  a = b[i]
  bride.append(a)

for i in range(N):
  a = g[i]
  groom.append(a)  

count = N

front = 0
c = 0

for i in range(N*N):
  if(len(bride) == 0):
    break
    
  if(bride[front] == groom[front]):
    bride.pop(front)
    groom.pop(front)
    count -= 1
    c = 0
    continue

  else:
    a = groom.pop(0)
    groom.append(a)
    c += 1
    
    if(c >= N):
      break

print(count)
print("\n")