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=list(input())
k=int(input())
if len(s)==1:
    print(k//2)
    exit()
ans=0
f=1
for i in range(len(s)-1):
    if s[i]==s[i+1] and f:
        ans+=1
        f=0
    else:
        f=1
if s[-1]!=s[-2] and s[0]==s[-1]:
    print(ans*k+k-1)
    exit()
if s[0]==s[-1] and f==1:
    print(ans*k+k-1)
    exit()
print(ans*k)

Submission status: Wrong Answer

Solution code:
def main():
    S = input()
    K = int(input())
    a = list(S)
    cnt = 0
    for i in range(len(a)-1):
        if a[i+1] == a[i]:
            a[i+1] = str(i)
            cnt += 1
    cnt *= K
    if a[0] == a[-1]:
        cnt += K-1
    print(cnt)

    
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
S = list(input().rstrip()) # len(S) <= 100
K = int(input())    # K <= 10**9

N = len(S)
cnt = 0
for i in range(N-1):
    if S[i] == S[i+1]:
        #print(S[i], S[i+1])
        S[i+1] = "_"
        cnt += 1

if N == 1:
    print((K-(K%2))//2)
else:
    if S[0] != S[-1]:
        print(cnt*K)
    else:
        print(cnt*K+K-1)

Submission status: Wrong Answer

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

count = 0
for i in range(len(S)-1):
	if S[i] == S[i+1]:
		S[i+1] = '?'
		count += 1


count = count*K

if S[0] == S[-1]:
	if S[-1] == '?':
		count += K-1

print(count)

Submission status: Wrong Answer

Solution code:
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
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 LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

#A
def A():
    s = S()
    k = I()
    n = len(s)
    for i in range(n):
        if s[i] != s[0]:
            break
    else:
        print((k*n)>>1)
        return
    s += s
    s = s[i:i+n]
    ans = 0
    i = 0
    while i < n:
        t = s[i]
        l = 0
        while i < n and t == s[i]:
            i += 1
            l += 1
        ans += l >> 1
    print(ans*k)
    return

#B
def B():

    return

#C
def C():

    return

#D
def D():

    return

#E
def E():

    return

#F
def F():

    return

#Solve
if __name__ == "__main__":
    A()

Submission status: Wrong Answer

Solution code:
def li():
    return list(map(input().split()))


if __name__ == "__main__":
    s = input()
    k = int(input())

    count = 0
    before = ""
    for si in s:
        if before == si:
            count += 1
            before = ""
        else:
            before = si

    is_corner = before == s[0]
    corner_count = k - 1 if is_corner else 0
    print(count * k + corner_count)

Submission status: Wrong Answer

Solution code:
s = input()
k = int(input())
cnt = 0
i = 0
while i < len(s)-1:
  if s[i] == s[i+1]:
    i += 2
    cnt += 1
  else:
    i += 1


print(cnt*k)

Submission status: Wrong Answer

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

if len(S) == 1:
    print(K//2)
    exit()
cons = 0
for i in range(len(S)-1):
    if S[i] == S[i+1]:
        cons += 1
        S[i+1] = '_'
cons2 = int(S[0] == S[-1])
print(cons * K + cons2 * (K-1))

Submission status: Wrong Answer

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

lst = []
ch = ''
cnt = 0
for c in s:
    if c == ch:
        cnt += 1
    else :
        lst.append([ch, cnt])
        ch = c
        cnt = 1
lst.append([ch, cnt])
ans = 0
for ch, cnt in lst:
    ans += cnt // 2
print(ans * k)

Submission status: Wrong Answer

Solution code:
S = list(input())
K = int(input())
now = ""
ans = 0
for i in range(len(S)):
    tmp = S[i]
    if tmp == now:
        ans += 1
        now = ""
    elif i == len(S)-1:
        if tmp == S[0]:
            ans += 1
    else:
        now = S[i]
    
print(ans*K)

Submission status: Wrong Answer

Solution code:
#import numpy as np
#from numpy import*
#from scipy.sparse.csgraph import shortest_path #shortest_path(csgraph=graph) # dijkstra# floyd_warshall
#from scipy.sparse import csr_matrix
 
from collections import* #defaultdict Counter deque appendleft
from fractions import gcd
from functools import* #reduce
from itertools import* #permutations("AB",repeat=2) combinations("AB",2) product("AB",2) groupby accumulate
from operator import mul,itemgetter
from bisect import* #bisect_left bisect_right
from heapq import* #heapify heappop heappushpop
from math import factorial,pi
from copy import deepcopy
import sys
sys.setrecursionlimit(10**8)
#input=sys.stdin.readline  #危険！基本オフにしろ！
 
def main():
    s=input()
    k=int(input())
    ans=0
    x=[len(list(v))//2 for k,v in groupby(s)]
#    print(x)
    if s[0]==s[-1]:
        if not(x[0]>0 or x[-1]>0):
            ans+=k-1
    ans+=sum(x)*k
    print(ans)
    

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

ans = [0] * 2
for i in (0, 1):
    # print("#", ans)
    ans_tmp = 0
    S_tmp = S * (i + 1)
    cnt = 0
    for j, Sj in enumerate(S_tmp):
        if j == 0:
            cnt = 1
        else:
            if Sj == Sj_prev:
                cnt += 1
            else:
                ans_tmp += cnt // 2
                cnt = 1
        #
        Sj_prev = Sj
    else:
        ans_tmp += cnt // 2
    #
    ans[i] = ans_tmp

print(ans[0] + (K - 1) * (ans[1] - ans[0]))

Submission status: Wrong Answer

Solution code:
S = input()
N = int(input())
st = []
c = 0
s = S+S
j = [True]*len(s)
for i in range(0,len(s)-1):
  if s[i]==s[i+1] and j[i]==True:
    #print(i,s[i],s[i+1])
    #print(s)
    j[i+1]=False
    c+=1
print(N*c//2)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

def f(s):
    i = 0
    n = 0
    while i < len(s)-1:
        if s[i] == s[i+1]:
            n += 1
            i += 2
        else:
            i += 1
    return n

def main():
    S = input().strip()
    K = int(input())
    print(K//2 * f(S*2) + K%2 * f(S))

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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


change = 0

sl = list(S)
for i in range(len(sl)-1):
    if sl[i] == sl[i+1]:
        change = change + 1
        sl[i+1] = '8'

change2 = 0
if sl[-1] == sl[0]:
    change2 = 1
print(change*K + change2*(K-1))

Submission status: Wrong Answer

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

def solve():
    S = input()
    K = int(input())
    N = len(S)

    if N == 1:
        if K == 1:
            print(0)
        else:
            print(K//2)
        return

    base = 0
    pre_moji = S[0]
    for i in range(1, N):
        if S[i] == pre_moji:
            base += 1
            pre_moji = "?"
        else:
            pre_moji = S[i]

    if K == 1:
        print(base)
        return

    if pre_moji == S[0]:
        K_base = base + 1
    else:
        K_base = base

    print(base + K_base*(K-1))


if __name__ == "__main__":
    solve()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
#AGC39 A

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

s = input()
k = I()
n = len(s)
res = 0
i = 0
while i < n:
    tmp = s[i]
    i += 1
    cnt = 0
    while i < n and tmp == s[i]:
        cnt += 1
        i += 1
    res += (cnt+1)//2
print(res*k)

Submission status: Wrong Answer

Solution code:
s=list(input())
k=int(input())
count=0
for i in range(1,len(s)):
    if s[i]==s[i-1]:
        s[i]="A"
        count +=1
if s[0]==s[-1] and s[-1]!="A":
    count +=1

print(count*k)

Submission status: Wrong Answer

Solution code:
from heapq import heappush, heappop
from collections import deque,defaultdict,Counter
import itertools
from itertools import permutations,combinations
import sys
import bisect
import string
#import math
#import time
#import random
def I():
    return int(input())
def MI():
    return map(int,input().split())
def LI():
    return [int(i) for i in input().split()]
def LI_():
    return [int(i)-1 for i in input().split()]
def StoI():
    return [ord(i)-97 for i in input()]
def show(*inp,end='\n'):
    if show_flg:
        print(*inp,end=end)
YN=['Yes','No']
mo=10**9+7
#ts=time.time()
#sys.setrecursionlimit(10**6)
#input=sys.stdin.readline
show_flg=False
show_flg=True

a=StoI()
a=a+[a[0]]
k=I()
n=len(a)
p=a[0]
t=0
for i in range(n-1):
    if p==a[i+1]:
        t+=1
        p=-1
    else:
        p=a[i+1]

ans=t*k
if n==2:
    ans=k//2
print(ans)
#show(a,k)

Submission status: Wrong Answer

Solution code:
s = input()
k = int(input())
cnt = 0
streak = 1
for i in range(len(s)-1):
    if s[i + 1] == s[i]:
        streak += 1
    else:
        if streak > 1:
            cnt += streak // 2
        streak = 1
if s[-1] == s[0]:
    cnt += (streak + 1) // 2
else:
    if streak > 1:
        cnt += streak // 2
res = cnt * k
if len(s) > 2:
    if s[-1] == s[0] and s[-1] != s[-2]:
        res -= 1
print(res)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from copy import deepcopy
from sys import exit,setrecursionlimit
import math
from collections import defaultdict,Counter,deque
from fractions import Fraction as frac
import bisect
import sys
input = sys.stdin.readline

setrecursionlimit(1000000)


def main():
	s = input()
	k = int(input())
	s_ = [[s[0],1]]
	ct = 0
	for i in s[1:]:
		if(s_[-1][0] == i):
			s_[-1][1] += 1
		else:
			s_.append([i,1])
	for i in s_:
		if(i[1] > 1):
			ct += math.ceil((i[1] - 1)/2)
	ct *= k
	if(s[0] == s[-1]):
		ct += k-1
	print(ct)


def zip(a):
	mae = a[0]
	ziparray = [mae]
	for i in range(1,len(a)):
		if(mae != a[i]):
			ziparray.append(a[i])
			mae = a[i]
	return ziparray

def is_prime(n):
	if n < 2: return False

	for k in range(2, int(math.sqrt(n)) + 1):
		if n % k == 0:
			return False

	return True

def list_replace(n,f,t):
	return [t if i==f else i for i in n]

def base_10_to_n(X, n):
	X_dumy = X
	out = ''
	while X_dumy>0:
		out = str(X_dumy%n)+out
		X_dumy = int(X_dumy/n)
	if(out == ''): return '0'
	return out

def gcd(l):
	x = l.pop()
	y = l.pop()
	while(x%y!=0):
		z = x%y
		x = y
		y = z
	l.append(min(x,y))
	return gcd(l) if len(l) > 1 else l[0]

class Queue():
	def __init__(self):
		self.q = deque([])
	def push(self,i):
		self.q.append(i)
	def pop(self):
		return self.q.popleft()
	def size(self):
		return len(self.q)
	def debug(self):
		return self.q

class Stack():
	def __init__(self):
		self.q = []
	def push(self,i):
		self.q.append(i)
	def pop(self):
		return self.q.pop()
	def size(self):
		return len(self.q)
	def debug(self):
		return self.q

class graph():
	def __init__(self):
		self.graph = defaultdict(list)
	def addnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].append(t)
		self.graph[t].append(f)
	def rmnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].remove(t)
		self.graph[t].remove(f)
	def linked(self,f):
		return self.graph[f]

class dgraph():
	def __init__(self):
		self.graph = defaultdict(set)
	def addnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].append(t)
	def rmnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].remove(t)
	def linked(self,f):
		return self.graph[f]

main()

Submission status: Wrong Answer

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

singleCnt = 0
for i in range(len(S)-1):
  if S[i] == S[i+1]:
    S[i+1] = "1" # かぶらない文字に変換
    singleCnt +=1
if S[0] == S[-1]:
  ans = singleCnt * K + K - 1
else:
  ans = singleCnt * K
print(ans)

Submission status: Wrong Answer

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

if len(set(s)) == 1:
    print len(s) * k / 2
else:
    n = len(s)
    a = [1]
    for i in xrange(1, n):
        if s[i] == s[i - 1]:
            a[-1] += 1
        else:
            a.append(1)
    ans = 0
    if s[0] == s[-1]:
        ans += a[0] / 2 + a[-1] / 2 + (a[0] + a[1]) / 2 * (k - 1)
        a = a[1:-1]
    ans += sum(x / 2 for x in a) * k
    print ans

Submission status: Wrong Answer

Solution code:
from itertools import groupby
S = input()
K = int(input())
lenS = len(S)
cnt = 0
for key, values in groupby(S):
  len_values = len(list(values)) 
  if len_values >= 2:
    cnt += len_values//2

if key == S[0] and len_values%2==1: cnt += 1
    
print(cnt*K)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict as df
s=input().rstrip()
k=int(input())
count=0
ans=0
s=[i for i in s]
for i in range(1,len(s)):
    if s[i]==s[i-1]:
        s[i]='1'
        count+=1
print(count*k)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

s_2 = s + s

num_first = 0
renzoku = 1
before = 0
for i in range(len(s)):
    now = s[i]
    if now == before:
        renzoku += 1
    else:
        num_first += renzoku // 2
        renzoku = 1
    before = now
num_first += renzoku // 2

num_rest = 0
renzoku = 1
before = 0
for i in range(len(s_2)):
    now = s_2[i]
    if now == before:
        renzoku += 1
    else:
        num_rest += renzoku // 2
        renzoku = 1
    before = now
num_rest += renzoku // 2

num_rest -= num_first

print(num_first + (k-1) * num_rest)

Submission status: Wrong Answer

Solution code:
S = list(input())
K = int(input())
ans = 0
for i in range(1, len(S)):
    if S[i] == S[i - 1]:
        ans += 1
        S[i] = 'AB' [i % 2]
ans *= K
ans += (S[0] == S[-1]) * (K - 1)
print(ans)

Submission status: Wrong Answer

Solution code:
s = input()
k = int(input())
a = s  + s[0]
prev = a[0]
c = 0
for b in list(s)[1:]:
  if b == prev:
    c += 1
    prev = "0"
  prev = b
print(c*k)

Submission status: Wrong Answer

Solution code:
S=input()
K=int(input())
total=0
count=0
if len(S)==1:
    print(K//2)
    exit(0)
for i in range(len(S)-1):
    if S[i]==S[i+1]:
        count+=1
    else:
        count+=1
        total+=count//2
        count=0
    #print(count,total)
count+=1
if S[len(S)-1]==S[0]:
    count+=1
total+=count//2

print(total*K)

Submission status: Wrong Answer

Solution code:
s = input()
k = int(input())
p = s[0]
loop = 0
tmp = 1
first_tmp = 0
for c in s[1:]:
    if c == p:
        tmp += 1
    else:
        loop += tmp // 2
        if first_tmp == 0:
            first_tmp = tmp
        tmp = 1
    p = c
loop += tmp // 2
ans = loop * k
if s[0] == s[-1] and first_tmp % 2 == 1 and tmp % 2 == 1:
    ans += k - 1
print(ans)

Submission status: Wrong Answer

Solution code:

S = input()

K = int(input())

now = 1
ans = 0

for i in range(len(S)-1):

    if S[i+1] == S[i]:
        now += 1

    else:

        ans += now // 2
        now = 1

ans += now // 2



S2 = S + S

now = 1
ans2 = 0
for i in range(len(S2)-1):

    if S2[i+1] == S2[i]:
        now += 1

    else:

        ans2 += now // 2
        now = 1



ans2 += now // 2
sub = ans2 - ans

#print (ans,ans2)


print (ans + sub * (K-1))

Submission status: Wrong Answer

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

count = 0
flag = 0
for i in range(len(s) - 1):
    if flag == 0:
        if s[i] == s[i + 1]:
            count += 1
            flag = 1
    else:
        flag = 0

print(count * k)

Submission status: Wrong Answer

Solution code:
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
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 LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

#A
def A():
    s = S()
    k = I()
    n = len(s)
    for i in range(n):
        if s[i] != s[0]:
            break
    else:
        print((k*n)>>1)
        return
    s += s
    s = s[i:i+n]
    ans = 0
    i = 0
    while i < n-1:
        t = s[i]
        l = 0
        while i < n and t == s[i]:
            i += 1
            l += 1
        ans += l >> 1
    print(ans*k)
    return

#B
def B():

    return

#C
def C():

    return

#D
def D():

    return

#E
def E():

    return

#F
def F():

    return

#Solve
if __name__ == "__main__":
    A()

Submission status: Wrong Answer

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

count=0
end=True
for i in range(1,len(s)):
  if s[i-1]==s[i]:
    s[i]=1
    count+=1
    if i==len(s)-1:
      end=False

if end and s[0]==s[-1]:
  count+=1

print(k*count)

Submission status: Wrong Answer

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

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

print(0)

ans = 0

T = list(S)
b = 0

for i, t in enumerate(T[1:], start=1):
    if t == T[i - 1] and T[i - 1] != '.':
        b += 1
        T[i] = '.'

print(ans + b * K)

Submission status: Wrong Answer

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

idx = 0
res = 0
while idx+1 < len(S):
  if S[idx] == S[idx+1]:
    res += 1
    idx += 2
  else:
    idx += 1
print(res*K)

Submission status: Wrong Answer

Solution code:
s=input()
n=int(input())
c=0
s=list(s)
for i in range(1,len(s)):
  if s[i]==s[i-1]:
    s[i]='12'
    c+=1
# print(s)
# print(c)
print(n*c)

'''
c o o o o o o o o o n t e e e e e e e e e e s t


'''

Submission status: Wrong Answer

Solution code:
#A問題
S = list(str(input()))
K = int(input())

if K == 1:
    ans = 0
    old = ""
    for s in S:
        if old == "":
            old = s
        else:
            if old == s:
                ans+=1
                old = ""
            else:
                old = s
                
    print(ans)
else:
    ans = 0
    old = ""
    T = S+S
    for i in range(len(T)):
        if old == "":
            old = T[i]
        else:
            if old == T[i]:
                ans+=1
                old = ""
            else:
                old = T[i]
        
    if K%2 == 0:
        print(ans*(K//2))
    else:
        ans2 = 0
        old = ""
        for s in S:
            if old == "":
                old = s
            else:
                if old == s:
                    ans2+=1
                    old = ""
                else:
                    old = s
        print(ans*(K//2) + ans2)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
s = [i for i in input()]
t = s
k = int(input())
a = 0
for i in range(0, len(s) - 1):
    if t[i] == t[i + 1]:
        a += 1
        t[i + 1] = "-"
if t[0] == t[-1]:
    b = 1*(len(s)&1)
else:
    b = 0
print(a*k+b*(k-1))

Submission status: Wrong Answer

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

mycnt = 0
myflag = 0

for i in range(len(S)-1):
    if S[i] == S[i+1] and myflag == 0:
        mycnt += 1
        myflag = 1
    else: myflag = 0

print(mycnt * K)

Submission status: Wrong Answer

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

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

ans = 0

T = list(S)
b = 0

for i, t in enumerate(T[1:], start=1):
    if t == T[i - 1] and T[i - 1] != '.':
        b += 1
        T[i] = '.'

print(ans + b * K)

Submission status: Wrong Answer

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

cons = 0
for i in range(len(S)-1):
    if S[i] == S[i+1]:
        cons += 1
        S[i+1] = '_'
cons2 = int(S[0] == S[-1])
print(cons * K + cons2 * (K-1))

Submission status: Wrong Answer

Solution code:
# 入力が10**5とかになったときに100ms程度早い
import sys
read = sys.stdin.readline


def read_ints():
    return list(map(int, read().split()))


def read_a_int():
    return int(read())


def read_matrix(H):
    '''
    H is number of rows
    '''
    return [list(map(int, read().split())) for _ in range(H)]


def read_map(H):
    '''
    H is number of rows
    文字列で与えられた盤面を読み取る用
    '''
    return [read()[:-1] for _ in range(H)]


def read_col(H, n_cols):
    '''
    H is number of rows
    n_cols is number of cols

    A列、B列が与えられるようなとき
    '''
    ret = [[] for _ in range(n_cols)]
    for _ in range(H):
        tmp = list(map(int, read().split()))
        for col in range(n_cols):
            ret[col].append(tmp[col])

    return ret


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

pre = S[0]
first_cnt = 0
for s in S[1:]:
    if s == pre:
        first_cnt += 1
        pre = None
    else:
        pre = s

continuous_cnt = 0
for s in S:
    if s == pre:
        continuous_cnt += 1
        pre = None
    else:
        pre = s

print(first_cnt+continuous_cnt*(K-1))

Submission status: Wrong Answer

Solution code:
S=input()
K=int(input())
count_single=count_double=0
flag=True
for i in range(1, len(S)):
  if not flag:
    flag=True
    continue
  if S[i-1]==S[i]:
    count_single+=1
    flag=False
SS=S+S
flag=True
for i in range(1, len(SS)):
  if not flag:
    flag=True
    continue
  if SS[i-1]==SS[i]:
    count_double+=1
    flag=False
print((K//2)*count_double+(K%2)*count_single)

Submission status: Wrong Answer

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

def main():
    s = list(input().rstrip())
    k = int(input())

    c = 0

    if s[0] == s[-1]:
        s[-1] = '2'
        c += 1

    for i in range(len(s) - 1):
        if s[i] == s[i+1]:
            c += 1
            s[i+1] = '1'

    print(c*k)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

for i in range(1, len(S)):
    if S[i] == S[i-1]:
        ans += 1
        S[i] = str(i)
ans *= K
if S[-1] == S[0]:
    ans += (K-1)
print(ans)

Submission status: Wrong Answer

Solution code:
from heapq import heappush, heappop
from collections import deque,defaultdict,Counter
import itertools
from itertools import permutations,combinations
import sys
import bisect
import string
#import math
#import time
#import random
def I():
    return int(input())
def MI():
    return map(int,input().split())
def LI():
    return [int(i) for i in input().split()]
def LI_():
    return [int(i)-1 for i in input().split()]
def StoI():
    return [ord(i)-97 for i in input()]
def show(*inp,end='\n'):
    if show_flg:
        print(*inp,end=end)
YN=['Yes','No']
mo=10**9+7
#ts=time.time()
#sys.setrecursionlimit(10**6)
#input=sys.stdin.readline
show_flg=False
show_flg=True

a=StoI()
a=a+[a[0]]
k=I()
n=len(a)
p=a[0]
t=0
for i in range(n-1):
    if p==a[i+1]:
        t+=1
        p=-1
    else:
        p=a[i+1]

print(t*k)
#show(a,k)

Submission status: Wrong Answer

Solution code:
s = input()
k = int(input())
c = 0
i = 0
while i<len(s)-1:
    if s[i] == s[i+1]:
        c += 1
        i += 2
    else:
        i += 1
if s[0] == s[-1] and i==len(s)-1:
    c += 1
    print(k*c-1)
else:
    print(k*c)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

flag=[0]*len(ss)
for i in range(1,len(ss)):
    if ss[i-1]==ss[i] and flag[i-1]==0:
        flag[i]=1
        continue

count=sum(flag[0:len(s)])+sum(flag[len(s):2*len(s)])*(k-2)+sum(flag[2*len(s):3*len(s)])
print(count)

Submission status: Wrong Answer

Solution code:
#gcdは3.4.3だとfractionsにある
from fractions import gcd

from math import factorial as f

from math import ceil,floor,sqrt

from sys import exit

from copy import deepcopy
import numpy as np

import bisect
import re


ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))



def main():
    s = input()
    k = ii()
    s = list(s)
    sc = deepcopy(s)

    n = len(s)
    cnt = 0
    for i in range(1,n):
        if sc[i] == sc[i-1]:
            sc[i] = '0'
            cnt+=1
    
    if sc[n-1] == sc[n-2] or sc[0] == sc[n-1]:
        flag = True
    else:
        flag = False

    ans = cnt*k+(flag*(k-1))

    cnt = 0
    for i in range(1,n):
        if s[i] == s[i-1]:
            s[i] = '0'
            cnt+=1
    
    if s[n-1] == s[n-2] or s[0] == s[n-1]:
        flag = True
    else:
        flag = False

    ans = min(ans,cnt*k+(flag*(k-1)))
    print(ans)





main()

Submission status: Wrong Answer

Solution code:
S = list(input().rstrip()) # len(S) <= 100
K = int(input())    # K <= 10**9

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

if S[0] != S[-1]:
    print(cnt*K)
else:
    print(cnt*K+K-1)

Submission status: Wrong Answer

Solution code:
s = input()
k = int(input())
count = 0
for i in range(len(s) - 1):
    if s[i] == s[i + 1]:
        count += 1
        s = s[: i + 1] + "." + s[i + 2 :]
if s[-1] == s[0]:
    flag = 1
else:
    flag = 0

print(count * k + flag * (k - 1))

Submission status: Wrong Answer

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

cnt = 1
ans = 0
cnt2 = 1
flag = True
for i in range(1, len(S)):
  if S[i] == S[i - 1]:
    cnt += 1
    if flag:
      cnt2 += 1
  else:
    ans += cnt // 2
    cnt = 1
    flag = False

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

print(ans)

Submission status: Wrong Answer

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

# はじめに例外処理
if len(S) == 1:
    print(len(S) // 2)
    exit()

# 最後の文字以外をカウント
for si in range(1, len(S) - 1):
    if S[si] == S[si - 1]:
        S = S[: si] + "?" + S[si + 1:]
        ans += 1

# 最後の文字についてカウント
if S[-1] == S[0]:
    ans += 1

print(ans * K)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
# coding: utf-8

line = [x for x in input()]
counter = 0
for i in range(1, len(line)):
    if line[i] == line[i - 1]:
        counter += 1
        line[i] = "."

counter2 = 0
if line[0] == line[-1]:
    counter2 = 1

num = int(input())
print(num * counter + (num - 1) * counter2)

Submission status: Wrong Answer

Solution code:
S=input()
K=int(input())
total=0
count=0
for i in range(len(S)-1):
    if S[i]==S[i+1]:
        count+=1
    else:
        count+=1
        total+=count//2
        count=0
    #print(count,total)
count+=1
if S[len(S)-1]==S[0]:
    count+=1
total+=count//2

print(total*K)

Submission status: Wrong Answer

Solution code:
s=list(input())
k=int(input())
an=0
skip=0

for i in range(len(s)-1):
    if skip==1:
        skip=0
        continue
    
    if s[i]==s[i+1]:
        an+=1
        skip=1

print(an*k)

Submission status: Wrong Answer

Solution code:
from sys import stdin

S = stdin.readline().rstrip()
K = int(stdin.readline().rstrip())
ans = 0
changed = [False] * len(S)

for i in range(1, len(S)):
    if S[i] == S[i - 1] and not changed[i - 1]:
        ans += 1
        changed[i] = True
if S[0] == S[len(S) - 1] and not changed[len(S) - 1]:
    ans += 1

print(ans * K)

Submission status: Wrong Answer

Solution code:
s = [i for i in input()]
t = s
k = int(input())
a = 0
for i in range(0, len(s) - 1):
    if t[i] == t[i + 1]:
        a += 1
        t[i + 1] = "-"
if t[0] == t[-1]:
    b = 1
else:
    b = 0
print(a*k+b*(k-1))

Submission status: Wrong Answer

Solution code:
s = input()
k = int(input())
x = 0
cur = ""
count = 1
for i in range(len(s)):
    #print("i={0}, cur = ".format(i, cur))
    if cur == s[i]:
        count += 1
        #print(" same count = {0}".format(count))
    else:
        x += count // 2
        #print(" change add = {0}".format(count // 2))
        count = 1
    cur = s[i]
if s[0] == s[-1]:
    x += 1
x *= k
print(x)

Submission status: Wrong Answer

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

pre = ""
count = 0
for s in S:
    if s == pre:
        pre = ""
        count += 1
    else:
        pre = s

result = count * K

if S[0] == pre:
    result += (K-1)

print(result)