def f(k):
    T = S*k
    N = len(T)
    cur = T[0]
    cnt = 1
    ans = 0
    for i in range(1,N):
        if T[i]==cur:
            cnt += 1
        else:
            ans += cnt//2
            cur = T[i]
            cnt = 1
    ans += cnt//2
    return ans
S = input().strip()
K = int(input())
ans1 = f(1)
ans2 = f(2)
ans3 = f(3)
d1 = f(2)-f(1)
d2 = f(3)-f(2)
k = (K-1)//2
if (K-1)%2==0:
    print(f(1)+(d1+d2)*k)
else:
    print(f(1)+(d1+d2)*k+d1) def f(k):
    T = S*k
    N = len(T)
    cur = T[0]
    cnt = 1
    ans = 0
    for i in range(1,N):
        if T[i]==cur:
            cnt += 1
        else:
            ans += cnt//2
            cur = T[i]
            cnt = 1
    ans += cnt//2
    return ans f T = S*k T S*k S k N = len(T) N len(T) len T cur = T[0] cur T[0] T 0 cnt = 1 cnt 1 ans = 0 ans 0 for i in range(1,N):
        if T[i]==cur:
            cnt += 1
        else:
            ans += cnt//2
            cur = T[i]
            cnt = 1
     i range(1,N) range 1 N if T[i]==cur:
            cnt += 1
        else:
            ans += cnt//2
            cur = T[i]
            cnt = 1
     T[i]==cur T[i] T i cur cnt += 1 cnt 1 ans += cnt//2 ans cnt//2 cnt 2 cur = T[i] cur T[i] T i cnt = 1 cnt 1 ans += cnt//2 ans cnt//2 cnt 2 return ans ans k k S = input().strip() S input().strip() ().strip () input strip K = int(input()) K int(input()) int input() input ans1 = f(1) ans1 f(1) f 1 ans2 = f(2) ans2 f(2) f 2 ans3 = f(3) ans3 f(3) f 3 d1 = f(2)-f(1) d1 f(2)-f(1) f(2) f 2 f(1) f 1 d2 = f(3)-f(2) d2 f(3)-f(2) f(3) f 3 f(2) f 2 k = (K-1)//2 k (K-1)//2 K-1 K 1 2 if (K-1)%2==0:
    print(f(1)+(d1+d2)*k)
else:
    print(f(1)+(d1+d2)*k+d1) (K-1)%2==0 (K-1)%2 K-1 K 1 2 0 print(f(1)+(d1+d2)*k) print f(1)+(d1+d2)*k f(1) f 1 (d1+d2)*k d1+d2 d1 d2 k print(f(1)+(d1+d2)*k+d1) print f(1)+(d1+d2)*k+d1 f(1)+(d1+d2)*k f(1) f 1 (d1+d2)*k d1+d2 d1 d2 k d1 ans3 = f(3) f(3) ans3 ans2 = f(2) f(2) ans2 d1 = f(2)-f(1) f(2)-f(1) d1 k = (K-1)//2 (K-1)//2 k S = input().strip() input().strip() S def f(k):
    T = S*k
    N = len(T)
    cur = T[0]
    cnt = 1
    ans = 0
    for i in range(1,N):
        if T[i]==cur:
            cnt += 1
        else:
            ans += cnt//2
            cur = T[i]
            cnt = 1
    ans += cnt//2
    return ans def f(k):
    T = S*k
    N = len(T)
    cur = T[0]
    cnt = 1
    ans = 0
    for i in range(1,N):
        if T[i]==cur:
            cnt += 1
        else:
            ans += cnt//2
            cur = T[i]
            cnt = 1
    ans += cnt//2
    return ans f ans1 = f(1) f(1) ans1 K = int(input()) int(input()) K d2 = f(3)-f(2) f(3)-f(2) d2
def f(k):
    T = S*k
    N = len(T)
    cur = T[0]
    cnt = 1
    ans = 0
    for i in range(1,N):
        if T[i]==cur:
            cnt += 1
        else:
            ans += cnt//2
            cur = T[i]
            cnt = 1
    ans += cnt//2
    return ans
S = input().strip()
K = int(input())
ans1 = f(1)
ans2 = f(2)
ans3 = f(3)
d1 = f(2)-f(1)
d2 = f(3)-f(2)
k = (K-1)//2
if (K-1)%2==0:
    print(f(1)+(d1+d2)*k)
else:
    print(f(1)+(d1+d2)*k+d1)