s = list(input())
n = int(input())
ans = 0
if s[0] != s[-1]:
    cnt = 1
    tmp = ''
    for i in range(len(s)):
        if i == 0:
            tmp = s[i]
            continue
        if tmp == s[i]:
            cnt += 1
        else:
            ans += cnt // 2
            cnt = 1
            tmp = s[i]
    ans += cnt // 2
    print(ans*n)
else:
    cnt = 1
    tmp = ''
    f = 0
    for i in range(len(s)):
        if i == 0:
            tmp = s[i]
            continue
        if tmp == s[i]:
            cnt += 1
        else:
            if f == 0:
                f = cnt
            ans += cnt // 2
            cnt = 1
            tmp = s[i]
    ans += cnt // 2
    if f == 0:
        print((cnt*n)//2)
    else:
        m = ans - f//2 - cnt//2
        ans = f // 2 + cnt // 2
        # print(m,ans)
        ans += m * n
        # print(m*n)

        ans += (n-1) * ((f+cnt) // 2)
        # print((n-1)*((f+cnt)//2))
        print(ans) s = list(input()) s list(input()) list input() input n = int(input()) n int(input()) int input() input ans = 0 ans 0 if s[0] != s[-1]:
    cnt = 1
    tmp = ''
    for i in range(len(s)):
        if i == 0:
            tmp = s[i]
            continue
        if tmp == s[i]:
            cnt += 1
        else:
            ans += cnt // 2
            cnt = 1
            tmp = s[i]
    ans += cnt // 2
    print(ans*n)
else:
    cnt = 1
    tmp = ''
    f = 0
    for i in range(len(s)):
        if i == 0:
            tmp = s[i]
            continue
        if tmp == s[i]:
            cnt += 1
        else:
            if f == 0:
                f = cnt
            ans += cnt // 2
            cnt = 1
            tmp = s[i]
    ans += cnt // 2
    if f == 0:
        print((cnt*n)//2)
    else:
        m = ans - f//2 - cnt//2
        ans = f // 2 + cnt // 2
        # print(m,ans)
        ans += m * n
        # print(m*n)

        ans += (n-1) * ((f+cnt) // 2)
        # print((n-1)*((f+cnt)//2))
        print(ans) s[0] != s[-1] s[0] s 0 s[-1] s -1 cnt = 1 cnt 1 tmp = '' tmp '' for i in range(len(s)):
        if i == 0:
            tmp = s[i]
            continue
        if tmp == s[i]:
            cnt += 1
        else:
            ans += cnt // 2
            cnt = 1
            tmp = s[i]
     i range(len(s)) range len(s) len s if i == 0:
            tmp = s[i]
            continue
         i == 0 i 0 tmp = s[i] tmp s[i] s i continue if tmp == s[i]:
            cnt += 1
        else:
            ans += cnt // 2
            cnt = 1
            tmp = s[i]
     tmp == s[i] tmp s[i] s i cnt += 1 cnt 1 ans += cnt // 2 ans cnt // 2 cnt 2 cnt = 1 cnt 1 tmp = s[i] tmp s[i] s i ans += cnt // 2 ans cnt // 2 cnt 2 print(ans*n) print ans*n ans n cnt = 1 cnt 1 tmp = '' tmp '' f = 0 f 0 for i in range(len(s)):
        if i == 0:
            tmp = s[i]
            continue
        if tmp == s[i]:
            cnt += 1
        else:
            if f == 0:
                f = cnt
            ans += cnt // 2
            cnt = 1
            tmp = s[i]
     i range(len(s)) range len(s) len s if i == 0:
            tmp = s[i]
            continue
         i == 0 i 0 tmp = s[i] tmp s[i] s i continue if tmp == s[i]:
            cnt += 1
        else:
            if f == 0:
                f = cnt
            ans += cnt // 2
            cnt = 1
            tmp = s[i]
     tmp == s[i] tmp s[i] s i cnt += 1 cnt 1 if f == 0:
                f = cnt
             f == 0 f 0 f = cnt f cnt ans += cnt // 2 ans cnt // 2 cnt 2 cnt = 1 cnt 1 tmp = s[i] tmp s[i] s i ans += cnt // 2 ans cnt // 2 cnt 2 if f == 0:
        print((cnt*n)//2)
    else:
        m = ans - f//2 - cnt//2
        ans = f // 2 + cnt // 2
        # print(m,ans)
        ans += m * n
        # print(m*n)

        ans += (n-1) * ((f+cnt) // 2)
        # print((n-1)*((f+cnt)//2))
        print(ans) f == 0 f 0 print((cnt*n)//2) print (cnt*n)//2 cnt*n cnt n 2 m = ans - f//2 - cnt//2 m ans - f//2 - cnt//2 ans - f//2 ans f//2 f 2 cnt//2 cnt 2 ans = f // 2 + cnt // 2 ans f // 2 + cnt // 2 f // 2 f 2 cnt // 2 cnt 2 ans += m * n ans m * n m n ans += (n-1) * ((f+cnt) // 2) ans (n-1) * ((f+cnt) // 2) n-1 n 1 (f+cnt) // 2 f+cnt f cnt 2 print(ans) print ans cnt += 1 1 cnt ans += cnt // 2 cnt // 2 ans tmp = '' '' tmp tmp = s[i] s[i] tmp ans = 0 0 ans ans += m * n m * n ans tmp = s[i] s[i] tmp tmp = s[i] s[i] tmp cnt = 1 1 cnt ans += cnt // 2 cnt // 2 ans cnt = 1 1 cnt tmp = '' '' tmp tmp = s[i] s[i] tmp ans += (n-1) * ((f+cnt) // 2) (n-1) * ((f+cnt) // 2) ans n = int(input()) int(input()) n cnt = 1 1 cnt ans += cnt // 2 cnt // 2 ans ans += cnt // 2 cnt // 2 ans ans = f // 2 + cnt // 2 f // 2 + cnt // 2 ans m = ans - f//2 - cnt//2 ans - f//2 - cnt//2 m f = cnt cnt f f = 0 0 f s = list(input()) list(input()) s cnt = 1 1 cnt cnt += 1 1 cnt
s = list(input())
n = int(input())
ans = 0
if s[0] != s[-1]:
    cnt = 1
    tmp = ''
    for i in range(len(s)):
        if i == 0:
            tmp = s[i]
            continue
        if tmp == s[i]:
            cnt += 1
        else:
            ans += cnt // 2
            cnt = 1
            tmp = s[i]
    ans += cnt // 2
    print(ans*n)
else:
    cnt = 1
    tmp = ''
    f = 0
    for i in range(len(s)):
        if i == 0:
            tmp = s[i]
            continue
        if tmp == s[i]:
            cnt += 1
        else:
            if f == 0:
                f = cnt
            ans += cnt // 2
            cnt = 1
            tmp = s[i]
    ans += cnt // 2
    if f == 0:
        print((cnt*n)//2)
    else:
        m = ans - f//2 - cnt//2
        ans = f // 2 + cnt // 2
        # print(m,ans)
        ans += m * n
        # print(m*n)

        ans += (n-1) * ((f+cnt) // 2)
        # print((n-1)*((f+cnt)//2))
        print(ans)
