Problem:
Score : 400 points

Problem Statement

There are N people standing in a queue from west to east.

Given is a string S of length N representing the directions of the people.
The i-th person from the west is facing west if the i-th character of S is L, and east if that character of S is R.

A person is happy if the person in front of him/her is facing the same direction.
If no person is standing in front of a person, however, he/she is not happy.

You can perform the following operation any number of times between 0 and K (inclusive):

Operation: Choose integers l and r such that 1 \leq l \leq r \leq N, and rotate by 180 degrees the part of the queue: the l-th, (l+1)-th, ..., r-th persons. That is, for each i = 0, 1, ..., r-l, the (l + i)-th person from the west will stand the (r - i)-th from the west after the operation, facing east if he/she is facing west now, and vice versa.

What is the maximum possible number of happy people you can have?

Constraints

N is an integer satisfying 1 \leq N \leq 10^5.

K is an integer satisfying 1 \leq K \leq 10^5.

|S| = N

Each character of S is L or R.

Input

Input is given from Standard Input in the following format:

N K
S

Output

Print the maximum possible number of happy people after at most K operations.

Sample Input 1

6 1
LRLRRL

Sample Output 1

3

If we choose (l, r) = (2, 5), we have LLLRLL, where the 2-nd, 3-rd, and 6-th persons from the west are happy.

Sample Input 2

13 3
LRRLRLRRLRLLR

Sample Output 2

9

Sample Input 3

10 1
LLLLLRRRRR

Sample Output 3

9

Sample Input 4

9 2
RRRLRLRLL

Sample Output 4

7

Solution in C# (Mono 4.6.2.0) (judge verdict: Accepted)

#if true
//#if false
#define UTAKA_DEBUG
#endif

using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Runtime.CompilerServices;

namespace UtakaApp
{
    public partial class Program
    {
        public const string ContestName = "abc140";
        public const string ProblemName = "D";

        public static void Main(string[] args)
        {
#if UTAKA_LOCAL
//#if false
            new TestCaseCheckerForAtCoder().TestProblems();
#else
            var console = new MyConsole();
            new Program().Solve(System.Console.In, console);
            console.Flush();
#endif
            var sw = new StreamWriter(System.Console.OpenStandardOutput()) {AutoFlush = false};
        }

        public void Solve(TextReader textReader, IConsole console)
        {
            var cin = new ConsoleInput(textReader, ' ');

            int N = cin.ReadInt;
            int K = cin.ReadInt;

            string S = cin.Read;

            bool[] A = new bool[N];
            
            for (int i = 0; i < N; i++)
            {
                char c = S[i];
                if (c == 'L')
                {
                    A[i] = true;
                }
                else
                {
                    A[i] = false;
                }
            }

            int initialCount = 0;

            bool prev = A[0];

            for (int i = 1; i < N; i++)
            {
                bool current = A[i];
                if (prev == current)
                {
                    initialCount ++;
                }

                prev = current;
            }

            int ans = initialCount + (2 * K);

            ans = Math.Min(ans, N - 1);
            
            console.WriteLine(ans.ToString());



//            int count = 0;
//
//            int leftIndex = 0;
//            int rightIndex = N - 1;
//
//            bool lastLeft = false;
//            bool lastRight = false;
//
//            while (true)
//            {
//                while (leftIndex < rightIndex)
//                {
//                }
//            }
        }
    }

    public partial class Program
    {
        public const int ModLarge = 1000000007;
    }

    public class ConsoleInput
    {
        private readonly TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;

        public ConsoleInput(TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }

        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                {
                    inputStream.Enqueue(tmp[i]);
                }

                return inputStream.Dequeue();
            }
        }

        public string ReadLine => _stream.ReadLine();
        public int ReadInt => int.Parse(Read);
        public long ReadLong => long.Parse(Read);
        public double ReadDouble => double.Parse(Read);

        public string[] ReadStrArray(long N)
        {
            var ret = new string[N];
            for (long i = 0; i < N; ++i) ret[i] = Read;
            return ret;
        }

        public int[] ReadIntArray(long N)
        {
            var ret = new int[N];
            for (long i = 0; i < N; ++i) ret[i] = ReadInt;
            return ret;
        }

        public long[] ReadLongArray(long N)
        {
            var ret = new long[N];
            for (long i = 0; i < N; ++i) ret[i] = ReadLong;
            return ret;
        }
    }

    public interface IConsole
    {
        void Flush();
        void Write(string str);
        void WriteLine(string str);
    }

    public class MyConsole : IConsole
    {
        public MyConsole()
        {
            var sw = new StreamWriter(System.Console.OpenStandardOutput()) {AutoFlush = false};
            System.Console.SetOut(sw);
        }

        public void Flush()
        {
            System.Console.Out.Flush();
        }

        public void Write(string str)
        {
            System.Console.Write(str);
        }

        public void WriteLine(string str)
        {
            System.Console.WriteLine(str);
        }
    }

#if UTAKA_LOCAL

    public class DebugConsole : IConsole
    {
        private StringBuilder mSb;

        public DebugConsole()
        {
            mSb = new StringBuilder();
        }

        public void Flush()
        {
            // 何もしない
        }

        public void Write(string str)
        {
            mSb.Append(str);
        }

        public void WriteLine(string str)
        {
            mSb.AppendLine(str);
        }

        public string GetAllOutput()
        {
            return mSb.ToString();
        }
    }

#endif

#if UTAKA_LOCAL

    public class TestCaseCheckerForAtCoder
    {
        private string DirectoryPath => $"../../../../{Program.ContestName}/{Program.ProblemName}";

        private string GetInputFilePath(int testCaseNumber)
        {
            //return $"{DirectoryPath}/sample-{testCaseNumber}.in";
            return $"{DirectoryPath}/in_{testCaseNumber}.txt";
        }

        private string GetOutputFilePath(int testCaseNumber)
        {
            //return $"{DirectoryPath}/sample-{testCaseNumber}.out";
            return $"{DirectoryPath}/out_{testCaseNumber}.txt";
        }

        public bool TestProblem(int testCaseNumber)
        {
            var inputFilePath = GetInputFilePath(testCaseNumber);
            var outputFilePath = GetOutputFilePath(testCaseNumber);

            TextReader inputStream = new StreamReader(inputFilePath);

            var debugConsoleWriter = new DebugConsole();

            new Program().Solve(inputStream, debugConsoleWriter);

            var output = debugConsoleWriter.GetAllOutput();

            TextReader outputStream = new StreamReader(outputFilePath);
            var outputAnswer = outputStream.ReadToEnd();

            Dbg.WriteLine(output);
            Dbg.WriteLine(outputAnswer);

            var isCorrect = output == outputAnswer;

            return isCorrect;
        }

        public void TestProblems()
        {
            var isSuccessAll = true;

            var testCaseNumber = 1;
            while (true)
            {
                var inputFileName = GetInputFilePath(testCaseNumber);
                if (!File.Exists(inputFileName))
                {
                    break;
                }

                System.Console.WriteLine($"TestCase {testCaseNumber} =====================================================");

                var result = TestProblem(testCaseNumber);

                if (result)
                {
                    System.Console.WriteLine($"Success");
                }
                else
                {
                    isSuccessAll = false;
                    System.Console.WriteLine($"Failure *****");
                }

                testCaseNumber++;
            }

            if (isSuccessAll)
            {
                System.Console.WriteLine($"!!!!!!!!! All Success !!!!!!!!!");
            }
        }
    }

#endif

#if UTAKA_LOCAL

    public static class Dbg
    {
        public static void WriteLine(string str)
        {
            System.Console.WriteLine(str);
        }

        public static void Write(string str)
        {
            System.Console.Write(str);
        }
    }
#else
    public static class Dbg
    {
        public static void WriteLine(string str)
        {
        }

        public static void Write(string str)
        {
        }
    }

#endif
}