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 zen(t):
    aa=0
    for i in range(len(t)-1):
        if t[i]==t[i+1]:
            aa+=1
        if len(t)-1==aa:
            return True
        else:
            return False

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

def zen(t):
    aa=0
    for i in range(len(t)-1):
        if t[i]==t[i+1]:
            aa+=1
        if len(t)-1==aa:
            return True
        else:
            return False

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

def is_all(t):
    for i in range(len(t)-1):
        if t[i]!=t[i+1]:
            return False
    return True

s=input()
n=len(s)
k=int(input())
cor=[0]
ans=0
c=1
if is_all(s):
    print(n*k//2)
    exit()
i=0
while i<n-1:
    if s[i]==s[i+1]:
        cor[0]+=1
        i+=1
    else:
        i+=1
        break
if cor[0]==0:
    cor[0]+=1
while i<n-1:
    if s[i]==s[i+1]:
        cor.append(1)
        while i<n-1:
            if s[i]==s[i+1]:
                cor[-1]+=1
                i+=1
            else:
                break
    i+=1
print(cor)
if s[0]==s[-1]:
    for i in range(1,len(cor)-1):
        ans+=cor[i]//2
    ans*=k
    ans+=(cor[0]+cor[-1])//2*(k-1)
    print(ans+cor[0]//2+cor[-1]//2)
else:
    for i in range(len(cor)):
        ans+=cor[i]//2
    print(ans*k)

def is_all(t):
    for i in range(len(t)-1):
        if t[i]!=t[i+1]:
            return False
    return True

s=input()
n=len(s)
k=int(input())
cor=[1]
ans=0
c=1
if is_all(s):
    print(n*k//2)
    exit()
i=0
while i<n-1:
    if s[i]==s[i+1]:
        cor[0]+=1
        i+=1
    else:
        i+=1
        break
while i<n-1:
    if s[i]==s[i+1]:
        cor.append(1)
        while i<n-1:
            if s[i]==s[i+1]:
                cor[-1]+=1
                i+=1
            else:
                break
    i+=1
#print(cor)
if s[0]==s[-1]:
    for i in range(1,len(cor)-1):
        ans+=cor[i]//2
    ans*=k
    ans+=(cor[0]+cor[-1])//2*(k-1)
    print(ans+cor[0]//2+cor[-1]//2)
else:
    for i in range(len(cor)):
        ans+=cor[i]//2
    print(ans*k)

Verdicts: Runtime Error

Runtime Error

Wrong Answer

Accepted