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:
#l=list(map(int, input().split()))
#n,m=map(int, input().split())
#l=list(map(int, input().split()))
#n = int(input())
def map_all(s):
    temp = s[0]
    
    for i in range(1,len(s)-1):
        if (temp != s[i]):
            return False

    return True

s = input()
k = int(input())

if map_all(s):
    temp = k * len(s)
    print(temp//2)
    exit()

le = len(s) -1
ans = []
temp = 0
de = True
for i in range(le):
    if s[i] == s[i+1]:
        temp+=1
        if (de == True):
            de = False
    else:
        if (de == False):
            ans.append(temp)
            temp = 0
            de= True
if (temp != 0):
    ans.append(temp)

ansVal = 0
for i in ans:
    temp = k*(i+1)
    ansVal+=temp//2

print(ansVal)

Submission status: Wrong Answer

Solution code:
from itertools import groupby
s=input()
k=int(input())
l=len(s)
g=groupby(s)
a=[]
for i,j in g:
  a.append(len(list(j)))
if len(a)==1:
  x=len(s)*k
  if x%2==0:
    print(x//2)
  else:
    print((x-1)//2)
else:
  c=0
  for i in a:
    if i%2==0:
      t=i//2
    else:
      t=(i-1)//2
    c+=t
  if s[0]==s[l-1] and k!=1:
    a[0]=a[0]+a[len(a)-1]
    a=a[:len(a)-1]
    z=0
    for i in a:
      if i%2==0:
        t=i//2
      else:
        t=(i-1)//2
      z+=t
    print(z*k+c)
  else:
    print(c*k)

Submission status: Wrong Answer

Solution code:
a=input()
b=int(input())
s="A"
zn=0
n=0
nn=0
i=0
aa=[]
ab=[]
abb=0
abc=0

for x in a:
    if aa==[]:
        n+=1
    elif x==s:
        n+=1
    elif x!=s:
        ab.append(n)
        n=1
    s=x
    i+=1
    aa.append(x)
    if i==len(a):
        ab.append(n)
if aa[0]==aa[-1] and len(ab)>2:
    if ab[-1]!=1:
        abb=ab[-1]
        del ab[-1]
    if ab[0]!=1:
        abc=ab[0]
        del ab[0]
    s=aa[0]
    i=0
    for x in aa:
        if aa[i]==s:
            nn+=1
        else:
            break
        i+=1
    i=1
    for x in aa:
        if aa[-i]==s:
            nn+=1
        else:
            break
        i+=1    
for x in ab:
    zn+=(x//2)
if len(a)==1:
    print(b//2)
elif len(ab)==1:
    print((b*ab[0])//2)
else:
    print(zn*b+(nn//2)*(b-1)+(abb+abc)//2)

Submission status: Wrong Answer

Solution code:
S = list(input()) * 2
K = int(input())
Len_S2 = len(S)
Len_S1 = Len_S2 // 2
count1 = 0
count2 = 0
for i in range(Len_S2-1):
    if S[i] == S[i+1]:
        if i < Len_S1 - 1:
            count1 += 1
        if i < Len_S2:
            count2 += 1
        S[i+1] = "1"
diff = count2 - count1
print(count1 + diff * (K-1))

Submission status: Wrong Answer

Solution code:
from itertools import groupby

S = input()
K = int(input())
A = []
for s in S:
  A.append(s)

def cont(A):
  B = []
  b = 0
  for key, value in groupby(A):
    B.append([key, list(value)])
  for i in range(len(B)):
    b += len(B[i][1]) // 2
  return b

def plus1(A):
  plu1 = 0
  for i in range(1,len(A)):
    if A[0] == A[i]:
      plu1 += 1
    else:
      break
  return plu1

def plus2(A):
  plu2 = 0
  for j in range(1,len(A)):
    if A[0] == A[-j]:
      plu2 += 1
    else:
      break
  return plu2

X = len(S) - len(list(set(A)))
if len(list(set(A))) == 1:
  an = len(S)*K
  ans = an // 2
elif X == 0:
  ans = 0
elif A[0] != A[len(A)-1]:
  ans = cont(A) * K
else:
  if plus1(A) == 0 and plus2(A) == 1:
    ans = cont(A)*K + (K-1)
  elif plus1(A)%2 == 1 and plus2(A)%2 == 1:
    ans = cont(A)*K + (K-1)
  else:
    ans = cont(A) * K
print(ans)

Submission status: Wrong Answer

Solution code:
S = list(input())
N = len(S)
K = int(input())
T = S.copy()
X = S.copy()
X += T
S += T
ans = 0
cnt = 0

if N == 1:
    print(K // 2)
    exit()

for i in range(1, N):
    if S[i - 1] == S[i]:
        cnt += 1
        S[i] = "-1"
cnt1 = 0
skip = set()
for i in range(N):
    if i in skip:
        continue
    if X[i + 1] == X[i]:
        cnt1 += 1
        skip.add(i + 1)
if T[0] == T[-1]:
    ans = min(cnt * (K // 2) + cnt1 * ((K + 1) // 2), cnt1 * ((K + 1) // 2) + cnt * (K // 2))
else:
    ans = cnt * K
    ans = min(ans, cnt1 * K)
print(ans)

Submission status: Wrong Answer

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

count=0
i=1
while i<len(S):
    if S[i]==S[i-1]:
        count+=1

        S[i]="."
    i+=1

a=(S[0]==S[-1])

print(count*K+a*(K-1))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
# 整数の入力
s = input()
k = int(input())
# print (s,k)
n=len(s)
# print (s[0],s[n-1])
p=0
q=0
if s[0] == s[n-1]:
    l=1 
    # Start 
    for i in range(1,n):
        #print("loop",i)
        if s[i] == s[i-1]:
            p +=1
        else:
            break
    if l < n:
        for i in range(n-2,0,-1):
            if s[i] == s[i+1]:
                q +=1
            else:
                break
    l = 1 + p + q
    # print("Ring ", l, p,q)
    op = ((l // 2) + (l % 2)) * (k-1)
    op += ((p // 2) + (p % 2)) 
    op += ((q // 2) + (q % 2))
else: 
    op = 0     

# print("OP",op)

s2 = s[p+1:n-1-q] 
# print("s2",s2)
n=len(s2)
            

l = 0
for i in range(1,n):
    # print(s2[i],i,l,op)
    if s2[i-1] != s2[i]:
        op += (l // 2 + l % 2) * k
        l = 0 
    else:
        l += 1 
if l != 0:
    op += (l // 2 + l % 2) * k

        
print(op)

Submission status: Wrong Answer

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


def count(s):
    s_length = len(s)
    s_types = len(set(s))
    if s_length == s_types:
        return 0
    if s_length == 2:
        if s_types == 1:
            return 1
        else:
            return 0
    else:
        i = 0
        replace = 0
        while i < s_length:
            chunk = s[i:i + 3]
            chunk_types = len(set(chunk))
            if len(chunk) == 1:
                break
            elif len(chunk) == 2:
                if chunk_types == 1:
                    replace += 1
                    break
                else:
                    break
            else:
                if chunk_types == 1:
                    replace += 1
                    i += 2
                elif chunk_types == 2:
                    if chunk[0] == chunk[1]:
                        replace += 1
                        i += 2
                    elif chunk[1] == chunk[2]:
                        replace += 1
                        i += 3
                    else:
                        i += 2
                else:
                    i += 2

    return replace



def check(s, k):
    s_length = len(s)
    if s_length == 1:
        return s_length * k / 2
    elif s[0] == s[-1] and s[-1] != s[-2]:
        return count(s) * k + (k - 1)
    else:
        return count(s) * k


print(check(S, K))

Submission status: Wrong Answer

Solution code:
S=input()
K=int(input())
# 一番効率が良いのは3連続で同じ文字列が続くときに真ん中を別の文字に変換する場合
# 2連続で同じ文字が続く場合は後ろの文字を変える.次の文字からまた数え直す
# 最後の文字列については無視すれば良い

# S=''.join([S for _ in range(K)])
same=False
count = 0
flag=False
flag_odd=False
for i in range(1,len(S)):
    if not same:
        if S[i]==S[i-1]:
            same=True
            count+=1
        else:
            pass
    else:
        same=False
    if not same and i==len(S)-1 and S[0] == S[-1]:
        flag=True
        

same=False
count_odd = 0
for i in range(1,len(S)):
    if not same:
        if S[-i]==S[-i-1]:
            same=True
            count_odd+=1
        else:
            pass
    else:
        same=False
    if not same and i==len(S)-1 and S[0] == S[-1]:
        flag_odd=True
    # 文字列の最後尾が変更されずに、かつ前の文字列と同じであった場合は最後尾もしくは、最前を変える必要がある
min_count = min(count*K+flag*(K-1), count_odd*K+flag_odd*(K-1))
print(min_count)

# countは一つの文字列中に存在する必要変換回数.ただし、(文末が変化しない場合)文末の文字が文頭のものとかぶる場合があるので、その場合については、
# 文頭を変化させる

Submission status: Wrong Answer

Solution code:
#-------------------------------------------------------------------
import sys
def p(*_a):
  _s=" ".join(map(str,_a))
  #print(_s)
  sys.stderr.write(_s+"\n")
#-------------------------------------------------------------------
s = input()		# 文字列の入力  abcdefg...
k = int(input())						# 5


ans=0

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

if len(s)==2:
	if s[0]==s[-1]: ans=k
	print(ans)
	exit(0)



# グループ作成
#「groupby」は、「キーとグループ」を返すようなイテレータを作成します
from itertools import groupby
#s='AAABBCABBB'

#「groupby」は、キーとグループを返すようなイテレータを作成します
m=[]
for key, g in groupby(s):
	#print( key, list(g) )
	m.append([key,len(list(g))])

p(m)

if m[0][0]==m[-1][0]:

	for i in range(1,len(m)-1):
		ans+=(m[i][1]//2)*k

	ans+=(m[0][1]//2)
	ans+=(m[-1][1]//2)

	ans+=((m[0][1]+m[-1][1])//2)*(k-1)

else:
	for a,i in m:
		#p(a,i)
		ans+=(i//2)*k


print(ans)

Submission status: Wrong Answer

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

for i in range(1, len(S)):
    if S[i] == S[i-1] and S[i] != None:
        ans += 1
        S[i] = None
ans *= K

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

if S[-1] == S[0] and S[1] != None:
    ans += (K-1)
elif len(S) % 2 != 0 and S[-1] == S[0]:
    ans += (K-1)

print(ans)

Submission status: Wrong Answer

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

box = ""
count = 0
     
for mozi in S:
  if mozi == box:
    count += 1
    box = ""
  else:
    box = mozi
    
box = S[0]
count_sta = 0
for mozi in S:
  if box != mozi:
  	break
  count_sta +=1

box = S[len(S)-1]
count_fin = 0
for mozi in reversed(S):
  if box != mozi:
  	break
  count_fin +=1

if S[0] == S[len(S)-1] and (count_sta + count_fin)%2 == 0:
  print((count+1)*K-1)
else:
  print(count*K)

Submission status: Wrong Answer

Solution code:
S, K = open(0).read().split()

cGroups = []
tempList = []
for i, c in zip(range(len(S)), S):
    tempList.append(c)
    if (i == len(S) - 1) or c != S[i + 1]:
        cGroups.append(tempList)
        tempList = []

singleResult = 0
for g in cGroups:
    if len(g) > 1:
        singleResult += len(g) // 2
print(singleResult * int(K))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline

def main():
    s = list(input().rstrip())
    k = int(input())


    if len(s) == 1:
        print(k//2)
    else:
        sa = s[:]

        c1 = 0
        c2 = 0

        for i in range(len(s) - 1):
            if sa[i] == sa[i+1]:
                c1 += 1
                sa[i+1] = '1'

        if sa[0] == sa[-1]:
            if s[0] == s[1]:
                s[0] = '2'
                c2 += 1

            for i in range(len(s) - 1):
                if s[i] == s[i+1]:
                    c2 += 1
                    s[i+1] = '2'


            if k % 2 == 0:
                x = k // 2
                print(c1*x + c2*x)
            else:
                x = k // 2
                print(c1*(x+1) + c2*x)
        else:
            print(c1*k)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def count_changes(s, k, prev=None):
    count = 0
    for _ in range(k):
        for cur in s:
            if cur == prev:
                count += 1
                prev = None
            else:
                prev = cur
    return count


if __name__ == '__main__':
    s = input()
    k = int(input())
    if k <= 3:
        print(count_changes(s, k))
    else:
        base_count = count_changes(s, 3)
        d, rest = divmod(k, 3)
        res = base_count * d
        if rest:
            res += count_changes(s, rest, s[-1])
        elif s[0] == s[-1]:
            res += (d - 1)
        print(res)

Submission status: Wrong Answer

Solution code:
s = input() 
k = int(input())
t = s * 2

l = []
for i in range (len(t)-1):
  if t[i+1] == t[i]:
    l.append(1)
  else:
    l.append(0)

for i in range (len(l)-1):
  if l[i+1] == l[i] == 1:
    l[i+1] = 0

ans = 0
if k == 1:
  ans = sum(l[0:len(s)-1])
elif k%2 == 0:
  ans = sum(l)*(k//2)
elif k%2 == 1:
  ans = sum(l)*(k//2) + sum(l[len(s)-1:len(l)])

print(ans)

Submission status: Wrong Answer

Solution code:
s = input()
k = int(input())
# s = 'si'
# k = 3

s_cnt = 0
for i in range(len(s) - 1):
    if s[i] != s[i + 1]:
        s_cnt = i + 1
        break
else:
    s_cnt = len(s)
for i in range(len(s) - 1, 1, -1):
    if s[i] != s[i - 1]:
        e_cnt = len(s) - i
        break
else:
    e_cnt = len(s)
is_start = False
idx_list = []
for i in range(len(s) - 1):
    if s[i] == s[i + 1]:
        if not is_start:
            is_start = True
            s_idx = i
    else:
        if is_start:
            is_start = False
            e_idx = i
            idx_list.append((s_idx, e_idx))
else:
    if is_start:
        idx_list.append((s_idx, len(s) - 1))
ans = 0
for s_idx, e_idx in idx_list:
    ans += (e_idx - s_idx + 1) // 2
ans *= k
if s_cnt == len(s) and e_cnt == len(s) and len(s) % 2 == 1 and len(s) != 1:
    ans += 1
elif s_cnt % 2 == 1 and e_cnt % 2 == 1 and s[0] == s[-1]:
    ans += k - 1
print(ans)

Submission status: Wrong Answer

Solution code:
s = input()
k = int(input())
cnt = 0
len_cnt = len(s)
submit = 0
if len_cnt == 1:
    print(k//2)
else:
    ato = 1
    while cnt < len_cnt-1:
        #print(len_cnt)
        if s[cnt] == s[cnt+1]:
            ato = cnt+1
            while s[cnt] == s[ato]:
                ato+=1
                #print(s[cnt])
                if len_cnt == ato:

                    submit = submit + (ato-cnt)//2
                    cnt = len_cnt
                    break
            submit = submit + (ato-cnt)//2
            #print((ato-cnt)//2)
            cnt = ato
        else:
            cnt+=1
#print(submit)
print(submit*k)

Submission status: Wrong Answer

Solution code:
S, K = open(0).read().split()
# print(S, K)
# print(alpha)
# print(type(S))
list_s = list(S)
# print(list_s)
cnt = 0
for i in range(len(list_s)-1):
    if list_s[i] == list_s[i+1]:
        list_s[i+1] = "_"
        cnt += 1 
#     print(list_s)
# print(cnt)
# print(list_s)
if list_s[0] == list_s[-1]:
    print(cnt * int(K) + int(K) -1)
elif len(list_s) == 1:
    print(K//2)
else:    
    print(cnt * int(K))

Submission status: Wrong Answer

Solution code:
s = input()
k = int(input())
c = 0
if len(s)==1:
    print(k//2)
elif len(s)==3:
    if s[0]==s[1] and s[0]!=s[2]:
        print(k)
    elif s[0]==s[1] and s[0]==s[2]:
        if k>1:
            print((3*k)//2)
        else:
            print(1)
    elif s[1]==s[2]:
        print(k)
    elif s[0]==s[2]:
        print(k-1)
    else:
        print(0)
else:
    i = 0
    q = False
    while i < len(s)-1:
        if s[i]==s[i+1]:
            c+=1
            i+=1
        i+=1
    if s[len(s)-1]==s[0]:
        if s[len(s)-1]!=s[len(s)-2]:
            c+=1
            q = True
        elif s[len(s)-2]==s[len(s)-3]:
            c+=1
            q = True
    if q:
        if c==1:
            print(k-1)
        else:
            if s[0]!=s[1]:
                print((c-1)*k+k-1)
            else:
                print((c-1)*k)
    else:
        print(c*k)

Submission status: Wrong Answer

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

N=len(S)
t=S[0]
cnt=0
arr=[]
for s in S[1:N]:
    if t==s:
        cnt+=1
    else:
        arr.append(cnt+1)
        cnt=0
    t=s
arr.append(cnt+1)
ans=sum(map(lambda x: x//2, arr))
if len(arr)>1 and S[0]==S[-1] and arr[0]%2==1 and arr[-1]%2==1:
    print((ans+1)*K)
#     print('A')
elif len(arr)==1 and N%2==1:
    if N==1:
        print(K//2)
    else:    
        print((ans+1)*K)
else:
    print((ans)*K)

Submission status: Wrong Answer

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

if k == 1:
    if n == 1:
        print(0)
        exit()
    cnt1 = 0
    cnt2 = 0
    for i in range(n):
        if i == 0:
            if s[i] == s[i+1]:
                cnt1 += 1
        elif i == n-1:
            if i%2 == 0:
                if s[i] == s[i-1]:
                    cnt1 += 1
            else:
                if s[i] == s[i-1]:
                    cnt2 += 1
        else:
            if i%2 == 0:
                if s[i] == s[i-1] or s[i] == s[i+1]:
                    cnt1 += 1
            else:
                if s[i] == s[i-1] or s[i] == s[i+1]:
                    cnt2 += 1
    print(min(cnt1, cnt2))
elif k == 2:
    s *= 2
    cnt1 = 0
    cnt2 = 0
    for i in range(2*n):
        if i == 0:
            if s[i] == s[i+1]:
                cnt1 += 1
        elif i == 2*n-1:
            if i%2 == 0:
                if s[i] == s[i-1]:
                    cnt1 += 1
            else:
                if s[i] == s[i-1]:
                    cnt2 += 1
        else:
            if i%2 == 0:
                if s[i] == s[i-1] or s[i] == s[i+1]:
                    cnt1 += 1
            else:
                if s[i] == s[i-1] or s[i] == s[i+1]:
                    cnt2 += 1
    print(min(cnt1, cnt2))
else:
    s *= 3
    s1 = ''
    s2 = ''
    for i in range(3*n):
        if i < 3*n - 1 and i > 0:
            if i % 2 == 0:
                s2 += s[i]
                if s[i] == s[i-1] or s[i] == s[i + 1]:
                    s1 += '0'
                else:
                    s1 += s[i]
            else:
                s1 += s[i]
                if s[i] == s[i-1] or s[i] == s[i + 1]:
                    s2 += '0'
                else:
                    s2 += s[i]
        elif i == 3*n - 1:
            if i % 2 == 0:
                s2 += s[i]
                if s[i] == s[i-1]:
                    s1 += '0'
                else:
                    s1 += s[i]
            else:
                s1 += s[i]
                if s[i] == s[i-1]:
                    s2 += '0'
                else:
                    s2 += s[i]
        else:
            if i % 2 == 0:
                s2 += s[i]
                if s[i] == s[i + 1]:
                    s1 += '0'
                else:
                    s1 += s[i]
                    
    s1_arr = [s1[:n].count('0'), s1[n:2*n].count('0'), s1[2*n:].count('0')]
    s2_arr = [s2[:n].count('0'), s2[n:2*n].count('0'), s2[2*n:].count('0')]
    print(min(s1_arr[0] + s1_arr[1]*(k-2) + s1_arr[2], s2_arr[0] + s2_arr[1]*(k-2) + s2_arr[2]))

Submission status: Wrong Answer

Solution code:
S=input()
K=int(input())
SS=list(S)
n=0
#モノマー内の重複を修正(偶数文字)
if len(S)%2==0:
    for i in range(len(S)-1):
        if SS[i]==SS[i+1]:
            SS[i+1]="A"
            n+=1
    if SS[0]==SS[-1]:
        n+=1
    print(n*K)
else: #文字数が奇数の場合、偶数回目と奇数回目で伏せる文字を変えた方が効率的なことがある
    SSS=list(S+S)
    for i in range(len(SSS)-1):
        if SSS[i]==SSS[i+1]:
            SSS[i+1]="A"
            n+=1
    if K%2==0: #Kが偶数なら単純
        if SSS[0]==SSS[-1]:
            n+=1
        print(n*K//2)
    else: #Kが奇数なら最後の1ループは例外的に計算
        nn=0
        for i in range(len(S)-1):
            if SS[i]==SS[i+1]:
                SS[i+1]="A"
                nn+=1
        print(n*(K//2)+nn)

Submission status: Wrong Answer

Solution code:
s = input()
k = int(input())
s = s * 2
count = 0
i = 0
while i <= len(s):
    tmp = 1
    for j in range(i + 1, len(s)):
        if s[i] == s[j]:
            tmp += 1
        else:
            break
    i += tmp
    tmp //= 2
    count += tmp

print(int(count * k / 2))

Submission status: Wrong Answer

Solution code:
s = list(input())
k = int(input())
count = 0
ans = 0
fcount = 0
lcount = 0
flflag = False
mukade = False

if s[0] == s[len(s) - 1]:
    for i in range(1, len(s)):
        if s[i] == s[i  - 1]:
            fcount += 1
        else:
            break
    for i in range(len(s) - 1, 0, -1):
        if s[i] == s[i - 1]:
            lcount += 1
        else:
            break
    ans += int((fcount + lcount + 2) / 2)
    if lcount == 0 and fcount == 0:
        mukade = True
    flFlag = True

if fcount == lcount and lcount + 1 == len(s) and flFlag == True:
    if len(s) % 2 == 1:
        print((int(len(s) / 2) + 1) * k)
    else:
        print(int(len(s) / 2) * k)
elif (lcount + fcount + 2 == len(s) or lcount + fcount + 3 == len(s) ) and flFlag == True:
    print(ans * k)
elif lcount + fcount + 4 == len(s) and flFlag == True:
    if s[fcount] == s[len(s) - 1 - lcount]:
        print((ans + 1) * k)
    else:
        print(ans * k)
else:
    for i in range(fcount + 1, len(s)- lcount):
        if s[i] == s[i - 1]:
            count += 1
        elif count > 0:
            ans += int((count + 1) / 2)
            count = 0
    if mukade == True:
        print(ans * k - 1)
    else:
        print(ans * k)

Submission status: Wrong Answer

Solution code:
import numpy as np

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

def connect_cnt(S):
	cnt_tmp = 1
	cnt = []

	for i in range(len(S) - 1):

		if S[i] == S[i+1]:
			cnt_tmp += 1
		else:
			cnt.append(cnt_tmp)
			cnt_tmp = 1

		if i == len(S)-2:
			cnt.append(cnt_tmp)

	connect_cnt = sum(np.array(cnt) // 2)
	return connect_cnt


if K == 1:
	print(connect_cnt(S))
	exit(0)

if len(S) == 1:
	print(connect_cnt(S*K))
	exit(0)

if S[0] != S[-1]:

	connect_cnt = connect_cnt(S)
	ans = connect_cnt * K
	print(ans)

else:

	S_dash = S + S
	connect_cnt_Sdash = connect_cnt(S_dash)
	connect_cnt_S = connect_cnt(S[0] + S)

	if K > 2:
		ans = connect_cnt_Sdash * (K//2) + connect_cnt_S
		print(ans)
		exit(0)

	else:
		ans = connect_cnt_Sdash * (K//2)
		print(ans)

Submission status: Wrong Answer

Solution code:
s = input()
k = int(input())
m = 0
n = 0
j = 0
for i in range(len(s)):
    if s.count(s[0]) == len(s):
        print(len(s) * k // 2)
        exit()
    if len(s) <= j + 1:
        if s[0] == s[-1] and s[-1]!=s[-2] and s[0]!=s[1]:
            print(s[10000000000000000000000000])
        break
    if s[j] == s[j + 1]:
        if j == len(s) - 1:
            n += 1
        else:
            m += 1
        j += 1
    j += 1
print(m * k + n)

Submission status: Wrong Answer

Solution code:
st = input()
s = [i for i in st]
k = int(input())
l = len(s)
c=0
i=0
f=0
# if l>=2 and s[0]==s[1]:
#     f=1
# if l>=2 and s[-1]==s[-2]:
#     f=2
def count(s,l):
    c=0
    i=0
    while i<l-1:
        if i+1 <=l-1 and s[i]==s[i+1]:
            s[i+1]='#'
            c+=1
            i+=1
        else:
            i+=1
    return c
# print(c)
c = count(s,l)
if k>1:
    s1 = []
    s1 = [ i for i in st]
    for i in range(l):
        s1.append(st[i])
    # print(s1)
    l1 = len(s1)
    c1 = count(s1,l1)
    # diff = c1-c
    kr = k-2
    if kr%2==0:
        res = c1+c1*kr//2
    else:
        res = c1+c1*(kr-1)//2+c
    # print(c1,c,kr)
    # res = c1+kr*diff
else:
    res = c

if l==1:
    if k%2==0:
        res=k//2
    else:
        res = (k-1)//2


print(res)

# c*=k
# if l==1:
#     if k%2==0:
#         c=k//2
#     else:
#         c = (k-1)//2
# print(c)

Submission status: Wrong Answer

Solution code:
#code
s = input()
k = int(input())
l = 1
m = 0
for i in range(0, len(s) - 1):
    if s[i] == s[i + 1]:
        l += 1
    else:
        l = int(l / 2)
        m += l
        l = 1
if l > 1:
    l = int(l / 2)
    m += l
if s[0] == s[len(s) - 1] and len(s) > 2:
    l += 1
    l = int(l / 2)
    m += l
print(m * k)

Submission status: Wrong Answer

Solution code:
S = input()
K = int(input())
N = len(S)
counts = 0
count2 = 0
adder = 0
adder2 = 0

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

elif len(S) == 3 and(S[0] == S[1]) and (S[1] == S[2]):
    if K % 2 == 0:
        print(int(3*K/2))
    elif K == 1:
        print(1)
    else:
        print(2 + 2*(K-2))

elif K == 3:
    S_arranged = list(S*3)
    for i in range(len(S_arranged)-2):
        if (S_arranged[i] == S_arranged[i+1]) and (S_arranged[i+1] == S_arranged[i+2]):
            S_arranged[i+1] = "0"
            counts += 1
        
    for i in range(len(S_arranged)-1):
        if S_arranged[i] == S_arranged[i+1]:
            S_arranged[i] = "1"
            counts += 1
            
    print(counts)

else:
    S_arranged = list(S*4)
    for i in range(len(S_arranged) - 2):
        if (S_arranged[i] == S_arranged[i+1]) and (S_arranged[i+1] == S_arranged[i+2]):
            S_arranged[i+1] = "0"
            if i+1 <= len(S)-1:
                adder += 1
            elif i+1 > len(S)*3 -1:
                adder2 += 1
            elif i+1 > len(S) - 1 and i+1 <= len(S)*2 - 1:
                counts +=1
            else:
                count2 +=1

    for i in range(len(S_arranged)-1):
        if S_arranged[i] == S_arranged[i+1]:
            S_arranged[i] = "1"
            if i <= len(S)-1:
                adder += 1
            elif i > len(S)*3 -1:
                adder2 += 1
            elif i > len(S)-1 and i+1 <= len(S)*2-1:
                counts +=1
            else:
                count2 +=1


    if K % 2 == 0:
        print(int(adder + (counts + count2) * ((K-2)/2) + adder2))

    else:
        print(int((adder + counts * ((K-2)/2) + count2 * ((K-2)/2 -1) +adder2)))

Submission status: Wrong Answer

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

ans = 0
length = len(s)

if length == 1:
  ans = k // 2
elif length == 2:
  if s[0] == s[1]:
    ans = k
else:
  sep = 0
  i = 1
  last = 0
  firstchar = s[0]
  is_one_char = True
  while i < length:
    if firstchar != s[i] or firstchar != s[i-1]:
      is_one_char = False
    
    if s[i] == s[i-1]:
      sep += 1
      last = i
    i += 1
  
  if is_one_char:
    ans = (length // 2) * k
    if length % 2 != 0:
      ans += k // 2
  else:
    ans = sep * k
    if last != length-1 and s[0] == s[length-1]:
      ans += k-1

print(ans)

Submission status: Wrong Answer

Solution code:
S = list(input())
K = int(input())
n = len(S)
s_pre = '_'
count = 0
last = 0
output = 0
if  len(S) == 1:
  output = K//2
else:
  for s in S:
    if s_pre == s:
      s = '_'
      count += 1
    s_pre = s
  if S[-1] == S[0]:
    S[-1] = '_'
    output -= 1
  output = K*count

print(output)

Submission status: Wrong Answer

Solution code:
s=input()
k=int(input())
ans=0
for i in range(len(s)-1):
  if s[i]==s[i+1]:
    ans+=1
    s=s[:i+1]+'0'+s[i+2:]
ans*=k
if s[0]==s[-1]:
  ans+=k-1
print(ans)

Submission status: Wrong Answer

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

count = 0
i=0
join_flag =0
join_n = 0

if len(s)==1:
  print(k//2)
    
elif len(s)==2:
  if s[0]==s[1]:
    print(k)
  else:
    print(0)
  
elif len(set(s))==1:
  print(len(s)*k //2)
  
else:
  while i<len(s)-1:
    if s[i] == s[i+1]:
      count+=1
      i+=2
    else:
      i+=1
  
  if (s[-1] == s[0]) :
    join_flag =1
    
  if join_flag:      
    left_len = 1
    right_len = 1

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

    for i in range(len(s)-1):    
      if s[-1-i]==s[-2-i]:
        right_len +=1
      else:
        break            
    
    if right_len %2 ==0:
      join_n =0
    else:            
      join_n = k-1      
  print(count*k + join_n)

Submission status: Wrong Answer

Solution code:
# A - Connection and Disconnection
s = input()
k = (int)(input())

beforeStr = ''
count = 0

if len(s) == 1:
    print((int)(k / 2))
else:
    list_s = list(s)

    for i in range(len(s) + 1):

        if i == len(s):
            if beforeStr == list_s[0]:
                count + 1
            break
        if beforeStr == list_s[i]:
            count += 1
            list_s[i] = 'Z'
        beforeStr = list_s[i]

    print(count * k)

Submission status: Wrong Answer

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

cnt = 0
ans = 0

for i in range(len(S)-1):
    if S[i] == S[i+1]:
        cnt += 1
        if i == len(S)-2:
            ans += (cnt + 1) // 2
    else:
        if cnt != 0:
            ans += (cnt + 1) // 2
        cnt = 0

if S[0] == S[len(S)-1]:
    fcnt = 0
    for i in range(len(S) - 1):
        if S[i] == S[i + 1]:
            fcnt += 1
        else:
            break
    bcnt = 0
    for i in range(len(S)-1, 0, -1):
        if S[i] == S[i - 1]:
            bcnt += 1
        else:
            break
    if fcnt%2 == 0 and bcnt%2 == 0:
        print((ans+1)*N-1)
    else:
        print(ans*N)
else:
    print(ans*N)

Submission status: Wrong Answer

Solution code:
s = input()
n = len(s)
K = int(input())
s = s*2
s = list(s)
cnt = 0
for i in range(1, len(s)):
    if s[i] == s[i-1]:
        s[i] = 'A'
        cnt += 1
res = 0
if cnt % 2 == 1:
    res = (cnt//2)*K + K-1
else:
    res = cnt//2 * K
if n == 1:
    res = K//2
print(res)

Submission status: Wrong Answer

Solution code:
s = input()
k = int(input())
m = 0
n = 0
j = 0
for i in range(len(s)):
    if s.count(s[0]) == len(s):
        print(len(s) * k // 2)
        exit()
    if len(s) <= j + 1:
        if s[0] == s[-1] and s[-1]!=s[-2] and s[0]!=s[1]:
            n += 3
        break
    if s[j] == s[j + 1]:
        if j == len(s) - 1:
            n += 1
        else:
            m += 1
        j += 1
    j += 1
print(m * k + n)

Submission status: Wrong Answer

Solution code:
s = input()
k = int(input())
n = len(s)
l = []

x = 1
for i in range(n):
    if i == n-1:
        if s[i] == s[0]:
            l.append(x)
        continue
    
    if s[i] == s[i+1]:
        x += 1
    else:
        l.append(x)
        x = 1

ans = 0
for i in l:
    ans += i // 2
ans *= k
if l[0] % 2 and l[-1] % 2 and s[0] == s[-1]:
    ans += k-1

print(ans)

Submission status: Wrong Answer

Solution code:
a = input()
j = int(input())

# is0i0is0i0
# print(a, len(a))
i = 0
c = 0
prev = False
for x in a:
  # print(prev)
  if c > 0:
    # print(x, a[c-1], c, prev, x == a[c-1] and not prev)
    if x == a[c-1] and not prev:
      i += 1
      prev = True
      c += 1
      continue
  if c != len(x):
    prev = False
  # print("c++", c)
  c +=1 

#prev and
if a[0] == a[-1]:
  if (i==0) and j>1:
    print("|1|")
    print(int((j+j%2)/2))
  elif not prev:
    print(i*j+(j-1))
  else: 
    # print("|2|", i, j)
    print(i*j)
else:
  print("|3|")
  print(i*j)

Submission status: Wrong Answer

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

if not(1 <= len(S) and len(S) <= 100):
    exit()
if not (S.isalpha() and S.islower()):
    exit()
if not float(K).is_integer():
    exit()
if not (1 <= int(K) and int(K) <= 10 ** 9):
    exit()



L = []
tmp = []
pre = ""
for s in S:
    if len(tmp) == 0:
        pre = s
        tmp.append(s)
    elif pre == s:
        tmp.append(s)
    else:
        L.append(tmp)
        pre = s
        tmp = [s]
L.append(tmp)

count = 0
for l in L:
    count += int(len(l) / 2)

count *= int(K)
if len(L) == 1:
    print(count)
    exit()
if L[0][0] == L[len(L)-1][0]:
    if (len(L[0]) + len(L[len(L) - 1])) % 2 == 0:
        count = count + 1 * int(K) - 1
print(count)