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



Sample input:
issii
2


Sample output:
4

Submission status: Wrong Answer

Solution code:
s=str(input())
k=int(input())
count=1
ans=0
s2=s+s
ans2=0
#print(s2)
for i in range(len(s)-1):
    if s[i]==s[i+1]:
        count+=1
    else:
        if 2<=count:
            ans+=count//2
        count=1
if 2<=count:
    ans+=count//2
count=1
for i in range(len(s2)-1):
    if s2[i]==s2[i+1]:
        count+=1
    else:
        if 2<=count:
            ans2+=count//2
        count=1

if 2<=count:
    ans2+=count//2
    #print(count)
#print(ans,ans2)
if s[0]==s[-1]:
    print((ans2-ans)*k+ans)
else:
    print(ans*k)

Submission status: Wrong Answer

Solution code:
s=str(input())
k=int(input())
count=1
ans=0
s2=s+s
ans2=0
#print(s2)
for i in range(len(s)-1):
    if s[i]==s[i+1]:
        count+=1
    else:
        if 2<=count:
            ans+=count//2
        count=1
if 2<=count:
    ans+=count//2
count=1
for i in range(len(s2)-1):
    if s2[i]==s2[i+1]:
        count+=1
    else:
        if 2<=count:
            ans2+=count//2
        count=1

if 2<=count:
    ans2+=count//2
    #print(count)
#print(ans,ans2)
if s[0]==s[-1]:
    print((ans2-ans)*k)
else:
    print(ans*k)

Submission status: Wrong Answer

Solution code:
S = input()
K = int(input())
cot = 0
before = ""
seq = []


for i in range(len(S)):
    c = S[i]
    if cot == 0:
        cot += 1
        before =c
    else:
        if c == before:
            cot += 1
        else:
            before = c
            seq.append(cot)
            cot = 1

seq.append(cot)
ans = 0
for temp in seq:
    ans +=temp//2
ans *= K
if S[0] == S[-1]:
    ans += (seq[0] + seq[-1]) * (K - 1) //2 - (seq[0] //2 + seq[-1]//2 )* (K - 1)
if len(seq) == 1:
    ans = min(ans,seq[0] * K //2)
print(ans)

Submission status: Wrong Answer

Solution code:
import sys


def input():
    return sys.stdin.readline().strip()


sys.setrecursionlimit(10 ** 9)


def main():
    S = input()
    K = int(input())
    last = ""
    a = 0
    if len(S) == 1:
        print(K // 2)
        return
    for s in S:
        if s == last:
            a += 1
            last = ""
        else:
            last = s
    if S[0] != S[-1]:
        print(a * K)
    elif len(S) == 2:
        print(a * K)
    else:
        x = 0
        y = 0
        for i in range(len(S) // 2):
            if S[i] == S[0]:
                x += 1
        for j in range(len(S) // 2):
            if S[len(S) - j - 1] == S[-1]:
                y += 1

        if x % 2 == 1 and y % 2 == 1:
            b = 1
        else:
            b = 0

        print(a * K + b * (K - 1))


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys


def input():
    return sys.stdin.readline().strip()


sys.setrecursionlimit(10 ** 9)


def main():
    S = input()
    K = int(input())
    last = ""
    a = 0
    if len(S) == 1:
        print(K // 2)
        return
    for s in S:
        if s == last:
            a += 1
            last = ""
        else:
            last = s
    b = 0
    if S[0] == S[-1]:
        if S[-2] == S[0] or S[1] == S[0]:
            b = 0
        else:
            b = 1

    print(a * K + b * (K - 1))


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
S=input()
K=int(input())
L=len(S)
cnt=0
ren=1

if L==1:
  ans= K//2
elif L==2:
  if S[0]==S[1]:
    ans = K
  else:
    ans = 0
else:  #|S|>=3が保証
  if S[0]!=S[-1]:
    for i in range(1,L):  
      if S[i]==S[i-1]:
        ren +=1
        if i==L-1:
          cnt += ren//2  
      else:
        cnt += ren//2
        ren=1        
  else:
    pass
  
    
#print(ans)

Submission status: Wrong Answer

Solution code:
def resolve():
    '''
    code here
    Sを先頭　真ん中　お尻の三分割する
    連結した場合を考えると以下の場合分け
    先頭　お尻　真ん中×K　（先頭₊お尻）×（K-1）
    同じ文字が続いたらn//2個の文字変更が必要
    以上で解けるはず

    '''
    S = input()
    K = int(input())

    S_head = ''
    head = S[0]
    for s in S:
        if s == head:
            S_head += s
        else:
            break
    
    S_tail = ''
    tail = S[-1]
    for s in S[::-1]:
        if s == tail:
            S_tail += s
        else:
            break
    S_tail = S_tail[::-1]

    S_body = S[len(S_head):-1 * len(S_tail)]
    
    def double_counter(S):
        cnt = 0
        if len(S) >= 2:
            prev = S[0]
            for item in S[1:]:
                if item == prev:
                    cnt += 1
                    prev = -1
                else:
                    prev = item

        return cnt
    
    if len(S) >= 2 and len(S) != len(S_head):
        res = len(S_head)//2\
            + len(S_tail)\
            + double_counter(S_body) * K\
            + double_counter(S_tail+S_head) * (K-1)
    elif len(S) == 1:
        res = K // 2
    elif len(S) == len(S_head):
        res = (K * len(S)) // 2

    print(res)

if __name__ == "__main__":
    resolve()

Submission status: Wrong Answer

Solution code:
S = input()
K = int(input())

tmp = 1
cnt = 0
for i in range(1, len(S)):
    if(S[i] == S[i-1]):
        tmp += 1
    else:
        cnt += tmp//2
        tmp = 1
cnt += tmp//2        
a = 1
b = 1

if(S[0] == S[len(S)-1] and S.count(S[0]) != len(S)):
    s = S[::-1]
    for j in range(1, len(S)):
        if(s[j] == s[j-1]):
            a += 1
        else:
            break
    for j in range(1, len(S)):
        if(S[j] == S[j-1]):
            b += 1
        else:
            break
    print(cnt*K-(a//2+b//2-(a+b)//2)*(K-1))
else:
    print(cnt*K)

Submission status: Wrong Answer

Solution code:
S = input()
K = int(input())

tmp = 1
cnt = 0
for i in range(1, len(S)):
    if(S[i] == S[i-1]):
        tmp += 1
    else:
        cnt += tmp//2
        tmp = 1
cnt += tmp//2        
tmp = 1
if(S[0] == S[len(S)-1]):
    s = S[::-1]
    for j in range(1, len(S)):
        if(s[j] == s[j-1]):
            tmp += 1
        else:
            break
    tmp += 1
    for j in range(1, len(S)):
        if(S[j] == S[j-1]):
            tmp += 1
        else:
            break
    if(tmp%2 == 0):
        print(cnt*K+(K-1))
    else:
        print(cnt*K)
else:
    print(cnt*K)

Submission status: Wrong Answer

Solution code:
S = input()
K = int(input())

tmp = 1
cnt = 0
for i in range(1, len(S)):
    if(S[i] == S[i-1]):
        tmp += 1
    else:
        cnt += tmp//2
        tmp = 1
cnt += tmp//2        
tmp = 1
if(S[0] == S[len(S)-1]):
    s = S[::-1]
    for j in range(1, len(S)):
        if(s[i] == s[i-1]):
            tmp += 1
        else:
            break
    for j in range(1, len(S)):
        if(s[i] == s[i-1]):
            tmp += 1
        else:
            break
    if(tmp%2 == 0):
        print(cnt*K+(K-1))
    else:
        print(cnt*K)
else:
    print(cnt*K)

Submission status: Wrong Answer

Solution code:
import sys

S = input()
K = int(input())
n = len(S)

if n == 1:
  print(K // 2)
  sys.exit()

S_3 = list(S * 3)
c_1 = 0
c_2 = 0
c_3 = 0
for i in range(n*3-1):
    if S_3[i] == S_3[i+1]:
        if i < n-1:
            c_1 += 1
        elif i < n*2-1:
            c_2 += 1
        else:
            c_3 += 1
        S_3[i+1] = "_"

if K == 1:
    c = 0
    for i in range(n-1):
        if S[i] == S[i+1]:
            c += 1
else:
    c = c_1 + c_2 * (K-2) + c_3
print(c)

Submission status: Wrong Answer

Solution code:
S = input()
K = int(input())
n = len(S)
S_3 = list(S * 3)
c_1 = 0
c_2 = 0
c_3 = 0
for i in range(n*3-1):
    if S_3[i] == S_3[i+1]:
        if i < n-1:
            c_1 += 1
        elif i < n*2-1:
            c_2 += 1
        else:
            c_3 += 1
        S_3[i+1] = "_"

if K == 1:
    c = 0
    for i in range(n-1):
        if S[i] == S[i+1]:
            c += 1
else:
    c = c_1 + c_2 * (K-2) + c_3
print(c)

Submission status: Wrong Answer

Solution code:
S = input()
K = int(input())
n = len(S)
print(S*3)
S_3 = list(S * 3)
c_1 = 0
c_2 = 0
c_3 = 0
for i in range(n*3-1):
    if S_3[i] == S_3[i+1]:
        if i < n-1:
            c_1 += 1
        elif i < n*2-1:
            c_2 += 1
        else:
            c_3 += 1
        S_3[i+1] = "_"

if K == 1:
    c = 0
    for i in range(n-1):
        if S[i] == S[i+1]:
            c += 1
else:
    c = c_1 + c_2 * (K-2) + c_3
print(c)

Submission status: Wrong Answer

Solution code:
def input_list():
  return list(map(int, input().split()))


def main():
  s = list(input())
  k = int(input())
  if len(set(s)) == 1:
    print(int(len(s)*(k/2)))
    exit()
  
  sw = [s[0]]
  num = 0
  numbers = [num]
  for i in range(1, len(s)):
    if s[i-1] != s[i]:
      num += 1
    numbers.append(num)
    if num == 0 and sw[0] == s[i]:
      sw.append(s[i])

  num = 0
  end_w = s[-1]
  ew = []
  for i in range(len(s)-1, -1, -1):
    if end_w != s[i]:
      num += 1
    if num == 0 and end_w == s[i]:
      ew.append(s[i])
  nc = collections.Counter(numbers)
  
  a = 0
  for n,c in nc.items():
    if c == 1:
      continue
    if c % 2 == 0:
      a += c // 2
    else:
      a += (c-1)//2
  
  if ew[0] == sw[0]:
    haji = len(sw) + len(ew)
    if haji % 2 == 0:
      print(a * (k + (k-1)))
      exit()
  else:
    print(a*k)
  
import math
import fractions
import collections
import itertools
from functools import reduce
main()

Submission status: Wrong Answer

Solution code:
def input_list():
  return list(map(int, input().split()))


def main():
  s = list(input())
  k = int(input())
  if len(set(s)) == 1:
    print(int(len(s)*(k/2)))
    exit()
  
  sw = [s[0]]
  num = 0
  numbers = [num]
  for i in range(1, len(s)):
    if s[i-1] != s[i]:
      num += 1
    numbers.append(num)
    if num == 0 and sw[0] == s[i]:
      sw.append(s[i])

  num = 0
  end_w = s[-1]
  ew = []
  for i in range(len(s)-1, -1, -1):
    if end_w != s[i]:
      num += 1
    if num == 0 and end_w == s[i]:
      ew.append(s[i])
  nc = collections.Counter(numbers)
  
  a = 0
  for n,c in nc.items():
    if c == 1:
      continue
    if c % 2 == 0:
      a += c // 2
    else:
      a += (c-1)//2
  
  ans = a * k
  b = 0
  if ew[0] == sw[0]:
    haji = len(sw) + len(ew)
    if haji % 2 == 0:
      print(a * (k + (k-1)))
      exit()
  print(ans - b)
  
import math
import fractions
import collections
import itertools
from functools import reduce
main()

Submission status: Wrong Answer

Solution code:
def input_list():
  return list(map(int, input().split()))


def main():
  s = list(input())
  k = int(input())
  if len(set(s)) == 1:
    print(int(len(s)*(k/2)))
    exit()
  
  sw = [s[0]]
  num = 0
  numbers = [num]
  for i in range(1, len(s)):
    if s[i-1] != s[i]:
      num += 1
    numbers.append(num)
    if num == 0 and sw[0] == s[i]:
      sw.append(s[i])

  num = 0
  end_w = s[-1]
  ew = []
  for i in range(len(s)-1, -1, -1):
    if end_w != s[i]:
      num += 1
    if num == 0 and end_w == s[i]:
      ew.append(s[i])
  nc = collections.Counter(numbers)
  
  a = 0
  for n,c in nc.items():
    if c == 1:
      continue
    if c % 2 == 0:
      a += c // 2
    else:
      a += (c-1)//2
  
  ans = a * k
  b = 0
  if ew[0] == sw[0]:
    haji = len(sw) + len(ew)
    if haji == 2:
      print(ans + haji)
      exit(0)
    elif haji % 2 == 0:
      print(a * (k + (k-1)))
      exit()
  print(ans - b)
  
import math
import fractions
import collections
import itertools
from functools import reduce
main()

Submission status: Wrong Answer

Solution code:
def input_list():
  return list(map(int, input().split()))


def main():
  s = list(input())
  k = int(input())
  sw = [s[0]]
  num = 0
  numbers = [num]
  for i in range(1, len(s)):
    if s[i-1] != s[i]:
      num += 1
    numbers.append(num)
    if num == 0 and sw[0] == s[i]:
      sw.append(s[i])

  num = 0
  end_w = s[-1]
  ew = []
  for i in range(len(s)-1, -1, -1):
    if end_w != s[i]:
      num += 1
    if num == 0 and end_w == s[i]:
      ew.append(s[i])
  nc = collections.Counter(numbers)
  
  a = 0
  for n,c in nc.items():
    if c == len(s):
      print(k)
      exit()
    if c == 1:
      continue
    if c % 2 == 0:
      a += c // 2
    else:
      a += (c-1)//2
  
  ans = a * k
  b = 0
  if ew[0] == sw[0]:
    haji = len(sw) + len(ew)
    if haji == 2:
      print(ans + haji)
      exit(0)
    
    b = int(len(sw)/2 + len(ew)/2) - haji//2
  print(ans - b)
  
import math
import fractions
import collections
import itertools
from functools import reduce
main()

Submission status: Wrong Answer

Solution code:
def input_list():
  return list(map(int, input().split()))


def main():
  s = list(input())
  k = int(input())
  sw = [s[0]]
  num = 0
  numbers = [num]
  for i in range(1, len(s)):
    if s[i-1] != s[i]:
      num += 1
    numbers.append(num)
    if num == 0 and sw[0] == s[i]:
      sw.append(s[i])

  num = 0
  end_w = s[-1]
  ew = []
  for i in range(len(s)-1, -1, -1):
    if end_w != s[i]:
      num += 1
    if num == 0 and end_w == s[i]:
      ew.append(s[i])
  nc = collections.Counter(numbers)
  
  a = 0
  for n,c in nc.items():
    if c == len(s):
      print(k)
    if c == 1:
      continue
    if c % 2 == 0:
      a += c // 2
    else:
      a += (c-1)//2
  
  ans = a * k
  b = 0
  if ew[0] == sw[0]:
    haji = len(sw) + len(ew)
    if haji == 2:
      print(ans + haji)
      exit(0)
    
    b = int(len(sw)/2 + len(ew)/2) - haji//2
  print(ans - b)
  
import math
import fractions
import collections
import itertools
from functools import reduce
main()

Submission status: Wrong Answer

Solution code:
def input_list():
  return list(map(int, input().split()))


def main():
  s = list(input())
  k = int(input())
  sw = [s[0]]
  num = 0
  numbers = [num]
  for i in range(1, len(s)):
    if s[i-1] != s[i]:
      num += 1
    numbers.append(num)
    if num == 0 and sw[0] == s[i]:
      sw.append(s[i])

  num = 0
  end_w = s[-1]
  ew = []
  for i in range(len(s)-1, -1, -1):
    if end_w != s[i]:
      num += 1
    if num == 0 and end_w == s[i]:
      ew.append(s[i])
  nc = collections.Counter(numbers)
  
  a = 0
  for n,c in nc.items():
    if c == len(s):
      print(len(s))
    if c == 1:
      continue
    if c % 2 == 0:
      a += c // 2
    else:
      a += (c-1)//2
  
  ans = a * k
  b = 0
  if ew[0] == sw[0]:
    haji = len(sw) + len(ew)
    if haji == 2:
      print(ans + haji)
      exit(0)
    
    b = int(len(sw)/2 + len(ew)/2) - haji//2
  print(ans - b)
  
import math
import fractions
import collections
import itertools
from functools import reduce
main()

Submission status: Wrong Answer

Solution code:
def input_list():
  return list(map(int, input().split()))


def main():
  s = list(input())
  k = int(input())
  sw = [s[0]]
  num = 0
  numbers = [num]
  for i in range(1, len(s)):
    if s[i-1] != s[i]:
      num += 1
    numbers.append(num)
    if num == 0 and sw[0] == s[i]:
      sw.append(s[i])

  num = 0
  end_w = s[-1]
  ew = []
  for i in range(len(s)-1, -1, -1):
    if end_w != s[i]:
      num += 1
    if num == 0 and end_w == s[i]:
      ew.append(s[i])
  nc = collections.Counter(numbers)
  
  a = 0
  for n,c in nc.items():
    if c == 1:
      continue
    if c % 2 == 0:
      a += c // 2
    else:
      a += (c-1)//2
  
  ans = a * k
  b = 0
  if ew[0] == sw[0]:
    haji = len(sw) + len(ew)
    if haji == 2:
      b = 1
    elif haji > 3 and haji % 2 != 0:
      b = (haji-1)//2
  print(ans - b)
  
import math
import fractions
import collections
import itertools
from functools import reduce
main()

Submission status: Wrong Answer

Solution code:
from math import floor, ceil
s = input()
k = int(input())

def f(s):
    b = ''
    ret = 0
    for i in s:
        if i==b:
            b = ''
            ret += 1
            continue
        b = i
    return ret

b = f(s*2) - f(s*1)
c = f(s*3) - f(s*2)
print(b*floor(k/2) + c*ceil(k/2))

Submission status: Wrong Answer

Solution code:
s = input()
k = int(input())

def f(s):
    b = ''
    ret = 0
    for i in s:
        if i==b:
            b = ''
            ret += 1
            continue
        b = i
    return ret

b = f(s*3) - f(s*2)
print(f(s) + b*(k-1))

Submission status: Wrong Answer

Solution code:
s = input()
k = int(input())

def f(s):
    b = ''
    ret = 0
    for i in s:
        if i==b:
            b = ''
            ret += 1
            continue
        b = i
    return ret

b = f(s*2) - f(s)
print(f(s) + b*(k-1))

Submission status: Wrong Answer

Solution code:
S = list(input())
K = int(input())

if len(set(S))==1:
    print(len(S)*K//2)
    exit()

cnt1 = 0
tmp = S[0]
for i in range(1, len(S)):
    if S[i] == tmp:
        cnt1 += 1
        S[i] = '.'
    tmp = S[i]

if S[0] == S[-1]:
    cnt2 = K-1
else:
    cnt2 = 0

print(cnt1*K + cnt2)

Submission status: Wrong Answer

Solution code:
S = list(input())
K = int(input())

if len(set(S))==1:
    print(len(S)*K//2)
    exit()

cnt1 = 0
tmp = S[0]
for i in range(1, len(S)):
    if S[i] == tmp:
        cnt1 += 1
        S[i] = '.'
    tmp = S[i]

if S[0] == S[-1]:
    cnt2 = K-1
else:
    cnt2 = 0

print(cnt1 + cnt2)

Submission status: Wrong Answer

Solution code:
S = input()
S = [c for c in S]
K = int(input())

cnt1 = 0
tmp = S[0]
for i in range(1, len(S)):
    if S[i] == tmp:
        cnt1 += 1
        S[i] = '.'
    tmp = S[i]

if S[0] == S[-1]:
    cnt2 = K-1
else:
    cnt2 = 0

print(cnt1*K + cnt2)

Submission status: Wrong Answer

Solution code:
S = input()
K = int(input())

if S[0] != S[-1]:
    ans = 0
    for i in range(len(S[1:-1]) - 1):
        if S[i + 2] == S[i + 1]:
            S = S[:i + 2] + '*' + S[i + 3:]
            ans += 1
    print(ans * K)
else:
    # S -> s_1 s_2 ... s_k + A + t_l t_l-1 ... t_1 (s_i = t_j)と分解
    k, l = 0, len(S) - 1
    while k < len(S) and S[k] == S[-1]:
        k += 1
    while l > -1 and S[l] == S[0]:
        l -= 1

    # 連結に関係ない部分のカウント
    A = S[k:l + 1]
    ans = 0
    for i in range(len(A) - 1):
        if A[i + 1] == A[i]:
            A = A[:i + 1] + '*' + A[i + 2:]
            ans += 1
    ans *= K

    # 連結に関係ある部分のカウント
    if l == -1 and k == len(S):
        # 全部同じ
        print((len(S) * K) // 2)
    else:
        ans += (len(S) - l + k - 1) // 2 * (K - 1)
        ans += (len(S) - l) // 2 + (k - 1) // 2
        print(ans)

Submission status: Wrong Answer

Solution code:

s = input()
k = int(input())
ans = 0

if s[0] == s[-1]:
    ans += 1
    for i in range(len(s)-2):
        if s[i] == s[i+1]:
            ans += 1
        else:
            pass
else:
    for i in range(len(s)-2):
        if s[i] == s[i+1]:
            ans += 1
        else:
            pass

print(ans * k)

Submission status: Wrong Answer

Solution code:
S=input()
N=len(S)
K=int(input())
s="".join((S,S))
cnt1=0
cnt2=0
buf=0
piv=""
for i in range(N):
    if S[i]==piv:
        buf=buf+1
    else:
        piv=S[i]
        cnt1=cnt1+(buf+1)//2
        buf=0
cnt1=cnt1+(buf+1)//2
buf=0
piv=""
for i in range(2*N):
    if s[i]==piv:
        buf=buf+1
    else:
        piv=s[i]
        cnt2=cnt2+(buf+1)//2
        buf=0
    #print(buf)
cnt2=cnt2+(buf+1)//2
x=cnt2-cnt1
print(cnt1+(K-1)*x)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline

S = input().strip()
K = int(input())

count_l = 0
count_r = 0
for x in S:
    if x == S[0]:
        count_l += 1
    else:
        break

for x in S[::-1]:
    if x == S[-1]:
        count_r += 1
    else:
        break

ans = 0
for i in range(len(S) - 1):
    if S[i] == S[i + 1]:
        s = S[i]
        ans += 1
        S = S.replace(s * 2, s + '_', 1)

if count_l % 2 and count_r % 2 and S[0] == S[-1]:
    ans = (ans + 1) * K - 1
else:
    ans *= K

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline

S = input().strip()
K = int(input())

count = 0
for i in range(len(S) - 1):
    if S[i] == S[i + 1]:
        s = S[i]
        count += 1
        S = S.replace(s * 2, s + '_', 1)

count *= K

print(count)

Submission status: Wrong Answer

Solution code:
S=list(input())
K=int(input())
cnt=0
s=S*2
if len(set(S))==1:
    print(len(S)*K//2);exit()
for i in range(len(s)-1):
    if s[i+1]==s[i]:
        cnt+=1
        s[i+1]="#"
print(int(s.count("#")*K/2))

Submission status: Wrong Answer

Solution code:
from itertools import groupby

s = input()
k = int(input())

cont = [sum(1 for _ in it) for k, it in groupby(s)]

if len(s) == 1:
    res = k // 2
else:
    res = k-1 if s[0] == s[-1] and cont[0] % 2 == 1 and cont[-1] % 2 == 1 else 0
    for c in cont:
        if c != 1:
            res += c // 2 * k

print(res)

Submission status: Wrong Answer

Solution code:
from itertools import groupby

s = input()
k = int(input())

cont = [sum(1 for _ in it) for k, it in groupby(s)]

res = k-1 if s[0] == s[-1] and cont[0] % 2 == 1 and cont[-1] % 2 else 0
for c in cont:
    if c != 1:
        res += c // 2 * k

print(res)

Submission status: Wrong Answer

Solution code:
from itertools import groupby

s = input()
k = int(input())

cont = [sum(1 for _ in it) for k, it in groupby(s)]

res = 1 if s[0] == s[-1] and cont[0] % 2 == 1 and cont[-1] % 2 and k != 1 == 1 else 0
for c in cont:
    if c != 1:
        res += c // 2

print(res * k)

Submission status: Wrong Answer

Solution code:
from itertools import groupby

s = input()
k = int(input())

cont = [sum(1 for _ in it) for k, it in groupby(s)]

res = 1 if s[0] == s[-1] and cont[0] % 2 == 1 and cont[-1] % 2 == 1 else 0
for c in cont:
    if c != 1:
        res += c // 2

print(res * k)

Submission status: Wrong Answer

Solution code:
S = input()
K = int(input())
ans = 0
tmp = 1

for i in range(1, len(S)):
    if S[i] == S[i-1]:
        tmp += 1
    else:
        ans += tmp//2
        tmp = 1

ans += tmp // 2
ans *= K
if S[0] == S[-1] and tmp % 2 != 0:
    ans += K-1

print(ans)

Submission status: Wrong Answer

Solution code:
import math
s = list(input())
ss = s[:]
k = int(input())
cnt = 0

if len(set(s)) == 1:
    cnt = math.floor(len(s) * k / 2)
else:
    cnt = 0
    for i in range(len(s) - 1):
        if s[i] == s[i + 1]:
            cnt += 1
            s[i + 1] = '*'
    cnt *= k
    if ss[0] == ss[-1]:
        a = 0
        for i in range(len(ss) - 1):
            if ss[i] == ss[i + 1]:
                a += 1
            else:
                break
        b = 0
        for j in range(len(ss) - 1, 0, -1):
            if ss[j] == ss[j - 1]:
                b += 1
            else:
                break
        cnt -= (k - 1) * (math.floor(a / 2) + math.floor(b / 2) - math.floor((a + b) / 2))
print(cnt)

Submission status: Wrong Answer

Solution code:
import math
s = list(input())
ss = s[:]
k = int(input())
cnt = 0

if len(set(s)) == 1:
    cnt = math.floor(len(s) * k / 2)
else:
    cnt = 0
    for i in range(len(s) - 1):
        if s[i] == s[i + 1]:
            cnt += 1
            s[i + 1] = '*'
    cnt *= k
    if s[0] == s[-1]:
        a = 0
        for i in range(len(s) - 1):
            if ss[i] == ss[i + 1]:
                a += 1
        b = 0
        for j in range(len(s)-1, 0, -1):
            if ss[j] == ss[j - 1]:
                b += 1
        cnt -= (k - 1) * (math.floor(a / 2) + math.floor(b / 2) - math.floor((a + b) / 2))
print(cnt)

Submission status: Wrong Answer

Solution code:
import math
s = list(input())
ss = s[:]
k = int(input())
cnt = 0
if len(set(s)) == 1:
    cnt = math.floor(len(s) * k / 2)
else:
    cnt = 0
    for i in range(len(s) - 1):
        if s[i] == s[i + 1]:
            cnt += 1
            s[i + 1] = '*'
    cnt *= k
    if s[0] == s[-1]:
        a = 0
        for i in range(len(s) - 1):
            if ss[i] == ss[i + 1]:
                a += 1
        b = 0
        for j in range(len(s), 0, -1):
            if ss[i] == ss[i - 1]:
                b += 1
        cnt -= (k - 1) * (math.floor(a / 2) + math.floor(b / 2) - math.floor((a + b) / 2))
print(cnt)

Submission status: Wrong Answer

Solution code:
import math
s = list(input())
k = int(input())
cnt = 0
if len(s) == 1:
    cnt = math.floor(k / 2)
else:
    for i in range(len(s)-1):
        if s[i] == s[i + 1]:
            s[i + 1] = '*'
            cnt += 1
    cnt *= k
    if s[0] == s[-1]:
        cnt += k - 1
print(cnt)

Submission status: Wrong Answer

Solution code:
s = list(input())
k = int(input())
cnt = 0
for i in range(len(s)-1):
    if s[i] == s[i + 1]:
        s[i + 1] = '*'
        cnt += 1
cnt *= k
if s[0] == s[-1]:
    cnt += k - 1
print(cnt)

Submission status: Wrong Answer

Solution code:
#template
def inputlist(): return [int(j) for j in input().split()]
#template
#issueから始める
s = list(input())
K = int(input())
n = len(s)
if len(set(s)) == 1:
    print(K*len(s)//2)
    exit()
count =0
counta = 0
if s[0] == s[-1]:
    if s[-1] != s[-2]:
        counta = K-1
for i in range(n-1):
    if s[i] == s[i+1]:
        count +=1
        s[i+1] = '?'
print(count*K+counta)

Submission status: Wrong Answer

Solution code:
#template
def inputlist(): return [int(j) for j in input().split()]
#template
#issueから始める
s = list(input())
K = int(input())
n = len(s)
if n == 1:
    print(K//2)
    exit()
count =0
counta = 0
if s[0] == s[-1]:
    if s[-1] != s[-2]:
        counta = K-1
for i in range(n-1):
    if s[i] == s[i+1]:
        count +=1
        s[i+1] = '?'
if set(s) == 1:
    counta +=1
print(count*K+counta)

Submission status: Wrong Answer

Solution code:
import math
import fractions
import bisect
import collections
import itertools
import heapq
import string
import sys
import copy
from decimal import *
from collections import deque
sys.setrecursionlimit(10**7)
MOD = 10**9+7
INF = float('inf') #無限大
def gcd(a,b):return fractions.gcd(a,b) #最大公約数
def lcm(a,b):return (a*b) // fractions.gcd(a,b) #最小公倍数
def iin(): return int(sys.stdin.readline()) #整数読み込み
def ifn(): return float(sys.stdin.readline()) #浮動小数点読み込み
def isn(): return sys.stdin.readline().split() #文字列読み込み
def imn(): return map(int, sys.stdin.readline().split()) #整数map取得
def imnn(): return map(lambda x:int(x)-1, sys.stdin.readline().split()) #整数-1map取得
def fmn(): return map(float, sys.stdin.readline().split()) #浮動小数点map取得
def iln(): return list(map(int, sys.stdin.readline().split())) #整数リスト取得
def iln_s(): return sorted(iln()) # 昇順の整数リスト取得
def iln_r(): return sorted(iln(), reverse=True) # 降順の整数リスト取得
def fln(): return list(map(float, sys.stdin.readline().split())) # 浮動小数点リスト取得
def join(l, s=''): return s.join(l) #リストを文字列に変換
def perm(l, n): return itertools.permutations(l, n) # 順列取得
def perm_count(n, r): return math.factorial(n) // math.factorial(n-r) # 順列の総数
def comb(l, n): return itertools.combinations(l, n) # 組み合わせ取得
def comb_count(n, r): return math.factorial(n) // (math.factorial(n-r) * math.factorial(r)) #組み合わせの総数
def two_distance(a, b, c, d): return ((c-a)**2 + (d-b)**2)**.5 # 2点間の距離
def m_add(a,b): return (a+b) % MOD
def print_list(l): print(*l, sep='\n')

def sieves_of_e(n):
    is_prime = [True] * (n+1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5)+1):
        if not is_prime[i]: continue
        for j in range(i * 2, n+1, i): is_prime[j] = False
    return is_prime

S = list(input())
K = iin()
s = copy.deepcopy(S)
last_update = False
count1 = 0
for si in range(1, len(s)):
    if s[si-1] == s[si]:
        s[si] = '?'
        count1 += 1
        if si == len(s)-1:
            last_update = True
count2 = 0
last_update2 = False
if not last_update and S[0] == S[-1]:
    count2 = 1
    S2 = list('?')
    S2.extend(S[1:])
    for i in range(2, len(S2)):
        if S2[i-1] == S2[i]:
            S2[i] = '?'
            count2 += 1
            if i == len(S2)-1:
                last_update2 = True
if K == 1:
    print(count1)
elif count2 == 0:
    print(K*count1)
else:
    if last_update2:
        count12 = count1+count2
        ans = count12*(K//2)
        if K % 2 == 1: 
            ans+= count1
        print(ans)
    else:
        print(count1 + count2*(K-1))

Submission status: Wrong Answer

Solution code:
import math
import fractions
import bisect
import collections
import itertools
import heapq
import string
import sys
import copy
from decimal import *
from collections import deque
sys.setrecursionlimit(10**7)
MOD = 10**9+7
INF = float('inf') #無限大
def gcd(a,b):return fractions.gcd(a,b) #最大公約数
def lcm(a,b):return (a*b) // fractions.gcd(a,b) #最小公倍数
def iin(): return int(sys.stdin.readline()) #整数読み込み
def ifn(): return float(sys.stdin.readline()) #浮動小数点読み込み
def isn(): return sys.stdin.readline().split() #文字列読み込み
def imn(): return map(int, sys.stdin.readline().split()) #整数map取得
def imnn(): return map(lambda x:int(x)-1, sys.stdin.readline().split()) #整数-1map取得
def fmn(): return map(float, sys.stdin.readline().split()) #浮動小数点map取得
def iln(): return list(map(int, sys.stdin.readline().split())) #整数リスト取得
def iln_s(): return sorted(iln()) # 昇順の整数リスト取得
def iln_r(): return sorted(iln(), reverse=True) # 降順の整数リスト取得
def fln(): return list(map(float, sys.stdin.readline().split())) # 浮動小数点リスト取得
def join(l, s=''): return s.join(l) #リストを文字列に変換
def perm(l, n): return itertools.permutations(l, n) # 順列取得
def perm_count(n, r): return math.factorial(n) // math.factorial(n-r) # 順列の総数
def comb(l, n): return itertools.combinations(l, n) # 組み合わせ取得
def comb_count(n, r): return math.factorial(n) // (math.factorial(n-r) * math.factorial(r)) #組み合わせの総数
def two_distance(a, b, c, d): return ((c-a)**2 + (d-b)**2)**.5 # 2点間の距離
def m_add(a,b): return (a+b) % MOD
def print_list(l): print(*l, sep='\n')

def sieves_of_e(n):
    is_prime = [True] * (n+1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5)+1):
        if not is_prime[i]: continue
        for j in range(i * 2, n+1, i): is_prime[j] = False
    return is_prime

S = list(input())
K = iin()
s = copy.deepcopy(S)
last_update = False
count1 = 0
for si in range(1, len(s)):
    if s[si-1] == s[si]:
        s[si] = '?'
        count1 += 1
        if si == len(s)-1:
            last_update = True
count2 = 0
last_update2 = False
if not last_update and S[0] == S[-1]:
    count2 = 1
    S2 = list('?')
    S2.extend(S[1:])
    for i in range(2, len(S2)):
        if S2[i-1] == S2[i]:
            S2[i] = '?'
            count2 += 1
            if i == len(S2)-1:
                last_update2 = True
if K == 1:
    print(count1)
elif count2 == 0:
    print(K*count1)
else:
    if last_update2:
        print(count1)
        print(count2)
        count12 = count1+count2
        ans = count12*(K//2)
        if K % 2 == 1: 
            ans+= count1
        print(ans)
    else:
        print(count1 + count2*(K-1))