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 collections import Counter
s = input()
k = int(input())


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


if s[0] != s[-1]:
    total = 0
    cnt = 0
    for i in range(1,len(s)):
        if s[i] == s[i-1]:
            cnt += 1
        else:
            tmp = cnt // 2
            if cnt % 2 != 0:
                total += tmp + 1
            else:
                total += tmp
            cnt = 0
    print(total * k)


else:
    
    cnt = 1
    for i in range(1,len(s)):
        if s[i] == s[i-1]:
            cnt += 1
        else:
            break
    
    cnt2 = 1
    for i in range(len(s)-1,-1,-1):
        if s[i] == s[i-1]:
            cnt2 += 1
        else:
            break

    
    syoko = cnt // 2

    
    saikuru = (cnt + cnt2) // 2

    
    total = 0
    cnt3 = 0
    
    for i in range(cnt,len(s)-cnt2):
        if s[i] == s[i-1]:
            cnt3 += 1
        else:
            tmp = cnt3 // 2
            if cnt3 % 2 != 0:
                total += tmp + 1
            else:
                total += tmp
            cnt = 0
    saikuru += total
    print(syoko + saikuru * k - saikuru + cnt2//2 + total)






from collections import Counter
s = input()
k = int(input())


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


if s[0] != s[-1]:
    aida = 0
    cnt = 0
    for i in range(1,len(s)):
        if s[i] == s[i-1]:
            cnt += 1
        else:
            tmp = cnt // 2
            if cnt % 2 != 0:
                aida += tmp
            else:
                aida += tmp
            cnt = 0
    print(aida * k)


else:
    
    cnt = 1
    for i in range(1,len(s)):
        if s[i] == s[i-1]:
            cnt += 1
        else:
            break
    
    cnt2 = 1
    for i in range(len(s)-1,-1,-1):
        if s[i] == s[i-1]:
            cnt2 += 1
        else:
            break

    
    syoko = cnt // 2

    
    sotogawa = (cnt + cnt2) // 2

    
    aida = 0
    cnt3 = 0
    #print(s[cnt : len(s)-cnt2])
    for i in range(cnt+1,len(s)-cnt2+1):
        if s[i] == s[i-1]:
            cnt3 += 1
        else:
            tmp = cnt3 // 2
            if cnt3 % 2 != 0:
                aida += tmp
            else:
                aida += tmp
            cnt3 = 0

    saikuru = aida + sotogawa
    print(syoko + saikuru * k - saikuru + aida + cnt2//2)






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

cnt = 0
if K == 1:
    i = 1
    while True:
        if i + 1 >= len(S):
            break
        if S[i] == S[i+1]:
            cnt += 1
            i += 2
        else:
            i += 1

elif K >= 2:

    if S[0] == S[-1]:
        cnt += 1
    i = 1
    while True:
        if i + 1 >= len(S):
            break
        if S[i] == S[i+1]:
            cnt += 1
            i += 2
        else:
            i += 1


print(cnt * K)





from collections import Counter
s = input()
k = int(input())


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


if s[0] != s[-1]:
    aida = 0
    cnt = 0
    for i in range(1,len(s)):
        if s[i] == s[i-1]:
            cnt += 1
        else:
            tmp = cnt // 2
            aida += tmp
            cnt = 0
    print(aida * k)


else:
    
    cnt = 1
    for i in range(1,len(s)):
        if s[i] == s[i-1]:
            cnt += 1
        else:
            break
    
    cnt2 = 1
    for i in range(len(s)-1,-1,-1):
        if s[i] == s[i-1]:
            cnt2 += 1
        else:
            break

    
    syoko = cnt // 2

    
    sotogawa = (cnt + cnt2) // 2

    
    aida = 0
    cnt3 = 0
    print(s[cnt : len(s)-cnt2])
    for i in range(cnt+1,len(s)-cnt2+1):
        if s[i] == s[i-1]:
            cnt3 += 1
        else:
            tmp = cnt3 // 2
            aida += tmp
            cnt3 = 0
    
    saikuru = aida + sotogawa
    print(syoko + saikuru * k - saikuru + aida + cnt2//2)






from collections import Counter
s = input()
k = int(input())


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


if s[0] != s[-1]:
    aida = 0
    cnt = 0
    for i in range(1,len(s)):
        if s[i] == s[i-1]:
            cnt += 1
        else:
            tmp = cnt // 2
            if cnt % 2 != 0:
                aida += tmp + 1
            else:
                aida += tmp
            cnt = 0
    tmp = cnt // 2
    if cnt % 2 != 0:
        aida += tmp + 1
    else:
        aida += tmp


    print(aida * k)


else:
    
    cnt = 1
    for i in range(1,len(s)):
        if s[i] == s[i-1]:
            cnt += 1
        else:
            break
    
    cnt2 = 1
    for i in range(len(s)-1,-1,-1):
        if s[i] == s[i-1]:
            cnt2 += 1
        else:
            break

    
    syoko = cnt // 2

    
    sotogawa = (cnt + cnt2) // 2

    
    aida = 0
    cnt3 = 0
    #print(s[cnt : len(s)-cnt2])
    for i in range(cnt+1,len(s)-cnt2+1):
        if s[i] == s[i-1]:
            cnt3 += 1
        else:
            tmp = cnt3 // 2
            if cnt3 % 2 != 0:
                aida += tmp + 1
            else:
                aida += tmp
            cnt3 = 0

    saikuru = aida + sotogawa
    print(syoko + saikuru * k - saikuru + aida + cnt2//2)






Verdicts: Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Accepted