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())
R = int(input())
lengths = []
same = False
All = False
odd = False
sl = 1
Sum = 0
if S[0] == S[len(S)-1]:
  same = True
S.append('0')
for i in range(len(S)-1):
  if S[i] == S[i+1]:
    sl += 1
  else:
    lengths.append(sl)
    sl = 1
if len(lengths) == 1:
  All = True
if lengths[0]%2 == 1 and lengths[len(lengths)-1]%2 == 1:
  odd = True
if same:
  if All:
    Sum += (lengths[0]*R)//2
  else:
    temp = lengths[0]
    lengths[0] = 0
    lengths[len(lengths)-1] += temp
    if odd:
      for k in range(len(lengths)):
        Sum += (lengths[k]//2)*R
        Sum -= 1
    else:
      for g in range(len(lengths)):
        Sum += (lengths[g]//2)*R
else:
  for j in range(len(lengths)):
    Sum += (lengths[j]//2)*R
print(Sum)

Submission status: Wrong Answer

Solution code:
S = list(input())
R = int(input())
lengths = []
same = False
All = False
odd = False
sl = 1
Sum = 0
if S[0] == S[len(S)-1]:
  same = True
S.append('0')
for i in range(len(S)-1):
  if S[i] == S[i+1]:
    sl += 1
  else:
    lengths.append(sl)
    sl = 1
if len(lengths) == 1:
  All = True
if lengths[0]%2 == 0 and lengths[len(lengths)-1]%2 == 0:
  odd = True
if same:
  if All:
    Sum += (lengths[0]*R)//2
  else:
    temp = lengths[0]
    lengths[0] = 0
    lengths[len(lengths)-1] += temp
    if odd:
      for g in range(len(lengths)):
        Sum += (lengths[j]//2)*R - 1
    else:
      for k in range(len(lengths)):
        Sum += (lengths[k]//2)*R - 1
else:
  for j in range(len(lengths)):
    Sum += (lengths[j]//2)*R
print(Sum)

Submission status: Wrong Answer

Solution code:
import re
s = input()
k = int(input())
if len(s)==1:
    print(k//2)
else:
    ss = re.findall(r"(.)\1",s,re.S)
    print(len(ss)*k)

Submission status: Wrong Answer

Solution code:
# 2019/12/12

s=list(input())
k=int(input())
n=len(s)
cnt=0
for i in range(n-1):
    if s[i]==s[i+1]:
        s[i+1]='@'
        cnt+=1
cnt*=k
print(cnt)

Submission status: Wrong Answer

Solution code:
# 2019/12/12

s=list(input())
k=int(input())
n=len(s)
cnt=0
for i in range(1,n):
    if s[i-1]==s[i]:
        s[i]='@'
        cnt+=1
cnt*=k
if s[0]==s[-1]:
    cnt+=(k-1)
print(cnt)

Submission status: Wrong Answer

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

ret = 0
for i in range(1, len(S)) :
    if S[i] == S[i-1] :
        ret += 1
        S[i] = '#'

ret *= K
if S[0] == S[-1] :
    ret += K - 1
    
print(ret)

Submission status: Wrong Answer

Solution code:
s = list(input())
k = int(input())
tmp = 0
cnt = 0
for i in range(len(s)-1):
    if s[i] == s[i+1]:
        s[i+1] = "0"
        tmp += 1
if s[-1] == s[0]:
    #print(s[len(s)-1])
    cnt += 1
#print("".join(s))
ans = tmp * k + cnt *(k)
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

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

    if s[0] == s[-1]:
        ans = li[0]//2 + li[-1]//2
        ans += ((li.pop(0) + li.pop())//2) * (k-1)

    ans = 0
    for i in li:
        ans += (i//2)*k
    print(ans)






if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import math
S = input()
K = int(input())
cnt = 1
ans = 0
for i in range(len(S)-1):
  if S[i] == S[i+1]:
    cnt += 1
  else:
    ans += math.floor(cnt/2)
    cnt = 1
  if i == len(S)-2:
    if cnt > 1:
      if cnt%2 == 0:    
        ans += math.floor(cnt/2)
      elif cnt%2!=0 and S[0] == S[-1]:
        ans += math.floor(cnt/2)+1
    else:
      if S[0]==S[-1]:
        ans += 1
print(math.ceil(ans)*K)

Submission status: Wrong Answer

Solution code:
import math
S = input()
K = int(input())
cnt = 1
ans = 0
for i in range(len(S)-1):
  if S[i] == S[i+1]:
    cnt += 1
  else:
    ans += math.floor(cnt/2)
    cnt = 1
  if i == len(S)-2 and cnt > 1:
    ans += math.floor(cnt/2)
print(math.ceil(ans)*K)

Submission status: Wrong Answer

Solution code:
import math
S = input()
K = int(input())
cnt = 0
ans = 0
for i in range(len(S)-1):
  if S[i] == S[i+1]:
    cnt += 1
  else:
    ans += math.ceil(cnt/2)
    cnt = 0
  if i == len(S)-2 and cnt > 0:
    ans += math.ceil(cnt/2)
print(math.ceil(ans)*K)

Submission status: Wrong Answer

Solution code:
import math
S = input()
K = int(input())
cnt = 0
ans = 0
for i in range(len(S)-1):
  if S[i] == S[i+1]:
    cnt += 1
  else:
    ans += math.ceil(cnt/2)
    cnt = 0
ans += cnt
print(math.ceil(ans)*K)

Submission status: Wrong Answer

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

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

while S[0]==S[-1]:
  S=S[1:]+S[:1]

import itertools
ans_in_s=0
for key,g in itertools.groupby(S):
  length=len(list(g))
  ans_in_s+=length//2
print(ans_in_s*K)

Submission status: Wrong Answer

Solution code:
s=str(input())
k=int(input())
li=[1]
ans=0
for i in range(1,len(s)):
    if s[i]==s[i-1]:
        li[-1]+=1
    else:
        li.append(1)

for j in range(len(li)):
    ans+=int(li[j]//2)*k

if s[0]==s[-1] and li[0]%2==li[-1]%2==1:
    ans+=k-1

print(ans)

Submission status: Wrong Answer

Solution code:
s=str(input())
k=int(input())
x=s[0]
y=s[-1]
cnt=0
for i in range(1,len(s)):
    if s[i]==x:
        x="0"
        cnt+=1   
    else:
        x=s[i]


if cnt==int(len(s)//2):
    print(int(len(s)*k//2))      
elif s[0]==y and x==y:
    print((cnt*k)+k-1)
else:
    print(cnt*k)

Submission status: Wrong Answer

Solution code:
s=str(input())
k=int(input())
x=s[0]
y=s[-1]
cnt=0
for i in range(1,len(s)):
    if s[i]==x:
        x="0"
        cnt+=1   
    else:
        x=s[i]


if cnt==int(len(s)//2):
    print(int(len(s)*k//2))      
elif s[0]==y and x==y:
    print((cnt*k)+k-1)
else:
    (cnt*k)

Submission status: Wrong Answer

Solution code:
s=str(input())
k=int(input())
x=s[0]
y=s[-1]
cnt=0
for i in range(1,len(s)):
    if s[i]==x:
        x="0"
        cnt+=1   
    else:
        x=s[i]
        
if s[0]==y:
    if x!=y:
        print(cnt*k)
    else:
        print((cnt*k)+k-1)
else:
  print(cnt*k)

Submission status: Wrong Answer

Solution code:
s=str(input())
k=int(input())
x=s[0]
cnt=0
for i in range(1,len(s)):
    if s[i]==x:
        x="0"
        cnt+=1   
    else:
        x=s[i]
if s[0]==s[len(s)-1] and s[0]!=x:
    print((cnt*k)+k-1)
else:
    print(cnt*k)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

tmp = '0'
count = 0
for x in s:
	if tmp == x:
		count += 1
		tmp = '0'
	else:
		tmp = x
if tmp == s[0]:
	start_count = 0
	for x in s:
		if tmp != x:
			break
		start_count += 1
	print((count+start_count%2)*k-start_count%2)
else:
	print(count*k)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
S = input()
K = int(input())
l = [0]
tmp = 0
for i in range(len(S)-1):
    if S[i] == S[i+1]:
        # l.append(tmp + 1)
        tmp += 1
    else:
        if tmp > 0:
            l.append(tmp+1)
        tmp = 0
if tmp != 0:
    l.append(tmp+1)
ans = 0
ans += l[-1]//2
if S[0] == S[-1]:
    l[-1] += 1
for i in range(1, len(l)-1):
    ans += l[i]//2 * K
# print(ans)
ans += l[-1]//2 * (K-1)
# print(l)
print(ans)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
S = input()
K = int(input())
l = [0]
tmp = 0
for i in range(len(S)-1):
    if S[i] == S[i+1]:
        # l.append(tmp + 1)
        tmp += 1
    else:
        if tmp > 1:
            l.append(tmp+1)
        tmp = 0
ans = 0
ans += l[-1]//2
if S[0] == S[-1]:
    l[-1] += 1
for i in range(1, len(l)-1):
    ans += l[i]//2 * K
# print(ans)
ans += l[-1]//2 * (K-1)
# print(l)
print(ans)

Submission status: Wrong Answer

Solution code:
s=input()
n=int(input())
my_bool=True
cnt=0
if len(s)==1:
    print(n//2)
    exit()
if len(set(s))==1:
    print((len(s)*n)//2)
    exit()
for i in range(1,len(s)):
    if my_bool:
        if s[i-1]==s[i]:
            cnt+=1
            my_bool=False
    else:
        my_bool=True
        continue
if my_bool:
    if not s[-1]==s[-2] and s[0]==s[-1]:
        cnt+=1
print(cnt*n)

Submission status: Wrong Answer

Solution code:
s=input()
n=int(input())
my_bool=True
cnt=0
if len(s)==1:
    print(n//2)
    exit()
for i in range(1,len(s)):
    if my_bool:
        if s[i-1]==s[i]:
            cnt+=1
            my_bool=False
    else:
        my_bool=True
        continue
if my_bool:
    if not s[-1]==s[-2] and s[0]==s[-1]:
        cnt+=1
print(cnt*n)

Submission status: Wrong Answer

Solution code:
s=input()
n=int(input())
my_bool=True
cnt=0
for i in range(1,len(s)):
    if my_bool:
        if s[i-1]==s[i]:
            cnt+=1
            my_bool=False
    else:
        my_bool=True
        continue
if my_bool:
    if s[0]==s[-1]:
        cnt+=1
print(cnt*n)

Submission status: Wrong Answer

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

changed = [False for _ in range(len(S))]
res = 0
i = 0
while i < len(S) - 1:
    if S[i] == S[i + 1]:
        changed[i + 1] = True
        res += 1
        i += 1
    i += 1

res *= K
if K > 0 and S[0] == S[-1] and not changed[-1]:
    res += K - 1
print(res)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
S=list(input())
K=int(input())

flag=True
for i in range(len(S)-1):
    if S[i+1]!=S[i]:
        flag=False
        break

if flag and K>1:
    S*=2
    for i in range(len(S)-1):
        if S[i+1]==S[i]:
            S[i+1]="?"
    temp=S.count("?")
    print(K//2*temp+temp//2)
    exit()

if K==1:
    for i in range(len(S)-1):
        if S[i+1]==S[i]:
            S[i+1]="?"
    print(S.count("?"))
    exit()

n=len(S)
S*=4
N=len(S)-1

for i in range(N):
    if S[i+1]==S[i]:
        S[i+1]="?"

l=[S[:n],S[n:2*n],S[2*n:3*n],S[3*n:]]

ans=[0]*4
for i in range(4):
    ans[i]=l[i].count("?")

print(ans[0]+ans[3]+ans[1]*(-(-(K-2)//2))+ans[2]*((K-2)//2))

#qqq 5

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
S=list(input())
K=int(input())

if K==1:
    for i in range(len(S)-1):
        if S[i+1]==S[i]:
            S[i+1]="?"
    print(S.count("?"))
    exit()

n=len(S)
S*=4
N=len(S)-1

for i in range(N):
    if S[i+1]==S[i]:
        S[i+1]="?"

l=[S[:n],S[n:2*n],S[2*n:3*n],S[3*n:]]

ans=[0]*4
for i in range(4):
    ans[i]=l[i].count("?")

print(ans[0]+ans[3]+ans[1]*(-(-(K-2)//2))+ans[2]*((K-2)//2))

Submission status: Wrong Answer

Solution code:
# 先頭と末尾が同じ場合はそれを省き、単体で完結するもの*K + 先頭と末尾が同じ場合の連結部分 * (K-1)
# ただし全部同じ場合は別で計算
# 3WA出した後にtestcase: aaaeiiiaiaa でやって気づいた
from math import floor

s = input()
k = int(input())
if len(set(list(s))) == 1:
    print(floor((len(s) * k) / 2))
    exit()

if s[0] == s[-1]:
    # このへんの算数は手書きでいくつか書いて帰納的に導出した
    # だるいしs<=100なので愚直に数えるわ
    pre, suf = 0, 0
    for c in s:
        if c == s[0]:
            pre += 1
        else:
            break
    for c in s[::-1]:
        if c == s[-1]:
            suf += 1
        else:
            break
    # 先頭と末尾の連続する文字を除いたやつのうち連続するやつからいらないやつを数える
    idx = 0
    cc = 0
    t = s[pre : len(s) - suf]
    while idx < len(t):
        c = 0
        tmp = idx
        while tmp < len(t) and t[tmp] == t[idx]:
            tmp += 1
            c += 1
        if c > 1:
            cc += floor(c / 2)
        idx = tmp
    ans = floor(pre / 2) + cc * k + floor((pre + suf) / 2) + floor(suf / 2)
    print(ans)
else:
    idx = 0
    cc = 0
    t = s[:]
    while idx < len(t):
        c = 0
        tmp = idx
        while tmp < len(t) and t[tmp] == t[idx]:
            tmp += 1
            c += 1
        if c > 1:
            cc += floor(c / 2)
        idx = tmp
    ans = cc * k
    print(ans)

Submission status: Wrong Answer

Solution code:
# 先頭と末尾が同じ場合はそれを省き、単体で完結するもの*K + 先頭と末尾が同じ場合の連結部分 * (K-1)
# ただし全部同じ場合は別で計算

from math import floor

s = input()
k = int(input())
if len(set(list(s))) == 1:
    print(floor((len(s) * k) / 2))
    exit()

if s[0] == s[-1]:
    # このへんの算数は手書きでいくつか書いて帰納的に導出した
    # だるいしs<=100なので愚直に数えるわ
    pre, suf = 0, 0
    for c in s:
        if c == s[0]:
            pre += 1
        else:
            break
    for c in s[::-1]:
        if c == s[-1]:
            suf += 1
        else:
            break

    # 先頭と末尾の連続する文字を除いたやつのうち連続するやつからいらないやつを数える
    idx = 0
    cc = 0
    t = s[pre : suf + 1]
    while idx < len(t):
        c = 0
        tmp = idx
        while tmp < len(t) and t[tmp] == t[idx]:
            tmp += 1
            c += 1
        if c > 1:
            cc += floor(c / 2)
        idx = tmp

    ans = floor(pre / 2) + cc * k + floor((pre + suf) / 2) + floor(suf / 2)
    print(ans)
else:
    idx = 0
    cc = 0
    t = s[:]
    while idx < len(t):
        c = 0
        tmp = idx
        while tmp < len(t) and t[tmp] == t[idx]:
            tmp += 1
            c += 1
        if c > 1:
            cc += floor(c / 2)
        idx = tmp
    ans = cc * k
    print(ans)

Submission status: Wrong Answer

Solution code:
# 先頭と末尾が同じ場合はそれを省き、単体で完結するもの*K + 先頭と末尾が同じ場合の連結部分 * (K-1)
# ただし全部同じ場合は別で計算

from math import floor

s = input()
k = int(input())
if len(set(list(s))) == 1:
    print(floor((len(s) * k) / 2))
    exit()

if s[0] == s[-1]:
    # このへんの算数は手書きでいくつか書いて帰納的に導出した
    # だるいしs<=100なので愚直に数えるわ
    pre, suf = 0, 0
    for c in s:
        if c == s[0]:
            pre += 1
        else:
            break
    for c in s[::-1]:
        if c == s[-1]:
            suf += 1
        else:
            break

    # print("pre:suf = {}:{}".format(pre, suf))
    # 先頭と末尾の連続する文字を除いたやつのうち連続するやつからいらないやつを数える
    idx = 0
    cc = 0
    t = s[pre : suf + 1]
    while idx < len(t):
        c = 0
        tmp = idx
        while tmp < len(t) and t[tmp] == t[idx]:
            tmp += 1
            c += 1
        if c > 1:
            cc += floor(c / 2)
        idx = tmp + 1

    ans = floor(pre / 2) + cc * k + floor((pre + suf) / 2) + floor(suf / 2)
    print(ans)
else:
    idx = 0
    cc = 0
    t = s[:]
    while idx < len(t):
        c = 0
        tmp = idx
        while tmp < len(t) and t[tmp] == t[idx]:
            tmp += 1
            c += 1
        if c > 1:
            cc += floor(c / 2)
        idx = tmp
    ans = cc * k
    print(ans)

Submission status: Wrong Answer

Solution code:
# 先頭と末尾が同じ場合はそれを省き、単体で完結するもの*K + 先頭と末尾が同じ場合の連結部分 * (K-1)
# ただし全部同じ場合は別で計算

from math import floor

s = input()
k = int(input())
if len(set(list(s))) == 1:
    print(floor((len(s) * k) / 2))
    exit()

if s[0] == s[-1]:
    # このへんの算数は手書きでいくつか書いて帰納的に導出した
    # だるいしs<=100なので愚直に数えるわ
    pre, suf = 0, 0
    for c in s:
        if c == s[0]:
            pre += 1
        else:
            break
    for c in s[::-1]:
        if c == s[-1]:
            suf += 1
        else:
            break

    # print("pre:suf = {}:{}".format(pre, suf))
    # 先頭と末尾の連続する文字を除いたやつのうち連続するやつからいらないやつを数える
    idx = 0
    cc = 0
    t = s[pre : suf + 1]
    while idx < len(t):
        c = 0
        tmp = idx
        while tmp < len(t) and t[tmp] == t[idx]:
            tmp += 1
            c += 1
        if c > 1:
            cc += floor((c + 1) / 2)
        idx = tmp + 1

    ans = floor(pre / 2) + cc * k + floor((pre + suf) / 2) + floor(suf / 2)
    print(ans)
else:
    idx = 0
    cc = 0
    t = s[:]
    while idx < len(t):
        c = 0
        tmp = idx
        while tmp < len(t) and t[tmp] == t[idx]:
            tmp += 1
            c += 1
        if c > 1:
            cc += floor((c + 1) / 2)
        idx = tmp + 1
    ans = cc * k
    print(ans)

Submission status: Wrong Answer

Solution code:
# 2019-11-25 06:26:24(JST)
import sys

def main():
    s, k = sys.stdin.read().split()
    k = int(k)

    if len(s) == 1:
        print(k // 2)
        sys.exit()
    
    if s.count(s[0]) == len(s):
        if len(s) % 2 == 0:
            ans = len(s) // 2 * k
        else:
            if k % 2 == 0:
                ans = len(s) * k // 2
            else:
                ans = len(s) * k // 2 + len(s) // 2
        print(ans)
        sys.exit()

    count = 0
    same = 1
    for i in range(len(s)-1):
        if s[i] == s[i+1]:
            same += 1
        else:
            if count == 0:
                first_same = same
            count += same // 2
            same = 1
    
    bl = False
    if s[-1] == s[0]:
        if same % 2 == 1 and first_same % 2 == 1:
            count += same // 2 + 1
            bl = True
        else:
            count += same // 2
    else:
        count += same // 2

    ans = count * k
    if bl:
        ans -= 1

    print(ans)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
# 2019-11-25 06:26:24(JST)
import sys

def main():
    s, k = sys.stdin.read().split()
    k = int(k)

    if len(s) == 1:
        print(k // 2)
        sys.exit()
    
    if s.count(s[0]) == len(s):
        # if len(s) % 2 == 0:
        ans = len(s) // 2 * k
        # else:
        #     if k % 2 == 0:
        #         ans = len(s) * k // 2
        #     else:
        #         ans = len(s) // 2 * (k // 2 + 1) + (len(s) // 2 + 1) * k // 2
        print(ans)
        sys.exit()

    count = 0
    same = 1
    for i in range(len(s)-1):
        if s[i] == s[i+1]:
            same += 1
        else:
            if count == 0:
                first_same = same
            count += same // 2
            same = 1
    
    bl = False
    if s[-1] == s[0]:
        if same % 2 == 1 and first_same % 2 == 1:
            count += same // 2 + 1
            bl = True
        else:
            count += same // 2
    else:
        count += same // 2

    ans = count * k
    if bl:
        ans -= 1

    print(ans)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
# 2019-11-25 06:26:24(JST)
import sys

def main():
    s, k = sys.stdin.read().split()
    k = int(k)

    if len(s) == 1:
        print(k // 2+100)
        sys.exit()
    
    if s.count(s[0]) == len(s):
        if len(s) % 2 == 0:
            ans = len(s) // 2  * k
        else:
            if k % 2 == 0:
                ans = len(s) * k // 2
            else:
                ans = len(s) // 2 * (k // 2 + 1) + (len(s) // 2 + 1) * k // 2
        print(ans)
        sys.exit()

    count = 0
    same = 1
    for i in range(len(s)-1):
        if s[i] == s[i+1]:
            same += 1
        else:
            if count == 0:
                first_same = same
            count += same // 2
            same = 1
    
    bl = False
    if s[-1] == s[0]:
        if same % 2 == 1 and first_same % 2 == 1:
            count += same // 2 + 1
            bl = True
        else:
            count += same // 2
    else:
        count += same // 2

    ans = count * k
    if bl:
        ans -= 1

    print(ans)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
# 2019-11-25 06:26:24(JST)
import sys

def main():
    s, k = sys.stdin.read().split()
    k = int(k)

    if len(s) == 1:
        print(k // 2)
        sys.exit()
    
    if s.count(s[0]) == len(s):
        if len(s) % 2 == 0:
            ans = len(s) // 2  * k
        else:
            if k % 2 == 0:
                ans = len(s) * k // 2
            else:
                ans = len(s) // 2 * (k // 2 + 1) + (len(s) // 2 + 1) * k // 2
        print(ans)
        sys.exit()
        
    count = 0
    same = 1
    for i in range(len(s)-1):
        if s[i] == s[i+1]:
            same += 1
        else:
            if count == 0:
                first_same = same
            count += same // 2
            same = 1
    
    bl = False
    if s[-1] == s[0]:
        if same % 2 == 1 and first_same % 2 == 1:
            count += same // 2 + 1
            bl = True
        else:
            count += same // 2
    else:
        count += same // 2

    ans = count * k
    if bl:
        ans -= 1

    print(ans)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
# 2019-11-25 06:26:24(JST)
import sys

def main():
    s, k = sys.stdin.read().split()
    k = int(k)

    count = 0
    same = 1
    for i in range(len(s)-1):
        if s[i] == s[i+1]:
            same += 1
        else:
            count += same // 2
            same = 1
    
    bl = False
    if s[-1] == s[0]:
        if same % 2 == 1:
            count += same // 2 + 1
            bl = True
        else:
            count += same // 2

    else:
        count += same // 2

    ans = count * k
    if bl:
        ans -= 1

    print(ans)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
S_input = list(input())
K = int(input())
 
# 書き換えの最小値を求める
def change_count(str_list):
    answer = 0
    for i in range(1,len(str_list)):
        if str_list[i] == str_list[i-1]:
            answer += 1
            str_list[i] = i
    return answer

Submission status: Wrong Answer

Solution code:
s=str(input())
k=int(input())
n=len(s)
if s[0]!=s[-1] or k==1:
    ans=0
    a=0
    c='0'
    for i in range(n):
        if s[i]==c:
            a+=1
        else:
            c=s[i]
            ans+=-(-a//2)
            a=0
    ans+=-(-a//2)
    print(ans*k)
elif n==1:
    print(k//2)
else:
    ans=0
    a=0
    c='0'
    for i in range(n):
        if s[i]==c:
            a+=1
        else:
            c=s[i]
            ans+=-(-a//2)
            a=0
    ans+=-(-a//2)
    ANS=0
    a=0
    c='0'
    s+=s
    for i in range(2*n):
        if s[i]==c:
            a+=1
        else:
            c=s[i]
            ANS+=-(-a//2)
            a=0
    ANS+=-(-a//2)
    print(ans+(ANS-ans)*(k-1))

Submission status: Wrong Answer

Solution code:
s=str(input())
k=int(input())
n=len(s)
if s[0]!=s[-1] or k==1:
    ans=0
    a=0
    c='0'
    for i in range(n):
        if s[i]==c:
            a+=1
        else:
            c=s[i]
            ans+=-(-a//2)
            a=0
    print(ans*k)
elif n==1:
    print(k//2)
else:
    ans=0
    a=0
    c='0'
    for i in range(n):
        if s[i]==c:
            a+=1
        else:
            c=s[i]
            ans+=-(-a//2)
            a=0
    ans+=-(-a//2)
    ANS=0
    a=0
    c='0'
    s+=s
    for i in range(2*n):
        if s[i]==c:
            a+=1
        else:
            c=s[i]
            ANS+=-(-a//2)
            a=0
    ANS+=-(-a//2)
    print(ans+(ANS-ans)*(k-1))

Submission status: Wrong Answer

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

def main(s, n):
  seperation = []
  tmp = ""
  for x in range(len(s)-1):
    tmp += s[x]
    if s[x] == s[x+1]:
      if tmp == "":
        tmp += s[x]
    else:
      seperation.append(tmp)
      tmp = ""
  tmp += s[-1]
  seperation.append(tmp)

  total = 0

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

  if (s[0] == s[-1]) and n>1 and len(seperation)>1:
    a = len(seperation[0])//2
    b = len(seperation[-1])//2
    total += a
    total += b
    seperation[0] += seperation[-1]
    a = seperation[0]
    c = (len(a)//2)*(k-1)
    total += c
    seperation = seperation[1:-1]

  for x in seperation:
    total += (len(x)//2)*k

  return total

print(main(s,k))

Submission status: Wrong Answer

Solution code:
def main1(str, n):
  seperation = []
  tmp = ""
  for x in range(len(str)-1):
    tmp += str[x]
    if str[x] == str[x+1]:
      if tmp == "":
        tmp += str[x]
    else:
      seperation.append(tmp)
      tmp = ""
  tmp += str[-1]
  seperation.append(tmp)

  total = 0

  print(seperation)

  if len(seperation) == 1:
    if (len(seperation[0]) == 1):
      return n//2

  if (str[0] == str[-1]) and n>1 and len(seperation)>1:
    a = len(seperation[0])//2
    b = len(seperation[-1])//2
    # print("a,b:",a,b)
    total += a
    total += b
    seperation[0] += seperation[-1]
    a = seperation[0]
    print(a,len(a),len(a)//2, n-1)
    c = (len(a)//2)*(n-1)
    print("c:",c)
    total += c
    seperation = seperation[1:-1]

  # print(total)
  print(seperation)

  for x in seperation:
    total += (len(x)//2)*n

  # print(seperation)
  return total

Submission status: Wrong Answer

Solution code:
a = str(input())
b = int(input())
print(a, b)

Submission status: Wrong Answer

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

seperation = []
tmp = ""
for x in range(len(str)-1):
  tmp += str[x]
  if str[x] == str[x+1]:
    if tmp == "":
      tmp += str[x]
  else:
    seperation.append(tmp)
    tmp = ""
tmp += str[-1]
seperation.append(tmp)

total = 0

# print(seperation)

if (str[0] == str[-1]) and n>1 and len(seperation)>1:
  total += len(seperation[0])//2
  total += len(seperation[-1])//2
  seperation[0] += seperation[-1]
  a = seperation[0]
  total += (len(a)//2)*n-1
  seperation = seperation[1:-1]

# print(total)

for x in seperation:
  total += (len(x)//2)*n

# print(seperation)
print(total)

Submission status: Wrong Answer

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

#s *= k 
ans = 0
#print(s,k)
s_m = s[0]  
for i in s[1:]:
#  print(i,s_m)
  if i == s_m:
    ans += 1
    s_m = '0'
  else:
    s_m = i  

if s[0] == s[-1] and len(s) >3:
  print(ans+k)
else:
  print(ans*k)

Submission status: Wrong Answer

Solution code:
# AGC039
S = list(input())
K = int(input())
N = len(S)
ans = 0
cnt = 0
if N == 1:
    print(N * K // 2)
    exit()
if len(set(S)) == 1:
    print(N * K // 2)
    exit()
for i in range(N-1):
    if S[i] == S[i+1]:
        S[i+1] = "!"
        ans += 1
if S[0] == S[-1]:
    S[-1] = "#"
    cnt += 1
if cnt == 0:
    print(ans * K)
else:
    print(ans * K + cnt * (K- 1))

Submission status: Wrong Answer

Solution code:
# AGC039
S = list(input())
K = int(input())
N = len(S)
ans = 0
cnt = 0
if N == 1:
    print(N // 2)
    exit()
if len(set(S)) == 1:
    print(N * K // 2)
    exit()
for i in range(N-1):
    if S[i] == S[i+1]:
        S[i+1] = "!"
        ans += 1
if S[0] == S[-1]:
    S[-1] = "#"
    ans += 1
    cnt += 1
if cnt == 0:
    print(ans * K)
else:
    print(ans * K - cnt * (K- 1) - 1)

Submission status: Wrong Answer

Solution code:
# AGC039
S = list(input())
K = int(input())
N = len(S)
ans = 0
cnt = 0
if N == 1:
    print(N // 2)
    exit()
if len(set(S)) == 1:
    print(N * K // 2)
    exit()
for i in range(N-1):
    if S[i] == S[i+1]:
        S[i+1] = "!"
        ans += 1
if S[0] == S[-1]:
    S[-1] = "#"
    ans += 1
    cnt += 1
if cnt == 0:
    print(ans * K)
else:
    print(ans * K - cnt * (K- 1) + 1)

Submission status: Wrong Answer

Solution code:
# AGC039
S = list(input())
K = int(input())
N = len(S)
ans = 0
cnt = 0
for i in range(N-1):
    if S[i] == S[i+1]:
        S[i+1] = "!"
        ans += 1
if S[0] == S[-1]:
    S[-1] = "#"
    ans += 1
    cnt += 1
print(ans * K - cnt)

Submission status: Wrong Answer

Solution code:
# AGC039
S = list(input())
K = int(input())
N = len(S)
ans = 0
cnt = 0
if S[0] == S[-1]:
    S[-1] = "#"
    ans += 1
    cnt += 1
for i in range(N-1):
    if S[i] == S[i+1]:
        S[i+1] = "!"
        ans += 1
print(ans * K - cnt)

Submission status: Wrong Answer

Solution code:
# AGC039
S = list(input())
K = int(input())
N = len(S)
ans = 0
if S[0] == S[-1]:
    S[-1] = "#"
    ans += 1
for i in range(N-1):
    if S[i] == S[i+1]:
        S[i+1] = "!"
        ans += 1
print(ans * K)

Submission status: Wrong Answer

Solution code:
S = [s for s in input()]
k = int(input())

if S[0] == S[-1]: S[-1] = '*'

for i in range(1,len(S)):
    if S[i-1] == S[i]: S[i] = '*'

print( S.count('*') * k )

Submission status: Wrong Answer

Solution code:
def hoge(value,st,pre):
    count=0
    for i in range(st,len(S)):

        if pre==S[i]:
            value+=1
        else:
            count+=value//2
            value=1
            pre=S[i]
        #print(S[i],value,count)
    count+=value//2
    return(count)
S=input()
K=int(input())

count=0
if K==1:
    count=hoge(0,1,S[0])

elif K>=2:
    if S[0]!=S[-1]:
        count=hoge(0,1,S[0])
        count*=K
    else:
        count=hoge(1,0,S[0])
        count*=K
        if len(S)>2:
            count-=2
        elif len(S)==2:
            pass
    if len(S)==1:
        count=K-2

print(count)

Submission status: Wrong Answer

Solution code:
def hoge(value,st,pre):
    count=0
    for i in range(st,len(S)):

        if pre==S[i]:
            value+=1
        else:
            count+=value//2
            value=1
            pre=S[i]
        #print(S[i],value,count)
    count+=value//2
    return(count)
S=input()
K=int(input())

count=0
if K==1:
    count=hoge(0,1,S[0])

elif K>=2:
    if S[0]!=S[-1]:
        count=hoge(0,1,S[0])
        count*=K
    else:
        count=hoge(1,0,S[0])
        count*=K
    if len(S)>2:
        count-=2
    elif len(S)==2:
        pass
    elif len(S)==1:
        count=K-2    

print(count)

Submission status: Wrong Answer

Solution code:
def hoge(value,st,pre):
    count=0
    for i in range(st,len(S)):

        if pre==S[i]:
            value+=1
        else:
            count+=value//2
            value=1
            pre=S[i]
        #print(S[i],value,count)
    count+=value//2
    return(count)
S=input()
K=int(input())

count=0
if K==1:
    count=hoge(0,1,S[0])

elif K>=2:
    if S[0]!=S[-1]:
        count=hoge(0,1,S[0])
        count*=K
    else:
        count=hoge(1,0,S[0])
        count*=K
        if len(S)>2:
            count-=2
        elif len(S)==2:
            pass
        elif len(S)==1:
            count=K-2

print(count)

Submission status: Wrong Answer

Solution code:
S = input()
K = int(input())
c = 1
p = ''
ans0 = 0
ans1 = 0
for i in S:
    if i == p:
        c += 1
    else:
        ans0 += c // 2
        c = 1
    p = i
ans0 += c // 2

c = 1
p = ''
for i in S + S:
    if i == p:
        c += 1
    else:
        ans1 += c // 2
        c = 1
    p = i
ans1 += c // 2
print(ans0 + (ans1 - ans0) * (K - 1))

Submission status: Wrong Answer

Solution code:
s=input()
t=int(input())
a=len(s)
b=0
i=0
while i<a-1:
  if s[i]==s[i+1]:
    b=b+1
    i+=2
  else:
    i+=1
if s[0]!=s[a-1]:
  print(b*t)
else:
  d=1
  i=0
  while i<a-1:
    if s[i]==s[i+1]:
      d+=1 
      i=i+1
    else:
      break
  e=1
  i=0
  while i<a-1:
    if s[a-1-i]==s[a-1-i-1]:
      e+=1
      i=i+1
    else:
      break
  if d+e==a:
    print(a*t//2)
  else:
    b-=d//2
    b-=e//2
    print(b*t+d//2+e//2+(d+e)//2*(t-1))