s = input()
k = int(input())
n = len(s)
res = 0
i = 0
if s.count(s[0]) == n:#全て同じ文字
    print(n*k//2)
    exit()

while i < n-1:
    if s[i] == s[i+1]:
        res += 1
        i += 1
    i += 1

res *= k

if s[0] != s[n-1]: #先頭と末尾の文字が異なる
    print(res)
else:
    a = 0
    b = 0
    i = 0
    while s[i] == s[0]:
        a += 1
        i += 1
    while s[n-1] == s[0]:
        b += 1
        n -= 1
    res -= ((a//2)+(b//2)-((a+b)//2))*(k-1)
    print(res) s = input() s input() input k = int(input()) k int(input()) int input() input n = len(s) n len(s) len s res = 0 res 0 i = 0 i 0 if s.count(s[0]) == n:#全て同じ文字
    print(n*k//2)
    exit() s.count(s[0]) == n s.count(s[0]) s.count s count s[0] s 0 n print(n*k//2) print n*k//2 n*k n k 2 exit() exit while i < n-1:
    if s[i] == s[i+1]:
        res += 1
        i += 1
    i += 1 i < n-1 i n-1 n 1 if s[i] == s[i+1]:
        res += 1
        i += 1
     s[i] == s[i+1] s[i] s i s[i+1] s i+1 i 1 res += 1 res 1 i += 1 i 1 i += 1 i 1 res *= k res k if s[0] != s[n-1]: #先頭と末尾の文字が異なる
    print(res)
else:
    a = 0
    b = 0
    i = 0
    while s[i] == s[0]:
        a += 1
        i += 1
    while s[n-1] == s[0]:
        b += 1
        n -= 1
    res -= ((a//2)+(b//2)-((a+b)//2))*(k-1)
    print(res) s[0] != s[n-1] s[0] s 0 s[n-1] s n-1 n 1 print(res) print res a = 0 a 0 b = 0 b 0 i = 0 i 0 while s[i] == s[0]:
        a += 1
        i += 1
     s[i] == s[0] s[i] s i s[0] s 0 a += 1 a 1 i += 1 i 1 while s[n-1] == s[0]:
        b += 1
        n -= 1
     s[n-1] == s[0] s[n-1] s n-1 n 1 s[0] s 0 b += 1 b 1 n -= 1 n 1 res -= ((a//2)+(b//2)-((a+b)//2))*(k-1) res ((a//2)+(b//2)-((a+b)//2))*(k-1) (a//2)+(b//2)-((a+b)//2) (a//2)+(b//2) a//2 a 2 b//2 b 2 (a+b)//2 a+b a b 2 k-1 k 1 print(res) print res k = int(input()) int(input()) k res *= k k res n = len(s) len(s) n i = 0 0 i res -= ((a//2)+(b//2)-((a+b)//2))*(k-1) ((a//2)+(b//2)-((a+b)//2))*(k-1) res s = input() input() s i += 1 1 i b += 1 1 b a += 1 1 a res = 0 0 res i = 0 0 i res += 1 1 res i += 1 1 i i += 1 1 i a = 0 0 a b = 0 0 b n -= 1 1 n
s = input()
k = int(input())
n = len(s)
res = 0
i = 0
if s.count(s[0]) == n:#全て同じ文字
    print(n*k//2)
    exit()

while i < n-1:
    if s[i] == s[i+1]:
        res += 1
        i += 1
    i += 1

res *= k

if s[0] != s[n-1]: #先頭と末尾の文字が異なる
    print(res)
else:
    a = 0
    b = 0
    i = 0
    while s[i] == s[0]:
        a += 1
        i += 1
    while s[n-1] == s[0]:
        b += 1
        n -= 1
    res -= ((a//2)+(b//2)-((a+b)//2))*(k-1)
    print(res)