s = input()
k = int(input())

if len(set(s)) == 1:
    print((len(s)*k)//2)
else:
    t = [1]
    for i in range(1, len(s)):
        if s[i-1] == s[i]:
            t[-1] += 1
        else:
            t.append(1)
    a = 0
    for i in t:
        a += (i//2)*k
    if s[0] == s[-1]:
        if t[0] % 2 == t[-1] % 2 == 1:
            a += k-1
    print(a) 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:
    t = [1]
    for i in range(1, len(s)):
        if s[i-1] == s[i]:
            t[-1] += 1
        else:
            t.append(1)
    a = 0
    for i in t:
        a += (i//2)*k
    if s[0] == s[-1]:
        if t[0] % 2 == t[-1] % 2 == 1:
            a += k-1
    print(a) 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 t = [1] t [1] 1 for i in range(1, len(s)):
        if s[i-1] == s[i]:
            t[-1] += 1
        else:
            t.append(1)
     i range(1, len(s)) range 1 len(s) len s if s[i-1] == s[i]:
            t[-1] += 1
        else:
            t.append(1)
     s[i-1] == s[i] s[i-1] s i-1 i 1 s[i] s i t[-1] += 1 t[-1] t -1 1 t.append(1) t.append t append 1 a = 0 a 0 for i in t:
        a += (i//2)*k
     i t a += (i//2)*k a (i//2)*k i//2 i 2 k if s[0] == s[-1]:
        if t[0] % 2 == t[-1] % 2 == 1:
            a += k-1
     s[0] == s[-1] s[0] s 0 s[-1] s -1 if t[0] % 2 == t[-1] % 2 == 1:
            a += k-1
     t[0] % 2 == t[-1] % 2 == 1 t[0] % 2 == t[-1] % 2 t[0] % 2 t[0] t 0 2 t[-1] % 2 t[-1] t -1 2 1 a += k-1 a k-1 k 1 print(a) print a k = int(input()) int(input()) k a += (i//2)*k (i//2)*k a a = 0 0 a s = input() input() s a += k-1 k-1 a t = [1] [1] t
s = input()
k = int(input())

if len(set(s)) == 1:
    print((len(s)*k)//2)
else:
    t = [1]
    for i in range(1, len(s)):
        if s[i-1] == s[i]:
            t[-1] += 1
        else:
            t.append(1)
    a = 0
    for i in t:
        a += (i//2)*k
    if s[0] == s[-1]:
        if t[0] % 2 == t[-1] % 2 == 1:
            a += k-1
    print(a)