from collections import Counter
def dd(S):
    S += "#"
    s0 = S[0]
    cnt, r = 1, 0
    for s in S[1:]:
        if s == s0:
            cnt += 1
        else:
            r += cnt // 2
            cnt = 1
        s0 = s
    return r
S = input().rstrip()
K = int(input())
s = dd(S)
t = dd(S*2)
if len(Counter(S))==1:
    print(len(S)*K//2)
else:
    print(s*K + (t-2*s)*(K-1))
"""
aaa
3
""" from collections import Counter def dd(S):
    S += "#"
    s0 = S[0]
    cnt, r = 1, 0
    for s in S[1:]:
        if s == s0:
            cnt += 1
        else:
            r += cnt // 2
            cnt = 1
        s0 = s
    return r dd S += "#" S "#" s0 = S[0] s0 S[0] S 0 cnt, r = 1, 0 cnt 1 r 0 for s in S[1:]:
        if s == s0:
            cnt += 1
        else:
            r += cnt // 2
            cnt = 1
        s0 = s
     s S[1:] S 1: 1 if s == s0:
            cnt += 1
        else:
            r += cnt // 2
            cnt = 1
         s == s0 s s0 cnt += 1 cnt 1 r += cnt // 2 r cnt // 2 cnt 2 cnt = 1 cnt 1 s0 = s s0 s return r r S S S = input().rstrip() S input().rstrip() ().rstrip () input rstrip K = int(input()) K int(input()) int input() input s = dd(S) s dd(S) dd S t = dd(S*2) t dd(S*2) dd S*2 S 2 if len(Counter(S))==1:
    print(len(S)*K//2)
else:
    print(s*K + (t-2*s)*(K-1)) len(Counter(S))==1 len(Counter(S)) len Counter(S) Counter S 1 print(len(S)*K//2) print len(S)*K//2 len(S)*K len(S) len S K 2 print(s*K + (t-2*s)*(K-1)) print s*K + (t-2*s)*(K-1) s*K s K (t-2*s)*(K-1) t-2*s t 2*s 2 s K-1 K 1 """
aaa
3
""" t = dd(S*2) dd(S*2) t s = dd(S) dd(S) s K = int(input()) int(input()) K S = input().rstrip() input().rstrip() S def dd(S):
    S += "#"
    s0 = S[0]
    cnt, r = 1, 0
    for s in S[1:]:
        if s == s0:
            cnt += 1
        else:
            r += cnt // 2
            cnt = 1
        s0 = s
    return r def dd(S):
    S += "#"
    s0 = S[0]
    cnt, r = 1, 0
    for s in S[1:]:
        if s == s0:
            cnt += 1
        else:
            r += cnt // 2
            cnt = 1
        s0 = s
    return r dd
from collections import Counter
def dd(S):
    S += "#"
    s0 = S[0]
    cnt, r = 1, 0
    for s in S[1:]:
        if s == s0:
            cnt += 1
        else:
            r += cnt // 2
            cnt = 1
        s0 = s
    return r
S = input().rstrip()
K = int(input())
s = dd(S)
t = dd(S*2)
if len(Counter(S))==1:
    print(len(S)*K//2)
else:
    print(s*K + (t-2*s)*(K-1))
"""
aaa
3
"""