s = input()
k = int(input())
m = 0
j = 0
if len(set(list(s))) == 1:
    print((len(s) * k) // 2)
    exit()
for i in range(len(s)):
    if len(s) <= j + 1:
        a = m * k
        if s[0] == s[-1] == s[len(s) // 3]:
            print(a + k - 1)
        else:
            print(a)
        break
    if s[j] == s[j + 1]:
        m += 1
        j += 1
    j += 1 s = input() s input() input k = int(input()) k int(input()) int input() input m = 0 m 0 j = 0 j 0 if len(set(list(s))) == 1:
    print((len(s) * k) // 2)
    exit() len(set(list(s))) == 1 len(set(list(s))) len set(list(s)) set list(s) list s 1 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(len(s)):
    if len(s) <= j + 1:
        a = m * k
        if s[0] == s[-1] == s[len(s) // 3]:
            print(a + k - 1)
        else:
            print(a)
        break
    if s[j] == s[j + 1]:
        m += 1
        j += 1
    j += 1 i range(len(s)) range len(s) len s if len(s) <= j + 1:
        a = m * k
        if s[0] == s[-1] == s[len(s) // 3]:
            print(a + k - 1)
        else:
            print(a)
        break
     len(s) <= j + 1 len(s) len s j + 1 j 1 a = m * k a m * k m k if s[0] == s[-1] == s[len(s) // 3]:
            print(a + k - 1)
        else:
            print(a)
         s[0] == s[-1] == s[len(s) // 3] s[0] == s[-1] s[0] s 0 s[-1] s -1 s[len(s) // 3] s len(s) // 3 len(s) len s 3 print(a + k - 1) print a + k - 1 a + k a k 1 print(a) print a break if s[j] == s[j + 1]:
        m += 1
        j += 1
     s[j] == s[j + 1] s[j] s j s[j + 1] s j + 1 j 1 m += 1 m 1 j += 1 j 1 j += 1 j 1 k = int(input()) int(input()) k j += 1 1 j j += 1 1 j j = 0 0 j a = m * k m * k a m += 1 1 m s = input() input() s m = 0 0 m
s = input()
k = int(input())
m = 0
j = 0
if len(set(list(s))) == 1:
    print((len(s) * k) // 2)
    exit()
for i in range(len(s)):
    if len(s) <= j + 1:
        a = m * k
        if s[0] == s[-1] == s[len(s) // 3]:
            print(a + k - 1)
        else:
            print(a)
        break
    if s[j] == s[j + 1]:
        m += 1
        j += 1
    j += 1