s=input()
k=int(input())
n = len(s)
same = True
for i in range(1,len(s)):
    if s[i]!=s[i-1]:
        same = False
if same:
    print(len(s)*k//2)
    exit()

for i in range(1,len(s)):
    if s[i] != s[i-1]:
        before = i-1
        break
for i in range(len(s)-1,-1,-1):
    if s[i] != s[i-1]:
        after = i
        break

ans = (before+1)//2 
ans += (len(s)-after)//2
if s[0] == s[-1]:
    ans += (before + 1 + len(s) - after)//2 * (k-1)
else:
    ans += ((before+1)//2  + (len(s)-after)//2)*(k-1)
cnt = 1
for i in range(before+2, after):
    if s[i] != s[i-1]:
        ans += cnt //2 *k
        cnt = 1
    else:
        cnt +=1
ans += cnt //2 * k
print(ans) s=input() s input() input k=int(input()) k int(input()) int input() input n = len(s) n len(s) len s same = True same True for i in range(1,len(s)):
    if s[i]!=s[i-1]:
        same = False i range(1,len(s)) range 1 len(s) len s if s[i]!=s[i-1]:
        same = False s[i]!=s[i-1] s[i] s i s[i-1] s i-1 i 1 same = False same False if same:
    print(len(s)*k//2)
    exit() same print(len(s)*k//2) print len(s)*k//2 len(s)*k len(s) len s k 2 exit() exit for i in range(1,len(s)):
    if s[i] != s[i-1]:
        before = i-1
        break i range(1,len(s)) range 1 len(s) len s if s[i] != s[i-1]:
        before = i-1
        break s[i] != s[i-1] s[i] s i s[i-1] s i-1 i 1 before = i-1 before i-1 i 1 break for i in range(len(s)-1,-1,-1):
    if s[i] != s[i-1]:
        after = i
        break i range(len(s)-1,-1,-1) range len(s)-1 len(s) len s 1 -1 -1 if s[i] != s[i-1]:
        after = i
        break s[i] != s[i-1] s[i] s i s[i-1] s i-1 i 1 after = i after i break ans = (before+1)//2 ans (before+1)//2 before+1 before 1 2 ans += (len(s)-after)//2 ans (len(s)-after)//2 len(s)-after len(s) len s after 2 if s[0] == s[-1]:
    ans += (before + 1 + len(s) - after)//2 * (k-1)
else:
    ans += ((before+1)//2  + (len(s)-after)//2)*(k-1) s[0] == s[-1] s[0] s 0 s[-1] s -1 ans += (before + 1 + len(s) - after)//2 * (k-1) ans (before + 1 + len(s) - after)//2 * (k-1) (before + 1 + len(s) - after)//2 before + 1 + len(s) - after before + 1 + len(s) before + 1 before 1 len(s) len s after 2 k-1 k 1 ans += ((before+1)//2  + (len(s)-after)//2)*(k-1) ans ((before+1)//2  + (len(s)-after)//2)*(k-1) (before+1)//2  + (len(s)-after)//2 (before+1)//2 before+1 before 1 2 (len(s)-after)//2 len(s)-after len(s) len s after 2 k-1 k 1 cnt = 1 cnt 1 for i in range(before+2, after):
    if s[i] != s[i-1]:
        ans += cnt //2 *k
        cnt = 1
    else:
        cnt +=1 i range(before+2, after) range before+2 before 2 after if s[i] != s[i-1]:
        ans += cnt //2 *k
        cnt = 1
    else:
        cnt +=1 s[i] != s[i-1] s[i] s i s[i-1] s i-1 i 1 ans += cnt //2 *k ans cnt //2 *k cnt //2 cnt 2 k cnt = 1 cnt 1 cnt +=1 cnt 1 ans += cnt //2 * k ans cnt //2 * k cnt //2 cnt 2 k print(ans) print ans ans += cnt //2 *k cnt //2 *k ans ans = (before+1)//2 (before+1)//2 ans ans += (len(s)-after)//2 (len(s)-after)//2 ans cnt +=1 1 cnt cnt = 1 1 cnt cnt = 1 1 cnt k=int(input()) int(input()) k before = i-1 i-1 before ans += ((before+1)//2  + (len(s)-after)//2)*(k-1) ((before+1)//2  + (len(s)-after)//2)*(k-1) ans after = i i after s=input() input() s n = len(s) len(s) n ans += cnt //2 * k cnt //2 * k ans ans += (before + 1 + len(s) - after)//2 * (k-1) (before + 1 + len(s) - after)//2 * (k-1) ans same = False False same same = True True same
s=input()
k=int(input())
n = len(s)
same = True
for i in range(1,len(s)):
    if s[i]!=s[i-1]:
        same = False
if same:
    print(len(s)*k//2)
    exit()

for i in range(1,len(s)):
    if s[i] != s[i-1]:
        before = i-1
        break
for i in range(len(s)-1,-1,-1):
    if s[i] != s[i-1]:
        after = i
        break

ans = (before+1)//2 
ans += (len(s)-after)//2
if s[0] == s[-1]:
    ans += (before + 1 + len(s) - after)//2 * (k-1)
else:
    ans += ((before+1)//2  + (len(s)-after)//2)*(k-1)
cnt = 1
for i in range(before+2, after):
    if s[i] != s[i-1]:
        ans += cnt //2 *k
        cnt = 1
    else:
        cnt +=1
ans += cnt //2 * k
print(ans)
