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)
l = [1]*n
'''
S = set(s)
n1 = len(s)
n2 = len(S)
l = [0]*n1

for i in range(n2):
    for j in range(n1):
        temp = 0
        chk = 0
        if s[i] == s[j]:
            l[chk] += 1
        else:
            chk += 1
'''

chk = 0
temp = 0
for i in range(n-1):
    if s[(i+1)%n] == s[i]:
        l[chk] += 1
        if s[0] == s[n-1]:
            temp = 1
    else:
        chk += 1

memo = 0
edge = 0
ans = 0
for i in range(n-1,-1,-1):
    if l[i] != 1 and memo == 0 and temp == 1:
        memo += 1
        edge = i + 1
    ans += k*(l[i]//2)

if temp == 1: 
    front = 0
    rear = 0
    for i in range(edge):
        if s[i] == s[0]:
            front += 1
    for i in range(edge-1,-1,-1):
        if s[i] == s[edge - 1]:
            rear += 1
    if (front + rear) % 2 == 0 and front % 2 == 1:
        ans += k-1

print(ans,l)


s = input()
k = int(input())
n = len(s)
l = [1]*n
'''
S = set(s)
n1 = len(s)
n2 = len(S)
l = [0]*n1

for i in range(n2):
    for j in range(n1):
        temp = 0
        chk = 0
        if s[i] == s[j]:
            l[chk] += 1
        else:
            chk += 1
'''

chk = 0
temp = 0
for i in range(n-1):
    if s[i+1] == s[i]:
        l[chk] += 1
    else:
        chk += 1

if s[0] == s[n-1]:
        temp = 1

memo = 0
edge = 0
ans = 0
for i in range(n-1,-1,-1):
    if l[i] != 1 and memo == 0 and temp == 1:
        memo += 1
        edge = i
    ans += k*(l[i]//2)

if temp == 1 and edge != 0: 
    if (l[0] + l[edge]) % 2 == 0 and l[0] % 2 == 1:
        ans += k-1
elif temp == 1:
    if l[0] % 2 == 1:
        ans += k//2
if n == 1:
    ans = k//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):
import math
from collections import deque


def main():
    s = list(input())
    k = int(input())
    lst = []
    cnt = 1
    flg = 0
    ans = 0

    for i in range(len(s)-1):
        if s[i + 1] == s[i]:
            cnt += 1
        else:
            lst.append(cnt)
            cnt = 1
            flg = 1
    if flg == 0:
        print(s * k // 2)
        return
    ans += sum(map(lambda x: x // 2, lst[1:len(lst)-1]))*k
    if s[-1] == s[0]:
        ans += (lst[0] + lst[-1]) // 2 * (k - 1)
        ans += lst[0] // 2 + lst[-1] // 2
    else:
        ans += (lst[0] // 2 + lst[-1] // 2) * k
    print(ans)


if __name__ == "__main__":
    main()


import math
from collections import deque


def main():
    s = list(input())
    k = int(input())
    lst = []
    cnt = 1
    flg = 0
    ans = 0
    prev = s[0]
    for i in range(1, len(s)):
        if prev == s[i]:
            cnt += 1
        else:
            lst.append(cnt)
            cnt = 1
            prev = s[i]
            flg = 1
    if flg == 0:
        print(s * k // 2)
        return
    ans += sum(map(lambda x: x // 2, lst[1:len(lst)-1]))*k
    if s[-1] == s[0]:
        ans += (lst[0] + lst[-1]) // 2 * (k - 1)
        ans += lst[0] // 2 + lst[-1] // 2
    else:
        ans += (lst[0] // 2 + lst[-1] // 2) * k
    print(ans)


if __name__ == "__main__":
    main()



def main():
    s = list(input())
    k = int(input())
    lst = []
    cnt = 1
    flg = 0
    ans = 0
    prev = s[0]
    for i in range(1, len(s)):
        if prev == s[i]:
            cnt += 1
        else:
            lst.append(cnt)
            cnt = 1
            prev = s[i]
            flg = 1
    lst.append(cnt)
    if len(lst) == 1:
        ans = len(s) * k // 2
    else:
        ans += sum(map(lambda x: x // 2, lst[1:len(lst)-1])) * k
        # for l in lst[1: len(lst) - 1]:
        #     ans += l // 2 * k
        if s[-1] == s[0]:
            ans += (lst[0] + lst[-1]) // 2 * (k - 1)
            ans += lst[0] // 2 + lst[-1] // 2
        else:
            ans += (lst[0] // 2 + lst[-1] // 2) * k
    print(ans)


if __name__ == "__main__":
    main()


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):
# -*- coding:utf-8 -*-

def is_onaji(S):
    pre_moji = S[0]
    for i in range(1, len(S)):
        if S[i] == pre_moji:
            pre_moji = S[i]
            continue
        else:
            return False
    return True


def solve():
    S = input()
    K = int(input())
    N = len(S)

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

    
    base1 = 0
    pre_moji = S[0]
    for i in range(1, N):
        if S[i] == pre_moji:
            base1 += 1
            pre_moji = "?"
        else:
            pre_moji = S[i]

    if K == 1:
        print(base1)
        return

    
    base2 = 0
    for i in range(0, N):
        if S[i] = pre_moji:
            base2 += 1
            pre_moji = "?"
        else:
            pre_moji = S[i]

    if K == 2:
        print(base1+base2)

    
    base3 = 0
    for i in range(0, N):
        if S[i] = pre_moji:
            base3 += 1
            pre_moji = "?"
        else:
            pre_moji = S[i]

    if K == 3:
        print(base1+base2+base3)

    if base1 == base2 and base2 == base3:
        print(base1*K)
    elif base1 != base2 and base2 == base3:
        print(base1 + base2*(K-1))
    else:
        
        print(base1*((K+1)//2) + base2*(K//2))


if __name__ == "__main__":
    solve()


# -*- coding:utf-8 -*-

def is_onaji(S):
    pre_moji = S[0]
    for i in range(1, len(S)):
        if S[i] == pre_moji:
            pre_moji = S[i]
            continue
        else:
            return False
    return True


def solve():
    S = input()
    K = int(input())
    N = len(S)

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

    
    base1 = 0
    pre_moji = S[0]
    for i in range(1, N):
        if S[i] == pre_moji:
            base1 += 1
            pre_moji = "?"
        else:
            pre_moji = S[i]

    if K == 1:
        print(base1)
        return

    
    base2 = 0
    for i in range(0, N):
        if S[i] == pre_moji:
            base2 += 1
            pre_moji = "?"
        else:
            pre_moji = S[i]

    if K == 2:
        print(base1+base2)
        return

    
    base3 = 0
    for i in range(0, N):
        if S[i] == pre_moji:
            base3 += 1
            pre_moji = "?"
        else:
            pre_moji = S[i]

    if K == 3:
        print(base1+base2+base3)
        return

    if base1 == base2 and base2 == base3:
        print(base1*K)
    elif base1 != base2 and base2 == base3:
        print(base1 + base2*(K-1))
    else:
        
        print(base1*((K+1)//2) + base2*(K//2))


if __name__ == "__main__":
    solve()


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

ss = s + s

if len(set(s)==1):
    print(int((len(s)*k)/2))
else:
    a=0
    prev = "?"
    for v in s:
        if v==prev:
            a += 1
            prev = "?"
        else:
            prev = v

    b=0
    prev = "?"
    for v in ss:
        if v==prev:
            b += 1
            prev = "?"
        else:
            prev = v

    print(a+(b-a)*(k-1))

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

ss = s + s

if len(set(s))==1:
    print(int((len(s)*k)/2))
else:
    a=0
    prev = "?"
    for v in s:
        if v==prev:
            a += 1
            prev = "?"
        else:
            prev = v

    b=0
    prev = "?"
    for v in ss:
        if v==prev:
            b += 1
            prev = "?"
        else:
            prev = v

    print(a+(b-a)*(k-1))

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):
# coding: utf-8
# Your code here!

# coding: utf-8
# Your code here!

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

def monomer(A): 
    N=0
    for i in range(len(A)-1):
        if A[i]==A[i+1]:
            A[i+1]="?"
            N+=1
    return N

 
if S[0]!=S[-1]: 
    print(monomer(S)*K)


else:
    S1=list(s)
    n=monomer(S1) 
    WS=list(s*2) 
    WS.insert(0,WS[-1]) 
    wn=monomer(WS)
    S1.insert(0,S[-1])
    nn=monomer(S1)
    print(n+wn*((K-1)//2)+nn*((K-1)%2)) 


# coding: utf-8
# Your code here!

# coding: utf-8
# Your code here!

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

def monomer(A): 
    N=0
    for i in range(len(A)-1):
        if A[i]==A[i+1]:
            A[i+1]="?"
            N+=1
    return N

 
if S[0]!=S[-1]: 
    print(monomer(S)*K)


else:
    S1=list(s)
    del S1[-1]
    n=monomer(S1)
    WS=list(s*2) 
    WS.insert(0,WS[-1]) 
    wn=monomer(WS)
    S1.insert(0,S[-1])
    nn=monomer(S1)
    print(n+wn*((K-1)//2)+nn*((K-1)%2)) 


# coding: utf-8
# Your code here!

# coding: utf-8
# Your code here!

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

def monomer(A): 
    N=0
    for i in range(len(A)-1):
        if A[i]==A[i+1]:
            A[i+1]="?"
            N+=1
    return N

n=monomer(S) 
if S[0]!=S[-1]: 
    print(n*K)


else:
    WS=list(s*2) 
    WS.insert(0,WS[-1]) 
    wn=monomer(WS)
    SS=list(s)
    SS.insert(0,SS[-1])
    nn=monomer(SS)
    print(n+wn*((K-1)//2)+nn*((K-1)%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):
def main():
    S = input()
    K = int(input())
    ans = 0
    L = len(S)
    if L == 1:
        ans = K//2
        print(ans)
        exit()
        
    cnt = 1
    for i in range(L-1):
        if S[i] == S[i+1]:
            cnt += 1
        else:
            ans += cnt//2
            cnt = 1
    ans += cnt//2
    ans *= K
    if S[0] == S[-1]:ans += K-1
    print(ans)
if __name__ == "__main__":
    main()


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


def main():
    S = input()
    K = int(input())
    ans = 0
    L = len(S)
    s = set([i for i in S])
    if len(s) == 1:
        print((L*K)//2)
        exit()
    cnt = 1
    for i in range(L):
        if i < L-1 and S[i] == S[i+1]:
            cnt += 1
        else:
            ans += cnt//2
            cnt = 1
    ans *= K
    if S[0] == S[-1]:
        t = S[0]
        i = 0
        a = 0
        b = 0
        while i < L and S[i] == t:
            a += 1
            i += 1

        i = L-1
        while i >= 0 and S[i] == t:
            b += 1
            i -= 1

        tmp = a//2+b//2-(a+b)//2
        tmp *= (K-1)
        ans -= tmp
    print(ans)
if __name__ == "__main__":
    main()


Verdicts: 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())
brob = 0
temp = 1
first = 0
for i in range(len(S)-1):
    if S[i] == S[i+1]:
        temp += 1
    else:
        if first == 0:
            first = temp
        brob += temp // 2
        temp = 1S = input()
K = int(input())
brob = 0
temp = 1
first = 0
for i in range(len(S)-1):
    if S[i] == S[i+1]:
        temp += 1
    else:
        if first == 0:
            first = temp
        brob += temp // 2
        temp = 1
        
brob += temp // 2
last = temp

if K == 1:
    print(brob)

else:
    if last == len(S):
        print(len(S) * K // 2)
    
    elif S[-1] != S[0]:
        print(brob * K)
    

    elif last % 2 and first % 2:
        print(brob * K + K - 1)

    else:
        print(brob * K)

        
brob += temp // 2
last = temp

if K == 1:
    print(brob)

else:
    if len(S) == 1:
        print(K // 2)
    
    elif S[-1] != S[0]:
        print(brob * K)

    elif last % 2 and first % 2:
        print(brob * K + K - 1)

    else:
        print(brob * K)


S = input()
K = int(input())
brob = 0
temp = 1
first = 0
for i in range(len(S)-1):
    if S[i] == S[i+1]:
        temp += 1
    else:
        if first == 0:
            first = temp
        brob += temp // 2
        temp = 1
        
brob += temp // 2
last = temp

if K == 1:
    print(brob)

else:
    if last == len(S):
        print(len(S) * K // 2)
    
    elif S[-1] != S[0]:
        print(brob * K)
    

    elif last % 2 and first % 2:
        print(brob * K + K - 1)

    else:
        print(brob * K)


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):
#coding:utf-8
s = input()
k = int(input())


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

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



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

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

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



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

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

dup = [1]
for i in range(1,len(s)):
  if s[i-1]==s[i]:
    dup[-1]+=1
  else:
    dup.append(1)
    
ans = 0
for i in dup:
  ans += (i//2)*k

if s[0]==s[-1]:
  ans += ((dup[0]+dup[-1])//2 - (dup[0]//2+dup[-1]//2))*(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()
s = s + "1"
k = int(input())
ans = 0
lis = []
tem = 1
for i in range(len(s)-1):
  if s[i] == s[i+1]:
    tem += 1
  else:
    lis.append(tem)
    tem = 1
if s[0] == s[-2]:
  t = lis[0]+lis[-1]
  for i in range(1,len(lis)-1):
    if item % 2 == 0:
      ans += item//2
    else:
      ans += (item-1)//2
  ans*= k
  if t%2 == 0:
    ans += (k-1)*t//2
  else:
    ans += (k-1)*(t-1)//2
  if lis[0]%2 == 0:
    ans += (k-1)*lis[0]//2
  else:
    ans += (k-1)*(lis[0]-1)//2
  if lis[-1]%2 == 0:
    ans += (k-1)*lis[-1]//2
  else:
    ans += (k-1)*(lis[-1]-1)//2
else:
  for item in lis:
    if item % 2 == 0:
      ans += item//2
    else:
      ans += (item-1)//2
  ans *= k
  
print(ans)

s = input()
s = s + "1"
k = int(input())
ans = 0
lis = []
tem = 1
for i in range(len(s)):
  if s[i] == s[i+1]:
    tem += 1
  else:
    lis.append(tem)
    tem = 1
if s[0] == s[-2]:
  t = lis[0]+lis[-1]
  for i in range(1,lis(lis)-1):
    if item % 2 == 0:
      ans += item//2
    else:
      ans += (item-1)//2
  ans*= k
  if t%2 == 0:
    ans += (k-1)*t//2
  else:
    ans += (k-1)*(t-1)//2
  if lis[0]%2 == 0:
    ans += (k-1)*lis[0]//2
  else:
    ans += (k-1)*(lis[0]-1)//2
  if lis[-1]%2 == 0:
    ans += (k-1)*lis[-1]//2
  else:
    ans += (k-1)*(lis[-1]-1)//2
else:
  for item in lis:
    if item % 2 == 0:
      ans += item//2
    else:
      ans += (item-1)//2
  ans *= k
  
print(ans)

s = input()
s = s + "1"
k = int(input())
ans = 0
lis = []
tem = 1
for i in range(len(s)-1):
  if s[i] == s[i+1]:
    tem += 1
  else:
    lis.append(tem)
    tem = 1
if s[0] == s[-2]:
  t = lis[0]+lis[-1]
  for i in range(1,len(lis)-1):
    if lis[i] % 2 == 0:
      ans += lis[i]//2
    else:
      ans += (lis[i]-1)//2
  ans*= k
  if t%2 == 0:
    ans += (k-1)*t//2
  else:
    ans += (k-1)*(t-1)//2
  if lis[0]%2 == 0:
    ans += lis[0]//2
  else:
    ans += (lis[0]-1)//2
  if lis[-1]%2 == 0:
    ans += lis[-1]//2
  else:
    ans += (lis[-1]-1)//2
else:
  for item in lis:
    if item % 2 == 0:
      ans += item//2
    else:
      ans += (item-1)//2
  ans *= k
if len(lis) == 1:
  anse = (len(s)-1)*k
  if anse%2 == 0:
    ans = anse//2
  else:
    ans =(anse-1)//2
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):
from itertools import*
s,k=open(0)
k=int(k)
g=[len(list(v))for _,v in groupby(s)]
print(sum(c//2for c in g)*k+((s[0]==s[-2])*g[0]%2&g[-2]%2)*(k//2*(-len(s)~g[0])or k-1))

s,k=open(0)
a,k=0,int(k)
b=t=s[0]
for c in s[1:-1]:
  a+=c==b
  b=c*(c!=b)
print(a*k+~-k)

from itertools import*
s,k=open(0)
k=int(k)
g=[len(list(v))for _,v in groupby(s)]
print(sum(c//2for c in g)*k+((g[0]*g[-2]%2*s[0]==s[-2])*~-k>>(len(s)-2<g[0])))

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 = list(input().rstrip()) # len(S) <= 100
K = int(input())    # K <= 10**9

N = len(S)
cnt = 0
for i in range(N-1):
    if S[i] == S[i+1]:
        print(S[i], S[i+1])
        S[i+1] = "_"
        cnt += 1

if S[0] != S[-1]:
    print(cnt*K)
else:
    print(cnt*K+K-1)


import sys

def solveA(S):
    N = len(S)
    count = 0
    for i in range(N-1):
        if S[i] == S[i+1]:
            S[i+1] = "_"
            count += 1
    return count

def solve(S, K):
    S0 = S[:]
    N = len(S)
    if N == 1:
        return (K-(K%2))//2
    if K < 10:
        return solveA(S*K)
    #actual=(solveA(S*K))
    S1 = S0*1
    S2 = S0*2
    c1 = solveA(S1)
    c2 = solveA(S2)
    if c1 * 2 == c2:
        return c1 * K
    if S2[0] != S2[-1]:
        return c2 * (K//2) + (K%2) * c1
    else:
        a =  c2 * (K//2) + (K%2)*c1 + (K//2)-(1-K%2)
            #if a != solveA(S0*K):
            #print(c1, c2, S2[0]!=S2[-1])
            
        return a


def main():
    S = list(input().rstrip()) # len(S) <= 100
    K = int(input())    # K <= 10**9

    print(solve(S, K))
def test():
    import random

    for i in range(2000):
        n = random.randint(1,100)
        S = random.choices("aaaaaabcedbdddddklkjlkjdsfaak", k=n)
        S0 = S[:]
        K = random.randint(2, 30)
        SK = S*K
        a, a0 = solve(S, K), solveA(SK)
        if a != a0:
            print("".join(S0))
            print(K)
            print("actual=",a, ",expected=",a0)
            print("BAD\n")
            return
#test()
main()


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):
from collections import Counter
def main():
   s = input()
   k = int(input())
   li = []
   num = 1
   for i in range(len(s)-1):
       if s[i] != s[i+1]:
           li.append(1)
       else:
           li[-1] += 1
   temp = 0
   ans = 0
   if len(list((Counter(li).keys()))) == 1:
       ans += len(s) * k // 2
   else:
       for i in li:
           temp += i//2
       if s[0] != s[-1]:
           ans = temp * k
       else:
           li[0] += li[-1]
           for i in li[:-1]:
               ans += i//2
           ans = ans * (k-1) + temp
   print(ans)
main()

from collections import Counter
def main():
   s = input()
   k = int(input())
   li = []
   num = 1
   for i in range(len(s)-1):
       if s[i] != s[i+1]:
           li.append(num)
           num = 1
       else:
           num += 1
   li.append(num)
   temp = 0
   ans = 0
   if len(li) == 1:
       ans += len(s) * k // 2
   else:
       for i in li:
           temp += i//2
       if s[0] != s[-1]:
           ans = temp * k
       else:
           li[0] += li[-1]
           for i in li[:-1]:
               ans += i//2
           ans = ans * (k-1) + temp
   print(ans)
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()
K=int(input())

l=len(s)
first=0
second=0
last=0
S=s+s
LS=list(S)

for n in range(2*l):
  if n==0:
    pass
  if 0<n<=l-1:
    if LS[n-1]==LS[n]:
      first+=1
      LS[n]=str(n)
  if l<=n<2*l-1:
    if LS[n-1]==LS[n]:
      second+=1
      LS[n]=str(n)
  if n==2*l-1:
    if LS[n-1]==LS[n] or LS[n]==LS[0]:
      last+=1
      LS[n]=str(n)

if K%2==0:
  ans=(first+second)*(K//2)+last*((K//2)-1)
else:
  ans=(first+second)*(K//2)+first+last*((K//2)-1)

print(ans)


s=input()
K=int(input())

l=len(s)
ans=0

if K==1:
  Ls=list(s)
  for n in range(1,l):
    if Ls[n]==Ls[n-1]:
      ans+=1
      Ls[n]=str(n)
elif K==2:
  Ls=list(s+s)
  for n in range(1,2*l):
    if Ls[n]==Ls[n-1]:
      ans+=1
      Ls[n]=str(n)
else:
  ansA=0
  ansB=0
  ansC=0
  Ls=list(s+s+s)
  for n in range(1,l):
    if Ls[n]==Ls[n-1]:
      ansA+=1
      Ls[n]=str(n)
  for n in range(l,2*l):
    if Ls[n]==Ls[n-1]:
      ansB+=1
      Ls[n]=str(n)
  for n in range(2*l,3*l):
    if Ls[n]==Ls[n-1]:
      ansC+=1
      Ls[n]=str(n)
  if Ls[0]==Ls[l]:
    ans=ansA*K
  elif Ls[0]!=Ls[l] and Ls[0]==Ls[2*l]:
    if K%2==0:
      ans=(ansA+ansB)*(K//2)
    else:
      ans=(ansA+ansB)*(K//2)+ansA
  else:
    ans=ansA+ansB*(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())

cnt = 0
t_cnt = 1
tmp = ''
for i in range(len(s)):
    if tmp==s[i]:
        t_cnt += 1
    else:
        cnt += t_cnt//2
        tmp = s[i]
        t_cnt = 1
cnt += t_cnt//2

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

bottom_cnt = 0
char = s[-1]
for i in range(1, len(s)+1):
    if char == s[-i]:
        bottom_cnt += 1
    else:
        break
        
if len(set(s))==1:
    print(len(s)*k//2)
else:
    if s[0]!=s[-1]:
        print(cnt*k)
    else:
        print(cnt*k-top_cnt//2+bottom_cnt//2+k-1)

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

tmp = 1
count = 0
for i in range(len(s)-1):
    if s[i] == s[i+1]:
        tmp += 1
    else:
        count += tmp // 2
        tmp = 1
count += tmp//2

if len(set(s))==1:
    print(len(s)*k//2)
else:
    if s[0] != s[-1]:
        print(count*k)
    else:
        h = 0
        for i in s:
            if i != s[0]:
                break
            else:
                h += 1
        t = 0
        for i in s[::-1]:
            if i != s[-1]:
                break
            else:
                t += 1
        print(count*k-(h//2+t//2-(h+t)//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):
import sys
sys.stdin.readline

S = [a for a in input()]
Y = [1 for i in range(len(S))]
K = int(input())
length = len(S) * K
count = 0
sum = 0

if S[0] == S[len(S)-1]:
    for i in range(1, len(S)):
        if S[i] == S[i-1]:
            count += 1
        else:
            Y[i-1] += count
            count = 0
    if count != 0:
        Y[len(S)-1] += count
    start = Y[0]
    fin = Y[len(S)-1]
    for i in range(len(Y)):
        sum += Y[i] // 2
    print(-(start+fin)//2)
    print(start//2)
    print(fin//2)
    print(sum * K+ (-((start + fin)//2) + start//2 + fin//2)*(K-1))
else:
    for i in range(1, len(S)):
        if S[i] == S[i-1]:
            count += 1
        else:
            Y[i-1] += count
            count = 0
    if count != 0:
        Y[len(S)-1] += count
    for i in range(len(Y)):
        sum += Y[i] // 2
    print(sum * K)


import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
import functools
def s(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
cnt = 1
ans = 0
inf = float("inf")

s = s()
k = k()

if s[0]*len(s) == s:
    print(len(s)*k // 2)
    sys.exit()

res = [1]

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

for i in res:
    ans += (i//2)*k
if s[0] == s[-1]:
    diff = (res[0]+res[-1])//2 - (res[0]//2 + res[-1]//2)
    ans += diff*(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()
ss = s + s
sss = s + s + s
k = int(input())
n = 0
nn = 0
nnn = 0
s = list(s)
for i in range(1,len(s)):
  if s[i-1] == s[i]:
    n += 1
    s[i] = '.'
ss = list(ss)
for i in range(1,len(ss)):
  if ss[i-1] == ss[i]:
    nn += 1
    ss[i] = '.'
sss = list(sss)
for i in range(1,len(sss)):
  if sss[i-1] == sss[i]:
    nn += 1
    sss[i] = '.'
a = nn-n*2
if sss == n*3+a*(2):
  print(n*k+a*(k-1))
else:
  print((len(s)*k)//2)

s = input()
ss = s + s
sss = s + s + s
k = int(input())
n = 0
nn = 0
nnn = 0
s = list(s)
for i in range(1,len(s)):
  if s[i-1] == s[i]:
    n += 1
    s[i] = '.'
ss = list(ss)
for i in range(1,len(ss)):
  if ss[i-1] == ss[i]:
    nn += 1
    ss[i] = '.'
sss = list(sss)
for i in range(1,len(sss)):
  if sss[i-1] == sss[i]:
    nnn += 1
    sss[i] = '.'
a = nn-n*2
if nnn == n*3+a*2:
  print(n*k+a*(k-1))
else:
  print((len(s)*k)//2)

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

inner_difference = 0
  
if len(set(list(S))) == 1:
  print(K*len(S)//2)
else:
  i = 0
  while i < len(S)-1:
    if S[i] == S[i+1]:
      inner_difference += 1
      i += 1
    i += 1

  if (S[0] != S[-1])or(S[0]==S[1])or(S[N-1]==S[N-2]):
    print(inner_difference*K)
  else:
    print(inner_difference*K + K-1)

S = input()
K = int(input())
 
INNER = 0
  
if len(set(list(S))) == 1:
  print(K*len(S)//2)
else: 
  i = 0
  while i < len(S)-1:
    if S[i] == S[i+1]:
      INNER += 1
      i += 1
    i += 1
  
  if (S[0] != S[-1]):
    print(INNER*K)
  else:
    same_from_start = 0
    same_from_end = 0
    
    count_from_start = 0
    count_from_end = 0
    
    flag_same_from_start = 0
    flag_same_from_end = 0
    
    while flag_same_from_start == 0:
      if S[count_from_start] == S[count_from_start+1]:
        count_from_start += 1
      else:
        count_from_start += 1
        flag_same_from_start = 1
    
    while flag_same_from_end == 0:
      if S[len(S)-count_from_end-1] == S[len(S)-count_from_end-2]:
        count_from_end += 1
      else:
        count_from_end += 1
        flag_same_from_end = 1
    print(INNER*K + (K -1) * ((count_from_start+count_from_end)//2 -\
                              count_from_start//2- count_from_end//2))

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())
ans = 0

T = ""
for _ in range(K):
    T += S

for ti in range(1, len(T)):
    if T[i] == T[i - 1]:
        T = T[: i] + "?" + T[i + 1:]
        ans += 1

print(ans)


S = input()
K = int(input())
ans_s2, ans_s3 = 0, 0


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

S_double = S + S
for i in range(1, len(S_double)):
    if S_double[i] == S_double[i - 1]:
        S_double = S_double[: i] + "?" + S_double[i + 1:]
        ans_s2 += 1

S_triple = S + S + S
for j in range(1, len(S_triple)):
    if S_triple[j] == S_triple[j - 1]:
        S_triple = S_triple[: j] + "?" + S_triple[j + 1:]
        ans_s3 += 1

ans_increase = ans_s3 - ans_s2  

ans = ans_s2 + max(0, ans_increase * (K - 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):
a=input()
b=int(input())
s="A"
zn=0
n=0
nn=0
i=0
aa=[]
ab=[]

for x in a:
    if aa==[]:
        n+=1
    elif x==s:
        n+=1
    elif x!=s:
        ab.append(n)
        n=1
    s=x
    i+=1
    aa.append(x)
    if i==len(a):
        ab.append(n)
if aa[0]==aa[-1]:
    s=a[0]
    i=0
    for x in aa:
        if a[i]==s:
            nn+=1
        else:
            break
        i+=1
    i=1
    for x in aa:
        if a[-i]==s:
            nn+=1
        else:
            break
        i+=1
for x in ab:
    zn+=(x//2)
if len(a)==1:
    print(b//2)
elif len(ab)!=1:
    print(zn*b+(nn//2)*(b-1))
else:
    print((b*ab[0])//2)

a=input()
b=int(input())
s=""
zn=0
n=0
nn=0
i=0
aa=[]
ab=[]
abb=0
abc=0

for x in a:
    if aa==[]:
        n+=1
    elif x==s:
        n+=1
    elif x!=s:
        ab.append(n)
        n=1
    s=x
    i+=1
    aa.append(x)
    if i==len(a):
        ab.append(n)
if aa[0]==aa[-1] and len(ab)>2:
    if ab[-1]!=1:
        abb=ab[-1]
        del ab[-1]
    if ab[0]!=1:
        abc=ab[0]
        del ab[0]
    s=aa[0]
    i=0
    for x in aa:
        if aa[i]==s:
            nn+=1
        else:
            break
        i+=1
    i=1
    for x in aa:
        if aa[-i]==s:
            nn+=1
        else:
            break
        i+=1    
for x in ab:
    zn+=(x//2)
if len(a)==1:
    print(b//2)
elif len(ab)==1 and abb==0 and abc==0:
    print((b*ab[0])//2)
else:
    print(zn*b+(nn//2)*(b-1)+abb//2+abc//2)

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())
cnt = 0
ss = s
for i in range(len(ss)):
    if i == 0:
        continue
    
    if ss[i-1] == ss[i]:
        ss = ss[:i] + '\\' + ss[i+1:]
        cnt += 1

cnt = cnt * k

print(cnt)
if len(s) >= 3 and k >= 2 and s[0] == s[1] and s[0] == s[2]:
    cnt += k -1
print(cnt)

# if len(s) >=3:
#     if len(s) % 2 == 1:
#         cnt = cnt -((k + 1) // 2 - 1)

if len(s) >=3:
    if s[0] == s[len(s)-1] and s[0] != s[1] and  s[len(s)-1] != s[len(s)-2]:
        cnt = cnt + (k - 1)
print(cnt)


def f(s, k):
    
    k = int(k)
    
    cnt = 0
    ss = s
    for i in range(len(ss)):
        if i == 0:
            continue

        if ss[i-1] == ss[i]:
            ss = ss[:i] + '\\' + ss[i+1:]
            cnt += 1
        
    cnt = cnt * k
    
    if s.count(s[0]) == len(s):
        if len(s) % 2 == 1:
            cnt = cnt + (k//2)
    else:    
        cntchk1 = 0
        cntchk2 = 0
        if s[0] == s[len(s)-1]:
            for i in range(len(s)):
                if s[len(s)-1] == s[len(s)-1 - i]:
                    cntchk1 += 1
#                 else:
#                     break
                if i < len(s)-1 and s[0] == s[i+1]:
                    cntchk2 += 1
                    
            if cntchk1 % 2 == 0 and cntchk1 % 2 == 0:
                cnt = cnt + (k -1)
                
    return str(cnt)

## Submit
print(f(input(),input()))

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,K=open(0);K=int(K);s=1;l=[]
for c,d in zip(S,S[1:]):
 if c==d:s+=1
 else:l+=[s];s=1
print((len(l)==1)*l[0]*K//2or(S[0]!=S[-2])*K*sum(i//2for i in l))or K*sum(i//2for i in[l[0]+l[-1]]+l[1:-1])-(l[0]&l[-1]&1) 

S,K=open(0);K=int(K);s=1;l=[]
for c,d in zip(S,S[1:]):
 if c==d:s+=1
 else:l+=[s];s=1
if len(l)==1:print(l[0]*K//2)
elif S[0]==S[-2]:print(K*sum(i//2for i in l[1:-1]+[l[0]+l[-1]])-(l[0]&l[-1]&1))
else:print(K*sum(i//2for i in l))

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

S2 = S*2

for i in range(1,len(S2)):
    if S2[i-1]== S2[i]:
        s_d[i] = '@'
        
        if i>=len(S2)//2:
            ans+= K-1
        else:
            ans+=1

print(ans) 

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

S2 = S*2

for i in range(1,len(S2)):
    if S2[i-1]== S2[i]:
        S2[i] = '@'
        
        if i>=len(S2)//2:
            ans+= K-1
        else:
            ans+=1
            
if len(set(S)) ==1 and len(S)%2 !=0:
   ans = len(S)*(K//2)+(K%2==1)*(len(S)//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=list(input())
K=int(input())
count=0

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

for i in range(len(S)):
    if S[i]==S[i-1]:
        if i%2==0:
            S[i]="?"
        else:
            S[i]="!"
        count+=1
if S[-1]==S[0]:
    print("a")
    print(count*K-2)
else:
    if K==1:
        print(count*K-1)
    else:
        print(count*K)




# coding: utf-8
# Your code here!
S=list(input())
K=int(input())

flag=True
for i in range(len(S)-1):
    if S[i+1]!=S[i]:
        flag=False
        break

if flag and K>1:
    S*=2
    for i in range(len(S)-1):
        if S[i+1]==S[i]:
            S[i+1]="?"
    temp=S.count("?")
    print(K//2*temp+(temp//2 if K%2==1 else 0))
    exit()

if K==1:
    for i in range(len(S)-1):
        if S[i+1]==S[i]:
            S[i+1]="?"
    print(S.count("?"))
    exit()

n=len(S)
S*=4
N=len(S)-1

for i in range(N):
    if S[i+1]==S[i]:
        S[i+1]="?"

l=[S[:n],S[n:2*n],S[2*n:3*n],S[3*n:]]

ans=[0]*4
for i in range(4):
    ans[i]=l[i].count("?")

print(ans[0]+ans[3]+ans[1]*(-(-(K-2)//2))+ans[2]*((K-2)//2))





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
s=s*2
for i in range(len(s)-1):
  if s[i]==s[i+1]:
    s=s[:(i+1)]+'0'+s[(i+2):]
    ans+=1
print(ans*k*0.5 if k%2==0 else ans*k*0.5-0.5)

s=input()
s1=s
k=int(input())
ans1=0
ans2=0
for i in range(len(s)-1):
  if s1[i]==s1[i+1]:
    s1=s1[:(i+1)]+'0'+s1[(i+2):]
    ans1+=1
if s1[0]==s1[-1]:
  s1=s1+'0'+s[1:]
  ans2+=1
  k-=1
  for i in range(len(s),len(s1)-1):
    if s1[i]==s1[i+1]:
      s1=s1[:(i+1)]+'0'+s1[(i+2):]
      ans2+=1 
  if s1[0]==s1[-1]:
    ans=ans1+ans2*k
  else:
    ans=(ans1+ans2)*(k//2)+ans1
else:
  ans=ans1*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):
# -*- coding: utf-8 -*-
S = str(input())
K = int(input())

if len(S) == 1:
    print(K // 2)
else:
    before_s = ""
    dup_list = []
    dup_num = 0
    for s in S:
        if s == before_s:
            dup_num += 1
            if dup_num == 1:
                dup_list.append(dup_num)
            else:
                dup_list[-1] = dup_num
        else:
            before_s = s
            dup_num = 0
    ans = 0
    for dnum in dup_list:
        ans += (dnum + 1) // 2
    ans *= K
    print(dup_num)
    if S[0] == S[-1]:
        if S[-1] != S[-2] or dup_num % 2 == 0: 
            ans += K - 1
    print(ans)

# -*- coding: utf-8 -*-
S = str(input())
K = int(input())

if len(set(S)) == 1:
    print(len(S) * K // 2)
else:
    before_s = ""
    dup_list = []
    dup_num = 0

    for s in S:
        if s == before_s:
            dup_num += 1
            if dup_num == 1:
                dup_list.append(dup_num)
            else:
                dup_list[-1] = dup_num
        else:
            before_s = s
            dup_num = 0
    single_ans = 0
    for dnum in dup_list:
        single_ans += (dnum + 1) // 2

    before_s = ""
    dup_list = []
    dup_num = 0
    for s in S * 2:
        if s == before_s:
            dup_num += 1
            if dup_num == 1:
                dup_list.append(dup_num)
            else:
                dup_list[-1] = dup_num
        else:
            before_s = s
            dup_num = 0
    double_ans = 0
    for dnum in dup_list:
        double_ans += (dnum + 1) // 2
    
    ans = single_ans * K + (double_ans - 2 * single_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):
from itertools import groupby
s = input()
k = int(input())
l = [[k, len(list(g))] for k, g in groupby(s)]
ans = 0
ans2 = 0
for i in range(len(l)):
  if l[i][1] > 1:
    ans += l[i][1] // 2
if len(l) > 1:
  if l[0][0] == l[-1][0]:
    if l[0][1] % 2 == 1 and  l[-1][1] % 2 == 1 :
        ans2 = k - 1
if len(s) == 1:
  print(k // 2)
elif len(l) == 1:
  if l[0][1] % 2 == 1:
    print(((l[0][1] // 2) * k + (k - 1))
  else:
    print((l[0][1] // 2) * k)
else:
  print(ans * k + ans2)
    



from itertools import groupby
s = input()
k = int(input())
l = [[k, len(list(g))] for k, g in groupby(s)]
ans = 0
ans2 = 0
for i in range(len(l)):
  if l[i][1] > 1:
    ans += l[i][1] // 2
if len(l) > 1:
  if l[0][0] == l[-1][0]:
    if l[0][1] % 2 == 1 and  l[-1][1] % 2 == 1 :
        ans2 = k - 1
if len(s) == 1:
  print(k // 2)
elif len(l) == 1:
  #if l[0][1] % 2 == 1:
  
  #else:
  print(len(s) * k // 2)
else:
  print(ans * k + ans2)
    



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())
a = []
ans = 0
count = 0
for i in range(len(S)-1):
    if S[i] == S[i+1] :
        count += 1
    else:
        if count!=0:
            ans += (count+1)//2
            a.append(count+1)
            count = 0
if count !=0:
    ans += (count+1)//2 
ans = ans*K
a.append(0)
if len(S) == 1:
    ans = K//2
    print(ans)
    break
if (count+1)%2==1 and a[0]%2 == 1 and S[0]== S[1] and S[0] == S[len(S)-1]:
    
    ans+=K-1
if S[0]!= S[1] and (count+1)%2 ==1 and  S[0] == S[len(S)-1]:
    ans+=K-1

S = input()
K = int(input())
a = [0]
ans = 0
count = 0
for i in range(len(S)-1):
    if S[i] == S[i+1] :
        count += 1
    else:
        if count!=0:
            ans += (count+1)//2
            a.append(count)
            count = 0
if count !=0:
    ans += (count+1)//2 
ans = ans*K
if (count+a[1])%2 == 0 and count!=0:
    ans+=K-1

print(ans)

S = input()
K = int(input())
a = []
ans = 0
count = 0
for i in range(len(S)-1):
    if S[i] == S[i+1] :
        count += 1
    else:
        if count!=0:
            ans += (count+1)//2
            a.append(count)
            count = 0
if count !=0:
    ans += (count+1)//2 
ans = ans*K
if (count+a[0])%2 == 0 and count!=0:
    ans+=K-1

print(ans)

S = input()
K = int(input())
a = []
ans = 0
count = 0
for i in range(len(S)-1):
    if S[i] == S[i+1] :
        count += 1
    else:
        if count!=0:
            ans += (count+1)//2
            a.append(count+1)
            count = 0
if count !=0:
    ans += (count+1)//2 
ans = ans*K
a.append(0)
if len(S) == 1:
    ans = K//2
else:    
    
    if (count+1)%2==1 and a[0]%2 == 1 and S[0]== S[1] and S[0] == S[len(S)-1]:
    
        ans+=K-1
    if S[0]!= S[1] and (count+1)%2 ==1 and  S[0] == S[len(S)-1]:
        ans+=K-1
    if count+1 == len(S):
        if len(S)%2==1:
            ans = (len(S)*K)//2
 
print(ans)

Verdicts: Runtime Error

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())
ans = 0

if len(S) == 1:
    ans = K//2
elif len(set(s)) == 1:
    ans = int(len(S)*K/2)
else:
    for i in range(len(S)-1):
        if S[i] == S[i+1]:
            ans += 1
            S[i+1] = "#"

    ans *= K

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

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

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

S2 = list(S) * 2
cnt2 = 0
for i in range(1, len(S2)):
    if S2[i] == S2[i - 1]:
        S2[i] = '*'
        cnt2 += 1
        
S3 = list(S) * 3
cnt3 = 0
for i in range(1, len(S3)):
    if S3[i] == S3[i - 1]:
        S3[i] = '*'
        cnt3 += 1

# print("#", S1, S2, S3)
# print("#", cnt1, cnt2, cnt3)
ans = cnt1 + (cnt2 - cnt1) * (K // 2) + (cnt3 - cnt2) * ((K - 1) // 2)
print(ans)


Verdicts: Runtime Error

Accepted