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

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

tmp = list(s * 2)
for i in range(len(tmp)-1):
    if i < len(s) and tmp[i] == tmp[i+1]:
        tmp[i + 1] = "#"
    elif i >= len(s) and tmp[i] == tmp[i+1]:
        tmp[i + 1] = "#"

fst = tmp[:len(s)].count("#")
snd = tmp[len(s):].count("#")

if k == 1:
    print(fst)
else:
    print(fst + snd * (k-1)) 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 tmp = list(s * 2) tmp list(s * 2) list s * 2 s 2 for i in range(len(tmp)-1):
    if i < len(s) and tmp[i] == tmp[i+1]:
        tmp[i + 1] = "#"
    elif i >= len(s) and tmp[i] == tmp[i+1]:
        tmp[i + 1] = "#" i range(len(tmp)-1) range len(tmp)-1 len(tmp) len tmp 1 if i < len(s) and tmp[i] == tmp[i+1]:
        tmp[i + 1] = "#"
    elif i >= len(s) and tmp[i] == tmp[i+1]:
        tmp[i + 1] = "#" i < len(s) and tmp[i] == tmp[i+1] i < len(s) i len(s) len s tmp[i] == tmp[i+1] tmp[i] tmp i tmp[i+1] tmp i+1 i 1 tmp[i + 1] = "#" tmp[i + 1] tmp i + 1 i 1 "#" elif i >= len(s) and tmp[i] == tmp[i+1]:
        tmp[i + 1] = "#" i >= len(s) and tmp[i] == tmp[i+1] i >= len(s) i len(s) len s tmp[i] == tmp[i+1] tmp[i] tmp i tmp[i+1] tmp i+1 i 1 tmp[i + 1] = "#" tmp[i + 1] tmp i + 1 i 1 "#" fst = tmp[:len(s)].count("#") fst tmp[:len(s)].count("#") [:len(s)].count [:len(s)] tmp :len(s) len(s) len s count "#" snd = tmp[len(s):].count("#") snd tmp[len(s):].count("#") [len(s):].count [len(s):] tmp len(s): len(s) len s count "#" if k == 1:
    print(fst)
else:
    print(fst + snd * (k-1)) k == 1 k 1 print(fst) print fst print(fst + snd * (k-1)) print fst + snd * (k-1) fst snd * (k-1) snd k-1 k 1 s = input() input() s k = int(input()) int(input()) k tmp = list(s * 2) list(s * 2) tmp fst = tmp[:len(s)].count("#") tmp[:len(s)].count("#") fst snd = tmp[len(s):].count("#") tmp[len(s):].count("#") snd
s = input()
k = int(input())

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

tmp = list(s * 2)
for i in range(len(tmp)-1):
    if i < len(s) and tmp[i] == tmp[i+1]:
        tmp[i + 1] = "#"
    elif i >= len(s) and tmp[i] == tmp[i+1]:
        tmp[i + 1] = "#"

fst = tmp[:len(s)].count("#")
snd = tmp[len(s):].count("#")

if k == 1:
    print(fst)
else:
    print(fst + snd * (k-1))