TnT/Multi_CodeNet4Repair huggingface dataset:
Problem: 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.

Submission attempts (in order):
S = input()
K = int(input())
N = len(S)

ans = 0
prev = S[0]
for i in range(1,N):
    if S[i] == prev:
        ans += 1
        prev = 0
    else:
        prev = S[i]

if K == 1:
    print(ans)
else:
    if S[0] != S[-1]:
        print(ans * K)
    else:
        ans2 = 0
        prev = 1
        for i in range(1,N):
            if S[i] == prev:
                ans += 1
                prev = 0
            else:
                prev = S[i]
        print(ans + (1+ans2) * (K-1))



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

ans = 0
prev = S[0]
endchange = False
for i in range(1,N):
    if S[i] == prev:
        ans += 1
        prev = 0
        if i == N:
            endchange = True
    else:
        prev = S[i]

if all([s == S[0] for s in S]):
    print((N*K)//2)

elif K==1 or S[0] != S[-1]:
    print(ans * K)
else:
    front = 1
    while 1:
        if S[front] == S[0]:
            front += 1
        else:break
    back = -1
    while 1:
        if S[back] == S[0]:
            back -= 1
        else:break
    back = -1-back
    print(ans*K + ((front+back)//2 - front//2 - back//2) * (K-1))


Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
s = input()
k = int(input())

prev = ""
count1 = 0
flag = 0
for i in s:
    if flag == 1:
        prev = i
        flag = 0
        continue
    if prev == i:
        count1 += 1
        flag = 1
    prev = i

prev = s[-1]
count2 = 0
flag = 0
for i in s:
    if flag == 1:
        prev = i
        flag = 0
        continue
    if prev == i:
        count2 += 1
        flag = 1
    prev = i

ret = count1 + (k-1) * count2

print(ret)

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

prev = ""
count1 = 0
count2 = 0
count3 = 0
flag = 0
for i in s:
    if flag == 1:
        prev = i
        flag = 0
        continue
    if prev == i:
        count1 += 1
        flag = 1
    prev = i



for i in s:
    if flag == 1:
        prev = i
        flag = 0
        continue
    if prev == i:
        count2 += 1
        flag = 1
    prev = i

for i in s:
    if flag == 1:
        prev = i
        flag = 0
        continue
    if prev == i:
        count3 += 1
        flag = 1
    prev = i

if k % 2 == 1:
    ret = count1 + (k-1) // 2 * (count2 + count3)
else:
    ret = count1 + ((k-1)//2+1) * count2 + (k-1)//2 * count3

print(ret)


Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
import copy

S=input()
K=int(input())
S=list(S)
n=len(S)
ans=0
j=1

def allsame(str):
    flag = True
    for i in range(len(str)-1):
        if str[i+1]!=str[i]:
            flag=False
            break;
    return flag

if S[0]!=S[n-1]:
    for i in range(n):
        if i==n-1:
            ans += j//2
            break
        if S[i+1]==S[i]:
            j += 1
        else:
            ans += j//2
            j=1
    ans = ans*K
elif allsame(S):
    ans = n*K//2
else:
    i=0
    l=1
    for i in range(n):
        if S[i+1]==S[i]:
            l += 1
        else:
            tempans =l//2
            break;
    T=copy.copy(S)
    T.reverse()
    k=1
    for i in range(n):
        if T[i+1]==T[i]:
            k += 1
        else:
            tempans +=k//2
            break;
        
    for i in range(n-l-k):
        if i==n-l-k-1:
            ans += j//2
            break;
        if S[i+l+1]==S[i+l]:
            j += 1
        else:
            ans += j//2
            j=1
    ans = (ans+l+k//2)*K
    ans = ans + tempans -(k+l)//2
    
print(ans)

import copy

S=input()
K=int(input())
S=list(S)
n=len(S)
ans=0
j=1

def allsame(str):
    flag = True
    for i in range(len(str)-1):
        if str[i+1]!=str[i]:
            flag=False
            break;
    return flag

if S[0]!=S[n-1]:
    for i in range(n):
        if i==n-1:
            ans += j//2
            break
        if S[i+1]==S[i]:
            j += 1
        else:
            ans += j//2
            j=1
    ans = ans*K
elif allsame(S):
    ans = n*K//2
else:
    i=0
    l=1
    for i in range(n):
        if S[i+1]==S[i]:
            l += 1
        else:
            tempans =l//2
            break;
    T=copy.copy(S)
    T.reverse()
    k=1
    for i in range(n):
        if T[i+1]==T[i]:
            k += 1
        else:
            tempans +=k//2
            break;
        
    for i in range(n-l-k):
        if i==n-l-k-1:
            ans += j//2
            break;
        if S[i+l+1]==S[i+l]:
            j += 1
        else:
            ans += j//2
            j=1
    ans = (ans+(l+k)//2)*K
    ans = ans + tempans -(k+l)//2
    
print(ans)

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
def solve():
    S = input()
    K = int(input())
    a = [len(tuple(s)) for _, s in groupgy(S)]
    
    if S[0] == S[-1] and K > 1:
        if len(a) == 1:
            return a[0] * K // 2
        else:
            ans = a[0] // 2 + a[-1] // 2 + (a[0]+a[-1]) // 2 * (K-1)
            ans += sum(n // 2 for n in a[1:-1]) * K
            return ans
    else:
        return sum(n // 2 for n in a) * K
    
print(solve())

from itertools import groupby

def solve():
    S = input()
    K = int(input())
    a = [len(tuple(s)) for _, s in groupgy(S)]
    
    if S[0] == S[-1] and K > 1:
        if len(a) == 1:
            return a[0] * K // 2
        else:
            ans = a[0] // 2 + a[-1] // 2 + (a[0]+a[-1]) // 2 * (K-1)
            ans += sum(n // 2 for n in a[1:-1]) * K
            return ans
    else:
        return sum(n // 2 for n in a) * K
    
print(solve())

from itertools import groupby

def solve():
    S = input()
    K = int(input())
    a = [len(tuple(s)) for _, s in groupby(S)]
    
    if S[0] == S[-1] and K > 1:
        if len(a) == 1:
            return a[0] * K // 2
        else:
            ans = a[0] // 2 + a[-1] // 2 + (a[0]+a[-1]) // 2 * (K-1)
            ans += sum(n // 2 for n in a[1:-1]) * K
            return ans
    else:
        return sum(n // 2 for n in a) * K
    
print(solve())

Verdicts: Runtime Error

Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
s = input()
k = int(input())
n = len(s)
ss = set(s)
# print(ss)
ans = 0
if n == 1:
    print(n//2)
    exit()
if len(ss) == 1:
    print(k*n//2)
    exit()
streaks = []
cnt = 0
now = s[0]
for i in range(n):
    if now == s[i]:
        cnt += 1
    else:
        streaks.append(cnt)
        now = s[i]
        cnt = 1
streaks.append(cnt)
print(streaks)
m = len(streaks)
if s[0] == s[-1]:
    for i in range(1, m-1):
        ans += streaks[i]//2
    # print(ans)
    ans *= k
    # print(ans)
    ans += (streaks[0] + streaks[m-1])//2*(k-1)
    # print(ans)
    ans += streaks[0]//2 + streaks[m-1]//2
    # print(ans)
else:
    for i in range(m):
        ans += streaks[i]//2
    ans *= k

print(ans)


s = input()
k = int(input())
n = len(s)
ss = set(s)
# print(ss)
ans = 0
if len(ss) == 1:
    print(k*n//2)
    # print('y')
    exit()
if n == 1:
    print(n//2)
    exit()
streaks = []
cnt = 0
now = s[0]
for i in range(n):
    if now == s[i]:
        cnt += 1
    else:
        streaks.append(cnt)
        now = s[i]
        cnt = 1
streaks.append(cnt)

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

print(ans)


Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
s = input()
k = int(input())
strings = ""
for i in range(k):
    strings += s
print(strings)
count = 0
for i in range(len(strings) - 2):
    tmp_str = strings[i:i+3]
    if tmp_str[0] == tmp_str[1]:
        count += 1
print(count)

s = input()
k = int(input())
if len(set(list(s))) ==1:
    print((len(s)*k)//2)
    exit()
t=[1]
for i in range(1,len(s)):
    if s[i-1]==s[i]:
        t[-1]+=1
    else:
        t.append(1)
a=0
for i in t:
    a+=(i//2)*k
if s[0]==s[-1]:
    if t[0]%2 == t[-1]%2 ==1:
        a += k-1
print(a)

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
import sys

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

if len(list(set(S))):
	print((len(S)*K)//2)
	sys.exit()

if K == 1:
	tmp = S[0]
	cnt = 0
	for i in range(1,len(S)):
		if S[i] == tmp:
			cnt += 1
			tmp = "#"
		else:
			tmp = S[i]
	print(cnt)
	sys.exit()

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

	if S[0] == tmp:
		cnt += 1
	print(cnt*K)

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

def solve(s):
	tmp = ""
	streak = 1
	cnt = 0
	for i in range(len(s)):
		if s[i] == tmp:
			streak += 1
		else:
			cnt += streak // 2
			tmp = s[i]
			streak = 1
	cnt += streak // 2
	return cnt
	

if len(list(set(list(map(str,s))))) == 1:
	ans = len(s)*k//2
elif s[0] == s[-1]:
	key_c = s[0]
	pre_ind = 0
	epi_ind = 0

	for i in range(len(s)):
		if s[i] != key_c:
			pre_ind = i-1
			break
	for i in range(len(s)):
		if s[-(i+1)] != key_c:
			epi_ind = len(s)-i
			break

	cnt_mid = solve(s[pre_ind+1:epi_ind])
	cnt_left = (pre_ind+1)//2
	cnt_right = (len(s)-epi_ind)//2
	cnt_conection = (pre_ind+1+len(s)-epi_ind)//2

	ans = cnt_left + cnt_mid*k + cnt_conection*(k-1) + cnt_right
	

elif s[0] != s[-1]:
	cnt = solve(s)
	ans = cnt * k

print(ans)

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):

def connection_count(word)->list:
    i=0
    a=[]
    count=1
    while i<(len(word)-1):
        while word[i]==word[i+1]:
            count+=1
            i+=1
            if i>=(len(word)-1):
                break
        a.append(count)
        count=1
        i+=1
    if a[-1]==1:
        a.append(count)
    return a


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

connection=[]

connection=connection_count(S)
print(connection)
if len(connection)==1:
    print(((connection[0]*K)//2))
elif S[0]!=S[-1]:
    connection2=map(lambda x:x//2,connection)
    print((sum(connection2)*K))
else:
    t=S*K
    connection3=connection_count(t)
    print(connection3)#
    connection4=map(lambda x:x//2,connection3)
    print(connection4)
    print(sum(connection4))



def connection_count(word)->list:
    i=0
    a=[]
    count=1
    while i<(len(word)-1):
        while word[i]==word[i+1]:
            count+=1
            i+=1
            if i>=(len(word)-1):
                break
        a.append(count)
        count=1
        i+=1
    if a[-1]==1:
        a.append(count)
    return a


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

connection=[]

connection=connection_count(S)
print(connection)
if len(connection)==1:
    print(((connection[0]*K)//2))
elif S[0]!=S[-1]:
    connection2=map(lambda x:x//2,connection)
    print((sum(connection2)*K))
else:
    t=S*K
    connection3=connection_count(t)
    print(connection3)#
    connection4=map(lambda x:x//2,connection3)
    print(connection4)
    print(sum(connection4))


import sys


def connection_count(word)->list:
    i=0
    a=[]
    count=1
    while i<(len(word)-1):
        while word[i]==word[i+1]:
            count+=1
            i+=1
            if i>=(len(word)-1):
                break
        a.append(count)
        count=1
        i+=1
    if a[-1]==1:
        a.append(count)
    return a


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


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


connection=connection_count(S)


if len(connection)==1:
    print(((connection[0]*K)//2))

elif S[0]!=S[-1]:
    connection2=list(map(lambda x:x//2,connection))
    print((sum(connection2)*K))

else:
    t=S*2
    connection2=list(map(lambda x:x//2,connection))
    connection3=list(connection_count(t))
    connection4=map(lambda x:x//2,connection3)
    a=sum(connection2)
    b=sum(connection4)
    ans=a+(b-a)*(K-1)
    print(ans)


Verdicts: Runtime Error

Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
def check_subseq(s):
    subseq_list = []
    tmp_length = 1
    for i in range(1, len(s)):
        if s[i - 1] == s[i]:
            tmp_length += 1
        else:
            if tmp_length >= 2:
                subseq_list.append(tmp_length)
            tmp_length = 1
        
    if tmp_length >= 2:
        subseq_list.append(tmp_length)

    return subseq_list


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

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

    i = 1
    while True:
        if s[i] != s[-1]:
            first_subseq_length = i
            break
        i += 1

    i = 1
    while True:
        if s[-(i + 1)] != s[0]:
            last_subseq_length = i
            break
        i += 1

    print(first_subseq_length, last_subseq_length)
    s = s[first_subseq_length:] + s[:first_subseq_length]
    subseq_list = check_subseq(s)
    ans = sum(map(lambda x: x // 2, subseq_list)) * k
    ans += first_subseq_length // 2 + last_subseq_length // 2 - subseq_list[-1] // 2
else:
    subseq_list = check_subseq(s)
    ans = sum(map(lambda x: x // 2, subseq_list)) * k
print(ans)



def check_subseq(s):
    subseq_list = []
    tmp_length = 1
    for i in range(1, len(s)):
        if s[i - 1] == s[i]:
            tmp_length += 1
        else:
            if tmp_length >= 2:
                subseq_list.append(tmp_length)
            tmp_length = 1
        
    if tmp_length >= 2:
        subseq_list.append(tmp_length)

    return subseq_list


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

if s[0] == s[-1]:
    if len(set(s)) == 1:
        ans = len(s) * k // 2
    else:
        i = 1
        while True:
            if s[i] != s[-1]:
                first_subseq_length = i
                break
            i += 1

        i = 1
        while True:
            if s[-(i + 1)] != s[0]:
                last_subseq_length = i
                break
            i += 1

        
        s = s[first_subseq_length:] + s[:first_subseq_length]
        subseq_list = check_subseq(s)
        ans = sum(map(lambda x: x // 2, subseq_list)) * k
        ans += first_subseq_length // 2 + last_subseq_length // 2 - subseq_list[-1] // 2
else:
    subseq_list = check_subseq(s)
    ans = sum(map(lambda x: x // 2, subseq_list)) * k
print(ans)



Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
s = str(input())
k = int(input())
 
tmp = s + s + s + s
 
c = [0]
for i in range(1, len(tmp)):
    if tmp[i] == tmp[i-1] and c[-1] == 0:
        c.append(1)
    else:
        c.append(0)
 
ans = 0
 
if k == 1:
    ans = sum(c[:len(s)])
elif k == 2:
    ans = sum(c[:2*len(s)])

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

pre_c = ''
flg = 0
count = 1

f_c = S[0]
f_e = S[-1]
t = []

for c in S:
  if c == pre_c:
    count += 1
  elif pre_c == '':
    pass
  else:
    t.append(count)
    count = 1
  pre_c = c

t.append(count)
count_1 = 0
for i in t:
  count_1 += i // 2
  
if f_c == f_e and len(t) != 1:
  t[0] = t[0] + t[-1]
  t.pop(-1)

count_2 = 0
for i in t:
  count_2 += i // 2
  
if len(S) == 1:
  print(K // 2)
elif len(t) == 1:
  print(K * len(S) // 2)
else:
  print(count_1 + count_2 * (K - 1))
  

    
  

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
S = input()
k = int(input())

ans = 0
cnt = 1

for i in range(len(S)):
    if S[i] == S[i-1]:
        cnt += 1
    else:
        ans += cnt//2
        cnt = 1
if cnt != 1:
    ans += cnt//2

print(ans*k)


S = input()
k = int(input())

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


Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
S = input()
K = int(input())
L = len(S)
a = S[0]
modi = 0
i = 0
C = []
while i < L-1:
    count = 1
    b,c = S[i],S[i+1]
    i+= 1
    while b == c:
        count += 1
        if i == L-1:
            C.append(count)
            break
        b,c = S[i],S[i+1]
        i += 1
    if i == L-1:
        break
    C.append(count)
if a != S[L-1]:
    num = 0
    for co in C:
        num += co//2
    print(int(num*K))
else:
    num1 = 0
    for co in C:
        num1 += co//2
    num2 = (C[len(C)-1]+1)//2
    for co in C[:len(C)-1]:
        num2 += co//2
        print(co,co//2)
    print(int(num1+num2*(K-1)))

S = input()
K = int(input())
L = len(S)
a = S[0]
i = 0
C = []
if L == 1:
    C = [1]
while i < L-1:
    count = 1
    b,c = S[i],S[i+1]
    i+= 1
    while b == c:
        count += 1
        if i == L-1:
            break
        b,c = S[i],S[i+1]
        i += 1
    C.append(count)
if a != S[L-1]:
    num = 0
    for co in C:
        num += co//2
    ans = int(num*K)
else:
    if len(C) == 1:
        ans  = L*K//2
    else:
        num1 = 0
        for co in C:
            num1 += co//2
        num2 = (C[len(C)-1]+C[0])//2
        for co in C[1:len(C)-1]:
            num2 += co//2
        ans = int(num1+num2*(K-1))
print(ans)

Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
S = input()
K = int(input())

print(S * K)

X = []
b = S[0]
cnt = 1
for i in range(1, len(S)):
    s = S[i]
    if b == s:
        cnt += 1
    else:
        X.append([b, cnt])
        cnt = 1
        b = s
X.append([b, cnt])

result = 0
for x in X:
    result += x[1] // 2

result = result * K
if X[0][0] == X[-1][0]:
    result += 1
print(result)


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

X = []
b = S[0]
cnt = 1
for i in range(1, len(S)):
    s = S[i]
    if b == s:
        cnt += 1
    else:
        X.append([b, cnt])
        cnt = 1
        b = s
X.append([b, cnt])

result = 0
for x in X:
    result += x[1] // 2

result = result * K
if X[0][0] == X[-1][0]:
    result += 1
print(result)


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

X = []
b = S[0]
cnt = 1
for i in range(1, len(S)):
    s = S[i]
    if b == s:
        cnt += 1
    else:
        X.append([b, cnt])
        cnt = 1
        b = s
X.append([b, cnt])

if len(X) == 1:
    print(X[0][1] * K // 2)
elif X[0][0] != X[-1][0]:
    print(sum(x[1] // 2 for x in X) * K)
else:
    s = X[0]
    e = X.pop(-1)
    if (s[1] + e[1]) % 2 == 0:
        X.append(e)
        print(sum(x[1] // 2 for x in X) * K + (K - 1))
    else:
        X[0] = [s[0], s[1] + e[1]]
        print(sum(x[1] // 2 for x in X) * K)


Verdicts: Runtime Error

Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
import random
import string

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

prev_c = ''
num_changes = 0
if S[0] == S[-1]:
    num_changes += 1
    prev_c = 'replaced'

for i, c in enumerate(S[1:]):
    if c == prev_c:
        num_changes += 1
        prev_c = 'replaced'
    else:
        prev_c = c

print(num_changes * K)


import random
import string

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

prev_c = S[0]
num_changes = 0
if S[0] == S[-1]:
    num_changes += 1
    prev_c = 'replaced'

for i, c in enumerate(S[1:]):
    if c == prev_c:
        num_changes += 1
        prev_c = 'replaced'
    else:
        prev_c = c

print(num_changes * K)


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

prev_c = S[0]
num_changes = 0
for c in S[1:]:
    if c == prev_c:
        num_changes += 1
        prev_c = 'replaced'
    else:
        prev_c = c

total_changes = 0
if len(S) == 1:
    if len(S) % 2 == 0:
        total_changes = int(K/2)
    else:
        total_changes = int((K-1)/2)
elif S[0] == prev_c and S[1] == S[0] and len(S) % 2 == 1:
    num_changes2 = 0
    for c in S:
        if c == prev_c:
            num_changes2 += 1
            prev_c = 'replaced'
        else:
            prev_c = c
    total_changes = num_changes * int(K/2 + 1) + num_changes2 * int(K/2)
elif S[0] == prev_c:
    num_changes2 = 0
    for c in S:
        if c == prev_c:
            num_changes2 += 1
            prev_c = 'replaced'
        else:
            prev_c = c
    total_changes = num_changes + num_changes2 * (K-1)
else:
    total_changes = num_changes * K

print(total_changes)


Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
S = list(input())
K = int(input())
S.extend(S)

prev = ''
cnt = 0
for s in S:
    if s == prev:
        cnt += 1
        prev = ''
    else:
        prev = s

b = 0
if K > 2 and S[0] == S[-1]:
    mae = 1
    while S[mae] == S[0]:
        mae += 1
    if mae % 2 == 1 and mae != len(S):
        usiro = 1
        i = len(S) - 2
        while S[i] == S[-1]:
            usiro += 1
            i -= 1
        if usiro % 2 == 1:
            b = K // 2

if K % 2 == 0:
    res = cnt * (K // 2) + (b - 1)
else:
    res = cnt * (K // 2) + cnt // 2 + b
print(res)


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

prev = ''
cnt = 0
for s in S:
    if s == prev:
        cnt += 1
        prev = ''
    else:
        prev = s

b = 0
if K % 2 == 0:
    b += 1
if K > 2 and S[0] == S[-1]:
    mae = 1
    while mae < len(S) and S[mae] == S[0]:
        mae += 1
    if mae % 2 == 1 and mae != len(S):
        usiro = 1
        i = len(S) - 2
        while S[i] == S[-1]:
            usiro += 1
            i -= 1
        if usiro % 2 == 1:
            b = K // 2

if K % 2 == 0:
    res = cnt * (K // 2) + (b - 1)
else:
    res = cnt * (K // 2) + cnt // 2 + b
print(res)


Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
s = input()
k = int(input())
n = len(s)
if n == 1:
    if k == 1:
        print(0)
    else:
        print(k//2)
else:
    ans = []
    ss = 0
    i = 0
    while True:
        if i == n:
            break
        curr = s[i]
        temp = 1
        i += 1
        if i == n :
            ans.append(temp)
            break
        while s[i] == curr:
            temp += 1
            i += 1
            if i == n:
                break
        ans.append(temp)
    print(ans)
    if len(ans) > 1:
        for i in ans:
            ss += (i//2)*k
        if s[0] == s[-1] and ans[0]%2 == ans[-1]%2 == 1:
            ss += k-1
    else:
        ss = (n//2)*k
    print(ss)

s = input()
k = int(input())
n = len(s)
if n == 1:
    if k == 1:
        print(0)
    else:
        print(k//2)
else:
    ans = []
    ss = 0
    i = 0
    while True:
        if i == n:
            break
        curr = s[i]
        temp = 1
        i += 1
        if i == n :
            break
        while s[i] == curr:
            temp += 1
            i += 1
            if i == n:
                break
        ans.append(temp)
    print(ans)
    if len(ans) > 1:
        for i in ans:
            ss += (i//2)*k
        if s[0] == s[-1] and ans[0]%2 == ans[-1]%2 == 1:
            ss += k-1
    else:
        ss = (n//2)*k
    print(ss)


s = input()
k = int(input())
n = len(s)
if n == 1:
    if k == 1:
        print(0)
    else:
        print(k//2)
else:
    ans = []
    ss = 0
    i = 0
    while True:
        if i == n:
            break
        curr = s[i]
        temp = 1
        i += 1
        if i == n :
            break
        while s[i] == curr:
            temp += 1
            i += 1
            if i == n:
                break
        ans.append(temp)
    if len(ans) > 1:
        for i in ans:
            ss += (i//2)*k
        if s[0] == s[-1] and ans[0]%2 == ans[-1]%2 == 1:
            ss += k-1
    else:
        ss = n*k//2
    print(ss)

Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
#!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()


#!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:
        if cn > 1:
            ans += cn // 2
        ans *= K
    else:
        ans = ans * K + ((i0+cn)//2) * (K-1) + i0//2 + cn//2


    print(ans)

if __name__ == "__main__":
    resolve()


Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
S = input()
K = int(input())

length = len(S)

num_correct = 0
pre_char = ''
count = 0
for i in range(length):
    now_char = S[i]
    if pre_char != now_char:
        num_correct += count//2
        count = 0
    else:
        count += 1
    pre_char = now_char
num_correct += count//2

# print(num_correct)

if S[0] == S[length - 1]:
    head_length = 1
    head_char = S[0]
    for i in range(1, length):
        now_char = S[i]
        if now_char != head_char:
            break
        head_length += 1
    tail_length = 1
    tail_char = S[length - 1]
    for i in range(1, length):
        now_char = S[length - 1 - i]
        if now_char != tail_char:
            break
        tail_length += 1
    if length == head_length == tail_length:
        ans = num_correct * K
    else:
        ans = K * num_correct - (K - 1) * (head_length // 2 + tail_length // 2 - (head_length + tail_length) // 2)
else:
    ans = num_correct * K

print(ans)


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

length = len(S)

num_fixed = 0
pre_char = ''
count = 0
for i in range(length):
    now_char = S[i]
    if pre_char != now_char:
        num_fixed += count//2
        count = 0
    count += 1
    pre_char = now_char
    # print("pre_char:{}, now_char:{}, count:{}".format(pre_char, now_char, count))
num_fixed += count//2

# print(num_fixed)

if S[0] == S[length - 1]:
    head_length = 1
    head_char = S[0]
    for i in range(1, length):
        now_char = S[i]
        if now_char != head_char:
            break
        head_length += 1
    tail_length = 1
    tail_char = S[length - 1]
    for i in range(1, length):
        now_char = S[length - 1 - i]
        if now_char != tail_char:
            break
        tail_length += 1
    if length == head_length == tail_length:
        ans = length * K // 2
    else:
        ans = K * num_fixed - (K - 1) * (head_length // 2 + tail_length // 2 - (head_length + tail_length) // 2)
else:
    ans = num_fixed * K

print(ans)


Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
s = input()
k = int(input())
import math

if len(s) == 1:
    print(math.floor(k/2))
    exit()
if len(s) == 2:
    if s[0] == s[1]:
        print(k)
        exit()
    else:
        print(0)

ans=0
last=s[0]
length=1
change=0
for i in range(1,len(s)):
    if s[i] == last:
        length+=1
    else:
        change += math.floor(length/2)
        length=1
    last=s[i]

change += math.floor(length/2)

ans=change*k
if s[0] != s[-1]:
    print(ans)
    exit()

if s[0] != s[1] or s[-1] != s[-2]:
    print(ans+k-1)
    exit()

print(ans)

s = input()
k = int(input())
import math

if len(s) == 1:
    print(math.floor(k/2))
    exit()
if len(s) == 2:
    if s[0] == s[1]:
        print(k)
        exit()
    else:
        print(0)
        exit()

ans=0
last=s[0]
length=1
change=0
for i in range(1,len(s)):
    if s[i] == last:
        length+=1
    else:
        change += math.floor(length/2)
        length=1
    last=s[i]

change += math.floor(length/2)

ans=change*k
if s[0] != s[-1]:
    print(ans)
    exit()

for i in range(10**10):
    3*4

if s[0] != s[1] and s[-1] != s[-2]:
    print(ans+k-1)
    exit()

print(ans)

s = input()
k = int(input())
import math

if len(s) == 1:
    print(math.floor(k/2))
    exit()
if len(s) == 2:
    if s[0] == s[1]:
        print(k)
        exit()
    else:
        print(0)
        exit()

ans=0
last=s[0]
length=1
change=0
for i in range(1,len(s)):
    if s[i] == last:
        length+=1
    else:
        change += math.floor(length/2)
        length=1
    last=s[i]

change += math.floor(length/2)

ans=change*k
if s[0] != s[-1]:
    print(ans)
    exit()


if s[0] != s[1] and s[-1] != s[-2]:
    print(ans+k-1)
    exit()
for i in range(10**10):
    3*4

print(ans)

s = input()
k = int(input())
import math
if len(set(list(s))) == 1:
    print(len(s) * k // 2)
    exit()
last=s[0]
length=1
change=0
for i in range(1,len(s)):
    if s[i] == last:
        length+=1
    else:
        change += math.floor(length/2)
        length=1
    last=s[i]

change += math.floor(length/2)
ans=change*k
if s[0] != s[-1]:
    print(ans)
    exit()

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

if l_length%2==1 and r_length%2==1:
    print(ans+k-1)
    exit()
print(ans)

Verdicts: Wrong Answer

Time Limit Exceeded

Time Limit Exceeded

Accepted
Problem: 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.

Submission attempts (in order):
s = list(input())
k = int(input())
n = len(s)
count = 0
c = 1
now = 1
while now < n:
    if s[now] == s[now-1]:
        c += 1
    else:
        break
    now += 1
if now == n:
    print(n*k//2)
    exit()
count += c//2
now2 = n-2
c2 = 1
while now2 >= 0:
    if s[now2] == s[now2+1]:
        c2 += 1
    else:
        break
    now2 -= 1
count += c2//2
if s[0] == s[-1]:
    count += ((c+c2)//2)*(k-1)
c3 = 0

for i in range(now,now2):
    if s[i] == s[i-1]:
        c3 += 1
        s[i] = "1"
count += c3*k

print(count)




import copy
s = list(input())
n = len(s)
s2 = copy.deepcopy(s)
la = s[-1]
for i in range(n):
    if s[i] == la:
        s2.append(la)
    else:
        break

n2 = len(s2)
k = int(input())
if n2 == 2*n:
    print(n*k//2)
    exit()
count = 0
for i in range(n2-n+1,n2):
    if s2[i] == s2[i-1]:
        s2[i] = "1"
        count += 1
ans = k*count
c = 1
for i in range(n-2,-1,-1):
    if s[i] == s[i+1]:
        c += 1

if c > 1 and c%2:
    ans -= 1
print(ans)





import copy
s = list(input())
n = len(s)
s2 = copy.deepcopy(s)
la = s[-1]
for i in range(n):
    if s[i] == la:
        s2.append(la)
    else:
        break

n2 = len(s2)
k = int(input())
if n2 == 2*n:
    print(n*k//2)
    exit()
count = 0
for i in range(n2-n+1,n2):
    if s2[i] == s2[i-1]:
        s2[i] = "1"
        count += 1
ans = k*count

c = 0

for i in range(n-1,-1,-1):
    if la == s[i]:
        c += 1

if n2 > n and c > 1 and c%2:
    ans -= 1
print(ans)





import copy
s = list(input())
n = len(s)
s2 = copy.deepcopy(s)
la = s[-1]
for i in range(n):
    if s[i] == la:
        s2.append(la)
    else:
        break

n2 = len(s2)
k = int(input())
if n2 == 2*n:
    print(n*k//2)
    exit()
count = 0
for i in range(n2-n+1,n2):
    if s2[i] == s2[i-1]:
        s2[i] = "1"
        count += 1
ans = k*count

c = 0

for i in range(n-1,-1,-1):
    if la == s[i]:
        c += 1
    else:
        break

if n2 > n and (n2-n)%2 and c > 1 and c%2:
    ans -= 1
print(ans)

Verdicts: Wrong Answer

Wrong Answer

Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
S = input()
K = int(input())

a = S[0]
c = 0
g = []

for i in range(len(S)):
    if a == S[i]:
        c += 1
    else:
        g.append(c)
        a = S[i]
        c = 1

g.append(c)

if len(g) == 1:
    c = len(S) * K / 2
elif S[0] == S[-1]:
    c = int(g[0] / 2)
    c += int(g[-1] / 2)

    for i in range(1, len(g) - 1):
        c += int(g[i] / 2) * (K - 1)
else:
    c = 0
    for i in g:
        c += int(i / 2) * K


print(int(c))



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

a = S[0]
c = 0
g = []

for i in range(len(S)):
    if a == S[i]:
        c += 1
    else:
        g.append(c)
        a = S[i]
        c = 1

g.append(c)

if len(g) == 1:
    c = len(S) * K / 2
elif S[0] == S[-1]:
    c = int(g[0] / 2)
    c += int(g[-1] / 2)

    for i in range(1, len(g) - 1):
        c += int(g[i] / 2) * K
else:
    c = 0
    for i in g:
        c += int(i / 2) * K


print(int(c))



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

a = S[0]
c = 0
g = []

for i in range(len(S)):
    if a == S[i]:
        c += 1
    else:
        g.append(c)
        a = S[i]
        c = 1

g.append(c)

if len(g) == 1:
    c = len(S) * K / 2
elif S[0] == S[-1]:
    c = int(g[0] / 2)
    c += int(g[-1] / 2)
    c += int((g[0]+g[-1]) / 2) * (K-1)

    for i in range(1, len(g) - 1):
        c += int(g[i] / 2) * K
else:
    c = 0
    for i in g:
        c += int(i / 2) * K


print(int(c))



Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
s = input()
k = int(input())

l = list(s)

count = 0
new_l = l.copy()
for i, c in enumerate(s[1:]):
    if c == new_l[i]:
        new_l[i + 1] = 0
        count += 1
result = count * k
if s[0] == s[-1]:
    result = +k - 1
print(result)


def cad(s, k):
    if len(s) == 1:
        return k // 2
    if len(set(s)) == 1:
        return len(s) * k // 2

    l = list(s)

    count = 0
    new_l = l.copy()

    first_len = 1
    first_block = True
    for i, c in enumerate(s[1:]):
        if c == new_l[i]:
            new_l[i + 1] = 0
            count += 1

        if first_block:
            if c == s[0]:
                first_len += 1
            else:
                first_block = False

    result = count * k

    if new_l[0] == new_l[-1] and first_len % 2 == 1:
        result += k - 1

    return result


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


Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
s=str(input())
k=int(input())
count=1
ans=0
s2=s+s
ans2=0
#print(s2)
for i in range(len(s)-1):
    if s[i]==s[i+1]:
        count+=1
    else:
        if 2<=count:
            ans+=count//2
        count=1
if 2<=count:
    ans+=count//2
count=1
for i in range(len(s2)-1):
    if s2[i]==s2[i+1]:
        count+=1
    else:
        if 2<=count:
            ans2+=count//2
        count=1

if 2<=count:
    ans2+=count//2
    #print(count)
#print(ans,ans2)
if s[0]==s[-1]:
    print((ans2-ans)*k+ans)
else:
    print(ans*k)

s=str(input())
k=int(input())
ans=0
count=1
c1=0
c2=0

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

if s[0]==s[-1]:
    for i in range(len(s)-1):
        if s[i]==s[i+1]:
            count+=1
        else:
            if 2<=count:
                ans+=count//2
            count=1
    ans+=count//2
    i=0
    while s[i]==s[0]:
        c1+=1
        i+=1
    
    i=len(s)-1
    while s[i]==s[-1]:
        c2+=1
        i-=1
    #print(c1,c2)
    ans*=k
    if c1%2==1 and c2%2==1:
        ans+=k-1

    print(ans)


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

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
s = list(input())
k = int(input())
ans = 0

if s[0] != s[-1]:
    for i in range(len(s)-1):
        if s[i] == s[i + 1]:
            s[i+1] = "OK"
            ans += 1
    print(ans * k)

else:
    if len(set(s)) == 1:
        if len(s) % 2 == 0:
            print((len(s) // 2) * k)
        else:
            print(len(s) * (k // 2) if k %
                  2 == 0 else len(s) * (k // 2) + (len(s) // 2))
    else:
        mae = 1
        for i in range(len(s) - 1):
            if s[i] == s[i + 1]:
                mae += 1
            else:
                break

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

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

        ans_ = 0
        for i in range(mae, len(s) - ushiro):
            if s[i] == "OK":
                ans_ += 1
        print(((mae + ushiro) // 2 * (k - 1)), ans_ * (k - 1), ans)
        print(((mae + ushiro) // 2 * (k - 1)) + ans_ * (k - 1) + ans)


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

if s[0] != s[-1]:
    for i in range(len(s)-1):
        if s[i] == s[i + 1]:
            s[i+1] = "OK"
            ans += 1
    print(ans * k)

else:
    if len(set(s)) == 1:
        if len(s) % 2 == 0:
            print((len(s) // 2) * k)
        else:
            print(len(s) * (k // 2) if k %
                  2 == 0 else len(s) * (k // 2) + (len(s) // 2))
    else:
        mae = 1
        for i in range(len(s) - 1):
            if s[i] == s[i + 1]:
                mae += 1
            else:
                break

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

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

        ans_ = 0
        for i in range(mae, len(s) - ushiro):
            if s[i] == "OK":
                ans_ += 1
        print(((mae + ushiro) // 2 * (k - 1)) + ans_ * (k - 1) + ans)

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
# AGC039
S = list(input())
K = int(input())
N = len(S)
ans = 0
cnt = 0
if S[0] == S[-1]:
    S[-1] = "#"
    ans += 1
    cnt += 1
for i in range(N-1):
    if S[i] == S[i+1]:
        S[i+1] = "!"
        ans += 1
print(ans * K - cnt)

def RanLengthEncoding(S):
    N = len(S)
    RLE = []
    now_char = S[0]
    now_cnt = 1
    for i in range(1, N):
        if now_char == S[i]:
            now_cnt += 1
        else:
            RLE.append([now_char, now_cnt])
            now_char = S[i]
            now_cnt = 1
    RLE.append([now_char, now_cnt])
    return RLE

S = input()
K = int(input())
rle = RanLengthEncoding(S)
if len(rle) == 1:
    ans = rle[0][1] * K // 2
    print(ans)
    exit()
cnt = 0
for i in range(1, len(rle)-1):
    cnt += rle[i][1] // 2

if rle[0][0] != rle[-1][0]:
    cnt += rle[0][1] // 2
    cnt += rle[-1][1] // 2
    ans = cnt * K
else:
    tmp = (rle[0][1] + rle[-1][1]) // 2
    ans = cnt * K
    ans += tmp * (K-1)
    ans += rle[0][1] // 2
    ans += rle[-1][1] // 2
print(ans)

Verdicts: Wrong Answer

Accepted