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())
ans = 0
i= 1

while i < len(S)-1:
    if S[i-1] == S[i]:
        ans += 1
        i += 1
    i+=1
if K != 1:
    if S[0] == S[len(S)-1]: ans += 1

ans *= K

print(ans)

Submission status: Wrong Answer

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

first = S[0]
ans = 0
pre = first

for i in S[1:]:
    if pre == i:
        ans += 1
        i = "1"
    pre = i
ans_e = 1 if first == ans else 0
print((ans+ans_e)*K - ans_e)

Submission status: Wrong Answer

Solution code:
# coding:utf-8

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

if(len(s) == 1 and k > 1):
    print( int(k / 2) )
elif(len(s) == 1 and k == 1):
    print(0)
else:
    chenge_count = 0
    count_tmp = 0
    for i in range(1, len(s)):
        if( s[i] == s[i-1] ):
            count_tmp += 1
        elif(s[i] != s[i-1]):
            count_tmp += 1
            chenge_count += int(count_tmp / 2)
            count_tmp = 0
    if(s[0] == s[-1]):
        chenge_count += 1
    print(chenge_count * k)

Submission status: Wrong Answer

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

s.append(s[0])
ans=0

last=False
for n in range(len(s)-1):

	if s[n]==s[n+1]:
		if not last:
			ans+=1
			last=True

	else:
		last=False


print(ans*k)

Submission status: Wrong Answer

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

import numpy as np
s = input()
k = ii()

s = list(s)
cnt = 0
for i in range(len(s)):
    if i < len(s)-1:
        if s[i] == s[i+1]:
            s[i+1] = '?'
            cnt += 1

if s[0] == s[-1]:
    print(cnt*k + k-1)
else:
    print(cnt*k)

Submission status: Wrong Answer

Solution code:
s = list(x for x in input())
s2 = s + s
count = 0
count2 = 0
k = int(input())

for i in range(len(s)-1):
  if s[i] == s[i+1]:
    s[i+1] = 0
    count += 1
for i in range(len(s2)-1):
  if s2[i] == s2[i+1]:
    s2[i+1] = 0
    count2 += 1
if len(s) == 1:
  print(k//2)
else:
  print((count2-count)*(k-1) + count)

Submission status: Wrong Answer

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

mycnt = 0
myflag = 0

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

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

    print(mycnt)

Submission status: Wrong Answer

Solution code:
S = input()
K = int(input())
i = 0
ans = 0
while i<len(S)-1:
  if (S[i]==S[i+1]):
    ans += 1
    i+=2
  else:
    i += 1
    
print(ans*K)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.buffer.readline
S = list(input())[: -1]
K = int(input())
if len(S) == 1:
  print(K // 2)
  exit(0)
res = 0
a = 0
i = 0
while i < len(S) - 1:
  if S[i] == S[i + 1]:
    res += 1
    if i == len(S) - 2:
      a -= 1
    i += 1
  i += 1
if S[0] == S[-1]: 
  a += 1
print(res * K + max(a, 0) * (K - 1))

Submission status: Wrong Answer

Solution code:
s=input()
k=int(input())
co=0
ju=True
end=False

for i in range(len(s)-1):
    if s[i+1]==s[i] and ju:
        co+=1
        ju = False
    else:
        ju=True

if s[0]==s[-1]:
    tempf=0
    tempr=0
    for i in range(len(s)-1):
        if s[i+1]==s[i]:
            tempf+=1
        else:
            break
    for i in range(len(s)-1):
        if s[-i-1]==s[-i-2]:
            tempr+=1
        else:
            break
    if tempf%2==0 and tempr%2==0:
        end=True

ans=co*k
if end:
    ans+=k-1

print(ans)

Submission status: Wrong Answer

Solution code:
S = input()
K = int(input())
brob = 0
temp = 1
for i in range(len(S)-1):
    if S[i] == S[i+1]:
        temp += 1
    else:
        brob += temp // 2
        temp = 1
        
brob += temp // 2

if K == 1:
    print(brob)
else:
    if len(S) == 1:
        print(K // 2)
    elif S[-1] != S[0]:
        print(brob * K)
    elif S[-2] == S[0] or S[1] == S[-1]:
        print(brob * K)
    else:
        print(brob * K + 1)

Submission status: Wrong Answer

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

leng = len(s)
if(leng==1):
    print(k//2)
    exit()
elif(leng==2):
    if(s[0]==s[1]):
        print(k)
    else:
        print(0)
    exit()

if(s[:-1]==s[1:]):
    print(leng*k//2)
    exit()

ct = 0
for i in range(1,leng):
    if(s[i-1]==s[i]):
        s = s[:i] + '?' + s[i+1:]
        ct += 1

ans = ct*k
if(s[0]==s[leng-1]):
    ans += k-1

print(ans)

Submission status: Wrong Answer

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

if len(S)==1:
    print(len(S)*K//2)
elif K==1:
    i=0
    count=0
    while i<len(S)-1:
        if S[i]==S[i+1]:
            count+=1
            i+=2
        else:
            i+=1
    print(count)
else:
    i=0
    count=0
    while i<len(S):
        if i==len(S)-1:
            if S[i]==S[0]:
                count+=1
            i+=1
        elif S[i]==S[i+1]:
                count+=1
                i+=2
        else:
            i+=1
    print(count*K)

Submission status: Wrong Answer

Solution code:
S = input()
N = int(input())
c = 0
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
c = c*N
if S[0]==S[-1]:
  c+=(N-1)
print(c)

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:-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[-2] and s_[0][1] == s_[-1][1]):
		ct += k-1
	if(len(s)-1 == 2):
		ct -= 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 = input()
K = int(input())

def count(string):
    total = 0
    i = 1
    while i < len(string):
        if string[i-1] == string[i]:
            total += 1
            if i+1 < len(string) and string[i+1] == string[i]:
                i += 1
        i += 1
    return total

if len(set(S)) == 1:
    res = (K * len(S)) // 2      
elif S[0] == S[-1]:
    new = S.strip(S[0])
    res = K * (count(new) + (len(S) - len(new)) // 2)
else:
    res = K * count(S)

print(res)

Submission status: Wrong Answer

Solution code:
a=list(input())
b=int(input())
if len(a)==1:
  print(b//2)
else:
  ans1=0
  ans2=0
  for i in range(1,len(a)):
    if a[i]==a[i-1]:
      ans1+=1
      a[i]=str(i%10)
  if a[-1]==a[0]:
      ans2+=1
      a[0]=str(0)
  if ans1==0:
    print(ans2*(b-1))
  else:
    print(ans1*b)

Submission status: Wrong Answer

Solution code:
from itertools import groupby
s = list(input())
k = int(input())

G = []
for key, group in groupby(s):
    G += [list(group)]
count = 0
if len(s)==1:
    print(k//2)

elif s[0]!=s[-1]:
    for g in G:
        count += len(g)//2
    print(count*k)
else:
    d = len(G[0])//2+len(G[-1])//2-len(G[0]+G[-1])//2
    for g in G:
        count += len(g)//2
    print(count*k + d*(k-1))

Submission status: Wrong Answer

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

cnt = 0
last = 0
for i, s in enumerate(S):
    if S[(i + 1) % len(S)] == S[(i + 2) % len(S)] == s:
        S[(i + 1) % len(S)] = '_'
        cnt += 1
    elif S[(i + 1) % len(S)] == s:
        S[i] = '_'
        cnt += 1
        if i == len(S) - 1:
            last = 1

if len(S) == 1:
    print(K//2)
else:
    print(cnt * K - last)

Submission status: Wrong Answer

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


if __name__ == "__main__":
    resolve()

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())
    a1 = f(S)
    a2 = f(S*2)
    ans = K * a1
    if a1*2 != a2:
        ans += K-1
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

leng = len(s)
if(leng==1):
    print(k//2)
    exit()
elif(leng==2):
    if(s[0]==s[1]):
        print(k)
    else:
        print(0)
    exit()

if(s[:-1]==s[1:]):
    print(leng*k//2)

ct = 0
for i in range(1,leng):
    if(s[i-1]==s[i]):
        s = s[:i] + '?' + s[i+1:]
        ct += 1

ans = ct*k
if(s[0]==s[leng-1]):
    ans += k-1

print(ans)

Submission status: Wrong Answer

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



new_s = s + "#"
n = len(new_s)
i = 0
j = 1
cnt = 1
ans = 0
while True:
    if j >= n:
        break
    if new_s[i] == new_s[j]:
        cnt += 1
        j += 1
        continue
    if new_s[i] != new_s[j]:
        ans += cnt // 2
        cnt = 1
        i = j
        j = i + 1

t = 2*s + "#"
n = len(t)
i = 0
j = 1
cnt = 1
ans2 = 0
while True:
    if j >= n:
        break
    if t[i] == t[j]:
        cnt += 1
        j += 1
        continue
    if t[i] != t[j]:
        ans2 += cnt // 2
        cnt = 1
        i = j
        j = i + 1

tmp = ans2 - ans
print(tmp*(k-1)+ans)

Submission status: Wrong Answer

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

leng = len(S)
result = 0
flg = 0

for i in range(1,len(S)):
    #print(i)
    #print(S)
    if S[i] == S[i-1]:
        #print("change")
        result = result + 1
        S = S[:i] + '.' + S[i+1:]

#print(S)

if S[0] == S[leng-1]:
    result = result + 1
    flg = 1

result = result * K
if flg == 1:
    result = result - 1
#print("result")
print(result)



#0 0 10 10 10 23

Submission status: Wrong Answer

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

x = 0
i = 0
while i < len(s) - 1:
    if s[i] == s[i + 1]:
        x += 1
        i += 2
    else:
        i += 1


ss = s + s
xx = 0
i = 0
while i < len(ss) - 1:
    if ss[i] == ss[i + 1]:
        xx += 1
        i += 2
    else:
        i += 1
ans = k // 2 * xx + (x if k % 2 == 1 else 0)

ans = x + (xx - x) * (k - 1)

print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
from heapq import heappush, heappop, heapreplace

alpha = set(chr(i) for i in range(97,123))
def solve():
    S = input()
    l = len(S)
    K = int(input())
    SK = S*min(3,K)
    s1 = s2 = s3 = ''
    swap_count = [0,0,0]
    for i,s in enumerate(SK+'--', start=-2):
        if s3:
            s1, s2, s3 = s2, s3, s
        elif s2:
            s3 = s
        elif s1:
            s2 = s
        else:
            s1 = s

        if s3 and len({s1,s2})==1:
            s2 = (alpha - {s1,s3}).pop()
            swap_count[i//l] += 1

    res = sum(swap_count) + max(0, K-3)*swap_count[1]
    return str(res)
    

if __name__ == '__main__':
    print(solve())

Submission status: Wrong Answer

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

i = 0
n = len(S)
count = 0
while i < n - 1:
    if S[i] == S[i + 1]: #次のやつと連続の時
        count += 1
        i += 2
    else:
        i += 1

tmp1 = count
if K == 1:
    print (count)
    exit()

while i < 2 * n - 1:
    if S[i - n] == S[i + 1 - n]: #次のやつと連続の時
        count += 1
        i += 2
    else:
        i += 1

tmp2 = 0
if i == 2 * n:
    pass
else:
    if S[0] == S[-1]:
        tmp2 = 1

if K % 2 == 0:
    print (count * (K // 2) + tmp2 * ((K + 1) // 2 - 1))
else:
    print (count * (K // 2) + tmp1 + tmp2 * ((K + 1) // 2 - 1))

Submission status: Wrong Answer

Solution code:
s = raw_input()
t = raw_input()
c = 0
for i in range(len(s)-1):
  if s[i] == s[i+1]:
    c += 1
print(int(t)*c)

Submission status: Wrong Answer

Solution code:
s = input()
k = int(input())
cnt = 0
cntw = 0
i = 0
while True:
    if len(s)-1 < i:
        break
    if len(s)-1 == i:
        if s[i] == s[0]:
            cntw = 1
    elif s[i] == s[i+1]:
        cnt+= 1
        i += 1
    i += 1

ans = cnt*k+cntw*(k-1)
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
def input():
    return sys.stdin.readline()[:-1]
inf=float("inf")
s=input()
k=int(input())
cnt=0
tmp=0
flag=0

for i in range(len(s)):
    if s[0]==s[i]:
        flag+=1
if flag==len(s):
    print(len(s)*k//2)
    quit()

for i in range(len(s)-1):
    if s[i]==s[i+1]:
        tmp+=1
    else:
        cnt+=(tmp+1)//2
        tmp=0
cnt+=(tmp+1)//2
hoka=0
# print(cnt)
if s[0]==s[-1]:
    if s[0]!=s[1] and s[-1]!=s[-2]:
        hoka+=1

print(cnt*k+hoka*(k-1))

Submission status: Wrong Answer

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

ans = 0
now = 0
flag = True

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

for i in range(len(s)):
    #print(i,now)
    if now >= len(s) - 1:
        break
    if s[now] == s[now+1]:
       ans += 1
       now += 2
       if now+1 == len(s) -1:
           flag = False
    else:
        now += 1

if flag == True:
    if s[i] == s[-1]:
        flag = True
    else:
        flag = False

#print(flag)
if len(s) == 2:
    print(ans*k)
else:
    print(ans*k+flag*(k-1))
#print(ans,ans*k,ans*k+flag*(k-1))

Submission status: Wrong Answer

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

if len(S) == 1:
    print(K//2)
    exit()
minus = 0
if len(S) >= 3 and S[0] == S[1] == S[-1]:
    if S[0] != S[2]:
        minus = 1
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) - minus * (K-1))

Submission status: Wrong Answer

Solution code:
import math as m

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


#S = 'iii'
#K = 4

change = 0

# odd_ptn
c_odd = 0
sl = list(S)
for i in range(len(sl)):
    if i == len(sl)-1:
        continue
    if sl[i] == sl[i+1]:
        c_odd = c_odd + 1
        sl[i+1] = '8'


# even_ptn

c_even = 0
sl = list(S)

for i in range(len(sl)):
    if i == 0 and sl[0] == sl[-1]:
        c_even = c_even + 1
        sl[0] = '8'
    elif i == len(sl)-1:
        continue
    elif sl[i] == sl[i+1] :
        c_even = c_even + 1
        sl[i+1] = '8'

print(m.floor((K+1)/2) * c_odd + m.floor(K/2) * c_even)

Submission status: Wrong Answer

Solution code:
S = input()
K = int(input())
S_0 = [i for i in S]
S_1 = S_0+S_0
ans_0 = 0
tmp = S_0[0]
for i in range(1,len(S_0)):
    if S_0[i] == tmp:
        S_0[i] = "0"
        ans_0 += 1
    tmp = S_0[i]
ans_1 = 0
tmp = S_1[0]
for i in range(1,len(S_1)):
    if S_1[i] == tmp:
        S_1[i] = "0"
        ans_1 += 1
    tmp = S_1[i]
ans = ans_0 + (ans_1 - ans_0)*(K-1)
print(ans)

Submission status: Wrong Answer

Solution code:

S = list(input())
K = int(input())
N = len(S)

import sys

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

if S[0] == S[-1]:
    
    cnt = 1
    m = 0
    flag = True
    tmpcnt1 = 0
    for i in range(N-1):
        if S[i+1] == S[i]:
            cnt += 1
        else:
            if flag:
                tmpcnt1 = cnt
                flag = False
                cnt = 1
            else:
                m += cnt//2
                cnt = 1
    ans = 0
    ans += m*K
    ans += (tmpcnt1 + cnt)//2 *(K-1)
    ans += tmpcnt1//2
    ans += cnt//2
    
    print(ans)
        
else:
    cnt = 1
    m = 0
    for i in range(N-1):
        if S[i+1] == S[i]:
            cnt += 1
        else:
            m += cnt//2
            cnt = 1
    m += cnt//2
    print(m*K)

Submission status: Wrong Answer

Solution code:
s = list(input().strip())
t = int(input())
ans = 0
change = False
last = False
for i in range(1, len(s)):
    if change == True:  # 変更直後は必ず通る
        change = False
        continue
    if s[i] == s[i - 1]:  # 変更する
        ans += 1
        change = True
# 最初と最後が同じ文字かつ、最後を変更していない場合
if change == False and s[0] == s[-1]:
    ans += 1
    last = True
# 最後の一回は最後の文字を変更する必要ない
if last == True:
    print(ans * t - 1)
else:
    print(ans*t)

Submission status: Wrong Answer

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

same = 1
for i in range(1, len(s)):
    if s[i-1] == s[i]:
        same += 1
    else:
        break

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

re_same = 1
for i in range(len(s)-2, -1, -1):
    if s[i+1] == s[i]:
        re_same += 1
    else:
        break


f = 0
count = 0
for i in range(1, len(s)):
    if f == 1:
        f = 0
        continue

    if s[i-1] == s[i]:
        f = 1
        count += 1

print(count)

if (re_same + same) % 2 == 0 and s[0] == s[len(s)-1]:
    print(count*k + k - 1)
else:
    print(count*k)

Submission status: Wrong Answer

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

cnt,ans=0,0
for i in range(1,len(S)):
  if S[i-1]==S[i]:
    cnt+=1
  else:
    cnt+=1
    ans+=cnt//2
    cnt=0
if S[0]==S[-1]:
  print(ans*k+k)
else:
  print(ans*k)

Submission status: Wrong Answer

Solution code:
s = list(input())
k = int(input())
n = len(s) - 1
count = 1
output = 0
last = 0
tmp = 0

for i in range(n):
    if s[i] == s[i + 1]:
        count += 1

    if s[i] != s[i + 1]:
        output += count // 2
        count = 1

if s[0] == s[-1]:
    for i in range(n):
        if i == s[0]:
            count += 1
            tmp = i + 1
            break

output += count // 2
count = 1

for i in range(tmp, n):
    if s[i] == s[i + 1]:
        count += 1

    if s[i] != s[i + 1]:
        last += count // 2
        count = 1

last += count // 2

print(output * (k - 1) + last)

Submission status: Wrong Answer

Solution code:
s=list(str(input()))
n=int(input())

i0 = s[0]
count = 0
if len(s) == 1:
    ans = n//2
else:
    for i, name in enumerate(s[1:]):
        if name == i0:
            i0 = -1
            count += 1
            s[i+1] = i0
        else:
            i0 = name
    if s[0] == s[-1]:
        al = n-1
    else:
        al = 0
    ans = count*n + al
print(ans)

Submission status: Wrong Answer

Solution code:
S=input()
K=int(input())
total=0
count=0
flag=0
ss=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:
        if flag==0:
            ss=count+1
        flag=1
        count+=1
        total+=count//2
        count=0
    #print(count,total)

if flag==0:
    print((len(S)*K)//2)
    exit(0)


count+=1
if S[len(S)-1]==S[0]:
    count+=1
total+=count//2
if count%2==0:
    print(total*K-1)
else:
    print(total*K)

Submission status: Wrong Answer

Solution code:
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    S=ST()
    K=I()
    T=S*2
    before = ""
    RLE = []
    for t in T:
        if before != t:
            RLE.append(1)
            before = t
        else:
            RLE[-1]+=1
    cnt=0
    for x in RLE:
        cnt+=x//2

    RLE = []
    before = ""
    for t in S:
        if before != t:
            RLE.append(1)
            before = t
        else:
            RLE[-1]+=1

    cnt2 = 0    
    for x in RLE:
        cnt2+=x//2

    cnt3 = cnt - cnt2*2

    ans=cnt2*K + cnt3*(K-1)

    print(ans)
    

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
st = input()
s = [i for i in st]
k = int(input())
l = len(s)
c=0
i=0
while i<l-1:
    if i+1 <=l-1 and s[i]==s[i+1]:
        s[i+1]='|'
        c+=1
        i+=1
    else:
        i+=1
c*=k
if k>0:
    a = s[0]
    if a==s[-1]:
        c+=k
print(c)

Submission status: Wrong Answer

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

count = 0
xi = 0

if len(s) == 1:
    print(int(k//2))
else:
    for i in range(len(s)-1):
        if s[i] == s[i+1]:
            count += 1
            p = i % 10
            s[i+1] = str(p)

    if s[0] == s[-1]:
        xi= 1
        p = i % 10
        s[-1] = str(p)

    print(int(count*k+xi*(k-1)))

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 t in T:
        if old == "":
            old = t
        else:
            if old == t:
                ans+=1
                old = ""
            else:
                old = t
    if K%2 == 0:
        print(ans*(K//2))
    else:
        ans2 = 0
        old = ""
        for i in range(len(S)):
            if i == 0:
                if len(S) > 1 and S[0] == S[-1] and S[-1] != S[-2]:
                    old = ""
                    ans2+=1
                else:
                    old = S[i]
            elif old == "":
                old = S[i]
            else:
                if old == S[i]:
                    ans2+=1
                    old = ""
                else:
                    old = S[i]
        print(ans*(K//2) + ans2)

Submission status: Wrong Answer

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

Count = []
c = []
pre = ''
for s in S:
  if s != pre:
    if len(c) != 0:
      Count.append(c)
    c = [s,1]
    pre = s
  else:
    c[1] += 1
if len(c) != 0:
  Count.append(c)
#print(Count)
if len(Count) == 1:
  ans = Count[0][1]*K//2
else:
  ans = 0
  for i in range(len(Count)):
    ans += Count[i][1]//2
  ans *= K
print(ans)

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
    
#    print(x)
    if s[0]!=s[-1]:
        y=[len(list(v))//2 for k,v in groupby(s)]
        print(sum(y)*k)
    else:
        x=[len(list(v))//2 for k,v in groupby(s)]
        #print(x)
        if len(x)!=1:
            ans+=x[0]+x[-1]
#            print(ans)
            ans+=sum(x[1:-1])*k
#            print(ans)
            ans+=(k-1)*(x[0]+x[-1])
            print(ans)
        else:
            print(len(s)*k//2)
        
    


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

#S = 'cooooooooonteeeeeeeeeest'
#K = 999993333

result = 0

# S内の重複
dup_c = 0
c_list = ['XXXXX']
for s in S:
    if c_list[0] == s:
        dup_c += 1
        c_list = ['XXXXX']
    else:
        c_list[0] = s
result = dup_c * K

# 間の重複
if len(S) > 1:
    if S[0] == S[len(S)-1]:
        if S[1] != S[0] and S[len(S)-2] != S[0]:
            result += K

print(result)

Submission status: Wrong Answer

Solution code:
s_list = list(input())
k = int(input())
s_len_list = []
dbls_len_list = []
dbls_list = s_list * 2
temp_len = 1
ans = 0

for i in range(len(s_list)-1):
    if s_list[i+1] == s_list[i]:
        temp_len += 1
    else:
        s_len_list.append(temp_len)
        temp_len = 1
s_len_list.append(temp_len)

temp_len = 1
for i in range(len(dbls_list)-1):
    if dbls_list[i+1] == dbls_list[i]:
        temp_len += 1
    else:
        dbls_len_list.append(temp_len)
        temp_len = 1
dbls_len_list.append(temp_len)
# print(s_list)
# print(s_len_list)
# print(dbls_list)
# print(dbls_len_list)
for i in s_len_list:
    ans += i // 2
ans *= k
# if s_len_list[len(s_len_list)-1] // 2 == dbls_len_list[len(s_len_list)-1] // 2 :
#     for i in s_len_list:
#         ans += i // 2
#     ans *= k
# else:
#     for i in s_len_list:
#         ans += i // 2
#     ans *= k
#     ans += (dbls_len_list[len(s_len_list)-1] // 2 - s_len_list[len(s_len_list)-1] // 2)*(k-1)
print(ans)

Submission status: Wrong Answer

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

n=len(s)
ss=s+s
nn=len(ss)
tmps=1
cnts=0
tmpss=1
cntss=0

for i in range(n-1):
    if s[i]==s[i+1]:
        tmps+=1
    else:
        cnts+=(tmps//2)
        tmps=1
cnts+=(tmps//2)

for i in range(nn-1):
    if ss[i]==ss[i+1]:
        tmpss+=1
    else:
        cntss+=(tmpss//2)
        tmpss=1
cntss+=(tmpss//2)

if n==1:
    if k%2==0:
        print(k//2)
    else:
        print((k-1)//2)
else:
    print((cntss-cnts)*(k-1)+cnts)

Submission status: Wrong Answer

Solution code:
S = list(input())
K = int(input())
ans = 0
if len(S) == 1:
  print(K//2);exit()
elif len(S) == 2:
  if S[0] ==  S[1]:
    ans += 1
else:
  for i in range(0,len(S)-2,1):
    s = S[i:i+3]
    if s[0] == s[1] and s[1] == s[2]:
      ans += 1
      S[i+1] = "0"
    elif s[0] == s[1]:
      ans += 1
      S[i+1] = "0"
    elif s[1] == s[2]:
      ans += 1
      S[i+2] = "0"
print(ans*K)

Submission status: Wrong Answer

Solution code:
s=input()
k=int(input())
if len(s)==1:
  print(k//2)
else:
  ans=0
  chg=0
  for i in range(1,len(s)):
    if chg==0 and s[i-1]==s[i]:
      ans+=1
      chg=1
    else:
      chg=0
  ans2=1
  chg2=1
  for i in range(1,len(s)):
    if chg2==0 and s[i-1]==s[i]:
      ans2+=1
      chg2=1
    else:
      chg2=0
  if s[0]!=s[-1] or chg==1:
    print(k*ans)
  else:
    if s[0]==s[1]:
      print(k*ans2)
    else:
      print((k-1)*ans2+ans)

Submission status: Wrong Answer

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

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

flag = False
if s[0] == s[-1]:
#    print("flag")
    flag = True
else:
    pass

#sの中だけ考える
count = 0
dp = ""
for i in range(len(s)):
    if dp == s[i]:
        count += 1
        dp = ""
    else:
        dp = s[i]
ans = count * k


if flag:
    try:
        #もし後ろ３つが同じなら
#        print("here")
        if len(set([s[-1],s[-2],s[-3]])) == 1:
            ans = ans + (k-1)
    except IndexError:
        pass
else:
    pass

print(ans)

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]='0'
        count+=1
ans=count*k
if s[-1]== s[0]: ans+=k-1
if len(s)==1: 
    print(k//2)
else:print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
S = str(input())
K = int(input())

if len(S) == 1:
    print(K // 2)
else:
    before_s = ""
    dup_list = []
    dup_num = 0
    for s in S:
        if s == before_s:
            dup_num += 1
            if dup_num == 1:
                dup_list.append(dup_num)
            else:
                dup_list[-1] = dup_num
        else:
            before_s = s
            dup_num = 0
    ans = 0
    for dnum in dup_list:
        ans += (dnum + 1) // 2
    ans *= K
    if S[0] == S[-1] and S[-1] != S[-2]:
        ans += K - 1
    print(ans)

Submission status: Wrong Answer

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

cnt = 0
L = len(S)

if L == 1:
    print(K//2)
    exit()

changed = False
Flg = False
for i in range(L-1):
    if not changed:
        if i == L - 2:
            if S[i] == S[i+1]:
                cnt += 1
                changed = True
            else:
                if K > 1:
                    if S[0] == S[i+1]:
                        cnt += 1
                        changed = True
                        Flg = True
        else:
            if S[i] == S[i+1]:
                cnt += 1
                changed = True
    else:
        changed = False

cnt *= K
if Flg:
    cnt -= 1
print(cnt)