s = list(input())

k = int(input())

n = len(s)

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

k = int(input())

n = len(s)

if(len(set(s)) == 1):
    print(n*k//2)
else:
    t = 0
    c = 1
    for i in range(n-1):
        if(s[i] == s[i+1]):
            c += 1
        else:
            t += c // 2
            c = 1
    t += c // 2
    if(s[0] != s[-1]):
        print(t*k)
    else:
        a = 0
        b = 0
        for i in range(n):
            if(s[i] == s[0]):a+=1
            else:break
        for i in range(n)[::-1]:
            if(s[i] == s[-1]):b+=1
            else:break
        print(t*k - (a//2 + b//2 - (a+b)//2) * (k-1))