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>
using namespace std;
#define ll long long
#define ii pair<ll,ll>
#define fi first
#define se second
#define endl '\n'
#define rep(x,s,e) for (auto x=(s)-((s)>(e));x!=(e)-((s)>(e));((s)<(e)?x++:x--))
#define all(x) (x).begin(),(x).end()
#define sz(x) (int) (x).size()
#define puf push_front
#define pof pop_front
#define pub push_back
#define pob pop_back
#define lb lower_bound
#define ub upper_bound
mt19937 rng(123123);
int n;
int arr[1000005];
int level[1000005];
vector<int> pos[1000005];
vector<int> v;
vector<vector<int> > ans;
vector<int> stk;
int lis;
bool dfs(int i){
	stk.pub(i);
	
	if (level[i]==lis){
		ans.pub(stk);
		return true;
	}
	
	while (!pos[level[i]+1].empty() && pos[level[i]+1].back()<i) pos[level[i]+1].pob();
	
	while (!pos[level[i]+1].empty() && arr[i]<arr[pos[level[i]+1].back()]){
		bool temp=dfs(pos[level[i]+1].back());
		pos[level[i]+1].pob();
		
		if (temp){
			return true;
		}
	}
	
	stk.pob();
	
	return false;
}
int main(){
	cin.tie(0);
	cout.tie(0);
	cin.sync_with_stdio(false);
	
	cin>>n;
	rep(x,0,n) cin>>arr[x];
	
	rep(x,0,n){
		if (v.empty() || v.back()<arr[x]){
			level[x]=sz(v);
			v.pub(arr[x]);
		}
		else{
			int idx=lb(all(v),arr[x])-v.begin();
			level[x]=idx;
			v[idx]=arr[x];
		}
	}
	
	lis=sz(v)-1;
	
	rep(x,n,0){
		pos[level[x]].pub(x);
	}
	
	//rep(x,0,n) cout<<level[x]<<" "; cout<<endl;
	
	while (!pos[0].empty()){
		stk.clear();
		dfs(pos[0].back());
		pos[0].pob();
	}
	
	cout<<sz(ans)<<" "<<lis+1<<endl;
	for (auto &it:ans){
		for (auto &it2:it) cout<<it2+1<<" "; cout<<endl;
	}
}
Compilation message (stderr)
Main.cpp: In function 'int main()':
Main.cpp:96:3: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   96 |   for (auto &it2:it) cout<<it2+1<<" "; cout<<endl;
      |   ^~~
Main.cpp:96:40: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   96 |   for (auto &it2:it) cout<<it2+1<<" "; cout<<endl;
      |                                        ^~~~| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... |