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

# is0i0is0i0

i = 0
c = 0
prev = False
for x in a:
  # print(prev)
  if c > 0:
    # print(x, a[c-1], c, prev, x == a[c-1] and not prev)
    if x == a[c-1] and not prev:
      i += 1
      prev = True
      c += 1
      continue
  prev = False
  # print("c++", c)
  c +=1 

if a[0] == a[-1]:
  i += 1
print(i*j)

str = str(input())
n = int(input())

seperation = []
tmp = ""
for x in range(len(str)-1):
  tmp += str[x]
  if str[x] == str[x+1]:
    if tmp == "":
      tmp += str[x]
  else:
    seperation.append(tmp)
    tmp = ""
tmp += str[-1]
seperation.append(tmp)

total = 0

# print(seperation)

if len(seperation) == 1:
  if (len(seperation[0]) == 1):
    return n//2

if (str[0] == str[-1]) and n>1 and len(seperation)>1:
  a = len(seperation[0])//2
  b = len(seperation[-1])//2
  # print("a,b:",a,b)
  total += a
  total += b
  seperation[0] += seperation[-1]
  a = seperation[0]
  print(a,len(a),len(a)//2, n-1)
  c = (len(a)//2)*(n-1)
  # print("c:",c)
  total += c
  seperation = seperation[1:-1]

# print(total)
# print(seperation)

for x in seperation:
  total += (len(x)//2)*n

print(total)

def main1(str, n):
  seperation = []
  tmp = ""
  for x in range(len(str)-1):
    tmp += str[x]
    if str[x] == str[x+1]:
      if tmp == "":
        tmp += str[x]
    else:
      seperation.append(tmp)
      tmp = ""
  tmp += str[-1]
  seperation.append(tmp)

  total = 0

  print(seperation)

  if len(seperation) == 1:
    if (len(seperation[0]) == 1):
      return n//2

  if (str[0] == str[-1]) and n>1 and len(seperation)>1:
    a = len(seperation[0])//2
    b = len(seperation[-1])//2
    # print("a,b:",a,b)
    total += a
    total += b
    seperation[0] += seperation[-1]
    a = seperation[0]
    print(a,len(a),len(a)//2, n-1)
    c = (len(a)//2)*(n-1)
    print("c:",c)
    total += c
    seperation = seperation[1:-1]

  # print(total)
  print(seperation)

  for x in seperation:
    total += (len(x)//2)*n

  # print(seperation)
  return total

a = str(input())
b = int(input())
print(a, b)

a = input()
j = int(input())

# is0i0is0i0

i = 0
c = 0
prev = False
for x in a:
  # print(prev)
  if c > 0:
    # print(x, a[c-1], c, prev, x == a[c-1] and not prev)
    if x == a[c-1] and not prev:
      i += 1
      prev = True
      c += 1
      continue
  prev = False
  # print("c++", c)
  c +=1 

# "abababa"
# "abababaabababaabababa"

if a[0] == a[-1]:
  i += 1
if (i==1):
  print(i*(j-1))
else:
  print(i*j)

a = input()
j = int(input())

i = 0
c = 0
prev = False
for x in a:
  if c > 0:
    if x == a[c-1] and not prev:
      i += 1
      prev = True
      c += 1
      continue
  prev = False
  # print("c++", c)
  c +=1 

# If the first and last characters are the same
if a[0] == a[-1]:
  # If the string repeats but does not contain any consecutive characters, e.g aba*2
  if (i==0) and j>1: 
    print(j-1)
  # If the string repeats and contains consecutive characters e.g aabba
  else: 
    print(i*j+(j-1))
# If the first and last characters are different e.g ab, abc, abba
else:
  print(i*j)


#aAaAaA

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

def main(s, k):
  separation = []
  tmp = ""
  for x in range(len(s)-1):
    tmp += s[x]
    if s[x] == s[x+1]:
      if tmp == "":
        tmp += s[x]
    else:
      separation.append(tmp)
      tmp = ""
  tmp += s[-1]
  separation.append(tmp)

  total = 0

  if len(separation) == 1:
    if (len(separation[0]) == 1):
      return k//2
    else:
      return (len(separation[0])*k)//2

  if (s[0] == s[-1]) and k>1 and len(separation)>1:
    a = len(separation[0])//2
    b = len(separation[-1])//2
    total += a
    total += b
    separation[0] += separation[-1]
    a = separation[0]
    c = (len(a)//2)*(k-1)
    total += c
    separation = separation[1:-1]

  # print(separation)

  for x in separation:
    total += (len(x)//2)*k

  return total

print(main(s,k))

Verdicts: Wrong Answer

Runtime Error

Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Accepted