#!/usr/bin/env python3

def main():
    S = input()
    K = int(input())

    cnt = 0
    ans = 0
    s_temp = S[0]
    fcnt = 0
    for s in S:
        if s_temp == s:
            cnt += 1
            s_temp = s
        else:
            ans += cnt // 2
            if fcnt == 0:
                fcnt = cnt
            cnt = 1
            s_temp = s
    if fcnt == 0:
        fcnt = cnt
    ans += cnt // 2
    ans *= K
    if len(S) == fcnt:
        ans = (len(S) * K) // 2
    elif S[0] == S[-1] and cnt % 2 == 1 and fcnt % 2 == 1:
        ans += K - 1

    print(ans)


if __name__ == "__main__":
    main() def main():
    S = input()
    K = int(input())

    cnt = 0
    ans = 0
    s_temp = S[0]
    fcnt = 0
    for s in S:
        if s_temp == s:
            cnt += 1
            s_temp = s
        else:
            ans += cnt // 2
            if fcnt == 0:
                fcnt = cnt
            cnt = 1
            s_temp = s
    if fcnt == 0:
        fcnt = cnt
    ans += cnt // 2
    ans *= K
    if len(S) == fcnt:
        ans = (len(S) * K) // 2
    elif S[0] == S[-1] and cnt % 2 == 1 and fcnt % 2 == 1:
        ans += K - 1

    print(ans) main S = input() S input() input K = int(input()) K int(input()) int input() input cnt = 0 cnt 0 ans = 0 ans 0 s_temp = S[0] s_temp S[0] S 0 fcnt = 0 fcnt 0 for s in S:
        if s_temp == s:
            cnt += 1
            s_temp = s
        else:
            ans += cnt // 2
            if fcnt == 0:
                fcnt = cnt
            cnt = 1
            s_temp = s
     s S if s_temp == s:
            cnt += 1
            s_temp = s
        else:
            ans += cnt // 2
            if fcnt == 0:
                fcnt = cnt
            cnt = 1
            s_temp = s
     s_temp == s s_temp s cnt += 1 cnt 1 s_temp = s s_temp s ans += cnt // 2 ans cnt // 2 cnt 2 if fcnt == 0:
                fcnt = cnt
             fcnt == 0 fcnt 0 fcnt = cnt fcnt cnt cnt = 1 cnt 1 s_temp = s s_temp s if fcnt == 0:
        fcnt = cnt
     fcnt == 0 fcnt 0 fcnt = cnt fcnt cnt ans += cnt // 2 ans cnt // 2 cnt 2 ans *= K ans K if len(S) == fcnt:
        ans = (len(S) * K) // 2
    elif S[0] == S[-1] and cnt % 2 == 1 and fcnt % 2 == 1:
        ans += K - 1

     len(S) == fcnt len(S) len S fcnt ans = (len(S) * K) // 2 ans (len(S) * K) // 2 len(S) * K len(S) len S K 2 elif S[0] == S[-1] and cnt % 2 == 1 and fcnt % 2 == 1:
        ans += K - 1

     S[0] == S[-1] and cnt % 2 == 1 and fcnt % 2 == 1 S[0] == S[-1] and cnt % 2 == 1 S[0] == S[-1] S[0] S 0 S[-1] S -1 cnt % 2 == 1 cnt % 2 cnt 2 1 fcnt % 2 == 1 fcnt % 2 fcnt 2 1 ans += K - 1 ans K - 1 K 1 print(ans) print ans if __name__ == "__main__":
    main() __name__ == "__main__" __name__ "__main__" main() main def main():
    S = input()
    K = int(input())

    cnt = 0
    ans = 0
    s_temp = S[0]
    fcnt = 0
    for s in S:
        if s_temp == s:
            cnt += 1
            s_temp = s
        else:
            ans += cnt // 2
            if fcnt == 0:
                fcnt = cnt
            cnt = 1
            s_temp = s
    if fcnt == 0:
        fcnt = cnt
    ans += cnt // 2
    ans *= K
    if len(S) == fcnt:
        ans = (len(S) * K) // 2
    elif S[0] == S[-1] and cnt % 2 == 1 and fcnt % 2 == 1:
        ans += K - 1

    print(ans) def main():
    S = input()
    K = int(input())

    cnt = 0
    ans = 0
    s_temp = S[0]
    fcnt = 0
    for s in S:
        if s_temp == s:
            cnt += 1
            s_temp = s
        else:
            ans += cnt // 2
            if fcnt == 0:
                fcnt = cnt
            cnt = 1
            s_temp = s
    if fcnt == 0:
        fcnt = cnt
    ans += cnt // 2
    ans *= K
    if len(S) == fcnt:
        ans = (len(S) * K) // 2
    elif S[0] == S[-1] and cnt % 2 == 1 and fcnt % 2 == 1:
        ans += K - 1

    print(ans) main
#!/usr/bin/env python3

def main():
    S = input()
    K = int(input())

    cnt = 0
    ans = 0
    s_temp = S[0]
    fcnt = 0
    for s in S:
        if s_temp == s:
            cnt += 1
            s_temp = s
        else:
            ans += cnt // 2
            if fcnt == 0:
                fcnt = cnt
            cnt = 1
            s_temp = s
    if fcnt == 0:
        fcnt = cnt
    ans += cnt // 2
    ans *= K
    if len(S) == fcnt:
        ans = (len(S) * K) // 2
    elif S[0] == S[-1] and cnt % 2 == 1 and fcnt % 2 == 1:
        ans += K - 1

    print(ans)


if __name__ == "__main__":
    main()
