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:
import sys
from collections import Counter
input = sys.stdin.readline

def main():
    a = input().strip()
    n = int(input())
    b = Counter(a)
    if len(b) == 1:
        c = (n * len(a)) // 2
        print(c)
        exit()
    a = a + a[0]
    l = len(a)
    su = 0
    ans = 0
    for i in range(1, l):
        if a[i] == a[i - 1]:
            su += 1
        else:
            ans += (su + 1) // 2
            su = 0
    ans += (su + 1) // 2
    print(ans * n)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

def main():
    a = input()
    a = a + a[0]
    n = int(input())
    l = len(a)
    su = 0
    ans = 0
    for i in range(1, l):
        if a[i] == a[i - 1]:
            su += 1
        else:
            ans += (su + 1) // 2
            su = 0
    print(ans * n)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def find_operation_num(word):
    count = 0
    before = word[0]
    result = 0
    for w in word[1:] + " ":
        if before == w:
            count += 1
        else:
            before = w
            result += count // 2
            count = 1
    return result


def main():
    # 等差数列を利用する
    word = input()
    repeat = int(input())
    answer = 0
    if len(set(list(word))) == 1:
        answer = len(word) * repeat // 2
    else:
        count = [find_operation_num(word), find_operation_num(word + word)]
        answer = count[0] + (repeat - 1) * (count[1] - count[0])
    print(answer)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    # not AC -> AGCは後回しにする．
    string = input()
    repeat = int(input())
    count_succession = 0
    before = ""
    can_change = True
    answer = 0
    for i in range(len(string)):
        if before == string[i] and can_change:
            count_succession += 1
            can_change = False
        else:
            before = string[i]
            can_change = True
    if len(string) > 1:
        if string[0] == string[-1] and string[-2] != string[-1]:
            answer += repeat // 2
            if repeat % 2:
                answer += 1
        answer += count_succession * repeat
    else:
        answer = repeat // 2
    print(answer)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    string = input()
    repeat = int(input())
    count_succession = 0
    before = ""
    can_change = True
    answer = 0
    for i in range(len(string)):
        if before == string[i] and can_change:
            count_succession += 1
            can_change = False
        else:
            before = string[i]
            can_change = True
    if len(string) > 1:
        if string[0] == string[-1] and string[-2] != string[-1]:
            answer += repeat // 2
        answer += count_succession * repeat
    else:
        answer = repeat // 2
    print(answer)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

for i in range(len(S)-1):
  if S[i]!=S[i+1]:
    break
else:
  print((len(S)*K)//2)
  exit()

cnt=0
for i in range(len(S)-1):
  if S[i]==S[i+1]:
    S[i+1]='0'
    cnt+=1
#print(S)
cnt2=0
if S[-1]==S[0]:
  cnt2+=1
ans=cnt*K+cnt2*(K-1)
print(ans)

Submission status: Wrong Answer

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

for i in range(len(S)-1):
  if S[i]==S[i+1]:
    continue
else:
  print((len(S)*K)//2)
  exit()

cnt=0
for i in range(len(S)-1):
  if S[i]==S[i+1]:
    S[i+1]='0'
    cnt+=1
#print(S)
cnt2=0
if S[-1]==S[0]:
  cnt2+=1
ans=cnt*K+cnt2*(K-1)
print(ans)

Submission status: Wrong Answer

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

cnt=0
for i in range(len(S)-1):
  if S[i]==S[i+1]:
    S[i+1]='0'
    cnt+=1
#print(S)
cnt2=0
if S[-1]==S[0]:
  cnt2+=1
ans=cnt*K+cnt2*(K-1)
print(ans)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

#整数値龍力　複数の入力
def input_multiple_number():
    return map(int, input().split())

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


if len(S) >= 1:
	flagtail = 0
	old_s = ""
	cnt = 0
	for s_ in S:
		if s_ == old_s:
			cnt +=1
			old_s = ""
		else:
			old_s = s_
	ans = cnt

	cnt1 = cnt
	cnt = 0
	old_s = ""

	if(K > 1 and K %2 == 0):
		S = S*2
		cnt1 = cnt
		cnt = 0
		old_s = ""
		for s_ in S:
			if s_ == old_s:
				cnt +=1
				old_s = ""
			else:
				old_s = s_

		ans = cnt1 + (cnt-cnt1)*(K-1)

	if(K > 1 and K %2 != 0):
		S = S*3
		cnt1 = cnt
		cnt = 0
		old_s = ""
		for s_ in S:
			if s_ == old_s:
				cnt +=1
				old_s = ""
			else:
				old_s = s_

		ans = cnt1 + (cnt-cnt1)*(K-1)//2
	print(ans)
else:
	print(K//2)

Submission status: Wrong Answer

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

#整数値龍力　複数の入力
def input_multiple_number():
    return map(int, input().split())

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


if len(S) >= 1:
	flagtail = 0
	old_s = ""
	cnt = 0
	for s_ in S:
		if s_ == old_s:
			cnt +=1
			old_s = ""
		else:
			old_s = s_
	ans = cnt

	if(K > 1):
		S = S*2
		cnt1 = cnt
		cnt = 0
		old_s = ""
		for s_ in S:
			if s_ == old_s:
				cnt +=1
				old_s = ""
			else:
				old_s = s_

		ans = cnt1 + (cnt-cnt1)*(K-1)

	print(ans)
else:
	print(K//2)

Submission status: Wrong Answer

Solution code:
from itertools import groupby
S = input()
K = int(input())
ans = 0
L = []
for key, val in groupby(S):
  tmp = len(list(val))
  L.append(tmp)
sum_A = sum(k//2 for k in L)
ans = sum_A * K
if S[0] == S[-1]:
  ans += ((L[0]+L[-1])//2 - (L[0]//2+L[-1]//2))*(K-1)
print(ans)

Submission status: Wrong Answer

Solution code:
S = input()
K = int(input())
S += "!"
cnt, ans = 0, 0
for i in range(len(S)-1):
  cnt += 1
  if S[i] != S[i+1]:
    if cnt >= 2:
      ans += cnt//2
    cnt = 0
print(ans*K)

Submission status: Wrong Answer

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

if len(set(S)) == 1:
    print(l*K//2)
    exit()
else:
    ans = 0
    tmp = ""
    count = [1]
    for i in range(l-1):
        if S[i] == S[i+1]:
            count[-1] += 1
        else:
            count.append(1)
    
    for i in count:
        ans += i//2*K

    if S[0] == S[-1]:
        ans += K-1

    print(ans)

Submission status: Wrong Answer

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

S = list(input())
S_one = S.copy()
S_two = S*2
K = INT()

inner = 0
outer = 0

tmp = ""
for i, s in enumerate(S_one):
    if tmp == s:
        S_one[i] = "_"
        inner += 1
        tmp = ""
    else:
        tmp = s

tmp = ""
for i, s in enumerate(S_two):
    if tmp == s:
        S_two[i] = "_"
        outer += 1
        tmp = "_"
    else:
        tmp = s
outer -= (inner*2)

print(inner*K+outer*(K-1))

Submission status: Wrong Answer

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

if len(set(S)) == 1:
    print(l//2*K)
else:
    tmp = 0
    ans = 0
    ff = []
    flag = True
    for i in range(l-1):
        if i == l-2:
            if S[i] == S[i+1]:
                tmp += 1
            ff.append(tmp)
            ans += tmp//2
        elif S[i] == S[i+1]:
            tmp += 1
        else:
            if flag:
                ff.append(tmp)
            ans += tmp//2
            tmp = 1
    ans *= K
    if S[0] == S[-1]:
        ans += (ff[0]//2+ff[1]//2-(ff[0]+ff[1])//2)*(K-1)
    print(ans)

Submission status: Wrong Answer

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

if len(set(S)) == 1:
    print(l//2*K)
else:
    tmp = 0
    ans = 0
    ff = []
    flag = True
    for i in range(l-1):
        if i == l-2:
            if S[i] == S[i+1]:
                tmp += 1
            ff.append(tmp)
            ans += tmp//2
        elif S[i] == S[i+1]:
            tmp += 1
        else:
            if flag:
                ff.append(tmp)
            ans += tmp//2
            tmp = 1
    ans *= K
    print(ans)

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

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

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

ans = 0
flag = False
if S[0] == S[-1]:
    flag = True
    S[-1] = "1"

for i in range(l-1):
    if S[i] == S[i+1]:
        ans += 1
        S[i+1] = "1"
if flag:##S[0] == S[-1]
    print(ans*K+K)
else:
    print(ans*K)

Submission status: Wrong Answer

Solution code:
S = list(input())
K = int(input())
l = len(S)
"""
if l == 1:
    print(K//2)
    exit()
"""
ans = 0
flag = False
if S[0] == S[-1]:
    flag = True
    S[-1] = "1"

for i in range(1,l-1):
    if S[i] == S[i+1]:
        ans += 1
        S[i+1] = "1"

if flag:##S[0] == S[-1]
    print(ans*K+K)
else:
    print(ans*K)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
S = list(input())
s = len(S)
K = int(input())
A = []
j = 1

for i in range(0,s-1,1):
  if S[i] == S[i+1]:
    j += 1
  else:
    A.append(j)
    j = 1
A.append(j)

a = len(A)

b = 0
for i in range(0,a,1):
  b += A[i]//2
  
x = b*K

if a == 1:
  x = (s*K)//2
elif S[s-1] == S[0] and A[a-1] % 2 == 1 and A[1] % 2 == 1:
  x += K-1

print(x)

Submission status: Wrong Answer

Solution code:
import sys

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

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

x = 0
while True:
    if s[x]!=s[x+1]:
        break
    x += 1
    if x == len(s)-1:
        print(len(s)*k//2)
        sys.exit()

if k==1 or s[0]!=s[-1]:
    x = 0
    for i in range(len(s)-1):
        if s[i]==s[i+1]:
            x += 1
            s[i+1] = 0
    print(x*k) 
    sys.exit()

if s[0]==s[-1]:
    b = 1
    x = 0
    while True:
        if s[x]==s[x+1]:
            b += 1
            x += 1
        else:
            break
    a = 1
    x = 0
    while True:
        if s[-1-x]==s[-2-x]:
            a += 1
            x += 1
        else:
            break
    x = 0
    for i in range(len(s)-1):
        if s[i]==s[0]:
            continue
        if s[i]==s[i+1]:
            x += 1
            s[i+1] = 0

    print(x,a,b)
    print(x*k+((a+b)//2)*(k-1)+a//2+b//2)

Submission status: Wrong Answer

Solution code:
import sys

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

if k==1:
    if len(s)!=1:
        n = 0
        z = 0
        for i in range(len(s)-1):
            if s[i]==s[i+1]:
                s[i+1] = z
                n += 1
                z += 1
    else:
        n = 1
    print(n)
    sys.exit()

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



n = 0
z = 0
for i in range(len(s)-1):
    if s[i]==s[i+1]:
        s[i+1] = z
        n += 1
        z += 1

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

Submission status: Wrong Answer

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

N = len(S)

def calc(s):
    ans = 0
    pre = s[0]
    for ss in s[1:]:
        if ss == pre:
            ans += 1
            pre = '0'
        else: pre = ss
    return ans

if N == 1:
    print(K//2)
elif N == 2:
    print(K)
else:
    if K == 1:
        print(calc(S))
    elif K == 2:
        print(calc(S + S[0]) + calc(S[1:N]))
    else:
        print(calc(S + S[0]) + calc(S[1:N]) + (K - 2) * calc(S[1:N] + S[0]))

Submission status: Wrong Answer

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

N = len(S)

def calc(s):
    ans = 0
    pre = s[0]
    for ss in s[1:]:
        if ss == pre:
            ans += 1
            pre = '0'
        else: pre = ss
    return ans

if N == 1:
    print(K//2)
elif N == 2:
    print(K)
else:
    if K == 1:
        print(cals(S))
    elif K == 2:
        print(calc(S + S[0]) + calc(S[1:N]))
    else:
        print(calc(S + S[0]) + calc(S[1:N]) + (K - 2) * calc(S[1:N] + S[0]))

Submission status: Wrong Answer

Solution code:
import sys
s=input()
k=int(input())
l=len(s)
  
if len(set(list(s)))==1:
  print((l*k)//2)
  sys.exit()
lst=[]

cnt=1
for i in range(l-1):
  if s[i]==s[i+1]:
    if i==l-2:
        lst.append(cnt+1)
    else:
        cnt+=1
  else:
    if i==l-2:
      lst.append(1)
    else:
      lst.append(cnt)
      cnt=1
      

num=0
for i in range(len(lst)):
  num+=lst[i]//2
  
if s[0]!=s[l-1]:
  print(num*k)
else:
  Num=(lst[0]+lst[len(lst)-1])//2-(lst[0]//2+lst[len(lst)-1]//2)
  print(num*k+Num*(k-1))

Submission status: Wrong Answer

Solution code:
import sys
s=input()
k=int(input())
l=len(s)

if l==1:
  print(0)
  sys.exit()
  
if len(set(list(s)))==1:
  print((l*k)//2)
  sys.exit()
lst=[]

cnt=1
for i in range(l-1):
  if s[i]==s[i+1]:
    if i==l-2:
        lst.append(cnt+1)
    else:
        cnt+=1
  else:
    if i==l-2:
      lst.append(1)
    else:
      lst.append(cnt)
      cnt=1
      

num=0
for i in range(len(lst)):
  num+=lst[i]//2
  
if s[0]!=s[l-1]:
  print(num*k)
else:
  Num=(lst[0]+lst[len(lst)-1])//2-(lst[0]//2+lst[len(lst)-1]//2)
  print(num*k+Num*(k-1))

Submission status: Wrong Answer

Solution code:
import sys
s=input()
k=int(input())
l=len(s)

if l==1:
  print(0)
  sys.exit()
  
if len(set(s))==1:
  print(l//2)
  sys.exit()
lst=[]

cnt=1
for i in range(l-1):
  if s[i]==s[i+1]:
    if i==l-2:
        lst.append(cnt+1)
    else:
        cnt+=1
  else:
    if i==l-2:
      lst.append(1)
    else:
      lst.append(cnt)
      cnt=1
      

num=0
for i in range(len(lst)):
  num+=lst[i]//2
  
if s[0]!=s[l-1]:
  print(num*k)
else:
  Num=(lst[0]+lst[len(lst)-1])//2-(lst[0]//2+lst[len(lst)-1]//2)
  print(num*k+Num*(k-1))

Submission status: Wrong Answer

Solution code:
import sys
s=input()
k=int(input())
l=len(s)

if l==1:
  print(0)
  sys.exit()
lst=[]

cnt=1
for i in range(l-1):
  if s[i]==s[i+1]:
    if i==l-2:
        lst.append(cnt+1)
    else:
        cnt+=1
  else:
    if i==l-2:
      lst.append(1)
    else:
      lst.append(cnt)
      cnt=1
      

num=0
for i in range(len(lst)):
  num+=lst[i]//2
  
if s[0]!=s[l-1]:
  print(num*k)
else:
  Num=(lst[0]+lst[len(lst)-1])//2-(lst[0]//2+lst[len(lst)-1]//2)
  print(num*k+Num*(k-1))

Submission status: Wrong Answer

Solution code:
import sys
s=input()
k=int(input())
l=len(s)

if l==1:
  print(0)
  sys.exit()
lst=[]

cnt=1
for i in range(l-1):
  if s[i]==s[i+1]:
    if i==l-2:
        lst.append(cnt+1)
    else:
        cnt+=1
  else:
    if i==l-2:
      lst.append(1)
    else:
      lst.append(cnt)
      cnt=1
      

print(lst)
num=0
for i in range(len(lst)):
  num+=lst[i]//2
  
if s[0]!=s[l-1]:
  print(num*k)
else:
  Num=(lst[0]+lst[len(lst)-1])//2-(lst[0]//2+lst[len(lst)-1]//2)
  print(num*k+Num*(k-1))
  print(Num)

Submission status: Wrong Answer

Solution code:
import sys
s=input()
k=int(input())
l=len(s)

if l==1:
  print(0)
  sys.exit()
lst=[]

cnt=1
for i in range(l-1):
  cnt=1
  if s[i]==s[i+1]:
    if i==l-2:
      lst.append(cnt+1)
    else:
      cnt+=1
  else:
    if i==l-2:
      lst.append(1)
    else:
      lst.append(cnt)
      cnt=1

num=0
for i in range(len(lst)):
  num+=lst[i]//2
  
if s[0]!=s[l-1]:
  print(num*k)
else:
  Num=-(lst[0]//2+lst[len(lst)-1]//2)+(lst[0]+lst[len(lst)-1])//2
  print(num*k+Num*(k-1))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def main():
    S = input()
    K = int(input())
    ans = 0
    L = len(S)
    if L == 1:
        ans = K//2
        print(ans)
        exit()
    cnt = 1
    for i in range(L):
        if i < L-1 and S[i] == S[i+1]:
            cnt += 1
        else:
            ans += cnt//2
            cnt = 1
    ans *= K
    if S[0] == S[-1]:
        t = S[0]
        i = 0
        a = 0
        b = 0
        while S[i] == t and i < L:
            a += 1
            i += 1
            if i >= L:break
        i = L-1
        while S[i] == t and i >= 0:
            b += 1
            i -= 1
            if i < 0:break
        tmp = a//2+b//2-(a+b)//2
        tmp *= (K-1)
        ans -= tmp
    print(ans)
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
def main():
    S = input()
    K = int(input())
    ans = 0
    L = len(S)
    if L == 1:
        ans = K//2
        print(ans)
        exit()
    cnt = 1
    for i in range(L-1):
        if S[i] == S[i+1]:
            cnt += 1
        else:
            ans += cnt//2
            cnt = 1
    ans += cnt//2
    ans *= K
    if S[0] == S[-1]:
        t = S[0]
        i = 0
        a = 0
        b = 0
        while S[i] == t and i < L:
            a += 1
            i += 1
            if i >= L:break
        i = L-1
        while S[i] == t and i >= 0:
            b += 1
            i -= 1
            if i < 0:break
        tmp = a//2+b//2-(a+b)//2
        tmp *= (K-1)
        ans -= tmp
    print(ans)
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import math

s = input()
k = int(input())
cnt = 0
if len(s) == 1:
    cnt = math.floor(k / 2)
else:
    for i in range(1, len(s)):
        if s[i] == s[i - 1]:
            s = s[:i] + '#' + s[i + 1:]
            cnt += 1
    cnt *= k
    if k != 1 and s[0] == s[-1]:
        cnt += (k - 1)
print(cnt)

Submission status: Wrong Answer

Solution code:
def main():
    S = input()
    K = int(input())
    ans = 0
    L = len(S)
    if L == 1:
        ans = K//2
        print(ans)
        exit()
    S += S
    if K%2:
        tmp = 0
        ans = 0
        cnt = 1
        for i in range(2*L-1):
            if i == L-1:tmp = ans
            if S[i] == S[i+1]:
                cnt += 1
            else:
                ans += cnt//2
                cnt = 1
        ans += cnt//2
        ans *= K//2
        ans += tmp
    else:
        cnt = 1
        for i in range(2*L-1):
            if S[i] == S[i+1]:
                cnt += 1
            else:
                ans += cnt//2
                cnt = 1
        ans += cnt//2
        ans *= K//2
    print(ans)
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
def main():
    S = input()
    K = int(input())
    ans = 0
    L = len(S)
    if L == 1:
        ans = K//2
        print(ans)
        exit()
        '''
    i = 0
    while i < L-1:
        if S[i] == S[i+1]:
            ans += 1
            i += 2
        else:
            i += 1
    if S[0] == S[-1]:
        if i == L:
            ans *= K
        else:
            ans *= K
            tmp = K-1
            ans += tmp
    else:ans *= K
    '''
    cnt = 1
    for i in range(L-1):
        if S[i] == S[i+1]:
            cnt += 1
        else:
            ans += cnt//2
            cnt = 1
    ans += cnt//2
    ans *= K
    if L >= 4 and S[-3]==S[-2]==S[-1]:ans += K-1
    print(ans)
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
def main():
    S = input()
    K = int(input())
    ans = 0
    L = len(S)
    if L == 1:
        ans = K//2
        print(ans)
        exit()
        '''
    i = 0
    while i < L-1:
        if S[i] == S[i+1]:
            ans += 1
            i += 2
        else:
            i += 1
    if S[0] == S[-1]:
        if i == L:
            ans *= K
        else:
            ans *= K
            tmp = K-1
            ans += tmp
    else:ans *= K
    '''
    cnt = 1
    for i in range(L-1):
        if S[i] == S[i+1]:
            cnt += 1
        else:
            ans += cnt//2
            cnt = 1
    ans += cnt//2
    ans *= K
    if S[0] == S[-1]:ans += K-1
    print(ans)
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
def main():
    S = input()
    K = int(input())
    ans = 0
    L = len(S)
    if L == 1:
        ans = K//2
        print(ans)
        exit()
        '''
    i = 0
    while i < L-1:
        if S[i] == S[i+1]:
            ans += 1
            i += 2
        else:
            i += 1
    if S[0] == S[-1]:
        if i == L:
            ans *= K
        else:
            ans *= K
            tmp = K-1
            ans += tmp
    else:ans *= K
    '''
    cnt = 1
    for i in range(L-1):
        if S[i] == S[i+1]:
            cnt += 1
        else:
            ans += cnt//2
            cnt = 1
    ans += cnt//2
    ans *= K
    print(ans)
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
def main():
    S = input()
    K = int(input())
    ans = 0
    L = len(S)
    if L == 1:
        ans = K//2
        print(ans)
        exit()
    i = 0
    while i < L-1:
        if S[i] == S[i+1]:
            ans += 1
            i += 2
        else:
            i += 1
    if S[0] == S[-1]:
        if i == L:
            ans *= K
        else:
            ans *= K
            tmp = K-1
            ans += tmp
    else:ans *= K
    print(ans)
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
def main():
    S = input()
    K = int(input())
    ans = 0
    L = len(S)
    i = 0
    while i < L-1:
        if S[i] == S[i+1]:
            ans += 1
            i += 2
        else:
            i += 1
    if S[0] == S[-1]:
        if i == L:
            ans *= K
        else:
            ans *= K
            tmp = K-1
            ans += tmp
    else:ans *= K
    print(ans)
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
#!python3

iim = lambda: map(int, input().rstrip().split())

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

    ls = len(S)

    if ls == 1:
        print(K//2)
        return

    if ls == 2:
        print(0 if S[0] != S[1] else K)
        return

    if S[0] == S[-1]:
        c0 = S[0]
        for i in range(1, ls):
            if c0 != S[i]:
                break
        else:
            print(ls*K//2)
            return
        i0 = i
    else:
        i = i0 = 0

    ans = 0
    c0 , cn = "", 0
    for i in range(i, ls):
        c1 = S[i]
        if c1 == c0:
            cn += 1
        else:
            if cn > 1:
                ans += cn // 2
            cn = 1
            c0 = c1

    if i0 == 0:
        ans *= K
    else:
        ans = ans * K + ((i0+cn)//2) * (K-1) + i0//2 + cn//2


    print(ans)

if __name__ == "__main__":
    resolve()

Submission status: Wrong Answer

Solution code:
#!python3

iim = lambda: map(int, input().rstrip().split())

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

    ls = len(S)

    if ls == 1:
        print(K//2)
        return

    if ls == 2:
        print(0 if S[0] != S[1] else K)
        return

    if S[0] == S[-1]:
        c0 = S[0]
        for i in range(1, ls):
            if c0 != S[i]:
                break
        else:
            print(ls*K//2)
            return
        i0 = i
    else:
        i = i0 = 0

    ans = 0
    c0 , cn = "", 0
    for i in range(i, ls):
        c1 = S[i]
        if c1 == c0:
            cn += 1
        else:
            if cn > 1:
                ans += cn // 2
            cn = 1
            c0 = c1

    if i0 == 0:
        ans *= K
    else:
        print(i0, cn)
        ans = ans * K + ((i0+cn)//2) * (K-1) + i0//2 + cn//2


    print(ans)

if __name__ == "__main__":
    resolve()

Submission status: Wrong Answer

Solution code:
#!python3

iim = lambda: map(int, input().rstrip().split())

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

    ls = len(S)

    if ls == 1:
        print(K//2)
        return

    if ls == 2:
        print(0 if S[0] != S[1] else K)
        return

    if S[0] == S[-1]:
        c0 = S[0]
        for i in range(1, ls):
            if c0 != S[i]:
                break
        i0 = i
    else:
        i = i0 = 0

    ans = 0
    c0 , cn = "", 0
    for i in range(i, ls):
        c1 = S[i]
        if c1 == c0:
            cn += 1
        else:
            if cn > 1:
                ans += cn // 2
            cn = 1
            c0 = c1

    if i0 == 0:
        ans *= K
    else:
        ans = ans * K + ((i0+cn)//2) * (K-1) + i0//2 + cn//2


    print(ans)

if __name__ == "__main__":
    resolve()

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
s = input()
k = int(input())

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

count = []
tmp = 0
for i in range(len(s) - 1):
    if s[i] == s[i + 1]:
        tmp += 1
    if s[i] != s[i + 1]:
        count.append(tmp + 1)
        tmp = 0
count.append(tmp + 1)
#print(count)

flag = True
ans = 0
if s[0] == s[-1]:
    if count[-1] == 1 and count[0] == 1:
        ans += k - 1
        flag = False
    elif abs((count[-1] + count[0])) % 2 == 1:
        if count[-1] >= count[0]:
            count[-1] -= 1
        else:
            count[0] -= 1
        ans += k - 1

for i in range(len(count)):
    if count[i] > 1:
        ans += (count[i] // 2) * k
if s[0] == s[-1] and count[-1] >= 1 and flag:
    ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
s = input()
k = int(input())

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

count = []
tmp = 0
for i in range(len(s) - 1):
    if s[i] == s[i + 1]:
        tmp += 1
    if s[i] != s[i + 1]:
        count.append(tmp + 1)
        tmp = 0
count.append(tmp + 1)
#print(count)

ans = 0
if s[0] == s[-1]:
    if abs((count[-1] + count[0])) % 2 == 1:
        if count[-1] >= count[0]:
            count[-1] -= 1
        else:
            count[0] -= 1
        ans += k - 1
for i in range(len(count)):
    if count[i] > 1:
        ans += (count[i] // 2) * k
if s[0] == s[-1] and count[-1] >= 1:
    ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7

s = STR()
k = INT()
ans = 0
a = 0
b = 0
if s[0] == s[-1]:
    if len(set(s)) == 1:
        ans = len(s) * k // 2
        print(ans)
        exit()
    for j in range(len(s)):
        if s[0] == s[j]:
            a += 1
        else:
            break
    for j in reversed(range(len(s))):
        if s[-1] == s[j]:
            b += 1
        else:
            break
    ans = a // 2 + b // 2 + (a + b) * (k - 1) // 2
i = a
ans2 = 0
while i < len(s) - b:
    tmp = 1
    for j in range(i + 1, len(s)):
        if s[i] == s[j]:
            tmp += 1
        else:
            break
    i += tmp
    tmp //= 2
    ans2 += tmp
ans2 *= k

print(ans + ans2)

Submission status: Wrong Answer

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7

s = STR()
k = INT()
ans = 0
a = 0
b = 0
if s[0] == s[-1]:
    if len(set(s)) == 1:
        ans = len(s) * k // 2
        print(ans)
        exit()
    for j in range(len(s)):
        if s[0] == s[j]:
            a += 1
        else:
            break
    for j in reversed(range(len(s))):
        if s[-1] == s[j]:
            b += 1
        else:
            break
    ans = a // 2 + b // 2 + (a + b) * (k - 1) // 2
i = a + 1
flag = False
while i < len(s) - b:
    tmp = 1
    for j in range(i + 1, len(s)):
        if s[i] == s[j]:
            tmp += 1
        else:
            break
    i += tmp
    tmp //= 2
    ans += tmp
ans *= k

print(ans)

Submission status: Wrong Answer

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7

s = STR()
k = INT()
ans = 0
i = 0
flag = False
while i < len(s):
    tmp = 1
    for j in range(i + 1, len(s)):
        if s[i] == s[j]:
            tmp += 1
        else:
            break
    i += tmp
    if tmp % 2 == 1:
        flag = True
    else:
        flag = False
    tmp //= 2
    ans += tmp
ans *= k
if s[0] == s[-1] and flag:
    ans += k - 1
print(ans)