import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    from itertools import groupby

    s = input()
    k = int(readline())
    l = len(s)

    if len(set(s)) == 1:
        return print(l * k // 2)

    ans = 0
    gr = [list(g) for k, g in groupby(s)]
    for g in gr:
        ans += len(g) // 2 * k

    if gr[0][0] == gr[-1][-1]:
        ans += ((len(gr[0]) + len(gr[-1])) // 2) * (k - 1)
        ans -= (len(gr[0]) // 2 + len(gr[-1]) // 2) * (k - 1)

    print(ans)


if __name__ == '__main__':
    main() import sys sys readline = sys.stdin.readline readline sys.stdin.readline sys.stdin sys stdin readline MOD = 10 ** 9 + 7 MOD 10 ** 9 + 7 10 ** 9 10 9 7 INF = float('INF') INF float('INF') float 'INF' sys.setrecursionlimit(10 ** 5) sys.setrecursionlimit sys setrecursionlimit 10 ** 5 10 5 def main():
    from itertools import groupby

    s = input()
    k = int(readline())
    l = len(s)

    if len(set(s)) == 1:
        return print(l * k // 2)

    ans = 0
    gr = [list(g) for k, g in groupby(s)]
    for g in gr:
        ans += len(g) // 2 * k

    if gr[0][0] == gr[-1][-1]:
        ans += ((len(gr[0]) + len(gr[-1])) // 2) * (k - 1)
        ans -= (len(gr[0]) // 2 + len(gr[-1]) // 2) * (k - 1)

    print(ans) main from itertools import groupby s = input() s input() input k = int(readline()) k int(readline()) int readline() readline l = len(s) l len(s) len s if len(set(s)) == 1:
        return print(l * k // 2)

     len(set(s)) == 1 len(set(s)) len set(s) set s 1 return print(l * k // 2) print(l * k // 2) print l * k // 2 l * k l k 2 ans = 0 ans 0 list(g) for k, g in groupby(s) for k, g in groupby(s) k g groupby(s) groupby s for k, g in groupby(s) list(g) list g gr = [list(g) for k, g in groupby(s)] gr [list(g) for k, g in groupby(s)] for g in gr:
        ans += len(g) // 2 * k

     g gr ans += len(g) // 2 * k ans len(g) // 2 * k len(g) // 2 len(g) len g 2 k if gr[0][0] == gr[-1][-1]:
        ans += ((len(gr[0]) + len(gr[-1])) // 2) * (k - 1)
        ans -= (len(gr[0]) // 2 + len(gr[-1]) // 2) * (k - 1)

     gr[0][0] == gr[-1][-1] gr[0][0] [0] gr 0 0 gr[-1][-1] [-1] gr -1 -1 ans += ((len(gr[0]) + len(gr[-1])) // 2) * (k - 1) ans ((len(gr[0]) + len(gr[-1])) // 2) * (k - 1) (len(gr[0]) + len(gr[-1])) // 2 len(gr[0]) + len(gr[-1]) len(gr[0]) len gr[0] gr 0 len(gr[-1]) len gr[-1] gr -1 2 k - 1 k 1 ans -= (len(gr[0]) // 2 + len(gr[-1]) // 2) * (k - 1) ans (len(gr[0]) // 2 + len(gr[-1]) // 2) * (k - 1) len(gr[0]) // 2 + len(gr[-1]) // 2 len(gr[0]) // 2 len(gr[0]) len gr[0] gr 0 2 len(gr[-1]) // 2 len(gr[-1]) len gr[-1] gr -1 2 k - 1 k 1 print(ans) print ans if __name__ == '__main__':
    main() __name__ == '__main__' __name__ '__main__' main() main readline = sys.stdin.readline sys.stdin.readline readline MOD = 10 ** 9 + 7 10 ** 9 + 7 MOD def main():
    from itertools import groupby

    s = input()
    k = int(readline())
    l = len(s)

    if len(set(s)) == 1:
        return print(l * k // 2)

    ans = 0
    gr = [list(g) for k, g in groupby(s)]
    for g in gr:
        ans += len(g) // 2 * k

    if gr[0][0] == gr[-1][-1]:
        ans += ((len(gr[0]) + len(gr[-1])) // 2) * (k - 1)
        ans -= (len(gr[0]) // 2 + len(gr[-1]) // 2) * (k - 1)

    print(ans) def main():
    from itertools import groupby

    s = input()
    k = int(readline())
    l = len(s)

    if len(set(s)) == 1:
        return print(l * k // 2)

    ans = 0
    gr = [list(g) for k, g in groupby(s)]
    for g in gr:
        ans += len(g) // 2 * k

    if gr[0][0] == gr[-1][-1]:
        ans += ((len(gr[0]) + len(gr[-1])) // 2) * (k - 1)
        ans -= (len(gr[0]) // 2 + len(gr[-1]) // 2) * (k - 1)

    print(ans) main INF = float('INF') float('INF') INF
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    from itertools import groupby

    s = input()
    k = int(readline())
    l = len(s)

    if len(set(s)) == 1:
        return print(l * k // 2)

    ans = 0
    gr = [list(g) for k, g in groupby(s)]
    for g in gr:
        ans += len(g) // 2 * k

    if gr[0][0] == gr[-1][-1]:
        ans += ((len(gr[0]) + len(gr[-1])) // 2) * (k - 1)
        ans -= (len(gr[0]) // 2 + len(gr[-1]) // 2) * (k - 1)

    print(ans)


if __name__ == '__main__':
    main()
