def counter(s):
    cnt = 0
    flag = 0
    for i in range(1, len(s)):
        if flag == 1:
            flag = 0
        else:
            if s[i] == s[i-1]:
                cnt += 1
                flag = 1
    return cnt * k

s = str(input())
k = int(input())
if len(set(s)) == 1:
    ans = len(s) * k // 2
else:
    if k == 1 or s[0] != s[-1]:
        ans = counter(s)
    else:
        l = 0
        r = 0
        for i in range(len(s)):
            if s[i] == s[0]:
                l += 1
            else:
                break
        for j in range(len(s)-1, 0, -1):
            if s[j] == s[0]:
                r += 1
            else:
                break
        ans = counter(s[l:-r])
        ans += l // 2 + r // 2 + (l + r) // 2 * (k - 1)        
print(ans) def counter(s):
    cnt = 0
    flag = 0
    for i in range(1, len(s)):
        if flag == 1:
            flag = 0
        else:
            if s[i] == s[i-1]:
                cnt += 1
                flag = 1
    return cnt * k counter cnt = 0 cnt 0 flag = 0 flag 0 for i in range(1, len(s)):
        if flag == 1:
            flag = 0
        else:
            if s[i] == s[i-1]:
                cnt += 1
                flag = 1
     i range(1, len(s)) range 1 len(s) len s if flag == 1:
            flag = 0
        else:
            if s[i] == s[i-1]:
                cnt += 1
                flag = 1
     flag == 1 flag 1 flag = 0 flag 0 if s[i] == s[i-1]:
                cnt += 1
                flag = 1
     s[i] == s[i-1] s[i] s i s[i-1] s i-1 i 1 cnt += 1 cnt 1 flag = 1 flag 1 return cnt * k cnt * k cnt k s s s = str(input()) s str(input()) str input() input k = int(input()) k int(input()) int input() input if len(set(s)) == 1:
    ans = len(s) * k // 2
else:
    if k == 1 or s[0] != s[-1]:
        ans = counter(s)
    else:
        l = 0
        r = 0
        for i in range(len(s)):
            if s[i] == s[0]:
                l += 1
            else:
                break
        for j in range(len(s)-1, 0, -1):
            if s[j] == s[0]:
                r += 1
            else:
                break
        ans = counter(s[l:-r])
        ans += l // 2 + r // 2 + (l + r) // 2 * (k - 1)         len(set(s)) == 1 len(set(s)) len set(s) set s 1 ans = len(s) * k // 2 ans len(s) * k // 2 len(s) * k len(s) len s k 2 if k == 1 or s[0] != s[-1]:
        ans = counter(s)
    else:
        l = 0
        r = 0
        for i in range(len(s)):
            if s[i] == s[0]:
                l += 1
            else:
                break
        for j in range(len(s)-1, 0, -1):
            if s[j] == s[0]:
                r += 1
            else:
                break
        ans = counter(s[l:-r])
        ans += l // 2 + r // 2 + (l + r) // 2 * (k - 1)         k == 1 or s[0] != s[-1] k == 1 k 1 s[0] != s[-1] s[0] s 0 s[-1] s -1 ans = counter(s) ans counter(s) counter s l = 0 l 0 r = 0 r 0 for i in range(len(s)):
            if s[i] == s[0]:
                l += 1
            else:
                break
         i range(len(s)) range len(s) len s if s[i] == s[0]:
                l += 1
            else:
                break
         s[i] == s[0] s[i] s i s[0] s 0 l += 1 l 1 break for j in range(len(s)-1, 0, -1):
            if s[j] == s[0]:
                r += 1
            else:
                break
         j range(len(s)-1, 0, -1) range len(s)-1 len(s) len s 1 0 -1 if s[j] == s[0]:
                r += 1
            else:
                break
         s[j] == s[0] s[j] s j s[0] s 0 r += 1 r 1 break ans = counter(s[l:-r]) ans counter(s[l:-r]) counter s[l:-r] s l:-r l -r r ans += l // 2 + r // 2 + (l + r) // 2 * (k - 1) ans l // 2 + r // 2 + (l + r) // 2 * (k - 1) l // 2 + r // 2 l // 2 l 2 r // 2 r 2 (l + r) // 2 * (k - 1) (l + r) // 2 l + r l r 2 k - 1 k 1 print(ans) print ans s = str(input()) str(input()) s ans = counter(s) counter(s) ans l += 1 1 l def counter(s):
    cnt = 0
    flag = 0
    for i in range(1, len(s)):
        if flag == 1:
            flag = 0
        else:
            if s[i] == s[i-1]:
                cnt += 1
                flag = 1
    return cnt * k def counter(s):
    cnt = 0
    flag = 0
    for i in range(1, len(s)):
        if flag == 1:
            flag = 0
        else:
            if s[i] == s[i-1]:
                cnt += 1
                flag = 1
    return cnt * k counter l = 0 0 l ans += l // 2 + r // 2 + (l + r) // 2 * (k - 1) l // 2 + r // 2 + (l + r) // 2 * (k - 1) ans ans = len(s) * k // 2 len(s) * k // 2 ans r = 0 0 r k = int(input()) int(input()) k ans = counter(s[l:-r]) counter(s[l:-r]) ans r += 1 1 r
def counter(s):
    cnt = 0
    flag = 0
    for i in range(1, len(s)):
        if flag == 1:
            flag = 0
        else:
            if s[i] == s[i-1]:
                cnt += 1
                flag = 1
    return cnt * k

s = str(input())
k = int(input())
if len(set(s)) == 1:
    ans = len(s) * k // 2
else:
    if k == 1 or s[0] != s[-1]:
        ans = counter(s)
    else:
        l = 0
        r = 0
        for i in range(len(s)):
            if s[i] == s[0]:
                l += 1
            else:
                break
        for j in range(len(s)-1, 0, -1):
            if s[j] == s[0]:
                r += 1
            else:
                break
        ans = counter(s[l:-r])
        ans += l // 2 + r // 2 + (l + r) // 2 * (k - 1)        
print(ans)
