import sys
import itertools
# import numpy as np
import time
import math
from heapq import heappop, heappush
from collections import defaultdict
from collections import Counter
from collections import deque
from itertools import permutations
sys.setrecursionlimit(10 ** 7)
 
INF = 10 ** 18
MOD = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

# map(int, input().split())
S = input()
K = int(input())
ans = 0

S = list(S)
def f(T):
    ret = 0
    l = 0
    r = 1
    n = len(T)
    while l < n:
        while r < n and T[l] == T[r]:
            r += 1
        c = r - l
        ret += c // 2
        l = r
        r = l + 1
    return ret

first = f(S)
second = f(S + S)
diff = second - first

if len(set(S)) == 1:
    print(len(S) * K // 2)
else:
    print(first + diff * (K - 1)) import sys sys import itertools itertools import time time import math math from heapq import heappop, heappush from collections import defaultdict from collections import Counter from collections import deque from itertools import permutations sys.setrecursionlimit(10 ** 7) sys.setrecursionlimit sys setrecursionlimit 10 ** 7 10 7 INF = 10 ** 18 INF 10 ** 18 10 18 MOD = 10 ** 9 + 7 MOD 10 ** 9 + 7 10 ** 9 10 9 7 read = sys.stdin.buffer.read read sys.stdin.buffer.read sys.stdin.buffer sys.stdin sys stdin buffer read readline = sys.stdin.buffer.readline readline sys.stdin.buffer.readline sys.stdin.buffer sys.stdin sys stdin buffer readline readlines = sys.stdin.buffer.readlines readlines sys.stdin.buffer.readlines sys.stdin.buffer sys.stdin sys stdin buffer readlines S = input() S input() input K = int(input()) K int(input()) int input() input ans = 0 ans 0 S = list(S) S list(S) list S def f(T):
    ret = 0
    l = 0
    r = 1
    n = len(T)
    while l < n:
        while r < n and T[l] == T[r]:
            r += 1
        c = r - l
        ret += c // 2
        l = r
        r = l + 1
    return ret f ret = 0 ret 0 l = 0 l 0 r = 1 r 1 n = len(T) n len(T) len T while l < n:
        while r < n and T[l] == T[r]:
            r += 1
        c = r - l
        ret += c // 2
        l = r
        r = l + 1
     l < n l n while r < n and T[l] == T[r]:
            r += 1
         r < n and T[l] == T[r] r < n r n T[l] == T[r] T[l] T l T[r] T r r += 1 r 1 c = r - l c r - l r l ret += c // 2 ret c // 2 c 2 l = r l r r = l + 1 r l + 1 l 1 return ret ret T T first = f(S) first f(S) f S second = f(S + S) second f(S + S) f S + S S S diff = second - first diff second - first second first if len(set(S)) == 1:
    print(len(S) * K // 2)
else:
    print(first + diff * (K - 1)) 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 print(first + diff * (K - 1)) print first + diff * (K - 1) first diff * (K - 1) diff K - 1 K 1 first = f(S) f(S) first ans = 0 0 ans def f(T):
    ret = 0
    l = 0
    r = 1
    n = len(T)
    while l < n:
        while r < n and T[l] == T[r]:
            r += 1
        c = r - l
        ret += c // 2
        l = r
        r = l + 1
    return ret def f(T):
    ret = 0
    l = 0
    r = 1
    n = len(T)
    while l < n:
        while r < n and T[l] == T[r]:
            r += 1
        c = r - l
        ret += c // 2
        l = r
        r = l + 1
    return ret f read = sys.stdin.buffer.read sys.stdin.buffer.read read INF = 10 ** 18 10 ** 18 INF MOD = 10 ** 9 + 7 10 ** 9 + 7 MOD K = int(input()) int(input()) K S = list(S) list(S) S readlines = sys.stdin.buffer.readlines sys.stdin.buffer.readlines readlines S = input() input() S diff = second - first second - first diff second = f(S + S) f(S + S) second readline = sys.stdin.buffer.readline sys.stdin.buffer.readline readline
import sys
import itertools
# import numpy as np
import time
import math
from heapq import heappop, heappush
from collections import defaultdict
from collections import Counter
from collections import deque
from itertools import permutations
sys.setrecursionlimit(10 ** 7)
 
INF = 10 ** 18
MOD = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

# map(int, input().split())
S = input()
K = int(input())
ans = 0

S = list(S)
def f(T):
    ret = 0
    l = 0
    r = 1
    n = len(T)
    while l < n:
        while r < n and T[l] == T[r]:
            r += 1
        c = r - l
        ret += c // 2
        l = r
        r = l + 1
    return ret

first = f(S)
second = f(S + S)
diff = second - first

if len(set(S)) == 1:
    print(len(S) * K // 2)
else:
    print(first + diff * (K - 1))