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

    int main(){
        int n;
        cin>>n;
        int arr[n];
        vector <int> v;
        for(int i=0;i<n;i++){
            cin>>arr[i];
        }
        int count=0;
        int c=0;
        int val=0;
        int i;
        map<int,int> m;
        for(i=0;i<n;i++){
            if(m[arr[i]==0]){
            m[arr[i]]++;
            val+=arr[i];
            if(val<0){
                cout<<-1<<endl;
                break;
            }
            else if(val==0){
                count++;
                v.push_back(count);
                count=0;
                c++;
            }
            else{
                count++;
            }
            }
            else{
                cout<<-1<<endl;
                break;
            }
        }
        if(i==n && val>0){
            cout<<-1<<endl;
        }
        else if(i==n && val==0){
            cout<<c<<endl;
            for(int i=0;i<v.size();i++){
                cout<<v[i]<<endl;
            }
        }

    }


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

    int main(){
        int n;
        cin>>n;
        int arr[n];
        vector <int> v;
        for(int i=0;i<n;i++){
            cin>>arr[i];
        }
        int count=0;
        int c=0;
        int val=0;
        int i;
        map<int,int> m;
        for(i=0;i<n;i++){
          if(m[arr[i]]<=c){
            m[arr[i]]++;
            val+=arr[i];
            if(val<0){
                cout<<-1<<endl;
                break;
            }
            else if(val==0){
                count++;
                v.push_back(count);
                count=0;
                c++;
            }
            else{
                count++;
            }
            }
            else{
                cout<<-1<<endl;
                break;
            }
        }
        if(i==n && val>0){
            cout<<-1<<endl;
        }
        else if(i==n && val==0){
            cout<<c<<endl;
            for(int i=0;i<v.size();i++){
                cout<<v[i]<<endl;
            }
        }

    }


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

    int main(){
        int n;
        cin>>n;
        int arr[n];
        vector <int> v;
        for(int i=0;i<n;i++){
            cin>>arr[i];
        }
        int count=0;
        int c=0;
        long long int val=0;
        int i;
        map<int,int> m;
        for(i=0;i<n;i++){
          if(m[arr[i]]<=c){
            m[arr[i]]++;
            val+=arr[i];
            if(val<0){
                cout<<-1<<endl;
                break;
            }
            else if(val==0){
                count++;
                v.push_back(count);
                count=0;
                c++;
            }
            else{
                count++;
            }
            }
            else{
                cout<<-1<<endl;
                break;
            }
        }
        if(i==n && val>0){
            cout<<-1<<endl;
        }
        else if(i==n && val==0){
            cout<<c<<endl;
            for(int i=0;i<v.size();i++){
                cout<<v[i]<<endl;
            }
        }

    }


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

    int main(){
        int n;
        cin>>n;
        long long int arr[n];
        vector <int> v;
        for(int i=0;i<n;i++){
            cin>>arr[i];
        }
        int count=0;
        int c=0;
        long long int val=0;
        int i;
        map<long long int,long long int> m;
        for(i=0;i<n;i++){
          if(m[arr[i]]==0){
            if(arr[i]<0 && m[abs(arr[i])]==0){
                cout<<-1<<endl;
                break;
            }
            m[arr[i]]++;
            val+=arr[i];
            if(val<0){
                cout<<-1<<endl;
                break;
            }
            else if(val==0){
                count++;
                v.push_back(count);
                count=0;
                c++;
                m.clear();
            }
            else{
                count++;
            }
            }
            else{
                cout<<-1<<endl;
                break;
            }
        }
        if(i==n && val>0){
            cout<<-1<<endl;
        }
        else if(i==n && val==0){
            cout<<c<<endl;
            for(int i=0;i<v.size();i++){
                cout<<v[i]<<endl;
            }
        }

    }


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

    int main(){
        int n;
        cin>>n;
        int arr[n];
        vector <int> v;
        for(int i=0;i<n;i++){
            cin>>arr[i];
        }
        int count=0;
        int c=0;
        int val=0;
        int i;
        for(i=0;i<n;i++){
            val+=arr[i];
            if(val<0){
                cout<<-1<<endl;
                break;
            }
            else if(val==0){
                v.push_back(count);
                count=0;
                c++;
            }
            else{
                count++;
            }
        }
        if(i==n && val>0){
            cout<<-1<<endl;
        }
        else if(i==n && val==0){
            cout<<c<<endl;
            for(int i=0;i<v.size();i++){
                cout<<v[i]<<endl;
            }
        }

    }


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

    int main(){
        int n;
        cin>>n;
        long long int arr[n];
        vector <int> v;
        for(int i=0;i<n;i++){
            cin>>arr[i];
        }
        int count=0;
        int c=0;
        long long int val=0;
        int i;
        map<long long int,long long int> m;
        for(i=0;i<n;i++){
          if(m[arr[i]]<=c){
            m[arr[i]]++;
            val+=arr[i];
            if(val<0){
                cout<<-1<<endl;
                break;
            }
            else if(val==0){
                count++;
                v.push_back(count);
                count=0;
                c++;
            }
            else{
                count++;
            }
            }
            else{
                cout<<-1<<endl;
                break;
            }
        }
        if(i==n && val>0){
            cout<<-1<<endl;
        }
        else if(i==n && val==0){
            cout<<c<<endl;
            for(int i=0;i<v.size();i++){
                cout<<v[i]<<endl;
            }
        }

    }


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

    int main(){
        int n;
        cin>>n;
        long long int arr[n];
        vector <int> v;
        for(int i=0;i<n;i++){
            cin>>arr[i];
        }
        int count=0;
        int c=0;
        long long int val=0;
        int i;
        map<long long int,long long int> m;
        for(i=0;i<n;i++){
          if(m[arr[i]]==0){
            m[arr[i]]++;
            val+=arr[i];
            if(val<0){
                cout<<-1<<endl;
                break;
            }
            else if(val==0){
                count++;
                v.push_back(count);
                count=0;
                c++;
                m.clear();
            }
            else{
                count++;
            }
            }
            else{
                cout<<-1<<endl;
                break;
            }
        }
        if(i==n && val>0){
            cout<<-1<<endl;
        }
        else if(i==n && val==0){
            cout<<c<<endl;
            for(int i=0;i<v.size();i++){
                cout<<v[i]<<endl;
            }
        }

    }


#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

set<ll> st;

int main()
{

	int n;
	cin>>n;

	int a[n+5];

	for(int i=1;i<=n;i++)cin>>a[i];

	vector<int> ind;
	int seg = 1;

	int op = 0;
	int cl = 0;
	ind.push_back(1);

	for(int i=1;i<=n;i++)
	{
		if(a[i]>0)
		{
			if(st.count(a[i])>0)
			{
				seg++;
				if(op!=cl)
				{
					cout<<-1<<'\n';
					return 0;
				}
				st.clear();
				ind.push_back(i);
				st.insert(a[i]);
				op = 0;
				cl = 0;
				op++;
			}
			else
			{
				st.insert(a[i]);
				op++;
			}
		}
		else
		{
			if(st.count(a[i])>0)
			{
				cout<<-1<<'\n';
				return 0;
			}
			if(st.count(-a[i])==0)
			{
				cout<<-1<<'\n';
				return 0;
			}
			if(st.count(-a[i])>0)
			{
				st.insert(a[i]);
				cl++;
			}
		}
	}
	//int oo = 0;
	//int cc = 0;

	ll sum = 0;

	for(ll ele: st)
	{
		sum+=ele;
	}
	if(sum!=0)
	{
		if(n==100000)
		{
			cout<<"YO"<<'\n';
		}
		cout<<-1<<'\n';
		return 0;
	}
	ind.push_back(n+1);
	cout<<seg<<'\n';
	for(int i=0;i<ind.size()-1;i++)
	{
		cout<<abs(ind[i]-ind[i+1])<<" ";
	}
	cout<<endl;
	return 0;
}


#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

map<int,int> pos;
map<int,int> neg;

int main()
{

	int n;
	cin>>n;

	int a[n+5];

	for(int i=1;i<=n;i++)
		cin>>a[i];

	int seg = 1;
	int open = 0;
	int close = 0;

	int seg_start = 1;

	vector<int> ind;
	ind.push_back(seg_start);
	for(int i=1;i<=n;i++)
	{
		if(a[i]>0)
		{
			if(pos.count(a[i])>0)
			{
				seg++;
				if(open!=close)
				{
					cout<<-1<<'\n';
					return 0;
				}
				seg_start = i;
				ind.push_back(seg_start);
				pos[a[i]]=i;
				open++;
			}
			else
			{
				pos[a[i]]=i;
				open++;
			}
		}
		else
		{
			if(pos[(-1)*a[i]]<seg_start || pos.count((-1)*a[i])==0)
			{
				cout<<-1<<'\n';
				return 0;
			}
			if(neg[(-1)*a[i]]>seg_start)
			{
				cout<<-1<<'\n';
				return 0;
			}
			neg[(-1)*a[i]]=i;
			close++;
		}

	}
	if(open!=close)
	{
		cout<<-1<<'\n';
		return 0;
	}

	ind.push_back(n+1);

	cout<<seg<<'\n';
	for(int i=0;i<ind.size()-1;i++)
	{
		cout<<abs(ind[i]-ind[i+1])<<" ";
	}
	cout<<endl;
	return 0;
}


#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

set<int> st;

int main()
{

	int n;
	cin>>n;

	int a[n+5];

	for(int i=1;i<=n;i++)cin>>a[i];

	vector<int> ind;
	int seg = 1;

	int op = 0;
	int cl = 0;
	ind.push_back(1);

	for(int i=1;i<=n;i++)
	{
		if(a[i]>0)
		{
			if(st.count(a[i])>0)
			{
				seg++;
				if(op!=cl)
				{
					cout<<-1<<'\n';
					return 0;
				}
				st.clear();
				ind.push_back(i);
				st.insert(a[i]);
				op = 0;
				cl = 0;
				op++;
			}
			else
			{
				st.insert(a[i]);
				op++;
			}
		}
		else
		{
			if(st.count(a[i])>0)
			{
				cout<<-1<<'\n';
				return 0;
			}
			if(st.count(-a[i])==0)
			{
				cout<<-1<<'\n';
				return 0;
			}
			if(st.count(-a[i])>0)
			{
				st.insert(a[i]);
				cl++;
			}
		}
	}
	if(op!=cl)
	{	cout<<-1<<'\n';
		return 0;
	}
	ind.push_back(n+1);
	cout<<seg<<'\n';
	for(int i=0;i<ind.size()-1;i++)
	{
		cout<<abs(ind[i]-ind[i+1])<<" ";
	}
	cout<<endl;
	return 0;
}


#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

map<int,int> pos;
map<int,int> neg;

int main()
{
	int n;
	cin>>n;
	int a[n+5];
	for(int i=1;i<=n;i++)
		cin>>a[i];
	int seg = 1;
	int open = 0;
	int close = 0;
	int seg_start = 1;
	vector<int> ind;
	ind.push_back(seg_start);

	for(int i=1;i<=n;i++)
	{
		if(a[i]>0)
		{
			if(pos.count(a[i])>0 && pos[a[i]]>=seg_start)
			{
				seg++;
				if(open!=close)
				{
					cout<<-1<<'\n';
					return 0;
				}
				seg_start = i;
				ind.push_back(seg_start);
				pos[a[i]]=i;
				open++;
			}
			else
			{
				pos[a[i]]=i;
				open++;
			}
		}
		else
		{
			if(pos.count((-1)*a[i])==0)
			{
				cout<<-1<<'\n';
				return 0;
			}
			if(pos[(-1)*a[i]]<seg_start)
			{
				cout<<-1<<'\n';
				return 0;
			}
			if(neg[(-1)*a[i]]>seg_start)
			{
				cout<<-1<<'\n';
				return 0;
			}
			neg[(-1)*a[i]]=i;
			close++;
		}

	}
	if(open!=close)
	{
		cout<<-1<<'\n';
		return 0;
	}

	ind.push_back(n+1);

	cout<<seg<<'\n';
	for(int i=0;i<ind.size()-1;i++)
	{
		cout<<abs(ind[i]-ind[i+1])<<" ";
	}
	cout<<endl;
	return 0;
}


#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

set<int> st;

int main()
{

	int n;
	cin>>n;

	int a[n+5];

	for(int i=1;i<=n;i++)cin>>a[i];

	vector<int> ind;
	int seg = 1;

	int op = 0;
	int cl = 0;
	ind.push_back(1);

	for(int i=1;i<=n;i++)
	{
		if(a[i]>0)
		{
			if(st.count(a[i])>0)
			{
				seg++;
				if(op!=cl)
				{
					cout<<-1<<'\n';
					return 0;
				}
				st.clear();
				ind.push_back(i);
				st.insert(a[i]);
				op = 0;
				cl = 0;
				op++;
			}
			else
			{
				st.insert(a[i]);
				op++;
			}
		}
		else
		{
			if(st.count(a[i])>0)
			{
				cout<<-1<<'\n';
				return 0;
			}
			if(st.count(-a[i])==0)
			{
				cout<<-1<<'\n';
				return 0;
			}
			if(st.count(-a[i])>0)
			{
				st.insert(a[i]);
				cl++;
			}
		}
	}
	//int oo = 0;
	//int cc = 0;

	ll sum = 0;

	for(int ele: st)
	{
		sum+=ele;
	}
	if(sum!=0)
	{
		cout<<-1<<'\n';
		return 0;
	}
	ind.push_back(n+1);
	cout<<seg<<'\n';
	for(int i=0;i<ind.size()-1;i++)
	{
		cout<<abs(ind[i]-ind[i+1])<<" ";
	}
	cout<<endl;
	return 0;
}


#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

set<ll> st;

int main()
{

	int n;
	cin>>n;

	int a[n+5];

	for(int i=1;i<=n;i++)cin>>a[i];

	vector<int> ind;
	int seg = 0;

	int op = 0;
	int cl = 0;
	ind.push_back(1);
	for(int i=1;i<=n;i++)
	{
		if(a[i]>0)
		{
			if(st.count(a[i])>0)
			{
				cout<<-1<<'\n';
				return 0;
			}
			else
			{
				st.insert(a[i]);
				op++;
			}
		}
		else
		{
			if(st.count(a[i])>0)
			{
				cout<<-1<<'\n';
				return 0;
			}
			if(st.count(-a[i])==0)
			{
				cout<<-1<<'\n';
				return 0;
			}
			if(st.count(-a[i])>0)
			{
				st.insert(a[i]);
				cl++;
				if(op==cl)
				{
				seg++;
				st.clear();
				ind.push_back(i+1);
				}
			}
		}

	}
	ll sum = 0;
	for(ll ele: st)
	{
		sum+=ele;
	}
	if(sum!=0)
	{
		cout<<-1<<'\n';
		return 0;
	}
	cout<<seg<<'\n';
	for(int i=0;i<ind.size()-1;i++)
	{
		cout<<abs(ind[i]-ind[i+1])<<" ";
	}
	cout<<endl;
	return 0;
}


#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

map<int,int> pos;
map<int,int> neg;

int main()
{

	int n;
	cin>>n;

	int a[n+5];

	for(int i=1;i<=n;i++)
		cin>>a[i];

	int seg = 1;
	int open = 0;
	int close = 0;

	int seg_start = 1;

	vector<int> ind;
	ind.push_back(seg_start);
	for(int i=1;i<=n;i++)
	{
		if(a[i]>0)
		{
			if(pos.count(a[i])>0)
			{
				seg++;
				if(open!=close)
				{
					cout<<-1<<'\n';
					return 0;
				}
				seg_start = i;
				ind.push_back(seg_start);
				pos[a[i]]=i;
			}
			else
			{
				pos[a[i]]=i;
				open++;
			}
		}
		else
		{
			if(pos[(-1)*a[i]]<seg_start || pos.count((-1)*a[i])==0)
			{
				cout<<-1<<'\n';
				return 0;
			}
			if(neg[(-1)*a[i]]>seg_start)
			{
				cout<<-1<<'\n';
				return 0;
			}
			neg[(-1)*a[i]]=i;
			close++;
		}

	}
	ind.push_back(n+1);

	cout<<seg<<'\n';
	for(int i=0;i<ind.size()-1;i++)
	{
		cout<<abs(ind[i]-ind[i+1])<<" ";
	}
	cout<<endl;
	return 0;
}


#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

set<ll> st;

int main()
{

	int n;
	cin>>n;

	int a[n+5];

	for(int i=1;i<=n;i++)cin>>a[i];

	vector<int> ind;
	int seg = 0;

	int op = 0;
	int cl = 0;
	ind.push_back(1);
	for(int i=1;i<=n;i++)
	{
		if(a[i]>0)
		{
			if(st.count(a[i])>0)
			{

				op = 0;
				cl = 0;
				op++;
			}
			else
			{
				st.insert(a[i]);
				op++;
			}
		}
		else
		{
			if(st.count(a[i])>0)
			{
				cout<<-1<<'\n';
				return 0;
			}
			if(st.count(-a[i])==0)
			{
				cout<<-1<<'\n';
				return 0;
			}
			if(st.count(-a[i])>0)
			{
				st.insert(a[i]);
				cl++;
				if(op==cl)
				{
				seg++;
				st.clear();
				ind.push_back(i+1);
				}
			}
		}

	}

	ll sum = 0;

	for(ll ele: st)
	{
		sum+=ele;
	}
	if(sum!=0)
	{
		cout<<-1<<'\n';
		return 0;
	}
	//ind.push_back(n+1);
	cout<<seg<<'\n';
	for(int i=0;i<ind.size()-1;i++)
	{
		cout<<abs(ind[i]-ind[i+1])<<" ";
	}
	cout<<endl;
	return 0;
}


#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

map<int,int> pos;
map<int,int> neg;

int main()
{

	int n;
	cin>>n;

	int a[n+5];

	for(int i=1;i<=n;i++)
		cin>>a[i];

	int seg = 1;
	int open = 0;
	int close = 0;

	int seg_start = 1;

	vector<int> ind;
	ind.push_back(seg_start);
	for(int i=1;i<=n;i++)
	{
		if(a[i]>0)
		{
			if(pos.count(a[i])>0 && pos[a[i]]>=seg_start)
			{
				seg++;
				if(open!=close)
				{
					cout<<-1<<'\n';
					return 0;
				}
				seg_start = i;
				ind.push_back(seg_start);
				pos[a[i]]=i;
				open++;
			}
			else
			{
				pos[a[i]]=i;
				open++;
			}
		}
		else
		{
			if(pos[(-1)*a[i]]<seg_start || pos.count((-1)*a[i])==0)
			{
				cout<<-1<<'\n';
				return 0;
			}
			if(neg[(-1)*a[i]]>seg_start)
			{
				cout<<-1<<'\n';
				return 0;
			}
			neg[(-1)*a[i]]=i;
			close++;
		}

	}
	if(open!=close)
	{
		cout<<-1<<'\n';
		return 0;
	}

	ind.push_back(n+1);

	cout<<seg<<'\n';
	for(int i=0;i<ind.size()-1;i++)
	{
		cout<<abs(ind[i]-ind[i+1])<<" ";
	}
	cout<<endl;
	return 0;
}


#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

set<ll> st;

int main()
{

	int n;
	cin>>n;

	int a[n+5];

	for(int i=1;i<=n;i++)cin>>a[i];

	vector<int> ind;
	int seg = 1;

	int op = 0;
	int cl = 0;
	ind.push_back(1);

	for(int i=1;i<=n;i++)
	{
		if(a[i]>0)
		{
			if(st.count(a[i])>0)
			{
				seg++;
				if(op!=cl)
				{
					cout<<-1<<'\n';
					return 0;
				}
				st.clear();
				ind.push_back(i);
				st.insert(a[i]);
				op = 0;
				cl = 0;
				op++;
			}
			else
			{
				st.insert(a[i]);
				op++;
			}
		}
		else
		{
			if(st.count(a[i])>0)
			{
				cout<<-1<<'\n';
				return 0;
			}
			if(st.count(-a[i])==0)
			{
				cout<<-1<<'\n';
				return 0;
			}
			if(st.count(-a[i])>0)
			{
				st.insert(a[i]);
				cl++;
			}
		}
	}
	//int oo = 0;
	//int cc = 0;

	ll sum = 0;

	for(ll ele: st)
	{
		sum+=ele;
	}
	if(sum!=0)
	{
			cout<<"YO"<<'\n';

		cout<<-1<<'\n';
		return 0;
	}
	ind.push_back(n+1);
	cout<<seg<<'\n';
	for(int i=0;i<ind.size()-1;i++)
	{
		cout<<abs(ind[i]-ind[i+1])<<" ";
	}
	cout<<endl;
	return 0;
}


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

typedef long long ll;

#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define forr(i,m,n) for(ll i=m;i<n;i++)
#define testcase int t;cin>>t;while(t--)
#define all(v) v.begin(),v.end()
#define rev(v) v.rbegin(),v.rend()
#define pb push_back
#define mp make_pair
#define endl "\n"
#define print(v) forr(i,0,v.size())cout<<v[i]<<" ";cout<<endl;
#define print_map(m) for(auto it=m.begin(); it!=m.end();it++) cout<<(*it).first<<" "<<(*it).second<<endl;
#define vi vector<int>
#define vl vector<ll>
#define vp vector< pair<ll, ll> >

const int M = 1e9+7;

ll maxi(ll a, ll b){
	if(a>b) return a;
	return b;
}

ll mini(ll a, ll b){
	if(a>b) return b;
	return a;
}

int main(){
	fastio
	int n; cin>>n;
	vector<bool> arr(1000000+5,0); int sum=0;
	int tt; vi ans;
	int arr_chk=0;
	bool flag=true;
	map<int, int> m;
	forr(i,0,n){
		cin>>tt;
		if(tt>0){
			arr[tt]=1; sum++; m[tt]++;
			if(m[tt]>1) {flag=false; break;}
		}
		if(tt<0){
			if(arr[-tt]==0) {flag=false; break;}
			arr[-tt]=0; sum--;
		}
		if(sum==0){
			m.clear();
			if(ans.size()==0) {ans.pb(i+1); arr_chk=i+1;}
			else {ans.pb(i+1-arr_chk); arr_chk=i+1;}
			// print(ans);
		}
	}
	if(flag){
		cout<<ans.size()<<endl;
		print(ans);
	}
	else cout<<-1<<endl;
	return 0;
}


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

typedef long long ll;

#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define forr(i,m,n) for(ll i=m;i<n;i++)
#define testcase int t;cin>>t;while(t--)
#define all(v) v.begin(),v.end()
#define rev(v) v.rbegin(),v.rend()
#define pb push_back
#define mp make_pair
#define endl "\n"
#define print(v) forr(i,0,v.size())cout<<v[i]<<" ";cout<<endl;
#define print_map(m) for(auto it=m.begin(); it!=m.end();it++) cout<<(*it).first<<" "<<(*it).second<<endl;
#define vi vector<int>
#define vl vector<ll>
#define vp vector< pair<ll, ll> >

const int M = 1e9+7;

ll maxi(ll a, ll b){
	if(a>b) return a;
	return b;
}

ll mini(ll a, ll b){
	if(a>b) return b;
	return a;
}

int main(){
	fastio
	int n; cin>>n;
	vector<bool> arr(1000000+5,0); ll sum=0;
	int tt; vi ans;
	int arr_chk=0;
	bool flag=true;
	map<int, int> m;
	forr(i,0,n){
		cin>>tt;
		if(tt>0){
			arr[tt]=1; sum++; m[tt]++;
			if(m[tt]>1) {flag=false; break;}
		}
		if(tt<0){
			m[tt]++;
			if(m[tt]>1) {flag=false; break;}
			if(arr[-tt]==0) {flag=false; break;}
			arr[-tt]=0; sum--;
		}
		if(sum==0){
			m.clear();
			if(ans.size()==0) {ans.pb(i+1); arr_chk=i+1;}
			else {ans.pb(i+1-arr_chk); arr_chk=i+1;}
			// print(ans);
		}
	}
	if(sum==0){
		cout<<1<<endl<<n<<endl;
	}
	if(flag){
		cout<<ans.size()<<endl;
		print(ans);
	}
	else cout<<-1<<endl;
	return 0;
}


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

typedef long long ll;

#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define forr(i,m,n) for(ll i=m;i<n;i++)
#define testcase int t;cin>>t;while(t--)
#define all(v) v.begin(),v.end()
#define rev(v) v.rbegin(),v.rend()
#define pb push_back
#define mp make_pair
#define endl "\n"
#define print(v) forr(i,0,v.size())cout<<v[i]<<" ";cout<<endl;
#define print_map(m) for(auto it=m.begin(); it!=m.end();it++) cout<<(*it).first<<" "<<(*it).second<<endl;
#define vi vector<int>
#define vl vector<ll>
#define vp vector< pair<ll, ll> >

const int M = 1e9+7;

ll maxi(ll a, ll b){
	if(a>b) return a;
	return b;
}

ll mini(ll a, ll b){
	if(a>b) return b;
	return a;
}

int main(){
	// fastio
	int tt; bool flag=true; vi ans; int sum=0, arr_chk=0; vi v(1000000+5,0);
	int n; cin>>n;
	forr(i,1,n+1){
		cin>>tt;
		if(tt>0){
			if(v[tt]>0) {flag=false; break;}
			v[tt]=1; sum++;
		}
		if(tt<0){
			if(v[-tt]>1) {flag=false; break;}
			v[-tt]=2; sum--;
		}
		if(sum<0) {flag=false; break;}
		if(sum==0){
			ans.pb(i-arr_chk); arr_chk=i;
			v.clear(); v.resize(1000000+5, 0);
			// print(ans);
		}
	}
	if(flag){
		cout<<ans.size()<<endl;
		print(ans);
	}
	else cout<<-1<<endl;
	return 0;
}


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

typedef long long ll;

#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define forr(i,m,n) for(ll i=m;i<n;i++)
#define testcase int t;cin>>t;while(t--)
#define all(v) v.begin(),v.end()
#define rev(v) v.rbegin(),v.rend()
#define pb push_back
#define mp make_pair
#define endl "\n"
#define print(v) forr(i,0,v.size())cout<<v[i]<<" ";cout<<endl;
#define print_map(m) for(auto it=m.begin(); it!=m.end();it++) cout<<(*it).first<<" "<<(*it).second<<endl;
#define vi vector<int>
#define vl vector<ll>
#define vp vector< pair<ll, ll> >

const int M = 1e9+7;

ll maxi(ll a, ll b){
	if(a>b) return a;
	return b;
}

ll mini(ll a, ll b){
	if(a>b) return b;
	return a;
}

int main(){
	fastio
	int n; cin>>n;
	vector<bool> arr(1000000+5,0); int sum=0;
	int tt; vi ans;
	int arr_chk=0;
	bool flag=true;
	map<int, int> m;
	forr(i,0,n){
		cin>>tt;
		if(tt>0){
			arr[tt]=1; sum++; m[tt]++;
			if(m[tt]>1) {flag=false; break;}
		}
		if(tt<0){
			if(arr[-tt]==0) {flag=false; break;}
			arr[-tt]=0; sum--;
		}
		if(sum==0){
			m.clear();
			if(ans.size()==0) {ans.pb(i+1); arr_chk=i+1;}
			else {ans.pb(i+1-arr_chk); arr_chk=i+1;}
			// print(ans);
		}
	}
	if(sum!=0) flag=false;
	if(flag){
		cout<<ans.size()<<endl;
		print(ans);
	}
	else cout<<-1<<endl;
	return 0;
}


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

typedef long long ll;

#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define forr(i,m,n) for(ll i=m;i<n;i++)
#define testcase int t;cin>>t;while(t--)
#define all(v) v.begin(),v.end()
#define rev(v) v.rbegin(),v.rend()
#define pb push_back
#define mp make_pair
#define endl "\n"
#define print(v) forr(i,0,v.size())cout<<v[i]<<" ";cout<<endl;
#define print_map(m) for(auto it=m.begin(); it!=m.end();it++) cout<<(*it).first<<" "<<(*it).second<<endl;
#define vi vector<int>
#define vl vector<ll>
#define vp vector< pair<ll, ll> >

const int M = 1e9+7;

ll maxi(ll a, ll b){
	if(a>b) return a;
	return b;
}

ll mini(ll a, ll b){
	if(a>b) return b;
	return a;
}

int main(){
	// fastio
	int tt; bool flag=true; vi ans; int sum=0, arr_chk=0; vi v(1000000+5,0);
	int n; cin>>n;
	forr(i,1,n+1){
		cin>>tt;
		if(tt>0){
			if(v[tt]>0) {flag=false; break;}
			v[tt]=1; sum++;
		}
		if(tt<0){
			if(v[-tt]>1) {flag=false; break;}
			v[-tt]=2; sum--;
		}
		if(sum<0) {flag=false; break;}
		if(sum==0){
			ans.pb(i-arr_chk); arr_chk=i;
			v.clear(); v.resize(1000000+5, 0);
			// print(ans);
		}
	}
	if(sum!=0) flag=false;
	if(flag){
		cout<<ans.size()<<endl;
		print(ans);
	}
	else cout<<-1<<endl;
	return 0;
}


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

typedef long long ll;

#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define forr(i,m,n) for(ll i=m;i<n;i++)
#define testcase int t;cin>>t;while(t--)
#define all(v) v.begin(),v.end()
#define rev(v) v.rbegin(),v.rend()
#define pb push_back
#define mp make_pair
#define endl "\n"
#define print(v) forr(i,0,v.size())cout<<v[i]<<" ";cout<<endl;
#define print_map(m) for(auto it=m.begin(); it!=m.end();it++) cout<<(*it).first<<" "<<(*it).second<<endl;
#define vi vector<int>
#define vl vector<ll>
#define vp vector< pair<ll, ll> >

const int M = 1e9+7;

ll maxi(ll a, ll b){
	if(a>b) return a;
	return b;
}

ll mini(ll a, ll b){
	if(a>b) return b;
	return a;
}

int main(){
	fastio
	int n; cin>>n;
	vector<bool> arr(1000000+5,0); ll sum=0;
	int tt; vi ans;
	int arr_chk=0;
	bool flag=true;
	map<int, int> m;
	forr(i,0,n){
		cin>>tt;
		if(tt>0){
			if(arr[tt]==1) {flag=false; break;}
			arr[tt]=1; sum++; m[tt]++;
			if(m[tt]>1) {flag=false; break;}
		}
		if(tt<0){
			m[tt]++;
			if(m[tt]>1) {flag=false; break;}
			if(arr[-tt]==0) {flag=false; break;}
			arr[-tt]=0; sum--;
		}
		if(sum==0){
			m.clear();
			if(ans.size()==0) {ans.pb(i+1); arr_chk=i+1;}
			else {ans.pb(i+1-arr_chk); arr_chk=i+1;}
			// print(ans);
		}
	}
	if(flag){
		cout<<ans.size()<<endl;
		print(ans);
	}
	else cout<<-1<<endl;
	return 0;
}


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

typedef long long ll;

#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define forr(i,m,n) for(ll i=m;i<n;i++)
#define testcase int t;cin>>t;while(t--)
#define all(v) v.begin(),v.end()
#define rev(v) v.rbegin(),v.rend()
#define pb push_back
#define mp make_pair
#define endl "\n"
#define print(v) forr(i,0,v.size())cout<<v[i]<<" ";cout<<endl;
#define print_map(m) for(auto it=m.begin(); it!=m.end();it++) cout<<(*it).first<<" "<<(*it).second<<endl;
#define vi vector<int>
#define vl vector<ll>
#define vp vector< pair<ll, ll> >

const int M = 1e9+7;

ll maxi(ll a, ll b){
	if(a>b) return a;
	return b;
}

ll mini(ll a, ll b){
	if(a>b) return b;
	return a;
}

int main(){
	fastio
	int tt; bool flag=true; vi ans; int sum=0, arr_chk=0; vi v(1000000+5,0);
	int n; cin>>n;
	forr(i,1,n+1){
		cin>>tt;
		if(tt>0){
			if(v[tt]>0) {flag=false; break;}
			v[tt]=1; sum++;
		}
		if(tt<0){
			if(v[-tt]>1) {flag=false; break;}
			v[-tt]=2; sum--;
		}
		if(sum<0) {flag=false; break;}
		if(sum==0){
			ans.pb(i-arr_chk); arr_chk=i;
			v.clear(); v.resize(1000000+5, 0);
			// print(ans);
		}
	}
	if(sum!=0) flag=false;
	if(flag){
		cout<<ans.size()<<endl;
		print(ans);
	}
	else cout<<-1<<endl;
	return 0;
}


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

typedef long long ll;

#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define forr(i,m,n) for(ll i=m;i<n;i++)
#define testcase int t;cin>>t;while(t--)
#define all(v) v.begin(),v.end()
#define rev(v) v.rbegin(),v.rend()
#define pb push_back
#define mp make_pair
#define endl "\n"
#define print(v) forr(i,0,v.size())cout<<v[i]<<" ";cout<<endl;
#define print_map(m) for(auto it=m.begin(); it!=m.end();it++) cout<<(*it).first<<" "<<(*it).second<<endl;
#define vi vector<int>
#define vl vector<ll>
#define vp vector< pair<ll, ll> >

const int M = 1e9+7;

ll maxi(ll a, ll b){
	if(a>b) return a;
	return b;
}

ll mini(ll a, ll b){
	if(a>b) return b;
	return a;
}

int main(){
	fastio
	int n; cin>>n;
	vector<bool> arr(1000000+5,0); ll sum=0;
	int tt; vi ans;
	int arr_chk=0;
	bool flag=true;
	map<int, int> m;
	forr(i,0,n){
		cin>>tt;
		if(tt>0){
			arr[tt]=1; sum++; m[tt]++;
			if(m[tt]>1) {flag=false; break;}
		}
		if(tt<0){
			m[tt]++;
			if(m[tt]>1) {flag=false; break;}
			if(arr[-tt]==0) {flag=false; break;}
			arr[-tt]=0; sum--;
		}
		if(sum==0){
			m.clear();
			if(ans.size()==0) {ans.pb(i+1); arr_chk=i+1;}
			else {ans.pb(i+1-arr_chk); arr_chk=i+1;}
			// print(ans);
		}
	}
	if(sum==0){
		cout<<1<<endl<<n<<endl;
	}
	else if(flag){
		cout<<ans.size()<<endl;
		print(ans);
	}
	else cout<<-1<<endl;
	return 0;
}


 #include<bits/stdc++.h>
using namespace std;
#define MAX 1.25
#define ll long long
#define power(x) (ceil(log2(x))==floor(log2(x)))?1:0

int main(){

ll int n;
cin>>n;
ll int a[n];

ll sum =0 , pos=0;
for(ll int i=0;i<n;i++){
    cin>>a[i];
    sum = sum + a[i];
if(a[i]>0)
    pos++;
}
if(sum!=0 || pos!=(n/2)){
    cout<<"-1";
    return 0;
}
map<int ll , int ll>m;
vector<int ll> ans;
ll int prev=0;

for(ll int i=0;i<n;i++){
    if(a[i]>0){
        if(m[a[i]]==1){
//        cout<<"-1";
//        return 0;
if(m[-1*a[i]]==0){
    cout<<"-1";
    return 0;
}
ans.push_back(i-prev);
prev=i;
m.clear();
m[a[i]] =1;
        }
        else{
            m[a[i]]=1;
        }

    }
    else{
        if(m[(-1*a[i])]==0){
                //cout<<i<<endl;
            cout<<"-1";
            return 0;
        }

        else if(m[a[i]]==1){
 cout<<"-1";
            return 0;
        }
        else{
            m[a[i]]=1;
        }
    }
}
//
//m.clear();
//ans.clear();
//for(ll int i=0;i<n;i++){
//        if(m.size()==0 && i!=0){
//            ans.push_back(i-prev);
//prev=i;
//        }
//if(a[i]>0){
//    if(m[a[i]]==0){
//        m[a[i]]=1;
//    }
//    else{
//       cout<<"-1";
//        return 0;
//}
//}
//else{
//    if(m[-1*a[i]]==1){
//        m.erase(-1*a[i]);
//    }
//    else{
//        cout<<"-1";
//        return 0;
//    }
//}
//}

if(ans.size()==0)
	{
		cout<<1<<"\n"<<n;

	}
	else
	{
		cout<<ans.size()+1<<endl;
	    for(ll i=0;i<ans.size();++i)
	    {
	    	cout<<ans[i]<<" ";
	    }
	    cout<<n-prev<<"\n";

	}

}


#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define N 2000
#define ll long long

map<int , bool> en , ex;
int main(){
//int t;
//cin>>t;
//while(t--)
    {
    int n , k, sum=0;
    cin>>n;
    int a[n];
    map<int , int> mp;
    for(int i=0;i<n;i++){
        cin>>a[i];

    }

   vector<int> ans;
   if(a[0]>0){sum++; en[a[0]]=true;}
   else {cout<<"-1"; return 0;}

    for(int i=1;i<n;i++){

 if(a[i]>0){
    if(en.find(a[i])!=en.end()){
        ans.clear();
        cout<<"-1\n";
        return 0;
    }
    en[a[i]]=true;
    ex[a[i]]=false;
    sum++;
 }
 else{
if(en.find(-a[i])==en.end() || ex.find(-a[i])!=ex.end()){cout<<"-1"; return 0;}
sum--;
ex[-a[i]]=true;

 }
  if(sum==0){
    ans.push_back(i+1);
   en.clear();
   ex.clear();
}

    }
if((ans.size()==0) || (sum!=0)){
    cout<<"-1";
    return 0;
}
    cout<<ans.size()<<endl;
    cout<<ans[0]<<" ";
    for(int i=1;i<ans.size();i++)cout<<ans[i] - ans[i-1]<<" ";
return 0;

    }}


 #include<bits/stdc++.h>
using namespace std;
#define MAX 1.25
#define ll long long
#define power(x) (ceil(log2(x))==floor(log2(x)))?1:0

int main(){

ll int n;
cin>>n;
ll int a[n];

ll sum =0 , pos=0;
for(ll int i=0;i<n;i++){
    cin>>a[i];
    sum = sum + a[i];
if(a[i]>0)
    pos++;
}
if(sum!=0 || pos!=(n/2)){
    cout<<"-1";
    return 0;
}
map<int ll , int ll>m;
vector<int ll> ans;
ll int prev=0;

for(ll int i=0;i<n;i++){
    if(a[i]>0){
        if(m[a[i]]==1){
//        cout<<"-1";
//        return 0;
ans.push_back(i-prev);
prev=i;
m.clear();
m[a[i]=1;
        }
        else{
            m[a[i]]=1;
        }

    }
    else{
        if(m[(-1*a[i])]==0){
                //cout<<i<<endl;
            cout<<"-1";
            return 0;
        }

        else if(m[a[i]]!=0){
 cout<<"-1";
            return 0;
        }
        else{
            m[a[i]]=1;
        }
    }
}

if(ans.size()==0)
	{
		cout<<1<<"\n"<<n;

	}
	else
	{
		cout<<ans.size()+1<<endl;
	    for(ll i=0;i<ans.size();++i)
	    {
	    	cout<<ans[i]<<" ";
	    }
	    cout<<n-prev<<"\n";

	}

}


#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define N 2000
#define ll long long

map<int , bool> en , ex;
int main(){
//int t;
//cin>>t;
//while(t--)
    {
    int n , k, sum=0;
    cin>>n;
    int a[n];
    map<int , int> mp;
    for(int i=0;i<n;i++){
        cin>>a[i];

    }

   vector<int> ans;
   if(a[0]>0){sum++; en[a[0]]=true;}
   else {cout<<"-1"; return 0;}

    for(int i=1;i<n;i++){

 if(a[i]>0){
    if(en.find(a[i])!=en.end()){
        ans.clear();
        cout<<"-1\n";
        return 0;
    }
    en[a[i]]=true;
    ex[a[i]]=false;
    sum++;
 }
 else{
if((en.find(-a[i])==en.end()) || (ex[-a[i]]==true)){cout<<"-1";
//cout<<a[i]<<endl;
return 0;}
sum--;
ex[-a[i]]=true;

 }
  if(sum==0){
    ans.push_back(i+1);
   en.clear();
   ex.clear();
}

    }
if((ans.size()==0) || (sum!=0)){
    cout<<"-1";
    return 0;
}
    cout<<ans.size()<<endl;
    cout<<ans[0]<<" ";
    for(int i=1;i<ans.size();i++)cout<<ans[i] - ans[i-1]<<" ";
return 0;

    }}


 #include<bits/stdc++.h>
using namespace std;
#define MAX 1.25
#define ll long long
#define power(x) (ceil(log2(x))==floor(log2(x)))?1:0

int main(){

ll int n;
cin>>n;
ll int a[n];

ll sum =0 , pos=0;
for(ll int i=0;i<n;i++){
    cin>>a[i];
    sum = sum + a[i];
if(a[i]>0)
    pos++;
}
if(sum!=0 || pos!=(n/2)){
    cout<<"-1";
    return 0;
}
map<int ll , int ll>m;
vector<int ll> ans;
ll int prev=0;

for(ll int i=0;i<n;i++){
    if(a[i]>0){
        if(m[a[i]]==1){
//        cout<<"-1";
//        return 0;
ans.push_back(i-prev);
prev=i;
m.clear();
        }
        else{
            m[a[i]]=1;
        }

    }
    else{
        if(m[(-1*a[i])]==0){
            cout<<"-1";
            return 0;
        }

        else if(m[a[i]]!=0){
 cout<<"-1";
            return 0;
        }
        else{
            m[a[i]]=1;
        }
    }
}

if(ans.size()==0)
	{
		cout<<1<<"\n"<<n;

	}
	else
	{
		cout<<ans.size()+1<<endl;
	    for(ll i=0;i<ans.size();++i)
	    {
	    	cout<<ans[i]<<" ";
	    }
	    cout<<n-prev<<"\n";

	}

}


#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define N 2000
#define ll long long

map<int , bool> en , ex;
int main(){
//int t;
//cin>>t;
//while(t--)
    {
    int n , k, sum=0;
    cin>>n;
    int a[n];
    map<int , int> mp;
    for(int i=0;i<n;i++){
        cin>>a[i];

    }

   vector<int> ans;
   if(a[0]>0){sum++; en[a[0]]=true;}
   else {cout<<"-1"; return 0;}

    for(int i=1;i<n;i++){

 if(a[i]>0){
    if(en.find(a[i])!=en.end()){
        ans.clear();
        cout<<"-1\n";
        return 0;
    }
    en[a[i]]=true;
    ex[a[i]]=false;
    sum++;
 }
 else{
if(en.find(-a[i])==en.end()){cout<<"-1"; return 0;}
sum--;
ex[-a[i]]=true;

 }
  if(sum==0){
    ans.push_back(i+1);
   en.clear();
   ex.clear();
}

    }

    cout<<ans.size()<<endl;
    cout<<ans[0]<<" ";
    for(int i=1;i<ans.size();i++)cout<<ans[i] - ans[i-1]<<" ";
return 0;

    }}


#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define N 2000
#define ll long long

map<int , bool> en , ex;
int main(){
//int t;
//cin>>t;
//while(t--)
    {
    int n , k, sum=0;
    cin>>n;
    int a[n];
    map<int , int> mp;
    for(int i=0;i<n;i++){
        cin>>a[i];

    }

   vector<int> ans;
   if(a[0]>0){sum++; en[a[0]]=true;}
   else {cout<<"-1"; return 0;}

    for(int i=1;i<n;i++){

 if(a[i]>0){
    if(en.find(a[i])!=en.end()){
        ans.clear();
        cout<<"-1\n";
        return 0;
    }
    en[a[i]]=true;
    ex[a[i]]=false;
    sum++;
 }
 else{
if(en.find(-a[i])==en.end()){cout<<"-1"; return 0;}
sum--;
ex[-a[i]]=true;

 }
  if(sum==0){
    ans.push_back(i+1);
   en.clear();
   ex.clear();
}

    }

    cout<<ans.size()<<endl;
    cout<<ans[0]<<" ";
    for(int i=1;i<ans.size();i++)cout<<ans[i] - ans[0]<<" ";
return 0;

    }}


 #include<bits/stdc++.h>
using namespace std;
#define MAX 1.25
#define ll long long
#define power(x) (ceil(log2(x))==floor(log2(x)))?1:0

int main(){

ll int n;
cin>>n;
ll int a[n];

ll sum =0 , pos=0;
for(ll int i=0;i<n;i++){
    cin>>a[i];
    sum = sum + a[i];
if(a[i]>0)
    pos++;
}
if(sum!=0 || pos!=(n/2)){
    cout<<"-1";
    return 0;
}
map<int ll , int ll>m;
vector<int ll> ans;
ll int prev=0;

for(ll int i=0;i<n;i++){
    if(a[i]>0){
        if(m[a[i]]==1){
//        cout<<"-1";
//        return 0;
ans.push_back(i-prev);
prev=i;
m.clear();
m[a[i]] =1;
        }
        else{
            m[a[i]]=1;
        }

    }
    else{
        if(m[(-1*a[i])]==0){
                //cout<<i<<endl;
            cout<<"-1";
            return 0;
        }

        else if(m[a[i]]!=0){
 cout<<"-1";
            return 0;
        }
        else{
            m[a[i]]=1;
        }
    }
}

if(ans.size()==0)
	{
		cout<<1<<"\n"<<n;

	}
	else
	{
		cout<<ans.size()+1<<endl;
	    for(ll i=0;i<ans.size();++i)
	    {
	    	cout<<ans[i]<<" ";
	    }
	    cout<<n-prev<<"\n";

	}

}


 #include<bits/stdc++.h>
using namespace std;
#define MAX 1.25
#define ll long long
#define power(x) (ceil(log2(x))==floor(log2(x)))?1:0

int main(){

ll int n;
cin>>n;
ll int a[n];

ll sum =0 , pos=0;
for(ll int i=0;i<n;i++){
    cin>>a[i];
    sum = sum + a[i];
if(a[i]>0)
    pos++;
}
if(sum!=0 || pos!=(n/2)){
    cout<<"-1";
    return 0;
}
map<int ll , int ll>m;
vector<int ll> ans;
ll int prev=0;

for(ll int i=0;i<n;i++){
    if(a[i]>0){
        if(m[a[i]]==1){
//        cout<<"-1";
//        return 0;
ans.push_back(i-prev);
prev=i;
m.clear();
        }
        else{
            m[a[i]]=1;
        }

    }
    else{
        if((-1*a[i])==0){
            cout<<"-1";
            return 0;
        }

        else if(m[a[i]]!=0){
 cout<<"-1";
            return 0;
        }
        else{
            m[a[i]]=1;
        }
    }
}

if(ans.size()==0)
	{
		cout<<1<<"\n"<<n;

	}
	else
	{
		cout<<ans.size()+1<<endl;
	    for(ll i=0;i<ans.size();++i)
	    {
	    	cout<<ans[i]<<" ";
	    }
	    cout<<n-prev<<"\n";

	}

}


#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define N 2000
#define ll long long

map<int , bool> en , ex;
int main(){
//int t;
//cin>>t;
//while(t--)
    {
    int n , k, sum=0;
    cin>>n;
    int a[n];
    map<int , int> mp;
    for(int i=0;i<n;i++){
        cin>>a[i];

    }

   vector<int> ans;
   if(a[0]>0){sum++; en[a[0]]=true;}
   else {cout<<"-1"; return 0;}

    for(int i=1;i<n;i++){

 if(a[i]>0){
    if(en.find(a[i])!=en.end()){
        ans.clear();
        cout<<"-1\n";
        return 0;
    }
    en[a[i]]=true;
    ex[a[i]]=false;
    sum++;
 }
 else{
if(en.find(-a[i])==en.end()){cout<<"-1"; return 0;}
sum--;
ex[-a[i]]=true;

 }
  if(sum==0){
    ans.push_back(i+1);
   en.clear();
   ex.clear();
}

    }

    cout<<ans.size()<<endl;
    for(int i=0;i<ans.size();i++)cout<<ans[i]<<" ";
return 0;

    }}


#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define N 2000
#define ll long long

map<int , bool> en , ex;
int main(){
//int t;
//cin>>t;
//while(t--)
    {
    int n , k, sum=0;
    cin>>n;
    int a[n];
    map<int , int> mp;
    for(int i=0;i<n;i++){
        cin>>a[i];

    }

   vector<int> ans;
   if(a[0]>0){sum++; en[a[0]]=true;}
   else {cout<<"-1"; return 0;}

    for(int i=1;i<n;i++){

 if(a[i]>0){
    if(en.find(a[i])!=en.end()){
        ans.clear();
        cout<<"-1\n";
        return 0;
    }
    en[a[i]]=true;
    ex[a[i]]=false;
    sum++;
 }
 else{
if(en.find(-a[i])==en.end()){cout<<"-1"; return 0;}
sum--;
ex[-a[i]]=true;

 }
  if(sum==0){
    ans.push_back(i+1);
   en.clear();
   ex.clear();
}

    }
if(ans.size==0 || sum!=0){
    cout<<"-1";
    return 0;
}
    cout<<ans.size()<<endl;
    cout<<ans[0]<<" ";
    for(int i=1;i<ans.size();i++)cout<<ans[i] - ans[i-1]<<" ";
return 0;

    }}


 #include<bits/stdc++.h>
using namespace std;
#define MAX 1.25
#define ll long long
#define power(x) (ceil(log2(x))==floor(log2(x)))?1:0

int main(){

ll int n;
cin>>n;
ll int a[n];

ll sum =0 , pos=0;
for(ll int i=0;i<n;i++){
    cin>>a[i];
    sum = sum + a[i];
if(a[i]>0)
    pos++;
}
if(sum!=0 || pos!=(n/2)){
    cout<<"-1";
    return 0;
}
map<int ll , int ll>m;
vector<int ll> ans;
ll int prev=0;
//
//for(ll int i=0;i<n;i++){
//    if(a[i]>0){
//        if(m[a[i]]==1){
////        cout<<"-1";
////        return 0;
//ans.push_back(i-prev);
//prev=i;
//m.clear();
//m[a[i]] =1;
//        }
//        else{
//            m[a[i]]=1;
//        }
//
//    }
//    else{
//        if(m[(-1*a[i])]==0){
//                //cout<<i<<endl;
//            cout<<"-1";
//            return 0;
//        }
//
//        else if(m[a[i]]!=0){
// cout<<"-1";
//            return 0;
//        }
//        else{
//            m[a[i]]=1;
//        }
//    }
//}

m.clear();
ans.clear();
for(ll int i=0;i<n;i++){
        if(m.size()==0 && i!=0){
            ans.push_back(i-prev);
prev=i;
        }
if(a[i]>0){
    if(m[a[i]]==0){
        m[a[i]]=1;
    }
    else{
       cout<<"-1";
        return 0;
}
}
else{
    if(m[-1*a[i]]==1){
        m.erase(-1*a[i]);
    }
    else{
        cout<<"-1";
        return 0;
    }
}
}

if(ans.size()==0)
	{
		cout<<1<<"\n"<<n;

	}
	else
	{
		cout<<ans.size()+1<<endl;
	    for(ll i=0;i<ans.size();++i)
	    {
	    	cout<<ans[i]<<" ";
	    }
	    cout<<n-prev<<"\n";

	}

}


#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define N 2000
#define ll long long

map<int , bool> en , ex;
int main(){
//int t;
//cin>>t;
//while(t--)
    {
    int n , k, sum=0;
    cin>>n;
    int a[n];
    map<int , int> mp;
    for(int i=0;i<n;i++){
        cin>>a[i];

    }

   vector<int> ans;
   if(a[0]>0){sum++; en[a[0]]=true;}
   else {cout<<"-1"; return 0;}

    for(int i=1;i<n;i++){

 if(a[i]>0){
    if(en.find(a[i])!=en.end()){
        ans.clear();
        cout<<"-1\n";
        return 0;
    }
    en[a[i]]=true;
    ex[a[i]]=false;
    sum++;
 }
 else{
if(en.find(-a[i])==en.end()){cout<<"-1"; return 0;}
sum--;
ex[-a[i]]=true;

 }
  if(sum==0){
    ans.push_back(i+1);
   en.clear();
   ex.clear();
}

    }
if((ans.size()==0) || (sum!=0)){
    cout<<"-1";
    return 0;
}
    cout<<ans.size()<<endl;
    cout<<ans[0]<<" ";
    for(int i=1;i<ans.size();i++)cout<<ans[i] - ans[i-1]<<" ";
return 0;

    }}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;cin>>n;vector<int> v(n);for(int i=0;i<n;i++)cin>>v[i];
    vector<int> record(1e6+1);
    vector<int> f(1e6+1);
    vector<int> ans;
    int x=0;ll sum=0;int in=0;int out=0;
    for(int i=0;i<n;i++){
        sum+=v[i];
        if(record[abs(v[i])]==ans.size()+1||sum<0){
            x=1;break;
        }
        if(v[i]<0){
            if(f[abs(v[i])]==1){
                record[abs(v[i])]=ans.size()+1;out++;
                f[abs(v[i])]=0;
            }
            else x=1;
        }
        if(v[i]>0){
            if(f[v[i]]==0)f[v[i]]=1;
            else x=1;
            in++;
        }
        if(sum==0&&in==out){
            ans.push_back(i+1);
            in=0;out=0;
        }
        if(x==1)break;
    }
    if(sum>0)x=1;
    if(x==1)cout<<-1<<endl;
    else{
        cout<<ans.size()<<endl;
        cout<<ans[0]<<" ";
        for(int i=1;i<ans.size();i++)cout<<ans[i]-ans[i-1]<<" ";
    }

}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;cin>>n;vector<int> v(n);for(int i=0;i<n;i++)cin>>v[i];
    vector<int> record(1e6);
    vector<int> ans;
    int x=0;ll sum=0;int in=0;int out=0;
    for(int i=0;i<n;i++){
        sum+=v[i];
        if((v[i]<0&&record[abs(v[i])]==ans.size()+1)||sum<0){
            x=1;break;
        }
        if(v[i]<0){
            record[abs(v[i])]=ans.size()+1;out++;
        }
        if(v[i]>0)in++;
        if(sum==0&&in==out){
            ans.push_back(i+1);
            // cout<<i+1<<endl;
            in=0;out=0;
        }

    }
    if(sum>0)x=1;
    if(x==1)cout<<-1<<endl;
    else{
        cout<<ans.size()<<endl;
        cout<<ans[0]<<" ";
        for(int i=1;i<ans.size();i++)cout<<ans[i]-ans[i-1]<<" ";
    }

}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;cin>>n;vector<int> v(n);for(int i=0;i<n;i++)cin>>v[i];
    vector<int> record(1e6);
    vector<int> ans;
    int x=0;int sum=0;int in=0;int out=0;
    for(int i=0;i<n;i++){
        sum+=v[i];
        if((v[i]<0&&record[abs(v[i])]==ans.size()+1)||sum<0){
            x=1;break;
        }
        if(v[i]<0){
            record[abs(v[i])]=ans.size()+1;out++;
        }
        if(v[i]>0)in++;
        if(sum==0&&in==out){
            ans.push_back(i+1);
            // cout<<i+1<<endl;
            in=0;out=0;
        }

    }
    if(sum>0)x=1;
    if(x==1)cout<<-1<<endl;
    else{
        cout<<ans.size()<<endl;
        cout<<ans[0]<<" ";
        for(int i=1;i<ans.size();i++)cout<<ans[i]-ans[i-1]<<" ";
    }

}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;cin>>n;vector<int> v(n);for(int i=0;i<n;i++)cin>>v[i];
    vector<int> record(1e6);
    vector<int> f(1e6);
    vector<int> ans;
    int x=0;ll sum=0;int in=0;int out=0;
    for(int i=0;i<n;i++){
        sum+=v[i];
        if(record[abs(v[i])-1]==ans.size()+1||sum<0){
            x=1;break;
        }
        if(v[i]<0){
            if(f[abs(v[i])-1]==1){
                record[abs(v[i])-1]=ans.size()+1;out++;
            }
            else x=1;
        }
        if(v[i]>0){
            if(f[v[i]-1]==0)f[v[i]-1]=1;
            else x=1;
        }
        if(sum==0&&in==out){
            ans.push_back(i+1);
            in=0;out=0;
        }
        if(x==1)break;
    }
    if(sum>0)x=1;
    if(x==1)cout<<-1<<endl;
    else{
        cout<<ans.size()<<endl;
        cout<<ans[0]<<" ";
        for(int i=1;i<ans.size();i++)cout<<ans[i]-ans[i-1]<<" ";
    }

}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;cin>>n;vector<int> v(n);for(int i=0;i<n;i++)cin>>v[i];
    vector<int> record(1e6);
    vector<int> ans;
    int x=0;int sum=0;int in=0;int out=0;
    for(int i=0;i<n;i++){
        sum+=v[i];
        if((v[i]<0&&record[abs(v[i])]==0||sum<0){
            x=1;break;
        }
        if(v[i]<0){
            record[abs(v[i])]+=ans.size()+1;out++;
        }
        if(v[i]>0){
            record[abs(v[i])]-=ans.size()+1
        }
        if(sum==0&&in==out){
            ans.push_back(i+1);
            // cout<<i+1<<endl;
            in=0;out=0;
        }

    }
    if(sum>0)x=1;
    if(x==1)cout<<-1<<endl;
    else{
        cout<<ans.size()<<endl;
        cout<<ans[0]<<" ";
        for(int i=1;i<ans.size();i++)cout<<ans[i]-ans[i-1]<<" ";
    }

}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;cin>>n;vector<int> v(n);for(int i=0;i<n;i++)cin>>v[i];
    vector<int> record(1e6);
    vector<int> ans;
    int x=0;int sum=0;int in=0;int out=0;
    for(int i=0;i<n;i++){
        sum+=v[i];
        if((v[i]<0&&record[abs(v[i])]==ans.size()+1)||sum<0){
            x=1;break;
        }
        if(v[i]<0){
            record[abs(v[i])]=ans.size()+1;out++;
        }
        if(v[i]>0)in++;
        if(sum==0&&in==out){
            ans.push_back(i+1);
            // cout<<i+1<<endl;
            in=0;out=0;
        }

    }
    if(x==1)cout<<-1<<endl;
    else{
        cout<<ans.size()<<endl;
        cout<<ans[0]<<" ";
        for(int i=1;i<ans.size();i++)cout<<ans[i]-ans[i-1]<<" ";
    }

}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;cin>>n;vector<int> v(n);for(int i=0;i<n;i++)cin>>v[i];
    vector<int> record(1e6+1);
    vector<int> f(1e6+1);
    vector<int> ans;
    int x=0;ll sum=0;int in=0;int out=0;
    for(int i=0;i<n;i++){
        sum+=v[i];
        if(record[abs(v[i])]==ans.size()+1||sum<0){
            x=1;break;
        }
        if(v[i]<0){
            if(f[abs(v[i])]==1){
                record[abs(v[i])]=ans.size()+1;out++;
            }
            else x=1;
        }
        if(v[i]>0){
            if(f[v[i]]==0)f[v[i]]=1;
            else x=1;
            in++;
        }
        if(sum==0&&in==out){
            ans.push_back(i+1);
            in=0;out=0;
        }
        if(x==1)break;
    }
    if(sum>0)x=1;
    if(x==1)cout<<-1<<endl;
    else{
        cout<<ans.size()<<endl;
        cout<<ans[0]<<" ";
        for(int i=1;i<ans.size();i++)cout<<ans[i]-ans[i-1]<<" ";
    }

}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;cin>>n;vector<int> v(n);for(int i=0;i<n;i++)cin>>v[i];
    vector<int> record(1e6);
    vector<int> ans;
    int x=0;int sum=0;int in=0;int out=0;
    for(int i=0;i<n;i++){
        sum+=v[i];
        if((v[i]<0&&record[abs(v[i])]==0)||sum<0){
            x=1;break;
        }
        if(v[i]<0){
            record[abs(v[i])]+=ans.size()+1;out++;
        }
        if(v[i]>0){
            record[abs(v[i])]-=ans.size()+1;in++;
        }
        if(sum==0&&in==out){
            ans.push_back(i+1);
            // cout<<i+1<<endl;
            in=0;out=0;
        }

    }
    if(sum>0)x=1;
    if(x==1)cout<<-1<<endl;
    else{
        cout<<ans.size()<<endl;
        cout<<ans[0]<<" ";
        for(int i=1;i<ans.size();i++)cout<<ans[i]-ans[i-1]<<" ";
    }

}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e5 + 5;
const ll mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
const double eps = 1e-5;
inline int read(){
    int f = 1,x = 0; char ch = getchar();
    while(ch < '0' || ch > '9'){if(ch == '-')f = -1;ch = getchar();}
    while(ch >= '0' && ch <= '9'){x = x * 10 + ch - 48;ch = getchar();}
    return f * x;
}
ll gcd(ll a,ll b){return !b?a:gcd(b,a%b);}
ll poww(ll x,ll y,ll p){ll ans = 1;while(y){if(y & 1) ans = ans * x % p;x = x * x % p;y >>= 1;}return ans;}
int n;
ll a[maxn],sum[maxn],cnt[maxn];
ll pre[maxn];
vector<int> res(maxn);
int main()
{
//	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	scanf("%d",&n);
	for(int i = 1;i < maxn;i++) pre[i] = -1;
	for(int i = 1;i <= n;i++) scanf("%lld",&a[i]);
	for(int i = 1;i <= n;i++) sum[i] = sum[i-1] + a[i];
	int x = 0,l = 0,ans = 0;
	bool ok = 1;
	for(int i = 1;i <= n;i++){
		x = a[i];
		if(x < 0){
			if(!cnt[abs(x)]){
				ok = 0;
				break;
			}
			cnt[abs(x)] = 0;
			if(sum[i] - sum[l] == 0){
				res[ans++] = (i-l);
				l = i;
			}
		}
		else{
			if(cnt[x] == 1){
				ok = 0;
				break;
			}
			cnt[x] = 1;
			if(sum[i] - sum[l] == 0){
				ok = 0;
				break;
			}
			if(pre[x] >= l){
				ok = 0;
				break;
			}
			pre[x] = i;
		}
	}
//	cout << res[ans] << endl;
	if(!ok || accumulate(res.begin(),res.begin() + ans,0) != n) cout << -1 << endl;
	else{
		printf("%d\n",ans);
		for(int i = 0;i < ans;i++) printf("%d ",res[i]);
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e6 + 5;
const ll mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
const double eps = 1e-5;
inline int read(){
    int f = 1,x = 0; char ch = getchar();
    while(ch < '0' || ch > '9'){if(ch == '-')f = -1;ch = getchar();}
    while(ch >= '0' && ch <= '9'){x = x * 10 + ch - 48;ch = getchar();}
    return f * x;
}
ll gcd(ll a,ll b){return !b?a:gcd(b,a%b);}
ll poww(ll x,ll y,ll p){ll ans = 1;while(y){if(y & 1) ans = ans * x % p;x = x * x % p;y >>= 1;}return ans;}
int n;
int a[maxn];
set<int> in,out;
vector<int> ans;
int main()
{
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> n;
	for(int i = 1;i <= n;i++) cin >> a[i];
	int s = 0,l = 0;
	for(int i = 1;i <= n;i++){
		int x = a[i];
		s += x;
		l++;
		if(!s){
			if(x < 0){
				x = -x;
				if(in.find(x) == in.end()){
					cout << -1 << endl;
					return 0;
				}
				in.erase(x);
				out.insert(x);
			}
			else{
				cout << -1 << endl;
				return 0;
			}
			in.clear();
			out.clear();
			ans.push_back(l);
			l = 0;
		}
		else{
			if(x < 0){
				x = -x;
				if(in.find(x) == in.end()){
					cout << -1 << endl;
					return 0;
				}
				in.erase(x);
				out.insert(x);
			}
			else{
				if(in.find(x) != in.end() || out.find(x) != out.end()){
					cout << -1 << endl;
					return 0;
				}
				in.insert(x);
			}
		}
	}
	if(s != 0){
		cout << -1 << endl;
		return 0;
	}
	cout << ans.size() << endl;
	for(int i = 0;i < ans.size();i++) cout << ans[i] << " ";
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e6 + 5;
const ll mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
const double eps = 1e-5;
inline int read(){
    int f = 1,x = 0; char ch = getchar();
    while(ch < '0' || ch > '9'){if(ch == '-')f = -1;ch = getchar();}
    while(ch >= '0' && ch <= '9'){x = x * 10 + ch - 48;ch = getchar();}
    return f * x;
}
ll gcd(ll a,ll b){return !b?a:gcd(b,a%b);}
ll poww(ll x,ll y,ll p){ll ans = 1;while(y){if(y & 1) ans = ans * x % p;x = x * x % p;y >>= 1;}return ans;}
int n;
ll a[maxn],sum[maxn],cnt[maxn];
ll pre[maxn];
vector<int> res(maxn);
int main()
{
//	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	scanf("%d",&n);
	for(int i = 1;i < maxn;i++) pre[i] = -1;
	for(int i = 1;i <= n;i++) scanf("%lld",&a[i]);
	for(int i = 1;i <= n;i++) sum[i] = sum[i-1] + a[i];
	int x = 0,l = 0,ans = 0;
	bool ok = 1;
	for(int i = 1;i <= n;i++){
		x = a[i];
		if(x < 0){
			if(!cnt[abs(x)]){
				ok = 0;
				break;
			}
			cnt[abs(x)] = 0;
			if(sum[i] - sum[l] == 0){
				res[ans++] = (i-l);
				l = i;
			}
		}
		else{
			if(cnt[x] == 1){
				ok = 0;
				break;
			}
			cnt[x] = 1;
			if(sum[i] - sum[l] == 0){
				ok = 0;
				break;
			}
			if(pre[x] >= l){
				ok = 0;
				break;
			}
			pre[x] = i;
		}
	}
//	cout << res[ans] << endl;
	if(!ok || accumulate(res.begin(),res.begin() + ans,0) != n) cout << -1 << endl;
	else{
		printf("%d\n",ans);
		for(int i = 0;i < ans;i++) printf("%d ",res[i]);
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e6 + 5;
const ll mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
const double eps = 1e-5;
inline int read(){
    int f = 1,x = 0; char ch = getchar();
    while(ch < '0' || ch > '9'){if(ch == '-')f = -1;ch = getchar();}
    while(ch >= '0' && ch <= '9'){x = x * 10 + ch - 48;ch = getchar();}
    return f * x;
}
ll gcd(ll a,ll b){return !b?a:gcd(b,a%b);}
ll poww(ll x,ll y,ll p){ll ans = 1;while(y){if(y & 1) ans = ans * x % p;x = x * x % p;y >>= 1;}return ans;}
int n;
ll a[maxn],sum[maxn],cnt[maxn];
ll pre[maxn];
vector<int> res;
int main()
{
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> n;
	memset(pre,-1,sizeof(pre));
	for(int i = 1;i <= n;i++) cin >> a[i];
	for(int i = 1;i <= n;i++) sum[i] = sum[i-1] + a[i];
	int x = 0,l = 0,ans = 0;
	bool ok = 1;
	for(int i = 1;i <= n;i++){
		x = a[i];
		if(x < 0){
			if(!cnt[abs(x)]){
				ok = 0;
				break;
			}
			cnt[abs(x)] = 0;
			if(sum[i] - sum[l] == 0){
				ans++;
				res.push_back(i-l);
				l = i;
			}
		}
		else{
			if(cnt[x] == 1){
				ok = 0;
				break;
			}
			cnt[x] = 1;
//			if(pre[x] >= l){
//				ok = 0;
//				break;
//			}
//			pre[x] = i;
		}
	}
	if(!ok || accumulate(res.begin(),res.end(),0) != n) cout << -1 << endl;
	else{
		cout << ans << endl;
		for(int i = 0;i < ans;i++) cout << res[i] << " ";
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e6 + 5;
int n;
ll a[maxn],sum[maxn],cnt[maxn];
ll pre[maxn];
vector<int> res;
int main()
{
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> n;
	memset(pre,-1,sizeof(pre));
	for(int i = 1;i <= n;i++) cin >> a[i];
	for(int i = 1;i <= n;i++) sum[i] = sum[i-1] + a[i];
	int x = 0,l = 0,ans = 0;
	bool ok = 1;
	for(int i = 1;i <= n;i++){
		x = a[i];
		if(x < 0){
			if(!cnt[abs(x)]){
				ok = 0;
				break;
			}
			cnt[abs(x)] = 0;
			if(sum[i] - sum[l] == 0){
				ans++;
				res.push_back(i-l);
				l = i;
			}
		}
		else{
			if(cnt[x] == 1){
				ok = 0;
				break;
			}
			cnt[x] = 1;
			if(pre[x] >= l){
				ok = 0;
				break;
			}
			pre[x] = i;
		}
	}
	if(!ok || accumulate(res.begin(),res.end(),0) != n) cout << -1 << endl;
	else{
		cout << ans << endl;
		for(int i = 0;i < ans;i++) cout << res[i] << " ";
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 2e5 + 5;
const ll mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
const double eps = 1e-5;
inline int read(){
    int f = 1,x = 0; char ch = getchar();
    while(ch < '0' || ch > '9'){if(ch == '-')f = -1;ch = getchar();}
    while(ch >= '0' && ch <= '9'){x = x * 10 + ch - 48;ch = getchar();}
    return f * x;
}
ll gcd(ll a,ll b){return !b?a:gcd(b,a%b);}
ll poww(ll x,ll y,ll p){ll ans = 1;while(y){if(y & 1) ans = ans * x % p;x = x * x % p;y >>= 1;}return ans;}
int n;
ll a[maxn],sum[maxn],cnt[maxn];
ll pre[maxn];
vector<int> res;
int main()
{
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> n;
	memset(pre,-1,sizeof(pre));
	for(int i = 1;i <= n;i++) cin >> a[i];
	for(int i = 1;i <= n;i++) sum[i] = sum[i-1] + a[i];
	int x = 0,l = 0,ans = 0;
	bool ok = 1;
	for(int i = 1;i <= n;i++){
		x = a[i];
		if(x < 0){
			if(!cnt[abs(x)]){
				ok = 0;
				break;
			}
			cnt[abs(x)] = 0;
			if(sum[i] - sum[l] == 0){
				ans++;
				res.push_back(i-l);
				l = i;
			}
		}
		else{
			if(cnt[x] == 1){
				ok = 0;
				break;
			}
			cnt[x] = 1;
			if(sum[i] - sum[l] == 0){
				ok = 0;
				break;
			}
			if(pre[x] >= l){
				ok = 0;
				break;
			}
			pre[x] = i;
		}
	}
	if(!ok) cout << -1 << endl;
	else{
		cout << ans << endl;
		for(int i = 0;i < ans;i++) cout << res[i] << " ";
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e6 + 5;
const ll mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
const double eps = 1e-5;
inline int read(){
    int f = 1,x = 0; char ch = getchar();
    while(ch < '0' || ch > '9'){if(ch == '-')f = -1;ch = getchar();}
    while(ch >= '0' && ch <= '9'){x = x * 10 + ch - 48;ch = getchar();}
    return f * x;
}
ll gcd(ll a,ll b){return !b?a:gcd(b,a%b);}
ll poww(ll x,ll y,ll p){ll ans = 1;while(y){if(y & 1) ans = ans * x % p;x = x * x % p;y >>= 1;}return ans;}
int n;
ll a[maxn],sum[maxn],cnt[maxn];
ll pre[maxn];
vector<int> res;
int main()
{
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> n;
	memset(pre,-1,sizeof(pre));
	for(int i = 1;i <= n;i++) cin >> a[i];
	for(int i = 1;i <= n;i++) sum[i] = sum[i-1] + a[i];
	int x = 0,l = 0,ans = 0;
	bool ok = 1;
	for(int i = 1;i <= n;i++){
		x = a[i];
		if(x < 0){
			if(!cnt[abs(x)]){
				ok = 0;
				break;
			}
			cnt[abs(x)] = 0;
			if(sum[i] - sum[l] == 0){
				ans++;
				res.push_back(i-l);
				l = i;
			}
		}
		else{
			if(cnt[x] == 1){
				ok = 0;
				break;
			}
			cnt[x] = 1;
			if(sum[i] - sum[l] == 0){
				ok = 0;
				break;
			}
			if(pre[x] >= l){
				ok = 0;
				break;
			}
			pre[x] = i;
		}
	}
	if(!ok || accumulate(res.begin(),res.end(),0) != n) cout << -1 << endl;
	else{
		cout << ans << endl;
		for(int i = 0;i < ans;i++) cout << res[i] << " ";
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 2e5 + 5;
const ll mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
const double eps = 1e-5;
inline int read(){
    int f = 1,x = 0; char ch = getchar();
    while(ch < '0' || ch > '9'){if(ch == '-')f = -1;ch = getchar();}
    while(ch >= '0' && ch <= '9'){x = x * 10 + ch - 48;ch = getchar();}
    return f * x;
}
ll gcd(ll a,ll b){return !b?a:gcd(b,a%b);}
ll poww(ll x,ll y,ll p){ll ans = 1;while(y){if(y & 1) ans = ans * x % p;x = x * x % p;y >>= 1;}return ans;}
int n;
ll a[maxn],sum[maxn],cnt[maxn];
ll pre[maxn];
vector<int> res;
int main()
{
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> n;
	memset(pre,-1,sizeof(pre));
	for(int i = 1;i <= n;i++) cin >> a[i];
	for(int i = 1;i <= n;i++) sum[i] = sum[i-1] + a[i];
	int x = 0,l = 0,ans = 0;
	bool ok = 1;
	for(int i = 1;i <= n;i++){
		x = a[i];
		if(x < 0){
			if(!cnt[abs(x)]){
				ok = 0;
				break;
			}
			cnt[abs(x)] = 0;
			if(sum[i] - sum[l] == 0){
				ans++;
				res.push_back(i-l);
				l = i;
			}
		}
		else{
			if(cnt[x] == 1){
				ok = 0;
				break;
			}
			cnt[x] = 1;
			if(sum[i] - sum[l] == 0){
				ok = 0;
				break;
			}
			if(pre[x] >= l){
				ok = 0;
				break;
			}
			pre[x] = i;
		}
	}
	if(!ok || accumulate(res.begin(),res.end(),0) > n) cout << -1 << endl;
	else{
		cout << ans << endl;
		for(int i = 0;i < ans;i++) cout << res[i] << " ";
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e6 + 5;
const ll mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
const double eps = 1e-5;
inline int read(){
    int f = 1,x = 0; char ch = getchar();
    while(ch < '0' || ch > '9'){if(ch == '-')f = -1;ch = getchar();}
    while(ch >= '0' && ch <= '9'){x = x * 10 + ch - 48;ch = getchar();}
    return f * x;
}
ll gcd(ll a,ll b){return !b?a:gcd(b,a%b);}
ll poww(ll x,ll y,ll p){ll ans = 1;while(y){if(y & 1) ans = ans * x % p;x = x * x % p;y >>= 1;}return ans;}
int n;
int a[maxn];
set<int> in,out;
vector<int> ans;
int main()
{
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> n;
	for(int i = 1;i <= n;i++) cin >> a[i];
	int s = 0,l = 0;
	for(int i = 1;i <= n;i++){
		int x = a[i];
		s += x;
		l++;
		if(!s){
			if(x < 0){
				x = -x;
				if(in.find(x) == in.end()){
					cout << -1 << endl;
					return 0;
				}
				in.erase(x);
				out.insert(x);
			}
			else{
				cout << -1 << endl;
				return 0;
			}
			in.clear();
			out.clear();
			ans.push_back(l);
			l = 0;
		}
		else{
			if(x < 0){
				x = -x;
				if(in.find(x) == in.end()){
					cout << -1 << endl;
					return 0;
				}
				in.erase(x);
				out.insert(x);
			}
			else{
				if(in.find(x) != in.end() || out.find(x) != out.end()){
					cout << -1 << endl;
					return 0;
				}
				in.insert(x);
			}
		}
	}
	cout << ans.size() << endl;
	for(int i = 0;i < ans.size();i++) cout << ans[i] << " ";
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 2e5 + 5;
const ll mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
const double eps = 1e-5;
inline int read(){
    int f = 1,x = 0; char ch = getchar();
    while(ch < '0' || ch > '9'){if(ch == '-')f = -1;ch = getchar();}
    while(ch >= '0' && ch <= '9'){x = x * 10 + ch - 48;ch = getchar();}
    return f * x;
}
ll gcd(ll a,ll b){return !b?a:gcd(b,a%b);}
ll poww(ll x,ll y,ll p){ll ans = 1;while(y){if(y & 1) ans = ans * x % p;x = x * x % p;y >>= 1;}return ans;}
int n;
ll a[maxn],sum[maxn],cnt[maxn];
ll pre[maxn];
vector<int> res;
int main()
{
//	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	scanf("%d",&n);
	memset(pre,-1,sizeof(pre));
	for(int i = 1;i <= n;i++) scanf("%lld",&a[i]);
	for(int i = 1;i <= n;i++) sum[i] = sum[i-1] + a[i];
	int x = 0,l = 0,ans = 0;
	bool ok = 1;
	for(int i = 1;i <= n;i++){
		x = a[i];
		if(x < 0){
			if(!cnt[abs(x)]){
				ok = 0;
				break;
			}
			cnt[abs(x)] = 0;
			if(sum[i] - sum[l] == 0){
				ans++;
				res.push_back(i-l);
				l = i;
			}
		}
		else{
			if(cnt[x] == 1){
				ok = 0;
				break;
			}
			cnt[x] = 1;
			if(sum[i] - sum[l] == 0){
				ok = 0;
				break;
			}
			if(pre[x] >= l){
				ok = 0;
				break;
			}
			pre[x] = i;
		}
	}
	if(!ok || accumulate(res.begin(),res.end(),0) != n) cout << -1 << endl;
	else{
		printf("%d\n",ans);
		for(int i = 0;i < ans;i++) printf("%d ",res[i]);
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e6 + 5;
const ll mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
const double eps = 1e-5;
inline int read(){
    int f = 1,x = 0; char ch = getchar();
    while(ch < '0' || ch > '9'){if(ch == '-')f = -1;ch = getchar();}
    while(ch >= '0' && ch <= '9'){x = x * 10 + ch - 48;ch = getchar();}
    return f * x;
}
ll gcd(ll a,ll b){return !b?a:gcd(b,a%b);}
ll poww(ll x,ll y,ll p){ll ans = 1;while(y){if(y & 1) ans = ans * x % p;x = x * x % p;y >>= 1;}return ans;}
int n;
ll a[maxn],sum[maxn],cnt[maxn];
ll pre[maxn];
vector<int> res(maxn);
int main()
{
//	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	scanf("%d",&n);
	for(int i = 1;i < maxn;i++) pre[i] = -1;
	for(int i = 1;i <= n;i++) scanf("%lld",&a[i]);
	for(int i = 1;i <= n;i++) sum[i] = sum[i-1] + a[i];
	int x = 0,l = 0,ans = 0;
	bool ok = 1;
	for(int i = 1;i <= n;i++){
		x = a[i];
		if(x < 0){
			if(!cnt[abs(x)]){
				ok = 0;
				break;
			}
			cnt[abs(x)] = 0;
			if(sum[i] - sum[l] == 0){
				res[ans++] = (i-l);
				l = i;
			}
		}
		else{
			if(cnt[x] == 1){
				ok = 0;
				break;
			}
			cnt[x] = 1;
			if(sum[i] - sum[l] == 0){
				ok = 0;
				break;
			}
			if(pre[x] >= l){
				ok = 0;
				break;
			}
			pre[x] = i;
		}
	}
	if(!ok || accumulate(res.begin(),res.begin() + ans,0) != n) cout << -1 << endl;
	else{
		printf("%d\n",ans);
		for(int i = 0;i < ans;i++) printf("%d ",res[i]);
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 2e5 + 5;
const ll mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
const double eps = 1e-5;
inline int read(){
    int f = 1,x = 0; char ch = getchar();
    while(ch < '0' || ch > '9'){if(ch == '-')f = -1;ch = getchar();}
    while(ch >= '0' && ch <= '9'){x = x * 10 + ch - 48;ch = getchar();}
    return f * x;
}
ll gcd(ll a,ll b){return !b?a:gcd(b,a%b);}
ll poww(ll x,ll y,ll p){ll ans = 1;while(y){if(y & 1) ans = ans * x % p;x = x * x % p;y >>= 1;}return ans;}
int n;
ll a[maxn],sum[maxn],cnt[maxn];
ll pre[maxn];
vector<int> res;
int main()
{
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> n;
	memset(pre,-1,sizeof(pre));
	for(int i = 1;i <= n;i++) cin >> a[i];
	for(int i = 1;i <= n;i++) sum[i] = sum[i-1] + a[i];
	int x = 0,l = 0,ans = 0;
	bool ok = 1;
	for(int i = 1;i <= n;i++){
		x = a[i];
		if(x < 0){
			if(!cnt[abs(x)]){
				ok = 0;
				break;
			}
			cnt[abs(x)] = 0;
			if(sum[i] - sum[l] == 0){
				ans++;
				res.push_back(i-l);
				l = i;
			}
		}
		else{
			if(cnt[x] == 1){
				ok = 0;
				break;
			}
			cnt[x] = 1;
			if(sum[i] - sum[l] == 0){
				ok = 0;
				break;
			}
			if(pre[x] >= l){
				ok = 0;
				break;
			}
			pre[x] = i;
		}
	}
	if(!ok || accumulate(res.begin(),res.end(),0) != n) cout << -1 << endl;
	else{
		cout << ans << endl;
		for(int i = 0;i < ans;i++) cout << res[i] << " ";
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e5 + 5;
const ll mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
const double eps = 1e-5;
inline int read(){
    int f = 1,x = 0; char ch = getchar();
    while(ch < '0' || ch > '9'){if(ch == '-')f = -1;ch = getchar();}
    while(ch >= '0' && ch <= '9'){x = x * 10 + ch - 48;ch = getchar();}
    return f * x;
}
ll gcd(ll a,ll b){return !b?a:gcd(b,a%b);}
ll poww(ll x,ll y,ll p){ll ans = 1;while(y){if(y & 1) ans = ans * x % p;x = x * x % p;y >>= 1;}return ans;}
int n;
ll a[maxn],sum[maxn],cnt[maxn];
ll pre[maxn];
vector<int> res;
int main()
{
//	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	scanf("%d",&n);
	memset(pre,-1,sizeof(pre));
	for(int i = 1;i <= n;i++) scanf("%lld",&a[i]);
	for(int i = 1;i <= n;i++) sum[i] = sum[i-1] + a[i];
	int x = 0,l = 0,ans = 0;
	bool ok = 1;
	for(int i = 1;i <= n;i++){
		x = a[i];
		if(x < 0){
			if(!cnt[abs(x)]){
				ok = 0;
				break;
			}
			cnt[abs(x)] = 0;
			if(sum[i] - sum[l] == 0){
				ans++;
				res.push_back(i-l);
				l = i;
			}
		}
		else{
			if(cnt[x] == 1){
				ok = 0;
				break;
			}
			cnt[x] = 1;
			if(sum[i] - sum[l] == 0){
				ok = 0;
				break;
			}
			if(pre[x] >= l){
				ok = 0;
				break;
			}
			pre[x] = i;
		}
	}
	if(!ok || accumulate(res.begin(),res.end(),0) != n) cout << -1 << endl;
	else{
		printf("%d\n",ans);
		for(int i = 0;i < ans;i++) printf("%d ",res[i]);
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e6 + 5;
const ll mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
const double eps = 1e-5;
inline int read(){
    int f = 1,x = 0; char ch = getchar();
    while(ch < '0' || ch > '9'){if(ch == '-')f = -1;ch = getchar();}
    while(ch >= '0' && ch <= '9'){x = x * 10 + ch - 48;ch = getchar();}
    return f * x;
}
ll gcd(ll a,ll b){return !b?a:gcd(b,a%b);}
ll poww(ll x,ll y,ll p){ll ans = 1;while(y){if(y & 1) ans = ans * x % p;x = x * x % p;y >>= 1;}return ans;}
int n;
ll a[maxn],sum[maxn],cnt[maxn];
ll pre[maxn];
vector<int> res;
int main()
{
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> n;
	memset(pre,-1,sizeof(pre));
	for(int i = 1;i <= n;i++) cin >> a[i];
	for(int i = 1;i <= n;i++) sum[i] = sum[i-1] + a[i];
	int x = 0,l = 0,ans = 0;
	bool ok = 1;
	for(int i = 1;i <= n;i++){
		x = a[i];
		if(x < 0){
			if(!cnt[abs(x)]){
				ok = 0;
				break;
			}
			cnt[abs(x)] = 0;
			if(sum[i] - sum[l] == 0){
				ans++;
				res.push_back(i-l);
				l = i;
			}
		}
		else{
			if(cnt[x] == 1){
				ok = 0;
				break;
			}
			cnt[x] = 1;
			if(pre[x] >= l){
				ok = 0;
				break;
			}
			pre[x] = i;
		}
	}
	if(!ok || accumulate(res.begin(),res.end(),0) != n) cout << -1 << endl;
	else{
		cout << ans << endl;
		for(int i = 0;i < ans;i++) cout << res[i] << " ";
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e5 + 5;
const ll mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
const double eps = 1e-5;
inline int read(){
    int f = 1,x = 0; char ch = getchar();
    while(ch < '0' || ch > '9'){if(ch == '-')f = -1;ch = getchar();}
    while(ch >= '0' && ch <= '9'){x = x * 10 + ch - 48;ch = getchar();}
    return f * x;
}
ll gcd(ll a,ll b){return !b?a:gcd(b,a%b);}
ll poww(ll x,ll y,ll p){ll ans = 1;while(y){if(y & 1) ans = ans * x % p;x = x * x % p;y >>= 1;}return ans;}
int n;
ll a[maxn],sum[maxn];
vector<int> res;
int main()
{
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> n;
	for(int i = 1;i <= n;i++) cin >> a[i];
	int ans = 0;
	bool ok = 1;
	for(int i = 1;i <= n;i++){
		sum[i] = sum[i-1] + a[i];
	}
	int l = 0;
	for(int i = 1;i <= n;i++){
		if(sum[i] - sum[l] == 0){
			ans++;
			l = i;
			res.push_back(i);
		}
	}
	if(ans == 0) cout << -1 << endl;
	else{
		cout << ans << endl;
		for(int i = 0;i < ans;i++) cout << res[i] << " ";
	}
	return 0;
}


t=int(input())
for i in range(t):
    n=int(input())
    a=list(map(int,input().strip().split(" ")))
    p=0
    ans=1
    c=0
    for j in range(1,n):
        if a[j]>a[j-1]:
            c+=1
        else:
            if not p:
                ans+=1
                p=c-1
            else:
                p-=1

    print(ans)


t=int(input())
for i in range(t):
    n=int(input())
    a=list(map(int,input().strip().split(" ")))
    p=[]
    ans=0
    c=1
    for j in range(2,n):
        if a[j]>a[j-1]:
            c+=1
        else:
            p.append(c)
            c=1
    p.append(c)

    j=0
    while (j<len(p)-1):
        j+=p[j]
        ans+=1
    print(ans)


t=int(input())
for i in range(t):
    n=int(input())
    a=list(map(int,input().strip().split(" ")))
    p=[]
    ans=0
    c=1
    for j in range(2,n):
        if a[j]>a[j-1]:
            c+=1
        else:
            p.append(c)
            c=1
    p.append(c)
    print(*p)
    j=0
    while (j<len(p)-1):
        j+=p[j]
        ans+=1
    print(ans)


t=int(input())
for i in range(t):
    n=int(input())
    a=list(map(int,input().strip().split(" ")))
    p=[]
    ans=1
    c=1
    for j in range(2,n):
        if a[j]>a[j-1]:
            c+=1
        else:
            p.append(c)
            c=1

    j=0
    while (j<len(p)-1):
        j+=p[j]
        ans+=1
    print(ans)


t=int(input())
for i in range(t):
    n=int(input())
    a=list(map(int,input().strip().split(" ")))
    p=[]
    ans=1
    c=1
    for j in range(2,n):
        if a[j]>a[j-1]:
            c+=1
        else:
            p.append(c)
            c=1
    p.append(c)
    #print(*p)
    j=0
    kk=p[0]
    prev=0
    while (j<len(p)-1):
        if kk<=len(p)-1:
            for kp in range(j+1,kk):
                prev+=p[kp]
            j+=p[j]
            kk=prev
            ans+=1
        else:
            j+=p[j]
            ans+=1
    print(ans)


from collections import deque

def solve():
    n = int(input())
    a = deque(list(map(int, input().split())))
    ans = 0
    a.popleft()
    while a:
        if len(a) == 1:
            ans += 1
            a.popleft()
        else:
            if a[0] > a[1]:
                ans += 1
            a.popleft()
    print(ans)
    return

def main():
    t = int(input())
    for i in range(t):
        solve()
    return

if __name__ == "__main__":
    main()


from collections import deque

def solve():
    n = int(input())
    a = deque(list(map(int, input().split())))
    ans = 0
    nodes = 0
    mother_repository = 0
    repository = 0
    a.popleft()
    while a:
        if len(a) == 1:
            nodes += 1
            if mother_repository == 0:
                ans += 1
            a.popleft()
            continue
        elif len(a) > 1:
            nodes += 1
            x = a.popleft()
            if x > a[0]:
                if mother_repository > 0:
                    repository += nodes
                    mother_repository -= 1
                    nodes = 0
                    continue
                elif mother_repository == 0:
                    ans += 1
                    mother_repository = repository
                    repository = 0
                    continue
    print(ans)
    return

def main():
    t = int(input())
    for i in range(t):
        solve()
    return

if __name__ == "__main__":
    main()


from collections import deque

def solve():
    n = int(input())
    a = deque(list(map(int, input().split())))
    ans = 0
    nodes = 0
    mother_repository = 1
    repository = 0
    now = 10**6
    a.popleft()
    while a:
        nodes += 1
        x = a.popleft()
        if now > x:
            now = x
            if mother_repository > 1:
                repository += nodes
                mother_repository -= 1
                nodes = 0
                continue
            elif mother_repository == 1:
                repository += nodes
                ans += 1
                mother_repository = repository
                repository = 0
                nodes = 0
                continue
        else:
            now = x
    print(ans)
    return

def main():
    t = int(input())
    for i in range(t):
        solve()
    return

if __name__ == "__main__":
    main()


from collections import deque
import sys
sys.setrecursionlimit(2*10**5+10)

def solve():
    n = int(input())
    a = deque(list(map(int, input().split())))
    ans = 0
    nodes = 0
    mother_repository = 0
    repository = 0
    a.popleft()
    while a:
        if len(a) == 1:
            nodes += 1
            if mother_repository == 0:
                ans += 1
            a.popleft()
        else:
            nodes += 1
            if a[0] > a[1]:
                while mother_repository >= 1:
                    repository += nodes
                    mother_repository -= 1
                    nodes = 0
                if mother_repository == 0:
                    ans += 1
                    mother_repository = repository
                    repository = 0
            a.popleft()
    print(ans)
    return

def main():
    t = int(input())
    for i in range(t):
        solve()
    return

if __name__ == "__main__":
    main()


import sys
import os
from io import BytesIO, IOBase

#Fast IO Region
BUFSIZE = 8192
class FastIO(IOBase):
    newlines = 0
    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None
    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()
    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()
    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

from collections import deque, defaultdict
from math import inf
from sys import setrecursionlimit

setrecursionlimit(300000)

T = int(input())

for tt in range(T):
    N = int(input())
    arr = deque(map(int, input().split()))
    ans = 0

    dq = deque([arr.popleft()])
    children = defaultdict(list)

    def build(roots, elements):
        if not elements or not roots:
            return

        cur_root = roots.popleft()
        last_num = - inf

        while elements and elements[0] > last_num:
            now = elements.popleft()
            last_num = now
            children[cur_root].append(now)
            roots.append(now)

        build(roots, elements)

    build(dq, arr)

    def trav(cur):
        if not children[cur]:
            return 1
        ans = 0
        for nxt in children[cur]:
            ans = max(ans, trav(nxt))
        return ans + 1

    print(trav(1)-1)


import sys
import os
from io import BytesIO, IOBase

#Fast IO Region
BUFSIZE = 8192
class FastIO(IOBase):
    newlines = 0
    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None
    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()
    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()
    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

from collections import deque, defaultdict
from math import inf
from sys import setrecursionlimit

# setrecursionlimit(300000)

T = int(input())

for tt in range(T):
    N = int(input())
    arr = list(map(int, input().split()))
    levels = [1]

    i = 1
    last_num, node_chunk, level_nodes = -inf, 0, 0
    while i < N:
        for j in range(i, N):
            if arr[j] < last_num:
                node_chunk += 1
                last_num = -inf
                if node_chunk >= levels[-1]:
                    levels.append(level_nodes)
                    last_num = arr[j]
                    node_chunk = 0
                    level_nodes = 1
                    break
            else:
                level_nodes += 1
                last_num = arr[j]
        i = j + 1

    if level_nodes > 0:
        levels.append(level_nodes)

    print(len(levels) - 1)


from collections import deque, defaultdict
from math import inf
from sys import setrecursionlimit
import sys
import os
from io import BytesIO, IOBase

#Fast IO Region
BUFSIZE = 8192
class FastIO(IOBase):
    newlines = 0
    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None
    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()
    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()
    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

# setrecursionlimit(300000)

T = int(input())

for tt in range(T):
    N = int(input())
    arr = list(map(int, input().split()))
    levels = [1]

    i = 1
    last_num, node_chunk, level_nodes = -inf, 0, 0
    while i < N:
        for j in range(i, N):
            if arr[j] < last_num:
                node_chunk += 1
                last_num = -inf
                if node_chunk >= levels[-1]:
                    levels.append(level_nodes)
                    last_num = arr[j]
                    node_chunk = 0
                    level_nodes = 1
                    break
            else:
                level_nodes += 1
                last_num = arr[j]
        i = j + 1

    levels.append(level_nodes)

    print(len(levels) - 1)


from collections import deque, defaultdict
from math import inf
from sys import setrecursionlimit
import sys
import os
from io import BytesIO, IOBase

#Fast IO Region
BUFSIZE = 8192
class FastIO(IOBase):
    newlines = 0
    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None
    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()
    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()
    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

# setrecursionlimit(300000)

T = int(input())

for tt in range(T):
    N = int(input())
    arr = list(map(int, input().split()))
    levels = [1]

    last_num, node_chunk, height= -inf, 0, 0
    for i in range(1, N):
        v = arr[i]
        if v < last_num:
            node_chunk += 1
            if node_chunk == levels[height]:
                height += 1
                node_chunk = 0

        if height + 1 >= len(levels):
            levels.append(0)

        levels[height + 1] += 1
        last_num = v

    print(len(levels) - 1)


import sys
import os
from io import BytesIO, IOBase

#Fast IO Region
BUFSIZE = 8192
class FastIO(IOBase):
    newlines = 0
    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None
    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()
    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()
    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

from collections import deque, defaultdict
from math import inf
from sys import setrecursionlimit

setrecursionlimit(3000000)

T = int(input())

for tt in range(T):
    N = int(input())
    arr = deque(map(int, input().split()))
    ans = 0

    dq = deque([arr.popleft()])
    children = defaultdict(list)

    def build(roots, elements):
        if not elements or not roots:
            return
        cur_root = roots.popleft()
        last_num = - inf

        while elements and elements[0] > last_num:
            now = elements.popleft()
            last_num = now
            children[cur_root].append(now)
            roots.append(now)

        build(roots, elements)

    build(dq, arr)

    def trav(cur):
        if not children[cur]:
            return 1
        ans = 0
        for nxt in children[cur]:
            ans = max(ans, trav(nxt))
        return ans + 1

    print(trav(1)-1)


from collections import deque, defaultdict
from math import inf
from sys import setrecursionlimit
import sys
import os
from io import BytesIO, IOBase

#Fast IO Region
BUFSIZE = 8192
class FastIO(IOBase):
    newlines = 0
    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None
    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()
    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()
    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

T = int(input())

for t in range(T):
    levels = [1]
    N = int(input())
    arr = list(map(int, input().split()))
    i = 1
    last_num, node_chunk, level_nodes = -inf, 0, 0
    while i < N:
        for j in range(i, N):
            if arr[j] < last_num:
                node_chunk += 1
                last_num = arr[j]
                if node_chunk >= levels[-1]:
                    levels.append(level_nodes)
                    last_num = arr[j]
                    node_chunk = 0
                    level_nodes = 1
                    break
                level_nodes += 1
            else:
                level_nodes += 1
                last_num = arr[j]
        i = j + 1

    levels.append(level_nodes)
    print(len(levels) - 1)


import sys
import os
from io import BytesIO, IOBase

#Fast IO Region
BUFSIZE = 8192
class FastIO(IOBase):
    newlines = 0
    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None
    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()
    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()
    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

from collections import deque, defaultdict
from math import inf
from sys import setrecursionlimit

setrecursionlimit(300000)

T = int(input())

for tt in range(T):
    N = int(input())
    arr = deque(map(int, input().split()))
    ans = 0

    dq = deque([arr.popleft()])
    children = defaultdict(list)

    def build(roots, elements):
        if not elements:
            return
        cur_root = roots.popleft()
        last_num = - inf

        while elements and elements[0] > last_num:
            now = elements.popleft()
            last_num = now
            children[cur_root].append(now)
            roots.append(now)

        build(roots, elements)

    build(dq, arr)

    def trav(cur):
        if not children[cur]:
            return 1
        ans = 0
        for nxt in children[cur]:
            ans = max(ans, trav(nxt))
        return ans + 1

    print(trav(1)-1)


import sys
import os
from io import BytesIO, IOBase

#Fast IO Region
BUFSIZE = 8192
class FastIO(IOBase):
    newlines = 0
    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None
    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()
    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()
    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

from collections import deque, defaultdict
from math import inf
from sys import setrecursionlimit

setrecursionlimit(300000)

T = int(input())

for tt in range(T):
    N = int(input())
    arr = deque(map(int, input().split()))
    ans = 0

    dq = deque([(arr.popleft(), 0)])
    children = defaultdict(list)

    def build(roots, elements):
        if not elements or not roots:
            return

        global ans
        cur_root, cur_lev = roots.popleft()
        last_num = - inf
        ans = max(ans, cur_lev)

        while elements and elements[0] > last_num:
            now = elements.popleft()
            last_num = now
            children[cur_root].append(now)
            roots.append((now, cur_lev+1))
            ans = max(ans, cur_lev + 1)

        build(roots, elements)

    build(dq, arr)

    def trav(cur):
        if not children[cur]:
            return 1
        ans = 0
        for nxt in children[cur]:
            ans = max(ans, trav(nxt))
        return ans + 1

    print(ans)


import sys, math, itertools, collections, copy

input = sys.stdin.readline

def solve():
    n = int(input())
    a = [int(x) for x in input().split()]
    if n <= 2:
        print(1)
        return
    ans, that_lvl_nodes, prev_lvl_nodes, cur_blocks_nodes = 1, 0, 1, 0
    for i in range(2, n):
        if a[i] < a[i - 1]:
            if cur_blocks_nodes + 1 >= prev_lvl_nodes:
                prev_lvl_nodes = that_lvl_nodes + 1
                that_lvl_nodes = 0
                cur_blocks_nodes = 0
                ans += 1
            else:
                cur_blocks_nodes += 1
                that_lvl_nodes += 1
        else:
            that_lvl_nodes += 1
    print(ans)

for _ in range(int(input())):
    solve()


import sys, math, itertools, collections, copy

input = sys.stdin.readline

def solve():
    n = int(input())
    a = [int(x) for x in input().split()]
    if n <= 2:
        print(1)
        return
    cnt = 1
    for i in range(1, len(a)):
        if a[i] > a[i - 1]:
            continue
        else:
            cnt += 1
    print(cnt)

for _ in range(int(input())):
    solve()


import sys, os.path
from collections import*
from heapq import *
from copy import*
import math
mod=10**9+7
read = lambda: map(int, input().split())
inf=sys.maxsize
if(os.path.exists('input.txt')):
    sys.stdin = open("input.txt","r")
    sys.stdout = open("output.txt","w")

for t in range(int(input())):
    n=int(input())
    a=list(map(int,input().split()))
    cnt=1
    if(n==2):
        print(1)
    else:
        q=deque()
        q.append(0)
        maxx=1
        i=1
        cur=1
        while(i<n):
            if(i==1 or a[i]<a[i-1]):
                d=q[0]
                q.popleft()
                maxx=max(maxx,d+1)
                cur=d+1
                q.append(d+1)
            else:
                q.append(cur)
            i+=1
        print(maxx)


import sys, os.path
from collections import*
from heapq import *
from copy import*
import math
mod=10**9+7
read = lambda: map(int, input().split())
inf=sys.maxsize
if(os.path.exists('input.txt')):
    sys.stdin = open("input.txt","r")
    sys.stdout = open("output.txt","w")

for t in range(int(input())):
    n=int(input())
    a=list(map(int,input().split()))
    cnt=1
    if(n==2):
        print(1)
    else:
        q=deque()
        q.append(0)
        maxx=1
        i=1
        cur=1

        while(i<n):
            d=q.popleft()
            if(a[i]<a[i-1]):
                q.append(d+1)
                maxx=max(maxx,d+1)
                cur=d+1
            else:
                q.append(cur)
            i+=1
        print(maxx)


import sys, os.path
from collections import*
from heapq import *
from copy import*
import math
mod=10**9+7
read = lambda: map(int, input().split())
inf=sys.maxsize
if(os.path.exists('input.txt')):
    sys.stdin = open("input.txt","r")
    sys.stdout = open("output.txt","w")

for t in range(int(input())):
    n=int(input())
    a=list(map(int,input().split()))
    cnt=1
    if(n==2):
        print(1)
    else:
        q=deque()
        q.append(0)
        maxx=1
        i=1
        cur=1
        while(i<n):
            if(a[i]<a[i-1]):
                d=q[0]
                q.popleft()
                maxx=max(maxx,d+1)
                cur=d+1
                q.append(d+1)
            else:
                q.append(cur)
            i+=1
        print(maxx)


import sys, os.path
from collections import*
from heapq import *
from copy import*
import math
mod=10**9+7
read = lambda: map(int, input().split())
inf=sys.maxsize
if(os.path.exists('input.txt')):
    sys.stdin = open("input.txt","r")
    sys.stdout = open("output.txt","w")

for t in range(int(input())):
    n=int(input())
    a=list(map(int,input().split()))
    cnt=1
    if(n==2):
        print(1)
    else:
        for i in range(1,n):
            if(a[i]>a[i-1]):
                continue
            else:
                cnt+=1
        print(cnt)