import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

S = list(input())
K = int(input())
leng = len(S)
if len(set(S))==1:
    print(K*leng//2)
    exit()
if S[0]!=S[-1] or K==1:
    last = S[0]
    cnt = 0
    for s in S[1:]:
        if s==last:
            cnt += 1
            last = '.'
        else:
            last = s
    print(cnt*K)
else:
    S += ['.']
    cnt = 1
    lis = []
    last = S[0]
    for s in S[1:]:
        if s==last:
            cnt += 1
        else:
            lis.append(cnt)
            last = s
            cnt = 1
    first = lis.pop(0)
    end = lis.pop()
    others = sum([i//2 for i in lis])
    ans = first//2 + others*K + (first+end)//2*(K-1)+end//2
    print(ans) import sys sys def input(): return sys.stdin.readline().strip() input def mapint(): return map(int, input().split()) mapint sys.setrecursionlimit(10**9) sys.setrecursionlimit sys setrecursionlimit 10**9 10 9 S = list(input()) S list(input()) list input() input K = int(input()) K int(input()) int input() input leng = len(S) leng len(S) len S if len(set(S))==1:
    print(K*leng//2)
    exit() len(set(S))==1 len(set(S)) len set(S) set S 1 print(K*leng//2) print K*leng//2 K*leng K leng 2 exit() exit if S[0]!=S[-1] or K==1:
    last = S[0]
    cnt = 0
    for s in S[1:]:
        if s==last:
            cnt += 1
            last = '.'
        else:
            last = s
    print(cnt*K)
else:
    S += ['.']
    cnt = 1
    lis = []
    last = S[0]
    for s in S[1:]:
        if s==last:
            cnt += 1
        else:
            lis.append(cnt)
            last = s
            cnt = 1
    first = lis.pop(0)
    end = lis.pop()
    others = sum([i//2 for i in lis])
    ans = first//2 + others*K + (first+end)//2*(K-1)+end//2
    print(ans) S[0]!=S[-1] or K==1 S[0]!=S[-1] S[0] S 0 S[-1] S -1 K==1 K 1 last = S[0] last S[0] S 0 cnt = 0 cnt 0 for s in S[1:]:
        if s==last:
            cnt += 1
            last = '.'
        else:
            last = s
     s S[1:] S 1: 1 if s==last:
            cnt += 1
            last = '.'
        else:
            last = s
     s==last s last cnt += 1 cnt 1 last = '.' last '.' last = s last s print(cnt*K) print cnt*K cnt K S += ['.'] S ['.'] '.' cnt = 1 cnt 1 lis = [] lis [] last = S[0] last S[0] S 0 for s in S[1:]:
        if s==last:
            cnt += 1
        else:
            lis.append(cnt)
            last = s
            cnt = 1
     s S[1:] S 1: 1 if s==last:
            cnt += 1
        else:
            lis.append(cnt)
            last = s
            cnt = 1
     s==last s last cnt += 1 cnt 1 lis.append(cnt) lis.append lis append cnt last = s last s cnt = 1 cnt 1 first = lis.pop(0) first lis.pop(0) lis.pop lis pop 0 end = lis.pop() end lis.pop() lis.pop lis pop i//2 for i in lis for i in lis i lis for i in lis i//2 i 2 others = sum([i//2 for i in lis]) others sum([i//2 for i in lis]) sum [i//2 for i in lis] ans = first//2 + others*K + (first+end)//2*(K-1)+end//2 ans first//2 + others*K + (first+end)//2*(K-1)+end//2 first//2 + others*K + (first+end)//2*(K-1) first//2 + others*K first//2 first 2 others*K others K (first+end)//2*(K-1) (first+end)//2 first+end first end 2 K-1 K 1 end//2 end 2 print(ans) print ans leng = len(S) len(S) leng last = S[0] S[0] last S = list(input()) list(input()) S cnt = 1 1 cnt first = lis.pop(0) lis.pop(0) first ans = first//2 + others*K + (first+end)//2*(K-1)+end//2 first//2 + others*K + (first+end)//2*(K-1)+end//2 ans K = int(input()) int(input()) K last = '.' '.' last end = lis.pop() lis.pop() end cnt += 1 1 cnt S += ['.'] ['.'] S cnt = 0 0 cnt def input(): return sys.stdin.readline().strip() def input(): return sys.stdin.readline().strip() input cnt += 1 1 cnt def mapint(): return map(int, input().split()) def mapint(): return map(int, input().split()) mapint last = s s last lis = [] [] lis last = S[0] S[0] last last = s s last others = sum([i//2 for i in lis]) sum([i//2 for i in lis]) others cnt = 1 1 cnt
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

S = list(input())
K = int(input())
leng = len(S)
if len(set(S))==1:
    print(K*leng//2)
    exit()
if S[0]!=S[-1] or K==1:
    last = S[0]
    cnt = 0
    for s in S[1:]:
        if s==last:
            cnt += 1
            last = '.'
        else:
            last = s
    print(cnt*K)
else:
    S += ['.']
    cnt = 1
    lis = []
    last = S[0]
    for s in S[1:]:
        if s==last:
            cnt += 1
        else:
            lis.append(cnt)
            last = s
            cnt = 1
    first = lis.pop(0)
    end = lis.pop()
    others = sum([i//2 for i in lis])
    ans = first//2 + others*K + (first+end)//2*(K-1)+end//2
    print(ans)
