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):
import re
import sys
import copy

s = input()
k = int(input())
count01=0
count02=0

#case01
if len(s)==1:
  print(k//2)
  sys.exit(0)
  
#case02
tmp = s[0]
flag=True
for i in range(len(s)):
  if s[i]!=tmp:
    flag=False
if flag==True:
  print((len(s)*k)//2)
  sys.exit(0)

s2 = copy.deepcopy(s)
if s[0]==s[-1]:
  tmp = s[0]

  offset01=0
  while s[0]==tmp:
    offset01+=1
    s = s[1:] + s[0]
    #print(s)
  offset02=0
  while s2[-1]==tmp:
    offset02+=1
    s2 = s2[-1] + s2[:-1]
    #print(s2)
  
  count01 += (offset01//2 + offset02//2)
  k -= 1

pattern = "a+|b+|c+|d+|e+|f+|g+|h+|i+|j+|k+|l+|m+|n+|o+|p+|q+|r+|s+|t+|u+|v+|w+|x+"
result = re.finditer(pattern, s)
for res in result:
  l = res.end()-res.start()
  if l>1:
    
    count02 += l//2
    #print(count)

print(count01 + count02*k)

import re
import sys
import copy

def get_count(s):
  count02=0
  pattern = "a+|b+|c+|d+|e+|f+|g+|h+|i+|j+|k+|l+|m+|n+|o+|p+|q+|r+|s+|t+|u+|v+|w+|x+|y+|z+"
  result = re.finditer(pattern, s)
  for res in result:
    print(res.group())
    l = res.end()-res.start()
    if l>1:
      
      count02 += l//2
  return count02

s = input()
k = int(input())
count01=0
count02=0

#case01
if len(s)==1:
  print(k//2)
  sys.exit(0)
  
#case02
tmp = s[0]
flag=True
for i in range(len(s)):
  if s[i]!=tmp:
    flag=False
if flag==True:
  print((len(s)*k)//2)
  sys.exit(0)

#case03
s_org = copy.deepcopy(s)
s2 = copy.deepcopy(s)
if s[0]==s[-1]:
  tmp = s[0]

  offset01=0
  while s[0]==tmp:
    offset01+=1
    s = s[1:] + s[0]
    #print(s)
  offset02=0
  while s2[-1]==tmp:
    offset02+=1
    s2 = s2[-1] + s2[:-1]
    #print(s2)
  k -= 1
  print(">", s_org[:offset01])
  print(">", s, k)
  print(">", s_org[offset01:])
  print(get_count(s_org[:offset01]) + get_count(s)*k + get_count(s_org[offset01:]))
  sys.exit(0)

  
#case04
print(get_count(s)*k)


import re
import sys
import copy

def get_count(s):
  count02=0
  pattern = "a+|b+|c+|d+|e+|f+|g+|h+|i+|j+|k+|l+|m+|n+|o+|p+|q+|r+|s+|t+|u+|v+|w+|x+|y+|z+"
  result = re.finditer(pattern, s)
  for res in result:
    l = res.end()-res.start()
    if l>1:
      
      count02 += l//2
  return count02

s = input()
k = int(input())
count01=0
count02=0

#case01
if len(s)==1:
  print(k//2)
  sys.exit(0)
  
#case02
tmp = s[0]
flag=True
for i in range(len(s)):
  if s[i]!=tmp:
    flag=False
if flag==True:
  print((len(s)*k)//2)
  sys.exit(0)

#case03
s_org = copy.deepcopy(s)
s2 = copy.deepcopy(s)
if s[0]==s[-1]:
  tmp = s[0]

  offset01=0
  while s[0]==tmp:
    offset01+=1
    s = s[1:] + s[0]
    #print(s)
  offset02=0
  while s2[-1]==tmp:
    offset02+=1
    s2 = s2[-1] + s2[:-1]
    #print(s2)
  k -= 1
  print(get_count(s_org[:offset01]) + get_count(s)*k + get_count(s_org[offset01:]))
  sys.exit(0)

  
#case04
print(get_count(s)*k)


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

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

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

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


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

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

print(count)

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





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

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

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

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


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

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


if (re_same + same) % 2 == 0 and s[0] == s[len(s)-1]:
    print(count*k + k - 1)
else:
    print(count*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 = input()
K = int(input())

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

b = [1]
for i in S[:-1]:
    if S[i] == S[i+1]:
        b[-1] += 1
    else:
        b.append(1)

ans = 0
for i in b:
    ans += i//2
ans *= K

if S[0] == S[-1] and b[0]%2 == b[-1]%2 == 1:
    ans += K - 1
print(ans)

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

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

b = [1]
for i in range(len(S)-1):
    if S[i] == S[i+1]:
        b[-1] += 1
    else:
        b.append(1)

ans = 0
for i in b:
    ans += i//2
ans *= K

if S[0] == S[-1] and b[0]%2 == b[-1]%2 == 1:
    ans += 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())
cnt=1
temp=[]
for i in range(len(s)-1):
    if s[i]==s[i+1]: cnt+=1
    else:
        temp.append([s[i],cnt])
        cnt=1
if cnt>=1: temp.append([s[-1],cnt])
if len(temp)==1:
    print(k*len(s)//2)
    exit()
ans=0
if temp[0][0]!=temp[-1][0]:
    for pair in temp:
        if pair[1]!=1: ans+=pair[1]//2
    print(ans*k)
else:
    for pair in temp[1:-1]:
        if pair[1]!=1: ans+=pair[1]//2
    ans*=k
    ans+=(k-1)*((temp[0][0]+temp[-1][0])//2)
    ans+=temp[0][0]//2+temp[-1][0]//2
    print(ans)

s=input()
k=int(input())
cnt=1
temp=[]
for i in range(len(s)-1):
    if s[i]==s[i+1]: cnt+=1
    else:
        temp.append([s[i],cnt])
        cnt=1
if cnt>=1: temp.append([s[-1],cnt])
if len(temp)==1:
    print(k*len(s)//2)
    exit()
ans=0
if temp[0][0]!=temp[-1][0]:
    for pair in temp:
        if pair[1]!=1: ans+=pair[1]//2
    print(ans*k)
else:
    for pair in temp[1:-1]:
        if pair[1]!=1: ans+=pair[1]//2
    ans*=k
    ans+=(k-1)*((temp[0][1]+temp[-1][1])//2)
    ans+=temp[0][1]//2+temp[-1][1]//2
    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())
count = 0
count2 = 1
count3 = 1
flag = 0
flag2 = 0
if len(S) == 1:
    print(K // 2)
else:
    for i in range(len(S)-1):
        if S[i] == S[i+1] and flag == 0:
            count += 1
            flag = 1
        else:
            flag = 0
        if S[i] != S[i+1]:
            flag2 = 1
    num = count * K
    if flag2 == 0:
        print(len(S) * K //2)
    else:

        if S[0] == S[-1]:
            if len(S) == 2:
                print(num)
            else:
                for i in range(len(S)-1):
                    if S[i] == S[i+1]:
                        count2 += 1
                for i in range(len(S)-1, 0, -1):
                    if S[i] == S[i-1]:
                        count3 += 1
                if count2 % 2 != 0 and count3 % 2 != 0:
                    print(num + K - 1)
                else:
                    print(num)
        else:
            print(num)


S = input()
K = int(input())
count = 0
count2 = 1
count3 = 1
flag = 0
flag2 = 0
if len(S) == 1:
    print(K // 2)
else:
    for i in range(len(S)-1):
        if S[i] == S[i+1] and flag == 0:
            count += 1
            flag = 1
        else:
            flag = 0
        if S[i] != S[i+1]:
            flag2 = 1
    num = count * K
    if flag2 == 0:
        print(len(S) * K //2)
    else:

        if S[0] == S[-1]:
            if len(S) == 2:
                print(num)
            else:
                flag3 = 0
                for i in range(len(S)-1):
                    if S[i] == S[i+1] and flag3 == 0:
                        count2 += 1
                    else:
                        flag3 = 1
                flag3 = 0
                for i in range(len(S)-1, 0, -1):
                    if S[i] == S[i-1] and flag3 == 0:
                        count3 += 1
                    else:
                        flag3 = 1
                if count2 % 2 != 0 and count3 % 2 != 0:
                    print(num + K - 1)
                else:
                    print(num)
        else:
            print(num)


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 = list(input())
K = int(input())


a = S[0]
c = 0
S2 = copy.deepcopy(S)
for i in range(1,len(S)):
    if S2[i] == S2[i-1]:
        S2[i] = '1'
        c += 1

if S[0] == S[-1]:
    c3 = 0
    S3 = copy.deepcopy(S)
    for i in range(2,len(S)):
        if S3[i] == S3[i-1]:
            S3[i] = '1'
            c3 += 1
    print(c + (c3+1)*(K-1))
else:
    print(c*K)



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


a = S[0]
c = 0
S2 = copy.deepcopy(S)
for i in range(1,len(S)):
    if S2[i] == S2[i-1]:
        S2[i] = '1'
        c += 1

a = S[-1]
last = 1
for i in range(2,len(S)+1):
    last += 1
    if S[-i] != a:
        break


if S[0] == S[-1] and last%2==1:
    c3 = 0
    S3 = copy.deepcopy(S)
    for i in range(2,len(S)):
        if S3[i] == S3[i-1]:
            S3[i] = '1'
            c3 += 1
    print(c + (c3+1)*(K-1))
else:
    print(c*K)



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


a = S[0]
c = 0
S2 = copy.deepcopy(S)
for i in range(1, len(S)):
    if S2[i] == S2[i-1]:
        S2[i] = '1'
        c += 1

a = S[-1]
last = 0
for i in range(2, len(S)+1):
    last += 1
    if S[-i] != a:
        break

if all([e == S[0] for e in S[1:]]) == True:
    if len(S)%2==0:
        print(int(len(S)/2*K))
    else:
        print(int(len(S)//2*((K+1)//2)+(len(S)//2+1)*(K//2)))
elif S[0] == S[-1] and last % 2 == 1:
    c3 = 0
    S3 = copy.deepcopy(S)
    for i in range(2, len(S)):
        if S3[i] == S3[i-1]:
            S3[i] = '1'
            c3 += 1
    print(c + (c3+1)*(K-1))
else:
    print(c*K)


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

#

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

#

#
if s[0] != s[-1]:
    cnt = 0
    bf_same = False
    tmp = 1
    for i in range(len(s) - 1):
        if s[i] == s[i + 1]:
            tmp += 1
        else:
            if tmp > 1:
                cnt += (tmp // 2) * k
                tmp = 1
    else:
        if tmp > 1:
            cnt += (tmp // 2) * k
        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
bf_same = False
tmp = 1
for i in range(tp_idx + 1, bt_idx - 1):
    if s[i] == s[i + 1]:
        tmp += 1
    else:
        if tmp > 1:
            cnt += (tmp // 2) * k
            tmp = 1
else:
    if tmp > 1:
        cnt += (tmp // 2) * k

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


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
    tmp = 1
    for i in range(len(s) - 1):
        if s[i] == s[i + 1]:
            tmp += 1
        else:
            if tmp > 1:
                cnt += (tmp // 2) * k
                tmp = 1
    else:
        if tmp > 1:
            cnt += (tmp // 2) * k
        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
bf_same = False
tmp = 1
for i in range(tp_idx + 1, bt_idx - 1):
    if s[i] == s[i + 1]:
        tmp += 1
    else:
        if tmp > 1:
            cnt += (tmp // 2) * k
            tmp = 1
else:
    if tmp > 1:
        cnt += (tmp // 2) * k

#print(tp, bt, cnt)
#print(tp // 2 + bt // 2 + ((tp + bt) // 2) * (k - 1))
ans = cnt + tp // 2 + bt // 2 + ((tp + bt) // 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=list(input())
K=int(input())

P=0
if len(S)==1:
	P=K//2
else:
	for G in range(1,len(S):
		B=S[G-1]
		if S[G] in B:
			S[G]='O'
			P+=1
		else:
			continue
	P=P*K
	if S[0]==S[len(S)-1]:
		P+=K-1
print(P)

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

P=0
if len(S)==1:
	P=K//2
else:
	for G in range(1,len(S):
		B=S[G-1]
		if S[G] in B:
			S[G]='O'
			P+=1
		else:
			continue
	P=P*K
	if S[0]==S[len(S)-1]:
		P+=K-1
print(P)
S=list(input())
K=int(input())
P=0
if len(S)==1:
	P=K//2
else:
	for G in range(1,len(S)):
		B=S[G-1]
		if S[G] in B:
			S[G]='O'
			P+=1
		else:
			continue
	P=P*K
	if S[0]==S[len(S)-1]:
		P+=K-1
print(P)

S=list(input())
K=int(input())
SS=S*2
F=S[0]
if len(S)==1:
	P=int(K//2)
elif S==[F]*len(S):
	P=int((len(S))*K//2)
else:
	for G in range(1,len(S)):
		if S[G-1]==S[G]:
			S[G]="O"
		else:
			continue
	A=S.count("O")
	for J in range(1,len(SS)):
		if SS[J-1]==SS[J]:
			SS[J]="O"
		else:
			continue
	B=SS.count("O")
	P=A+(B-A)*(K-1)
print(P)

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):
#include <bits/stdc++.h>
using namespace std;


#define all(it) it.begin(), it.end()




lint INF = 2e18;
lint MOD = 1e9 + 7;

lint i, j, k, t;

int main() {
    string S;
    lint K;

    cin >> S >> K;

    S += S[0];

    lint cnt = 0;
    regex re(R"(([a-z])\1{0,})");

    for(sregex_iterator it(all(S), re), end; it != end; ++it) {
        auto &&m = *it;
        cnt += m.length() / 2;
    }

    cout << cnt * K << endl;
}

#!/usr/bin/env python3

# from numba import njit

# input = stdin.readline

def countProcedure(string):
  res = 0
  strCount = 1
  prev = "" 
  for i in range(len(string)):
    if string[i] == prev:
      strCount += 1
    else:
      res += strCount // 2
      strCount = 1
    prev = string[i]

  if strCount != 1:
    res += strCount // 2
  return res

def solve(s,k):
  if s[0] != s[-1]:
    return countProcedure(s)*k
  if all(x == s[0] for x in s):
    return len(s)*k//2
  else:
    leftLength = max(i for i in range(1,len(s)) if s[:i]== s[0]*i)
    left = s[0]*leftLength
    right = s[leftLength:]
    ans = countProcedure(left) + countProcedure(right) + countProcedure("".join([right,left]))*(k-1)
    return ans


def main():
  S = input()
  K = int(input())
  # N,M = map(int,input().split())
  # a = list(map(int,input().split()))
  print(solve(S,K))
  
  
if __name__ == '__main__':
  main()


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()
n = len(s)
K = int(input())
L = 2
t = list(s*L)
s = list(s)
m = len(t)
cnt = 0
c = 0
for i in range(1, m):
    if t[i] == t[i-1]:
        t[i] = 'A'
        cnt+=1
for i in range(1, n):
    if s[i] == s[i-1]:
        s[i] = 'A'
        c+=1
res = c+(cnt-c)//L*(K-1)
if n == 1:
    res = K//2
print(res)


s = input()
check = False
if len(set(s)) == 1:
    check = True
n = len(s)
K = int(input())
s = s*2
s = list(s)
cnt = 0
for i in range(1, len(s)):
    if s[i] == s[i-1]:
        s[i] = 'A'
        cnt += 1
res = 0
if cnt % 2 == 1:
    res = (cnt//2)*K + K-1
else:
    res = cnt//2 * K
if check:
    res = n * K // 2
if n == 1:
    res = K//2
print(res)

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())
n=len(s)
cnt=1
ans=0
l=[]
for i in range(n-1):
  if s[i]==s[i+1]:
    cnt+=1
  else:
    l.append(cnt)
    cnt=1
l.append(cnt)
if len(l)==1:
  print(k*sum(l)//2)
else:
  if s[0]!=s[n-1]:
    for i in range(len(l)):
      ans+=k*(l[i]//2)
  else:
    for i in range(1,len(l)-1):
      ans+=k*(l[i]//2)
    ans+=(k-1)*((l[0]+l[len(l)-1])//2)
    ans+=l[0]//2+l[len(l)-1]//2
  print(ans)
  print(l)

s=input()
k=int(input())
n=len(s)
cnt=1
ans=0
l=[]
for i in range(n-1):
  if s[i]==s[i+1]:
    cnt+=1
  else:
    l.append(cnt)
    cnt=1
l.append(cnt)
if len(l)==1:
  print(k*sum(l)//2)
else:
  if s[0]!=s[n-1]:
    for i in range(len(l)):
      ans+=k*(l[i]//2)
  else:
    for i in range(1,len(l)-1):
      ans+=k*(l[i]//2)
    ans+=(k-1)*((l[0]+l[len(l)-1])//2)
    ans+=l[0]//2+l[len(l)-1]//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):
S = list(input())
K = int(input())
cnt = 1
ans = 0
counter = []

if len(S) == 1:
  print(K//2)
  exit()
  
else:
  for i in range(len(S)-1):
    if S[i] == S[i+1]:
      cnt += 1
    else:
      counter.append(cnt)
      cnt = 1
  counter.append(cnt)
    
  for l in counter:
    ans += l//2*K
  print(ans)
  if S[0] == S[-1]:
    a = counter[0]
    b = counter[-1]
    ans -= (a//2 + b//2 - (a+b)//2)*(K-1)
  
  print(ans)

S = list(input())
K = int(input())
cnt = 1
ans = 0
counter = []

if len(S) == 1:
  print(len(S)*K//2)
  exit()
  
else:
  for i in range(len(S)-1):
    if S[i] == S[i+1]:
      cnt += 1
    else:
      counter.append(cnt)
      cnt = 1
  counter.append(cnt)
    
  for l in counter:
    ans += l//2

  if S[0] == S[-1]:
    a = counter[0]
    b = counter[-1]
    ans -= (a//2 + b//2 - (a+b)//2)*(K-1)
  
  print(ans)

s = list(input())
k = int(input())
a = '0'
cnt = 0
flag = 1
out = 0

for i in range(len(s)-1):
    if s[i] == s[i+1]:
        s[i+1] = a
        cnt += 1

    if s[0] == s[len(s)-1]:
        cnt += 1
        flag = -1

out = cnt * k

if flag == -1:
    out -= 1
if len(s) >= 2:
	print(out)
if len(s) == 1:
  print(k//2)


S = list(input())
K = int(input())
cnt = 1
ans = 0
counter = []

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

  if S[0] == S[-1]:
    a = counter[0]
    b = counter[-1]
    ans -= (a//2 + b//2 - (a+b)//2)*(K-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())
l=len(s)
now=1
seq=[]
re=False
all=False
for i in range(l):
    if s[i%l]==s[(i+1)%l]:
        now+=1
        if i==l-1:
            re=True
            if len(seq)==0:
                all=True
            else:
                first=seq[0]//2
                end=now//2
                seq[0]=(seq[0]+now)
    else:
        seq.append(now)
        now=1
if all:
    ans=len(s)*k//2
else:
    seq=[i//2 for i in seq]
    if re:
        ans=sum(seq)*k-seq[0]+first+end
    else:
        ans=sum(seq)*k

print(ans)

S = input()
K = int(input())
cnt = 0
for i in range(len(S)-1):
    if (S[i]==S[i+1])&&(S[i-1]!=S[i]):
        cnt += K
print(cnt)

S = input()
K = int(input())
cnt = 0
for i in range(len(S)-1):
    if S[i]==S[i+1]&&S[i-1]!=S[i]:
        cnt += K
print(cnt)

s=input()
k=int(input())
l=len(s)
now=1
seq=[]
re=False
all=False
for i in range(l):
    if s[i%l]==s[(i+1)%l]:
        now+=1
        if i==l-1:
            re=True
            if len(seq)==0:
                all=True
            else:
                first=seq[0]
                end=now
                seq[0]=(seq[0]+now)
    else:
        seq.append(now)
        now=1
if all:
    ans=len(s)*k//2
else:
    seq=[i//2 for i in seq]
    if re:
        ans=sum(seq)*k-seq[0]+first+end
    else:
        ans=sum(seq)*k

print(ans)

S = input()
K = int(input())
cnt = 0
for i in range(len(S)):
    if (S[i]==S[i+1])&(S[i]!=S[i-1]):
        cnt += K
print(cnt)


s=input()
k=int(input())
l=len(s)
now=1
seq=[]
re=False
all=False
for i in range(l):
    if s[i%l]==s[(i+1)%l]:
        if i==l-1:
            re=True
            if len(seq)==0:
                all=True
            else:
                first=seq[0]//2
                end=now//2
                seq[0]=(seq[0]+now)
        now+=1
    else:
        seq.append(now)
        now=1
if all:
    ans=len(s)*k//2
else:
    seq=[i//2 for i in seq]
    if re:
        ans=sum(seq)*k-seq[0]+first+end
    else:
        ans=sum(seq)*k

print(ans)


Verdicts: Wrong Answer

Runtime Error

Runtime Error

Wrong Answer

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())
s = s + '0'

e = 1
l = []
for i in range(len(s)-1):
    if s[i]==s[i+1]:
        e+=1
    else:
        l.append(e)
        e=1

s = s[:-1]

if len(s)==1:
    print(k//2)    
else:
    if s[0]!=s[-1]:
        print(k*sum([i//2 for i in l]))
    else:
        if k==1:
            print(k*sum([i//2 for i in l]))
        else:
            if len(l)==1:
                print((k*l[0])//2)
            else:
                a = l.pop(0)
                b = l.pop(-1)
                l.append(a+b)
                print((k-1)*sum([i//2 for i in l])+a//2+b//2)

s = input()
k = int(input())
s = s + '0'

e = 1
l = []
for i in range(len(s)-1):
    if s[i]==s[i+1]:
        e+=1
    else:
        l.append(e)
        e=1

s = s[:-1]

if len(s)==1:
    print(k//2)    
else:
    if s[0]!=s[-1] or k==1 or len(l)==1:
        print(k*sum([i//2 for i in l]))
    else:
        a = l.pop(0)
        b = l.pop(-1)
        l.append(a+b)
        print((k-1)*sum([i//2 for i in l])+a//2+b//2)

s = input()
k = int(input())
s = s + '0'

e = 1
l = []
for i in range(len(s)-1):
    if s[i]==s[i+1]:
        e+=1
    else:
        l.append(e)
        e=1

s = s[:-1]

if len(s)==1:
    print(k//2)    
else:
    if s[0]!=s[-1]:
        print(k*sum([i//2 for i in l]))
    else:
        if k==1:
            print(k*sum([i//2 for i in l]))
        else:
            if len(l)==1:
                print((k*l[0])//2)
            else:
                a = l.pop(0)
                b = l.pop(-1)
                l.append(a+b)
                print(k*sum([i//2 for i in l])-(a+b)//2+a//2+b//2)

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):
A=list(input())
n=int(input())
tmp=0
for i in range(len(A)-1):
   if A[i] == A[i+1]:
      A[i+1]=1
      tmp+=1
if A[0] == A[-1]:
   tmp2=n-1
print(tmp*n+tmp2)

A=list(input())
n=int(input())
tmp=0
if len(set(A)) == 1:
   print(len(A)*n//2)
   exit()
sum_n=0
tmp3=0
while A[0] == A[tmp3]:
   tmp3+=1
sum_n+=tmp3
tmp3=0
while A[-1] == A[-1-tmp3]:
   tmp3+=1
sum_n+=tmp3
for i in range(len(A)-1):
   if A[i] == A[i+1]:
      A[i+1]="1"
      tmp+=1
tmp2=0
if A[0] == A[-1]:
   tmp2=n-1
   if sum_n%2 == 1:
      tmp2-=n-1
print(tmp*n+tmp2)

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


cnt = 0
for i in range(len(S)-1):
    if S[i] == S[i+1]:
        cnt += 0.5
    else:
        cnt = int(cnt+0.5)
cnt = int(cnt+0.5)


s3 = S*3
cnt_1 = 0
for i in range((len(s3)*3)-1):
    if s3[i] == s3[i+1]:
        cnt_1 += 0.5
    else:
        cnt_1 = int(cnt_1+0.5)
cnt_1 = int(cnt_1+0.5)


ans = int((cnt_1-cnt*3)/2*(K-1)+0.5)+cnt*K
print(ans)


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

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

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

sum_cnt *= K
if S[0] == S[-1]:
    sum_cnt += K-1
print(sum_cnt)


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


cnt = 0
for i in range(len(S)-1):
    if S[i] == S[i+1]:
        cnt += 0.5
    else:
        cnt = int(cnt+0.5)
cnt = int(cnt+0.5)


s3 = S*3
cnt_1 = 0
for i in range(len(s3)-1):
    if s3[i] == s3[i+1]:
        cnt_1 += 0.5
    else:
        cnt_1 = int(cnt_1+0.5)
cnt_1 = int(cnt_1+0.5)


ans = int((cnt_1-cnt*3)/2*(K-1)+0.5)+cnt*K
print(ans)


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):
s=input()
S=s+s
K=int(input())
post=S[0]
rep=0
later=0
for i in range(1,len(S)):
  if S[i]==post:
    rep+=1
    if i>=len(s):
      later+=1
    post="1"
  else:
    post=S[i]
ans=rep*(K//2)
if K%2==1:
  if post!=s[0] or K==1:
    ans+=rep-later
  else:
    ans+=later
print(ans+1)

s=input()
S=s+s
K=int(input())
post=S[0]
rep=0
later=0
for i in range(1,len(S)):
  if S[i]==post:
    rep+=1
    if i>=len(s):
      later+=1
    post="1"
  else:
    post=S[i]
ans=rep*(K//2)
if K%2==1:
  if post!=s[0] or K==1:
    ans+=rep-later
  else:
    ans+=later
print(ans-1)

S=input()
K=int(input())
post=S[0]
rep=0
for i in range(1,len(S)):
  if S[i]==post:
    rep+=1
    post="1"
  else:
    post=S[i]
ans=rep
print(ans)

S = input()
K = int(input())
X = 0
i = 1
while i < len(S):
  if S[i] == S[i - 1]:
    X += 1
    i += 1
  i += 1
X *= K
if S == S[0] * len(S) and len(S) % 2 == 1:
  X += K // 2
elif i == len(S) and S[0] == S[-1]:
  x = 1
  i = 2
  while i < len(S):
    if S[i] == S[i - 1]:
      x += 1
      i += 1
    i += 1
  X += (K - 1) * (x - X // K)
print(X)


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

SL=list(S)
seq=0
for i in range(len(SL)-1):
  if SL[i]==SL[i+1]:
    SL[i+1]=SL[i+1].upper()
    seq+=1

if K==1 or S[0]!=S[-1]:
  print(seq*K)
else:
  SL2=list(S)
  SL2[0]="#"
  seq2=1
  for i in range(1,len(SL2)-1):
    if SL2[i]==SL2[i+1]:
      SL2[i+1]=SL2[i+1].upper()
      seq2+=1
  
  if K%2==0:
    print((seq+seq2)*(K//2))
  else:
    print(seq*((K+1)//2)+seq2*(K//2))

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

SL=list(S)
seq=0
for i in range(len(SL)-1):
  if SL[i]==SL[i+1]:
    SL[i+1]=SL[i+1].upper()
    seq+=1

if K==1 or SL[0]!=SL[-1]:
  print(seq*K)
else:
  SL2=list(S)
  SL2[0]="#"
  seq2=1
  for i in range(1,len(SL2)-1):
    if SL2[i]==SL2[i+1]:
      SL2[i+1]=SL2[i+1].upper()
      seq2+=1
  
  if SL2[-1]!=S[0]:
    if K%2==0:
      print((seq+seq2)*(K//2))
    else:
      print(seq*((K+1)//2)+seq2*(K//2))
  else:
    print(seq+seq2*(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
i=0
while i<len(S)-1:
    renzoku=1
    x=i
    while S[x] == S[i+1]:
        i=i+1
        renzoku+=1
    if renzoku >1:
        ans+=renzoku//2
    i+=1
    
print(ans*K)

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

end=0
if K!=1:
    S_old = S
    i=-1
    while S_old[0] == S_old[i]:
        S= S + S[0]
        i-=1
ans = 0
i=0
while i<len(S)-1:
    renzoku=1
    x=i
    while S[x] == S[i+1]:
        renzoku+=1
        if i+2 < len(S):
            i=i+1
        else:
            break
    if renzoku >1:
        ans+=renzoku//2
    i+=1
if K== 1:
    pass
else:
    S=S_old
    ans = ans*(K-1)
    i=0
    while S[i] == S[0]:
        i+=1
    S=S[i:]
    i=0
    while i<len(S)-1:
        renzoku=1
        x=i
        while S[x] == S[i+1]:
            renzoku+=1
            if i+2 < len(S):
                i=i+1
            else:
                break
        if renzoku >1:
            ans+=renzoku//2
        i+=1
print(ans)

S=input()
K=int(input())
flg=False
for s in S:
    if S[0] != s:
        flg=True
        break
if not flg:
    print(len(S)*K//2)
    exit()
ans = 0
i=0
while i<len(S)-1:
    renzoku=1
    x=i
    while S[x] == S[i+1]:
        renzoku+=1
        if i+2 < len(S):
            i=i+1
        else:
            break

    if renzoku >1:
        ans+=renzoku//2
    i+=1

if S[0] == S[-1]:
    s=S[0]
    top=0
    bottom=0
    i=0
    while S[i] == s:
        top+=1
        i+=1
    i=-1
    while S[i] == s:
        bottom+=1
        i-=1
    if (top%2) + (bottom%2) == 2:
        print((ans+1)*K-1)
        exit()
    
print(ans*K)





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 = list(input())
K = int(input())
R = []
hoge = 1
for i in range(1,len(S)):
    if S[i] == S[i-1]:
        hoge += 1
    else:
        R.append(S)
        hoge = 1
R.append(hoge)
ans = 0
if len(R) == 1:
    print((R[0]*K)//2)
    exit()
if S[0] == S[-1]:
    ans += (K-1)*((R[0]+R[-1])//2) + R[0]//2 + R[-1]//2
    R[0],R[-1] = 0,0
for i in R:
    ans += (i//2)*K 
print(ans)

S = list(input())
K = int(input())
R = []
hoge = 1
for i in range(1,len(S)):
    if S[i] == S[i-1]:
        hoge += 1
    else:
        R.append(hoge)
        hoge = 1
R.append(hoge)
ans = 0
if len(R) == 1:
    print((R[0]*K)//2)
    exit()
if S[0] == S[-1]:
    ans += (K-1)*((R[0]+R[-1])//2) + R[0]//2 + R[-1]//2
    R[0],R[-1] = 0,0
for i in R:
    ans += (i//2)*K 
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):
import sys
s = input()
k = int(input())
if len(set(list(s))) == 1:
	print((len(s)*k)//2)
	sys.exit()
s += s[0]
tmp = s[0]
cnt = 1
ans = 0
for i in range(1, len(s)):
	if s[i] == tmp:
		cnt += 1
	else:
		ans += cnt//2
		tmp = s[i]
		cnt = 1
ans += cnt//2
ans *= k
if s[-1] == s[-2]:
	ans -= 1
print(ans)

import sys
s = input()
k = int(input())
if len(set(list(s))) == 1:
	print((len(s)*k)//2)
	sys.exit()
tmp = s[0]
cnt = 1
base = 0
is_first = True
for i in range(1, len(s)):
	if s[i] == tmp:
		cnt += 1
	else:
		if is_first:
			is_first = False
			first = cnt//2
		else:
			base += cnt//2
		tmp = s[i]
		cnt = 1

if s[0] != tmp:
	base += cnt//2
	print((first+base)*k)
else:
	i = 0
	last = cnt//2
	while s[i] == tmp:
		cnt += 1
		i += 1
	base += cnt//2
	
	print(first + base*(k-1) + last)

import sys
s = input()
k = int(input())
if len(set(list(s))) == 1:
	print((len(s)*k)//2)
	sys.exit()
tmp = s[0]
cnt = 1
base = 0
is_first = True
for i in range(1, len(s)):
	if s[i] == tmp:
		cnt += 1
	else:
		if is_first:
			is_first = False
			first = cnt//2
		else:
			base += cnt//2
		tmp = s[i]
		cnt = 1

if s[0] != tmp:
	base += cnt//2
	print((first+base)*k)
else:
	i = 0
	last = cnt//2
	while s[i] == tmp:
		cnt += 1
		i += 1
	base += cnt//2
	
	print(first + base*k - cnt//2 + last)

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):
l=list(input())
k=int(input())
n=len(s)
if n==1:
    if k%2==0:
        print(k//2)
    else:
        print((k-1)//2)
    exit()
al=[]
su=[]
f=1
for i in range(n-1):
    if l[i]!=l[i+1]:
        al.append(l[i])
        su.append(f)
        f=1
    else:
        f+=1
if l[-2]==l[-1]:
    al.append(l[-1])
    su.append(f)
else:
    al.append(l[-1])
    su.append(1)
    
if len(al)==1:
    j=su[0]*k
    if j%2==0:
        print(j//2)
    else:
        print((j-1)//2)
    exit()

if al[0]!=al[-1]:
    ans=0
    for i in su:
        if i%2==0:
            ans+=i//2
        else:
            ans+=(i-1)//2
    print(k*ans)
else:
    ans=0
    if su[0]%2==0:
        ans+=su[0]//2
    else:
        ans+=(su[0]-1)//2
    tmp=0
    for i in range(len(al)-2):
        if su[i+1]%2==0:
            tmp+=su[i+1]//2
        else:
            tmp+=(su[i+1]-1)//2
    ans+=tmp*k
    j=su[0]+su[-1]
    if j%2==0:
        ans+=(j//2)*(k-1)
    else:
        ans+=((j-1)//2)*(k-1)
    if su[-1]%2==0:
        ans+=su[-1]//2
    else:
        ans+=(su[-1]-1)//2
    print(ans)   

l=list(input())
k=int(input())
n=len(l)
if n==1:
    if k%2==0:
        print(k//2)
    else:
        print((k-1)//2)
    exit()
al=[]
su=[]
f=1
for i in range(n-1):
    if l[i]!=l[i+1]:
        al.append(l[i])
        su.append(f)
        f=1
    else:
        f+=1
if l[-2]==l[-1]:
    al.append(l[-1])
    su.append(f)
else:
    al.append(l[-1])
    su.append(1)
    
if len(al)==1:
    j=su[0]*k
    if j%2==0:
        print(j//2)
    else:
        print((j-1)//2)
    exit()

if al[0]!=al[-1]:
    ans=0
    for i in su:
        if i%2==0:
            ans+=i//2
        else:
            ans+=(i-1)//2
    print(k*ans)
else:
    ans=0
    if su[0]%2==0:
        ans+=su[0]//2
    else:
        ans+=(su[0]-1)//2
    tmp=0
    for i in range(len(al)-2):
        if su[i+1]%2==0:
            tmp+=su[i+1]//2
        else:
            tmp+=(su[i+1]-1)//2
    ans+=tmp*k
    j=su[0]+su[-1]
    if j%2==0:
        ans+=(j//2)*(k-1)
    else:
        ans+=((j-1)//2)*(k-1)
    if su[-1]%2==0:
        ans+=su[-1]//2
    else:
        ans+=(su[-1]-1)//2
    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):
t=input()
s=list(t)
k=int(input())
if s==[s[0]]*len(s):
  print((len(s)*k)//2)
  exit()
ans=0
for i in range(len(s)-1):
  if s[i]==s[i+1]:
    s[i+1]=0
    ans+=k
if t[0]==t[-1]:ans+=k-1
print(ans)

t=input()
s=list(t)
k=int(input())
if s==[s[0]]*len(s):
  print((len(s)*k)//2)
  exit()
b=[1]
for i in range(1,len(s)):
  if s[i-1]==s[i]:b[-1]+=1
  else:b.append(1)
ans=0
for i in b:ans+=i//2*k
if t[0]==t[-1] and (b[0]+b[-1])%2==0:ans+=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):
import sys


def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def S(): return input()
def LS(): return input().split()


s = S()
k = I()
counts = [1]
for i in range(1, len(s)):
    if s[i - 1] == s[i]:
        counts[-1] += 1
    else:
        counts.append(1)


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

else:
    ans = 0
    
    if s[0] != s[-1]:
        for cnt in counts:
            ans += cnt // 2
        ans *= k

    
    else:
        
        for cnt in counts[1:-1]:
            ans += cnt // 2
        ans *= k
        length = counts[0] + counts[-1]
        
        ans += (length // 2) * (k - 1)

    print(ans)


import sys


def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def S(): return input()
def LS(): return input().split()


s = S()
k = I()
counts = [1]
for i in range(1, len(s)):
    if s[i - 1] == s[i]:
        counts[-1] += 1
    else:
        counts.append(1)

print(counts)

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

else:
    ans = 0
    
    if s[0] != s[-1]:
        for cnt in counts:
            ans += cnt // 2
        ans *= k

    
    else:
        
        for cnt in counts[1:-1]:
            ans += cnt // 2
        ans *= k
        length = counts[0] + counts[-1]
        
        ans += (length // 2) * (k - 1)

    print(ans)


import sys


def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def S(): return input()
def LS(): return input().split()


s = S()
k = I()
counts = [1]
for i in range(1, len(s)):
    if s[i - 1] == s[i]:
        counts[-1] += 1
    else:
        counts.append(1)


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

else:
    ans = 0
    
    if s[0] != s[-1]:
        for cnt in counts:
            ans += cnt // 2
        ans *= k

    
    else:
        
        for cnt in counts[1:-1]:
            ans += cnt // 2
        ans *= k
        
        ans += counts[0] // 2
        
        ans += counts[-1] // 2
        length = counts[0] + counts[-1]
        
        ans += (length // 2) * (k - 1)

    print(ans)


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())
cnt = 0
tmp = s[0]
tmp_cnt = 1

for c in s[1:] + '*':
    if c == tmp:
        tmp_cnt += 1
    else:
        cnt += (tmp_cnt // 2)
        tmp_cnt = 1
        tmp = c

if k == 1:
    print(cnt)
    exit()

tmp_cnt = 1
cnt2 = 0
tmp = s[0]
for c in s[1:] + s + '*':
    if c == tmp:
        tmp_cnt += 1
    else:
        cnt2 += (tmp_cnt // 2)
        tmp_cnt = 1
        tmp = c

if k%2 == 0:
    ans = cnt2 * (k/2)
else:
    ans = cnt2 * (k//2) + cnt

print(ans)

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

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

first, last = s[0], s[-1]
first_flag = 1
a, b  = 0, 0
tmp = s[0]
tmp_cnt = 0
cnt = 0

for i in range(len(s)):
    c = s[i]
    if c == first and first_flag:  
        a += 1
    elif c != first:
        first_flag = 0
    
    if c == tmp:  
        tmp_cnt += 1
    else:
        cnt += (tmp_cnt // 2)
        tmp_cnt = 1
        tmp = c
        
    if i == len(s) -1:  
        b = tmp_cnt
        cnt += (tmp_cnt // 2)

if first != last:  
    ans = cnt * k
else:  
    ans = cnt * k - (a//2 + b//2 - (a+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):
a=list(input())
b=int(input())
if len(a)==1:
  print(b//2)
else:
  ans1=0
  ans2=0
  i=0
  j=len(a)-1
  k=0
  while i>len(a):
    if a[0]==a[i]:
      k+=1
      i+=1
    else:
      break
  while 1:
    if i==j:
      break
    if a[0]==a[j]:
      k+=1
      j-=1
    else:
      break
      
  if k%2==0:
    ans2=1 
  for i in range(1,len(a)):
    if a[i]==a[i-1]:
      ans1+=1
      a[i]=str(i%10)
  print(ans1*b+ans2*(b-1))



a=list(input())
b=int(input())
if len(a)==1:
  print(b//2)
else:
  ans1=0
  ans2=0
  i=0
  j=len(a)-1
  k=0
  while i>len(a):
    if a[0]==a[i]:
      k+=1
      i+=1
    else:
      break
  while 1:
    if i==j:
      break
    if a[0]==a[j]:
      k+=1
      j-=1
    else:
      break
      
  if k!=0 and k%2==0:
    ans2=1 
  for i in range(1,len(a)):
    if a[i]==a[i-1]:
      ans1+=1
      a[i]=str(i%10)
  print(ans1*b+ans2*(b-1))



import copy
a=list(input())
b=int(input())
if len(a)==1:
  print(b//2)
else:
  c=copy.copy(a) 
  l=len(a)
  ans1=0
  ans2=0
  t=0
  for i in range(1,len(a)):
    if c[i]==c[i-1]:
      ans1+=1
      c[i]=str(i%10)
      if i==len(a)-1:
        t=2
  c=a*2
  if t==2:
    c[l-1]=str(1)
  for i in range(l,len(c)):
    if c[i]==c[i-1]:
      ans2+=1
      c[i]=str(i%10)
      if i==len(c)-1:
        t=1
  if b==1:
    print(ans1)
  elif t:
    if b%2==0:
      print((ans1+ans2)*b//2)
    else:
      print((ans1+ans2)*(b//2)+ans1)
  else:
    print(ans1+ans2*(b-1))



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()
a=0
b=0
for i in range(len(S)-1):
  if S[i]==S[i+1]:
    a+=1
  else:
    b+=a//2
    a=0
if S[-1]==S[0]:
  b+=(a+1)//2
else:
  b+=a//2
print(b*int(input()))

S=input()
a=0
b=0
for i in range(len(S)-1):
  if S[i]==S[i+1]:
    a+=1
  else:
    b+=(a+1)//2
    a=0
k=int(input())
print((b+a//2+1)*k-1 if S[-1]==S[0] else (b+a//2)*k)

S=input()
k=int(input())
x=1
L=[]
for i in range(len(S)-1):
  if S[i]==S[i+1]:
    x+=1
  else:
    L.append(x)
    x=1
L.append(x)
s=sum([l//2 for l in L])
if S[0]!=S[-1]:
  print(s*k)
else:
  if len(L)>1:
    L[0]+=L[-1]
    print(s+sum([l//2 for l in L[:-1]])*(k-1))
  else:
    print(L[0]*k//2)

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):
import sys
s = input()
k = int(input())

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


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



j = 0
counta = 1
while (j<=len(s)-2):
    if s[j] == s[j+1]:
        counta += 1
        j += 1
        continue
    else:
        break

print(counta)
if counta % 2 == 0:
    flaga = 0
else:
    flaga = 1
        


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


flagb = 0
if s[len(s)-1] == s[0]:
    if flaga == 1:
        countb += 1
        flagb = 1
        
    


if flagb == 0:
    print(countb * k)
else:
    print(countb * k - 1)










 

 


                                        




    




        


    







        



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

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


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



j = 0
counta = 1
while (j<=len(s)-2):
    if s[j] == s[j+1]:
        counta += 1
        j += 1
        continue
    else:
        break


if counta % 2 == 0:
    flaga = 0
else:
    flaga = 1
        


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


flagb = 0
if s[len(s)-1] == s[0]:
    if flaga == 1:
        countb += 1
        flagb = 1
        
    


if flagb == 0:
    print(countb * k)
else:
    print(countb * k - 1)










 

 


                                        




    




        


    







        



Verdicts: Wrong Answer

Accepted