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 Rust (1.15.1) (judge verdict: Accepted)

// This code is generated by [cargo-atcoder](https://github.com/tanakh/cargo-atcoder)
// Original source code:
/*
#![allow(unused_imports)]
use std::cmp::*;
use std::collections::*;
use itertools::Itertools;
use num::clamp;
use proconio::{input, marker::*, fastout};
use superslice::*;

#[fastout()]
fn main() {
    input! {
        n: usize, k: usize,
        s: Chars
    }

    let mut happiness = 0;
    for i in 0..n-1 {
        if s[i] == 'R' && s[i+1] == 'R' {
            happiness += 1;
        }
        if s[n-1-i] == 'L' && s[n-2-i] == 'L' {
            happiness += 1;
        }
    }

    let mut to_r = 0;
    let mut r_happiness = happiness;
    let mut pos = 0;
    let mut has_l = false;
    let mut has_r = false;
    while pos < n && to_r < k{
        if s[pos] == 'R' {
            has_r = true;
            if has_l {
                to_r += 1;
                r_happiness += 2;
                has_l = false;
            }
        } else if has_r {
            has_l = true;
        }
        pos += 1;
    }
    if pos == n && has_r && has_l && to_r < k {
        to_r += 1;
        r_happiness += 1;
    }
    if has_r && to_r < k && s[0] == 'L' {
        r_happiness +=1;
    }

    let mut to_l = 0;
    let mut l_happiness = happiness;
    let mut rpos = n;
    let mut has_r = false;
    let mut has_l = false;
    while rpos > 0 && to_l < k{
        if s[rpos-1] == 'L' {
            has_l = true;
            if has_r {
                to_l += 1;
                l_happiness += 2;
                has_r = false;
            }
        } else if has_l {
            has_r = true;
        }
        rpos -= 1;
    }
    if rpos == 0 && has_l && has_r && to_l < k {
        to_l += 1;
        l_happiness += 1;
    }
    if has_l && to_l < k && s[n-1] == 'R' {
        l_happiness +=1;
    }

    let ans = max(l_happiness, r_happiness);
    println!("{}", ans);
}
*/

fn main() {
    let exe = "/tmp/bin38FD4ED1";
    std::io::Write::write_all(&mut std::fs::File::create(exe).unwrap(), &decode(BIN)).unwrap();
    std::fs::set_permissions(exe, std::os::unix::fs::PermissionsExt::from_mode(0o755)).unwrap();
    std::process::exit(std::process::Command::new(exe).status().unwrap().code().unwrap())
}

fn decode(v: &str) -> Vec<u8> {
    let mut ret = vec![];
    let mut buf = 0;
    let mut tbl = vec![64; 256];
    for i in 0..64 { tbl[TBL[i] as usize] = i as u8; }
    for (i, c) in v.bytes().filter_map(|c| { let c = tbl[c as usize]; if c < 64 { Some(c) } else { None } }).enumerate() {
        match i % 4 {
            0 => buf = c << 2,
            1 => { ret.push(buf | c >> 4); buf = c << 4; }
            2 => { ret.push(buf | c >> 2); buf = c << 6; }
            3 => ret.push(buf | c),
            _ => unreachable!(),
        }
    }
    ret
}

const TBL: &'static [u8] = b"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
const BIN: &'static str = "<base64-encoded ELF executable removed>";