criyle/codenet-compile-errors huggingface dataset:
Language: Java

import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class Main {
	public static void main(String[]args) {
		try(Scanner scan = new Scanner(System.in)){
			
			int N = scan.nextInt();
			int K = scan.nextInt();
			
			int[]x = new int[N];
			
			ArrayList<Integer>pra = new ArrayList<Integer>();//+
			ArrayList<Integer>mai = new ArrayList<Integer>();//-
			
			for(int i = 0;i<N;i++) {
				x[i] = scan.nextInt();
				if(x[i]>=0)pra.add(x[i]);
				else mai.add(x[i]);
			}
			
			Collections.sort(mai, Collections.reverseOrder());
			
			
			
			
			
			if(pra.size()==0) {
				System.out.println(Math.abs(mai.get(K-1)));
				System.exit(0);
			}else if(mai.size()==0) {
				System.out.println(pra.get(K-1));
				System.exit(0);
			}
			
			
			int p = 0;
			int m = 0;
			
			while(true) {
				
				//int M = Math.abs(mai.get(m));
				
				if(pra.size()-1==p) {
					m++;
				}else if(mai.size()-1==m) {
					p++;
				}else if(mai.size()-1==m||pra.size()-1==p) {
					break;
				}else {
					if(pra.get(p+1)<=Math.abs(mai.get(m+1))) 
						p++;
					else 
						m++;
				}
				/*
				if(pra.get(p)<=M) {
					if(pra.size()-1==p) m++;
					else p++;
				}else {
					if(mai.size()-1==m)p++;
					else m++;
				}*/
				
				if(p+m+2==K)break;
			}
			
			System.out.println(p);
			System.out.println(pra.get(p));
			System.out.println(m);
			System.out.println(mai.get(m));
			
			
			if(Math.abs(mai.get(m))<=pra.get(p)) {
				System.out.println(2*(long)Math.abs(mai.get(m))+(long)pra.get(p));
			}else {
				System.out.println((long)Math.abs(mai.get(m))+2*(long)pra.get(p));
			}


Compiler output:
Main.java:79: error: reached end of file while parsing
			}
			 ^
1 error
Language: Java

mport java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class Main {
	public static void main(String[]args) {
		try(Scanner scan = new Scanner(System.in)){
			
			int N = scan.nextInt();
			int K = scan.nextInt();
			
			int[]x = new int[N];
			
			ArrayList<Integer>pra = new ArrayList<Integer>();//+
			ArrayList<Integer>mai = new ArrayList<Integer>();//-
			
			for(int i = 0;i<N;i++) {
				x[i] = scan.nextInt();
				if(x[i]>=0)pra.add(x[i]);
				else mai.add(x[i]);
			}
			
			Collections.sort(mai, Collections.reverseOrder());
			
			
			
			
			
			if(pra.size()==0) {
				System.out.println(Math.abs(mai.get(K-1)));
				System.exit(0);
			}else if(mai.size()==0) {
				System.out.println(pra.get(K-1));
				System.exit(0);
			}
			
			
			int p = 0;
			int m = 0;
			
			while(true) {
				
				//int M = Math.abs(mai.get(m));
				
				if(pra.size()-1==p) {
					m++;
				}else if(mai.size()-1==m) {
					p++;
				}else if(mai.size()-1==m||pra.size()-1==p) {
					break;
				}else {
					if(pra.get(p+1)<=Math.abs(mai.get(m+1))) 
						p++;
					else 
						m++;
				}
				/*
				if(pra.get(p)<=M) {
					if(pra.size()-1==p) m++;
					else p++;
				}else {
					if(mai.size()-1==m)p++;
					else m++;
				}*/
				
				if(p+m+2==K)break;
			}
			
			System.out.println(p);
			System.out.println(pra.get(p));
			System.out.println(m);
			System.out.println(mai.get(m));
			
			
			if(Math.abs(mai.get(m))<=pra.get(p)) {
				System.out.println(2*(long)Math.abs(mai.get(m))+(long)pra.get(p));
			}else {
				System.out.println((long)Math.abs(mai.get(m))+2*(long)pra.get(p));
			}


Compiler output:
Main.java:1: error: class, interface, enum, or record expected
mport java.util.ArrayList;
^
Main.java:2: error: class, interface, enum, or record expected
import java.util.Collections;
^
Main.java:3: error: class, interface, enum, or record expected
import java.util.Scanner;
^
Main.java:79: error: reached end of file while parsing
			}
			 ^
4 errors
Language: C++

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

int main(){
    long long N,K;
    cin >> N,K;
    vector<long long>x(N);
    for(int i = 0; i < N; i++) {
        cin >> x[i];
    }
    long long ans = 100000000000000;
    for(int i = 0; i < N; i++) {
        long long hidari = i;
        long long migi = i+K-1;
        long long hajime = min(abs(0-hidari),abs(0-migi))
        ans = min(ans,migi-hidari+hajime);
    }
    cout << ans << endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:16:9: error: expected ',' or ';' before 'ans'
   16 |         ans = min(ans,migi-hidari+hajime);
      |         ^~~
Language: C++

#include<bits/stdc++.h>
using namespace std;
int main(){
int N,K;
  cin>>N>>K;
  vector<int>A={};
  for(int i=0;i<K;i++)
    A.push_back(-1000000000);
  for(int i=0;i<N;i++){
  int x;
    cin>>x;
    A.push_back(x);
  
  }for(int i=0;i<K;i++)
    A.push_back(1000000000);
  auto itr=lower_bound(A.begin(),A.end,0);
  int k=distance(A.begin(),itr);
  int ans;
  if(*itr!=0){
    ans=min(abs(A.at(k-K)),A.at(k+K-1));
    for(int i=0;i<=K-2;i++){
      int a=A.at(k+i); int b=abs(A.at(k-K+1+i));
      int Min=a+b+min(a,b);
      if(Min<ans)
        ans=Min;
    }cout<<ans<<endl;
}else{
ans=abs(A.at(k-K+1));
    for(int i=0;i<K;i++){
    int a=abs(A.at(k-K+i+1));
      int b=A.at(k+i);
      int Min=a+b+min(a,b);
      if(Min<ans)
        ans=Min;
    } cout<<ans<<endl;

}
   return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:16:23: error: no matching function for call to 'lower_bound(std::vector<int>::iterator, <unresolved overloaded function type>, int)'
   16 |   auto itr=lower_bound(A.begin(),A.end,0);
      |            ~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~
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:1530:5: note: candidate: '_ForwardIterator std::lower_bound(_ForwardIterator, _ForwardIterator, const _Tp&) [with _ForwardIterator = __gnu_cxx::__normal_iterator<int*, vector<int> >; _Tp = int]'
 1530 |     lower_bound(_ForwardIterator __first, _ForwardIterator __last,
      |     ^~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:1530:60: note:   no known conversion for argument 2 from '<unresolved overloaded function type>' to '__gnu_cxx::__normal_iterator<int*, std::vector<int> >'
 1530 |     lower_bound(_ForwardIterator __first, _ForwardIterator __last,
      |                                           ~~~~~~~~~~~~~~~~~^~~~~~
In file included from /usr/include/c++/14/algorithm:61:
/usr/include/c++/14/bits/stl_algo.h:1963:5: note: candidate: 'template<class _FIter, class _Tp, class _Compare> _FIter std::lower_bound(_FIter, _FIter, const _Tp&, _Compare)'
 1963 |     lower_bound(_ForwardIterator __first, _ForwardIterator __last,
      |     ^~~~~~~~~~~
/usr/include/c++/14/bits/stl_algo.h:1963:5: note:   candidate expects 4 arguments, 3 provided
Language: C++

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

int main(){
    int N,K;cin>>N>>K;
    vector<int> x(N);
    int j;
    int ans=1<<29;
    for(int i=0;i<N;i++){
            cin>>x[i];
            if(i==k){
                    ans=x[i]-x[0]+min(abs(x[i]),abs(x[0]));
            }else if(i>k){
                    ans=min(ans,x[i]-x[i-k]+min(abs(x[i]),abs(x[i-k])));
            }
    }
    cout<<ans<<endl;
    return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:11:19: error: 'k' was not declared in this scope
   11 |             if(i==k){
      |                   ^
Language: C++

//   _/                _/                 _/_/_/   _/
//_/_/_/_/   _/_/   _/_/_/_/   _/_/    _/       _/_/
// _/     _/    _/   _/     _/    _/  _/_/_/     _/
//_/     _/    _/   _/     _/    _/  _/    _/   _/
// _/_/   _/_/       _/_/   _/_/      _/_/     _/
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;
using ll=long long;
const int MOD=1e9+7;
const double pi=3.14159265358979323846;
const int inf=1e9;
const ll INF=5e18;
using P=pair<int,int>;
int main() {
  cin.tie(0),cout.tie(0);
  ios::sync_with_stdio(false);
  int n,k,x[100005]={},ans=inf;
  cin >> n >> k;
  for(int i=0; i<n; i++) {
    cin >> x[i];
  }
  for(int i=0; i<n-k+1; i++) {
    if(a[i+k-1]<=0) {
      ans=min(ans,abs(a[i]));
    }
    else if(a[i]>=0) {
      ans=min(ans,a[i+k-1]);
    }
    else {
      ans=min({ans,abs(a[i])*2+a[i+k-1],abs(a[i])+a[i+k-1]*2});
    }
  }
  cout << ans << endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:30:8: error: 'a' was not declared in this scope
   30 |     if(a[i+k-1]<=0) {
      |        ^
a.cc:37:14: error: no matching function for call to 'min(<brace-enclosed initializer list>)'
   37 |       ans=min({ans,abs(a[i])*2+a[i+k-1],abs(a[i])+a[i+k-1]*2});
      |           ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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:6:
/usr/include/c++/14/bits/stl_algobase.h:233:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  233 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note:   candidate expects 2 arguments, 1 provided
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  281 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note:   candidate expects 3 arguments, 1 provided
In file included from /usr/include/c++/14/algorithm:61,
                 from a.cc:7:
/usr/include/c++/14/bits/stl_algo.h:5686:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(initializer_list<_Tp>)'
 5686 |     min(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5686:5: note:   template argument deduction/substitution failed:
/usr/include/c++/14/bits/stl_algo.h:5696:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(initializer_list<_Tp>, _Compare)'
 5696 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5696:5: note:   candidate expects 2 arguments, 1 provided
Language: C++

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main()
{
    ll n, k;
    cin >> n >> k;
    vector<ll> x(n);
    sort(x.begin(), x.end());
    ll ans = 1145141919810364;
    for (int i = 0; i <= n - k; i++)
    {
        if (x[i] < 0 && x[i + k] > 0)
            ans = min(ans, abs(x[i + k] - 2 * x[i])) else ans = min(ans, max(abs(x[i]), abs(x[i + k])));
    }
    cout << ans << endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:14:53: error: expected ';' before 'else'
   14 |             ans = min(ans, abs(x[i + k] - 2 * x[i])) else ans = min(ans, max(abs(x[i]), abs(x[i + k])));
      |                                                     ^~~~~
      |                                                     ;
Language: C

#include <iostream>
#include <queue>
#include <vector>
#include <utility>
using namespace std;
int main(){
    int N, K;
    cin >> N >> K;
    vector<long long> a(N);
    for(int i = 0; i < N; i++) cin >> a[i];
    priority_queue<pair<long long, int>, vector<pair<long long, int>>, greater<pair<long long, int>>> q;
    for(int i = 0; i < N; i++){
        if(a[i] < 0) q.push(make_pair(-1*a[i], -1));
        else q.push(make_pair(a[i], 1));
    }
    long long ans = 0;
    long long res = 0;
    int prep = 0, prem = 0;
    for(int i = 0; i < K; i++){
        pair<long long, int> p = q.top();
        if(p.second == -1){
            res += p.first - prem;
            prem = p.first;
        }
        else{
            ans += p.first - prep;
            prep = p.first;
        }
        q.pop();
    }
    ans += res + min(prep, prem);
    cout << ans << endl;
}

Compiler output:
main.c:1:10: fatal error: iostream: No such file or directory
    1 | #include <iostream>
      |          ^~~~~~~~~~
compilation terminated.
Language: C++

#include<bits/stdc++.h>

#define rep(i, n) for(int i = 0; i < (n); ++i)

using namespace std;
using ll = long long;

signed main() {
  int n, k; cin >> n >> k;
  vector<int> v(n); rep(i, n) cin >> v[i];

  ll ans = 1e9;
  rep(i, n-k+1) {
    ans = min(ans, v[i+k-1] - v[i] + min(abs(v[i]), abs(v[i+k-1])));
  }
  cout << ans << endl;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:14:14: error: no matching function for call to 'min(ll&, __gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type)'
   14 |     ans = min(ans, v[i+k-1] - v[i] + min(abs(v[i]), abs(v[i+k-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:14:14: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'})
   14 |     ans = min(ans, v[i+k-1] - v[i] + min(abs(v[i]), abs(v[i+k-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:14:14: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   14 |     ans = min(ans, v[i+k-1] - v[i] + min(abs(v[i]), abs(v[i+k-1])));
      |           ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Language: C++

#include<bits/stdc++.h>

#define rep(i, n) for(int i = 0; i < (n); ++i)
#define int long long

using namespace std;

using ll = long long;

int main() {
  int n, k; cin >> n >> k;
  vector<int> v(n); rep(i, n) cin >> v[i];

  ll ans = 1e9;
  rep(i, n-k+1) {
    int gap = abs(v[i] - v[i+k-1]);
    ll a = abs(v[i]) + gap;
    ll b = abs(v[i+k-1]) + gap;
    ans = min(ans, min(a, b));
  }
  cout << (n-k ? ans : abs(v[0]-v[k-1])) << endl;
}


Compiler output:
cc1plus: error: '::main' must return 'int'
Language: C++

#include<bits/stdc++.h>

#define rep(i, n) for(int i = 0; i < (n); ++i)
#defint int long long

using namespace std;

using ll = long long;

int main() {
  int n, k; cin >> n >> k;
  vector<int> v(n); rep(i, n) cin >> v[i];

  ll ans = 1e9;
  rep(i, n-k+1) {
    int gap = abs(v[i] - v[i+k-1]);
    ll a = abs(v[i]) + gap;
    ll b = abs(v[i+k-1]) + gap;
    ans = min(ans, min(a, b));
  }
  cout << (n-k ? ans : abs(v[0]-v[k-1])) << endl;
}


Compiler output:
a.cc:4:2: error: invalid preprocessing directive #defint; did you mean #define?
    4 | #defint int long long
      |  ^~~~~~
      |  define
Language: C++

#include<bits/stdc++.h>
using namespace std;
using ll=long long;
const int INF = 100000000;

int main(){
    ll n,k;cin>>n>>k;//n:candle総本数 k:灯したいcandle数
    vector<ll> x(n+1);
    for(i=0;i<n;i++){cin>>x[i];}
    x[n]=0;
    sort(x.begin(),x.end());
    
    ll num;
    for(num=0;x[num]!=0;num++);//0の場所
    
    ll mini=100000000000000,ans=100000000000000;
    for(i=0;i<=num;i++){
        if(i+k>n){break;}//はみでてる
        if(num-i>k){continue;}//0を含むような幅kの区間を探索
        mini=min(-2*x[i]+x[i+k],2*x[i+k]-x[i]);
        ans=min(ans,mini);
    }

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

Compiler output:
a.cc: In function 'int main()':
a.cc:9:9: error: 'i' was not declared in this scope
    9 |     for(i=0;i<n;i++){cin>>x[i];}
      |         ^
a.cc:17:9: error: 'i' was not declared in this scope
   17 |     for(i=0;i<=num;i++){
      |         ^
Language: C++

#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int main () {
   int N, K;
    cin >> N >> K;
    vector<int> X(N);
    vector<int> costs;
 
    rep(i, N)
    {
        cin >> X[i];
    }
 
    rep(i, N - K + 1)
    {
        int left = X[i];
        int right = X[i + K - 1];
 
        if (left <= 0 && right <= 0)
        {
            costs.push_back(-1 * left);
        }
        else if (left <= 0 && right >= 0)
        {
            costs.push_back(-1 * left + right + min(-1 * left, right));
        }
        else
        {
            costs.push_back(right);
        }
    }
 
    sort(costs.begin(), costs.end());
    cout << costs.front() << endl;
}

}

 


Compiler output:
a.cc: In function 'int main()':
a.cc:16:9: error: 'i' was not declared in this scope
   16 |     rep(i, N)
      |         ^
a.cc:16:5: error: 'rep' was not declared in this scope
   16 |     rep(i, N)
      |     ^~~
a.cc: At global scope:
a.cc:44:1: error: expected declaration before '}' token
   44 | }
      | ^
Language: C++

#include <iostream>
#include <vector>
#define rep(i,n) for(int (i)=0;(i)<(n);++(i))

using namespace std;
using ll = long long;


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

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

Compiler output:
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: In instantiation of 'constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare) [with _Tp = long long int; _Compare = long long int]':
a.cc:17:27:   required from here
   17 |         ans = min(ans, min(abs(left), abs(right), left - right));
      |                        ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:284:17: error: '__comp' cannot be used as a function
  284 |       if (__comp(__b, __a))
      |           ~~~~~~^~~~~~~~~~
Language: C++

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using p = pair<int, int>;
using P = pair<ll, ll>;
using V = vector<int>;
using VV = vector<vector<int>>;
using VVV = vector<vector<vector<int>>>;
using VL = vector<ll>;
using VVL = vector<vector<ll>>;
using VVVL = vector<vector<vector<ll>>>;
using Graph = VV;
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()
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; }
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
int Inf = (1 << 30);
ll inf = (1LL << 60);
const int MOD = 1e9 + 7;
int main() { // 左から右だけじゃなくて右から左も考える!
	int n, k;
	cin >> n >> k;
	VL a(n);
	int i;
	for (i = 0; i < n; i++) {
		cin >> a[i];
	}
	ll ans = inf;
	rep(i, n - k + 1) {
		chmin(ans, abs(a[i]) + abs(a[i + k - 1] - a[i]));
		chmin(ans, abs(a[i + k - 1] + abs(a[i] - a[i + k - 1]));
	}
	cout << ans << endl;
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:33:72: error: expected ')' before ';' token
   33 |                 chmin(ans, abs(a[i + k - 1] + abs(a[i] - a[i + k - 1]));
      |                      ~                                                 ^
      |                                                                        )
Language: C++

#include <bits/stdc++.h>
using namespace std;
int main(){
int N, K; cin >> N >> K;
vector<int> x(N);
for(int i = 0; i < N; i++){cin >> x[i];}
int ans = 1e9;
for(int i = 0; i <= N - K; i++){
int min1, max_K, min_K;
max_K = x[i + K - 1];
min_K = x[i];
if(min_K >= 0) min1 = max_K;
else if(max_K <= 0) min1 = -min_K;
else min1 = min(abs(min_K)*2+max_K , max_K*2+abs(min_K)) ;
ans = min(ans, min1);
} c
out << ans << endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:16:3: error: 'c' was not declared in this scope
   16 | } c
      |   ^
Language: C++

#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using Graph=vector<vector<int>>;

int main(){
  int N,K;
  cin>>N>>K;
  vector<int> plus,minus;
  for(int i=0;i<N;i++){
    int x;
    cin>>x;
    if(x<0){
      minus.push_back(-x);
    }else{
      plus.push_back(x);
    }
  }
  int n=plus.size();
  reverse(minus.begin(),minus.end());
  int m=minus.size();
  int ans=1000000000;
  if(K<=n){
    ans=min(ans,plus.at(K-1));
  }
  if(K<=m){
    ans=min(ans,minus.at(K-1));
  }
  for(int i=1;i=<min(n,K);i++){
    if(K-i>m){
      continue;
    }
    ans=min(ans,2*plus.at(i-1)+minus.at(K-i-1));
    ans=min(ans,plus.at(i-1)+2*minus.at(K-i-1));
  }
  cout<<ans<<endl;
}


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

#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll a[100005],sum1,sum2,b[100005];
ll ans=1e9;
int n,k,pos,m,x;
int main(){
sum1=1e9;sum2=1e9; 
   cin>>n>>k;
   for(int i=1;i<=n;i++)cin>>a[i];
   for(int i=1;i<=n;i++)
    {if(a[i]>=0){pos=i;break;}}
   for(int i=pos-1;i>=1;i--)b[++m]=-1*a[i];
     if(n-m>=k) sum1=a[pos+k-1];if(sum1<ans)ans=sum1;
     if(m>=k) sum2=b[k]; if(sum2<ans)ans=sum2;
    for(int j=1;j<k;j++)
    {
 
  if(n-m>=j&&m>=k-j) sum1=(a[pos+j-1])*2+b[k-j],if(sum1<ans)ans=sum1;
  
  if(m>=j&&n-m>=k-j) sum2=b[j]*2+a[pos+k-j-1], 
  if(sum2<ans)ans=sum2;
    	//cout<<sum1<<" "<<sum2<<" "<<ans<<endl;
    }
    cout<<ans;
	return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:19:49: error: expected primary-expression before 'if'
   19 |   if(n-m>=j&&m>=k-j) sum1=(a[pos+j-1])*2+b[k-j],if(sum1<ans)ans=sum1;
      |                                                 ^~
a.cc:22:3: error: expected primary-expression before 'if'
   22 |   if(sum2<ans)ans=sum2;
      |   ^~
Language: C++

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
  int N, K;
  cin >> N >> K;
  vector <int> x(N);
  for (int i = 0; i < N; i+) cin >> x[i];
  
  int ans = 200000002;
  for (int i = K-1; i < N; i++) {
    ans = min(ans, x[i]-x[i-K+1]);
  }
  cout << ans << endl;
  return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:10:28: error: expected primary-expression before ')' token
   10 |   for (int i = 0; i < N; i+) cin >> x[i];
      |                            ^
Language: C++

#include <iostream>
#inclue <vector>
#include <algorithm>
using namespace std;
int main()
{
  int N, K;
  cin >> N >> K;
  vector <int> x(N);
  for (int i = 0; i < N; i+) cin >> x[i];
  
  int ans = 200000002;
  for (int i = K-1; i < N; i++) {
    ans = min(ans, x[i]-x[i-K+1]);
  }
  cout << ans << endl;
  return 0;
}


Compiler output:
a.cc:2:2: error: invalid preprocessing directive #inclue; did you mean #include?
    2 | #inclue <vector>
      |  ^~~~~~
      |  include
a.cc: In function 'int main()':
a.cc:9:3: error: 'vector' was not declared in this scope
    9 |   vector <int> x(N);
      |   ^~~~~~
a.cc:4:1: note: 'std::vector' is defined in header '<vector>'; this is probably fixable by adding '#include <vector>'
    3 | #include <algorithm>
  +++ |+#include <vector>
    4 | using namespace std;
a.cc:9:11: error: expected primary-expression before 'int'
    9 |   vector <int> x(N);
      |           ^~~
a.cc:10:28: error: expected primary-expression before ')' token
   10 |   for (int i = 0; i < N; i+) cin >> x[i];
      |                            ^
a.cc:10:37: error: 'x' was not declared in this scope
   10 |   for (int i = 0; i < N; i+) cin >> x[i];
      |                                     ^
a.cc:14:20: error: 'x' was not declared in this scope
   14 |     ans = min(ans, x[i]-x[i-K+1]);
      |                    ^
Language: C++

#include<bits/stdc++.h>
 
using namespace std;
 
int main(){
  int N, K;
  cin >> N >> K;
  vector<long> V(N);
  for(int i = 0; i < N; i++){
    cin >> V.at(i);
  }
  
  // 連続するK本の組み合わせ N-K+1パターンで全探索する
  long min_time = 100000000;
 
  for(int i = 0; i < N-K+1; i++){
    long time = 0;
    int left = i;
    int right = i+K-1;
    
    time += V.at(right) - V.at(left);
 
    // 左端から始めるか、or右端から始めるか
    time = time + min(abs(V.at(left)), abs(V.at(right)));
    cerr << "time " <<  time << " min_time: " << min_time << endl;
    cerr << (min_time < time) << endl;
    
    if(time < min_time){
      min_time = time;
    }
  }
  
  cout << min_time << endl;
}
#include<bits/stdc++.h>

using namespace std;

int main(){
  int N, K;
  cin >> N >> K;
  vector<long> V(N);
  for(int i = 0; i < N; i++){
    cin >> V.at(i);
  }
  
  // 連続するK本の組み合わせ N-K+1パターンで全探索する
  long min_time = 100000000000;

  for(int i = 0; i < N-K+1; i++){
    long time = 0;
    int left = i;
    int right = i+K-1;
    
    time += V.at(right) - V.at(left);
 
    // 左端から始めるか、or右端から始めるか
    time = time + min(abs(V.at(left)), abs(V.at(right)));
    
    if(time < min_time){
      min_time = time;
    }
  }
  
  cout << min_time << endl;
}
提出情報

Compiler output:
a.cc:39:5: error: redefinition of 'int main()'
   39 | int main(){
      |     ^~~~
a.cc:5:5: note: 'int main()' previously defined here
    5 | int main(){
      |     ^~~~
a.cc:67:1: error: '\U000063d0\U000051fa\U000060c5\U00005831' does not name a type
   67 | 提出情報
      | ^~~~~~~~
Language: C++

n,k = map(int, input().split())
x = list(map(int, input().split()))

  
s = 10**9
for i in range(n-k+1) :
  f = x[i:i+k] 
  m = min(abs(f[0]) +abs(f[-1] - f[0]) , abs(f[-1]) + abs(f[-1] - f[0]))
  if s >m :
    s = m
print(s)

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

#include <iostream>
#include <queue>

#define INF 1000000000

using namespace std;

int main(){
    int N, K;
    cin >> N >> K;
    long x[N];
    for(int i=0; i<N; i++){
        cin >> x[i];
    }
    int l_lim = lower_bound(x, x + N, 0) - x;
    int u_lim = upper_bound(x, x + N, 0) - x;
    long ans = INF;
    long temp = INF;
    for(int i=0; i<=l_lim; i++){
        if(i + K -1 < N && x[max(u_lim-1, 0)] <= x[i+K-1]){
            if(x[i] * x[i+K-1] < 0) temp = min(abs(x[i]) + x[i+K-1] * 2, abs(x[i]) * 2 + x[i+K-1]);
            else temp = max(abs(x[i]), x[i+K-1]);
        }
        ans = min(ans, temp);
    }
    cout << ans << endl;
    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:16:17: error: 'upper_bound' was not declared in this scope
   16 |     int u_lim = upper_bound(x, x + N, 0) - x;
      |                 ^~~~~~~~~~~
Language: C++

#include <iostream>
#include <queue>

#define INF 1000000000

using namespace std;

int main(){
    int N, K;
    cin >> N >> K;
    long x[N];
    for(int i=0; i<N; i++){
        cin >> x[i];
    }
    int l_lim = lower_bound(x, x + N, 0) - x;
    int u_lim = upper_bound(x, x + N, 0) - x;
    long ans = INF;
    long temp;
    for(int i=0; i<=l_lim; i++){
        if(i + K -1 < N && x[max(u_lim-1, 0)] <= x[i+K-1]){
            if(x[i] * x[i+K-1] < 0) temp = min(abs(x[i]) + x[i+K-1] * 2, abs(x[i]) * 2 + x[i+K-1]);
            else temp = max(abs(x[i]), x[i+K-1]);
        }
        ans = min(ans, temp);
    }
    cout << ans << endl;
    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:16:17: error: 'upper_bound' was not declared in this scope
   16 |     int u_lim = upper_bound(x, x + N, 0) - x;
      |                 ^~~~~~~~~~~
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();

        int[] array = new int[n];

        for (int i = 0; i < n; i++) {
            array[i] = sc.nextInt();
        }

        int ans = Integer.MAX_VALUE;

        for (int i = 0; i < n - k; i++) {
            int min = array[i];
            int max = array[i + k];
            if (min > 0) {
                min = 0;
            }

            if (max < 0) {
                max = 0;
            }

            maxAbs = Math.abs(max);
            minAbs = Math.abs(min);

            if (maxAbs > minAbs) {
                maxAbs = maxAbs * 2;
            } else {
                minAbs = minAbs * 2;
            }

            if (ans > maxAbs + minAbs) {
                ans = maxAbs + minAbs;
            }

        }

        System.out.println(ans);

    }
}

Compiler output:
Main.java:29: error: cannot find symbol
            maxAbs = Math.abs(max);
            ^
  symbol:   variable maxAbs
  location: class Main
Main.java:30: error: cannot find symbol
            minAbs = Math.abs(min);
            ^
  symbol:   variable minAbs
  location: class Main
Main.java:32: error: cannot find symbol
            if (maxAbs > minAbs) {
                ^
  symbol:   variable maxAbs
  location: class Main
Main.java:32: error: cannot find symbol
            if (maxAbs > minAbs) {
                         ^
  symbol:   variable minAbs
  location: class Main
Main.java:33: error: cannot find symbol
                maxAbs = maxAbs * 2;
                ^
  symbol:   variable maxAbs
  location: class Main
Main.java:33: error: cannot find symbol
                maxAbs = maxAbs * 2;
                         ^
  symbol:   variable maxAbs
  location: class Main
Main.java:35: error: cannot find symbol
                minAbs = minAbs * 2;
                ^
  symbol:   variable minAbs
  location: class Main
Main.java:35: error: cannot find symbol
                minAbs = minAbs * 2;
                         ^
  symbol:   variable minAbs
  location: class Main
Main.java:38: error: cannot find symbol
            if (ans > maxAbs + minAbs) {
                      ^
  symbol:   variable maxAbs
  location: class Main
Main.java:38: error: cannot find symbol
            if (ans > maxAbs + minAbs) {
                               ^
  symbol:   variable minAbs
  location: class Main
Main.java:39: error: cannot find symbol
                ans = maxAbs + minAbs;
                      ^
  symbol:   variable maxAbs
  location: class Main
Main.java:39: error: cannot find symbol
                ans = maxAbs + minAbs;
                               ^
  symbol:   variable minAbs
  location: class Main
12 errors
Language: C++

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>

using namespace std;

#define ll long long
const int N = 3*1e6;

ll n,a[N],k,sum1[N],sum2[N];

int main(){
	cin >> n >> k;
	ll now=1,check = 0;
	for(int i = 1; i <= n; i++){
		cin >> a[i];
		if(a[i] >= 0 && check == 0) now = i,check = 1;
	} 
	for(int i = now; i <= n; i++) sum2[i-now+1] = abs(a[i]);
	for(int i = now-1; i > 0; i--) sum1[now-i] = abs(a[i]);
	ll ans = 2e18;
	int t1 = max(0ll,now-k);
	int t2 = t1 + k;
	while(t1 < now && t2 <= (n-now+1)){
		ans = min(ans,min(sum1[t1]*2+sum2[t2],sum1[t1],sum2[t2]*2));
	}
	cout << ans;
} 

Compiler output:
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: In instantiation of 'constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare) [with _Tp = long long int; _Compare = long long int]':
a.cc:26:20:   required from here
   26 |                 ans = min(ans,min(sum1[t1]*2+sum2[t2],sum1[t1],sum2[t2]*2));
      |                               ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:284:17: error: '__comp' cannot be used as a function
  284 |       if (__comp(__b, __a))
      |           ~~~~~~^~~~~~~~~~
Language: C

#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#include <time.h>
typedef long long llint;
typedef long double ldouble;
// 小大
int compare(const void *a, const void *b){return *(llint *)a - *(llint *)b;}
typedef struct{
    llint aa;
    llint bb;
}frequent;
// 小大
int cmp( const void *p, const void *q ) {
    return ((frequent*)p)->bb - ((frequent*)q)->bb;
}
/*2つのうち小さい数を返す*/
llint min2(llint a,llint b){return a>=b?b:a;}


int main(void){
    llint n,i,k,m=0,t=300000001;
    scanf("%lld%lld",&n,&k);
    llint x[n];
    for(i=0;i<n;i++){
        scanf("%lld",&x[i]);
        if(x[i]<0) m++;
    }
    if(m==0){
        printf("%lld\n",x[k-1]);
        return 0;
    }
    if(m==n){
        printf("%lld\n",-x[n-k]);
        return 0;
    }
    llint minus[m],plus[n-m];
    for(i=0;i<m;i++){
        minus[i]=-x[m-1-i];
        // printf("%lld ",minus[i]);
    }
    for(i=0;i<n-m;i++){
        plus[i]=x[m+i];
        // printf("%lld ",plus[i]);
    }
    if(n==k){
        t=
    }
    for(i=0;i<=k/2+1;i++){
        if(i==0){
            if(k<=m){
                t=min2(minus[k-1],t);
            }
            if(k<=n-m){
                t=min2(plus[k-1],t);
            }
            // printf("%lld ",t);
            continue;
        }
        if(k-i<=m && n-m>=i){
            // printf("%lld ",t);
            t=min2(t,minus[k-1-i]+2*plus[i-1]);
            // printf("! ");
        }
        if(k-i<=n-m && m>=i){
            t=min2(t,plus[k-1-i]+2*minus[i-1]);
            // printf("? ");
        }
        // printf("%lld ",t);
    }


    printf("%lld\n",t);
    return 0;
}


Compiler output:
main.c: In function 'main':
main.c:49:5: error: expected expression before '}' token
   49 |     }
      |     ^
Language: C++

#include <bits/stdc++.h>

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int INF = 1e9;

int main() {
  int n, k, ans = INF;
  cin >> n >> k;
  vector<int> x(n);
  rep(i, n) cin >> x[i];

  if (k == 1) {
    int a = INF;
    rep(i, n) a = min(a, abs(x[i]));
    cout << a << endl;
    return 0;
  }

  for (int i = 0; i < n - k; ++i) {
    if (x[i] * x[i + k - 1] < 0) {
      int mn = min(abs(x[i]), abs(x[i + k - 1]));
      int mx = max(abs(x[i]), abs(x[i + k - 1]));
      ans = min(ans, mn * 2 + mx);
    } else {
      if (x[i + k - 1] <= 0)
        ans = abs(a[i]);
      else if (0 <= x[i])
        ans = abs(x[i + k - 1]);
      //      ans = min(ans, max(abs(x[i]), abs(x[i + k - 1])));
    }
  }

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


Compiler output:
a.cc: In function 'int main()':
a.cc:28:19: error: 'a' was not declared in this scope
   28 |         ans = abs(a[i]);
      |                   ^
Language: C

#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#include <limits.h>
#include <math.h>
int acs(const void *a, const void *b){return *(int*)a - *(int*)b;} /* 1,2,3,4.. */
int des(const void *a, const void *b){return *(int*)b - *(int*)a;} /* 8,7,6,5.. */
int cmp_char(const void *a, const void *b){return *(char*)a - *(char*)b;} /* a,b,c,d.. */
int cmp_str(const void *a, const void *b){return strcmp(*(const char **)a, *(const char **)b);} /* aaa,aab.. */
#define min(a,b) (a < b ? a: b)
#define max(a,b) (a > b ? a: b)
#define rep(i, l, r) for (int i = l; i < r; i++)
#define MAX 1000005
#define MOD 1000000007

typedef long long int lli;


// 優先度付きキュー Priority Queue

typedef struct
{
  long long int pri;
  long long int val;
} que;

que pq[MAX];
int pq_size = 0; // 最大要素

void PQadd(long long int pri, long long int val)
{
  int last = ++pq_size;
  que new;
  new.pri = pri;
  new.val = val;
  pq[pq_size] = new;

  while (last > 1 && pq[last].pri < pq[last / 2].pri)
  {
    que temp;
    temp = pq[last];
    pq[last] = pq[last / 2];
    pq[last / 2] = temp;
    last /= 2;
  }
  return;
}

que PQget(void)
{
  que root = pq[1];
  pq[1] = pq[pq_size--];

  int last = 1, bigger_child;
  while (last * 2 <= pq_size)
  {
    if (last * 2 == pq_size)
      bigger_child = last * 2;
    else
      bigger_child = pq[last * 2].pri < pq[last * 2 + 1].pri ? last * 2 : last * 2 + 1;

    if (pq[last].pri > pq[bigger_child].pri)
    {
      que temp;
      temp = pq[last];
      pq[last] = pq[bigger_child];
      pq[bigger_child] = temp;
      last = bigger_child;
    }
    else
      break;
  }
  return root;
}


int main(void) {
  int N, K;
  scanf("%d %d", &N, &K);
  int x[MAX];
  rep(i, 0, N) {
    scanf("%d", &x[i]);
  }

  int ans, left, right;
  // 左に進む場合(右が戻る)
  rep(i, 0, N) { // 左
    if (x[xi] > 0) break;
    PQadd(abs(x[xi]), 0);
  }
  rep(i, 0, N) { // 右
    if (x[xi] <= 0) continue; 
    PQadd(abs(x[xi]) * 2, 1);
  }

  left = 0; right = 0;
  rep(ki, 0, K) {
    que min = PQget();
    if ( min.val == 0 ) {
      left = min.pri;
    } else {
      right = min.pri;
    }
  }
  ans = left + right;

  pq_size = 0;
  // 右に進む場合(左が戻る)
  rep(i, 0, N) { // 左
    if (x[xi] > 0) break;
    PQadd(abs(x[xi]) * 2, 0);
  }
  rep(i, 0, N) { // 右
    if (x[xi] <= 0) continue; 
    PQadd(abs(x[xi]), 1);
  }
  // printf("before:%d\n", pq_size);

  left = 0; right = 0;
  rep(ki, 0, K) {
    que min = PQget();
    if ( min.val == 0 ) {
      left = min.pri;
    } else {
      right = min.pri;
    }
  }
  // printf("after:%d\n", pq_size);
  ans = min(ans, left + right);

  // rep(i, 0, size) printf("%d ", x[i]);
  // printf("\n");
  // printf("o = %d\n", o);
  printf("%d\n", ans);
  return 0;
}


Compiler output:
main.c: In function 'main':
main.c:90:11: error: 'xi' undeclared (first use in this function); did you mean 'i'?
   90 |     if (x[xi] > 0) break;
      |           ^~
      |           i
main.c:90:11: note: each undeclared identifier is reported only once for each function it appears in
Language: C++


#include <iostream>
#include <iomanip> //! for setprecision(10)
#include <math.h>
#include <algorithm>
#include <functional> 
#include <string>
#include <vector>

#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <utility>

using namespace std;

typedef long long LL;

#define dump(c) { for (auto it = c.begin(); it != c.end(); ++it) if (it == c.begin()) cout << *it; else cout << ' ' << *it; cout << endl; } 
#define rep(i,n) for (int i = 0; i < (n); ++i)

const int MOD = 1000000007;

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

    int N, K;
    cin >> N >> K;

    vector<int> x;
    x.reserve(N);
    int negCount = 0;
    rep(i, N) {
        int xin;
        cin >> xin;
        if (xin < 0) {
            ++negCount;
        }
        if (xin) {
            x.push_back(xin); 
        } else {
            --K; //! remove candle on 0
        }
    }
    N = x.size();
    if (K == 0) {
        cout << 0 << endl;
        return 0;
    }
    int posCount = N - negCount;

    int ans = 1000000000;

    //! Move negative side first
    for (int i = 1; i <= negCount; ++i) {
        int tmp = 0;
        if (K <= i) {
            tmp = -x[negCount-i];
        } else {
            tmp = -2 * x[negCount-i];
            tmp += x[negCount+K-i-1];
        }
        ans = min(ans, tmp);
    }

    //! Move positive side first
    for (int i = 1; i <= posCount; ++i) {
        int tmp = INT_MAX;
        if (K <= i) {
            tmp = x[negCount+i-1];
        } else {
            tmp = 2 * x[negCount+i-1];
            tmp -= x[negCount-(K-i)];
        }
        ans = min(ans, tmp);
    }

    cout << ans << endl;

    return 0;
}


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


#include <iostream>
#include <iomanip> //! for setprecision(10)
#include <math.h>
#include <algorithm>
#include <functional> 
#include <string>
#include <vector>

#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <utility>

using namespace std;

typedef long long LL;

#define dump(c) { for (auto it = c.begin(); it != c.end(); ++it) if (it == c.begin()) cout << *it; else cout << ' ' << *it; cout << endl; } 
#define rep(i,n) for (int i = 0; i < (n); ++i)

const int MOD = 1000000007;

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

    int N, K;
    cin >> N >> K;

    vector<int> x;
    x.reserve(N);
    int negCount = 0;
    rep(i, N) {
        int xin;
        cin >> xin;
        if (xin < 0) {
            ++negCount;
        }
        if (xin) {
            x.push_back(xin); 
        } else {
            --K; //! remove candle on 0
        }
    }
    N = x.size();
    if (K == 0) {
        cout << 0 << endl;
        return 0;
    }
    int posCount = N - negCount;

    int ans = INT_MAX;

    //! Move negative side first
    for (int i = 1; i <= negCount; ++i) {
        int tmp = INT_MAX;
        if (K <= i) {
            tmp = -x[negCount-i];
        } else {
            tmp = -2 * x[negCount-i];
            tmp += x[negCount+K-i-1];
        }
        ans = min(ans, tmp);
    }

    //! Move positive side first
    for (int i = 1; i <= posCount; ++i) {
        int tmp = INT_MAX;
        if (K <= i) {
            tmp = x[negCount+i-1];
        } else {
            tmp = 2 * x[negCount+i-1];
            tmp -= x[negCount-(K-i)];
        }
        ans = min(ans, tmp);
    }

    cout << ans << endl;

    return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:55:15: error: 'INT_MAX' was not declared in this scope
   55 |     int 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 <utility>
  +++ |+#include <climits>
   15 |
Language: C++

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

int n,k;
vector<long long> x;
int main(){
  cin >> n >> k;
  x.resize(n);
  rep(i,n) cin >> x[i];
  long long res = 1LL<<60;
  for(int i=0;i+k-1<n;i++){
    long long left = x[i],right = x[i+k-1];
    res = min(res,min(abs(left),abs(right))+right-left);
  }
  cout << res << endl;
}


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

#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using datas=pair<ll,ll>;
using ddatas=pair<double,double>;
using tdata=pair<ll,datas>;
using vec=vector<ll>;
using mat=vector<vec>;
using pvec=vector<datas>;
using pmat=vector<pvec>;
#define For(i,a,b) for(i=a;i<(ll)b;i++)
#define bFor(i,a,b) for(i=a;i>=(ll)b;i--)
#define rep(i,N) For(i,0,N)
#define rep1(i,N) For(i,1,N)
#define brep(i,N) bFor(i,N-1,0)
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define vsort(v) sort(all(v))
#define vrsort(v) sort(allr(v))
#define endl "\n"
#define pb push_back
#define output(v) do{bool f=0;for(auto outi:v){cout<<(f?" ":"")<<outi;f=1;}cout<<endl;}while(0)
const ll mod=1000000007;
const ll inf=1LL<<60;
template<class T> inline bool chmax(T& a,T b){bool x=a<b;if(x)a=b;return x;} 
template<class T> inline bool chmin(T& a,T b){bool x=a>b;if(x)a=b;return x;} 

double distance(ddatas& x,ddatas& y){
  double a=x.first-y.first,b=x.second-y.second;
  return sqrt(a*a+b*b);
}

ll modinv(ll a) {
  ll b=mod,u=1,v=0,t;
  while(b){
    t=a/b;
    a-=t*b; swap(a,b);
    u-=t*v; swap(u,v);
  }
  return (u+mod)%mod;
}

ll moddevide(ll a,ll b){return (a*modinv(b))%mod;}

vec modncrlistp,modncrlistm;

ll modncr(ll n,ll r){
  ll i,size=modncrlistp.size();
  if(size<=n){
    modncrlistp.resize(n+1);
    modncrlistm.resize(n+1);
    if(!size){
      modncrlistp[0]=modncrlistm[0]=1;
      size++;
    }
    For(i,size,n+1){
      modncrlistp[i]=modncrlistp[i-1]*i%mod;
      modncrlistm[i]=modinv(modncrlistp[i]);
    }
  }
  return modncrlistp[n]*modncrlistm[r]%mod*modncrlistm[n-r]%mod;
}

ll modpow(ll a,ll n){
  ll res=1;
  while(n){
    if(n&1)res=res*a%mod;
    a=a*a%mod;
    n>>=1;
  }
  return res;
}

ll gcd(ll a,ll b){if(!b)return a;return (a%b==0)?b:gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

ll countdigits(ll n){
  ll ans=0;
  while(n){n/=10;ans++;}
  return ans;
}

ll sumdigits(ll n){
  ll ans=0;
  while(n){ans+=n%10;n/=10;}
  return ans;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll i,N,k,ans=inf,res;
  cin>>N>>K;K--;
  vec v(N);
  rep(i,N){
    cin>>v[i];
  }
  rep(i,N-K){
    if(v[i]*v[i+K]<0){
      res=min(-v[i],v[i+K])+v[i+K]-v[i];
    }else{
      res=max(labs(v[i]),labs(v[i+K]));
    }
    chmin(ans,res);
  }
  cout<<ans<<endl;
  return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:94:11: error: 'K' was not declared in this scope
   94 |   cin>>N>>K;K--;
      |           ^
Language: C++

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

int main() {
    int N, K;
    cin >> N >> K;
    vector<int> plus;
    vector<int> minus;
    int x;
    for (int i = 0; i < N; i++){
        cin >> x;
        if (x < 0){
            minus.push_back(x);
        }
        else{
            plus.push_back(x);
        }
    }
    reverse(minus.begin(), minus.end());
    int tmp_p = -1;
    int tmp_m = -1;
    int cnt = 0;
    int num = 0;
    int cnt1 = 100000000;
    int cnt2 = 100000000;
    if (plus.size() >= K){
        cnt1 = plus[K-1];
    }
    if (minus.size() >= K) {
        cnt2 = minus[K-1];
    }

    while (cnt < K) {
        if (tmp_p+1 < plus.size()){
            if (plus[tmp_p+1] == num){
                cnt++;
                tmp_p++;
            }
        }
        if (tmp_m+1 < minus.size()){
            if (minus[tmp_m+1] == -num){
                cnt++;
                tmp_m++;
            }
        }
        
        num++;
    }
    if (cnt == K){
        if (tmp_p >= 0 && tmp_m >= 0){
            cout << min({cnt1, cnt2, 2 * min(plus[tmp_p], -minus[tmp_m]) + max(plus[tmp_p], -minus[tmp_m])}) << endl;
        }
        else if (tmp_p < 0){
            cout << min({cnt1, cnt2, -minus[tmp_m]}) << endl;
        }
        else {
            cout << min({cnt1, cnt2, plus[tmp_p]}) << endl;
        }
    }
    else if (tmp_p != 0 && tmp_m != 0){
        cout << min({cnt1, cnt2, 2*min(plus[tmp_p-1], -minus[tmp_m]) + max(plus[tmp_p-1], -minus[tmp_m]), 2*min(plus[tmp_p], -minus[tmp_m-1]) + max(plus[tmp_p], -minus[tmp_m-1])}) << endl;
    }
    else if (tmp_p ==0){
        cout << min({cnt1, cnt2, 2*min(plus[tmp_p], -minus[tmp_m-1]) + max(plus[tmp_p], -minus[tmp_m-1])}) << endl;
    }
    else{
        cout << min({cnt1, cnt2, 2*min(plus[tmp_p-1], -minus[tmp_m]) + max(plus[tmp_p-1], -minus[tmp_m])})
    }
}


Compiler output:
a.cc: In function 'int main()':
a.cc:70:107: error: expected ';' before '}' token
   70 |         cout << min({cnt1, cnt2, 2*min(plus[tmp_p-1], -minus[tmp_m]) + max(plus[tmp_p-1], -minus[tmp_m])})
      |                                                                                                           ^
      |                                                                                                           ;
   71 |     }
      |     ~