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()
K = int(input())

def func(ms):
    r = 0
    k = 0
    m = ms[0]
    for i in range(1, len(ms)):
        if ms[i] == ms[i-1]:
            k+=1
        else:
            r += int((k+1)/2)
            k = 0
        m = ms[i]
    r += int((k+1)/2)
    return r            
    
if S[0] * len(S) == S:
    if len(S) == 1:
        print(int(K/2))
    else:
        print(int(len(S) * K / 2))
elif len(set(S)) == len(S):
    print(0)
elif S[0] == S[-1]:
    r = 0
    m = S[0]
    f = 0
    for c in S:
        if c == m:
            r += 1
            f += 1
        else:
            break   
    s = S[::-1]
    fe = 0
    for c in s:
        if c == m:
            r += 1
            fe += 1
        else:
            break
    S = S[f:-fe]
    tr = int(r/2) * (K-1)
    r = func(S) * K
    print(r+tr)
else:
    print(func(S)*K)
    
    
    
     

S = raw_input()
K = int(raw_input())

def func(ms):
    r = 0
    k = 0
    m = ms[0]
    for i in range(1, len(ms)):
        if ms[i] == ms[i-1]:
            k+=1
        else:
            r += int((k+1)/2)
            k = 0
        m = ms[i]
    r += int((k+1)/2)
    return r            

m = S[0]
f = True
for i in range(1, len(S)):
        if S[i]  != S[i-1]:
            f = False
            
if f == True:
    if len(S) == 1:
        print(int(K/2))
    else:
        print(int(len(S) * K / 2))
elif len(set(S)) == len(S):
    print(0)
elif S[0] == S[-1]:
    r = 0
    m = S[0]
    f = 0
    for c in S:
        if c == m:
            r += 1
            f += 1
        else:
            break   
    s = S[::-1]
    fe = 0
    for c in s:
        if c == m:
            r += 1
            fe += 1
        else:
            break
    S = S[f:-fe]
    tr = int(r/2) * (K-1)
    r = func(S) * K
    print(r+tr)
else:
    r = 0
    k = 0
    m = S[0]
    for i in range(1, len(S)):
        if S[i] == S[i-1]:
            k+=1
        else:
            r += int((k+1)/2)
            k = 0
        m = S[i]
    r += int((k+1)/2)
    print(r*K)
    
    
    
  


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

def func(ms):
    r = 0
    k = 0
    m = ms[0]
    for i in range(1, len(ms)):
        if ms[i] == ms[i-1]:
            k+=1
        else:
            r += int((k+1)/2)
            k = 0
        m = ms[i]
    r += int(k+1/2)
    return r            
    
if S[0] * len(S) == S:
    if len(S) == 1:
        print(int(K/2))
    else:
        print(int(len(S) * K / 2))
elif len(set(S)) == len(S):
    print(0)
elif S[0] == S[-1]:
    r = 0
    m = S[0]
    f = 0
    for c in S:
        if c == m:
            r += 1
            f += 1
        else:
            break   
    s = S[::-1]
    fe = 0
    for c in s:
        if c == m:
            r += 1
            fe += 1
        else:
            break
    S = S[f:-fe]
    tr = int(r/2) * (K-1)
    r = func(S) * K
    print(r+tr)
else:
    print(func(S)*K)
    
    
    
     

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

def func(ms):
    r = 0
    k = 0
    m = ms[0]
    for i in range(1, len(ms)):
        if ms[i] == ms[i-1]:
            k+=1
        else:
            r += int((k+1)/2)
            k = 0
        m = ms[i]
    r += int((k+1)/2)
    return r            
    
if S[0] * len(S) == S:
    if len(S) == 1:
        print(int(K/2))
    else:
        print(int(len(S) * K / 2))
elif len(set(S)) == len(S):
    print(0)
elif S[0] == S[-1]:
    r = 0
    m = S[0]
    f = 0
    for c in S:
        if c == m:
            r += 1
            f += 1
        else:
            break   
    s = S[::-1]
    fe = 0
    for c in s:
        if c == m:
            r += 1
            fe += 1
        else:
            break
    S = S[f:-fe]
    tr = int(r/2) * (K-1)
    r = func(S) * K
    print(r+tr)
else:
    print(func(S)*K)
    
    
    
     

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

def func(ms):
    r = 0
    k = 0
    m = ms[0]
    for i in range(1, len(ms)):
        if ms[i] == ms[i-1]:
            k+=1
        else:
            r += int((k+1)/2)
            k = 0
        m = ms[i]
    r += int((k+1)/2)
    return r            
    
if S[0] * len(S) == S:
    if len(S) == 1:
        print(int(K/2))
    else:
        print(int(len(S) * K / 2))
elif len(set(S)) == len(S):
    print(0)
elif S[0] == S[-1]:
    r = 0
    m = S[0]
    f = 0
    for c in S:
        if c == m:
            r += 1
            f += 1
        else:
            break   
    s = S[::-1]
    fe = 0
    for c in s:
        if c == m:
            r += 1
            fe += 1
        else:
            break
    S = S[f:-fe]
    tr = int(r/2) * (K-1)
    r = func(S) * K
    print(r+tr)
else:
    ms = S
    r = 0
    k = 0
    m = ms[0]
    for i in range(1, len(ms)):
        if ms[i] == ms[i-1]:
            k+=1
        else:
            r += int((k+1)/2)
            k = 0
        m = ms[i]
    r += int((k+1)/2)
    print(r*K)
    
    
    
     


s=input()
k=int(input())
if len(set(list(s)))==1:print((len(s)*k)//2);exit()
t=[1]
for i in range(1,len(s)):
  if s[i-1]==s[i]:t[-1]+=1
  else:t.append(1)
a=0
for i in t:a+=(i//2)*k
if s[0]==s[-1]:
  if t[0]%2==t[-1]%2==1:a+=k-1
print(a)


Verdicts: Wrong Answer

Runtime Error

Wrong Answer

Wrong Answer

Wrong Answer

Accepted