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

// AtCoder.cpp : コンソール アプリケーションのエントリ ポイントを定義します。
//

#pragma once

#include "stdafx.h" //提出の時は消去する

#include <stdio.h>
#include <string>
#include <iostream>
#include <queue>
#include <algorithm>
#include <sstream>
#include <vector>
#include <math.h>
#include <set>

using namespace std;

long long A, B, C, D, K, M, N, X, Y, Z;
long long a[10000];
char ch;
vector <long long>vl;
string S;


int main()
{

	cin >> N >> K >> S;
	B = 0;
	C = 0;
	D = 0;
	X = 0;
	Y = 0;
	A = S[0] - '0';
	Z=A;

	for (int i = 0; i < S.size(); i++) {


		if (Z == S[i] - '0') {
			D++;
		}
		else {
			vl.push_back(D);
			D = 1;
			Z++;
			Z %= 2;
		}

	}

	if (D > 0) {
		vl.push_back(D);
	}


	if (vl.size() == 1) {
		C = N;
		

	}
	else {
		for (int i = 0; i < vl.size() && i < K * 2; i++) {
			B += vl[i];
			X = i;
		}

		if (A == 1) {

			if (X == vl.size() - 1) {

			}
			else {
				B += vl[X + 1];
				X++;
			}

			C = B;

			B -= vl[0] + vl[1];
			Y = 2;

			while (X < vl.size() - 1) {
				if (X < vl.size() - 2) {
					B += vl[X + 1] + vl[X + 2];
				}
				else {
					B += vl[X + 1];
				}

				X += 2;

				if (C < B) {
					C = B;
				}

				B -= vl[Y] + vl[Y + 1];
				Y += 2;

			}

		}
		else {

			C = B;

			if (vl.size() >= 2) {
				B -= vl[0];
				Y = 1;
			}

			while (X < vl.size() - 1) {
				if (X < vl.size() - 2) {
					B += vl[X + 1] + vl[X + 2];
				}
				else {
					B += vl[X + 1];
				}

				X += 2;

				if (C < B) {
					C = B;
				}


				if (Y < vl.size() - 2)
					B -= vl[Y] + vl[Y + 1];
				Y += 2;

			}
		}
	}

	cout << C << endl;

	return 0;
}



Compiler output:
a.cc:4:9: warning: #pragma once in main file
    4 | #pragma once
      |         ^~~~
a.cc:6:10: fatal error: stdafx.h: No such file or directory
    6 | #include "stdafx.h" //提出の時は消去する
      |          ^~~~~~~~~~
compilation terminated.
Language: C++

// AtCoder.cpp : コンソール アプリケーションのエントリ ポイントを定義します。
//

#pragma once

#include "stdafx.h" //提出の時は消去する

#include <stdio.h>
#include <string>
#include <iostream>
#include <queue>
#include <algorithm>
#include <sstream>
#include <vector>
#include <math.h>
#include <set>

using namespace std;

long long A, B, C, D, K, M, N, X, Y, Z;
long long a[10000];
char ch;
vector <long long>vl;
string S;


int main()
{

	cin >> N >> K >> S;
	B = 0;
	C = 0;
	D = 0;
	X = 0;
	Y = 0;
	A = S[0] - '0';
	Z=A;

	for (int i = 0; i < S.size(); i++) {


		if (Z == S[i] - '0') {
			D++;
		}
		else {
			vl.push_back(D);
			D = 1;
			Z++;
			Z %= 2;
		}

	}

	if (D > 0) {
		vl.push_back(D);
	}


	if (vl.size() == 1) {
		C = N;
		if (A == 1 && K == 1) {
			C--;
		}

		if (N == 1) {
			C = 0;

			if (K % 2 == 0 && A == 0) {
				C = 1;
			}
			if (K % 2 == 1 && A == 1) {
				C = 1;
			}
			

		}

	}
	else {
		for (int i = 0; i < vl.size() && i < K * 2; i++) {
			B += vl[i];
			X = i;
		}

		if (A == 1) {

			if (X == vl.size() - 1) {

			}
			else {
				B += vl[X + 1];
				X++;
			}

			C = B;

			B -= vl[0] + vl[1];
			Y = 2;

			while (X < vl.size() - 1) {
				if (X < vl.size() - 2) {
					B += vl[X + 1] + vl[X + 2];
				}
				else {
					B += vl[X + 1];
				}

				X += 2;

				if (C < B) {
					C = B;
				}

				B -= vl[Y] + vl[Y + 1];
				Y += 2;

			}

		}
		else {

			C = B;

			if (vl.size() >= 2) {
				B -= vl[0];
				Y = 1;
			}

			while (X < vl.size() - 1) {
				if (X < vl.size() - 2) {
					B += vl[X + 1] + vl[X + 2];
				}
				else {
					B += vl[X + 1];
				}

				X += 2;

				if (C < B) {
					C = B;
				}


				if (Y < vl.size() - 2)
					B -= vl[Y] + vl[Y + 1];
				Y += 2;

			}
		}
	}

	cout << C << endl;

	return 0;
}



Compiler output:
a.cc:4:9: warning: #pragma once in main file
    4 | #pragma once
      |         ^~~~
a.cc:6:10: fatal error: stdafx.h: No such file or directory
    6 | #include "stdafx.h" //提出の時は消去する
      |          ^~~~~~~~~~
compilation terminated.
Language: C++


    if(j<k) ans=n;
    else
    {
        if(a[0]=='1') ans=b[k][1]-b[0][0]+1;
        else ans=b[k-1][1]-b[0][0]+1;
        for(i=1;i+k<l;i++) ans=max(ans,b[i+k][1]-b[i][0]+1);
    }
    cout<<ans<<endl;
    return 0;
}

Compiler output:
a.cc:2:5: error: expected unqualified-id before 'if'
    2 |     if(j<k) ans=n;
      |     ^~
a.cc:3:5: error: expected unqualified-id before 'else'
    3 |     else
      |     ^~~~
a.cc:9:5: error: 'cout' does not name a type
    9 |     cout<<ans<<endl;
      |     ^~~~
a.cc:10:5: error: expected unqualified-id before 'return'
   10 |     return 0;
      |     ^~~~~~
a.cc:11:1: error: expected declaration before '}' token
   11 | }
      | ^
Language: C++

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;

int main()
{
    ll n, k;
    string str;
    cin >> n >> k >> str;
    vector<ll> ary;
#if 1
    int now = 1; //今見ている数
    int cnt = 0; //nowがいくつ並んでいるか
    for (int i = 0; i < N; i++)
    {
        if (S[i] == (char)('0' + now)) cnt++;
        else {
            Nums.push_back(cnt);
            now = 1 - now; //0と1を切り替える時の計算 now ^= 1;
            cnt = 1; //新しいのをカウントし始める
        }
    }
    if (cnt != 0) Nums.push_back(cnt);

    //1-0-1-0-1-0-1って感じの配列が欲しい
    //1-0-1-0みたいに0で終わってたら、適当に１つ足す
    if (Nums.size() % 2 == 0) Nums.push_back(0);
    if (str[0] == '0') {
        ary.push_back(0);
    }
#else
    char prev = 0;
    for (ll i = 0; (i < n); i++) {
        char curr = str[i];
        if (prev != curr) {
            prev = curr;
            ary.push_back(1);
        } else {
            ary[ary.size()-1]++;
        }
    }
    if (str[n-1] == '0') ary.push_back(0);
#endif
    vector<ll> sum(ary.size()+1, 0);
    for (ll i = 0; (i < ary.size()); ++i) {
        sum[i+1] = sum[i] + ary[i];
    }
    ll maxv = 0;
    for(ll i = 1; (i < ary.size()); i+=2) {
        ll left = i - 1;
        ll right = min((ll)(sum.size()-1), i+(k-1)*2+1+1);
        maxv = max(maxv, sum[right] - sum[left]);
    }
    cout << maxv << endl;
    return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:16:25: error: 'N' was not declared in this scope
   16 |     for (int i = 0; i < N; i++)
      |                         ^
a.cc:18:13: error: 'S' was not declared in this scope
   18 |         if (S[i] == (char)('0' + now)) cnt++;
      |             ^
a.cc:20:13: error: 'Nums' was not declared in this scope
   20 |             Nums.push_back(cnt);
      |             ^~~~
a.cc:25:19: error: 'Nums' was not declared in this scope
   25 |     if (cnt != 0) Nums.push_back(cnt);
      |                   ^~~~
a.cc:29:9: error: 'Nums' was not declared in this scope
   29 |     if (Nums.size() % 2 == 0) Nums.push_back(0);
      |         ^~~~
Language: C++

#include <bits/stdc++.h>

using namespace std;

char sw_state(char state){
  if(state == '1'){
    return '0';
  }
  else {
    return '1';
  }
}

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

  char state = '1';
  
  vector<int> v;
  /* 最初が0から始まる場合は、１が0個という意味で、0を入れておく */
  
  int count = 0;
  for(int i = 0;i<N;i++){
    if(S[i] == state){
      count++;
    }
    else{
      state = sw_state(state);
      v.push_back(count);
      count = 1;
    }
  }

  if(count == 1){
    v.push_back(count);
  }

  if(S[(N-1)] == '0'){
    v.push_back(0);
  }

  for(int i=0;i<v.size();i++){
    cout << v[i] << endl;
  }

  vector<int> csum;
  for(int i=0;i<v.size();i++){
      csum[i+1] == csum[i] + v[j];
  }

  for(int i=0;i<v.size();i++){
    cout << csum[i] << endl;
  }
  /* 0-1-2-3-4 */
  /* 1-0-1-0-1 */
  /* 0-3-5-9-10 */
  /* |   |     */
  /*     |   | */
  /*    2*K    */
  int result = 0;
  for(int i=0;i<v.size()-2*K;i+=2){
    if(i==0){
      result = max(result,(csum[i+2*K]));
    }
    else{
      result = max(result,(csum[i+2*K]- csum[i-1]));
    }
  }

  cout << result << endl;
  return 0;

}
  
  
  

Compiler output:
a.cc: In function 'int main()':
a.cc:52:32: error: 'j' was not declared in this scope
   52 |       csum[i+1] == csum[i] + v[j];
      |                                ^
Language: C++

#include<cstdio>
#include<algorithm>
using namespace std;
const int N=5*1e5+10;
char s[N];
int a[N],n,m,ans,sum[N];
int main()
{
	scanf("%d%d%s",&n,&m,s+1);
	s[0]='0';
	for(int i=1;i<=n;i++)
		sum[i]=sum[i-1]+(a[i]=(s[i]-'0')^(s[i-1]-'0'));
	for(int i=1,k=a[1];i<=n;i++,k^=a[i])
		ans=max(ans*1ll,upper_bound(sum,sum+1+n,m*2-(!k)+sum[i])-sum-i);
	printf("%d",ans);
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:14:24: error: no matching function for call to 'max(long long int, long int)'
   14 |                 ans=max(ans*1ll,upper_bound(sum,sum+1+n,m*2-(!k)+sum[i])-sum-i);
      |                     ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/algorithm:60,
                 from a.cc:2:
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
a.cc:14:24: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'long int')
   14 |                 ans=max(ans*1ll,upper_bound(sum,sum+1+n,m*2-(!k)+sum[i])-sum-i);
      |                     ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note:   candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61:
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5706 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5716 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note:   template argument deduction/substitution failed:
a.cc:14:24: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   14 |                 ans=max(ans*1ll,upper_bound(sum,sum+1+n,m*2-(!k)+sum[i])-sum-i);
      |                     ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Language: C++

#include<map>
#include<cmath>
#include<stack>
#include<queue>
#include<cstdio>
#include<vector>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
template<class Read>void in(Read &x){
    x=0;
    int f=0;
    char ch=getchar();
    while(ch<'0'||ch>'9'){
        f|=(ch=='-');
        ch=getchar();
    }
    while(ch>='0'&&ch<='9'){
        x=(x<<1)+(x<<3)+(ch^48);
        ch=getchar();
    }
    x=f?-x:x;
    return;
}
int n,k,ans;
string a;
vector<int>v,sum;
int main(){
	in(n);in(k);
	cin>>a;
	if(a[0]=='0')v.push_back(0);
	int now=0;
	for(int i=0;i<n;i++){
		if(i>0&&a[i]!=a[i-1]){
			v.push_back(now);
			now=1;
		}
		else now++;
	}
	v.push_back(now);
	sum.resize(v.size()+1);
	sum[0]=0;
	for(int i=0;i<v.size();i++){
		sum[i+1]=sum[i]+v[i];
	}
	for(int i=0;i<sum.size();i+=2){
		int x=sum[min((int)v.size(),i+2*k+1)]-sum[i]
		ans=max(ans,x);
	}
	printf("%d\n",ans);
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:50:17: error: expected ',' or ';' before 'ans'
   50 |                 ans=max(ans,x);
      |                 ^~~
Language: C++

#include <stdio.h>
#include <stdlib.h>
int main(void){
	int n,k,i;
	scanf("%d%d",&n,&k);
	char s[100005];
	int a[100005];
	int b[100005];
	int cnt;
	scanf("%s",s);
	//連続する1の数を正、0の数を負として配列a[]に保存する
	i=0;cnt=1;
	a[0]=0;
	while(i<n){
		while(i < n && s[i]=='0'){
			a[cnt]--;
			i++;
			if(s[i]=='1'){
				cnt++;
			}
		}
		while(i < n && s[i]=='1'){
			a[cnt]++;
			i++;
			if(s[i]=='0'){
				cnt++;
			}
		}
	}
	cnt++;
	//printf("cnt=%d\n",cnt);
	b[0]=abs(a[0]);
	for(i=1;i<cnt;i++){
		b[i]+= b[i-1]+abs(a[i]);
	}
	int ans=b[1];
	int temp;
	int min ( int x ,int y){
		int min = x;
		if(min>y)min=y;
		return y;
	}
	for(i=0;i<cnt;i++){
		//printf("b[%d]=%d\n",i,b[i]);
	}
	for(i=0;i<cnt;i++){
		//printf("a[%d]=%d\n",i,a[i]);
	}
	for(i=1;i<cnt;i++){
		//左端がiでa[i]の値を使って右端を求めていく。
		int r;
		if(a[i]>0){
			r= i+2*k;
			if(r>=cnt)r=cnt;
		}else{
			r = i+(2*k)-1;
			if(r>=cnt)r=cnt;
		}
		temp = b[r]-b[i-1];
		//printf("temp=%d\n",temp);
		if(temp>ans)ans=temp;
	}
	printf("%d",ans);
	return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:38:32: error: a function-definition is not allowed here before '{' token
   38 |         int min ( int x ,int y){
      |                                ^
Language: C++

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define fi first
#define se second
int main(){
    int n,k,ans=0;
    string s;
    cin >> n >> k >> s;
    vector<int> v,u;//zero列の開始位置と終了位置
    if(n==1){
        cout << 1 << endl;
        return 0;
    }//サイズ１の時はv,uのサイズが２になってしまうので別処理

    v.push_back(-1);
    u.push_back(-1);//-1に0列の終点があることにしておく
    if(s.at(0)=='0'){
        v.push_back(0);
    }//一番左の0だけ先頭の条件が異なる
    for(int i=1;i < n;i++)
    {
        if(s.at(i)=='0'&& s.at(i-1)=='1')
        {
            v.push_back(i);
        }
        if(s.at(i)=='1'&& s.at(i-1)=='0')
        {
            u.push_back(i-1);
        }
    }
    if(s.at(n-1)=='0'){
        u.push_back(n-1);
    }//一番右の0だけ終端の条件が異なる
    v.push_back(n);
    u.push_back(n);//nに0列の先頭があることにしておく

    
    for(int i=1;i+k<v.size();i++)a
    {
        ans = max(ans,v.at(i+k)-u.at(i-1)-1);
        //i番目からi+k-1番目の０列を反転する
        //連続する１の長さは（i+k番目の0列の先頭）-（i-1番目の0列の終点）-1で求まる
    }
    
    if(k>=v.size()-2){
        cout << n << endl;
    }else{
        cout << ans << endl;
    }
    
}
/*実験より0列を連続してk個とるとき、どの取り方が最も１が多く並ぶか調べればよい
うまく動かないときは、もう一度アルゴリズムを整理すること

v.size()は最初はintになってないので,intとして処理させるには(int)v.size()とかする*/

Compiler output:
a.cc: In function 'int main()':
a.cc:39:34: error: 'a' was not declared in this scope
   39 |     for(int i=1;i+k<v.size();i++)a
      |                                  ^
Language: C++

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define fi first
#define se second
int main(){
    int n,k,ans=0;
    string s;
    cin >> n >> k >> s;
    vector<int> v,u;//zero列の開始位置と終了位置
    if(n==1){
        cout << 1 << endl;
        return 0;
    }//サイズ１の時はv,uのサイズが２になってしまうので別処理

    v.push_back(-1);
    u.push_back(-1);//-1に0列の終点があることにしておく
    if(s.at(0)=='0'){
        v.push_back(0);
    }//一番左の0だけ先頭の条件が異なる
    for(int i=1;i < n;i++)
    {
        if(s.at(i)=='0'&& s.at(i-1)=='1')
        {
            v.push_back(i);,,
        }
        if(s.at(i)=='1'&& s.at(i-1)=='0')
        {
            u.push_back(i-1);
        }
    }
    if(s.at(n-1)=='0'){
        u.push_back(n-1);
    }//一番右の0だけ終端の条件が異なる
    v.push_back(n);
    u.push_back(n);//nに0列の先頭があることにしておく

    
    for(int i=1;i+k<v.size();i++)
    {
        ans = max(ans,v.at(i+k)-u.at(i-1)-1);
        //i番目からi+k-1番目の０列を反転する
        //連続する１の長さは（i+k番目の0列の先頭）-（i-1番目の0列の終点）-1で求まる
    }
    
    if(k>=v.size()-2){
        cout << n << endl;
    }else{
        cout << ans << endl;
    }
    
}
/*実験より0列を連続してk個とるとき、どの取り方が最も１が多く並ぶか調べればよい
うまく動かないときは、もう一度アルゴリズムを整理すること

v.size()は最初はintになってないので,intとして処理させるには(int)v.size()とかする*/

Compiler output:
a.cc: In function 'int main()':
a.cc:25:28: error: expected primary-expression before ',' token
   25 |             v.push_back(i);,,
      |                            ^
a.cc:25:29: error: expected primary-expression before ',' token
   25 |             v.push_back(i);,,
      |                             ^
a.cc:26:9: error: expected primary-expression before '}' token
   26 |         }
      |         ^
Language: C++

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define fi first
#define se second
int main(){
    int n,k,ans=0;
    string s;
    cin >> n >> k >> s;
    vector<int> v,u;//zero列の開始位置と終了位置
    if(n==1){
        cout << 1 << endl;
        return 0;
    }//サイズ１の時はv,uのサイズが２になってしまうので別処理

    v.push_back(100);
    u.push_back(-1);//-1に0列の終点があることにしておく
    if(s.at(0)=='0'){
        v.push_back(0);
    }//一番左の0だけ先頭の条件が異なる
    for(int i=1;i < n;i++)
    {
        if(s.at(i)=='0'&& s.at(i-1)=='1')
        {
            v.push_back(i);,,
        }
        if(s.at(i)=='1'&& s.at(i-1)=='0')
        {
            u.push_back(i-1);
        }
    }
    if(s.at(n-1)=='0'){
        u.push_back(n-1);
    }//一番右の0だけ終端の条件が異なる
    v.push_back(n);
    u.push_back(100);//nに0列の先頭があることにしておく

    
    for(int i=1;i+k<v.size();i++)
    {
        ans = max(ans,v.at(i+k)-u.at(i-1)-1);
        //i番目からi+k-1番目の０列を反転する
        //連続する１の長さは（i+k番目の0列の先頭）-（i-1番目の0列の終点）-1で求まる
    }
    
    if(k>=v.size()-2){
        cout << n << endl;
    }else{
        cout << ans << endl;
    }
    
}
/*実験より0列を連続してk個とるとき、どの取り方が最も１が多く並ぶか調べればよい
うまく動かないときは、もう一度アルゴリズムを整理すること

v.size()は最初はintになってないので,intとして処理させるには(int)v.size()とかする

Compiler output:
a.cc:53:1: error: unterminated comment
   53 | /*実験より0列を連続してk個とるとき、どの取り方が最も１が多く並ぶか調べればよい
      | ^
a.cc: In function 'int main()':
a.cc:25:28: error: expected primary-expression before ',' token
   25 |             v.push_back(i);,,
      |                            ^
a.cc:25:29: error: expected primary-expression before ',' token
   25 |             v.push_back(i);,,
      |                             ^
a.cc:26:9: error: expected primary-expression before '}' token
   26 |         }
      |         ^
Language: C++

import numpy as np

n, k = [int(i) for i in input().split()]
s = input()

ones = [len(x) for x in s.replace('0', ' ').split()]
zeros = [len(x) for x in s.replace('1', ' ').split()]

if s[0]=='0':
  ones = [0] + ones
if s[-1]=='0':
  ones = ones + [0]

if k >= len(zeros):
  result = n
else: 
  result = [
    np.sum(ones[i:i+k+1]) + np.sum(zeros[i:i+k])
    for i in range(len(zeros)) if i+k+1 <= len(ones)]
  result = max(result)

print(result)

Compiler output:
a.cc:1:1: error: 'import' does not name a type
    1 | import numpy as np
      | ^~~~~~
a.cc:1:1: note: C++20 'import' only available with '-fmodules-ts'
Language: C++

//
// Created on 2019-02-09.
//
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
template<class T> bool INRANGE(T x,T a,T b) { return a<=x&&x<=b; }

#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
                      << " " << __FILE__ << endl;

#define PB push_back
#define INF 1e9
#define MOD 1e9+7
#define EPS 1e-9

typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);


    int N, K;
    string s;
    cin >> N >> K >> s;

    vector<int> Nums;
    int now = 1; //今見ている数
    int cnt = 0; //nowがいくつ並んでいるか
    for (int i = 0; i < N; i++)
    {
        if (S[i] == (char)('0' + now)) cnt++;
        else {
            Nums.push_back(cnt);
            now = 1 - now; //0と1を切り替える時の計算 now ^= 1;
            cnt = 1; //新しいのをカウントし始める
        }
    }
    if (cnt != 0) Nums.push_back(cnt);

    //1-0-1-0-1-0-1って感じの配列が欲しい
    //1-0-1-0みたいに0で終わってたら、適当に１つ足す
    if (Nums.size() % 2 == 0) Nums.push_back(0);


    ll ans = 1;
    int num_cnt = 2*K+1;

    for (int i = 0; i < Nums.size(); i+=2) {
        if (i+num_cnt-1>Nums.size()) break;
        ll cnt = 0;
        REP(j, num_cnt) cnt += Nums[i+j];
        ans = max(ans, cnt);
    }

    cout << ans << endl;


    return 0;

}

Compiler output:
a.cc: In function 'int main()':
a.cc:40:13: error: 'S' was not declared in this scope
   40 |         if (S[i] == (char)('0' + now)) cnt++;
      |             ^
Language: C++

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>

#define NN 100010

int main(void)
{
  int i, k, id, N, K;
  scanf("%d %d",&N, &K);
  int S;
  int s[NN];
  for(i=0;i<N;i++){
    scanf("%01d",&s[i]);
  }
  /**/
  int len[NN];
  int old = 1;
  int d=0;  
  for(i=0;i<N+1;i++) len[i] = 0;
  for(i=0;i<N;i++){
    if(old !=s[i] ) d ++;
    len[d] ++; 
    old = s[i];
  }
  if(s[N-1] == 0){
    d++;
    len[d]=0;
  }
  int L = d+1, oldid;
  int max = 0;
  /* maxint */
   for(i=0;i<L;i+=2){
     if (len[i] > max ){
       max = len[i];
       oldid = i;
     }
   }
    
  for(k=0;k<K;k++){
    //    maxim(&max, &id, L);
    int sum = 0;
    max = 0;
    id = 0;
    //    for(i=1;i<L;i+=2){
    for(i=oldid;i<oldid+=4;i+=2){
      sum = len[i-1] + len[i] + len[i+1] ;
      if(sum > max  ){
	max = sum;
	id = i;
      }
    }
    //  printf("%d(%d,%d,%d),  ",i, len[i-1],  len[i] , len[i+1]); 


    //    printf("max %d  id%d \n", max, id);
    if(max >=N) break;
    if(k != K-1){
      L -=2;
      len[id-1] = max;
      for(i=id;i<L;i+=2){
	len[i] = len[i+2];
	len[i+1] = len[i+3];
      }
    }
    //  for(i=0;i<length;i++){
      //      printf("%d(%d,%d,%d),  ",i, len1[i][0],  len1[i][1] , len1[i][2]); 
    //}
  }

  //  if(max >=N) max = N;
  printf("%d", max); 

  return (0);
}


Compiler output:
a.cc: In function 'int main()':
a.cc:47:18: error: lvalue required as left operand of assignment
   47 |     for(i=oldid;i<oldid+=4;i+=2){
      |                 ~^~~~~~
Language: C++

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;

int main()
{
    ll n, k;
    string str;
    cin >> n >> k >> str;
    vector<ll> ary;
    ll idx = -1;
    if (str[0] == '0') {
        ary.push_back(0);
        idx++;
    }
    ll prev = -1, idx = -1;
    for (ll i = 0; (i < n); i++) {
        ll curr = str[i];
        if (prev != curr) {
            prev = curr;
            idx++;
            ary.push_back(1);
        } else {
            ary[idx]++;
        }
    }
    if (str[n-1] == '0') ary.push_back(0);
    vector<ll> sum(ary.size()+1, 0);
    for (ll i = 0; (i < ary.size()); ++i) {
        sum[i+1] = sum[i] + ary[i];
    }
    ll maxv = 0;
    for(ll i = 1; (i < ary.size()); i+=2) {
        ll left = i - 1;
        ll right = min((ll)(sum.size()-1), i+(k-1)*2+1+1);
        maxv = max(maxv, sum[right] - sum[left]);
    }
    cout << maxv << endl;
    return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:18:19: error: redeclaration of 'll idx'
   18 |     ll prev = -1, idx = -1;
      |                   ^~~
a.cc:13:8: note: 'll idx' previously declared here
   13 |     ll idx = -1;
      |        ^~~
Language: C++

typedef long long ll;

int main()
{
    ll n, k;
    string str;
    cin >> n >> k >> str;
    vector<ll> ary;
    ll idx = -1;
    if (str[0] == '0') {
        ary.push_back(0);
        idx++;
    }
    ll prev = -1, idx = -1;
    for (ll i = 0; (i < n); i++) {
        ll curr = str[i];
        if (prev != curr) {
            prev = curr;
            idx++;
            ary.push_back(1);
        } else {
            ary[idx]++;
        }
    }
    if (str[n-1] == '0') ary.push_back(0);
    vector<ll> sum(ary.size()+1, 0);
    for (ll i = 0; (i < ary.size()); ++i) {
        sum[i+1] = sum[i] + ary[i];
    }
    ll maxv = 0;
    for(ll i = 1; (i < ary.size()); i+=2) {
        ll left = i - 1;
        ll right = min((ll)(sum.size()-1), i+(k-1)*2+1+1);
        maxv = max(maxv, sum[right] - sum[left]);
    }
    cout << maxv << endl;
    return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:6:5: error: 'string' was not declared in this scope
    6 |     string str;
      |     ^~~~~~
a.cc:7:5: error: 'cin' was not declared in this scope
    7 |     cin >> n >> k >> str;
      |     ^~~
a.cc:7:22: error: 'str' was not declared in this scope; did you mean 'std'?
    7 |     cin >> n >> k >> str;
      |                      ^~~
      |                      std
a.cc:8:5: error: 'vector' was not declared in this scope
    8 |     vector<ll> ary;
      |     ^~~~~~
a.cc:8:14: error: expected primary-expression before '>' token
    8 |     vector<ll> ary;
      |              ^
a.cc:8:16: error: 'ary' was not declared in this scope
    8 |     vector<ll> ary;
      |                ^~~
a.cc:14:19: error: redeclaration of 'll idx'
   14 |     ll prev = -1, idx = -1;
      |                   ^~~
a.cc:9:8: note: 'll idx' previously declared here
    9 |     ll idx = -1;
      |        ^~~
a.cc:26:14: error: expected primary-expression before '>' token
   26 |     vector<ll> sum(ary.size()+1, 0);
      |              ^
a.cc:26:16: error: 'sum' was not declared in this scope
   26 |     vector<ll> sum(ary.size()+1, 0);
      |                ^~~
a.cc:33:20: error: 'min' was not declared in this scope; did you mean 'main'?
   33 |         ll right = min((ll)(sum.size()-1), i+(k-1)*2+1+1);
      |                    ^~~
      |                    main
a.cc:34:16: error: 'max' was not declared in this scope; did you mean 'maxv'?
   34 |         maxv = max(maxv, sum[right] - sum[left]);
      |                ^~~
      |                maxv
a.cc:36:5: error: 'cout' was not declared in this scope
   36 |     cout << maxv << endl;
      |     ^~~~
a.cc:36:21: error: 'endl' was not declared in this scope
   36 |     cout << maxv << endl;
      |                     ^~~~
Language: C++

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;

int main()
{
    ll n, k;
    string str;
    cin >> n >> k >> str;
	vector<int> ary;
	int now = 1; //今見ている数
	int cnt = 0; //nowがいくつ並んでいるか
	for (int i = 0; i < N; i++)
	{
		if (S[i] == (char)('0' + now)) cnt++;
		else {
			ary.push_back(cnt);
			now = 1 - now; //0と1を切り替える時の計算 now ^= 1;
			cnt = 1; //新しいのをカウントし始める
		}
	}
	if (cnt != 0) ary.push_back(cnt);
 
	//1-0-1-0-1-0-1って感じの配列が欲しい
	//1-0-1-0みたいに0で終わってたら、適当に１つ足す
	if (ary.size() % 2 == 0) ary.push_back(0);
	vector<int> sum(ary.size() + 1);
	for (int i = 0; i < ary.size(); i++)
	{
		sum[i + 1] = sum[i] + ary[i];
	}
  	int Add = 2 * k + 1;
 	int ans = 0;
	//1-0-1...の1から始めるので、偶数番目だけ見る
	for (int i = 0; i < ary.size(); i += 2)
	{
		//次のleft, rightを計算する [left, right)
		int left = i;
		int right = min(i + Add, (int)ary.size());
		int tmp = sum[right] - sum[left];
 
		ans = max(tmp, ans);
	}
    cout << ans << endl;
    return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:15:29: error: 'N' was not declared in this scope
   15 |         for (int i = 0; i < N; i++)
      |                             ^
a.cc:17:21: error: 'S' was not declared in this scope
   17 |                 if (S[i] == (char)('0' + now)) cnt++;
      |                     ^
Language: C++

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;

int main()
{
    ll n, k;
    string str;
    cin >> n >> k >> str;
    vector<ll> ary;
    if (str[0] == '0') ary.push_back(0);
    ll prev = -1, idx = -1;
    for (ll i = 0; (i < n); i++) {
        ll curr = str[i];
        if (prev != curr) {
            prev = curr;
            idx++;
            ary.push_back(1);
        } else {
            ary[idx]++;
        }
    }
    if (str[n-1] == '0') ary.push_back(0);
    vector<ll> sum(ary.size()+1, 0);
    for (ll i = 0; (i < ary.size()); ++i) {
        sum[i+1] = sum[i] + ary[i];
    }
    ll maxv = 0;
    fo (ll i = 1; (i < ary.size()); i+=2) {
        ll left = i - 1;
        ll right = min((ll)(sum.size()-1), i+(k-1)*2+1+1);
        maxv = max(maxv, sum[right] - sum[left]);
    }
    cout << maxv << endl;
    return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:31:12: error: expected primary-expression before 'i'
   31 |     fo (ll i = 1; (i < ary.size()); i+=2) {
      |            ^
a.cc:31:20: error: 'i' was not declared in this scope
   31 |     fo (ll i = 1; (i < ary.size()); i+=2) {
      |                    ^
Language: C++

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define all(sdk) sdk.begin(),sdk.end()
#define mll map<int, int>
#define pb push_back
#define rep(i,a,b) for(int i=a;i<b;++i)
#define repd(i,a,b) for(int i=a;i>=b;--i)
#define mp make_pair
#define hell 1000000007
#define endl '\n'
#define vvll vector<vector<int> >
#define vll vector<int>
#define mint map<int,int> 
#define sz(x) (int)x.size()
#define sll set<int>
#define pll pair<int,int>
#define F first
#define S second

vector<pll> v;
int pref[100005];
void solve(){  
	int n,k;
	cin>>n>>k;
	string s;
	cin>>s;
	int rl=1;
	v.pb(mp(0,0));
	rep(i,1,n){
		if(a[i]!=a[i-1]){
			v.pb(mp(rl,s[i]-'0'));
			rl=1;
		}
		else{
			++rl;
		}
	}  
	v.pb(mp(rl,s[sz(s)-1]-'0'));
	rep(i,1,sz(v)){
		pref[i]+=v[i].F;
	}
	int ans=0;
	rep(i,1,sz(v)){
		int prev;
		if(v[i].S==0)
		prev=max(0,i-2*k);
		else prev=max(0,i-2*k-1);
		ans=max(ans,pref[i]-pref[prev]);

	}
	cout<<ans<<endl;
}

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t=1;
    // cin>>t;
    while(t--){
        solve();
    }
    return 0;
}

Compiler output:
a.cc: In function 'void solve()':
a.cc:31:20: error: 'a' was not declared in this scope
   31 |                 if(a[i]!=a[i-1]){
      |                    ^
Language: C++

//accumulative sum
#include <iostream>
#include <algorithm>

using namespace std;
int main()
{
	int N, K;
	string s;	
	cin >> N >> K;
	cin >> s;
	vector<int> nums;
	int now = 1, cnt = 0;
	for(char& c : s)
	{
		if(c == char(now + '0')) cnt++;
		else
		{
			nums.emplace_back(cnt);
			cnt = 1;
			now ^= 1;
		}
	}
	if(cnt != 0) nums.emplace_back(cnt);

	if(nums.size() % 2 == 0) nums.emplace_back(0);
	int length = K * 2 + 1;

	int left = 0, right = 0;
	int sum = 0, ans = 0;
	for(int i = 0; i < nums.size(); i += 2)
	{
		int nextL = i;
		int nextR = min(nextL + length, (int)nums.size());
		while(left < nextL)
		{
			sum -= nums[left];
			left++;
		}
		while(right < nextR)
		{
			sum += nums[right];
			right++;
		}
		ans = max(ans, sum);
	}

	cout << ans << endl;
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:12:9: error: 'vector' was not declared in this scope
   12 |         vector<int> nums;
      |         ^~~~~~
a.cc:4:1: note: 'std::vector' is defined in header '<vector>'; this is probably fixable by adding '#include <vector>'
    3 | #include <algorithm>
  +++ |+#include <vector>
    4 | 
a.cc:12:16: error: expected primary-expression before 'int'
   12 |         vector<int> nums;
      |                ^~~
a.cc:19:25: error: 'nums' was not declared in this scope
   19 |                         nums.emplace_back(cnt);
      |                         ^~~~
a.cc:24:22: error: 'nums' was not declared in this scope
   24 |         if(cnt != 0) nums.emplace_back(cnt);
      |                      ^~~~
a.cc:26:12: error: 'nums' was not declared in this scope
   26 |         if(nums.size() % 2 == 0) nums.emplace_back(0);
      |            ^~~~
a.cc:31:28: error: 'nums' was not declared in this scope
   31 |         for(int i = 0; i < nums.size(); i += 2)
      |                            ^~~~
Language: Java

import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int num = sc.nextInt();
		int k = sc.nextInt();
		String s = sc.next();
        String[] line = new String[num];
        line = s.split("");
		//System.out.println(line.length);
        String former = line[0];
        int check = 0;
        int count = 1;
        int count2 = 0;
        int index = 0;
        int sum = 0;
        int max = 0;
        int temp = 0;
        List<Integer> counter = new ArrayList<Integer>();
        List<Integer> counter2 = new ArrayList<Integer>();
        if(line[0].equals("0")) check = 1;
        if(line.length == 1) {
            counter.add(count);
            counter2.add(count);
        }
        for(int i=1; i<num; i++){
          if(line[i].equals(former)){
            count++;
          }
          else{
            check++;
            count++;
            if(line[i].equals("0")) former = "0";
            else former = "1";
          }
          if(check == 2) count2++;
          if(check == 3){
            counter.add(count-1);
            counter2.add(count-1-temp);
            count = count2+1;
            temp = count2;
            count2 = 0;
            check = 1;
          }
          if(i+1 >= num) {
            counter.add(count);
            counter2.add(count-temp);
            break;
          }
        }
        temp = 0;
        //System.out.println("size="+counter.size());
        while(true){
          temp = index;
          //System.out.println("index="+index+", value="+counter.get(index));
          sum += counter.get(index);
          index++;
          for(int j=1; j<k; j++){
             //System.out.println("index="+index+", value="+counter2.get(index));
             sum += counter2.get(index);
             index++;
             if(index+k > counter2.size()) break;
          }
          //sum -= k-1;
          if(max < sum) max = sum;
          sum = 0;
          index = temp + 1;
        }
        if(max == 0) max = counter.get(0);
        System.out.println(max);
	}
}

Compiler output:
Main.java:69: error: unreachable statement
        if(max == 0) max = counter.get(0);
        ^
1 error
Language: Java

import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int num = sc.nextInt();
		int k = sc.nextInt();
		String s = sc.next();
        String[] line = new String[num];
        line = s.split("");
		//System.out.println(line.length);
        String former = line[0];
        int check = 0;
        int count = 1;
        int count2 = 0;
        int index = 0;
        int sum = 0;
        int max = 0;
        int temp = 0;
        List<Integer> counter = new ArrayList<Integer>();
        List<Integer> counter2 = new ArrayList<Integer>();
        if(line[0].equals("0")) check = 1;
        if(line.length == 1) {
            counter.add(count);
            counter2.add(count);
        }
        for(int i=1; i<num; i++){
          if(line[i].equals(former)){
            count++;
          }
          else{
            check++;
            count++;
            if(line[i].equals("0")) former = "0";
            else former = "1";
          }
          if(check == 2) count2++;
          if(check == 3){
            counter.add(count-1);
            counter2.add(count-1-temp);
            count = count2+1;
            temp = count2;
            count2 = 0;
            check = 1;
          }
          if(i+1 >= num) {
            counter.add(count);
            counter2.add(count-temp);
            break;
          }
        }
        temp = 0;
        //System.out.println("size="+counter.size());
        while(true){
          temp = index;
          //System.out.println("index="+index+", value="+counter.get(index));
          sum += counter.get(index);
          index++;
          for(int j=1; j<k; j++){
             //System.out.println("index="+index+", value="+counter2.get(index));
             sum += counter2.get(index);
             index++;
             if(index+k > counter2.size()) break;
          }
          //sum -= k-1;
          if(max < sum) max = sum;
          sum = 0;
          index = temp + 1;
        }
        if(max = 0) max = counter.get(0);
        System.out.println(max);
	}
}

Compiler output:
Main.java:69: error: incompatible types: int cannot be converted to boolean
        if(max = 0) max = counter.get(0);
               ^
1 error
Language: Java

import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int num = sc.nextInt();
		int k = sc.nextInt();
		String s = sc.next();
        String[] line = new String[num];
        line = s.split("");
		//System.out.println(line.length);
        String former = line[0];
        int check = 0;
        int count = 1;
        int count2 = 0;
        int index = 0;
        int sum = 0;
        int max = 0;
        int temp = 0;
        List<Integer> counter = new ArrayList<Integer>();
        List<Integer> counter2 = new ArrayList<Integer>();
        if(line[0].equals("0")) check = 1;
        if(line.length == 1) {
            counter.add(count);
            counter2.add(count);
        }
        for(int i=1; i<num; i++){
          if(line[i].equals(former)){
            count++;
          }
          else{
            check++;
            count++;
            if(line[i].equals("0")) former = "0";
            else former = "1";
          }
          if(check == 2) count2++;
          if(check == 3){
            counter.add(count-1);
            counter2.add(count-1-temp);
            count = count2+1;
            temp = count2;
            count2 = 0;
            check = 1;
          }
          if(i+1 >= num) {
            counter.add(count);
            counter2.add(count-temp);
            break;
          }
        }
        temp = 0;
        //System.out.println("size="+counter.size());
        while(true){
          if(index+k > counter2.size()) break;
          temp = index;
          //System.out.println("index="+index+", value="+counter.get(index));
          sum += counter.get(index);
          index++;
          for(int j=1; j<k; j++){
             //System.out.println("index="+index+", value="+counter2.get(index));
             sum += counter2.get(index);
             index++;
          }
          //sum -= k-1;
          if(max < sum) max = sum;
          sum = 0;
          index = temp + 1;
        }
        if(max = 0) max = counter.get(0);
        System.out.println(max);
	}
}

Compiler output:
Main.java:69: error: incompatible types: int cannot be converted to boolean
        if(max = 0) max = counter.get(0);
               ^
1 error
Language: C++

#include <cstdio>
#include <vector>
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define all(a) (a).begin(), (a).end()

int N, K;
char S[100010];
std::vector<int> a, b;
int Sa[100010], Sb[100010];
int ans;

int main()
{
  scanf( "%d%d", &N, &K );
  scanf( "%s", S );

  int cnt = 0;

  S[N] = '2';

  rep( i, N+1 )
  {
    if( i && S[i] != S[i-1] )
      (S[i-1]=='1'?b:a).push_back( cnt ), cnt = 0;

    ++cnt;
  }

  rep( i, a.size() )
    Sa[i+1] = Sa[i]+a[i];//, printf( "a[%d] = %d\n", i, a[i] );
  rep( i, b.size() )
    Sb[i+1] = Sb[i]+b[i];//, printf( "b[%d] = %d\n", i, b[i] );

  if( K == 1 )
  {
    if( a.empty() )
    {
      printf( "%d\n", *std::max_element( b.begin(), b.end() ) );

      return 0;
    }

    int ma = *std::max_element( a.begin(), a.end() );

    rep( i, N ) if( a[i] == ma )
    {
      if( S[0] == '0' )
        printf( "%d\n", std::max( ma+b[i], i ? ma+b[i-1] : 0 ) );
      else
        printf( "%d\n", std::max( ma+b[i], i+1 < b.size() ? ma+b[i+1] : 0 ) );
    }

    return 0;
  }

  // a: '0', b: '1'
  rep( i, std::max<int>(a.size()-K+1,0) )
  {
    // a0 b0 a1 b1
    if( S[0] == '0' )
      ans = std::max( ans, Sa[i+K]-Sa[i]+Sb[std::min<int>(i+K,b.size())]-Sb[std::max(0,i-1)] );
    // b0 a0 b1 a1
    else
      ans = std::max( ans, Sa[i+K]-Sa[i]+Sb[std::min<int>(i+K+1,b.size())]-Sb[i] );
  }

  rep( i, std::max<int>(b.size()-K,0) )
  {
    // a0 b0 a1 b1
    if( S[0] == '0' )
      ans = std::max( ans, Sa[std::min<int>(i+K,a.size())]-Sa[std::min<int>(i,a.size())]+Sb[std::min<int>(i+K,b.size())]-Sb[std::max(i-1,0)] );
    // b0 a0 b1 a1
    else
      ans = std::max( ans, Sa[std::min<int>(i+K-1,a.size())]-Sa[std::max(0,i-1)]+Sb[std::min<int>(i+K,b.size())]-Sb[std::max(i-1,0)] );

    //printf( "{%d} %d\n", i, Sa[std::min<int>(i+K-1,a.size())]-Sa[std::max(0,i-1)]+Sb[std::min<int>(i+K,b.size())]-Sb[std::max(i-1,0)] );
  }

  /*
    K = 2
    i = 3

    i = 0

    111 0 1 0 1 0 [11] 00 11
    a: 1,1,1,2
    b: 3,1,1,[2],2
  */

  printf( "%d\n", ans );

  return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:39:29: error: 'max_element' is not a member of 'std'; did you mean 'tuple_element'?
   39 |       printf( "%d\n", *std::max_element( b.begin(), b.end() ) );
      |                             ^~~~~~~~~~~
      |                             tuple_element
a.cc:44:20: error: 'max_element' is not a member of 'std'; did you mean 'tuple_element'?
   44 |     int ma = *std::max_element( a.begin(), a.end() );
      |                    ^~~~~~~~~~~
      |                    tuple_element
Language: C++

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

int main() {
	ios::sync_with_stdio(false);
	int N, K;
	string S;
	cin >> N >> K >> S;

	vector<int> a;//個数
	char tmp='1';
	int cnt = 0;

	for (int i = 0; i < N;i++) {
		if (S.at(i) == tmp) {
			cnt++;
		}
		else {
			a.push_back(cnt);
			cnt = 1;
			tmp = S.at(i);
		}
	}

	a.push_back(cnt);
	
	/*////////////////////////////////////////
	for (auto&i:a) {
		cout << i << " ";
	}
	cout << "\n";*/

	int add = K * 2 + 1;
	if (a.size() <= add) {
		cout << N << "\n";
		return 0;
	}
	
	vector<int> sums(a.size()+1);

	for (int i = 0; i < a.size(); i++) {
		sums.at(i + 1) = sums.at(i) + a.at(i);
	}
	
	/*////////////////////////////////////////
	for (auto&i : sums) {
		cout << i << " ";
	}
	cout << "\n";*/

	int left = 0, right = 0, tmp;
	int ans = 0;
	
	for (int i = 0; i < a.size(); i++) {
		left = i;
		right = min((int)a.size(), i+add);
		int tmp = sums.at(right) - sums.at(left);
		ans = max(ans, tmp);
	}

	cout << ans << "\n";

	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:51:34: error: conflicting declaration 'int tmp'
   51 |         int left = 0, right = 0, tmp;
      |                                  ^~~
a.cc:11:14: note: previous declaration as 'char tmp'
   11 |         char tmp='1';
      |              ^~~
Language: C++

#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;

int main(){
  int N,K,ans=0;
  string S;
  cin>>N>>K>>S;
  vector<int> Z;
  
  int AAA=0,BBB=0;
  for(int i=0; i<N; ++i){
    if(S.at(i)=='1'){
      BBB ++;
      if(AAA>0){
        Z.push_back(AAA); 
        AAA=0;
      }
    }
    else{
      AAA ++;
      if(BBB>0){
        Z.push_back(BBB); 
        BBB=0;
      }
    }
  }
  
  vector<int> ZZ;
  int g=0;
  for(int i=0; i<Z.size(); ++i){
    g+=Z[i];
    ZZ.push_back(g);
  }
  
  for(int i=0; i<100000; ++i) ZZ.push_back(g);
  
  
  
  int A=Z.size()-2*K;
  if(A<1) A=2;
  
  if(S.at(0)=='0'){
    int aaa=2*K;
    if(aaa>Z.size() && Z.size%2==0) aaa=Z.size();
    else if(aaa>Z.size() && Z.size%2==1) aaa=Z.size()-1;
    ans=max(0,ZZ[aaa]);
    for(int i=0; i<A; ++i){
      if(i%2==0) ans=max(ans,ZZ[i+2*K+1]-ZZ[i]);
    }
  }
  else{
    int bbb=2*K+1;
    if(bbb>Z.size() && Z.size%2==1) bbb=Z.size();
    else if(bbb>Z.size() && Z.size%2==0) bbb=Z.size()-1;
    ans=max(0,ZZ[bbb]);
    for(int i=0; i<=A; ++i){
      if(i%2==1) ans=max(ans,ZZ[i+2*K+1]-ZZ[i]);
    }
  }
  
  cout<<ans<<endl;
}



Compiler output:
a.cc: In function 'int main()':
a.cc:47:26: error: invalid use of member function 'std::vector<_Tp, _Alloc>::size_type std::vector<_Tp, _Alloc>::size() const [with _Tp = int; _Alloc = std::allocator<int>; size_type = long unsigned int]' (did you forget the '()' ?)
   47 |     if(aaa>Z.size() && Z.size%2==0) aaa=Z.size();
      |                        ~~^~~~
      |                              ()
a.cc:48:31: error: invalid use of member function 'std::vector<_Tp, _Alloc>::size_type std::vector<_Tp, _Alloc>::size() const [with _Tp = int; _Alloc = std::allocator<int>; size_type = long unsigned int]' (did you forget the '()' ?)
   48 |     else if(aaa>Z.size() && Z.size%2==1) aaa=Z.size()-1;
      |                             ~~^~~~
      |                                   ()
a.cc:56:26: error: invalid use of member function 'std::vector<_Tp, _Alloc>::size_type std::vector<_Tp, _Alloc>::size() const [with _Tp = int; _Alloc = std::allocator<int>; size_type = long unsigned int]' (did you forget the '()' ?)
   56 |     if(bbb>Z.size() && Z.size%2==1) bbb=Z.size();
      |                        ~~^~~~
      |                              ()
a.cc:57:31: error: invalid use of member function 'std::vector<_Tp, _Alloc>::size_type std::vector<_Tp, _Alloc>::size() const [with _Tp = int; _Alloc = std::allocator<int>; size_type = long unsigned int]' (did you forget the '()' ?)
   57 |     else if(bbb>Z.size() && Z.size%2==0) bbb=Z.size()-1;
      |                             ~~^~~~
      |                                   ()
Language: C++

#include<vector>
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;

#define BEGIN ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define END return EXIT_SUCCESS
#define up(I,A,B) for(auto I=(A);I<=(B);++I)
#define pb push_back
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
template<class T>inline void                             in(T &p){cin>>p;}
template<class T1,class T2>inline void                   in(T1 &p1,T2 &p2){cin>>p1>>p2;}
template<class T1,class T2,class T3>inline void          in(T1 &p1,T2 &p2,T3 &p3){cin>>p1>>p2>>p3;}
template<class T1,class T2,class T3,class T4>inline void in(T1 &p1,T2 &p2,T3 &p3,T4 &p4){cin>>p1>>p2>>p3>>p4;}
template<class T>inline void                             ins(T &p){for_each(all(p),in<decltype(p[0])>);}
template<class T>inline void                             out(T p){cout<<p<<endl;}
template<class T1,class T2>inline void                   out(T1 p1,T2 p2){cout<<p1<<" "<<p2<<endl;}
template<class T1,class T2,class T3>inline void          out(T1 p1,T2 p2,T3 p3){cout<<p1<<" "<<p2<<" "<<p3<<endl;}
template<class T1,class T2,class T3,class T4>inline void out(T1 p1,T2 p2,T3 p3,T4 p4){cout<<p1<<" "<<p2<<" "<<p3<<" "<<p4<<endl;}
template<class T>inline void                             outs(T p){for_each(all(p),out<decltype(p[0])>);}
long N,K,len=1,i,M,ans=1,L,A;
string S;
vector<long>v,s;
inline void solve(void){
  in(N,K,S);
  up(i,1,N-1){
    if(S[i]==S[i-1])len++;
    else{
      v.pb(len);
      len=1;
    }
  }
  v.pb(len);
  M=v.size();
  s.resize(M+1);
  for(i=0;i<M;i++)s[i+1]=s[i]+v[i];
  A=S[0]=='1'?0:1;
  for(k=0;k<=K;k++){
    L=2*k+1;
    for(i=A;i+L<=M;i+=2)chmax(ans,s[i+L]-s[i]);
  }
  for(i=A;i+L<=M;i+=2)chmax(ans,s[i+L]-s[i]);
  if(S[0]=='0')chmax(ans,s[min(K*2,M)]-s[0]);
  if(S[N-1]=='0')chmax(ans,s[M]-s[max(M-K*2,0L)]);
  out(ans);
}

int main(int argc,char**argv){
  BEGIN;
  solve();
  END;
}


Compiler output:
a.cc: In function 'void solve()':
a.cc:39:7: error: 'k' was not declared in this scope
   39 |   for(k=0;k<=K;k++){
      |       ^