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):
s = input()
num = int(input())

prev = ""

n = 0

if len(s) == 1:
    print(num // 2)
else:
    if len(set(s)) == 1:
        ans = len(s) * num // 2
    
    elif s[0] == s[-1]:
        b = 1
        for i in range(1, len(s)):
            if s[0] == s[i]:
                b += 1
            else:
                start = i
                break
        ss = s[::-1]
        
        c = 1
        for i in range(1, len(s)):
            if ss[0] == ss[i]:
                c += 1
            else:
                end = i
                break
        
        for i in range(start, len(s) - end):
            print(s[i])
            if prev == s[i]:
                n += 1
                prev = ""
            else:
                prev = s[i]
        ans = (b + c) // 2
        ans += b // 2 + c // 2
        ans += n * num

    else:
        for x in s:
            if prev == x:
                n += 1
                prev = ""
            else:
                prev = x
        ans = n * num


    print(ans)

s = input()
num = int(input())

prev = ""

n = 0

if len(s) == 1:
    print(num // 2)
else:
    if len(set(s)) == 1:
        ans = len(s) * num // 2
    
    elif s[0] == s[-1]:
        b = 1
        for i in range(1, len(s)):
            if s[0] == s[i]:
                b += 1
            else:
                start = i
                break
        ss = s[::-1]
        c = 1
        for i in range(1, len(s)):
            if ss[0] == ss[i]:
                b += 1
            else:
                end = i
                break
        for i in range(start, len(s) - end):
            print(s[i])
            if prev == s[i]:
                n += 1
                prev = ""
            else:
                prev = s[i]
        ans = (b + c) // 2
        ans += b // 2 + c // 2
        ans += n * num

    else:
        for x in s:
            if prev == x:
                n += 1
                prev = ""
            else:
                prev = x
        ans = n * num


    print(ans)

s = input()
num = int(input())


prev = ""

n = 0

if len(s) == 1:
    print(num // 2)
else:
    if len(set(s)) == 1:
        ans = len(s) * num // 2
    
    elif s[0] == s[-1]:
        b = 1
        for i in range(1, len(s)):
            if s[0] == s[i]:
                b += 1
            else:
                start = i
                break
        
        ss = s[::-1]
        c = 1
        for i in range(1, len(s)):
            if ss[0] == ss[i]:
                c += 1
            else:
                end = i
                break
        
        for i in range(start, len(s) - end):
            if prev == s[i]:
                n += 1
                prev = ""
            else:
                prev = s[i]
        ans = ((b + c) // 2) * (num - 1)
        ans += b // 2 + c // 2
        ans += n * num

    else:
        for x in s:
            if prev == x:
                n += 1
                prev = ""
            else:
                prev = x
        ans = n * num


    print(ans)

Verdicts: Wrong Answer

Wrong Answer

Accepted