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

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

s += "🐧"

wow = 0
yeah = []
for i in range(len(s)-1):
    if s[i] != s[i+1]:
        wow += 1
        yeah.append((s[i], wow))
        wow = 0
    else:
        wow += 1

ans = sum(c // 2 for _, c in yeah) * k

if s[0] == s[-2]:
    katakuna = yeah[0][1]
    ijippari = yeah[-1][1]
    te = katakuna // 2 + ijippari // 2 - (katakuna + ijippari) // 2
    ans -= te * (k - 1)

print(ans) s = input() s 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 s += "🐧" s "🐧" wow = 0 wow 0 yeah = [] yeah [] for i in range(len(s)-1):
    if s[i] != s[i+1]:
        wow += 1
        yeah.append((s[i], wow))
        wow = 0
    else:
        wow += 1 i range(len(s)-1) range len(s)-1 len(s) len s 1 if s[i] != s[i+1]:
        wow += 1
        yeah.append((s[i], wow))
        wow = 0
    else:
        wow += 1 s[i] != s[i+1] s[i] s i s[i+1] s i+1 i 1 wow += 1 wow 1 yeah.append((s[i], wow)) yeah.append yeah append (s[i], wow) s[i] s i wow wow = 0 wow 0 wow += 1 wow 1 ans = sum(c // 2 for _, c in yeah) * k ans sum(c // 2 for _, c in yeah) * k sum(c // 2 for _, c in yeah) sum c // 2 c 2 k if s[0] == s[-2]:
    katakuna = yeah[0][1]
    ijippari = yeah[-1][1]
    te = katakuna // 2 + ijippari // 2 - (katakuna + ijippari) // 2
    ans -= te * (k - 1) s[0] == s[-2] s[0] s 0 s[-2] s -2 katakuna = yeah[0][1] katakuna yeah[0][1] [0] yeah 0 1 ijippari = yeah[-1][1] ijippari yeah[-1][1] [-1] yeah -1 1 te = katakuna // 2 + ijippari // 2 - (katakuna + ijippari) // 2 te katakuna // 2 + ijippari // 2 - (katakuna + ijippari) // 2 katakuna // 2 + ijippari // 2 katakuna // 2 katakuna 2 ijippari // 2 ijippari 2 (katakuna + ijippari) // 2 katakuna + ijippari katakuna ijippari 2 ans -= te * (k - 1) ans te * (k - 1) te k - 1 k 1 print(ans) print ans s += "🐧" "🐧" s yeah = [] [] yeah ans = sum(c // 2 for _, c in yeah) * k sum(c // 2 for _, c in yeah) * k ans wow += 1 1 wow k = int(input()) int(input()) k s = input() input() s katakuna = yeah[0][1] yeah[0][1] katakuna wow = 0 0 wow ijippari = yeah[-1][1] yeah[-1][1] ijippari te = katakuna // 2 + ijippari // 2 - (katakuna + ijippari) // 2 katakuna // 2 + ijippari // 2 - (katakuna + ijippari) // 2 te wow += 1 1 wow wow = 0 0 wow ans -= te * (k - 1) te * (k - 1) ans
s = input()
k = int(input())

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

s += "🐧"

wow = 0
yeah = []
for i in range(len(s)-1):
    if s[i] != s[i+1]:
        wow += 1
        yeah.append((s[i], wow))
        wow = 0
    else:
        wow += 1

ans = sum(c // 2 for _, c in yeah) * k

if s[0] == s[-2]:
    katakuna = yeah[0][1]
    ijippari = yeah[-1][1]
    te = katakuna // 2 + ijippari // 2 - (katakuna + ijippari) // 2
    ans -= te * (k - 1)

print(ans)