if __name__ == '__main__':
    s = list(input())
    ss = s + s
    k = int(input())
    if len(set(s)) == 1:
        print(len(s) * k // 2)
        exit(0)

    tmp, tmp2 = 0, 0
    for i in range(len(s) - 1):
        if s[i] == s[i + 1]:
            tmp += 1
            s[i + 1] = '-1'
    for i in range(len(s) * 2 - 1):
        if ss[i] == ss[i + 1]:
            tmp2 += 1
            ss[i + 1] = '-1'
    print(tmp + (tmp2 - tmp) * (k - 1)) if __name__ == '__main__':
    s = list(input())
    ss = s + s
    k = int(input())
    if len(set(s)) == 1:
        print(len(s) * k // 2)
        exit(0)

    tmp, tmp2 = 0, 0
    for i in range(len(s) - 1):
        if s[i] == s[i + 1]:
            tmp += 1
            s[i + 1] = '-1'
    for i in range(len(s) * 2 - 1):
        if ss[i] == ss[i + 1]:
            tmp2 += 1
            ss[i + 1] = '-1'
    print(tmp + (tmp2 - tmp) * (k - 1)) __name__ == '__main__' __name__ '__main__' s = list(input()) s list(input()) list input() input ss = s + s ss s + s s s k = int(input()) k int(input()) int input() input if len(set(s)) == 1:
        print(len(s) * k // 2)
        exit(0)

     len(set(s)) == 1 len(set(s)) len set(s) set s 1 print(len(s) * k // 2) print len(s) * k // 2 len(s) * k len(s) len s k 2 exit(0) exit 0 tmp, tmp2 = 0, 0 tmp 0 tmp2 0 for i in range(len(s) - 1):
        if s[i] == s[i + 1]:
            tmp += 1
            s[i + 1] = '-1'
     i range(len(s) - 1) range len(s) - 1 len(s) len s 1 if s[i] == s[i + 1]:
            tmp += 1
            s[i + 1] = '-1'
     s[i] == s[i + 1] s[i] s i s[i + 1] s i + 1 i 1 tmp += 1 tmp 1 s[i + 1] = '-1' s[i + 1] s i + 1 i 1 '-1' for i in range(len(s) * 2 - 1):
        if ss[i] == ss[i + 1]:
            tmp2 += 1
            ss[i + 1] = '-1'
     i range(len(s) * 2 - 1) range len(s) * 2 - 1 len(s) * 2 len(s) len s 2 1 if ss[i] == ss[i + 1]:
            tmp2 += 1
            ss[i + 1] = '-1'
     ss[i] == ss[i + 1] ss[i] ss i ss[i + 1] ss i + 1 i 1 tmp2 += 1 tmp2 1 ss[i + 1] = '-1' ss[i + 1] ss i + 1 i 1 '-1' print(tmp + (tmp2 - tmp) * (k - 1)) print tmp + (tmp2 - tmp) * (k - 1) tmp (tmp2 - tmp) * (k - 1) tmp2 - tmp tmp2 tmp k - 1 k 1 s = list(input()) list(input()) s k = int(input()) int(input()) k tmp += 1 1 tmp tmp2 += 1 1 tmp2 ss = s + s s + s ss tmp, tmp2 = 0, 0 0 tmp tmp2 = 0, 0 0 tmp2
if __name__ == '__main__':
    s = list(input())
    ss = s + s
    k = int(input())
    if len(set(s)) == 1:
        print(len(s) * k // 2)
        exit(0)

    tmp, tmp2 = 0, 0
    for i in range(len(s) - 1):
        if s[i] == s[i + 1]:
            tmp += 1
            s[i + 1] = '-1'
    for i in range(len(s) * 2 - 1):
        if ss[i] == ss[i + 1]:
            tmp2 += 1
            ss[i + 1] = '-1'
    print(tmp + (tmp2 - tmp) * (k - 1))
