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 Go (1.6) (judge verdict: Wrong Answer)

package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
)

var (
	sc      = bufio.NewScanner(os.Stdin)
	mod int = 1e9 + 7
)

func init() {
	sc.Split(bufio.ScanWords)
}

func main() {
	S := getString()
	K := getInt()

	oldS := []byte(S)
	newS := []byte(S)

	changeCnt := 0

	if len(newS) == 1 {
		changeCnt = K / 2
	} else {
		for i := 1; i < len(newS); i++ {
			if newS[i] == newS[i-1] {
				newS[i] = '*'
			}
		}

		if len(newS) >= 3 {
			if newS[1] == '*' && newS[0] != newS[2] {
				newS[1] = newS[0]
				newS[0] = '*'
			}
		}

		cnt := 0
		for i := 0; i < len(newS); i++ {
			if newS[i] == newS[0] || newS[i] == '*' {
				cnt++
			} else {
				break
			}
		}
		
		if cnt%2 == 0 {
			for i := 0; i < cnt/2; i++ {
				newS[2*i+1] = newS[2*i]
				newS[2*i] = '*'
			}
		}

		if newS[0] == newS[len(newS)-1] {
			newS[len(newS)-1] = '*'
		}

		for _, c := range newS {
			if c == '*' {
				changeCnt++
			}
		}

		changeCnt = changeCnt * K

		// 末尾2つが*なら、1回減らす
		if newS[len(newS)-2] == '*' && newS[len(newS)-1] == '*' {
			changeCnt--
		} else if newS[len(newS)-1] == '*' && oldS[len(oldS)-2] != oldS[len(oldS)-1] {
			changeCnt--
		}

		//fmt.Println(string(newS), string(newS))
	}

	fmt.Println(changeCnt)
}

func getInt() int {
	sc.Scan()
	str := sc.Text()
	value, _ := strconv.Atoi(str)
	return value
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

func abs(a int) int {
	return int(math.Abs(float64(a)))
}

func pow(p, q int) int {
	return int(math.Pow(float64(p), float64(q)))
}

func min(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton min() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Min(float64(res), float64(nums[i])))
	}
	return res
}

func max(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton max() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Max(float64(res), float64(nums[i])))
	}
	return res
}

func strSearch(a []string, b string) bool {
	for i := 0; i < len(a); i++ {
		if a[i] == b {
			return true
		}
	}
	return false
}

func printIntArray(array []int) {
	strArray := fmt.Sprint(array)
	fmt.Println(strArray[1 : len(strArray)-1])
}

func calcMod(x int) int {
	return x % mod
}