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 re

def nchars(s, n):
    
    assert n > 0
    reg = re.compile("(.)\\1{%d,}" % (n - 1))  
    while True:
        m = reg.search(s)
        if not m:
            break
        yield m.group(0)
        s = s[m.end():]

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

con = list(nchars(S, 2))
cons = []
for coni in con:
    cons.append(int(len(coni)/2))

c1 = cons[0]

c2 = 0
for i in range(len(cons)):
    if i != 0 and i != len(cons)-1:
        c2 += consi[i]

c3 = int(cons[0]+cons[len(cons)-1])/2

c4 = int(cons[len(cons)-1])

print(int(c1 + c2*K + c3 *(K-1) + c4))


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

import re

def nchars(s, n):
    
    assert n > 0
    reg = re.compile("(.)\\1{%d,}" % (n - 1))  
    while True:
        m = reg.search(s)
        if not m:
            break
        yield m.group(0)
        s = s[m.end():]

S = "cooooooooonteeeeeeeeeest"
K = 999993333

ans = 0
#print(S[0])
#print(len(S))



con = list(nchars(S, 2))

for coni in con:
    if int(len(coni))%2==0:
        print("even")
    elif int(len(coni))%2==1:
        print("odd")
    else:
        print("break")

    print(int(len(coni)/2))
    ans +=int(len(coni)/2)

print(ans*K)


import re

def nchars(s, n):
    
    assert n > 0
    reg = re.compile("(.)\\1{%d,}" % (n - 1))  
    while True:
        m = reg.search(s)
        if not m:
            break
        yield m.group(0)
        s = s[m.end():]

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

ans = 0
#print(S[0])
#print(len(S))



con = list(nchars(S, 2))

for coni in con:
    if int(len(coni))%2==0:
        print("even")
    elif int(len(coni))%2==1:
        print("odd")
    else:
        print("break")

    print(int(len(coni)/2))
    ans +=int(len(coni)/2)

print(ans*K)



import re

def nchars(s, n):
    
    assert n > 0
    reg = re.compile("(.)\\1{%d,}" % (n - 1))  
    while True:
        m = reg.search(s)
        if not m:
            break
        yield m.group(0)
        s = s[m.end():]

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

ans1 = 0
#print(S[0])
#print(len(S))



con = list(nchars(S, 2))

for coni in con:
    """
    if int(len(coni))%2==0:
        print("even")
    elif int(len(coni))%2==1:
        print("odd")
    else:
        print("break")
    """
    #print(int(len(coni)/2))
    ans1 +=int(len(coni)/2)

ans2 = 0
if S[0]==S[len(S)-1]:
    ans2 += 1


print(ans1*K+ans2*(K-1))



import re

def nchars(s, n):
    
    assert n > 0
    reg = re.compile("(.)\\1{%d,}" % (n - 1))  
    while True:
        m = reg.search(s)
        if not m:
            break
        yield m.group(0)
        s = s[m.end():]

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

con = list(nchars(S, 1))
#print(con)
if len(con)==1:
    print(int(len(S)*K/2))

else:
    cons = []
    for coni in con:
        cons.append(int(len(coni)/2))

    c1 = cons[0]

    c2 = 0
    for i in range(len(cons)):
        if i != 0 and i != len(cons)-1:
            c2 += cons[i]

    if con[0][0]==con[-1][0]:
        c3 = int(len(con[0]+con[-1])/2)
    else:
        c3 = int(len(con[0])/2) + int(len(con[-1])/2)

    c4 = int(cons[-1])

    print(int(c1 + c2*K + c3 *(K-1) + c4))


Verdicts: Runtime Error

Wrong Answer

Wrong Answer

Wrong Answer

Accepted