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 = list(input())
k = int(input())
count = 0
ans = 0
fcount = 0
lcount = 0
flflag = 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)
    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
    print(ans * k)

Submission status: Wrong Answer

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

pre_str = ''
count = 1
base_count = 0
for a in list(S):
    if pre_str == a:
        count += 1
    else:
        base_count += int(count / 2)
        count = 1
        pre_str = a
base_count += int(count / 2)
ret = 0
if not S:
    ret = 0
elif len(list(set(list(S)))) == 1:
    ret = int(len(S) * K / 2)
elif len(S) > 2 and S[0] != S[1] and S[-1] != S[-2] and S[0] == S[-1]:
    ret = base_count * K
    ret += K - 1
else:
    ret = base_count * K
print(ret)

Submission status: Wrong Answer

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

lens = len(s)

cnt = 0
ans = 0

sig = lens % 2

i=0
frg = False
while i < lens:
  if i != lens-1 and s[i] == s[i+1]:
    cnt += 1
    i+=2
    flg = True
  else:
    i+=1
    flg = False

ans = cnt * k

# lensが奇数で最初と最後が同じ場合
if not flg and s[0] == s[-1]:
  ans += k-1


print(ans)

Submission status: Wrong Answer

Solution code:
S = input()
K = int(input())
N = len(S)
M = [0 for i in range(N)]

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

for i in range(N-1):
    if S[i]==S[i+1]:
        M[i]=1
if S[0]==S[N-1]:
    M[N-1]=1

count = 0
total = 0

for i in range(N):
    if M[i] == 1:
        count+=1
    elif count==1:
        total+=1
        count=0
    elif count!=0:
        total+=int((1+count)/2)
        count=0
if count==1:
    total+=1
elif count!=0:
    total+=int((1+count)/2)

print(total*K)

Submission status: Wrong Answer

Solution code:
S = input()
K = int(input())
N = len(S)
cnt = 0
flg1 = False
flg2 = False
flg3 = False
flg4 = 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 (S[0] == S[N-1]) and K != 1:
    if S[0] != S[1]:
        cnt += 1
        flg1 = True
if (S[N-2] == S[N-1]):
    flg4 = 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)
if flg1 and flg4 == False:
    print(cnt*K-1)
else:
    print(cnt*K)
# print(cnt*K)

Submission status: Wrong Answer

Solution code:
s = input()
k = int(input())
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(count * k)

Submission status: Wrong Answer

Solution code:
s = list(input())
k = int(input())
n = len(s)
ans = 0
if n > 1:
  for i in range(n-1):
    if s[i] == s[i+1]:
      s[i+1] = 'あ'
      ans += 1
  if s[0] == s[n-1] and k > 1:
    ans += 1
    ans = ans*k - 1
  else:
      ans = ans*k
else:
  ans = k//2
print(ans)

Submission status: Wrong Answer

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


a = S[0]
c = 0
S2 = copy.deepcopy(S)
for i in range(1, len(S)):
    if S2[i] == S2[i-1]:
        S2[i] = '1'
        c += 1

a = S[-1]
last = 0
for i in range(2, len(S)+1):
    last += 1
    if S[-i] != a:
        break

if all([e == S[0] for e in S[1:]]) == True:
    if len(S)%2==0:
        print(int(len(S)/2*K))
    else:
        print(int(len(S)//2*(K//2+1)+(len(S)//2+1)*K//2))
elif S[0] == S[-1] and last % 2 == 1:
    c3 = 0
    S3 = copy.deepcopy(S)
    for i in range(2, len(S)):
        if S3[i] == S3[i-1]:
            S3[i] = '1'
            c3 += 1
    print(c + (c3+1)*(K-1))
else:
    print(c*K)

Submission status: Wrong Answer

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

ans = 0
now = 0
flag = 1
onaji = False

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

for i in range(len(s)):
    #print(i,now)
    if now >= len(s) - 1:
        break
    if s[now] == s[now+1]:
       ans += 1
       now += 2
       if now+1 == len(s) -1:
           flag = 0
    else:
        now += 1

if len(s) == 2:
    print(ans*k)
    exit()

for i in range(len(s)-1):
    if s[i] != s[i+1]:
        break
    if i == len(s) - 2:
        onaji = True

#print(flag)

if flag == 1:
    if s[0] == s[-1]:
        if s[0] == s[1]:
            flag = 2
        else:
            flag = 1
    else:
        flag = 0
#print(flag)

if flag != 2:
    print(ans*k+flag*(k-1))
else:
    if onaji == True:
        print(int(ans*k+k//2))
    else:
        print(int(ans*k+1*(k-1)))
#print(ans,ans*k,ans*k+flag*(k-1))

Submission status: Wrong Answer

Solution code:
import collections
import sys

input = sys.stdin.readline


class AtCoder:
    def main(self):
        S = input().rstrip()
        K = int(input())

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

        ans = 0
        start = 0
        end = len(S)
        cnt_1 = 1
        cnt_2 = 1

        if len(collections.Counter(S)) == 1:
            print((len(S) // 2) * K)
            exit()

        if S[0] == S[-1]:
            for i in range(1, len(S) - 1):
                if S[i] != S[0]:
                    start = i
                    break
                else:
                    cnt_1 += 1

            for i in range(1, len(S) - 1)[::-1]:
                if S[i] != S[0]:
                    end = i + 1
                    break
                else:
                    cnt_2 += 1

            ans += (cnt_1 // 2) + ((cnt_1 + cnt_2) // 2) * (K - 1) + (cnt_2 // 2)

        before = S[start]
        length = 1
        changes = 0
        for i in range(start + 1, end):
            if S[i] == before:
                length += 1
            else:
                changes += length // 2
                length = 1
                before = S[i]

        changes += length // 2
        ans += changes * K
        print(ans)

# Run main
if __name__ == '__main__':
    AtCoder().main()

Submission status: Wrong Answer

Solution code:
from collections import defaultdict as df
s=input().rstrip()
ini=len(s)
k=int(input())
s=[i for i in s]
if len(s)==2:
    if s[0]!=s[-1]:
        print(0)
    else:
        print((len(s)*k)//2)
    exit()
if len(s)==1:
    print(k//2)
    exit()
else:
    count=0
    temp=[]+s
    temp=[ i for i in temp]
    for i in range(1,len(s)):
        if temp[i]==temp[i-1]:
            temp[i]='randi'
            
            count+=1
    if s[0]!=s[-1]:
        print(count*k)
        exit()
    if s.count(s[0])==len(s):
        print((len(s)*k)//2)
        exit()
    if k==1:
        print(count)
        exit()
    if s[-1]==s[0] and s[0]!=s[1] and s[-1]!=s[-2]:
        print(count*k + k-1)
        exit()
    
    if s[-1]==s[0]==s[1]==s[-2]:
        print(count*k)
        exit()
    if s[i]==s[-1] and s[0]!=s[1] and s[-1]==s[-2]:
        print(count*k)
        exit()
    if s[0]==s[1] and s[0]==s[-1] and s[-1]!=s[-2]:
        print(count*k + k -1)
        exit()
    else:
        print(count*k)

Submission status: Wrong Answer

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

s = str(input()).replace('\n', '')
k = int(input())

s = s + s[0]

lst = []
last = ''
cnt = 0
for i in range(len(s)):
  if s[i] == last or last == '':
    cnt += 1
  else:
    lst.append(cnt)
    cnt = 1
  last = s[i]
lst.append(cnt)

    
n_lst = [i // 2 for i in lst]
answer = sum(n_lst)*k
if lst[-1]%2 == 0:
  answer -=  1
  
if len(lst) == 1:
  answer = (len(s)-1)*k//2
  
if s[0] == s[-2]:
  answer -= k//2
  

print(answer)

Submission status: Wrong Answer

Solution code:

# import sys
# input = sys.stdin.readline
from collections import Counter
import string


def main():
    # while True:
        S = input()
        K = int(input())

        count_1st = 0
        S1 = list(S * 1)
        for i in range(len(S) - 1):
            if S1[i] == S1[i+1]:
                count_1st += 1
                S1[i+1] = '_'
                # for c in string.ascii_lowercase:
                #     if i == 0:
                #         if c != S1[i+1]:
                #             count_1st += 1
                #             S1[i+1] = c
                #             break
                #     else:
                #         if c != S1[i-1] and c != S1[i+1]:
                #             count_1st += 1
                #             S1[i+1] = c
                #             break

        count_2nd = 0
        S2 = list(S * 2)
        for i in range(len(S) * 2 - 1):
            if S2[i] == S2[i+1]:
                count_2nd += 1
                S2[i+1] = '_'

        count_3rd = 0
        S3 = list(S * 3)
        for i in range(len(S) * 3 - 1):
            if S3[i] == S3[i+1]:
                count_3rd += 1
                S3[i+1] = '_'

        count_4th = 0
        S4 = list(S * 4)
        for i in range(len(S) * 4 - 1):
            if S4[i] == S4[i+1]:
                count_4th += 1
                S4[i+1] = '_'

        # count_k = 0
        # SK = list(S * K)
        # for i in range(len(S) * K - 1):
        #     if SK[i] == SK[i+1]:
        #         for c in string.ascii_lowercase:
        #             if i == 0:
        #                 if c != SK[i+1]:
        #                     count_k += 1
        #                     SK[i+1] = c
        #                     break
        #             else:
        #                 if c != SK[i-1] and c != SK[i+1]:
        #                     count_k += 1
        #                     SK[i+1] = c
        #                     break

        if K <= 4:
            if K == 1:
                print(count_1st)
            elif K == 2:
                print(count_2nd)
            elif K == 3:
                print(count_3rd)
            elif K == 4:
                print(count_4th)
        elif len(S) == 1:
            print(K//2)
        else:
            d = count_3rd - count_2nd
            # last_d = count_4th - count_3rd
            print(count_1st + d * (K-1))
            # print(*S1)
            # print(*S2)
            # print(*S3)
            # print(*S4)
            # print(d * K)
        # # print(K, d, count_1st)
        # # print(count_1st, count_2nd, count_3rd)
        # # print(count_k)
        # # print(*SK)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
s = list(input())
n = int(input())
a,b,c = 0,0,0
l = len(s)
for i in range(l-1):
    if s[i] == s[i+1]:
        a += 1
    else:
        break
for j in range(l-1,1,-1):
    if s[i] == s[i-1]:
        b += 1
    else:
        break
while l >= 2:
    x = s.pop(0)
    l -= 1
    if s[0] == x:
        c += 1
        s.pop(0)
        l -= 1
if a % 2 == 1 and b % 2 == 1:
    print(c*n+n-1)
else:
    print(c*n)

Submission status: Wrong Answer

Solution code:
s = input()
k = int(input())
t = s
cnt = 0
loop = 0
t = [i for i in t]
b = 0
while b < len(t) - 1:
    if t[b] == t[b + 1]:
        t[b + 1] = '?'
    b += 1
print(t.count("?") * k)

Submission status: Wrong Answer

Solution code:
s = input()
k = int(input())
t = s + s
ans = 0
i = 1
while True:
    c = 0
    while True:
        if i>=len(t):
            break
        elif t[i-1] == t[i]:
            i +=2
            c+= 1
        else:
            break
    ans += c
    if i>=len(t):
        break
    i+=1
if len(set(s))==1:
    c = int(len(s)%2==0)
elif s[0]==s[-1]:
    c = 0
    while True:
        s0 = s[-1]
        if len(s)==1:
            break
        if s0==s[0]:
            c +=1
            s = s[:-1]
        else:
            break
if c%2 ==1:
    print(((ans* k)+1)//2)
else:
    print(((ans* k))//2)

Submission status: Wrong Answer

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

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

another_c = ''
cnt = 0


t = list(s)
for i, c in enumerate(t):
    prev_c = t[i-1]
    next_c = t[(i+1)%len(t)]
    if i > 0 and c == prev_c:
        if i != len(t)-1 and next_c == chr(ord(c) + 1): 
            another_c = chr(ord(c) + 2)
        else:
            another_c = chr(ord(c) + 1)
        if ord(another_c) > ord('z'):
            another_c = 'a'
        t[i] = another_c
        cnt = cnt + 1
    #else:
    #    another_c = ''
    #print(i, c, another_c)

#print("".join(t))

if k > 2:
    cnt2 = 0
    t = list(s)
    for i, c in enumerate(t):
        prev_c = t[i-1]
        next_c = t[(i+1)%len(t)]
        if c == prev_c:
            if i != len(t)-1 and next_c == chr(ord(c) + 1): 
                another_c = chr(ord(c) + 2)
            else:
                another_c = chr(ord(c) + 1)
            if ord(another_c) > ord('z'):
                another_c = 'a'
            t[i] = another_c
            cnt2 = cnt2 + 1
        #else:
        #    another_c = ''
        #print(i, c, another_c)
    cnt = cnt + (cnt2 * (k-2))
        #print("".join(t))

if k > 1:
    t = list(s)
    for i, c in enumerate(t):
        prev_c = t[i-1]
        next_c = t[(i+1)%len(t)]
        if i != len(t)-1 and c == prev_c:
            if i != len(t)-1 and next_c == chr(ord(c) + 1): 
                another_c = chr(ord(c) + 2)
            else:
                another_c = chr(ord(c) + 1)
            if ord(another_c) > ord('z'):
                another_c = 'a'
            t[i] = another_c
            cnt = cnt + 1
        #else:
        #    another_c = ''
        #print(i, c, another_c)

    #print("".join(t))

print(cnt)

Submission status: Wrong Answer

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

ss=[]
if k%2 != 0:
    ss = s + s

def counter(string):
    count = 0
    answer = 0
    prev = ""
    for index,sss in enumerate(string):
        if prev == "" or sss == prev:
            count+=1
            if count == 2: 
                answer+=1
                count=0
                string[index] = "1"
        else:
            count=1
        prev = sss
    return answer,string

if not ss: 
    answer, string = counter(s)
    if string[0] == string[-1]:
        print(answer*k+k-1)
    else:
        print(answer*k)
else:
    kk = k//2
    answer, string = counter(s)
    answer2, string2 = counter(ss)

    if string2[0] == string2[-1]:
        print(answer2*kk + answer + k-1)
    else:
        print(answer2*kk + answer)

Submission status: Wrong Answer

Solution code:
#code
s=input()
k=int(input())
l=list()
curr=0
if(len(s)==1):
    print(int(k//2))
else:    
    for i in range(1,len(s)):
    
        if(s[i]!=s[i-1]and curr!=0):
            l.append(curr+1)
            curr=0
        if(s[i]==s[i-1]):
            curr+=1
    if(curr!=0):
        l.append(curr+1)
#for start
    start=0
    if(s[0]==s[len(s)-1] ):
        if(len(l)==0):
            start=2
        else:
            for i in range(1,len(s)):
                if(s[i]==s[i-1]):
                    start+=1
                else:
                    break
            start+=l[len(l)-1]+1
    ans=0
    if(start==0):
        for i in range(len(l)):
            ans+=(l[i]//2)
    
        ans=ans*k    
    else:
        if(len(l)==1):
            ans+=((l[0])//2)*k
        else:
            ans+=(start)//2
            ans=ans*(k-1)
            if(len(l)!=0):
                ans+=l[0]//2
                ans+=l[len(l)-1]//2
                if(len(l)>=3):
                    for i in range(1,len(l)-1):
                        ans+=((l[i]//2)*k)
    print(int(ans))

Submission status: Wrong Answer

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


def main():
    s = input()
    k = int(input())

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

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

    cnt2 = 1
    ans2 = 0
    s2 = s*2
    for i in range(len(s2)-1):
        if s2[i] == s2[i+1]:
            cnt2 += 1
        else:
            ans2 += cnt2 // 2
            cnt2 = 1
    ans2 += cnt2 // 2

    if ans * 2 != ans2:
        print(ans*k+k-1)
        exit()

    print(ans*k)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import collections
S =[i for i in input()]
K = int(input())
a = 1
b = []
c = []
result = 0
if S[0] != S[-1]:
  try:
    for j in range(len(S)):
      if S[j] == S[j+1]:
        a += 1
      else:
        b.append(a)
        a = 1
  except:
    b.append(a)
  for k in b:
    result += k//2
  print(result*K)
elif len(collections.Counter(S)) == 1:
  print(len(S)*K//2)
else:
  for j in range(len(S)):
    if S[j] == S[j + 1]:
      a += 1
    else:
      c.append(a)
      a = 1
      break
  for j in range(len(S)):
    if S[-j-1] == S[-j-2]:
      a += 1
    else:
      c.append(a)
      break
  S = S+S
  S = S[c[0]:-c[1]]
  try:
    for j in range(len(S)):
      if S[j] == S[j+1]:
        a += 1
      else:
        b.append(a)
        a = 1
  except:
    b.append(a)
  for k in b:
    result += k//2
  print(result*K//2+c[0]//2+c[1]//2+(c[0]+c[1])//2*K//2)

Submission status: Wrong Answer

Solution code:
X=input()
a=int(input())
count=0
z=list(X)
b=0
ans=0
k=0
for k in range(len(z)-1):
    if z[k]==z[len(z)-1]:
        b+=1
for i in range(len(z)-1):
    if z[i]==z[i+1]:
        z[i+1]=0
        count=count+1
ans=int(a*count+(a-1)*(((b+1)/2)-1))
print(ans)

Submission status: Wrong Answer

Solution code:
s=list(input())
ss=s[:]
k=int(input())
count=0
for i in range(len(s)-1):
    if s[i]==s[i+1]:
        s[i+1]='0'
        count+=1
ans=count*k
if s[-1]== s[0]: ans+=k-1
if len(s)==1: 
    print(k//2)
elif len(set(ss))==1:
        print(k*len(s)//2)    
else:print(ans)

Submission status: Wrong Answer

Solution code:
# A - Connection and Disconnection
S = str(input())
K = int(input())
count =  0
tmp = 0
N = len(S)

if N == 1:
    if K >= 2:
        count = 1 * (K//2)
    else:
        count = 0
elif S[0] == S[N-1]:
    count += 1
else:
    pass

for i in range(1,N-1):
    if S[i-1] == S[i] == S[i+1] and tmp == 0:
        tmp = 1
    else:
        tmp = 0
    if S[i-1] == S[i] and tmp == 0:
        count += 1
    else:
        pass
if S[N-2] == S[N-1] and tmp == 1:
    count += 1
else:
    pass


if N == 1 and tmp == 0:
    print(count)
elif N == 3 and tmp == 0:
    print(count*(K-1))
elif N == 3 and tmp == 1:
    print(count + K)
else:
    ans = count * K
    print(ans)

Submission status: Wrong Answer

Solution code:
import string


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 <= 2:
        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])
        print(res)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

# sが1種類の文字の繰り返しの場合
if len(set(s)) == 1:
    print((len(s) * k) // 2)

# 複数種の場合
else :
    # 同じ文字の連続する箇所をカウント
    before_mozi = ''
    count_l = [0]
    same_f = False
    for mozi in s:
        if mozi == before_mozi:
            if not same_f:
                count_l.append(1)
            count_l[-1] += 1
            same_f = True
        else:
            same_f = False
        before_mozi = mozi

    # 先端と末端の文字が同じ場合
    if s[0] == s[-1]:

        # 先端と末端の文字が同じで，
        # かつお互いが2文字以上連続していないとき
        if s[0] != s[1] and s[-1] != s[-2]:
            result = sum([x // 2 for x in count_l]) * k + k-1

        # どちらかが1文字の場合
        elif s[0] != s[1] or s[-2] != s[-1]:
            # 先頭が1文字の場合
            if s[0] != s[1]:
                result = sum([x // 2 for x in count_l[:-1]]) * k + (count_l[-1] + 1)//2 * (k-1) + count_l[-1]//2
            # 末端が1文字の場合
            else:
                result = sum([x // 2 for x in count_l[1:]]) * k + (count_l[0] + 1)//2 * (k-1) + count_l[0]//2

        # どちらも2文字以上連続する場合
        else:
            result = sum([x // 2 for x in count_l[1:-1]]) * k + (count_l[0] + count_l[1])//2 + count_l[0]//2 + count_l[-1]//2

    else:
        result = sum([x // 2 for x in count_l]) * k

    print(result)

Submission status: Wrong Answer

Solution code:
s = list(input())
k = int(input())
t = s[:]
c = 0

if len(t) == 1:
    print(0)
else:
    t.append(s[0])
    # print(t)
    for i in range(1, len(t) - 1):
        if t[i - 1] == t[i]:
            c += 1
            t[i] = "A"
    # print(t)
    c *= k
    if t[-1] == t[-2]:
        c += k - 1
    print(c)

Submission status: Wrong Answer

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

check = True
def makerawlist(S):
    sigma = 0
    counter = 1
    for i in range(len(S)-1):
        if S[i]==S[i+1]:
            counter += 1
        else:
            sigma += counter//2
            check = False
            counter = 1
    sigma += counter//2
    return sigma


sigma = makerawlist(S)
if check:
    if (len(S)*K)%2==1:
        print((len(S)*K)//2)
    elif len(S)%2==1 and (len(S)*K)%2==0:
        print((len(S)*K)//2)

elif S[0]==S[len(S)-1] and S[0]!=S[1] and S[len(S)-2]!=S[len(S)-1]:
    print(sigma*K+K-1)
else:
    print(sigma*K)

Submission status: Wrong Answer

Solution code:
s=input()
k=int(input())
p=s[0]
cnt=1
q=[]
for i in range(len(s)-1):
	if s[i+1]==p:
		cnt+=1
	else:
		q.append(cnt)
		cnt=1
		p=s[i+1]
q.append(cnt)
if q[-1]%2==0:
	cnt=True
else:
	cnt=False
ans=0
if cnt==True:
	for i in range(len(q)):
		ans+=q[i]//2
	print(ans*k)
	exit()
for i in range(len(q)):
	ans+=q[i]//2
ans*=k
if s[0]==s[-1]:
	ans+=k-1
print(ans)

Submission status: Wrong Answer

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

# now_s = S[0]
# for i in range(1, len(S)):
#     if now_s == S[i]:
#         cnt += 1
#     now_s = S[i]

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


cnt = 0
ruisekiwa = [1]
now_s = S[0]
for i in range(1, len(S)):
    if now_s == S[i]:
        ruisekiwa[-1] += 1
    else:
        ruisekiwa.append(1)
    now_s = S[i]

if len(ruisekiwa) == 1:
    if ruisekiwa[0] % 2 == 0:
        print(ruisekiwa[0]//2*K)
        exit()

    # 文字数が奇数
    if K % 2 == 0:
        cnt += (ruisekiwa[0]-2) * (K//2)
        cnt += (ruisekiwa[0]-1) * (K//2)
    else:
        cnt += (ruisekiwa[0]-2) * (K//2 + 1)
        cnt += (ruisekiwa[0]-1) * (K//2)
    print(cnt)
    exit()

# 文字種が1種類のパターンはおk

cnt = 0
for i in range(len(ruisekiwa)):
    cnt += ruisekiwa[i]//2

# 先頭と末尾が違うなら問題ない
if S[0] != S[-1]:
    print(cnt*K)
    exit()




# 先頭と末尾が同じ場合を考える

# 先頭が偶数回数続いていて, 末尾も偶数回数
if ruisekiwa[0] % 2 == 0 and ruisekiwa[-1] % 2 == 0:
    print(cnt * K)
    exit()

# 先頭が奇数回数続いていて, 末尾も奇数回数
if ruisekiwa[0] % 2 == 1 and ruisekiwa[-1] % 2 == 1:
    # if K % 2 == 1:
    #     print(cnt * (K//2+1) + (cnt+1) * (K//2))
    # else:
    #     print(cnt * (K//2) + (cnt+1) * (K//2))
    # exit()
    print((cnt+1) * K -1)
    exit()
    # ここを直した

# 先頭が偶数, 末尾が奇数
if ruisekiwa[0] % 2 == 0 and ruisekiwa[-1] % 2 == 1:
    print(cnt * K)
    exit()

# 先頭が奇数, 末尾が偶数
if ruisekiwa[0] % 2 == 1 and ruisekiwa[-1] % 2 == 0:
    print(cnt * K)
    exit()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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


# for s in S:
#     if s.isupper():
#         exit()
#     try:
#         float(s)
#     except ValueError:
#         pass
#     else:
#         exit()
# try:
#     float(K)
# except ValueError:
#     exit()
# else:
#     if not float(K).is_integer():
#         exit()

# if not (1 <= len(S) and len(S) <= 100):
#     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)
# print(L)

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

print(count*int(K))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from sys import stdin
from itertools import groupby

s = stdin.readline().rstrip()
k = int(stdin.readline().rstrip())

def cou(st):
    li = []
    point = 1
    for i in range(len(st)-1):
        if st[i] == st[i+1]:
            point += 1
            if i == len(st)-2:
                li.append(point)
        else:
            li.append(point)
            point = 1
    return li

if len(s) == 1:
    lin = [1]
else:
    lin = cou(s)

if len(lin) == 1:
    print(lin[0]*k//2)
    exit()

lin2 = lin

if k > 1:
    if s[0] == s[-1]:
        lin[-1] += lin[0]
else:
    if len(s) == 1:
        print(0)
        exit()

point = 0
point2 = 0
for i in range(1,len(lin)):
    point += lin[i]//2
for w in range(1,len(lin2)):
    point2 += lin2[w]//2
point = point*(k-1)
point += point2
point += lin[0]//2
print(int(point))

Submission status: Wrong Answer

Solution code:
s = input()
k = int(input())
sum_count = 0
count = 1
key = s[0]
flag = False
if s[0] == s[len(s)-1] and s[len(s)-2] != s[len(s)-1] and len(s)>=3:
    flag = True
    for i in range(1,len(s)):
        if s[i] == key:
            count += 1
        else:
            sum_count += count//2
            key = s[i]
            count = 1
elif s.count(s[0]) == len(s):
    sum_count = int((len(s)/2)*k)
    k = 1
else:
    flag = False
    for i in range(1,len(s)):
        if s[i] == key:
            count += 1
        else:
            sum_count += count//2
            key = s[i]
            count = 1

sum_count += count//2

if flag == True:
    print((sum_count)*k+1)
else:
    print(sum_count*k)

Submission status: Wrong Answer

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


# for s in S:
#     if s.isupper():
#         exit()
#     try:
#         float(s)
#     except ValueError:
#         pass
#     else:
#         exit()
# try:
#     float(K)
# except ValueError:
#     exit()
# else:
#     if not float(K).is_integer():
#         exit()

# if not (1 <= len(S) and len(S) <= 100):
#     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)
# print(L)

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

print(count*int(K))

Submission status: Wrong Answer

Solution code:
from sys import stdin


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

    s1, s2 = S, S + S
    num = [0, 0]
    for i, s in enumerate((s1, s2)):
        l, prev = 1, ''
        for si in s:
            if si == prev:
                l += 1
            else:
                num[i] += l // 2
                l = 1
            prev = si
        num[i] += l // 2
    ans = num[0] + (num[1] - num[0]) * (K - 1)
    print(ans)


main()

Submission status: Wrong Answer

Solution code:
S = list(input())
K = int(input())
if S.count(S[0]) == len(S):
    print(len(S) * K // 2)
    exit()

cnt = 0
continuous = 0
chr = S[0]
for i in range(1, len(S)):
    if chr == S[i]:
        cnt += 1
    if chr != S[i] or i == len(S) - 1:
        continuous += (cnt + 1) // 2
        cnt = 0
    chr = S[i]
if continuous == 0 and S[0] == S[-1]:
    print(K - 1)
else:
    if S[0] == S[-1] and S[-2] != S[0] and S[2] != S[0]:
        print(K * continuous + K - 1)
    else:
        print(K * continuous)

Submission status: Wrong Answer

Solution code:
S = list(input())
l = int(len(S))      ##Sの長さ
K = int(input())
counter_mae = 0            ##最初からカウント             
counter_ato = 0
count = 0
Frag = False         ##偶奇フラグ(Trueは影響なし)
Frag_z = False       ##全部同じかどうか
if S[0] == S[l - 1]:        ##先頭と末尾が同じとき
    for i in range(1,l):        ##先頭からの何文字目まで同じか
        if S[i] == S[0]:
            counter_mae += 1
        else:
            break
    if counter_mae == l:        ##全文字同じ場合 
        Frag_z = True
    else:                       ##全文字同じではないとき
        for i in range(l - 1):
            if S[0] == S[l - i - 1]:        ##後ろから何文字まで同じか
                counter_ato += 1

            else:
                break

        if counter_ato % 2 == 0:
            Frag = True
        else:
            if counter_mae % 2 == 0:
                Frag = True

for i in range(len(S) - 1):     ##Sの中の書き換え操作回数
    if S[i] == S[i + 1]:
        count += 1
        S[i + 1] = "0"

if Frag_z == True:
    if count % 2 == 0:
        print(K * count)
    else:
        if K % 2 == 0:
            print((K // 2) *(2 * count + 1))
        else:
            print((K // 2) * (count + 1) + (K // 2 + 1) * (count))
else:
    if Frag == True:
        print(K * count)

    else:
        print(count + (K - 1) * count)