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:
import itertools
s = input()
n = int(input())

check_str=[[k, len(list(g))] for k, g in itertools.groupby(s)]
c = 0
for i in range(len(check_str)):
	c += check_str[i][1]//2
if c == 0:
	if check_str[0] == check_str[-1]:
		print("%d" % (n//2))
	else:
		print(0)
else:
	print("%d" % (c*n))

Submission status: Wrong Answer

Solution code:
import itertools
s = input()
n = int(input())

check_str=[[k, len(list(g))] for k, g in itertools.groupby(s)]
c = 0
for i in range(len(check_str)):
	c += check_str[i][1]//2

print("%d" % (c*n))

Submission status: Wrong Answer

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

sequence = 0
count = 0
primary = 0
last = 0

if S[0] != S[-1]:
    for i in range(len(S)-1):
        if S[i] == S[i+1]:
            count += 1
        else:
            sequence += (count + 1) // 2
            count = 0
    else:
        sequence += (count + 1) // 2
        print(sequence * K)
else:
    for i in range(len(S)-1):
        if S[-1-i] == S[-2-i]:
            count += 1
        else:
            last += count + 1
            break
            
    count = 0
            
    for i in range(len(S)-1):
        if i >= (len(S) - last):
            pass
        else:
            if primary != 0:
                if S[i] == S[i+1]:
                    count += 1
                else:
                    sequence += (count + 1) // 2
                    count = 0
            else:
                if S[i] == S[i+1]:
                    count += 1
                else:
                    primary += count + 1
                    count = 0
    else:
        sequence += (count + 1) // 2
        count = 0
        
        pl = ((primary + last) // 2) * (K - 1) + (primary // 2) + (last // 2)
        print(sequence * K + pl)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!

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

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

if flag:
    print(N*K // 2)
    exit()
cnt = 0
for i in range(1,N):
    if S[i] == S[i-1]:
        cnt += 1
        S[i] = "$"
ans = cnt * K
if S[0] == S[N-1]:
    head = 1
    tail = 1
    i = 0
    while S[i] == S[i+1]:
        head += 1
        i += 1
    i = N-1
    while S[i] == S[i-1]:
        tail += 1
        i -= 1
    if (head + tail) % 2 == 0:
        ans += K-1
print(ans)

Submission status: Wrong Answer

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

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

if flag:
    print(N*K // 2)
    exit()
cnt = 0
for i in range(1,N):
    if S[i] == S[i-1]:
        cnt += 1
        S[i] = "$"
ans = cnt * K
if S[0] == S[N-1]:
    ans += K-1
print(ans)

Submission status: Wrong Answer

Solution code:
s=input()
k=int(input())
ls=len(s)
t=""
for i in range(1):
    t+=s[0:ls]

lt=0
ex=0
if ls ==1:
    if k%2==0:
        ex=k//2
    else:
        k-=1
        ex=k//2
elif ls==2:
    if s[0]==s[1]:
        ex=k
    else:
        ex=0
else:
    if ls >=3:    
        for i in range(ls*1):
            try:
                t[lt+1]
            except IndexError:
                lt+=1
            else:
                if t[lt]==t[lt+1]:
                    ex+=1
                    try:
                        t[lt+2]
                    except IndexError:
                        lt+=1
                    else:
                        if t[lt+1]==t[lt+2]:
                            
                            lt+=2
                        else:
                            
                            lt+=1
                else:
                    lt+=1
                
    if s[0]==s[ls-1]:
        left=1
        for i in range(ls-1):
            if s[i]!=s[i+1]:
                break
            else:
                left+=1
        right =1
        for i in range(ls-1,0,-1):
            if s[i]!=s[i-1]:
                break
            else:
                right+=1
        if left%2==0 or right%2==0:
            ex*=k
        else:
            ex+=1
            ex*=k
            ex-=1
    else:
        ex*=k
print(ex)

Submission status: Wrong Answer

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

cnt = 0
for i in range(1,N):
    if S[i] == S[i-1]:
        cnt += 1
        S[i] = "$"
ans = cnt * K
if S[0] == S[N-1]:
    ans += K-1
print(ans)

Submission status: Wrong Answer

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

cnt = 0
changed = [False for i in range(N)]
for i in range(1,N):
    if S[i] == S[i-1] and not changed[i-1]:
        cnt += 1
        changed[i] = True
ans = cnt * K
if S[0] == S[N-1] and not changed[N-1]:
    ans += K-1

print(ans)

Submission status: Wrong Answer

Solution code:
import sys

input = sys.stdin.readline

S = input().strip()
K = int(input())

fnum = 0
pre = ''
num = 0
for ts in S:
	if ts==pre:
		num += 1
	else:
		fnum += num//2
		num = 1
		pre = ts
fnum += num//2

snum = 0
pre = ''
num = 0
for ts in S+S:
	if ts==pre:
		num += 1
	else:
		snum += num//2
		num = 1
		pre = ts
snum += num//2

ans = fnum + (snum-fnum)*(K-1)

print(ans)

Submission status: Wrong Answer

Solution code:
import sys

input = sys.stdin.readline

S = input().strip()
K = int(input())

fs = S[0]
fnum = 1
fi = len(S)-1
for i, ts in enumerate(S[1:]):
	if ts==fs:
		fnum += 1
	else:
		fi = i+1
		break
fnum = fnum//2

if fi==len(S)-1:
	ans = (len(S)*K)//2
else:
	ls = S[-1]
	lnum = 1
	for i, ts in enumerate(S[-2::-1]):
		if ts==ls:
			lnum += 1
		else:
			li = len(S)-i-2
			break
	lnum = lnum//2

	mnum = 0
	pre = ''
	num = 0
	for ts in S[fi:li+1]:
		if ts==pre:
			num += 1
		else:
			mnum += num//2
			num = 1
			pre = ts
	mnum += num//2

	if S[0]==S[-1]:
		clen = len(S)-(li-fi+1)
		cnum = clen//2
	else:
		cnum = 0

	ans = fnum + lnum + mnum*K + cnum*(K-1)

print(ans)

Submission status: Wrong Answer

Solution code:
s=input()
k=int(input())
ss=len(s)
ans=0
aans=0
try:
  if s[0]==s[ss-1]and s[0]!=s[1] and s[ss-1]!=s[ss-2]:
    pass
except IndexError:
  print(k-1)
else :
  kaisu=0  
  kaisuu=0
  mae=s[0]
  for ii in range (ss):
    if s[ii] !=mae:
      break
    else:
      mae=s[ii]
      kaisu+=1
  gyaku =list(reversed(s))
  for iii in range (ss):
    if gyaku[iii] !=mae:
      break
    else:
      mae=gyaku[iii]
      kaisuu+=1    
  if kaisu %2 ==1 and kaisuu %2==1 and (kaisu+kaisuu)%2==0:
    if k %2==0:
      aans=k-1
    else :
      aans=k-2
  chkk=0
  for i in range (ss-1):
    if s[i] == s[i+1]and chkk==0:
      ans+=1
      chkk=1
    else:
      chkk=0
  print(ans*k+aans)

Submission status: Wrong Answer

Solution code:
S=input()
K=int(input())
s=list(S*2)
c=0
for i in range(len(s)-2):
    t=set(s[i:i+2])
    if len(t)==1:
        s[i+1]="@"
        c+=1
if s[0]==s[-1]:c+=1
print(int(c*K/2))

Submission status: Wrong Answer

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

count=0

if len(S)>=4:
  for i in range(len(S)-2):
      if i>=1:  
        if  S[i]==S[i+1]:
          count+=K
  if S[0]==S[len(S)-1]:
    count+=K-1
  elif S[0]==S[1] or S[len(S)-2]==S[len(S)-1]:
    count+=K
elif len(S)==3:
  if S[0]==S[2]:
    count+=K-1
  elif S[0]==S[1] or S[1]==S[2]:
    count+=K
elif len(S)==2:
  if S[0]==S[1]:
    count+=K-1
elif len(S)==1:
  if K%2==1:
    count+=K//2
  else:
    count+=K/2
print(count)

Submission status: Wrong Answer

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

count=0

if len(S)>=4:
  for i in range(len(S)-2):
      if i>=1:  
        if  S[i]==S[i+1]:
          count+=K
  if S[0]==S[len(S)-1]:
    count+=K-1
  elif S[0]!=S[len(S)-1] and (S[0]==S[1] or S[len(S)-2]==S[len(S)-1]):
    count+=K
elif len(S)==3:
  if S[0]==S[2]:
    count+=K-1
  elif S[0]==S[1] or S[1]==S[2]:
    count+=K
elif len(S)==2:
  if S[0]==S[1]:
    count+=K-1
elif len(S)==1:
  if K%2==1:
    count+=K//2
  else:
    count+=K/2
print(count)

Submission status: Wrong Answer

Solution code:
s=input()
k=int(input())
ss=len(s)
ans=0
aans=0
try:
  if s[0]==s[ss-1]and s[0]!=s[1] and s[ss-1]!=s[ss-2]:
    pass
except IndexError:
  print(k-1)
else :
  kaisu=0  
  kaisuu=0
  mae=s[0]
  for ii in range (ss):
    if s[ii] !=mae:
      break
    else:
      mae=s[ii]
      kaisu+=1
  gyaku =list(reversed(s))
  for iii in range (ss):
    if gyaku[iii] !=mae:
      break
    else:
      mae=gyaku[iii]
      kaisuu+=1    
  if kaisu %2 ==1 and kaisuu %2==1 and (kaisu+kaisuu)%2==0:
    aans=k-1
  chkk=0
  for i in range (ss-1):
    if s[i] == s[i+1]and chkk==0:
      ans+=1
      chkk=1
    else:
      chkk=0
  print(ans*k+aans)

Submission status: Wrong Answer

Solution code:
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools, pdb
sys.setrecursionlimit(10**7)
from queue import PriorityQueue
from fractions import gcd
inf, eps, mod = 10 ** 20, 1.0 / 10**10, 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def _I(): return int(sys.stdin.readline())
def _F(): return float(sys.stdin.readline())
def _pf(s): return print(s, flush=True)
def _cumsum(l): return list(itertools.accumulate(l)) 
"""
なかのものと端のもの
両端が一緒かどうか
一緒なら、K-1個変える
中を変える/2切り下げ
まず、端が一緒か
"""
S = input()
K = _I()
ans = 0

if len(set(S)) == 1:
    print(int(math.floor(len(S)*K/2)))
    exit()

if K >= 10:
    S = S*10
else:
    S = S*K

torn_list = []

previous = 'hoge'
for s in S:
    if previous == s:
        torn_list[-1] += 1
    else:
        previous = s
        torn_list.append(1)
#  print(torn_list)
if K <= 9:
    for t in torn_list:
        ans += math.floor(t/2)
else:
    for t in torn_list[1:-1]:
        if t >= 2:
            ans += int(math.floor(t/2))
    ans = ans / 10 * K
    # 真ん中の部分だけ計算

    # 端を足す
    ans += math.floor(torn_list[0]/2)
    ans += math.floor(torn_list[-1]/2)
print(int(ans))
"""
aba
5
なら
aba aba aba aba aba
端は0 0
中が
1 1 1 1で4つ
3で4つなら、100で99つ

abba
5
なら
abba abba abba abba abba
bbがK回

"""

Submission status: Wrong Answer

Solution code:
s = input()
s2=s+s
k = int(input())
flag = False
result = 0
for i in range(len(s)):
        if flag:
                flag = False
                continue

        if s2[i] == s2[i+1]:
                flag = True
                result += 1
result *= k
print(result)

Submission status: Wrong Answer

Solution code:
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools, pdb
sys.setrecursionlimit(10**7)
from queue import PriorityQueue
from fractions import gcd
inf, eps, mod = 10 ** 20, 1.0 / 10**10, 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def _I(): return int(sys.stdin.readline())
def _F(): return float(sys.stdin.readline())
def _pf(s): return print(s, flush=True)
def _cumsum(l): return list(itertools.accumulate(l)) 
"""
なかのものと端のもの
両端が一緒かどうか
一緒なら、K-1個変える
中を変える/2切り下げ
まず、端が一緒か
"""
S = input()
K = _I()
ans = 0

if len(set(S)) == 1:
    print(int(math.floor(len(S)*K/2)))
    exit()

if K >= 10:
    S = S*10
else:
    S = S*K

torn_list = []

previous = 'hoge'
for s in S:
    if previous == s:
        torn_list[-1] += 1
    else:
        previous = s
        torn_list.append(1)
#  print(torn_list)
if K <= 9:
    for t in torn_list:
        ans += math.floor(t/2)
else:
    for t in torn_list:
        if t >= 2:
            ans += int(math.floor(t/2))
    ans = ans / 10 * K
    # 端を足す
    #  ans += math.floor(torn_list[0]/2)
    #  ans += math.floor(torn_list[-1]/2)
print(int(ans))
"""
aba
5
なら
aba aba aba aba aba
端は0 0
中が
1 1 1 1で4つ
3で4つなら、100で99つ

abba
5
なら
abba abba abba abba abba
bbがK回

"""

Submission status: Wrong Answer

Solution code:
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools, pdb
sys.setrecursionlimit(10**7)
from queue import PriorityQueue
from fractions import gcd
inf, eps, mod = 10 ** 20, 1.0 / 10**10, 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def _I(): return int(sys.stdin.readline())
def _F(): return float(sys.stdin.readline())
def _pf(s): return print(s, flush=True)
def _cumsum(l): return list(itertools.accumulate(l)) 
"""
なかのものと端のもの
両端が一緒かどうか
一緒なら、K-1個変える
中を変える/2切り下げ
まず、端が一緒か
"""
S = input()
K = _I()
ans = 0

if len(set(S)) == 1:
    print(int(math.floor(len(S)*K/2)))
    exit()

if K >= 10:
    S = S*10
else:
    S = S*K

torn_list = []

previous = 'hoge'
for s in S:
    if previous == s:
        torn_list[-1] += 1
    else:
        previous = s
        torn_list.append(1)
#  print(torn_list)
if K <= 9:
    for t in torn_list:
        ans += math.floor(t/2)
else:
    for t in torn_list:
        if t >= 2:
            ans += math.floor(t/2)
    ans = ans / 10 * K
    # 端を足す
    #  ans += math.floor(torn_list[0]/2)
    #  ans += math.floor(torn_list[-1]/2)
print(int(ans))
"""
aba
5
なら
aba aba aba aba aba
端は0 0
中が
1 1 1 1で4つ
3で4つなら、100で99つ

abba
5
なら
abba abba abba abba abba
bbがK回

"""

Submission status: Wrong Answer

Solution code:
s=input()
k=int(input())
ss=len(s)
ans=0
aans=0
try:
  if s[0]==s[ss-1]and s[0]!=s[1] and s[ss-1]!=s[ss-2]:
    pass
except IndexError:
  print(k-1)
else :
  if s[0]==s[ss-1]and s[0]!=s[1] and s[ss-1]!=s[ss-2] :
    aans=k-1
  chkk=0
  for i in range (ss-1):
    if s[i] == s[i+1]and chkk==0:
      ans+=1
      chkk=1
    else:
      chkk=0
  print(ans*k+aans)

Submission status: Wrong Answer

Solution code:
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools, pdb
sys.setrecursionlimit(10**7)
from queue import PriorityQueue
from fractions import gcd
inf, eps, mod = 10 ** 20, 1.0 / 10**10, 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def _I(): return int(sys.stdin.readline())
def _F(): return float(sys.stdin.readline())
def _pf(s): return print(s, flush=True)
def _cumsum(l): return list(itertools.accumulate(l)) 
"""
なかのものと端のもの
両端が一緒かどうか
一緒なら、K-1個変える
中を変える/2切り下げ
まず、端が一緒か
"""
S = input()
K = _I()
ans = 0

if len(set(S)) == 1:
    print(int(math.floor(len(S)*K/2)))
    exit()

if K >= 10:
    S = S*10
else:
    S = S*K

torn_list = []

previous = 'hoge'
for s in S:
    if previous == s:
        torn_list[-1] += 1
    else:
        previous = s
        torn_list.append(1)
#  print(torn_list)
if K <= 9:
    for t in torn_list:
        ans += math.floor(t/2)
else:
    for t in torn_list[1:-1]:
        if t >= 2:
            ans += math.floor(t/2)
    ans = ans / 10 * K
    # 端を足す
    ans += math.floor(torn_list[0]/2)
    ans += math.floor(torn_list[-1]/2)
print(int(ans))

Submission status: Wrong Answer

Solution code:
s=input()
k=int(input())
ss=len(s)
ans=0
aans=0
try:
  if s[0]==s[ss-1]and s[0]!=s[1] and s[ss-1]!=s[ss-2]:
    pass
except IndexError:
  print(k-1)
else :
  if s[0]==s[ss-1]and s[0]!=s[1] and s[ss-1]!=s[ss-2] :
    aans=k-1
  chkk=0
  for i in range (ss-1):
    if s[i] == s[i+1]and chkk==0:
      ans+=1
      chkk=1
    else:
      chkk=0
  print(ans*k+aans)

Submission status: Wrong Answer

Solution code:
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools, pdb
sys.setrecursionlimit(10**7)
from queue import PriorityQueue
from fractions import gcd
inf, eps, mod = 10 ** 20, 1.0 / 10**10, 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def _I(): return int(sys.stdin.readline())
def _F(): return float(sys.stdin.readline())
def _pf(s): return print(s, flush=True)
def _cumsum(l): return list(itertools.accumulate(l))

"""
なかのものと端のもの
両端が一緒かどうか
一緒なら、K-1個変える
中を変える/2切り下げ
まず、端が一緒か
"""
S = input()
K = _I()
ans = 0

if len(set(S)) == 1:
    print(int(math.floor(len(S)*K/2)))
    exit()

if K >= 10:
    S = S*10
else:
    S = S*K

torn_list = []

previous = 'hoge'
for s in S:
    if previous == s:
        torn_list[-1] += 1
    else:
        previous = s
        torn_list.append(1)
#  print(torn_list)
if K <= 9:
    for t in torn_list:
        ans += math.floor(t/2)
else:
    for t in torn_list[1:-1]:
        if t >= 2:
            ans += math.floor(t/2) / 10 * K
    # 端を足す
    ans += math.floor(torn_list[0]/2)
    ans += math.floor(torn_list[-1]/2)
print(int(ans))

Submission status: Wrong Answer

Solution code:
s=input()
k=int(input())
ss=len(s)
ans=0
aans=0
try:
  print(s[0]==s[ss-1]and s[0]!=s[1] and s[ss-1]!=s[ss-2])
except IndexError:
  print(k-1)
else :
  if s[0]==s[ss-1]and s[0]!=s[1] and s[ss-1]!=s[ss-2] :
    aans=k-1
  chkk=0
  for i in range (ss-1):
    if s[i] == s[i+1]and chkk==0:
      ans+=1
      chkk=1
    else:
      chkk=0
  print(ans*k,aans)

Submission status: Wrong Answer

Solution code:
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools, pdb
sys.setrecursionlimit(10**7)
from queue import PriorityQueue
from fractions import gcd
inf, eps, mod = 10 ** 20, 1.0 / 10**10, 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def _I(): return int(sys.stdin.readline())
def _F(): return float(sys.stdin.readline())
def _pf(s): return print(s, flush=True)
def _cumsum(l): return list(itertools.accumulate(l))

"""
なかのものと端のもの
両端が一緒かどうか
一緒なら、K-1個変える
中を変える/2切り下げ
まず、端が一緒か
"""
S = input()
K = _I()
ans = 0

if len(set(S)) == 1:
    print(math.floor(len(S)*K/2))
    exit()

if K >= 10:
    S = S*10
else:
    S = S*K

torn_list = []

previous = 'hoge'
for s in S:
    if previous == s:
        torn_list[-1] += 1
    else:
        previous = s
        torn_list.append(1)
#  print(torn_list)
if K <= 9:
    for t in torn_list:
        ans += math.floor(t/2)
else:
    for t in torn_list[1:-1]:
        if t >= 2:
            ans += math.floor(t/2) / 10 * K
    # 端を足す
    ans += math.floor(torn_list[0]/2)
    ans += math.floor(torn_list[-1]/2)
print(int(ans))

Submission status: Wrong Answer

Solution code:
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools, pdb
sys.setrecursionlimit(10**7)
from queue import PriorityQueue
from fractions import gcd
inf, eps, mod = 10 ** 20, 1.0 / 10**10, 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def _I(): return int(sys.stdin.readline())
def _F(): return float(sys.stdin.readline())
def _pf(s): return print(s, flush=True)
def _cumsum(l): return list(itertools.accumulate(l))

"""
なかのものと端のもの
両端が一緒かどうか
一緒なら、K-1個変える
中を変える/2切り下げ
まず、端が一緒か
"""
S = input()
K = _I()
ans = 0

if len(set(S)) == 1:
    print(math.floor(len(S)*K/2))
    exit()

if K >= 10:
    S = S*10
else:
    S = S*K

torn_list = []

previous = 'hoge'
for s in S:
    if previous == s:
        torn_list[-1] += 1
    else:
        previous = s
        torn_list.append(1)
#  print(torn_list)
if K <= 9:
    for t in torn_list:
        ans += math.floor(t/2)
else:
    for t in torn_list[1:-1]:
        if t >= 2:
            ans += math.floor(t/2) / 10 * K
    # 端を足す
    ans += math.floor(torn_list[0]/2)
    ans += math.floor(torn_list[-1]/2)
print(ans)

Submission status: Wrong Answer

Solution code:
S=str(input())
S1=list(S)
S2=list(S)
K=int(input())
ans1=0
ans2=0
ans3=0
ans4=0

for i in range(1,len(S1)):
    if S1[i] == S1[i-1]:
        ans1 += 1
        S1[i] = '_'
if S1[0] == S1[-1]:
    ans2 = 1

for j in range(len(S2)-1):
    if S2[j] == S2[j+1]:
        ans3 += 1
        S2[j] = '_'
if S2[0] == S2[-1]:
    ans4 = 1

ans = min(ans1*K+ans2*(K-1),ans3*K+ans4*(K-1))
print(ans)

Submission status: Wrong Answer

Solution code:
txt, n = [input() for i in range(2)]
n = int(n)

first_flg = True
present_char = txt[0]
present_cnt = 0
numlen_list = []

for x in txt:
  if x == present_char:
    present_cnt += 1
  else:
    first_flg = False
    numlen_list.append(present_cnt)
    present_cnt = 1
    present_char = x

numlen_list.append(present_cnt)
guruguru_flg = (txt[0] == txt[-1])

if len(numlen_list) == 1:
  print(numlen_list[0] * n // 2)
elif guruguru_flg:
  print(sum([x // 2 for x in numlen_list[1:-1]])*n
        + (numlen_list[0] + numlen_list[1]) // 2 * (n-1)
        + numlen_list[0] // 2
        + numlen_list[-1] // 2)
else:
  print(sum([x // 2 for x in numlen_list]) * n)

Submission status: Wrong Answer

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

for i in range(len(S)-1):
    if S[i]==S[i+1]:
        S[i+1]='A'
        cnt+=1
cnt*=K

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

print(cnt)

Submission status: Wrong Answer

Solution code:
txt, n = [input() for i in range(2)]
n = int(n)

first_flg = True
present_char = txt[0]
present_cnt = 0
numlen_list = []

for x in txt:
  if x == present_char:
    present_cnt += 1
  else:
    first_flg = False
    numlen_list.append(present_cnt)
    present_cnt = 1
    present_char = x

numlen_list.append(present_cnt)
guruguru_flg = (txt[0] == txt[-1])

if len(numlen_list) == 1:
  print(len(numlen_list) * n // 2)
elif guruguru_flg:
  print(sum([x // 2 for x in numlen_list[1:-1]])*n
        + (numlen_list[0] + numlen_list[1]) // 2 * (n-1)
        + numlen_list[0] // 2
        + numlen_list[-1] // 2)
else:
  print(sum([x // 2 for x in numlen_list]) * n)

Submission status: Wrong Answer

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

if len(set(S))==1:
  print(N*K//2)
else:
  if S[0]!=S[-1]:
    cnt=1
    ans=0
    for i in range(1,N):
      if S[i]==S[i-1]:
        cnt+=1
      else:
        ans+=cnt//2
        cnt=1
    print(ans*K)
  else:
    fi,bi=0,0
    for i in range(N):
      if S[i]!=S[0]:
        fi=i
        break
    for i in range(N-1,-1,-1):
      if S[i]!=S[-1]:
        bi=i
        break
    #print(fi,bi)
    
    tmp=0
    cnt=1
    for i in range(fi,bi+1):
      if S[i]==S[i-1]:
        cnt+=1
      else:
        tmp+=cnt//2
        cnt=1
    tmp+=cnt//2
    #print(tmp)
    #print(fi,N-bi-1)
    print(K*tmp+fi//2+(N-bi-1)//2+(fi+N-bi-1)//2*(K-1))

Submission status: Wrong Answer

Solution code:
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools, pdb
sys.setrecursionlimit(10**7)
from queue import PriorityQueue
from fractions import gcd
inf, eps, mod = 10 ** 20, 1.0 / 10**10, 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def _I(): return int(sys.stdin.readline())
def _F(): return float(sys.stdin.readline())
def _pf(s): return print(s, flush=True)
def _cumsum(l): return list(itertools.accumulate(l))

"""
なかのものと端のもの
両端が一緒かどうか
一緒なら、K-1個変える
中を変える/2切り下げ
まず、端が一緒か
"""
S = input()
K = _I()
ans = 0
#  if K <= 5:
#      print(S*K)

if len(S) == 1:
    print(math.floor(K//2))
    exit()
if len(S) == 2:
    if S[0] == S[1]:
        print(K)
    else:
        print(0)
    exit()

if len(set(S)) == 1:
    print(math.floor(len(S) * K / 2))
    exit()

# 端変えないので、中だけ
#  previous = 'HOGE'
#  for s in S:
#      if s == previous:
#          ans += K
#          previous = 'HOGE'
#      else:
#          previous = s

# 連続する部分を抜き出して数える


original_last_char = S[-1]
if S[0] == S[-1]:
    S = S[:-1] + '?'
    ans += K - 1
    # 端は上で変えられた
else:
    pass
#  print('hashi', ans)

torn_list = []
previous = 'hoge'
for s in S:
    #  print(s)
    if s == previous:
        torn_list[-1] += 1
    else:
        torn_list.append(1)
        previous = s

#  print(torn_list)

for item in torn_list:
    if item >= 2:
        ans += math.floor(item/2)*K
#  print('torn', ans)
# last K
if S[-1] == '?':
    #  pdb.set_trace()
    last_sequence = torn_list[-2]
    ans -= math.floor(last_sequence/2)
    if original_last_char == S[-2]:
        last_sequence += 1
    if last_sequence >= 2:
        ans += math.floor(last_sequence/2)

print(ans)

Submission status: Wrong Answer

Solution code:
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools, pdb
sys.setrecursionlimit(10**7)
from queue import PriorityQueue
from fractions import gcd
inf, eps, mod = 10 ** 20, 1.0 / 10**10, 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def _I(): return int(sys.stdin.readline())
def _F(): return float(sys.stdin.readline())
def _pf(s): return print(s, flush=True)
def _cumsum(l): return list(itertools.accumulate(l))

"""
なかのものと端のもの
両端が一緒かどうか
一緒なら、K-1個変える
中を変える/2切り下げ
まず、端が一緒か
"""
S = input()
K = _I()
ans = 0
#  if K <= 5:
#      print(S*K)

if len(S) == 1:
    print(math.floor(K//2))
    exit()
if len(S) == 2:
    if S[0] == S[1]:
        print(K)
    else:
        print(0)
    exit()


# 端変えないので、中だけ
#  previous = 'HOGE'
#  for s in S:
#      if s == previous:
#          ans += K
#          previous = 'HOGE'
#      else:
#          previous = s

# 連続する部分を抜き出して数える


original_last_char = S[-1]
if S[0] == S[-1]:
    S = S[:-1] + '?'
    ans += K - 1
    # 端は上で変えられた
else:
    pass
#  print('hashi', ans)

torn_list = []
previous = 'hoge'
for s in S:
    #  print(s)
    if s == previous:
        torn_list[-1] += 1
    else:
        torn_list.append(1)
        previous = s

#  print(torn_list)

for item in torn_list:
    if item >= 2:
        ans += math.floor(item/2)*K
#  print('torn', ans)
# last K
if S[-1] == '?':
    #  pdb.set_trace()
    last_sequence = torn_list[-2]
    ans -= math.floor(last_sequence/2)
    if original_last_char == S[-2]:
        last_sequence += 1
    if last_sequence >= 2:
        ans += math.floor(last_sequence/2)

print(ans)

Submission status: Wrong Answer

Solution code:
def olcnt(s):
    i = 0
    lst = []
    while i < len(s):
        j = 1
        while i + j < len(s) and s[i] == s[i + j]:
            j += 1
        lst.append((s[i], j))
        i += j
    return lst
 
  
s = list(input())
k = int(input())
 
if len(set(s)) == 1:
    print(int(len(s)*k/2))
else:
    cnt1 = sum([int(x[1]/2) for x in olcnt(s)])
 
    print(cnt1 *k)

Submission status: Wrong Answer

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

c = [0] * len(s)
for i in range(len(s)):
    if i == len(s) - 1:
        if k == 1:
            continue
        if s[i] == s[0]:
            c[i] = 1
    elif s[i] == s[i+1]:
        c[i] = 1

if len(s) == 1:
    print(k // 2)
else:
    # print(c)
    ans = 0
    f = 0
    for i in range(len(s)):
        if c[i] == 1 and f == 0:
            ans += 1
            f = 1
        elif f == 1:
            f = 0
    
    print(ans*k-1)

Submission status: Wrong Answer

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

c = [0] * len(s)
for i in range(len(s)):
    if i == len(s) - 1:
        if k == 1:
            continue
        if s[i] == s[0]:
            c[i] = 1
    elif s[i] == s[i+1]:
        c[i] = 1

if len(s) == 1:
    print(k // 2)
else:
    # print(c)
    ans = 0
    f = 0
    for i in range(len(s)):
        if c[i] == 1 and f == 0:
            ans += 1
            f = 1
        elif f == 1:
            f = 0
    
    print(ans*k)

Submission status: Wrong Answer

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

c = [0] * len(s)
for i in range(len(s)):
    if i == len(s) - 1:
        if k == 1:
            continue
        if s[i] == s[0]:
            c[i] = 1
    elif s[i] == s[i+1]:
        c[i] = 1

if len(s) == 1:
    print(k // 2)
else:
    # print(c)
    ans = 0
    f = 0
    for i in range(len(s)):
        if c[i] == 1 and f == 0:
            ans += 1
            f = 1
        elif f == 1:
            f = 0

    if c[-1] + c[-2] == 1 and k > 2 :
        print(ans*k-1)
    else:
        print(ans*k)

Submission status: Wrong Answer

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

c = [0] * len(s)
for i in range(len(s)):
    if i == len(s) - 1:
        if k == 1:
            continue
        if s[i] == s[0]:
            c[i] = 1
    elif s[i] == s[i+1]:
        c[i] = 1

# print(c)
ans = 0
f = 0
for i in range(len(s)):
    if c[i] == 1 and f == 0:
        ans += 1
        f = 1
    elif f == 1:
        f = 0

print(ans*k)

Submission status: Wrong Answer

Solution code:
def get(s):
	ans = 0
	n = len(s)
	for i in range(0, n):
		if i == 0 or s[i - 1] != s[i]:
			ted = 0
			for j in range(i, n):
				if s[j] != s[i]:
					break
				ted += 1
			ans += ted // 2
	return ans
s = input()
k = int(input())
a = get(s)
s = s + s
b = get(s)

print(a + (k - 1) * (b - a))