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.42.0) (judge verdict: Wrong Answer)

// // -*- coding:utf-8-unix -*-

// #[macro_use]
extern crate lazy_static;
extern crate num_bigint; // 0.2.2
extern crate num_traits; // 0.2.8
use num_bigint::BigInt;
use num_traits::Pow;
use petgraph::algo::dijkstra;
use petgraph::Directed;

// // use proconio::derive_readable;
use proconio::fastout;
use proconio::input;
// use std::convert::TryInto;
use ascii::{AsciiChar, AsciiString};
use itertools::concat;
use lazy_static::lazy_static;
// use libm::*;
use petgraph::Graph;
use std::cmp::*;
use std::collections::{BinaryHeap, HashMap, HashSet, VecDeque};
use std::io::*;
use std::ops::Range;
use std::str::FromStr;
use std::sync::Mutex;
use superslice::*;

// pub fn read<T: FromStr>() -> T {
//     let stdin = stdin();
//     let stdin = stdin.lock();
//     let token: String = stdin
//         .bytes()
//         .map(|c| c.expect("failed to read char") as char)
//         .skip_while(|c| c.is_whitespace())
//         .take_while(|c| !c.is_whitespace())
//         .collect();
//     token.parse().ok().expect("failed to parse token")
// }

// // lazy_static! {
// //     static ref H: Mutex<Vec<i32>> = Mutex::default();
// //     static ref W: Mutex<Vec<i32>> = Mutex::default();
// // }

// // let mut values = VALUES.lock().unwrap();
// // values.extend_from_slice(&[1, 2, 3, 4]);
// // assert_eq!(&*values, &[1, 2, 3, 4]);

use proconio::marker::Chars;
// use std::collections::HashMap;

// static ASCII_LOWER: [char; 26] = [
//     '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',
// ];

// abc172-D
fn main() {
    input! {
        n: usize,
        k: usize,
        s: Chars
    }

    // let mut s_extend = Vec::new();
    // s_extend.push('R');
    // s_extend.extend_from_slice(s.as_slice());
    // s_extend.push('L');
    let mut changes_l2r = 0;
    let mut changes_r2l = 0;
    let mut old = None;
    let mut hap = 0;
    let mut del: i64 = 0;
    for s in s.iter() {
        if let Some(v) = old {
            if v != *s {
                if *s == 'L' {
                    changes_r2l += 1;
                } else {
                    changes_l2r += 1;
                }
            } else {
                hap += 1;
            }
        } else {
            if *s == 'L' {
                changes_r2l += 1;
                del -= 1;
            } else {
                // changes_l2r += 1;
            }
        }
        old = Some(*s);
    }

    if *s.last().unwrap() == 'R' {
        changes_r2l += 1;
        del -= 1;
    }

    let min_v = min(changes_r2l, changes_l2r);
    // eprintln!("{}, {}, {}", changes_r2l, changes_l2r, hap);
    if min_v <= k {
        // if min_v % 2 == 1 {
        //     println!("1:{}", min_v * 2 + hap - 1);
        //     return;
        // } else {
        if del == -2 && changes_r2l != changes_l2r {
            del = -1;
        }
        println!("{}", (min_v * 2 + hap) as i64 + del);
        return;
        // }
    }

    println!("{}", (hap + 2 * k) as i64);

    // println!("{}", ans);
}