s = list(input())
k = int(input())

if len(set(s)) == 1:
    print((len(s)*k)//2)
    exit()

def n_change(sss):
    s = sss.copy()
    x = 0
    for i in range(1, len(s)):
        if s[i] == s[i-1]:
            s[i] = "X"
            x += 1
    return x

print(n_change(s) + (k-1) * (n_change(2*s) - n_change(s))) s = list(input()) s list(input()) list input() input k = int(input()) k int(input()) int input() input if len(set(s)) == 1:
    print((len(s)*k)//2)
    exit() len(set(s)) == 1 len(set(s)) len set(s) set s 1 print((len(s)*k)//2) print (len(s)*k)//2 len(s)*k len(s) len s k 2 exit() exit def n_change(sss):
    s = sss.copy()
    x = 0
    for i in range(1, len(s)):
        if s[i] == s[i-1]:
            s[i] = "X"
            x += 1
    return x n_change s = sss.copy() s sss.copy() sss.copy sss copy x = 0 x 0 for i in range(1, len(s)):
        if s[i] == s[i-1]:
            s[i] = "X"
            x += 1
     i range(1, len(s)) range 1 len(s) len s if s[i] == s[i-1]:
            s[i] = "X"
            x += 1
     s[i] == s[i-1] s[i] s i s[i-1] s i-1 i 1 s[i] = "X" s[i] s i "X" x += 1 x 1 return x x sss sss print(n_change(s) + (k-1) * (n_change(2*s) - n_change(s))) print n_change(s) + (k-1) * (n_change(2*s) - n_change(s)) n_change(s) n_change s (k-1) * (n_change(2*s) - n_change(s)) k-1 k 1 n_change(2*s) - n_change(s) n_change(2*s) n_change 2*s 2 s n_change(s) n_change s s = list(input()) list(input()) s def n_change(sss):
    s = sss.copy()
    x = 0
    for i in range(1, len(s)):
        if s[i] == s[i-1]:
            s[i] = "X"
            x += 1
    return x def n_change(sss):
    s = sss.copy()
    x = 0
    for i in range(1, len(s)):
        if s[i] == s[i-1]:
            s[i] = "X"
            x += 1
    return x n_change k = int(input()) int(input()) k
s = list(input())
k = int(input())

if len(set(s)) == 1:
    print((len(s)*k)//2)
    exit()

def n_change(sss):
    s = sss.copy()
    x = 0
    for i in range(1, len(s)):
        if s[i] == s[i-1]:
            s[i] = "X"
            x += 1
    return x

print(n_change(s) + (k-1) * (n_change(2*s) - n_change(s)))