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:
def slove():
    import sys
    input = sys.stdin.readline
    ss = str(input().rstrip('\n'))
    nn = int(input().rstrip('\n'))
    s = 0
    sb = True
    e = 0
    eb = True
    t = 0
    cnt = 0
    if ss[0] == ss[-1]:
        for i in range(len(ss)):
            if ss[i] == ss[0]:
                if sb:
                    s += 1
            else:
                sb = False
            if ss[-i-1] == ss[0]:
                if eb:
                    e += 1
            else:
                eb = False
    else:
        sb = False
        eb = False
    if sb and eb:
        cnt += ((s + e) // 2 // 2)
        s = 0
        e = 0
    else:
        for i in range(max(s, 1), min(len(ss) - e + 1, len(ss))):
            if ss[i] == ss[i-1]:
                t += 1
            else:
                t += 1
                cnt += (t // 2)
                t = 0
        cnt += (t // 2)
    print(cnt * nn + s // 2 + e // 2 + (s + e) // 2 * (nn - 1))


if __name__ == '__main__':
    slove()

Submission status: Wrong Answer

Solution code:
S = input()
K = int(input())
i = 0
ans = 0
while i<len(S)-1:
  if (S[i]==S[i+1]):
    ans += 1
    i+=2
  else:
    i += 1
if (len(S)>2):
  if (S[len(S)-2]==S[len(S)-1]):
    if(S[0]==S[len(S)-1]):
      ans=ans+K-1
         
print(ans*K)

Submission status: Wrong Answer

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

a = S[0]
c = 0
g = []

for i in range(len(S)):
    if a == S[i]:
        c += 1
    else:
        g.append(c)
        a = S[i]
        c = 1

g.append(c)

if len(g) == 1:
    c = len(S) * K / 2
elif S[0] == S[-1]:
    c = int(g[0] / 2)
    c += int(g[-1] / 2)

    for i in range(1, len(g) - 1):
        c += int(g[i] / 2) * K
else:
    c = 0
    for i in g:
        c += int(i / 2) * K


print(int(c))

Submission status: Wrong Answer

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

def is_onaji(S):
    pre_moji = S[0]
    for i in range(1, len(S)):
        if S[i] == pre_moji:
            pre_moji = S[i]
            continue
        else:
            return False
    return True


def solve():
    S = input()
    K = int(input())
    N = len(S)

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

    base = 0
    pre_moji = S[0]
    for i in range(1, N):
        if S[i] == pre_moji:
            base += 1
            pre_moji = "?"
        else:
            pre_moji = S[i]

    if K == 1:
        print(base)
        return

    # Sがすべて同じ文字で構成されているかを調べる
    if is_onaji(S):
        if N%2 == 1:
            odd_base = base
            even_base = base+1
            odd = (K+1)//2
            even = K//2
            print(odd_base*odd + even_base*even)
            return
        else:
            K_base = base
    else:
        if pre_moji == S[0]:
            K_base = base + 1
        else:
            K_base = base

    print(base + K_base*(K-1))


if __name__ == "__main__":
    solve()

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()


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

cnt = cnt * K

if S[0] == S[-1] and S[-2] != S[-1]:
    cnt += K-1

print(cnt)

Submission status: Wrong Answer

Solution code:
s=input()
n=int(input())
ss=s+s
tmp1=0
tmps=""
for i in s:
    if tmps==i:
        tmp1+=1
        tmps=""
    else:
        tmps=i
tmp2=0
tmps=""
for i in ss:
    if tmps==i:
        tmp2+=1
        tmps=""
    else:
        tmps=i
sss=s+s+s
tmp3=0
tmps=""
for i in sss:
    if tmps==i:
        tmp3+=1
        tmps=""
    else:
        tmps=i

sa1=tmp2-tmp1
sa2=tmp3-tmp2
if n%2==1:
    print(tmp1+(sa1+sa2)*(n//2))
else:
    print(tmp1+(sa1+sa2)*(n//2-1)*sa1)

Submission status: Wrong Answer

Solution code:
S = input()
K = int(input())
pre_character = ''
S_list=list(S)
def get_abc(s1,s2):
    if s1 == 'a':
        if s2 == 'b':
            return 'c'
        else:
            return 'b'
    elif s1 == 'b':
        if s2 == 'a':
            return 'c'
        else:
            return 'a'
    else:
        if s2 == 'a':
            return 'b'
        else:
            return 'a'
        
s_len = len(S)
count = 0
for i in range(s_len):
    if pre_character == S_list[i]:
        count += 1
        if (s_len - 1) != i:
            S_list[i] = get_abc(pre_character,S_list[i+1])
        else:
            S_list[i] = get_abc(pre_character,S_list[0])
    pre_character = S_list[i]
if S_list[0] == S_list[-1]:
    pre_character = S_list[-1]
    S_list=list(S)
    second_count = 0
    for i in range(s_len):
        if pre_character == S_list[i]:
            second_count += 1
            if (s_len - 1) != i:
                S_list[i] = get_abc(pre_character,S_list[i+1])
            else:
                S_list[i] = get_abc(pre_character,S_list[0])
        pre_character = S_list[i]
    print(count + (second_count*(K-1)))
else:
    print(count*K)

Submission status: Wrong Answer

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

count = 0
flag = 0
for i in range(len(s) - 1):
    if flag == 0:
        if s[i] == s[i + 1]:
            count += 1
            flag = 1
    else:
        flag = 0

ans = count * k

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

Submission status: Wrong Answer

Solution code:
s=input()
k=int(input())
ans=0
tmp=0
before=s[0]
t=0
flag=0
tmp2=0
hoge=0
for i in range(len(s)-1):
    if before==s[i+1]:
        t+=1
    else:
        if flag==0:
            hoge+=t
            flag=1
            tmp+=-(-t//2)
        elif i==len(s)-2:
            hoge+=t
            tmp+=-(-t//2)
        else:
            tmp+=-(-t//2)
            tmp2+=-(-t//2)
        t=0
        before=s[i+1]
tmp+=-(-t//2)
hoge+=t
tmp2+=-(-(hoge+1)//2)
if s[0]==s[-1]:
    print(tmp2*(k-1)+tmp)
else:
    print(tmp*k)

Submission status: Wrong Answer

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

prev = ""

n = 0

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

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


    print(ans)

Submission status: Wrong Answer

Solution code:
import sys

str = input()
N = int(input())

cnt = 0

l = len(str)

if str[0] == str[l-1]:
    cnt += 1

for i in range(1,l-3):
    if str[i] == str[i+1]:
        cnt += 1

print(cnt*N)

Submission status: Wrong Answer

Solution code:
s=input()
k=int(input())
z=0
if s[0] == s[-1]:
    # head
    h = 1
    for i in range(1,len(s)):
        if s[0] == s[i]:
            h += 1
        else:
            break
    # tail
    t = 1
    for i in range(len(s)-2, -1, -1):
        if s[-1] == s[i]:
            t += 1
        else:
            break
    if h == len(s):
        # s only consists of the same letter
        z = h // 2
    else:
        z = (h + t) // 2
    #print(999,h,t,z)
else:
    h = t = 0
#print(s,k,h,t)
if (h + t) < len(s):
    m = s[h]
    n = 1
    for i in range(h+1, len(s)-t):
        if m == s[i]:
            n += 1
            if (n & 2):
                z += 1
        else:
            m = s[i]
            n = 1
print(z * k)

Submission status: Wrong Answer

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

n = len(s)
cnt = [0]

for i in range(0,n-1):
    if s[i] == s[i+1]:
        cnt[-1] += 1
    else:
        if cnt[-1] != 0:
            cnt.append(0)

ren = 0
for i in cnt:
    ren += (i+1)//2

b=0
if s[0] == s[-1]:
    if (cnt[-1] % 2) == 0:
        b += k-1

ans = ren * k + b

print(ans)

Submission status: Wrong Answer

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

first_char = s[0]
pre_char = ''
char = ''
ans = 0
last_char_change = False

for i in range(len(s)):
    if pre_char == '':
        pre_char = s[i]
    else:
        char = s[i]
        if pre_char == char:
            ans += 1
            pre_char = ''
        else:
            pre_char = char
            if i == len(s) - 1:
                if first_char == char:
                    ans += 1
                    last_char_change = True
            
    
ans *= n

if last_char_change:
    ans -= 1

print(ans)

Submission status: Wrong Answer

Solution code:
from itertools import groupby
S = input()
K = int(input())

s = [[k, len(list(g))] for k, g in groupby(S)]
s_count = sum(ss[1] // 2 for ss in s)
result = s_count * K
print(result)

Submission status: Wrong Answer

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

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

zcount=0
ju=0
for i in range(len(S)):
  if S[i]==S[0]:
    zcount+=1
    if i==len(S)-1:
      ju=1
  else:
    break

if ju==0:
  for i in reversed(range(len(S))):
    if S[i]==S[0]:
      zcount+=1
    else:
      break
  
if S[0]==S[1]:
  S[0]="#"
for i in range(1,len(S)):
  if S[i-1]==S[i]:
    S[i]="#"

ans=S.count("#")
if ju==1 and len(S)%2==1:
  print((len(S)*K)//2)
  exit()
  
if S[0]=="#" and zcount%2==1 and ju==0:
  ans-=1
print(ans*K)

Submission status: Wrong Answer

Solution code:
a = list(input())
b = int(input())
c = len(a)
sum = 0
for i in range(0,c-1):
  if a[i]==a[i+1]:
    a[i+1]="q"
    sum+=1
print(sum*b)

Submission status: Wrong Answer

Solution code:
def li():
    return list(map(input().split()))


if __name__ == "__main__":
    s = input()
    k = int(input())

    count = 0
    before = ""
    for si in s:
        if before == si:
            count += 1
            before = ""
        else:
            before = si

    count2 = 0
    before = ""
    for si in s + s:
        if before == si:
            count2 += 1
            before = ""
        else:
            before = si
    diff = count2 - count

    is_corner = before == s[0]
    corner_count = k - 1 if is_corner else 0
    # print(count * k + corner_count)
    print(count + diff * (k - 1))
    # print(count, count2)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
#AGC39 A

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

s = input()
k = I()
n = len(s)
res1 = 0
i = 0
while i < n:
    tmp = s[i]
    i += 1
    cnt = 1
    while i < n and tmp == s[i]:
        cnt += 1
        i += 1
    res1 += cnt//2
s = s+s
res = 0
i = 0
while i < 2*n:
    tmp = s[i]
    i += 1
    cnt = 1
    while i < 2*n and tmp == s[i]:
        cnt += 1
        i += 1
    res += cnt//2
if s[0] == s[-1] and res1 == 0:
    tmp = 1
else:
    tmp = 0
print(res*(k//2)+res1*(k%2)+tmp)

Submission status: Wrong Answer

Solution code:
# coding:utf-8

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

if(len(s) == 1 and k > 1):
    print( int(k / 2) )
elif(len(s) == 1 and k == 1):
    print(0)
else:
    chenge_count = 0
    count_tmp = 0
    for i in range(1, len(s)):
        if( s[i] == s[i-1] ):
            count_tmp += 1
        elif(s[i] != s[i-1]):
            count_tmp += 1
            chenge_count += int(count_tmp / 2)
            count_tmp = 0
    chenge_count += int(count_tmp / 2)
    if(s[0] == s[-1] and k > 1):
        chenge_count += 1
    print(chenge_count * 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 same_f:
                count_l[-1] += 1
            else:
                count_l.append(2)
                same_f = True
        else:
            same_f = False
        before_mozi = mozi

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

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

    print(result)

Submission status: Wrong Answer

Solution code:

import sys
input = sys.stdin.readline
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
# A = [ int(input()) for _ in range(N) ]
##############################

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

T = S

count = 0
for i in range(1, len(T)):
    if T[i-1] == T[i]:
        count += 1
        T[i] = '-'

count *= K

if T[0] == T[-1]:
    count += (K-1)

print(count)

Submission status: Wrong Answer

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

tmp = ""
cnt = 0
ans = 0
for s in S:
    if s == tmp:
        cnt += 1
    else:
        ans += cnt//2
        cnt = 1
    tmp = s

if cnt == len(S):
    ans += (cnt*K)//2
else:
    ans *= K
    
    first_cnt = 0
    if S[0] == S[-1]:
        for s in S:
            if s == S[0]:
                first_cnt += 1
            else:
                break
        ans += (cnt+first_cnt)//2 * (K-1)
        ans += cnt//2
    else:
        ans += cnt//2 * K

print(ans)

Submission status: Wrong Answer

Solution code:
s=list(str(input()))
n=int(input())

i0 = s[0]
count = 0
if len(s) == 1:
    ans = n//2
else:
    for i, name in enumerate(s[1:]):
        if name == i0:
            i0 = -1
            count += 1
            s[i+1] = i0
        else:
            i0 = name
    if s[0] == s[-1]:
        al = n-1
        if s[1] == -1:
            al = 0
    else:
        al = 0
    ans = count*n + al
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np

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

S_twice = S + S

A = np.full(len(S),0)
A_twice = np.full(len(S),0)

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

count = 0
for i in range(0, len(S_twice)-1):
    if S_twice[i] == S_twice[i-1]:
        count = count + 1
    else:
        A_twice[count] = A_twice[count] + 1
        count = 0

if count > len(S):
    print len(S)*K/2
    exit()

A_k = A + (K-1)*(A_twice-A)

ans = 0

for i in range(A_k.shape[0]):
    ans = ans + (i+1)/2*A_k[i]

print ans

Submission status: Wrong Answer

Solution code:
def getCount(target, index):
    count = 0
    key_char = target[index]
    
    for char in target[index::] :
        if (key_char == char) :
            count += 1
        else :
            break
    
    return count

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

head_seq = getCount(s, 0)
target_str = s[head_seq::] + s[0:head_seq:]

position = 0
replace_count = 0
while position < len(target_str) :
    temp_seq = getCount(target_str, position)
    replace_count += temp_seq // 2
    position += temp_seq

print(replace_count * k)

Submission status: Wrong Answer

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

def counter_func(string,x):
  try:
    if string[x] == string[x+1]:
      return 1
    else:
      return 0
  except:
    return 0
  
counter = []
count = 0
j = 0
while j < length:
  if counter_func(s,j) == 1:
    count += 1
  else:
    counter.append(count)
    count = 0
  j += 1
if s[-1] == s[0]:
  counter[-1] += 1
sum = 0
for i in range(len(counter)):
  if counter[i] != 0:
    sum += int((counter[i]+1)/2)*k
print(sum)

Submission status: Wrong Answer

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

# Summarize count of factor within list
def summarize_list(l):
  sl=l

  a=sl[0]
  c=1
  res=[]

  for x in sl[1:]:
    if x==a:
      c+=1
    else:
      res.append([a,c])
      a=x
      c=1
  res.append([a,c])

  return res

def main():
  s=S()
  k=I()

  if len(s)==1:
    return k//2

  l=summarize_list(s)

  if len(l)==1:
    return (l[0][1]*k)//2

  ans=0
  bf=False
  
  if l[0][0]==l[-1][0] and l[0][1]==1 and l[-1][1]==1:
    bf=True

  _ans=0
  for x in l:
    _ans+=x[1]//2
  ans+=_ans*k

  if bf:
    ans+=k-1

  return ans

# main()
print(main())

Submission status: Wrong Answer

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

a = len(S)
b = len(set(S))

n = (a-b)//2
if (a-b) % 2 == 1:
    n += 1

print(n*K)

Submission status: Wrong Answer

Solution code:

def hoge():
    string = input()
    string = string + string[0] + '0'
    num = int(input())
    count = 0
    total_count = 0
    for i in range(len(string) - 1):
        if string[i] == string[i+1]:
            count += 1
        else:
            if count != 0:
                total_count += (count + 1) // 2
                count = 0

    print(total_count * num)

hoge()

Submission status: Wrong Answer

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

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

if len(S) == 1:
    ans = K // 2
    print(ans)
    exit()
if S[-1] == S[0] and S[0] != None:
    ans += (K-1)
print(ans)

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] :
        S[i]=j
        count+=1
        break
print(count*k)

Submission status: Wrong Answer

Solution code:
s = input()
k = int(input())
n = len(s)
count = 0
C = 0
change = 0
for i in range(n-1):
  if s[i] == s[i+1]:
    count += 1
    C += 1
  else:
    if count == 1:
      change += 1
    elif count%2 == 0:
      change += count//2
    else:
      change += (count+1)//2
    count = 0
    C = 0
if count == 1:
  change += 1
elif count%2 == 0:
  change += count//2
else:
  change += (count+1)//2
if C%2 != 0:
  print(change*k)
else:
  print(change*k + k-1)

Submission status: Wrong Answer

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

counter = 0
tmp = s[0]
counter_list = []

s_dict = dict()
for i,one in enumerate(s):
    s_dict[one] = i
    
if len(s_dict) == 1:
    print((len(s)*k)//2)
else:
    for one in s[1:]:
        if tmp == one:
            counter += 1
        else:
            counter_list.append((counter+1)//2)
            counter = 0
            tmp = one
    counter_list.append((counter+1)//2)

    sum_counter = sum(counter_list)
    if s[0] == s[-1]:
        if counter % 2 != 0:
            print(sum_counter*k)
        else:
            print(sum_counter*k + k -1)
    else:
        print(sum_counter*k)

Submission status: Wrong Answer

Solution code:
S = input()
N = int(input())
c = 0
s = S
j = [True]*len(s)
if len(S)==1:
  print(N//2)
  exit()
for i in range(0,len(s)-1):
  if s[i]==s[i+1] and j[i]==True:
    ##print(i,s[i],s[i+1])
    #print(s)
    j[i+1]=False
    c+=1

c = c*N
if S[0]==S[-1] and len(S)>2 and j[-1]==True:
  c+=(N-1)
print(c)

Submission status: Wrong Answer

Solution code:
s = input()
length = len(s)
k = int(input())
if(len(s)==1):
    print(int(k/2))
    exit()
start = 0
end = 0
t = 0
last = 0
count = 0
ans = 0
b4 = s[0]
for c in s:
    if(b4!=c):
        if(last==0):
            start=t
            t=1
            last = 1
        else:
            ans+=int(t/2)
            t=1
    else:
        t+=1
    count+=1
    b4=c
end = t
#print(start)
#print(end)
if(s[0] == s[-1]):
    result = (ans*k)+int((start+end)/2)*k +int(start/2) +int(end/2)-1
    if(result<0):print(0)
    else:print(result)
else:print((int(end/2)+int(start/2)+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

    else:
        j = 0

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

Submission status: Wrong Answer

Solution code:
s=list(input())
k=int(input())
an1=0
an2=0
skip=0

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

for i in range(len(s)-1):
    if skip==1:
        skip=0
        continue
    
    if s[i]==s[i+1]:
        an1+=1
        skip=1

if len(s)>=3:
    if s[0]==s[-1]:
        if s[0]!=s[-2]:
            an2=k-1

print(an1*k+an2)

Submission status: Wrong Answer

Solution code:
from copy import deepcopy
from sys import exit,setrecursionlimit
import math
from collections import defaultdict,Counter,deque
from fractions import Fraction as frac
import bisect
import sys
input = sys.stdin.readline

setrecursionlimit(1000000)


def main():
	s = input()
	k = int(input())
	s_ = [[s[0],1]]
	ct = 0
	for i in s[1:-1]:
		if(s_[-1][0] == i):
			s_[-1][1] += 1
		else:
			s_.append([i,1])
	for i in s_:
		if(i[1] > 1):
			ct += math.ceil((i[1] - 1)/2)
	ct *= k
	if((len(s) - 1) ^ 2 == 1 and len(s_ ) == 1):
		print((len(s) - 1) * k // 2)
	else:
		print(ct)


def zip(a):
	mae = a[0]
	ziparray = [mae]
	for i in range(1,len(a)):
		if(mae != a[i]):
			ziparray.append(a[i])
			mae = a[i]
	return ziparray

def is_prime(n):
	if n < 2: return False

	for k in range(2, int(math.sqrt(n)) + 1):
		if n % k == 0:
			return False

	return True

def list_replace(n,f,t):
	return [t if i==f else i for i in n]

def base_10_to_n(X, n):
	X_dumy = X
	out = ''
	while X_dumy>0:
		out = str(X_dumy%n)+out
		X_dumy = int(X_dumy/n)
	if(out == ''): return '0'
	return out

def gcd(l):
	x = l.pop()
	y = l.pop()
	while(x%y!=0):
		z = x%y
		x = y
		y = z
	l.append(min(x,y))
	return gcd(l) if len(l) > 1 else l[0]

class Queue():
	def __init__(self):
		self.q = deque([])
	def push(self,i):
		self.q.append(i)
	def pop(self):
		return self.q.popleft()
	def size(self):
		return len(self.q)
	def debug(self):
		return self.q

class Stack():
	def __init__(self):
		self.q = []
	def push(self,i):
		self.q.append(i)
	def pop(self):
		return self.q.pop()
	def size(self):
		return len(self.q)
	def debug(self):
		return self.q

class graph():
	def __init__(self):
		self.graph = defaultdict(list)
	def addnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].append(t)
		self.graph[t].append(f)
	def rmnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].remove(t)
		self.graph[t].remove(f)
	def linked(self,f):
		return self.graph[f]

class dgraph():
	def __init__(self):
		self.graph = defaultdict(set)
	def addnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].append(t)
	def rmnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].remove(t)
	def linked(self,f):
		return self.graph[f]

main()

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)
if 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:
        if s[-2]==s[-1]:print(cnt*k)
        else:print(cnt*k+k-1)
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:
from sys import stdin
from itertools import accumulate, dropwhile, takewhile, groupby

# 入力 =stdin.readline().rstrip()
# 分割 = stdin.readline().rstrip().split()

'''
条件に合うものを絞り込む
data = [1, 2, 3]
s = [x for x in data if x % 3 == 0]
'''

'''
文字配列を数値に
l_si = ['-10', '0', '100']

l_si_i = [int(s) for s in l_si]
'''

'''
a = [2, 4, 6, 8]
b = [3, 6, 9]

print(list(set(a) | set(b)))  # 和集合
print(list(set(a) & set(b)))  # 積集合
'''

'''
N = int(stdin.readline().rstrip())
A = [int(x) for x in stdin.readline().rstrip().split()]
count = 0
while len([x for x in A if x % 2 == 0]) == N:
    A = list(map(lambda y: y / 2, A))
    count += 1
print(count)
'''

'''
.append(要素)
.insert(場所,要素)
-1で末尾で末尾から一つ前
'''
'''
間に空白追加
' '.join(lis)
'''
T = stdin.readline().rstrip()
num = int(stdin.readline().rstrip())
ch = ''
count = 0
forcount = 0
changed = False
test = False
for t in T:
    if (ch == t and not changed):
        count += 1
        changed = True
    elif (changed):
        changed = False
    if (forcount == len(T) - 1 and ch == T[0] and not changed):
        test = True
    ch = t
    forcount += 1
count *= num
if (test):
    count += num-1

print(count)

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

    if(isbefchange == False and S[len(S)-1] == S[0]):
        count += 1
    
    count *= K 
    print(count * K)

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 s[0]!=s[1] and s[-1]!=s[-2]:
        ans+=-(-k//2)
print(ans)

Submission status: Wrong Answer

Solution code:
S=input()
K=int(input())
l=len(S)
a=0
s=S[0]
b,c=-1,-1
for i in range(1,l):
    if s!=S[i]:
        b=i
        a+=i//2
        break
s=S[-1]
if b!=-1:
    for i in range(l-2,-1,-1):
        if s!=S[i]:
            c=i
            a+=(l-i-1)//2
            break
if b==-1:
    print(l*K//2)
else:
    t=1
    s=S[b]
    for i in range(b+1,c+1):
        if S[i]==s:
            t+=1
        else:
            a+=t//2*K
            t=1
            s=S[i]
    a+=t//2*K
    if S[0]==S[-1]:
        a+=(b+l-c-1)//2*(K-1)
    print(a)

Submission status: Wrong Answer

Solution code:
import sys
def input():
    return sys.stdin.readline()[:-1]
inf=float("inf")
s=input()
k=int(input())
cnt=0
tmp=0
flag=0

for i in range(len(s)):
    if s[0]==s[i]:
        flag+=1
if flag==len(s):
    print(len(s)*k//2)
    quit()

for i in range(len(s)-1):
    if s[i]==s[i+1]:
        tmp+=1
    else:
        cnt+=(tmp+1)//2
        tmp=0
cnt+=(tmp+1)//2
hoka=0
# print(cnt)
left=0
right=0
if s[0]==s[-1]:
    for i in range(len(s)):
        if s[0]==s[i]:
            left+=1
        else:
            break
    for i in range(len(s)):
        if s[-1]==s[-1-i]:
            right+=1
        else:
            break
    if right==1 and left%2==1:
        hoka=1
    elif left==1 and right%2==1:
        hoka=1

print(cnt*k+hoka*(k-1))

Submission status: Wrong Answer

Solution code:
S=input()
K=int(input())
count=1
ans=0
old='old'
for x in S:
    if old==x:
        count+=1
    else:
        ans+=count//2
        count=1
    old=x

ans+=count//2
check=0
check+=ans

ans-=count//2

for x in S:
    if old==x:
        count+=1
    else:
        ans+=count//2
        count=1
#     print(count)
    old=x

ans+=count//2
if ans==check*2 and K!=1:
    print(check*K)
if ans==check*2+1 and K!=1:
    print(check*K+1)
if K==1:
    print(K)

Submission status: Wrong Answer

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

first = S[0]
ans = 0
pre = first

for i in S[1:]:
    if pre == i:
        ans += 1
        i = "1"
    pre = i
ans_e = 1 if first == pre else 0
print((ans+ans_e)*K - ans_e)

Submission status: Wrong Answer

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

if(len(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:
S = input()
K = int(input())
result = 0
if S[0] != S[-1]:
    t = None
    for i in range(len(S)):

        if i == 0:
            t = S[i]
            continue

        if t == S[i]:
            result += 1
            t = None
            continue

        t = S[i]

    print(result * K)
    exit()

else:
    t = None
    for i in range(len(S)):

        if i == 0:
            t = S[i]
            continue

        if t == S[i]:
            result += 1
            t = None
            continue

        t = S[i]

    count = 1
    t = S[0]
    for i in range(len(S)):
        if i == 0:
            continue

        if t == S[i]:
            count += 1
        else:
            break
    if count == len(S):
        result = len(S) // 2
        print(result * K)
        exit()

    for i in range(len(S)):
        if t == S[-i]:
            count += 1
        else:
            break

    print(result * K)