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

#include <iostream>
#include <vector>
 
using namespace std;
 
int main(){
  int n, k, t;
  int min = 1000;
  int cnt = 0;
  int index;
  bool flag;
  vector<int> vec;
  for (int i = 0; i < n; i++) {
    cin >> t;
    vec.push_back(t);
    if (min > t) {min = t; index = vec.size() - 1;}
  }
  for (int i = index; i > -1; i-=k) {
    flag = false;
    for(int j = i; j > i - k; j--){
      if (vec[j] > min) { vec[j] = min; flag = true;}
    }
    if(flag) cnt++;
  }
  for (int i = index; i < vec.size(); i += k){
    flag = true
    for(int j = i; j < j + k; j++){
      if (vec[j] > min) { vec[j] = min; flag  true;}
    }
    if(flag) cnt++;
  }
  cout << cnt << endl;

Compiler output:
a.cc: In function 'int main()':
a.cc:26:16: error: expected ';' before 'for'
   26 |     flag = true
      |                ^
      |                ;
   27 |     for(int j = i; j < j + k; j++){
      |     ~~~         
a.cc:27:20: error: 'j' was not declared in this scope
   27 |     for(int j = i; j < j + k; j++){
      |                    ^
a.cc:32:23: error: expected '}' at end of input
   32 |   cout << cnt << endl;
      |                       ^
a.cc:6:11: note: to match this '{'
    6 | int main(){
      |           ^
Language: C++

#include <iostream>
#include <vector>
 
using namespace std;
 
int main(){
  int n, k, t;
  int min = 1000;
  int cnt = 0;
  int index;
  bool flag;
  vector<int> vec;
  for (int i = 0; i < n; i++) {
    cin >> t;
    vec.push_back(t);
    if (min > t) {min = t; index = vec.size() - 1;}
  }
  for (int i = index; i > -1; i-=k) {
    flag = false
    for(int j = i; j > i - k; j--){
      if (vec[j] > min) { vec[j] = min; flag = true;}
    }
    if(flag) cnt++;
  }
  for (int i = index; i < vec.size(); i += k){
    flag = true
    for(int j = i; j < j + k; j++){
      if (vec[j] > min) { vec[j] = min; flag  true;}
    }
    if(flag) cnt++;
  }
  cout << cnt << endl;

Compiler output:
a.cc: In function 'int main()':
a.cc:19:17: error: expected ';' before 'for'
   19 |     flag = false
      |                 ^
      |                 ;
   20 |     for(int j = i; j > i - k; j--){
      |     ~~~          
a.cc:20:20: error: 'j' was not declared in this scope
   20 |     for(int j = i; j > i - k; j--){
      |                    ^
a.cc:26:16: error: expected ';' before 'for'
   26 |     flag = true
      |                ^
      |                ;
   27 |     for(int j = i; j < j + k; j++){
      |     ~~~         
a.cc:27:20: error: 'j' was not declared in this scope
   27 |     for(int j = i; j < j + k; j++){
      |                    ^
a.cc:32:23: error: expected '}' at end of input
   32 |   cout << cnt << endl;
      |                       ^
a.cc:6:11: note: to match this '{'
    6 | int main(){
      |           ^
Language: C++

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

int main(){
  vector<int> vec(100000);
  int n, k, t;
  int min = 1000;
  bool flag;
  int cnt=0;
  cin >> n >> k;
  for (int i = 0; i < n; i++) { cin >> t; vec.push_back(int(t) - '0'); }
  for (int i = 0; ; i+=k) {
    flag = true
    for (int j = 0; j < k; j++){
    	t = vec.at(j);
        if (min > t) min = t;
    }
    for (int j = 0; j < k; j++){
      vec.at(j) = min;
    }
    cnt++;
    for (int j = 0; j < n; j++){
      if(vec.at(j) != min) { flag = false; break; }
    }
    if(flag) break;
  }
}

Compiler output:
a.cc: In function 'int main()':
a.cc:14:16: error: expected ';' before 'for'
   14 |     flag = true
      |                ^
      |                ;
   15 |     for (int j = 0; j < k; j++){
      |     ~~~         
a.cc:15:21: error: 'j' was not declared in this scope
   15 |     for (int j = 0; j < k; j++){
      |                     ^
Language: C++

#include<bits/stdc++.h>
#define rep(i, x) for(int i = 0; i < (int)(x); i++)
#define reps(i, x) for(int i = 1; i <= (int)(x); i++)
#define For(i, a, b) for(int i = (a); i < (b); i++)
#define UNIQUE(v) v..erase( unique(v.begin(), v.end()), v.end() );
#define Size(x) ((int)(x).size())
using namespace std;

int solv(int a, int b){
	int num_a, over_a, ans_a;
	num_a = a / (k - 1);
	over_a = a % (k - 1);
	if(over_a == 0) ans_a = num_a;
	else ans_a = num_a + 1;

	int num_b, over_b, ans_b;
	if(over_a != 0) b -= k - over_a;
	num_b = b / (k - 1);
	over_b =  b % (k - 1);
	if(over_b == 0) ans_b = num_b;
	else ans_b = num_b + 1;

	return ans_a + ans_b;
}

int main(){
	int n, k;
	cin >> n >> k;
	int a = 0, b = 0;
	bool flag = true;
	rep(i, n){
		int tmp;
		cin >> tmp;
		if(flag and tmp != 1) a++;
		else if(!flag) b++;
		if(tmp == 1) flag = false;
	}

	cout << min(solv(a, b), solv(b, a)) << endl;

	return 0;
}


Compiler output:
a.cc: In function 'int solv(int, int)':
a.cc:11:22: error: 'k' was not declared in this scope
   11 |         num_a = a / (k - 1);
      |                      ^
Language: C++

#include<bits/stdc++.h>
#define rep(i, x) for(int i = 0; i < (int)(x); i++)
#define reps(i, x) for(int i = 1; i <= (int)(x); i++)
#define For(i, a, b) for(int i = (a); i < (b); i++)
#define UNIQUE(v) v..erase( unique(v.begin(), v.end()), v.end() );
#define Size(x) ((int)(x).size())
using namespace std;

int solv(int a, int b){
	int num_a, over_a, ans_a;
	num_a = a / (k - 1);
	over_a = a % (k - 1);
	if(over_a == 0) ans_a = num_a;
	else ans_a = num_a + 1;

	int num_b, over_b, ans_b;
	if(over_a != 0) b -= k - over_a;
	num_b = b / (k - 1);
	over_b =  b % (k - 1);
	if(over_b == 0) ans_b = num_b;
	else ans_b = num_b + 1;

	return ans_a + ans_b << endl;
}

int main(){
	int n, k;
	cin >> n >> k;
	int a = 0, b = 0;
	bool flag = true;
	rep(i, n){
		int tmp;
		cin >> tmp;
		if(flag and tmp != 1) a++;
		else if(!flag) b++;
		if(tmp == 1) flag = false;
	}

	cout << min(solv(a, b), solv(b, a)) << endl;

	return 0;
}


Compiler output:
a.cc: In function 'int solv(int, int)':
a.cc:11:22: error: 'k' was not declared in this scope
   11 |         num_a = a / (k - 1);
      |                      ^
a.cc:23:30: error: invalid operands of types 'int' and '<unresolved overloaded function type>' to binary 'operator<<'
   23 |         return ans_a + ans_b << endl;
      |                ~~~~~~~~~~~~~~^~~~~~~
Language: C

#include <stdio.h>

int main(void)
{
   int n,k,a[100000],ans,i;

   scanf("%d%d",&n,&k);

   for(i=0,i<n;i++)
      scanf("%d",&a[i]);

   n--; k--;
   ans=n/k+n%k;

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

   return 0;
}


Compiler output:
main.c: In function 'main':
main.c:9:19: error: expected ';' before ')' token
    9 |    for(i=0,i<n;i++)
      |                   ^
      |                   ;
Language: C

#include <stdio.h>

int main(void)
{
   int n,k,a[i],ans;

   scanf("%d%d",&n,&k);

   for(i=0,i<n;i++)
      scanf("%d",&a[i]);

   n--; k--;
   ans=n/k+n%k;

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

   return 0;
}


Compiler output:
main.c: In function 'main':
main.c:5:14: error: 'i' undeclared (first use in this function)
    5 |    int n,k,a[i],ans;
      |              ^
main.c:5:14: note: each undeclared identifier is reported only once for each function it appears in
main.c:9:19: error: expected ';' before ')' token
    9 |    for(i=0,i<n;i++)
      |                   ^
      |                   ;
Language: C

#include <stdio.h>

int main(void)
{
   int n,k a[i],ans;
 
   scanf("%d%d",&n,&k);
  
   for(i=0,i<n;i++)
      scanf("%d",&a[i]);
 
   n--; k--;
   ans=n/k+n%k;

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

   return 0;
}


Compiler output:
main.c: In function 'main':
main.c:5:12: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'a'
    5 |    int n,k a[i],ans;
      |            ^
main.c:7:21: error: 'k' undeclared (first use in this function)
    7 |    scanf("%d%d",&n,&k);
      |                     ^
main.c:7:21: note: each undeclared identifier is reported only once for each function it appears in
main.c:9:8: error: 'i' undeclared (first use in this function)
    9 |    for(i=0,i<n;i++)
      |        ^
main.c:9:19: error: expected ';' before ')' token
    9 |    for(i=0,i<n;i++)
      |                   ^
      |                   ;
main.c:10:19: error: 'a' undeclared (first use in this function)
   10 |       scanf("%d",&a[i]);
      |                   ^
main.c:13:4: error: 'ans' undeclared (first use in this function)
   13 |    ans=n/k+n%k;
      |    ^~~
Language: Java

class Main {
  public static void main(String[] args) {
    Scanner scan = new Scanner(System.in);
    int n = scan.nextInt();
    int k = scan.nextInt();
    System.out.println(n/(k-1));
  }}

Compiler output:
Main.java:3: error: cannot find symbol
    Scanner scan = new Scanner(System.in);
    ^
  symbol:   class Scanner
  location: class Main
Main.java:3: error: cannot find symbol
    Scanner scan = new Scanner(System.in);
                       ^
  symbol:   class Scanner
  location: class Main
2 errors
Language: C++

#include <iostream>
#include <vector>

int main() {
  int n, k;
  int ar[100000];
  std::cin >> n >> k;
  for (int i = 0; i < n; ++i) {
    std::cin >> ar[i];
  }
  if (n == k) {
    std::cout << 1 << std::endl;
    return 0;
  }
  int idx = std::find(ar, ar + n, 1) - ar;

  int res = idx / (k - 1) ? idx / (k - 1) : 1;
  res += (n - idx) / (k - 1) ? (n - idx) / (k - 1) : 1;
  std::cout << res << std::endl;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:15:22: error: no matching function for call to 'find(int [100000], int*, int)'
   15 |   int idx = std::find(ar, ar + n, 1) - ar;
      |             ~~~~~~~~~^~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/bits/locale_facets.h:48,
                 from /usr/include/c++/14/bits/basic_ios.h:37,
                 from /usr/include/c++/14/ios:46,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:1:
/usr/include/c++/14/bits/streambuf_iterator.h:435:5: note: candidate: 'template<class _CharT2> typename __gnu_cxx::__enable_if<std::__is_char<_CharT2>::__value, std::istreambuf_iterator<_CharT> >::__type std::find(istreambuf_iterator<_CharT>, istreambuf_iterator<_CharT>, const _CharT2&)'
  435 |     find(istreambuf_iterator<_CharT> __first,
      |     ^~~~
/usr/include/c++/14/bits/streambuf_iterator.h:435:5: note:   template argument deduction/substitution failed:
a.cc:15:22: note:   mismatched types 'std::istreambuf_iterator<_CharT>' and 'int*'
   15 |   int idx = std::find(ar, ar + n, 1) - ar;
      |             ~~~~~~~~~^~~~~~~~~~~~~~~
Language: Java

import java.io.*;
import java.util.*;
public class Main
{
BufferedReader br;
BufferedWriter bw;
public static void main(String args[]) throws IOException
{
  (new Minim()).run();
}
 
void run() throws IOException
{
  br =new BufferedReader(new InputStreamReader(System.in));
  bw =new BufferedWriter(new OutputStreamWriter(System.out));
  // code starts here
  String s[]=line().split(" ");
  int n=toInt(s[0]);
  int k=toInt(s[1]);
  int ar[]=na();
  if(k>=n)
  {
      System.out.println("1");
      return;
  }
  int i=0,pos=0;
  while(i<n && ar[i]!=1)
  i++;
  int left=pos-0,right=n-1-pos;
  int ans=0;
  if(left>k)
  {
      ans+=Math.ceil(left/(1.0*k));
  }
  else
  ans++;
    if(right>k)
    ans+=Math.ceil(right/(1.0*k));
    else 
    ans++;
    System.out.println(ans);
    
    
 
 
 bw.flush();
}
 
String line() throws IOException
{
return br.readLine();
}
int[] na() throws IOException
{
String s[]=line().split(" ");
int len=s.length;
int ar[]=new int[len];
for(int i=0;i<len;i++)
ar[i]=toInt(s[i]);
return ar;
}
 
int[][] matrix(int n,int m) throws IOException
{
int ar[][]=new int[n][m];
for(int i=0;i<n;i++)
ar[i]=na();
return ar;
}
int toInt(String s) throws IOException
{
return Integer.parseInt(s);
} 
long toLong(String s) throws IOException
{
return Long.parseLong(s);
}
double toDouble(String s) throws IOException
{
return Double.parseDouble(s);
}
private void tr(Object... o) { System.out.println(Arrays.deepToString(o)); }
}

Compiler output:
Main.java:9: error: cannot find symbol
  (new Minim()).run();
       ^
  symbol:   class Minim
  location: class Main
1 error
Language: Java

import java.io.*;
import java.util.*;
public class Minim
{
BufferedReader br;
BufferedWriter bw;
public static void main(String args[]) throws IOException
{
  (new Minim()).run();
}

void run() throws IOException
{
  br =new BufferedReader(new InputStreamReader(System.in));
  bw =new BufferedWriter(new OutputStreamWriter(System.out));
  // code starts here
  String s[]=line().split(" ");
  int n=toInt(s[0]);
  int k=toInt(s[1]);
  int ar[]=na();
  if(k>=n)
  {
      System.out.println("1");
      return;
  }
  int i=0,pos=0;
  while(i<n && ar[i]!=1)
  i++;
  int left=pos-0,right=n-1-pos;
  int ans=0;
  if(left>k)
  {
      ans+=Math.ceil(left/(1.0*k));
  }
  else
  ans++;
    if(right>k)
    ans+=Math.ceil(right/(1.0*k));
    else 
    ans++;
    System.out.println(ans);
    
    


 bw.flush();
}

String line() throws IOException
{
return br.readLine();
}
int[] na() throws IOException
{
String s[]=line().split(" ");
int len=s.length;
int ar[]=new int[len];
for(int i=0;i<len;i++)
ar[i]=toInt(s[i]);
return ar;
}

int[][] matrix(int n,int m) throws IOException
{
int ar[][]=new int[n][m];
for(int i=0;i<n;i++)
ar[i]=na();
return ar;
}
int toInt(String s) throws IOException
{
return Integer.parseInt(s);
} 
long toLong(String s) throws IOException
{
return Long.parseLong(s);
}
double toDouble(String s) throws IOException
{
return Double.parseDouble(s);
}
private void tr(Object... o) { System.out.println(Arrays.deepToString(o)); }
}

Compiler output:
Main.java:3: error: class Minim is public, should be declared in a file named Minim.java
public class Minim
       ^
1 error
Language: C++

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

int main() {
	int n k ;
	cin >> n >> k ;
	vector <int> a(n) ;
	int m=0 ;
	int j=k-1 ;
	int ans=0 ;
	for ( int i=0 ; i<n ; i++ ){
		cin >> a.at(i) ;
		if ( a.at(i)==1 ) m=i+1 ;
	}
	if ( m>1) {
		if ( (m-1)%j==0 ) ans+=(m-1)/j ;
		else ans+=(m-1)/j+1 ;
	}
	if ( (n-m)>0 ) {
		if ( (n-m)%j==0 ) ans+=(n-m)/j ;
		else ans+=(n-m)/j+1 ;
	}
	cout << ans << endl ;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:5:15: error: expected initializer before 'k'
    5 |         int n k ;
      |               ^
a.cc:6:16: error: 'n' was not declared in this scope; did you mean 'yn'?
    6 |         cin >> n >> k ;
      |                ^
      |                yn
a.cc:6:21: error: 'k' was not declared in this scope
    6 |         cin >> n >> k ;
      |                     ^
Language: C++

include<stdio.h>
int main(){
int n,k,i,a,ans;
scanf("%d%d",&n,&k);
for(i=0;i<n;i++)
scanf("%d",&a);
ans=(n-1)/(k-1);
if((n-1)%(k-1)!=0)
ans++;
printf("%d\n",ans);
return 0;
}

Compiler output:
a.cc:1:1: error: 'include' does not name a type
    1 | include<stdio.h>
      | ^~~~~~~
Language: C++

#include<iostream>
#include<vector>
using namespace std;
int N K;
vector<int> a;

void solve(){
    if(N%K == 0){
        cout << N/K << endl;
    } else{
        cout << (N-1)/(K-1) + 1 << endl;
    }
}

int main(){
    cin >> N >> K;
    for (int i = 0; i<N; i++){
        cin >> a[i];
    }
    solve();
}

Compiler output:
a.cc:4:7: error: expected initializer before 'K'
    4 | int N K;
      |       ^
a.cc: In function 'void solve()':
a.cc:8:8: error: 'N' was not declared in this scope
    8 |     if(N%K == 0){
      |        ^
a.cc:8:10: error: 'K' was not declared in this scope
    8 |     if(N%K == 0){
      |          ^
a.cc: In function 'int main()':
a.cc:16:12: error: 'N' was not declared in this scope
   16 |     cin >> N >> K;
      |            ^
a.cc:16:17: error: 'K' was not declared in this scope
   16 |     cin >> N >> K;
      |                 ^
Language: C

#include<stdio.h>

int main(void){
  int K,N,i,n1,ope;
  int a[100000];
  
  scanf("%d %d",&N,&K);
  for(i = 0;i < N;i++){
    scanf("%d",&a[i]);
    if(a[i] == 1)
      n1 = i + 1;
  }
  
  ope = (n1 - 1)/(K-1) + (N - n1)/(K-1);
  if((n1 - 1)%(K-1) != 0)
    ope++;
  if((N - n1)%(K - 1) != 0)
    ope++;
  if((N - n1)%(K - 1) + (n1 - 1)%(K-1) > k-1)
    ope--;
  
  printf("%d",ope);
}

Compiler output:
main.c: In function 'main':
main.c:19:42: error: 'k' undeclared (first use in this function)
   19 |   if((N - n1)%(K - 1) + (n1 - 1)%(K-1) > k-1)
      |                                          ^
main.c:19:42: note: each undeclared identifier is reported only once for each function it appears in
Language: C++

#include<bits/stdc++.h>
using namespace std;
int main(){
    int N,K;
    cin>>N>>K;
    int A[1000001];
    A[0]=0;
    for(int i=1;i<=N;i++){
        cin>>A[i];
    }
    int cut=K-1;
    if((N-1)%K==0){
        cout<<(N-1)/cut<<<endl;
    }else{
        cout<<(N-1)/cut+1<<endl;
    }
    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:13:26: error: expected primary-expression before '<' token
   13 |         cout<<(N-1)/cut<<<endl;
      |                          ^
Language: C++

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

int main() {
	// your code goes here
	int n,k,t;
	cin >> n >> k;
	for(int i = 0 ; i < n ; i++)
	{
	    cin >> t;
	}
    int quo = (n-1)/(k-1),rem = (n-1)%(k-1),ans = quo+remp;
    cout << rem;
	return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:12:55: error: 'remp' was not declared in this scope; did you mean 'rem'?
   12 |     int quo = (n-1)/(k-1),rem = (n-1)%(k-1),ans = quo+remp;
      |                                                       ^~~~
      |                                                       rem
Language: C++

#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,k;
	cin>>n>>k;
	int ans=0;
	int a[n+1];
	for(int i=1;i<=n;++i){
	cin>>a[i];
	}
	int ans=(n-1+k-2)/(k-1);
	cout<<ans<<endl;
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:11:13: error: redeclaration of 'int ans'
   11 |         int ans=(n-1+k-2)/(k-1);
      |             ^~~
a.cc:6:13: note: 'int ans' previously declared here
    6 |         int ans=0;
      |             ^~~
Language: Java

import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
                int l = sc.nextInt();
	        int[] A = new int[N];
      for(int i=0: i<N; i++){
A[i] = sc.nextInt();
}

System.out.println((N-1)/(l-1));
	}

}


Compiler output:
Main.java:9: error: ';' expected
      for(int i=0: i<N; i++){
                 ^
Main.java:9: error: > or ',' expected
      for(int i=0: i<N; i++){
                      ^
Main.java:9: error: not a statement
      for(int i=0: i<N; i++){
                    ^
Main.java:9: error: ';' expected
      for(int i=0: i<N; i++){
                           ^
4 errors
Language: C++

#include<iostream>
#include<cstdio>
int main(){
    int N, K;
    scanf("%d%d", &N, &K);
    printf("%d", (N-1)/(K-1))
    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:6:30: error: expected ';' before 'return'
    6 |     printf("%d", (N-1)/(K-1))
      |                              ^
      |                              ;
    7 |     return 0;
      |     ~~~~~~
Language: C++

#include<stdio.h>
int a[1e5+1],n,k;

int main(){
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;++i)scanf("%d",&a[i]);
    int ans=(n-1+k-2)/(k-1);
    printf("%d\n",ans);
}

Compiler output:
a.cc:2:10: error: conversion from 'double' to 'long unsigned int' in a converted constant expression
    2 | int a[1e5+1],n,k;
      |       ~~~^~
a.cc:2:10: error: could not convert '(1.0e+5 + (double)1)' from 'double' to 'long unsigned int'
    2 | int a[1e5+1],n,k;
      |       ~~~^~
      |          |
      |          double
a.cc:2:10: error: size of array 'a' has non-integral type 'double'
Language: C++

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define pb push_back
#define pf push_front
#define rep(i, a, n) for(int i = (a); i < (n); i++)
#define dep(i, a, n) for(int i = (a); i >= (n); i--)
#define mod (ll)(1e9+7)
#define int ll

__attribute__((constructor))
void initial() {
    cin.tie(0);
    ios::sync_with_stdio(false);
}

void solve()
{
    int n, k;
    cin >> n >> k;

    cout << (n / (k - 1) << endl;

}

signed main() {

    solve();

    return 0;
}

Compiler output:
a.cc: In function 'void solve()':
a.cc:26:26: error: invalid operands of types 'll' {aka 'long long int'} and '<unresolved overloaded function type>' to binary 'operator<<'
   26 |     cout << (n / (k - 1) << endl;
      |              ~~~~~~~~~~~~^~~~~~~
a.cc:26:33: error: expected ')' before ';' token
   26 |     cout << (n / (k - 1) << endl;
      |             ~                   ^
      |                                 )
Language: C++

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

int main() {
    int N, K;
    cin >> N >> K;
    int A[N];
    for (int count = 0; count < N; count++) {
        cin >> A[count];
    }
    int one, left, right;
    for (int count = 0; count < N; count++) {
        if (A[count] == 1) {
            one = count;
            left = count;
            right = count;
        }
    }
    int ans_count = 0, count = 0;
    bool left_start = false, first_time_check = true, left_end_check = false, right_end_check = false;
    if ((one * 2) < (N - 1)) {
        left_start = true;
    }
    while ((left != 0) || (right != (N - 1))) {
        if (left_start) {
            while (true) {
                A[left] = 1;
                count++;
                if (left == 0) {
                    if (count == K) {
                        count = 0;
                    }
                    left_start = false;
                    left_end_check = true;
                    break;
                }
                if (count == K) {
                    first_time_check = false;
                    count = 0;
                    break;
                }
                left--;
            }
        } else {
            while (true) {
                A[right] = 1;
                count++;
                if (right == (N - 1)) {
                    if (count == K) {
                        count = 0;
                    }
                    left_start = true;
                    right_end_check = true;
                    break;
                }
                if (count == K) {
                    first_time_check = false;
                    count = 0;
                    break;
                }
                right++;
            }
        }
        if (!same_check) {
            ans_count++;
        }
        if (left_end_check && right_end_check) {
            break;
        }
    }
    
    cout << ans_count << endl;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:64:14: error: 'same_check' was not declared in this scope
   64 |         if (!same_check) {
      |              ^~~~~~~~~~
Language: C++

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

int main() {
  int n,k;
  cin >> n >> k;
  vector<int> V(n);
  for(int& i : V)
    cin >> i;
  if (n == k) {
    cout << 1 << endl;
    return 0;
  }
  pair<int,int> me { 1000000000, -1};
  for(int i = 0; i < V.size(); i++) {
    if (V[i] == 1) {
      me.first = 1;
      me.second = i;
      break;
    }
  }
  int l = me.second, r = me.second;
  int ans = 0;
  while(true) {
    if (r >= n-1)
      break;
    else {
      r += (k-1);
      ++ans;
    }
  }
  while(true) {
    if (l <= 0)
       break;
    else {
      l -= (k-1);
      ++ans;
    }
  }
  cout << ans << endl;
  return 0;



Compiler output:
a.cc: In function 'int main()':
a.cc:44:12: error: expected '}' at end of input
   44 |   return 0;
      |            ^
a.cc:7:12: note: to match this '{'
    7 | int main() {
      |            ^
Language: C

#include<stdio.h>
int main(){
  int n,k,i,m,s;
  
  scanf("%d %d",&n,&k);
  
  int a[n];
  for(i=0;i<n;i++)
    scanf("%d",&a[i]);
  
  for(i=0;i<n;i++){
    if(a[i]==1)
      m=i+1;
  }
    
    s=(m-1)/(k-1) + (n-m)/(k-1);
  
    if( (n-m)%(k-1)!=0 ){
      if( (m-1-((n-m)%(k-1)))!=0 )
      s=s+1;
         }
      
       if( (m-1)%(k-1)!=0 ){
         if( (n-m-(m-1)%(k-1))!=0)
      s=s+1;
  
   
      

    printf("%d",s);
}
  
  
  
  


Compiler output:
main.c: In function 'main':
main.c:31:1: error: expected declaration or statement at end of input
   31 | }
      | ^
Language: C

#include<stdio.h>
int main(){
  int n,k,i,m,s;
  
  scanf("%d %d",&n,&k);
  
  int a[n];
  for(i=0;i<n;i++)
    scanf("%d",&a[i]);
  
  for(i=0;i<n;i++){
    if(a[i]==1)
      m=i;
  }
    
    s=(m-1)/(k-1) + (n-m)/(k-1);
  
    if( (n-m)%(k-1)!=0 ){
      if( (m-1-((n-m)%(k-1))!=0 )
      s=s+1;
         }
      
      
  
   
      
  printf("%d\n",(n-m)%(k-1));
  printf("%d\n",(m-1)%(k-1));
    printf("%d",s);
}
  
  

Compiler output:
main.c: In function 'main':
main.c:19:34: error: expected ')' before 's'
   19 |       if( (m-1-((n-m)%(k-1))!=0 )
      |         ~                        ^
      |                                  )
   20 |       s=s+1;
      |       ~                           
main.c:21:10: error: expected expression before '}' token
   21 |          }
      |          ^
Language: C

#include <stdio.h>
int char_count(const char B[]){
  int len=0;
  while(B[len]){
    len++;
  }return len;
}
int main(void)
{
  int N,K;
  char A[200000];
  int num;
  int i=10;
  int k=1;
  int a;


  scanf("%d",&N);
  scanf("%d",&K);
  scanf("%s",A);

  int cnt = 0;
	while (1)
	{
		if (n <= k) {
			cnt++;
			break;
		}
		else {
			n -= (k-1);
			cnt++;
		}
	}
	printf("%d\n", cnt);
  return 0;
}


Compiler output:
main.c: In function 'main':
main.c:25:21: error: 'n' undeclared (first use in this function)
   25 |                 if (n <= k) {
      |                     ^
main.c:25:21: note: each undeclared identifier is reported only once for each function it appears in
Language: C

#include <stdio.h>

int main(){
	int a,b;
	scanf("%d %d",&a,&b);
	int c[n], i;
	for(i=0;i<n;i++){
		scanf("%d",&c[i]);
	}
	printf("%d\n",(a+b-3)/(b-1));
	return 0;
}


Compiler output:
main.c: In function 'main':
main.c:6:15: error: 'n' undeclared (first use in this function)
    6 |         int c[n], i;
      |               ^
main.c:6:15: note: each undeclared identifier is reported only once for each function it appears in
Language: C++

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
int n, k, pos, a;

int main() {
	cin >> n >> k;
	k--;
	int minT = 1e5 + 7;
	for(int i = 1; i <= n; i++) {
		cin >> a;
		if(a == 1) pos = i;
	}
	int p1, p2;
	int ans = 0;
	for(int i = 0; i <= k; i++) {
		ans = 1;
		p1 = pos + i;
		p2 = pos - (k - i);
		int t1 = (n - p1) / k;
		int t2 = (p2 - 1) / k;
		if((n - p1) % k > 0) t1++;
		if((p2 - 1) % k > 0) t2++;
		if(t1 > 0) ans += t1;
		if(t2 > 0) ans += t2;
		ans = min(minT, ans);
	}
	cout << min(ans, res) << endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:37:26: error: 'res' was not declared in this scope
   37 |         cout << min(ans, res) << endl;
      |                          ^~~
Language: C++

#include<iostream>
int main(){
	int n,k;cin>>n>>k;
    cout<<(n+k-1)/(k-1)-1<<endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:3:17: error: 'cin' was not declared in this scope; did you mean 'std::cin'?
    3 |         int n,k;cin>>n>>k;
      |                 ^~~
      |                 std::cin
In file included from a.cc:1:
/usr/include/c++/14/iostream:62:18: note: 'std::cin' declared here
   62 |   extern istream cin;           ///< Linked to standard input
      |                  ^~~
a.cc:4:5: error: 'cout' was not declared in this scope; did you mean 'std::cout'?
    4 |     cout<<(n+k-1)/(k-1)-1<<endl;
      |     ^~~~
      |     std::cout
/usr/include/c++/14/iostream:63:18: note: 'std::cout' declared here
   63 |   extern ostream cout;          ///< Linked to standard output
      |                  ^~~~
a.cc:4:28: error: 'endl' was not declared in this scope; did you mean 'std::endl'?
    4 |     cout<<(n+k-1)/(k-1)-1<<endl;
      |                            ^~~~
      |                            std::endl
In file included from /usr/include/c++/14/iostream:41:
/usr/include/c++/14/ostream:744:5: note: 'std::endl' declared here
  744 |     endl(basic_ostream<_CharT, _Traits>& __os)
      |     ^~~~
Language: C++

#include <bits/stdc++.h>
using namespace std;
int main(){
    int ans=0;
    int n,k;
    cin >> n>>k;
    if(n==k){
        cout<<1<<endl;
        return;
    }
    vector<int> a(n);
    for(int i =0;i<n;i++){
        cin >> a[i];
    }
    size_t place =distance(a.begin(), min_element(a.begin(),a.end()));
    for(int i = (int)place;i>0;){
        i -= k-1;
        ans++;
    }
    for(int i =(int)place;i<n-1;){
        i +=k-1;
        ans++;
    }
    cout << ans <<endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:9:9: error: return-statement with no value, in function returning 'int' [-fpermissive]
    9 |         return;
      |         ^~~~~~
Language: C++

#include <bits/stdc++.h>
using namespace std;
int main(){
    int ans=0;
    int n,k;
    cin >> n>>k;
    if(n==k){
        cout<<1<<endl;
        break;
    }
    vector<int> a(n);
    for(int i =0;i<n;i++){
        cin >> a[i];
    }
    size_t place =distance(a.begin(), min_element(a.begin(),a.end()));
    for(int i = (int)place;i>0;){
        i -= k-1;
        ans++;
    }
    for(int i =(int)place;i<n-1;){
        i +=k-1;
        ans++;
    }
    cout << ans <<endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:9:9: error: break statement not within loop or switch
    9 |         break;
      |         ^~~~~
Language: C++

count = 0
N,K = map(int,input().split( ))
J = list(map(int,input().split( )))
for i,j in zip(range(N),J):
    if j==1:
        s = i
        t = N-1-i
for _ in range(N+N):
    if s<=0:
        break
    else:
        s -= K-1
        count += 1

for _ in range(N+N):
    if t<=0:
        break
    else:
        t -= K-1
        count += 1
        
if N<=K:
    count = 1
print(count)

Compiler output:
a.cc:1:1: error: 'count' does not name a type
    1 | count = 0
      | ^~~~~
Language: C++

#include<iostream>
#include<algorithm>
#include<math.h>
#include<string>
#include<set>
#include<iostream>
#include<stdlib.h>
using namespace std;
typedef long long ll;

int main7() {
	ll N, K, num = 0, count = 0,part=0;
	cin >> N >> K;
	ll a;
	for (ll i = 0;i < N;i++) {
		cin >> a;
		if (a == 1) {
			num = i + 1;
			if (num > N / 2)num = N - num + 1;
			break;
		}
	}
	if (N == K) {
		cout << 1 << endl;
		return 0;
	}
	part = N - num + 1;
	int part1 = N - part + 1;
	if (num<K) {
		while (part >= K) {
			count++;
			part = part - K + 1;
			
		}
		if (num == 1) {
			if (part >= 2) {
				cout << count + 1 << endl;
				return 0;
			}
			if(part==1) {
				cout << count << endl;
				return 0;
			}
		}
		else {
			if (part >= 2) {
				cout << count + 2 << endl;
				return 0;
			}
			else {
				cout << count+1 << endl;
				return 0;
			}
		}
	}
	else {
		while (part >= K) {
			count++;
			part = part - K + 1;
		}
		while (part1 >= K) {
			count++;
			part1 = part1 - K + 1;
		}
		if (num == 1) {
			if (part >= 2) {
				cout << count + 1 << endl;
				return 0;
			}
			if (part == 1) {
				cout << count << endl;
				return 0;
			}
		}
		else {
			if (part1 >= 2) {
				if (part >= 2) {
					cout << count + 2 << endl;
					return 0;
				}
				else {
					cout << count + 1 << endl;
					return 0;
				}
			}
			else {
				if (part >= 2) {
					cout << count + 1 << endl;
					return 0;
				}
				if (part == 1) {
					cout << count << endl;
					return 0;
				}
			}
		}
	}
	

	return 0;

}

Compiler output:
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/14/../../../x86_64-linux-gnu/Scrt1.o: in function `_start':
(.text+0x17): undefined reference to `main'
collect2: error: ld returned 1 exit status
Language: C++

#include<bits/stdc++.h>
using namespace std;
int main(){
    int N,K;
    cin>>N>>K;
    int A[1000001];
    A[0]=0;
    for(int i=1;i<=N;i++){
        cin>>A[i];
    }
    int place1;
    int cut=K-1;
    for(int i=1;i<=N;i++){
        if(A[i]==1){
            place1=i;
            break;
        }
    }
    int i=place1;
   if(place1!=1){
       ans=ans+(place1-1)/cut;
       i=(place1-1)%cut;
   }
   if(i!=0){
       ans++;
   }
   int k=place1;
   if(place1!=N){
       ans=ans+(N-place1)/cut;
       k=(N-place1)%cut;
   }
   if(k!=0){
       ans++;
   }
   cout<<ans<<endl;
   return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:21:8: error: 'ans' was not declared in this scope; did you mean 'abs'?
   21 |        ans=ans+(place1-1)/cut;
      |        ^~~
      |        abs
a.cc:25:8: error: 'ans' was not declared in this scope; did you mean 'abs'?
   25 |        ans++;
      |        ^~~
      |        abs
a.cc:29:8: error: 'ans' was not declared in this scope; did you mean 'abs'?
   29 |        ans=ans+(N-place1)/cut;
      |        ^~~
      |        abs
a.cc:33:8: error: 'ans' was not declared in this scope; did you mean 'abs'?
   33 |        ans++;
      |        ^~~
      |        abs
a.cc:35:10: error: 'ans' was not declared in this scope; did you mean 'abs'?
   35 |    cout<<ans<<endl;
      |          ^~~
      |          abs
Language: C++

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

using namespace std;

vector<int> A;
vector<int> B;

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

    A.resize(N);
    B.resize(N);

    for (int i = 0; i < N;i++)
    {
        cin >> A[i];
        B[N - i - 1] = A[i];
    }

    int mi = distance(A.begin(), min_element(A.begin(), A.end())) + 1;

    int p = 1;
    int ans = 0;
    for (int i = 0; i < N; i++)
    {
        p = p + (K - 1);
        if(mi <= p)
        {
            ans += i + 1;
            break;
        }
    }

    if (p == N)
    {
        cout << ans << endl;
        return 0;
    }

    int q = p;
    for (int i = 0; i < N; i++)
    {
        q = q + (K - 1);
        if (N <= q)
        {
            ans += i + 1;
            break;
        }
    }

    mi = distance(B.begin(), min_element(B.begin(), B.end())) +
    
    p = 1;
    int ans2 = 0;
    for (int i = 0; i < N; i++)
    {
        p = p + (K - 1);
        if (mi <= p)
        {
            ans2 += i + 1;
            break;
        }
    }

    if (p == N)
    {
        cout << ans << endl;
        return 0;
    }

    q = p;
    for (int i = 0; i < N; i++)
    {
        q = q + (K - 1);
        if (N <= q)
        {
            ans2 += i + 1;
            break;
        }
    }

    cout << min(ans, ans2) << endl;

    return 0;
}
/*
8 3
8 4 3 1 6 5 7 2

8 5
8 4 3 1 6 5 7 2

8 3
8 4 1 3 6 5 7 2

8 3
1 8 4 3 6 5 7 2

*/

Compiler output:
a.cc: In function 'int main()':
a.cc:57:63: error: lvalue required as left operand of assignment
   57 |     mi = distance(B.begin(), min_element(B.begin(), B.end())) +
      |          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
   58 | 
      |                                                                
   59 |     p = 1;
      |     ~
Language: C++

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

int main()
{
    int n,i,k;
    scanf("%d%d",&n,&k);
    int a[n];
    for(i=0; i<n; i++)
    {
        scanf("%d",&a[i]);
    }
    int sum=1;
    if((n-1)%(k-1)>0)a
    {
        sum=(n-1)/(k-1)+1;
    }
    if((n-1)%(k-1)==0)
        sum=(n-1)/(k-1);

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



    return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:14:23: error: expected ';' before '{' token
   14 |     if((n-1)%(k-1)>0)a
      |                       ^
      |                       ;
   15 |     {
      |     ~
Language: Java

import java.util.*;

class Main{
	
	public static void main(String args[]){

		Scanner sc = new Scanner(System.in);
		
		int N = sc.nextInt();
		int M = sc.nextInt();

		int arr[] = new int[N];
		int one = -1;
		for(int n=0;n<N;n++){
			arr[n] = sc.nextInt();
			if(arr[n] == 1) one = n;
			one = Math.min(one,N-one-1);
		}

		
			if(one<M || one > N-M-1){
				System.out.println((int)Math.ceil((float)(N-M)/(M-1))+1);	
			}
			else{
				System.out.println((int)(Math.ceil((one)/(float)(M-1)) + 
					Math.ceil((N-one-1-(one)%(float)(M-1))/(float)(M-1))));
			}
		

	}

Compiler output:
Main.java:30: error: reached end of file while parsing
	}
	 ^
1 error
Language: C++

#include<iostream>
#include<algorithm>
#include<math.h>
#include<string>
#include<set>
#include<iostream>
#include<stdlib.h>
using namespace std;
typedef long long ll;

int main7() {
	ll N, K, num = 0, count = 0,part=0;
	cin >> N >> K;
	int a;
	for (ll i = 0;i < N;i++) {
		cin >> a;
		if (a == 1) {
			num = i + 1;
			if (num > N / 2)num = N - num + 1;
			break;
		}
	}
	if (N == K) {
		cout << 1 << endl;
		return 0;
	}
	part = N - num + 1;
	int part1 = N - part + 1;
	if (num<K) {
		while (part >= K) {
			count++;
			part = part - K + 1;
			
		}
		if (num == 1) {
			if (part >= 2) {
				cout << count + 1 << endl;
				return 0;
			}
			if(part==1) {
				cout << count << endl;
				return 0;
			}
		}
		else {
			if (part >= 2) {
				cout << count + 2 << endl;
				return 0;
			}
			else {
				cout << count+1 << endl;
				return 0;
			}
		}
	}
	else {
		while (part >= K) {
			count++;
			part = part - K + 1;
		}
		while (part1 >= K) {
			count++;
			part1 = part1 - K + 1;
		}
		if (num == 1) {
			if (part >= 2) {
				cout << count + 1 << endl;
				return 0;
			}
			if (part == 1) {
				cout << count << endl;
				return 0;
			}
		}
		else {
			if (part1 >= 2) {
				if (part >= 2) {
					cout << count + 2 << endl;
					return 0;
				}
				else {
					cout << count + 1 << endl;
					return 0;
				}
			}
			else {
				if (part >= 2) {
					cout << count + 1 << endl;
					return 0;
				}
				if (part == 1) {
					cout << count << endl;
					return 0;
				}
			}
		}
	}
	

	return 0;

}

Compiler output:
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/14/../../../x86_64-linux-gnu/Scrt1.o: in function `_start':
(.text+0x17): undefined reference to `main'
collect2: error: ld returned 1 exit status
Language: C

    #include<stdio.h>

    int main(){
        int k,n,i,mark,ans;

        scanf("%d %d",&n,&k);

        int a[n];

        for(i=0; i<n-1; i++){
            scanf("%d ",&a[i]);
            if(a[i] == 1)mark = i;
        }
    if(n%2 == 1){
        if(mark%(k-1) == 0){
            ans = n / (k - 1);
        }else{
            ans = n / (k - 1);
            ans++:;
        }
    }else{
        ans = n / (k - 1);
    }

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

Compiler output:
main.c: In function 'main':
main.c:19:18: error: expected ';' before ':' token
   19 |             ans++:;
      |                  ^
      |                  ;
Language: C

#include <stdio.h>
int char_count(const char B[]){
  int len=0;
  int count=0;
  while(B[len]){

    len++;
    count++;

  }
  int a;
  a=num+len;
  return a;
}
int main(void)
{
  int N,K;
  char A[200000];
  int num;
  int i=10;
  int k=1;


  scanf("%d",&N);
  scanf("%d",&K);
  scanf("%s",A);

  num=char_count(A);
if(K%2==1){
  num=num-K;
  if(num>0){
    while(i>0){
      num=num-K+1;
      k++;
      if(num<0){
        i=-1;
      }
    }
  }
}else{
num=num-K;
if(num>0){
  while(i>0){
    num=num-K;
    k++;
    if(num<0){
      i=-1;
    }
  }
}


}
  printf("%d",k);
  return 0;
}


Compiler output:
main.c: In function 'char_count':
main.c:12:5: error: 'num' undeclared (first use in this function)
   12 |   a=num+len;
      |     ^~~
main.c:12:5: note: each undeclared identifier is reported only once for each function it appears in
Language: C

#include <stdio.h>
int char_count(const char B[]){
  int len=0;int count=0;
  while(B[len]){

    len++;
    count++

  }
  int a;
  a=num+len;
  return a;
}
int main(void)
{
  int N,K;
  char A[200000];
  int num;
  int i=10;
  int k=1;


  scanf("%d",&N);
  scanf("%d",&K);
  scanf("%s",A);

  num=char_count(A);
if(K%2==1){
  num=num-K;
  if(num>0){
    while(i>0){
      num=num-K+1;
      k++;
      if(num<0){
        i=-1;
      }
    }
  }
}else{
num=num-K;
if(num>0){
  while(i>0){
    num=num-K;
    k++;
    if(num<0){
      i=-1;
    }
  }
}


}
  printf("%d",k);
  return 0;
}


Compiler output:
main.c: In function 'char_count':
main.c:7:12: error: expected ';' before '}' token
    7 |     count++
      |            ^
      |            ;
    8 | 
    9 |   }
      |   ~         
main.c:11:5: error: 'num' undeclared (first use in this function)
   11 |   a=num+len;
      |     ^~~
main.c:11:5: note: each undeclared identifier is reported only once for each function it appears in
Language: C++


int main() {

	int n;
	int k;

	int a;

	// 入力数
	scanf( "%d %d", &n, &k );

	scanf( "%d", &a );

	printf( "%d\n", (n-k+1) / (k-1) + 1 );

}


Compiler output:
a.cc: In function 'int main()':
a.cc:10:9: error: 'scanf' was not declared in this scope
   10 |         scanf( "%d %d", &n, &k );
      |         ^~~~~
a.cc:14:9: error: 'printf' was not declared in this scope
   14 |         printf( "%d\n", (n-k+1) / (k-1) + 1 );
      |         ^~~~~~
a.cc:1:1: note: 'printf' is defined in header '<cstdio>'; this is probably fixable by adding '#include <cstdio>'
  +++ |+#include <cstdio>
    1 |
Language: Java

import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int n = sc.nextInt();
		// スペース区切りの整数の入力
		int k = sc.nextInt();
		// 文字列の入力
		List<Integer> list = new ArrayList<>();
		int resultCount =0;

		for(int i=0;i<n;i++){
			list.add(sc.nextInt());
		}
      Optional<Integer> min = list.stream()
                            .min((a, b) -> a.compareTo(b));
        int count = 0;
		for(int j=0;j<n;j++){
			if(min.get()==list.get(j)){
				count++;
			}
		}
		resultCount = ((n-count+1)/(k-1)) ;

      System.out.println(resultCount);


      }
	}
}

Compiler output:
Main.java:31: error: class, interface, enum, or record expected
}
^
1 error
Language: C++

#include <iostream>
#include <algorithm>
#include <math.h>
#include <string>
using namespace std;

int main (){
        long long N,K;
        long long Ans;
        long long tmp;
        long long arr[100000] = {};
        long long min = 0;
        cin >> N >> K;
        
        if( N == K){
            cout <<1<< endl;
        }else if(2*K >N){
            out <<2<< endl;
        }else{
            for (long long i = 1; i <= N; i++) {
                    cin >>arr[i];
                    if(arr[i] ==1){
                        min = i;
                    }
            }
            Ans = (N-min+K-2)/(K-1) + (min-1+K-2)/(K-1);
            cout << Ans<< endl;
        }
}


Compiler output:
a.cc: In function 'int main()':
a.cc:18:13: error: 'out' was not declared in this scope
   18 |             out <<2<< endl;
      |             ^~~
Language: C++

#include <iostream>
using namespace std;
int main(){
int N,K,ans;
cin>>N>>K;

N=N-K;
if(N==0){
  ans=1;
}else if(N%(k-1)==0){
  ans=N/(K-1)+1;
}else{
  ans=(N-(N%(K-1)))/(K-1)+2;
}

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


Compiler output:
a.cc: In function 'int main()':
a.cc:10:13: error: 'k' was not declared in this scope
   10 | }else if(N%(k-1)==0){
      |             ^
Language: C++

#include <iostream>
using namespace std;
int main(){
  int N,K;
  int req = 0;
  cin >> N >> K;
  int A[N];
  for(int i = 0; N > i; i++) cin >> A[i];
  for(int i = 0; N > i; i++) {
    if(A[i] == 1){
      int tmp = i;
      if(tmp % K == 0) {
        req += tmp / K;
      } else {
        req += (tmp / K) + 1;
      }
      if((N - tmp) % K == 0){
        req += (N - tmp) / K;
      } else {
        req += ((N-tmp) / K) + 1;
      }
      if(tmp / K > 1){
        req++
      }
      if((N - tmp) / K > 1){
        req++;
      }
    }
  }
  cout << req << endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:23:14: error: expected ';' before '}' token
   23 |         req++
      |              ^
      |              ;
   24 |       }
      |       ~
Language: C++

#include<bits/stdc++.h>

using namespace std;

int main(){
  int N,K;
  vector<int> A;
  cin >> N >> K;
  for(int i=0;i<N;i++){
    int tmp;
    cin >> tmp;
    A.push_back(tmp);
  }

  // int counter = 0;
  // auto oneItr = find(A.begin(),A.end(),1);
  // int one = (int)(oneItr - A.begin());

  counter = (N-1 + K-2)/(K-1);
  cout << counter << endl;
  return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:19:3: error: 'counter' was not declared in this scope
   19 |   counter = (N-1 + K-2)/(K-1);
      |   ^~~~~~~
Language: C++

#include <iostream>
using namespace std;
int main(){
    int N,K,M,ans=0;
    char a[100005];
    cin >> N >> K;
    for(int i=0;i<N;i++){
        cin >> a[i];
    }
    for(int i=0;i<N;i++){
        if(a[i]=='1'){
            M = i;
            break;
        }
    }
    for(int i=0;i<N;i++){
        if(M<=K*i){
            ans = i;
        }
        if(M<=K*i){
            break;
        }
    }
         for(int i=0;i<N;i++){
         if(N-M<K*i){
             ans = ans+i;
         }
         if(N-M<K*i){
             break;
            }
     }
    cout << ans << endl;
         }
}

Compiler output:
a.cc:34:1: error: expected declaration before '}' token
   34 | }
      | ^
Language: C++

#include<iostream>
#include<bitset>
#include<string>
#include<cmath>
#include<vector>
#include<tuple>
#include <algorithms>
using namespace std;
template <typename T>
void show(vector<T> &vec){
    for (auto value : vec) {
        cout << value << " ";
    }
    cout << endl;
}
int main(){
    int n, k;
    cin >> n >> k;
    vector<int> input;
    int tmp;
    for (int i = 0; i < n; i++){
        cin >> tmp;
        input.push_back(tmp);
    }     
    int start = 0;
    int end = n;
    int minidx = min_element(input.begin(), input.end()) - input.begin();
    int n_op = 0;
    k -= 1;
    // start 
    n_op += minidx / k;
    // if (minidx % k >= 1) n_op += 1;
    cout << n_op;
    // end
    n_op += (end - minidx) / k;
    //  if ((end - minidx) % k >= 1) n_op += 1;
    cout << n_op;
    return 0;
}

Compiler output:
a.cc:7:10: fatal error: algorithms: No such file or directory
    7 | #include <algorithms>
      |          ^~~~~~~~~~~~
compilation terminated.
Language: C++

#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <numeric>
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define REP(i,b) FOR(i,0,b)
#define INF 1e9

typedef unsigned long long ull;

int main()
{
  int n, k, p1, ans;
  cin>>n>>k;

  REP(i,n) {
    cin>>a[i];
    if (a[i] == 1) p1 = i;
  }

  if (n == k) ans = 1;
  else if (k == 2) ans = n - 1;
  else if (p1 == 0 || p1 == n-1)
    ans = (n-1)%(k-1) == 0 ? (n-1)/(k-1) : (n-1)/(k-1) + 1;
  else if (p1 + 1 < k || n - p1  + 1< k)
    ans = (n+1)/(k-1) == 0 ? (n+1)/(k-1) : (n+1)/(k-1) + 1;
  else {
    ans = (p1-1)%(k-1) == 0 ? (p1-1)/(k-1) : (p1-1)/(k-1) + 1;
    ans += (n-p1-1)%(k-1)== 0 ? (n-p1-1)/(k-1) : (n-p1-1)/(k-1) + 1;
  }

  cout<<ans<<endl;

  return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:21:10: error: 'a' was not declared in this scope
   21 |     cin>>a[i];
      |          ^
Language: C++

#include<iostream>
#include<bitset>
#include<string>
#include<cmath>
#include<vector>
#include<tuple>
using namespace std;
template <typename T>
void show(vector<T> &vec){
    for (auto value : vec) {
        cout << value << " ";
    }
    cout << endl;
}
int main(){
    int n, k;
    cin >> n >> k;
    vector<int> input;
    int tmp;
    for (int i = 0; i < n; i++){
        cin >> tmp;
        input.push_back(tmp);
    }     
    int start = 0;
    int end = n;
    int minidx = min_element(input.begin(), input.end()) - input.begin();
    int n_op = 0;
    k -= 1;
    // start 
    n_op += minidx / k;
    // if (minidx % k >= 1) n_op += 1;
    cout << n_op;
    // end
    n_op += (end - minidx) / k;
    //  if ((end - minidx) % k >= 1) n_op += 1;
    cout << n_op;
    return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:26:18: error: 'min_element' was not declared in this scope
   26 |     int minidx = min_element(input.begin(), input.end()) - input.begin();
      |                  ^~~~~~~~~~~