s = list(input())
k = int(input())

l = len(s)

ss = s + s
ll = len(ss)

single = 0
cnt = 0

for i in range(1, l):
    if s[i - 1] == s[i]:
        if cnt == 0:
            single += 1
            cnt = 1
        else:
            if cnt % 2 == 0:
                single += 1
                cnt += 1
            else:
                cnt += 1
    else:
        cnt = 0

double = 0
cnt = 0

for i in range(1, ll):
    if ss[i - 1] == ss[i]:
        if cnt == 0:
            double += 1
            cnt = 1
        else:
            if cnt % 2 == 0:
                double += 1
                cnt += 1
            else:
                cnt += 1
    else:
        cnt = 0

if len(set(s)) == 1:
    ans = double * (k // 2) + single * (k % 2)
elif single * 2 == double:
    ans = single * k
else:
    ans = single + (single + 1) * (k - 1)

# print(single, double)
print(ans) s = list(input()) s list(input()) list input() input k = int(input()) k int(input()) int input() input l = len(s) l len(s) len s ss = s + s ss s + s s s ll = len(ss) ll len(ss) len ss single = 0 single 0 cnt = 0 cnt 0 for i in range(1, l):
    if s[i - 1] == s[i]:
        if cnt == 0:
            single += 1
            cnt = 1
        else:
            if cnt % 2 == 0:
                single += 1
                cnt += 1
            else:
                cnt += 1
    else:
        cnt = 0 i range(1, l) range 1 l if s[i - 1] == s[i]:
        if cnt == 0:
            single += 1
            cnt = 1
        else:
            if cnt % 2 == 0:
                single += 1
                cnt += 1
            else:
                cnt += 1
    else:
        cnt = 0 s[i - 1] == s[i] s[i - 1] s i - 1 i 1 s[i] s i if cnt == 0:
            single += 1
            cnt = 1
        else:
            if cnt % 2 == 0:
                single += 1
                cnt += 1
            else:
                cnt += 1
     cnt == 0 cnt 0 single += 1 single 1 cnt = 1 cnt 1 if cnt % 2 == 0:
                single += 1
                cnt += 1
            else:
                cnt += 1
     cnt % 2 == 0 cnt % 2 cnt 2 0 single += 1 single 1 cnt += 1 cnt 1 cnt += 1 cnt 1 cnt = 0 cnt 0 double = 0 double 0 cnt = 0 cnt 0 for i in range(1, ll):
    if ss[i - 1] == ss[i]:
        if cnt == 0:
            double += 1
            cnt = 1
        else:
            if cnt % 2 == 0:
                double += 1
                cnt += 1
            else:
                cnt += 1
    else:
        cnt = 0 i range(1, ll) range 1 ll if ss[i - 1] == ss[i]:
        if cnt == 0:
            double += 1
            cnt = 1
        else:
            if cnt % 2 == 0:
                double += 1
                cnt += 1
            else:
                cnt += 1
    else:
        cnt = 0 ss[i - 1] == ss[i] ss[i - 1] ss i - 1 i 1 ss[i] ss i if cnt == 0:
            double += 1
            cnt = 1
        else:
            if cnt % 2 == 0:
                double += 1
                cnt += 1
            else:
                cnt += 1
     cnt == 0 cnt 0 double += 1 double 1 cnt = 1 cnt 1 if cnt % 2 == 0:
                double += 1
                cnt += 1
            else:
                cnt += 1
     cnt % 2 == 0 cnt % 2 cnt 2 0 double += 1 double 1 cnt += 1 cnt 1 cnt += 1 cnt 1 cnt = 0 cnt 0 if len(set(s)) == 1:
    ans = double * (k // 2) + single * (k % 2)
elif single * 2 == double:
    ans = single * k
else:
    ans = single + (single + 1) * (k - 1)

# print(single, double) len(set(s)) == 1 len(set(s)) len set(s) set s 1 ans = double * (k // 2) + single * (k % 2) ans double * (k // 2) + single * (k % 2) double * (k // 2) double k // 2 k 2 single * (k % 2) single k % 2 k 2 elif single * 2 == double:
    ans = single * k single * 2 == double single * 2 single 2 double ans = single * k ans single * k single k ans = single + (single + 1) * (k - 1) ans single + (single + 1) * (k - 1) single (single + 1) * (k - 1) single + 1 single 1 k - 1 k 1 print(ans) print ans single += 1 1 single l = len(s) len(s) l single += 1 1 single cnt += 1 1 cnt ans = single * k single * k ans cnt = 0 0 cnt double += 1 1 double ss = s + s s + s ss cnt = 0 0 cnt s = list(input()) list(input()) s k = int(input()) int(input()) k cnt = 0 0 cnt ll = len(ss) len(ss) ll cnt = 1 1 cnt cnt = 1 1 cnt cnt += 1 1 cnt ans = double * (k // 2) + single * (k % 2) double * (k // 2) + single * (k % 2) ans cnt = 0 0 cnt cnt += 1 1 cnt double = 0 0 double double += 1 1 double single = 0 0 single cnt += 1 1 cnt ans = single + (single + 1) * (k - 1) single + (single + 1) * (k - 1) ans
s = list(input())
k = int(input())

l = len(s)

ss = s + s
ll = len(ss)

single = 0
cnt = 0

for i in range(1, l):
    if s[i - 1] == s[i]:
        if cnt == 0:
            single += 1
            cnt = 1
        else:
            if cnt % 2 == 0:
                single += 1
                cnt += 1
            else:
                cnt += 1
    else:
        cnt = 0

double = 0
cnt = 0

for i in range(1, ll):
    if ss[i - 1] == ss[i]:
        if cnt == 0:
            double += 1
            cnt = 1
        else:
            if cnt % 2 == 0:
                double += 1
                cnt += 1
            else:
                cnt += 1
    else:
        cnt = 0

if len(set(s)) == 1:
    ans = double * (k // 2) + single * (k % 2)
elif single * 2 == double:
    ans = single * k
else:
    ans = single + (single + 1) * (k - 1)

# print(single, double)
print(ans)
