# Author: cr4zjh0bp
# Created: Sat Mar 14 20:41:10 UTC 2020
import sys
 
stdin = sys.stdin
inf = 1 << 60
mod = 1000000007
 
ni = lambda: int(ns())
nin = lambda y: [ni() for _ in range(y)]
na = lambda: list(map(int, stdin.readline().split()))
nan = lambda y: [na() for _ in range(y)]
nf = lambda: float(ns())
nfn = lambda y: [nf() for _ in range(y)]
nfa = lambda: list(map(float, stdin.readline().split()))
nfan = lambda y: [nfa() for _ in range(y)]
ns = lambda: stdin.readline().rstrip()
nsn = lambda y: [ns() for _ in range(y)]
ncl = lambda y: [list(ns()) for _ in range(y)]
nas = lambda: stdin.readline().split()

from collections import Counter

s = ns()
n = len(s)
s = s + "$"
k = ni()

c = []
cnt = 1
for i in range(len(s) - 1):
    if s[i] == s[i + 1]:
        cnt += 1
    elif cnt > 1:
        c.append(cnt)
        cnt = 1

if (len(c) == 1 and c[0] == n) or n == 1:
    print(n * k // 2)
elif s[0] != s[-2]:
    print(sum([x // 2 for x in c[:]]) * k)
else:
    a, b = 1, 1
    if s[0] == s[1]:
        a = c[0]
    if s[-2] == s[-3]:
        b = c[-1]
    print(sum([x // 2 for x in c[:]]) * k - (a // 2 + b // 2 - (a + b) // 2) * (k - 1)) import sys sys stdin = sys.stdin stdin sys.stdin sys stdin inf = 1 << 60 inf 1 << 60 1 60 mod = 1000000007 mod 1000000007 ni = lambda: int(ns()) ni lambda: int(ns()) int(ns()) int ns() ns ni() for _ in range(y) for _ in range(y) _ range(y) range y for _ in range(y) ni() ni nin = lambda y: [ni() for _ in range(y)] nin lambda y: [ni() for _ in range(y)] [ni() for _ in range(y)] y na = lambda: list(map(int, stdin.readline().split())) na lambda: list(map(int, stdin.readline().split())) list(map(int, stdin.readline().split())) list map(int, stdin.readline().split()) map int stdin.readline().split() stdin.readline().split stdin.readline() stdin.readline stdin readline split na() for _ in range(y) for _ in range(y) _ range(y) range y for _ in range(y) na() na nan = lambda y: [na() for _ in range(y)] nan lambda y: [na() for _ in range(y)] [na() for _ in range(y)] y nf = lambda: float(ns()) nf lambda: float(ns()) float(ns()) float ns() ns nf() for _ in range(y) for _ in range(y) _ range(y) range y for _ in range(y) nf() nf nfn = lambda y: [nf() for _ in range(y)] nfn lambda y: [nf() for _ in range(y)] [nf() for _ in range(y)] y nfa = lambda: list(map(float, stdin.readline().split())) nfa lambda: list(map(float, stdin.readline().split())) list(map(float, stdin.readline().split())) list map(float, stdin.readline().split()) map float stdin.readline().split() stdin.readline().split stdin.readline() stdin.readline stdin readline split nfa() for _ in range(y) for _ in range(y) _ range(y) range y for _ in range(y) nfa() nfa nfan = lambda y: [nfa() for _ in range(y)] nfan lambda y: [nfa() for _ in range(y)] [nfa() for _ in range(y)] y ns = lambda: stdin.readline().rstrip() ns lambda: stdin.readline().rstrip() stdin.readline().rstrip() stdin.readline().rstrip stdin.readline() stdin.readline stdin readline rstrip ns() for _ in range(y) for _ in range(y) _ range(y) range y for _ in range(y) ns() ns nsn = lambda y: [ns() for _ in range(y)] nsn lambda y: [ns() for _ in range(y)] [ns() for _ in range(y)] y list(ns()) for _ in range(y) for _ in range(y) _ range(y) range y for _ in range(y) list(ns()) list ns() ns ncl = lambda y: [list(ns()) for _ in range(y)] ncl lambda y: [list(ns()) for _ in range(y)] [list(ns()) for _ in range(y)] y nas = lambda: stdin.readline().split() nas lambda: stdin.readline().split() stdin.readline().split() stdin.readline().split stdin.readline() stdin.readline stdin readline split from collections import Counter s = ns() s ns() ns n = len(s) n len(s) len s s = s + "$" s s + "$" s "$" k = ni() k ni() ni c = [] c [] cnt = 1 cnt 1 for i in range(len(s) - 1):
    if s[i] == s[i + 1]:
        cnt += 1
    elif cnt > 1:
        c.append(cnt)
        cnt = 1 i range(len(s) - 1) range len(s) - 1 len(s) len s 1 if s[i] == s[i + 1]:
        cnt += 1
    elif cnt > 1:
        c.append(cnt)
        cnt = 1 s[i] == s[i + 1] s[i] s i s[i + 1] s i + 1 i 1 cnt += 1 cnt 1 elif cnt > 1:
        c.append(cnt)
        cnt = 1 cnt > 1 cnt 1 c.append(cnt) c.append c append cnt cnt = 1 cnt 1 if (len(c) == 1 and c[0] == n) or n == 1:
    print(n * k // 2)
elif s[0] != s[-2]:
    print(sum([x // 2 for x in c[:]]) * k)
else:
    a, b = 1, 1
    if s[0] == s[1]:
        a = c[0]
    if s[-2] == s[-3]:
        b = c[-1]
    print(sum([x // 2 for x in c[:]]) * k - (a // 2 + b // 2 - (a + b) // 2) * (k - 1)) (len(c) == 1 and c[0] == n) or n == 1 len(c) == 1 and c[0] == n len(c) == 1 len(c) len c 1 c[0] == n c[0] c 0 n n == 1 n 1 print(n * k // 2) print n * k // 2 n * k n k 2 elif s[0] != s[-2]:
    print(sum([x // 2 for x in c[:]]) * k) s[0] != s[-2] s[0] s 0 s[-2] s -2 x // 2 for x in c[:] for x in c[:] x c[:] c : for x in c[:] x // 2 x 2 print(sum([x // 2 for x in c[:]]) * k) print sum([x // 2 for x in c[:]]) * k sum([x // 2 for x in c[:]]) sum [x // 2 for x in c[:]] k a, b = 1, 1 a 1 b 1 if s[0] == s[1]:
        a = c[0]
     s[0] == s[1] s[0] s 0 s[1] s 1 a = c[0] a c[0] c 0 if s[-2] == s[-3]:
        b = c[-1]
     s[-2] == s[-3] s[-2] s -2 s[-3] s -3 b = c[-1] b c[-1] c -1 x // 2 for x in c[:] for x in c[:] x c[:] c : for x in c[:] x // 2 x 2 print(sum([x // 2 for x in c[:]]) * k - (a // 2 + b // 2 - (a + b) // 2) * (k - 1)) print sum([x // 2 for x in c[:]]) * k - (a // 2 + b // 2 - (a + b) // 2) * (k - 1) sum([x // 2 for x in c[:]]) * k sum([x // 2 for x in c[:]]) sum [x // 2 for x in c[:]] k (a // 2 + b // 2 - (a + b) // 2) * (k - 1) a // 2 + b // 2 - (a + b) // 2 a // 2 + b // 2 a // 2 a 2 b // 2 b 2 (a + b) // 2 a + b a b 2 k - 1 k 1 nfa = lambda: list(map(float, stdin.readline().split())) lambda: list(map(float, stdin.readline().split())) nfa ns = lambda: stdin.readline().rstrip() lambda: stdin.readline().rstrip() ns nf = lambda: float(ns()) lambda: float(ns()) nf s = ns() ns() s k = ni() ni() k a, b = 1, 1 1 a cnt += 1 1 cnt cnt = 1 1 cnt ncl = lambda y: [list(ns()) for _ in range(y)] lambda y: [list(ns()) for _ in range(y)] ncl a = c[0] c[0] a s = s + "$" s + "$" s ni = lambda: int(ns()) lambda: int(ns()) ni nas = lambda: stdin.readline().split() lambda: stdin.readline().split() nas cnt = 1 1 cnt nan = lambda y: [na() for _ in range(y)] lambda y: [na() for _ in range(y)] nan b = 1, 1 1 b na = lambda: list(map(int, stdin.readline().split())) lambda: list(map(int, stdin.readline().split())) na b = c[-1] c[-1] b nfan = lambda y: [nfa() for _ in range(y)] lambda y: [nfa() for _ in range(y)] nfan stdin = sys.stdin sys.stdin stdin nfn = lambda y: [nf() for _ in range(y)] lambda y: [nf() for _ in range(y)] nfn c = [] [] c nin = lambda y: [ni() for _ in range(y)] lambda y: [ni() for _ in range(y)] nin mod = 1000000007 1000000007 mod inf = 1 << 60 1 << 60 inf nsn = lambda y: [ns() for _ in range(y)] lambda y: [ns() for _ in range(y)] nsn n = len(s) len(s) n
# Author: cr4zjh0bp
# Created: Sat Mar 14 20:41:10 UTC 2020
import sys
 
stdin = sys.stdin
inf = 1 << 60
mod = 1000000007
 
ni = lambda: int(ns())
nin = lambda y: [ni() for _ in range(y)]
na = lambda: list(map(int, stdin.readline().split()))
nan = lambda y: [na() for _ in range(y)]
nf = lambda: float(ns())
nfn = lambda y: [nf() for _ in range(y)]
nfa = lambda: list(map(float, stdin.readline().split()))
nfan = lambda y: [nfa() for _ in range(y)]
ns = lambda: stdin.readline().rstrip()
nsn = lambda y: [ns() for _ in range(y)]
ncl = lambda y: [list(ns()) for _ in range(y)]
nas = lambda: stdin.readline().split()

from collections import Counter

s = ns()
n = len(s)
s = s + "$"
k = ni()

c = []
cnt = 1
for i in range(len(s) - 1):
    if s[i] == s[i + 1]:
        cnt += 1
    elif cnt > 1:
        c.append(cnt)
        cnt = 1

if (len(c) == 1 and c[0] == n) or n == 1:
    print(n * k // 2)
elif s[0] != s[-2]:
    print(sum([x // 2 for x in c[:]]) * k)
else:
    a, b = 1, 1
    if s[0] == s[1]:
        a = c[0]
    if s[-2] == s[-3]:
        b = c[-1]
    print(sum([x // 2 for x in c[:]]) * k - (a // 2 + b // 2 - (a + b) // 2) * (k - 1))