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


if len(set(S)) == 1:
    print(len(S)*K//2)
else:
    i, count1 = 1, 0
    while i < len(S):
        if S[i] == S[i-1]:
            count1 += 1
            i += 2
        else:
            i += 1
    ss = S*2
    i, count2 = 1, 0
    while i < len(ss):
        if ss[i] == ss[i-1]:
            count2 += 1
            i += 2
        else:
            i += 1
    print(count1+(count2-count1)*(K-1)) S = input() S input() input K = int(input()) K int(input()) int input() input if len(set(S)) == 1:
    print(len(S)*K//2)
else:
    i, count1 = 1, 0
    while i < len(S):
        if S[i] == S[i-1]:
            count1 += 1
            i += 2
        else:
            i += 1
    ss = S*2
    i, count2 = 1, 0
    while i < len(ss):
        if ss[i] == ss[i-1]:
            count2 += 1
            i += 2
        else:
            i += 1
    print(count1+(count2-count1)*(K-1)) 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 i, count1 = 1, 0 i 1 count1 0 while i < len(S):
        if S[i] == S[i-1]:
            count1 += 1
            i += 2
        else:
            i += 1
     i < len(S) i len(S) len S if S[i] == S[i-1]:
            count1 += 1
            i += 2
        else:
            i += 1
     S[i] == S[i-1] S[i] S i S[i-1] S i-1 i 1 count1 += 1 count1 1 i += 2 i 2 i += 1 i 1 ss = S*2 ss S*2 S 2 i, count2 = 1, 0 i 1 count2 0 while i < len(ss):
        if ss[i] == ss[i-1]:
            count2 += 1
            i += 2
        else:
            i += 1
     i < len(ss) i len(ss) len ss if ss[i] == ss[i-1]:
            count2 += 1
            i += 2
        else:
            i += 1
     ss[i] == ss[i-1] ss[i] ss i ss[i-1] ss i-1 i 1 count2 += 1 count2 1 i += 2 i 2 i += 1 i 1 print(count1+(count2-count1)*(K-1)) print count1+(count2-count1)*(K-1) count1 (count2-count1)*(K-1) count2-count1 count2 count1 K-1 K 1 count2 = 1, 0 0 count2 count1 += 1 1 count1 ss = S*2 S*2 ss S = input() input() S i, count2 = 1, 0 1 i i += 1 1 i i += 2 2 i K = int(input()) int(input()) K i += 1 1 i i += 2 2 i count2 += 1 1 count2 i, count1 = 1, 0 1 i count1 = 1, 0 0 count1
S = input()
K = int(input())


if len(set(S)) == 1:
    print(len(S)*K//2)
else:
    i, count1 = 1, 0
    while i < len(S):
        if S[i] == S[i-1]:
            count1 += 1
            i += 2
        else:
            i += 1
    ss = S*2
    i, count2 = 1, 0
    while i < len(ss):
        if ss[i] == ss[i-1]:
            count2 += 1
            i += 2
        else:
            i += 1
    print(count1+(count2-count1)*(K-1))
