s=list(input()) ;k=int(input()) ;n=len(s)
ss=s*2
import sys
mod=10**9+7 ; inf=float("inf")
from math import sqrt, ceil
from collections import deque, Counter, defaultdict #すべてのkeyが用意されてる defaultdict(int)で初期化
input=lambda: sys.stdin.readline().strip()
sys.setrecursionlimit(11451419)
from decimal import ROUND_HALF_UP,Decimal as D  #変換後の末尾桁を0や0.01で指定
  #Decimal((str(0.5)).quantize(Decimal('0'), rounding=ROUND_HALF_UP))
from functools import lru_cache
from bisect import bisect_left as bileft, bisect_right as biright
from fractions import Fraction as F  #F(a,b)で正確なa/b
#メモ化再帰defの冒頭に毎回 @lru_cache(maxsize=10**10)
#引数にlistはだめ
#######ここまでテンプレ#######
#ソート、"a"+"b"、再帰ならPython3の方がいい
#######ここから天ぷら########


if n==1:
    print(k//2);exit()

def qq(s,n):
    ans=0
    if n==2:
        if s[0]==s[1]:return 1
        return 0
    nows=s[0];now=1
    for i in range(1,n):
        if s[i]==nows:
            now+=1
        else:
            ans+= now//2
            now=1 ;nows=s[i]
    else:
        ans+=now//2
    return ans 

if len(Counter(s))==1:
    print((n*k)//2)
    exit()
if s[0]!=s[-1]:
    print(qq(s,n)*k)
    exit()
st=1; go=1
for i in range(1,n):
    if s[i]==s[0]:
        st+=1
    else:
        break
for i  in range(-2,-n-1,-1):
    if s[i]==s[-1]:
        go+=1
    else:break
print(qq(s,n)*k - (st//2+go//2-(st+go)//2)*(k-1)) s=list(input()) s list(input()) list input() input k=int(input()) k int(input()) int input() input n=len(s) n len(s) len s ss=s*2 ss s*2 s 2 import sys sys mod=10**9+7 mod 10**9+7 10**9 10 9 7 inf=float("inf") inf float("inf") float "inf" from math import sqrt, ceil from collections import deque, Counter, defaultdict input=lambda: sys.stdin.readline().strip() input lambda: sys.stdin.readline().strip() sys.stdin.readline().strip() sys.stdin.readline().strip sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline strip sys.setrecursionlimit(11451419) sys.setrecursionlimit sys setrecursionlimit 11451419 from decimal import ROUND_HALF_UP,Decimal as D from functools import lru_cache from bisect import bisect_left as bileft, bisect_right as biright from fractions import Fraction as F if n==1:
    print(k//2);exit() n==1 n 1 print(k//2) print k//2 k 2 exit() exit def qq(s,n):
    ans=0
    if n==2:
        if s[0]==s[1]:return 1
        return 0
    nows=s[0];now=1
    for i in range(1,n):
        if s[i]==nows:
            now+=1
        else:
            ans+= now//2
            now=1 ;nows=s[i]
    else:
        ans+=now//2
    return ans  qq ans=0 ans 0 if n==2:
        if s[0]==s[1]:return 1
        return 0
     n==2 n 2 if s[0]==s[1]:return 1
         s[0]==s[1] s[0] s 0 s[1] s 1 return 0 0 nows=s[0] nows s[0] s 0 now=1 now 1 for i in range(1,n):
        if s[i]==nows:
            now+=1
        else:
            ans+= now//2
            now=1 ;nows=s[i]
    else:
        ans+=now//2
     i range(1,n) range 1 n if s[i]==nows:
            now+=1
        else:
            ans+= now//2
            now=1 ;nows=s[i]
     s[i]==nows s[i] s i nows now+=1 now 1 ans+= now//2 ans now//2 now 2 now=1 now 1 nows=s[i] nows s[i] s i ans+=now//2 ans now//2 now 2 return ans ans s s n n if len(Counter(s))==1:
    print((n*k)//2)
    exit() len(Counter(s))==1 len(Counter(s)) len Counter(s) Counter s 1 print((n*k)//2) print (n*k)//2 n*k n k 2 exit() exit if s[0]!=s[-1]:
    print(qq(s,n)*k)
    exit() s[0]!=s[-1] s[0] s 0 s[-1] s -1 print(qq(s,n)*k) print qq(s,n)*k qq(s,n) qq s n k exit() exit st=1 st 1 go=1 go 1 for i in range(1,n):
    if s[i]==s[0]:
        st+=1
    else:
        break i range(1,n) range 1 n if s[i]==s[0]:
        st+=1
    else:
        break s[i]==s[0] s[i] s i s[0] s 0 st+=1 st 1 break for i  in range(-2,-n-1,-1):
    if s[i]==s[-1]:
        go+=1
    else:break i range(-2,-n-1,-1) range -2 -n-1 -n n 1 -1 if s[i]==s[-1]:
        go+=1
    else:break s[i]==s[-1] s[i] s i s[-1] s -1 go+=1 go 1 print(qq(s,n)*k - (st//2+go//2-(st+go)//2)*(k-1)) print qq(s,n)*k - (st//2+go//2-(st+go)//2)*(k-1) qq(s,n)*k qq(s,n) qq s n k (st//2+go//2-(st+go)//2)*(k-1) st//2+go//2-(st+go)//2 st//2+go//2 st//2 st 2 go//2 go 2 (st+go)//2 st+go st go 2 k-1 k 1 ss=s*2 s*2 ss def qq(s,n):
    ans=0
    if n==2:
        if s[0]==s[1]:return 1
        return 0
    nows=s[0];now=1
    for i in range(1,n):
        if s[i]==nows:
            now+=1
        else:
            ans+= now//2
            now=1 ;nows=s[i]
    else:
        ans+=now//2
    return ans  def qq(s,n):
    ans=0
    if n==2:
        if s[0]==s[1]:return 1
        return 0
    nows=s[0];now=1
    for i in range(1,n):
        if s[i]==nows:
            now+=1
        else:
            ans+= now//2
            now=1 ;nows=s[i]
    else:
        ans+=now//2
    return ans  qq n=len(s) len(s) n inf=float("inf") float("inf") inf st+=1 1 st go+=1 1 go k=int(input()) int(input()) k go=1 1 go mod=10**9+7 10**9+7 mod s=list(input()) list(input()) s input=lambda: sys.stdin.readline().strip() lambda: sys.stdin.readline().strip() input st=1 1 st
s=list(input()) ;k=int(input()) ;n=len(s)
ss=s*2
import sys
mod=10**9+7 ; inf=float("inf")
from math import sqrt, ceil
from collections import deque, Counter, defaultdict #すべてのkeyが用意されてる defaultdict(int)で初期化
input=lambda: sys.stdin.readline().strip()
sys.setrecursionlimit(11451419)
from decimal import ROUND_HALF_UP,Decimal as D  #変換後の末尾桁を0や0.01で指定
  #Decimal((str(0.5)).quantize(Decimal('0'), rounding=ROUND_HALF_UP))
from functools import lru_cache
from bisect import bisect_left as bileft, bisect_right as biright
from fractions import Fraction as F  #F(a,b)で正確なa/b
#メモ化再帰defの冒頭に毎回 @lru_cache(maxsize=10**10)
#引数にlistはだめ
#######ここまでテンプレ#######
#ソート、"a"+"b"、再帰ならPython3の方がいい
#######ここから天ぷら########


if n==1:
    print(k//2);exit()

def qq(s,n):
    ans=0
    if n==2:
        if s[0]==s[1]:return 1
        return 0
    nows=s[0];now=1
    for i in range(1,n):
        if s[i]==nows:
            now+=1
        else:
            ans+= now//2
            now=1 ;nows=s[i]
    else:
        ans+=now//2
    return ans 

if len(Counter(s))==1:
    print((n*k)//2)
    exit()
if s[0]!=s[-1]:
    print(qq(s,n)*k)
    exit()
st=1; go=1
for i in range(1,n):
    if s[i]==s[0]:
        st+=1
    else:
        break
for i  in range(-2,-n-1,-1):
    if s[i]==s[-1]:
        go+=1
    else:break
print(qq(s,n)*k - (st//2+go//2-(st+go)//2)*(k-1))
