Problem:
Score : 300 points

Problem Statement

Given is a string S. Let T be the concatenation of K copies of S.
We can repeatedly perform the following operation: choose a character in T and replace it with a different character.
Find the minimum number of operations required to satisfy the following condition: any two adjacent characters in T are different.

Constraints

1 \leq |S| \leq 100

S consists of lowercase English letters.

1 \leq K \leq 10^9

K is an integer.

Input

Input is given from Standard Input in the following format:

S
K

Output

Print the minimum number of operations required.

Sample Input 1

issii
2

Sample Output 1

4

T is issiiissii. For example, we can rewrite it into ispiqisyhi, and now any two adjacent characters are different.

Sample Input 2

qq
81

Sample Output 2

81

Sample Input 3

cooooooooonteeeeeeeeeest
999993333

Sample Output 3

8999939997

Solution in C# (Mono 4.6.2.0) (judge verdict: Wrong Answer)

using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCorder
{
	public class Program
	{
		// sbsss sbsss sbsss
		// sbshs sbshs sbshs
		// 
		// sbssss sbssss sbssss
		// sbshsh sbshsh sbshsh
		static void Main(string[] args)
		{
			Scanner cin = new Scanner();
			string s = cin.Next();
			int k = cin.Int();
			char prev = s[0];
			int n = s.Length;
			bool changed = false;
			long ans = 0;

			if (n == 1) {
				ans = k / 2;
				Console.WriteLine(ans);
				return;
			} else if(n == 2) {
				if (s[0] != s[1]) {
					ans = 0;
				} else {
					ans = k;
				}

				Console.WriteLine(ans);
				return;
			}

			bool isAllSame = true;
			char first = s[0];
			for (int i = 1; i < n; i++) {
				if (s[i] != first) {
					isAllSame = false;
					break;
				}
			}

			if (isAllSame) {
				ans = (n * k) / 2;
				Console.WriteLine(ans);
				return;
			}

			for (int i = 1; i < n; i++) {
				if (s[i] == s[i - 1]) {
					if (changed) {
						changed = false;
					} else {
						++ans;
						changed = true;
					}
				} else {
					changed = false;
				}
			}

			ans *= k;

			if (s[0] == s[n - 1]) {
				int count = 1;
				int index = n - 2;
				while (index >= 0) {
					if (s[index] == s[n - 1]) {
						++count;
					} else {
						break;
					}

					--index;
				}

				if (count % 2 == 1) {
					ans += k - 1;
				}
			} 

			Console.WriteLine(ans);
		}
	}

	public class Scanner
	{
		private readonly char[] delimiter_ = new char[] { ' ' };
		private string[] buf_;
		private int index_;

		public Scanner()
		{
			buf_ = new string[0];
			index_ = 0;
		}

		public string Next()
		{
			if (index_ < buf_.Length) {
				return buf_[index_++];
			}

			string st = Console.ReadLine();
			while (st == "") {
				st = Console.ReadLine();
			}

			buf_ = st.Split(delimiter_, StringSplitOptions.RemoveEmptyEntries);
			if (buf_.Length == 0) {
				return Next();
			}

			index_ = 0;
			return buf_[index_++];
		}

		public int Int() => int.Parse(Next());
		public long Long() => long.Parse(Next());
		public double Double() => double.Parse(Next());

		public int[] ArrayInt(int N, int add = 0)
		{
			int[] Array = new int[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Int() + add;
			}
			return Array;
		}

		public long[] ArrayLong(int N, long add = 0)
		{
			long[] Array = new long[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Long() + add;
			}
			return Array;
		}

		public double[] ArrayDouble(int N, double add = 0)
		{
			double[] Array = new double[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Double() + add;
			}
			return Array;
		}
	}
}