output_description: Print the minimum number of operations required.
  
  * * *
input_description: Input is given from Standard Input in the following format:
  
      
      
      S
      K
attempt: # test
  def test():
      param = []
      val = ["issii", "2", "4"]
      param.append(val)
  
      # issii issii issii
      #   x x   x x   x x
      val = ["issii", "3", "6"]
      param.append(val)
  
      # qq qq qq
      #  x  x  x
      val = ["qq", "81", "81"]
      param.append(val)
  
      val = ["cooooooooonteeeeeeeeeest", "999993333", "8999939997"]
      param.append(val)
  
      # aaa aaa aaa aaa
      # _x_ x_x _x_ x_x
      val = ["aaa", "4", "6"]
      param.append(val)
  
      # aaaa aaaa aaaa aaaa
      #  x x  x x  x x  x x
      val = ["aaaa", "4", "8"]
      param.append(val)
  
      # aaaaa aaaaa aaaaa aaaaa
      #  x x  x x x  x x  x x x
      val = ["aaaaa", "4", "10"]
      param.append(val)
  
      # i i i i
      #   x   x
      val = ["i", "4", "2"]
      param.append(val)
  
      # isi isi isi isi
      #     x   x   x
      val = ["isi", "4", "3"]
      param.append(val)
  
      # isssi isssi isssi
      #   x   x x   x x
      val = ["isssi", "3", "5"]
      param.append(val)
  
      # isiii isiii isiii
      #    x  x  x  x  x
      val = ["isssi", "3", "5"]
      param.append(val)
  
      # iissi iissi iissi
      #  x x  x  x  x  x
      val = ["iissi", "3", "6"]
      param.append(val)
  
      print(param)
  
      for i in range(len(param)):
          ret = f(param[i][0], param[i][1])
          if ret == param[i][2]:
              chk = "o"
          else:
              chk = "x"
          space = "  "
          print(
              chk
              + space
              + param[i][0]
              + space
              + param[i][1]
              + space
              + param[i][2]
              + space
              + "test..."
              + ret
          )
  
  
  def f(s, k):
  
      k = int(k)
  
      cnt = 0
      ss = s
      for i in range(len(ss)):
          if i == 0:
              continue
  
          if ss[i - 1] == ss[i]:
              ss = ss[:i] + "\\" + ss[i + 1 :]
              cnt += 1
  
      cnt = cnt * k
  
      if s.count(s[0]) == len(s):
          if len(s) % 2 == 1:
              cnt = cnt + (k // 2)
      else:
          cntchk1 = 0
          cntchk2 = 0
          if s[0] == s[len(s) - 1]:
              for i in range(len(s)):
                  if s[len(s) - 1] == s[len(s) - 1 - i]:
                      cntchk1 += 1
                  #                 else:
                  #                     break
                  if i < len(s) - 1 and s[0] == s[i + 1]:
                      cntchk2 += 1
  
              if cntchk1 % 2 == 0 and cntchk1 % 2 == 0:
                  cnt = cnt + (k - 1)
  
      return str(cnt)
  
  
  ## Submit
  print(f(input(), input()))
  
problem_description: 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.
samples: [{"input": "issii\n    2", "output": "4\n    \n\nT is `issiiissii`. For example, we can rewrite it into `ispiqisyhi`, and now\nany two adjacent characters are different.\n\n* * *"}, {"input": "qq\n    81", "output": "81\n    \n\n* * *"}, {"input": "cooooooooonteeeeeeeeeest\n    999993333", "output": "8999939997"}]