using System;
class ConnectionandDisconnection
{
	static void Main(string[] args)
	{
		string S = Console.ReadLine();
		long K = long.Parse(Console.ReadLine());
		Console.WriteLine(disconnect(S, K));
	}

	static long disconnect(string conn_str, long loop) {
		long totalCounter = 0;
		if (conn_str.Length==0) return 0;
		else if (conn_str.Length==1) return (long)loop/2;
		// 先頭
		DisconnectedParts first = getDisconnectedStringForOneLoop(conn_str, null, true, false);
		totalCounter += (long)first.counter;
		//Console.WriteLine(first.counter+" "+totalCounter);
		// 先頭・最終以外
		string last_targetPrevString = first.disconnected_str;
		if (loop>2) {
    	    DisconnectedParts part1 = getDisconnectedStringForOneLoop(conn_str, last_targetPrevString, false, false);
    	    totalCounter += (long)part1.counter;
    	    //Console.WriteLine(part1.counter+" "+totalCounter);
    	    last_targetPrevString = part1.disconnected_str;
    	    if (loop>3) {
    	        DisconnectedParts part2 = getDisconnectedStringForOneLoop(conn_str, last_targetPrevString, false, false);
    	        if (part1.disconnected_str!=part2.disconnected_str) {
    	            // 偶数のとき
    	            if ((loop%2)==0) {
    	               totalCounter += (long)((part1.counter*((loop-2)/2))+(part2.counter*((loop-2)/2))-part1.counter);
    	               last_targetPrevString = part2.disconnected_str;
    	               //Console.WriteLine((long)(part1.counter*((loop-2)/2))+(part2.counter*((loop-2)/2))-part1.counter);
    	            }
    	            // 奇数のとき
    	            else {
    	                totalCounter += (long)(part1.counter*(((loop-2)/2)+1)+(part2.counter*((loop-2)/2))-part1.counter);
    	                //Console.WriteLine(((long)part1.counter*((loop-2)/2+1)+(part2.counter*((loop-2)/2))-part1.counter)+" "+totalCounter);
    	            }
    	        }
    	        else {
    	            totalCounter += (long)part1.counter*(loop-3);
    	        }
    	    }
		}
		// 最終
		if (loop>1) {
    		DisconnectedParts last = getDisconnectedStringForOneLoop(conn_str, last_targetPrevString, false, true);
    		totalCounter += (long)last.counter;
    		//Console.WriteLine(last.counter);
		}
		return totalCounter;
	}
	
    static DisconnectedParts getDisconnectedStringForOneLoop(string conn_str, string prev_str, Boolean isStartForLoop,  Boolean isEndForLoop) {
        int size = conn_str.Length;
		string alph = "abcdefghijklmnopqrstuvwxyz";

        string disconnected_str = "";
        DisconnectedParts part = new DisconnectedParts();

        if (isStartForLoop) {
        	disconnected_str += conn_str[0];
        }
        else {
            if (conn_str[0]==prev_str[size-1]) {
                int index = (getIndexNum(alph, conn_str[0])+1)%alph.Length;
                while (prev_str[size-1]==alph[index]||alph[index]==conn_str[1]) {
    				index = (index+1)%alph.Length;
    				//Console.WriteLine(index);
    			}
    			part.count();
    			disconnected_str += alph[index];
            }
            else {
                disconnected_str += conn_str[0];
            }
        }
        
        for (int i=0;i<size-2;i++) {
    		if (disconnected_str[i]==conn_str[i+1]) {
    			int index = (getIndexNum(alph, conn_str[i+1])+1)%alph.Length;
    			while (disconnected_str[i]==alph[index]||alph[index]==conn_str[i+2]) {
    				index = (index+1)%alph.Length;
    				//Console.WriteLine(index);
    			}
    			part.count();
    			disconnected_str += alph[index];
    			//Console.WriteLine(disconnected_str);
    		}
    		else {
    			disconnected_str += conn_str[i+1];
    		}
    	}
		
		if (!isEndForLoop) {
		// 終端文字の判定
    		if (disconnected_str[size-2]==conn_str[size-1]) {
    		    int index = (getIndexNum(alph, conn_str[size-1])+1)%alph.Length;
                while (disconnected_str[size-2]==alph[index]||alph[index]==conn_str[0]) {
    				index = (index+1)%alph.Length;
    				// Console.WriteLine(index);
    			}
    			part.count();
    			disconnected_str += alph[index];
    			//Console.WriteLine(disconnected_str);
    		}
    		else {
    		    disconnected_str += conn_str[size-1];
    		}
		}
		else {
		    if (disconnected_str[size-2]==conn_str[size-1]) {
		        int index = (getIndexNum(alph, conn_str[size-1])+1)%alph.Length;
                while (disconnected_str[size-2]==alph[index]) {
    				index = (index+1)%alph.Length;
    				// Console.WriteLine(index);
    			}
    			part.count();
    			disconnected_str += alph[index];
    			//Console.WriteLine(disconnected_str);
    		}
    		else {
    		    disconnected_str += conn_str[size-1];
    		}
		}
		part.setDiscpnnectedString(disconnected_str);
		//Console.WriteLine(disconnected_str);
		return part;
    }

	static int getIndexNum(string basestr, char target) {
		for (int i=0;i<basestr.Length;i++) {
			if (basestr[i]==target) {
				return i;
			}
		}
		return -1;
	}
}

class DisconnectedParts {
    public int counter;
    public string disconnected_str;
    public DisconnectedParts() {
        counter = 0;
        disconnected_str = "";
    }
    public void count() {
        counter++;
    }
    public void setDiscpnnectedString(string disconn_str) {
        this.disconnected_str = disconn_str;
    }
}

Measured memory_bytes: 11348