# -*- coding: utf-8 -*-
import sys
from collections import deque, defaultdict
from math import sqrt, factorial, gcd, ceil
# def input(): return sys.stdin.readline()[:-1] # warning not \n
# def input(): return sys.stdin.buffer.readline().strip() # warning bytes
# def input(): return sys.stdin.buffer.readline().decode('utf-8')
import string
# string.ascii_lowercase
from bisect import bisect_left

def solve():
    # n, m = [int(x) for x in input().split()]
    s = [x for x in input()]
    k = int(input())
    n = len(s)
    if len(set(s)) == 1:
        print(n*k//2)
        return
    b = [1]
    for i in range(1, n):
        if s[i] == s[i-1]:
            b[-1] += 1
        else:
            b.append(1)
    ans = 0
    for e in b:
        ans += e // 2 * k

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


t = 1
# t = int(input())
for case in range(1,t+1):
    ans = solve()


"""

azyxwvutsrqponmlkjihgfedcb

""" import sys sys from collections import deque, defaultdict from math import sqrt, factorial, gcd, ceil import string string from bisect import bisect_left def solve():
    # n, m = [int(x) for x in input().split()]
    s = [x for x in input()]
    k = int(input())
    n = len(s)
    if len(set(s)) == 1:
        print(n*k//2)
        return
    b = [1]
    for i in range(1, n):
        if s[i] == s[i-1]:
            b[-1] += 1
        else:
            b.append(1)
    ans = 0
    for e in b:
        ans += e // 2 * k

    if s[0] == s[-1] and b[0] % 2 and b[-1] % 2:
        ans += k-1
    
    print(ans) solve x for x in input() for x in input() x input() input for x in input() x s = [x for x in input()] s [x for x in input()] k = int(input()) k int(input()) int input() input n = len(s) n len(s) len s if len(set(s)) == 1:
        print(n*k//2)
        return
     len(set(s)) == 1 len(set(s)) len set(s) set s 1 print(n*k//2) print n*k//2 n*k n k 2 return b = [1] b [1] 1 for i in range(1, n):
        if s[i] == s[i-1]:
            b[-1] += 1
        else:
            b.append(1)
     i range(1, n) range 1 n if s[i] == s[i-1]:
            b[-1] += 1
        else:
            b.append(1)
     s[i] == s[i-1] s[i] s i s[i-1] s i-1 i 1 b[-1] += 1 b[-1] b -1 1 b.append(1) b.append b append 1 ans = 0 ans 0 for e in b:
        ans += e // 2 * k

     e b ans += e // 2 * k ans e // 2 * k e // 2 e 2 k if s[0] == s[-1] and b[0] % 2 and b[-1] % 2:
        ans += k-1
    
     s[0] == s[-1] and b[0] % 2 and b[-1] % 2 s[0] == s[-1] and b[0] % 2 s[0] == s[-1] s[0] s 0 s[-1] s -1 b[0] % 2 b[0] b 0 2 b[-1] % 2 b[-1] b -1 2 ans += k-1 ans k-1 k 1 print(ans) print ans t = 1 t 1 for case in range(1,t+1):
    ans = solve() case range(1,t+1) range 1 t+1 t 1 ans = solve() ans solve() solve """

azyxwvutsrqponmlkjihgfedcb

""" def solve():
    # n, m = [int(x) for x in input().split()]
    s = [x for x in input()]
    k = int(input())
    n = len(s)
    if len(set(s)) == 1:
        print(n*k//2)
        return
    b = [1]
    for i in range(1, n):
        if s[i] == s[i-1]:
            b[-1] += 1
        else:
            b.append(1)
    ans = 0
    for e in b:
        ans += e // 2 * k

    if s[0] == s[-1] and b[0] % 2 and b[-1] % 2:
        ans += k-1
    
    print(ans) def solve():
    # n, m = [int(x) for x in input().split()]
    s = [x for x in input()]
    k = int(input())
    n = len(s)
    if len(set(s)) == 1:
        print(n*k//2)
        return
    b = [1]
    for i in range(1, n):
        if s[i] == s[i-1]:
            b[-1] += 1
        else:
            b.append(1)
    ans = 0
    for e in b:
        ans += e // 2 * k

    if s[0] == s[-1] and b[0] % 2 and b[-1] % 2:
        ans += k-1
    
    print(ans) solve t = 1 1 t ans = solve() solve() ans
# -*- coding: utf-8 -*-
import sys
from collections import deque, defaultdict
from math import sqrt, factorial, gcd, ceil
# def input(): return sys.stdin.readline()[:-1] # warning not \n
# def input(): return sys.stdin.buffer.readline().strip() # warning bytes
# def input(): return sys.stdin.buffer.readline().decode('utf-8')
import string
# string.ascii_lowercase
from bisect import bisect_left

def solve():
    # n, m = [int(x) for x in input().split()]
    s = [x for x in input()]
    k = int(input())
    n = len(s)
    if len(set(s)) == 1:
        print(n*k//2)
        return
    b = [1]
    for i in range(1, n):
        if s[i] == s[i-1]:
            b[-1] += 1
        else:
            b.append(1)
    ans = 0
    for e in b:
        ans += e // 2 * k

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


t = 1
# t = int(input())
for case in range(1,t+1):
    ans = solve()


"""

azyxwvutsrqponmlkjihgfedcb

"""
