This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
#define ll long long
#define fr first
#define se second
using namespace std;
set< pair< ll, ll > > st;
vector< pair<ll,pair< ll, ll> > > ans;
int main(){
ll n, k;
cin>>n>>k;
for( ll i =1 ; i <= n ; i ++ ){
    ll x;
    cin>>x;
    st.insert({x,i});
}
/***
std::pair<ll,ll> x;
x=*st.rbegin();
st.erase(x);
***/
while(st.size()>1){
        std::pair< ll , ll > x;
        x=*st.rbegin();
        st.erase(*st.rbegin());
        std::pair< ll , ll > y;
        y=*st.rbegin();
        st.erase(*st.rbegin());
        if( x.fr-1 != 0 ) st.insert({x.fr-1,x.se});
        if( y.fr-1 != 0 ) st.insert({y.fr-1,y.se});
        ans.push_back({1,{x.se,y.se}});
}
if( st.size() == 1 ){
    cout<<-1;
    return 0;
}
cout<<ans.size()<<endl;
for( ll i = 0; i < ans.size(); i  ++ ){
    cout<<ans[i].fr<<' '<<ans[i].se.fr<<' '<<ans[i].se.se<<endl;
}
}
Compilation message (stderr)
nicegift.cpp: In function 'int main()':
nicegift.cpp:37:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
 for( ll i = 0; i < ans.size(); i  ++ ){
                ~~^~~~~~~~~~~~| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... |