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

#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <math.h>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
 
// #include <bits/stdc++.h>
// #include <epxt/pb_ds/assoc_container.hpp>
// using namespace __gnu_pbds;
using namespace std;
// typedef pair<LL,LL> pii;
// tree <pii,null_tpype,greater<pii>,rb_tree_tag,tree_order_statistics_node_update> tr;
// cin.tie(0);
// std::ios::spync_with_stdio(false);
typedef long long LL;
const int N = 200005;
const int M = 205;
// const int V = 207;
// const int E = 60007;
const int INF = 0x3f3f3f3f;
const double inf = 2e9;
const double Pi = acos(-1);
const int MOD = 1e9+7;
const double eps=1e-13;
int n,m;
int vis[N];
int s[N];
bool cmp(int a,int b){return a>b;}
int main()
{
    while (~scanf("%d%d",&n,&k))
    {
        for (int i=0;i<n;i++)
        {
            int x;
            scanf("%d",&x);
            vis[x]++;
        }
        sort(vis,vis+200000,cmp);
        int ans = 0;
        for (int i=k;i<=200000;i++)
            ans += vis[i];
        printf("%d\n", ans);
    }
    return 0;
}


/*



*/

Compiler output:
a.cc: In function 'int main()':
a.cc:35:30: error: 'k' was not declared in this scope
   35 |     while (~scanf("%d%d",&n,&k))
      |                              ^
Language: C++

#include <bits/stdc++.h>
//#define ll long long int
#define int long long
#define mp make_pair
#define pb push_back
#define ld long double
#define pii pair<int,int>
#define sz(x) (int)x.size()
#define piii pair<pii,pii>
#define precise cout<<fixed<<setprecision(10)
#define st first
#define nd second
#define ins insert
#define vi vector<int>
#define BOOST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;
const int MAX=55;
int a[MAX];
vector<pii>ans;
int maxi=-1,pos=-1;
int32_t main()
{
  BOOST;
	int n;
	cin>>n;
	for (int i=1;i<=n;i++){
		cin>>a[i];
		if (abs(a[i])>maxi)maxi=a[i],pos=i;
	}
	//3
	//1000 -1000 0
  if (a[pos]<0){
  	if (i!=pos)
		for (int i=1;i<=n;i++)ans.pb(mp(pos,i));
		for (int i=n-1;i>=1;i--)ans.pb(mp(i+1,i));
	}
	else{
		if (i!=pos)
		for (int i=1;i<=n;i++)ans.pb(mp(pos,i));
		for (int i=2;i<=n;i++)ans.pb(mp(i-1,i));
	}
	
	cout<<sz(ans)<<"\n";
	for(auto it:ans)cout<<it.st<<" "<<it.nd<<"\n";
  return 0;
}


Compiler output:
a.cc: In function 'int32_t main()':
a.cc:33:13: error: 'i' was not declared in this scope
   33 |         if (i!=pos)
      |             ^
a.cc:38:21: error: 'i' was not declared in this scope
   38 |                 if (i!=pos)
      |                     ^
Language: C++

#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,a,n) for(ll i = a;i < n;i++)
#define rrep(i,a,n) for(ll i = n; i >= a;i--)
#define index_check(i,n) if(i > n-1 || i < 0) continue; 
#define LINF 1e18
#define INF 1e9
#define MOD (ll)(1e9+7)
using namespace std;

#define fs first
#define sc second

using P = pair<ll,ll>;
using Pll = pair<P,ll>;
using PQ = priority_queue<P,vector<P>,greater<P>>;

signed main(){
    ll n;
    cin >> n;
    ll a[n];
    vector<P> ans,vec;
    bool flag1 = true,flag2 = true;

    rep(i,0,n){
        cin >> a[i];
        vec.push_back(P(a[i],i));
        if(a[i] < 0) flag1 = false;
        else flag2 = false;
    }

    if(!flag1 && !flag2){
        sort(vec.begin(),vec.end());
        if(abs(vec[n-1].sc) >= abs(vec[0].sc)){
            rep(i,0,n){
                a[i] += a[vec[n-1].sc];
                ans.push_back(P(vec[n-1]].sc,i));
            }
            flag2 = true;
        }
        else{
            rep(i,0,n){
                a[i] += a[vec[0].sc];
                ans.push_back(P(vec[0].sc,i));
            }
            flag1 = true;
        }
    }
    
    if(flag1){ //すべて非負整数
        rep(i,0,n-1){
            a[i+1] += a[i];
            ans.push_back(P(i,i+1));
        }
    }
    else if(flag2){ 
        rep(i,0,n-1){
            a[n-i-2] += a[n-i-1];
            ans.push_back(P(n-i-1,n-i-2));
        }
    }
    

    cout << (ll)ans.size() << endl;
    rep(i,0,(ll)ans.size()){
        cout << ans[i].fs +1 << " " << ans[i].sc + 1 << endl;
    }
    return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:37:32: error: expected primary-expression before '(' token
   37 |                 ans.push_back(P(vec[n-1]].sc,i));
      |                                ^
a.cc:37:41: error: expected ')' before ']' token
   37 |                 ans.push_back(P(vec[n-1]].sc,i));
      |                                ~        ^
      |                                         )
Language: C++

#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; ++i)
#define rrep(i, n) for(int i = n-1; i >= 0; --i)
#define fi first
#define se second
using namespace std;
using lint = long long;
using uint = unsigned int;
using ulint = unsigned long long;
using ldouble = long double;
using pii = pair<int, int>;
using pli = pair<lint, lint>;
using pdd = pair<double, double>;
using pld = pair<ldouble, ldouble>;
using v1i = vector<int>;
using v1li = vector<lint>;
using v2i = vector<vector<int>>;
using v2li = vector<vector<lint>>;
using v3i = vector<vector<vector<int>>>;
using v3li = vector<vector<vector<lint>>>;
using v1b = vector<bool>;
using v2b = vector<vector<bool>>;
using v3b = vector<vector<vector<bool>>>;
using v1c = vector<char>;
using v2c = vector<vector<char>>;
using v3c = vector<vector<vector<char>>>;
constexpr lint mod1 = 1e9+7;
constexpr lint mod2 = 998244353;

int main() {
  int n, p = 0, q = 0, r, s;
  scanf("%d", &n);
  v1i(n);
  rep(i, n) scanf("%d", &v[i]);
  rep(i, n){
    if(p >= v[i]){
      p = v[i];
      r = i+1;
    }
    if(q <= v[i]){
      q = v[i];
      s = i+1;
    }
  }
  if(q >= 0){
    int m = n-1;
    printf("%d", m);
    rep(i, m) printf("%d %d", i+1, i+2);
  }
  else if(p <= 0){
    int m = n-1;
    printf("%d", m);
    rep(i, m) printf("%d %d", i+1, i+2);
  }
  else if(p > -1*q){
    int m = 2*n-1;
    printf("%d", m);
    rep(i, m/2+1) printf("%d %d", r, i+1);
    rep(i, m/2) printf("%d %d", i+1, i+2);
  }
  else{
    int m = 2*n-1;
    printf("%d", m);
    rep(i, m/2+1) printf("%d %d", s, i+1);
    rep(i, m/2) printf("%d %d", i+1, i+2);
  }
  return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:33:7: error: conflicting declaration 'v1i n'
   33 |   v1i(n);
      |       ^
a.cc:31:7: note: previous declaration as 'int n'
   31 |   int n, p = 0, q = 0, r, s;
      |       ^
a.cc:34:26: error: 'v' was not declared in this scope
   34 |   rep(i, n) scanf("%d", &v[i]);
      |                          ^
a.cc:36:13: error: 'v' was not declared in this scope
   36 |     if(p >= v[i]){
      |             ^
a.cc:40:13: error: 'v' was not declared in this scope
   40 |     if(q <= v[i]){
      |             ^
Language: C++

#include <iostream>
using namespace std;

int main() {
    long long n, a, b;
    cin >> n >> a >> b;
    long long h[n], begin = 1, end = 0;
    for (int i = 0; cin >> h[i]; i++) {
        end = max(end, h[i]);
    }
    end = max(1, end / b);
    while (begin < end) {
        long long mid = (begin + end) / 2, count = 0;
        for (long long i = 0; i < n; i++) {
            if (h[i] - mid * b > 0) {
                count += (h[i] - mid * b - 1) / (a - b) + 1;
            }
        }
        if (count <= mid) {
            end = mid;
        } else {
            begin = mid + 1;
        }
    }
    cout << begin;
    return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:11:14: error: no matching function for call to 'max(int, long long int)'
   11 |     end = max(1, end / b);
      |           ~~~^~~~~~~~~~~~
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:   template argument deduction/substitution failed:
a.cc:11:14: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
   11 |     end = max(1, end / b);
      |           ~~~^~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note:   candidate expects 3 arguments, 2 provided
Language: C++

#include <bits/stdc++.h>
using namespace std;
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 main(){
    int N;
    cin >> N;
    long long ans = 0;
    vector<long long> A(N);
    vector<pair<int, int>> pro;
    long long Mi = 1e9, Ma = -1e9;
    int mi, ma;
    for(int i = 0; i < N; i++){
        cin >> A[i];
        if(chmin(Mi, A[i]))mi = i + 1;
        if(chmax(Ma, A[i]))ma = i + 1;
    }
    
    if(Mi >= 0){
        for(int i = 1; i < N; i++){
            A[i] += A[i - 1];
            pro.push_back(make_pair(i + 1, i));
            ans++;
        }
    }
    else if(Ma =< 0){
        for(int i = N - 1; i > 0; i--){
            A[i - 1] += A[i];
            pro.push_back(make_pair(i, i + 1));
            ans++;
        }
    }else{
        if(abs(Mi) < abs(Ma)){
            for(int i = 1; i < N; i++){
                while(A[i - 1] > A[i]){
                    A[i] += Ma;
                    pro.push_back(make_pair(i + 1, ma));
                    ans++;
                }
            }
        }else{
            for(int i = N - 1; i > 0; i--){
                while(A[i - 1] > A[i]){
                    A[i - 1] += Mi;
                    pro.push_back(make_pair(i, mi));
                    ans++;
                }
            }
        }
    }
    
    cout << ans << endl;
    for(int i = 0; i < pro.size(); i++){
        cout << pro[i].second << " " << pro[i].first << endl;
    }
    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:39:17: error: expected primary-expression before '<' token
   39 |     else if(Ma =< 0){
      |                 ^
Language: C++

for(int i=1;i<n;i++){
		res tmp;
		if(a[i]>a[i+1]&&a[i+1]>=0){
			tmp.x=i+1;
			tmp.y=i;
			que.push(tmp);
			cou++;
		}else if(a[i]>a[i+1]&&a[i+1]<0&&a[i]>=0&&abs(a[i+1])<=a[i]){
			tmp.x=i+1;
			tmp.y=i;
			que.push(tmp);
			tmp.x=i+1;
			tmp.y=i;
			que.push(tmp);
			cou+=2;
		}else if(a[i]>a[i+1]&&a[i+1]<0&&a[i]>=0&&abs(a[i+1])>a[i]){
			tmp.x=i;
			tmp.y=i+1;
			que.push(tmp);
			tmp.x=i;
			tmp.y=i+1;
			que.push(tmp);
			cou+=2;
		}else if(a[i]>a[i+1]&&a[i+1]<0&&a[i]<0){
			tmp.x=i;
			tmp.y=i+1;
			que.push(tmp);
			cou++;
		}
	}

Compiler output:
a.cc:1:1: error: expected unqualified-id before 'for'
    1 | for(int i=1;i<n;i++){
      | ^~~
a.cc:1:13: error: 'i' does not name a type
    1 | for(int i=1;i<n;i++){
      |             ^
a.cc:1:17: error: 'i' does not name a type
    1 | for(int i=1;i<n;i++){
      |                 ^
Language: C++

#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;

int main(){
  int N;cin>>N;
  vi a;
  int m=0;
  vii ans;
  for (int i=0;i<N;++i){int a_;cin>>a_;a.push_back(a_);}
  int top=N;
  int smallest=0;
  int smallest_pos=N-1;
  for (int i=N-1;i>=0;--i){
    if(smallest>a[i]){smallest_pos=i;smallest=a[i];}
    if (a[i]>=abs(smallest)){top=i;}
  }

  ii p;

  if(top!=0&&top!=1){
    a[top-1]+=2*a[smallest_pos];
    p=make_pair(smallest_pos, top-1);
    ans.push_back(p);
    ans.push_back(p);
    m+=2;
  }

  if(top!=N&&top!=N-1){
    int i=top;
    while(i<N-1){
      a[i+1]+=a[i];
      p=make_pair(i,i+1);
      ans.push_back(p);
      m++;
      if(a[i+1]>=a[i]){i++;}
    }
  }
  
  if(top!=0&&top!=1){
    i=top-1;
    while(i>0){
      a[i-1]+=a[i];
      p=make_pair(i,i-1);
      ans.push_back(q);
      m++;
      if(a[i-1]<=a[i]){i--;}
    }
  }

  cout << m << endl;
  for (int i=0;i<m;++i){
    ii q=ans[i];
    int x=q.first, y=q.second;
    cout << x << ' ' << y << endl;
  }
  return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:43:5: error: 'i' was not declared in this scope
   43 |     i=top-1;
      |     ^
a.cc:47:21: error: 'q' was not declared in this scope
   47 |       ans.push_back(q);
      |                     ^
Language: C++

N = int(input())
A = [int(i) for i in input().split()]
max_i = A.index(max(A))
min_i = A.index(min(A))
abs_max_i = max(max_i,min_i,key = lambda x:abs(A[x]))
print(2*N-2)
for i in range(N):
    [print("{} {}".format(abs_max_i, i)) if i != abs_max_i else None]
if A[abs_max_i] > 0:
    for i in range(N-1):
        print("{} {}".format(i, i+1))
else:
    for i in range(N-1,0,-1):
        print("{} {}".format(i, i-1))

Compiler output:
a.cc:1:1: error: 'N' does not name a type
    1 | N = int(input())
      | ^
Language: C++

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

int main(){
  int n;
  vector<pair<int,int> > v;
  cin >> n;
  long long a[n];
  int t;
  long long mx = 0,cnt=0;
  bool ch;
  for(i=0;i<n;i++){
    cin >> a[i];
    if(abs(a[i])-abs(mx)>0){
      mx = a[i];
      t=i;
    }
  }
  if(mx>=0)ch=true;
  else ch = false;
  for(i=0;i<n;i++){
    a[i]+=mx;
    cnt++;
    v.push_back(make_pair(i,t));
  }
  if(ch){
  	for(i=1;i<n;i++){
      if(a[i]<a[i-1]){
        a[i]+=a[i-1];
        v.push_back(make_pair(i,i-1));
        cnt++;
      }
    }
  }else{
    for(i=n-1;i>=0;i--){
      if(a[i]>a[i+1]){
        a[i]+=a[i+1];
        v.push_back(make_pair(i,i+1));
        cnt++;
      }
    }
  }
  cout << cnt << endl;
  for(i=0;i<v.size();i++){
    cout << v[i].first << " " << v[i].second << endl;
  }
   return 0;
}
    

Compiler output:
a.cc: In function 'int main()':
a.cc:14:7: error: 'i' was not declared in this scope
   14 |   for(i=0;i<n;i++){
      |       ^
a.cc:23:7: error: 'i' was not declared in this scope
   23 |   for(i=0;i<n;i++){
      |       ^
a.cc:29:13: error: 'i' was not declared in this scope
   29 |         for(i=1;i<n;i++){
      |             ^
a.cc:37:9: error: 'i' was not declared in this scope
   37 |     for(i=n-1;i>=0;i--){
      |         ^
a.cc:46:7: error: 'i' was not declared in this scope
   46 |   for(i=0;i<v.size();i++){
      |       ^
Language: C++

N = int(input())
a = list(map(int,input().split()))
pos_max = max(a)
neg_max = min(a)
res = []
if abs(pos_max) >= abs(neg_max):
    # pos_max を 全要素に足す
    pos = a.index(pos_max) + 1
    for i in range(N):
        a[i] += pos_max
        res.append([pos, i + 1])
    # 全要素が正
    for i in range(N-1):
        a[i+1] += a[i]
        res.append([i + 2, i + 1])
else:
    # neg_max を 全要素に足す
    pos = a.index(neg_max) + 1
    for i in range(N):
        a[i] += neg_max
        res.append([pos, i + 1])
    # 全要素が負
    for i in range(N-2,-1,-1):
        a[i] += a[i+1]
        res.append([i + 1, i + 2])

# print(*a)
print(len(res))
for l in res:
    print(*l)


Compiler output:
a.cc:7:7: error: invalid preprocessing directive #pos_max
    7 |     # pos_max を 全要素に足す
      |       ^~~~~~~
a.cc:12:7: error: invalid preprocessing directive #\U00005168\U00008981\U00007d20\U0000304c\U00006b63
   12 |     # 全要素が正
      |       ^~~~~~~~~~
a.cc:17:7: error: invalid preprocessing directive #neg_max
   17 |     # neg_max を 全要素に足す
      |       ^~~~~~~
a.cc:22:7: error: invalid preprocessing directive #\U00005168\U00008981\U00007d20\U0000304c\U00008ca0
   22 |     # 全要素が負
      |       ^~~~~~~~~~
a.cc:27:3: error: invalid preprocessing directive #print
   27 | # print(*a)
      |   ^~~~~
a.cc:1:1: error: 'N' does not name a type
    1 | N = int(input())
      | ^
Language: C++

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

using namespace std;

int main(){
    vector<int> vc;
    vector<pair<int,int>> vp;
    int i,j;
    cin >> i;
    while(i--){
        cin >> j;
        vc.push_back(j);
    }

    int max_id = 0;
    int min_id = 0;
    int maxv = INT_MIN;
    int minv = INT_MAX;
    for(size_t i = 0;i<vc.size();i++){
        if(vc[i] > maxv){
            max_id = i;
            maxv = vc[i];
        }
        if(vc[i] < minv){
            min_id = i;
            minv = vc[i];
        }
    }

    if(abs(maxv) > abs(minv)){
        for(size_t i = 0; i < vc.size();i++){
            if(vc[i] < 0){
                vp.push_back(make_pair(i+1,max_id+1));
            }
        }

        for(size_t i = 0; i < vc.size()-1;i++){
            vp.push_back(make_pair(i+2,i+1));
        }
    }
    else{
        for(size_t i = 0; i < vc.size();i++){
            if(vc[i] > 0){
                vp.push_back(make_pair(i+1,min_id+1));
            }
        }
        for(i = vc.size()-1; i > 0 ;i--){
            vp.push_back(make_pair(i,i+1));
        }
    }

    cout << vp.size()<<endl;
    for(auto a:vp){
        cout<<a.first<<" "<<a.second<<endl;
    }
}

Compiler output:
a.cc: In function 'int main()':
a.cc:20:16: error: 'INT_MIN' was not declared in this scope
   20 |     int maxv = INT_MIN;
      |                ^~~~~~~
a.cc:5:1: note: 'INT_MIN' is defined in header '<climits>'; this is probably fixable by adding '#include <climits>'
    4 | #include <utility>
  +++ |+#include <climits>
    5 | 
a.cc:21:16: error: 'INT_MAX' was not declared in this scope
   21 |     int minv = INT_MAX;
      |                ^~~~~~~
a.cc:21:16: note: 'INT_MAX' is defined in header '<climits>'; this is probably fixable by adding '#include <climits>'
Language: C

#include <bits/stdc++.h>
#define maxn 1000006
using namespace std;
long long n, a[maxn], d = 0, luu1[maxn], luu2[maxn];
void print()
{
    //for (int i = 1; i <= n; i++) cout << a[i] << ' ';
    cout << d << '\n';
    for (int i = 1; i <= d; i++)
    {
        cout << luu1[i] << ' ' << luu2[i] << '\n';
    }
}
void trau()
{
    a[0] = INT_MIN;
    for (int i = 1; i <= n; i++)
    {
        if (a[i] < a[i - 1])
        {
            if (a[i - 1] < 0)
            {
                for (int j = 1; j <= i - 1; j++)
                {
                    a[j] += a[i];
                    //cout << i << ' ' << j << '\n';
                    luu1[++d] = i; luu2[d] = j;
                }
            }

            else
            {
                if (a[i] < 0)
                {
                    if (abs(a[i]) > abs(a[i - 1]))
                    {
                        for (int j = 1; j <= i - 1; j++)
                        {
                            a[j] += a[i] * 2;
                            luu1[++d] = i; luu2[d] = j;
                            luu1[++d] = i; luu2[d] = j;
                            //cout << i << ' ' << j << '\n';
                            //cout << i << ' ' << j << '\n';
                        }
                    }

                    else
                    {
                        a[i] += a[i - 1] * 2;
                        luu1[++d] = i - 1; luu2[d] = i;
                        luu1[++d] = i - 1; luu2[d] = i;
                        //cout << i - 1 << ' ' << i << '\n';
                        //cout << i - 1 << ' ' << i << '\n';
                    }
                }

                else
                {
                    a[i] += a[i - 1];
                    luu1[++d] = i - 1; luu2[d] = i;
                    //cout << i - 1 << ' ' << i << '\n';

                }
            }
        }
    }
}
int main()
{
    //freopen ("test.inp", "r", stdin);
    //freopen ("test.out", "w", stdout);
    cin >> n;
    for (int i = 1; i <= n; i++) cin >> a[i];

    trau();
    print();
}


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

#include <bits/stdc++.h>
using namespace std;
int main()
{
long long int cnt=0,n,b[1001];
cin>>n;
for (int j=0;j<n;j++){
		cin>>b[j];
}
for (int j=0;j<n;j++){
if(b[1]+b[2]==0)
{
	cout<<0;
	return 0;
}
if(b[1]==-1)
{
		cout <<n-1<<endl;
		cout<<n<<" "<<n-1;
		return 0;
}
if(b[i]==-2)
{
		cout <<n-1<<endl;
		cout<<n-1<<" "<<n<<endl;
		cout<<n<<" "<<n;
		return 0;
}

}
}

Compiler output:
a.cc: In function 'int main()':
a.cc:22:6: error: 'i' was not declared in this scope
   22 | if(b[i]==-2)
      |      ^
Language: C++

#include<stdio.h>
using namespace std;
bool isf(long long num[],int n){
for(int i=1;i<n;i++){
    if(num[i]>0) {
            return true;
    }
}
return false;
}

int  isbz(long long num[],int n){
    long long max=0;
    int k;
    for(int i=1;i<n;i++)
    {
if(num[i]>max)    k=i;
   }
    return k;
}

int ismz(long long num[],int n){
   long  long min=0;
    int k;
    for(int i=1;i<n;i++)
    {
if(num[i]<min)    k=i;
    }
    return k;
}
int main(){
int N,m=0;
scanf("%d",&N);
N=N+1;
long long  K[10000]={0};
long long  I[10000]={0};
long  long a[N];
for(int i=1;i<N;i++){
    scanf("%lld",&a[i]);
}
if(isf(a,N)){
for(int i=1;i<N-1;i++){
    while(a[i]>a[i+1]){
      int k=isbz(a,N);
        a[i+1]+=a[isbz(a,N)];
    K[m]=i+1;
    I[m]=k;
    m++;
    }
}
}
else {
for(int i=1;i<N-1;i++){
    while(a[i]>a[i+1]){
        int k=ismz(a,N);
        a[i]+=a[ismz(a,N)];

    K[m]=i;
    I[m]=k;
    m++;


}
}
printf("%d\n",m);
for(int i=0;i<10000;i++){
if(K[i]==0) break;
printf("%lld",I[i]);
printf("%s"," ");
printf("%lld\n",K[i]);

}

}





Compiler output:
a.cc: In function 'int main()':
a.cc:74:2: error: expected '}' at end of input
   74 | }
      |  ^
a.cc:31:11: note: to match this '{'
   31 | int main(){
      |           ^
Language: C++

#include<stdio.h>
using namespace std;
bool isf(int num[],int n){
for(int i=1;i<n;i++){
    if(num[i]>0) {
            return true;
    }
}
return false;
}

int  isbz(int num[],int n){
    long  max=0;
    int k;
    for(int i=1;i<n;i++)
    {
if(num[i]>max)    k=i;
   }
    return k;
}

int ismz(int num[],int n){
   long  min=0;
    int k;
    for(int i=1;i<n;i++)
    {
if(num[i]<min)    k=i;
    }
    return k;
}
int main(){
int N,m=0;
scanf("%d",&N);
N=N+1;
int K[2*N]={0};
int I[2*N]={0};
long a[N];
for(int i=1;i<N;i++){
    scanf("%d",&a[i]);
}
if(isf(a,N)){
for(int i=1;i<N-1;i++){
    while(a[i]>a[i+1]){
      int k=isbz(a,N);
        a[i+1]+=a[isbz(a,N)];
    K[m]=i+1;
    I[m]=k;
    m++;}
}
}
else {
for(int i=1;i<N-1;i++){
    while(a[i]>a[i+1]){
        int k=ismz(a,N);
        a[i]+=a[ismz(a,N)];
    K[m]=i;
    I[m]=k;
    m++;}
}
}
printf("%d\n",m);
for(int i=0;i<2*N;i++){
if(K[i]==0) break;
printf("%ld",I[i]);
printf("%s"," ");
printf("%ld\n",K[i]);

}

}





Compiler output:
a.cc: In function 'int main()':
a.cc:41:8: error: cannot convert 'long int*' to 'int*'
   41 | if(isf(a,N)){
      |        ^
      |        |
      |        long int*
a.cc:3:14: note:   initializing argument 1 of 'bool isf(int*, int)'
    3 | bool isf(int num[],int n){
      |          ~~~~^~~~~
a.cc:44:18: error: cannot convert 'long int*' to 'int*'
   44 |       int k=isbz(a,N);
      |                  ^
      |                  |
      |                  long int*
a.cc:12:15: note:   initializing argument 1 of 'int isbz(int*, int)'
   12 | int  isbz(int num[],int n){
      |           ~~~~^~~~~
a.cc:45:24: error: cannot convert 'long int*' to 'int*'
   45 |         a[i+1]+=a[isbz(a,N)];
      |                        ^
      |                        |
      |                        long int*
a.cc:12:15: note:   initializing argument 1 of 'int isbz(int*, int)'
   12 | int  isbz(int num[],int n){
      |           ~~~~^~~~~
a.cc:54:20: error: cannot convert 'long int*' to 'int*'
   54 |         int k=ismz(a,N);
      |                    ^
      |                    |
      |                    long int*
a.cc:22:14: note:   initializing argument 1 of 'int ismz(int*, int)'
   22 | int ismz(int num[],int n){
      |          ~~~~^~~~~
a.cc:55:22: error: cannot convert 'long int*' to 'int*'
   55 |         a[i]+=a[ismz(a,N)];
      |                      ^
      |                      |
      |                      long int*
a.cc:22:14: note:   initializing argument 1 of 'int ismz(int*, int)'
   22 | int ismz(int num[],int n){
      |          ~~~~^~~~~
Language: C++

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

typedef long long ll;
typedef pair<int, int> ii; 

int a[100], n, neg, pos, mx = -1e9, pm, mn = 1e9, pn; 
vector<ii> sol;

void do_pos() {
	for(int i = 1; i < n; i++) 
		sol.push_back({i, i + 1}); 
}
void do_neg() {
	for(int i = n - 1; i >= 1; i--) 
		sol.push_back({i + 1, i});
}

int main(int argc, char const *argv[]) {
#ifdef LOCAL_TESTING
	freopen("in", "r", stdin);
#endif
	scanf("%d", &n);
	for(int i = 0; i < n; i++) {
		scanf("%d", &a[i]); 
		neg += a[i] <= 0; 
		pos += a[i] >= 0;
		if(a[i] > mx) mx = a[i], pm = i;
		if(a[i] < mn) mn = a[i], pn = i;
	}
	if(neg == n) do_neg(); 
	else if(pos == n) do_pos(); 
	else if(abs(mx) > abs(mn)) {
		for(int i = 0; i < n; i++) 
			sol.push_back({pm + 1, i + 1});
		do_pos(); 
	} else {
		for(int i = 0; i < n; i++) 
			sol.push_back({pn + 1, i + 1});
		do_neg();
	}
	printf("%d\n", sol.size());
	for(auto x : sol) printf("%d %d\n"; x.first, x.second);
}

Compiler output:
a.cc: In function 'int main(int, const char**)':
a.cc:43:43: error: expected ')' before ';' token
   43 |         for(auto x : sol) printf("%d %d\n"; x.first, x.second);
      |                                 ~         ^
      |                                           )
a.cc:43:45: error: 'x' was not declared in this scope
   43 |         for(auto x : sol) printf("%d %d\n"; x.first, x.second);
      |                                             ^
Language: C++

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

int main() {
        int n;
        scanf("%d", &n);
        vector<int> a(n);
        int ma = 0;
        for (int i = 0; i < n; i ++) {
                scanf("%d", &a[i]);
                ma = max(ma, abs(a[i]));
        }
        bool ispos = true;
        int p = 0;
        for (int i = 0; i < n; i ++) {
                if (abs(a[i]) == ma) {
                        ispos = a[i] >= 0;
                        p = i;
                        break;
                }
        }
        if (!ispos) {
                ma *= -1;
        }
        vector<pair<int, int>> ans;
        for (int i = 0; i < n; i ++) {
                ans.emplace_back(p, i);
        }
        if (ispos) {
                for (int i = 1; i < n; i ++) {
                        ans.emplace_back(i - 1, i);
                }
        } else {
                for (int i = n - 2; i >= 0; i --) {
                        ans.emplace_back(i + 1, i);
                }
        }
        printf("%d\n", (int) ans.size());
        for (int i = 0; i < (int) ans.size(); i ++) {
                printf("%d %d\n", ans[i].first + 1, ans[i].second + 1);
        }
        return 0;
}



Compiler output:
a.cc: In function 'int main()':
a.cc:12:30: error: 'abs' was not declared in this scope
   12 |                 ma = max(ma, abs(a[i]));
      |                              ^~~
a.cc:17:21: error: 'abs' was not declared in this scope
   17 |                 if (abs(a[i]) == ma) {
      |                     ^~~
Language: C++

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

#define REP(i,n) for(int i=0;i<n;++i)
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 0
#  define DBG(fmt, ...) printf(fmt, __VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

#define MOD 1000000007
#define INF 1000000000
#define MAX_N 100010

ll N;
vector<ll> A;
int main()
{
    cin >> N;

    pair<ll, ll> a_min = make_pair(0, 100000000);
    pair<ll, ll> a_max = make_pair(0, -100000000);

    REP(i, N) {
        ll a;
        cin >> a;
        if(a < a_min.second) {
            a_min = make_pair(i, a);
        }
        if(a > a_max.second) {
            a_max = make_pair(i, a);
        }
        A.push_back(a);
    }

    if(a_min.second == 0 && a_max.second == 0) {
        printf("0\n");
        return 0;
    }

    DBG("a_min: %lld a_max: %lld\n", a_min.second, a_max.second);

    bool isPlus = true;     // どちらの符号に揃えるか
    if(a_max.second == 0) { isPlus = false }
    else if(a_min.second == 0) { isPlus = true; }
    else if(a_min.second < 0 && a_max.second < 0) { isPlus = false; }
    else if(a_min.second >= 0 && a_max.second >= 0) { isPlus = true; }
    else {
        if(abs(a_max.second) / abs(a_min.second) < abs(a_max.second) / abs(a_min.second)) {
            isPlus = false;
        }
    }

    DBG("use %d\n", (isPlus) ? 1 : -1);

    vector< pair<ll, ll> > ans;
    if(isPlus) {
        // 正に寄せる
        REP(i, A.size()) {
            if(A[i] <= 0) {
                while(A[i] <= 0) {
                    A[i] += a_max.second;
                    ans.push_back(make_pair(a_max.first+1, i+1));
                }
            }
        }
        // 左から足していく
        for(int i = 1; i < A.size(); ++i) {
            if(A[i-1] > A[i]) {
                A[i] += A[i-1];
                ans.push_back(make_pair(i, i+1));
            }
        }
    } else {
        // 負に寄せる
        REP(i, A.size()) {
            if(A[i] >= 0) {
                while(A[i] >= 0) {
                    A[i] += a_min.second;
                    ans.push_back(make_pair(a_min.first+1, i+1));
                }
            }
        }
        // 右から足していく
        for(int i = A.size() - 1; i > 0; --i) {
            if(A[i-1] > A[i]) {
                A[i-1] += A[i];
                ans.push_back(make_pair(i+1, i));
            }
        }
    }

    // 答えの出力
    printf("%zu\n", ans.size());
    for(auto& p : ans) {
        printf("%lld %lld\n", p.first, p.second);
    }
    return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:49:43: error: expected ';' before '}' token
   49 |     if(a_max.second == 0) { isPlus = false }
      |                                           ^~
      |                                           ;
Language: C++

#include<iostream>
#include<algorithm>
#include<vector>
#include<math.h>

using namespace std;
typedef long long ll;

int a[51];
int cnt = 0;

int main()
{
 	ios_base::sync_with_stdio(0);
 	int n;
 	cin >> n;
 	int m=INT_MAX, M=INT_MIN;
 	int mind, Mind;
 	for(int i=1; i<=n; i++) {
 		cin >> a[i];
 		if(a[i] < m) {
 			m = a[i];
 			mind = i;
 		}
 		if(a[i] > M) {
 			M = a[i];
 			Mind = i;
 		}
 	}

 	if(m+M<0) {
 		cout << 2*n - 1 << endl;
 		for(int i=1; i<=n; i++) {
 			cout << mind << " " << i << endl;
 		}
 		for(int i=n; i>1; i--) {
 			cout << i << " " << i-1 << endl;
 		}
 		return 0;
 	}
 	else {
 		cout << 2*n - 1 << endl;
 		for(int i=1; i<=n; i++) {
 			cout << Mind << " " << i << endl;
 		}
 		for(int i=1; i<n; i++) {
 			cout << i << " " << i+1 << endl;
 		}
 		return 0;
 	}
}


Compiler output:
a.cc: In function 'int main()':
a.cc:17:15: error: 'INT_MAX' was not declared in this scope
   17 |         int m=INT_MAX, M=INT_MIN;
      |               ^~~~~~~
a.cc:5:1: note: 'INT_MAX' is defined in header '<climits>'; this is probably fixable by adding '#include <climits>'
    4 | #include<math.h>
  +++ |+#include <climits>
    5 | 
a.cc:25:27: error: 'M' was not declared in this scope
   25 |                 if(a[i] > M) {
      |                           ^
a.cc:31:14: error: 'M' was not declared in this scope
   31 |         if(m+M<0) {
      |              ^
Language: C++

#include <stdio.h>
#include <algorithm>
#include <string.h>
using namespace std;
const int maxn = 1e6+10;
const int inf = 1e7;
int a[55] , vis[maxn];
int main()
{
	int n;
	while(scanf("%d",&n)!=EOF)
	{
		int MAX = -inf, MIN = inf;
		int idx , idn;
		for(int i = 0 ; i < n ; i++)
		{
			scanf("%d",&a[i]);
			if(a[i] > MAX)
			{
				MAX = a[i];
				idx = i;
			}
			else (a[i] < MIN) 
			{
				MIN = a[i];
				idn = i;
			}
		}
		if(MIN>=0)
		{
			printf("%d\n",n-1);
			for(int i = 1 ; i <n ;i++)
			{
				printf("%d %d\n",i,i+1);
			}
		}
		else if(MAX <= 0)
		{
			printf("%d\n",n-1);
			for(int i = n ; i>1 ; i--)
			{
				printf("%d %d\n",i,i-1);
			}
		}
		else if(abs(MAX)>=abs(MIN))
		{
			printf("%d\n",2*n-1);
			for(int i = 1 ; i <= n ; i++)
			{
				printf("%d %d\n",idx , i);
			}
			for(int i = 1 ; i < n ; i++)
			{
				printf("%d %d\n",i,i+1);
			}
		}
		else
		{
			printf("%d\n",2*n-1);
			for(int i = 1 ; i <= n ; i++)
			{
				printf("%d %d\n",idn,i);
			}
			for(int i = n ; i >1;i--)
			{
				printf("%d %d\n",i,i-1);
			}
		}
	}
}

Compiler output:
a.cc: In function 'int main()':
a.cc:23:42: error: expected ';' before '{' token
   23 |                         else (a[i] < MIN)
      |                                          ^
      |                                          ;
   24 |                         {
      |                         ~
Language: C

#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
 
int main(void)
{
	int n;
	int i, max_i, min_i;
	int a[50];
	int max = INT_MIN, min = INT_MAX;
	int cs;
	int cnt;
	scanf("%d", &n);
	for (i = 0; i < n; ++i){
		scanf("%d", a + i);
		if (a[i] > max){
			max = a[i];
			max_i = i;
		}
		if (a[i] < min){
			min = a[i];
			min_i = i;
		}
	}
	//	printf("%d\n", n * 2);
	if (max <= 0){
		//all negative
		printf("%d\n", n - 1);
		for (i = 0; i < n - 1; ++i){
			printf("%d %d\n", n - i, n - i - 1);
		}
	}
	else if (min >= 0){
		//all positive
		printf("%d\n", n - 1);
		for (i = 0; i < n - 1; ++i){
			printf("%d %d\n", i + 1, i + 2);
		}
	}
	else if (-max < min){
		printf("%d\n", n + n - 1);
		for (i = 0; i < n; ++i){
			printf("%d %d\n", i + 1, max_i);
		}
		for (i = 0; i < n - 1; ++i){
			printf("%d %d\n", i + 1, i + 2);
		}
	}
	else{
		printf("%d\n", n + n - 1);
		for (i = 0; i < n; ++i){
			printf("%d %d\n", i + 1, min_i);
		}
		for (i = 0; i < n - 1; ++i){
			printf("%d %d\n", n - i, n - i - 1);
		}
	}
	//	printf("%s\n", s);
	return 0;
}

Compiler output:
main.c:5:1: error: stray '\302' in program
    5 | <U+00A0>
      | ^~~~~~~~
Language: C++

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int N, a[51];
using P = pair<int, int>;
vector<P> v;
int iabs(int a) { return a < 0 ? -a : a; }
int main() {
    cin >> N;
    for(int i{ 1 }; i <= N; ++i) cin >> a[i];
    int mx{ *max_element(a + 1, a + N + 1) }, mn{ *min_element(a + 1, a + N + 1) };
    bool mode{};
    if((mx < 0 && mn < 0) || (mx >= 0 && mx < iabs(mn))) mode = 1;
    if(mode) {
        int done{ 1 };
        while(done < N) {
            auto m = min_element(a + 1, a + N + 1);
            if(distance(a, m) == done) ++done;
            else {
                n = max_element(a + 1, a + N + 1);
                if(m == n) ++done;
                else a[distance(a, n)] += *m, v.emplace_back(distance(a, n), distance(a, m));
            }
        }
    }
    else {
        int done{ 1 };
        while(done < N) {
            auto m = max_element(a + 1, a + N + 1);
            if(distance(a, m) == done) ++done;
            else {
                n = min_element(a + 1, a + N + 1);
                if(m == n) ++done;
                else a[distance(a, n)] += *m, v.emplace_back(distance(a, n), distance(a, m));
            }
        }
    }
    cout << v.size() << endl;
    for(auto& x : v)
        cout << x.first << ' ' << x.second << endl;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:20:17: error: 'n' was not declared in this scope
   20 |                 n = max_element(a + 1, a + N + 1);
      |                 ^
a.cc:32:17: error: 'n' was not declared in this scope
   32 |                 n = min_element(a + 1, a + N + 1);
      |                 ^
Language: C++

#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define INF (1LL << 55)
#define MOD (1000 * 1000 * 1000 + 7)
#define maxn 55

typedef long long ll;
typedef long double ld;

ll arr[maxn];

vector<pair<ll, ll> > ans;

ll main(){
	ll n, mini = 1e9, maks = -1e9;
	scanf("%lld", &n);
	for(ll i = 0; i < n; i++){
		scanf("%lld", arr + i);
		maks = max(maks, arr[i]);
		mini = min(mini, arr[i]);
	}

	if(abs(maks) >= abs(mini)){
		for(ll i = 0; i < n; i++){
			for(ll k = 0; k < 2; k++){
				ll x = -INF;
				ll ind = 0;
				for(ll j = 0; j < n; j++){
					if(arr[j] > x){
						x = arr[j];
						ind = j;
					}
				}

				ans.pb(mp(ind, i));
				arr[i] += x;
			}
		}
	}

	if(abs(maks) < abs(mini)){
		for(ll i = n - 1; i >= 0; i--){
			for(ll k = 0; k < 2; k++){
				ll x = INF;
				ll ind = 0;
				for(ll j = 0; j < n; j++){
					if(arr[j] < x){
						x = arr[j];
						ind = j;
					}
				}

				ans.pb(mp(ind, i));
				arr[i] += x;
			}
		}
	}

	printf("%lld\n", (ll) ans.size());
	for(auto i : ans)
		printf("%lld %lld\n", i.fi + 1, i.se + 1);

//	for(ll i = 0; i < n; i++)
//		printf("%lld ", arr[i]);

	return 0;
}

Compiler output:
a.cc:20:1: error: '::main' must return 'int'
   20 | ll main(){
      | ^~
Language: C

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

int main(void)
{
	int n;
	int i, max_i, min_i;
	int a[50];
	int max = INT_MIN, min = INT_MAX;
	int cs;
	int cnt;
	scanf("%d", &n);
	for (i = 0; i < n; ++i){
		scanf("%d", a + i);
		if (a[i] > max){
			max = a[i];
			max_i = i;
		}
		if (a[i] < min){
			min = a[i];
			min_i = i;
		}
	}
	//	printf("%d\n", n * 2);
	if (max <= 0){
		//all negative
		printf("%d\n", n - 1);
		for (i = 0; i < n - 1; ++i){
			printf("%d %d\n", n - i, n - i - 1);
		}
	}
	else if (min >= 0){
		//all positive
		printf("%d\n", n - 1);
		for (i = 0; i < n - 1; ++i){
			printf("%d %d\n", i + 1, i + 2);
		}
	}
	else if (-max < min){
		printf("%d\n", n + n - 1);
		for (i = 0; i < n; ++i){
			printf("%d %d\n", i + 1, max_i);
		}
		for (i = 0; i < n - 1; ++i){
			printf("%d %d\n", i + 1, i + 2);
		}
	}
	else{
		printf("%d\n", n + n - 1);
		for (i = 0; i < n; ++i){
			printf("%d %d\n", i + 1, min_i);
		}
		for (i = 0; i < n - 1; ++i){
			printf("%d %d\n", n - i, n - i - 1);
		}
	}
	//	printf("%s\n", s);
	return 0;
}


Compiler output:
main.c: In function 'main':
main.c:10:19: error: 'INT_MIN' undeclared (first use in this function)
   10 |         int max = INT_MIN, min = INT_MAX;
      |                   ^~~~~~~
main.c:4:1: note: 'INT_MIN' is defined in header '<limits.h>'; this is probably fixable by adding '#include <limits.h>'
    3 | #include <stdlib.h>
  +++ |+#include <limits.h>
    4 | 
main.c:10:19: note: each undeclared identifier is reported only once for each function it appears in
   10 |         int max = INT_MIN, min = INT_MAX;
      |                   ^~~~~~~
main.c:10:34: error: 'INT_MAX' undeclared (first use in this function)
   10 |         int max = INT_MIN, min = INT_MAX;
      |                                  ^~~~~~~
main.c:10:34: note: 'INT_MAX' is defined in header '<limits.h>'; this is probably fixable by adding '#include <limits.h>'
Language: C++

//2
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<algorithm>
#include<cstdlib>
#include<cassert>
using namespace std;
int main(){
    int N;
    cin >> N;
    int a[50];

    bool all_p = true;
    bool all_m = true;
    bool all_z = true;

    int max = -9999999;
    int min = 9999999;
    int max_num = -1;
    int min_num = -1;

    //int kari = 0;
    
    for(int i=0; i<N; i++){
        cin >> a[i];
        //if(a[i-1] > a[i]) kari++;
        if(a[0]>0){
            all_m = false;
            all_z = false;
        }
        else if(a[0]<0){
            all_z = false;
        }

        if(a[i] > max){
            max = a[i];
            max_num = i;
        }
        if(a[i] < min){
            min = a[i];
            min_num = i;
        }
    }

    if(all_z){
        cout << 0 << endl;
    }
    else if(all_p){
        cout << N-1 << endl;
        for(int i=1; i<N; i++){
            cout << i-1 << " " << i << endl;
        }
    }
    else if(all_m){
        cout << N-1 << endl;
        for(int i=1; i<N; i++){
            cout << N-i-1 << " " << N-i << endl;
        }
    }
    else{
        if(abs(max) >= abs(min)){
            cout << 2*N << endl;
            cout << max_num << " " << max_num << endl;
            for(int i=0; i<N; i++){
                cout << max_num << " " << i << endl;
            }
            for(int i=1; i<N; i++){
                cout << i-1 << " " << i << endl;
            }
        }
        else{
            cout << 2*N << endl;
            cout << min_num << " " << min_num << endl;
            for(int i=0; i<N; i++){
                cout << mix_num << " " << i << endl;
            }
            for(int i=1; i<N; i++){
                cout << N-i-1 << " " << N-i << endl;
            }
        }
    }

    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:78:25: error: 'mix_num' was not declared in this scope; did you mean 'min_num'?
   78 |                 cout << mix_num << " " << i << endl;
      |                         ^~~~~~~
      |                         min_num
Language: C++

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

vector<pair<ll, ll>> res;
int kek;
vector<ll> f(vector<ll> a) {
    res.clear();
    for (int i = 1; i < a.size(); ++i) {
        if (a[i] >= a[i - 1]) continue;
        ll best = 0;
        ll mn = 2e9;
        for (int j = 0; j < a.size(); ++j) {
            if (a[j] <= 0) continue;
            ll d = (a[i - 1] - a[i]) / a[j];
            while (d * a[j] + a[i] < a[i - 1]) ++d;
            if (d < mn) {
                mn = d;
                best = j;
            } else if (d == mn) {
                if (a[j] < a[best]) {
                    best = j;
                }
            }
        }
        if (mn == 2e9 || kek + mn > a.size * 2) return a;
        for (int j = 0; j < mn; ++j) {
            res.push_back({best + 1, i + 1});
        }
        a[i] += a[best] * mn;
    }
    return a;
}

bool good(vector<ll> a) {
    auto b = a;
    sort(b.begin(), b.end());
    return a == b;
}

vector<pair<ll, ll>> dec(vector<ll> a, int x) {
    ll mn = 2e9;
    ll val;
    ll best;
    for (int i = 0; i < a.size(); ++i) {
        if (a[i] >= 0) continue;
        ll dd = x / -a[i];
        while (abs(dd * a[i]) < x) {
            ++dd;
        }
        if (mn > dd) {
            mn = dd;
            val = dd * a[i];
            best = i;
        } else if (mn == dd) {
            if (val < dd * a[i]) {
                val = dd * a[i];
                best = i;
            }
        }
    }
    if (mn == 2e9 || mn > 2ll * a.size()) return {};
    vector<pair<ll, ll>> kek;
    for (int i = 0; i < mn; ++i) {
        kek.push_back({best + 1, 1});
    }
    return kek;
}

int main() {
    int n;
    cin >> n;
    vector<ll> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    ll l = -1, r = 1 + *max_element(a.begin(), a.end()) - *min_element(a.begin(), a.end());
    vector<pair<ll, ll>> qwe;
    auto ans = qwe;
    while (r - l > 1) {
        int m = (l + r) / 2;
        auto w = dec(a, m);
        kek = w.size();
        auto b = a;
        if (!w.empty()) b[0] += b[w[0].first - 1]  * w.size();
        auto c = f(b);
        if (good(c)) {
            r = m;
            ans = res;
        } else {
            l = m;
        }
    }
    qwe = dec(a, r);
    cout << res.size() + qwe.size() << '\n';
    for (auto w : ans) cout << w.first << " " << w.second << '\n';
    for (auto w : qwe) cout << w.first << " " << w.second << '\n';
}



Compiler output:
a.cc: In function 'std::vector<long long int> f(std::vector<long long int>)':
a.cc:27:39: error: invalid use of member function 'std::vector<_Tp, _Alloc>::size_type std::vector<_Tp, _Alloc>::size() const [with _Tp = long long int; _Alloc = std::allocator<long long int>; size_type = long unsigned int]' (did you forget the '()' ?)
   27 |         if (mn == 2e9 || kek + mn > a.size * 2) return a;
      |                                     ~~^~~~
      |                                           ()
Language: C

      for(;mi&&u[mi-1]==0;mi--){
	a[r]=mi+1;
	b[r++]=mi;
	u[mi]=1;
      }
    }
    else{
      for(;mi+1<n&&u[mi+1]==0;mi++){
	a[r]=mi+1;
	b[r++]=mi+2;
	u[mi]=1;
      }
    }
  }//printf("%d\n",r);
  printf("%d\n",r*2);
  for(i=0;i<r;i++)printf("%d %d\n%d %d\n",a[i],b[i],a[i],b[i]);
  return 0;
}


Compiler output:
main.c:1:7: error: expected identifier or '(' before 'for'
    1 |       for(;mi&&u[mi-1]==0;mi--){
      |       ^~~
main.c:1:14: error: expected '=', ',', ';', 'asm' or '__attribute__' before '&&' token
    1 |       for(;mi&&u[mi-1]==0;mi--){
      |              ^~
main.c:1:29: error: expected '=', ',', ';', 'asm' or '__attribute__' before '--' token
    1 |       for(;mi&&u[mi-1]==0;mi--){
      |                             ^~
main.c:6:5: error: expected identifier or '(' before '}' token
    6 |     }
      |     ^
main.c:7:5: error: expected identifier or '(' before 'else'
    7 |     else{
      |     ^~~~
main.c:14:3: error: expected identifier or '(' before '}' token
   14 |   }//printf("%d\n",r);
      |   ^
main.c:15:10: error: expected declaration specifiers or '...' before string constant
   15 |   printf("%d\n",r*2);
      |          ^~~~~~
main.c:15:17: error: unknown type name 'r'
   15 |   printf("%d\n",r*2);
      |                 ^
main.c:16:3: error: expected identifier or '(' before 'for'
   16 |   for(i=0;i<r;i++)printf("%d %d\n%d %d\n",a[i],b[i],a[i],b[i]);
      |   ^~~
main.c:16:12: error: expected '=', ',', ';', 'asm' or '__attribute__' before '<' token
   16 |   for(i=0;i<r;i++)printf("%d %d\n%d %d\n",a[i],b[i],a[i],b[i]);
      |            ^
main.c:16:16: error: expected '=', ',', ';', 'asm' or '__attribute__' before '++' token
   16 |   for(i=0;i<r;i++)printf("%d %d\n%d %d\n",a[i],b[i],a[i],b[i]);
      |                ^~
main.c:17:3: error: expected identifier or '(' before 'return'
   17 |   return 0;
      |   ^~~~~~
main.c:18:1: error: expected identifier or '(' before '}' token
   18 | }
      | ^