criyle/codenet-compile-errors huggingface dataset:
Language: C++

#include<bits\stdc++.h>
#deifne ll long long int
#define size(x)   x.size()
#define rep(i,a,b) for(ll i=a;i<b;i++)
using namespace std;
signed main(){
ll n;
  cin>>n;
  ll k;
  cin>>k;
  string s;
  cin>>s;
  ll dif=0,ans=0;
  rep(i,0,n-1)
  {
   if(s[i] == s[i+1])
     ans++;
    else dif++;
  }
  ans+=min(dif,2*k);
  cout<<ans;
}
  

Compiler output:
a.cc:1:9: fatal error: bits\stdc++.h: No such file or directory
    1 | #include<bits\stdc++.h>
      |         ^~~~~~~~~~~~~~~
compilation terminated.
Language: C++

#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

using namespace std;
typedef long long ll;

int main(){
	ll n, k;
	string s;
	cin >> n >> k;
	ll count = 0;
	cin >> s;

	for (int i = 0; i < n; i++){
		if (i != 0 && s[i] != s[i - 1])	count++;
	}
	ll ans = n - count + 2 * k-1;
	cout << min(ans, n - 1);

	cout << ans << endl;


Compiler output:
a.cc: In function 'int main()':
a.cc:22:29: error: expected '}' at end of input
   22 |         cout << ans << endl;
      |                             ^
a.cc:9:11: note: to match this '{'
    9 | int main(){
      |           ^
Language: C++

#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define HSORT(V,n) sort(V,V+n)
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
int main(){
    int n,k;
    cin >> n >> k;
    string s;
    cin >> s;
    int c = 0;
    int ans = 0;
    bool check = false;
    REP(i,n-1){
        if (s[i] == s[i+1]) ans++;
    }
    REP(i,n-1){
        if (s[i] == 'L' && s[i+1] == 'R'){
            c++;
        }
        if (c == k) {
            FOR(j,i+1,n) {
                if (s[j] == 'L') check = true;
            }
            break;
        }
    }
    if (i==n-2){
        if (s[0] == 'R') ans++;
        if (s[n-1] == 'L') check = true;
    }
    ans += 2*c;
    if (!check) ans--;
    PRINT(ans);
}


Compiler output:
a.cc: In function 'int main()':
a.cc:35:9: error: 'i' was not declared in this scope
   35 |     if (i==n-2){
      |         ^
Language: C++

#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;

int main(){
  int N, K;
  cin >> N >> K;
  string S;
  cin >> S;

  int score = 0;
  rep(i,N-1){
    if (S[i] == S[i+1]) score++;
  }
  int ans = min(score+2*K, n-1);
  cout << ans << endl;

  return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:15:28: error: 'n' was not declared in this scope
   15 |   int ans = min(score+2*K, n-1);
      |                            ^
Language: C++


#include <iostream>
#include <vector>

using namespace std;

int main(){
    int N, K;
    cin >> N >> K;
    string S;
    cin >> S;

    int ans = 0;
    for(int i = 0; i < N-1; i++){
        if(S[i] == S[i+1]){
            ans++;
        }
    }

    ans = min(ans+2*k, N-1);

    cout << ans << endl;


    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:20:21: error: 'k' was not declared in this scope
   20 |     ans = min(ans+2*k, N-1);
      |                     ^
Language: C++

#include <iostream>
#include <vector>
#include <map>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <functional>
#include <queue>
#include <utility>
#include <string>
using namespace std;
typedef long long ll;
int main(){
  int N,K;
  cin >> N >> K;
  string s;
  cin >> s;

  int score = 0;
  for(int i = 0;i < N - 1;i++)
    if(s[i] == s[i+1])score++;

  int ans = min(score+2*K,n-1);

  cout << ans << endl;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:23:27: error: 'n' was not declared in this scope
   23 |   int ans = min(score+2*K,n-1);
      |                           ^
Language: C++

#include<bits/stdc++.h>
using namespace std;
int main(){
    int n, k;
    cin >> n >> k;
    string s, buff;
    cin >> s;
    int flag = 0;
    for(int i=0; i<s.length();){
        int j = i;
        while(j<s.length() && s[j]==s[i])
            j++;
        buff.push_back(flag+'0');
        flag = flag^1;
        i = j;
    }
    if(buff.length()==1){
        cout << ((int)s.length())-1;
        return 0;
    }
    if(buff.length()==2){
        if(k>0)
            cout << ((int)s.length())-1;
        else
            cout << ((int)s.length())-2;
        return 0;
    }
    int len = buff.length();
    int i;
    if(buff[len-1])
        i=2;
    else
        i = 1;
    while(i<buff.length() && k){
        buff[i] = buff[i]^1;
        i+=2;
        k--;
    }
    if(k>0)
        buf[0] = buff[0]^1;
    int ctr = 0;
    for(int i=1; i<buff.length(); i++){
        if(buff[i]!=buff[i-1])
            ctr++;
    }
    cout << s.length()-ctr-1;
    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:40:9: error: 'buf' was not declared in this scope; did you mean 'buff'?
   40 |         buf[0] = buff[0]^1;
      |         ^~~
      |         buff
Language: C++

#include <iostream>
#include <string>

using namespace std;

int main(){
    int N,K;
    string S;
    cin >> N >> K;
    cin >> S;
    int count = 0;
    int initial = 0;
    for(int i = 0; i < S.length()-1;i++){
        if(S[i] == 'R' && S[i+1] == 'L') count += 1;
        if(S[i] == S[i+1]) initial += 1;
    }
    int ans = 0;
    if(K <= count-1) ans = initial + 2 * K;
    else if((S[0] == 'R' || S[N] == 'L') && K = count ) ans = initial + 2*(count-1) + 1;
    else if((S[0] == 'R' || S[N] == 'L') && K > count) ans = initial + 2*(count-1) + 2;
    

    cout << ans << endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:19:42: error: lvalue required as left operand of assignment
   19 |     else if((S[0] == 'R' || S[N] == 'L') && K = count ) ans = initial + 2*(count-1) + 1;
      |             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~
Language: C++

#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
#include<iomanip>
#include<list>
#include<deque>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define END {}
#endif
typedef long long ll;
#define int ll
#define uset unordered_set
#define umap unordered_map
typedef std::pair<int,int> P;
struct edge{int to,cost;};
const int INF=100000000000000000;
const int INF2=9223372036854775807;
const int MOD=1000000007;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define min(X,Y) (((int)(X)<(int)(Y))?(X):(Y))
#define max(X,Y) (((int)(X)>(int)(Y))?(X):(Y))
#define MAX(X,Y) (*max_element(X,Y))
#define MIN(X,Y) (*min_element(X,Y))
#define NP(X,Y) next_permutation(X,Y)
#define setp(X,Y) cout<<fixed<<setprecision(Y)<<X;
int ceil2(int a,int b){if(a%b==0){return a/b;}else{return a/b+1;}}
int pow2(int a,int b){int r=1;for(int i=1;i<=b;i++){r*=a;}return r;}
int Log2(int a){int t=0;while(1){if(a==0||a==1){break;}a/=2;t++;}return t;}

int N,K;
string S;
vector<int> v,v2;
int num[100010];

signed main(){
	cin>>N>>K;
	cin>>S;
	int cnt=1;
	REP(i,N-1){
		if(S[i]!=S[i+1]){
			cnt++;
		}
		else{
			ans++;
		}
	}
	if(cnt-N*2<=1){
		cout<<N-1<<endl;
	}
	else{
		ans+=2*K;
		cout<<ans<<endl;
	}
	return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:62:25: error: 'ans' was not declared in this scope; did you mean 'abs'?
   62 |                         ans++;
      |                         ^~~
      |                         abs
a.cc:69:17: error: 'ans' was not declared in this scope; did you mean 'abs'?
   69 |                 ans+=2*K;
      |                 ^~~
      |                 abs
Language: C++

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
int main() {
    int n,k,i,j,ans,co;
    co=0;
    cin>>n>>k;
    char a[n];
    rep(i,n){
      cin>>a[i];
    }
    ans=0;
   rep(i,n-1){
     if(a[i]=='R'&&a[i+1]=='R'){
         ans++;
     }
   }
   for(i=n-1;i>0;i--){
     if(a[i]=='L'&&a[i-1]=='L'){
         ans++;
     }
   }
   for(i=0;i<n-1;i++){
       if(a[i]=='L'&&a[i+1]=='R'){
        co++;
       }
       if(a[i]=='R'&&a[i+1]=='L'){
        co++;
       }
   }
   if(co+1-2k>2){
   cout<<ans+k*2<<endl;
   }else if(co==0){
       cout<<ans<<endl;
   }
   else {
   cout<<ans+co*2-1<<endl;
   }
}

Compiler output:
a.cc: In function 'int main()':
a.cc:33:12: error: fixed-point types not supported in C++
   33 |    if(co+1-2k>2){
      |            ^~
Language: C++

#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,k,a=0;string s;cin>>n>>k>>s;
  for(int i=0;i<N-1;i++){
    if(s.at(i)==s.at(i+1))a++;
  }
  cout<<min(k*2+a,n-1)<<endl;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:5:17: error: 'N' was not declared in this scope
    5 |   for(int i=0;i<N-1;i++){
      |                 ^
Language: C++

import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int N = stdIn.nextInt();
		int K = stdIn.nextInt();
		String S = stdIn.next();
		char[] s = S.toCharArray();
		long sum = 0;
		int out = 0;
		int in = 0;
		
		if(s[0] == 'R' && s[1] == 'R') sum++;
		else if(s[0] == 'L' && s[1] == 'R') out++;
		else if(s[0] == 'R' && s[1] == 'L') in++;
		
		if(s[N-1] == 'L' && s[N-2] == 'L') sum++;
		for(int i = 1; i < N-1; i++) {
			if(s[i] == 'L' && s[i-1] == 'L') sum++;
			else if(s[i] == 'R' && s[i+1] == 'R') sum++;
			
			if(s[i] == 'L' && s[i+1] == 'R') out++;
			else if(s[i] == 'R' && s[i+1] == 'L') in++;
		}
		
		if(Math.min(out,in) >= K) {
			sum += K*2;
		}
		else {
			sum += Math.min(out,in)*2;
			if(out == in);
			else if(K-Math.min(out,in) == 1 || Math.max(out,in)-Math.min(out,in) == 1) {
				if(Math.max(out,in) == out && (s[0] == 'L' || s[N-1] == 'R')) sum++;
				else if(Math.max(out,in) == in && (s[0] == 'R' || s[N-1] == 'L')) sum++;
			}
			else {
				if(Math.max(out,in) == out) {
					if(s[0] == 'L')sum++;
					if(s[N-1] == 'R')sum++;
				}
				else if(Math.max(out,in) == in) {
					if(s[0] == 'R')sum++;
					if(s[N-1] == 'L')sum++;
				}
			}
		}
		
		System.out.println(sum);

	}

}

Compiler output:
a.cc:1:1: error: 'import' does not name a type
    1 | import java.util.*;
      | ^~~~~~
a.cc:1:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:2:1: error: expected unqualified-id before 'public'
    2 | public class Main {
      | ^~~~~~
Language: C++

#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int N, K, count, d; cin >> N >> K;
  char S[N];
  cin >> S;
  
  for(int i = 0; i < N; i++){
  if(S[i] == S[i + 1]){
    count++;
  }
  }
  d = N - count - 1;
  //境界の数
  
  if(d > K * 2){
  count += K * 2;
  }
  else if(d <= K * 2){
    count = N;
  }
  cout << count << endl;
    

Compiler output:
a.cc: In function 'int main()':
a.cc:23:25: error: expected '}' at end of input
   23 |   cout << count << endl;
      |                         ^
a.cc:4:11: note: to match this '{'
    4 | int main(){
      |           ^
Language: C++

#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = s; i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << endl;
#define CFYN(n) cout << ( (n) ? "YES":"NO") << endl;
using ll = long long;
using ull = unsigned long long;

int main(void)
{
    IOS
    int n, k;
    cin >> n >> k;
    string s; cin >> s;
    int rcnt = 0;
    int rnow = 0;
    int know = 0;
    int ans = 0;

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

    if (s[0] == 'r' && s[1] == s[0]) ans++;
    FOR(i,1,n) {
        if (i != n-1 && s[i] == 'r') {
            if (s[i] == s[i+1]) ans++;
        } else  {
            if (s[i] == s[i-1]) ans++;
        }

        if (s[i-1] != s[i]) {
            rcnt++;
            rnow++;
        } else {
            while(rnow > 2 && know < k ){
                rnow -= 2;
                rcnt -= 2;
                ans += 2;
                know++;
            }
            rnow = 0;
        }
    }

    if (know < k) {
        if (rcnt >= 2) ans += 2;
        } else {
            ans = n-1;
        }
    }

    cout << ans << endl;

    return 0;
}

Compiler output:
a.cc:58:5: error: 'cout' does not name a type
   58 |     cout << ans << endl;
      |     ^~~~
a.cc:60:5: error: expected unqualified-id before 'return'
   60 |     return 0;
      |     ^~~~~~
a.cc:61:1: error: expected declaration before '}' token
   61 | }
      | ^
Language: Java


        for(int i = 0; i < llist.size(); i++) {
            int get = llist.get(i);
            if (get > 1) {
                rsum += get -1;
            }
        }

Compiler output:
Main.java:2: error: class, interface, enum, or record expected
        for(int i = 0; i < llist.size(); i++) {
        ^
Main.java:2: error: class, interface, enum, or record expected
        for(int i = 0; i < llist.size(); i++) {
                       ^
Main.java:2: error: class, interface, enum, or record expected
        for(int i = 0; i < llist.size(); i++) {
                                         ^
Main.java:4: error: class, interface, enum, or record expected
            if (get > 1) {
            ^
Main.java:6: error: class, interface, enum, or record expected
            }
            ^
5 errors
Language: C++

#include <bits/stdc++.h>

using namespace std;
int countFreq(string &pat, string &txt)
{
    int M = pat.length();
    int N = txt.length();
    int res = 0;

    /* A loop to slide pat[] one by one */
    for (int i = 0; i <= N - M; i++)
    {
        /* For current index i, check for
           pattern match */
        int j;
        for (j = 0; j < M; j++)
            if (txt[i+j] != pat[j])
                break;

        // if pat[0...M-1] = txt[i, i+1, ...i+M-1]
        if (j == M)
        {
           res++;
           j = 0;
        }
    }
    return res;
}

int main()
{
    
    #endif
    int n,k;
    cin>>n>>k;
    string s;
    cin>>s;
    int sumr = 0;
    int suml = 0;
    for(int i = 1; i < n;i++)
    {
        if(s[i] == 'L'&&s[i-1] == 'L')
        {
            suml++;
        }
        if(s[i] == 'R'&&s[i-1] == 'R')
        {
            sumr++;
        }
    }
    string R = "";
    string L = "";
    map<string,int>countR;
    map<string,int>countL;
    for(int i = 0;i < n;i++)
    {
        R += "R";
        L += "L";
        countR[R] += countFreq(R,s);
        countL[L] += countFreq(L,s);
    }
    int sumRK = 0;
    int sumLK = 0;

    for(int i = 0;i < n;i++)
    {
        if(sumRK < k&&countR[R] != 0)
        {
            sumRK++;
            suml += countR[R];
        }
        if(sumLK < k&&countL[L] != 0)
        {
            sumLK++;
            sumr += countL[L];
        }
        R.erase(R.end()-1,R.end());
        L.erase(L.end()-1,L.end());
       // cout<<R<<" "<<L<<endl;
    }
 cout<<max(suml,sumr)-1;
        return 0;
}


Compiler output:
a.cc:33:6: error: #endif without #if
   33 |     #endif
      |      ^~~~~
Language: C++

#include<bits/stdc++.h>
using namespace std;

#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define pb push_back
#define mod 1000000007
#define INF 2000000000
typedef long long ll;
bool compare(pair<int, int> a, pair<int, int> b) {
    if(a.first != b.first){
        return a.first < b.first;
        
    }else{
        return a.second < b.second;
    }
}
// 入力



int main() {
    int N,K;
    string S;
    int sumL[100005]={},sumR[100005]={};
    int cnt=0,mode=0;
    cin >> N >>K;
    cin >> S;
    int fis=1;
    int count =0;
    int kR=0,kL=0;
        if(N>1){
            if(S[0]=='L'&&S[1]!='L'){
                kL+=1;
            }else if(){
                kR+=1;
            }
            if(N>3){
                if(S[N-1]=='L'){
                    kL+=1;
                }else{
                    kR+=1;
                }
            }
        }else{
             if(S[0]=='L'){
                kL+=1;
            }else{
                kR+=1;
            }
        }
    rep(i,N){
        if(mode==0){
             if(S[i] == 'L'){
                mode=1;
            }else{
                mode=2;
            }
        }
        else if(mode == 1){
            if(S[i] == 'L'){
                cnt++;
            }else{
                fis+=cnt-1;
                sumL[i]=cnt;
                cnt = 1;
                mode = 2;
                count++;
            }
        }else if(mode == 2){
            if(S[i] == 'R'){
                cnt++;
            }else{
                fis+=cnt-1;
                sumR[i]=cnt;
                cnt = 1;
                mode = 1;
                count++;
            }
        }
    }
    if(mode == 1){
        sumL[100002]=cnt-1;
    }else{
        sumR[100002]=cnt-1;
    }
    fis += cnt-1;
    sort(sumL, sumL + 100004, greater<int>());
    sort(sumR, sumR + 100004, greater<int>());
    int sumsumL=0,sumsumR=0;
    rep(i,K) {
        if(sumL[i]==0){
            if(kL>0){
                sumsumL+=1;
                kR--;
            }
        }else{
            sumsumL+=2;
        }
        
        //cout << sumsumR << sumR[i]<< endl;
    }

    rep(i,K) {
        if(sumR[i]==0){
            if(kR>0){
                sumsumR+=1;
                kR--;
            }
        }else{
            sumsumR+=2;
        }
        
        //cout << sumsumR << sumR[i]<< endl;
    }
    
    cout << fis +max(sumsumR,sumsumL) << endl;
    
    return 0;
    

}

Compiler output:
a.cc: In function 'int main()':
a.cc:35:22: error: expected primary-expression before ')' token
   35 |             }else if(){
      |                      ^
Language: Java

import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		String[] info=sc.nextLine().split(" ");
		int n=Integer.parseInt(info[0]);
		int k=Integer.parseInt(info[1]);
		StringBuilder sb=new StringBuilder(sc.nextLine());
		Long left=Arrays.asList(sb.toString().split("")).stream().filter(s->s.equals("L")).count();
		Long right=n-left;
		for(int i=0;i<k;i++) {
			StringBuilder next=new StringBuilder();
			String target=sb.substring(0,1).equals("L")?"R":"L";
			next.append(sb.substring(0, sb.indexOf(target)));
			Integer nextIndex=Integer.min(sb.lastIndexOf(target)+1,sb.length());
			next.append(flip(sb.substring(sb.indexOf(target),nextIndex)));
			next.append(sb.substring(nextIndex));
			left=Arrays.asList(sb.toString().split("")).stream().filter(s->s.equals("L")).count();
			right=n-left;
			sb=new StringBuilder(next);
		}
		System.out.println(Long.max(left, right));
	}
}

Compiler output:
Main.java:18: error: cannot find symbol
			next.append(flip(sb.substring(sb.indexOf(target),nextIndex)));
			            ^
  symbol:   method flip(String)
  location: class Main
1 error
Language: C++

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n,k;
  cin>>n>>k;
  vector<char> s(n);
  for(int i=0;i<n;i++){
    cin>>s[i];
  }
  int g=0;
  if(s[0]=='L') g+=1;
  if(s[n-1]=='R') g+=1;
  int h=0;
  for(int i=0;i<n-1;i++){
    if(s[i]=='R' && s[i+1]=='L'){
      h+=2;
    }
  }
  if(h/2>=k){
    h-=2*k;
  }
  else if(g==1 && k-h/2==1){
    h=0;
    g-=1;
  }
  else if(g==2 && k-h/2==1){
    h=0;
    g-=1;
  }
  else if(g==1 && k-h/>1){
    h=0;
    g=0;
  }
  else if(g==2 && k-h/2>1){
    h=0;
    g=0;
  }
  cout<<n-g-h<<endl;
}
    
    


Compiler output:
a.cc: In function 'int main()':
a.cc:30:23: error: expected primary-expression before '>' token
   30 |   else if(g==1 && k-h/>1){
      |                       ^
Language: C++

#include <cstdio>
#include <iostream>
#include <queue>
#include <string>
#include <algorithm>
#include <vector>
#include <utility>
#include <tuple>
typedef long long ll;

using namespace std;
int main(){
    ll n,k;
    string s;
    ll ans=0;
    ll rl=0;
    ll lr=0;
    ll num_edge=0;
    cin>>n>>k>>s;
    for(ll i=0;i<n;i++){
        if(s[i]=='L'){
            if(i>0){
                if(s[i-1]=='L'){
                    ans++;
                }else{
                    rl++;
                }
            }else{
                num_edge++;
            }
            if(i<n-1){
                if(s[i+1]=='R'){
                    lr++;
                }
            }
        }else if(s[i]=='R'){
            if(i<n-1){
                if(s[i+1]=='R'){
                    ans++;
                }
            }else{
                num_edge++;
            }
        }
    }
    ans+=2*min({k,rl,lr});
    ll rest=0;
    if(min(k,lr)-rl>0){
        rest=min(k,lr)-rl;
    };
    ans+=min({num_edge,rest,1});
    cout<<ans<<endl;
    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:51:13: error: no matching function for call to 'min(<brace-enclosed initializer list>)'
   51 |     ans+=min({num_edge,rest,1});
      |          ~~~^~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/string:51,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:2:
/usr/include/c++/14/bits/stl_algobase.h:233:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  233 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note:   candidate expects 2 arguments, 1 provided
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  281 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note:   candidate expects 3 arguments, 1 provided
In file included from /usr/include/c++/14/algorithm:61,
                 from a.cc:5:
/usr/include/c++/14/bits/stl_algo.h:5686:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(initializer_list<_Tp>)'
 5686 |     min(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5686:5: note:   template argument deduction/substitution failed:
a.cc:51:13: note:   deduced conflicting types for parameter '_Tp' ('long long int' and 'int')
   51 |     ans+=min({num_edge,rest,1});
      |          ~~~^~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algo.h:5696:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(initializer_list<_Tp>, _Compare)'
 5696 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5696:5: note:   candidate expects 2 arguments, 1 provided
Language: C++

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
int main() {
    ll int n,k,i,j,ans,co;
    co=0;
    cin>>n>>k;
    char a[n];
    rep(i,n){
      cin>>a[i];
    }
    ans=0;
   rep(i,n-1){
     if(a[i]=='R'&&a[i+1]=='R'){
         ans++;
     }
   }
   for(i=n-1;i>0;i--){
     if(a[i]=='L'&&a[i-1]=='L'){
         ans++;
     }
   }
   for(i=0;i<n-1;i++){
       if(a[i]=='L'&&a[i+1]=='R'){
        co++;
       }
       if(a[i]=='R'&&a[i+1]=='L'){
        co++;
       }
   }
   if(co-1>=k){
   cout<<ans+k*2<<endl;
   }
   else{
   cout<<ans+co*2-1<<endl;
   }
}


Compiler output:
a.cc: In function 'int main()':
a.cc:7:5: error: two or more data types in declaration of 'n'
    7 |     ll int n,k,i,j,ans,co;
      |     ^~
a.cc:7:5: error: two or more data types in declaration of 'k'
a.cc:7:5: error: two or more data types in declaration of 'i'
a.cc:7:5: error: two or more data types in declaration of 'j'
a.cc:7:5: error: two or more data types in declaration of 'ans'
a.cc:7:5: error: two or more data types in declaration of 'co'
a.cc:8:5: error: 'co' was not declared in this scope; did you mean 'cos'?
    8 |     co=0;
      |     ^~
      |     cos
a.cc:9:10: error: 'n' was not declared in this scope; did you mean 'yn'?
    9 |     cin>>n>>k;
      |          ^
      |          yn
a.cc:9:13: error: 'k' was not declared in this scope
    9 |     cin>>n>>k;
      |             ^
a.cc:12:12: error: 'a' was not declared in this scope
   12 |       cin>>a[i];
      |            ^
a.cc:14:5: error: 'ans' was not declared in this scope; did you mean 'abs'?
   14 |     ans=0;
      |     ^~~
      |     abs
a.cc:16:9: error: 'a' was not declared in this scope
   16 |      if(a[i]=='R'&&a[i+1]=='R'){
      |         ^
a.cc:20:8: error: 'i' was not declared in this scope
   20 |    for(i=n-1;i>0;i--){
      |        ^
a.cc:21:9: error: 'a' was not declared in this scope
   21 |      if(a[i]=='L'&&a[i-1]=='L'){
      |         ^
a.cc:25:8: error: 'i' was not declared in this scope
   25 |    for(i=0;i<n-1;i++){
      |        ^
a.cc:26:11: error: 'a' was not declared in this scope
   26 |        if(a[i]=='L'&&a[i+1]=='R'){
      |           ^
a.cc:29:11: error: 'a' was not declared in this scope
   29 |        if(a[i]=='R'&&a[i+1]=='L'){
      |           ^
Language: C++

#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>

using namespace std;

int main()
{
  int N, K;
  cin >> N >> K;
  string S;
  cin >> S;

  int d=1;
  vector<int> data;
  //iとi+1
  //vector<pair<int, int>> d;

  //どのように並んでいるか
  for (int i = 1; i < N; i++)
  {
    if(S[i-1]==S[i])
      d++;
    else{
      data.push_back(d);
      d = 1;
    }
    if (i == N - 1)
      data.push_back(d);
  }

  //最大を探す
  long long ans= 0;
  for (int i = 0; i < data.size();i++){
    if(data[i]!=1)
      ans += data[i] - 1;
  }
  int memo0 = 0,memo1=0;
  memo0 = data[0];
  memo1 = data[(int)data.size() - 1];

  //cout << memo0 << " " << memo1 << endl;

  sort(data.begin(), data.end(), greater<int>());
  data[K] = data[K-1];
  for (int i = 0; i < K; i++)
  {
    if(data[i]==memo1 || data[i]==memo0){
      if(i!=k-1){
        if (data[i] == data[i + 1])
          ans += 1;
      }

      else
        ans += 2;
    }
    else
      ans += 2;
  }
  cout << ans << endl;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:64:13: error: 'k' was not declared in this scope
   64 |       if(i!=k-1){
      |             ^
Language: C

#include<stdio.h>
int main(){
  int n;
  int k;
  scanf("%d%d",&n,&k);
  char s[n];
  scanf("%s",s);
  int x=0;//koufuku
  for (int i=0;i<n-1;i++){
    if(s[i]==s[i+1]){
      x=x+1;
    }
  }
  int y=x+2*k；
  if(y<n-1){
    printf("%d\n",y);
  }
  else{
    printf("%d\n",n-1);
  }
}


Compiler output:
main.c: In function 'main':
main.c:14:13: error: 'k\U0000ff1b' undeclared (first use in this function)
   14 |   int y=x+2*k；
      |             ^~~
main.c:14:13: note: each undeclared identifier is reported only once for each function it appears in
main.c:15:3: error: expected ',' or ';' before 'if'
   15 |   if(y<n-1){
      |   ^~
main.c:18:3: error: 'else' without a previous 'if'
   18 |   else{
      |   ^~~~
Language: Java

import java.util.*;
public class Main {
  	static int mod = 1000000007;
  static int size = 200001;
	static long[] fac = new long[size];
	static long[] finv = new long[size];
	static long[] inv = new long[size];
	static int INF = Integer.MAX_VALUE;
public static void main(String[] args){
	Scanner sc = new Scanner(System.in);
	// 整数の入力
	int N = sc.nextInt();
  int K = sc.nextInt();
    String S = sc.next();
  int Rcount=0;
  int Lcount=0;
  int RRcount=0;
  int LLcount=0;
    int RLcount=0;
  int i=0;
  int sum=0;
  String before = "N";
  int j=0;
  for(i=0;i<N;i++){
    if("R".equals(S.substring(i,i+1))){
      Rcount++;
      RRcount++;
      if(RRcount>1){
        sum++;
      }
      if(!"R".equals(before)&&!"N".equals(before)){
        LLcount=0;
        RLcount++;
      }
      before="R";
    }else{
      Lcount++;
      LLcount++;
      if(LLcount>1){
        sum++;
      }
      if(!"L".equals(before)&&!"N".equals(before)){
        RRcount=0;
        RLcount++;
      }
      before="L";
    }
  }
  if(RLcount-1<=K) {
    System.out.println(N-1);
  }else if(RLcount-2=K){
    System.out.println(sum+K*2-1);
  }
  else{
    System.out.println(sum+K*2);
  }




} 

 //fac, inv, finvテーブルの初期化、これ使う場合はinitComb()で初期化必要
	public static  void initComb(){
		fac[0] = finv[0] = inv[0] = fac[1] = finv[1] = inv[1] = 1;
		for (int i = 2; i < size; ++i) {
			fac[i] = fac[i - 1] * i % mod;
			inv[i] = mod - (mod / i) * inv[(int) (mod % i)] % mod;
			finv[i] = finv[i - 1] * inv[i] % mod;
		}
	}
 
	//nCk % mod
	public static long comb(int n, int k){
        if (n < k) return 0;
        if (n < 0 || k < 0) return 0;
		return fac[n] * finv[k] % mod * finv[n - k] % mod;
	}
 
	//n! % mod
	public static long fact(int n){
		return fac[n];
	}
 
	//(n!)^-1 with % mod
	public static long finv(int n){
		return finv[n];
	}
  
}

Compiler output:
Main.java:51: error: unexpected type
  }else if(RLcount-2=K){
                  ^
  required: variable
  found:    value
1 error
Language: Java

import java.util.*;
public class Main {
  	static int mod = 1000000007;
  static int size = 200001;
	static long[] fac = new long[size];
	static long[] finv = new long[size];
	static long[] inv = new long[size];
	static int INF = Integer.MAX_VALUE;
public static void main(String[] args){
	Scanner sc = new Scanner(System.in);
	// 整数の入力
	int N = sc.nextInt();
  int K = sc.nextInt();
    String S = sc.next();
  int Rcount=0;
  int Lcount=0;
  int RRcount=0;
  int LLcount=0;
    int RLcount=0;
  int i=0;
  int sum=0;
  String before = "N";
  int j=0;
  for(i=0;i<N;i++){
    if("R".equals(S.substring(i,i+1))){
      Rcount++;
      RRcount++;
      if(RRcount>1){
        sum++;
      }
      if(!"R".equals(before)&&!"N".equals(before)){
        LLcount=0;
        RLcount++;
      }
      before="R";
    }else{
      Lcount++;
      LLcount++;
      if(LLcount>1){
        sum++;
      }
      if(!"L".equals(before)&&!"N".equals(before)){
        RRcount=0;
        RLcount++;
      }
      before="L";
    }
  }
  if(RLcount-1<=K) {
    System.out.println(N-1);
  }else if{
    System.out.println(sum+K*2-1);
  }
  else{
    System.out.println(sum+K*2);
  }




} 

 //fac, inv, finvテーブルの初期化、これ使う場合はinitComb()で初期化必要
	public static  void initComb(){
		fac[0] = finv[0] = inv[0] = fac[1] = finv[1] = inv[1] = 1;
		for (int i = 2; i < size; ++i) {
			fac[i] = fac[i - 1] * i % mod;
			inv[i] = mod - (mod / i) * inv[(int) (mod % i)] % mod;
			finv[i] = finv[i - 1] * inv[i] % mod;
		}
	}
 
	//nCk % mod
	public static long comb(int n, int k){
        if (n < k) return 0;
        if (n < 0 || k < 0) return 0;
		return fac[n] * finv[k] % mod * finv[n - k] % mod;
	}
 
	//n! % mod
	public static long fact(int n){
		return fac[n];
	}
 
	//(n!)^-1 with % mod
	public static long finv(int n){
		return finv[n];
	}
  
}

Compiler output:
Main.java:51: error: '(' expected
  }else if{
          ^
1 error
Language: C++

#include <iostream>

#include <vector>

#include <algorithm>

#include <cstdio>

#include <cmath>

#include <cstdlib>

#include <ctime>

#include <cctype>

#include <cstring>

#include <utility>

#include <map>

using namespace std;

typedef pair<int,int> P;

typedef long long ll;

int main()

{

    int n,k;

    cin>>n>>k;

    string s;

    cin>>s;

    vector<int> ll(k);

    vector<int> rr(k);

        int l=0;

        int r=n-1;

        int cnt=0;

        for(l;l<n-1;l++)

        {

            if(s[l]!=s[l+1])

            { cnt++;ll[cnt-1]=l;

            if(cnt==k)

                break;}

        }

        cnt=0;

        for(r;r>0;r--)

        {

            if(s[r]!=s[r-1])

            {  cnt++;rr[cnt-1]=r;

            if(cnt==k)

                break;}

        }

    

   /* for(int i=0;i<k;i++)

    {

        cout<<ll[i]<<endl;

        cout<<rr[i]<<endl;

    }*/

       /* for(int i=l+1;i<=r-1;i++)

        {

            if(s[i]=='L')

                s[i]='R';

            else if(s[i]=='R')

         

Compiler output:
a.cc:93:8: error: unterminated comment
   93 |        /* for(int i=l+1;i<=r-1;i++)
      |        ^
a.cc: In function 'int main()':
a.cc:79:10: error: expected '}' at end of input
   79 |         }
      |          ^
a.cc:31:1: note: to match this '{'
   31 | {
      | ^
Language: C++

#include <bits/stdc++.h>
#include "local_debug.h"
using namespace std;
#define endl endl
#define debug(x) cout << #x << " = " << (x) << endl
typedef long long ll;
const int MOD = (int)1e9 + 7;
const int MAXN = (int)2e5 + 5;
ll n, k;
string s;
int main()
{
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	while (cin >> n >> k >> s)
	{
		s += '#';
		ll len = 1, sum = 0, cnt = 0;
		for (ll i = 0; i < n; ++i)
		{
			if (s[i] == s[i + 1])
				len++;
			else
				cnt++, sum += len, len = 1;
		}
		cnt = max(1LL, cnt - k * 2);
		cout << sum - cnt << endl;
	}
}
/*
6 1
LRLRRL

13 3
LRRLRLRRLRLLR

10 1
LLLLLRRRRR

9 2
RRRLRLRLL
*/

Compiler output:
a.cc:2:10: fatal error: local_debug.h: No such file or directory
    2 | #include "local_debug.h"
      |          ^~~~~~~~~~~~~~~
compilation terminated.
Language: C++

#include<bits/stdc++.h>
using namespace std;
#define ls rt<<1
#define rs (rt<<1)+1
#define PI acos(-1)
#define eps 1e-8
#define ll long long
#define fuck(x) cout<<#x<<"     "<<x<<endl;
typedef pair<int,int> pii;
const int maxn=1e6+10;
int d[4][2]={1,0,-1,0,0,1,0,-1};
//int lowbit(int x){return x&-x;}
//void add(int x,int v){while(x<=n)bit[x]+=v,x+=lowbit(x);}
//int sum(int x){int ans=0;while(x>=1) ans+=bit[x],x-=lowbit(x);return ans;}
struct node{
    int st,num;
};
vector<node>v;
char s[maxn];
int main(){
    
    int n,k,tmp,ans;
    scanf("%s",s+1);
    s[n+1]='p';
    tmp=1;
    for(int i=2;i<=n+1;i++){
        if(s[i]!=s[tmp])
        {
            v.push_back(node(tmp,i-tmp));
            tmp=i;
            if(i==n+1)
                break;
        }
    }
    tmp=v.size();
    if(tmp==1){
        cout<<n-1<<endl;
        return 0;
    }

    for(int i=1;i<=v.size()-1;i++)
    {
        if(!k) break;
        if(i%2){
            tmp-=2;
            if(i==v.size()-1)
                tmp++;
            k--;
        }
    }
    cout<<n-tmp<<endl;
    return 0;
    
}

Compiler output:
a.cc: In function 'int main()':
a.cc:29:39: error: no matching function for call to 'node::node(int&, int)'
   29 |             v.push_back(node(tmp,i-tmp));
      |                                       ^
a.cc:15:8: note: candidate: 'node::node()'
   15 | struct node{
      |        ^~~~
a.cc:15:8: note:   candidate expects 0 arguments, 2 provided
a.cc:15:8: note: candidate: 'constexpr node::node(const node&)'
a.cc:15:8: note:   candidate expects 1 argument, 2 provided
a.cc:15:8: note: candidate: 'constexpr node::node(node&&)'
a.cc:15:8: note:   candidate expects 1 argument, 2 provided
Language: C++

#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,K,i,j,k,l,ans=0;
  string S;
  
  cin >> N >> K >>S;
  
  if(N>=2){
    for(i=0;i<K;i++){
      j=1;
      while(S.front()!=S[j])&&(j < N)){
        j++;
      }
      if(j==N)
        break;

      k=N-2;
      while((S.back()!=S[k])&&(k > -1)){
        k--;
      }
      if(j<k){
        for(l=j;l<=k;l++){
          if(S[l] == 'R')
            S[l] == 'L';
          else
            S[l] == 'R';
        }
      }else{
        for(l=0;l<=j-1;l++){
          if(S[l] == 'R')
            S[l] == 'L';
          else
            S[l] == 'R';
        }
      }
    }
    
    for(i=1;i<N;i++){
        if(S[i]==S[i-1])ans++; 
    }
    
  }else{
    ans=0;
  }
 
  cout << ans << endl;
  

  return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:13:31: error: expected identifier before '(' token
   13 |       while(S.front()!=S[j])&&(j < N)){
      |                               ^
Language: C++

#include <bits/stdc++.h>
using namespace std;

int main() {
  int N,K;
  cin>>N>>K;
  string S;
  cin>>S;
  int a;
  a=0;
  for(int i=0;i<N-1;i++){
  if(S.at(i)==S.at(i+1)){
    a++;
  }
  }
    int ans;
    for(int i=0;i<N-1;i++){
      if(S.at(i)!=S.at(i+1)){
        ans++;
      }
    }
    if(a/2>K){
      ans+=2*K;
    }
      else if{
        int c=0;
        c=a/2;
        ans+=K+c;
      }
      cout<<ans<<endl;
    
    
  
}


Compiler output:
a.cc: In function 'int main()':
a.cc:25:14: error: expected '(' before '{' token
   25 |       else if{
      |              ^
      |              (
Language: C++

#pragma GCC optimize("O2")
#include<bits/stdc++.h>
#define ll long long
using namespace std;
typedef pair<int,int> pii;
const int N = 1e5+10;
int n,k;
char s[N];
int a[N],idx,ans,ans2;
priority_queue<int,vector<int>,less<int> > q;
int main(){
    scanf("%d%d",&n,&k);
    scanf("%s",s);
    a[++idx] = 1;
    ans = k;
    for(int i=1;i<n;++i){
        if(s[i]==s[i-1])    a[idx]++;
        else a[++idx]++;
    }
    for(int i=1;i<=idx;++i){
        if(i%2) q.push(a[i]);
        else ans += a[i]-1;
    }
    int t = k;
    while(q.size() && t--){
        ans += q.top(); q.pop();
    }
    ans = min(ans,n-1);
    while(q.size())q.pop();
    ans2 = k;
    for(int i=;i<=idx;++i){
        if(i%2) ans+=a[i]-1;
        else q.push(a[i]);
    }
    t = k;
    while(q.size() && t--){
        ans += q.top(); q.pop();
    }
    ans2 = min(ans2,n-1);
    printf("%d\n",max(ans,ans2));
    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:31:15: error: expected primary-expression before ';' token
   31 |     for(int i=;i<=idx;++i){
      |               ^
Language: C++

#include <bits/stdc++.h>
using namespace std;

int main() {
  int N,K;
  cin>>N>>K;
  string S;
  cin>>S;
  int a;
  a=0;
  for(int i=0;i<N-1;i++){
  if(S.at(i)==S.at(i+1)){
    a++;
  }
    int ans;
    for(int i=0;i<N-1;i++){
      if(S.at(i)!=S.at(i+1)){
        ans++;
      }
    if(a/2>K){
      ans+=2K;
    }
      else if{
        int c=0;
        c=a/2;
        ans+=K+c;
      }
      cout<<ans<<endl;
    
    
  
}


Compiler output:
a.cc: In function 'int main()':
a.cc:21:12: error: fixed-point types not supported in C++
   21 |       ans+=2K;
      |            ^~
a.cc:23:14: error: expected '(' before '{' token
   23 |       else if{
      |              ^
      |              (
a.cc:32:2: error: expected '}' at end of input
   32 | }
      |  ^
a.cc:11:25: note: to match this '{'
   11 |   for(int i=0;i<N-1;i++){
      |                         ^
a.cc:32:2: error: expected '}' at end of input
   32 | }
      |  ^
a.cc:4:12: note: to match this '{'
    4 | int main() {
      |            ^
Language: C++

#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,K,i,j,k,l,ans=0;
  string S;
  
  cin >> N >> K >>S;
  
  if(N>=2){
    for(i=0;i<K;i++){
      j=1;
      while(S.front()!=S[j])&&(j < N)){
        j++;
      }
      if(j==N)
        break;

      k=N-2;
      while(S.back()!=S[k])&&(k > -1)){
        k--;
      }
      if(j<k){
        for(l=j;l<=k;l++){
          if(S[l] == 'R')
            S[l] == 'L';
          else
            S[l] == 'R';
        }
      }else{
        for(l=0;l<=j-1;l++){
          if(S[l] == 'R')
            S[l] == 'L';
          else
            S[l] == 'R';
        }
      }
    }
    
    for(i=1;i<N;i++){
        if(S[i]==S[i-1])ans++; 
    }
    
  }else{
    ans=0
  }
 
  cout << ans << endl;
  

  return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:13:31: error: expected identifier before '(' token
   13 |       while(S.front()!=S[j])&&(j < N)){
      |                               ^
a.cc:20:30: error: expected identifier before '(' token
   20 |       while(S.back()!=S[k])&&(k > -1)){
      |                              ^
a.cc:45:10: error: expected ';' before '}' token
   45 |     ans=0
      |          ^
      |          ;
   46 |   }
      |   ~
Language: C++

#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,K,i,j,k,l,ans=0;
  string S;
  
  cin >> N >> K >>S;
  
  if(N>=2){
    for(i=0;i<K;i++){
      j=1;
      while(S.fromt()!=S[j])&&(j < N)){
        j++;
      }
      if(j==N)
        break;

      k=N-2;
      while(S.back()!=S[k])&&(k > -1)){
        k--;
      }
      if(j<k){
        for(l=j;l<=k;l++){
          if(S[l] == 'R')
            S[l] == 'L';
          else
            S[l] == 'R';
        }
      }else{
        for(l=0;l<=j-1;l++){
          if(S[l] == 'R')
            S[l] == 'L';
          else
            S[l] == 'R';
        }
      }
    }
    
    for(i=1;i<N;i++){
        if(S[i]==S[i-1])ans++; 
    }
    
  }else{
    ans=0
  }
 
  cout << ans << endl;
  

  return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:13:15: error: 'std::string' {aka 'class std::__cxx11::basic_string<char>'} has no member named 'fromt'; did you mean 'front'?
   13 |       while(S.fromt()!=S[j])&&(j < N)){
      |               ^~~~~
      |               front
a.cc:13:31: error: expected identifier before '(' token
   13 |       while(S.fromt()!=S[j])&&(j < N)){
      |                               ^
a.cc:20:30: error: expected identifier before '(' token
   20 |       while(S.back()!=S[k])&&(k > -1)){
      |                              ^
a.cc:45:10: error: expected ';' before '}' token
   45 |     ans=0
      |          ^
      |          ;
   46 |   }
      |   ~
Language: C++

#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,K,i,j,k,l,ans=0;
  string S;
  
  cin >> N >> K >>S;
  
  if(N>=2){
    for(i=0;i<K;i++){
      j=1
      while(S.fromt()!=S[j])&&(j < N)){
        j++;
      }
      if(j==N)
        break;

      k=N-2;
      while(S.back()!=S[k])&&(k > -1)){
        k--;
      }
      if(j<k){
        for(l=j;l<=k;l++){
          if(S[l] == 'R')
            S[l] == 'L';
          else
            S[l] == 'R';
        }
      }else{
        for(l=0;l<=j-1;l++){
          if(S[l] == 'R')
            S[l] == 'L';
          else
            S[l] == 'R';
        }
      }
    }
    
    for(i=1;i<N;i++){
        if(S[i]==S[i-1])ans++; 
    }
    
  }else{
    ans=0
  }
 
  cout << ans << endl;
  

  return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:12:10: error: expected ';' before 'while'
   12 |       j=1
      |          ^
      |          ;
   13 |       while(S.fromt()!=S[j])&&(j < N)){
      |       ~~~~~
a.cc:20:30: error: expected identifier before '(' token
   20 |       while(S.back()!=S[k])&&(k > -1)){
      |                              ^
a.cc:45:10: error: expected ';' before '}' token
   45 |     ans=0
      |          ^
      |          ;
   46 |   }
      |   ~
Language: C++

#include <bits/stdc++.h>

using namespace std;

#define int long long 
#define INF 21000000000

bool cmp(int a,int b){
		return a > b;
}

signed main(){
		int n,k;
		cin >> n >> k;
		vector<int> cnt;
		char flag;
		for(int i=0;i<n;i++){
				char tmp;
				cin >> tmp;
				if(i == 0) cnt.push_back(1);
				else{
						if(tmp == flag) cnt[cnt.size()-1] += 1;
						else cnt.push_back(1);
				}
				flag = tmp;
		}
		vector<int> sum;
		if(cnt.size() > 2){
			for(int i=0;i<n-2;i++){
					sum.push_back(cnt[i]+cnt[i+1]+cnt[i+2]);
			}
			sort(sum.begin(),sum.end(),cmp);
			int ans = 0;
			for(int i=0;i<k;i++){
					ans += sum[i];
			}
			ans -= k;
		}
		else ans = accumulate(cnt.begin(),cnt.end(),0) - 1;
		cout << ans << endl;
}



Compiler output:
a.cc: In function 'int main()':
a.cc:39:22: error: 'ans' was not declared in this scope; did you mean 'abs'?
   39 |                 else ans = accumulate(cnt.begin(),cnt.end(),0) - 1;
      |                      ^~~
      |                      abs
a.cc:40:25: error: 'ans' was not declared in this scope; did you mean 'abs'?
   40 |                 cout << ans << endl;
      |                         ^~~
      |                         abs
Language: C++

#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bits/stdc++.h>
#include<cmath>
#include<bitset>
#define ll long long
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,0,n)
#define SORT(V) sort((V).begin(),(V).end())
#define REVERSE(V) reverse((V).begin(),(V).end())
#define INF ((1LL<<62)-(1LL<<31))
#define MOD 1000000007
using namespace std;

int main(){
  int N,K,ans=0;
  string S;
  cin>>N>>K>>S;
  
  for(int i=0; i<S.size()-1; ++i){
    if(S.at(i)==S.at(i+1)) ans++;
  }
  
  cout<<min(ans+2*K,S.size())<<endl;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:28:12: error: no matching function for call to 'min(int, std::__cxx11::basic_string<char>::size_type)'
   28 |   cout<<min(ans+2*K,S.size())<<endl;
      |         ~~~^~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/string:51,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_algobase.h:233:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  233 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note:   template argument deduction/substitution failed:
a.cc:28:12: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'})
   28 |   cout<<min(ans+2*K,S.size())<<endl;
      |         ~~~^~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  281 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note:   candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61,
                 from a.cc:4:
/usr/include/c++/14/bits/stl_algo.h:5686:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(initializer_list<_Tp>)'
 5686 |     min(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5686:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5696:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(initializer_list<_Tp>, _Compare)'
 5696 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5696:5: note:   template argument deduction/substitution failed:
a.cc:28:12: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   28 |   cout<<min(ans+2*K,S.size())<<endl;
      |         ~~~^~~~~~~~~~~~~~~~~~
Language: C++

n,k = map(int,input().split())
s = input()
cnt = 0
ans = 0
for i in range(n-1):
    if s[i]==s[i+1]:
        ans += 1
    else:
        cnt+=1
print(ans+min((cnt,2*k)))

Compiler output:
a.cc:1:1: error: 'n' does not name a type
    1 | n,k = map(int,input().split())
      | ^