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 sys import stdin
from itertools import groupby

s = stdin.readline().rstrip()
k = int(stdin.readline().rstrip())

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

li = []
point = 1
for i in range(len(s)-1):
    if s[i] == s[i+1]:
        point += 1
        if i == len(s)-2:
            li.append(point)
    else:
        li.append(point)
        point = 1
if s[-1] != s[-2]:
    li.append(1)

if s[0] != s[-1]:
    co = 0
    for j in range(len(li)):
        co += li[j]//2
    print(co*k)
    exit()

else:
    co = 0
    for i in range(1,-1):
        co += li[i]//2
    co *= k
    co += ((li[0]+li[-1])//2)+(k-1)
    co += li[0]//2
    co += li[-1]//2
    print(co)

from sys import stdin
from itertools import groupby

s = stdin.readline().rstrip()
k = int(stdin.readline().rstrip())

def cou(st):
    li = []
    point = 1
    for i in range(len(st)-1):
        if st[i] == st[i+1]:
            point += 1
            if i == len(st)-2:
                li.append(point)
        else:
            li.append(point)
            point = 1
    if st[-1] != st[-2]:
        li.append(1)
    return li

if len(s) == 1:
    lin = [1]
else:
    lin = cou(s)
if len(lin) == 1:
    print((lin[0]*k)//2)
    exit()

lin2 = cou(s)

if k > 1:
    if s[0] == s[-1]:
        lin[-1] += lin[0]

point = 0
point2 = 0
point3 = 0

for i in range(1,len(lin)):
    point3 += lin[i]//2

for w in range(1,len(lin2)):
    point2 += lin2[w]//2

point += (point3*(k-1))
point += point2
point += lin2[0]//2

print(str(point-1))

from sys import stdin
from itertools import groupby

s = stdin.readline().rstrip()
k = int(stdin.readline().rstrip())

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

li = []
point = 1
for i in range(len(s)-1):
    if s[i] == s[i+1]:
        point += 1
        if i == len(s)-2:
            li.append(point)
    else:
        li.append(point)
        point = 1
if s[-1] != s[-2]:
    li.append(1)

if s[0] != s[-1]:
    co = 0
    for j in range(len(li)):
        co += li[j]//2
    print(co*k)
    exit()

else:
    co = 0
    for k in range(1,-1):
        co += li[j]//2
    co = co*k
    co += (li[0]+li[-1])*(k-1)//2
    co += li[0]//2
    co += li[-1]//2
    print(co)

from sys import stdin
from itertools import groupby

s = stdin.readline().rstrip()
k = int(stdin.readline().rstrip())

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

li = []
point = 1
for i in range(len(s)-1):
    if s[i] == s[i+1]:
        point += 1
        if i == len(s)-2:
            li.append(point)
    else:
        li.append(point)
        point = 1
if s[-1] != s[-2]:
    li.append(1)

print(li)

if s[0] != s[-1]:
    co = 0
    for j in range(len(li)):
        co += li[j]//2
    print(co*k)
    exit()

else:
    co = 0
    for i in range(1,-1):
        co += li[i]//2
    co *= k
    co += ((li[0]+li[-1])//2)+(k-1)
    co += li[0]//2
    co += li[-1]//2

from sys import stdin
from itertools import groupby

s = stdin.readline().rstrip()
k = int(stdin.readline().rstrip())

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

li = []
point = 1
for i in range(len(s)-1):
    if s[i] == s[i+1]:
        point += 1
        if i == len(s)-2:
            li.append(point)
    else:
        li.append(point)
        point = 1
if s[-1] != s[-2]:
    li.append(1)

if s[0] != s[-1]:
    co = 0
    for j in range(len(li)):
        co += li[j]//2
    print(co*k)
    exit()

else:
    co = 0
    for k in range(1,-1):
        co += li[j]//2
    co += (li[0]+li[-1])*(k-1)//2
    co += li[0]//2
    co += li[-1]//2
    print(co)

from sys import stdin
from itertools import groupby

s = stdin.readline().rstrip()
k = int(stdin.readline().rstrip())

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

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

if s[-1] != s[-2]:
    li.append(1)

if len(li) == 1:
    print(li[0]*k//2)
    exit()

if s[0] != s[-1]:
    co = 0
    for j in range(len(li)):
        co += li[j]//2
    print(co*k)
    exit()

else:
    co = 0
    for i in range(len(li)):
        co += li[i]//2
    co *= k
    co -= ((li[0]//2+li[-1]//2)-(li[0]+li[-1])//2)*(k-1)
    print(co)

Verdicts: Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Accepted