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

if len(set(s)) == 1:
    print(n * k // 2)

else:
    memo = []
    tmp = 1
    for i in range(n-1):
        if s[i] == s[i+1]:
            tmp += 1
        else:
            memo.append(tmp)
            tmp = 1
    memo.append(tmp)
    m = len(memo)

    if s[0] == s[-1]:
        ans = 0
        for i in range(m):
            if i == 0 or i == m-1:
                ans += memo[i] // 2
            else:
                ans += (memo[i] // 2) * k
        ans += ((memo[0] + memo[-1]) // 2) * (k-1)

    else:
        ans = sum(memo[i] // 2 for i in range(m)) * k

    print(ans) s = input() s input() input n = len(s) n len(s) len s k = int(input()) k int(input()) int input() input if len(set(s)) == 1:
    print(n * k // 2)

else:
    memo = []
    tmp = 1
    for i in range(n-1):
        if s[i] == s[i+1]:
            tmp += 1
        else:
            memo.append(tmp)
            tmp = 1
    memo.append(tmp)
    m = len(memo)

    if s[0] == s[-1]:
        ans = 0
        for i in range(m):
            if i == 0 or i == m-1:
                ans += memo[i] // 2
            else:
                ans += (memo[i] // 2) * k
        ans += ((memo[0] + memo[-1]) // 2) * (k-1)

    else:
        ans = sum(memo[i] // 2 for i in range(m)) * k

    print(ans) 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 memo = [] memo [] tmp = 1 tmp 1 for i in range(n-1):
        if s[i] == s[i+1]:
            tmp += 1
        else:
            memo.append(tmp)
            tmp = 1
     i range(n-1) range n-1 n 1 if s[i] == s[i+1]:
            tmp += 1
        else:
            memo.append(tmp)
            tmp = 1
     s[i] == s[i+1] s[i] s i s[i+1] s i+1 i 1 tmp += 1 tmp 1 memo.append(tmp) memo.append memo append tmp tmp = 1 tmp 1 memo.append(tmp) memo.append memo append tmp m = len(memo) m len(memo) len memo if s[0] == s[-1]:
        ans = 0
        for i in range(m):
            if i == 0 or i == m-1:
                ans += memo[i] // 2
            else:
                ans += (memo[i] // 2) * k
        ans += ((memo[0] + memo[-1]) // 2) * (k-1)

    else:
        ans = sum(memo[i] // 2 for i in range(m)) * k

     s[0] == s[-1] s[0] s 0 s[-1] s -1 ans = 0 ans 0 for i in range(m):
            if i == 0 or i == m-1:
                ans += memo[i] // 2
            else:
                ans += (memo[i] // 2) * k
         i range(m) range m if i == 0 or i == m-1:
                ans += memo[i] // 2
            else:
                ans += (memo[i] // 2) * k
         i == 0 or i == m-1 i == 0 i 0 i == m-1 i m-1 m 1 ans += memo[i] // 2 ans memo[i] // 2 memo[i] memo i 2 ans += (memo[i] // 2) * k ans (memo[i] // 2) * k memo[i] // 2 memo[i] memo i 2 k ans += ((memo[0] + memo[-1]) // 2) * (k-1) ans ((memo[0] + memo[-1]) // 2) * (k-1) (memo[0] + memo[-1]) // 2 memo[0] + memo[-1] memo[0] memo 0 memo[-1] memo -1 2 k-1 k 1 ans = sum(memo[i] // 2 for i in range(m)) * k ans sum(memo[i] // 2 for i in range(m)) * k sum(memo[i] // 2 for i in range(m)) sum memo[i] // 2 memo[i] memo i 2 k print(ans) print ans n = len(s) len(s) n ans += memo[i] // 2 memo[i] // 2 ans ans += ((memo[0] + memo[-1]) // 2) * (k-1) ((memo[0] + memo[-1]) // 2) * (k-1) ans s = input() input() s ans = sum(memo[i] // 2 for i in range(m)) * k sum(memo[i] // 2 for i in range(m)) * k ans tmp = 1 1 tmp tmp = 1 1 tmp m = len(memo) len(memo) m tmp += 1 1 tmp memo = [] [] memo ans = 0 0 ans ans += (memo[i] // 2) * k (memo[i] // 2) * k ans k = int(input()) int(input()) k
s = input()
n = len(s)
k = int(input())

if len(set(s)) == 1:
    print(n * k // 2)

else:
    memo = []
    tmp = 1
    for i in range(n-1):
        if s[i] == s[i+1]:
            tmp += 1
        else:
            memo.append(tmp)
            tmp = 1
    memo.append(tmp)
    m = len(memo)

    if s[0] == s[-1]:
        ans = 0
        for i in range(m):
            if i == 0 or i == m-1:
                ans += memo[i] // 2
            else:
                ans += (memo[i] // 2) * k
        ans += ((memo[0] + memo[-1]) // 2) * (k-1)

    else:
        ans = sum(memo[i] // 2 for i in range(m)) * k

    print(ans)