from copy import copy
def solve():
    S = input()
    K = int(input())
    ans = 0
    seqs = []
    seq = 1
    for i in range(1,len(S)):
        if S[i]==S[i-1]:
            seq += 1
        else:
            seqs.append(seq)
            seq = 1
    seqs.append(seq)
    first_seq = seqs[0]
    last_seq = seqs[-1]
    seqs.pop(0)
    if len(seqs):
        ans += first_seq//2 + last_seq//2
        seqs.pop(-1)
        if S[0]==S[-1]:
            ans += ((first_seq + last_seq)//2)*(K-1)
        else:
            ans *= K
        ans += sum(map(lambda x: x//2,seqs))*K
    else:
        if S[0]==S[-1]:
            ans += first_seq*K//2
        else:
            ans += first_seq//2*K
    return ans
print(solve()) from copy import copy def solve():
    S = input()
    K = int(input())
    ans = 0
    seqs = []
    seq = 1
    for i in range(1,len(S)):
        if S[i]==S[i-1]:
            seq += 1
        else:
            seqs.append(seq)
            seq = 1
    seqs.append(seq)
    first_seq = seqs[0]
    last_seq = seqs[-1]
    seqs.pop(0)
    if len(seqs):
        ans += first_seq//2 + last_seq//2
        seqs.pop(-1)
        if S[0]==S[-1]:
            ans += ((first_seq + last_seq)//2)*(K-1)
        else:
            ans *= K
        ans += sum(map(lambda x: x//2,seqs))*K
    else:
        if S[0]==S[-1]:
            ans += first_seq*K//2
        else:
            ans += first_seq//2*K
    return ans solve S = input() S input() input K = int(input()) K int(input()) int input() input ans = 0 ans 0 seqs = [] seqs [] seq = 1 seq 1 for i in range(1,len(S)):
        if S[i]==S[i-1]:
            seq += 1
        else:
            seqs.append(seq)
            seq = 1
     i range(1,len(S)) range 1 len(S) len S if S[i]==S[i-1]:
            seq += 1
        else:
            seqs.append(seq)
            seq = 1
     S[i]==S[i-1] S[i] S i S[i-1] S i-1 i 1 seq += 1 seq 1 seqs.append(seq) seqs.append seqs append seq seq = 1 seq 1 seqs.append(seq) seqs.append seqs append seq first_seq = seqs[0] first_seq seqs[0] seqs 0 last_seq = seqs[-1] last_seq seqs[-1] seqs -1 seqs.pop(0) seqs.pop seqs pop 0 if len(seqs):
        ans += first_seq//2 + last_seq//2
        seqs.pop(-1)
        if S[0]==S[-1]:
            ans += ((first_seq + last_seq)//2)*(K-1)
        else:
            ans *= K
        ans += sum(map(lambda x: x//2,seqs))*K
    else:
        if S[0]==S[-1]:
            ans += first_seq*K//2
        else:
            ans += first_seq//2*K
     len(seqs) len seqs ans += first_seq//2 + last_seq//2 ans first_seq//2 + last_seq//2 first_seq//2 first_seq 2 last_seq//2 last_seq 2 seqs.pop(-1) seqs.pop seqs pop -1 if S[0]==S[-1]:
            ans += ((first_seq + last_seq)//2)*(K-1)
        else:
            ans *= K
         S[0]==S[-1] S[0] S 0 S[-1] S -1 ans += ((first_seq + last_seq)//2)*(K-1) ans ((first_seq + last_seq)//2)*(K-1) (first_seq + last_seq)//2 first_seq + last_seq first_seq last_seq 2 K-1 K 1 ans *= K ans K ans += sum(map(lambda x: x//2,seqs))*K ans sum(map(lambda x: x//2,seqs))*K sum(map(lambda x: x//2,seqs)) sum map(lambda x: x//2,seqs) map lambda x: x//2 x//2 x 2 x seqs K if S[0]==S[-1]:
            ans += first_seq*K//2
        else:
            ans += first_seq//2*K
     S[0]==S[-1] S[0] S 0 S[-1] S -1 ans += first_seq*K//2 ans first_seq*K//2 first_seq*K first_seq K 2 ans += first_seq//2*K ans first_seq//2*K first_seq//2 first_seq 2 K return ans ans print(solve()) print solve() solve def solve():
    S = input()
    K = int(input())
    ans = 0
    seqs = []
    seq = 1
    for i in range(1,len(S)):
        if S[i]==S[i-1]:
            seq += 1
        else:
            seqs.append(seq)
            seq = 1
    seqs.append(seq)
    first_seq = seqs[0]
    last_seq = seqs[-1]
    seqs.pop(0)
    if len(seqs):
        ans += first_seq//2 + last_seq//2
        seqs.pop(-1)
        if S[0]==S[-1]:
            ans += ((first_seq + last_seq)//2)*(K-1)
        else:
            ans *= K
        ans += sum(map(lambda x: x//2,seqs))*K
    else:
        if S[0]==S[-1]:
            ans += first_seq*K//2
        else:
            ans += first_seq//2*K
    return ans def solve():
    S = input()
    K = int(input())
    ans = 0
    seqs = []
    seq = 1
    for i in range(1,len(S)):
        if S[i]==S[i-1]:
            seq += 1
        else:
            seqs.append(seq)
            seq = 1
    seqs.append(seq)
    first_seq = seqs[0]
    last_seq = seqs[-1]
    seqs.pop(0)
    if len(seqs):
        ans += first_seq//2 + last_seq//2
        seqs.pop(-1)
        if S[0]==S[-1]:
            ans += ((first_seq + last_seq)//2)*(K-1)
        else:
            ans *= K
        ans += sum(map(lambda x: x//2,seqs))*K
    else:
        if S[0]==S[-1]:
            ans += first_seq*K//2
        else:
            ans += first_seq//2*K
    return ans solve
from copy import copy
def solve():
    S = input()
    K = int(input())
    ans = 0
    seqs = []
    seq = 1
    for i in range(1,len(S)):
        if S[i]==S[i-1]:
            seq += 1
        else:
            seqs.append(seq)
            seq = 1
    seqs.append(seq)
    first_seq = seqs[0]
    last_seq = seqs[-1]
    seqs.pop(0)
    if len(seqs):
        ans += first_seq//2 + last_seq//2
        seqs.pop(-1)
        if S[0]==S[-1]:
            ans += ((first_seq + last_seq)//2)*(K-1)
        else:
            ans *= K
        ans += sum(map(lambda x: x//2,seqs))*K
    else:
        if S[0]==S[-1]:
            ans += first_seq*K//2
        else:
            ans += first_seq//2*K
    return ans
print(solve())