Problem:


Score : 300 points

Problem Statement

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.

Constraints

1 \leq |S| \leq 100

S consists of lowercase English letters.

1 \leq K \leq 10^9

K is an integer.

Input

Input is given from Standard Input in the following format:

S
K

Output

Print the minimum number of operations required.

Sample Input 1

issii
2

Sample Output 1

4

T is issiiissii.  For example, we can rewrite it into ispiqisyhi, and now any two adjacent characters are different.

Sample Input 2

qq
81

Sample Output 2

81

Sample Input 3

cooooooooonteeeeeeeeeest
999993333

Sample Output 3

8999939997



Sample input:
issii
2


Sample output:
4

Submission status: Wrong Answer

Solution code:
S = input()
K = int(input())
N = len(S)
cnt = 0
flg1 = False
flg2 = False
flg3 = False
for i in range(N-1):
    if S[i] != S[i+1]:
        flg3 = True
        break
if (flg3 == False) and N % 2 == 1:
    print((N*K)//2)
    exit()
# if N == 1:
#     print(K//2)
#     exit()
# if N == 3:
#     print((K*3)//2)
#     exit()
if S[0] == S[N-1]:
    cnt += 1
    flg1 = True
for i in range(N-1):
    if flg2:
        flg2 = False
        continue
    if (i == N - 2) and flg1:
        break
    if S[i] == S[i+1]:
        cnt += 1
        flg2 = True
# print(cnt)
print(cnt*K)

Submission status: Wrong Answer

Solution code:
s = list(input())
k = int(input())
same = []
tmp = 1
ans = 0
tsunagi = 0
for i in range(len(s)-1):
         if s[i] == s[i+1]:
                  tmp += 1
         else:
                  same.append(tmp)
                  tmp = 1
same.append(tmp)
if s[0] == s[len(s)-1] and same[0] ==1 and same [len(same)-1] == 0:
         tsunagi = 1
if tmp == len(s):
         print((len(s)*k)//2)
else:
         for i in range(len(same)):
                  ans += (same[i]//2)*k
         ans += (tsunagi)*(k-1)
         print(ans)

Submission status: Wrong Answer

Solution code:
from sys import stdin

S = stdin.readline().rstrip()
K = int(stdin.readline().rstrip())
ans_odd = 0
ans_even = 0
changed_odd = [False] * len(S)
changed_even = [False] * len(S)

if len(S) == 1:
    print(K // 2)
    exit()

for i in range(1, len(S)):
    if S[i] == S[i - 1] and not changed_odd[i - 1]:
        ans_odd += 1
        changed_odd[i] = True

if S[0] == S[len(S) - 1] and not changed_odd[len(S) - 1]:
    ans_odd += 1
    changed_even[0] = True

for i in range(1, len(S)):
    if S[i] == S[i - 1] and not changed_even[i - 1]:
        ans_even += 1
        changed_even[i] = True

if S[0] == S[len(S) - 1] and not changed_even[len(S) - 1]:
    print(ans_odd * (K - 1) + ans_even)
else:
    if K % 2 == 0:
        print((ans_odd + ans_even) * (K // 2))
    else:
        print((ans_odd + ans_even) * (K // 2) + min(ans_even, ans_odd))

Submission status: Wrong Answer

Solution code:
import string


def count_changes(s, k, pool, prev=None):
    if k == 0:
        return 0, None, None
    t = s * k
    count = 0
    i = 0
    prev = prev or t[0]
    for cur in t[1:]:
        if cur == prev:
            count += 1
            prev = pool[i]
            i = (i + 1) % length
        else:
            prev = cur
    return count, i, prev


if __name__ == '__main__':
    s = input()
    k = int(input())
    pool = list(set(string.ascii_lowercase) - set(s))
    length = len(pool)
    if k <= 2:
        print(count_changes(s, k, pool)[0])
    else:
        base_count, i, prev = count_changes(s, 3, pool)
        d, rest = divmod(k, 3)
        print(base_count * d + count_changes(s, rest, pool, prev)[0])

Submission status: Wrong Answer

Solution code:
S = input()
K = int(input())

if len(S) == 1:
    print(int(K/2))
else:    
    count = 0
    bef = ""
    isbefchange = False
    for i in range(0, len(S)):
        if(isbefchange == False and S[i] == bef):
            count += 1
            isbefchange = True
            bef = S[i]
            continue
        bef = S[i]
        isbefchange = False
    count *= K
    if(isbefchange == False and S[len(S)-1] == S[0]):
        count += (K-1)
    print(count)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

S = list(input().strip())
K = int(input())

L = [i for i in S]


if len(S) == 1:
    if K == 1:
        print(0)
    else:
        print(K//2)
    sys.exit()

count = 0
tmp = S[0]
for i in range(1, len(S)):
    if S[i] == tmp:
        count += 1
        S[i] = "A"
        tmp = S[i]
    else:
        tmp = S[i]

count2 = 0
if S[0] == S[-1]:
    L[0] = "A"
    count2 += 1
    tmp = L[0]
    for i in range(1, len(L)):
        if L[i] == tmp:
            count2 += 1
            L[i] = "A"
            tmp = L[i]
        else:
            tmp = L[i]
    print((K//2)*count2 + (K//2+K%2)*count)
else:
    print(count * K)

Submission status: Wrong Answer

Solution code:
S=list(input())
K=int(input())

if len(S) == 1:
  print(K//2)
  exit()
  
SR=S+[S[0]]
cnt=0
for i in range(len(S)-1):
  if SR[i]==SR[i+1]==SR[i+2]:
    SR[i+1]=0
    cnt+=1

for i in range(len(S)):
  if SR[i]==SR[i+1]:
    SR[i]=1
    cnt+=1

if (SR[-2]==0 or 1) and SR[-2]!=SR[-3]:
  ans = cnt*K-1
else:
  ans = cnt*K
print(ans)

Submission status: Wrong Answer

Solution code:
S = list(input())
K = int(input())
S2 = S[:] * 2

if len(S) == 1:
    print(K//2)
    exit()
cons = 0
for i in range(len(S)-1):
    if S[i] == S[i+1]:
        cons += 1
        S[i+1] = '_'
cons2 = int(S[0] == S[-1])
if K == 1:
    print(cons)
    exit()
cons3 = 0
for i in range(len(S2) - 1):
    if S2[i] == S2[i+1]:
        cons3 += 1
        S2[i+1] = '_'
if cons3 != cons * 2 + cons2:
    minus = 1
else:
    minus = 0
print(cons * K + cons2 * (K-1) - minus * (K-1))

Submission status: Wrong Answer

Solution code:
def count(S):
    ans = 0
    i = 1
    while i < len(S):
        if S[i-1] == S[i]:
            i += 1
            ans += 1
        i += 1
    return ans

def main():
    S = input()
    K = int(input())

    if K == 1:
        print(count(S))
        exit()

    ans = count(S*2)
    ans *= K // 2
    if K % 2 == 1:
        ans += count(S)

    print(ans)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
s = input()
k = int(input())

if len(set(s)) ==1:
  print(k //2)
  exit(0)

is_same = False
b = ''
count = 0
tail = False
for c in s:
  if c == b and not is_same:
    count += 1
    is_same = True
  else:
    is_same = False
  b = c
else:
  if s[0] == s[-1] and not is_same:
    tail = True
ans = count * k
if tail:
  ans += k-1
print(ans)

Submission status: Wrong Answer

Solution code:
from itertools import groupby
s = input()
k = int(input())
l = [[k, len(list(g))] for k, g in groupby(s)]
ans = 0
for i in range(len(l)):
  if l[i][1] > 1:
    ans += l[i][1] // 2
if len(s) == 1:
  print(k // 2)
else:
  print(ans * k)

Submission status: Wrong Answer

Solution code:
S = input()
K = int(input())

if len(S) == 1:
    print(K//2)
elif len(set(S)) == 1:
    print(len(S)*K//2)
else:
    c = 0
    flg = False
    for i in range(len(S)-1):
        if S[i] == S[i+1] and flg is False:
            c += 1
            flg = True
        else:
            flg = False

    if flg is False and S[-1] == S[0]:
        j = 1
        if len(S) >= 4 and S[0] == S[1]:
            j = 0
            if len(S) >= 4 and S[0] == S[1] and S[1] == S[2]:
                j = 1

    else:
        j = 0

    print(c*K+j*(K-1))
    # print(c, j)

Submission status: Wrong Answer

Solution code:
S = list(input())
K = int(input())
ans = 0
i= 1

if len(S) == 1:
    ans = -(-K//2)
else:
    while i < len(S):
        if S[i-1] == S[i]:
            ans += 1
            i += 1
        i+=1
    ans *= K
    if K != 1:
        if S[0] == S[len(S)-1] and S[len(S)-2] != S[len(S)-1]: ans += K -1



print(ans)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
s=list(input())
k=int(input())
cnt=1
cnt2=0
tmp=0
flg=0
flg2=0
for i in range(len(s)):
    if tmp==s[i]:
        cnt+=1
    else:
        cnt2+=cnt//2
        cnt=1
    tmp=s[i]
cnt2+=cnt//2
if len(s)==1:
    flg2=1

elif s[0]==s[-1]:
    m=0
    cnt3=0
    while s[m]==s[0]:
        cnt3+=1
        m+=1
        if m==len(s)-1:
            cnt3+=1
            break
    n=1
    cnt4=0
    while s[-n]==s[0]:
        cnt4+=1
        n+=1
        if n==len(s):
            cnt4+=1
            break
    if cnt3%2==1 and cnt4%2==1:
        flg=1

if flg==1:
    ans=cnt2*k+k-1
elif flg2==1:
    ans=k//2
else:
    ans=cnt2*k
    
print(ans)

Submission status: Wrong Answer

Solution code:
s = input()
k = int(input())


cnt = 0
l = [0]*(len(s))
if(len(s) == 1):
    cnt = k // 2
else :
    for i in range(len(s)-1):
        if(l[i] == 0 and s[i] == s[i+1]):
            l[i+1] = 1
            cnt += 1

    cnt = cnt * k
    if(l[len(s)-1] != 1 and s[0] == s[len(s)-1]):
        cnt += k
print(cnt)

Submission status: Wrong Answer

Solution code:
t=str(input())
k=int(input())
L = len(t)
tmp = t[0]
n = 0 #change
flag = 0
for i in range(1,L):
  if flag==1:
    flag=0
  elif t[i]==tmp:# and flag==0:
    n+=1
    flag=1  
  tmp=t[i]
ans=k*n

if L>2:
  if t[0]==t[-1] and flag==0:
    if k%2==1 and t[0]==t[1]:
      ans+=k-2
    else:
      ans+=k-1

if L==1:
  ans=k//2
print(ans)

Submission status: Wrong Answer

Solution code:
s = input()
k = int(input())
a = [0 for i in range(len(s))]
cnt = 0
i = 0
while i < len(s)-1:
  if s[i] == s[i+1]:
    a[i] = 1
    a[i+1] = 1
    i += 2
    cnt += 1
  elif s[i] != s[i+1]:
    i += 1

if a[0] == 0 and a[-1] == 0 and s[0] == s[-1]:
  print(cnt*k + k-1)
else:
  print(cnt*k)

Submission status: Wrong Answer

Solution code:
import string

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

end = len(S) -1
j = 0

for i in range(1, len(S)-1):
    if S[i-1] == S[i]:
        chars = list(string.ascii_lowercase)
        pre = S[i-1]
        back = S[i+1]
        if pre != back:
            chars.pop(chars.index(pre))
            chars.pop(chars.index(back))
        else:
            chars.pop(chars.index(pre))
        S[i] = chars[0]
        j += 1
    else:
        continue

if S[end] == S[0]:
    chars = list(string.ascii_lowercase)
    pre = S[end -1]
    back = S[0]
    if pre != back:
        chars.pop(chars.index(pre))
        chars.pop(chars.index(back))
    else:
        chars.pop(chars.index(pre))
    S[end] = chars[0]
    j += 1

print(j*K)

Submission status: Wrong Answer

Solution code:
S = input()
K = int(input())
flag = False
count = 0
for i in range(len(S)-1):
    if not flag:
        if S[i] == S[i+1]:
            count += 1
            flag = True
    else:
        flag = False
ans = 0
if flag:
    ans = count * K
elif S[0] == S[-1]:
    ans += count
    count = 0
    for i in range(1, len(S)-1):
        if not flag:
            if S[i] == S[i+1]:
                count += 1
                flag = True
        else:
            flag = False
    ans += (count + 1)*(K-1)
else:
    ans = count * K
print(ans)

Submission status: Wrong Answer

Solution code:
s = input()
k = int(input())
cnt = 0
i = 0
c0 = 0
c1 = 0
key = 0
endkey = 0
while i < len(s) - 1:
    if s[i] == s[i + 1]:
        start = i
        end = i
        for j in range(i + 1, len(s)):
            end = j
            if s[j] != s[i]:
                break

        if end == len(s) - 1: #もし最後の一文字が連続に含まれるとき
            if (end - start) % 2 == 0 and s[-1] == s[0]: #最後の一文字が連続でかつ最初の文字と同じでかつ奇数の時
                end += 1
                endkey = 1
            end += 1
        cnt += (end - start) // 2 * k

        if start == 0 and end == len(s) and len(s) % 2 == 1:
            key = 1
            cnt += (end - start) * k // 2
            if k % 2 == 1:
                cnt += (end - start) // 2
        i = end - 1
        # print(start, end)
    i += 1

if len(s) == 1:
    cnt += k // 2
if endkey:
    cnt -= 1
print(cnt, endkey)

Submission status: Wrong Answer

Solution code:
s = input()
k = int(input())

ops = 0
i = 1

while i < len(s):
    if s[i-1] == s[i]:
        ops += 1
        i += 1
    i += 1

ops *= k

between = False

if i == len(s) and k >= 2 and s[0] == s[-1]:
    between = True

if i == len(s) and k >= 2 and len(s) >= 2 and s[0] == s[1]:
    between = False

if between:
    ops += k - 1

print(ops)

Submission status: Wrong Answer

Solution code:
S=list(input())
K=int(input())
c=0
f=1
if len(S) == 1:
    ans=K//2
else:
    for a in range(len(S)-1):
        if S[a] == S[a+1]:
            c+=1
            if a != len(S)-2 and S[a+1] == S[a+2]:
                f+=1
            else:
                c-=f//2
                f=1
    ans=c*K
    if S[0] == S[len(S)-1]:
        if len(S) > 2 and ((S[0] == S[1] and S[1] == S[2]) or (S[len(S)-1] == S[len(S)-2] and S[len(S)-3] == S[len(S)-2])):
            ans+=K-1
print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
s = input()
k = int(input())

tmp_count = 0
continue_str = s[0]
count_in_loop = 0
half_count = 0
result = 0
if len(s) == 1:
    result = k // 2
else:
    for i, si in enumerate(s):
        # print(i)
        if continue_str == si:
            tmp_count += 1
            # print("matched: " + str(tmp_count))
        else:
            count_in_loop += tmp_count // 2
            tmp_count = 1
            continue_str = si
            # print("unmatched: " + str(count_in_loop))
        if i == len(s) - 1:
            count_in_loop += tmp_count // 2
            if (tmp_count % 2 == 1) & (si == s[0]):
                half_count = 1
    result = count_in_loop * k + half_count * (k-1)
print(result)

Submission status: Wrong Answer

Solution code:
s = input()
k = int(input())
dup = 0
tmp = ""

if s == s[0] * len(s):
    answer = len(s) * k // 2
    print(answer)
    quit()

for c1, c2 in zip(s, s[1:]):
    if c1 == c2:
        if tmp:
            tmp = ""
        else:
            dup += 1
            tmp = c1
    else:
        tmp = ""

answer = dup * k

if s[0] == s[-1]:
   dup += int(0.5 * k)

print(answer)

Submission status: Wrong Answer

Solution code:
s=input()
k=int(input())
n=len(s)
if n==1:
    print(k//2)
    exit()
if n==2:
    if s[0]==s[1]:
        print(k)
    else:
        print(0)
    exit()
tc=1
ac=0
p=s[0]
for i in range(1,n):
    if s[i]==p:
        tc+=1
    else:
        ac+=tc//2
        tc=1
        p=s[i]
else:
    ac+=tc//2
ans=ac*k
if s[0]==s[-1]:
    if n==3:
        ans+=1
    elif s[0]!=s[1] and s[-1]!=s[-2]:
        ans+=k-1
print(ans)

Submission status: Wrong Answer

Solution code:
s = str(input())
k=int(input())



if len(s)==1:
    if k<=2:
        ans = 0
    else:
        ans = k//2
elif len(s)==2:
    if s[0]==s[1]:
        ans = k
    else:
        ans = 0
else:
    if k == 1:
        ans = 0
        bef = ""
        befchen = False
        trignum = 0
        for i in range(len(s)):
            now = s[i]
            if bef==now:
                if befchen == False:
                    ans += 1
                    befchen = True
                    trignum = i
            if  befchen == True:
                if trignum == i-1:
                    befchen = False
            bef = now

    elif k >=2:
        ans = 0
        bef = ""
        befchen = False
        trignum = 0
        for i in range(len(s)):
            now = s[i]
            if bef==now:
                if befchen == False:
                    #print(now)
                    ans += 1
                    befchen = True
                    trignum = i
            if  befchen == True:
                if trignum == i-1:
                    befchen = False
            bef = now
        
        if s[0]==s[-1]:
            if befchen == False:
                ans += 1
                
        ans *= k
        
        if s[0]==s[-1]:
            if befchen == False:
                ans -= 1

print(ans)

Submission status: Wrong Answer

Solution code:
s = input()
k = int(input())

if len(s) == 1:
    print(k//2)
    exit(0)

if s[0] == s[-1] and s[0] != s[1] and s[-1] != s[-2]:
    count = 1
else:
    count = 0

ngo = 1
for i in range(len(s)-1):
    if s[i] == s[i+1]:
        ngo+=1
    else:
        count += ngo//2
        ngo=1
count += ngo//2

ngongo = 0
while ngongo < len(s) and s[len(s)-ngongo-1] == s[-1]:
    ngongo+=1

ngongongo = 0
while ngongongo < len(s) and s[ngongongo] == s[0]:
    ngongongo += 1
    
f = 0
if ngongo > 1 and ngongongo > 1 and ngongo %2 == 1 and ngongongo %2 == 1 and s[0] == s[-1]:
    count += 1
    if ngongo%2 == 1:
        f += 1

print(count*k-f)

Submission status: Wrong Answer

Solution code:
s=input()
k=int(input())
if len(s)==1:
    print(k//2)
elif len(s)==2:
    if s[0]==s[1]:print(k)
    else:print(0)
elif k!=1 and len(s)>2:
    cnt=0;i=0
    while i < len(s)-1:
        if s[i]==s[i+1]:
            cnt+=1
            i+=2
        else:i+=1
    if s[-1]!=s[0]:print(cnt*k)
    else:
        j=0;jcnt=0
        while j < len(s)-2:
            if s[j]==s[j+1]:
                jcnt+=1
                j+=2
            else:j+=1
        print(jcnt*(k-1)+k-1+cnt)
else:
    i=0
    cnt=0
    while i < len(s)-1:
        if s[i]==s[i+1]:
            cnt+=1
            i+=2
        else:i+=1
    print(cnt)

Submission status: Wrong Answer

Solution code:
s = raw_input()
k = raw_input()
c = 0
i = 0
while( i < len(s)-1 ):
  if s[i] == s[i+1]:
    c += 1
    i += 1
  elif i == len(s)-2 and s[0] == s[len(s)-1]:
    c += 1
  i += 1
print(int(k)*c)

Submission status: Wrong Answer

Solution code:
S = input()
K = int(input())
brob = 0
temp = 1
first = 0
for i in range(len(S)-1):
    if S[i] == S[i+1]:
        temp += 1
    else:
        if brob == 0:
            first = brob
        brob += temp // 2
        temp = 1
        
brob += temp // 2
last = temp

if K == 1:
    print(brob)

else:
    if len(S) == 1:
        print(K // 2)
    
    elif S[-1] != S[0]:
        print(brob * K)

    elif last % 2 or first % 2:
        print(brob * K + K - 1)

    else:
        print(brob * K)

Submission status: Wrong Answer

Solution code:
from sys import stdin
S = (stdin.readline().rstrip())
K = int(stdin.readline().rstrip())
ans = 0
N=len(S)
cnt = 1
G = S+"@"
for i in range(0,N):
    if G[i] == G[i+1]:
        cnt += 1
    else:
        if cnt != 1:
            #print(cnt)
            ans += (cnt//2)
            cnt = 1
for_eq = 1
rev_eq = 1
revS = S[::-1]
for j in range(0,N-1):
    if S[j] == S[j+1]:
        for_eq += 1
    else:
        break
for k in range(0,N-1):
    if revS[k] == revS[k+1]:
        rev_eq += 1
    else:
        break
#print(ans)
ans = ans*K
#print(rev_eq,for_eq)
if S[0] == S[-1]:
  if (rev_eq % 2 != 0) and (for_eq % 2 != 0):
    ans += ((K+1)//2)
print(ans)

Submission status: Wrong Answer

Solution code:
s = input()
k = int(input())

l = list(s)

count = 0
new_l = l.copy()
for i, c in enumerate(s[1:]):
    if c == new_l[i]:
        new_l[i + 1] = 0
        count += 1
result = count * k
if s[0] == s[-1]:
    result = +k - 1
print(result)

Submission status: Wrong Answer

Solution code:
s = input()
k = int(input())
#
# s='aaaabba'
# k=13

leng = len(s)
if(leng==1):
    print(k//2)
    exit()
elif(leng==2):
    if(s[0]==s[1]):
        print(k)
    else:
        print(0)
    exit()

if(s[:-1]==s[1:]):
    print(leng*k//2)
    exit()

ct = 0
for i in range(1,leng):
    if(s[i-1]==s[i]):
        s = s[:i] + '?' + s[i+1:]
        ct += 1

ans = ct*k
if(s[0]==s[leng-1]):
    if(s[1]!='?'):
        ans += k-1

print(ans)

Submission status: Wrong Answer

Solution code:
s = list(input())
k = int(input())

check = ""
check_cnt = 0
ans1 = 0
for i in range(len(s)):
    if check_cnt == 0:
        check = s[i]
        check_cnt += 1
        continue
    if check == s[i]:
        check_cnt += 1
        continue
    else:
        check = s[i]
        if check_cnt == 1:
            pass
        elif check_cnt%2 == 0:
            ans1 += check_cnt//2
        else:
            ans1 += (check_cnt - 1)//2
    check_cnt = 1
else:
    if check_cnt == 1:
        pass
    elif check_cnt%2 == 0:
        ans1 += check_cnt//2
    else:
        ans1 += (check_cnt - 1)//2
    
cnt2 = 0
cnt3 = 0

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

add = 0
if cnt2%2 == 1 and cnt3%2 == 1:
    add = 1
    
same = s[0]
for i in range(len(s)):
    if same == s[i]:
        continue
    else:
        break
else:
    t = len(s) * k
    if k%2 == 0:
        print(t//2)
    else:
        print((t-1)//2)
    exit()
    
print(ans1 * k + add * (k-1))

Submission status: Wrong Answer

Solution code:
def zen(s):
    ans=0
    for i in range(len(s)-1):
        if s[i]==s[i+1]:
            ans+=1
        if len(s)-1==ans:
            return True
        else:
            return False

s=input()
k=int(input())
a=s*2
cnt=[0]*len(s)
cnt2=[0]*len(a)
l=0
m=0
ans=0
if zen(s):
    print(len(s)*k//2)
else:
    for i in range(len(s)-1):
        if s[i]==s[i+1]:
            cnt[l]+=1
        elif cnt[l]!=0:
            l+=1
    for i in range(len(a)-1):
        if a[i]==a[i+1]:
            cnt2[m]+=1
        elif cnt2[m]!=0:
            m+=1
    ans=0
    p=0
    while cnt[p]!=0:
        ans+=(cnt2[p]+1)//2
        p+=1
    ans*=k-1
    for i in range(p):
        ans+=(cnt[i]+1)//2
    print(ans)

Submission status: Wrong Answer

Solution code:
import math
import copy 
S = list(input())
K = int(input())
S1 = copy.copy(S)

x = S[0]
c1 = 0
c2 = 0
for i in range(len(S)-1):
    if x == S[i+1]:
        c1 += 1
    else:
        c2 += math.ceil(c1/2)
        c1 = 0
    x = S[i+1]
c2 += math.ceil(c1/2)
a = c2

S.extend(S1)
x = S[0]
c1 = 0
c2 = 0
for i in range(len(S)-1):
    if x == S[i+1]:
        c1 += 1
    else:
        c2 += math.ceil(c1/2)
        c1 = 0
    x = S[i+1]

c2 += math.ceil(c1/2)
b = c2

S.extend(S1)

x = S[0]
c1 = 0
c2 = 0
for i in range(len(S)-1):
    if x == S[i+1]:
        c1 += 1
    else:
        c2 += math.ceil(c1/2)
        c1 = 0
    x = S[i+1]
c2 += math.ceil(c1/2)
c = c2
if K==1:
    print(a)
else:
    print((K//2)*b+K%2*(c-b))

Submission status: Wrong Answer

Solution code:
s = input()
k = int(input())

j = 0
counta = 1
while (j<=len(s)-2):
    if s[j] == s[j+1]:
        counta += 1
        j += 1
        continue
    else:
        break

if counta % 2 == 0:
    flaga = 0
else:
    flaga = 1
        


countb = 0
for i in range(len(s)-1):
    if s[i] == s[i+1]:
        s = s[:i+1] + "0" + s[i+2:]
        countb += 1


flagb = 0
if s[len(s)-1] == s[0]:
    if flaga == 1:
        countb += 1
        flagb = 1
        
    


if flagb == 0:
    print(countb * k)
else:
    print(countb * k - 1)

Submission status: Wrong Answer

Solution code:
S = list(str(input()))
T = S+S
N = len(S)
K = int(input())

ans1 = 0
old = ""
flag = 0
for i in range(2*N):
    if old == "":
        old = T[i]
    else:
        if old == T[i]:
            ans1+=1
            old = ""
        else:
            old = T[i]
            
if old == T[-1]:
    flag = 1
    
ans2 = 0
old = ""
for i in range(N):
    if i == 0:
        if flag == 1 and S[0] == S[-1]:
            ans2+=1
            
        else:
            old = S[0]
    elif old == "":
        old = S[i]
    else:
        if old == S[i]:
            ans2+=1
            old = ""
        else:
            old = S[i]

if K%2 == 0:
    print(ans1*(K//2))
else:
    print(ans1*(K//2) + ans2)

Submission status: Wrong Answer

Solution code:
S=input()
K=int(input())

SL=list(S)
seq=0
for i in range(len(SL)-1):
  if SL[i]==SL[i+1]:
    SL[i+1]=SL[i+1].upper()
    seq+=1

if K==1 or S[0]!=S[-1]:
  print(seq*K)
else:
  SL2=list(S)
  SL2[0]="#"
  seq2=1
  for i in range(1,len(SL2)-1):
    if SL2[i]==SL2[i+1]:
      SL2[i+1]=SL2[i+1].upper()
      seq2+=1
  
  if K%2==0:
    print((seq+seq2)*(K//2))
  else:
    print(seq*((K+1)//2)+seq2*(K//2))

Submission status: Wrong Answer

Solution code:
s=input()
k=int(input())
S=''
#for i in range(k):
#	S+=s
#print(s)
S = list(s)
#last_word=s[-1]
count=0
l_s=len(S)
code_list = 'abcdefghijklmnopqrstuvwxyz'
#print('step1')
for i in range(1,l_s):
  #print(S,count)
  if S[i]==S[i-1] and i<l_s-1:
    for j in code_list:
      if j != S[i+1] and j !=S[i-1]:
        S[i]=j
        count+=1
        break
  elif S[i]==S[i-1]:
    for j in code_list:
      if j != S[i-1] and j !=S[0]:
        S[i]=j
        count+=1
        break
print(count*k)

Submission status: Wrong Answer

Solution code:
s = input()
k = int(input())
cnt = 0
cntw = 0
i = 0

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

if len(list(set(s))) == 1:
    print((k*len(s))//2)
    exit()
while True:
    if len(s)-1 < i:
        break
    if len(s)-1 == i:
        if s[i] == s[0]:
            cntw = 1
    elif s[i] == s[i+1]:
        cnt+= 1
        i += 1
    i += 1


ans = cnt*k+cntw*(k-1)
print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding:utf-8 -*-

s = input()
k = int(input())
flag = 1
lenth = 1
ans = 0
for i in range(len(s)-1):
    if s[i] == s[i+1]:
        lenth += 1
    else :
        flag = 0
    if flag == 0:
       ans += lenth//2
       lenth = 1
       flag = 1
ans += lenth//2
lenth = 1
flag = 1

ji = 0
for i in range(len(s)-1):
    if s[i] == s[i+1]:
        lenth += 1
    else :
        flag = 0
    if flag == 0:
       # print(lenth)
       if lenth%2 == 1:
            ji += 1
       break
if lenth%2 == 1 and flag ==1:
    ji += 1
lenth = 1
flag = 1
for i in range(len(s)-1):

    if s[len(s)-i-1] == s[len(s)-1-(i+1)]:
        lenth += 1
    else :
        flag = 0
    if flag == 0:
       # print(lenth)
       if lenth%2 == 1:
            ji += 1
       break
if lenth%2 == 1 and flag == 1:
    ji += 1
ans = ans*k
# print(ans, ji)
if ji == 2:
    ans = ans+k-1
print(ans)

Submission status: Wrong Answer

Solution code:
s = input()
k = int(input())
co1 = 0
co2 = 0
co3 = 0
ju = True

for i in range(len(s)-1):
    if s[i+1] == s[i] and ju:
        co1 += 1
        ju = False
    else:
        ju = True

s2=s+s
for i in range(len(s2)-1):
    if s2[i+1] == s2[i] and ju:
        co2 += 1
        ju = False
    else:
        ju = True

s3 = s2+s
for i in range(len(s3)-1):
    if s3[i+1] == s3[i] and ju:
        co3 += 1
        ju = False
    else:
        ju = True

adeven=co2-co1
addodd=co3-co2

print(co1+adeven*(k//2)+addodd*((k-1)//2))

Submission status: Wrong Answer

Solution code:
S = input()
K = int(input())
S = S + S[0]
samecount = 1
count = 0
pre = ''
for s in S:
    if s == pre:
        samecount += 1
    else:
        count += samecount//2
        samecount = 1
    pre = s

ans = K * count
if samecount % 2 == 0:
    ans += K*(samecount-1)//2
    check = True
    samecount = 1
    pre = S[0]
    for s in S[1:]:
        if s == pre:
            samecount += 1
        else:
            break

    if samecount % 2 == 0:
        pass
    else:
        ans += K-1
else:
    ans += K*(samecount//2)

print(ans)

Submission status: Wrong Answer

Solution code:
S = input()
K = input()

if not (1 <= len(S) and len(S) <= 100):
    exit()
if not (1 <= int(K) and int(K) <= 10 ** 9):
    exit()

pre = ""
count = 0
first = S[0]
last = S[len(S)-1]
flag = False
for i in range(len(S)):
    if i == (len(S) - 1):
        if pre == "" and first == S[i]:
            flag = True
    if pre != S[i]:
        pre = S[i]

    elif pre == S[i]:
        count += 1
        pre = ""


count *= int(K)
if flag:
    count = count + 1*int(K) -1 
print(count)

Submission status: Wrong Answer

Solution code:
S = input()
K = int(input())

l = len(S)
pair = []
current = S[0]
seq = 1
for i in range(1, l):
    if(i == l-1):
        if(S[i]==current):
            seq += 1
        if(seq != 1):
            pair.append(seq)
    elif(S[i] == current):
        seq += 1
    else:
        if(seq != 1):
            pair.append(seq)
        seq = 1
        current = S[i]

ans = 0
#print(pair)
if(l==1):
    ans = K-1
elif(S[0] != S[l-1] or l == 2):
    for i in range(len(pair)):
        ans += K * (pair[i]//2)
else:
    if(S[l-2] != S[l-1]):
        pair.append(1)
    if(len(pair) == 1):
        ans += (pair[0]*K)//2
    else:
        for i in range(len(pair)-1):
            ans += K * i
        ans += ((pair[i+1]+1)//2)*(K-1) + (pair[i+1]//2)

print(ans)

Submission status: Wrong Answer

Solution code:
s = list(input())
k = int(input())
ans = 0
t = s+s

if len(s)== 1:
    ans += k//2
else:
    for i in range(0,len(t)-1):
        if t[i]==t[i+1]:
            ans += k//2
            t[i+1] = "0"
    if t[0] == t[-1]:
        ans += k//2-1
    if k%2:
        u = t[len(t)//2:len(t)] + s
        for i in range(0,len(u)-1):
            if u[i]==u[i+1]:
                ans += 1
                u[i+1] = "0"
print(ans)

Submission status: Wrong Answer

Solution code:
t = input()
s = list(t)
k = int(input())

ans = 0

s = s+s
for i in range(1,len(s)):
  if s[i-1] == s[i]:
    s[i] = "0"
    if i>=len(s)//2:
      ans += k-1
    else:
      ans += 1
      
if len(set(list(t))) == 1 and len(t)%2 == 1:
  ans = len(t) * (k//2) + (k%2==1)*(k//2)
print(ans)

Submission status: Wrong Answer

Solution code:
def f():
    S = input()
    K = int(input())
    S = list(S)
    if K == 1 and len(S) == 1:
        print(0)
        return
    
    if K == 1 and len(S) != 1:
        ans = 0
        for i in range(len(S)-1):
            if S[i] == S[i+1]:
                S[i+1] = '1'
                ans += 1
        print(ans)
        return
    
    if K != 1 and len(S) == 1:
        ans = K // 2
        print(ans)
        return
    
    if K != 1 and len(S) != 1:
        ORG_S = S[:]
        
        # A
        ans_a = 0
        for i in range(len(S)-1):
            if S[i] == S[i+1]:
                S[i+1] = str(i)
                ans_a += 1
                
        if S[0] == S[-1]:
            ans_a = ans_a*K + K-1
        else:
            ans_a = ans_a*K
            
            
        # B
        S = ORG_S[:]
        ans_b = 0
        if S[0] == S[1]:
            S[0] = 'X'
            ans_b = 1
        
        for i in range(len(S)-1):
            if S[i] == S[i+1]:
                S[i+1] = str(i)
                ans_b += 1
                
        if S[0] == S[-1]:
            ans_b = ans_b*K + K-1
        else:
            ans_b = ans_b*K
        
        # C
        S = ORG_S[:]
        ans_c = 0
        if S[0] == S[1]:
            S[0] = 'X'
            ans_c = 1
        if S[-2] == S[-1]:
            S[-1] = 'Y'
            ans_c += 1
        for i in range(len(S)-1):
            if S[i] == S[i+1]:
                S[i+1] = str(i)
                ans_c += 1
                
        if S[0] == S[-1]:
            ans_c = ans_c*K + K-1
        else:
            ans_c = ans_c*K            
        
        ans = min(ans_a, ans_b, ans_c)
        print(ans)
        return

f()

Submission status: Wrong Answer

Solution code:
from sys import stdin


def main():
    input = lambda: stdin.readline()[:-1]
    S = input()
    K = int(input())

    ans = 0
    l, prev = 1, ''
    for s in S:
        if s == prev:
            l += 1
        else:
            ans += l // 2
            l = 1
        prev = s
    ans += l // 2
    print(ans * K)


main()

Submission status: Wrong Answer

Solution code:
s=list(input())
k=int(input())
l=len(s)
if l%2 and len(set(s))==1:
    print(l*k//2)
    exit()
if s[-1]==s[0]:
    if s[0]==s[1]: s[0]='.'
for i in range(1,l):
    if s[i]==s[i-1]: s[i]='.'
ans=s.count(('.'))*k
if s[0]==s[-1] and s[0]!='.': ans+=k-1 
print(ans)

Submission status: Wrong Answer

Solution code:
def a(ll):
	cc = 0
	for xx in ll:
		if 0 < xx:
			cc += xx//2 + xx % 2
	return cc

s = input()
C = int(input())
s_ = ""
c = 0
l=[]
for x in s+"$":
	#print(s_,x)
	if s_ == x:
		c += 1
	else:
		l.append(c)
		c = 0
	s_ = x
#print(l)
print(a(l)*C)