def main():
    S = input()
    K = int(input())
    l = []
    t = 1
    m = S[0]
    if len(S) == 1:
        print(K//2)
        return
    if len(S) == 2:
        if S[0] == S[1]:
            print(K)
            return
        else:
            print(0)
            return
    if len(S) == 3:
        if S[0] == S[1] == S[2]:
            print(3*K//2)
            return
        elif S[0] == S[1] or S[1] == S[2]:
            print(K)
            return
        elif S[0] == S[2]:
            print(K-1)
            return
        else:
            print(0)
            return
    for v in S[1:]:
        if v == m:
            t += 1
        elif t != 1:
            l.append(t)
            t = 1
        m = v
    if t != 1:
        l.append(t)
    ls = 0
    lsm = 0
    lsu = 0
    if S[0] == S[-1]:
        if len(l) == 1 and l[0] == len(S):
            print(l[0] * K//2)
            return
        elif len(l) == 1:
            print(((l[0] + 1)//2) *(K-1) + (l[0] // 2))
            return
        if S[0] == S[1] == S[-2]:
            ls = l[-1] + l[0]
            lsm = l[0]
            lsu = l[-1]
            l = l[1:-1]
        elif S[-1] == S[-2]:
            ls = l[-1] + 1
            lsu = l[-1]
            l = l[:-1]
        elif S[0] == S[1]:
            ls = l[0] + 1
            lsm = l[0]
            l = l[1:]
        else:
            ls = 2
    r = 0
    for i in l:
        r += i // 2
    r *= K
    r += (K-1) * (ls // 2)
    r += (lsm  // 2) + (lsu // 2)
    print(r)
main() def main():
    S = input()
    K = int(input())
    l = []
    t = 1
    m = S[0]
    if len(S) == 1:
        print(K//2)
        return
    if len(S) == 2:
        if S[0] == S[1]:
            print(K)
            return
        else:
            print(0)
            return
    if len(S) == 3:
        if S[0] == S[1] == S[2]:
            print(3*K//2)
            return
        elif S[0] == S[1] or S[1] == S[2]:
            print(K)
            return
        elif S[0] == S[2]:
            print(K-1)
            return
        else:
            print(0)
            return
    for v in S[1:]:
        if v == m:
            t += 1
        elif t != 1:
            l.append(t)
            t = 1
        m = v
    if t != 1:
        l.append(t)
    ls = 0
    lsm = 0
    lsu = 0
    if S[0] == S[-1]:
        if len(l) == 1 and l[0] == len(S):
            print(l[0] * K//2)
            return
        elif len(l) == 1:
            print(((l[0] + 1)//2) *(K-1) + (l[0] // 2))
            return
        if S[0] == S[1] == S[-2]:
            ls = l[-1] + l[0]
            lsm = l[0]
            lsu = l[-1]
            l = l[1:-1]
        elif S[-1] == S[-2]:
            ls = l[-1] + 1
            lsu = l[-1]
            l = l[:-1]
        elif S[0] == S[1]:
            ls = l[0] + 1
            lsm = l[0]
            l = l[1:]
        else:
            ls = 2
    r = 0
    for i in l:
        r += i // 2
    r *= K
    r += (K-1) * (ls // 2)
    r += (lsm  // 2) + (lsu // 2)
    print(r) main S = input() S input() input K = int(input()) K int(input()) int input() input l = [] l [] t = 1 t 1 m = S[0] m S[0] S 0 if len(S) == 1:
        print(K//2)
        return
     len(S) == 1 len(S) len S 1 print(K//2) print K//2 K 2 return if len(S) == 2:
        if S[0] == S[1]:
            print(K)
            return
        else:
            print(0)
            return
     len(S) == 2 len(S) len S 2 if S[0] == S[1]:
            print(K)
            return
        else:
            print(0)
            return
     S[0] == S[1] S[0] S 0 S[1] S 1 print(K) print K return print(0) print 0 return if len(S) == 3:
        if S[0] == S[1] == S[2]:
            print(3*K//2)
            return
        elif S[0] == S[1] or S[1] == S[2]:
            print(K)
            return
        elif S[0] == S[2]:
            print(K-1)
            return
        else:
            print(0)
            return
     len(S) == 3 len(S) len S 3 if S[0] == S[1] == S[2]:
            print(3*K//2)
            return
        elif S[0] == S[1] or S[1] == S[2]:
            print(K)
            return
        elif S[0] == S[2]:
            print(K-1)
            return
        else:
            print(0)
            return
     S[0] == S[1] == S[2] S[0] == S[1] S[0] S 0 S[1] S 1 S[2] S 2 print(3*K//2) print 3*K//2 3*K 3 K 2 return elif S[0] == S[1] or S[1] == S[2]:
            print(K)
            return
         S[0] == S[1] or S[1] == S[2] S[0] == S[1] S[0] S 0 S[1] S 1 S[1] == S[2] S[1] S 1 S[2] S 2 print(K) print K return elif S[0] == S[2]:
            print(K-1)
            return
         S[0] == S[2] S[0] S 0 S[2] S 2 print(K-1) print K-1 K 1 return print(0) print 0 return for v in S[1:]:
        if v == m:
            t += 1
        elif t != 1:
            l.append(t)
            t = 1
        m = v
     v S[1:] S 1: 1 if v == m:
            t += 1
        elif t != 1:
            l.append(t)
            t = 1
         v == m v m t += 1 t 1 elif t != 1:
            l.append(t)
            t = 1
         t != 1 t 1 l.append(t) l.append l append t t = 1 t 1 m = v m v if t != 1:
        l.append(t)
     t != 1 t 1 l.append(t) l.append l append t ls = 0 ls 0 lsm = 0 lsm 0 lsu = 0 lsu 0 if S[0] == S[-1]:
        if len(l) == 1 and l[0] == len(S):
            print(l[0] * K//2)
            return
        elif len(l) == 1:
            print(((l[0] + 1)//2) *(K-1) + (l[0] // 2))
            return
        if S[0] == S[1] == S[-2]:
            ls = l[-1] + l[0]
            lsm = l[0]
            lsu = l[-1]
            l = l[1:-1]
        elif S[-1] == S[-2]:
            ls = l[-1] + 1
            lsu = l[-1]
            l = l[:-1]
        elif S[0] == S[1]:
            ls = l[0] + 1
            lsm = l[0]
            l = l[1:]
        else:
            ls = 2
     S[0] == S[-1] S[0] S 0 S[-1] S -1 if len(l) == 1 and l[0] == len(S):
            print(l[0] * K//2)
            return
        elif len(l) == 1:
            print(((l[0] + 1)//2) *(K-1) + (l[0] // 2))
            return
         len(l) == 1 and l[0] == len(S) len(l) == 1 len(l) len l 1 l[0] == len(S) l[0] l 0 len(S) len S print(l[0] * K//2) print l[0] * K//2 l[0] * K l[0] l 0 K 2 return elif len(l) == 1:
            print(((l[0] + 1)//2) *(K-1) + (l[0] // 2))
            return
         len(l) == 1 len(l) len l 1 print(((l[0] + 1)//2) *(K-1) + (l[0] // 2)) print ((l[0] + 1)//2) *(K-1) + (l[0] // 2) ((l[0] + 1)//2) *(K-1) (l[0] + 1)//2 l[0] + 1 l[0] l 0 1 2 K-1 K 1 l[0] // 2 l[0] l 0 2 return if S[0] == S[1] == S[-2]:
            ls = l[-1] + l[0]
            lsm = l[0]
            lsu = l[-1]
            l = l[1:-1]
        elif S[-1] == S[-2]:
            ls = l[-1] + 1
            lsu = l[-1]
            l = l[:-1]
        elif S[0] == S[1]:
            ls = l[0] + 1
            lsm = l[0]
            l = l[1:]
        else:
            ls = 2
     S[0] == S[1] == S[-2] S[0] == S[1] S[0] S 0 S[1] S 1 S[-2] S -2 ls = l[-1] + l[0] ls l[-1] + l[0] l[-1] l -1 l[0] l 0 lsm = l[0] lsm l[0] l 0 lsu = l[-1] lsu l[-1] l -1 l = l[1:-1] l l[1:-1] l 1:-1 1 -1 elif S[-1] == S[-2]:
            ls = l[-1] + 1
            lsu = l[-1]
            l = l[:-1]
         S[-1] == S[-2] S[-1] S -1 S[-2] S -2 ls = l[-1] + 1 ls l[-1] + 1 l[-1] l -1 1 lsu = l[-1] lsu l[-1] l -1 l = l[:-1] l l[:-1] l :-1 -1 elif S[0] == S[1]:
            ls = l[0] + 1
            lsm = l[0]
            l = l[1:]
         S[0] == S[1] S[0] S 0 S[1] S 1 ls = l[0] + 1 ls l[0] + 1 l[0] l 0 1 lsm = l[0] lsm l[0] l 0 l = l[1:] l l[1:] l 1: 1 ls = 2 ls 2 r = 0 r 0 for i in l:
        r += i // 2
     i l r += i // 2 r i // 2 i 2 r *= K r K r += (K-1) * (ls // 2) r (K-1) * (ls // 2) K-1 K 1 ls // 2 ls 2 r += (lsm  // 2) + (lsu // 2) r (lsm  // 2) + (lsu // 2) lsm  // 2 lsm 2 lsu // 2 lsu 2 print(r) print r main() main def main():
    S = input()
    K = int(input())
    l = []
    t = 1
    m = S[0]
    if len(S) == 1:
        print(K//2)
        return
    if len(S) == 2:
        if S[0] == S[1]:
            print(K)
            return
        else:
            print(0)
            return
    if len(S) == 3:
        if S[0] == S[1] == S[2]:
            print(3*K//2)
            return
        elif S[0] == S[1] or S[1] == S[2]:
            print(K)
            return
        elif S[0] == S[2]:
            print(K-1)
            return
        else:
            print(0)
            return
    for v in S[1:]:
        if v == m:
            t += 1
        elif t != 1:
            l.append(t)
            t = 1
        m = v
    if t != 1:
        l.append(t)
    ls = 0
    lsm = 0
    lsu = 0
    if S[0] == S[-1]:
        if len(l) == 1 and l[0] == len(S):
            print(l[0] * K//2)
            return
        elif len(l) == 1:
            print(((l[0] + 1)//2) *(K-1) + (l[0] // 2))
            return
        if S[0] == S[1] == S[-2]:
            ls = l[-1] + l[0]
            lsm = l[0]
            lsu = l[-1]
            l = l[1:-1]
        elif S[-1] == S[-2]:
            ls = l[-1] + 1
            lsu = l[-1]
            l = l[:-1]
        elif S[0] == S[1]:
            ls = l[0] + 1
            lsm = l[0]
            l = l[1:]
        else:
            ls = 2
    r = 0
    for i in l:
        r += i // 2
    r *= K
    r += (K-1) * (ls // 2)
    r += (lsm  // 2) + (lsu // 2)
    print(r) def main():
    S = input()
    K = int(input())
    l = []
    t = 1
    m = S[0]
    if len(S) == 1:
        print(K//2)
        return
    if len(S) == 2:
        if S[0] == S[1]:
            print(K)
            return
        else:
            print(0)
            return
    if len(S) == 3:
        if S[0] == S[1] == S[2]:
            print(3*K//2)
            return
        elif S[0] == S[1] or S[1] == S[2]:
            print(K)
            return
        elif S[0] == S[2]:
            print(K-1)
            return
        else:
            print(0)
            return
    for v in S[1:]:
        if v == m:
            t += 1
        elif t != 1:
            l.append(t)
            t = 1
        m = v
    if t != 1:
        l.append(t)
    ls = 0
    lsm = 0
    lsu = 0
    if S[0] == S[-1]:
        if len(l) == 1 and l[0] == len(S):
            print(l[0] * K//2)
            return
        elif len(l) == 1:
            print(((l[0] + 1)//2) *(K-1) + (l[0] // 2))
            return
        if S[0] == S[1] == S[-2]:
            ls = l[-1] + l[0]
            lsm = l[0]
            lsu = l[-1]
            l = l[1:-1]
        elif S[-1] == S[-2]:
            ls = l[-1] + 1
            lsu = l[-1]
            l = l[:-1]
        elif S[0] == S[1]:
            ls = l[0] + 1
            lsm = l[0]
            l = l[1:]
        else:
            ls = 2
    r = 0
    for i in l:
        r += i // 2
    r *= K
    r += (K-1) * (ls // 2)
    r += (lsm  // 2) + (lsu // 2)
    print(r) main
def main():
    S = input()
    K = int(input())
    l = []
    t = 1
    m = S[0]
    if len(S) == 1:
        print(K//2)
        return
    if len(S) == 2:
        if S[0] == S[1]:
            print(K)
            return
        else:
            print(0)
            return
    if len(S) == 3:
        if S[0] == S[1] == S[2]:
            print(3*K//2)
            return
        elif S[0] == S[1] or S[1] == S[2]:
            print(K)
            return
        elif S[0] == S[2]:
            print(K-1)
            return
        else:
            print(0)
            return
    for v in S[1:]:
        if v == m:
            t += 1
        elif t != 1:
            l.append(t)
            t = 1
        m = v
    if t != 1:
        l.append(t)
    ls = 0
    lsm = 0
    lsu = 0
    if S[0] == S[-1]:
        if len(l) == 1 and l[0] == len(S):
            print(l[0] * K//2)
            return
        elif len(l) == 1:
            print(((l[0] + 1)//2) *(K-1) + (l[0] // 2))
            return
        if S[0] == S[1] == S[-2]:
            ls = l[-1] + l[0]
            lsm = l[0]
            lsu = l[-1]
            l = l[1:-1]
        elif S[-1] == S[-2]:
            ls = l[-1] + 1
            lsu = l[-1]
            l = l[:-1]
        elif S[0] == S[1]:
            ls = l[0] + 1
            lsm = l[0]
            l = l[1:]
        else:
            ls = 2
    r = 0
    for i in l:
        r += i // 2
    r *= K
    r += (K-1) * (ls // 2)
    r += (lsm  // 2) + (lsu // 2)
    print(r)
main()
