#!/usr/bin python3
# -*- coding: utf-8 -*-

def cnt(st):
    x = st.copy()
    ret = 0
    for i in range(1,len(st)):
        if x[i]==x[i-1]:
            ret += 1
            x[i] = '0'
    return ret

def main():
    S = list(input())
    K = int(input())
    res1 = cnt(S)
    res2 = cnt(S+S)
    res3 = cnt(S+S+S)
    d1=res2-res1
    d2=res3-res2
    x2=(K-1)//2
    x1=K-1 - x2
    ret=res1+x1*d1+x2*d2
    print(ret)

if __name__ == '__main__':
    main() def cnt(st):
    x = st.copy()
    ret = 0
    for i in range(1,len(st)):
        if x[i]==x[i-1]:
            ret += 1
            x[i] = '0'
    return ret cnt x = st.copy() x st.copy() st.copy st copy ret = 0 ret 0 for i in range(1,len(st)):
        if x[i]==x[i-1]:
            ret += 1
            x[i] = '0'
     i range(1,len(st)) range 1 len(st) len st if x[i]==x[i-1]:
            ret += 1
            x[i] = '0'
     x[i]==x[i-1] x[i] x i x[i-1] x i-1 i 1 ret += 1 ret 1 x[i] = '0' x[i] x i '0' return ret ret st st def main():
    S = list(input())
    K = int(input())
    res1 = cnt(S)
    res2 = cnt(S+S)
    res3 = cnt(S+S+S)
    d1=res2-res1
    d2=res3-res2
    x2=(K-1)//2
    x1=K-1 - x2
    ret=res1+x1*d1+x2*d2
    print(ret) main S = list(input()) S list(input()) list input() input K = int(input()) K int(input()) int input() input res1 = cnt(S) res1 cnt(S) cnt S res2 = cnt(S+S) res2 cnt(S+S) cnt S+S S S res3 = cnt(S+S+S) res3 cnt(S+S+S) cnt S+S+S S+S S S S d1=res2-res1 d1 res2-res1 res2 res1 d2=res3-res2 d2 res3-res2 res3 res2 x2=(K-1)//2 x2 (K-1)//2 K-1 K 1 2 x1=K-1 - x2 x1 K-1 - x2 K-1 K 1 x2 ret=res1+x1*d1+x2*d2 ret res1+x1*d1+x2*d2 res1+x1*d1 res1 x1*d1 x1 d1 x2*d2 x2 d2 print(ret) print ret if __name__ == '__main__':
    main() __name__ == '__main__' __name__ '__main__' main() main def main():
    S = list(input())
    K = int(input())
    res1 = cnt(S)
    res2 = cnt(S+S)
    res3 = cnt(S+S+S)
    d1=res2-res1
    d2=res3-res2
    x2=(K-1)//2
    x1=K-1 - x2
    ret=res1+x1*d1+x2*d2
    print(ret) def main():
    S = list(input())
    K = int(input())
    res1 = cnt(S)
    res2 = cnt(S+S)
    res3 = cnt(S+S+S)
    d1=res2-res1
    d2=res3-res2
    x2=(K-1)//2
    x1=K-1 - x2
    ret=res1+x1*d1+x2*d2
    print(ret) main def cnt(st):
    x = st.copy()
    ret = 0
    for i in range(1,len(st)):
        if x[i]==x[i-1]:
            ret += 1
            x[i] = '0'
    return ret def cnt(st):
    x = st.copy()
    ret = 0
    for i in range(1,len(st)):
        if x[i]==x[i-1]:
            ret += 1
            x[i] = '0'
    return ret cnt
#!/usr/bin python3
# -*- coding: utf-8 -*-

def cnt(st):
    x = st.copy()
    ret = 0
    for i in range(1,len(st)):
        if x[i]==x[i-1]:
            ret += 1
            x[i] = '0'
    return ret

def main():
    S = list(input())
    K = int(input())
    res1 = cnt(S)
    res2 = cnt(S+S)
    res3 = cnt(S+S+S)
    d1=res2-res1
    d2=res3-res2
    x2=(K-1)//2
    x1=K-1 - x2
    ret=res1+x1*d1+x2*d2
    print(ret)

if __name__ == '__main__':
    main()