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:
#!/usr/bin/env python3

def main():
    S = input()
    K = int(input())

    cnt = 0
    ans = 0
    s_temp = S[0]
    fcnt = 0
    for s in S:
        if s_temp == s:
            cnt += 1
            s_temp = s
        else:
            ans += cnt // 2
            if fcnt == 0:
                fcnt = cnt
            cnt = 1
            s_temp = s
    ans += cnt // 2
    ans *= K
    if S[0] == S[-1] and cnt % 2 == 1 and fcnt % 2 == 1:
        ans += K - 1
    if len(S) == 1:
        ans = (K + 1) // 2 - 1

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

def main():
    S = input()
    K = int(input())

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

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

def main():
    S = input()
    K = int(input())

    cnt = 0
    ans = 0
    s_temp = S[0]
    fcnt = 0
    for s in S:
        if s_temp == s:
            cnt += 1
            s_temp = s
        else:
            ans += cnt // 2
            if fcnt == 0:
                fcnt = cnt
            cnt = 1
            s_temp = s
    ans += cnt // 2
    ans *= K
    if S[0] == S[-1] and cnt % 2 == 1 and fcnt % 2 == 1:
        ans += K - 1
    if len(S) == 1:
        ans = K // 2

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

def main():
    S = input()
    K = int(input())

    cnt = 0
    ans = 0
    s_temp = S[0]
    fcnt = 0
    for s in S:
        if s_temp == s:
            cnt += 1
            s_temp = s
        else:
            ans += cnt // 2
            if fcnt == 0:
                fcnt = cnt
            cnt = 1
            s_temp = s
    ans += cnt // 2
    ans *= K
    if S[0] == S[-1] and cnt % 2 == 1 and fcnt % 2 == 1:
        ans += K - 1
    elif len(S) == 1:
        ans = K // 2

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

def main():
    S = input()
    K = int(input())

    cnt = 0
    ans = 0
    s_temp = ""
    for s in S:
        if s_temp == s:
            cnt += 1
            s_temp = s
        else:
            ans += cnt // 2
            cnt = 1
            s_temp = s
    ans += cnt // 2
    ans *= K
    if S[0] == S[-1] and cnt % 2 == 1:
        ans += K - 1
    elif len(S) == 1:
        ans = K // 2

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

def main():
    S = input()
    K = int(input())

    cnt = 0
    ans = 0
    s_temp = ""
    for s in S:
        if s_temp == s:
            cnt += 1
            s_temp = s
        else:
            ans += cnt // 2
            cnt = 1
            s_temp = s
    ans += cnt // 2
    ans *= K
    if S[0] == S[-1] and cnt % 2 == 1:
        ans += K - 1

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

sh=s+s[0]
cnt=0
moji=s[0]
l=0
r=0
for i in range(1,len(sh)):
    if moji!=sh[i] or i==len(sh)-1:
        cnt+=(r-l+1)//2
        l=i
        r=i
        moji=sh[i]
    else:
        r=i

print(cnt*k)

Submission status: Wrong Answer

Solution code:
S = list(input())
K = int(input())
ls = len(S)
cnt = 0
for i in range(1, ls):
    if S[i] == S[i-1]:
        S[i] = "."
        cnt += 1
if S[-1] == S[0]:
    print(cnt * K + K - 1)
else:
    print(cnt * K)

Submission status: Wrong Answer

Solution code:
s=input()
n=int(input())
ans=0
tmp=1
for i in range(len(s)-1):
  if s[i]==s[i+1]:
    tmp+=1
  else:
    ans+=tmp//2
    tmp=1
if tmp!=0:
  ans+=tmp//2
ans*=n
if len(s)!=1 and s[0]==s[-1]:
  top=0
  bottom=0
  for i in range(len(s)):
    if s[:i].count(s[0])==i:
      top=i+1
    if s[-i:].count(s[-1])==i:
      bottom=i+1
  if top!=len(s):
    ans+=(top//2+bottom//2-(top+bottom)//2)*(n-1)
  elif len(s)%2==1:
    ans+=n//2
if len(s)==1:
  print(n//2)
else:
  print(ans)

Submission status: Wrong Answer

Solution code:
s=input()
n=int(input())
ans=0
tmp=1
for i in range(len(s)-1):
  if s[i]==s[i+1]:
    tmp+=1
  else:
    ans+=tmp//2
    tmp=1
if tmp!=0:
  ans+=tmp//2
ans*=n
if len(s)!=1 and s[0]==s[-1]:
  top=0
  bottom=0
  for i in range(len(s)):
    if s[:i].count(s[0])==i:
      top=i
    if s[-i-1:].count(s[-1])==i:
      bottom=i
  ans+=(top//2+bottom//2-(top+bottom)//2)*(n-1)
if len(s)==1:
  print(n//2)
else:
  print(ans)

Submission status: Wrong Answer

Solution code:
s=input()
n=int(input())
ans=0
tmp=1
for i in range(len(s)-1):
  if s[i]==s[i+1]:
    tmp+=1
  else:
    ans+=tmp//2
    tmp=1
if tmp!=0:
  ans+=tmp//2
ans*=n
if len(s)!=1 and s[0]==s[-1]:
  top=0
  bottom=0
  for i in range(len(s)):
    if s[:i].count(s[0])==i:
      top=i
    if s[-i-1:].count(s[-1])==i:
      bottom=i
  ans+=(top//2+bottom//2-(top+bottom)//2)*(n-1)
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
def main():
    S = input().rstrip()
    K = int(input())
    if len(set(S)) == 1:
        ans = len(S)*K //2 
        print(ans)
        return
    CNT = 1
    ans = 0
    if S[0] != S[len(S)-1]:
        for i in range(len(S)-1):
            if S[i] == S[i+1]:
                CNT += 1
            else:
                ans += CNT//2
                CNT = 1
        ans += CNT//2
        print(ans*K)
        return
    else:
        SS = S + S
        for i in range(len(SS)-1):
            if SS[i] == SS[i+1]:
                CNT += 1
            else:
                ans += CNT//2
                CNT = 1
                # print(SS[i], 'ans', ans)
        ans += CNT//2
        print(ans*(K-1))
        return

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
def main():
    S = input().rstrip()
    K = int(input())
    if len(set(S)) == 1:
        ans = len(S)//2 * K
        print(ans)
        return
    CNT = 1
    ans = 0
    if S[0] != S[len(S)-1]:
        for i in range(len(S)-1):
            if S[i] == S[i+1]:
                CNT += 1
            else:
                ans += CNT//2
                CNT = 1
        ans += CNT//2
        print(ans*K)
        return
    else:
        SS = S + S
        for i in range(len(SS)-1):
            if SS[i] == SS[i+1]:
                CNT += 1
            else:
                ans += CNT//2
                CNT = 1
                # print(SS[i], 'ans', ans)
        ans += CNT//2
        print(ans*(K-1))
        return

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

if cnt>=2:
    ans += cnt//2

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

if lftcnt==len(s):
    ans=(lftcnt*k)//2
else:
    ans *= k
    if s[0]==s[-1]:
        a=(lftcnt//2) + (cnt//2) - ((lftcnt+cnt)//2)
        ans +=a

print(ans)

Submission status: Wrong Answer

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

if cnt>=2:
    ans += cnt//2

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

if lftcnt==len(s):
    ans=(lftcnt*k)//2
else:
    ans *= k
    if s[0]==s[-1] and lftcnt+cnt%2==0:
        ans += k-1

print(ans)

Submission status: Wrong Answer

Solution code:
def count(S):
    all_cnt = 0
    cnt = 0
    for i in range(len(S)-1):
        if S[i] == S[i+1]:
            cnt += 1
        else:
            if cnt > 0:
                if cnt % 2 == 1:
                    all_cnt += (cnt + 1) / 2
                else:
                    all_cnt += cnt / 2
            cnt = 0
        # print(cnt,all_cnt)
    if cnt > 0:
        if cnt % 2 == 1:
            all_cnt += (cnt + 1) / 2
        else:
            all_cnt += cnt / 2
    return int(all_cnt)

def main():
    S = input()
    K = int(input())
    if S.count(S[0]) == len(S):
        print(len(S)*K // 2)
        return
    if S[-1] == S[0]:
        print(count(S + S[0])*(K-1) + count(S))
    else:
        print(count(S)*K)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    S = input()
    K = int(input())
    all_cnt = 0
    cnt = 0
    if S.count(S[0]) != len(S):
        while S[-1] == S[0]:
            S = S[1:] + S[0]
            # print(S)
    else:
        if len(S)*K % 2 == 1:
            print(int((len(S) - 1)*K / 2) + 1)
            return
        else:
            print(int(len(S)*K / 2))
            return
    for i in range(len(S)-1):
        if S[i] == S[i+1]:
            cnt += 1
        else:
            if cnt > 0:
                if cnt % 2 == 1:
                    all_cnt += (cnt + 1) / 2
                else:
                    all_cnt += cnt / 2
            cnt = 0
        # print(cnt,all_cnt)
    if cnt > 0:
        if cnt % 2 == 1:
            all_cnt += (cnt + 1) / 2
        else:
            all_cnt += cnt / 2
    print(int(all_cnt*K))

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    S = input()
    K = int(input())
    all_cnt = 0
    cnt = 0
    for i in range(len(S)-1):
        if S[i] == S[i+1]:
            cnt += 1
        else:
            if cnt > 0:
                if cnt % 2 == 1:
                    all_cnt += (cnt + 1) / 2
                else:
                    all_cnt += cnt / 2
            cnt = 0
        # print(cnt,all_cnt)
    if cnt > 0:
        if cnt % 2 == 1:
            all_cnt += (cnt + 1) / 2
        else:
            all_cnt += cnt / 2
    print(int(all_cnt*K))

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

SS = input().rstrip()
ls = len(SS)
Ki = int(input())
lis= []

for K in range(1,3):
    S = list(SS*K)
    N = len(S)
    cnt = 0
    for i in range(1,N-1):
        if S[i-1] == S[i] == S[i+1]:
            S[i] = '5'
            cnt += 1
    for i in range(N-1):
        if S[i]==S[i+1]:
            S[i] = '5'
            cnt += 1
    lis.append(cnt)
a = lis[0]
d = lis[1]-lis[0]

print(a+ d*(Ki-1))

Submission status: Wrong Answer

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

S = input().rstrip()
ls = len(S)
K = int(input())

if K < 3:
    S = list(S*K)
    N = len(S)
    cnt = 0
    for i in range(1,N-1):
        if S[i-1] == S[i] == S[i+1]:
            S[i] = '5'
            cnt += 1
    for i in range(N-1):
        if S[i]==S[i+1]:
            S[i] = '5'
            cnt += 1
if K >= 3:
    S = list(S*3)
    N = len(S)
    for i in range(1,N-1):
        if S[i-1] == S[i] == S[i+1]:
            S[i] = '5'
    for i in range(N-1):
        if S[i]==S[i+1]:
            S[i] = '5'
    cnt1 = S[:ls].count('5')
    cntf = S[-ls:].count('5')
    cntm = S[ls:-ls].count('5')*(K-2)
    cnt = cnt1+cntf+cntm

print(cnt)

Submission status: Wrong Answer

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

if(S.count(S[0]) == len(S)):
    print(len(S)*K//2)
else:
    if(S[0] != S[-1]):
        cnt = 0
        lst = []
        tmp = S[0]
        for i in range(len(S)):
            if(tmp == S[i]):
                cnt += 1
            else:
                tmp = S[i]
                if(cnt > 1):
                    lst.append(cnt)
                cnt = 1   
        if(cnt > 1):
            lst.append(cnt)
        
        ans = 0
        for i in range(len(lst)):
            ans += K*(lst[i]//2)
        print(ans)
    else:
        cnt = 0
        lst = []
        tmp = S[0]
        for i in range(len(S)):
            if(tmp == S[i]):
                cnt += 1
            else:
                tmp = S[i]
                if(cnt > 1):
                    lst.append(cnt)
                cnt = 1
        if(cnt > 1):
            lst.append(cnt)
    
        ans = 0
        for i in range(len(lst)):
            ans += K*(lst[i]//2)
        a = 0
        b = 0
        tmp = S[0]
        for i in range(len(S)):
            if(tmp != S[i]):
                break
            a += 1
        for i in S[::-1]:
            if(tmp != i):
                break
            b += 1
        print(ans+((a+b)//2-(a//2+b//2)*(K-1)))

Submission status: Wrong Answer

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

if(S.count(S[0]) == len(S)):
    if(len(S) == 1):
        print(K-1)
    else:
        print((len(S)//2)*K)
else:
    if(S[0] != S[-1]):
        cnt = 0
        lst = []
        tmp = S[0]
        for i in range(len(S)):
            if(tmp == S[i]):
                cnt += 1
            else:
                tmp = S[i]
                if(cnt > 1):
                    lst.append(cnt)
                cnt = 1   
        if(cnt > 1):
            lst.append(cnt)
        
        ans = 0
        for i in range(len(lst)):
            ans += K*(lst[i]//2)
        print(ans)
    else:
        cnt = 0
        lst = []
        tmp = S[0]
        for i in range(len(S)):
            if(tmp == S[i]):
                cnt += 1
            else:
                tmp = S[i]
                if(cnt > 1):
                    lst.append(cnt)
                cnt = 1
        if(cnt > 1):
            lst.append(cnt)
    
        ans = 0
        for i in range(len(lst)):
            ans += K*(lst[i]//2)
        a = 0
        b = 0
        tmp = S[0]
        for i in range(len(S)):
            if(tmp != S[i]):
                break
            a += 1
        for i in S[::-1]:
            if(tmp != i):
                break
            b += 1
        print(ans-(a//2+b//2-(a+b)//2)*(K-1))

Submission status: Wrong Answer

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

if(S.count(S[0]) == len(S)):
    print((len(S)//2)*K)
elif(len(S) == 1):
    print(K-1)
else:
    if(S[0] != S[-1]):
        cnt = 0
        lst = []
        tmp = S[0]
        for i in range(len(S)):
            if(tmp == S[i]):
                cnt += 1
            else:
                tmp = S[i]
                if(cnt > 1):
                    lst.append(cnt)
                cnt = 1   
        if(cnt > 1):
            lst.append(cnt)
        
        ans = 0
        for i in range(len(lst)):
            ans += K*(lst[i]//2)
        print(ans)
    else:
        cnt = 0
        lst = []
        tmp = S[0]
        for i in range(len(S)):
            if(tmp == S[i]):
                cnt += 1
            else:
                tmp = S[i]
                if(cnt > 1):
                    lst.append(cnt)
                cnt = 1
        if(cnt > 1):
            lst.append(cnt)
    
        ans = 0
        for i in range(len(lst)):
            ans += K*(lst[i]//2)
        a = 0
        b = 0
        tmp = S[0]
        for i in range(len(S)):
            if(tmp != S[i]):
                break
            a += 1
        for i in S[::-1]:
            if(tmp != i):
                break
            b += 1
        print(ans-(a//2+b//2-(a+b)//2)*(K-1))

Submission status: Wrong Answer

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

if(S.count(S[0]) == len(S)):
    print((len(S)//2)*K)
else:
    if(S[0] != S[-1]):
        cnt = 0
        lst = []
        tmp = S[0]
        for i in range(len(S)):
            if(tmp == S[i]):
                cnt += 1
            else:
                tmp = S[i]
                if(cnt > 1):
                    lst.append(cnt)
                cnt = 1   
        if(cnt > 1):
            lst.append(cnt)
        
        ans = 0
        for i in range(len(lst)):
            ans += K*(lst[i]//2)
        print(ans)
    else:
        cnt = 0
        lst = []
        tmp = S[0]
        for i in range(len(S)):
            if(tmp == S[i]):
                cnt += 1
            else:
                tmp = S[i]
                if(cnt > 1):
                    lst.append(cnt)
                cnt = 1
        if(cnt > 1):
            lst.append(cnt)
    
        ans = 0
        for i in range(len(lst)):
            ans += K*(lst[i]//2)
        a = 0
        b = 0
        tmp = S[0]
        for i in range(len(S)):
            if(tmp != S[i]):
                break
            a += 1
        for i in S[::-1]:
            if(tmp != i):
                break
            b += 1
        print(ans-(a//2+b//2-(a+b)//2)*(K-1))

Submission status: Wrong Answer

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

if(S.count(S[0]) == len(S)):
    print((len(S)//2)*K)
else:
    if(S[0] != S[-1]):
        cnt = 0
        lst = []
        tmp = S[0]
        for i in range(len(S)):
            if(tmp == S[i]):
                cnt += 1
            else:
                tmp = S[i]
                if(cnt > 1):
                    lst.append(cnt)
                cnt = 1   
        if(cnt > 1):
            lst.append(cnt)
        
        ans = 0
        for i in range(len(lst)):
            ans += K*(lst[i]//2)
        print(ans)
    else:
        cnt = 0
        lst = []
        tmp = S[0]
        for i in range(len(S)):
            if(tmp == S[i]):
                cnt += 1
            else:
                tmp = S[i]
                if(cnt > 1):
                    lst.append(cnt)
                cnt = 1
        if(cnt > 1):
            lst.append(cnt)
    
        ans = 0
        for i in range(len(lst)):
            ans += K*(lst[i]//2)
        a = 0
        b = 0
        tmp = S[0]
        for i in range(len(S)):
            if(tmp != S[i]):
                break
            a += 1
        for i in S[::-1]:
            if(tmp != i):
                break
            b += 1
        print(ans+(a//2+b//2-(a+b)//2)*(K-1))

Submission status: Wrong Answer

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

if(S.count(S[0]) == len(S)):
    print((len(S)-1)*K)
else:
    if(S[0] != S[-1]):
        cnt = 0
        lst = []
        tmp = S[0]
        for i in range(len(S)):
            if(tmp == S[i]):
                cnt += 1
            else:
                tmp = S[i]
                if(cnt > 1):
                    lst.append(cnt)
                cnt = 1
            
        if(cnt > 1):
            lst.append(cnt)
        
        ans = 0
        for i in range(len(lst)):
            ans += K*(lst[i]//2)
        print(ans)
    else:
        cnt = 0
        lst = []
        tmp = S[0]
        for i in range(len(S)):
            if(tmp == S[i]):
                cnt += 1
            else:
                tmp = S[i]
                if(cnt > 1):
                    lst.append(cnt)
                cnt = 1
        if(cnt > 1):
            lst.append(cnt)
    
        ans = 0
        for i in range(len(lst)):
            ans += K*(lst[i]//2)
        c = 0
        tmp = S[0]
        for i in range(len(S)):
            if(tmp != S[i]):
                break
            c += 1
        for i in S[::-1]:
            if(tmp != i):
                break
            c += 1
        if(c%2 != 0):
            print(ans)
        else:
            print(ans+(K-1)*(c//2-1))

Submission status: Wrong Answer

Solution code:
# こういうのは2回繰り返してみるのが定石っぽいけど、1回だけのやつで「同じのが並んでたら後ろのほうを変える」でいいんじゃないか？
# んで最初と最後が同じならk-1回ぶん帳尻を合わせる

# なぜか3ケース合わない 意味不明
# aabaaa 2 で7になってしまう やっぱり2回繰り返してみる
# なぜか1ケース合わない aba 3 で1になってしまう
# a 5 とかのケースでも合わない もうこのケースだけ嘘で通すか 1ケースだけ合わないってことはどうせコーナーケースだろうし

s = list(input())
k = int(input())
t = s * 2
a = 0
if len(s) == 1:
    # 嘘
    print(k // 2)
    exit()

for i in range(1, len(t)):
    if t[i] == t[i - 1]:
        t[i] = "夏"
        a += 1
print(a * k // 2)

Submission status: Wrong Answer

Solution code:
# こういうのは2回繰り返してみるのが定石っぽいけど、1回だけのやつで「同じのが並んでたら後ろのほうを変える」でいいんじゃないか？
# んで最初と最後が同じならk-1回ぶん帳尻を合わせる

# なぜか3ケース合わない 意味不明
# aabaaa 2 で7になってしまう やっぱり2回繰り返してみる
# なぜか1ケース合わない aba 3 で1になってしまう
# a 5 とかのケースでも合わない もうこのケースだけ嘘で通すか 1ケースだけ合わないってことはどうせコーナーケースだろうし

s = list(input())
k = int(input())
t = s * 2
a = 0
if len(set(s)) == 1:
    # 嘘
    print(k // 2)
    exit()

for i in range(1, len(t)):
    if t[i] == t[i - 1]:
        t[i] = "夏"
        a += 1
print(a * k // 2)

Submission status: Wrong Answer

Solution code:
# こういうのは2回繰り返してみるのが定石っぽいけど、1回だけのやつで「同じのが並んでたら後ろのほうを変える」でいいんじゃないか？
# んで最初と最後が同じならk-1回ぶん帳尻を合わせる

# なぜか3ケース合わない 意味不明
# aabaaa 2 で7になってしまう やっぱり2回繰り返してみる
# なぜか1ケース合わない aba 3 で1になってしまう
s = list(input())
k = int(input())
t = s * 2
a = 0

for i in range(1, len(t)):
    if t[i] == t[i - 1]:
        t[i] = "夏"
        a += 1
if t[0] == t[-1]:
    print(a * (k - 1) // 2 + 1)  # 先頭の分？？？
else:
    print(a * k // 2)

Submission status: Wrong Answer

Solution code:
# こういうのは2回繰り返してみるのが定石っぽいけど、1回だけのやつで「同じのが並んでたら後ろのほうを変える」でいいんじゃないか？
# んで最初と最後が同じならk-1回ぶん帳尻を合わせる

# なぜか3ケース合わない 意味不明
# aabaaa 2 で7になってしまう やっぱり2回繰り返してみる
# なぜか1ケース合わない
# aba 3 で1になってしまう

s = list(input())
k = int(input())
t = s * 2
a = 0

for i in range(1, len(t)):
    if t[i] == t[i - 1]:
        t[i] = "夏"
        a += 1

if k > 2 and t[0] == t[-1]:
    print(a * k // 2 + a)
else:
    print(a * k // 2)

Submission status: Wrong Answer

Solution code:
# こういうのは2回繰り返してみるのが定石っぽいけど、1回だけのやつで「同じのが並んでたら後ろのほうを変える」でいいんじゃないか？
# んで最初と最後が同じならk-1回ぶん帳尻を合わせる

# なぜか3ケース合わない 意味不明
# aabaaa 2 で7になってしまう やっぱり2回繰り返してみる
s = list(input())
k = int(input())
t = s * 2
a = 0

for i in range(1, len(t)):
    if t[i] == t[i - 1]:
        t[i] = "夏"
        a += 1

print(a * k // 2)

Submission status: Wrong Answer

Solution code:
# こういうのは2回繰り返してみるのが定石っぽいけど、1回だけのやつで「同じのが並んでたら後ろのほうを変える」でいいんじゃないか？
# んで最初と最後が同じならk-1回ぶん帳尻を合わせる
s = list(input())
k = int(input())
a = 0
for i in range(1, len(s)):
    if s[i] == s[i - 1]:
        s[i] = "夏"
        a += 1

if s[0] == s[-1]:
    print(a * k + (k - 1))
else:
    print(a * k)

Submission status: Wrong Answer

Solution code:
# こういうのは2回繰り返してみるのが定石っぽいけど、1回だけのやつで「同じのが並んでたら後ろのほうを変える」でいいんじゃないか？
# んで最初と最後が同じならk-1回ぶん帳尻を合わせる
s = list(input())
k = int(input())
a = 0
for i in range(1, len(s)):
    if s[i] == s[i - 1]:
        s[i] = "夏"
        a += 1
if s[0] == s[-1]:
    print(a * k + a * (k - 1))
else:
    print(a * k)

Submission status: Wrong Answer

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

ans = 0
i = 0
cnt = 1
first = 0

for i in range(1, len(s)):
    if s[i] != s[0]:
        first = i
        break

if first == 0:
    if len(s) % 2 == 0:
        print((len(s) // 2) * k)
    else:
        print(len(s) * k // 2)
    exit()

while i < len(s) - 1:
    if s[i] == s[i+1]:
        cnt += 1
        if i == len(s) - 2:
            ans += cnt // 2
    else:
        ans += cnt // 2
        cnt = 1
    i += 1

ans *= k

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

print(ans)

Submission status: Wrong Answer

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

ans = 0
i = 0
cnt = 1
first = 0

for i in range(1, len(s)):
    if s[i] != s[0]:
        first = i
        break

if first == 0:
    if len(s) % 2 == 1:
        print((len(s) // 2) * k)
    else:
        print((len(s) // 2 + 1) * k)
    exit()

while i < len(s) - 1:
    if s[i] == s[i+1]:
        cnt += 1
        if i == len(s) - 2:
            ans += cnt // 2
    else:
        ans += cnt // 2
        cnt = 1
    i += 1

ans *= k

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

print(ans)

Submission status: Wrong Answer

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

ans = 0
i = 0
cnt = 1
first = 0

for i in range(1, len(s)):
    if s[i] != s[0]:
        first = i
        break

if first == 0:
    if len(s) % 2 == 0:
        print((len(s) // 2) * k)
    else:
        print((len(s) // 2 + 1) * k)
    exit()

while i < len(s) - 1:
    if s[i] == s[i+1]:
        cnt += 1
        if i == len(s) - 2:
            ans += cnt // 2
    else:
        ans += cnt // 2
        cnt = 1
    i += 1

ans *= k

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

print(ans)

Submission status: Wrong Answer

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

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

ans = 0
judge = [False] * len(S)

for i in range(1, len(S)):
    if S[i-1] == S[i]:
        ans += 1
        judge[i] = True
        S[i] = '-1'
    
if not judge[len(S)-1] and S[0] == S[-1]:
    ans += 1
    print(ans * K - 1)
else:
    print(ans * K)

Submission status: Wrong Answer

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

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

ans = 0
judge = [False] * len(S)

for i in range(1, len(S)):
    if S[i-1] == S[i]:
        ans += 1
        judge[i] = True
        S[i] = '-1'
    
if not judge[len(S)-1] and S[0] == S[-1]:
    ans += 1

print(ans * K - 1)

Submission status: Wrong Answer

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

ans = 0
judge = [False] * len(S)

for i in range(1, len(S)):
    if S[i-1] == S[i]:
        ans += 1
        judge[i] = True
        S[i] = '-1'
    
if not judge[len(S)-1] and S[0] == S[-1]:
    ans += 1

print(ans * K)

Submission status: Wrong Answer

Solution code:
s=str(input())
k=int(input())
s=list(s)
s2=s+s
cnt=0
temp1=0
temp2=0
for i in range(1,len(s)):
  if s[i]==s[i-1]:
    cnt=cnt+1
  if s[i]!=s[i-1]:
    temp1=temp1+(cnt+1)//2
    cnt=0
temp1=temp1+(cnt+1)//2
cnt=0
for i in range(1,len(s2)):
  if s2[i]==s2[i-1]:
    cnt=cnt+1
  if s2[i]!=s2[i-1]:
    temp2=temp2+(cnt+1)//2
    cnt=0
temp2=temp2+(cnt+1)//2
cnt=0
if len(s)==1:
  print(k//2)
elif k==1:
  print(temp1)
else:
  print(temp1+(temp2-temp1)*(k-1))

Submission status: Wrong Answer

Solution code:
s=str(input())
k=int(input())
s=list(s)
s2=s+s
cnt=0
temp1=0
temp2=0
for i in range(1,len(s)):
  if s[i]==s[i-1]:
    cnt=cnt+1
  if s[i]!=s[i-1]:
    temp1=temp1+(cnt+1)//2
    cnt=0
temp1=temp1+(cnt+1)//2
cnt=0
for i in range(1,len(s2)):
  if s2[i]==s2[i-1]:
    cnt=cnt+1
  if s2[i]!=s2[i-1]:
    temp2=temp2+(cnt+1)//2
    cnt=0
temp2=temp2+(cnt+1)//2
cnt=0
if k==1:
  print(temp1)
else:
  print(temp1+(temp2-temp1)*(k-1))

Submission status: Wrong Answer

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

if list(s[0]*len(s))==s:
	#print('a')
	print(len(s)*k//2)
	exit()

'''ans = 0
if s[0]!=s[-1]:
	for i in range(1,len(s)-1):
		if s[i]==s[i+1]:
			ans += 1
			s[i+1] = '#'
	#print('b')
	print(ans*k)
	exit()


head = 0
while True:
	if s[head]==s[head+1]:
		head +=1
	else:
		break

tail = 1
while True:
	if s[-tail]==s[-(tail+1)]:
		tail +=1
	else:
		break
#print('head,tail',head,tail)
ans = head//2 + ((head+tail)//2)*(k-1) + tail//2
body = 0
for i in range(head, len(s)-tail-1):
	if s[i]==s[i+1]:
		#print(body)
		body += 1
		s[i+1] = '#'
ans += body*k
print(ans)'''
res = [1]
for i in range(len(s)-1):
	if s[i]==s[i+1]:
		res[-1] += 1
	else:
		res.append(1)
ans = 0
for i in res:
	ans += (i//2)*k
if s[0]==s[-1]:
	diff = (res[0]+res[-1])//2 -(res[0]//2 + res[-1]//2)
	ans += diff*k
print(ans)

Submission status: Wrong Answer

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

if list(s[0]*len(s))==s:
	#print('a')
	print(len(s)*k//2)
	exit()

ans = 0
if s[0]!=s[-1]:
	for i in range(1,len(s)-1):
		if s[i]==s[i+1]:
			ans += 1
			s[i+1] = '#'
	#print('b')
	print(ans*k)
	exit()


head = 0
while True:
	if s[head]==s[head+1]:
		head +=1
	else:
		break

tail = 1
while True:
	if s[-tail]==s[-(tail+1)]:
		tail +=1
	else:
		break
#print('head,tail',head,tail)
ans = head//2 + ((head+tail)//2)*(k-1) + tail//2
body = 0
for i in range(head, len(s)-tail-1):
	if s[i]==s[i+1]:
		#print(body)
		body += 1
		s[i+1] = '#'
ans += body*k
print(ans)

Submission status: Wrong Answer

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

if list(s[0]*len(s))==s:
	#print('a')
	print(len(s)*k//2)
	exit()

ans = 0
if s[0]!=s[-1]:
	for i in range(1,len(s)-1):
		if s[i]==s[i+1]:
			ans += 1
			s[i+1] = '#'
	#print('b')
	print(ans*k)
	exit()

pre = s[0]
head = 0
while True:
	if pre==s[head]:
		head +=1
	else:
		break

tail = 1
while True:
	if pre==s[-tail]:
		tail +=1
	else:
		tail -=1
		break
#print('head,tail',head,tail)
ans = head//2 + ((head+tail)//2)*(k-1) + tail//2
body2 = 0
for i in range(head, len(s)-tail-1):
	if s[i]==s[i+1]:
		#print(body2)
		body2 += 1
		s[i+1] = '#'
ans += body2*k
print(ans)

Submission status: Wrong Answer

Solution code:
s = list(input())
k = int(input())
n = len(s)
res = 0
i = 0
if s.count(s[0]) == n: # 全て同じ
    print(n*k//2)
    exit()

while i < n-1:
    if s[i] == s[i+1]:
        res += 1
        i +=1
    i+=1
res *= k

if s[0] != s[n-1]:
    print(res)
else:
    a=0
    b=0
    v=s[0]
    i=0
    while s[i] == v:
        a+=1
        i+=1
    while s[n-1] == v:
        b+=1
        n-=1
    res -= ((a//2)+(b//2)-((a+b)//2))//(k-1)
    print(res)

Submission status: Wrong Answer

Solution code:
S=input()
K=int(input())
post=S[0]
rep=0
for i in range(1,len(S)):
  if S[i]==post:
    rep+=1
    post="1"
  else:
    post=S[i]
ans=rep
print(ans)

Submission status: Wrong Answer

Solution code:
s=input()
S=s+s
K=int(input())
post=S[0]
rep=0
later=0
for i in range(1,len(S)):
  if S[i]==post:
    rep+=1
    if i>=len(s):
      later+=1
    post="1"
  else:
    post=S[i]
ans=rep*(K//2)
print(ans)
exit()
if K%2==1:
  if post!=s[0] or K==1:
    ans+=rep-later
  else:
    ans+=later
print(ans)

Submission status: Wrong Answer

Solution code:
s=input()
S=s+s
K=int(input())
post=S[0]
rep=0
later=0
for i in range(1,len(S)):
  if S[i]==post:
    rep+=1
    if i>=len(s):
      later+=1
    post="1"
  else:
    post=S[i]
ans=rep*(K//2)
if K%2==1:
  if post!=s[0] or K==1:
    ans+=rep-later
  else:
    ans+=later
print(ans-1)

Submission status: Wrong Answer

Solution code:
s=input()
S=s+s
K=int(input())
post=S[0]
rep=0
later=0
for i in range(1,len(S)):
  if S[i]==post:
    rep+=1
    if i>=len(s):
      later+=1
    post="1"
  else:
    post=S[i]
ans=rep*(K//2)
if K%2==1:
  if post!=s[0] or K==1:
    ans+=rep-later
  else:
    ans+=later
print(ans+1)

Submission status: Wrong Answer

Solution code:
s=input()
S=s+s
K=int(input())
post=S[0]
rep=0
later=0
for i in range(1,len(S)):
  if S[i]==post:
    rep+=1
    if i>=len(s):
      later+=1
    post="1"
  else:
    post=S[i]
ans=rep*(K//2)
if K%2==1:
  if post!=s[0] or K==1:
    ans+=rep-later
  else:
    ans+=later
print(ans)

Submission status: Wrong Answer

Solution code:
s=input()
S=s+s
K=int(input())
post=S[0]
rep=0
later=0
for i in range(1,len(S)):
  if S[i]==post:
    rep+=1
    if i>=len(s):
      later+=1
    post="1"
  else:
    post=S[i]
ans=rep*(K//2)
if K%2==1:
  if post!=s[0]:
    ans+=rep-later
  else:
    ans+=later
print(ans)