def main():
    S = input()
    K = int(input())
    if len(set(S)) == 1:
        print((len(S) * K)//2)
        return
    result = 0
    piyo = 0
    hoge = S[0]
    huga = 1
    first = 0
    for s in S[1:]:
        if s == hoge:
            huga += 1
            if huga % 2 == 0:
                piyo += 1
        else:
            if first == 0:
                first = huga
            hoge = s
            huga = 1
    if first == 0:
        first = huga
    if first % 2 == 1 and huga % 2 == 1 and S[0] == S[-1]:
        result += K - 1
    print(piyo * K + result)
main() def main():
    S = input()
    K = int(input())
    if len(set(S)) == 1:
        print((len(S) * K)//2)
        return
    result = 0
    piyo = 0
    hoge = S[0]
    huga = 1
    first = 0
    for s in S[1:]:
        if s == hoge:
            huga += 1
            if huga % 2 == 0:
                piyo += 1
        else:
            if first == 0:
                first = huga
            hoge = s
            huga = 1
    if first == 0:
        first = huga
    if first % 2 == 1 and huga % 2 == 1 and S[0] == S[-1]:
        result += K - 1
    print(piyo * K + result) main S = input() S input() input K = int(input()) K int(input()) int input() input if len(set(S)) == 1:
        print((len(S) * K)//2)
        return
     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 return result = 0 result 0 piyo = 0 piyo 0 hoge = S[0] hoge S[0] S 0 huga = 1 huga 1 first = 0 first 0 for s in S[1:]:
        if s == hoge:
            huga += 1
            if huga % 2 == 0:
                piyo += 1
        else:
            if first == 0:
                first = huga
            hoge = s
            huga = 1
     s S[1:] S 1: 1 if s == hoge:
            huga += 1
            if huga % 2 == 0:
                piyo += 1
        else:
            if first == 0:
                first = huga
            hoge = s
            huga = 1
     s == hoge s hoge huga += 1 huga 1 if huga % 2 == 0:
                piyo += 1
         huga % 2 == 0 huga % 2 huga 2 0 piyo += 1 piyo 1 if first == 0:
                first = huga
             first == 0 first 0 first = huga first huga hoge = s hoge s huga = 1 huga 1 if first == 0:
        first = huga
     first == 0 first 0 first = huga first huga if first % 2 == 1 and huga % 2 == 1 and S[0] == S[-1]:
        result += K - 1
     first % 2 == 1 and huga % 2 == 1 and S[0] == S[-1] first % 2 == 1 and huga % 2 == 1 first % 2 == 1 first % 2 first 2 1 huga % 2 == 1 huga % 2 huga 2 1 S[0] == S[-1] S[0] S 0 S[-1] S -1 result += K - 1 result K - 1 K 1 print(piyo * K + result) print piyo * K + result piyo * K piyo K result main() main def main():
    S = input()
    K = int(input())
    if len(set(S)) == 1:
        print((len(S) * K)//2)
        return
    result = 0
    piyo = 0
    hoge = S[0]
    huga = 1
    first = 0
    for s in S[1:]:
        if s == hoge:
            huga += 1
            if huga % 2 == 0:
                piyo += 1
        else:
            if first == 0:
                first = huga
            hoge = s
            huga = 1
    if first == 0:
        first = huga
    if first % 2 == 1 and huga % 2 == 1 and S[0] == S[-1]:
        result += K - 1
    print(piyo * K + result) def main():
    S = input()
    K = int(input())
    if len(set(S)) == 1:
        print((len(S) * K)//2)
        return
    result = 0
    piyo = 0
    hoge = S[0]
    huga = 1
    first = 0
    for s in S[1:]:
        if s == hoge:
            huga += 1
            if huga % 2 == 0:
                piyo += 1
        else:
            if first == 0:
                first = huga
            hoge = s
            huga = 1
    if first == 0:
        first = huga
    if first % 2 == 1 and huga % 2 == 1 and S[0] == S[-1]:
        result += K - 1
    print(piyo * K + result) main
def main():
    S = input()
    K = int(input())
    if len(set(S)) == 1:
        print((len(S) * K)//2)
        return
    result = 0
    piyo = 0
    hoge = S[0]
    huga = 1
    first = 0
    for s in S[1:]:
        if s == hoge:
            huga += 1
            if huga % 2 == 0:
                piyo += 1
        else:
            if first == 0:
                first = huga
            hoge = s
            huga = 1
    if first == 0:
        first = huga
    if first % 2 == 1 and huga % 2 == 1 and S[0] == S[-1]:
        result += K - 1
    print(piyo * K + result)
main()
