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:
def count(st):
    n=len(st)
    tmp=1
    res=[]
    for i in range(n-1):
        if st[i]==st[i+1]:
            tmp+=1
        else:
            res.append(tmp)
            tmp=1
    res.append(tmp)
    return res
S=input()
K=int(input())
T=S*3
N=len(S)
if N==1:
    print(K//2)
    exit()
if K<=2:
    Y=count(S*K)
    ans=0
    for i in Y:
        ans+=i//2
    print(ans)
    exit()
X=[]
if S[0]==S[-1]:
    for j in range(1,N):
        if S[j-1]!=S[j]:
            break
    tmp=1
    for i in range(j,j+N-1):
        if T[i]==T[i+1]:
            tmp+=1
        else:
            X.append(tmp)
            tmp=1
    X.append(tmp)
else:
    X=count(S)

cnt=0
for i in X:
    cnt+=i//2
Y=count(T)
cnt2=0
for i in Y:
    cnt2+=i//2
print(cnt*(K-3)+cnt2)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
s = list(input())
k = int(input())
n = len(s)
if n == 1:
    print(k // 2)
    exit()
c = 0
for i in range(n - 1):
    if s[i + 1] == 'X':
        continue
    if s[i] == s[i + 1]:
        s[i + 1] = 'X'
        c += 1
print(c * k + (s[0] == s[-1]) * (k - 1))

Submission status: Wrong Answer

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

box = ""
count=0

for i in S:
  if box == i:
    count += 1
    box = ""
  else:
   	box = i
    
if box == S[0]:
  count += 1
  
print(count*K)

Submission status: Wrong Answer

Solution code:
import sys
readline = sys.stdin.readline
S = [ord(s)-97 for s in readline().strip()]
K = int(readline())
dp = [1]*26
dp[S[0]] = 0
inf = 10**9

for s in S[1:]:
    dp2 = [inf]*26
    for i in range(26):
        for j in range(26):
            if i == j:
                continue
            dp2[i] = min(dp2[i], 1+dp[j])
    
    for j in range(26):
        if s == j:
            continue
        dp2[s] = min(dp2[s], dp[j])
    
    dp = dp2[:]

ans = inf
for i in range(26):
    if i == S[0]:
        continue
    ans = min(ans, dp[i])

print(ans*(K-1) + min(dp))

Submission status: Wrong Answer

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

if len(S) == 1:
    print(K//2)
elif len(set(S)) == 1:
    print(len(S)*K//2)
else:
    c = 0
    flg = False
    for i in range(len(S)-1):
        if S[i] == S[i+1] and flg is False:
            c += 1
            flg = True
        else:
            flg = False

    if flg is False and S[-1] == S[0]:
        j = 1
    else:
        j = 0

    print(c*K+j*(K-1))
    # print(c, j)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
s = input()
k = int(input())
sum_count = 0
count = 1
key = s[0]

for i in range(1,len(s)):
    if s[i] == key:
        count += 1
    else:
        sum_count += count//2
        key = s[i]
        count = 1
sum_count += count//2


print(sum_count*k)

Submission status: Wrong Answer

Solution code:
import sys
import math
stdin = sys.stdin
mod = 10**9 + 7

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
sa = lambda h: [list(map(int, stdin.readline().split())) for i in range(h)]

s = ns()
k = ni()

w = s[0]
a = []
count = 1
for i in s[1:]:
    if w == i:
        count += 1
    else:
        a.append(count)
        count = 1
        w = i
if s.count(s[0]) == len(s):
    ans = len(s) * k // 2
elif w != s[0]:
    ans = 0
    for i in a:
        ans += i // 2
    ans = ans * k
else:
    al = a[0]
    ar = count
    ans = 0
    for i in a[1:]:
        ans += i // 2
    ans = ans * k
    ans += al //2 + ar //2
    ans += (al + ar) * (k -1)//2
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

if len(S_list) == 1:
    print(K//2)
elif len(S_list) == 2:
    if S_list[0]==S_list[1]:
        print(K)
    else:
        print(0)
else:
    count = 0
    flag = False
    s = S_list[0]
    S_list.append(s)
    for i in range(1, len(S_list)):
        if flag == False:
            if s == S_list[i]:
                count += 1
                flag = True
        else:
            flag = False
        s = S_list[i]

    if S_list[-1] == S_list[-2]:
        if S_list[-2] == S_list[-3]:
            print(K*count)
        else:
            print(K*count-1)
    else:
        print(K*count)

Submission status: Wrong Answer

Solution code:
s, k = input(), int(input())
char=[]
prev = "0"
cnt = 0
for i in s:
    if i==prev: cnt+=1
    else: char.append(cnt);cnt=1
    prev = i
char.append(cnt)

if s[0]==s[-1]:
    tmp = char.pop(1)
    char[-1] += tmp
    ans = 0
    for i in char: ans += i//2
    ans *= k
    ans += tmp//2*2

else:
    ans = 0
    for i in char: ans += i//2
    ans *= k

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

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[-2]):
		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())
if len(set(s))==1:
  print(len(s)*k//2)
else:
  cnt=1
  s_ans=0
  x=s[0]
  for a in s[1:]:
    if a==x:
      cnt+=1
    else:
      s_ans+=cnt//2
      x=a
      cnt=1
  if s[0]!=s[-1]:
    print(s_ans*k)
  else:
    ss=s*2
    cnt=1
    ss_ans=0
    x=ss[0]
    for a in ss[1:]:
      if a==x:
        cnt+=1
      else:
        ss_ans+=cnt//2
        x=a
        cnt=1
    print(s_ans*k+(ss_ans-s_ans)*(k-1))

Submission status: Wrong Answer

Solution code:

# import sys
# input = sys.stdin.readline

def main():
    S = input()
    K = int(input())

    count_1st = 0
    S1 = list(S * 1)
    for i in range(len(S) - 1):
        if S1[i] == S1[i+1]:
            count_1st += 1
            S1[i+1] = '_'

    count_2nd = 0
    S2 = list(S * 2)
    for i in range(len(S) * 2 - 1):
        if S2[i] == S2[i+1]:
            count_2nd += 1
            S2[i+1] = '_'

    count_3rd = 0
    S3 = list(S * 3)
    for i in range(len(S) * 3 - 1):
        if S3[i] == S3[i+1]:
            count_3rd += 1
            S3[i+1] = '_'

    d = count_3rd - count_2nd
    print(d * K)
    # print(count_1st, count_2nd, count_3rd)
    # print(S1)
    # print(S2)
    # print(S3)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

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

L = [i for i in S]


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

count = 0
tmp = S[0]
for i in range(1, len(S)):
    if S[i] == tmp:
        count += 1
        S[i] = "A"
        tmp = S[i]
    else:
        tmp = S[i]

count2 = 0
if S[0] == S[-1]:
    L[0] = "A"
    count2 += 1
    tmp = L[0]
    for i in range(1, len(L)):
        if L[i] == tmp:
            count2 += 1
            L[i] = "A"
            tmp = L[i]
        else:
            tmp = L[i]
    print((K//2)*count2 + (K//2+K%2)*count)
else:
    print(count * K)

Submission status: Wrong Answer

Solution code:
S = input()
K = int(input())
d = [0 for _ in range(100)]
ans = 0
l = len(S)
for i in range(l-1):
    if i == 0 and S[i] == S[i+1]:
        ans += 1
        d[0] = 1
    if i > 0 and S[i] == S[i+1] and d[i-1] == 0:
        ans += 1
        d[i] = 1
ans = ans * K

if S[0] == S[-1] and d[l-2] == 0:
    ans += K -1

print(ans)

Submission status: Wrong Answer

Solution code:
s=input()
k=int(input())
ans=0
tmp=0
before=s[0]
t=0
flag=0
tmp2=0
hoge=0
for i in range(len(s)-1):
    if before==s[i+1]:
        t+=1
    else:
        if flag==0 or i==len(s)-2:
            hoge+=t
            flag=1
        else:
            tmp+=-(-t//2)
        t=0
        before=s[i+1]
tmp2=tmp-(-t//2)
tmp+=-(-t//2)
if s[0]==s[-1]:
    print(tmp2*(k-1)+tmp)
else:
    print(tmp*k)

Submission status: Wrong Answer

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

l = []
cnt = 1
for i in range(1, n + 1):
    if s[i - 1] != s[i]:
        l.append(cnt)
        cnt = 1
    else:
        cnt += 1
m = sum(map(lambda li: li // 2, l))
ans = m * k
if s[0] == s[-2] and l[0] % 2 == l[-1] % 2 == 1:
    ans += k - 1
print(ans)

Submission status: Wrong Answer

Solution code:
s=input()
k=int(input())
c=0
b=0
a=0
if len(s)==1:
  print(k//2)
else:
  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())

if len(s) >= 3:
    ans1 = 0
    ans2 = 0
    use = [True]*len(s)
    use2 = [True]*len(s)
    for i in range(len(s)-1):
        if use[i+1] and use[i]:
            if s[i+1] == s[i]:
                ans1 += 1
                use[i+1] = False

    if use[-1] and use2[0]:
        if s[-1] == s[0]:
            ans2 += 1
            use2[0] = False

    for i in range(len(s)-1):
        if use2[i+1] and use2[i]:
            if s[i+1] == s[i]:
                ans2 += 1
                use2[i+1] = False

    print(ans1+ans2*(K-1))

else:
    if len(s) == 1:
        print(K//2)
    else:
        if s[0] == s[1]:
            print(K)
        else:
            print(0)

Submission status: Wrong Answer

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

if len(S) == 1:
    print(K//2)
elif len(S) % 2 == 1 and len(set(S)) == 1:
    print(len(S)*K//2)
else:
    c = 0
    flg = False
    for i in range(len(S)-1):
        if S[i] == S[i+1] and flg is False:
            c += 1
            flg = True
        else:
            flg = False

    if flg is False and S[-1] == S[0]:
        j = 1
    else:
        j = 0

    print(c*K+j*(K-1))
    # print(c, j)

Submission status: Wrong Answer

Solution code:
S = input()
K = int(input())
ns = []
c = S[0]
n = 1
for i in range(1, len(S)):
  if c == S[i]:
    n += 1
  else:
    ns.append(n)
    n = 1
  c = S[i]
ns.append(n)
#print(ns)
if len(ns) == 1:
  r = ns[0]*K//2
  print(r)
  exit()
r = (ns[0]//2)+(ns[-1]//2)
for i in range(1, len(ns)-1):
  r += K*(ns[i]//2)
if S[0] == S[-1]:
  r += (K-1)*((ns[0]+ns[-1])//2)
print(r)

Submission status: Wrong Answer

Solution code:
def solve(s, k):
    
    s_mod = [""] * len(s)
    pre = ""
    ans = 0
    for i, s_i in enumerate(s):
        if pre == s_i:
            ans += 1
            pre = ""
            s_mod[i] = ""
        else:
            pre = s_i
            s_mod[i] = s_i
    ans *= k
    if s_mod[0] == s_mod[len(s)-1]:
        ans += k

    print(ans)

if __name__ == '__main__':
    s = input().strip()
    k = int(input().strip())
    solve(s, k)

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 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 = input()
K = int(input())
cnt = 0
cont = 0
for i in range(1 , len(S)):
    if S[i] == S[i - 1]:
        cnt += 1
    else:
        cont += cnt // 2
        cnt = 0
if S[0] == S[-1] and len(S) != 2:
    cont += 1
print((1 + cont) * K)

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()


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=list(input())
k=int(input())
l=len(s)
if l%2 and len(set(s))==1:
    print(l*k//2)
    exit()
for i in range(1,l):
    if s[i]==s[i-1]: s[i]='.'
ans=s.count(('.'))*k
if s[0]==s[-1]: ans+=k-1 
print(ans)

Submission status: Wrong Answer

Solution code:
s = input()
k = int(input())
count = 0
if len(s) == 1:
    print(k // 2)
else:
    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]:
        if s[1] == "." and s[-2] == ".":
            flag = 0
        else:
            flag = 1
    else:
        flag = 0

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

Submission status: Wrong Answer

Solution code:
import sys
s=input()
k=int(input())
a,i=0,0
if s[0]==s[-1]:
    s=s*3
    while True:
        if s[i]==s[i+1]:
            a+=1
            i+=1
        i+=1
        if i>=len(s)-1:
            print(a)
            sys.exit()
if len(s)==1:
    print(k//2)
    sys.exit()
while True:
    if s[i]==s[i+1]:
        a+=1
        i+=1
    i+=1
    if i>=len(s)-1:
        break
print(a*k)

Submission status: Wrong Answer

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

mae=s[0]
f=0
cn=0
for i in range(1,le):
    if i==le-1:
        if s[le-1]==s[0]:
            cn+=1
            break
    if f==1:
        f=0
        mae=s[i]
        continue
    if mae==s[i]:
        cn+=1
        f=1
        mae=s[i]
        continue
    mae=s[i]

print(cn*k)

Submission status: Wrong Answer

Solution code:
import sys, math; readline = sys.stdin.readline; from collections import deque;

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

a = []

_c = None
_count = 0
for c in S:
    if c == _c:
        a[-1] += 1
    else:
        a.append(1)
    _c = c
total = 0

if len(a) >= 2:
    for x in a[1:-1]:
        total += x // 2 * K

    if S[0] == S[-1]:
        total += (a[0] + a[-1]) // 2 * (K - 1)
        total += a[0] // 2 + a[-1] // 2
    else:
        total += (a[0] // 2 + a[-1] // 2) * K
else:
    total = a[0] // 2

print(total)

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] and len(a) > 1:
        cnt += K-1
    if len(a) ==1:
        cnt += K//2
    print(cnt)

    
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
S = input()
K = int(input())
S_list = [i for i in S]
single_S = 0

for i in range(len(S_list) - 1):
    if S_list[i] == S_list[i + 1]:
        single_S += 1
        S_list[i + 1] = "1"
if S_list[0] == S_list[-1]:
    print(K * single_S + K - 1)
else:
    print(K * single_S)

Submission status: Wrong Answer

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

box = ""
count=0

for i in S:
  if box == i:
    count += 1
    box = ""
  else:
   	box = i
    
print(count*K)

Submission status: Wrong Answer

Solution code:
import sys, collections, copy

def solve():
    S = list(input())
    S2 = copy.deepcopy(S)
    K = int(input())
    lens = len(S)
    head_change = 0
    for i in range(1, lens):
        if S[i] == S[i - 1]:
            head_change += 1
            S[i] = "Changed"
    
    inner_change = 0
    S2[0] = "Changed"
    for i in range(1, lens):
        if S2[i] == S2[i-1]:
            inner_change += 1
            S2[i] = "Changed"

    if lens == 1: print(K // 2)
    elif S[lens-1] != "Changed" and S[0] == S[lens - 1]:
        if S2[lens-1] != "Changed":
            print(head_change + inner_change * (K - 1))
        else:
            print((head_change + inner_change) * (K // 2) + head_change * (K % 2))
    else:
        print(head_change * K)
    #print(S)

    return 0

if __name__ == "__main__":
    solve()

Submission status: Wrong Answer

Solution code:
S = list(input())
K = int(input())
for i in range(K-1):
    for j in range(len(S)):
        S.append(S[j])
count = 0

for i in range(int(len(S)/2)-1):
    if S[2*i+1] == S[2*i] or S[2*i+1] == S[2*i+2]:
        count +=1
        
print(count)

Submission status: Wrong Answer

Solution code:
s = input()
k = int(input())
dup = 0
tmp = ""

for c1, c2 in zip(s, s[1:]):
    if c1 == c2:
        if tmp:
            tmp = ""
        else:
            dup += 1
            tmp = c1
    else:
        tmp = ""

answer = dup * k

if s[0] == s[-1]:
   dup += int(0.5 * k)

print(answer)

Submission status: Wrong Answer

Solution code:
import sys

def input(): return sys.stdin.readline()[:-1]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def MATINT(h): return [list(map(int, input().split())) for _ in range(h)]
def MATSTR(h): return [input() for _ in range(h)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
inf = float('inf')
mod = 10 ** 9 + 7

S = input()
K = INT()

N = len(S)
numlist = []
count = 1
if N == 1:
    print(K // 2)
else:
    for i in range(1, N):
        if S[i] == S[i - 1]:
            count += 1
        else:
            numlist.append(count)
            count = 1
    numlist.append(count)
    if S[0] == S[-1] and len(numlist) > 2:
        center = numlist[0] + numlist[-1]
        ans = (center // 2) * (K - 1)
        ans += numlist[0] // 2
        ans += numlist[-1] // 2
        for i in range(1, len(numlist)-1):
            ans += (numlist[i] // 2) * K
    else:
        ans = 0
        for i in range(len(numlist)):
            ans += (numlist[i] // 2) * K
    print(ans)

Submission status: Wrong Answer

Solution code:
import sys

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

li = [0 for i in range(len(s)+1)]
wrd = [i for i in s]
wrd.append(wrd[0])

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

for i in range(len(s)):
    if wrd[i]==wrd[i+1] and li[i]==0:
        li[i+1] = 1

ans = 0    
for i in range(len(s)+1):
    if li[i] == 1:
        ans += 1

ans *= k

if li[len(s)]==1:
    ans -= 1
    
print(ans)

Submission status: Wrong Answer

Solution code:
S = list(input())
K = int(input())
now = ""
ans = 0
chk = 0
if len(S) == 1:
    print(K//2)
else:
    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
                chk = 1
        else:
            now = S[i]    
    print((ans*K)-chk)

Submission status: Wrong Answer

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

# Summarize count of factor within list
def summarize_list(l):
  sl=l

  a=sl[0]
  c=1
  res=[]

  for x in sl[1:]:
    if x==a:
      c+=1
    else:
      res.append([a,c])
      a=x
      c=1
  res.append([a,c])

  return res

def main():
  s=S()
  k=I()

  if len(s)==1:
    return k//2

  l=summarize_list(s)

  ans=0
  bf=False
  
  if l[0][0]==l[-1][0] and (l[-1][1]+l[0][1])%2==1:
    ans+=min(0,k-1)

  _ans=0
  for x in l:
    _ans+=x[1]//2
  ans+=_ans*k

  return ans

# main()
print(main())

Submission status: Wrong Answer

Solution code:
from itertools import groupby

s = input()
k = int(input())
a = [sum(1 for _ in g) for _, g in groupby(s)]
if s[0] == s[-1] and len(a) > 1:
    a[0] += a.pop()
print(sum(x // 2 for x in a) * k)

Submission status: Wrong Answer

Solution code:
s=list(input())
k=int(input())
count,flag=0,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
    flag=1


print(count*k if flag==1 else (count*k)-1)

Submission status: Wrong Answer

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

for i in range(len(S)):
    if S[i]==S[i-1] and i!=len(S)-1:
        count +=1
    elif S[i]==S[i-1] and i==len(S)-1:
        count += 1
        if count!=len(S):
            onelen += (count+1)//2
        else:
            ans = (count*K)//2
    else:
        onelen += (count+1)//2
        count = 0
if ans == 0:
    ans = onelen*K
    if S[0] == S[-1]:
        ans -= 2

print(ans)

Submission status: Wrong Answer

Solution code:
s=list(input())
k=int(input())
if len(s)==1:
    print(k//2)
    exit()
from collections import Counter
l=Counter(s)
if len(l)==1:
    print(k*len(s)//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:

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)*(K-1)//2
    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=input()
k=int(input())
ans=0
tmp=0
before=s[0]
t=0
flag=0
tmp2=0
hoge=0
for i in range(len(s)-1):
    if before==s[i+1]:
        t+=1
    else:
        if flag==0:
            hoge+=t
            flag=1
        else:
            tmp+=-(-t//2)
        if i==len(s)-2:
            hoge+=t
        t=0
        before=s[i+1]
tmp2=tmp-(-t//2)
tmp+=-(-t//2)
if s[0]==s[-1]:
    print(tmp2*(k-1)+tmp)
else:
    print(tmp*k)

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
print(ans)

Submission status: Wrong Answer

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

def main():
    S = input().strip()
    K = int(input())

    count1 = 0
    now_count = 1
    for i in range(len(S) - 1):
        if S[i] == S[i + 1]:
            now_count += 1
        else:
            count1 += now_count // 2
            now_count = 1
    count1 += now_count // 2

    doubleS = S * 2
    count2 = 0
    now_count = 1
    for i in range(len(doubleS) - 1):
        if doubleS[i] == doubleS[i + 1]:
            now_count += 1
        else:
            count2 += now_count // 2
            now_count = 1
    count2 += now_count // 2

    ans = count1 + (count2 - count1) * (K - 1)
    print(ans)



    

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

seq=0
for i in range(len(S)-1):
  if S[i]==S[i+1]:
    S[i+1]=S[i+1].upper()
    seq+=1
    
if S[0]!=S[-1]:
  print(seq*K)
else:
  print(seq*K+K-1)

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 = "aa"
            count += 1
            s[i+1] = i0
        else:
            i0 = name
    if s[0] == s[-1]:
        al = n-1
    else:
        al = 0
    ans = count*n + 0

print(ans)

Submission status: Wrong Answer

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

if len(s) == 1:
  print(k // 2)
else:
  cnt = 0
  p = 1
  while p < len(s):
    if s[p-1] == s[p]:
      cnt += 1
      p += 1
    p += 1

  cnt2 = 0
  if s[0] == s[-1]:
    cnt2 += 1

  cnt3 = 0
  if s[-2] == s[-1]:
    cnt3 += 1
    
  cnt4 = 0
  if len(s) > 2:
    if cnt2 == 1 and s[-1] == s[-2] == s[-3]:
      cnt4 = 1

  ans = k*cnt + (k - 1)*cnt2 - (k - 1)*cnt3 +(k - 1)*cnt4
  print(ans)

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
print((count2-count)*(k-1) + count)

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]:
        count += 1
        S[i + 1] = 'A'
print(count*K)

Submission status: Wrong Answer

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

ans = 0 
target = [s[0]]

for i in range(1,len(s)):
  if target[i - 1] == s [i]:
    target.append("0")
    ans += 1
  else:
    target.append(s[i])
    
if target[0] == target[-1]:
  target[-1] ="0"
  ans += 1
  ans = ans * n - 1
else:
  ans = ans * n
  
print(ans)

Submission status: Wrong Answer

Solution code:
def main():
    s = input()
    k = int(input())
    s_ = []
    f = False
    for i in range(len(s)):
        if not s_:
            s_.append(s[i])
        elif not s_[-1][0] == s[i]:
            s_.append(s[i])
        else:
            s_[-1] += s[i]
    if s_[0][0] == s_[-1][0]:
        if len(s_) > 1:
            s_[0] = s_[0] + s_[-1]
            s_ = s_[:-1]
            f = True
    ans = 0
    for i in s_:
        ans += len(i)//2
    ans *= k
    if f == True and len(s_[0])%2 == 0:
      ans -= 1
    print(ans)
    
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
s = input()
k = int(input())
x = 0
cur = ""
count = 1

#print("s={0}".format(s))
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]
x += count // 2
#print(" change add = {0}".format(count // 2))
res1 = x
#print(res1)

s = s * 2
cur = ""
count = 1
x=0
#print("s={0}".format(s))
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]
x += count // 2
#print(" change add = {0}".format(count // 2))
res2 = x
#print(res2)

res = 0

if k % 2 == 1:
    res += res2 * (k//2)
    res += res1
else:
    res += res2 * (k//2)

print(res)

Submission status: Wrong Answer

Solution code:
import math

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

x = S[0]
c1 = 0
c2 = 0
for i in range(len(S)-1):
    if x == S[i+1]:
        c1 += 1
    else:
        c2 += math.ceil(c1/2)
        c1 = 0
    x = S[i+1]

c2 += math.ceil(c1/2)
a = c2

S.extend(S)

x = S[0]
c1 = 0
c2 = 0
for i in range(len(S)-1):
    if x == S[i+1]:
        c1 += 1
    else:
        c2 += math.ceil(c1/2)
        c1 = 0
    x = S[i+1]

c2 += math.ceil(c1/2)
b = c2

print((K//2)*b+K%2*a)

Submission status: Wrong Answer

Solution code:
from itertools import groupby

s = input()
k = int(input())
a, b = [], []
count1, count2 = 0, 0

for key, group in groupby(s):
  a.append(list(group))

for key, group in groupby(s*2):
  b.append(list(group))  
  
for i in a:
  count1 += len(i) // 2
  
for i in b:
  count2 += len(i) // 2
  
c = count2 - count1
  
print(count1 + c*(k-1))

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:
    print((k-1)//2)
else:
    print((cntss-cnts)*(k-1)+cnts)

Submission status: Wrong Answer

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

x = [0]*len(s)
for i in range(len(s)):
    if s[i] == s[(i+1)%len(s)]:
        x[(i+1)%len(s)] = 1
        if x[i] == 1:
            x[(i+1)%len(s)] = 0

cnt = sum(x)
if k == 1:
    cnt = cnt -1
print(cnt*k)