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:
#! /usr/bin/env python3

import sys
import numpy as np
int1 = lambda x: int(x) - 1
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

S = list(readline().decode().rstrip())
K = int(readline())

cnt = 0
for i in range(len(S) - 1):
    if S[i] == S[i + 1]:
        S[i + 1] = "0"
        cnt += 1
if S[0] == S[-1]:
    cnt += 1

print(cnt * K)

Submission status: Wrong Answer

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

def main():
    S = input()
    K = int(input())
    N = len(S)
    SS = S+S
    t = ''
    tt = ''
    flg = 0
    for i in range(N):
        if i and t[i-1] == S[i]:
            t += '#'
        else:
            t += S[i]

    for i in range(2*N):
        if i and tt[i-1] == SS[i]:
            tt += '#'
        else:
            tt += SS[i]

    d = tt.count('#')-t.count('#')
    print(t.count('#')+(K-1)*d)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

def main():
    S = input()
    K = int(input())
    N = len(S)
    t = ''
    flg = 0
    for i in range(N):
        if i and t[i-1] == S[i]:
            t += '#'
        else:
            t += S[i]

    if t[-1] != '#' and t[-1] == t[0]:
        t = t[:-1]+'#'
        flg = 1

    print(t.count('#')*K-flg)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys


def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def S(): return input()
def LS(): return input().split()


s = S()
k = I()
counts = [1]
for i in range(1, len(s)):
    if s[i - 1] == s[i]:
        counts[-1] += 1
    else:
        counts.append(1)

# 文字が 1 種類
if len(counts) == 1:
    print(len(s) * k // 2)

else:
    ans = 0
    # 語頭と語尾が同じ文字でない
    if s[0] != s[-1]:
        for cnt in counts:
            ans += cnt // 2
        ans *= k

    # 語頭と語尾が同じ文字
    else:
        # 語頭と語尾(の連続する文字)を除いて考える
        for cnt in counts[1:-1]:
            ans += cnt // 2
        ans *= k
        length = counts[0] + counts[-1]
        # k-1個あるsの境目の変換の回数
        ans += (length // 2) * (k - 1)

    print(ans)

Submission status: Wrong Answer

Solution code:
import sys


def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def S(): return input()
def LS(): return input().split()


s = S()
k = I()
counts = [1]
for i in range(1, len(s)):
    if s[i - 1] == s[i]:
        counts[-1] += 1
    else:
        counts.append(1)

print(counts)
# 文字が 1 種類
if len(counts) == 1:
    print(len(s) * k // 2)

else:
    ans = 0
    # 語頭と語尾が同じ文字でない
    if s[0] != s[-1]:
        for cnt in counts:
            ans += cnt // 2
        ans *= k

    # 語頭と語尾が同じ文字
    else:
        # 語頭と語尾(の連続する文字)を除いて考える
        for cnt in counts[1:-1]:
            ans += cnt // 2
        ans *= k
        length = counts[0] + counts[-1]
        # k-1個あるsの境目の変換の回数
        ans += (length // 2) * (k - 1)

    print(ans)

Submission status: Wrong Answer

Solution code:
import sys


def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def S(): return input()
def LS(): return input().split()


s = S()
k = I()
counts = [1]
for i in range(1, len(s)):
    if s[i - 1] == s[i]:
        counts[-1] += 1
    else:
        counts.append(1)

# 連続して同じ文字がでてこない
if all([cnt == 1 for cnt in counts]):
    # 語頭と語尾が同じ文字
    if s[0] != s[-1]:
        print(0)
    else:
        print(k - 1)

# 文字が 1 種類
elif len(counts) == 1:
    print(len(s) * k // 2)

else:
    ans = 1
    if s[0] != s[-1]:
        for cnt in counts:
            ans *= cnt
        ans *= k
    # 語頭と語尾が同じ文字
    else:
        length = counts[0] + counts[-1]
        for cnt in counts[1:-1]:
            ans *= cnt
        ans += length // 2 * k

    print(ans)

Submission status: Wrong Answer

Solution code:
s = list(input())
k = int(input())
s += '+'+'-'

releki = []
cnt = 1
pre = s[0]
for i in range(1,len(s)):
    if pre==s[i]:
        cnt += 1
    else:
        releki.append([pre,cnt])
        pre = s[i]
        cnt = 1
        
ans = 0
for i in range(len(releki)):
    ans += releki[i][1]//2

if s[0]!=s[-3]:
    print(ans*k)
else:
    a = releki[0][1]
    b = releki[-1][1]
    ans = ans*k - (k-1)*(a//2 +b//2 -(a+b)//2)
    print(ans)

Submission status: Wrong Answer

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

s += s[0]

cnt = 0
pre = ''
for i in range(len(s)):
    if s[i]==pre:
        cnt += 1
        pre =''
    else:
        pre = s[i]
ans = cnt*k
print(ans)

Submission status: Wrong Answer

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

s += s[0]
cnt = 0
pre = s[0]
for i in range(1,len(s)):
    if s[i]==pre:
        cnt += 1
        pre =''
    else:
        pre = s[i]
print(cnt*k)

Submission status: Wrong Answer

Solution code:
import sys
import math
import itertools
import collections
import heapq
import re
import numpy as np

rr = lambda: sys.stdin.readline().rstrip()
rs = lambda: map(str, sys.stdin.buffer.readline().split())
ri = lambda: int(sys.stdin.readline())
rm = lambda: map(int, sys.stdin.buffer.readline().split())
rl = lambda: list(map(int, sys.stdin.buffer.readline().split()))

s = rr()
k = ri()
cnt = 0
i = 0
if len(set(s)) == 1:
  print(int(len(s)*k/2))
  exit()
while i < len(s)-1:
  if s[i] == s[i+1]:
    cnt += 1
    i += 1
  i += 1
print(cnt)
cnt1 = 0
i1 = 0
s *= 2
while i1 < len(s)-1:
  if s[i1] == s[i1+1]:
    cnt1 += 1
    i1 += 1
  i1 += 1
print(cnt1)
print((cnt1 - cnt)*(k-1) + cnt)

Submission status: Wrong Answer

Solution code:
import sys
import math
import itertools
import collections
import heapq
import re
import numpy as np

rr = lambda: sys.stdin.readline().rstrip()
rs = lambda: map(str, sys.stdin.buffer.readline().split())
ri = lambda: int(sys.stdin.readline())
rm = lambda: map(int, sys.stdin.buffer.readline().split())
rl = lambda: list(map(int, sys.stdin.buffer.readline().split()))

s = rr()
k = ri()
cnt = 0
i = 0
while i < len(s)-1:
  if s[i] == s[i+1]:
    cnt += 1
    i += 1
  i += 1
cnt1 = 0
i1 = 0
s *= 2
while i1 < len(s)-1:
  if s[i1] == s[i1+1]:
    cnt1 += 1
    i1 += 1
  i1 += 1
print((cnt1 - cnt)*(k-1) + cnt)

Submission status: Wrong Answer

Solution code:
import sys
import math
import itertools
import collections
import heapq
import re
import numpy as np

rr = lambda: sys.stdin.readline().rstrip()
rs = lambda: map(str, sys.stdin.buffer.readline().split())
ri = lambda: int(sys.stdin.readline())
rm = lambda: map(int, sys.stdin.buffer.readline().split())
rl = lambda: list(map(int, sys.stdin.buffer.readline().split()))

s = rr()
k = ri()
cnt = 0
i = 0
while i < len(s)-1:
  if s[i] == s[i+1]:
    cnt += 1
    i += 1
  i += 1
print(cnt*k)

Submission status: Wrong Answer

Solution code:
import sys
import math
import itertools
import collections
import heapq
import re
import numpy as np

rr = lambda: sys.stdin.readline().rstrip()
rs = lambda: map(str, sys.stdin.buffer.readline().split())
ri = lambda: int(sys.stdin.readline())
rm = lambda: map(int, sys.stdin.buffer.readline().split())
rl = lambda: list(map(int, sys.stdin.buffer.readline().split()))

s = rr()
k = ri()
cnt = 0
for i in range(len(s)-1):
  if s[i] == s[i+1]:
    cnt += 1
print(cnt*k)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
#from math import gcd
import bisect
from collections import defaultdict
from collections import deque
from collections import Counter
from functools import lru_cache


#############
# Constants #
#############

MOD = 10**9+7
INF = float('inf')

#############
# Functions #
#############

######INPUT######
def I(): return int(input().strip())
def S(): return input().strip()
def IL(): return list(map(int,input().split()))
def SL(): return list(map(str,input().split()))
def ILs(n): return list(int(input()) for _ in range(n))
def SLs(n): return list(input().strip() for _ in range(n))
def ILL(n): return [list(map(int, input().split())) for _ in range(n)]
def SLL(n): return [list(map(str, input().split())) for _ in range(n)]

######OUTPUT######
def P(arg): print(arg); return
def Y(): print("Yes"); return
def N(): print("No"); return
def E(): exit()
def PE(arg): print(arg); exit()
def YE(): print("Yes"); exit()
def NE(): print("No"); exit()

#####Shorten#####
def DD(arg): return defaultdict(arg)


#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0: 
        cnt+=1 
        temp //= i
      arr.append([i, cnt])
  if temp!=1:
    arr.append([temp, 1])
  if arr==[]:
    arr.append([n, 1])
  return arr

#####MakeDivisors######
def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i: 
        divisors.append(n//i)
  return divisors

#####MakePrimes######
def make_primes(N):
  max = int(math.sqrt(N))
  seachList = [i for i in range(2,N+1)]
  primeNum = []
  while seachList[0] <= max:
    primeNum.append(seachList[0])
    tmp = seachList[0]
    seachList = [i for i in seachList if i % tmp != 0]
  primeNum.extend(seachList)
  return primeNum

#####GCD#####
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#####BitCount#####
def count_bit(n):
  count = 0
  while n:
    n &= n -1
    count += 1
  return count

#####ChangeBase#####
def base_10_to_n(X, n):
  if X//n:
    return base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def base_n_to_10(X, n):
  return sum(int(str(X)[-i-1])*n**i for i in range(len(str(X))))

#####IntLog#####
def int_log(n, a):
  count = 0
  while n>=a:
    n //= a
    count += 1
  return count

#############
# Main Code #
#############

S = S()
K = I()

count = 1
prev = S[0]
L = []
for s in S[1:]:
  if s != prev:
    L.append(count)
    count = 1
  else:
    count += 1
  prev = s
L.append(count)

if len(L) == 1:
  print((K*L[0])//2)
else:
  ans = sum(x//2 for x in L[1:-1])*K
  if S[0] == S[-1]:
    ans += L[0]//2 + L[-1]//2 + (L[0]+L[-1])*(K-1)
  else:
    ans += (L[0]//2 + L[-1]//2)*K
  print(ans)

Submission status: Wrong Answer

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


count_in = 0
count_first = 0
count_last = 0
flag_same = 0

if S[0] == S[-1]:
    flag_same = 1

if len(S) <= 1:
    pass
else:
    if S[0] == S[1]:
        count_first += 1
    if S[-1] == S[-2]:
        count_last += 1
    
    prev_s = S[0]
    for s in S[1:]:
        if s == prev_s:
            count_in += 1
        prev_s = s

count_in = (count_in + 1)//2
print(K*count_in)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
def main():
    S = list(input().rstrip())
    K = int(input())
    if len(S) == 1:
        print(0)
        return
    CNT = 0
    p = S[0]
    cg = -1
    for i in range(1,len(S)):
        if S[i] == p and cg != i-1:
           CNT += 1
           cg = i
        p = S[i]
    # if S[0] == S[len(S)-1] and cg != len(S)-1:
    #     CNT += 1
    #     ans = CNT * K -1    
    # else:
    #     ans = CNT * K
    ans = CNT *K
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
def main():
    S = list(input().rstrip())
    K = int(input())
    if len(S) == 1:
        print(0)
        return
    CNT = 0
    p = S[0]
    cg = -1
    for i in range(1,len(S)):
        if S[i] == p and cg != i-1:
           CNT += 1
           cg = i
        p = S[i]
    if S[0] == S[len(S)-1] and cg != len(S)-1:
        CNT += 1
        ans = CNT * K -1    
    else:
        ans = CNT * K
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
def main():
    S = list(input().rstrip())
    K = int(input())
    CNT = 0
    p = S[0]
    cg = -1
    for i in range(1,len(S)):
        if S[i] == p and cg != i-1:
           CNT += 1
           cg = i
        p = S[i]
    if S[0] == S[len(S)-1] and cg != len(S)-1:
        CNT += 1
        ans = CNT * K -1    
    else:
        ans = CNT * K
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
s = input()
k = int(input())
s_len = len(s)
if s_len == 1:
    print(k//2)
    exit()
if s.count(s[0]) == s_len:
    print((k*s_len)//2)
    exit()
cnt = 0
ans = 0
flag = "off"
while cnt <= s_len-2:
    if s[cnt] == s[cnt+1]:
        if cnt == s_len-2:
            flag = "on"
        ans += 1
        cnt += 1
    cnt += 1
dum = s[0]
check1 = 0
for i in s:
    if dum == i:
        check1 += 1
    else:
        break
dum = s[-1]
check2 = 0
for i in s[::-1]:
    if dum == i:
        check2 += 1
    else:
        break
if check2%2 == 1 and s[0] == s[-1]:
    print(ans*k+(k-1))
else:
    print(ans*k)

Submission status: Wrong Answer

Solution code:
s = input()
k = int(input())
s_len = len(s)
if s_len == 1:
    print(k//2)
    exit()
cnt = 0
ans = 0
flag = "off"
while cnt <= s_len-2:
    if s[cnt] == s[cnt+1]:
        if cnt == s_len-2:
            flag = "on"
        ans += 1
        cnt += 1
    cnt += 1
dum = s[0]
check1 = 0
for i in s:
    if dum == i:
        check1 += 1
    else:
        break
dum = s[-1]
check2 = 0
for i in s[::-1]:
    if dum == i:
        check2 += 1
    else:
        break
if check2%2 == 1 and s[0] == s[-1]:
    print(ans*k+(k-1))
else:
    print(ans*k)

Submission status: Wrong Answer

Solution code:
s = input()
k = int(input())
s_len = len(s)
cnt = 0
ans = 0
flag = "off"
while cnt <= s_len-2:
    if s[cnt] == s[cnt+1]:
        if cnt == s_len-2:
            flag = "on"
        ans += 1
        cnt += 1
    cnt += 1
dum = s[0]
check1 = 0
for i in s:
    if dum == i:
        check1 += 1
    else:
        break
dum = s[-1]
check2 = 0
for i in s[::-1]:
    if dum == i:
        check2 += 1
    else:
        break
if check2%2 == 1 and s[0] == s[-1]:
    print(ans*k+(k-1))
else:
    print(ans*k)

Submission status: Wrong Answer

Solution code:


def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    S=list(input())
    K=I()
    
    ans=0
    
    N=len(S)
    
    flag=0
    if S.count(S[0])==N:
        flag=1
    
    if N==1 or flag:
        ans=(K*N)//2
    else:
        if S[0]==S[1]:
            ans+=1
            S[0]="."
        
        for i in range(N-1):
            if S[i]==S[i+1]:
                ans+=1
                S[i+1]="#"
                
        ans=ans*K
        
        if S[0]==S[-1]:
            ans+=K-1
        
    print(ans)

main()

Submission status: Wrong Answer

Solution code:


def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    S=list(input())
    K=I()
    
    ans=0
    
    N=len(S)
    
    if N==1:
        ans=(K)//2
    else:
        if S[0]==S[1]:
            ans+=1
            S[0]="."
        
        for i in range(N-1):
            if S[i]==S[i+1]:
                ans+=1
                S[i+1]="#"
                
        ans=ans*K
        
        if S[0]==S[-1]:
            ans+=K-1
        
    print(ans)

main()

Submission status: Wrong Answer

Solution code:


def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    S=list(input())
    K=I()
    
    ans=0
    
    N=len(S)
    for i in range(N-1):
        if S[i]==S[i+1]:
            ans+=1
            S[i+1]="#"
            
    ans=ans*K
    
    if S[0]==S[-1]:
        ans+=K-1
        
    print(ans)

main()

Submission status: Wrong Answer

Solution code:
import numpy as np
s=input()
k=int(input())
cnt=1
a=[]
ss=s+"."
for i in range(len(s)):
    if ss[i]==ss[i+1]:
        cnt+=1
    else:
        a.append(cnt)
        cnt=1

pp=0
if s[0]==s[len(s)-1]:
    pp=a[0]+a[-1]
    
b=[]
if len(a)>1:
    b.append(pp)
    b+=a[1:len(a)-1]

else:
    a=[len(s)*k]
    b=[]
arr=np.array(a)
arr2=np.array(b)

a=arr//2
b=arr2//2
if len(s)>=2:
    print(np.sum(a)+int((k-1)*np.sum(b)))
else:
    print(k//2)

Submission status: Wrong Answer

Solution code:
import numpy as np
s=input()
k=int(input())
cnt=1
a=[]
ss=s+"."
for i in range(len(s)):
    if ss[i]==ss[i+1]:
        cnt+=1
    else:
        a.append(cnt)
        cnt=1

pp=0
if s[0]==s[len(s)-1]:
    pp=a[0]+a[-1]
    
b=[]
if len(a)>1:
    b.append(pp)
    b+=a[1:len(a)-1]

else:
    a=[2]
    b=[2]
arr=np.array(a)
arr2=np.array(b)

a=arr//2
b=arr2//2
if len(s)>=2:
    print(np.sum(a)+int((k-1)*np.sum(b)))
else:
    print(k//2)

Submission status: Wrong Answer

Solution code:
import numpy as np
s=input()
k=int(input())
cnt=1
a=[]
ss=s+"."
for i in range(len(s)):
    if ss[i]==ss[i+1]:
        cnt+=1
    else:
        a.append(cnt)
        cnt=1

pp=0
if s[0]==s[len(s)-1]:
    pp=a[0]+a[-1]
    
b=[]
b.append(pp)
b+=a[1:len(s)-1]
arr=np.array(a)
arr2=np.array(b)

a=arr//2
b=arr2//2
if len(s)>=2:
    print(np.sum(a)+(k-1)*np.sum(b))
else:
    print(k//2)

Submission status: Wrong Answer

Solution code:
import numpy as np
s=input()
k=int(input())
cnt=1
a=[]
ss=s+"."
for i in range(len(s)):
    if ss[i]==ss[i+1]:
        cnt+=1
    else:
        a.append(cnt)
        cnt=1

pp=0
if s[0]==s[len(s)-1]:
    pp=a[0]+a[-1]
    
b=[]
b.append(pp)
b+=a[1:len(s)-2]
    
arr=np.array(a)
arr2=np.array(b)

a=arr//2
b=arr//2
if len(s)>=2:
    print(np.sum(a)+(k-1)*np.sum(b))
else:
    print(k//2)

Submission status: Wrong Answer

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

from itertools import groupby

n=len(s)
cnt =0

gp = groupby(s)

Keys=[]
values=[]
for key,value in gp:
    Keys.append(key)
    values.append(len(list(value)))

if k==1:
    for i in values:
        cnt+=i//2
    
    print(cnt)
    exit(0)

if len(Keys)==1:
    print(values[0]*k//2)
    exit(0)

if k==2:
    if Keys[0]==Keys[-1]:
        values2=list(reversed(values))

        for i in range(len(values)-1):
            if values[i]>=2:
                cnt+=values[i]//2
            if values2[i]>=2:
                cnt+=values2[i]//2
        
        cnt+= (values[0]+values[-1])//2

    print(cnt)
    exit(0)

if k>2:
    if Keys[0]==Keys[-1]:
        values2=list(reversed(values))

        m=len(values)

        for i in range(m-1):
            if values[i]>=2:
                cnt+=values[i]//2
            if values2[i]>=2:
                cnt+=values2[i]//2
        
        cnt+= (k-1) * ((values[0]+values[-1])//2)

        for j in range(m):
            if j==0 or j==m:
                continue
            else:
                cnt+= (k-2)*(values[j]//2)

        print(cnt)
        exit(0)

for i in values:
    if i>1:
        cnt += k*(i//2)


print(cnt)

Submission status: Wrong Answer

Solution code:
s = input()
n = int(input())
count1 = 0
t = s[:]
for i in range(1,len(s)):
    if s[i] == s[i-1]:
        count1+=1
        s = s[:i] + 'A' + s[i+1:]
if n == 1:
    print(count1)
    exit()
t += t
count2 = 0
for i in range(1,len(t)):
    if t[i] == t[i-1]:
        count2+=1
        t = t[:i] + 'A' + t[i+1:]
if count1 * 2 == count2:
    print(count1*n)
elif n % 2 == 0:
    print(count2*n//2)
else:
    print(count1 + count2*(n-1)//2)

Submission status: Wrong Answer

Solution code:
s = input()
n = int(input())
count1 = 0
t = s[:]
for i in range(1,len(s)):
    if s[i] == s[i-1]:
        count1+=1
        s = s[:i] + 'A' + s[i+1:]
if n == 1:
    print(count1)
    exit()
t += t
count2 = 0
for i in range(1,len(t)):
    if t[i] == t[i-1]:
        count2+=1
        t = t[:i] + 'A' + t[i+1:]
if count1 * 2 == count2:
    print(count1*n)
else:
    print((count1+1) * (n-1))

Submission status: Wrong Answer

Solution code:
S = input()
K = int(input())
prev = S[0]
compressed = [[prev, 1]]
for c in S[1:]:
    if c == compressed[-1][0]:
        compressed[-1][1] += 1
    else:
        compressed.append([c, 1])
ans = sum(cnt // 2 for _, cnt in compressed) * K
if S[0] == S[-1]:
    tmp = (compressed[0][1] + compressed[-1][1]) // 2
    tmp -= compressed[0][1] // 2
    tmp -= compressed[-1][1] // 2
    ans += tmp * (K - 1)
print(ans)

Submission status: Wrong Answer

Solution code:
S = input()
K = int(input())
prev = S[0]
compressed = [[prev, 1]]
for c in S[1:]:
    if c == compressed[-1][0]:
        compressed[-1][1] += 1
    else:
        compressed.append([c, 1])
ans = 0
for _, cnt in compressed[:-1]:
    ans += cnt // 2
if compressed[-1][1] > 1 or S[0] == S[-1]:
    ans += (compressed[-1][1] + 1) // 2
print(ans * K)

Submission status: Wrong Answer

Solution code:
S = input()
K = int(input())
prev = S[0]
cnt = 0
compressed = [[prev, 1]]
for c in S[1:-1]:
    if c == compressed[-1][0]:
        compressed[-1][1] += 1
    else:
        compressed.append([c, 1])
ans = 1 if S[0] == S[-1] else 0
for _, cnt in compressed:
    ans += cnt // 2
print(ans * K)

Submission status: Wrong Answer

Solution code:
s = input()
k = int(input())
s = s + '0'

e = 1
l = []
for i in range(len(s)-1):
    if s[i]==s[i+1]:
        e+=1
    else:
        l.append(e)
        e=1

s = s[:-1]

if len(s)==1:
    print(k//2)    
else:
    if s[0]!=s[-1]:
        print(k*sum([i//2 for i in l]))
    else:
        if k==1:
            print(k*sum([i//2 for i in l]))
        else:
            if len(l)==1:
                print((k*l[0])//2)
            else:
                a = l.pop(0)
                b = l.pop(-1)
                l.append(a+b)
                print((k-1)*sum([i//2 for i in l])+a//2+b//2)

Submission status: Wrong Answer

Solution code:
s = input()
k = int(input())
s = s + '0'

e = 1
l = []
for i in range(len(s)-1):
    if s[i]==s[i+1]:
        e+=1
    else:
        l.append(e)
        e=1

s = s[:-1]

if len(s)==1:
    print(k//2)    
else:
    if s[0]!=s[-1] or k==1 or len(l)==1:
        print(k*sum([i//2 for i in l]))
    else:
        a = l.pop(0)
        b = l.pop(-1)
        l.append(a+b)
        print((k-1)*sum([i//2 for i in l])+a//2+b//2)

Submission status: Wrong Answer

Solution code:
s = input()
k = int(input())
s = s + '0'

e = 1
l = []
for i in range(len(s)-1):
    if s[i]==s[i+1]:
        e+=1
    else:
        l.append(e)
        e=1

if s[0]!=s[-1] or k==1 or len(l)==1:
    print(k*sum([i//2 for i in l]))
else:
    a = l.pop(0)
    b = l.pop(-1)
    l.append(a+b)
    print((k-1)*sum([i//2 for i in l])+a//2+b//2)

Submission status: Wrong Answer

Solution code:
s = input() + "🐧"
k = int(input())

if len(set(s)) == 1:
    print(len(s) * k // 2)
    exit()

wow = 0
yeah = []
for i in range(len(s)-1):
    if s[i] != s[i+1]:
        wow += 1
        yeah.append((s[i], wow))
        wow = 0
    else:
        wow += 1

ans = sum(c // 2 for _, c in yeah) * k

if s[0] == s[-2]:
    katakuna = yeah[0][1]
    ijippari = yeah[-1][1]
    te = katakuna // 2 + ijippari // 2 - (katakuna + ijippari) // 2
    ans -= te * (k - 1)

print(ans)

Submission status: Wrong Answer

Solution code:
s = input() + "🐧"
k = int(input())

if len(set(s)) == 1:
    print(len(s) * k // 2)
    exit()

wow = 0
yeah = []
for i in range(len(s)-1):
    if s[i] != s[i+1]:
        wow += 1
        yeah.append((s[i], wow))
        wow = 0
    else:
        wow += 1

ans = sum(c // 2 for _, c in yeah) * k

if s[0] == s[-2]:
    katakuna = yeah[0][1]
    ijippari = yeah[-1][1]
    te = katakuna // 2 + ijippari // 2 - (katakuna + ijippari) // 2
    print(ans, te)
    ans -= te * (k - 1)

print(ans)

Submission status: Wrong Answer

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

from itertools import groupby

n=len(s)
cnt =0

gp = groupby(s)

Keys=[]
values=[]
for key,value in gp:
    Keys.append(key)
    values.append(len(list(value)))

for i in values:
    if i>1:
        cnt += k*(i//2)
    
if Keys[0]==Keys[-1] and values[0] + values[-1] ==2 and k>1:
    cnt+=(k-1)

print(cnt)

Submission status: Wrong Answer

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

before = string[0]
flg = False
cnt = 0
if string.count(before) == len(string):
    print(len(string) * k // 2)
    exit()
for s in string[1:]:
    if s == before and not flg:
        cnt += 1
        flg = True
        continue
    flg = False
    before = s
ans = cnt * k
if string[0] == string[-1] and not flg:
    ans += k - 1
print(ans)

Submission status: Wrong Answer

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

before = string[0]
flg = False
cnt = 0
for s in string[1:]:
    if s == before and not flg:
        cnt += 1
        flg = True
        continue
    flg = False
    before = s
ans = cnt * k
if string[0] == string[-1] and not flg:
    ans += k - 1
print(ans)

Submission status: Wrong Answer

Solution code:
def hoge(s):
  c = 0
  v = 1
  mae = ''
  for q in s:
    if q == mae:
      v += 1
    else:
      c += v//2
      v = 1
      mae = q
  c += v//2
  return c

s = input()
k = int(input())
t = s*2
a = hoge(s)
a2 = hoge(t)
r = a2 - a*2
print(a*k+r*(k-1))

Submission status: Wrong Answer

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

cnt = 0
if K == 1:
    i = 1
    while True:
        if i + 1 >= len(S):
            break
        if S[i] == S[i+1]:
            cnt += 1
            i += 2
        else:
            i += 1

elif K >= 2:

    if S[0] == S[-1]:
        cnt += 1
    i = 1
    while True:
        if i + 1 >= len(S):
            break
        if S[i] == S[i+1]:
            cnt += 1
            i += 2
        else:
            i += 1


print(cnt * K)

Submission status: Wrong Answer

Solution code:
S=input()
a=0
b=0
for i in range(len(S)-1):
  if S[i]==S[i+1]:
    a+=1
  else:
    b+=(a+1)//2
    a=0
k=int(input())
print((b+a//2+1)*k-1 if S[-1]==S[0] else (b+a//2)*k)

Submission status: Wrong Answer

Solution code:
S=input()
a=0
b=0
for i in range(len(S)-1):
  if S[i]==S[i+1]:
    a+=1
  else:
    b+=a//2
    a=0
if S[-1]==S[0]:
  b+=(a+1)//2
else:
  b+=a//2
print(b*int(input()))

Submission status: Wrong Answer

Solution code:
s = input() + "♡"
k = int(input())

def love_so_sweet():
    wow = 0
    for i in range(len(s)-1):
        if s[i] != s[i+1]:
            wow += 1
            yield wow // 2
            wow = 0
        else:
            wow += 1


print(sum(love_so_sweet()) * k)

Submission status: Wrong Answer

Solution code:
s = input()
k = int(input())
ss = s + s[0]
skip = 0
ans = 0
last = 0
for i in range(1,len(ss)):
    if skip == 1:
        skip = 0
        continue
    elif ss[i-1] == ss[i]:
        ans += 1
        skip = 1
        if i == len(ss)-1:
            last = 1
print(ans*k-last)

Submission status: Wrong Answer

Solution code:
s = input()
k = int(input())
ans = 0
s=s+s
s = list(s)
for i in range(len(s)-1):
    if s[i] == s[i+1]:
        ans += 1
        s[i+1] = "/"
if s[0] == s[-1]:
    ans += 1
r = ans*(k//2)
if k %2:
    r += ans//2
print(r)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
s = input()
k = int(input())
ans = 0
i = 1

#同じ文字列が二つ続いている部分が何箇所あるか探す
while i < len(s):
    if s[i-1] == s[i]:
        ans += 1
        i += 2
    else:
        i += 1

print(ans*k)

Submission status: Wrong Answer

Solution code:
s=input()
k=int(input())
cnt=1
l=[]
for i in range(1,len(s)):
    if s[i]==s[i-1]:
        cnt+=1
    else:
        l.append(cnt)
        cnt=1
l.append(cnt)
loop=0
ans=0
x=0
if s[0]!=s[-1]:
    for i in l:
        ans+=i//2
else:
    for i in range(1,len(l)-1):
        ans+=l[i]//2
        loop=(l[0]+l[-1])//2
    if len(l)==1:
        ans+=l[0]//2
    else:
        x=l[0]//2+l[-1]//2
print(ans*k+loop*(k-1)+x)

Submission status: Wrong Answer

Solution code:
s=input()
k=int(input())
cnt=1
l=[]
for i in range(1,len(s)):
    if s[i]==s[i-1]:
        cnt+=1
    else:
        l.append(cnt)
        cnt=1
l.append(cnt)
loop=0
ans=0
x=0
if s[0]!=s[-1]:
    for i in l:
        ans+=i//2
else:
    for i in range(1,len(l)-1):
        ans+=l[i]//2
        loop=(l[0]+l[-1])//2
    x=l[0]//2+l[-1]//2
print(ans*k+loop*(k-1)+x)

Submission status: Wrong Answer

Solution code:
s=input()
k=int(input())
cnt=1
l=[]
for i in range(1,len(s)):
    if s[i]==s[i-1]:
        cnt+=1
    else:
        l.append(cnt)
        cnt=1
l.append(cnt)
loop=0
ans=0
x=0
if s[0]!=s[-1]:
    for i in l:
        ans+=i//2
else:
    for i in range(1,len(l)-1):
        ans+=l[i]//2
        loop=(l[0]+l[-1])//2
        x=l[0]//2+l[-1]//2
print(ans*k+loop*(k-1)+x)

Submission status: Wrong Answer

Solution code:
s=input()
k=int(input())
cnt=1
l=[]
for i in range(1,len(s)):
    if s[i]==s[i-1]:
        cnt+=1
    else:
        l.append(cnt)
        cnt=1
l.append(cnt)
loop=0
ans=0
x=0
if s[0]!=s[-1]:
    for i in l:
        ans+=i//2
else:
    for i in range(1,len(l)-1):
        ans+=l[i]
        loop=(l[0]+l[-1])//2
        x=l[0]//2+l[-1]//2
print(ans*k+loop*(k-1)+x)

Submission status: Wrong Answer

Solution code:
s=input()
k=int(input())
cnt=1
l=[]
for i in range(1,len(s)):
    if s[i]==s[i-1]:
        cnt+=1
    else:
        l.append(cnt)
        cnt=1
l.append(cnt)
loop=0
ans=0
if s[0]!=s[-1]:
    for i in l:
        ans+=i//2
else:
    for i in range(1,len(l)-1):
        ans+=l[i]
        loop=(l[0]+l[-1])//2
print(ans*k+loop*(k-1))