C = {}
S = input().strip()
N = len(S)
K = int(input())
for i in range(N):
    s = S[i]
    if s not in C:
        C[s]=0
    C[s] += 1
if len(C)>1:
    a = 0
    cnt = 1
    for i in range(1,N):
        if S[i]==S[i-1]:
            cnt += 1
        else:
            a += cnt//2
            cnt = 1
    a += cnt//2
    X = S+S
    b = 0
    cnt = 1
    for i in range(1,2*N):
        if X[i]==X[i-1]:
            cnt += 1
        else:
            b += cnt//2
            cnt = 1
    b += cnt//2
    d = b-a
    print(a+d*(K-1))
else:
    A = list(C.items())
    k = A[0][1]
    if k%2==0:
        print((k//2)*K)
    else:
        if K%2==0:
            a = k
            b = 2*k
            d = k
            print(a+d*((K//2)-1))
        else:
            a = k//2
            b = (k*3)//2
            d = b-a
            print(a+d*(K//2)) C = {} C {} S = input().strip() S input().strip() ().strip () input strip N = len(S) N len(S) len S K = int(input()) K int(input()) int input() input for i in range(N):
    s = S[i]
    if s not in C:
        C[s]=0
    C[s] += 1 i range(N) range N s = S[i] s S[i] S i if s not in C:
        C[s]=0
     s not in C s C C[s]=0 C[s] C s 0 C[s] += 1 C[s] C s 1 if len(C)>1:
    a = 0
    cnt = 1
    for i in range(1,N):
        if S[i]==S[i-1]:
            cnt += 1
        else:
            a += cnt//2
            cnt = 1
    a += cnt//2
    X = S+S
    b = 0
    cnt = 1
    for i in range(1,2*N):
        if X[i]==X[i-1]:
            cnt += 1
        else:
            b += cnt//2
            cnt = 1
    b += cnt//2
    d = b-a
    print(a+d*(K-1))
else:
    A = list(C.items())
    k = A[0][1]
    if k%2==0:
        print((k//2)*K)
    else:
        if K%2==0:
            a = k
            b = 2*k
            d = k
            print(a+d*((K//2)-1))
        else:
            a = k//2
            b = (k*3)//2
            d = b-a
            print(a+d*(K//2)) len(C)>1 len(C) len C 1 a = 0 a 0 cnt = 1 cnt 1 for i in range(1,N):
        if S[i]==S[i-1]:
            cnt += 1
        else:
            a += cnt//2
            cnt = 1
     i range(1,N) range 1 N if S[i]==S[i-1]:
            cnt += 1
        else:
            a += cnt//2
            cnt = 1
     S[i]==S[i-1] S[i] S i S[i-1] S i-1 i 1 cnt += 1 cnt 1 a += cnt//2 a cnt//2 cnt 2 cnt = 1 cnt 1 a += cnt//2 a cnt//2 cnt 2 X = S+S X S+S S S b = 0 b 0 cnt = 1 cnt 1 for i in range(1,2*N):
        if X[i]==X[i-1]:
            cnt += 1
        else:
            b += cnt//2
            cnt = 1
     i range(1,2*N) range 1 2*N 2 N if X[i]==X[i-1]:
            cnt += 1
        else:
            b += cnt//2
            cnt = 1
     X[i]==X[i-1] X[i] X i X[i-1] X i-1 i 1 cnt += 1 cnt 1 b += cnt//2 b cnt//2 cnt 2 cnt = 1 cnt 1 b += cnt//2 b cnt//2 cnt 2 d = b-a d b-a b a print(a+d*(K-1)) print a+d*(K-1) a d*(K-1) d K-1 K 1 A = list(C.items()) A list(C.items()) list C.items() C.items C items k = A[0][1] k A[0][1] [0] A 0 1 if k%2==0:
        print((k//2)*K)
    else:
        if K%2==0:
            a = k
            b = 2*k
            d = k
            print(a+d*((K//2)-1))
        else:
            a = k//2
            b = (k*3)//2
            d = b-a
            print(a+d*(K//2)) k%2==0 k%2 k 2 0 print((k//2)*K) print (k//2)*K k//2 k 2 K if K%2==0:
            a = k
            b = 2*k
            d = k
            print(a+d*((K//2)-1))
        else:
            a = k//2
            b = (k*3)//2
            d = b-a
            print(a+d*(K//2)) K%2==0 K%2 K 2 0 a = k a k b = 2*k b 2*k 2 k d = k d k print(a+d*((K//2)-1)) print a+d*((K//2)-1) a d*((K//2)-1) d (K//2)-1 K//2 K 2 1 a = k//2 a k//2 k 2 b = (k*3)//2 b (k*3)//2 k*3 k 3 2 d = b-a d b-a b a print(a+d*(K//2)) print a+d*(K//2) a d*(K//2) d K//2 K 2 d = k k d a += cnt//2 cnt//2 a cnt = 1 1 cnt b = 2*k 2*k b C = {} {} C N = len(S) len(S) N b += cnt//2 cnt//2 b b = 0 0 b d = b-a b-a d cnt = 1 1 cnt cnt += 1 1 cnt X = S+S S+S X cnt += 1 1 cnt k = A[0][1] A[0][1] k a = k k a S = input().strip() input().strip() S K = int(input()) int(input()) K a = 0 0 a s = S[i] S[i] s A = list(C.items()) list(C.items()) A a += cnt//2 cnt//2 a d = b-a b-a d b += cnt//2 cnt//2 b b = (k*3)//2 (k*3)//2 b cnt = 1 1 cnt a = k//2 k//2 a cnt = 1 1 cnt
C = {}
S = input().strip()
N = len(S)
K = int(input())
for i in range(N):
    s = S[i]
    if s not in C:
        C[s]=0
    C[s] += 1
if len(C)>1:
    a = 0
    cnt = 1
    for i in range(1,N):
        if S[i]==S[i-1]:
            cnt += 1
        else:
            a += cnt//2
            cnt = 1
    a += cnt//2
    X = S+S
    b = 0
    cnt = 1
    for i in range(1,2*N):
        if X[i]==X[i-1]:
            cnt += 1
        else:
            b += cnt//2
            cnt = 1
    b += cnt//2
    d = b-a
    print(a+d*(K-1))
else:
    A = list(C.items())
    k = A[0][1]
    if k%2==0:
        print((k//2)*K)
    else:
        if K%2==0:
            a = k
            b = 2*k
            d = k
            print(a+d*((K//2)-1))
        else:
            a = k//2
            b = (k*3)//2
            d = b-a
            print(a+d*(K//2))