s = list(input())
k = int(input())
n = len(s)

if s == [s[0]]*n:
    print(n*k//2)
else:
    ss = s*2
    ans1 = 0
    for i in range(1, n):
        if s[i] == s[i -1]:
            s[i] = ""
            ans1 += 1
    ans2 = 0
    for i in range(1, 2*n):
        if ss[i] == ss[i - 1]:
            ss[i] = ""
            ans2 += 1
    j = ans2 - ans1
    print(ans1 + j*(k - 1)) s = list(input()) s list(input()) list input() input k = int(input()) k int(input()) int input() input n = len(s) n len(s) len s if s == [s[0]]*n:
    print(n*k//2)
else:
    ss = s*2
    ans1 = 0
    for i in range(1, n):
        if s[i] == s[i -1]:
            s[i] = ""
            ans1 += 1
    ans2 = 0
    for i in range(1, 2*n):
        if ss[i] == ss[i - 1]:
            ss[i] = ""
            ans2 += 1
    j = ans2 - ans1
    print(ans1 + j*(k - 1)) s == [s[0]]*n s [s[0]]*n [s[0]] s[0] s 0 n print(n*k//2) print n*k//2 n*k n k 2 ss = s*2 ss s*2 s 2 ans1 = 0 ans1 0 for i in range(1, n):
        if s[i] == s[i -1]:
            s[i] = ""
            ans1 += 1
     i range(1, n) range 1 n if s[i] == s[i -1]:
            s[i] = ""
            ans1 += 1
     s[i] == s[i -1] s[i] s i s[i -1] s i -1 i 1 s[i] = "" s[i] s i "" ans1 += 1 ans1 1 ans2 = 0 ans2 0 for i in range(1, 2*n):
        if ss[i] == ss[i - 1]:
            ss[i] = ""
            ans2 += 1
     i range(1, 2*n) range 1 2*n 2 n if ss[i] == ss[i - 1]:
            ss[i] = ""
            ans2 += 1
     ss[i] == ss[i - 1] ss[i] ss i ss[i - 1] ss i - 1 i 1 ss[i] = "" ss[i] ss i "" ans2 += 1 ans2 1 j = ans2 - ans1 j ans2 - ans1 ans2 ans1 print(ans1 + j*(k - 1)) print ans1 + j*(k - 1) ans1 j*(k - 1) j k - 1 k 1 s = list(input()) list(input()) s ans2 += 1 1 ans2 ans1 += 1 1 ans1 k = int(input()) int(input()) k ss = s*2 s*2 ss ans1 = 0 0 ans1 j = ans2 - ans1 ans2 - ans1 j n = len(s) len(s) n ans2 = 0 0 ans2
s = list(input())
k = int(input())
n = len(s)

if s == [s[0]]*n:
    print(n*k//2)
else:
    ss = s*2
    ans1 = 0
    for i in range(1, n):
        if s[i] == s[i -1]:
            s[i] = ""
            ans1 += 1
    ans2 = 0
    for i in range(1, 2*n):
        if ss[i] == ss[i - 1]:
            ss[i] = ""
            ans2 += 1
    j = ans2 - ans1
    print(ans1 + j*(k - 1))