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

if len(set(S)) == 1:
    print(len(S)*K //2)
else:
    cnt = [1]
    for i in range(len(S)-1):
        if S[i] == S[i+1]:
            cnt[-1] += 1
        else:
            cnt.append(1)
    
    res = 0
    for c in cnt:
        res += c//2*K

    if S[0] == S[-1]:
        if (cnt[0]+cnt[-1])%2 == 0:
            res += K-1
    
    print(res) S = list(input()) S list(input()) list input() input K = int(input()) K int(input()) int input() input if len(set(S)) == 1:
    print(len(S)*K //2)
else:
    cnt = [1]
    for i in range(len(S)-1):
        if S[i] == S[i+1]:
            cnt[-1] += 1
        else:
            cnt.append(1)
    
    res = 0
    for c in cnt:
        res += c//2*K

    if S[0] == S[-1]:
        if (cnt[0]+cnt[-1])%2 == 0:
            res += K-1
    
    print(res) len(set(S)) == 1 len(set(S)) len set(S) set S 1 print(len(S)*K //2) print len(S)*K //2 len(S)*K len(S) len S K 2 cnt = [1] cnt [1] 1 for i in range(len(S)-1):
        if S[i] == S[i+1]:
            cnt[-1] += 1
        else:
            cnt.append(1)
    
     i range(len(S)-1) range len(S)-1 len(S) len S 1 if S[i] == S[i+1]:
            cnt[-1] += 1
        else:
            cnt.append(1)
    
     S[i] == S[i+1] S[i] S i S[i+1] S i+1 i 1 cnt[-1] += 1 cnt[-1] cnt -1 1 cnt.append(1) cnt.append cnt append 1 res = 0 res 0 for c in cnt:
        res += c//2*K

     c cnt res += c//2*K res c//2*K c//2 c 2 K if S[0] == S[-1]:
        if (cnt[0]+cnt[-1])%2 == 0:
            res += K-1
    
     S[0] == S[-1] S[0] S 0 S[-1] S -1 if (cnt[0]+cnt[-1])%2 == 0:
            res += K-1
    
     (cnt[0]+cnt[-1])%2 == 0 (cnt[0]+cnt[-1])%2 cnt[0]+cnt[-1] cnt[0] cnt 0 cnt[-1] cnt -1 2 0 res += K-1 res K-1 K 1 print(res) print res K = int(input()) int(input()) K res += K-1 K-1 res S = list(input()) list(input()) S res = 0 0 res res += c//2*K c//2*K res cnt = [1] [1] cnt
S = list(input())
K = int(input())

if len(set(S)) == 1:
    print(len(S)*K //2)
else:
    cnt = [1]
    for i in range(len(S)-1):
        if S[i] == S[i+1]:
            cnt[-1] += 1
        else:
            cnt.append(1)
    
    res = 0
    for c in cnt:
        res += c//2*K

    if S[0] == S[-1]:
        if (cnt[0]+cnt[-1])%2 == 0:
            res += K-1
    
    print(res)