s = input()
k = int(input())
s_list = []
ans = 0

def rle(s):
    tmp, count = s[0], 1
    for i in range(1, len(s)):
        if tmp == s[i]:
            count += 1
        else:
            s_list.append(count)
            tmp = s[i]
            count = 1
    s_list.append(count)
    return

rle(s)

if len(s_list) >= 2:
    for i in range(len(s_list)):
        if s_list[i] >= 2:
            ans += s_list[i] // 2

    ans *= k

    if (s_list[0] + s_list[-1]) % 2 == 0 and s[0] == s[-1]:
        ans += k - 1

else:
    ans = len(s) * k // 2

print(ans) s = input() s input() input k = int(input()) k int(input()) int input() input s_list = [] s_list [] ans = 0 ans 0 def rle(s):
    tmp, count = s[0], 1
    for i in range(1, len(s)):
        if tmp == s[i]:
            count += 1
        else:
            s_list.append(count)
            tmp = s[i]
            count = 1
    s_list.append(count)
    return rle tmp, count = s[0], 1 tmp s[0] s 0 count 1 for i in range(1, len(s)):
        if tmp == s[i]:
            count += 1
        else:
            s_list.append(count)
            tmp = s[i]
            count = 1
     i range(1, len(s)) range 1 len(s) len s if tmp == s[i]:
            count += 1
        else:
            s_list.append(count)
            tmp = s[i]
            count = 1
     tmp == s[i] tmp s[i] s i count += 1 count 1 s_list.append(count) s_list.append s_list append count tmp = s[i] tmp s[i] s i count = 1 count 1 s_list.append(count) s_list.append s_list append count return s s rle(s) rle s if len(s_list) >= 2:
    for i in range(len(s_list)):
        if s_list[i] >= 2:
            ans += s_list[i] // 2

    ans *= k

    if (s_list[0] + s_list[-1]) % 2 == 0 and s[0] == s[-1]:
        ans += k - 1

else:
    ans = len(s) * k // 2 len(s_list) >= 2 len(s_list) len s_list 2 for i in range(len(s_list)):
        if s_list[i] >= 2:
            ans += s_list[i] // 2

     i range(len(s_list)) range len(s_list) len s_list if s_list[i] >= 2:
            ans += s_list[i] // 2

     s_list[i] >= 2 s_list[i] s_list i 2 ans += s_list[i] // 2 ans s_list[i] // 2 s_list[i] s_list i 2 ans *= k ans k if (s_list[0] + s_list[-1]) % 2 == 0 and s[0] == s[-1]:
        ans += k - 1 (s_list[0] + s_list[-1]) % 2 == 0 and s[0] == s[-1] (s_list[0] + s_list[-1]) % 2 == 0 (s_list[0] + s_list[-1]) % 2 s_list[0] + s_list[-1] s_list[0] s_list 0 s_list[-1] s_list -1 2 0 s[0] == s[-1] s[0] s 0 s[-1] s -1 ans += k - 1 ans k - 1 k 1 ans = len(s) * k // 2 ans len(s) * k // 2 len(s) * k len(s) len s k 2 print(ans) print ans ans *= k k ans s_list = [] [] s_list ans = len(s) * k // 2 len(s) * k // 2 ans def rle(s):
    tmp, count = s[0], 1
    for i in range(1, len(s)):
        if tmp == s[i]:
            count += 1
        else:
            s_list.append(count)
            tmp = s[i]
            count = 1
    s_list.append(count)
    return def rle(s):
    tmp, count = s[0], 1
    for i in range(1, len(s)):
        if tmp == s[i]:
            count += 1
        else:
            s_list.append(count)
            tmp = s[i]
            count = 1
    s_list.append(count)
    return rle ans += k - 1 k - 1 ans k = int(input()) int(input()) k s = input() input() s ans = 0 0 ans ans += s_list[i] // 2 s_list[i] // 2 ans
s = input()
k = int(input())
s_list = []
ans = 0

def rle(s):
    tmp, count = s[0], 1
    for i in range(1, len(s)):
        if tmp == s[i]:
            count += 1
        else:
            s_list.append(count)
            tmp = s[i]
            count = 1
    s_list.append(count)
    return

rle(s)

if len(s_list) >= 2:
    for i in range(len(s_list)):
        if s_list[i] >= 2:
            ans += s_list[i] // 2

    ans *= k

    if (s_list[0] + s_list[-1]) % 2 == 0 and s[0] == s[-1]:
        ans += k - 1

else:
    ans = len(s) * k // 2

print(ans)
