import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.io.BufferedReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        OutputWriter out = new OutputWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA {
        public void solve(int testNumber, InputReader in, OutputWriter out) {
            String s = in.next();
            int N = s.length();
            long K = in.nextInt();
            long ans = 0, count = 0;
            boolean allSame = true;
            for (int i = 1; i < N; i++) {
                if (s.charAt(i) != s.charAt(0)) {
                    allSame = false;
                    break;
                }
            }
            if (allSame) {
                out.printLine((N * K) / 2);
                return;
            }

            if (s.charAt(0) == s.charAt(N - 1)) {
                int start = 0;
                while (start < N && s.charAt(start) == s.charAt(0)) {
                    start++;
                    count++;
                }
                ans += count / 2;
                long count1 = 0;
                int end = N - 1;
                while (end >= 0 && s.charAt(end) == s.charAt(N - 1)) {
                    end--;
                    count1++;
                }
                ans += count1 / 2;
                ans += (K - 1) * ((count + count1) / 2);
                count = 1;
                for (int i = start; i <= end; i++) {
                    if (s.charAt(i) == s.charAt(i + 1)) {
                        count++;
                    } else {
                        ans += K * (count / 2);
                        count = 1;
                    }
                }
            } else {
                s = s + ' ';
                count = 1;
                for (int i = 0; i < N; i++) {
                    if (s.charAt(i) == s.charAt(i + 1)) {
                        count++;
                    } else {
                        ans += K * (count / 2);
                        count = 1;
                    }
                }
            }

            out.printLine(ans);
        }

    }

    static class InputReader {
        BufferedReader in;
        StringTokenizer tokenizer = null;

        public InputReader(InputStream inputStream) {
            in = new BufferedReader(new InputStreamReader(inputStream));
        }

        public String next() {
            try {
                while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                    tokenizer = new StringTokenizer(in.readLine());
                }
                return tokenizer.nextToken();
            } catch (IOException e) {
                return null;
            }
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }

    static class OutputWriter {
        PrintWriter writer;

        public OutputWriter(OutputStream outputStream) {
            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }

        public OutputWriter(Writer writer) {
            this.writer = new PrintWriter(writer);
        }

        public void print(Object... objects) {
            for (int i = 0; i < objects.length; i++) {
                if (i != 0) {
                    writer.print(' ');
                }
                writer.print(objects[i]);
            }
        }

        public void printLine(Object... objects) {
            print(objects);
            writer.println();
        }

        public void close() {
            writer.close();
        }

    }
}



Measured memory_bytes: 21332