def solve(S):
    pre = S[0]
    flag = False
    ans = 0
    cnt = 0
    for s in S[1:]:
        if flag:
            if pre == s:
                cnt += 1
            else:
                ans += cnt // 2
                cnt = 0
                flag = False
        else:
            if pre == s:
                cnt += 2
                flag = True
        pre = s
    if flag:
        ans += cnt // 2
    return ans


S = input()
K = int(input())
if len(S) == 1:
    print(K // 2)
elif len(S) == S.count(S[0]):
    print((len(S)*K)//2)
else:
    if K == 1:
        print(solve(S))
    elif K == 2:
        print(solve(S + S))
    else:
        ans2 = solve(S + S)
        ans3 = solve(S + S + S)
        print(ans2 + (ans3-ans2)*(K - 2)) def solve(S):
    pre = S[0]
    flag = False
    ans = 0
    cnt = 0
    for s in S[1:]:
        if flag:
            if pre == s:
                cnt += 1
            else:
                ans += cnt // 2
                cnt = 0
                flag = False
        else:
            if pre == s:
                cnt += 2
                flag = True
        pre = s
    if flag:
        ans += cnt // 2
    return ans solve pre = S[0] pre S[0] S 0 flag = False flag False ans = 0 ans 0 cnt = 0 cnt 0 for s in S[1:]:
        if flag:
            if pre == s:
                cnt += 1
            else:
                ans += cnt // 2
                cnt = 0
                flag = False
        else:
            if pre == s:
                cnt += 2
                flag = True
        pre = s
     s S[1:] S 1: 1 if flag:
            if pre == s:
                cnt += 1
            else:
                ans += cnt // 2
                cnt = 0
                flag = False
        else:
            if pre == s:
                cnt += 2
                flag = True
         flag if pre == s:
                cnt += 1
            else:
                ans += cnt // 2
                cnt = 0
                flag = False
         pre == s pre s cnt += 1 cnt 1 ans += cnt // 2 ans cnt // 2 cnt 2 cnt = 0 cnt 0 flag = False flag False if pre == s:
                cnt += 2
                flag = True
         pre == s pre s cnt += 2 cnt 2 flag = True flag True pre = s pre s if flag:
        ans += cnt // 2
     flag ans += cnt // 2 ans cnt // 2 cnt 2 return ans ans S S S = input() S input() input K = int(input()) K int(input()) int input() input if len(S) == 1:
    print(K // 2)
elif len(S) == S.count(S[0]):
    print((len(S)*K)//2)
else:
    if K == 1:
        print(solve(S))
    elif K == 2:
        print(solve(S + S))
    else:
        ans2 = solve(S + S)
        ans3 = solve(S + S + S)
        print(ans2 + (ans3-ans2)*(K - 2)) len(S) == 1 len(S) len S 1 print(K // 2) print K // 2 K 2 elif len(S) == S.count(S[0]):
    print((len(S)*K)//2) len(S) == S.count(S[0]) len(S) len S S.count(S[0]) S.count S count S[0] S 0 print((len(S)*K)//2) print (len(S)*K)//2 len(S)*K len(S) len S K 2 if K == 1:
        print(solve(S))
    elif K == 2:
        print(solve(S + S))
    else:
        ans2 = solve(S + S)
        ans3 = solve(S + S + S)
        print(ans2 + (ans3-ans2)*(K - 2)) K == 1 K 1 print(solve(S)) print solve(S) solve S elif K == 2:
        print(solve(S + S))
     K == 2 K 2 print(solve(S + S)) print solve(S + S) solve S + S S S ans2 = solve(S + S) ans2 solve(S + S) solve S + S S S ans3 = solve(S + S + S) ans3 solve(S + S + S) solve S + S + S S + S S S S print(ans2 + (ans3-ans2)*(K - 2)) print ans2 + (ans3-ans2)*(K - 2) ans2 (ans3-ans2)*(K - 2) ans3-ans2 ans3 ans2 K - 2 K 2 ans3 = solve(S + S + S) solve(S + S + S) ans3 S = input() input() S ans2 = solve(S + S) solve(S + S) ans2 def solve(S):
    pre = S[0]
    flag = False
    ans = 0
    cnt = 0
    for s in S[1:]:
        if flag:
            if pre == s:
                cnt += 1
            else:
                ans += cnt // 2
                cnt = 0
                flag = False
        else:
            if pre == s:
                cnt += 2
                flag = True
        pre = s
    if flag:
        ans += cnt // 2
    return ans def solve(S):
    pre = S[0]
    flag = False
    ans = 0
    cnt = 0
    for s in S[1:]:
        if flag:
            if pre == s:
                cnt += 1
            else:
                ans += cnt // 2
                cnt = 0
                flag = False
        else:
            if pre == s:
                cnt += 2
                flag = True
        pre = s
    if flag:
        ans += cnt // 2
    return ans solve K = int(input()) int(input()) K
def solve(S):
    pre = S[0]
    flag = False
    ans = 0
    cnt = 0
    for s in S[1:]:
        if flag:
            if pre == s:
                cnt += 1
            else:
                ans += cnt // 2
                cnt = 0
                flag = False
        else:
            if pre == s:
                cnt += 2
                flag = True
        pre = s
    if flag:
        ans += cnt // 2
    return ans


S = input()
K = int(input())
if len(S) == 1:
    print(K // 2)
elif len(S) == S.count(S[0]):
    print((len(S)*K)//2)
else:
    if K == 1:
        print(solve(S))
    elif K == 2:
        print(solve(S + S))
    else:
        ans2 = solve(S + S)
        ans3 = solve(S + S + S)
        print(ans2 + (ans3-ans2)*(K - 2))
