s = input()
k = int(input())
n = len(s)
renzoku_flag =False
renzoku_count = 0
count = 0
for i in range(n):
    if i != n-1:
        if s[i] == s[i+1]:
            renzoku_count += 1 #iのをカウントしている
        else:
            renzoku_count += 1 #i+1の分をカウント
            count += renzoku_count // 2
            renzoku_count = 0
    else:
        if s[n-2] == s[n-1]:
            renzoku_count += 1
        count += renzoku_count // 2

if s[0] != s[-1]:
    print(count*k)
else:
    ans = count*k
    initial = s[0]

    start_count = 0
    for i in range(n):
        if s[i] == initial:
            start_count += 1
        else:
            break
    else:
        print(n*k//2)
        exit()

    end_count = 0
    for i in range(n)[::-1]:
        if s[i] == initial:
            end_count += 1
        else:
            break

    ans -= (start_count//2 + end_count//2 - (start_count+end_count)//2)*(k-1)
    print(ans) s = input() s input() input k = int(input()) k int(input()) int input() input n = len(s) n len(s) len s renzoku_flag =False renzoku_flag False renzoku_count = 0 renzoku_count 0 count = 0 count 0 for i in range(n):
    if i != n-1:
        if s[i] == s[i+1]:
            renzoku_count += 1 #iのをカウントしている
        else:
            renzoku_count += 1 #i+1の分をカウント
            count += renzoku_count // 2
            renzoku_count = 0
    else:
        if s[n-2] == s[n-1]:
            renzoku_count += 1
        count += renzoku_count // 2 i range(n) range n if i != n-1:
        if s[i] == s[i+1]:
            renzoku_count += 1 #iのをカウントしている
        else:
            renzoku_count += 1 #i+1の分をカウント
            count += renzoku_count // 2
            renzoku_count = 0
    else:
        if s[n-2] == s[n-1]:
            renzoku_count += 1
        count += renzoku_count // 2 i != n-1 i n-1 n 1 if s[i] == s[i+1]:
            renzoku_count += 1 #iのをカウントしている
        else:
            renzoku_count += 1 #i+1の分をカウント
            count += renzoku_count // 2
            renzoku_count = 0
     s[i] == s[i+1] s[i] s i s[i+1] s i+1 i 1 renzoku_count += 1 renzoku_count 1 renzoku_count += 1 renzoku_count 1 count += renzoku_count // 2 count renzoku_count // 2 renzoku_count 2 renzoku_count = 0 renzoku_count 0 if s[n-2] == s[n-1]:
            renzoku_count += 1
         s[n-2] == s[n-1] s[n-2] s n-2 n 2 s[n-1] s n-1 n 1 renzoku_count += 1 renzoku_count 1 count += renzoku_count // 2 count renzoku_count // 2 renzoku_count 2 if s[0] != s[-1]:
    print(count*k)
else:
    ans = count*k
    initial = s[0]

    start_count = 0
    for i in range(n):
        if s[i] == initial:
            start_count += 1
        else:
            break
    else:
        print(n*k//2)
        exit()

    end_count = 0
    for i in range(n)[::-1]:
        if s[i] == initial:
            end_count += 1
        else:
            break

    ans -= (start_count//2 + end_count//2 - (start_count+end_count)//2)*(k-1)
    print(ans) s[0] != s[-1] s[0] s 0 s[-1] s -1 print(count*k) print count*k count k ans = count*k ans count*k count k initial = s[0] initial s[0] s 0 start_count = 0 start_count 0 for i in range(n):
        if s[i] == initial:
            start_count += 1
        else:
            break
    else:
        print(n*k//2)
        exit()

     i range(n) range n if s[i] == initial:
            start_count += 1
        else:
            break
     s[i] == initial s[i] s i initial start_count += 1 start_count 1 break print(n*k//2) print n*k//2 n*k n k 2 exit() exit end_count = 0 end_count 0 for i in range(n)[::-1]:
        if s[i] == initial:
            end_count += 1
        else:
            break

     i range(n)[::-1] (n) range n ::-1 -1 if s[i] == initial:
            end_count += 1
        else:
            break

     s[i] == initial s[i] s i initial end_count += 1 end_count 1 break ans -= (start_count//2 + end_count//2 - (start_count+end_count)//2)*(k-1) ans (start_count//2 + end_count//2 - (start_count+end_count)//2)*(k-1) start_count//2 + end_count//2 - (start_count+end_count)//2 start_count//2 + end_count//2 start_count//2 start_count 2 end_count//2 end_count 2 (start_count+end_count)//2 start_count+end_count start_count end_count 2 k-1 k 1 print(ans) print ans renzoku_count += 1 1 renzoku_count k = int(input()) int(input()) k renzoku_flag =False False renzoku_flag initial = s[0] s[0] initial end_count += 1 1 end_count renzoku_count = 0 0 renzoku_count renzoku_count += 1 1 renzoku_count count += renzoku_count // 2 renzoku_count // 2 count n = len(s) len(s) n count += renzoku_count // 2 renzoku_count // 2 count ans = count*k count*k ans end_count = 0 0 end_count renzoku_count += 1 1 renzoku_count s = input() input() s start_count += 1 1 start_count ans -= (start_count//2 + end_count//2 - (start_count+end_count)//2)*(k-1) (start_count//2 + end_count//2 - (start_count+end_count)//2)*(k-1) ans count = 0 0 count start_count = 0 0 start_count renzoku_count = 0 0 renzoku_count
s = input()
k = int(input())
n = len(s)
renzoku_flag =False
renzoku_count = 0
count = 0
for i in range(n):
    if i != n-1:
        if s[i] == s[i+1]:
            renzoku_count += 1 #iのをカウントしている
        else:
            renzoku_count += 1 #i+1の分をカウント
            count += renzoku_count // 2
            renzoku_count = 0
    else:
        if s[n-2] == s[n-1]:
            renzoku_count += 1
        count += renzoku_count // 2

if s[0] != s[-1]:
    print(count*k)
else:
    ans = count*k
    initial = s[0]

    start_count = 0
    for i in range(n):
        if s[i] == initial:
            start_count += 1
        else:
            break
    else:
        print(n*k//2)
        exit()

    end_count = 0
    for i in range(n)[::-1]:
        if s[i] == initial:
            end_count += 1
        else:
            break

    ans -= (start_count//2 + end_count//2 - (start_count+end_count)//2)*(k-1)
    print(ans)
