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().replace(" ", "")
K = int(input())

str1 = S
str2 = S * 2
n1 = 0
n2 = 0
ln1 = []
ln2 = []

for c in str1:
  ln1.append(c)
for i in range(len(ln1)):
  if i == 0:
    pass
  elif ln1[i-1] == ln1[i]:
    n1 += 1
    ln1[i] = "A"
    
for c in str2:
  ln2.append(c)
for i in range(len(ln2)):
  if i == 0:
    pass
  elif ln2[i-1] == ln2[i]:
    n2 += 1

S = input().replace(" ", "")
K = int(input())

str1 = S
str2 = S * 2
str3 = S * 3
str4 = S * 4
n1 = 0
n2 = 0
n3 = 0
n4 = 0
ln1 = []
ln2 = []
ln3 = []
ln4 = []

for c in str1:
  ln1.append(c)
for i in range(len(ln1)):
  if i == 0:
    pass
  elif ln1[i-1] == ln1[i]:
    n1 += 1
    ln1[i] = "A"
    
for c in str2:
  ln2.append(c)
for i in range(len(ln2)):
  if i == 0:
    pass
  elif ln2[i-1] == ln2[i]:
    n2 += 1
    ln2[i] = "A"
    
for c in str3:
  ln3.append(c)
for i in range(len(ln3)):
  if i == 0:
    pass
  elif ln3[i-1] == ln3[i]:
    n3 += 1
    ln3[i] = "A"
    
for c in str4:
  ln4.append(c)
for i in range(len(ln4)):
  if i == 0:
    pass
  elif ln4[i-1] == ln4[i]:
    n4 += 1
    ln4[i] = "A"
  
if len(S) == 1:
  print(K//2)
elif n1 == (n2 - n1) and (n2 - n1) == (n3 - n2):
  print(int(n1 * K))
elif n1 != (n2 - n1) and (n2 - n1) == (n3 - n2) and n1 == (n4 - n3):
  if K >= 3:
    print(int(n1 + (n3 - n1) * (K - 1)//2 - 1))
  elif K == 2:
    print(int(n2))
  else:
    print(int(n1))
elif n1 != (n2 - n1) and (n2 - n1) == (n3 - n2):
  if K >= 3:
    print(int(n1 + (n3 - n1) * (K - 1)//2))
  elif K == 2:
    print(int(n2))
  else:
    print(int(n1))
else:
  if K % 2 == 1:
    print(int(n1 + (n3 - n1) * (K - 1)//2))
  else:
    print(int(n2 * 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):
def main():
    S = input()
    K = int(input())
    ans = 0

    if len(set(S)) is 1:
        print(len(S) * K // 2)
        return

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

    if S[0] is S[-1]:
        tmp_str = S[::-1]
        cnt = 0
        i = 0
        while tmp_str[i] is tmp_str[0]:
            cnt += 1
            i += 1
        if cnt % 2 is not 0:
            ans += 1
        print(ans * K - 1)
        return

    if ans is 0 and S[0] is S[-1]:
        print(K - 1)
    else:
        print(ans * K)


if __name__ == "__main__":
    main()


def main():
    S = input()
    K = int(input())
    ans = 0

    if len(set(S)) is 1:
        print(len(S) * K // 2)
        return

    i = 0
    cnt = [1]
    while i < len(S) - 1:
        if S[i] is S[i + 1]:
            cnt[-1] += 1
        else:
            cnt.append(1)
        i += 1

    for v in cnt:
        ans += (v // 2) * K

    if S[0] is S[-1]:
        if cnt[0] % 2 == cnt[-1] % 2 == 1:
            ans += K - 1

    print(ans)


if __name__ == "__main__":
    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):
# coding: utf-8
S = input()
K = int(input())
if len(S) == 2:
    if S[0] != S[1]:
        print(0)
    else:
        print(K)
    exit()
l = []
SS = S * 2
s = SS[0]
cnt = 1
for i in range(1, len(SS)):
    if s != SS[i]:
        l.append(cnt)
        s = SS[i]
        cnt = 1
    else:
        cnt += 1
l.append(cnt)
ans = 0
if S[0] == S[-1]:
    # print(l)
    for i in range(len(l)):
        if i == 0 or i == len(l)-1:
            ans += l[i] // 2
        else:
            ans += l[i] // 2 * (K-1)
    ans -= (l[0] + l[-1]) // 2
else:
    # print(l[:len(l)//2])
    for i in range(len(l)//2):
        ans += l[i] // 2 * K
print(ans)


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


# coding: utf-8
S = input()
K = int(input())
l = [0]
tmp = 0
for i in range(len(S)-1):
    if S[i] == S[i+1]:
        # l.append(tmp + 1)
        tmp += 1
    else:
        if tmp > 1:
            l.append(tmp+1)
        tmp = 0
ans = 0
ans += l[-1]//2
if S[0] == S[-1]:
    l[-1] += 1
for i in range(1, len(l)-1):
    ans += l[i]//2 * K
# print(ans)
ans += l[-1]//2 * (K-1)
# print(l)
print(ans)

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


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):
def a(s):
    count = 0
    for i in range(len(s) - 2):
        if s[i] == s[i + 1]:
            s = s[:i + 1] + 'A' + s[i + 2:]
            count += 1
    if s[-1] == s[-2]:
        count +=1
    return count


s = str(input())
k = input()
if s[0] != s[-1] or k==1:
    print(a(s) * k)
else:
    new_s = s * 2
    org_count = a(s)
    new_count = a(new_s)
    diff = 2 * org_count - new_count
    print(org_count * k - diff * (k - 1))

def a(s):
    count = 0
    test = s[0]
    for i in range(len(s) - 1):
        if s[i] == s[i + 1] and test[i] != 'A':
            
            test += 'A'
            count += 1
        else:
            test += s[i]
    return count


s = input()
k = int(input())
if s[0] != s[-1] or k == 1:
    print(a(s) * k)
elif k == 2:
    new_s = s * 2
    print(a(new_s))
elif len(s) == s.count(s[0]):
    new_s = s * 2
    count_2 = a(new_s)
    print(count_2 * (k // 2) + a(s) * (k % 2))
else:
    new_s = s * 2
    count_2 = a(new_s)
    count_3 = a(new_s + s)
    diff = count_3 - count_2
    print(count_3 + (k-3) * diff)


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):
def resolve():
    
    S = input()
    K = int(input())

    S_head = ''
    head = S[0]
    for s in S:
        if s == head:
            S_head += s
        else:
            break
    
    S_tail = ''
    tail = S[-1]
    for s in S[::-1]:
        if s == tail:
            S_tail += s
        else:
            break
    S_tail = S_tail[::-1]

    S_body = S[len(S_head):-1 * len(S_tail)]
    
    def double_counter(S):
        cnt = 0
        if len(S) >= 2:
            prev = S[0]
            for item in S[1:]:
                if item == prev:
                    cnt += 1
                    prev = -1
                else:
                    prev = item

        return cnt
    
    if len(S) >= 2 and len(S) != len(S_head):
        res = len(S_head)//2\
            + len(S_tail)\
            + double_counter(S_body) * K\
            + double_counter(S_tail+S_head) * (K-1)
    elif len(S) == 1:
        res = K // 2
    elif len(S) == len(S_head):
        res = (K * len(S)) // 2

    print(res)

if __name__ == "__main__":
    resolve()


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

    S_head = ''
    head = S[0]
    for s in S:
        if s == head:
            S_head += s
        else:
            break
    
    S_tail = ''
    tail = S[-1]
    for s in S[::-1]:
        if s == tail:
            S_tail += s
        else:
            break
    S_tail = S_tail[::-1]

    S_body = S[len(S_head):-1 * len(S_tail)]
    
    def double_counter(S):
        cnt = 0
        if len(S) >= 2:
            prev = S[0]
            for item in S[1:]:
                if item == prev:
                    cnt += 1
                    prev = -1
                else:
                    prev = item

        return cnt
    
    if len(S) >= 2 and len(S) != len(S_head):
        res = len(S_head)//2\
            + len(S_tail)//2\
            + double_counter(S_body) * K\
            + double_counter(S_tail+S_head) * (K-1)
    elif len(S) == 1:
        res = K // 2
    elif len(S) == len(S_head):
        res = (K * len(S)) // 2

    print(res)

if __name__ == "__main__":
    resolve()


Verdicts: Wrong Answer

Accepted
Problem: Given is a string S. Let T be the concatenation of K copies of S. We can repeatedly perform the following operation: choose a character in T and replace it with a different character. Find the minimum number of operations required to satisfy the following condition: any two adjacent characters in T are different.

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

pat1 = 0
for i in range(L-1):
  f_s = S[i]
  s_s = S[i+1]
  if f_s == s_s:
    S[i+1] = '-'
    pat1 += 1
    
if S[-1] != '-' and S[0] == S[-1]:
  pat1 = (pat1 + 1) * K - 1
else:
  pat1 *= K
  
pat2 = 0
for i in range(L-1):
  f_s = S[i]
  s_s = S[i+1]
  if f_s == s_s:
    S[i] = '-'
    pat2 += 1

if S[-1] != '-' and S[0] == S[-1]:
  pat2 = (pat2 + 1) * K - 1
else:
  pat2 *= K
  
print(min(pat1,pat2))
  


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

ans = 0
for i in range(L-1):
  f_s = S[i]
  s_s = S[i+1]
  if f_s == s_s:
    s_s = '-'
    ans += 1
    
if S[-1] != '-' and S[0] == S[-1]:
  ans = (ans + 1) * K - 1
else:
  ans *= K
  
print(ans)
  

S = list(input())
NS = [s for s in S]
K = int(input())
L = len(S)

if "".join(S) == S[0] * L:
  print(L * K // 2)
  exit()

ans = 0
for i in range(L-1):
  f_s = S[i]
  s_s = S[i+1]
  if f_s == s_s:
    S[i+1] = '-'
    ans += 1


if S[0] != S[-1]:
  ans *= K

else:
  a = 0
  for i in range(L):
    if NS[i] == NS[0]:
      a += 1
    else:
      break
  
  b = 0
  for i in range(L)[::-1]:
    if NS[i] == NS[-1]:
      b += 1
    else:
      break
      

  ans *= K
  #t = (- (-a // 2)) + (- (-b // 2)) - (- (-a-b) // 2)
  #t = -(-a // 2) - (-b // 2) + (-(a+b) // 2)
  t = a // 2 + b // 2 - (a+b) // 2
  ans -= t * (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 = list(input())
k = int(input())
n = len(s)

ans = 0


if s == [s[0]] * n:
    print((n*k)//2)
    exit(0)


i = 1
while i < n:
    if s[i-1] == s[i]:
        t = 2
        i+=1
        while i < n and s[i-1] == s[i]:
            t+=1
            i+=1
        ans += (t//2)*k
    i+=1
if s[0] != s[-1]:
    print(ans)
    exit(0)




i = 1
left = 0
right = 0
while i < n:
    if s[i-1] == s[i]:
        t = 2
        i+=1
        while i < n and s[i-1] == s[i]:
            t+=1
            i+=1
        left += t
        break
    i+=1
i = n-1
while 0 < i < n:
    if s[i-1] == s[i]:
        t = 2
        i-=1
        while 0 < i < n and s[i-1] == s[i]:
            t+=1
            i-=1
        right += t
        break
    i-=1
if s[0] == s[-1]:
    ans = ans - (k-1) * (left//2 - right//2) + (k-1) * (left+right)//2
    print(ans)


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

ans = 0


if s == [s[0]] * n:
    print((n*k)//2)
    exit(0)


i = 1
while i < n:
    if s[i-1] == s[i]:
        t = 2
        i+=1
        while i < n and s[i-1] == s[i]:
            t+=1
            i+=1
        ans += (t//2)*k
    i+=1
if s[0] != s[-1]:
    print(ans)
    exit(0)




i = 1
left = 1
right = 1
for i in range(n):
    if s[i] == s[i+1]:
        left += 1
    else:
        break
for i in range(n-1, -1, -1):
    if s[i] == s[i-1]:
        right += 1
    else:
        break
if s[0] == s[-1]:
    ans = ans - (k-1) * (left//2 + right//2) + (k-1) * ((left+right)//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 = input()
k = int(input())
cnt = 0
flag = 0
for i in range(1,len(s)-2):
  if s[i] == s[i+1]:
    cnt += 1
    if s[i+1] == s[i+2] and flag == 0:
      cnt -= 1
      flag = 1
    else:
      flag = 0
print(cnt*k)

s = input()
k = int(input())
cnt = 0
flag = 0
for i in range(len(s)-1):
  if s[i] == s[i+1]:
    cnt += 1
    if i-1 >=0 and s[i-1] == s[i] and flag == 0:
      cnt -= 1
      flag = 1
    else:
      flag = 0
  else:
    flag = 0
tmp = 0
if len(s)%2 and (s[0] == s[1] == s[-1] or s[0] == s[-2] == s[-1]):
  tmp = k//2
print(cnt*k + tmp)

s = input()
k = int(input())
cnt = 0
flag = 0
for i in range(len(s)-1):
  if s[i] == s[i+1]:
    cnt += 1
    if i-1 >=0 and s[i-1] == s[i] and flag == 0:
      cnt -= 1
      flag = 1
    else:
      flag = 0
  else:
    flag = 0
tmp = 0
if len(s)%2 and s.count(s[0])%2:
  tmp = k//2
print(cnt*k + tmp)

s = input()
k = int(input())
cnt = 0
flag = 0
for i in range(len(s)-1):
  if s[i] == s[i+1]:
    cnt += 1
    if s[i+1] == s[i+2] and flag == 0 :
      flag = 1
      cnt -= 1
    else:
      flag = 0
print(cnt*k)

s = input()
k = int(input())
cnt = 0
flag = 0
for i in range(1,len(s)-2):
  if s[i] == s[i+1]:
    cnt += 1
    if s[i+1] == s[i+2] and flag == 0:
      cnt -= 1
      flag = 1
    else:
      flag = 0
  else:
    flag = 0
print(cnt*k)

s = input()
k = int(input())
cnt = 0
flag = 0
for i in range(len(s)-1):
  if s[i] == s[i+1]:
    cnt += 1
    if i-1 >=0 and s[i-1] == s[i] and flag == 0:
      cnt -= 1
      flag = 1
    else:
      flag = 0
  else:
    flag = 0
tmp = 0
if len(s)%2 and s.count(s[0])%2 and s[0] == s[-1]:
  tmp = k//2
print(cnt*k + tmp)

from itertools import groupby

s = input()
k = int(input())
a = [sum(1 for _ in g) for _, g in groupby(s)]
if len(a) == 1:
  print(len(s) * k // 2)
else:
  ans = sum(x // 2 for x in a) * k
  if s[0] == s[-1] and a[0] & a[-1] & 1:
    ans += k - 1
  print(ans)


Verdicts: Wrong Answer

Runtime Error

Wrong Answer

Runtime Error

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
def input():
    return sys.stdin.readline()[:-1]

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

N = len(S)
ans = 0
last_same = False
if N==1:
    print(K//2)
    exit()
for i in range(1,N):
    if S[i]!=S[i-1]:
        break
    else:
        print(N*K//2)
        exit()
pre = S[0]
p = False
for i in range(1,N):
    if p:
        pre = S[i]
        p = False
        continue
    s = S[i]
    if pre==s:
        ans += 1
        p = True
        if i==N-1:
            last_same = True
    pre = s

l_same = False
if not last_same:
    if S[0]==S[-1]:
        ans += 1
        l_same = True

import sys
def input():
    return sys.stdin.readline()[:-1]

S = list(input())
K = int(input())
N = len(S)
ans = 0
last_same = False
if N==1:
    print(K//2)
    exit()
for i in range(1,N):
    if S[i]!=S[i-1]:
        break
else:
    print(N*K//2)
    exit()
p = False


pre_num = 0
l_num = 1
if S[0]==S[-1]:
    pre_num = 1
    for i in range(1,N-1):
        if S[i]==S[i-1]:
            pre_num += 1
        else:
            break
    l_num = 1
    for i in range(N-1,0,-1):
        if S[i]==S[i-1]:
            l_num += 1
        else:
            break

for i in range(pre_num,N-l_num):
    if p:
        p = False
        continue
    if S[i]==S[i+1]:
        ans += 1
        p = True

ANS = (pre_num//2) + ans*K + ((pre_num+l_num)//2)*(K-1) + (l_num//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())
S2 = S + S
S3 = S + S + S
count1 = 0

for i in range(len(S)-1):
    if S[i] == S[i+1]:
        S[i+1] = '_'
        count1 += 1
count2 = 0

for i in range(len(S2)-1):
    if S2[i] == S2[i+1]:
        S2[i+1] = '_'
        count2 += 1
count3 = 0

for i in range(len(S3)-1):
    if S3[i] == S3[i+1]:
        S3[i+1] = '_'
        count3 += 1        
print(count1, count2)
if K == 1:
    print(count1)
else:
    print(K//2 * count2 + K%2 * (count3-count2))

import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

S = list(sr())
K = ir()

unit = 0
cur = ''
T = S.copy()
for i in range(len(T)):
    if T[i] == cur:
        T[i] = '_'
        unit += 1
    cur = T[i]

if len(set(S)) == 1:
    answer = len(S) * K // 2
elif S[0] != S[-1]:
    answer = unit * K
else:
    
    T = S.copy()
    head = 1; tail = 1
    for i in range(1, len(T)):
        if T[i] == T[0]:
            head += 1
        else:
            break
    for i in range(-2, -len(T)-1, -1):
        if T[i] == T[-1]:
            tail += 1
        else:
            break
    
    answer = unit * K - (head//2 + tail//2 - (head+tail)//2) * (K-1)

print(answer)
# 24


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

sames = 1
ans = 0
prev = 'prev'

for s in S:
	if prev == s:
		sames+=1
	else:
		if sames > 1:
			ans+=(sames//2)
			sames = 1
	prev = s
	
add = 0
if S[0] == S[len(S)-1]:
	for s in S:
		if s == S[0]:
			add+=1
		else:
			break
	for sr in reversed(S):
		if s == S[len(S)-1]:
			add+=1
		else:
			break

if len(set(list(S))) == 1:
	print(K*len(S)//2)
else:
	print(ans*K + (add//2)*(K-1))

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

sames = 1
ans = 0
prev = 'prev'


for s in S:
	if prev == s:
		sames+=1
	else:
		if sames > 1:
			ans+=(sames//2)
			sames = 1
	prev = s
ans+=(sames//2)


add_f = 0
add_b = 0
if S[0] == S[len(S)-1]:
	for s in S:
		if s == S[0]:
			add_f+=1
		else:
			break
	for sr in reversed(S):
		if sr == S[len(S)-1]:
			add_b+=1
		else:
			break
add = add_f+add_b


if len(set(list(S))) == 1:
	print(K*len(S)//2)
else:
	print(ans*K + (add//2)*(K-1) - (add_f//2)*(K-1) - (add_b//2)*(K-1))

Verdicts: Wrong Answer

Accepted
Problem: Given is a string S. Let T be the concatenation of K copies of S. We can repeatedly perform the following operation: choose a character in T and replace it with a different character. Find the minimum number of operations required to satisfy the following condition: any two adjacent characters in T are different.

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


Sfront = S[0]
Srear  = S[-1]
if Sfront == Srear and K > 1:
    Sleft = S.lstrip(Srear)
    kazu_left = len(S) - len(Sleft)
    ans += int(kazu_left/2)
    
    Sleftright = Sleft.rstrip(Srear)
    kazu_right = len(Sleft) - len(Sleftright)
    ans += int(kazu_right/2)
    
    kazu_wa = len(S) - len(Sleftright)
    ans += int(kazunoko/2) * (K-1)
    
    S = Sleftright
else:
    pass

while len(S) > 0:
#     print(S)
    current = S[0]
    Snext = S.lstrip(current)
    kazu = len(S) - len(Snext)
    ans += int(kazu/2) * K
    S = Snext
print(ans)

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


Sfront = S[0]
Srear  = S[-1]
if Sfront == Srear and K > 1:
    Sleft = S.lstrip(Srear)
    kazu_left = len(S) - len(Sleft)
    ans += int(kazu_left/2)
    
    Sleftright = Sleft.rstrip(Srear)
    kazu_right = len(Sleft) - len(Sleftright)
    ans += int(kazu_right/2)
    
    kazu_wa = len(S) - len(Sleftright)
    ans += int(kazunoko/2) * (K-1)
    
    S = Sleftright
else:
    pass

while len(S) > 0:
    print(S)
    current = S[0]
    Snext = S.lstrip(current)
    kazu = len(S) - len(Snext)
    ans += int(kazu/2) * K
    S = Snext
print(ans)

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


Sfront = S[0]
Srear  = S[-1]
if Sfront == Srear and K > 1:
    Sleft = S.lstrip(Srear)
    kazu_left = len(S) - len(Sleft)
    ans += int(kazu_left/2)
#     print(ans)
    
    Sleftright = Sleft.rstrip(Srear)
    kazu_right = len(Sleft) - len(Sleftright)
    if kazu_right != 0: 
        ans += int(kazu_right/2)

        kazu_wa = len(S) - len(Sleftright)
        ans += int(kazu_wa/2) * (K-1)

        S = Sleftright
         
    else: 
        ans = int(kazu_left * K / 2)
        
        S = ""
else:
    pass

while len(S) > 0:
#     print(S)
    current = S[0]
    Snext = S.lstrip(current)
    kazu = len(S) - len(Snext)
    ans += int(kazu/2) * K
    S = Snext
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):
S=list(input())
K=int(input())

if len(S) == 1:
  print(K//2)
  exit()
  
SR=S+[S[0]]
cnt=0
for i in range(len(S)-1):
  if SR[i]==SR[i+1]==SR[i+2]:
    SR[i+1]=0
    cnt+=1

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

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

if len(S) == 1:
  print(K//2)
  exit()
  
SR=S+[S[0]]
cnt=0
for i in range(len(S)-1):
  if SR[i]==SR[i+1]==SR[i+2]:
    SR[i+1]=0
    cnt+=1

for i in range(len(S)):
  if SR[i]==SR[i+1]:
    SR[i]=1
    cnt+=1

if (SR[-2]==0 or 1) and SR[-2]!=SR[-3]:
  ans = cnt*K-1
else:
  ans = cnt*K
print(ans)

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

for i in range(len(S)):
  if SR[i]==SR[i+1]:
    SR[i]=0
    cnt+=1
    
if SR[-2]==0 and S[-1]!=S[-2]:
  ans = cnt*K-1
else:
  ans = cnt*K
print(ans)

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

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

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

if s[0]==s[-1]:
  ans+= ((t[0]+t[-1])//2 - (t[0]//2+t[-1]//2))*(k-1)

print(ans)

Verdicts: Wrong Answer

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

F=0
for i in range(1,len(S)):
    if S[i]!=S[i-1]:
        F=1
        break
if F==0:
    print((len(S)*K)//2)
elif K==1:
    ans=0
    for i in range(1,len(S)):
        if S[i]==S[i-1]:
            ans+=1
            S[i]="#"
    print(ans)
else:
    ans1=0
    for i in range(1,len(S)):
        if S[i]==S[i-1]:
            ans1+=1
            S[i]="#"
    ans2=0
    S2=S*2
    for i in range(1,len(S2)):
        if S2[i]==S2[i-1]:
            ans2+=1
            S2[i]="#"
    print(ans1+(ans2-ans1)*(K-1))

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

check=0
for i in range(1,len(S)):
    if S[i]!=S[i-1]:
        check=1
#print(check)
if check==0:
    print(len(S)*K//2)
    exit()
import copy
s=copy.deepcopy(S)

cnt=0
for i in range(1,len(S)):
    if s[i]==s[i-1]:
        s[i]=str(i)
        cnt+=1

ss=S*2
cntss=0
#print(ss)
for i in range(1,len(ss)):
    if ss[i]==ss[i-1]:
        ss[i]=str(i)
        cntss+=1
print(cnt*(K)+(cntss-cnt*2)*(K-1))
#print(cnt,cntss)
#print(ss)
        

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 collections
s = str(input())
k = int(input())

ans = 0
#if s[0] == s[-1]:
#    ans += k

tmp = ''
tmp_num = 0
for i, w in enumerate(s):
    if i == 0:
        tmp = w
        tmp_num += 1
        continue
    
    if tmp == w:
        tmp_num += 1
        continue
    
    elif tmp != w:
        ans += (tmp_num // 2) * k
        #print('ans')
        #print(ans)
        tmp = w
        tmp_num = 1
    
    if i == len(s)-1:
        ans += (tmp_num // 2) * k

print(ans)



import collections
s = str(input())
k = int(input())

ans = 0
#if s[0] == s[-1]:
#    ans += k

tmp = ''
tmp_num = 0

check = ''
check_num = 0

if len(collections.Counter(s).keys()) == 1:
    ans = len(s)*k//2

else:
    for i, w in enumerate(s):
        if i == 0:
            tmp += w
            tmp_num += 1
            continue
        
        if tmp[-1] == w:
            tmp += w
            tmp_num += 1
        
        elif tmp[-1] != w:
            if check_num == 0:
                check = tmp
                check_num = 1

            ans += (tmp_num // 2) * k
            #print('ans', ans)
            tmp = w
            tmp_num = 1
        
        if i == len(s)-1:
            if len(tmp) == 1:
                if check[0] == tmp and (len(tmp)%2 == 1 and len(check)%2 == 1):
                    ans += k-1
            else:
                #print(check, tmp)
                if check[0] == tmp[-1] and (len(tmp)%2 == 1 and len(check)%2 == 1):
                    ans += k-1

            ans += (tmp_num // 2) * k
            #print('last', ans)

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

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

cnt,ans=0,0
for i in range(1,len(S)):
  if S[i-1]==S[i]:
    cnt+=1
  else:
    cnt+=1
    ans+=cnt//2
    cnt=0
ans+=cnt//2
if S[0]==S[-1] and S[-1]!=S[-2]:
  print(ans*k+k-1)
else:
  print(ans*k)

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

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

if len(S)==1:
  print(k//2)
  exit()
if len(S)==2:
  if S[0]==S[1]:
    print(k)
  else:
    print(0)
  exit()
  
if len(set(T))==1:
  if len(S)%2==0:
    print(len(S)//2*k)
  else:
    out=(len(S)//2)*(k-(k//2))+(len(S)//2+1)*(k//2)
    print(out)
  exit()
      
print(tmp+(ans-tmp)*(k-1))

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

tail = s[0]
if tail == s[-1]:
  tmp_cnt1 = 0
  tmp_cnt2 = 0
  for i in s:
    if tail == i:
      tmp_cnt1 += 1
    else:
      for i in s.reverse():
        if tail == i:
          tmp_cnt2 += 1
        else:
          break
      break
  if (tmp_cnt1 + tmp_cnt2) % 2 == 1:
    tail = ''

cnt=0
if len(s)==1:
  ret = k
else:
  tmp=s[0]
  tmp_cnt=0
  for i in s[1:]+tail:
    if tmp==i:
      tmp_cnt+=1
    else:
      cnt+=(tmp_cnt+1)//2
      tmp_cnt=0
    tmp=i
  cnt+=(tmp_cnt+1)//2
  ret=cnt*k
print(ret)

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

tail = s[0]
if tail == s[-1]:
  tmp_cnt1 = 0
  tmp_cnt2 = 0
  for i in s:
    if tail == i:
      tmp_cnt1 += 1
    else:
      for i in s.reverse():
        if tail == i:
          tmp_cnt2 += 1
        else:
          break
      break
  if (tmp_cnt1 + tmp_cnt2) % 2 == 1:
    tail = ''

cnt=0
if len(s)==1:
  ret = k
else:
  tmp=s[0]
  tmp_cnt=0
  for i in s[1:]+s[0]:
    if tmp==i:
      tmp_cnt+=1
    else:
      cnt+=(tmp_cnt+1)//2
      tmp_cnt=0
    tmp=i
  cnt+=(tmp_cnt+1)//2
  ret=cnt*k
print(ret)

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

tail = s[0]
plus = 0
flg = False
if tail == s[-1]:
  tmp_cnt1 = 0
  tmp_cnt2 = 0
  for i in s:
    if tail == i:
      tmp_cnt1 += 1
    else:
      break
  for i in s[::-1]:
    if tail == i:
      tmp_cnt2 += 1
    else:
      break
  if (tmp_cnt1 % 2) == 1 and (tmp_cnt2%2)==1:
    plus = 1
  if tmp_cnt1 == len(s):
    flg = True

cnt=0
if len(s)==1:
  ret = k//2
else:
  tmp=s[0]
  tmp_cnt=0
  for i in s[1:]:
    if tmp==i:
      tmp_cnt+=1
    else:
      cnt+=(tmp_cnt+1)//2
      tmp_cnt=0
    tmp=i
  cnt+=(tmp_cnt+1)//2
  ret=cnt*k
  if plus == 1:
    ret += k-1
  if flg:
    ret = len(s)*k//2
print(ret)

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

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

a=list(input())
k=int(input())
ans=0
if len(a)==1:
  print(k//2)
elif len(list(set(a)))==1:
  print((len(a)*k)//2)
else:  
  tmp=a[0]
  count1=0
  count2=0
  l=0
  while a[l]==tmp:
    count1+=1
    l+=1
  j=-1
  while a[j]==tmp:
    count2+=1
    j-=1
    
  for i in range(len(a)-1):
    if a[i]==a[i+1]:
      a[i+1]='1'
      ans+=1
  if a[0]==a[-1]:
    if count1%2==0:
      print(ans*k)
    else:
      print(ans*k+k-1)
  else:
    print(ans*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):
def cal(S):
    tmp, a, cnt = S[0], 1, 0
    flag = True
    for s in S[1:]:
        if S[0]!=s: flag=False
        if flag: a+=1
        if tmp[-1]==s:
            s = '*'
            ans += 1
        tmp += s
    return a, cnt


S = input().replace('\n', '')
k = int(input())
ans = 0
if len(list(set(S)))==1:
    ans = len(S)*k//2
else:
    a, cnt = cal(S)
    b, _ = cal(S[::-1])
    ans = cnt*k
    if S[0]==S[-1]:
        ans -= ((a//2)+(b//2)-((a+b)//2))*(k-1)
print(ans)

def cal(S):
    tmp, a, cnt = S[0], 1, 0
    flag = True
    for s in S[1:]:
        if S[0]!=s: flag=False
        if flag: a+=1
        if tmp[-1]==s:
            s = '*'
            cnt += 1
        tmp += s
    return a, cnt


S = input().replace('\n', '')
k = int(input())
ans = 0
if len(list(set(S)))==1:
    ans = len(S)*k//2
else:
    a, cnt = cal(S)
    b, _ = cal(S[::-1])
    ans = cnt*k
    if S[0]==S[-1]:
        ans -= ((a//2)+(b//2)-((a+b)//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):
def d_c(s):
  count = 0
  x = ''
  for i in range(len(s)):
    if x == s[0]:
      count += 1
      x = ''
    else:
      x = s[0]
    s = s[1:]
  return count
 
def num_con(s):
  x = s[0]
  s = s[1:]
  count = 1
  for i in range(len(s)):
    if s[0] == x:
      count += 1
      x = s[0]
      s = s[1:]
    else:
      break
  return count
      
    
s = input()
k = int(input())
 
if len(s)==1:
  print(k//2)
elif s[0]==s[-1]:
  f = num_con(s)
  m = num_con(s[::-1])
  dis = (f//2 + m//2 - (f+m)//2)*(k-1)
  print(dis)
  print(d_c(s)*k-dis)
else:
  print(d_c(s)*k)

def d_c(s):
  count = 0
  x = ''
  for i in range(len(s)):
    if x == s[0]:
      count += 1
      x = ''
    else:
      x = s[0]
    s = s[1:]
  return count
 
def num_con(s):
  x = s[0]
  s = s[1:]
  count = 1
  for i in range(len(s)):
    if s[0] == x:
      count += 1
      x = s[0]
      s = s[1:]
    else:
      break
  return count
      
    
s = input()
k = int(input())
 
if len(s)==1:
  print(k//2)
elif s[0]==s[-1]:
  f = num_con(s)
  m = num_con(s[::-1])
  dis = (f//2 + m//2 - (f+m)//2)*(k-1)
  print(d_c(s)-dis)
else:
  print(d_c(s)*k)

def d_c(s):
  count = 0
  x = ''
  for i in range(len(s)):
    if x == s[0]:
      count += 1
      x = ''
    else:
      x = s[0]
    s = s[1:]
  return count
 
def num_con(s):
  x = s[0]
  s = s[1:]
  count = 1
  for i in range(len(s)):
    if s[0] == x:
      count += 1
      x = s[0]
      s = s[1:]
    else:
      break
  return count
      
    
s = input()
k = int(input())
 
if len(s)==1:
  print(k//2)
elif num_con(s)==len(s):
  print((len(s)*k)//2)
elif s[0]==s[-1]:
  f = num_con(s)
  m = num_con(s[::-1])
  dis = (f//2 + m//2 - (f+m)//2)*(k-1)
  print(d_c(s)*k-dis)
else:
  print(d_c(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())
key = s[0]
count = 1
sum_count = 0
list1=[]
ans = 0
ans2 =0
for i in range(1,len(s)):
    if key == s[i]:
        count += 1
    else:
        list1.append(count)
        count = 1
        key = s[i]
list1.append(count)
if len(list1) == 1:
    print(list1[0]*k//2)
elif s[0] == s[len(s)-1]:
    ans += (list1[0]+list1[len(list1)-1])//2*(k-1)
    for i in range(1,len(list1)-1):
        ans2 += list1[i]//2
    print(ans2*k+ans+list1[0]//2*2)
else:
    for i in range(len(list1)):
        ans += list1[i]//2
    print(ans*k)

s = input()
k = int(input())
key = s[0]
count = 1
sum_count = 0
list1=[]
ans = 0
ans2 =0
for i in range(1,len(s)):
    if key == s[i]:
        count += 1
    else:
        list1.append(count)
        count = 1
        key = s[i]
list1.append(count)
if len(list1) == 1:
    print(list1[0]*k//2)
elif s[0] == s[len(s)-1]:
    ans += (list1[0]+list1[len(list1)-1])//2*(k-1)
    for i in range(1,len(list1)-1):
        ans2 += list1[i]//2
    print(ans2*k+ans+list1[0]//2+list1[len(list1)-1]//2)
else:
    for i in range(len(list1)):
        ans += list1[i]//2
    print(ans*k)

Verdicts: Wrong Answer

Accepted
Problem: Given is a string S. Let T be the concatenation of K copies of S. We can repeatedly perform the following operation: choose a character in T and replace it with a different character. Find the minimum number of operations required to satisfy the following condition: any two adjacent characters in T are different.

Submission attempts (in order):
().strip()
K = int(input())
if len(S)==1:
    cnt = K//2
else:
    A = []
    cur = 0
    for i in range(1,len(S)):
        if S[i]!=S[i-1]:
            if i-cur>=2:
                A.append([S[i-1],cur,i])
            cur = i
    if S[-1]==S[-2]:
        A.append([S[-1],cur,len(S)])
    cnt = 0
    for j in range(len(A)):
        cnt += (A[j][2]-A[j][1])//2
    if S[0]!=S[-1]:
        cnt = cnt*K
    else:
        if S[0]!=S[1] and S[-1]!=S[-2]:
            cnt = cnt+(cnt+1)*(K-1)
        elif S[0]==S[1] and S[-1]!=S[-2]:
            if (A[0][2]-A[0][1])%2==0:
                cnt = cnt*K
            else:
                cnt = cnt+(cnt+1)*(K-1)
        elif S[0]!=S[1] and S[-1]==S[-2]:
            if (A[-1][2]-A[-1][1])%2==0:
                cnt = cnt*K
            else:
                cnt = cnt+(cnt+1)*(K-1)
        elif S[0]==S[1] and S[-1]==S[-2]:
            if (A[0][2]-A[0][1])%2==0 or (A[-1][2]-A[-1][1])%2==0:
                cnt = cnt*K
            else:
                cnt = cnt+(cnt+1)*(K-1)
print(cnt)

S = input().strip()
K = int(input())
if len(S)==1:
    cnt = K//2
else:
    A = []
    cur = 0
    for i in range(1,len(S)):
        if S[i]!=S[i-1]:
            if i-cur>=2:
                A.append([S[i-1],cur,i])
            cur = i
    if S[-1]==S[-2]:
        A.append([S[-1],cur,len(S)])
    cnt = 0
    for j in range(len(A)):
        cnt += (A[j][2]-A[j][1])//2
    if S[0]!=S[-1]:
        cnt = cnt*K
    else:
        if S[0]!=S[1] and S[-1]!=S[-2]:
            cnt = cnt+(cnt+1)*(K-1)
        elif S[0]==S[1] and S[-1]!=S[-2]:
            if (A[0][2]-A[0][1])%2==0:
                cnt = cnt*K
            else:
                cnt = cnt+(cnt+1)*(K-1)
        elif S[0]!=S[1] and S[-1]==S[-2]:
            if (A[-1][2]-A[-1][1])%2==0:
                cnt = cnt*K
            else:
                cnt = cnt+(cnt+1)*(K-1)
        elif S[0]==S[1] and S[-1]==S[-2] and len(A)>1:
            if (A[0][2]-A[0][1])%2==0 or (A[-1][2]-A[-1][1])%2==0:
                cnt = cnt*K
            else:
                cnt = cnt+(cnt+1)*(K-1)
        else:
            cnt = (len(S)*K)//2
print(cnt)

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
import copy
s1 = list(set(s))
if len(s1) == 1:
    count = int((k * len(s)) / 2)
elif k >= 3:
    t1 = s * 5
    for i in range(len(t1) - 1):
        if t1[i] == t1[i + 1]:
            t1.pop(i + 1)
            t1.insert(i + 1, "")
            count += 1
    if count % 5 == 0:
        count = (count / 5) * k
    else (count + 2) % 5 == 0:
        count = ((count + 2) / 5) * k - 2
else:
    t1 = s * k
    for i in range(len(t1) - 1):
        if t1[i] == t1[i + 1]:
            t1.pop(i + 1)
            t1.insert(i + 1, "")
            count += 1
print(int(count))

s = list(input())
k = int(input())
count = 0
s1 = list(set(s))
if len(s1) == 1:
    count = int((k * len(s)) / 2)
elif k >= 3:
    t1 = s * 5
    for i in range(len(t1) - 1):
        if t1[i] == t1[i + 1]:
            t1.pop(i + 1)
            t1.insert(i + 1, "")
            count += 1
    if count % 5 == 0:
        count = (count / 5) * k
    elif (count + 1) % 5 == 0:
        count = ((count + 1) / 5) * k - 1
    else:
        count = ((count + 2) / 5) * k - 2
else:
    t1 = s * k
    for i in range(len(t1) - 1):
        if t1[i] == t1[i + 1]:
            t1.pop(i + 1)
            t1.insert(i + 1, "")
            count += 1
print(int(count))


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):
strings = list(input())
k = int(input())
counter = 0
same_starts = 0
for  i in range(len(strings)-1):
    if strings[i] != strings[i+1]:
        break
    same_starts += 1
for  i in range(len(strings)-1):
    if strings[i] == strings[i+1]:
        strings[i+1] = str(counter)
        counter += 1

if strings[0] != strings[-1]:
    print(counter * k)


if (same_starts + 1) == len(strings):
    
    if len(strings) % 2 == 0:
        print(k * len(strings)//2)
    else:
    
        
        if k % 2 == 0:
            print(counter * k // 2 + (counter + 1) * k // 2)
        else:
        
            print(counter * ((k - 1) // 2 + 1)+ (counter + 1) * (k - 1)//2)
else:
    if (same_starts+1) % 2 == 0:
        print(counter * k)
    else:
        print((counter+1) * (k-1) + counter)


strings = list(input())
k = int(input())
counter = 0
same_starts = 0
for  i in range(len(strings)-1):
    if strings[i] != strings[i+1]:
        break
    same_starts += 1
for  i in range(len(strings)-1):
    if strings[i] == strings[i+1]:
        strings[i+1] = str(counter)
        counter += 1


if (same_starts + 1) == len(strings):
    
    if len(strings) % 2 == 0:
        print(k * len(strings)//2)
    else:
    
        
        if k % 2 == 0:
            print(counter * k // 2 + (counter + 1) * k // 2)
        else:
        
            print(counter * ((k - 1) // 2 + 1)+ (counter + 1) * (k - 1)//2)
else:
    if (same_starts+1) % 2 == 0:
        print(counter * k)
    else:
        print((counter+1) * (k-1) + counter)


strings = list(input())
k = int(input())
counter = 0
same_starts = 0
for  i in range(len(strings)-1):
    if strings[i] != strings[i+1]:
        break
    same_starts += 1
for  i in range(len(strings)-1):
    if strings[i] == strings[i+1]:
        strings[i+1] = str(counter)
        counter += 1

if strings[0] != strings[-1]:
    print(counter * k)
else:
    
    if (same_starts + 1) == len(strings):
        
        if len(strings) % 2 == 0:
            print(k * len(strings)//2)
        else:
        
            
            if k % 2 == 0:
                print(counter * k // 2 + (counter + 1) * k // 2)
            else:
            
                print(counter * ((k - 1) // 2 + 1)+ (counter + 1) * (k - 1)//2)
    else:
        if (same_starts+1) % 2 == 0:
            print(counter * k)
        else:
            print((counter+1) * (k-1) + counter)


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):
n = int(input())
s = []
for _ in range(n):
    s.append(input())
check = []
testc = 1000
for i in range(n):
    test = 0
    for c in s[i]:
        test += int(c)
    if test == testc:
        check.append(i)
    elif test < testc:
        check.clear()
        testc = test
        check.append(i)

res = -1
for i in check:
    tres = 1
    flag = [-2 for _ in range(n)]

    flag[i] = 1
    que = [i]
    while que:
        target = que.pop()
        for j in range(n):
            if s[target][j] == "1":
                if flag[j] == -2:
                    flag[j] = flag[target] + 1
                    que.append(j)
                elif flag[j] != flag[target] + 1 and flag[j] != flag[target] - 1:
                    tres = -1
                    break
        if tres == -1:
            break
    if tres == -1:
        continue
    else:
        res = max(res, max(flag))

print(res)


s = input()
k = int(input())
if len(s) == 1:
    print(k // 2)
else:

    def counts(s):
        count = 0
        for i in range(len(s) - 1):

            if s[i] == s[i + 1]:
                count += 1
                s = s[: i + 1] + "." + s[i + 2 :]
        return count

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

s=input()
k=int(input())
cnt=1
l=[]
for i in range(1,len(s)):
    if s[i]==s[i-1]:
        cnt+=1
    else:
        l.append(cnt)
        cnt=1
l.append(cnt)
loop=0
ans=0
x=0
if s[0]!=s[-1]:
    for i in l:
        ans+=i//2
else:
    for i in range(1,len(l)-1):
        ans+=l[i]
        loop=(l[0]+l[-1])//2
        x=l[0]//2+l[-1]//2
print(ans*k+loop*(k-1)+x)

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

Wrong Answer

Accepted