import sys

readline = sys.stdin.readline
readlines = sys.stdin.readlines
ns = lambda: readline().rstrip() # input string
ni = lambda: int(readline().rstrip()) # input int
nm = lambda: map(int, readline().split()) # input multiple int 
nl = lambda: list(map(int, readline().split())) # input multiple int to list

s = ns()
k = ni()
cnt = 1
li = []
prev = '@'
for c in s:
    if c == '@':
        cnt = 1
        prev = c
        continue
    elif prev == c:
        cnt += 1
    else:
        li.append(cnt)
        cnt = 1
        prev = c
else:
    li.append(cnt)
li = li[1:]

ans_ele = 0
ans = 0
if len(set(s)) == 1:
    ans = len(s) * k // 2
elif s[0] == s[-1] and (li[0] + li[-1]) % 2 == 0:
#elif s[0] == s[-1] and li[0] == 1 and li[-1] == 1 :
    for e in li:
        if e >= 2:
            ans_ele += e // 2
    ans = ans_ele * k + k - 1
else:
    for e in li:
        if e >= 2:
            ans_ele += e // 2
    ans = ans_ele * k
print(ans)

""" same
1 ~ 1 :  + (k - 1)
2 ~ 1 : X
1 ~ 2 : X
2 ~ 2 : X
 and len(li) != 1
""" import sys sys readline = sys.stdin.readline readline sys.stdin.readline sys.stdin sys stdin readline readlines = sys.stdin.readlines readlines sys.stdin.readlines sys.stdin sys stdin readlines ns = lambda: readline().rstrip() ns lambda: readline().rstrip() readline().rstrip() ().rstrip () readline rstrip ni = lambda: int(readline().rstrip()) ni lambda: int(readline().rstrip()) int(readline().rstrip()) int readline().rstrip() ().rstrip () readline rstrip nm = lambda: map(int, readline().split()) nm lambda: map(int, readline().split()) map(int, readline().split()) map int readline().split() ().split () readline split nl = lambda: list(map(int, readline().split())) nl lambda: list(map(int, readline().split())) list(map(int, readline().split())) list map(int, readline().split()) map int readline().split() ().split () readline split s = ns() s ns() ns k = ni() k ni() ni cnt = 1 cnt 1 li = [] li [] prev = '@' prev '@' for c in s:
    if c == '@':
        cnt = 1
        prev = c
        continue
    elif prev == c:
        cnt += 1
    else:
        li.append(cnt)
        cnt = 1
        prev = c
else:
    li.append(cnt) c s if c == '@':
        cnt = 1
        prev = c
        continue
    elif prev == c:
        cnt += 1
    else:
        li.append(cnt)
        cnt = 1
        prev = c c == '@' c '@' cnt = 1 cnt 1 prev = c prev c continue elif prev == c:
        cnt += 1
     prev == c prev c cnt += 1 cnt 1 li.append(cnt) li.append li append cnt cnt = 1 cnt 1 prev = c prev c li.append(cnt) li.append li append cnt li = li[1:] li li[1:] li 1: 1 ans_ele = 0 ans_ele 0 ans = 0 ans 0 if len(set(s)) == 1:
    ans = len(s) * k // 2
elif s[0] == s[-1] and (li[0] + li[-1]) % 2 == 0:
#elif s[0] == s[-1] and li[0] == 1 and li[-1] == 1 :
    for e in li:
        if e >= 2:
            ans_ele += e // 2
    ans = ans_ele * k + k - 1
else:
    for e in li:
        if e >= 2:
            ans_ele += e // 2
    ans = ans_ele * k len(set(s)) == 1 len(set(s)) len set(s) set s 1 ans = len(s) * k // 2 ans len(s) * k // 2 len(s) * k len(s) len s k 2 elif s[0] == s[-1] and (li[0] + li[-1]) % 2 == 0:
#elif s[0] == s[-1] and li[0] == 1 and li[-1] == 1 :
    for e in li:
        if e >= 2:
            ans_ele += e // 2
    ans = ans_ele * k + k - 1 s[0] == s[-1] and (li[0] + li[-1]) % 2 == 0 s[0] == s[-1] s[0] s 0 s[-1] s -1 (li[0] + li[-1]) % 2 == 0 (li[0] + li[-1]) % 2 li[0] + li[-1] li[0] li 0 li[-1] li -1 2 0 for e in li:
        if e >= 2:
            ans_ele += e // 2
     e li if e >= 2:
            ans_ele += e // 2
     e >= 2 e 2 ans_ele += e // 2 ans_ele e // 2 e 2 ans = ans_ele * k + k - 1 ans ans_ele * k + k - 1 ans_ele * k + k ans_ele * k ans_ele k k 1 for e in li:
        if e >= 2:
            ans_ele += e // 2
     e li if e >= 2:
            ans_ele += e // 2
     e >= 2 e 2 ans_ele += e // 2 ans_ele e // 2 e 2 ans = ans_ele * k ans ans_ele * k ans_ele k print(ans) print ans """ same
1 ~ 1 :  + (k - 1)
2 ~ 1 : X
1 ~ 2 : X
2 ~ 2 : X
 and len(li) != 1
""" ni = lambda: int(readline().rstrip()) lambda: int(readline().rstrip()) ni ans = len(s) * k // 2 len(s) * k // 2 ans ans = 0 0 ans k = ni() ni() k cnt = 1 1 cnt prev = c c prev li = [] [] li ans_ele += e // 2 e // 2 ans_ele nm = lambda: map(int, readline().split()) lambda: map(int, readline().split()) nm readline = sys.stdin.readline sys.stdin.readline readline prev = '@' '@' prev ns = lambda: readline().rstrip() lambda: readline().rstrip() ns li = li[1:] li[1:] li ans = ans_ele * k + k - 1 ans_ele * k + k - 1 ans cnt = 1 1 cnt cnt += 1 1 cnt cnt = 1 1 cnt ans_ele = 0 0 ans_ele ans_ele += e // 2 e // 2 ans_ele ans = ans_ele * k ans_ele * k ans readlines = sys.stdin.readlines sys.stdin.readlines readlines prev = c c prev nl = lambda: list(map(int, readline().split())) lambda: list(map(int, readline().split())) nl s = ns() ns() s
import sys

readline = sys.stdin.readline
readlines = sys.stdin.readlines
ns = lambda: readline().rstrip() # input string
ni = lambda: int(readline().rstrip()) # input int
nm = lambda: map(int, readline().split()) # input multiple int 
nl = lambda: list(map(int, readline().split())) # input multiple int to list

s = ns()
k = ni()
cnt = 1
li = []
prev = '@'
for c in s:
    if c == '@':
        cnt = 1
        prev = c
        continue
    elif prev == c:
        cnt += 1
    else:
        li.append(cnt)
        cnt = 1
        prev = c
else:
    li.append(cnt)
li = li[1:]

ans_ele = 0
ans = 0
if len(set(s)) == 1:
    ans = len(s) * k // 2
elif s[0] == s[-1] and (li[0] + li[-1]) % 2 == 0:
#elif s[0] == s[-1] and li[0] == 1 and li[-1] == 1 :
    for e in li:
        if e >= 2:
            ans_ele += e // 2
    ans = ans_ele * k + k - 1
else:
    for e in li:
        if e >= 2:
            ans_ele += e // 2
    ans = ans_ele * k
print(ans)

""" same
1 ~ 1 :  + (k - 1)
2 ~ 1 : X
1 ~ 2 : X
2 ~ 2 : X
 and len(li) != 1
"""