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 = str(input())
k = int(input())
 
tmp = s + s + s + s
 
c = [0]
for i in range(1, len(tmp)):
    if tmp[i] == tmp[i-1] and c[-1] == 0:
        c.append(1)
    else:
        c.append(0)
 
ans = 0
 
if k == 1:
    ans = sum(c[:len(s)])
elif k == 2:
    ans = sum(c[:2*len(s)])
    
print(ans)

Submission status: Wrong Answer

Solution code:
s = str(input())
k = int(input())
 
tmp = s + s + s + s
 
c = [0]
for i in range(1, len(tmp)):
    if tmp[i] == tmp[i-1] and c[-1] == 0:
        c.append(1)
    else:
        c.append(0)
 
ans = 0
 
if k == 1:
    ans = sum(c[:len(s)])
elif k == 2:
    ans = sum(c[:2*len(s)])

Submission status: Wrong Answer

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

c = []
tmp = 1
pre = s[0]
for si in s[1:]:
    if pre != si:
        c.append(tmp)
        pre = si
        tmp = 1
    else:
        tmp += 1
c.append(tmp)

if s[0] != s[-1] or len(c) == 1:
    ans = sum(ci // 2 for ci in c) * k
else:
    ans = c[0] // 2 + (sum((ci // 2 for ci in c[1:-1])) + (c[0] + c[-1]) // 2) * (k - 1) + sum((ci // 2 for ci in c[1:]))
print(ans)

Submission status: Wrong Answer

Solution code:
S_list = [s for s in input()]
S_double_list = S_list + S_list
K = int(input())
first_count = 0
second_count = 0
first_last_flag = 0
second_last_flag = 0
if len(S_list) % 2 == 1 and len(set(S_list)) == 1:
    print((len(S_list) * K) // 2)

elif K > 1:
    S_double_list.append(S_list[0])

    for idx, s in enumerate(S_double_list):
        if idx == len(S_double_list) - 1:
            break
        if S_double_list[idx + 1] == s:
            if idx < len(S_list):
                first_count += 1
                S_double_list[idx + 1] = "*"
                if idx == len(S_list) - 1:
                    first_last_flag = 1
            else:
                second_count += 1
                S_double_list[idx + 1] = "*"
                if idx == len(S_double_list) - 2:
                    second_last_flag = 1
    if K % 2 == 0 and second_last_flag == 1 :
        print(first_count * (K - (K // 2)) + second_count * ((K // 2)) - 1)
    elif K % 2 == 1 and first_last_flag == 1:
        print(first_count * (K - (K // 2)) + second_count * ((K // 2)) - 1)
    else:
        print(first_count * (K - (K // 2)) + second_count * ((K // 2)))

else:
    for idx, s in enumerate(S_list):
        if idx == len(S_list) - 1:
            break
        if S_list[idx + 1] == s:
            count += 1
            S_list[idx + 1] = "*"
    print(count * K)

Submission status: Wrong Answer

Solution code:
from sys import stdin
from itertools import groupby

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

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

li = []
point = 1
for i in range(len(s)-1):
    if s[i] == s[i+1]:
        point += 1
        if i == len(s)-2:
            li.append(point)
    else:
        li.append(point)
        point = 1
if s[-1] != s[-2]:
    li.append(1)

if s[0] != s[-1]:
    co = 0
    for j in range(len(li)):
        co += li[j]//2
    print(co*k)
    exit()

else:
    co = 0
    for i in range(1,-1):
        co += li[i]//2
    co *= k
    co += ((li[0]+li[-1])//2)+(k-1)
    co += li[0]//2
    co += li[-1]//2
    print(co)

Submission status: Wrong Answer

Solution code:
from sys import stdin
from itertools import groupby

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

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

li = []
point = 1
for i in range(len(s)-1):
    if s[i] == s[i+1]:
        point += 1
        if i == len(s)-2:
            li.append(point)
    else:
        li.append(point)
        point = 1
if s[-1] != s[-2]:
    li.append(1)

print(li)

if s[0] != s[-1]:
    co = 0
    for j in range(len(li)):
        co += li[j]//2
    print(co*k)
    exit()

else:
    co = 0
    for i in range(1,-1):
        co += li[i]//2
    co *= k
    co += ((li[0]+li[-1])//2)+(k-1)
    co += li[0]//2
    co += li[-1]//2

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

lens = len(s)

cnt = 0
ans = 0

# すべて同じ文字の場合
if s == s[0]*lens:
  ans = lens * k//2
else:
  i=0
  while i < lens-1:
    if s[i] == s[i+1]:
      cnt += 1
      i+=2
    else:
      i+=1

  ans = cnt * k

  # 最初と最後が同じ場合
  if s[0] == s[-1]:
    ans += k-1

print(ans)

Submission status: Wrong Answer

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

tmp = s + s + s + s

c = [0]
for i in range(1, len(tmp)):
    if tmp[i] == tmp[i-1] and c[-1] == 0:
        c.append(1)
    else:
        c.append(0)

ans = 0

if k == 1:
    ans = sum(c[:len(s)])
elif k == 2:
    ans = sum(c[:2*len(s)])
else:
    if k % 2 == 1:
        ans = sum(c[:len(s)]) + sum(c[len(s):3*len(s)]) * (k - 1) // 2
    else:
        ans = sum(c[:len(s)]) + sum(c[len(s):3*len(s)]) * (k - 1) // 2 + sum(c[3*len(s):])
print(ans)

Submission status: Wrong Answer

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

def main():
    S = input()
    K = int(input())
    N = len(S)-1
    tmp = 1
    ans = 0
    for i in range(N-1):
        if S[i] == S[i+1]:
            tmp += 1
        else:
            ans += tmp // 2 * K
            tmp = 1
    ans += tmp // 2 * K
    r = 1
    for i in range(N-1):
        if S[i] == S[i+1]:
            r += 1
        else:
            break
    l = 1
    for i in range(N-1):
        if S[-i-2] == S[-i-3]:
            l += 1
        else:
            break
    tmp = r + l
    if S[0] == S[-2] and tmp != 2*N:
        ans -= l // 2 * (K-1)
        ans -= r // 2 * (K-1)
        ans += tmp // 2 * (K-1)
    print(ans)

if __name__ == '__main__': main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

def main():
    S = input()
    K = int(input())
    N = len(S)-1
    tmp = 1
    ans = 0
    for i in range(N-1):
        if S[i] == S[i+1]:
            tmp += 1
        else:
            ans += tmp // 2 * K
            tmp = 1
    ans += tmp // 2 * K
    r = 1
    for i in range(N-1):
        if S[i] == S[i+1]:
            r += 1
        else:
            break
    l = 1
    for i in range(N-1):
        if S[-i-2] == S[-i-3]:
            l += 1
        else:
            break
    tmp = r + l
    if S[0] == S[-2] and tmp != 2*N:
        if l >= 2:
            ans -= l // 2 * (K-1)
        if r >= 2:
            ans -= r // 2 * (K-1)
        ans += tmp // 2 * (K-1)
    print(ans)

if __name__ == '__main__': main()

Submission status: Wrong Answer

Solution code:
import math
import copy

s = list(input())
orig_s = copy.copy(s)
k = int(input())
# 隣り合う文字列を置換した回数をカウント
cnt = 0
for i in range(len(s) - 1):
  # 末尾1文字前まで
  if s[i] == s[i + 1]:
    s[i + 1] = "0" + str(i)
    cnt += 1

cnt = cnt * k
if len(s[-1]) == 1:
  if len(s) == 1:
    cnt += math.floor(k / 2)
  elif s[0] == s[-1]:
    cont_count = 0
    for j in range(len(orig_s)-1):
      if orig_s[j] == orig_s[j + 1]:
        cont_count += 1
      else:
        break
    # 先頭2n文字続きで置換されていたらこれ要らないよね
    if cont_count % 2 == 0:
      cnt += k - 1
    
print(cnt)

Submission status: Wrong Answer

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

ans=0
for i in range(len(s)):
	if i<(len(s)-1):
		if s[i]==s[i+1]:
			ans+=1
			s[i+1]="?"
	else:
		if s[0]==s[i]:
			ans+=1
print(ans*k)

Submission status: Wrong Answer

Solution code:
S_list = [s for s in input()]
S_double_list = S_list + S_list
K = int(input())
first_count = 0
second_count = 0
if len(S_list) % 2 == 1 and len(set(S_list)) == 1:
    print((len(S_list) * K) // 2)

elif K > 1:
    S_double_list.append(S_list[0])

    for idx, s in enumerate(S_double_list):
        if idx == len(S_double_list) - 1:
            break
        if S_double_list[idx + 1] == s:
            if idx < len(S_list):
                first_count += 1
                S_double_list[idx + 1] = "*"
            else:
                second_count += 1
                S_double_list[idx + 1] = "*"

    print(first_count * (K - (K // 2)) + second_count * ((K // 2)))

else:
    for idx, s in enumerate(S_list):
        if idx == len(S_list) - 1:
            break
        if S_list[idx + 1] == s:
            count += 1
            S_list[idx + 1] = "*"
    print(count * K)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

lens = len(s)

cnt = 0
ans = 0

i=0
while i < lens-1:
  if s[i] == s[i+1]:
    cnt += 1
    i+=2
  else:
    i+=1

ans = cnt * k

# 最初と最後が同じ場合
if lens > 1 and s[-1] != s[-2] and s[0] != s[1] and s[0] == s[-1]:
  ans += k-1

# すべて同じ文字の場合
if s == s[0]*lens:
  ans = lens * k//2

print(ans)

Submission status: Wrong Answer

Solution code:
import copy

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

def Scount():
    cnt_S = 0
    for i in range(len(S)-1):
        if S[i] == S[i+1]:
            S[i+1] = "1"
            cnt_S += 1
    return cnt_S

T = copy.copy(S)
T.insert(0, T[len(T)-1])
cnt_T = 0
for i in range(len(T)-1):
    if T[i] == T[i+1]:
        T[i+1] = "1"
        cnt_T += 1

if T[i+1] != "1":
    ans = Scount() + (cnt_T * (K-1))
else:
    TT = S * 2
    cnt_T = 0
    for i in range(len(TT)-1):
        if TT[i] == TT[i+1]:
            TT[i+1] = "1"
            cnt_T += 1
    if K % 2 == 0:
        ans = cnt_T * K / 2
    else:
        ans = (cnt_T * K // 2) + Scount()
    
print(ans)

Submission status: Wrong Answer

Solution code:
from itertools import groupby

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

a = [sum(1 for _ in g) for _, g in groupby(s)]

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

print(ans*k)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
 
s = input().rstrip()
k = int(input())
    
def check_count(s):
    cnt_list = [1]
    cnt = 1
    for i in range(1, len(s)):
        if s[i-1] == s[i]:
            cnt_list[-1] += 1
        else:
            cnt_list.append(1)
    return cnt_list

def calc_ans(cnt_list, k):
    _ans = 0
    for c in cnt_list:
        _ans += c//2
    return(_ans * k)

if len(s)==1:
    ans = k//2
else:
    cnt_list = check_count(s)
    if len(cnt_list)==1:
        ans = (len(s)*k)//2
    else:
        ans = calc_ans(cnt_list, k)
        if s[0]==s[-1]:
            if cnt_list[0]%2==1 and cnt_list[-1]%2==1:
                ans = k - 1

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

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

li = []
point = 1
for i in range(len(s)-1):
    if s[i] == s[i+1]:
        point += 1
        if i == len(s)-2:
            li.append(point)
    else:
        li.append(point)
        point = 1
if s[-1] != s[-2]:
    li.append(1)

if s[0] != s[-1]:
    co = 0
    for j in range(len(li)):
        co += li[j]//2
    print(co*k)
    exit()

else:
    co = 0
    for k in range(1,-1):
        co += li[j]//2
    co = co*k
    co += (li[0]+li[-1])*(k-1)//2
    co += li[0]//2
    co += li[-1]//2
    print(co)

Submission status: Wrong Answer

Solution code:
from itertools import groupby

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

a = [sum(1 for _ in g) for _, g in groupby(s)]
print(a)

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

print(ans*k)

Submission status: Wrong Answer

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

lens = len(s)

cnt = 0
ans = 0

i=0
while i < lens-1:
  if s[i] == s[i+1]:
    cnt += 1
    i+=2
  else:
    i+=1

ans = cnt * k

# 最初と最後が同じ場合
if lens > 1 and s[-1] != s[-2] and s[0] == s[-1]:
  ans += k-1

# すべて同じ文字の場合
if s == s[0]*lens:
  ans = lens * k//2

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
 
s = input().rstrip()
k = int(input())

def check_count(s):
    cnt_list = []
    cnt = 1
    for i in range(1, len(s)):
        if s[i-1] == s[i]:
            cnt += 1
        else:
            cnt_list.append(cnt)
            cnt = 1
    if cnt>1:
        cnt_list.append(cnt)
    return cnt_list

def calc_ans(cnt_list, k):
    _ans = 0
    for c in cnt_list:
        _ans += c//2
    return(_ans * k)

if len(s)==1:
    ans = k//2
else:
    cnt_list = check_count(s)
    if len(cnt_list)==1:
        ans = (len(s)*k)//2
    else:
        ans = calc_ans(cnt_list, k)
        if s[0]==s[-1]:
            if cnt_list[0]%2==1 and cnt_list[-1]%2==1:
                ans = k - 1

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

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

li = []
point = 1
for i in range(len(s)-1):
    if s[i] == s[i+1]:
        point += 1
        if i == len(s)-2:
            li.append(point)
    else:
        li.append(point)
        point = 1
if s[-1] != s[-2]:
    li.append(1)

if s[0] != s[-1]:
    co = 0
    for j in range(len(li)):
        co += li[j]//2
    print(co*k)
    exit()

else:
    co = 0
    for k in range(1,-1):
        co += li[j]//2
    co += (li[0]+li[-1])*(k-1)//2
    co += li[0]//2
    co += li[-1]//2
    print(co)

Submission status: Wrong Answer

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

end_str=ls[-1]
divide_idx=0
for i in range(len(ls)-1,0,-1):
    if ls[i]!=end_str:
        divide_idx=i+1
        break
#print(divide_idx)
#print(ls[divide_idx:])
#print(ls[:divide_idx])

start_ls=ls[:divide_idx]
middle_ls=ls[divide_idx:]+ls[:divide_idx]
end_ls=ls[divide_idx:]

#print(start_ls,middle_ls,end_ls)

def get_count(req_list):
    ls=req_list[:]
    count=0
    for i in range(len(ls)-1):
        a,b=ls[i],ls[i+1]
        if a==b:
            ls[i+1]='!'
            count+=1
    return count

start_counts=get_count(start_ls)
middle_counts=get_count(middle_ls)*(n-1)
end_counts=get_count(end_ls)
#print(start_counts,middle_counts,end_counts)
if len(ls)==1:
    print(n//2)
else:
    print(start_counts+middle_counts+end_counts)

Submission status: Wrong Answer

Solution code:
from collections import Counter
def main():
    s = input()
    k = int(input())
    li = []
    num = 1
    if len(s) == 1:
        li.append(1)
    for i in range(len(s)-1):
        if s[i] != s[i+1]:
            li.append(num)
            num = 1
        else:
            num += 1
    li.append(num)
    temp = 0
    ans = 0
    if len(list((Counter(li).keys()))) == 1:
        ans += len(s) * k // 2
    else:
        for i in li:
            temp += i//2
        if s[0] != s[-1]:
            ans = temp * k
        else:
            li[0] += li[-1]
            for i in li[:-1]:
                ans += i//2
            ans = ans * (k-1) + temp
    print(ans)

main()

Submission status: Wrong Answer

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

c = []
tmp = 1
pre = s[0]
for si in s[1:]:
    if pre != si:
        c.append(tmp)
        pre = si
        tmp = 1
    else:
        tmp += 1
c.append(tmp)
ans = sum(ci // 2 for ci in c) * k
if s[0] == s[-1] and len(c) > 2:
    if c[-1] % 2 == 1 and c[0] % 2 == 0:
        ans += k - 1
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

pre_c = ''
flg = 0
count = 1

f_c = S[0]
f_e = S[-1]
t = []

for c in S:
  if c == pre_c:
    count += 1
  elif pre_c == '':
    pass
  else:
    t.append(count)
    count = 1
  pre_c = c

t.append(count)
count_1 = 0
for i in t:
  count_1 += i // 2
  
if f_c == f_e:
  if len(t) != 1:
    t[0] = t[0] + t[-1]
    t.pop(-1)
  else:
    t[0] += 1

count_2 = 0
for i in t:
  count_2 += i // 2
  
if len(S) == 1:
  print(K // 2)
else:
  print(count_1 + count_2 * (K - 1))

Submission status: Wrong Answer

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

c = []
tmp = 1
pre = s[0]
for si in s[1:]:
    if pre != si:
        c.append(tmp)
        pre = si
        tmp = 1
    else:
        tmp += 1
c.append(tmp)
ans = sum(ci // 2 for ci in c)
if s[0] == s[-1] and len(c) > 2:
    if c[-1] % 2 == 1 and c[0] % 2 == 0:
        ans += 1
print(ans * k)

Submission status: Wrong Answer

Solution code:
S = input()
K = int(input())
prev = ''
new = ''
cnt = 0
for c in S:
    if prev == c:
        cnt += 1
        new += '0'
        prev = '0'
    else:
        new += c
        prev = c
cnt *= K
if new[0] == new[-1]:
    cnt += K - 1
print(cnt)

Submission status: Wrong Answer

Solution code:
s = list(input())
k = int(input())
cnt = 0
lenS = len(s)
ans = 0
if lenS == 1:
    ans = int(k//2)
elif lenS == s.count(s[0]):
    ans = (lenS * k // 2)
else:
    for i in range(0, lenS - 1):
        if s[i] == s[i + 1]:
            s[i + 1] = "1"
            ans += 1
    ans *= k
    if s[0] == s[lenS-1]:
        ans += k
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
def main():
    s = input()
    k = int(input())
    li = []
    num = 1
    for i in range(len(s)-1):
        if s[i] != s[i+1]:
            li.append(num)
            num = 1
        else:
            num += 1
    li.append(num)
    temp = 0
    ans = 0
    if len(list((Counter(li).keys()))) == 1:
        ans += len(s) * k // 2
    else:
        for i in li:
            temp += i//2
        if s[0] != s[-1]:
            ans = temp * k
        else:
            li[0] += li[-1]
            for i in li[:-1]:
                ans += i//2
            ans = ans * (k-1) + temp
    print(ans)

main()

Submission status: Wrong Answer

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

pre_c = ''
flg = 0
count = 1

f_c = S[0]
f_e = S[-1]
t = []

for c in S:
  if c == pre_c:
    count += 1
  elif pre_c == '':
    pass
  else:
    t.append(count)
    count = 1
  pre_c = c

t.append(count)
count_1 = 0
for i in t:
  count_1 += i // 2
  
if f_c == f_e:
  if len(t) != 1:
    t[0] = t[0] + t[-1]
    t.pop(-1)
  else:
    t[0] += 1

count_2 = 0
for i in t:
  count_2 += i // 2

print(count_1 + count_2 * (K - 1))

Submission status: Wrong Answer

Solution code:
s = list(input())
k = int(input())
cnt = 0
lenS = len(s)
ans = 0
if lenS == 1:
    ans = int(k//2)
elif lenS == s.count(s[0]):
    ans = (lenS * k // 2)
else:
    for i in range(0, lenS - 1):
        if s[i] == s[i + 1]:
            s[i + 1] = "1"
            ans += 1
    ans *= k
    # if s[0] == s[lenS-1]:
    #     ans += k - 1
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
 
s = input().rstrip()
k = int(input())

def check_count(s):
    cnt_list = []
    cnt = 1
    for i in range(1, len(s)):
        if s[i-1] == s[i]:
            cnt += 1
        else:
            cnt_list.append(cnt)
            cnt = 1
    cnt_list.append(cnt)
    return cnt_list

def calc_ans(cnt_list, k):
    _ans = 0
    for c in cnt_list:
        _ans += c//2
    return(_ans * k)

if len(s)==1:
    ans = k//2
else:
    cnt_list = check_count(s)
    if len(cnt_list)==1:
        ans = len(s)*k // 2
    else:
        ans = calc_ans(cnt_list, k)
        if s[0]==s[-1]:
            if cnt_list[0]%2==1 and cnt_list[-1]%2==1:
                ans = k - 1

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

l = len(s)
flag = 0
for i in range(1,l):
    if(s[i]!=s[i-1]):
        flag=1


flag2 = 0
cnt = 0

if(flag==0):
    a = (l*k)//2
    print(a)
else:
    if(l==1):
        print(k//2)
    else:
        i=1
        while(i<l):
            if((s[i]==s[i-1])):
                cnt+=1
                i+=2
            else:
                i+=1
        
        if(s[0]==s[l-1] and s[l-1]==s[l-2] and s[0]==s[1]):
            flag2=1

        print(flag2)
        if(flag2==1):
            if(k==1):
                print(cnt)
            else:
                print(cnt*k+k-1)
        else:
            print(cnt*k)

Submission status: Wrong Answer

Solution code:
s = list(input())
k = int(input())
cnt = 0
lenS = len(s)
ans = 0
if lenS == 1:
    ans = int(k//2)
elif lenS == s.count(s[0]):
    ans = (lenS * k // 2)
else:
    for i in range(0, lenS - 1):
        if s[i] == s[i + 1]:
            s[i + 1] = "1"
            ans += 1
    ans *= k
    if s[0] == s[lenS-1]:
        ans += k - 1
print(ans)

Submission status: Wrong Answer

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

def Scount():
    cnt_S = 0
    for i in range(len(S)-1):
        if S[i] == S[i+1]:
            S[i+1] == "1"
            cnt_S += 1
    return cnt_S

T = S
T.insert(0, T[len(T)-1])
cnt_T = 0
for i in range(len(T)-1):
    if T[i] == T[i+1]:
        T[i+1] == "1"
        cnt_T += 1

if T[i+1] != "1":
    ans = Scount() + (cnt_T * (K-1))
else:
    T = S * 2
    cnt_T = 0
    for i in range(len(T)-1):
        if T[i] == T[i+1]:
            T[i+1] == "1"
            cnt_T += 1
    if K % 2 == 0:
        ans = cnt_T * K / 2
    else:
        ans = (cnt_T * K // 2) + Scount()

print(ans)

Submission status: Wrong Answer

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

l = len(s)
flag = 0
for i in range(1,l):
    if(s[i]!=s[i-1]):
        flag=1


flag2 = 0
cnt = 0

if(flag==0):
    a = (l*k)//2
    print(a)
else:
    if(l==1):
        print(k//2)
    else:
        i=1
        while(i<l):
            if((s[i]==s[i-1])):
                cnt+=1
                i+=2
            else:
                i+=1
        
        if(s[0]==s[l-1] and s[l-1]!=s[l-2] and s[0]!=s[1]):
            flag2=1

        if(flag2==1):
            if(k==1):
                print(cnt)
            else:
                print(cnt*k+k-1)
        else:
            print(cnt*k)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
s=input()
k=int(input())
chain_hajime=0
chain_owa=0
for i in range(len(s)):
    if s[0]==s[i]:
        chain_hajime+=1
    else: break
for i in range(len(s)):
    if s[-1]==s[-(i+1)]:
        chain_owa+=1
    else: break
print(chain_hajime)
#print(chain_owa)
import re
def nchars(s, n):
    """文字列 s に、同じ文字が n 個以上連続している部分文字列を見つける
    """

    assert n > 0
    reg = re.compile("(.)\\1{%d,}" % (n - 1))  # カンマを取ると n 個ちょうどになる
    while True:
        m = reg.search(s)
        if not m:
            break
        yield m.group(0)
        s = s[m.end():]
a=list(nchars(s, 2))
b=0
for i in a:
    b+=len(i)//2


if len(set(s))==1:
    print(len(s)*k//2)
elif s[0]!=s[-1]:
    print(b*k)
else:
    print(b*k-(chain_hajime//2+chain_owa//2-(chain_hajime+chain_owa)//2)*(k-1))

Submission status: Wrong Answer

Solution code:
def main():
    S = input()
    K = int(input())
    a = list(S)
    cnt = 0
    if len(set(a))==1:
        cnt = (len(a)*K)//2
        print(cnt)
    else:
        temp = 1
        temp_2 = 1
        i = 0
        while a[i] == a[i+1]:
            temp += 1
            i += 1
        j = len(a) - 1
        while a[j] == a[j-1]:
            temp_2 += 1
            j -= 1
        for k in range(i+1,j-1):
            if a[k+1] == a[k]:
                a[k+1] = str(k)
                cnt += 1
        cnt *= K
        cnt += temp//2
        cnt += temp_2//2
        
        if a[0] == a[-1]:
            temp_3 = (temp + temp_2)//2
            cnt += temp_3 * (K-1)

        print(cnt)

    
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
 
s = input().rstrip()
k = int(input())

def check_count(s):
    pre_s = None
    cnt_list = []
    cnt = 1
    for _s in s:
        if pre_s == _s:
            cnt += 1
        else:
            cnt_list.append(cnt)
            cnt = 1
        # print(pre_s, _s, cnt, cnt_list)
        pre_s = _s    
    cnt_list.append(cnt)
    if len(cnt_list)==0:
        cnt_list.append(cnt)
    return cnt_list

def calc_ans(cnt_list, k):
    _ans = 0
    for c in cnt_list:
        _ans += c//2
    return(_ans * k)

if len(s)==1:
    ans = k//2
else:
    cnt_list = check_count(s)
    ans = calc_ans(cnt_list, k)
    if s[0]==s[-1]:
        if cnt_list[0]%2==1 and cnt_list[-1]%2==1:
            ans += k - 1

print(ans)

Submission status: Wrong Answer

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

l = len(s)
flag = 0
for i in range(1,l):
    if(s[i]!=s[i-1]):
        flag=1


flag2 = 0
cnt = 0

if(flag==0 and l%2==1):
    a = (l*k)//2
    print(a)
else:
    if(l==1):
        print(k//2)
    else:
        i=1
        while(i<l):
            if((s[i]==s[i-1])):
                cnt+=1
                i+=2
            else:
                i+=1
        
        if(s[0]==s[l-1] and s[l-1]!=s[l-2] and s[0]!=s[1]):
            flag2=1


        if(flag2==1):
            if(k==1):
                print(cnt)
            else:
                print(cnt*k+k-1)
        else:
            print(cnt*k)

Submission status: Wrong Answer

Solution code:
S = list(input())
K = int(input())
A = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
num = 0
TTL_num = 0
first = 0

if len(S)==1:
	num += 1
	first += 1
elif len(S)==2:
	if S[0] == S[1]:
		num += 1
else:
	for i in range(len(S)):
		if i <= (len(S)-2):
			if S[i] == S[i+1]:
				if i <= (len(S)-3):
					for j in range(len(A)):
						if S[i] != A[j] and S[i+2] != A[j]:
							S[i+1] = A[j]
							num += 1
							break
				elif i == (len(S)-2):
					for k in range(len(A)):
						if S[i] != A[k] and S[0] != A[k]:
							S[i+1] = A[k]
							num += 1
							break
		elif S[len(S)-1] == S[0]:
			for l in range(len(A)):
				if S[0] != A[l]:
					num += 1
					first += 1
					break

if first == 1:
	TTL_num = num*K -1
else:
	TTL_num = num*K

print(TTL_num)

Submission status: Wrong Answer

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

l = len(s)
flag = 0
for i in range(1,l):
    if(s[i]!=s[i-1]):
        flag=1


flag2 = 0
cnt = 0

if(flag==0 and l%2==1):
    a = (l*k)//2
    print(a)
else:
    if(l==1):
        print(k//2)
    else:
        i=1
        while(i<l):
            if((s[i]==s[i-1])):
                cnt+=1
                i+=2
            else:
                i+=1
        
        if(s[0]==s[l-1] and s[l-1]!=s[l-2] and s[0]!=s[1]):
            flag=1


        if(flag2==1):
            if(k==1):
                print(cnt)
            else:
                print(cnt*k+k)
        else:
            print(cnt*k)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
S = list(input())
K = int(input())
A = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
num = 0
TTL_num = 0
first = 0

if len(S)==1:
	num += 1
	first += 1
elif len(S)==2:
	if S[0] == S[1]:
		num += 1
else:
	for i in range(len(S)):
		if i <= (len(S)-2):
			if S[i] == S[i+1]:
				if i <= (len(S)-3):
					for j in range(len(A)):
						if S[i] != A[j] and S[i+2] != A[j]:
							S[i+1] = A[j]
							num += 1
							break
				elif i == (len(S)-2):
					for k in range(len(A)):
						if S[i] != A[k] and S[0] != A[k]:
							S[i+1] = A[k]
							num += 1
							break
		elif S[len(S)-1] == S[0]:
			for l in range(len(A)):
				if S[0] != A[l]:
					num += 1
					first += 1
					break

if first == 1:
	TTL_num = num*K -1
	print(S)
else:
	TTL_num = num*K
	print(S)

print(TTL_num)

Submission status: Wrong Answer

Solution code:
from itertools import groupby

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

A = [len(tuple(v)) for _, v in groupby(S)]
if len(A) == 1:
    print((A[0] * K) // 2)
    quit()

t = sum(a // 2 for a in A) * K
if S[0] == S[-1]:
    l, r = A[0], A[-1]
    m = l // 2 + r // 2 - (l + r) // 2
    print(t - m * K)
else:
    print(t)

Submission status: Wrong Answer

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

if S[0] != S[-1] :
    a = 0
    c = 1
    for i in range(len(S)) :
        if S[i] == S[i-1] :
            c += 1
        else :
            a += c//2
            c = 1
    print(a*N)