from collections import Counter
s = input()
k = int(input())

# 全部同じ
C = Counter(s)
if len(C) == 1:
    print(len(s) * k // 2)
    exit()

# 両端が異なる
if s[0] != s[-1]:
    aida = 0
    cnt = 0
    for i in range(1,len(s)):
        if s[i] == s[i-1]:
            cnt += 1
        else:
            tmp = cnt // 2
            if cnt % 2 != 0:
                aida += tmp + 1
            else:
                aida += tmp
            cnt = 0
    tmp = cnt // 2
    if cnt % 2 != 0:
        aida += tmp + 1
    else:
        aida += tmp


    print(aida * k)

# 両端が同じ
else:
    # 先端の個数
    cnt = 1
    for i in range(1,len(s)):
        if s[i] == s[i-1]:
            cnt += 1
        else:
            break
    # 末端の個数
    cnt2 = 1
    for i in range(len(s)-1,-1,-1):
        if s[i] == s[i-1]:
            cnt2 += 1
        else:
            break

    # 先端で書き換える個数
    syoko = cnt // 2

    # 末端＋先端で書き換える個数
    sotogawa = (cnt + cnt2) // 2

    # 先端と末端の間で書き換える個数
    aida = 0
    cnt3 = 0
    #print(s[cnt : len(s)-cnt2])
    for i in range(cnt+1,len(s)-cnt2+1):
        if s[i] == s[i-1]:
            cnt3 += 1
        else:
            tmp = cnt3 // 2
            if cnt3 % 2 != 0:
                aida += tmp + 1
            else:
                aida += tmp
            cnt3 = 0

    saikuru = aida + sotogawa
    print(syoko + saikuru * k - saikuru + aida + cnt2//2)



 from collections import Counter s = input() s input() input k = int(input()) k int(input()) int input() input C = Counter(s) C Counter(s) Counter s if len(C) == 1:
    print(len(s) * k // 2)
    exit()

# 両端が異なる len(C) == 1 len(C) len C 1 print(len(s) * k // 2) print len(s) * k // 2 len(s) * k len(s) len s k 2 exit() exit if s[0] != s[-1]:
    aida = 0
    cnt = 0
    for i in range(1,len(s)):
        if s[i] == s[i-1]:
            cnt += 1
        else:
            tmp = cnt // 2
            if cnt % 2 != 0:
                aida += tmp + 1
            else:
                aida += tmp
            cnt = 0
    tmp = cnt // 2
    if cnt % 2 != 0:
        aida += tmp + 1
    else:
        aida += tmp


    print(aida * k)

# 両端が同じ
else:
    # 先端の個数
    cnt = 1
    for i in range(1,len(s)):
        if s[i] == s[i-1]:
            cnt += 1
        else:
            break
    # 末端の個数
    cnt2 = 1
    for i in range(len(s)-1,-1,-1):
        if s[i] == s[i-1]:
            cnt2 += 1
        else:
            break

    # 先端で書き換える個数
    syoko = cnt // 2

    # 末端＋先端で書き換える個数
    sotogawa = (cnt + cnt2) // 2

    # 先端と末端の間で書き換える個数
    aida = 0
    cnt3 = 0
    #print(s[cnt : len(s)-cnt2])
    for i in range(cnt+1,len(s)-cnt2+1):
        if s[i] == s[i-1]:
            cnt3 += 1
        else:
            tmp = cnt3 // 2
            if cnt3 % 2 != 0:
                aida += tmp + 1
            else:
                aida += tmp
            cnt3 = 0

    saikuru = aida + sotogawa
    print(syoko + saikuru * k - saikuru + aida + cnt2//2) s[0] != s[-1] s[0] s 0 s[-1] s -1 aida = 0 aida 0 cnt = 0 cnt 0 for i in range(1,len(s)):
        if s[i] == s[i-1]:
            cnt += 1
        else:
            tmp = cnt // 2
            if cnt % 2 != 0:
                aida += tmp + 1
            else:
                aida += tmp
            cnt = 0
     i range(1,len(s)) range 1 len(s) len s if s[i] == s[i-1]:
            cnt += 1
        else:
            tmp = cnt // 2
            if cnt % 2 != 0:
                aida += tmp + 1
            else:
                aida += tmp
            cnt = 0
     s[i] == s[i-1] s[i] s i s[i-1] s i-1 i 1 cnt += 1 cnt 1 tmp = cnt // 2 tmp cnt // 2 cnt 2 if cnt % 2 != 0:
                aida += tmp + 1
            else:
                aida += tmp
             cnt % 2 != 0 cnt % 2 cnt 2 0 aida += tmp + 1 aida tmp + 1 tmp 1 aida += tmp aida tmp cnt = 0 cnt 0 tmp = cnt // 2 tmp cnt // 2 cnt 2 if cnt % 2 != 0:
        aida += tmp + 1
    else:
        aida += tmp


     cnt % 2 != 0 cnt % 2 cnt 2 0 aida += tmp + 1 aida tmp + 1 tmp 1 aida += tmp aida tmp print(aida * k) print aida * k aida k cnt = 1 cnt 1 for i in range(1,len(s)):
        if s[i] == s[i-1]:
            cnt += 1
        else:
            break
    # 末端の個数
     i range(1,len(s)) range 1 len(s) len s if s[i] == s[i-1]:
            cnt += 1
        else:
            break
    # 末端の個数
     s[i] == s[i-1] s[i] s i s[i-1] s i-1 i 1 cnt += 1 cnt 1 break cnt2 = 1 cnt2 1 for i in range(len(s)-1,-1,-1):
        if s[i] == s[i-1]:
            cnt2 += 1
        else:
            break

    # 先端で書き換える個数
     i range(len(s)-1,-1,-1) range len(s)-1 len(s) len s 1 -1 -1 if s[i] == s[i-1]:
            cnt2 += 1
        else:
            break

    # 先端で書き換える個数
     s[i] == s[i-1] s[i] s i s[i-1] s i-1 i 1 cnt2 += 1 cnt2 1 break syoko = cnt // 2 syoko cnt // 2 cnt 2 sotogawa = (cnt + cnt2) // 2 sotogawa (cnt + cnt2) // 2 cnt + cnt2 cnt cnt2 2 aida = 0 aida 0 cnt3 = 0 cnt3 0 for i in range(cnt+1,len(s)-cnt2+1):
        if s[i] == s[i-1]:
            cnt3 += 1
        else:
            tmp = cnt3 // 2
            if cnt3 % 2 != 0:
                aida += tmp + 1
            else:
                aida += tmp
            cnt3 = 0

     i range(cnt+1,len(s)-cnt2+1) range cnt+1 cnt 1 len(s)-cnt2+1 len(s)-cnt2 len(s) len s cnt2 1 if s[i] == s[i-1]:
            cnt3 += 1
        else:
            tmp = cnt3 // 2
            if cnt3 % 2 != 0:
                aida += tmp + 1
            else:
                aida += tmp
            cnt3 = 0

     s[i] == s[i-1] s[i] s i s[i-1] s i-1 i 1 cnt3 += 1 cnt3 1 tmp = cnt3 // 2 tmp cnt3 // 2 cnt3 2 if cnt3 % 2 != 0:
                aida += tmp + 1
            else:
                aida += tmp
             cnt3 % 2 != 0 cnt3 % 2 cnt3 2 0 aida += tmp + 1 aida tmp + 1 tmp 1 aida += tmp aida tmp cnt3 = 0 cnt3 0 saikuru = aida + sotogawa saikuru aida + sotogawa aida sotogawa print(syoko + saikuru * k - saikuru + aida + cnt2//2) print syoko + saikuru * k - saikuru + aida + cnt2//2 syoko + saikuru * k - saikuru + aida syoko + saikuru * k - saikuru syoko + saikuru * k syoko saikuru * k saikuru k saikuru aida cnt2//2 cnt2 2 cnt2 = 1 1 cnt2 syoko = cnt // 2 cnt // 2 syoko aida += tmp + 1 tmp + 1 aida tmp = cnt3 // 2 cnt3 // 2 tmp C = Counter(s) Counter(s) C saikuru = aida + sotogawa aida + sotogawa saikuru cnt = 0 0 cnt cnt = 0 0 cnt cnt += 1 1 cnt aida += tmp tmp aida cnt2 += 1 1 cnt2 cnt = 1 1 cnt cnt3 = 0 0 cnt3 s = input() input() s cnt3 = 0 0 cnt3 cnt3 += 1 1 cnt3 k = int(input()) int(input()) k aida = 0 0 aida aida = 0 0 aida tmp = cnt // 2 cnt // 2 tmp aida += tmp + 1 tmp + 1 aida aida += tmp + 1 tmp + 1 aida aida += tmp tmp aida cnt += 1 1 cnt aida += tmp tmp aida tmp = cnt // 2 cnt // 2 tmp sotogawa = (cnt + cnt2) // 2 (cnt + cnt2) // 2 sotogawa
from collections import Counter
s = input()
k = int(input())

# 全部同じ
C = Counter(s)
if len(C) == 1:
    print(len(s) * k // 2)
    exit()

# 両端が異なる
if s[0] != s[-1]:
    aida = 0
    cnt = 0
    for i in range(1,len(s)):
        if s[i] == s[i-1]:
            cnt += 1
        else:
            tmp = cnt // 2
            if cnt % 2 != 0:
                aida += tmp + 1
            else:
                aida += tmp
            cnt = 0
    tmp = cnt // 2
    if cnt % 2 != 0:
        aida += tmp + 1
    else:
        aida += tmp


    print(aida * k)

# 両端が同じ
else:
    # 先端の個数
    cnt = 1
    for i in range(1,len(s)):
        if s[i] == s[i-1]:
            cnt += 1
        else:
            break
    # 末端の個数
    cnt2 = 1
    for i in range(len(s)-1,-1,-1):
        if s[i] == s[i-1]:
            cnt2 += 1
        else:
            break

    # 先端で書き換える個数
    syoko = cnt // 2

    # 末端＋先端で書き換える個数
    sotogawa = (cnt + cnt2) // 2

    # 先端と末端の間で書き換える個数
    aida = 0
    cnt3 = 0
    #print(s[cnt : len(s)-cnt2])
    for i in range(cnt+1,len(s)-cnt2+1):
        if s[i] == s[i-1]:
            cnt3 += 1
        else:
            tmp = cnt3 // 2
            if cnt3 % 2 != 0:
                aida += tmp + 1
            else:
                aida += tmp
            cnt3 = 0

    saikuru = aida + sotogawa
    print(syoko + saikuru * k - saikuru + aida + cnt2//2)




