Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
S = input()
L = sorted(S)
if L[0]==L[1] and L[1]!=L[2] and L[2]==L[3]:
  print('Yes')
else:
  prin('No')

Fixed submission:
S = input()
S1 = []
for i in S:
  if i not in S1:
    S1.append(i)
if len(S1) == 2:
  print('Yes')
else:
  print('No')

Buggy python submission (verdict: Runtime Error):
S = input()
S1 = []
for i in S:
  if i not in S1:
    S1.append(i)
if len(S1) == 2:
  print('Yes')
else:
  prin('No')

Fixed submission:
S = input()
S1 = []
for i in S:
  if i not in S1:
    S1.append(i)
if len(S1) == 2:
  print('Yes')
else:
  print('No')
Buggy python submission (verdict: Runtime Error):
N = int(input())
X = list(map(int,input().split()))
A = 10**10
R = sum(X)
K = 0
for i in range (N-1):
	K += X[i]
	R -= X[i]
	A = min(A, abs(l-r))
print(A)

Fixed submission:
N = int(input())
X = list(map(int,input().split()))
A = 10**10
R = sum(X)
K = 0
for i in range (N-1):
	K += X[i]
	R -= X[i]
	A = min(A, abs(K-R))
print(A)

Buggy python submission (verdict: Runtime Error):
N = int(input())
X = list(map(int, input().split()))
A = 10**10
R = sum(X)
L = 0
for i in range(N-1):
	L += X[i]
	R -= X[i]
	A = min(A, abs(l-r))
print(A)

Fixed submission:
N = int(input())
X = list(map(int,input().split()))
A = 10**10
R = sum(X)
K = 0
for i in range (N-1):
	K += X[i]
	R -= X[i]
	A = min(A, abs(K-R))
print(A)
Buggy python submission (verdict: Runtime Error):
A,P = map(int, input().split())
print(((A*3)+P))//2)

Fixed submission:
A,P = map(int,input().split())
print((3*A+P)//2)
Buggy python submission (verdict: Runtime Error):
N = int(input('N: '))
K = int(input('K: '))
S = input('S: ')
S1 = ''
for i in range (N):
    if i + 1 == K:
        if S[i] == 'A':
            S1 += 'a'
        elif S[i] == 'B':
            S1 += 'b'
        elif S[i] == 'C':
            S1 += 'c'
    else:
        S1 += S[i]

print(S1)


Fixed submission:
n, k = map(int, input().split())
s = list(input())
s[k-1] = chr(ord(s[k-1])+ord('a')-ord('A'))
print(''.join(s))

Buggy python submission (verdict: Runtime Error):
N = 0
while N<1 or N>50:
	N = int(input('N: '))
    if N<1 or N>50:
      print('1 <= N <= 50')
K = 0
while K<1 or K>N:
  K = int(input('K: '))
  if K<1 or K>N:
    print('1 <= K <= N')
S = ''
while len(S) != N:
  S = input('S: ')
  if len(S) != N:
    print("Length doesn't Match")
  for i in S:
    if i != 'A' and i != 'B' and i != 'C':
      print('Only A, B and C allowed')
      S = ''
      break

S1 = ''
for i in range (N):
  if i + 1 == K:
    if S[i] == 'A':
      S1 += 'a'
    elif S[i] == 'B':
      S1 += 'b'
    elif S[i] == 'C':
      S1 += 'c'
  else:
 	 S1 += S[i]
S = S1
print(S)

Fixed submission:
n, k = map(int, input().split())
s = list(input())
s[k-1] = chr(ord(s[k-1])+ord('a')-ord('A'))
print(''.join(s))
Buggy python submission (verdict: Runtime Error):
S = input()
S1 = int(s[:2])
S2 = int(s[2:])

if 1<=s1<=12 and 1<=s2<=12:
  print("AMBIGUOUS")
elif 0<=s1<=99 and 1<=s2<=12:
  print("YYMM")
elif 1<=s1<=12 and 0<=s2<=99:
  print("MMYY")
else:
  print("NA")

Fixed submission:
S = input()
S1 = int(S[:2])
S2 = int(S[2:])

if 1 <= S1 <= 12 and 1 <= S2 <= 12:
  print("AMBIGUOUS")
elif 0 <= S1 <= 99 and 1 <= S2 <= 12:
  print("YYMM")
elif 1 <= S1 <= 12 and 0 <= S2 <= 99:
  print("MMYY")
else:
  print("NA")
Buggy python submission (verdict: Runtime Error):
N,K = map(int, input().split())
N += 1 ; K += 1
H = list(map(int, input().split()))
L = [0] + [1000000000]*N
for i in range (N):
  for j in range(i+1, min(i+K, N-1)):
    L[j] = min(L[j], L[i] + abs(H[j] - H[i]))
print(L[N-2])

Fixed submission:
N = int(input())
H = list(map(int, input().split()))
L = [0]*N
L[1] = abs(H[1] - H[0])
for i in range (2,N):
  X = L[i-1] + abs(H[i] - H[i-1])
  Y = L[i-2] + abs(H[i] - H[i-2])
  L[i] = min(X,Y)
print(L[N-1])
Buggy python submission (verdict: Time Limit Exceeded):
N,K = map(int, input().split())
H = list(map(int, input().split()))
L = [0]*N
for i in range (1,N):
  L[i] = min(L[i-j] + abs(H[i] - H[i-j]) for j in range(1, min(i,K)+1))
print(L[N-1])

Fixed submission:
N,K = map(int, input().split())
H = list(map(int, input().split()))
L = [0]*N
for i in range (1,N):
  L[i] = min(L[i-j] + abs(H[i] - H[i-j]) for j in range(1, min(i,K)+1))
print(L[N-1])

Buggy python submission (verdict: Time Limit Exceeded):
N,K = map(int, input().split())
N += 1 ; K += 1
H = list(map(int, input().split()))
L = [0] + [1000000000]*N
for i in range (N):
  for j in range(i+1, min(i+K, N-1)):
    L[j] = min(L[j], L[i] + abs(H[j] - H[i]))
print(L[N-2])

Fixed submission:
N,K = map(int, input().split())
H = list(map(int, input().split()))
L = [0]*N
for i in range (1,N):
  L[i] = min(L[i-j] + abs(H[i] - H[i-j]) for j in range(1, min(i,K)+1))
print(L[N-1])
Buggy python submission (verdict: Time Limit Exceeded):
N,W = map(int, input().split())
L = [0]*(W+1)
for i in range (N):
  X,Y = map(int, input().split())
  for j in range (W,X-1,-1):
    L[j] = max(L[j], L[j-X] + Y)
print(max(L))

Fixed submission:
N,W = map(int, input().split())
L = [0]*(W+1)
for i in range (N):
  X,Y = map(int, input().split())
  for j in range (W,X-1,-1):
    L[j] = max(L[j], L[j-X] + Y)
print(max(L))
Buggy python submission (verdict: Time Limit Exceeded):
S = input()
T = input()
X,Y = len(S),len(T)
L = [[0 for _ in range (Y+1)] for _ in range (X+1)]
for i in range (X):
  for j in range (Y):
    if S[i] == T[j]:
      L[i+1][j+1] = L[i][j]+1
    else:
      L[i+1][j+1] = max(L[i][j+1] , L[i+1][j] , L[i+1][j+1])
K = ''
while X*Y:
  if S[X-1] == T[Y-1]:
    K += S[X-1]
    X -= 1
    Y -= 1
  else:
    if L[X-1][Y] > L[X][Y-1]:
      X -= 1
    else:
      Y -= 1
print(K[::-1])

Fixed submission:
S = input()
T = input()
X,Y = len(S),len(T)
L = [[0 for _ in range (Y+1)] for _ in range (X+1)]
for i in range (X):
  for j in range (Y):
    if S[i] == T[j]:
      L[i+1][j+1] = L[i][j]+1
    else:
      L[i+1][j+1] = max(L[i][j+1] , L[i+1][j] , L[i+1][j+1])
K = ''
while X*Y:
  if S[X-1] == T[Y-1]:
    K += S[X-1]
    X -= 1
    Y -= 1
  else:
    if L[X-1][Y] > L[X][Y-1]:
      X -= 1
    else:
      Y -= 1
print(K[::-1])
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))
ctr = 0
for i in range (N):
  ck = 0
  for j in range (i, N):
    ck += A[j]
    if ck == 0:
      ctr += 1
print(ctr)

Fixed submission:
from collections import Counter
N = int(input())
A = list(map(int, input().split()))
for i in range (1, N):
  A[i] += A[i-1]
A = Counter(A)
k = 0
for j in A.values():
  k += j*(j-1)//2
k += A.get(0,0)
print(k)
Buggy python submission (verdict: Time Limit Exceeded):
a,b = map(int, input().split())
L = []
for i in range (a,b+1):
  L.append(i)
P = 1
for j in L:
  P *= j
if P > 0:
  print('Positive')
elif P == 0:
  print('Zero')
else:
  print('Negative')

Fixed submission:
a,b = map(int, input().split())
if a > 0:
  print("Positive")
elif b<0:
  if((b-a)%2 == 0):
    print("Negative")
  else:
    print("Positive")
else:
  print("Zero")

Buggy python submission (verdict: Runtime Error):
a,b = map(int, input().split())
L = []
for i in range (a,b+1):
  L.append(i)
P = 1
for j in L:
  P *= j
if P > 0:
  print('Positive')
elif P = 0:
  print('Zero')
else:
  print('Negetive')

Fixed submission:
a,b = map(int, input().split())
if a > 0:
  print("Positive")
elif b<0:
  if((b-a)%2 == 0):
    print("Negative")
  else:
    print("Positive")
else:
  print("Zero")
Buggy python submission (verdict: Runtime Error):
N = int(input())
L = list(map(int, input().split()))
L.sort()
S = 0
for i in range (0, 2*N+1, 2):
  S += L[i]
print(S)

Fixed submission:
N = int(input())
L = list(map(int, input().split()))
L.sort()
S = 0
for i in range (1, 2*N+1, 2):
  S += L[i-1]
print(S)
Buggy python submission (verdict: Time Limit Exceeded):
n,k  = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
start = 1
for i in range(k):
    start*=a[i]
for i in range(n-k):
    ele = a[i+k]
    new = (start//a[i])*ele
    if new<=start:
        print("No")
    else:
        print("Yes")
    start = new


Fixed submission:
n,k  = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
for i in range(n-k):
    ele = a[i+k]
    if ele<=a[i]:
        print("No")
    else:
        print("Yes")
Buggy python submission (verdict: Time Limit Exceeded):
import itertools
import sys
from collections import defaultdict

input = sys.stdin.readline


class AtCoder:
    def main(self):
        N = int(input())
        L = list(map(int, input().split()))

        ans = 0

        for a,b,c in itertools.combinations(L,3):
            if a < b + c and b < c + a and c < a + b:
                ans += 1

        print(ans)


# Run main
if __name__ == '__main__':
    AtCoder().main()


Fixed submission:
import bisect
import itertools
import sys

input = sys.stdin.readline


class AtCoder:
    def main(self):
        N = int(input())
        L = list(map(int, input().split()))

        ans = 0
        L.sort()

        for i in range(N - 2):
            for j in range(i + 1, N - 1):
                ind = bisect.bisect_left(L, L[i] + L[j])
                ans += ind - j - 1

        print(ans)


# Run main
if __name__ == '__main__':
    AtCoder().main()
Buggy python submission (verdict: Time Limit Exceeded):
import sys

input = sys.stdin.readline


# https://atcoder.jp/contests/agc039/submissions/7878237
class AtCoder:
    def main(self):
        N = int(input())
        X = input().rstrip()

        k_cycles = 0
        ans = 0
        L = []
        for k in self.make_divisors(N):
            if (N // k) % 2 != 0:
                first_k_bit = X[:k]
                first_k_bit_ = first_k_bit.replace("0", "2").replace("1", "0").replace("2", "1")
                check_target = first_k_bit + (first_k_bit_ + first_k_bit) * ((N // k - 1) // 2)
                k_cycle = int(first_k_bit, 2) + (int(check_target, 2) <= int(X, 2))

                for l, cnt in L:
                    if k % l == 0:
                        k_cycle -= cnt
                L.append((k, k_cycle))

                k_cycles += k_cycle
                ans += 2 * k * k_cycle

        ans += (int(X, 2) + 1 - k_cycles) * 2 * N

        print(ans % 998244353)

    def make_divisors(self, n: int):
        divisors = []
        for i in range(1, int(n ** 0.5) + 1):
            if n % i == 0:
                divisors.append(i)
                if i != n // i:
                    divisors.append(n // i)

        divisors.sort()
        return divisors


# Run main
if __name__ == '__main__':
    AtCoder().main()


Fixed submission:
import sys

input = sys.stdin.readline


# https://atcoder.jp/contests/agc039/submissions/7878237
class AtCoder:
    def main(self):
        N = int(input())
        X = input().rstrip()

        k_cycles = 0
        ans = 0
        L = []
        for k in self.make_divisors(N):
            if (N // k) % 2 != 0:
                first_k_bit = X[:k]
                first_k_bit_ = first_k_bit.replace("0", "2").replace("1", "0").replace("2", "1")
                check_target = first_k_bit + (first_k_bit_ + first_k_bit) * ((N // k - 1) // 2)
                k_cycle = int(first_k_bit, 2) + (int(check_target, 2) <= int(X, 2))

                for l, cnt in L:
                    if k % l == 0:
                        k_cycle -= cnt
                L.append((k, k_cycle))

                k_cycles += k_cycle
                ans += 2 * k * k_cycle

        ans += (int(X, 2) + 1 - k_cycles) * 2 * N

        print(ans % 998244353)

    def make_divisors(self, n: int):
        divisors = []
        for i in range(1, int(n ** 0.5) + 1):
            if n % i == 0:
                divisors.append(i)
                if i != n // i:
                    divisors.append(n // i)

        divisors.sort()
        return divisors


# Run main
if __name__ == '__main__':
    AtCoder().main()
Buggy python submission (verdict: Time Limit Exceeded):
from fractions import gcd
import sys

input = sys.stdin.readline


class AtCoder:
    def main(self):
        A, B = map(int, input().split())

        _gcd = gcd(A, B)

        root_gcd = _gcd ** 0.5
        p = 2
        prim_num = 1
        while p <= root_gcd or _gcd > 1:
            tmp = _gcd
            while True:
                if _gcd % p == 0:
                    _gcd /= p
                else:
                    break
            if tmp != _gcd:
                prim_num += 1

            p += 1
        print(prim_num)


# Run main
if __name__ == '__main__':
    AtCoder().main()


Fixed submission:
import sys

input = sys.stdin.readline


class AtCoder:

    def gcd(self, a, b):
        if b == 0:
            return a
        else:
            return self.gcd(b, a % b)

    def factorize(self, n):
        p = 2
        res = 1
        while p * p < n:
            if n % p == 0:
                res += 1
                while n % p == 0:
                    n /= p
            p += 1
        if n != 1:
            res += 1
        return res

    def main(self):
        A, B = map(int, input().split())

        _gcd = self.gcd(A, B)
        print(self.factorize(_gcd))


# Run main
if __name__ == '__main__':
    AtCoder().main()

Buggy python submission (verdict: Runtime Error):
import math
import sys

input = sys.stdin.readline


class AtCoder:
    def main(self):
        A, B = map(int, input().split())

        gcd = math.gcd(A, B)

        root_gcd = gcd ** 0.5
        p = 2
        prim_num = 1
        while p <= root_gcd or gcd > 1:
            tmp = gcd
            while True:
                if gcd % p == 0:
                    gcd /= p
                else:
                    break
            if tmp != gcd:
                prim_num += 1

            p += 1
        print(prim_num)


# Run main
if __name__ == '__main__':
    AtCoder().main()


Fixed submission:
import sys

input = sys.stdin.readline


class AtCoder:

    def gcd(self, a, b):
        if b == 0:
            return a
        else:
            return self.gcd(b, a % b)

    def factorize(self, n):
        p = 2
        res = 1
        while p * p < n:
            if n % p == 0:
                res += 1
                while n % p == 0:
                    n /= p
            p += 1
        if n != 1:
            res += 1
        return res

    def main(self):
        A, B = map(int, input().split())

        _gcd = self.gcd(A, B)
        print(self.factorize(_gcd))


# Run main
if __name__ == '__main__':
    AtCoder().main()
Buggy python submission (verdict: Runtime Error):
import numpy as np
h,w,a,b =map(int,input().split())
for i in range(b):
    print('1'*a+'0'*(w-a))
for i in range(h-b):
    print('0'*a+'1'*(w-a))

Fixed submission:
def main():
    h,w,a,b=map(int,input().split())
    Ans=[[0]*w for _ in range(h)]
    for x in range(h):
        for y in range(w):
            Ans[x][y]=int((x<b)^(y<a))
    for ans in Ans:
        print(*ans,sep='')
    return
    
if __name__=='__main__':
    main()

Buggy python submission (verdict: Runtime Error):
import sys

input = sys.stdin.readline


class AtCoder:
    def main(self):
        H, W, A, B = map(int, input().split())

        mergin = 0
        ans = [[0] * W for _ in range(H)]
        cnt_h = 0
        check_1 = [0] * W
        check_0 = [0] * W
        for h in range(H):
            cnt_w = 0
            for w in range(W):
                if w < mergin:
                    check_0[w] += 1
                elif cnt_w < A:
                    ans[h][w] = 1
                    check_1[w] += 1
                    cnt_w += 1
                else:
                    check_0[w] += 1
            cnt_h += 1
            if cnt_h == B:
                mergin += A
                cnt_h = 0

        flag = True
        for w in range(W):
            if min(check_0[w], check_1[w]) != B:
                flag = False
        for h in range(H):
            if min(ans[h].count(0), ans[h].count(1)) != A:
                flag = False
        if flag:
            for h in range(H):
                for w in range(W):
                    print(ans[h][w], end='')
                print()
            exit()

        mergin = 0
        ans = [[0] * W for _ in range(H)]
        cnt_h = 0
        check_1 = [0] * H
        check_0 = [0] * H
        for h in range(W):
            cnt_w = 0
            for w in range(H):
                if w < mergin:
                    check_0[w] += 1
                elif cnt_w < B:
                    ans[h][w] = 1
                    check_1[w] += 1
                    cnt_w += 1
                else:
                    check_0[w] += 1
            cnt_h += 1
            if cnt_h == A:
                mergin += B
                cnt_h = 0

        flag = True
        for w in range(H):
            if min(check_0[w], check_1[w]) != A:
                flag = False
        for h in range(W):
            if min(ans[h].count(0), ans[h].count(1)) != B:
                flag = False
        if flag:
            for h in range(H):
                for w in range(W):
                    print(ans[h][w], end='')
                print()
            exit()


# Run main
if __name__ == '__main__':
    AtCoder().main()


Fixed submission:
def main():
    h,w,a,b=map(int,input().split())
    Ans=[[0]*w for _ in range(h)]
    for x in range(h):
        for y in range(w):
            Ans[x][y]=int((x<b)^(y<a))
    for ans in Ans:
        print(*ans,sep='')
    return
    
if __name__=='__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
import bisect
import sys

input = sys.stdin.readline


class AtCoder:
    def main(self):
        N, M = map(int, input().split())
        A = list(map(int, input().split()))

        A.sort()
        for _ in range(M):
            bisect.insort(A, A.pop() // 2)

        print(sum(A))


# Run main
if __name__ == '__main__':
    AtCoder().main()


Fixed submission:
import bisect
import heapq
import sys

input = sys.stdin.readline


class AtCoder:
    def main(self):
        N, M = map(int, input().split())
        hq = []
        for c in input().split():
            heapq.heappush(hq, -1 * int(c))

        for _ in range(M):
            heapq.heappush(hq, int(heapq.heappop(hq) / 2))

        print(-1 * sum(hq))


# Run main
if __name__ == '__main__':
    AtCoder().main()

Buggy python submission (verdict: Time Limit Exceeded):
import bisect
import sys

input = sys.stdin.readline


class AtCoder:
    def main(self):
        N, M = map(int, input().split())
        A = list(map(int, input().split()))

        A.sort()
        for _ in range(M):
            v = A[-1] // 2
            A.pop()
            bisect.insort(A, v)

        print(sum(A))


# Run main
if __name__ == '__main__':
    AtCoder().main()


Fixed submission:
import bisect
import heapq
import sys

input = sys.stdin.readline


class AtCoder:
    def main(self):
        N, M = map(int, input().split())
        hq = []
        for c in input().split():
            heapq.heappush(hq, -1 * int(c))

        for _ in range(M):
            heapq.heappush(hq, int(heapq.heappop(hq) / 2))

        print(-1 * sum(hq))


# Run main
if __name__ == '__main__':
    AtCoder().main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys

input = sys.stdin.readline


class AtCoder:
    def main(self):
        N, M = map(int, input().split())
        A = list(map(int, input().split()))

        for _ in range(M):
            A.sort()
            A[-1] //= 2

        print(sum(A))


# Run main
if __name__ == '__main__':
    AtCoder().main()


Fixed submission:
import bisect
import heapq
import sys

input = sys.stdin.readline


class AtCoder:
    def main(self):
        N, M = map(int, input().split())
        hq = []
        for c in input().split():
            heapq.heappush(hq, -1 * int(c))

        for _ in range(M):
            heapq.heappush(hq, int(heapq.heappop(hq) / 2))

        print(-1 * sum(hq))


# Run main
if __name__ == '__main__':
    AtCoder().main()
Buggy python submission (verdict: Time Limit Exceeded):
import sys

input = sys.stdin.readline


class AtCoder:
    def main(self):
        N = int(input())
        S = input().rstrip()

        half = N // 2
        for length in range(1, half + 1)[::-1]:
            i = 0
            already = set()
            while i + length < N:
                v = S[i:i + length]
                if v in already:
                    i += 1
                    continue

                if S.count(S[i:i + length]) >= 2:
                    print(length)
                    exit()
                else:
                    already.add(v)
                    i += 1
        print(0)


# Run main
if __name__ == '__main__':
    AtCoder().main()


Fixed submission:
import sys

input = sys.stdin.readline


class AtCoder:
    def main(self):
        N = int(input())
        S = input().rstrip()

        dp = [[0 for i in range(N + 1)] for j in range(N + 1)]
        ans = 0
        for i in range(N)[::-1]:
            for j in range(N)[::-1]:
                if S[i] == S[j]:
                    dp[i][j] = min(dp[i + 1][j + 1] + 1, abs(i - j))
                    ans = max(ans, dp[i][j])
        print(ans)


# Run main
if __name__ == '__main__':
    AtCoder().main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys

input = sys.stdin.readline


class AtCoder:
    def main(self):
        N = int(input())
        S = input().rstrip()

        l = N // 2
        for i in range(1, l + 1)[::-1]:
            j = 0
            while j + i < N:
                if S.count(S[j:j + i]) >= 2:
                    print(i)
                    exit()
                else:
                    j += 1
        print(0)


# Run main
if __name__ == '__main__':
    AtCoder().main()

Fixed submission:
import sys

input = sys.stdin.readline


class AtCoder:
    def main(self):
        N = int(input())
        S = input().rstrip()

        dp = [[0 for i in range(N + 1)] for j in range(N + 1)]
        ans = 0
        for i in range(N)[::-1]:
            for j in range(N)[::-1]:
                if S[i] == S[j]:
                    dp[i][j] = min(dp[i + 1][j + 1] + 1, abs(i - j))
                    ans = max(ans, dp[i][j])
        print(ans)


# Run main
if __name__ == '__main__':
    AtCoder().main()
Buggy python submission (verdict: Runtime Error):
# sys.stdin.readline
import sys

input = sys.stdin.readline


class AtCoder:
    def main(self):
        N, K = map(int, input().split())
        S = input().rstrip()

        b = []
        before = S[0]
        cnt = 1
        for i in range(1, N):
            if before == S[i]:
                cnt += 1
                if i == N - 1:
                    b.append(cnt)
            else:
                b.append(cnt)
                cnt = 1
                before = S[i]

        for _ in range(K):
            target = None
            tmp = 0
            if len(b) == 1:
                break
            if len(b) == 2:
                b = [sum(b)]
                break
            for i in range(1, len(b) - 1):
                current = b[i - 1] + b[i] + b[i + 1]
                if current > tmp:
                    tmp = current
                    target = i
            b = b[:target - 1] + [tmp] + b[target + 2:]

        print(sum(b) - len(b))


# Run main
if __name__ == '__main__':
    AtCoder().main()

Fixed submission:
# sys.stdin.readline
import sys

input = sys.stdin.readline


class AtCoder:
    def main(self):
        N, K = map(int, input().split())
        S = input().rstrip()

        score = 0
        for i in range(N - 1):
            if S[i] == S[i + 1]:
                score += 1
        print(min(N - 1, score + 2 * K))
            

# Run main
if __name__ == '__main__':
    AtCoder().main()