#!/usr/bin/env python
# coding: utf-8

# In[33]:


from collections import deque
bride = "rmrm"
groom = "mmmr"
bride_list = list(bride[::-1])
groomlist = deque(groom)
status = False
for i in range(len(bride_list)):
    for j in range(len(groomlist)):
        if bride_list[-1] == groomlist[0]:
            bride_list.pop()
            groomlist.popleft()
            status=True
            break
        else:
            groomlist.rotate(-1)
            status=False
    if status==False:
        break
print(len(groomlist))    


d3a325301a926d1744347e53a730c28329d70768
<mask token>

<mask token>
for i in range(len(bride_list)):
    for j in range(len(groomlist)):
        if bride_list[-1] == groomlist[0]:
            bride_list.pop()
            groomlist.popleft()
            status = True
            break
        else:
            groomlist.rotate(-1)
            status = False
    if status == False:
        break
print(len(groomlist))

<mask token>
bride = 'rmrm'
groom = 'mmmr'
bride_list = list(bride[::-1])
groomlist = deque(groom)
status = False
for i in range(len(bride_list)):
    for j in range(len(groomlist)):
        if bride_list[-1] == groomlist[0]:
            bride_list.pop()
            groomlist.popleft()
            status = True
            break
        else:
            groomlist.rotate(-1)
            status = False
    if status == False:
        break
print(len(groomlist))

from collections import deque
bride = 'rmrm'
groom = 'mmmr'
bride_list = list(bride[::-1])
groomlist = deque(groom)
status = False
for i in range(len(bride_list)):
    for j in range(len(groomlist)):
        if bride_list[-1] == groomlist[0]:
            bride_list.pop()
            groomlist.popleft()
            status = True
            break
        else:
            groomlist.rotate(-1)
            status = False
    if status == False:
        break
print(len(groomlist))

#!/usr/bin/env python
# coding: utf-8

# In[33]:


from collections import deque
bride = "rmrm"
groom = "mmmr"
bride_list = list(bride[::-1])
groomlist = deque(groom)
status = False
for i in range(len(bride_list)):
    for j in range(len(groomlist)):
        if bride_list[-1] == groomlist[0]:
            bride_list.pop()
            groomlist.popleft()
            status=True
            break
        else:
            groomlist.rotate(-1)
            status=False
    if status==False:
        break
print(len(groomlist))    

