Language: Java

#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair < int , pair < int , int > > mp;

#define rep(i , j , n) for(long long i = j ; i <= n ; i++)
#define per(i , j , n) for(long long i = j ; i >= n ; i--)
 
const ll N = 123456;
const ll mod = 1e9 + 7;
const ld eps = 1e-6;
const ld pi = 3.1415926535;

int a[N];
int vis[N];
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
 
    cout << fixed << setprecision(12);

    int n;

    int k;

    cin >> n >> k;

    string s;
    cin >> s;

    rep(i , 1 , n) {
      if(s[i - 1] == 'L') {
        a[i] = 1;
      }
      else {
        a[i] = -1;
      }
    }

    // rep(i , 1 , n) {
    //   a[i] += a[i - 1];
    // }

    // rep(i , 1 , n) {
    //   cout << a[i] << " ";
    // }

    // cout << endl;

    int sum = 0;

    int cur = 1;
    if(n == 1) {
      cout << 0 << endl;
      return 0;
    }

    vector < int > res;

    // rep(i , 1 , n) {
    //     cout << a[i] << endl;
    // }
    rep(i , 2 , n) {
        if(a[i] == a[i - 1]) {
            //cout << a[i - 1] << " " << a[i] << endl;
            cur++;
        }
        else {
            res.push_back(cur);
            cur = 1;
        }
    }

    res.push_back(cur);

    for(auto j : res) {
        sum += j - 1;
    }

    while(k--) {
        sum += 2;
    }
    cout << min(sum , n - 1) << endl;
    return 0;

}


Compiler output:
Main.java:1: error: illegal character: '#'
#include <bits/stdc++.h>
^
Main.java:1: error: class, interface, enum, or record expected
#include <bits/stdc++.h>
         ^
Main.java:5: error: class, interface, enum, or record expected
typedef long long ll;
^
Main.java:6: error: class, interface, enum, or record expected
typedef long double ld;
^
Main.java:7: error: class, interface, enum, or record expected
typedef pair < int , pair < int , int > > mp;
^
Main.java:9: error: illegal character: '#'
#define rep(i , j , n) for(long long i = j ; i <= n ; i++)
^
Main.java:9: error: class, interface, enum, or record expected
#define rep(i , j , n) for(long long i = j ; i <= n ; i++)
        ^
Main.java:9: error: class, interface, enum, or record expected
#define rep(i , j , n) for(long long i = j ; i <= n ; i++)
                                             ^
Main.java:9: error: class, interface, enum, or record expected
#define rep(i , j , n) for(long long i = j ; i <= n ; i++)
                                                      ^
Main.java:10: error: illegal character: '#'
#define per(i , j , n) for(long long i = j ; i >= n ; i--)
^
Main.java:10: error: class, interface, enum, or record expected
#define per(i , j , n) for(long long i = j ; i >= n ; i--)
                                             ^
Main.java:10: error: class, interface, enum, or record expected
#define per(i , j , n) for(long long i = j ; i >= n ; i--)
                                                      ^
Main.java:13: error: class, interface, enum, or record expected
const ll mod = 1e9 + 7;
^
Main.java:14: error: class, interface, enum, or record expected
const ld eps = 1e-6;
^
Main.java:15: error: class, interface, enum, or record expected
const ld pi = 3.1415926535;
^
Main.java:17: error: class, interface, enum, or record expected
int a[N];
^
Main.java:18: error: class, interface, enum, or record expected
int vis[N];
^
Main.java:20: error: not a statement
    ios_base::sync_with_stdio(false);
    ^
Main.java:23: error: not a statement
    cout << fixed << setprecision(12);
                  ^
Main.java:29: error: not a statement
    cin >> n >> k;
             ^
Main.java:32: error: not a statement
    cin >> s;
        ^
Main.java:57: error: not a statement
      cout << 0 << endl;
                ^
Main.java:86: error: not a statement
    cout << min(sum , n - 1) << endl;
                             ^
Main.java:19: error: unnamed classes are a preview feature and are disabled by default.
int main() {
^
  (use --enable-preview to enable unnamed classes)
Main.java:20: error: ';' expected
    ios_base::sync_with_stdio(false);
                             ^
Main.java:34: error: ';' expected
    rep(i , 1 , n) {
                  ^
Main.java:66: error: ';' expected
    rep(i , 2 , n) {
                  ^
27 errors