from math import floor
s = input()
k = int(input())
if len(set(s)) == 1:
    print(floor(len(s) * k / 2))
    exit(0)
x = s[0]
y = 1
ans = 0
for i in s[1:]:
    if i == x:
        y += 1
    else:
        ans += floor(y / 2)
        x = i
        y = 1
ans += floor(y / 2)
if s[0] != s[-1]:
    print(ans * k)
else:
    x = s[0]
    y = 1
    for i in s[1:]:
        if x == i:
            y += 1
        else:
            a = y
            break
    y = 0
    for i in s[::-1]:
        if x == i:
            y += 1
        else:
            b = y
            break
    print(ans * k - ((floor(a / 2) + floor(b / 2) - floor((a + b) / 2)) * (k - 1))) from math import floor s = input() s input() input k = int(input()) k int(input()) int input() input if len(set(s)) == 1:
    print(floor(len(s) * k / 2))
    exit(0) len(set(s)) == 1 len(set(s)) len set(s) set s 1 print(floor(len(s) * k / 2)) print floor(len(s) * k / 2) floor len(s) * k / 2 len(s) * k len(s) len s k 2 exit(0) exit 0 x = s[0] x s[0] s 0 y = 1 y 1 ans = 0 ans 0 for i in s[1:]:
    if i == x:
        y += 1
    else:
        ans += floor(y / 2)
        x = i
        y = 1 i s[1:] s 1: 1 if i == x:
        y += 1
    else:
        ans += floor(y / 2)
        x = i
        y = 1 i == x i x y += 1 y 1 ans += floor(y / 2) ans floor(y / 2) floor y / 2 y 2 x = i x i y = 1 y 1 ans += floor(y / 2) ans floor(y / 2) floor y / 2 y 2 if s[0] != s[-1]:
    print(ans * k)
else:
    x = s[0]
    y = 1
    for i in s[1:]:
        if x == i:
            y += 1
        else:
            a = y
            break
    y = 0
    for i in s[::-1]:
        if x == i:
            y += 1
        else:
            b = y
            break
    print(ans * k - ((floor(a / 2) + floor(b / 2) - floor((a + b) / 2)) * (k - 1))) s[0] != s[-1] s[0] s 0 s[-1] s -1 print(ans * k) print ans * k ans k x = s[0] x s[0] s 0 y = 1 y 1 for i in s[1:]:
        if x == i:
            y += 1
        else:
            a = y
            break
     i s[1:] s 1: 1 if x == i:
            y += 1
        else:
            a = y
            break
     x == i x i y += 1 y 1 a = y a y break y = 0 y 0 for i in s[::-1]:
        if x == i:
            y += 1
        else:
            b = y
            break
     i s[::-1] s ::-1 -1 if x == i:
            y += 1
        else:
            b = y
            break
     x == i x i y += 1 y 1 b = y b y break print(ans * k - ((floor(a / 2) + floor(b / 2) - floor((a + b) / 2)) * (k - 1))) print ans * k - ((floor(a / 2) + floor(b / 2) - floor((a + b) / 2)) * (k - 1)) ans * k ans k (floor(a / 2) + floor(b / 2) - floor((a + b) / 2)) * (k - 1) floor(a / 2) + floor(b / 2) - floor((a + b) / 2) floor(a / 2) + floor(b / 2) floor(a / 2) floor a / 2 a 2 floor(b / 2) floor b / 2 b 2 floor((a + b) / 2) floor (a + b) / 2 a + b a b 2 k - 1 k 1 ans = 0 0 ans y = 1 1 y y = 1 1 y a = y y a y += 1 1 y y += 1 1 y s = input() input() s b = y y b y = 1 1 y y += 1 1 y x = i i x y = 0 0 y x = s[0] s[0] x x = s[0] s[0] x ans += floor(y / 2) floor(y / 2) ans ans += floor(y / 2) floor(y / 2) ans k = int(input()) int(input()) k
from math import floor
s = input()
k = int(input())
if len(set(s)) == 1:
    print(floor(len(s) * k / 2))
    exit(0)
x = s[0]
y = 1
ans = 0
for i in s[1:]:
    if i == x:
        y += 1
    else:
        ans += floor(y / 2)
        x = i
        y = 1
ans += floor(y / 2)
if s[0] != s[-1]:
    print(ans * k)
else:
    x = s[0]
    y = 1
    for i in s[1:]:
        if x == i:
            y += 1
        else:
            a = y
            break
    y = 0
    for i in s[::-1]:
        if x == i:
            y += 1
        else:
            b = y
            break
    print(ans * k - ((floor(a / 2) + floor(b / 2) - floor((a + b) / 2)) * (k - 1)))