S = input()
K = int(input())

if len(S) == 1:
    print(K//2)
    exit()

if len(set(S)) == 1:
    ans = len(S)*K//2
    print(ans)
    exit()

if S[0] != S[-1]:
    ans = 0
    tmp = ""
    for s in S:
        if s == tmp:
            ans += 1
            tmp = ""
            continue
        else:
            tmp = s
    ans *= K
    print(ans)
    exit()
elif S[0] == S[-1]:
    A = 0
    B = 0
    for s in S:
        if s == S[0]:
            A+=1
        else:
            break
    for s in S[::-1]:
        if s == S[0]:
            B+=1
        else:
            break
    ans = 0
    tmp = ""
    for s in S:
        if s == tmp:
            ans += 1
            tmp = ""
            continue
        else:
            tmp = s
    ans *= K
    ans = ans - (A//2 + B//2)*(K-1) + (A+B)//2*(K-1)
    print(ans)
    exit() S = input() S input() input K = int(input()) K int(input()) int input() input if len(S) == 1:
    print(K//2)
    exit() len(S) == 1 len(S) len S 1 print(K//2) print K//2 K 2 exit() exit if len(set(S)) == 1:
    ans = len(S)*K//2
    print(ans)
    exit() 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 print(ans) print ans exit() exit if S[0] != S[-1]:
    ans = 0
    tmp = ""
    for s in S:
        if s == tmp:
            ans += 1
            tmp = ""
            continue
        else:
            tmp = s
    ans *= K
    print(ans)
    exit()
elif S[0] == S[-1]:
    A = 0
    B = 0
    for s in S:
        if s == S[0]:
            A+=1
        else:
            break
    for s in S[::-1]:
        if s == S[0]:
            B+=1
        else:
            break
    ans = 0
    tmp = ""
    for s in S:
        if s == tmp:
            ans += 1
            tmp = ""
            continue
        else:
            tmp = s
    ans *= K
    ans = ans - (A//2 + B//2)*(K-1) + (A+B)//2*(K-1)
    print(ans)
    exit() S[0] != S[-1] S[0] S 0 S[-1] S -1 ans = 0 ans 0 tmp = "" tmp "" for s in S:
        if s == tmp:
            ans += 1
            tmp = ""
            continue
        else:
            tmp = s
     s S if s == tmp:
            ans += 1
            tmp = ""
            continue
        else:
            tmp = s
     s == tmp s tmp ans += 1 ans 1 tmp = "" tmp "" continue tmp = s tmp s ans *= K ans K print(ans) print ans exit() exit elif S[0] == S[-1]:
    A = 0
    B = 0
    for s in S:
        if s == S[0]:
            A+=1
        else:
            break
    for s in S[::-1]:
        if s == S[0]:
            B+=1
        else:
            break
    ans = 0
    tmp = ""
    for s in S:
        if s == tmp:
            ans += 1
            tmp = ""
            continue
        else:
            tmp = s
    ans *= K
    ans = ans - (A//2 + B//2)*(K-1) + (A+B)//2*(K-1)
    print(ans)
    exit() S[0] == S[-1] S[0] S 0 S[-1] S -1 A = 0 A 0 B = 0 B 0 for s in S:
        if s == S[0]:
            A+=1
        else:
            break
     s S if s == S[0]:
            A+=1
        else:
            break
     s == S[0] s S[0] S 0 A+=1 A 1 break for s in S[::-1]:
        if s == S[0]:
            B+=1
        else:
            break
     s S[::-1] S ::-1 -1 if s == S[0]:
            B+=1
        else:
            break
     s == S[0] s S[0] S 0 B+=1 B 1 break ans = 0 ans 0 tmp = "" tmp "" for s in S:
        if s == tmp:
            ans += 1
            tmp = ""
            continue
        else:
            tmp = s
     s S if s == tmp:
            ans += 1
            tmp = ""
            continue
        else:
            tmp = s
     s == tmp s tmp ans += 1 ans 1 tmp = "" tmp "" continue tmp = s tmp s ans *= K ans K ans = ans - (A//2 + B//2)*(K-1) + (A+B)//2*(K-1) ans ans - (A//2 + B//2)*(K-1) + (A+B)//2*(K-1) ans - (A//2 + B//2)*(K-1) ans (A//2 + B//2)*(K-1) A//2 + B//2 A//2 A 2 B//2 B 2 K-1 K 1 (A+B)//2*(K-1) (A+B)//2 A+B A B 2 K-1 K 1 print(ans) print ans exit() exit ans = ans - (A//2 + B//2)*(K-1) + (A+B)//2*(K-1) ans - (A//2 + B//2)*(K-1) + (A+B)//2*(K-1) ans ans += 1 1 ans K = int(input()) int(input()) K tmp = "" "" tmp B+=1 1 B ans *= K K ans ans += 1 1 ans tmp = "" "" tmp tmp = s s tmp A+=1 1 A ans *= K K ans ans = 0 0 ans ans = 0 0 ans tmp = "" "" tmp tmp = s s tmp S = input() input() S ans = len(S)*K//2 len(S)*K//2 ans tmp = "" "" tmp A = 0 0 A B = 0 0 B
S = input()
K = int(input())

if len(S) == 1:
    print(K//2)
    exit()

if len(set(S)) == 1:
    ans = len(S)*K//2
    print(ans)
    exit()

if S[0] != S[-1]:
    ans = 0
    tmp = ""
    for s in S:
        if s == tmp:
            ans += 1
            tmp = ""
            continue
        else:
            tmp = s
    ans *= K
    print(ans)
    exit()
elif S[0] == S[-1]:
    A = 0
    B = 0
    for s in S:
        if s == S[0]:
            A+=1
        else:
            break
    for s in S[::-1]:
        if s == S[0]:
            B+=1
        else:
            break
    ans = 0
    tmp = ""
    for s in S:
        if s == tmp:
            ans += 1
            tmp = ""
            continue
        else:
            tmp = s
    ans *= K
    ans = ans - (A//2 + B//2)*(K-1) + (A+B)//2*(K-1)
    print(ans)
    exit()
