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

def f(S):
    res = 0
    count = 1
    length = len(S)
    for i in range(1,length):
        if S[i] == S[i-1]:
            count += 1
        else:
            res += count // 2
            count = 1
    res += count // 2
    return res

res1 = f(s)
res2 = f(s+s)
res3 = f(s+s+s)

if res2 - res1 == res3 - res2:
    print(res1 + (res2-res1) * (k-1))
else:
    print(n * k // 2) s = input() s input() input k = int(input()) k int(input()) int input() input n = len(s) n len(s) len s def f(S):
    res = 0
    count = 1
    length = len(S)
    for i in range(1,length):
        if S[i] == S[i-1]:
            count += 1
        else:
            res += count // 2
            count = 1
    res += count // 2
    return res f res = 0 res 0 count = 1 count 1 length = len(S) length len(S) len S for i in range(1,length):
        if S[i] == S[i-1]:
            count += 1
        else:
            res += count // 2
            count = 1
     i range(1,length) range 1 length if S[i] == S[i-1]:
            count += 1
        else:
            res += count // 2
            count = 1
     S[i] == S[i-1] S[i] S i S[i-1] S i-1 i 1 count += 1 count 1 res += count // 2 res count // 2 count 2 count = 1 count 1 res += count // 2 res count // 2 count 2 return res res S S res1 = f(s) res1 f(s) f s res2 = f(s+s) res2 f(s+s) f s+s s s res3 = f(s+s+s) res3 f(s+s+s) f s+s+s s+s s s s if res2 - res1 == res3 - res2:
    print(res1 + (res2-res1) * (k-1))
else:
    print(n * k // 2) res2 - res1 == res3 - res2 res2 - res1 res2 res1 res3 - res2 res3 res2 print(res1 + (res2-res1) * (k-1)) print res1 + (res2-res1) * (k-1) res1 (res2-res1) * (k-1) res2-res1 res2 res1 k-1 k 1 print(n * k // 2) print n * k // 2 n * k n k 2 n = len(s) len(s) n res1 = f(s) f(s) res1 res2 = f(s+s) f(s+s) res2 k = int(input()) int(input()) k def f(S):
    res = 0
    count = 1
    length = len(S)
    for i in range(1,length):
        if S[i] == S[i-1]:
            count += 1
        else:
            res += count // 2
            count = 1
    res += count // 2
    return res def f(S):
    res = 0
    count = 1
    length = len(S)
    for i in range(1,length):
        if S[i] == S[i-1]:
            count += 1
        else:
            res += count // 2
            count = 1
    res += count // 2
    return res f res3 = f(s+s+s) f(s+s+s) res3 s = input() input() s
s = input()
k = int(input())
n = len(s)

def f(S):
    res = 0
    count = 1
    length = len(S)
    for i in range(1,length):
        if S[i] == S[i-1]:
            count += 1
        else:
            res += count // 2
            count = 1
    res += count // 2
    return res

res1 = f(s)
res2 = f(s+s)
res3 = f(s+s+s)

if res2 - res1 == res3 - res2:
    print(res1 + (res2-res1) * (k-1))
else:
    print(n * k // 2)
