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

# In[8]:


S = input()
K = int(input())


# In[10]:


cnt = 0
ans = 0
tmp = S[0]
fcnt = 0
for s in S:
    if tmp == s:
        cnt += 1
        tmp = s
    else:
        ans += cnt//2
        if fcnt == 0:
            fcnt = cnt
        cnt = 1
        tmp = s
if fcnt == 0:
    fcnt = cnt
ans += cnt//2
ans *= K

if len(S) == fcnt:
    ans = (len(S)*K)//2
elif S[0] == S[-1]:
    ans -= (fcnt//2 + cnt//2 - (fcnt+cnt)//2) * (K-1)
print(ans)


# In[ ]:



 S = input() S input() input K = int(input()) K int(input()) int input() input cnt = 0 cnt 0 ans = 0 ans 0 tmp = S[0] tmp S[0] S 0 fcnt = 0 fcnt 0 for s in S:
    if tmp == s:
        cnt += 1
        tmp = s
    else:
        ans += cnt//2
        if fcnt == 0:
            fcnt = cnt
        cnt = 1
        tmp = s s S if tmp == s:
        cnt += 1
        tmp = s
    else:
        ans += cnt//2
        if fcnt == 0:
            fcnt = cnt
        cnt = 1
        tmp = s tmp == s tmp s cnt += 1 cnt 1 tmp = s tmp s ans += cnt//2 ans cnt//2 cnt 2 if fcnt == 0:
            fcnt = cnt
         fcnt == 0 fcnt 0 fcnt = cnt fcnt cnt cnt = 1 cnt 1 tmp = s tmp s if fcnt == 0:
    fcnt = cnt fcnt == 0 fcnt 0 fcnt = cnt fcnt cnt ans += cnt//2 ans cnt//2 cnt 2 ans *= K ans K if len(S) == fcnt:
    ans = (len(S)*K)//2
elif S[0] == S[-1]:
    ans -= (fcnt//2 + cnt//2 - (fcnt+cnt)//2) * (K-1) len(S) == fcnt len(S) len S fcnt ans = (len(S)*K)//2 ans (len(S)*K)//2 len(S)*K len(S) len S K 2 elif S[0] == S[-1]:
    ans -= (fcnt//2 + cnt//2 - (fcnt+cnt)//2) * (K-1) S[0] == S[-1] S[0] S 0 S[-1] S -1 ans -= (fcnt//2 + cnt//2 - (fcnt+cnt)//2) * (K-1) ans (fcnt//2 + cnt//2 - (fcnt+cnt)//2) * (K-1) fcnt//2 + cnt//2 - (fcnt+cnt)//2 fcnt//2 + cnt//2 fcnt//2 fcnt 2 cnt//2 cnt 2 (fcnt+cnt)//2 fcnt+cnt fcnt cnt 2 K-1 K 1 print(ans) print ans ans += cnt//2 cnt//2 ans cnt = 1 1 cnt ans *= K K ans fcnt = 0 0 fcnt tmp = s s tmp fcnt = cnt cnt fcnt cnt = 0 0 cnt ans = (len(S)*K)//2 (len(S)*K)//2 ans ans -= (fcnt//2 + cnt//2 - (fcnt+cnt)//2) * (K-1) (fcnt//2 + cnt//2 - (fcnt+cnt)//2) * (K-1) ans cnt += 1 1 cnt tmp = S[0] S[0] tmp K = int(input()) int(input()) K tmp = s s tmp S = input() input() S ans += cnt//2 cnt//2 ans ans = 0 0 ans fcnt = cnt cnt fcnt
#!/usr/bin/env python
# coding: utf-8

# In[8]:


S = input()
K = int(input())


# In[10]:


cnt = 0
ans = 0
tmp = S[0]
fcnt = 0
for s in S:
    if tmp == s:
        cnt += 1
        tmp = s
    else:
        ans += cnt//2
        if fcnt == 0:
            fcnt = cnt
        cnt = 1
        tmp = s
if fcnt == 0:
    fcnt = cnt
ans += cnt//2
ans *= K

if len(S) == fcnt:
    ans = (len(S)*K)//2
elif S[0] == S[-1]:
    ans -= (fcnt//2 + cnt//2 - (fcnt+cnt)//2) * (K-1)
print(ans)


# In[ ]:




