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

if len(set(s)) == 1:
    print(len(s) * k // 2)
else:
    l = []
    tmp = s[0]
    tmp_c = 1
    for i in range(1,len(s)):
        if s[i] == tmp:
            tmp_c += 1
        else:
            l.append(tmp_c)
            tmp_c = 1
            tmp = s[i]
    l.append(tmp_c)
    ans = sum([k*(x//2) for x in l])
    if s[0] == s[-1]:
        a = 1
        tmp = s[0]
        for i in range(1,len(s)):
            if s[i] == tmp:
                a += 1
            else:
                break
        b = 1
        tmp = s[-1]
        for i in s[-2::-1]:
            if i == tmp:
                b += 1
            else:
                break
        ans -= (a//2 + b//2 - (a+b)//2) * (k-1)
    print(ans) s = input() s input() input k = int(input()) k int(input()) int input() input if len(set(s)) == 1:
    print(len(s) * k // 2)
else:
    l = []
    tmp = s[0]
    tmp_c = 1
    for i in range(1,len(s)):
        if s[i] == tmp:
            tmp_c += 1
        else:
            l.append(tmp_c)
            tmp_c = 1
            tmp = s[i]
    l.append(tmp_c)
    ans = sum([k*(x//2) for x in l])
    if s[0] == s[-1]:
        a = 1
        tmp = s[0]
        for i in range(1,len(s)):
            if s[i] == tmp:
                a += 1
            else:
                break
        b = 1
        tmp = s[-1]
        for i in s[-2::-1]:
            if i == tmp:
                b += 1
            else:
                break
        ans -= (a//2 + b//2 - (a+b)//2) * (k-1)
    print(ans) 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 l = [] l [] tmp = s[0] tmp s[0] s 0 tmp_c = 1 tmp_c 1 for i in range(1,len(s)):
        if s[i] == tmp:
            tmp_c += 1
        else:
            l.append(tmp_c)
            tmp_c = 1
            tmp = s[i]
     i range(1,len(s)) range 1 len(s) len s if s[i] == tmp:
            tmp_c += 1
        else:
            l.append(tmp_c)
            tmp_c = 1
            tmp = s[i]
     s[i] == tmp s[i] s i tmp tmp_c += 1 tmp_c 1 l.append(tmp_c) l.append l append tmp_c tmp_c = 1 tmp_c 1 tmp = s[i] tmp s[i] s i l.append(tmp_c) l.append l append tmp_c k*(x//2) for x in l for x in l x l for x in l k*(x//2) k x//2 x 2 ans = sum([k*(x//2) for x in l]) ans sum([k*(x//2) for x in l]) sum [k*(x//2) for x in l] if s[0] == s[-1]:
        a = 1
        tmp = s[0]
        for i in range(1,len(s)):
            if s[i] == tmp:
                a += 1
            else:
                break
        b = 1
        tmp = s[-1]
        for i in s[-2::-1]:
            if i == tmp:
                b += 1
            else:
                break
        ans -= (a//2 + b//2 - (a+b)//2) * (k-1)
     s[0] == s[-1] s[0] s 0 s[-1] s -1 a = 1 a 1 tmp = s[0] tmp s[0] s 0 for i in range(1,len(s)):
            if s[i] == tmp:
                a += 1
            else:
                break
         i range(1,len(s)) range 1 len(s) len s if s[i] == tmp:
                a += 1
            else:
                break
         s[i] == tmp s[i] s i tmp a += 1 a 1 break b = 1 b 1 tmp = s[-1] tmp s[-1] s -1 for i in s[-2::-1]:
            if i == tmp:
                b += 1
            else:
                break
         i s[-2::-1] s -2::-1 -2 -1 if i == tmp:
                b += 1
            else:
                break
         i == tmp i tmp b += 1 b 1 break ans -= (a//2 + b//2 - (a+b)//2) * (k-1) ans (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 print(ans) print ans ans = sum([k*(x//2) for x in l]) sum([k*(x//2) for x in l]) ans a += 1 1 a tmp = s[i] s[i] tmp tmp = s[0] s[0] tmp tmp_c += 1 1 tmp_c k = int(input()) int(input()) k l = [] [] l ans -= (a//2 + b//2 - (a+b)//2) * (k-1) (a//2 + b//2 - (a+b)//2) * (k-1) ans b = 1 1 b tmp = s[0] s[0] tmp tmp_c = 1 1 tmp_c tmp = s[-1] s[-1] tmp b += 1 1 b s = input() input() s a = 1 1 a tmp_c = 1 1 tmp_c
s = input()
k = int(input())

if len(set(s)) == 1:
    print(len(s) * k // 2)
else:
    l = []
    tmp = s[0]
    tmp_c = 1
    for i in range(1,len(s)):
        if s[i] == tmp:
            tmp_c += 1
        else:
            l.append(tmp_c)
            tmp_c = 1
            tmp = s[i]
    l.append(tmp_c)
    ans = sum([k*(x//2) for x in l])
    if s[0] == s[-1]:
        a = 1
        tmp = s[0]
        for i in range(1,len(s)):
            if s[i] == tmp:
                a += 1
            else:
                break
        b = 1
        tmp = s[-1]
        for i in s[-2::-1]:
            if i == tmp:
                b += 1
            else:
                break
        ans -= (a//2 + b//2 - (a+b)//2) * (k-1)
    print(ans)