s = input()
k = int(input())

vals = []
cur = s[0]
strk = 1

for i in range(1, len(s)):
    if s[i] == cur:
        strk += 1
    else:
        vals.append([cur, strk])
        cur = s[i]
        strk = 1
vals.append([cur, strk])

if len(vals) == 1:
    print((vals[0][1] * k) // 2)
else:
    if vals[0][0] == vals[-1][0]:
        start = vals[0][1] // 2
        join = (vals[0][1] + vals[-1][1]) // 2
        end = vals[-1][1] // 2

        middle = 0
        for i in range(1, len(vals)-1):
            middle += vals[i][1] // 2

        print(start + k*middle + (k-1)*join + end)
    else:
        cnt = 0
        for val in vals:
            cnt += (val[1]) // 2

        print(cnt*k) s = input() s input() input k = int(input()) k int(input()) int input() input vals = [] vals [] cur = s[0] cur s[0] s 0 strk = 1 strk 1 for i in range(1, len(s)):
    if s[i] == cur:
        strk += 1
    else:
        vals.append([cur, strk])
        cur = s[i]
        strk = 1 i range(1, len(s)) range 1 len(s) len s if s[i] == cur:
        strk += 1
    else:
        vals.append([cur, strk])
        cur = s[i]
        strk = 1 s[i] == cur s[i] s i cur strk += 1 strk 1 vals.append([cur, strk]) vals.append vals append [cur, strk] cur strk cur = s[i] cur s[i] s i strk = 1 strk 1 vals.append([cur, strk]) vals.append vals append [cur, strk] cur strk if len(vals) == 1:
    print((vals[0][1] * k) // 2)
else:
    if vals[0][0] == vals[-1][0]:
        start = vals[0][1] // 2
        join = (vals[0][1] + vals[-1][1]) // 2
        end = vals[-1][1] // 2

        middle = 0
        for i in range(1, len(vals)-1):
            middle += vals[i][1] // 2

        print(start + k*middle + (k-1)*join + end)
    else:
        cnt = 0
        for val in vals:
            cnt += (val[1]) // 2

        print(cnt*k) len(vals) == 1 len(vals) len vals 1 print((vals[0][1] * k) // 2) print (vals[0][1] * k) // 2 vals[0][1] * k vals[0][1] [0] vals 0 1 k 2 if vals[0][0] == vals[-1][0]:
        start = vals[0][1] // 2
        join = (vals[0][1] + vals[-1][1]) // 2
        end = vals[-1][1] // 2

        middle = 0
        for i in range(1, len(vals)-1):
            middle += vals[i][1] // 2

        print(start + k*middle + (k-1)*join + end)
    else:
        cnt = 0
        for val in vals:
            cnt += (val[1]) // 2

        print(cnt*k) vals[0][0] == vals[-1][0] vals[0][0] [0] vals 0 0 vals[-1][0] [-1] vals -1 0 start = vals[0][1] // 2 start vals[0][1] // 2 vals[0][1] [0] vals 0 1 2 join = (vals[0][1] + vals[-1][1]) // 2 join (vals[0][1] + vals[-1][1]) // 2 vals[0][1] + vals[-1][1] vals[0][1] [0] vals 0 1 vals[-1][1] [-1] vals -1 1 2 end = vals[-1][1] // 2 end vals[-1][1] // 2 vals[-1][1] [-1] vals -1 1 2 middle = 0 middle 0 for i in range(1, len(vals)-1):
            middle += vals[i][1] // 2

         i range(1, len(vals)-1) range 1 len(vals)-1 len(vals) len vals 1 middle += vals[i][1] // 2 middle vals[i][1] // 2 vals[i][1] [i] vals i 1 2 print(start + k*middle + (k-1)*join + end) print start + k*middle + (k-1)*join + end start + k*middle + (k-1)*join start + k*middle start k*middle k middle (k-1)*join k-1 k 1 join end cnt = 0 cnt 0 for val in vals:
            cnt += (val[1]) // 2

         val vals cnt += (val[1]) // 2 cnt (val[1]) // 2 val[1] val 1 2 print(cnt*k) print cnt*k cnt k strk = 1 1 strk cnt += (val[1]) // 2 (val[1]) // 2 cnt strk = 1 1 strk middle += vals[i][1] // 2 vals[i][1] // 2 middle s = input() input() s start = vals[0][1] // 2 vals[0][1] // 2 start vals = [] [] vals middle = 0 0 middle join = (vals[0][1] + vals[-1][1]) // 2 (vals[0][1] + vals[-1][1]) // 2 join cur = s[0] s[0] cur k = int(input()) int(input()) k cur = s[i] s[i] cur cnt = 0 0 cnt strk += 1 1 strk end = vals[-1][1] // 2 vals[-1][1] // 2 end
s = input()
k = int(input())

vals = []
cur = s[0]
strk = 1

for i in range(1, len(s)):
    if s[i] == cur:
        strk += 1
    else:
        vals.append([cur, strk])
        cur = s[i]
        strk = 1
vals.append([cur, strk])

if len(vals) == 1:
    print((vals[0][1] * k) // 2)
else:
    if vals[0][0] == vals[-1][0]:
        start = vals[0][1] // 2
        join = (vals[0][1] + vals[-1][1]) // 2
        end = vals[-1][1] // 2

        middle = 0
        for i in range(1, len(vals)-1):
            middle += vals[i][1] // 2

        print(start + k*middle + (k-1)*join + end)
    else:
        cnt = 0
        for val in vals:
            cnt += (val[1]) // 2

        print(cnt*k)