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

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

int main() {
  int n,k;
  cin>>n>>k;
  int x[100005];
  int i_zero=n;
  bool f=true;
  for (int i=0; i<n; i++) {
    cin>>x[i];
    if (x[i]==0) {
      k--;
    }
    if (x[i]>0&&f) {
      f=false;
      i_zero=i;
    }
  }
  if (n==1) ans=abs(x[0]);
  int ans=1e9;
  int l,r;
  if (i_zero>k) {
    l=i_zero-k;
    r=i_zero-1;
    ans=min(ans,-x[l]);
    l++; r++;
  }
  else {
    l=0;
    r=k-1;
  }
  
  while (l<i_zero&&r<n) {
    if (-x[l]<x[r]) {
      ans=min(ans,-x[l]*2+x[r]);
    }
    else {
      ans=min(ans,-x[l]+x[r]*2);
    }
    l++;
    r++;
  }
  if (l==i_zero&&r<n) ans=min(ans,x[r]);
  cout<<ans<<endl;     
  return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:22:13: error: 'ans' was not declared in this scope; did you mean 'abs'?
   22 |   if (n==1) ans=abs(x[0]);
      |             ^~~
      |             abs
Language: C++

>
using namespace std;

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

  long x[N];

  for (int i = 0; i < N; i++) {
    cin >> x[i];
  }

  long t = -1;

  for (int i = 0; i + K - 1 < N; i++) {
    if (t == -1) {
      t = abs(x[i] - x[i + K - 1]) + abs(x[i]);
    } else {
      t = min(t, abs(x[i] - x[i + K - 1]) + abs(x[i]));
    }
    t = min(t, abs(x[i] - x[i + K - 1]) + abs(x[i + K - 1]));
  }

  cout << t << endl;
}

Compiler output:
a.cc:1:1: error: expected unqualified-id before '>' token
    1 | >
      | ^
a.cc: In function 'int main()':
a.cc:6:3: error: 'cin' was not declared in this scope
    6 |   cin >> N >> K;
      |   ^~~
a.cc:18:11: error: 'abs' was not declared in this scope
   18 |       t = abs(x[i] - x[i + K - 1]) + abs(x[i]);
      |           ^~~
a.cc:20:18: error: 'abs' was not declared in this scope
   20 |       t = min(t, abs(x[i] - x[i + K - 1]) + abs(x[i]));
      |                  ^~~
a.cc:20:11: error: 'min' was not declared in this scope; did you mean 'main'?
   20 |       t = min(t, abs(x[i] - x[i + K - 1]) + abs(x[i]));
      |           ^~~
      |           main
a.cc:22:16: error: 'abs' was not declared in this scope
   22 |     t = min(t, abs(x[i] - x[i + K - 1]) + abs(x[i + K - 1]));
      |                ^~~
a.cc:22:9: error: 'min' was not declared in this scope; did you mean 'main'?
   22 |     t = min(t, abs(x[i] - x[i + K - 1]) + abs(x[i + K - 1]));
      |         ^~~
      |         main
a.cc:25:3: error: 'cout' was not declared in this scope
   25 |   cout << t << endl;
      |   ^~~~
a.cc:25:16: error: 'endl' was not declared in this scope
   25 |   cout << t << endl;
      |                ^~~~
Language: C++

#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define MOD 1e9+7
using namespace std;
typedef long long ll;

int main(){
    int N,K;
    cin>>N>>K;
    vector<ll> x(N);
    rep(i,N){cin>>x[i];}


    ll res = 1e+18
    for(int i=0;i<N-K+1;i++){
        ll tmp = min(abs(x[i])+abs(x[i+K-1]-x[i]),abs(x[i+K-1])+abs(x[i+K-1]-x[i]));
        res = min(res,tmp);
    }
    cout<<res;
}

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

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <climits>
#include <string>
#include <vector>

using namespace std;

int main () {
    long long n = 0, k = 0;
    cin >> n >> k;
    vector<long long> candle(n);
    for (int i=0; i<n; i++) {
        cin >> candle.at(i);
    }
    int zero = lower_bound(candle.begin(), candle.end(), 0) - candle.begin();
    if (zero < n && candle.at(zero) < 0) cout << candle.st(zero) << endl;
    long long mini = (n - zero >= k) ? candle.at(zero-1+k) : LLONG_MAX;
    for (int i=0; i<zero; i++) {
        if (zero - i > k) continue;
        if (zero - i == k) mini = min(abs(candle.at(i)), mini);
        if (k + i - 1 > n-1) break;
        mini = min(abs(candle.at(i)) + candle.at(k + i - 1) + min(abs(candle.at(i)), abs(candle.at(k+i-1))), mini);
    }
    cout << mini << endl;
    return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:21:57: error: 'class std::vector<long long int>' has no member named 'st'; did you mean 'at'?
   21 |     if (zero < n && candle.at(zero) < 0) cout << candle.st(zero) << endl;
      |                                                         ^~
      |                                                         at
Language: C++

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
#define REP(var, a, b) for (int var = (a); var < (b); var++)
#define rep(var, n) for (int var = 0; var < (n); ++var)
#define ALL(c) (c).begin(), (c).end()
#define rALL(c) (c).rbegin(), (c).rend()

int main() {
  //
  int n, k;
  cin >> n >> k;
  vl x(n);
  rep(i, n) cin >> x[i];
  ll ans = INT_MAX;
  rep(i, n - k + 1) {
    ll tmp = min(abs(x[i]), abs(x[i + k - 1])) + (x[i + k - 1] - x[i]);
    ans = min(ans, tmp);
  }
  cout << ans << endl;
  return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:33:12: error: 'INT_MAX' was not declared in this scope
   33 |   ll ans = INT_MAX;
      |            ^~~~~~~
a.cc:15:1: note: 'INT_MAX' is defined in header '<climits>'; this is probably fixable by adding '#include <climits>'
   14 | #include <unordered_set>
  +++ |+#include <climits>
   15 | #include <vector>
Language: C++

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

int main(){
    int n,k;
    cin>>n>>k;
    vector<int> v(n);
    for(auto&& e:v) cin>>e;
    int ans=numeric_limits<int>::max();
    for (int i=0,j=i+k-1; j<n; i++,j++) {
        ans=min(ans, v[j]-v[i]+min(int(abs(v[i])), int(abs(v[j]))));
    }
    cout<<ans<<endl;
    return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:10:13: error: 'numeric_limits' was not declared in this scope
   10 |     int ans=numeric_limits<int>::max();
      |             ^~~~~~~~~~~~~~
a.cc:10:28: error: expected primary-expression before 'int'
   10 |     int ans=numeric_limits<int>::max();
      |                            ^~~
Language: C++

#include <iostream>
#include <sstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <stdio.h>

using namespace std;

//typedefリスト
typedef vector<long long int> vint;
typedef vector<string> vstr;
typedef long long int llint;



int main(void) {
	llint N, K, jur; jur = 0;
	llint ans1 = 0, ans2 = 0;
	int zerocou = 0;
	int cou = 0;
	cin >> N >> K;
	vint x(N + 1), pos(N), neg(N);
	for (int i = 0; i < N + 1; i++) {
		cin >> x[i];
		if (i == N)x[i] = 0;
	}
	sort(x.begin(), x.end());
	for (int i = 0; i < N + 1; i++) {
		if (jur == 1) {
			pos[cou] = x[i] - x[i - 1];
			cou++;
		}
		if (x[i] == 0) 	jur = 1;
	}
	for (int i = cou; i < N; i++)pos[i] = 2000000001;

	sort(x.begin(), x.end(), greater<llint>());
	cou = 0;
	jur = 0;
	for (int i = 0; i < N + 1; i++) {
		if (jur == 1) {
			neg[cou] = x[i - 1] - x[i];
			cou++;
		}
		if (x[i] == 0) {
			jur = 1;
			zerocou++;
		}
	}
	for (int i = cou; i < N; i++)neg[i] = 2000000001;
	int poscou = 0, negcou = 0;
	for (int i = 0; i < K; i++) {

		if (pos[poscou] <= 2 * (neg[negcou])) {
			ans1 += pos[poscou];
			poscou++;
		}
		else {
			ans1 += 2 * neg[negcou];
			negcou++;
		}
	}
	poscou = 0, negcou = 0;
	for (int i = 0; i < K - zecou + 1; i++) {

		if (neg[negcou] <= 2 * pos[poscou]) {
			ans2 += neg[negcou];
			negcou++;
		}
		else {
			ans2 += 2 * pos[poscou];
			poscou++;
		}
	}
	cout << min(ans1, ans2) << endl;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:67:33: error: 'zecou' was not declared in this scope; did you mean 'negcou'?
   67 |         for (int i = 0; i < K - zecou + 1; i++) {
      |                                 ^~~~~
      |                                 negcou
Language: C++

#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;
int main(){
  int n, k, i;
  cin >> n >> k;
  int x[n];
  for(i=0; i<n; i++)
    cin >> x[n];
  sort(x, x+n);
  for(i=0; i<n-k; i++){
    if(ans>2*min(abs(x[i]), abs(x[i+k-1]))+max(abs(x[i]), abs(x[i+k-1])))
      ans=2*min(abs(x[i]), abs(x[i+k-1]))+max(abs(x[i]), abs(x[i+k-1]));
  }
  cout << ans;
  return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:13:8: error: 'ans' was not declared in this scope; did you mean 'abs'?
   13 |     if(ans>2*min(abs(x[i]), abs(x[i+k-1]))+max(abs(x[i]), abs(x[i+k-1])))
      |        ^~~
      |        abs
a.cc:16:11: error: 'ans' was not declared in this scope; did you mean 'abs'?
   16 |   cout << ans;
      |           ^~~
      |           abs
Language: C++

#include <iostream>
#include <cmath>
using namespace std;
int main(){
  int n, k, i;
  cin >> n >> k;
  int x[n];
  for(i=0; i<n; i++)
    cin >> x[n];
  sort(x, x+n);
  for(i=0; i<n-k; i++){
    if(ans>2*min(abs(x[i]), abs(x[i+k-1]))+max(abs(x[i]), abs(x[i+k-1])))
      ans=2*min(abs(x[i]), abs(x[i+k-1]))+max(abs(x[i]), abs(x[i+k-1]));
  }
  cout << ans;
  return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:10:3: error: 'sort' was not declared in this scope; did you mean 'sqrt'?
   10 |   sort(x, x+n);
      |   ^~~~
      |   sqrt
a.cc:12:8: error: 'ans' was not declared in this scope; did you mean 'abs'?
   12 |     if(ans>2*min(abs(x[i]), abs(x[i+k-1]))+max(abs(x[i]), abs(x[i+k-1])))
      |        ^~~
      |        abs
a.cc:15:11: error: 'ans' was not declared in this scope; did you mean 'abs'?
   15 |   cout << ans;
      |           ^~~
      |           abs
Language: C++

#include <iostream>
using namespace std;
int main(void){
    int n,k;
    int x[100009];
    // Your code here!
    cin>>n>>k;
    int neg=0,t=0;
    for(int i=0;i<n;i++){
        cin>>t;
        x[i]=t;
        if(t<0)neg++;
    }
    //cout<<n<<' '<<k<<endl;
    //for(int i=0;i<n;i++)cout<<x[i]<<' ';
    //cout<<neg<<endl;
    
    if (neg+k-1<n)ans=min(ans,x[neg+k-1]);
    if (neg-k-1<n and neg>=k)ans=min(ans,-x[neg-k-1]);
    //cout<<ans;
    for(int i=0;i<neg;i++){
        if (i+k-1<n)ans=min(ans,-x[i]*2+x[i+k-1]);
        if (i+k-1<n)ans=min(ans,-x[i]+x[i+k-1]*2);
    }
    cout<<ans;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:18:19: error: 'ans' was not declared in this scope; did you mean 'abs'?
   18 |     if (neg+k-1<n)ans=min(ans,x[neg+k-1]);
      |                   ^~~
      |                   abs
a.cc:19:30: error: 'ans' was not declared in this scope; did you mean 'abs'?
   19 |     if (neg-k-1<n and neg>=k)ans=min(ans,-x[neg-k-1]);
      |                              ^~~
      |                              abs
a.cc:22:21: error: 'ans' was not declared in this scope; did you mean 'abs'?
   22 |         if (i+k-1<n)ans=min(ans,-x[i]*2+x[i+k-1]);
      |                     ^~~
      |                     abs
a.cc:23:21: error: 'ans' was not declared in this scope; did you mean 'abs'?
   23 |         if (i+k-1<n)ans=min(ans,-x[i]+x[i+k-1]*2);
      |                     ^~~
      |                     abs
a.cc:25:11: error: 'ans' was not declared in this scope; did you mean 'abs'?
   25 |     cout<<ans;
      |           ^~~
      |           abs
Language: C++

#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <numeric>
#include <tuple>
#include <stack>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define print(s) cout << s << endl
using namespace std;
const int INF = 1e9;
typedef long long lint;
const lint LINF = 1e18;
const lint MOD = 1e9 + 7;
// const lint MOD = 998244353;
int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}
char upper(char c){
	return c-0x20;
}
char lower(char c){
	return c+0x20;
}

int gcd(int x, int y) {
  if (y == 0) return x;
  return gcd(y, x%y);
}
 
int main(){
	int n,k; cin>>n>>k;
	vector<int> v(n) d(n-k+1);
	rep(i,n) cin >> v[i];
	rep(i,n-k+1){
		d[i] = min(abs(v[i]) + abs(v[n+k-1] - v[i]), abs(v[n+k-1]) + abs(v[n+k-1] - v[i]));
	}
	cout << *min_element(all(d)) << endl;

}


Compiler output:
a.cc: In function 'int main()':
a.cc:40:26: error: expected ',' or ';' before 'd'
   40 |         vector<int> v(n) d(n-k+1);
      |                          ^
a.cc:43:17: error: 'd' was not declared in this scope
   43 |                 d[i] = min(abs(v[i]) + abs(v[n+k-1] - v[i]), abs(v[n+k-1]) + abs(v[n+k-1] - v[i]));
      |                 ^
a.cc:45:34: error: 'd' was not declared in this scope
   45 |         cout << *min_element(all(d)) << endl;
      |                                  ^
a.cc:11:16: note: in definition of macro 'all'
   11 | #define all(x) x.begin(),x.end()
      |                ^
Language: Java

N,K = [int(i) for i in input().split()]
X = [int(i) for i in input().split()]

ans = 10**9
for i in range(N-K+1):
    l = X[i]
    r = X[i+K-1]
    if l < 0 and r <= 0:
        tmp = -l
    elif l >= 0 and r > 0:
        tmp = r
    else:
        tmp = min(abs(l),r)*2 + max(abs(l),r)
    ans = min(ans,tmp)
print(ans)


Compiler output:
Main.java:1: error: class, interface, enum, or record expected
N,K = [int(i) for i in input().split()]
^
1 error
Language: C++

#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <tuple>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <numeric>
#include <string.h>
using namespace std;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<29;
const long long INFL = 1e18;
const int MOD = 1000000007;
const int MAX = 210000;
long n, k;
int gcd(int a, int b) {
    return b != 0 ? gcd(b, a % b) : a;
}

void solve() {
    cin >> n >> k;
    vector<long> x(n, 0);
    for (int i = 0; i < n; i++) {
        cin >> x[i];
    }
    if (n == 1) {
        cout << x[i] << endl;
        return;
    }
    long ans = INFL;
    for (int i = 0; i < (n - k + 1); ++i) {
        ans = min(ans, abs(x[i]) + abs(x[i] - x[i + k - 1]));
    }
    for (int i = (n - 1); i > (n - k); --i) {
        ans = min(ans, abs(x[i]) + abs(x[i] - x[i - k + 1]));
    }
    cout << ans << endl;
    return;
}
//逆元を求める関数
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++) {
      fac[i] = fac[i-1] * i % MOD;
      inv[i] = MOD - inv[MOD%i] * (MOD/i) % MOD;
      finv[i] = finv[i-1] * inv[i] % MOD;
    }
}
//組み合わせ
long long COM (int n, int k) {
    if(n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n-k] % MOD) % MOD;
}
int main(int args, char* argv[]) {
    solve();
    return 0;
}



Compiler output:
a.cc: In function 'void solve()':
a.cc:41:19: error: 'i' was not declared in this scope
   41 |         cout << x[i] << endl;
      |                   ^
Language: C++

#include <iostream>
#include <vector>

using  namespace std;

int main(){
  int N, K;
  cin >> N >> K;
  vector<long long int> C(N); 
  for(int i = 0; i < N; i++) cin >> C[i];
  
  int lbind = -1;
  
  for(int i = 0; i < N; i++){
    if(C[i] >= 0LL){
      lbind = i;
      break;
    }
  }
  
  long long int ans;
  
  if(lbind == -1){
    ans = abs(C[N - K]);
  }else if(lbind == 0){
    ans= abs(C[K - 1]);
  }else{
    long long int ans1 = 100000000LL;
    long long int ans2 = 100000000LL;
    for(int a = 0; a + lbind < N && a < K && lbind - b >= 0 ; a++){
      int b = K - a;
      ans1 = min(abs(C[a + lbind]) * 2 + abs(C[lbind - b]), ans1);
      ans2 = min(abs(C[a + lbind]) + 2 * abs(C[lbind - b]), ans1);
      ans = min(ans1, ans2);
    }  
  }
  cout  << ans;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:30:54: error: 'b' was not declared in this scope
   30 |     for(int a = 0; a + lbind < N && a < K && lbind - b >= 0 ; a++){
      |                                                      ^
Language: C++

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    int n,k; cin >> n >> k;
    vector<ll> x(n);
    for(int i = 0; i < n; i++) cin >> x[i];

    ll ans = 1e9;
    for(int i = 0; i < n-k+1; i++){
        if(ans > x[i+k-1] - x[i] + min(abs(x[i]),abs(x[i+k-1])){
            ans = x[i+k-1] - x[i] + min(abs(x[i]),abs(x[i+k-1]));
        }
    }
    cout << ans << endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:11:64: error: expected ')' before '{' token
   11 |         if(ans > x[i+k-1] - x[i] + min(abs(x[i]),abs(x[i+k-1])){
      |           ~                                                    ^
      |                                                                )
a.cc:14:5: error: expected primary-expression before '}' token
   14 |     }
      |     ^
Language: C++

#include <iostream>
#include <iomanip>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>

// using
using namespace std;

// typedef
typedef long long ll;
typedef unsigned long long ull;

// assert
template <typename T>
void assert_between(T val, T min, T max)
{
    assert(min <= val && val <= max);
}

// math
// 最大公約数(Gratest Common Divisor)を求める.
template <typename T>
T gcd(T a, T b)
{
    assert(a > 0 && b > 0);
    T num1 = max(a, b);
    T num2 = min(a, b);
    T mod = num1 % num2;
    return (mod == 0) ? num2 : gcd(num2, mod);
}

// 最小公倍数(Least Common Multiple)を求める.
template <typename T>
T lcm(T a, T b)
{
    return (a * b) / gcd(a, b);
}

// 奇数の場合: 全ての要素がkで割り切れる必要がある.
int solve_odd(const int n, const int k)
{
    int num = 0;
    for (int i = 1; i <= n; i++)
    {
        if (i % k == 0) num++;
    }
    
    return pow(num, 3);
}

// 偶数の場合: 全ての要素がkで割り切れるか､余りがk/2となる必要がある.
int solve_even(const int n, const int k)
{
    int num = 0;
    for (int i = 1; i <= n; i++)
    {
        if (i % k == k / 2) num++;
    }

    return pow(num, 3) + solve_odd(n, k);
}

int main ()
{
    int n, k;
    scanf("%d %d", &n, &k);
    assert_between<int>(n, 1, pow(10, 5));
    assert_between<int>(k, 1, n);

    vector<int> P = vector<int>(n, 0);
    for (int i = 0; i < n; i++)
    {
        scanf("%d", &P[i]);
        assert(P[i] <= pow(10, 8));
    }

    int dist = INT_MAX;
    for (int i = 0; i + k - 1 < n; i++)
    {
        int p1 = P[i];
        int p2 = P[i + k - 1];

        int d = INT_MAX;
        if (p1 * p2 >= 0) {
            // 折り返す必要がない場合.
            d = max(abs(p1), abs(p2));
        } else {
            // 折り返す場合は､より距離が小さい方で折り返す.
            int min_d = min(abs(p1), abs(p2));
            int max_d = max(abs(p1), abs(p2));
            d = min_d * 2 + max_d;
        }

        // 最小距離を更新する.
        dist = min(dist, d);
    }

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

Compiler output:
a.cc: In function 'int main()':
a.cc:90:16: error: 'INT_MAX' was not declared in this scope
   90 |     int dist = INT_MAX;
      |                ^~~~~~~
a.cc:18:1: note: 'INT_MAX' is defined in header '<climits>'; this is probably fixable by adding '#include <climits>'
   17 | #include <set>
  +++ |+#include <climits>
   18 |
Language: C++

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

int inf = 1000000000;
bool exist_zero = false;
int plus_start = -1;
int real_num, minus_end;
int minus_abs = 0;
int plus_abs = 0;
bool plus_comming = false;
int n, s, x;
int plus_count = 0;
int minus_count = 0;
std::vector<std::pair<int, int>> vec;
std::vector<int> res;

int main() {
    int t;
    std::cin >> n >> s;
    for (int i = 0; i < n; i++) {
        std::cin >> t;
        if (t < 0) {
            minus_count++;
        }
        else if (t == 0) {
            exist_zero = true;
        }
        else if (t > 0) {
            if (!plus_comming) {
                plus_start = i;
                plus_comming = true;
            }
            plus_count++;
        }
        vec.push_back(std::make_pair(std::abs(t), t));
    }
    real_num = s;
    if (exist_zero) {
        real_num--;
    }
    if (real_num == 0) {
        std::cout << "0" << std::endl;
        return 0;
    }
    if (minus_count >= real_num) {
        minus_end = plus_start;
        if (exist_zero) {
            minus_end--;
        }
        if (plus_start == -1 && exist_zero) {
            minus_end = vec.size() - 1;
        }
        else if (plus_start == -1 && !exist_zero) {
            minus_end = vec.size();
        }
        auto minus_end_it = std::next(vec.begin(), minus_end);

        res.push_back(std::max_element(std::prev(minus_end_it, real_num), minus_end_it)->first);
    }
    if (plus_count >= real_num) {
        auto plus_start_it = std::next(vec.begin(), plus_start);
        res.push_back(std::max_element(plus_start_it, std::next(plus_start_it, real_num))->first);
    }

    if (minus_count >= 1 && plus_count >= 1) {
        std::sort(vec.begin(), vec.end());
        int loop_start = 0;
        int loop_end = real_num;
        if (vec[0].first == 0) {
            loop_start = 1;
            loop_end++;
        }
        for (int i = loop_start; i < loop_end; i++) {
            if (vec[i].second < 0) {
                if (vec[i].first > minus_abs) {
                    minus_abs = vec[i].first;
                }
            }
            else if (vec[i].second > 0) {
                if (vec[i].first > plus_abs) {
                    plus_abs = vec[i].first;
                }
            }
        }
        plus_abs + minus_abs + std::min(plus_abs, minus_abs);
        res.push_back(c);
    }
    std::cout << *std::min_element(res.begin(), res.end()) << std::endl;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:89:23: error: 'c' was not declared in this scope
   89 |         res.push_back(c);
      |                       ^
Language: C++

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

int main(){
  int n,k;
  cin>>n>>k;
  int x[n];
  for(int i=0;i<n;i++)cin>>x[i];
  
  int l=max(x[0],-x[i]);
  intr=max(x[i+k-1],-x[i+k-1]);
  if(x[i]*x[i+k-1]<=0)int m=min(m,min(l,r)*2+max(l,r));
  else int m=min(m,max(l,r));
  
  for(int i=0;i<n-k+1;i++){
    l=max(x[i],-x[i]);
    r=max(x[i+k-1],-x[i+k-1]);
    if(x[i]*x[i+k-1]<=0)m=min(m,min(l,r)*2+max(l,r));
    else m=min(m,max(l,r));
  }
  cout<<m<<endl;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:10:21: error: 'i' was not declared in this scope
   10 |   int l=max(x[0],-x[i]);
      |                     ^
a.cc:11:3: error: 'intr' was not declared in this scope; did you mean 'int'?
   11 |   intr=max(x[i+k-1],-x[i+k-1]);
      |   ^~~~
      |   int
a.cc:12:41: error: 'r' was not declared in this scope
   12 |   if(x[i]*x[i+k-1]<=0)int m=min(m,min(l,r)*2+max(l,r));
      |                                         ^
a.cc:13:26: error: 'r' was not declared in this scope
   13 |   else int m=min(m,max(l,r));
      |                          ^
a.cc:17:5: error: 'r' was not declared in this scope
   17 |     r=max(x[i+k-1],-x[i+k-1]);
      |     ^
a.cc:18:25: error: 'm' was not declared in this scope
   18 |     if(x[i]*x[i+k-1]<=0)m=min(m,min(l,r)*2+max(l,r));
      |                         ^
a.cc:19:10: error: 'm' was not declared in this scope
   19 |     else m=min(m,max(l,r));
      |          ^
a.cc:21:9: error: 'm' was not declared in this scope
   21 |   cout<<m<<endl;
      |         ^
Language: C++

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

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

    long long x[N];
    for(int i = 0; i < N; i++){
        cin >> x[i];
    }

    long long minTime = 100000000000;
    bool flag = false;
    if(N == K){
        flag = true;
        long long time = min(2 * abs(x[i]) + abs(x[i+K-1]),abs(x[i]) + 2 * abs(x[i+K-1]) );
        if(time < minTime) minTime = time; 
    }
    for(int i = 0; i < N - K; i++){
        if(x[i+K-1] <= 0){
            flag = true;
            long long time = abs(x[i]);
            if(time < minTime) minTime = time; 
        }
        if(x[i] >= 0){
            flag = true;
            long long time = abs(x[i+K-1]);
            if(time < minTime) minTime = time; 
        }
        if(x[i] < 0 && x[i+K-1] > 0){
            flag = true;
            long long time = min(2 * abs(x[i]) + abs(x[i+K-1]),abs(x[i]) + 2 * abs(x[i+K-1]) );
            if(time < minTime) minTime = time; 
        }
    }

    if(flag) cout << minTime << endl;
    else cout << 0 << endl;
}



Compiler output:
a.cc: In function 'int main()':
a.cc:22:40: error: 'i' was not declared in this scope
   22 |         long long time = min(2 * abs(x[i]) + abs(x[i+K-1]),abs(x[i]) + 2 * abs(x[i+K-1]) );
      |                                        ^
Language: C++

#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
int main() {
  long long n,k,x[100000],ans=1000000000;
  cin >> n >> k;
  for(int i=0, i<n; i++) {
    cin >> x[i];
  }
  for(int i=0; i<n-k-1; i++) {
    ans=min(ans,abs(x[i+k-1]-x[i])+min(abs(x[i]),abs(x[i+k-1])));
  }
  cout << ans << endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:8:17: error: expected ';' before '<' token
    8 |   for(int i=0, i<n; i++) {
      |                 ^
      |                 ;
a.cc:8:17: error: expected primary-expression before '<' token
Language: C++

#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())
#define ll long long
#define pb(a) push_back(a)
#define INF 1000000000
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

typedef vector<unsigned int>vec;
typedef vector<vec> mat;
//typedef tuple<ll, ll, ll> T;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,k;
    cin>>n>>k;
    vector<ll> x(n);
    REP(i,n) cin>>x[i];
    ll ans=1e18;
    for(int i=0;i<n-k+1;i++){
        ll tmp1,tmp2;
        tmp1 = abs(x[i])+abs(x[i]-x[i+k-1]);
        tmp2 = abs(x[i+k-1])+abs(x[i]-x[i+k-1]);
        ans = min({ans,tmp1,tmp2});
    }˜
    cout<<ans<<endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:39:6: error: '\U000002dc' was not declared in this scope
   39 |     }˜
      |      ^
Language: C++

#include <bits/stdc++.h>

using namespace std;
typedef long long LL;
LL a[100005];
int main()
{
    LL n,k,sx,ex,sum=1e8+1000;
    cin >> n>>k;
    for(LL i = 0;i < n;i++)
        cin >> a[i];
    for(LL i = 0;i <= n-k;i++)
    {
        sx = a[i];
        ex = a[i+k-1];
        if(i*j>=0)
        {
            sum = min(sum,max(abs(sx),abs(ex)));
        }
        else
            sum = min(sum,ex-sx+min(abs(sx),abs(ex)));
    }
    cout << sum <<endl;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:16:14: error: 'j' was not declared in this scope
   16 |         if(i*j>=0)
      |              ^
Language: C++

#include <iostream>

using namespace std;

typedef long long ll;

const int Maxn = 100010;
ll x[Maxn];

int main() {
    int n, k;
    cin >> n >> k;
    for (int i = 0; i < n; ++i) {
        cin >> x[i];
    }

    ll ans = numeric_limits<ll>::max();
    for (int i = 0; i <= n - k; ++i) {
        ll len = x[i + k - 1] - x[i];
        len += min(abs(x[i + k - 1]), abs(x[i]));
        ans = min(ans, len);
    }

    cout << ans << endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:17:14: error: 'numeric_limits' was not declared in this scope
   17 |     ll ans = numeric_limits<ll>::max();
      |              ^~~~~~~~~~~~~~
a.cc:17:31: error: expected primary-expression before '>' token
   17 |     ll ans = numeric_limits<ll>::max();
      |                               ^
a.cc:17:37: error: no matching function for call to 'max()'
   17 |     ll ans = numeric_limits<ll>::max();
      |                                ~~~~~^~
In file included from /usr/include/c++/14/string:51,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_algobase.h: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:   candidate expects 2 arguments, 0 provided
/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, 0 provided
Language: C++

#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>
#include <map>
#include <cstdlib>
#define INF (1000000007)
#define rep(i,N) for(ll i=0;i<N;i++)
typedef long long int ll;
using namespace std;
using vl=vector<ll>;

int main(){
    ll N,K,l,r,t;
    ll ans=INF;
    cin>>N>>K;
    vl vec(N);
    rep(i,N){
        cin>>vec[i];
    }
    
    rep(i,N-K+1){
        r=vec[N-i-1];
        l=vec[N-K-i];
        if(r>=0){
            if(l>=0){
                t=r;
            }
            else{
                t=-l*2+r;
            }
        }
        else{
            t=-l;
            }
        }
        
        ans=min(ans,t);
    }
    
    cout<<ans<<endl;

    return 0;
}


Compiler output:
a.cc:42:5: error: 'cout' does not name a type
   42 |     cout<<ans<<endl;
      |     ^~~~
a.cc:44:5: error: expected unqualified-id before 'return'
   44 |     return 0;
      |     ^~~~~~
a.cc:45:1: error: expected declaration before '}' token
   45 | }
      | ^
Language: C++

#include<bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define int long long
#define vec(a,n) vector<int> (a)((n))
#define Vec(a,n) vector<string> (a)((n))
#define twovec(a,n,m) vector<vector<int>> a(n,vector<int>(m,0))
#define Twovec(a,n,m) vector<vector<double>> a(n,vector<double>(m,0))
#define P pair<int,int>
#define All(a) (a).begin(),(a).end()
#define Sort(a) sort(All(a))
#define Reverse(a) reverse(All(a))
#define PQ(n) priority_queue<P,vector<P>,greater<P>> (n)
#define pq(n) priority_queue<int> (n)
#define Lower(a,t) lower_bound(All(a),t)
using namespace std;
void Debug(auto a);
int Switch(int a,int b){
    if(a<0){
        if(b<0){
            return -1*a;
        }
        int x = -1*a*2+b;
        int y = -1*a+b*2;
        return min(x,y);
    }
    else{
        return b;
    }
}


signed main(){
    int n,k;
    cin >> n >> k;
    vec(a,n);
    REP(i,n){
        cin >> a[i];
    }
    int min = 1000000000;
    REP(i,n-k+1){
        int t = Switch(a[i],a[i+k-1]);
        min = min(min,t);
    }
    cout << min << endl;


    return 0;
}



void Debug(auto a){
    cout << "{ ";
    for(auto b: a){
        cout << b << " ";
    }
    cout << "}" << endl;
}


Compiler output:
a.cc:17:12: warning: use of 'auto' in parameter declaration only available with '-std=c++20' or '-fconcepts'
   17 | void Debug(auto a);
      |            ^~~~
a.cc: In function 'int main()':
a.cc:43:18: error: 'min' cannot be used as a function
   43 |         min = min(min,t);
      |               ~~~^~~~~~~
a.cc: At global scope:
a.cc:53:12: warning: use of 'auto' in parameter declaration only available with '-std=c++20' or '-fconcepts'
   53 | void Debug(auto a){
      |            ^~~~
Language: C++

#include<cstdio>
#include<algorithm>
int main(){
    int N,K;scanf("%d%d",&N,&K);
    int x[N];
    int j;
    int ans=1<<29;
    for(int i=0;i<N;i++){
        scanf("%d",&x[i]);
    }
    for(int i=0;i+K-1<N;i++){
        ans=std::min(ans,x[i+k-1]-x[i]+std::min(abs(x[i+k-1]),abs(x[i])));
    }
    printf("%d",ans);
    return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:12:30: error: 'k' was not declared in this scope
   12 |         ans=std::min(ans,x[i+k-1]-x[i]+std::min(abs(x[i+k-1]),abs(x[i])));
      |                              ^
Language: C++

#include<cstdio>
#include<algorithm>
int main(){
    int N,K;scanf("%d%d",&N,&K);
    int x[N];
    int j;
    int ans=1<<29;
    for(int i=0;i<N;i++){
        scanf("%d",&x[i]);
    }
    for(int i=0;i+k-1<N;i++){
        ans=std::min(ans,x[i+k-1]-x[i]+std::min(abs(x[i+k-1]),abs(x[i])));
    }
    printf("%d",ans);
    return 0;
}


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

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

int x[int(1e6)];

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, K, x0 = -1;
    long cu_time, ans = long(1e11);
    cin >> N >> K;
    if(K == 0){
        cout << "0\n";
        return 0;
    }
    for(int n=0; n<N; n++){
        cin >> x[n];
        if(x[n] >= 0 && x0 == -1)x0 = n;
    }
    //cout << x0 << "\n";
    if(x0 >= 0){
        if(K + x0 - 1 < N)ans = min(ans, x[K+x0-1]);
        if(x0 >= K)ans = min(ans, long(abs(x[x0-K])));
        for(int n=max(0,x0-K+1); n<=x0-1; n++){
            cu_time = 2 * min(abs(x[n]), x[K+n-1]) + max(abs(x[n]), x[K+n-1]);
            //cout << n << " " << cu_time << "\n";
            ans = min(ans, cu_time);
        }
    }
    else ans = abs(x[N-K]);
    cout << ans << "\n";
    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:22:36: error: no matching function for call to 'min(long int&, int&)'
   22 |         if(K + x0 - 1 < N)ans = min(ans, x[K+x0-1]);
      |                                 ~~~^~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_algobase.h:233:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  233 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note:   template argument deduction/substitution failed:
a.cc:22:36: note:   deduced conflicting types for parameter 'const _Tp' ('long int' and 'int')
   22 |         if(K + x0 - 1 < N)ans = min(ans, x[K+x0-1]);
      |                                 ~~~^~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  281 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note:   candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61:
/usr/include/c++/14/bits/stl_algo.h:5686:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(initializer_list<_Tp>)'
 5686 |     min(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5686:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5696:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(initializer_list<_Tp>, _Compare)'
 5696 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5696:5: note:   template argument deduction/substitution failed:
a.cc:22:36: note:   mismatched types 'std::initializer_list<_Tp>' and 'long int'
   22 |         if(K + x0 - 1 < N)ans = min(ans, x[K+x0-1]);
      |                                 ~~~^~~~~~~~~~~~~~~~
Language: C++

#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <cstdio>
#include <stack>
#include <functional>
#include <set>
#include <map>
#include <cmath>

using namespace std;
typedef long long ll;

#define ASIZE(arr) (sizeof(arr)/sizeof(arr[0])

//int dp[1000][1000];
//int n, W, w[1000], v[1000];
//void solve() {
//	for (int i = n - 1; i >= 0; i--)
//	{
//		for (int j = 0; j <= W; j++)
//		{
//			if (j < w[i]) {
//				dp[i][j] = dp[i + 1][j];
//			}
//			else {
//				dp[i][j] = max(dp[i + 1][j], dp[i + 1][j - w[i]] + v[i]);
//			}
//		}
//	}
//}

vector<ll> p = { 1 }, b = { 1 };

ll solve(ll n, ll x) {
	if (n == 0)return x <= 0 ? 0 : 1;
	else if (x <= 1 + b[n - 1]) return solve(n - 1, x - 1);
	else return p[n - 1] + 1 + solve(n - 1, x - 2 - b[n - 1]);
}

int main() {
	ll n, k;
	cin >> n >> k;
	vector<ll> x(n);

	for (ll i = 0; i < n; i++)
	{
		cin >> x[i];
	}

	ll ans = LLONG_MAX;

	for (ll i = 0; i <= n - k; i++)
	{
		ll temp = abs(x[i]) + x[i + k - 1] - x[i];
		ans = min(ans, temp);
	}

	cout << ans << endl;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:53:18: error: 'LLONG_MAX' was not declared in this scope
   53 |         ll ans = LLONG_MAX;
      |                  ^~~~~~~~~
a.cc:12:1: note: 'LLONG_MAX' is defined in header '<climits>'; this is probably fixable by adding '#include <climits>'
   11 | #include <cmath>
  +++ |+#include <climits>
   12 |
Language: C++

#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <cstdio>
#include <stack>
#include <functional>
#include <set>
#include <map>
#include <cstdlib>

using namespace std;
typedef long long ll;

#define ASIZE(arr) (sizeof(arr)/sizeof(arr[0])

//int dp[1000][1000];
//int n, W, w[1000], v[1000];
//void solve() {
//	for (int i = n - 1; i >= 0; i--)
//	{
//		for (int j = 0; j <= W; j++)
//		{
//			if (j < w[i]) {
//				dp[i][j] = dp[i + 1][j];
//			}
//			else {
//				dp[i][j] = max(dp[i + 1][j], dp[i + 1][j - w[i]] + v[i]);
//			}
//		}
//	}
//}

vector<ll> p = { 1 }, b = { 1 };

ll solve(ll n, ll x) {
	if (n == 0)return x <= 0 ? 0 : 1;
	else if (x <= 1 + b[n - 1]) return solve(n - 1, x - 1);
	else return p[n - 1] + 1 + solve(n - 1, x - 2 - b[n - 1]);
}

int main() {
	ll n, k;
	cin >> n >> k;
	vector<ll> x(n);

	for (ll i = 0; i < n; i++)
	{
		cin >> x[i];
	}

	ll ans = LLONG_MAX;

	for (ll i = 0; i <= n - k; i++)
	{
		ll temp = abs(x[i]) + x[i + k - 1] - x[i];
		ans = min(ans, temp);
	}

	cout << ans << endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:53:18: error: 'LLONG_MAX' was not declared in this scope
   53 |         ll ans = LLONG_MAX;
      |                  ^~~~~~~~~
a.cc:12:1: note: 'LLONG_MAX' is defined in header '<climits>'; this is probably fixable by adding '#include <climits>'
   11 | #include <cstdlib>
  +++ |+#include <climits>
   12 |
Language: C++

#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <cstdio>
#include <stack>
#include <functional>
#include <set>
#include <map>
 
using namespace std;
typedef long long ll;
 
int main() {
	ll n, k;
	cin >> n >> k;
	vector<ll> x(n);
 
	for (ll i = 0; i < n; i++)
	{
		cin >> x[i];
	}
 
	ll ans = LLONG_MAX;
 
	for (ll i = 0; i <= n - k; i++)
	{
		ll temp = abs(x[i]) + x[i + k - 1] - x[i];
		ans = min(ans, temp);
	}
 
	cout << ans << endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:25:18: error: 'LLONG_MAX' was not declared in this scope
   25 |         ll ans = LLONG_MAX;
      |                  ^~~~~~~~~
a.cc:11:1: note: 'LLONG_MAX' is defined in header '<climits>'; this is probably fixable by adding '#include <climits>'
   10 | #include <map>
  +++ |+#include <climits>
   11 |
Language: C++

MAX = 300000001

N, K = map(int, input().split())
xn = [int(i) for i in input().split()]


def main():
    ans = MAX

    for i in range(N - K + 1):
        ans = min(ans,
                  2 * abs(xn[i]) + abs(xn[i + K - 1]),
                  abs(xn[i]) + 2 * abs(xn[i + K - 1]))

    print(ans)
    return


main()


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

#include<bits/stdc++.h>
using namespace std;
#define dist(l,r) (abs(x[l]-x[r])+max(abs(x[r]),abs(x[l])))
int main(){
  int n,k,res;
  cin>>n>>k;
  vector<int> x(n);
  for(int i=0;i<n;++i)cin>>x[i];
  r=k-1;
  res=dist(0,k-1);
  for(int l=1;l+k-1<n;++l)res=max(res,dist(l,l+k-1));
  cout<<res;
  return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:9:3: error: 'r' was not declared in this scope
    9 |   r=k-1;
      |   ^
Language: Java

import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
    	Scanner input = new Scanner(System.in);
      	int N = input.nextInt();
      	int K = input.nextInt();
      	int[] X = new int[N];
      	int smallGap = 1000000000;
      
      	for (int i = 0; i < N; i++) {
        	X[i] = input.nextInt();
        }

      	for (int i = 0; i < N - K + 1; i++) {
        	int min = X[i];
          	int max = X[i + K - 1];
          	int gap;
          	if (min < 0) {
            	gap = max - (min * 2);
            } if else (max < 0) {
            	gap = - min;
            } else {
              	gap = max;
            }
          	if (gap < smallGap) {
              	smallGap = gap;
            }
        }
      
      System.out.print(smallGap);

    }
}

Compiler output:
Main.java:21: error: '(' expected
            } if else (max < 0) {
                ^
Main.java:21: error: illegal start of expression
            } if else (max < 0) {
                 ^
Main.java:21: error: not a statement
            } if else (max < 0) {
                      ^
Main.java:21: error: ';' expected
            } if else (max < 0) {
                               ^
Main.java:23: error: 'else' without 'if'
            } else {
              ^
5 errors
Language: C

n, k = map(int, input().split())
x = list(map(int, input().split()))
mintime = 10**20
for i in range(n-k+1):
    left = x[i]
    right = x[i+k-1]
    abss = (abs(left), abs(right))
    if left * right >= 0:
        mintime = min(mintime, max(abss))
    else:
        mintime = min(mintime, min(abss) * 2 + max(abss))
print(mintime)


Compiler output:
main.c:1:1: warning: data definition has no type or storage class
    1 | n, k = map(int, input().split())
      | ^
main.c:1:1: error: type defaults to 'int' in declaration of 'n' [-Wimplicit-int]
main.c:1:4: error: type defaults to 'int' in declaration of 'k' [-Wimplicit-int]
    1 | n, k = map(int, input().split())
      |    ^
main.c:1:8: error: implicit declaration of function 'map' [-Wimplicit-function-declaration]
    1 | n, k = map(int, input().split())
      |        ^~~
main.c:1:12: error: expected expression before 'int'
    1 | n, k = map(int, input().split())
      |            ^~~
main.c:2:1: error: expected ',' or ';' before 'x'
    2 | x = list(map(int, input().split()))
      | ^
Language: C++

#include <iostream>
#include <vector>
#include <algorithm>
#define rep(i,n) for(int i=0;i<n;i++)
#define vi vector<int>
#define pb push_back
#define bi_s binary_search
#define lb lower_bound
#define ub upper_bound
using namespace std;

int n;
int k;
int x[100005];
long ans=200000005;

int main(){
	cin >>n >>k;
  	rep(i,n){
    	cin >>x[i];
   	}

  	rep(i,n-k+1){
    ans=min(ans,min(abs(x[i]-0)+x[i+k-1]-x[i],abs(x[i+k-1]-0)+x[i+k-1]-x[i]));
    }
  
  	cout <<ans <<endl;
  	return 0;

}

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