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.Generic;//list用
using System.Text;//StringBuilder用
using System.Collections;//ハッシュテーブル用
using System.Linq;

class Program
{
    static List<int> s = new List<int>();
    static List<int> t = new List<int>();
    static List<int> u = new List<int>();
    static List<int>[] sl;
    static decimal result;
  static string S;
    static int N,K,M;
    //StringBuilder strresult= new StringBuilder("");//Append(str ○○)関数で文字を追加していく



    static void Main()
    {
        //Modular mo = new Modular(0);//素数で割った余りを出せで使う。()内が初期値。★使い方：Modular型で宣言すると、その時点でのその素数で割った余りを保持する変数になる（powべき乗、Fac累乗、nCr組み合わせも関数として存在）
        //Node<> no = new Node<>();//UnionFind★Find関数で根っこの値を返す（根っこの値が一緒なら同グループ）、Unite関数で二つの木をくっつける
        //Permutation<> pe = new Permutation<>();//配列＆リストを並べ替えた場合の全ケースを出力★All関数でリスト形式で返す。
        //Treap<> tr = new Treap<>();//平衡二分木★Insert()関数で挿入、FindIndex()関数で該当する大きさの物が入るべき配列番号を返す。
        //PriorityQueue<int,int> pr = new PriorityQueue<int,int>();//優先度付キュー★Add(key,value)で格納、Dequeue()で取りだし。keyが小さいものから取り出す。
S = Console.ReadLine();
        Read1();
      string S2=S+S;
      K=S.Length;

        bool start=true;
        int countA=1;
          int countB=1;
      decimal tr=0;
      for(int i=0;i<K-1;i++){if(S[i]==S[i+1]){
                                              countB++;
                                              if(countB%2==0){tr++;}}else{countB=1;start=false;}}
countA=1;countB=1;
      int tr2=0;
      for(int i=0;i<K*2-1;i++){if(S2[i]==S2[i+1]){
                                              countB++;
                                              if(countB%2==0){tr2++;}}else{countB=1;}}
      
result=(tr2-tr)*(N-1)+tr;
      //全部同じ文字なら
      if(start){result=N*K/2;}
      
        Console.WriteLine(result.ToString());
    }


    static void Read1()//1項
    {
        string tmp = Console.ReadLine();
        N = int.Parse(tmp);
    }

    static void Read2()//複数項（項目数Ｎ）
    {
        string[] tmp = Console.ReadLine().Split(' ');
        for (int i = 0; i < N; i++) { s.Add(int.Parse(tmp[i])); }
    }
    static void Read3()//1行複数項
    {
        string[] tmp = Console.ReadLine().Split(' ');
        for (int i = 0; i < tmp.Length; i++) { s.Add(int.Parse(tmp[i])); }
    }
    static void Read4()//NK１行
    {
        string[] tmp = Console.ReadLine().Split(' ');
        N = int.Parse(tmp[0]);
        K = int.Parse(tmp[1]);
    }
    static void Read5()//N行K項
    {
        sl = new List<int>[N];
        for (int i = 0; i < N; i++) {
            sl[i] = new List<int>();
            string[] tmp = Console.ReadLine().Split(' ');
            for (int j = 0; j < K; j++) {
                sl[i].Add(int.Parse(tmp[j]));
            }
        }

    }
}