import math
s = list(input())
ss = s[:]
k = int(input())
cnt = 0

if len(set(s)) == 1:
    cnt = math.floor(len(s) * k / 2)
else:
    cnt = 0
    for i in range(len(s) - 1):
        if s[i] == s[i + 1]:
            cnt += 1
            s[i + 1] = '*'
    cnt *= k
    if ss[0] == ss[-1]:
        a = 1
        for i in range(len(ss) - 1):
            if ss[i] == ss[i + 1]:
                a += 1
            else:
                break
        b = 1
        for j in range(len(ss) - 1, 0, -1):
            if ss[j] == ss[j - 1]:
                b += 1
            else:
                break
        cnt -= (k - 1) * (math.floor(a / 2) + math.floor(b / 2) - math.floor((a + b) / 2))
print(cnt) import math math s = list(input()) s list(input()) list input() input ss = s[:] ss s[:] s : k = int(input()) k int(input()) int input() input cnt = 0 cnt 0 if len(set(s)) == 1:
    cnt = math.floor(len(s) * k / 2)
else:
    cnt = 0
    for i in range(len(s) - 1):
        if s[i] == s[i + 1]:
            cnt += 1
            s[i + 1] = '*'
    cnt *= k
    if ss[0] == ss[-1]:
        a = 1
        for i in range(len(ss) - 1):
            if ss[i] == ss[i + 1]:
                a += 1
            else:
                break
        b = 1
        for j in range(len(ss) - 1, 0, -1):
            if ss[j] == ss[j - 1]:
                b += 1
            else:
                break
        cnt -= (k - 1) * (math.floor(a / 2) + math.floor(b / 2) - math.floor((a + b) / 2)) len(set(s)) == 1 len(set(s)) len set(s) set s 1 cnt = math.floor(len(s) * k / 2) cnt math.floor(len(s) * k / 2) math.floor math floor len(s) * k / 2 len(s) * k len(s) len s k 2 cnt = 0 cnt 0 for i in range(len(s) - 1):
        if s[i] == s[i + 1]:
            cnt += 1
            s[i + 1] = '*'
     i range(len(s) - 1) range len(s) - 1 len(s) len s 1 if s[i] == s[i + 1]:
            cnt += 1
            s[i + 1] = '*'
     s[i] == s[i + 1] s[i] s i s[i + 1] s i + 1 i 1 cnt += 1 cnt 1 s[i + 1] = '*' s[i + 1] s i + 1 i 1 '*' cnt *= k cnt k if ss[0] == ss[-1]:
        a = 1
        for i in range(len(ss) - 1):
            if ss[i] == ss[i + 1]:
                a += 1
            else:
                break
        b = 1
        for j in range(len(ss) - 1, 0, -1):
            if ss[j] == ss[j - 1]:
                b += 1
            else:
                break
        cnt -= (k - 1) * (math.floor(a / 2) + math.floor(b / 2) - math.floor((a + b) / 2)) ss[0] == ss[-1] ss[0] ss 0 ss[-1] ss -1 a = 1 a 1 for i in range(len(ss) - 1):
            if ss[i] == ss[i + 1]:
                a += 1
            else:
                break
         i range(len(ss) - 1) range len(ss) - 1 len(ss) len ss 1 if ss[i] == ss[i + 1]:
                a += 1
            else:
                break
         ss[i] == ss[i + 1] ss[i] ss i ss[i + 1] ss i + 1 i 1 a += 1 a 1 break b = 1 b 1 for j in range(len(ss) - 1, 0, -1):
            if ss[j] == ss[j - 1]:
                b += 1
            else:
                break
         j range(len(ss) - 1, 0, -1) range len(ss) - 1 len(ss) len ss 1 0 -1 if ss[j] == ss[j - 1]:
                b += 1
            else:
                break
         ss[j] == ss[j - 1] ss[j] ss j ss[j - 1] ss j - 1 j 1 b += 1 b 1 break cnt -= (k - 1) * (math.floor(a / 2) + math.floor(b / 2) - math.floor((a + b) / 2)) cnt (k - 1) * (math.floor(a / 2) + math.floor(b / 2) - math.floor((a + b) / 2)) k - 1 k 1 math.floor(a / 2) + math.floor(b / 2) - math.floor((a + b) / 2) math.floor(a / 2) + math.floor(b / 2) math.floor(a / 2) math.floor math floor a / 2 a 2 math.floor(b / 2) math.floor math floor b / 2 b 2 math.floor((a + b) / 2) math.floor math floor (a + b) / 2 a + b a b 2 print(cnt) print cnt k = int(input()) int(input()) k s = list(input()) list(input()) s cnt *= k k cnt cnt = 0 0 cnt cnt = math.floor(len(s) * k / 2) math.floor(len(s) * k / 2) cnt a = 1 1 a b = 1 1 b cnt -= (k - 1) * (math.floor(a / 2) + math.floor(b / 2) - math.floor((a + b) / 2)) (k - 1) * (math.floor(a / 2) + math.floor(b / 2) - math.floor((a + b) / 2)) cnt b += 1 1 b a += 1 1 a cnt = 0 0 cnt ss = s[:] s[:] ss cnt += 1 1 cnt
import math
s = list(input())
ss = s[:]
k = int(input())
cnt = 0

if len(set(s)) == 1:
    cnt = math.floor(len(s) * k / 2)
else:
    cnt = 0
    for i in range(len(s) - 1):
        if s[i] == s[i + 1]:
            cnt += 1
            s[i + 1] = '*'
    cnt *= k
    if ss[0] == ss[-1]:
        a = 1
        for i in range(len(ss) - 1):
            if ss[i] == ss[i + 1]:
                a += 1
            else:
                break
        b = 1
        for j in range(len(ss) - 1, 0, -1):
            if ss[j] == ss[j - 1]:
                b += 1
            else:
                break
        cnt -= (k - 1) * (math.floor(a / 2) + math.floor(b / 2) - math.floor((a + b) / 2))
print(cnt)