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=input()
t=int(input())
b=0
c=0
for i in range(c,len(s)-1):
  a=1
  for j in range(c+1,len(s)):
    if s[c]==s[j]:
      a+=1
    else:
      c=j
      break
  c=j
  b+=(a//2)
b=b*t
if s[0]==s[len(s)-1]:
  a=1
  c=1
  for k in range(len(s)-1):
    if s[k]==s[k+1]:
      c+=1
    else:
      break
  u=s[::-1]
  for l in range(len(s)-1):
    if u[l]==u[l+1]:
      a+=1
    else:
      break
  if a%2==1 and c%2==1:
    b+=t-1
if len(s)==1:
  b=t//2
print(b)

Submission status: Wrong Answer

Solution code:
S = list(input())
K = int(input())
cnt = 1
ans = 0
counter = []

if len(S) == 1:
  print(len(S)*K//2)
  
else:
  for i in range(len(S)-1):
    if S[i] == S[i+1]:
      cnt += 1
    else:
      counter.append(cnt)
      cnt = 1
  counter.append(cnt)
    
  for l in counter:
    ans += (l//2)*K

  if S[0] == S[-1]:
    a = counter[0]
    b = counter[-1]
    ans -= (a//2 + b//2 - (a+b)//2)*(K-1)
  
  print(ans)

Submission status: Wrong Answer

Solution code:
s = input()
k = int(input())
t = ''
i = 0
count = 0
start = 0
end = 0
if k == 0 or k == 1 :
	print(0)
for i in range(len(s)-1):
	if s[i] == s[i+1]:
		count +=1

if count == len(s)-1:#すべて同じ場合
	print(-(-count//2)*k)

elif s[0] != s[len(s)-1]:#先頭と末尾が異なる場合
	print(-(-count//2)*k)

elif s[0] == s[len(s)-1]:#先頭と末尾が同じ場合
	for i in range(len(s)):
		if s[0] == s[i+1]: 
			start += 1
		else:
			break
	for i in range(len(s)-1,0,-1):
		if s[len(s)-1] == s[i-1]:
			end += 1
		else:
			break
	print(start,end,count)
	print ((-(-count)*k)-(k-1)*(((-(-start//2))+(-(-end//2)+((-(start+end))//2)))))

Submission status: Wrong Answer

Solution code:
from itertools import*
s,k=open(0);k=int(k);x=0
g=[len(list(v))for k,v in groupby(s)]
for c in g:x+=c//2
x*=k
if s[-1]==s[0]:
	if g[0]%2 or g[-1]%2:pass
	elif len(s)==g[0]:y+=k//2
	else:x+=k-1
print(x)

Submission status: Wrong Answer

Solution code:
from itertools import*
s,k=open(0);k=int(k);x=0
g=[len(list(v))for k,v in groupby(s)]
for c in g:x+=c//2
x*=k
if s[-1]==s[0]:
	if g[0]%2 and g[-1]%2:pass
	elif len(s)==g[0]:y+=k//2
	else:x+=k-1
print(x)

Submission status: Wrong Answer

Solution code:
S = input()

K = int(input())

mycnt = 0
mynum = 1
for i in range(len(S)-1):
    if S[i] == S[i+1]:
        mynum += 1
    else: 
        if mynum > 1:
            mycnt += mynum//2
            mynum = 1

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

elif S[0] != S[-1]:
    
    print(mycnt * K)

else:
    myleft = 1
    myright = 0
    mys = S[0]
    i = 1
    while S[i] == mys:
        myleft += 1
        i += 1
    
    myright = 0
    i = -1
    while S[i] == mys:
        myright += 1
        i -= 1
    print( (mycnt * K) - ( myleft//2 + myright//2 - (myright + myleft)//2 ) * ( K - 1 ) )

Submission status: Wrong Answer

Solution code:
S = list(input())
K = int(input())
cnt = 1
ans = 0
counter = []

if len(S) == 1:
  print(len(S)*K//2)
  exit()
  
else:
  for i in range(len(S)-1):
    if S[i] == S[i+1]:
      cnt += 1
    else:
      counter.append(cnt)
      cnt = 1
  counter.append(cnt)
    
  for l in counter:
    ans += (l//2)*K

  if S[0] == S[-1]:
    a = counter[0]
    b = counter[-1]
    ans -= (a//2 + b//2 - (a+b)//2)*(K-1)
  
  print(ans)

Submission status: Wrong Answer

Solution code:
S = list(input())
K = int(input())
cnt = 1
ans = 0
counter = []

if len(S) == 1:
  print(len(S)*K//2)
  exit()
  
else:
  for i in range(len(S)-1):
    if S[i] == S[i+1]:
      cnt += 1
    else:
      counter.append(cnt)
      cnt = 1
  counter.append(cnt)
    
  for l in counter:
    ans += l//2 * K

  if S[0] == S[-1]:
    a = counter[0]
    b = counter[-1]
    ans -= (a//2 + b//2 - (a+b)//2)*(K-1)
  
  print(ans)

Submission status: Wrong Answer

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

            temp_4 = 0
            if temp > 1:
                temp_4 += temp
            elif temp_2 > 2:
                temp_4 += temp_2
            cnt += temp_4 * (K-1)


        print(cnt)

    
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
S = list(input())
K = int(input())
cnt = 1
ans = 0
counter = []

if len(S) == 1:
  print(len(S)*K//2)
  exit()
  
else:
  for i in range(len(S)-1):
    if S[i] == S[i+1]:
      cnt += 1
    else:
      counter.append(cnt)
      cnt = 1
  counter.append(cnt)
    
  for l in counter:
    ans += l//2

  if S[0] == S[-1]:
    a = counter[0]
    b = counter[-1]
    ans -= (a//2 + b//2 - (a+b)//2)*(K-1)
  
  print(ans)

Submission status: Wrong Answer

Solution code:
S = input()

K = int(input())

mycnt = 0
for i in range(len(S)-1):
    if S[i] == S[i+1]:
        mycnt += 1

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

elif S[0] != S[-1]:
    
    print(mycnt * K)

else:
    myleft = 1
    myright = 0
    mys = S[0]
    i = 1
    while S[i] == mys:
        myleft += 1
        i += 1
    
    myright = 0
    i = -1
    while S[i] == mys:
        myright += 1
        i -= 1
    print( (mycnt * K) - ( myleft//2 + myright//2 - (myright + myleft)//2 ) * ( K - 1 ) )

Submission status: Wrong Answer

Solution code:
S = list(input())
K = int(input())
cnt = 1
ans = 0
counter = []

if len(S) == 1:
  print(K//2)
  exit()
  
else:
  for i in range(len(S)-1):
    if S[i] == S[i+1]:
      cnt += 1
    else:
      counter.append(cnt)
      cnt = 1
  counter.append(cnt)
    
  for l in counter:
    ans += l//2*K
  print(ans)
  if S[0] == S[-1]:
    a = counter[0]
    b = counter[-1]
    ans -= (a//2 + b//2 - (a+b)//2)*(K-1)
  
  print(ans)

Submission status: Wrong Answer

Solution code:
s = input()
k = int(input())
t = ''
i = 0
count = 0
start = 0
end = 0

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

if count == len(s)-1:#すべて同じ場合
	print(-(-count//2)*k)

elif s[0] != s[len(s)-1]:#先頭と末尾が異なる場合
	print(-(-count//2)*k)

elif s[0] == s[len(s)-1]:#先頭と末尾が同じ場合
	for i in range(len(s)):
		if s[0] == s[i+1]: 
			start += 1
		else:
			break
	for i in range(len(s)-1,0,-1):
		if s[len(s)-1] == s[i-1]:
			end += 1
		else:
			break
	print(start,end,count)
	print ((-(-count)*k)-(k-1)*(((-(-start//2))+(-(-end//2)+((-(start+end))//2)))))

Submission status: Wrong Answer

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


        print(cnt)

    
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
def inputs():
    return [int(x) for x in input().split()]
S = list(input())
N = int(input())
if len(S)==2:
  print(N-1)
  exit()
ans = 0
flag=0
for i in range(len(S)-2):
    if S[i]==S[i+1]:
        ans +=1
        S[i+1]="aa"
if S[0]==S[-2]:
  ans+=1
  if S[0]==S[1]:
    S[0]="aaa"
  else:
    if S[-2]!=S[-3]:
      flag=1
    S[-2]="aaaa"
if flag==0:
	print(ans*N)
else:
  print(ans*N-1)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from sys import stdin
from itertools import groupby

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

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

li = [len(tuple(s)) for _, s in groupby(s)]

if li == None:
    print(k//2)
    exit

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

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

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

Submission status: Wrong Answer

Solution code:
s = input()
k = int(input())
n = len(s)
ans = []
ss = 0
i = 0
while True:
    if i == n:
        break
    curr = s[i]
    temp = 1
    i += 1
    if i == n :
        break
    while s[i] == curr:
        temp += 1
        i += 1
        if i == n:
            break
    ans.append(temp)
for i in ans:
    ss += (i//2)*k
print(ss)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
def inputs():
    return [int(x) for x in input().split()]
S = list(input())
N = int(input())
if len(S)==2:
  print(N-1)
  exit()
ans = 0
flag=0
if S[0]==S[-2]:
  ans+=1
  if S[0]==S[1]:
    S[0]="aaa"
    flag =1
  else:
    if S[-2]!=S[-3]:
      flag=1
    S[-2]="aaaa"
for i in range(len(S)-2):
    if S[i]==S[i+1]:
        ans +=1
        S[i+1]="aa"
if flag==0:
	print(ans*N)
else:
  print(ans*N-1)

Submission status: Wrong Answer

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

precount = 0

seqcnt = 0
revcnt = 0
if len(set(t)) > 1:
    if k > 1:
        if t[0] == t[-1]:
            for rv in t[::-1]:
                if rv != t[0]:
                    break
                else:
                    revcnt += 1
            for sq in t:
                if sq != t[0]:
                    break
                else:
                    seqcnt += 1
            if (seqcnt + revcnt) % 2 == 1:
                precount += (k - 1) // 2
    for i in range(len(t) - 1):
        if len(list(set(t[i:]))) == len(t[i:]):
            break
        if t[i] == t[i + 1]:
            t[i + 1] = '?'
    ans = precount + t.count("?") * k
else:
    ans = (len(t) * k) // 2

print(ans)

Submission status: Wrong Answer

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


        print(cnt)

    
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
def inputs():
    return [int(x) for x in input().split()]
S = list(input())
N = int(input())
if len(S)==2:
  print(N-1)
  exit()
ans = 0
flag=0
if S[0]==S[-2]:
  ans+=1
  if S[0]==S[1]:
    S[0]="aaa"
  else:
    if S[-2]!=S[-3]:
      flag=1
    S[-2]="aaaa"
for i in range(len(S)-2):
    if S[i]==S[i+1]:
        ans +=1
        S[i+1]="aa"
if flag==0:
	print(ans*N)
else:
  print(ans*N-1)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
def inputs():
    return [int(x) for x in input().split()]
S = list(input())
N = int(input())
if len(S)==2:
  print(N-1)
  exit()
ans = 0
flag=0
if S[0]==S[-2]:
  ans+=1
  if S[0]==S[1]:
    S[0]="aaa"
  else:
    S[-2]="aaaa"
    if S[-2]!=S[-3]:
      flag=1
for i in range(len(S)-2):
    if S[i]==S[i+1]:
        ans +=1
        S[i+1]="aa"
if flag==0:
	print(ans*N)
else:
  print(ans*N-1)

Submission status: Wrong Answer

Solution code:
s = input()
k = int(input())
t = ''
i = 0
count = 0
start = 0
end = 0

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

if count == len(s)-1:#すべて同じ場合
	print(-(-count//2)*k)

elif s[0] != s[len(s)-1]:#先頭と末尾が異なる場合
	print(-(-count//2)*k)

elif s[0] == s[len(s)-1]:#先頭と末尾が同じ場合
	for i in range(len(s)-1):
		if s[0] == s[i+1]: 
			start += 1
		else:
			break
	for i in range(len(s)-1,0):
		if s[len(s)-1] == s[i-1]:
			end += 1
		else:
			break
	print ((-(-count)*k)-(k-1)*(((-(-start//2))+(-(-end//2)+((-(start+end))//2)))))

Submission status: Wrong Answer

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

precount = 0

seqcnt = 0
revcnt = 0
if len(set(t)) > 1:
    if k > 1:
        for rv in t[::-1]:
            if rv != t[0]:
                break
            else:
                revcnt += 1
        for sq in t:
            if sq != t[0]:
                break
            else:
                seqcnt += 1
        if (seqcnt + revcnt) % 2 == 1:
            precount += (k - 1) // 2
    for i in range(len(t) - 1):
        if len(list(set(t[i:]))) == len(t[i:]):
            break
        if t[i] == t[i + 1]:
            t[i + 1] = '?'
    ans = precount + t.count("?") * k
else:
    ans = (len(t) * k) // 2

print(ans)

Submission status: Wrong Answer

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

def f(s):
    i = 0
    n = 0
    while i < len(s)-1:
        if s[i] == s[i+1]:
            n += 1
            i += 2
        else:
            i += 1
    return n

import collections

# 解説 AC のつもり
def main():
    S = input().strip()
    K = int(input())

    # S が全て同じ文字の場合
    if len(collections.Counter(S).keys()) == 1:
        print(len(S)*K//2)
        return

    # S について、変更が必要な回数
    n = f(S)

    # 末尾が異なる場合、n を K 倍すればよい
    if S[0] != S[-1]:
        print(n*K)
        return

    # 以降、末尾が同じ文字の場合

    # 末尾から連続して S[0] が現れる数
    a = 0
    for c in S[::-1]:
        if c == S[0]:
            a += 1
        else:
            break
    # 先頭から連続して S[0] が現れる数
    b = 0
    for c in S:
        if c == S[0]:
            b += 1
        else:
            break

    # まず（接続部を気にせず） n*K とした後、
    ans = n*K
    # K-1 個の S の接続部に対して計算し直す。
    # （S 単体で見たときの変更数を引き、S+S で見たときの変更数を足す）
    ans += (K-1) * (- a//2 - b//2 + (a+b)//2)
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from sys import stdin
from itertools import groupby

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

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

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

if s[-1] != s[-2]:
    li.append(1)

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

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

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

Submission status: Wrong Answer

Solution code:
s = input()
k = int(input())
t = ''
i = 0
count = 0
start = 0
end = 0

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

if count == len(s)-1:#すべて同じ場合
	print(-(-count//2)*k)

elif s[0] != s[len(s)-1]:#先頭と末尾が異なる場合
	print(-(-count//2)*k)

elif s[0] == s[len(s)-1]:#先頭と末尾が同じ場合
	for i in range(len(s)-1):
		if s[0] == s[i+1]: 
			start += 1
		else:
			break
	for i in range(len(s)-1,0):
		if s[len(s)-1] == s[i-1]:
			end += 1
		else:
			break
	print(-(-count)*k-(k-1)*((-(-start//2))+(-(-end//2)+(-(start+end))//2)))

Submission status: Wrong Answer

Solution code:
s = list(input())
s2= s+s
n = int(input())
c1=0
ss ='abc'
add1=0
if len(s)>1:
    if len(s)%2==1:
        if s[0] == s[-1]and s[0]!=s[1]:
            add1 = 1
            if(len(s)>2):
                if(s[0]==s[1]and s[1]!=s[2]):
                    add1=0
for i in range(1,len(s)):
    # print(s[i],s[i-1])
    if(i+1<len(s)):
        if s[i-1]==s[i] and s[i]==s[i+1]:
            c1 += 1
            for v in ss:
                if v!=s[i]:
                    s[i]=v
                    break
        elif s[i - 1] == s[i]:
            c1 += 1
            for v in ss:
                if v != s[i -1] and v!=s[i+1]:
                    s[i] = v
                    break
    else:
        if s[i - 1] == s[i]:
            c1 += 1
            for v in ss:
                if v != s[i -1]:
                    s[i] = v
                    break

c2=0
add2=0
# print(s2)
if s2[0] == s2[-1] and s2[-1]!=s2[-2]:
    add2 = 1
    if (len(s) > 2):
        if (s2[0] == s2[1] and s2[1] != s[2]):
            add2 = 0
for i in range(1,len(s2)):
    if(i+1<len(s2)):
        if s2[i-1]==s2[i] and s2[i]==s2[i+1]:
            for v in ss:
                if v!=s2[i]:
                    s2[i]=v
                    break
            c2+=1
        elif s2[i - 1] == s2[i]:
            for v in ss:
                if v != s2[i -1] and v!=s2[i+1]:
                    s2[i] = v
                    break
            c2+=1
    else:
        if s2[i - 1] == s2[i]:
            for v in ss:
                if v != s2[i -1]:
                    s2[i] = v
                    break
            c2+=1
if n==1:
    print(c1)
    exit()
elif(n==2):
    print(c2)
    exit()
res = 0
add=0
# print(s)
# print(s2)
# print('c1:',c1,'c2',c2,'add 1',add1)
if len(s)&1:
    run = n-1
    if run%2==0:
        time = run//2
        res= c2*time
        res+= add2*(time-1)
        res+=c1+add1
    else:
        time = n//2
        res = c2*time
        res += (time-1)*add2
else:
    if(n%2==0):
        time = n//2
        res=time*c2
        res+=add2*(time-1)
    else:
        time = n//2
        res=c2*time
        res+=(time-1)*add1
        res+=c1+add2


print(res)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

x_ = ""
c_ = 0
for x in s:
	if x_ == x:
		c_ += 1
	x_ = x
print(x_*c)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
def inputs():
    return [int(x) for x in input().split()]
S = list(input())
N = int(input())
if len(S)==2:
  print(N-1)
  exit()
ans = 0
flag=0
if S[0]==S[-2]:
  if S[-2]!=S[-3]:
    	flag = 1
  ans+=1
  S[-2]="aaaa"
for i in range(len(S)-2):
    if S[i]==S[i+1]:
        ans +=1
        S[i+1]="aa"
if flag==0:
	print(ans*N)
else:
  print(ans*N-1)

Submission status: Wrong Answer

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

ss = S + S[0]
slength = len(ss)

def chkerss(idx):
    i = 1
    while idx + i < slength and ss[idx] == ss[idx + i]:
        i += 1

    return i // 2, idx + i

c2, idx2 = 0, 0
while idx2 < slength:
    a, idx2 = chkerss(idx2)
    c2 += a

print(c2 * K)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from sys import stdin
from itertools import groupby

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

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

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

if s[-1] != s[-2]:
    li.append(1)

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

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

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

Submission status: Wrong Answer

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

precount = 0
revcnt = 0
if len(set(t)) > 1:
    if k > 1:
        for st in t[::-1]:
            if st != t[0]:
                break
            else:
                revcnt += 1
        if revcnt % 2 == 1:
            precount += k - 1
    for i in range(len(t) - 1):
        if len(list(set(t[i:]))) == len(t[i:]):
            break
        if t[i] == t[i + 1]:
            t[i + 1] = '?'
    ans = precount + t.count("?") * k
else:
    ans = (len(t) * k) // 2

print(ans)

Submission status: Wrong Answer

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

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

print(ans)

Submission status: Wrong Answer

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

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

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

print(TTL_num)

Submission status: Wrong Answer

Solution code:
def main():
    S = input()
    K = int(input())
    N = len(S)
    ans = 0
    from collections import Counter
    if N == 1:
        return print(K//2)
    elif N == 2:
        if S[0] == S[1]:
            return print(K)
        else: return print(0)
    
    tmp = 1
    for i in range(1,N):
        if S[i-1] == S[i]:
            tmp += 1
        else:
            ans += tmp // 2
            tmp = 1
    else:
        if tmp == N-1:
            ans = (tmp // 2) * K
        else:
            ans += (tmp // 2)
            ans *= K
            if S[0] == S[-1]:
                first = 1
                for i in range(1,N):
                    if S[i-1] != S[i]:
                        break
                    first += 1
                last = 1
                for i in range(N-1,0,-1):
                    if S[i-1] != S[i]:
                        break
                    last += 1
                revise = first//2 + last//2 - (first+last)//2
                revise *= (K-1)
                ans -= revise
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
s = input()
k = int(input())
t = ''
i = 0
count = 0
start = 0
end = 0

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

if count == len(s)-1:#すべて同じ場合
	print(-(-count//2)*k)

elif s[0] != s[len(s)-1]:#先頭と末尾が異なる場合
	print(-(-count//2)*k)

elif s[0] == s[len(s)-1]:#先頭と末尾が同じ場合
	for i in range(len(s)-1):
		if s[0] == s[i+1]: 
			start += 1
		else:
			break
	for i in range(len(s)-1,0):
		if s[len(s)-1] == s[i-1]:
			end += 1
		else:
			break
	print(-(-count//2)*k-(k-1)*(start+end)/2)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
def inputs():
    return [int(x) for x in input().split()]
S = list(input())
N = int(input())
ans = 0
flag=0
if S[0]==S[-1] and S[-2]!=S[-1]:
    flag = 1
    ans+=1
    S[-1]="aaaa"
for i in range(len(S)-1):
    if S[i]==S[i+1]:
        ans +=1
        S[i+1]="aa"
if flag==0:
	print(ans*N)
else:
  print(ans*N-1)

Submission status: Wrong Answer

Solution code:
# AGC039A - Connection and Disconnection
def main():
    S = input().rstrip()
    K = int(input())
    S += S[0]
    cur, cnt = S[0], 0
    for s in S[1:]:
        if s == cur:
            cur = "."
            cnt += 1
        else:
            cur = s
    ans = cnt * K
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

def replacePoint(s):
    arr = [-1]
    for i in range(len(s)):
        if arr[-1] != i-1:
            if s[i] == s[i-1]:
                arr.append(i)
    arr.remove(-1)
    return arr

double = s*2
triple = s*3
arr = replacePoint(s)
darr = replacePoint(double)
tarr = replacePoint(triple)
a = len(arr)
b = len(darr) - len(arr)

if arr+[i+len(s) for i in arr] == darr:
    print(a*k)
elif arr+darr+[i+len(s)*2 for i in arr] == tarr:
    print(a*((k+1)//2)+b*(k//2))
else:
    print(a+b*(k-1))

Submission status: Wrong Answer

Solution code:
s = input()
k = int(input())
t = ''
i = 0
count = 0
start = 0
end = 0

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

if count == len(s)-1:#すべて同じ場合
	print(-(-count//2)*k)

elif s[0] != s[len(s)-1]:#先頭と末尾が異なる場合
	print(-(-count//2)*k)

elif s[0] == s[len(s)-1]:#先頭と末尾が同じ場合
	for i in range(len(s)-1):
		if s[0] == s[i+1]: 
			start += 1
		else:
			break
	for i in range(len(s)-1,0):
		if s[len(s)-1] == s[i-1]:
			end += 1
		else:
			break
	print(-(-count/2)*k-(k-1)*(start+end)/2)

Submission status: Wrong Answer

Solution code:
import sys

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

ans=0
if len(set(s))==1:
	print((len(s)*k)//2)
	sys.exit()

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
from sys import stdin
from itertools import groupby

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

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

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

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

if s[-1] != s[-2]:
    li.append(1)

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

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

Submission status: Wrong Answer

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

precount = 0
revcnt = 0

if k > 1:
    for st in t[::-1]:
        if st != t[0]:
            break
        else:
            revcnt += 1
    if revcnt % 2 == 1:
        precount += k - 1

for i in range(len(t) - 1):
    if len(list(set(t[i:]))) == len(t[i:]):
        break
    if t[i] == t[i + 1]:
        t[i + 1] = '?'


aa = precount + t.count("?") * k
print(aa)

Submission status: Wrong Answer

Solution code:
from sys import stdin
from itertools import groupby

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

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

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

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

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