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 =[i for i in input()]
K = int(input())
a = 1
b = []
c = []
result = 0
if S[0] != S[-1]:
  try:
    for j in range(len(S)):
      if S[j] == S[j+1]:
        a += 1
      else:
        b.append(a)
        a = 1
  except:
    b.append(a)
  for k in b:
    result += k//2
  print(result*K)
elif len(collections.Counter(S)) == 1:
  print(len(S)*K//2)
else:
  for j in range(len(S)):
    if S[j] == S[j + 1]:
      a += 1
    else:
      c.append(a)
      a = 1
      break
  for j in range(len(S)):
    if S[-j-1] == S[-j-2]:
      a += 1
    else:
      c.append(a)
      break
  S = S+S
  S = S[c[0]:-c[1]]
  try:
    for j in range(len(S)):
      if S[j] == S[j+1]:
        a += 1
      else:
        b.append(a)
        a = 1
  except:
    b.append(a)
  for k in b:
    result += k//2
  print(result*K//2+c[0]//2+c[1]//2+(c[0]+c[1])//2*K//2)

import collections
S =[i for i in input()]
K = int(input())
a = 1
b = []
c = []
SS = len(S)
result = 0
if S[0] != S[-1]:
  try:
    for j in range(len(S)):
      if S[j] == S[j+1]:
        a += 1
      else:
        b.append(a)
        a = 1
  except:
    b.append(a)
  for k in b:
    result += k//2
  print(result*K)
elif len(collections.Counter(S)) == 1:
  print(len(S)*K//2)
else:
  result2 = 0
  for j in range(len(S)):
    if S[j] == S[j + 1]:
      a += 1
    else:
      c.append(a)
      a = 1
      break
  S2 = S[c[0]:]
  try:
    for j in range(len(S2)):
      if S[j] == S[j + 1]:
        a += 1
      else:
        c.append(a)
        a = 1
  except:
    c.append(a)
  S = S+S
  S = S[c[0]:-(SS-c[0])]
  try:
    for j in range(len(S)):
      if S[j] == S[j+1]:
        a += 1
      else:
        b.append(a)
        a = 1
  except:
    b.append(a)
  for k in b:
    result += k//2
  for l in c:
    result2 += l//2
  print(result*(K-1)+result2)


import collections
S =[i for i in input()]
K = int(input())
a = 1
b = []
c = []
SS = len(S)
result = 0
if S[0] != S[-1]:
  try:
    for j in range(len(S)):
      if S[j] == S[j+1]:
        a += 1
      else:
        b.append(a)
        a = 1
  except:
    b.append(a)
  for k in b:
    result += k//2
  print(result*K)
elif len(collections.Counter(S)) == 1:
  print(len(S)*K//2)
else:
  result2 = 0
  for j in range(len(S)):
    if S[j] == S[j + 1]:
      a += 1
    else:
      c.append(a)
      a = 1
      break
  S2 = S[c[0]:]
  try:
    for j in range(len(S2)):
      if S2[j] == S2[j + 1]:
        a += 1
      else:
        c.append(a)
        a = 1
  except:
    c.append(a)
  S = S+S
  S = S[c[0]:-(SS-c[0])]
  try:
    a = 1
    for j in range(len(S)):
      if S[j] == S[j+1]:
        a += 1
      else:
        b.append(a)
        a = 1
  except:
    b.append(a)
  for k in b:
    result += k//2
  for l in c:
    result2 += l//2
  print(result*(K-1)+result2)


Verdicts: Wrong Answer

Wrong Answer

Accepted