TnT/Multi_CodeNet4Repair huggingface dataset:
Problem: Takahashi has N cards. The i-th of these cards has an integer A_i written on it.  Takahashi will choose an integer K, and then repeat the following operation some number of times:    * Choose exactly K cards such that the integers written on them are all different, and eat those cards. (The eaten cards disappear.)  For each K = 1,2, \ldots, N, find the maximum number of times Takahashi can do the operation.

Submission attempts (in order):
import sys
import collections

def solve(N: int, A: "List[int]"):
    counter = sorted(list(collections.Counter(A).values()),reverse=True)
    for i in range(1,N+1):
        c_index = 0
        n = N
        while counter[c_index]*i > n and c_index<len(counter) and i>1:
            n-=counter[c_index]
            c_index+=1
            i-=1
        print(n//i)
    return

def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A)

if __name__ == '__main__':
    main()


#!/usr/bin/env python3
import sys
import collections

def solve(N: int, A: "List[int]"):
    counter = sorted(list(collections.Counter(A).values()),reverse=True)
    c_index = 0
    k=0
    for i in range(1,N+1):
        k+=1
        if len(counter)<i:
            print(0)
            continue
        while counter[c_index]*k > N and c_index<len(counter)-1:
            N-=counter[c_index]
            c_index+=1
            k-=1
        print(N//k)
    return

def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A)

if __name__ == '__main__':
    main()


Verdicts: Runtime Error

Accepted
Problem: Takahashi has N cards. The i-th of these cards has an integer A_i written on it.  Takahashi will choose an integer K, and then repeat the following operation some number of times:    * Choose exactly K cards such that the integers written on them are all different, and eat those cards. (The eaten cards disappear.)  For each K = 1,2, \ldots, N, find the maximum number of times Takahashi can do the operation.

Submission attempts (in order):
import numpy as np
np.count_nonzero

import numpy as np
import collections

n = int(input())
a = list(map(int, input().split()))

for k in range(1, n+1):
    counts = collections.Counter(a).values()
    counts = sorted(list(counts), reverse=True)
    
    eat = 0
    while True:

        if np.count_nonzero(counts) < k:
            break
        else:
            for i in range(k):
                counts[i] -= 1
            eat += 1
            counts = sorted(list(counts[:k]), reverse=True)
            
    print(eat)
            

import numpy as np
np.unique

import numpy as np
np.unique(np.array([1,2,3]), return_counts=True)

import collections
import numpy as np









#     return sum(min(arr.count(a), x) for a in arr) // x


n = int(input())
a = list(map(int, input().split()))

counter = collections.Counter(a)        #O(n)
nums = list(counter.values())           #O(n)
num_counter = collections.Counter(nums) #O(n)
lastest_add = np.count_nonzero(nums)    #O(n)
building, longests = [0], [0]
for i in range(1, n+1):                 #O(n)
    appended = building[-1] + lastest_add   #O(1)
    building.append(appended)               #O(1)
    longests.append(appended // i)          #O(1)
    lastest_add -= num_counter[i]           #O(1)


lastest_longest = 0
k_most = []
for i, x in enumerate(reversed(longests)):
    while x > lastest_longest:
        lastest_longest += 1
        k_most.append(n-i)

k_most.extend([0]*(n-len(k_most)))      

for longests_num in k_most:
    print(longests_num)

# print('----------------')
# for k in range(1, n+1):
#     maxindexes = list(i for i, x in enumerate(longests) if x >= k)
#     if maxindexes:
#         print(maxindexes[-1])
#     else:
#         print(0)


Verdicts: Wrong Answer

Wrong Answer

Wrong Answer

Runtime Error

Accepted
Problem: Takahashi has N cards. The i-th of these cards has an integer A_i written on it.  Takahashi will choose an integer K, and then repeat the following operation some number of times:    * Choose exactly K cards such that the integers written on them are all different, and eat those cards. (The eaten cards disappear.)  For each K = 1,2, \ldots, N, find the maximum number of times Takahashi can do the operation.

Submission attempts (in order):
import copy

N = int(input())
A = list(map(int, input().split()))
A.sort()

count = [0] * (N + 2)

tmp = 0
c = 0
for a in A:
    if a != tmp:
        count[c] += 1
        c = 1
        tmp = a
    else:
        c += 1

count[c] += 1
count[0] -= 1
lst = copy.deepcopy(count)


for i in range(1, N + 1):
    count[i + 1] *= (i + 1)
    count[i + 1] += count[i]
    lst[i + 1] += lst[i]

print (count)
print (lst)

def calc(k):
    tmp = N // k 
    
    # over = N - count[tmp] + lst[tmp]

    
    use = count[tmp] + (lst[-1] - lst[tmp])
    # ans = (N - over) // k
    ans = min(use // k, tmp)

    return ans


for t in range(1, N + 1):
    print (calc(t))

from bisect import bisect_left

N = int(input())
A = list(map(int, input().split()))

lst = [0] * (N)
for a in A:
    lst[a - 1] += 1
lst.sort() 

s = [0] * (N + 1)
for i in range(N):
    s[i + 1] = s[i] + lst[i]

# print (lst)
# print (s)







ans = N
i = N
for k in range(1, N + 1):
    while True:
        while  i >= 1 and lst[i - 1] >= ans:
            i -= 1
        total = ans * (N - i) + s[i]
        if total >= ans * k:
            break
        ans -= 1
    # print ('i =', i)
    print (ans)
        

Verdicts: Wrong Answer

Accepted
Problem: Takahashi has N cards. The i-th of these cards has an integer A_i written on it.  Takahashi will choose an integer K, and then repeat the following operation some number of times:    * Choose exactly K cards such that the integers written on them are all different, and eat those cards. (The eaten cards disappear.)  For each K = 1,2, \ldots, N, find the maximum number of times Takahashi can do the operation.

Submission attempts (in order):
import os
import sys

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7

N = int(sys.stdin.readline())
A = list(map(int, sys.stdin.readline().split()))


def test(k):
    if memo[k]:
        bc, ret = memo[k]
    else:
        bc = np.bincount(A)
        bc.sort()
        bc = bc[np.searchsorted(bc, 1):]
        bc = bc[::-1]
        ret = 0

    while len(bc) >= k:
        bc[:k] -= 1
        bc.sort()
        bc = bc[np.searchsorted(bc, 1):]
        bc = bc[::-1]
        ret += 1
    return ret


ans = [0] * N
for k in reversed(range(1, N + 1)):
    ans[k - 1] = test(k)
print(*ans, sep='\n')


import os
import sys

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7


# https://img.atcoder.jp/abc143/editorial.pdf
N = int(sys.stdin.readline())
A = list(map(int, sys.stdin.readline().split()))

A = np.array(A, dtype=int)
C = np.bincount(A, minlength=N + 2)
D = np.bincount(C, minlength=N + 2)

ld = (D * np.arange(len(D))).cumsum()
ud = D[::-1].cumsum()[::-1]

X = np.arange(1, N + 1, dtype=int)

L = np.zeros(N + 1, dtype=int)
L[X] = (ld[X] + X * ud[X + 1]) // X

i = len(L) - 1
for k in range(1, N + 1):
    while i > 0 and L[i] < k:
        i -= 1
    print(i)


Verdicts: Runtime Error

Accepted
Problem: Takahashi has N cards. The i-th of these cards has an integer A_i written on it.  Takahashi will choose an integer K, and then repeat the following operation some number of times:    * Choose exactly K cards such that the integers written on them are all different, and eat those cards. (The eaten cards disappear.)  For each K = 1,2, \ldots, N, find the maximum number of times Takahashi can do the operation.

Submission attempts (in order):
import copy
import bisect

N = int(input())
A = map(int, input().split())
C = [0]*(N + 1)
for a in A:
    C[a] += 1
sorted_C = sorted(C)

def h(L, i):
    
    if i == 1:
        return N
    
    if i > N//2:
        if L[N - i] == 0:
            return 0
        else:
            return 1
    
    for j in range(N - i, 0, - 1):
        if L[j] == 0:
            return L[N - i + 1]
        
        L[N - i + 1] += L[j]
        a = bisect.bisect_right(L[N - i + 2: ], L[N - i + 1])
        L[N - i + 1:] = L[N - i + 2: N - i + 2 + a] + [L[N - i + 1]] + L[N - i + 2 + a :]
        
        
    return L[N - i + 1]
        
for i in range(N):
    L = copy.copy(sorted_C)
    print(h(L, i + 1))

from collections import Counter
N = int(input())

C = list(Counter(map(int, input().split())).values())
C.sort()

rest = N
removed = 0
for K in range(1, N + 1):
    d = K - removed
    while C and C[- 1] > rest//d:
        rest -= C[- 1]
        C.pop()
        removed += 1
        d -= 1
    print(rest//d)

Verdicts: Wrong Answer

Accepted
Problem: Takahashi has N cards. The i-th of these cards has an integer A_i written on it.  Takahashi will choose an integer K, and then repeat the following operation some number of times:    * Choose exactly K cards such that the integers written on them are all different, and eat those cards. (The eaten cards disappear.)  For each K = 1,2, \ldots, N, find the maximum number of times Takahashi can do the operation.

Submission attempts (in order):
# -*- coding: utf-8 -*-
N = int(input())
A = list(map(int,input().split()))

B = [0 for _ in range(N)]
for i in A:
    B[i-1] += 1

for i in range(N):
    ans = 0
    C = B
    print(B)
    C = sorted(C, reverse = True)
    while C[i] != 0:
       
        for j in range(i+1):
               C[j] -= 1
        C = sorted(C, reverse = True)
        ans += 1
    print(ans)

# -*- coding: utf-8 -*-
from collections import Counter
from itertools import accumulate

N = int(input())
A = list(map(int,input().split()))

B = list(Counter(A).values())

C = [0] * N 
for i in B:
    C[i-1] += 1

F = list(accumulate(C))

S = [0] * N
f = [0] * N
S[0] = f[0] = sum(C) 
for i in range(2, N+1):
    S[i-1] = (S[i-2] + C[i-1] + S[0] - F[i-1] ) 
    f[i-1] = S[i-1] / i

f.sort()
n = 0     
K = 1
    
while K != N+1:
    if K <= f[n]:
        print(N-n)
        K += 1
    else:
        n += 1
    if n == N:
        for i in range(N-K+1):
            print(0)
        K = N+1    

Verdicts: Wrong Answer

Accepted
Problem: Takahashi has N cards. The i-th of these cards has an integer A_i written on it.  Takahashi will choose an integer K, and then repeat the following operation some number of times:    * Choose exactly K cards such that the integers written on them are all different, and eat those cards. (The eaten cards disappear.)  For each K = 1,2, \ldots, N, find the maximum number of times Takahashi can do the operation.

Submission attempts (in order):
from collections import Counter
from itertools import accumulate
n = int(input())
A = tuple(map(int, input().split()))
C = Counter(A)
D = [0]*(n+1)
for v in C.values():
  D[v] += 1
E = tuple(accumulate(k*d for k, d in enumerate(D)))
D = tuple(accumulate(D))
F = [0]*(n+1)
for x in range(1, n+1):
  temp = (E[x] + x*(D[n]-D[x])) // x
  F[x] = temp
print(*F[1:], sep="\n")

from collections import Counter
from itertools import accumulate
n = int(input())
A = tuple(map(int, input().split()))
C = Counter(A)
D = [0]*(n+1)
for v in C.values():
  D[v] += 1
E = tuple(accumulate(k*d for k, d in enumerate(D)))
D = tuple(accumulate(D))
F = [0]*(n+1)
for x in range(1, n+1):
  temp = (E[x] + x*(D[n]-D[x])) // x
  F[x] = temp
for k in range(1, n+1):
  ok = 0
  ng = n+1
  while ng-ok > 1:
    mid = (ok+ng)//2
    if k <= F[mid]:
      ok = mid
    else:
      ng = mid
  print(ok)

Verdicts: Wrong Answer

Accepted
Problem: Takahashi has N cards. The i-th of these cards has an integer A_i written on it.  Takahashi will choose an integer K, and then repeat the following operation some number of times:    * Choose exactly K cards such that the integers written on them are all different, and eat those cards. (The eaten cards disappear.)  For each K = 1,2, \ldots, N, find the maximum number of times Takahashi can do the operation.

Submission attempts (in order):
import sys
stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

import bisect
from collections import Counter

n = ni()
a = na()
aa = [a[0]]
for i in range(1,n):
    aa.append(aa[-1]+a[i])

c = sorted(Counter(a).values())
cc = [c[0]]
m = len(c)
for i in range(1,m):
    cc.append(cc[-1]+c[i])

for k in range(1,n+1):
    def is_ok(arg):
        b = bisect.bisect_right(c,arg)
        p = cc[b-1] + (m-b)*arg
        return True if p >= arg*k else False

    
    ok,ng = -1,n
    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if is_ok(mid):
            ok = mid
        else:
            ng = mid
    
    print(ok)
    

import sys
stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

import bisect
from collections import Counter

n = ni()
a = na()

c = sorted(Counter(a).values())
cc = [0]
m = len(c)
for i in c:
    cc.append(cc[-1]+i)

def is_ok(k,arg):
    b = bisect.bisect_right(c,arg)
    p = cc[b] + (m-b)*arg
    return True if p >= arg*k else False

for k in range(1,n+1):
    if k > m:
        print(0)
        continue
    
    ok,ng = -1,n//k+1
    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if is_ok(k,mid):
            ok = mid
        else:
            ng = mid
    
    print(ok)
    

Verdicts: Wrong Answer

Accepted
Problem: Takahashi has N cards. The i-th of these cards has an integer A_i written on it.  Takahashi will choose an integer K, and then repeat the following operation some number of times:    * Choose exactly K cards such that the integers written on them are all different, and eat those cards. (The eaten cards disappear.)  For each K = 1,2, \ldots, N, find the maximum number of times Takahashi can do the operation.

Submission attempts (in order):
import itertools
import collections
N = int(input())
A = [int(_) for _ in input().split()]
c = sorted(collections.Counter(A).values())
acc = list(itertools.accumulate([0] + c))
n = len(acc) - 1
j = 0
for i in range(1, N + 1):
    r = 0
    while i - j > 0:
        if (i - j) * c[-1 - j] <= acc[-1 - j]:
            r = acc[-1 - j] // (i - j)
            break
        else:
            j += 1
    print(r)


import itertools
import collections
N = int(input())
A = [int(_) for _ in input().split()]
c = sorted(collections.Counter(A).values())
acc = list(itertools.accumulate([0] + c))
n = len(acc) - 1
j = 0
for i in range(1, n + 1):
    r = 0
    while i - j > 0:
        if (i - j) * c[-1 - j] <= acc[-1 - j]:
            r = acc[-1 - j] // (i - j)
            break
        else:
            j += 1
    print(r)
for _ in range(N - n):
    print(0)


Verdicts: Runtime Error

Accepted
Problem: Takahashi has N cards. The i-th of these cards has an integer A_i written on it.  Takahashi will choose an integer K, and then repeat the following operation some number of times:    * Choose exactly K cards such that the integers written on them are all different, and eat those cards. (The eaten cards disappear.)  For each K = 1,2, \ldots, N, find the maximum number of times Takahashi can do the operation.

Submission attempts (in order):
import sys
input = sys.stdin.readline

from collections import Counter
from copy import deepcopy
from heapq import heapify, heappush, heappop


def main():
    n = int(input())
    a = list(map(int, input().split()))

    #n = 3 * 10 ** 5
    #a = list(range(1, n + 1))

    c = Counter(a)
    c = list(c.values())
    heapify(c)

    k_mx = len(c)

    for k in range(1, n + 1):
        if k > k_mx:
            print(0)
            continue

        cp = deepcopy(c)

        for _ in range(k_mx - k):
            continue
            cnt = heappop(cp)
            while cnt:
                mn = heappop(cp)
                cnt -= 1
                heappush(cp, mn + 1)

        ans = heappop(cp)
        print(ans)


if __name__ == "__main__":
    main()


import sys
input = sys.stdin.readline

from collections import Counter
from itertools import accumulate
from math import floor
from bisect import bisect_left


def main():
    n = int(input())
    a = list(map(int, input().split()))

    c = Counter(a)
    c = list(c.values())

    d = Counter(c)
    d_li = [0] * (n + 1)
    for k, v in d.items():
        d_li[k] = v

    dk_acm = list(accumulate(d_li))

    kdk_acm = [0]
    for k, e in enumerate(d_li[1:], 1):
        kdk_acm.append(kdk_acm[-1] + k * e)

    def f(x):
        kdk_sm = kdk_acm[x]
        dk_sm = dk_acm[n] - dk_acm[x]

        return floor((kdk_sm + x * dk_sm) / x)

    fs = [float("inf")] + [f(x) for x in range(1, n + 1)]
    fs = fs[::-1]

    for k in range(1, n + 1):
        print(n - bisect_left(fs, k))


if __name__ == "__main__":
    main()


Verdicts: Wrong Answer

Accepted
Problem: Takahashi has N cards. The i-th of these cards has an integer A_i written on it.  Takahashi will choose an integer K, and then repeat the following operation some number of times:    * Choose exactly K cards such that the integers written on them are all different, and eat those cards. (The eaten cards disappear.)  For each K = 1,2, \ldots, N, find the maximum number of times Takahashi can do the operation.

Submission attempts (in order):
import sys 
import collections as cl
N=int(input())
A=list(map(int,sys.stdin.readline().split()))
c=cl.Counter(A)
NumberTupleList=c.most_common()
NumberList=[x[1] for x in NumberTupleList[::-1]]
LengthOfNumberList=len(NumberList)
FormulaList=[sum([min(NumberList[i],x)//x for i in range(LengthOfNumberList)]) for x in range(1,N+1)]

pin=N-1
for K in range(1,N+1):
    while pin>=0 and K>FormulaList[pin]:
        pin-=1
    print(pin+1)


import sys 
import collections as cl
N=int(input())
A=list(map(int,sys.stdin.readline().split()))
c=cl.Counter(A)
NumberTupleList=c.most_common()
NumberList=[x[1] for x in NumberTupleList[::-1]]
LengthOfNumberList=len(NumberList)
FormulaList=[sum([min(NumberList[i],x)//x for i in range(LengthOfNumberList)]) for x in range(1,N+1)]

pin=N
for K in range(1,N+1):
    while pin>0 and K>FormulaList[pin-1]:
        pin-=1
    print(pin)


import sys 
import collections as cl


N=int(input())
A=list(map(int,sys.stdin.readline().split()))
c=cl.Counter(A)
NumberTupleList=c.most_common()
NumberList=[x[1] for x in NumberTupleList[::-1]]
LengthOfNumberList=len(NumberList)
FormulaList=[0 for i in range(N)]
flag=0
S=sum(NumberList)
for x in range(1,N+1):
    while flag<LengthOfNumberList and NumberList[flag]<=x:
        flag+=1
    if flag<LengthOfNumberList:
        FormulaList[x-1]=(sum(NumberList[:flag])+x*(LengthOfNumberList-flag))/x
    else:
        FormulaList[x-1]=S/x
pin=N-1
for K in range(1,N+1):
    while pin>=0 and K>FormulaList[pin]:
        pin-=1
    print(pin+1)



Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
s = input()
k = input()

ss = ""
for _ in range(k):
    ss += s

ss_list = list(ss)
count = 0
answer = 0
prev = ""
for sss in ss_list:
    if prev == "" or sss == prev:
        count+=1
        if count == 2: 
            answer+=1
            count=0

    else:
        count=1
    prev = sss

print(answer)

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

if len(set(s))==1:
	print((len(s)*k)//2)
	sys.exit()
    
def counter(string):
    count = 0
    answer = 0
    prev = ""
    for index,sss in enumerate(string):
        if prev == "" or sss == prev:
            count+=1
            if count == 2: 
                answer+=1
                count=0
                string[index] = "1"
        else:
            count=1
        prev = sss
    return answer,string

answer, string = counter(s.copy())

if string[0] != string[-1]:
    print(answer*k)
else:
    count = 0
    l = len(s)
    for i in range(l):
        if s[i] == s[0]:
            count += 1
        else:
            break
    for i in range(l):
        if s[-1-i] == s[0]:
        	count += 1
        else:
        	break

    if count % 2 ==0:
        print(answer*k + k-1)
    else:
        print(answer*k)


Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
from itertools import groupby
from functools import reduce
from operator import xor

s = input()
k = int(input())
r = len(s) * k // 2
a = [reduce(xor, (1 for _ g)) for _, g in groupby(s)]
if len(a) > 1:
  r -= sum(a) * k // 2
  if s[0] == s[-1] and a[0] & a[-1]:
    r += k - 1
print(r)


from itertools import groupby

s = input()
k = int(input())
r = len(s) * k // 2
a = [len(tuple(g)) & 1 for _, g in groupby(s)]
if len(a) > 1:
  r -= sum(a) * k // 2
  if s[0] == s[-1] and a[0] & a[-1]:
    r += k - 1
print(r)


Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
import numpy as np
import copy

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

A = np.zeros(1)
j = 0 

for i in range(len(S)-1):
    if S[i] == S[i+1]:
        A[j] += 1
    else:
        j += 1
        A = np.append(A, 0)

if np.size(A) == 1:
    ans = (len(S) * K) // 2
    
else:   
    A = A + 1
    print(A)
    B = copy.deepcopy(A)
    if S[0] == S[-1]:
        B[0] += A[-1]
        print(B)
        A = np.delete(A, np.size(A)-1)
        ans = np.sum(A // 2) + np.sum(B // 2) * (K-1)
    else:
        ans = np.sum(A // 2) * K

print(int(ans))

import numpy as np
import copy

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

A = np.zeros(1)
j = 0 

for i in range(len(S)-1):
    if S[i] == S[i+1]:
        A[j] += 1
    else:
        j += 1
        A = np.append(A, 0)
A += 1

if np.size(A) == 1:
    ans = (len(S) * K) // 2
    
else:
    B = copy.deepcopy(A)
    if S[0] == S[-1]:
        B[0] += A[-1]
        B = np.delete(B, np.size(A)-1)
        ans = np.sum(A // 2) + np.sum(B // 2) * (K-1)
    else:
        ans = np.sum(A // 2) * K

print(int(ans))

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
s = list(input())

k = int(input())

n = len(s)

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

s = list(input())

k = int(input())

n = len(s)

if(len(set(s)) == 1):
    print(n*k//2)
else:
    t = 0
    c = 1
    for i in range(n-1):
        if(s[i] == s[i+1]):
            c += 1
        else:
            t += c // 2
            c = 1
    t += c // 2
    if(s[0] != s[-1]):
        print(t*k)
    else:
        a = 0
        b = 0
        for i in range(n):
            if(s[i] == s[0]):a+=1
            else:break
        for i in range(n)[::-1]:
            if(s[i] == s[-1]):b+=1
            else:break
        print(t*k - (a//2 + b//2 - (a+b)//2) * (k-1))

Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
S = input()
K = int(input())


rle = []
pre = 'A'
chain = 1
for c in S:
    if c == pre:
        chain += 1
    else:
        if pre != 'A':
            rle.append([pre,chain])
        
        pre = c
        chain = 1
rle.append([pre,chain])

ans = 0


if len(rle) == 1:
    ans = (rle[0][1] * K) // 2


else:
    
    if rle[0][0] == rle[-1][0]:
        ans += rle[0][1]//2
        ans += rle[-1][1]//2
        rle[0][1] += rle[-1][1]
        rle[-1][1] = 0

        mid_chains = 0
        for i in range(len(rle)):
            mid_chains += rle[i][1]//2
        ans += mid_chains * (K-1)

    
    else:
        mid_chains = 0
        for i in range(len(rle)):
            mid_chains += rle[i][1]//2
        ans += mid_chains * K


#print(rle)
print(ans)

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


rle = []
pre = 'A'
chain = 1
for c in S:
    if c == pre:
        chain += 1
    else:
        if pre != 'A':
            rle.append([pre,chain])
        
        pre = c
        chain = 1
rle.append([pre,chain])

ans = 0


if len(rle) == 1:
    ans = (rle[0][1] * K) // 2


else:
    
    if rle[0][0] == rle[-1][0]:
        
        ans += rle[0][1]//2
        ans += rle[-1][1]//2
        rle[0][1] += rle[-1][1]
        rle[-1][1] = 0
        ans += rle[0][1]//2 * (K-1)

        
        mid_chains = 0
        for i in range(1,len(rle)):
            mid_chains += rle[i][1]//2
        ans += mid_chains * K

    
    else:
        mid_chains = 0
        for i in range(len(rle)):
            mid_chains += rle[i][1]//2
        ans += mid_chains * K


#print(rle)
print(ans)

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
import sys

args = sys.argv
S=args[1]
K=int(args[2])
result=0

a=S[0]
renzoku=0
sumInS=0
for s in S:
    if a==s:
        renzoku=renzoku+1
    else:
        sumInS=sumInS+renzoku//2
        renzoku=1
    a=s
sumInS=sumInS+renzoku//2
result = sumInS*K

if S[0]==S[-1]:
    rst=0
    for s in S:
        if s==S[0]:
            rst=rst+1
        else:
            break
    ren=0
    for s in S[::-1]:
        if s==S[-1]:
            ren=ren+1
        else:
            break
    if rst%2==1 and ren%2==1:
        result=result+(K-1)

if renzoku==len(S):
    total=len(S)*K
    result=total//2

print(result)

import sys

S=input()
K=int(input())
result=0

a=S[0]
renzoku=0
sumInS=0
for s in S:
    if a==s:
        renzoku=renzoku+1
    else:
        sumInS=sumInS+renzoku//2
        renzoku=1
    a=s
sumInS=sumInS+renzoku//2
result = sumInS*K

if S[0]==S[-1]:
    rst=0
    for s in S:
        if s==S[0]:
            rst=rst+1
        else:
            break
    ren=0
    for s in S[::-1]:
        if s==S[-1]:
            ren=ren+1
        else:
            break
    if rst%2==1 and ren%2==1:
        result=result+(K-1)

if renzoku==len(S):
    total=len(S)*K
    result=total//2

print(result)

Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
import sys
input = sys.stdin.readline

_s = input()[:-1]
_k = int(input())


def chker(S, K):
    s3 = S * 3
    for i in range(1, len(s3)):
        if s3[i - 1] == s3[i]:
            s3[i] = '0'

    ls = len(S)
    cnt_0 = s3[:ls].count('0')
    cnt_1 = s3[ls:2 * ls].count('0')
    cnt_2 = s3[2 * ls:3 * ls].count('0')

    print(cnt_0 + cnt_1 * (K // 2) * cnt_2 * ((K - 1) // 2))


chker(_s, _k)


import sys
input = sys.stdin.readline

_s = input()[:-1]
_k = int(input())


def chker(S, K):
    s3 = [item for item in S * 3]
    for i in range(1, len(s3)):
        if s3[i - 1] == s3[i]:
            s3[i] = 1

    s3 = [0 if item != 1 else item for item in s3]

    ls = len(S)
    cnt_0 = sum(s3[:ls])
    cnt_1 = sum(s3[ls:2 * ls])
    cnt_2 = sum(s3[2 * ls:3 * ls])

    print(cnt_0 + cnt_1 * (K // 2) + cnt_2 * ((K - 1) // 2))


chker(_s, _k)


Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
S = input()
K = int(input())
lenS = len(S)
ans = 0
if S.count(S[0]) == lenS:
    ans = (lenS*K)//2
else:
    if S[0] == S[lenS - 1] and lenS > 1:
        if S[0] == S[1]:
            ind = 1
            while(S[ind+1] == S[0]):
                ind += 1
            if ind % 2 == 1:
                S = "*"+S[1:]
                ans += K

        else:
            ans += K-1
            S = S[:lenS-1]+"*"

    for i in range(lenS - 1):
        if S[i] == S[i + 1]:
            S = S[:i+1] + '*'+S[i+2:]
            ans += K
            print(S)
            # print(i)


print(ans)


S = input()
K = int(input())
lenS = len(S)
ans = 0
if S.count(S[0]) == lenS:
    ans = (lenS*K)//2
else:
    if S[0] == S[lenS - 1] and lenS > 1:
        if S[0] == S[1]:
            ind = 1
            while(S[ind+1] == S[0]):
                ind += 1
            if ind % 2 == 1:
                S = "*"+S[1:]
                ans += K

        else:
            ans += K-1
            if S[lenS-1] == S[lenS-2]:
                ans += 1
            S = S[:lenS-1]+"*"

    for i in range(lenS - 1):
        if S[i] == S[i + 1]:
            S = S[:i+1] + '*'+S[i+2:]
            ans += K
            # print(S)
            # print(i)
    if S[0] == S[lenS - 1]:
        ans += K-1

print(ans)


Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
s = input()
k = int(input())
n = 0
j = s[0]
l = 1
for i in range(1,len(s)-1):
  if s[i] == j:
    l += 1
  else:
    n += l//2
    l = 1
    j = s[i]
print(n*k)

s = input()
k = int(input())
n = 0
j = s[0]
l = 1
p = 0
fi,la = 0,0
c = 1
if len(set(list(s))) == 1:
  print(len(s)*k//2)
else:
  for i in range(1,len(s)):
    if s[i] == j:
      l += 1
    else:
      n += l//2
      if s[i-1] == s[0] and c == 1:
        fi = l
        c = 0
      l = 1
      j = s[i]
  n += l//2
  la = l
  if s[0] == s[-1] and fi%2 == 1 and la%2 == 1:
    p = k-1
  print(n*k+p)

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
import math
S = input()
K = int(input())
buf=''
cnt = 0
for s in S:
    if s == buf:
        cnt += 1
    buf = s
print(math.ceil(cnt/2)*K)

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

buf=''
cnt = 1
total = 0
cnts = []


for s in S:
    
    if s == buf:
        cnt += 1       
    else:
        cnts.append(cnt)
        total += int(cnt/2)
        cnt = 1        
    buf = s
cnts.append(cnt)    
total += int(cnt/2)

if S[0]==S[-1]:
    if (cnts[1]+cnts[-1]) % 2 == 0:
        print(total*K+K-1)
else:
    print(total*K)

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

buf=''
cnt = 1
total = 0
cnts = []


for s in S:
    
    if s == buf:
        cnt += 1       
    else:
        cnts.append(cnt)
        total += int(cnt/2)
        cnt = 1        
    buf = s
cnts.append(cnt)    
total += int(cnt/2)

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

elif S[0]==S[-1] and cnts[1] % 2 != 0:
    if (cnts[1]+cnts[-1]) % 2 == 0:
        print(total*K+K-1)
else:
    print(total*K)
        
    


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

buf=''
cnt = 1
total = 0
cnts = []


for s in S:
    
    if s == buf:
        cnt += 1       
    else:
        cnts.append(cnt)
        total += int(cnt/2)
        cnt = 1        
    buf = s
cnts.append(cnt)    
total += int(cnt/2)

if S[0]==S[-1] and cnts[1] % 2 != 0:
    if (cnts[1]+cnts[-1]) % 2 == 0:
        print(total*K+K-1)
else:
    print(total*K)

buf=''
cnt = 1
total = 0
cnts = []


for s in S:
    
    if s == buf:
        cnt += 1       
    else:
        cnts.append(cnt)
        total += int(cnt/2)
        cnt = 1        
    buf = s
cnts.append(cnt)    
total += int(cnt/2)

if S[0]==S[-1]:
    if (cnts[1]+cnts[-1]) % 2 == 0:
        print(total*K+K-1)
else:
    print(total*K)

from itertools import groupby
S = input()
K = int(input())
a = [len(tuple(s)) for _, s in groupby(S)]
ans = 0
 
if S[0] == S[-1] and K > 1:
    if len(a) == 1:
        ans = a[0]*K // 2
    else:
        ans = a[0] // 2 + a[-1] // 2 + (a[0]+a[-1]) // 2 * (K-1)
        ans += sum(n // 2 for n in a[1:-1]) * K
else:
    ans = sum(n // 2 for n in a) * K
print(ans)

Verdicts: Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
S=input()
K=int(input())
L=len(S)
cnt=0
ren=1

if L==1:
  ans= K//2
elif L==2:
  if S[0]==S[1]:
    ans = K
  else:
    ans = 0
else:  
  if S[0]!=S[-1]:
    for i in range(1,L):  
      if S[i]==S[i-1]:
        ren +=1
        if i==L-1:
          cnt += ren//2  
      else:
        cnt += ren//2
        ren=1        
  else:
    pass
  
    
#print(ans)

S=input()
K=int(input())
L=len(S)
cnt=0
ren=1

if L==1:
  ans= K//2
elif L==2:
  if S[0]==S[1]:
    ans = K
  else:
    ans = 0
else:  
  if S[0]!=S[-1]:
    for i in range(1,L):  
      if S[i]==S[i-1]:
        ren +=1
        if i==L-1:
          cnt += ren//2  
      else:
        cnt += ren//2
        ren=1
    ans=cnt*K
  else:
    head=0
    tail=0
    i=0
    j=0
    while S[i]==S[0]:
      head += 1
      i +=1
    while S[-1-j]==S[-1]:
      tail += 1
      j += 1
    #print(head,tail)
    elif L-head-tail<=0:
      ans=K*L//2
    else:  
      for k in range(head,L-tail):  
        #print("k=",k,"S[k]=",S[k])
        if S[k]==S[k-1]:
          ren +=1
          if k==L-tail-1:
            cnt += ren//2  
        else:
          cnt += ren//2
          ren=1
      #print("cnt",cnt)   
      
    ans=K*cnt + (K-1)*(head+tail)//2 + head//2 + tail//2
    
print(ans)


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

if S.count(S[0])==N:
  ans= K*N//2
else:
  h=0
  for i in range(N):
    if S[i]==S[0]:
      h +=1
    else:
      break
  t=0
  for i in range(N-1,-1,-1):
    if S[i]==S[-1]:
      t +=1
    else:
      break
  ren=1
  cnt=0
  for i in range(h,N-t):
    if S[i]==S[i-1]:
      ren +=1
      if i==N-t-1:
        cnt += ren//2
    else:
      cnt += ren//2
      ren=1    
      
  if S[0]==S[-1]:
    
    ans= h//2 + (K-1)*((h+t)//2) + t//2 + K*cnt
  else:
    #print(h//2,cnt,t//2)
    ans= (h//2 + cnt + t//2)*K
print(ans)

Verdicts: Wrong Answer

Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
s = input()
k = int(input())
ans = 0
space = 0
while (i < len(s)):
  if s[i] == s[i + 1]:
	ans += 1
    i += 2
  else:
    i += 1
if s[-1] == s[0]:
  space = 1
final_ans = (ans * k) + (space * (k - 1))
print(final_ans)

s = input()
k = int(input())
count = []
now = 1
for i in range(len(s) - 1):
    if s[i] == s[i + 1]:
        now += 1
    else:
        count.append(now)
        now = 1
count.append(now)
if len(count) == 1:
    ans = (count[0] * k) // 2
else:
    if s[0] == s[-1]:
        temp = 0
        for i in count:
            temp += i // 2
        ans = (temp * k) - ((count[0] // 2) + (count[-1] // 2)  - ((count[0] + count[-1]) // 2)) * (k - 1)
    else:
        ans = sum([c // 2 for c in count]) * k
print(ans)

Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
S = str(input())
K = int(input())

flag = []

N = len(S)
for i in range(N):
    if i == N - 1:
        flag.append(0)
    else:
        if S[i]==S[i+1]:
            flag.append(1)
        else:
            flag.append(0)

flag_2 = []
for i in range(N):
    flag_2.append(0)

for i in range(N):
    if flag[i] == 1:
        k = 0
        count = 0
        while((i == 0 or flag[i-1] == 0) and (i + k) < N and flag[i + k] == 1):
            k += 1
            count += 1
        flag_2[i] = count

ans = 0
cara = set()
for i in range(N):
    cara.add(S[i])
if len(cara) == 1:
    ans = N*K//2
else:

    if(S[0] != S[N-1]):
        for i in range(N):
            ans += (flag_2[i] + 1)//2

        ans = ans * K

    else:
        last = 0
        for i in range(N):
            if(flag_2[N - 1- i] != 0):
                last = N - 1 - i
                temp = flag_2[0] + flag_2[last] + 2
                break
        ans += temp//2 * (K - 1)
        for i in range(1, last):
            ans += (flag_2[i] + 1)//2 * K

print(ans)




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

flag = []

N = len(S)
for i in range(N):
    if i == N - 1:
        flag.append(0)
        #if S[i] == S[0]:
            #flag.append(1)
        #else:
            #flag.append(0)
    else:
        if S[i]==S[i+1]:
            flag.append(1)
        else:
            flag.append(0)

flag_2 = []
for i in range(N):
    flag_2.append(0)

for i in range(N):
    if flag[i] == 1:
        k = 0
        count = 0
        while((i == 0 or flag[i-1] == 0) and (i + k) < N and flag[i + k] == 1):
            k += 1
            count += 1
        flag_2[i] = count

#print("flag",flag)
#print("flag2", flag_2)

ans = 0
cara = set()
for i in range(N):
    cara.add(S[i])
if len(cara) == 1:
    ans = N*K//2
else:

    if(S[0] != S[N-1]):
        for i in range(N-1):
            ans += (flag_2[i] + 1)//2

        ans = ans * K

    else:
        last = 0
        for i in range(N):
            if(S[0] != S[N - 1 - i]):
                last = N - i
                break
        #print("last",last)
        temp = flag_2[0] + (N - last) + 1
        ans += temp//2 * (K - 1)
        for i in range(1, last):
            ans += (flag_2[i] + 1)//2 * K
        ans += (flag_2[0] + 1)//2
        ans += (flag_2[last] + 1)//2

print(ans)




Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
S = input()
K = int(input())

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

if len(S)%2 == 0:
    ans = 0
    tmp = ""
    for s in S:
        if s == tmp:
            ans += 1
            tmp = ""
            continue
        else:
            tmp = s
    if S[0] == tmp:
        ans += 1
    ans *= K
    print(ans)
    exit()
else:
    len1 = len(S)-1
    S = S*2
    ans = 0
    tmp = ""
    for i in range(len(S)):
        if S[i] == tmp:
            ans += 1
            tmp = ""
            continue
        else:
            tmp = S[i]
        if i == len1:
            num = ans
    if S[0] == tmp:
        ans += 1
    d,m = divmod(K,2)
    ans = ans*d + num*m
    print(ans)
    exit()

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

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

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

if S[0] != S[-1]:
    ans = 0
    tmp = ""
    for s in S:
        if s == tmp:
            ans += 1
            tmp = ""
            continue
        else:
            tmp = s
    ans *= K
    print(ans)
    exit()
elif S[0] == S[-1]:
    A = 0
    B = 0
    for s in S:
        if s == S[0]:
            A+=1
        else:
            break
    for s in S[::-1]:
        if s == S[0]:
            B+=1
        else:
            break
    ans = 0
    tmp = ""
    for s in S:
        if s == tmp:
            ans += 1
            tmp = ""
            continue
        else:
            tmp = s
    ans *= K
    ans = ans - (A//2 + B//2)*(K-1) + (A+B)//2*(K-1)
    print(ans)
    exit()


Verdicts: Runtime Error

Accepted
Problem: 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.

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


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


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


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

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

s=str(input())
k=int(input())
li=[1]
ans=0
if len(set(s))==1:
    print(len(s)*k//2)
    exit()
for i in range(1,len(s)):
    if s[i]==s[i-1]:
        li[-1]+=1
    else:
        li.append(1)

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

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

print(ans)          
            
    

Verdicts: Wrong Answer

Wrong Answer

Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
S = list(input())
s = len(S)
K = int(input())
A = []
j = 1

for i in range(0,s-1,1):
  if S[i] == S[i+1]:
    j += 1
  else:
    A.append(j)
    j = 1
A.append(j)

a = len(A)

b = 0
for i in range(a):
  b += i//2
  
x = b*K

if S[s-1] == S[0] and A[a-1] % 2 == 1 and A[1] % 2 == 1:
  x += K-1
  
print(x)


S = list(input())
s = len(S)
K = int(input())
A = []
j = 1

for i in range(0,s-1,1):
  if S[i] == S[i+1]:
    j += 1
  else:
    A.append(j)
    j = 1
A.append(j)

a = len(A)

b = 0
for i in range(0,a,1):
  b += A[i]//2
  
x = b*K

if S[s-1] == S[0] and A[a-1] % 2 == 1 and A[1] % 2 == 1:
  x += K-1

print(b)
print(x)

S = list(input())
s = len(S)
K = int(input())
A = []
j = 1

for i in range(0,s-1,1):
  if S[i] == S[i+1]:
    j += 1
  else:
    A.append(j)
    j = 1
A.append(j)

a = len(A)

b = 0
for i in range(0,a,1):
  b += A[i]//2
  
x = b*K

if a == 1:
  x = (s*K)//2
elif S[s-1] == S[0] and A[a-1] % 2 == 1 and A[0] % 2 == 1:
  x += K-1

print(x)

Verdicts: Runtime Error

Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
S = list(input())
K = int(input())

#print(link_S)
#S = S.append(S[len(S)-1])
i = 0
sum = 1
total_sum = 0
sum_ketu = 0
while(1):
    if i == len(S)-1:
        if S[i] == S[0] and S[0] != S[1]:
            sum += 1
            sum_ketu = -1
        break
    if S[i] == S[i+1]:
     #   print("i is", i)
     #   print("S[i] is", S[i], "S[i+1] is", S[i+1])
        sum += 1
     #   print(sum)
        i += 1
    else:
        total_sum += sum // 2
        sum = 1
        i += 1
        
total_sum += sum // 2

print(total_sum * K + sum_ketu)



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

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

count = 1
i = 0
sum = 0
while(1):
    if S[i] == S[i+1]:
        count += 1
        i += 1
    else:
        sum += count//2
        count = 1
        i += 1
    if i == len(S)-1:
        break
if sum != 1:
    sum += count//2
#print("check1",sum)


j = 0 
a = 1 
while(1):
    if S[j] == S[j+1]:
        a += 1
        j += 1
    else:
        break
    if j == len(S) -1:
        break
#print("check")


m = len(S)-1 
b = 1 
while(1):
    if S[m] == S[m-1]:
        m -= 1
        b += 1
    else:
        break
    if m == 0:
        break

if S[len(S)-1] == S[0]:
    print( sum * K + ((a+b)//2 - a//2 - b //2 ) * ( K -1))
else:
    print( sum * K)


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

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

count = 1
i = 0
sum = 0
while(1):
    if S[i] == S[i+1]:
        count += 1
        i += 1
    else:
        sum += count//2
        count = 1
        i += 1
    if i == len(S)-1:
        break

sum += count//2 

#print("check1",sum)


j = 0 
a = 1 
while(1):
    if S[j] == S[j+1]:
        a += 1
        j += 1
    else:
        break
    if j == len(S) -1:
        break
#print("check")


m = len(S)-1 
b = 1 
while(1):
    if S[m] == S[m-1]:
        m -= 1
        b += 1
    else:
        break
    if m == 0:
        break

#print("a is",a)
#print("b is",b)
#print("sum is", sum)
if a == len(S): 
    print((len(S)* K)//2)
elif S[len(S)-1] == S[0]:
    print( sum * K + ((a+b)//2 - a//2 - b //2 ) * ( K -1))
else:
    print( sum * K)


Verdicts: Runtime Error

Wrong Answer

Accepted