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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
s, k = input(), int(input())
r = 0
f = True
fir = 0
las = 0

for i in range(len(s)):
    if s[i] == s[0]:
        fir += 1
    else:
        break

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

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

print(r * k - (k - 1) * (fir // 2 + las // 2 - (fir + las) // 2))

Submission status: Wrong Answer

Solution code:
s, k = input(), int(input())
r = 0
f = True
fall = True
i = 0
while i < len(s):
    if s[i] == s[(i + 1) % len(s)]:
        i += 1
        r += 1
    else:
        fall = False
    if i == len(s):
        f = False
    i += 1

if fall:
    print(len(s) * k // 2)
elif f:
    print(r * k)
else:
    print(r * k - 1)

Submission status: Wrong Answer

Solution code:
s, k = input(), int(input())
r = 0
f = True
i = 0
while i < len(s):
    if s[i] == s[(i + 1) % len(s)]:
        i += 1
        r += 1
    if i == len(s):
        f = False
    i += 1
if f:
    print(r * k)
else:
    print(r * k - 1)

Submission status: Wrong Answer

Solution code:
s,k,r,f,i=input(),int(input()),0,True,0
while i<len(s):
    if s[i]==s[(i+1)%len(s)]:
        i+=1
        r+=1
    if i==len(s):
        f=False
        i+=1
if f:
    print(r*k)
else:
    print(r*k-1)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
S = input()
K = int(input())
if len(S) == 2:
    if S[0] != S[1]:
        print(0)
    else:
        print(K)
    exit()
l = []
SS = S * 2
s = SS[0]
cnt = 1
for i in range(1, len(SS)):
    if s != SS[i]:
        l.append(cnt)
        s = SS[i]
        cnt = 1
    else:
        cnt += 1
l.append(cnt)
ans = 0
if S[0] == S[-1]:
    for i in range(len(l)//2 + 1):
        # if i == 0 or i == len(l)//2:
        #     ans += l[i] // 2
        if i == 0:
            ans += l[i] // 2
        elif i == len(l) // 2:
            ans += l[i] // 2 * (K-1)
        else:
            ans += l[i] // 2 * K
    ans += l[-1] // 2
    # ans -= (l[0] + l[-1]) // 2
else:
    # print(l[:len(l)//2])
    for i in range(len(l)//2):
        ans += l[i] // 2 * K
print(ans)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
S = input()
K = int(input())
if len(S) == 2:
    if S[0] != S[1]:
        print(0)
    else:
        print(K)
    exit()
l = []
SS = S * 2
s = SS[0]
cnt = 1
for i in range(1, len(SS)):
    if s != SS[i]:
        l.append(cnt)
        s = SS[i]
        cnt = 1
    else:
        cnt += 1
l.append(cnt)
ans = 0
if S[0] == S[-1]:
    # print(l)
    for i in range(len(l)):
        if i == 0 or i == len(l)-1:
            ans += l[i] // 2
        else:
            ans += l[i] // 2 * (K-1)
    ans -= (l[0] + l[-1]) // 2
else:
    # print(l[:len(l)//2])
    for i in range(len(l)//2):
        ans += l[i] // 2 * K
print(ans)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
S = input()
K = int(input())
if len(S) == 2:
    if S[0] != S[1]:
        print(0)
    else:
        print(K)
    exit()
l = []
SS = S * 2
s = SS[0]
cnt = 1
for i in range(1, len(SS)):
    if s != SS[i]:
        l.append(cnt)
        s = SS[i]
        cnt = 1
    else:
        cnt += 1
l.append(cnt)
ans = 0
if S[0] == S[-1]:
    # print(l)
    for i in range(len(l)):
        if i == 0 or i == len(l)-1:
            ans += l[i] // 2
        else:
            ans += l[i] // 2 * (K-1)
    ans -= l[-1] // 2
else:
    # print(l[:len(l)//2])
    for i in range(len(l)//2):
        ans += l[i] // 2 * K
print(ans)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
S = input()
K = int(input())
if len(S) == 2:
    if S[0] != S[1]:
        print(0)
    else:
        print(K)
    exit()
l = []
SS = S * 2
s = SS[0]
cnt = 1
for i in range(1, len(SS)):
    if s != SS[i]:
        l.append(cnt)
        s = SS[i]
        cnt = 1
    else:
        cnt += 1
l.append(cnt)
ans = 0
if S[0] == S[-1]:
    for i in range(len(l)):
        if i == 0 or i == len(l)-1:
            ans += l[i] // 2
        else:
            ans += l[i] // 2 * (K-1)
else:
    for i in range(len(l)//2):
        ans += l[i] // 2 * K
print(ans)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
S = input()
K = int(input())
if len(S) == 2:
    if S[0] != S[1]:
        print(0)
    else:
        print(K)
    exit()
l = []
SS = S * 2
s = SS[0]
cnt = 1
for i in range(1, len(SS)):
    if s != SS[i]:
        l.append(cnt)
        s = SS[i]
        cnt = 1
    else:
        cnt += 1
l.append(cnt)
ans = 0
if S[0] == S[-1]:
    for i in range(len(l)):
        if i == 0 or i == len(l)-1:
            ans += l[i] // 2
        else:
            ans += l[i] // 2 * (K-1)
else:
    for i in range(len(l)//2):
        if i == 0 or i == len(l)//2-1:
            ans += l[i] // 2
        else:
            ans += l[i] // 2 * K
print(ans)

Submission status: Wrong Answer

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

ans = 0
if len(set(list(s))) == 1:
  print(len(s)*k//2)
else:
  for i in range(len(l)):
    ans += l[i] // 2
  if s[0] != s[-1]:
    print(ans*k)
  else:
    fans = (k - 1) * (l[0] + l[-1]) // 2 + ans
    ans = 0
    for i in range(1,len(l)-1):
      ans += l[i] // 2
    fans += (k - 1) * ans
    print(fans)

Submission status: Wrong Answer

Solution code:
S = list(input())
K = int(input())
cnt = 0
start = S[0]
for i in range(len(S)):
    if start != S[i]:
        break
    if i == len(S) - 1:
        print(len(S) // 2 * K)
        exit()
ans = 0
now = start
for i in range(len(S)):
    if i == len(S) - 1:
        if now == S[i]:
            cnt += 1
        ans += cnt // 2
    else:
        if S[i] != now :
            ans += cnt // 2
            cnt = 1
            now = S[i]
        else:
            cnt += 1

end = S[-1]
start_cnt = 0
end_cnt = 0
for c in S:
    if c == start:
        start_cnt += 1
    else:
        break
for i in range(len(S) - 1 , - 1, -1):
    if S[i] == end:
        end_cnt += 1
    else:
        break
add = 0
if end_cnt % 2 == 1 and start_cnt % 2 == 1 and start == end:
    add = (K - 1)
print(ans * K + add)

Submission status: Wrong Answer

Solution code:
import re
def nchars(s, n):
    """文字列 s に、同じ文字が n 個以上連続している部分文字列を見つける
    """
    assert n > 0
    reg = re.compile("(.)\\1{%d,}" % (n - 1))  # カンマを取ると n 個ちょうどになる
    while True:
        m = reg.search(s)
        if not m:
            break
        yield m.group(0)
        s = s[m.end():]

S = input()
K = int(input())
T = list(nchars(S, 2))
ans = 0
if all(s == S[0] for s in S):
  ans = len(S)*K//2
else:
  S = S+S
  T = T[:len(T)//2]
  for Tp in T:
    ans += len(Tp)//2
  ans *= K
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

seq = [(s, len(list(k))) for s, k in groupby(S)]
print(*seq, sep="\n")

if len(seq) == 1:
    ans = (k * len(S)) // 2
else:
    if seq[0][0] != seq[-1][0]:
        ans = k*sum(a[1] // 2 for a in seq)
    else:
        left = seq[0][1]
        right = seq[-1][1]
        ans = k*sum(a[1] // 2 for a in seq[1:-1])
        ans += ((left + right) // 2) * (k - 1)
        ans += left // 2 + right // 2

print(ans)

Submission status: Wrong Answer

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

seq = [(s, len(list(k))) for s, k in groupby(S)]

if len(seq) == 1:
    ans = (k * len(S)) // 2
else:
    if seq[0][0] != seq[-1][0]:
        ans = k*sum(a[1] // 2 for a in seq)
    else:
        ans = k * sum(a[1] // 2 for a in seq[1:-1])
        ans += (k - 1) * (seq[0][1] + seq[-1][1]) // 2
        ans += seq[0][1]//2
        ans += seq[-1][1]//2

print(ans)

Submission status: Wrong Answer

Solution code:
#AGC-041
S = input()
K = int(input())
ans = 0

check_char = S[0]
repeat = 1

#まずSだけで数える。
for i in range(1, len(S)):
    if S[i] == check_char:
        repeat += 1
    else:
        ans += (repeat//2)
        check_char = S[i]
        repeat = 1
    
ans += (repeat//2)

#K倍を答えとする
if len(S) > 1 and S[0] == S[-1]:
    a, b, i, j = 1, 1, 1, -2
    char = S[0]
    while i < len(S):
        if S[i] == char:
            a += 1
            i += 1
        else:
            break
    char = S[-1]
    while j > (-1)*len(S):
        if S[j] == char:
            b += 1
            j -= 1
        else:
            break
    minus = (K-1) * (a//2 + b//2 - (a+b)//2)
    print(ans * K - minus)
else:
    print(ans * K)

Submission status: Wrong Answer

Solution code:
#AGC-041
S = input()
K = int(input())
ans = 0

check_char = S[0]
repeat = 1

#まずSだけで数える。
for i in range(1, len(S)):
    if S[i] == check_char:
        repeat += 1
    else:
        ans += (repeat//2)
        check_char = S[i]
        repeat = 1
    
ans += (repeat//2)

if len(S) > 1 and S[0] == S[-1]:
    a, b, i, j = 1, 1, 1, -2
    char = S[0]
    while i < len(S):
        if S[i] == char:
            a += 1
            i += 1
        else:
            break
    char = S[-1]
    while j > (-1)*len(S):
        if S[j] == char:
            b += 1
            j -= 1
        else:
            break
    minus = (K-1) * (a//2 + b//2 - (a+b)//2)
else:
    print(ans * K)

Submission status: Wrong Answer

Solution code:
#AGC-041
S = input()
K = int(input())
ans = 0

check_char = S[0]
repeat = 1

#まずSだけで数える。
for i in range(1, len(S)):
    if S[i] == check_char:
        repeat += 1
    else:
        ans += (repeat//2)
        check_char = S[i]
        repeat = 1
    
ans += (repeat//2)

#K倍を答えとする
print(ans * K)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
t = input()
k = int(input())
l = len(t)
head = t[0]
tail = t[-1]
tmp = head
cnt = 0
ans = 0
A = []
if l == 1:
    ans = k-1
else:
    for i in range(1,l):
        if t[i] == tmp:
            cnt+=1
        else:
            tmp = t[i]
            A.append(cnt+1)
            cnt = 0
    if cnt !=0:
        A.append(cnt+1)
    if len(A)==1:
        ans = (A[0]*k)//2
    else:
        for a in A:
            ans += a//2
        if head == tail and (A[0]+A[-1])%2 == 0:
            ans += 1
        ans *= k
print(ans)

Submission status: Wrong Answer

Solution code:
from itertools import groupby
S = list(input())
K = int(input())
newS = list([list(g) for k, g in groupby(S)])
change = 0
for i in range(len(newS)):
    change += len(newS[i])//2
chain = 0
if len(S) == 1:
    print(K//2)
else:
    if len(newS) > 2 and newS[0] == newS[len(newS)-1]:
        chain = 1
    print(change*K+chain*(K-1))

Submission status: Wrong Answer

Solution code:
from itertools import groupby
S = list(input())
K = int(input())
newS = list([list(g) for k, g in groupby(S)])
change = 0
for i in range(len(newS)):
    change += len(newS[i])//2
chain = 0
if len(newS) > 2 and newS[0] == newS[len(newS)-1]:
    chain = 1
print(change*K+chain*(K-1))

Submission status: Wrong Answer

Solution code:
from itertools import groupby
S = list(input())
K = int(input())
newS = list([list(g) for k, g in groupby(S)])
change = 0
for i in range(len(newS)):
    change += len(newS[i])//2
print(change*K)

Submission status: Wrong Answer

Solution code:
from collections import Counter
s = input()
k = int(input())
len_s = len(s)
INF = 10**18
best = INF
ct = Counter(s)

def check(s):
    cur = s[0]
    cnt = 0
    flg = 0
    for _s in s[1:]:
        if _s == cur:
            cnt += 1
            cur = "?"
        else:
            cur = _s
    if cur == s[0]:
        flg = 1
    return (cnt * k + flg * (k-1))

if len(ct.keys()) == 1:
    print(len_s * k // 2)
else:
    for i in range(len_s):
        score = check(s[i:] + s[:i])
        best = min(best, score)
    print(best)

Submission status: Wrong Answer

Solution code:
s = input()
k = int(input())
len_s = len(s)
cur = s[0]
cnt = 0
flg = 0
for _s in s[1:]:
    if _s == cur:
        cnt += 1
        cur = "?"
    else:
        cur = _s
if cur == s[0]:
    flg = 1
print(cnt * k + flg * (k-1))

Submission status: Wrong Answer

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

#
#  文字数一種類
#
if len(set(s)) == 1:
    print((len(s) * k) // 2)
    exit()

#
# 先頭と末尾が異なる
#
if s[0] != s[-1]:
    cnt = 0
    bf_same = False
    for i in range(1, len(s)):
        if s[i - 1] == s[i]:
            if bf_same:
                bf_same = False
            else:
                cnt += 1
                bf_same = True
        else:
            if bf_same:
                bf_same = False
    else:
        print(cnt * k)
    exit()

#
# 先頭と末尾が一緒
#

# 先頭のダブリ
tp = 1
tp_idx = -1
for i in range(len(s) - 1):
    if s[i] == s[i + 1]:
        tp += 1
        tp_idx = i + 1
    else:
        break

# 末尾のダブリ
bt = 1
bt_idx = -1
for i in range(len(s) - 1, 1, -1):
    if s[i] == s[i - 1]:
        bt += 1
        bt_idx = i - 1
    else:
        break

# 連結部分以外のダブリ
cnt = 0
bf_same = False
for i in range(tp_idx + 1, bt_idx - 1):
    if s[i] == s[i + 1]:
        if bf_same:
            bf_same = False
        else:
            cnt += 1
            bf_same = True

# print(tp, bt, cnt)
ans = cnt * k + tp // 2 + bt // 2 + (((tp + bt) * (k - 1)) // 2)
print(ans)

Submission status: Wrong Answer

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

#
#  文字数一種類
#
if len(set(s)) == 1:
    print((len(s) * k) // 2)
    exit()

#
# 先頭と末尾が異なる
#
if s[0] != s[-1]:
    tmp = 1
    cnt = 0
    for i in range(len(s) - 1):
        if(s[i] == s[i + 1]):
            tmp += 1
        else:
            cnt += tmp * k // 2
            tmp = 1
    if tmp != 1:
        cnt += tmp * k // 2
    print(cnt)
    exit()

#
# 先頭と末尾が一緒
#

# 先頭のダブリ
tp = 1
tp_idx = -1
for i in range(len(s) - 1):
    if s[i] == s[i + 1]:
        tp += 1
        tp_idx = i + 1
    else:
        break

# 末尾のダブリ
bt = 1
bt_idx = -1
for i in range(len(s) - 1, 0, -1):
    if s[i] == s[i - 1]:
        bt += 1
        bt_idx = i - 1
    else:
        break

# 連結部分以外のダブリ
cnt = 0
tmp = 1

t = s[tp_idx + 1: bt_idx]
# print("aa: ", t)
for i in range(len(t) - 1):
    if(t[i] == t[i + 1]):
        tmp += 1
    else:
        if tmp != 1:
            cnt += tmp * k // 2
        tmp = 1
if tmp != 1:
    # print("cnt-tmp", cnt, tmp) 
    cnt += tmp * k // 2

# print(tp, bt, cnt)
ans = cnt + tp // 2 + bt // 2 + (((tp + bt) * (k - 1)) // 2)
print(ans)

Submission status: Wrong Answer

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

#
#  文字数一種類
#
if len(set(s)) == 1:
    print((len(s) * k) // 2)
    exit()

#
# 先頭と末尾が異なる
#
if s[0] != s[-1]:
    tmp = 1
    cnt = 0
    for i in range(len(s) - 1):
        if(s[i] == s[i + 1]):
            tmp += 1
        else:
            cnt += tmp * k // 2
            tmp = 1
    if tmp != 1:
        cnt += tmp * k // 2
    print(cnt)
    exit()

#
# 先頭と末尾が一緒
#

# 先頭のダブリ
tp = 0
tp_idx = -1
for i in range(len(s) - 1):
    if s[i] == s[i + 1]:
        tp += 1
        tp_idx = i + 1
    else:
        break

# 末尾のダブリ
bt = 0
bt_idx = -1
for i in range(len(s) - 1, 0, -1):
    if s[i] == s[i - 1]:
        bt += 1
        bt_idx = i - 1
    else:
        break

# 連結部分以外のダブリ
cnt = 0
tmp = 1

t = s[tp_idx + 1: bt_idx]
# print("aa: ", t)
for i in range(len(t) - 1):
    if(t[i] == t[i + 1]):
        tmp += 1
    else:
        if tmp != 1:
            cnt += tmp * k // 2
        tmp = 1
if tmp != 1:
    # print("cnt-tmp", cnt, tmp) 
    cnt += tmp * k // 2

# print(tp, bt, cnt)
ans = cnt + tp + bt + (((tp + bt + 2) * (k - 1)) // 2)
print(ans)

Submission status: Wrong Answer

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

#
#  文字数一種類
#
if len(set(s)) == 1:
    print((len(s) * k) // 2)
    exit()

#
# 先頭と末尾が異なる
#
if s[0] != s[-1]:
    cnt = 0
    bf_same = False
    for i in range(1, len(s)):
        if s[i - 1] == s[i]:
            if bf_same:
                bf_same = False
            else:
                cnt += 1
                bf_same = True
        else:
            if bf_same:
                bf_same = False
    else:
        print(cnt * k)
    exit()

#
# 先頭と末尾が一緒
#

# 先頭のダブリ
tp = 0
tp_idx = -1
for i in range(len(s) - 1):
    if s[i] == s[i + 1]:
        tp += 1
        tp_idx = i + 1
    else:
        break

# 末尾のダブリ
bt = 0
bt_idx = -1
for i in range(len(s) - 1, 1, -1):
    if s[i] == s[i - 1]:
        bt += 1
        bt_idx = i - 1
    else:
        break

# 連結部分以外のダブリ
cnt = 0
bf_same = False
for i in range(tp_idx + 1, bt_idx - 1):
    if s[i] == s[i + 1]:
        if bf_same:
            bf_same = False
        else:
            cnt += 1
            bf_same = True

# print(tp, bt, cnt)
ans = cnt * k + tp + bt + (((tp + bt + 2) * (k - 1)) // 2)
print(ans)

Submission status: Wrong Answer

Solution code:
def solve(s, k):
    n = len(s)
    if len(set(s)) == 1:
        return n*k//2
    return (f(s+s) - f(s)) * k

def f(s):
    s = list(s)
    n = len(s)
    res = 0
    for i in range(n-1):
        if s[i] == s[i+1]:
            s[i+1] = "."
            res += 1
    return res

s = input()
k = int(input())
print(solve(s, k))

Submission status: Wrong Answer

Solution code:
def solve(s, k):
    return (f(s+s) - f(s)) * k

def f(s):
    s = list(s)
    n = len(s)
    res = 0
    for i in range(n-1):
        if s[i] == s[i+1]:
            s[i+1] = "."
            res += 1
    return res

s = input()
k = int(input())
print(solve(s, k))

Submission status: Wrong Answer

Solution code:
def solve(s, k):
    p = f(s)
    q = f(s+s)
    return p + (q-p) * (k-1)

def f(s):
    s = list(s)
    n = len(s)
    res = 0
    for i in range(n-1):
        if s[i] == s[i+1]:
            s[i+1] = "."
            res += 1
    return res

s = input()
k = int(input())
print(solve(s, k))

Submission status: Wrong Answer

Solution code:
def solve(s, k):
    s = list(s)
    n = len(s)
    if len(set(s)) == 1:
        return n*k//2
    cnt = 0
    for i in range(n-1):
        if s[i] == s[i+1]:
            s[i+1] = "."
            cnt += 1
    t = int(s[0] == s[-1])
    return (cnt + t) * k - t

s = input()
k = int(input())
print(solve(s, k))

Submission status: Wrong Answer

Solution code:
def solve(s, k):
    s = list(s)
    n = len(s)
    if n == 1:
        return k//2
    cnt = 0
    for i in range(n-1):
        if s[i] == s[i+1]:
            s[i+1] = "."
            cnt += 1
    t = int(s[0] == s[-1])
    return (cnt + t) * k - t

s = input()
k = int(input())
print(solve(s, k))

Submission status: Wrong Answer

Solution code:
def solve(s, k):
    s = list(s)
    n = len(s)
    if n == 1:
        return k//2
    cnt = 0
    for i in range(n-1):
        if s[i] == s[i+1]:
            s[i+1] = "."
            cnt += 1
    t = s[0] == s[-1]
    return (cnt + t) * k - t

s = input()
k = int(input())
print(solve(s, k))

Submission status: Wrong Answer

Solution code:
def solve(s, k):
    n = len(s)
    if n == 1:
        return k//2
    i, cnt = 0, 0
    hit = False
    while i < n-1:
        if s[i] == s[i+1]:
            if i == n-2:
                hit = True
            cnt += 1
            i += 1
        i += 1
    t = (s[0] == s[-1]) & (not hit)
    return (cnt + t) * k - t

s = input()
k = int(input())
print(solve(s, k))

Submission status: Wrong Answer

Solution code:
def solve(s, k):
    n = len(s)
    if n == 1:
        return k//2
    i, cnt = 0, 0
    while i < n-1:
        if s[i] == s[i+1]:
            cnt += 1
            i += 1
        i += 1
    t = (s[0] == s[-1]) & (s[-2] != s[-1])
    return (cnt + t) * k - t

s = input()
k = int(input())
print(solve(s, k))

Submission status: Wrong Answer

Solution code:
s = input()
k = int(input())
if k >= 2:
    s = s + s[0]
# print(s)

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

if k == 1:
    ans += (count-1) // 2
    print(ans * k)
else:
    ans += count // 2
    if (count // 2) == (count-1) // 2:
        print(ans * k)
    else:
        print(ans * k - 1)

Submission status: Wrong Answer

Solution code:
s = input()
k = int(input())
if k >= 2:
    s = s + s[0]
# print(s)

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

if k == 1:
    ans += (count-1) // 2
    print(ans * k)
else:
    ans += (count // 2)
    print(ans * (k-1) + ans - (count) // 2 + 1)

Submission status: Wrong Answer

Solution code:
s = input()
k = int(input())
if k >= 2:
    s = s + s[0]
# print(s)

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

if k == 1:
    ans += (count-1) // 2
    print(ans * k)
else:
    ans += (count // 2)
    print(ans * (k-1) + (count-1) // 2)

Submission status: Wrong Answer

Solution code:
s = input()
k = int(input())
if k >= 2:
    s = s + s[0]
# print(s)

count = 1
ans = 0
i = 0
while i < len(s) - 1:
    if s[i] == s[i+1]:
        count += 1
        i += 1
    else:
        ans += count // 2
        count = 1
        i += 1
if k >= 2:
    ans += count // 2

print(ans * k)

Submission status: Wrong Answer

Solution code:
s = input()
k = int(input())
if k >= 2:
    s = s + s[0]
# print(s)

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

print(ans * k)

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

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



head = 0
for i in range(len(s)):
    if head==0 or s[i]==s[i-1]:
        head+=1
    else:
        break

tail = 0
t = s[::-1]
for i in range(len(t)):
    if tail==0 or t[i]==t[i-1]:
        tail+=1
    else:
        break
#print (ans,head,tail)
print (ans*k-(k-1)*(head//2+tail//2-((head+tail)//2)))

Submission status: Wrong Answer

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


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

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



head = 0
for i in range(len(s)):
    if head==0 or s[i]==s[i-1]:
        head+=1
    else:
        break

tail = 0
t = s[::-1]
for i in range(len(t)):
    if tail==0 or t[i]==t[i-1]:
        tail+=1
    else:
        break

print (ans*k-(k-1)*(int(head/2)+int(tail/2)-int((head+tail)/2)))

Submission status: Wrong Answer

Solution code:
#coding:utf-8
s = input()
k = int(input())
s += s[0]
old = s
ans = 0
for i in range(len(s)):
    if(s[i]==old):
        ans+=1
        old = ""
    else:
        old = s[i]
print (ans*k)

Submission status: Wrong Answer

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

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

cnt = []
c = 1
for i in range(len(S) - 1):
    if S[i] == S[i + 1]:
        c += 1
    else:
        cnt.append(c if c > 0 else 0)
        c = 1
cnt.append(c)

a = cnt[0] // 2
b = cnt[-1] // 2
c = (cnt[0] + cnt[-1]) // 2 if S[0] == S[-1] else 0
d = sum([cnt[i] // 2 for i in range(1, len(cnt) - 1)])

print(a + b + (K - 1) * c + K * d)

Submission status: Wrong Answer

Solution code:
from itertools import groupby

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

s = [ len(list(j)) for i, j in groupby(S)]
ans = 0
for i in s:
    if i >= 2:
        ans += i // 2
ans *= K
if S[0] == S[-1] and s[0] % 2 == s[-1] % 2 == 1:
    ans += K - 1

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

Submission status: Wrong Answer

Solution code:
from itertools import groupby

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

s = [ len(list(j)) for i, j in groupby(S)]
ans = 0
for i in s:
    if i >= 2:
        ans += i // 2
ans *= K
if len(s) >= 2 and S[0] == S[-1]:
    if s[0] % 2 == s[-1] % 2 == 1:
        ans += K - 1

print(ans)

Submission status: Wrong Answer

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

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

n = 0
k = 0

i = 0

if len(S) == 1:
    S = ''.join((S for _ in range(K)))
    K = 1

while(i < len(S)-1):
    if S[i] == S[i+1]:
        n += 1
        i += 2
    else:
        i += 1

if i == len(S)-1:
    if S[0] == S[-1] and K >= 2:
        n += 1
        k = -1

print(n * K + k)

Submission status: Wrong Answer

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

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

n = 0
k = 0

i = 0

if len(S) == 1:
    S = ''.join((S for _ in range(K)))
    K = 1

while(i < len(S)-1):
    if S[i] == S[i+1]:
        n += 1
        i += 2
    else:
        i += 1

if i == len(S)-1 and S[0] == S[-1] and K > 1:
    n += 1
    k = -1

print(n * K + k)

Submission status: Wrong Answer

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

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

n = 0
k = 0

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

if i == len(S)-1 and S[0] == S[-1]:
    n += 1
    if K > 1:
        k = -1

print(n * K + k)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

print(ans*k)

Submission status: Wrong Answer

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

if list(S).count(S[0])==len(S):
    print(len(S)*K//2)

else:
    S_count=0
    i=0
    while i<len(S)-1:
        if S[i]==S[i+1]:
            S_count+=1
            i+=1
        i+=1

    if S[0]==S[-1]:
        a=0
        i=0
        while i<len(S)-1:
            if S[i]==S[i+1]:
                a+=1
                i+=2
            else:
                break
        b=0
        i=len(S)-1
        while i>0:
            if S[i]==S[i-1]:
                b+=1
                i+=-2
            else:
                break

        S_count*=K
        S_count-=(K-1)*(a + b - (a+b)//2)

    else:
        S_count*=K
    print(S_count)

Submission status: Wrong Answer

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

if list(S).count(S[0])==len(S):
    print(len(S)*K//2)

else:
    S_count=0
    i=0
    while i<len(S)-1:
        if S[i]==S[i+1]:
            S_count+=1
        i+=1
    S_count//=2

    if S[0]==S[-1]:
        a=0
        i=0
        while i<len(S)-1:
            if S[i]==S[i+1]:
                a+=1
                i+=1
            else:
                break
        b=0
        i=len(S)-1
        while i>0:
            if S[i]==S[i-1]:
                b+=1
                i+=-1
            else:
                break

        S_count*=K
        S_count-=(K-1)*(a//2 + b//2 - (a+b)//2)

    else:
        S_count*=K
    print(S_count)

Submission status: Wrong Answer

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

if list(S).count(S[0])==len(S):
    print(len(S)*K//2)

else:
    S_count=0
    i=0
    while i<len(S)-1:
        if S[i]==S[i+1]:
            S_count+=1
            i+=1
        i+=1

    if S[0]==S[-1]:
        a=0
        i=0
        while i<len(S)-1:
            if S[i]==S[i+1]:
                a+=1
                i+=1
            else:
                break
        b=0
        i=len(S)-1
        while i>0:
            if S[i]==S[i-1]:
                b+=1
                i+=-1
            else:
                break

        S_count*=K
        S_count-=(K-1)*(a//2 + b//2 - (a+b)//2)
    else:
        S_count*=K
    print(S_count)

Submission status: Wrong Answer

Solution code:
import re
s = input()
k = int(input())
count= 0
if len(re.findall(r"(.)*",s))==1:
    print(len(s)*k//2)
else:
    s=list(s)
    for i in range(len(s)-1):
        if s[i]==s[i+1]:
            count+=1
            s[i+1] = "1"
    count = count*k
    if s[0]==s[-1]:
        count+=k-1
    print(count)

Submission status: Wrong Answer

Solution code:
import re
s = list(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[i+1] = "1"
    count = count*k
    if s[0]==s[-1]:
        count+=k-1
    print(count)

Submission status: Wrong Answer

Solution code:
import re
s = list(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[i+1] = "1"
    count = count*k
    if s[0]==s[-1]:
        count+=k-1
    print(s,count)