import bisect,copy,heapq,string
from collections import *
from math import *
from itertools import *
import sys
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

s = input()
k = INT()
ans = 0
cnt = 1
s = s + s

for i in range(1, len(s)):
    if s[i] == s[i-1]:
        cnt += 1
    else:
        ans += cnt // 2
        cnt = 1
ans += cnt // 2

if ans % 2 == 0 or ans == len(s)//2:
    print(ans*k//2)
else:
    print(ans//2+(ans+1)//2*(k-1)) import bisect,copy,heapq,string bisect copy heapq string from collections import * from math import * from itertools import * import sys sys def input() : return sys.stdin.readline().strip() input def INT()   : return int(input()) INT def MAP()   : return map(int,input().split()) MAP def LIST()  : return list(MAP()) LIST s = input() s input() input k = INT() k INT() INT ans = 0 ans 0 cnt = 1 cnt 1 s = s + s s s + s s s for i in range(1, len(s)):
    if s[i] == s[i-1]:
        cnt += 1
    else:
        ans += cnt // 2
        cnt = 1 i range(1, len(s)) range 1 len(s) len s if s[i] == s[i-1]:
        cnt += 1
    else:
        ans += cnt // 2
        cnt = 1 s[i] == s[i-1] s[i] s i s[i-1] s i-1 i 1 cnt += 1 cnt 1 ans += cnt // 2 ans cnt // 2 cnt 2 cnt = 1 cnt 1 ans += cnt // 2 ans cnt // 2 cnt 2 if ans % 2 == 0 or ans == len(s)//2:
    print(ans*k//2)
else:
    print(ans//2+(ans+1)//2*(k-1)) ans % 2 == 0 or ans == len(s)//2 ans % 2 == 0 ans % 2 ans 2 0 ans == len(s)//2 ans len(s)//2 len(s) len s 2 print(ans*k//2) print ans*k//2 ans*k ans k 2 print(ans//2+(ans+1)//2*(k-1)) print ans//2+(ans+1)//2*(k-1) ans//2 ans 2 (ans+1)//2*(k-1) (ans+1)//2 ans+1 ans 1 2 k-1 k 1 def input() : return sys.stdin.readline().strip() def input() : return sys.stdin.readline().strip() input ans += cnt // 2 cnt // 2 ans cnt += 1 1 cnt k = INT() INT() k s = s + s s + s s ans += cnt // 2 cnt // 2 ans def MAP()   : return map(int,input().split()) def MAP()   : return map(int,input().split()) MAP def INT()   : return int(input()) def INT()   : return int(input()) INT def LIST()  : return list(MAP()) def LIST()  : return list(MAP()) LIST s = input() input() s cnt = 1 1 cnt cnt = 1 1 cnt ans = 0 0 ans
import bisect,copy,heapq,string
from collections import *
from math import *
from itertools import *
import sys
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

s = input()
k = INT()
ans = 0
cnt = 1
s = s + s

for i in range(1, len(s)):
    if s[i] == s[i-1]:
        cnt += 1
    else:
        ans += cnt // 2
        cnt = 1
ans += cnt // 2

if ans % 2 == 0 or ans == len(s)//2:
    print(ans*k//2)
else:
    print(ans//2+(ans+1)//2*(k-1))