# import sys
# sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
def II(): return int(input())

def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())

def LI(): return list(map(int, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]


def solve():
    S = list(input())
    k = II()
    n = len(S)
    S2 = S[:]

    if len(set(S)) == 1:
        print(n * k // 2)
    else:
        cnt = 0
        for i in range(n-1):
            j = i + 1
            si, sj = S[i], S[j]
            if si == sj:
                S[j] = i
                cnt += 1
        if S[0] == S[-1]:
            moji = S[0]
            sl = 0
            for s in S2:
                if s == moji:
                    sl += 1
                else:
                    break
            sr = 0
            for s in S2[::-1]:
                if s == moji:
                    sr += 1
                else:
                    break

            print(cnt * k + ((sl+sr)//2 - sl//2 - sr//2) * (k - 1))
        else:
            print(cnt * k)


if __name__ == '__main__':
    solve() int1 = lambda x: int(x) - 1 int1 lambda x: int(x) - 1 int(x) - 1 int(x) int x 1 x def II(): return int(input()) II def MI(): return map(int, input().split()) MI def MI1(): return map(int1, input().split()) MI1 def LI(): return list(map(int, input().split())) LI LI() for _ in range(rows_number) for _ in range(rows_number) _ range(rows_number) range rows_number for _ in range(rows_number) LI() LI def LLI(rows_number): return [LI() for _ in range(rows_number)] LLI rows_number rows_number def solve():
    S = list(input())
    k = II()
    n = len(S)
    S2 = S[:]

    if len(set(S)) == 1:
        print(n * k // 2)
    else:
        cnt = 0
        for i in range(n-1):
            j = i + 1
            si, sj = S[i], S[j]
            if si == sj:
                S[j] = i
                cnt += 1
        if S[0] == S[-1]:
            moji = S[0]
            sl = 0
            for s in S2:
                if s == moji:
                    sl += 1
                else:
                    break
            sr = 0
            for s in S2[::-1]:
                if s == moji:
                    sr += 1
                else:
                    break

            print(cnt * k + ((sl+sr)//2 - sl//2 - sr//2) * (k - 1))
        else:
            print(cnt * k) solve S = list(input()) S list(input()) list input() input k = II() k II() II n = len(S) n len(S) len S S2 = S[:] S2 S[:] S : if len(set(S)) == 1:
        print(n * k // 2)
    else:
        cnt = 0
        for i in range(n-1):
            j = i + 1
            si, sj = S[i], S[j]
            if si == sj:
                S[j] = i
                cnt += 1
        if S[0] == S[-1]:
            moji = S[0]
            sl = 0
            for s in S2:
                if s == moji:
                    sl += 1
                else:
                    break
            sr = 0
            for s in S2[::-1]:
                if s == moji:
                    sr += 1
                else:
                    break

            print(cnt * k + ((sl+sr)//2 - sl//2 - sr//2) * (k - 1))
        else:
            print(cnt * k) len(set(S)) == 1 len(set(S)) len set(S) set S 1 print(n * k // 2) print n * k // 2 n * k n k 2 cnt = 0 cnt 0 for i in range(n-1):
            j = i + 1
            si, sj = S[i], S[j]
            if si == sj:
                S[j] = i
                cnt += 1
         i range(n-1) range n-1 n 1 j = i + 1 j i + 1 i 1 si, sj = S[i], S[j] si S[i] S i sj S[j] S j if si == sj:
                S[j] = i
                cnt += 1
         si == sj si sj S[j] = i S[j] S j i cnt += 1 cnt 1 if S[0] == S[-1]:
            moji = S[0]
            sl = 0
            for s in S2:
                if s == moji:
                    sl += 1
                else:
                    break
            sr = 0
            for s in S2[::-1]:
                if s == moji:
                    sr += 1
                else:
                    break

            print(cnt * k + ((sl+sr)//2 - sl//2 - sr//2) * (k - 1))
        else:
            print(cnt * k) S[0] == S[-1] S[0] S 0 S[-1] S -1 moji = S[0] moji S[0] S 0 sl = 0 sl 0 for s in S2:
                if s == moji:
                    sl += 1
                else:
                    break
             s S2 if s == moji:
                    sl += 1
                else:
                    break
             s == moji s moji sl += 1 sl 1 break sr = 0 sr 0 for s in S2[::-1]:
                if s == moji:
                    sr += 1
                else:
                    break

             s S2[::-1] S2 ::-1 -1 if s == moji:
                    sr += 1
                else:
                    break

             s == moji s moji sr += 1 sr 1 break print(cnt * k + ((sl+sr)//2 - sl//2 - sr//2) * (k - 1)) print cnt * k + ((sl+sr)//2 - sl//2 - sr//2) * (k - 1) cnt * k cnt k ((sl+sr)//2 - sl//2 - sr//2) * (k - 1) (sl+sr)//2 - sl//2 - sr//2 (sl+sr)//2 - sl//2 (sl+sr)//2 sl+sr sl sr 2 sl//2 sl 2 sr//2 sr 2 k - 1 k 1 print(cnt * k) print cnt * k cnt k if __name__ == '__main__':
    solve() __name__ == '__main__' __name__ '__main__' solve() solve def solve():
    S = list(input())
    k = II()
    n = len(S)
    S2 = S[:]

    if len(set(S)) == 1:
        print(n * k // 2)
    else:
        cnt = 0
        for i in range(n-1):
            j = i + 1
            si, sj = S[i], S[j]
            if si == sj:
                S[j] = i
                cnt += 1
        if S[0] == S[-1]:
            moji = S[0]
            sl = 0
            for s in S2:
                if s == moji:
                    sl += 1
                else:
                    break
            sr = 0
            for s in S2[::-1]:
                if s == moji:
                    sr += 1
                else:
                    break

            print(cnt * k + ((sl+sr)//2 - sl//2 - sr//2) * (k - 1))
        else:
            print(cnt * k) def solve():
    S = list(input())
    k = II()
    n = len(S)
    S2 = S[:]

    if len(set(S)) == 1:
        print(n * k // 2)
    else:
        cnt = 0
        for i in range(n-1):
            j = i + 1
            si, sj = S[i], S[j]
            if si == sj:
                S[j] = i
                cnt += 1
        if S[0] == S[-1]:
            moji = S[0]
            sl = 0
            for s in S2:
                if s == moji:
                    sl += 1
                else:
                    break
            sr = 0
            for s in S2[::-1]:
                if s == moji:
                    sr += 1
                else:
                    break

            print(cnt * k + ((sl+sr)//2 - sl//2 - sr//2) * (k - 1))
        else:
            print(cnt * k) solve def LLI(rows_number): return [LI() for _ in range(rows_number)] def LLI(rows_number): return [LI() for _ in range(rows_number)] LLI int1 = lambda x: int(x) - 1 lambda x: int(x) - 1 int1 def LI(): return list(map(int, input().split())) def LI(): return list(map(int, input().split())) LI def II(): return int(input()) def II(): return int(input()) II def MI(): return map(int, input().split()) def MI(): return map(int, input().split()) MI def MI1(): return map(int1, input().split()) def MI1(): return map(int1, input().split()) MI1
# import sys
# sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
def II(): return int(input())

def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())

def LI(): return list(map(int, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]


def solve():
    S = list(input())
    k = II()
    n = len(S)
    S2 = S[:]

    if len(set(S)) == 1:
        print(n * k // 2)
    else:
        cnt = 0
        for i in range(n-1):
            j = i + 1
            si, sj = S[i], S[j]
            if si == sj:
                S[j] = i
                cnt += 1
        if S[0] == S[-1]:
            moji = S[0]
            sl = 0
            for s in S2:
                if s == moji:
                    sl += 1
                else:
                    break
            sr = 0
            for s in S2[::-1]:
                if s == moji:
                    sr += 1
                else:
                    break

            print(cnt * k + ((sl+sr)//2 - sl//2 - sr//2) * (k - 1))
        else:
            print(cnt * k)


if __name__ == '__main__':
    solve()
