#include <bits/stdc++.h>

using namespace std;

int main(){
	int n, temp, neg=0;
	vector <int> ans, zeros;
	cin>>n;

	for(int i=0; i<n; i++){
		cin>>temp;
		if(temp==0){
			zeros++;
			continue;
		}
		if(temp<0){
			if(neg==0){
				neg=temp;
				continue;
			}
			else{
				zeros.push_back(temp);
				continue;
			}
		}
		ans.push_back(temp);
	}

	cout<<1<<" "<<neg<<endl;
	cout<<ans.size();
	for(int i=0; i<ans.size(); i++){
		cout<<" "<<ans[i];
	}
	cout<<endl;
	cout<<zeros;
	for(int i=0; i<zeros; i++){
		cout<<" "<<0;
	}
	cout<<endl;
}


#include <bits/stdc++.h>

using namespace std;

int main(){
	int n, temp, zeros=0, neg=0;
	vector <int> ans;
	cin>>n;

	for(int i=0; i<n; i++){
		cin>>temp;
		if(temp==0){
			zeros++;
			continue;
		}
		if(temp<0&&neg==0){
			neg=temp;
			continue;
		}
		ans.push_back(temp);
	}

	temp=1;
	sort(ans.begin(), ans.end());
	for(int i=0; i<ans.size(); i++){
		temp*=ans[i];
	}

	int negzero=0;
	if(temp<0){
		negzero=ans[0];
	}

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

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main(){
	int n, temp, zeros=0, neg=0;
	vector <int> ans;
	cin>>n;

	for(int i=0; i<n; i++){
		cin>>temp;
		if(temp==0){
			zeros++;
			continue;
		}
		if(temp<0&&neg==0){
			neg=temp;
			continue;
		}
		ans.push_back(temp);
	}

	cout<<1<<" "<<neg<<endl;
	cout<<ans.size;
	for(int i=0; i<ans.size(); i++){
		cout<<" "<<ans[i];
	}
	cout<<endl;
	cout<<zeros;
	for(int i=0; i<zeros; i++){
		cout<<" "<<0;
	}
	cout<<endl;
}


#include <bits/stdc++.h>

using namespace std;

int main(){
	int n, temp, zeros=0, neg=0;
	vector <int> ans;
	cin>>n;

	for(int i=0; i<n; i++){
		cin>>temp;
		if(temp==0){
			zeros++;
			continue;
		}
		if(temp<0&&neg==0){
			neg=temp;
			continue;
		}
		ans.push_back(temp);
	}

	cout<<1<<" "<<neg<<endl;
	cout<<ans.size();
	for(int i=0; i<ans.size(); i++){
		cout<<" "<<ans[i];
	}
	cout<<endl;
	cout<<zeros;
	for(int i=0; i<zeros; i++){
		cout<<" "<<0;
	}
	cout<<endl;
}


#include <bits/stdc++.h>

using namespace std;

int main(){
	int n, temp, zeros=0, neg=0;
	vector <int> ans;
	cin>>n;

	for(int i=0; i<n; i++){
		cin>>temp;
		if(temp==0){
			zeros++;
			continue;
		}
		if(temp<0&&neg==0){
			neg=temp;
			continue;
		}
		ans.push_back(temp);
	}

	temp=0;
	sort(ans.begin(), ans.end());
	for(int i=0; i<ans.size(); i++){
		if(ans[i]<0) temp++;
	}

	int negzero=0;
	if(temp%2==1){
		negzero=ans[0];
	}

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

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main(){
	int n, temp, neg=0;
	vector <int> ans, zeros;
	cin>>n;

	for(int i=0; i<n; i++){
		cin>>temp;
		if(temp==0){
			zeros.push_back(temp);
			continue;
		}
		if(temp<0){
			if(neg==0){
				neg=temp;
				continue;
			}
			else{
				zeros.push_back(temp);
				continue;
			}
		}
		ans.push_back(temp);
	}

	cout<<1<<" "<<neg<<endl;
	cout<<ans.size();
	for(int i=0; i<ans.size(); i++){
		cout<<" "<<ans[i];
	}
	cout<<endl;
	cout<<zeros.size();
	for(int i=0; i<zeros.size(); i++){
		cout<<" "<<zeros[i];
	}
	cout<<endl;
}


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

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    vector<int> v;
    int a;
    cin>>n;
    for(int i=0; i<n; i++){
      cin>>a;
      v.pushback(a);
    }
    sort(v.begin(),v.end());
    cout<<1<<" "<<v[0]<<"\n";
    if(v[n-1]<1){
      cout<<2<<" "<<v[1]<<" "<<v[1]<<" "<<v[2]<<"\n";
      cout<<n-2<<" ";
      for(i=3; i<n; i++){
        cout<<v[i]<<" ";
      }
    }
    else{
      cout<<1<<" "<<v[n-1]<<"\n";
      cout<<n-2<<" ";
      for(i=1; i<n-1;i++){
        cout<<v[i]<<" ";
      }
    }

    return 0;
}


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

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    vector<int> v;
    int a, n;
    cin>>n;
    for(int i=0; i<n; i++){
      cin>>a;
      v.push_back(a);
    }
    sort(v.begin(),v.end());
    cout<<1<<" "<<v[0]<<"\n";
    if(v[n-1]<1){
      cout<<2<<" "<<v[1]<<" "<<" "<<v[2]<<"\n";
      cout<<n-2<<" ";
      for(int i=3; i<n; i++){
        cout<<v[i]<<" ";
      }
    }
    else{
      cout<<1<<" "<<v[n-1]<<"\n";
      cout<<n-2<<" ";
      for(int i=1; i<n-1;i++){
        cout<<v[i]<<" ";
      }
    }

    return 0;
}


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

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    vector<int> v;
    int a, n;
    cin>>n;
    for(int i=0; i<n; i++){
      cin>>a;
      v.push_back(a);
    }
    sort(v.begin(),v.end());
    cout<<1<<" "<<v[0]<<"\n";
    if(v[n-1]<1){
      cout<<2<<" "<<v[1]<<" "<<v[1]<<" "<<v[2]<<"\n";
      cout<<n-2<<" ";
      for(int i=3; i<n; i++){
        cout<<v[i]<<" ";
      }
    }
    else{
      cout<<1<<" "<<v[n-1]<<"\n";
      cout<<n-2<<" ";
      for(int i=1; i<n-1;i++){
        cout<<v[i]<<" ";
      }
    }

    return 0;
}


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

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    vector<int> v;
    int a, n;
    cin>>n;
    for(int i=0; i<n; i++){
      cin>>a;
      v.push_back(a);
    }
    sort(v.begin(),v.end());
    cout<<1<<" "<<v[0]<<"\n";
    if(v[n-1]<1){
      cout<<2<<" "<<v[1]<<" "<<v[2]<<"\n";
      cout<<n-2<<" ";
      for(int i=3; i<n; i++){
        cout<<v[i]<<" ";
      }
    }
    else{
      cout<<1<<" "<<v[n-1]<<"\n";
      cout<<n-2<<" ";
      for(int i=1; i<n-1;i++){
        cout<<v[i]<<" ";
      }
    }

    return 0;
}


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

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    vector<int> v;
    int a, n;
    cin>>n;
    for(int i=0; i<n; i++){
      cin>>a;
      v.push_back(a);
    }
    sort(v.begin(),v.end());
    cout<<1<<" "<<v[0]<<"\n";
    if(v[n-1]<1){
      cout<<2<<" "<<v[1]<<" "<<" "<<v[2]<<"\n";
      cout<<n-3<<" ";
      for(int i=3; i<n; i++){
        cout<<v[i]<<" ";
      }
    }
    else{
      cout<<1<<" "<<v[n-1]<<"\n";
      cout<<n-2<<" ";
      for(int i=1; i<n-1;i++){
        cout<<v[i]<<" ";
      }
    }

    return 0;
}


#include <iostream>
#include <vector>

using namespace std;

int main()
{
    int n;
    cin>>n;
    int a[n],su(1),su2(0),need(0);
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        if(a[i]<0)
        {
            need++;
        }
    }
    vector<int> f,s,t;
    for(int i=0;i<n;i++)
    {
        if(a[i]==0)
        {
            t.push_back(a[i]);
        }
        else if(a[i]>0)
        {
            s.push_back(a[i]);
            if(su2==0)
            {
                su2=a[i];
            }
            else
            {
                su2*=a[i];
            }
        }
        else if(a[i]<0)
        {
            if(su>0)
            {
                f.push_back(a[i]);
                su*=a[i];
            }
            else if((su2<=0)and(need>2))
            {
                s.push_back(a[i]);
                su2*=a[i];
            }
            else
            {
                t.push_back(a[i]);
            }
        }
    }
    cout<<f.size()<<" ";
    for (int i=0;i<f.size();i++) cout<<f[i]<<" ";
    cout<<endl;
    cout<<s.size()<<" ";
    for (int i=0;i<s.size();i++) cout<<s[i]<<" ";
    cout<<endl;
    cout<<t.size()<<" ";
    for (int i=0;i<t.size();i++) cout<<t[i]<<" ";
    cout<<endl;
}


#include <iostream>
#include <vector>

using namespace std;

int main()
{
    int n;
    cin>>n;
    int a[n],su(1),su2(0),need(1);
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        if(a[i]<0)
        {
            need*=a[i];
        }
    }
    vector<int> f,s,t;
    for(int i=0;i<n;i++)
    {
        if(a[i]==0)
        {
            t.push_back(a[i]);
        }
        else if(a[i]>0)
        {
            s.push_back(a[i]);
            su2=a[i];
        }
        else if(a[i]<0)
        {
            if(su>0)
            {
                f.push_back(a[i]);
                su*=a[i];
            }
            else if((su2<=0)and(need<0))
            {
                s.push_back(a[i]);
                su2*=a[i];
            }
            else
            {
                t.push_back(a[i]);
            }
        }
    }
    cout<<f.size()<<" ";
    for (int i=0;i<f.size();i++) cout<<f[i]<<" ";
    cout<<endl;
    cout<<s.size()<<" ";
    for (int i=0;i<s.size();i++) cout<<s[i]<<" ";
    cout<<endl;
    cout<<t.size()<<" ";
    for (int i=0;i<t.size();i++) cout<<t[i]<<" ";
    cout<<endl;
}


#include <iostream>
#include <vector>

using namespace std;

int main()
{
    int n;
    cin>>n;
    int a[n],su(1),su2(0),need(0);
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        if(a[i]<0)
        {
            need++;
        }
    }
    vector<int> f,s,t;
    for(int i=0;i<n;i++)
    {
        if(a[i]==0)
        {
            t.push_back(a[i]);
        }
        else if(a[i]>0)
        {
            s.push_back(a[i]);
            su2=a[i];
        }
        else if(a[i]<0)
        {
            if(su>0)
            {
                f.push_back(a[i]);
                su*=a[i];
            }
            else if((su2<=0)and(need>2))
            {
                s.push_back(a[i]);
                su2*=a[i];
            }
            else
            {
                t.push_back(a[i]);
            }
        }
    }
    cout<<f.size()<<" ";
    for (int i=0;i<f.size();i++) cout<<f[i]<<" ";
    cout<<endl;
    cout<<s.size()<<" ";
    for (int i=0;i<s.size();i++) cout<<s[i]<<" ";
    cout<<endl;
    cout<<t.size()<<" ";
    for (int i=0;i<t.size();i++) cout<<t[i]<<" ";
    cout<<endl;
}


#include <iostream>
#include <vector>

using namespace std;

int main()
{
    int n;
    cin>>n;
    int a[n],su(1),su2(0);
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    vector<int> f,s,t;
    for(int i=0;i<n;i++)
    {
        if(a[i]==0)
        {
            t.push_back(a[i]);
        }
        else if(a[i]>0)
        {
            s.push_back(a[i]);
            su2=a[i];
        }
        else if(a[i]<0)
        {
            if(su>0)
            {
                f.push_back(a[i]);
                su*=a[i];
            }
            else if((su2<=0))
            {
                s.push_back(a[i]);
                su2*=a[i];
            }
            else
            {
                t.push_back(a[i]);
            }
        }
    }
    cout<<f.size()<<" ";
    for (int i=0;i<f.size();i++) cout<<f[i]<<" ";
    cout<<endl;
    cout<<s.size()<<" ";
    for (int i=0;i<s.size();i++) cout<<s[i]<<" ";
    cout<<endl;
    cout<<t.size()<<" ";
    for (int i=0;i<t.size();i++) cout<<t[i]<<" ";
    cout<<endl;
}


#include <iostream>
#include <vector>

using namespace std;

int main()
{
    int n;
    cin>>n;
    int a[n],su(1),su2(0),need(0);
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        if(a[i]>0)
        {
            need++;
        }
    }
    vector<int> f,s,t;
    for(int i=0;i<n;i++)
    {
        if(a[i]==0)
        {
            t.push_back(a[i]);
        }
        else if(a[i]>0)
        {
            s.push_back(a[i]);
            {
                su2=a[i];
            }
        }
        else if(a[i]<0)
        {
            if(su>0)
            {
                f.push_back(a[i]);
                su*=a[i];
            }
            else if((su2<=0)and(need==0))
            {
                s.push_back(a[i]);
                if(su2==0)
                {
                    su2=a[i];
                }
                else
                {
                    su2*=a[i];
                }
            }
            else
            {
                t.push_back(a[i]);
            }
        }
    }
    cout<<f.size()<<" ";
    for (int i=0;i<f.size();i++) cout<<f[i]<<" ";
    cout<<endl;
    cout<<s.size()<<" ";
    for (int i=0;i<s.size();i++) cout<<s[i]<<" ";
    cout<<endl;
    cout<<t.size()<<" ";
    for (int i=0;i<t.size();i++) cout<<t[i]<<" ";
    cout<<endl;
}


#include <iostream>
#include <vector>

using namespace std;

int main()
{
    int n;
    cin>>n;
    int a[n],su(1),su2(0),need(0);
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        if(a[i]>0)
        {
            need++;
        }
    }
    vector<int> f,s,t;
    for(int i=0;i<n;i++)
    {
        if(a[i]==0)
        {
            t.push_back(a[i]);
        }
        else if(a[i]>0)
        {
            s.push_back(a[i]);
            {
                su2=a[i];
            }
        }
        else if(a[i]<0)
        {
            if(su>0)
            {
                f.push_back(a[i]);
                su*=a[i];
            }
            else if((su2<=0)and(need==0))
            {
                s.push_back(a[i]);
                su2*=a[i];
            }
            else
            {
                t.push_back(a[i]);
            }
        }
    }
    cout<<f.size()<<" ";
    for (int i=0;i<f.size();i++) cout<<f[i]<<" ";
    cout<<endl;
    cout<<s.size()<<" ";
    for (int i=0;i<s.size();i++) cout<<s[i]<<" ";
    cout<<endl;
    cout<<t.size()<<" ";
    for (int i=0;i<t.size();i++) cout<<t[i]<<" ";
    cout<<endl;
}


#include <iostream>
using namespace std;

int n,c,t,a,x,i,j;

main(){

	cin>>n>>t>>c;

	while(i<n){
		cin>>a;
		if(a<=t){x++;}
		else {x=0;}
		if(x>=c){j++;}
		i++;
	}
	cout<<j;
}


# include <bits/stdc++.h>

using namespace std;

#define ll long long
#define ld long double
#define ull unsigned long long

const int linf = (int)1e9 + 7;
const int N = (int)200;

int n;

int a[N];

vector < int > ans1;
vector < int > ans2;
vector < int > ans3;

void printans(){
  cout << ans1.size() << " ";
  for(auto i : ans1){
    cout << i << " ";
  }
  cout << endl;
  cout << ans2.size() << " ";
  for(auto i : ans2){
    cout << i << " ";
  }
  cout << endl;
  cout << ans3.size() << " ";
  for(auto i : ans3){
    cout << i << " ";
  }
}

int main(){
  scanf("%d", &n);
  for(int i = 1; i <= n; i++){
    scanf("%d", &a[i]);
    if(a[i] == 0)
      ans3.push_back(a[i]);
    if(a[i] > 0)
      ans2.push_back(a[i]);
    if(a[i] < 0)
      ans1.push_back(a[i]);
  }
  if(ans2.size() == 0){
    if(ans1.size() > 1){
      ans2.push_back(ans1[ans1.size() - 1]);
      ans2.push_back(ans1[ans1.size() - 2]);
      ans1.pop_back();
      ans1.pop_back();
    }
  }
  printans();
}


# include <bits/stdc++.h>

using namespace std;

#define ll long long
#define ld long double
#define ull unsigned long long

const int linf = (int)1e9 + 7;
const int N = (int)200;

int n;

int a[N];

vector < int > ans1;
vector < int > ans2;
vector < int > ans3;

void printans(){
  cout << 1 << " " << ans1[0] << endl;
  cout << ans2.size() << " ";
  for(auto i : ans2){
    cout << i << " ";
  }
  cout << endl;
  cout << ans3.size() << " ";
  for(auto i : ans3){
    cout << i << " ";
  }
}

int main(){
  scanf("%d", &n);
  for(int i = 1; i <= n; i++){
    scanf("%d", &a[i]);
    if(a[i] == 0)
      ans3.push_back(a[i]);
    if(a[i] > 0)
      ans2.push_back(a[i]);
    if(a[i] < 0)
      ans1.push_back(a[i]);
  }
  for(int i = ans1.size() - 1; i >= 1; i--){
    int x = ans1[i];
    ans2.push_back(x);
  }
  printans();
}


# include <bits/stdc++.h>

using namespace std;

#define ll long long
#define ld long double
#define ull unsigned long long

const int linf = (int)1e9 + 7;
const int N = (int)200;

int n;

int a[N];

vector < int > ans1;
vector < int > ans2;
vector < int > ans3;

void printans(){
  cout << 1 << " " << ans1[0] << endl;
  cout << ans2.size() << " ";
  for(auto i : ans2){
    cout << i << " ";
  }
  cout << endl;
  cout << ans3.size() << " ";
  for(auto i : ans3){
    cout << i << " ";
  }
}

int main(){
  scanf("%d", &n);
  for(int i = 1; i <= n; i++){
    scanf("%d", &a[i]);
    if(a[i] == 0)
      ans3.push_back(a[i]);
    if(a[i] > 0)
      ans2.push_back(a[i]);
    if(a[i] < 0)
      ans1.push_back(a[i]);
  }
  if(ans2.size() == 0){
    if(ans1.size() > 1){
      ans2.push_back(ans1[ans1.size() - 1]);
      ans2.push_back(ans1[ans1.size() - 2]);
      ans1.pop_back();
      ans1.pop_back();
    }
  }
  if(ans1.size() % 2 == 1){
    for(int i = ans1.size() - 1; i >= 1; i--){
      int x = ans1[i];
      ans2.push_back(x);
    }
  }
  else if(ans1.size() % 2 == 0){
    for(int i = ans1.size() - 1; i >= 1; i--){
      int x = ans1[i];
      ans3.push_back(x);
    }
  }
  printans();
}


# include <bits/stdc++.h>

using namespace std;

#define ll long long
#define ld long double
#define ull unsigned long long

const int linf = (int)1e9 + 7;
const int N = (int)200;

int n;

int a[N];

vector < int > ans1;
vector < int > ans2;
vector < int > ans3;

void printans(){
  cout << 1 << " " << ans1[0] << endl;
  cout << ans2.size() << " ";
  for(auto i : ans2){
    cout << i << " ";
  }
  cout << endl;
  cout << ans3.size() << " ";
  for(auto i : ans3){
    cout << i << " ";
  }
}

int main(){
  scanf("%d", &n);
  for(int i = 1; i <= n; i++){
    scanf("%d", &a[i]);
    if(a[i] == 0)
      ans3.push_back(a[i]);
    if(a[i] > 0)
      ans2.push_back(a[i]);
    if(a[i] < 0)
      ans1.push_back(a[i]);
  }
  if(ans1.size() % 2 == 1){
    for(int i = ans1.size() - 1; i >= 1; i--){
      int x = ans1[i];
      ans2.push_back(x);
    }
  }
  else if(ans1.size() % 2 == 0){
    for(int i = ans1.size() - 1; i >= 1; i--){
      int x = ans1[i];
      ans3.push_back(x);
    }
  }
  printans();
}


# include <bits/stdc++.h>

using namespace std;

#define ll long long
#define ld long double
#define ull unsigned long long

const int linf = (int)1e9 + 7;
const int N = (int)200;

int n;

int a[N];

vector < int > ans1;
vector < int > ans2;
vector < int > ans3;

void printans(){
  cout << ans1.size() << " ";
  for(auto i : ans1){
    cout << i << " ";
  }
  cout << endl;
  cout << ans2.size() << " ";
  for(auto i : ans2){
    cout << i << " ";
  }
  cout << endl;
  cout << ans3.size() << " ";
  for(auto i : ans3){
    cout << i << " ";
  }
}

int main(){
  scanf("%d", &n);
  for(int i = 1; i <= n; i++){
    scanf("%d", &a[i]);
    if(a[i] == 0)
      ans3.push_back(a[i]);
    if(a[i] > 0)
      ans2.push_back(a[i]);
    if(a[i] < 0)
      ans1.push_back(a[i]);
  }
  if(ans2.size() == 0){
    if(ans1.size() > 1){
      ans2.push_back(ans1[0]);
      ans2.push_back(ans1[1]);
    }
  }
  printans();
}


# include <bits/stdc++.h>

using namespace std;

#define ll long long
#define ld long double
#define ull unsigned long long

const int linf = (int)1e9 + 7;
const int N = (int)200;

int n;

int a[N];

vector < int > ans1;
vector < int > ans2;
vector < int > ans3;

void printans(){
  cout << ans1.size() << " ";
  for(auto i : ans1){
    cout << i << " ";
  }
  cout << endl;
  cout << ans2.size() << " ";
  for(auto i : ans2){
    cout << i << " ";
  }
  cout << endl;
  cout << ans3.size() << " ";
  for(auto i : ans3){
    cout << i << " ";
  }
}

int main(){
  scanf("%d", &n);
  for(int i = 1; i <= n; i++){
    scanf("%d", &a[i]);
    if(a[i] == 0)
      ans3.push_back(a[i]);
    if(a[i] > 0)
      ans2.push_back(a[i]);
    if(a[i] < 0)
      ans1.push_back(a[i]);
  }
  if(ans2.size() == 0){
    if(ans1.size() > 1){
      ans2.push_back(ans1[0]);
      ans2.push_back(ans1[1]);
      ans1.pop_back();
      ans1.pop_back();
    }
  }
  printans();
}


#include <bits/stdc++.h>
#define l1 long long int
using namespace std;
void solve()
{
int n;
cin>>n;
int a[n+1];
vector<int>pos;
vector<int>neg;
int zero;
for(int i=0;i<n;i++)
{
    cin>>a[i];
    if(a[i]<0){neg.push_back(a[i]); }
    if(a[i]>0){pos.push_back(a[i]);}
    if(a[i]==0){
        zero++;
    }
}

cout<<"1"<<" "<<neg[0]<<endl;
cout<<pos.size() + neg.size()-1<<" ";
for(int i=0;i<pos.size();i++){
    cout<<pos[i]<<" ";
}
if(neg.size()>1){
    for(int i=1;i<neg.size();i++){
        cout<<neg[i]<<" ";
    }
}
cout<<endl;
if(zero>0){
    cout<<"1"<<" "<<"0";
    cout<<endl;
}
else{
    cout<<"1"<<" "<<"0";
    cout<<endl;
}
}
int main() {
 solve();
}


#include <bits/stdc++.h>
#define l1 long long int
using namespace std;
void solve()
{
int n;
cin>>n;
int a[n+1];
vector<int>pos;
vector<int>neg;
int zero;
for(int i=0;i<n;i++)
{
    cin>>a[i];
    if(a[i]<0){neg.push_back(a[i]); }
    if(a[i]>0){pos.push_back(a[i]);}
    if(a[i]==0){
        zero++;
    }
}
if(neg.size()==0){
    cout<<"-1"<<"10000000"<<endl;;
}
else if( neg.size()>0){
    for(int i=0;i<neg.size();i++){
        cout<<neg[i]<<" ";
    }
    if(neg.size()%2==0){
  cout<<"-1000000"<<endl;
    }
    else{
        cout<<endl;
    }
}
if(pos.size()==0){
    cout<<"-1000000"<<"  "<<"-2000000"<<endl;;
}
else if(pos.size()>0){
for(int i=0;i<pos.size();i++){
    cout<<pos[i]<<" ";
}
cout<<endl;
}
if(zero>0){
    cout<<"0";
    cout<<endl;
}
else{
    cout<<"0";
    cout<<endl;
}
}
int main() {
 solve();
}


#include <bits/stdc++.h>
#define l1 long long int
using namespace std;
void solve()
{
int n;
cin>>n;
int a[n+1];
vector<int>pos;
vector<int>neg;
int zero;
for(int i=0;i<n;i++)
{
    cin>>a[i];
    if(a[i]<0){neg.push_back(a[i]); }
    if(a[i]>0){pos.push_back(a[i]);}
    if(a[i]==0){
        zero++;
    }
}

cout<<"1"<<" "<<neg[0]<<endl;
if(neg.size()%2==0){
cout<<pos.size() + neg.size()-2<<" ";
}
else{
cout<<pos.size() + neg.size()-1<<" ";
}
for(int i=0;i<pos.size();i++){
    cout<<pos[i]<<" ";
}

if(neg.size()%2==0){
    for(int i=1;i<neg.size()-1;i++){
        cout<<neg[i]<<" ";
    }
}
else{
     for(int i=1;i<neg.size();i++){
        cout<<neg[i]<<" ";
    }
}
cout<<endl;
if(neg.size()%2==0){
    cout<<"2"<<" "<<"0"<<" "<<neg[neg.size()-1]<<endl;
}
else{
     cout<<"1"<<" "<<"0"<<endl;
}
}
int main() {
 solve();
}


#include<bits/stdc++.h>
using  namespace std;
int main()
{
int n,i,t,x=0;
cin>>n;
vector<int> p,ne;
for(i=0;i<n;i++)
{
cin>>t;
if(t==0)
x++;
else if(t>0)
p.push_back(t);
else
ne.push_back(t);
}
cout<<"1"<<ne.back()<<endl;
ne.pop_back();
if(p.size()!=0)
{
cout<<"1"<<" "<<p.back();
p.pop_back();
}
else
{
cout<<"2"<<ne.back()<<" ";
ne.pop_back();
cout<<ne.back();
ne.pop_back();
}
cout<<endl;
t=x+p.size()+ne.size();
cout<<t<<" ";
while(x--)
cout<<"0"<<" ";
while(p.size()!=0)
{
cout<<p.back()<<" ";
p.pop_back();
}
while(ne.size()!=0)
{
cout<<ne.back()<<" ";
ne.pop_back();
}
}


#include<bits/stdc++.h>
using  namespace std;
int main()
{
int n,i,t,x;
cin>>n;
vector<int> p,ne;
for(i=0;i<n;i++)
{
cin>>t;
if(t==0)
x=0;
else if(t>0)
p.push_back(t);
else
ne.push_back(t);
}
cout<<"1"<<" "<<ne.back();
ne.pop_back();
cout<<endl;
t=ne.size()+p.size();
cout<<t<<" ";
while(p.size()!=0)
{
cout<<p.back()<<" ";
p.pop_back();
}
while(ne.size()!=0)
{
cout<<ne.back()<<" ";
ne.pop_back();
}
cout<<endl;
cout<<1<<" "<<0;
}


#include<bits/stdc++.h>
using  namespace std;
int main()
{
int n,i,t,x;
cin>>n;
vector<int> p,ne;
for(i=0;i<n;i++)
{
cin>>t;
if(t==0)
x=0;
else if(t>0)
p.push_back(t);
else
ne.push_back(t);
}
if(ne.size()%2==1)
{
cout<<"1"<<" "<<ne.back();
ne.pop_back();
}
else
{
cout<<2<<" "<<ne.back();
ne.pop_back();
cout<<ne.back();
ne.pop_back();
}
cout<<endl;
t=ne.size()+p.size();
cout<<t<<" ";
while(p.size()!=0)
{
cout<<p.back()<<" ";
p.pop_back();
}
while(ne.size()!=0)
{
cout<<ne.back()<<" ";
ne.pop_back();
}
cout<<endl;
cout<<1<<" "<<0;
}


#include<bits/stdc++.h>
using  namespace std;
int main()
{
int n,i,t,x=0;
cin>>n;
vector<int> p,ne;
for(i=0;i<n;i++)
{
cin>>t;
if(t==0)
x++;
else if(t>0)
p.push_back(t);
else
ne.push_back(t);
}
cout<<"1"<<" "<<ne.back()<<endl;
ne.pop_back();
if(p.size()!=0)
{
cout<<"1"<<" "<<p.back();
p.pop_back();
}
else
{
cout<<"2"<<ne.back()<<" ";
ne.pop_back();
cout<<ne.back();
ne.pop_back();
}
cout<<endl;
t=x+p.size()+ne.size();
cout<<t<<" ";
while(x--)
cout<<"0"<<" ";
while(p.size()!=0)
{
cout<<p.back()<<" ";
p.pop_back();
}
while(ne.size()!=0)
{
cout<<ne.back()<<" ";
ne.pop_back();
}
}


#include<bits/stdc++.h>
using  namespace std;
int main()
{
int n,i,t,x=0;
cin>>n;
vector<int> p,ne;
for(i=0;i<n;i++)
{
cin>>t;
if(t==0)
x++;
else if(t>0)
p.push_back(t);
else
ne.push_back(t);
}
cout<<"1"<<" "<<ne.back()<<endl;
ne.pop_back();
if(p.size()!=0)
{
cout<<"1"<<" "<<p.back();
p.pop_back();
}
else
{
cout<<"2"<<" "<<ne.back()<<" ";
ne.pop_back();
cout<<ne.back();
ne.pop_back();
}
cout<<endl;
t=x+p.size()+ne.size();
cout<<t<<" ";
while(x--)
cout<<"0"<<" ";
while(p.size()!=0)
{
cout<<p.back()<<" ";
p.pop_back();
}
while(ne.size()!=0)
{
cout<<ne.back()<<" ";
ne.pop_back();
}
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define tle ios_base::sync_with_stdio(false); cin.tie(NULL);
#define pb push_back
#define f first
#define s second
#define sparrow(i , a ,b) for(int i = a; i <= b; i++)
#define barbosa(i , b , a)for(int i = b; i >= a; i--)
#define jack(c,i) for(auto i = (c).begin(); i != (c).end(); ++i)
#define all(c) (c).begin(),(c).end()

int main()
{
	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	int n;

	cin >> n;

	int a[n];

	sparrow(i,0,n-1)
	{
		cin >> a[i];
	}

    vector<vector<int>>ans(3);

    bool ok = true , k = true;

    int cnt = 0;

    sparrow(i,0,n-1)
    {
        if(a[i] < 0)
        {
        	cnt++;

        }

    }

    if(cnt % 2 == 0)
    {
    	sparrow(i,0,n-1)
    	{
    		if(a[i] < 0)
    		{
    			if(ok){
    			ans[0].pb(a[i]);
    			ok = false;
    		    }
    		    else if(k)
    		    {
    		    	ans[2].pb(a[i]);
    		    	k = false;
    		    }
    		    else{
    		    	ans[1].pb(a[i]);
    		    }

    		}
    		else if(a[i] == 0)
    		{
    			ans[2].pb(a[i]);
    		}
    		else
    		{
    			ans[1].pb(a[i]);
    		}
    	}

    }
    else{

       sparrow(i,0,n-1)
       {
       	   if(a[i] < 0)
       	   {  if(ok){

       	   	     ans[0].pb(a[i]);
       	   	     ok = false;
       	   	    }

       	   	 else
       	   	 {
       	   	 	ans[1].pb(a[i]);
       	   	 }

       	   }
       	   else if(a[i] == 0)
       	   {
       	   	 ans[2].pb(a[i]);
       	   }
       	   else
       	   {
       	   	 ans[1].pb(a[i]);
       	   }
       }
    }

    sparrow(i,0,2)
    {
    	cout << ans[i].size()<<" ";
       for(int j = 0; j < ans[i].size(); j++)
       {
       	 cout << ans[i][j] << " ";
       }

       cout << endl;
    }
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define tle ios_base::sync_with_stdio(false); cin.tie(NULL);
#define pb push_back
#define f first
#define s second
#define sparrow(i , a ,b) for(int i = a; i <= b; i++)
#define barbosa(i , b , a)for(int i = b; i >= a; i--)
#define jack(c,i) for(auto i = (c).begin(); i != (c).end(); ++i)
#define all(c) (c).begin(),(c).end()

int main()
{
	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	int n;

	cin >> n;

	int a[n];

	sparrow(i,0,n-1)
	{
		cin >> a[i];
	}

    vector<vector<int>>ans(3);

    bool ok = true;

    sparrow(i,0,n-1)
    {
        if(a[i] < 0)
        {
        	if(ok)
        	{
        		ans[0].push_back(a[i]);
        		ok = false;
        	}
        	else
        	{
        		ans[2].push_back(a[i]);
        	}

        }
        else if(a[i] == 0)
        {
        	ans[2].push_back(a[i]);
        }
        else if(a[i] > 0)
        {
        	ans[1].push_back(a[i]);
        }
    }

    sparrow(i,0,2)
    {
    	cout << ans[i].size()<<" ";
       for(int j = 0; j < ans[i].size(); j++)
       {
       	 cout << ans[i][j] << " ";
       }

       cout << endl;
    }
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define tle ios_base::sync_with_stdio(false); cin.tie(NULL);
#define pb push_back
#define f first
#define s second
#define sparrow(i , a ,b) for(int i = a; i <= b; i++)
#define barbosa(i , b , a)for(int i = b; i >= a; i--)
#define jack(c,i) for(auto i = (c).begin(); i != (c).end(); ++i)
#define all(c) (c).begin(),(c).end()

int main()
{
	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	int n;

	cin >> n;

	int a[n];

	sparrow(i,0,n-1)
	{
		cin >> a[i];
	}

    vector<vector<int>>ans(3);

    bool ok = true , k = true;

    int cnt = 0;

    sparrow(i,0,n-1)
    {
        if(a[i] < 0)
        {
        	cnt++;

        }

    }

    if(cnt % 2 == 0)
    {
    	sparrow(i,0,n-1)
    	{
    		if(a[i] < 0)
    		{
    			if(ok){
    			ans[0].pb(a[i]);
    			ok = false;
    		    }
    		    else if(k)
    		    {
    		    	ans[2].pb(a[i]);
    		    	k = false;
    		    }
    		    else{
    		    	ans[1].pb(a[i]);
    		    }

    		}
    		else if(a[i] == 0)
    		{
    			ans[1].pb(a[i]);
    		}
    		else
    		{
    			ans[2].pb(a[i]);
    		}
    	}

    }
    else{

       sparrow(i,0,n-1)
       {
       	   if(a[i] < 0)
       	   {  if(ok){

       	   	     ans[0].pb(a[i]);
       	   	     ok = false;
       	   	    }

       	   	 else
       	   	 {
       	   	 	ans[1].pb(a[i]);
       	   	 }

       	   }
       	   else if(a[i] == 0)
       	   {
       	   	 ans[2].pb(a[i]);
       	   }
       	   else
       	   {
       	   	 ans[1].pb(a[i]);
       	   }
       }
    }

    sparrow(i,0,2)
    {
    	cout << ans[i].size()<<" ";
       for(int j = 0; j < ans[i].size(); j++)
       {
       	 cout << ans[i][j] << " ";
       }

       cout << endl;
    }
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define tle ios_base::sync_with_stdio(false); cin.tie(NULL);
#define pb push_back
#define f first
#define s second
#define sparrow(i , a ,b) for(int i = a; i <= b; i++)
#define barbosa(i , b , a)for(int i = b; i >= a; i--)
#define jack(c,i) for(auto i = (c).begin(); i != (c).end(); ++i)
#define all(c) (c).begin(),(c).end()

int main()
{
	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	int n;

	cin >> n;

	int a[n];

	sparrow(i,0,n-1)
	{
		cin >> a[i];
	}

    vector<vector<int>>ans(3);

    bool ok = true;

    sparrow(i,0,n-1)
    {
        if(a[i] < 0)
        {
        	if(ok)
        	{
        		ans[0].push_back(a[i]);
        		ok = false;
        	}
        	else
        	{
        		ans[2].push_back(a[i]);
        	}

        }
        else if(a[i] == 0)
        {
        	ans[2].push_back(a[i]);
        }
        else
        {
        	ans[1].push_back(a[i]);
        }
    }

    sparrow(i,0,2)
    {
    	cout << ans[i].size()<<" ";
       for(int j = 0; j < ans[i].size(); j++)
       {
       	 cout << ans[i][j] << " ";
       }

       cout << endl;
    }
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define tle ios_base::sync_with_stdio(false); cin.tie(NULL);
#define pb push_back
#define f first
#define s second
#define sparrow(i , a ,b) for(int i = a; i <= b; i++)
#define barbosa(i , b , a)for(int i = b; i >= a; i--)
#define jack(c,i) for(auto i = (c).begin(); i != (c).end(); ++i)
#define all(c) (c).begin(),(c).end()

int main()
{
	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	int n;

	cin >> n;

	int a[n];

	sparrow(i,0,n-1)
	{
		cin >> a[i];
	}

    vector<vector<int>>ans(3);

    bool ok = true;

    sparrow(i,0,n-1)
    {
        if(a[i] < 0)
        {
        	if(ok)
        	{
        		ans[0].push_back(a[i]);
        		ok = false;
        	}
        	else
        	{
        		ans[1].push_back(a[i]);
        	}

        }
        else if(a[i] == 0)
        {
        	ans[2].push_back(a[i]);
        }
        else
        {
        	ans[1].push_back(a[i]);
        }
    }

    sparrow(i,0,2)
    {
       for(int j = 0; j < ans[i].size(); j++)
       {
       	 cout << ans[i][j] << " ";
       }

       cout << endl;
    }
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define tle ios_base::sync_with_stdio(false); cin.tie(NULL);
#define pb push_back
#define f first
#define s second
#define sparrow(i , a ,b) for(int i = a; i <= b; i++)
#define barbosa(i , b , a)for(int i = b; i >= a; i--)
#define jack(c,i) for(auto i = (c).begin(); i != (c).end(); ++i)
#define all(c) (c).begin(),(c).end()

int main()
{
	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	int n;

	cin >> n;

	int a[n];

	sparrow(i,0,n-1)
	{
		cin >> a[i];
	}

    vector<vector<int>>ans(3);

    bool ok = true;

    sparrow(i,0,n-1)
    {
        if(a[i] < 0)
        {
        	if(ok)
        	{
        		ans[0].push_back(a[i]);
        		ok = false;
        	}
        	else
        	{
        		ans[1].push_back(a[i]);
        	}

        }
        else if(a[i] == 0)
        {
        	ans[2].push_back(a[i]);
        }
        else
        {
        	ans[1].push_back(a[i]);
        }
    }

    sparrow(i,0,2)
    {
    	cout << ans[i].size()<<" ";
       for(int j = 0; j < ans[i].size(); j++)
       {
       	 cout << ans[i][j] << " ";
       }

       cout << endl;
    }
}


#include<iostream>
#include<vector>
using namespace std;
vector<int>v1,v2,v3;
int main()
{
    int n,i,j,k,a;
    cin>>n;
    for(i=0;i<n;i++){
        cin>>a;
        if(a<0) v1.push_back(a);
        else if(a>0) v2.push_back(a);
        else if(a==0) v3.push_back(a);
    }
    if((v1.size() & 1)==0){
        v3.push_back(v1[v1.size()-1]);
    }
    if(v2.size()==0){
        v2.push_back(v1[v1.size()-1]);
        v1.pop_back();
        v2.push_back(v1[v1.size()-1]);
        v1.pop_back();
    }
    cout<<v1.size()<<" ";
    for(k=0;k<v1.size();k++) cout<<v1[k]<<" ";
    cout<<endl;
    cout<<v2.size()<<" ";
    for(k=0;k<v2.size();k++) cout<<v2[k]<<" ";
    cout<<endl;
    cout<<v3.size()<<" ";
    for(k=0;k<v3.size();k++) cout<<v3[k]<<" ";
    cout<<endl;
}


#include<iostream>
#include<vector>
using namespace std;
vector<int>v1,v2,v3;
int main()
{
    int n,i,j,k,a;
    cin>>n;
    for(i=0;i<n;i++){
        cin>>a;
        if(a<0) v1.push_back(a);
        else if(a>0) v2.push_back(a);
        else if(a==0) v3.push_back(a);
    }
    if((v1.size() & 1)==0){
        v3.push_back(v1[v1.size()-1]);
        v1.pop_back();
    }
    if(v2.size()==0){
        v2.push_back(v1[v1.size()-1]);
        v1.pop_back();
        v2.push_back(v1[v1.size()-1]);
        v1.pop_back();
    }
    cout<<v1.size()<<" ";
    for(k=0;k<v1.size();k++) cout<<v1[k]<<" ";
    cout<<endl;
    cout<<v2.size()<<" ";
    for(k=0;k<v2.size();k++) cout<<v2[k]<<" ";
    cout<<endl;
    cout<<v3.size()<<" ";
    for(k=0;k<v3.size();k++) cout<<v3[k]<<" ";
    cout<<endl;
}


#include<iostream>
using namespace std;
int main()
{
    int n,i,j,k,count=0,sum=1,last,x;
    cin>>n;
    int ara[n];
    for(i=0;i<n;i++) cin>>ara[i];
    for(i=0;i<n;i++){
        j=i;
        sum*=ara[i];
        count++;
        if(sum<0){
            x=i;
            cout<<count<<" ";
            for(k=0;k<=x;k++) cout<<ara[k]<<" ";
            cout<<endl;
            last=i+1;
            break;
        }
    }
    //cout<<last<<endl;
    sum=1;
    count=0;
    for(i=last;i<n;i++){
        sum*=ara[i];
        count++;
        if(sum>0){
            x=i;
            cout<<count<<" ";
            for(k=last;k<=x;k++) cout<<ara[k]<<" ";
            cout<<endl;
            last=i+1;
            break;
        }
    }
    //cout<<last<<endl;
    sum=1;
    count=0;
    for(i=last;i<n;i++){
        sum*=ara[i];
        count++;
        if(sum==0){
            x=i;
            cout<<count<<" ";
            for(k=last;k<=x;k++) cout<<ara[k]<<" ";
            cout<<endl;
            last=i+1;
            break;
        }
    }
    //cout<<last<<endl;
}


#include<iostream>
using namespace std;
int main()
{
    int n,i,j,k,count=0,sum=1,last=0,x;
    cin>>n;
    int ara[n];
    for(i=0;i<n;i++) cin>>ara[i];
    for(i=0;i<n;i++){
        j=i;
        sum*=ara[i];
        count++;
        if(sum<0){
            x=i;
            cout<<count<<" ";
            for(k=0;k<=x;k++) cout<<ara[k]<<" ";
            cout<<endl;
            last=i+1;
            break;
        }
    }
    if(sum>=0){
        cout<<0<<endl;
    }
    //cout<<last<<endl;
    sum=1;
    count=0;
    for(i=last;i<n;i++){
        sum*=ara[i];
        count++;
        if(sum>0){
            x=i;
            cout<<count<<" ";
            for(k=last;k<=x;k++) cout<<ara[k]<<" ";
            cout<<endl;
            last=i+1;
            break;
        }
    }
    if(sum<=0){
        cout<<0<<endl;
    }
    //cout<<last<<endl;
    sum=1;
    count=0;
    for(i=last;i<n;i++){
        sum*=ara[i];
        count++;
            x=i;
    }
        if(sum==0){
            cout<<count<<" ";
            for(k=last;k<=x;k++) cout<<ara[k]<<" ";
            cout<<endl;
            last=i+1;
            //break;
        }
    if(sum!=0){
        cout<<0<<endl;
    }

    //cout<<last<<endl;
}


#include<iostream>
using namespace std;
int main()
{
    int n,i,j,k,count=0,sum=1,last=0,x;
    cin>>n;
    int ara[n];
    for(i=0;i<n;i++) cin>>ara[i];
    for(i=0;i<n;i++){
        j=i;
        sum*=ara[i];
        count++;
        if(sum<0){
            x=i;
            cout<<count<<" ";
            for(k=0;k<=x;k++) cout<<ara[k]<<" ";
            cout<<endl;
            last=i+1;
            break;
        }
    }
    if(sum>=0){
        cout<<0<<endl;
    }
    //cout<<last<<endl;
    sum=1;
    count=0;
    for(i=last;i<n;i++){
        sum*=ara[i];
        count++;
        if(sum>0){
            x=i;
            cout<<count<<" ";
            for(k=last;k<=x;k++) cout<<ara[k]<<" ";
            cout<<endl;
            last=i+1;
            break;
        }
    }
    if(sum<=0){
        cout<<0<<endl;
    }
    //cout<<last<<endl;
    sum=1;
    count=0;
    for(i=last;i<n;i++){
        sum*=ara[i];
        count++;
        if(sum==0){
            x=i;
            cout<<count<<" ";
            for(k=last;k<=x;k++) cout<<ara[k]<<" ";
            cout<<endl;
            last=i+1;
            break;
        }
    }
    if(sum!=0){
        cout<<0<<endl;
    }

    //cout<<last<<endl;
}


#include<iostream>
#include<vector>
#include <cstdio>
using namespace std;
int main ()
{
    int n,c1=0,c2=0,c3=0;
    cin>>n;
    int x[n];
    vector<int> vPositive,vNegative,vZero;
    for (int i=0;i<n;i++)
    {
        scanf("%d",&x[i]);
        if (x[i]>0){
            vPositive.push_back(x[i]);
            c1++;}
        else if (x[i]<0){
            vNegative.push_back(x[i]);
            c2++;}

        else{
            vZero.push_back(x[i]);
            c3++;}
    }
    if (vNegative.size()%2==0)
    {
        vZero.push_back(vNegative.back());
        vNegative.pop_back();

        c2--;
        c3++;

    }
    if (vPositive.size()==0)
    {
        vPositive.push_back(vNegative.back());
        vNegative.pop_back();

        vPositive.push_back(vNegative.back());
        vNegative.pop_back();

        c2-=2;
        c1+=2;

    }
        cout<<c2;
    for (int i=0;i<vNegative.size();i++)
        cout<<" "<<vNegative[i];
    cout<<endl<<c1;
    for (int i=0;i<vPositive.size();i++)
        cout<<" "<<vPositive[i];
    cout<<endl<<c3;
    for (int i=0;i<vZero.size();i++)
        cout<<" "<<vZero[i];
    cout<<endl;

    return 0;
}


#include<iostream>
#include<vector>
using namespace std;
int main ()
{
    int n,c1=0,c2=0,c3=0;
    cin>>n;
    int x[n];
    vector<int> vPositive,vNegative,vZero;
    for (int i=0;i<n;i++)
    {
        scanf("%d",&x[i]);
        if (x[i]>0){
            vPositive.push_back(x[i]);
            c1++;}
        else if (x[i]<0){
            vNegative.push_back(x[i]);
            c2++;}

        else{
            vZero.push_back(x[i]);
            c3++;}
    }
    if (vPositive.size()==0&&vNegative.size()%2==0)
    {
        vPositive.push_back(x[0]);
        vPositive.push_back(x[1]);
        vZero.push_back(x[2]);

    vNegative.erase(vNegative.begin(),vNegative.begin()+3);

        c2-=3;
        c1+=2;
        c3++;
    }
    else if (vPositive.size()==0&&vNegative.size()%2!=0)
    {
        vPositive.push_back(x[0]);
        vPositive.push_back(x[1]);

        vNegative.erase(vNegative.begin(),vNegative.begin()+2);

        c2-=2;
        c1+=2;

    }
    else if (vNegative.size()%2==0&&vPositive.size()>0)
    {
        vNegative.erase(vNegative.begin());
        vZero.push_back(x[0]);
        c2--;
        c3++;

    }
    cout<<c2;
    for (int i=0;i<vNegative.size();i++)
        cout<<" "<<vNegative[i];
    cout<<endl<<c1;
    for (int i=0;i<vPositive.size();i++)
        cout<<" "<<vPositive[i];
    cout<<endl<<c3;
    for (int i=0;i<vZero.size();i++)
        cout<<" "<<vZero[i];
    cout<<endl;

    return 0;
}


#include<iostream>
#include<vector>
using namespace std;
int main ()
{
    int n,c1=0,c2=0,c3=0;
    cin>>n;
    int x[n];
    vector<int> vPositive,vNegative,vZero;
    for (int i=0;i<n;i++)
    {
        scanf("%d",&x[i]);
        if (x[i]>0){
            vPositive.push_back(x[i]);
            c1++;}
        else if (x[i]<0){
            vNegative.push_back(x[i]);
            c2++;}

        else{
            vZero.push_back(x[i]);
            c3++;}
    }
    if (vPositive.size()==0&&vNegative.size()%2==0)
    {
        vPositive.push_back(x[0]);
        vPositive.push_back(x[1]);
        vZero.push_back(x[2]);

    vNegative.erase(vNegative.begin(),vNegative.begin()+3);

        c2-=3;
        c1+=2;
        c3++;
    }
    else if (vPositive.size()==0&&vNegative.size()%2!=0)
    {
        vPositive.push_back(x[0]);
        vPositive.push_back(x[1]);

        vNegative.erase(vNegative.begin(),vNegative.begin()+2);

        c2-=2;
        c1+=2;

    }
    cout<<c2;
    for (int i=0;i<vNegative.size();i++)
        cout<<" "<<vNegative[i];
    cout<<endl<<c1;
    for (int i=0;i<vPositive.size();i++)
        cout<<" "<<vPositive[i];
    cout<<endl<<c3;
    for (int i=0;i<vZero.size();i++)
        cout<<" "<<vZero[i];
    cout<<endl;

    return 0;
}


#include<iostream>
#include<vector>
using namespace std;
int main ()
{
    int n,c1=0,c2=0,c3=0;
    cin>>n;
    int x[n];
    vector<int> vPositive,vNegative,vZero;
    for (int i=0;i<n;i++)
    {
        scanf("%d",&x[i]);
        if (x[i]>0){
            vPositive.push_back(x[i]);
            c1++;}
        else if (x[i]<0){
            vNegative.push_back(x[i]);
            c2++;}

        else{
            vZero.push_back(x[i]);
            c3++;}
    }
    if (vPositive.size()==0&&vNegative.size()%2==0)
    {
        vPositive.push_back(x[0]);
        vPositive.push_back(x[1]);
        vZero.push_back(x[2]);

    vNegative.erase(vNegative.begin(),vNegative.begin()+3);

        c2-=3;
        c1+=2;
        c3++;
    }
    else if (vPositive.size()==0&&vNegative.size()%2!=0)
    {
        vPositive.push_back(x[0]);
        vPositive.push_back(x[1]);

        vNegative.erase(vNegative.begin());
        vNegative.erase(vNegative.begin()+1);

        c2-=2;
        c1+=2;

    }
    cout<<c2;
    for (int i=0;i<vNegative.size();i++)
        cout<<" "<<vNegative[i];
    cout<<endl<<c1;
    for (int i=0;i<vPositive.size();i++)
        cout<<" "<<vPositive[i];
    cout<<endl<<c3;
    for (int i=0;i<vZero.size();i++)
        cout<<" "<<vZero[i];
    cout<<endl;

    return 0;
}


#include<iostream>
#include<vector>
using namespace std;
int main ()
{
    int n,c1=0,c2=0,c3=0;
    cin>>n;
    int x[n];
    vector<int> vPositive,vNegative,vZero;
    for (int i=0;i<n;i++)
    {
        scanf("%d",&x[i]);
        if (x[i]>0){
            vPositive.push_back(x[i]);
            c1++;}
        else if (x[i]<0){
            vNegative.push_back(x[i]);
            c2++;}

        else{
            vZero.push_back(x[i]);
            c3++;}
    }
    if (vNegative.size()%2==0)
    {
        vZero.push_back(x[0]);
        vNegative.erase(vNegative.begin());

        c2--;
        c3++;

    }
    if (vPositive.size()==0)
    {
        vPositive.push_back(x[1]);
        vPositive.push_back(x[2]);

        vNegative.erase(vNegative.begin()+1,vNegative.begin()+3);

        c2-=2;
        c1+=2;

    }
        cout<<c2;
    for (int i=0;i<vNegative.size();i++)
        cout<<" "<<vNegative[i];
    cout<<endl<<c1;
    for (int i=0;i<vPositive.size();i++)
        cout<<" "<<vPositive[i];
    cout<<endl<<c3;
    for (int i=0;i<vZero.size();i++)
        cout<<" "<<vZero[i];
    cout<<endl;

    return 0;
}


#include<iostream>
#include<vector>
#include <cstdio>
using namespace std;
int main ()
{
    int n,c1=0,c2=0,c3=0;
    cin>>n;
    int x[n];
    vector<int> vPositive,vNegative,vZero;
    for (int i=0;i<n;i++)
    {
        scanf("%d",&x[i]);
        if (x[i]>0){
            vPositive.push_back(x[i]);
            c1++;}
        else if (x[i]<0){
            vNegative.push_back(x[i]);
            c2++;}

        else{
            vZero.push_back(x[i]);
            c3++;}
    }
    if (vNegative.size()%2==0)
    {
        vZero.push_back(vNegative.back());
        vNegative.pop_back();

        c2--;
        c3++;

    }
    if (vPositive.size()==0)
    {
        vPositive.push_back(vNegative.back());
        vPositive.push_back(vNegative.back());

        vNegative.pop_back();
        vNegative.pop_back();

        c2-=2;
        c1+=2;

    }
        cout<<c2;
    for (int i=0;i<vNegative.size();i++)
        cout<<" "<<vNegative[i];
    cout<<endl<<c1;
    for (int i=0;i<vPositive.size();i++)
        cout<<" "<<vPositive[i];
    cout<<endl<<c3;
    for (int i=0;i<vZero.size();i++)
        cout<<" "<<vZero[i];
    cout<<endl;

    return 0;
}


#include <cstdio>
#include <vector>

using namespace std;
vector <int> first, second, third;
int main () {
        int n;
        scanf("%d", &n);
        for(int i = 0; i < n; i++) {
                int a;
                scanf("%d", &a);
                if (a == 0)
                 third.push_back(a);
                if (a > 0)
                        second.push_back(a);
                if (a < 0)
                        first.push_back(a);
        }
        if (second.size() == 0) {
                for(int i = 0; i < 2; i++)
                      second.push_back(first.back()), first.pop_back();
        }
        if (first.size() % 2 == 0) {
                third.push_back(first.back());
                first.pop_back();
        }
        printf("%d", first.size());
        for(int i = 0; i < first.size(); i++) {
                printf(" %d",first[i]);
        }
        printf("\n%d", second.size());
        for(int i = 0; i < second.size(); i++) {
                printf(" %d", second[i]);
        }
        printf("\n%d", third.size());
        for(int i = 0; i < third.size(); i++) {
                printf(" %d", third[i]);
        }
        puts("");
}


#include<iostream>
#include<set>
using namespace std;
int main ()
{
    int n,count=0,c1=0,c2=0,c3=0,NumberType=0,c4=0;
    cin>>n;
    int x[n];

    set<int> s1;
    set<int> s2;
    set<int> s3;

    for (int i=0;i<n;i++)
    {
        cin>>x[i];
        if (x[i]>0)
            count++;
        if (x[i]<0)
            NumberType++;
    }

        if (count>0&&NumberType%2!=0)
        for (int i=0;i<n;i++)
        {
            if (x[i]<0)
            {
                s1.insert(x[i]);
                c1++;
            }
            else if (x[i]>0)
            {
                s2.insert(x[i]);
                c2++;
            }
            else{
                s3.insert(x[i]);
                c3++;}
        }
    else if (count>0&&NumberType%2==0)
        for (int i=0;i<n;i++)
    {
        if (x[i]<0&&NumberType>1)
        {
            s1.insert(x[i]);
            c1++;
            NumberType--;
        }
        else if (x[i]>0)
        {
            s2.insert(x[i]);
            c2++;
        }
        else if (x[i]==0||NumberType--==1)
        {
            s3.insert(x[i]);
            c3++;

        }
    }

    else
        for (int i=0;i<n;i++)
        {
            if (NumberType%2==0)
            {
                if (x[i]<0&&c2==0){
                    s2.insert(x[i]);
                    c2++;}

                else if (x[i]<0){
                    s1.insert(x[i]);
                    c1++;}

                else{
                    s3.insert(x[i]);
                    c3++;}
            }
            else
            {
                if (x[i]<0&&c1==0){
                    s1.insert(x[i]);
                    c1++;}

                else if (x[i]<0){
                    s2.insert(x[i]);
                    c2++;}

                else{
                    s3.insert(x[i]);
                    c3++;}

            }

        }

    set<int>::iterator it;

    cout <<c1;
    for (it=s1.begin();it!=s1.end();it++)
        cout <<" "<<*it;
    cout<<endl<<c2;
    for (it=s2.begin();it!=s2.end();it++)
        cout <<" "<<*it;
    cout<<endl<<c3;
    for (it=s3.begin();it!=s3.end();it++)
        cout <<" "<<*it;

    cout<<endl;

    return 0;
}


#include<iostream>
#include<set>
using namespace std;
int main ()
{
    int n,count=0,c1=0,c2=0,c3=0,NumberType=0;
    cin>>n;
    int x[n];

    set<int> s1;
    set<int> s2;
    set<int> s3;

    for (int i=0;i<n;i++)
    {
        cin>>x[i];
        if (x[i]>0)
            count++;
        if (x[i]<0)
            NumberType++;
    }

        if (count>0)
        for (int i=0;i<n;i++)
        {
            if (x[i]<0)
            {
                s1.insert(x[i]);
                c1++;
            }
            else if (x[i]>0)
            {
                s2.insert(x[i]);
                c2++;
            }
            else{
                s3.insert(x[i]);
                c3++;}
        }

    else
        for (int i=0;i<n;i++)
        {
            if (NumberType%2==0)
            {
                if (x[i]<0&&c2==0){
                    s2.insert(x[i]);
                    c2++;}

                else if (x[i]<0){
                    s1.insert(x[i]);
                    c1++;}

                else{
                    s3.insert(x[i]);
                    c3++;}
            }
            else
            {
                if (x[i]<0&&c1==0){
                    s1.insert(x[i]);
                    c1++;}

                else if (x[i]<0){
                    s2.insert(x[i]);
                    c2++;}

                else{
                    s3.insert(x[i]);
                    c3++;}

            }

        }

    set<int>::iterator it;

    cout <<c1;
    for (it=s1.begin();it!=s1.end();it++)
        cout <<" "<<*it;
    cout<<endl<<c2;
    for (it=s2.begin();it!=s2.end();it++)
        cout <<" "<<*it;
    cout<<endl<<c3;
    for (it=s3.begin();it!=s3.end();it++)
        cout <<" "<<*it;

    cout<<endl;

    return 0;
}


#define     ll         long long
#define     pb         push_back

	#include<bits/stdc++.h>
	using namespace std;
int main() {
ll a,i,s,ans=0,j,k,b;
    cin>>a;
    vector < ll >x;
    vector < ll >y;
    vector < ll >z;
    vector < ll >r;
    for(i=0;i<a;i++){
        cin>>b;
        if(b==0){
            x.pb(b);
        }else if(b>0){
            y.pb(b);
        }else{
            z.pb(b);
        }
    }
    if(y.size()!=0){
        cout<<1<<" "<<z[0]<<endl;
        cout<<1<<" "<<y[0]<<endl;
        cout<<a-2<<" ";
        for(i=0;i<x.size();i++){
            cout<<x[i]<<" ";
        }
        for(i=1;i<y.size();i++){
            cout<<y[i]<<" ";
        }
        for(i=1;i<z.size();i++){
            cout<<z[i]<<" ";
        }
        cout<<endl;
    }else{
        cout<<1<<" "<<z[0]<<endl;
        cout<<2<<" "<<z[1]<<" "<<z[2]<<endl;
        cout<<a-3<<" ";
        for(i=0;i<x.size();i++){
            cout<<x[i]<<" ";
        }
        for(i=3;i<z.size();i++){
            cout<<z[i]<<" ";
        }
        cout<<endl;
    }
	}


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
using namespace std;
int main()
{
	int n,a[500],b=0,c=0,x,ans=0;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>x;
		if(x>0)
		{
			if(b==0)
				b=x;
			else
			{
				ans++;
				a[ans]=x;
			}
		}
		if(x<0)
		{
			if(c==0)
				c=x;
			else
			{
				ans++;
				a[ans]=x;
			}
		}
		if(x==0)
		{
			ans++;
			a[ans]=x;
		}
	}
	cout<<1<<' '<<c<<endl;
	cout<<1<<' '<<b<<endl;
	cout<<ans<<' ';
	for(int i=1;i<=ans;i++)
	{
		cout<<a[i]<<' ';
	}
	return 0;
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
using namespace std;
int main()
{
	int n,a[500],x[500],c[500],b=0,sum=0,sum2=0,ans=0,ans2=0;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>x[i];
		if(x[i]<0)
			sum++;
	}
	for(int i=1;i<=n;i++)
	{
		if(x[i]>0)
		{
			ans++;
			a[ans]=x[i];
		}
		if(x[i]==0)
		{
			ans2++;
			c[ans2]=x[i];
		}
		if(x[i]<0)
		{
			if(b==0)
			{
				b=x[i];
				sum--;
			}
			else
			{
				if((sum2==0&&sum>=2)||(sum!=0&&sum2%2==1))
				{
					ans++;
					a[ans]=x[i];
					sum--;
				}
				else
				{
					ans2++;
					c[ans2]=x[i];
					sum--;
				}
			}
		}
	}
	cout<<1<<' '<<b<<endl;
	cout<<ans<<' ';
	for(int i=1;i<=ans;i++)
		cout<<a[i]<<' ';
	cout<<endl;
	cout<<ans2<<' ';
	for(int i=1;i<=ans2;i++)
		cout<<c[i]<<' ';
	return 0;
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
using namespace std;
int main()
{
	int n,a[500],x[500],c[500],b=0,sum=0,sum2=0,ans=0,ans2=0;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>x[i];
		if(x[i]<0)
			sum++;
	}
	for(int i=1;i<=n;i++)
	{
		if(x[i]>0)
		{
			ans++;
			a[ans]=x[i];
		}
		if(x[i]==0)
		{
			ans2++;
			c[ans2]=x[i];
		}
		if(x[i]<0)
		{
			if(b==0)
			{
				b=x[i];
				sum--;
			}
			else
			{
				if((sum2==0&&sum>=2)||(sum!=0&&sum2%2==1))
				{
					ans++;
					a[ans]=x[i];
				}
			}
		}
	}
	cout<<1<<' '<<b<<endl;
	cout<<ans<<' ';
	for(int i=1;i<=ans;i++)
		cout<<a[i]<<' ';
	cout<<endl;
	cout<<ans2<<' ';
	for(int i=1;i<=ans2;i++)
		cout<<c[i]<<' ';
	return 0;
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
using namespace std;
int main()
{
	int n,a[500],b=0,c=0,x,ans=0;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>x;
		if(x>0)
		{
			if(b==0)
				b=x;
			else
			{
				ans++;
				a[ans]=x;
			}
		}
		if(x<0)
		{
			if(c==0)
				c=x;
			else
			{
				ans++;
				a[ans]=x;
			}
		}
		if(x==0)
		{
			ans++;
			a[ans]=x;
		}
	}
	cout<<1<<' '<<b<<endl;
	cout<<1<<' '<<c<<endl;
	cout<<ans<<' ';
	for(int i=1;i<=ans;i++)
	{
		cout<<a[i]<<' ';
	}
	return 0;
}


# cf 433 B 1200
n = int(input())
A = [*map(int, input().split())]
B = list(sorted(A))
m = int(input())

preA = [0] * (len(A) + 1)
preB = [0] * (len(B) + 1)

sa, sb = 0, 0
for i in range(1, len(A) + 1):
    sa += A[i - 1]
    preA[i] = sa
    sb += B[i - 1]
    preB[i] = sb

for _ in range(m):
    type_, l, r = map(int, input().split())
    l -= 1
    r -= 1
    if type_ == 1:
        print(preA[r + 1] - preA[l]) # sum(A[l - 1:r]))
    else:
        print(preB[r + 1] - preB[l]) # sum(B[l - 1:r]))


#B. Kuriyama Mirai's Stones
n = int(input())
u = list(map(int,input().split()))
v = sorted(u)
su = [u[0]]
sv = [v[0]]
for i in range(1,n):
    su.append(su[-1]+u[i])
    sv.append(sv[-1]+v[i])
#print(u)
#print(su)
#print(v)
#print(sv)
q = int(input())
for _ in range(q):
    t,l,r = map(int,input().split())
    if t==1:
        print(su[r-1]-su[l-1]+u[l-1])
    else:
        print(sv[r-1]-sv[l-1]+v[l-1])


n = int(input())
v = list(map(int, input().split(' ')))
m = int(input())

sum_v = [0]*(n+1)

for i in range(1, n+1):
  sum_v[i] = sum_v[i-1] + v[i-1]

sum_order = [0]*(n+1)
v.sort()
for i in range(1, n+1):
  sum_order[i] = sum_order[i-1] + v[i-1]

for i in range(m):
  t, l, r = map(int, input().split(' '))

  if(t == 1):
    print(sum_v[r] - sum_v[l-1])
  elif(t == 2):
    print(sum_order[r] - sum_order[l-1])


n=int(input())
l=[0]+list(map(int,input().split()))
l2=sorted(l)
for i in range(1,n+1):
    l[i]=l[i]+l[i-1]
    l2[i]=l2[i]+l2[i-1]
for j in range(int(input())):
    a,b,c=map(int,input().split())
    if a==2:print(l2[c]-l2[b-1])
    else:print(l[c]-l[b-1])


import os
import sys
from io import BytesIO, IOBase

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")

n = int(input())
arr = list(map(int,input().split()))
asort=arr.copy()
asort.sort()
dp_s = [0]
dp = [0]
for i in range(1,n+1):
    val = dp[-1]+arr[i-1]
    dp.append(val)
    val_s = dp_s[-1]+asort[i-1]
    dp_s.append(val_s)
m = int(input())
for i in range(m):
    t,l,r = map(int,input().split())
    if t == 1:
        print(dp[r]-dp[l-1])
    else:
        print(dp_s[r]-dp_s[l-1])


n = int(input())
arr = list(map(int,input().split()))
asort = sorted(arr)
dp_s = [0]*(n+1)
dp = [0]*(n+1)
for i in range(1,n+1):
    dp[i]=dp[i-1]+arr[i-1]
    dp_s[i]=dp_s[i-1]+asort[i-1]
m = int(input())
for i in range(m):
    t,l,r = map(int,input().split())
    if t == 1:
        print(dp[r]-dp[l-1])
    else:
        print(dp_s[r]-dp_s[l-1])


n = int(input())
arr = list(map(int,input().split()))
asort=arr.copy()
asort.sort()
dp_s = [0]
dp = [0]
for i in range(1,n+1):
    val = dp[-1]+arr[i-1]
    dp.append(val)
    val_s = dp_s[-1]+asort[i-1]
    dp_s.append(val_s)
m = int(input())
for i in range(m):
    t,l,r = map(int,input().split())
    if t == 1:
        print(dp[r]-dp[l-1])
    else:
        print(dp_s[r]-dp_s[l-1])


n = int(input())
arr = list(map(int,input().split()))
asort = sorted(arr)
dp_s = [0]
dp = [0]
for i in range(1,n+1):
    val = dp[-1]+arr[i-1]
    dp.append(val)
    val_s = dp_s[-1]+asort[i-1]
    dp_s.append(val_s)
m = int(input())
for i in range(m):
    t,l,r = map(int,input().split())
    if t == 1:
        print(dp[r]-dp[l-1])
    else:
        print(dp_s[r]-dp_s[l-1])


n = int(input())
a = list(map(int, input().split()))
b = [x for x in a]
b.sort()
q = int(input())
for i in range(q):
    t,l,r = map(int, input().split())
    if t==1:
        l,r = l-1,r-1
        print(sum(a[l:r+1]))
    if t==2:
        l,r = l-1,r-1
        print(sum(b[l:r+1]))


n = int(input())
dp_a = [-1  for _ in range(n)]
dp_b = [-1  for _ in range(n)]

def dp_sum_a (a):
    dp_a[0] = a[0]
    for i in range(1,n):
        dp_a[i] = dp_a[i-1] + a[i]
def dp_sum_b (b):
    dp_b[0] = b[0]
    for i in range(1,n):
        dp_b[i] = dp_b[i-1] + b[i]

# n = int(input())
a = list(map(int, input().split()))
b = [x for x in a]
b.sort()
dp_sum_a(a)
dp_sum_b(b)
q = int(input())
for i in range(q):
    t,l,r = map(int, input().split())
    if t==1:
        l,r = l-1,r-1
        x = dp_a[r] - dp_a[l] + a[l]
        print(x)
    if t==2:
        l,r = l-1,r-1
        x = dp_b[r] - dp_b[l] + b[l]
        print(x)


import math
from collections import defaultdict, Counter, deque

INF = float('inf')

def gcd(a, b):
	while b:
		a, b = b, a%b
	return a

def isPrime(n):
	if (n <= 1):
		return False
	i = 2
	while i ** 2 <= n:
		if n % i == 0:
			return False
		i += 1
	return True

def primeFactor(n):
	if n % 2 == 0:
		return 2
	i = 3
	while (i ** 2) <= n:
		if n % i == 0:
			return i
		i += 1
	return n

def vars():
	return map(int, input().split())

def array():
	return list(map(int, input().split()))

def main():
	n = int(input())
	arr = array()
	m = int(input())

	pre = {}
	pres = {}

	l = 0
	r = sum(arr)

	for i in range(n):
		r -= arr[i]
		pre[i] = (l, r)
		l += arr[i]

	arr2 = sorted(arr)
	l = 0
	r = sum(arr2)

	for i in range(n):
		r -= arr2[i]
		pres[i] = (l, r)
		l += arr2[i]

	for i in range(m):
		o, l, r = vars()
		if o == 1:
			print(arr[l - 1] + pre[l - 1][1] - pre[r - 1][1])
		else:
			print(arr2[l - 1] + pres[l - 1][1] - pres[r - 1][1])

if __name__ == "__main__":
	# t = int(input())
	t = 1
	for _ in range(t):
		main()


# Author: SaykaT
# Problem: 433B
# Time Created: August 02(Sunday) 2020 || 12:03:48

#>-------------------------<#
import sys

input = sys.stdin.readline

# Helper Functions. -> Don't cluster your code.
def prefix_sum(ls):
    l1 = sorted(ls)

    normal, inc = [ls[0]], [l1[0]]

    for i in range(1, len(ls)):
        normal.append(normal[i-1] + ls[i])
        inc.append(inc[i-1] + l1[i])

    return [normal, inc]

# IO Functions. -> Input output
def io():
    n = int(input())
    ls = list(map(int, input().split()))
    m = int(input())
    queries = []
    for _ in range(m):
        tmp = list(map(int, input().split()))
        queries.append(tmp)

    return [n, ls, m, queries]

# Main functions. -> Write the main solution here
def solve():
    n, ls, m, queries = io()
    normal, inc = prefix_sum(ls)

    for i in range(m):
        types = queries[i][0]
        l = queries[i][1]
        r = queries[i][2] - 1

        if l != 1:
            l -= 2
        else:
            l = -1

        if types == 1 and l >= 0:
            print(normal[r] - normal[l])
        elif types == 2 and l >= 0:
            print(inc[r] - inc[l])
        elif types == 1 and l < 0:
            print(normal[r])
        elif types == 2 and l < 0:
            print(inc[r])

# Multiple test cases. -> When you have T test cases.
solve()


n=int(input())
v=[int(i) for i in input().split()]
u=sorted(v)
pref1=[v[0]]
pref2=[u[0]]
for i in range(1,n):
    pref1.append(v[i]+pref1[i-1])
    pref2.append(u[i]+pref2[i-1])
m=int(input())
for i in range(m):
    t,l,r=(int(i) for i in input().split())
    if(t==1):
        if(l==1):
            print(pref1[r-1])
        else:
            print(pref1[r-1]-pref1[l-2])
    else:
        if(l==1):
            print(pref2[r-1])
        else:
            print(pref2[r-1]-pref2[l-2])


n=int(input())
a=[int(i) for i in input().split()]
b=sorted(a)
p=[0]
for i in a:
    p.append(i+p[-1])
q=[0]
for i in b:
    q.append(i+q[-1])

for i in range(int(input())):
    t,l,r=map(int,input().split())
    if t==1:
        print(p[r]-p[l-1])
    if t==2:
        print(q[r]-q[l-1])


n = int(input())
a = list(map(int, input().split()))
a.insert(0, 0)
b = sorted(a)
for i in range(2, n+1):
    a[i] += a[i-1]
    b[i] += b[i-1]
m = int(input())
dict = {}
while(m > 0):
    answer = 0
    c, a1, b1 = map(int, input().split())
    if(c == 1):
        answer += a[b1]-a[a1-1]
    else:

        answer += b[b1]-b[a1-1]
    print(answer)
    m -= 1


n = int(input())
a = list(map(int, input().split()))
b = sorted(a)
for i in range(1, n):
    a[i] += a[i-1]
    b[i] += b[i-1]
m = int(input())
dict = {}
while(m > 0):
    answer = 0
    c, a1, b1 = map(int, input().split())
    if(c == 1):
        answer += a[b1-1]-a[a1-1]
    else:
        answer += b[b1-1]-b[a1-1]
    print(answer)
    m -= 1


n = int(input())
a = list(map(int, input().split()))
b = sorted(a)
m = int(input())
dict = {}
while(m > 0):
    answer = 0
    c, a1, b1 = map(int, input().split())
    key = str(c)+str(a1)+str(b1)
    if key in dict.keys():
        print(dict[key])
    else:
        if(c == 1):
            answer += sum(a[a1-1:b1])
        else:
            answer += sum(b[a1-1:b1])
        dict[key] = answer
        print(answer)
    m -= 1


n = int(input())
a = list(map(int, input().split()))
b = sorted(a)
m = int(input())
while(m > 0):
    answer = 0
    c, a1, b1 = map(int, input().split())
    if(c == 1):
        answer += sum(a[a1-1:b1])
    else:
        answer += sum(b[a1-1:b1])
    print(answer)
    m -= 1


#------------------------template--------------------------#
import os
import sys
from math import *
from collections import *
from bisect import *
from io import BytesIO, IOBase
def vsInput():
    sys.stdin = open('input.txt', 'r')
    sys.stdout = open('output.txt', 'w')
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")
def value():return tuple(map(int,input().split()))
def array():return [int(i) for i in input().split()]
def Int():return int(input())
def Str():return input()
def arrayS():return [i for i in input().split()]

#-------------------------code---------------------------#
#vsInput()

def pre(a):
    ans=[0,a[0]]
    for i in a[1:]:
        ans.append(ans[-1]+i)
    return ans

n=Int()
a=array()
q1=pre(a)
q2=pre(sorted(a))
#print(q1)
for _ in range(Int()):
    q,l,r=value()
    if(q==1):
        print(q1[r]-q1[l-1])
    else:
        print(q2[r]-q2[l-1])


from functools import reduce
from collections import Counter
import time
import datetime
from math import sqrt,gcd

def time_t():
    print("Current date and time: " , datetime.datetime.now())
    print("Current year: ", datetime.date.today().strftime("%Y"))
    print("Month of year: ", datetime.date.today().strftime("%B"))
    print("Week number of the year: ", datetime.date.today().strftime("%W"))
    print("Weekday of the week: ", datetime.date.today().strftime("%w"))
    print("Day of year: ", datetime.date.today().strftime("%j"))
    print("Day of the month : ", datetime.date.today().strftime("%d"))
    print("Day of week: ", datetime.date.today().strftime("%A"))

def ip():
    return int(input())

def sip():
    return input()

def mip():
    return map(int,input().split())

def mips():
    return map(str,input().split())

def lip():
    return list(map(int,input().split()))

def matip(n,m):
    lst=[]
    for i in range(n):
        arr = lip()
        lst.append(arr)
    return lst

def factors(n): # find the factors of a number
    return list(set(reduce(list.__add__, ([i, n//i] for i in range(1, int(n**0.5) + 1) if n % i == 0))))

def minJumps(arr, n): #to reach from 0 to n-1 in the array in minimum steps
    jumps = [0 for i in range(n)]
    if (n == 0) or (arr[0] == 0):
        return float('inf')
    jumps[0] = 0
    for i in range(1, n):
        jumps[i] = float('inf')
        for j in range(i):
            if (i <= j + arr[j]) and (jumps[j] != float('inf')):
                jumps[i] = min(jumps[i], jumps[j] + 1)
                break
    return jumps[n-1]

def dic(arr): # converting list into dict of count
    return Counter(arr)

def prime(n):
    for i in range(3,int(n**(0.5))+1,2):
        if n%i==0:
            return False
    return True

# --------------------------------------------------------- #
# import sys
# sys.stdin = open('input.txt','r')
# sys.stdout = open('output.txt','w')
# --------------------------------------------------------- #

n = ip()
arr = lip()
lst = sorted(arr)
for i in range(1,n):
    arr[i] = arr[i]+arr[i-1]
    lst[i] = lst[i]+lst[i-1]
m = ip()
arr.insert(0,0)
lst.insert(0,0)
while m:
    m-=1
    t,l,r = mip()
    if t==1:
        print(arr[r]-arr[l-1])
    else:
        print(lst[r]-lst[l-1])


from functools import reduce
from collections import Counter
import time
import datetime
from math import sqrt,gcd

def time_t():
    print("Current date and time: " , datetime.datetime.now())
    print("Current year: ", datetime.date.today().strftime("%Y"))
    print("Month of year: ", datetime.date.today().strftime("%B"))
    print("Week number of the year: ", datetime.date.today().strftime("%W"))
    print("Weekday of the week: ", datetime.date.today().strftime("%w"))
    print("Day of year: ", datetime.date.today().strftime("%j"))
    print("Day of the month : ", datetime.date.today().strftime("%d"))
    print("Day of week: ", datetime.date.today().strftime("%A"))

def ip():
    return int(input())

def sip():
    return input()

def mip():
    return map(int,input().split())

def mips():
    return map(str,input().split())

def lip():
    return list(map(int,input().split()))

def matip(n,m):
    lst=[]
    for i in range(n):
        arr = lip()
        lst.append(arr)
    return lst

def factors(n): # find the factors of a number
    return list(set(reduce(list.__add__, ([i, n//i] for i in range(1, int(n**0.5) + 1) if n % i == 0))))

def minJumps(arr, n): #to reach from 0 to n-1 in the array in minimum steps
    jumps = [0 for i in range(n)]
    if (n == 0) or (arr[0] == 0):
        return float('inf')
    jumps[0] = 0
    for i in range(1, n):
        jumps[i] = float('inf')
        for j in range(i):
            if (i <= j + arr[j]) and (jumps[j] != float('inf')):
                jumps[i] = min(jumps[i], jumps[j] + 1)
                break
    return jumps[n-1]

def dic(arr): # converting list into dict of count
    return Counter(arr)

def prime(n):
    for i in range(3,int(n**(0.5))+1,2):
        if n%i==0:
            return False
    return True

# --------------------------------------------------------- #
# import sys
# sys.stdin = open('input.txt','r')
# sys.stdout = open('output.txt','w')
# --------------------------------------------------------- #

n = ip()
arr = lip()
lst = sorted(arr)
for i in range(1,n):
    arr[i] = arr[i]+arr[i-1]
    lst[i] = lst[i]+lst[i-1]
m = ip()
while m:
    m-=1
    t,l,r = mip()
    if t==1:
        print(arr[r-1])
    else:
        print(lst[r-1])


from functools import reduce
from collections import Counter
import time
import datetime
from math import sqrt,gcd

def time_t():
    print("Current date and time: " , datetime.datetime.now())
    print("Current year: ", datetime.date.today().strftime("%Y"))
    print("Month of year: ", datetime.date.today().strftime("%B"))
    print("Week number of the year: ", datetime.date.today().strftime("%W"))
    print("Weekday of the week: ", datetime.date.today().strftime("%w"))
    print("Day of year: ", datetime.date.today().strftime("%j"))
    print("Day of the month : ", datetime.date.today().strftime("%d"))
    print("Day of week: ", datetime.date.today().strftime("%A"))

def ip():
    return int(input())

def sip():
    return input()

def mip():
    return map(int,input().split())

def mips():
    return map(str,input().split())

def lip():
    return list(map(int,input().split()))

def matip(n,m):
    lst=[]
    for i in range(n):
        arr = lip()
        lst.append(arr)
    return lst

def factors(n): # find the factors of a number
    return list(set(reduce(list.__add__, ([i, n//i] for i in range(1, int(n**0.5) + 1) if n % i == 0))))

def minJumps(arr, n): #to reach from 0 to n-1 in the array in minimum steps
    jumps = [0 for i in range(n)]
    if (n == 0) or (arr[0] == 0):
        return float('inf')
    jumps[0] = 0
    for i in range(1, n):
        jumps[i] = float('inf')
        for j in range(i):
            if (i <= j + arr[j]) and (jumps[j] != float('inf')):
                jumps[i] = min(jumps[i], jumps[j] + 1)
                break
    return jumps[n-1]

def dic(arr): # converting list into dict of count
    return Counter(arr)

def prime(n):
    for i in range(3,int(n**(0.5))+1,2):
        if n%i==0:
            return False
    return True

# --------------------------------------------------------- #
# import sys
# sys.stdin = open('input.txt','r')
# sys.stdout = open('output.txt','w')
# --------------------------------------------------------- #

n = ip()
arr = lip()
lst = sorted(arr)
m = ip()
while m:
    m-=1
    t,l,r = mip()
    if t==1:
        print(sum(arr[l-1:r]))
    else:
        print(sum(lst[l-1:r]))


n = int(input())
arr = [int(i) for i in input().split()]
sor_arr = sorted(arr)
pre = [0] * n
pre_sor = [0] * n
for i in range(n):
    pre[i] = pre[i-1] + arr[i]
    pre_sor[i] = pre_sor[i-1] + sor_arr[i]
q = int(input())
for i in range(q):
    t, l, r = [int(i) for i in input().split()]
    if t == 1:
        if l == 1:
            print(pre[r-1])
        else:
            print(pre[r-1]-pre[l-2])
    else:
        if l == 1:
            print(pre_sor[r-1])
        else:
            print(pre_sor[r-1]-pre_sor[l-2])


import math
def change_char(s, p, r):
    return s[:p]+r+s[p+1:]

size = int(input())
arr = list(map(int, input().split()))
freq = [arr[0]]
i = 0

for element in arr[1:]:
    freq.append(element+ freq[i])
    i+= 1

arr.sort()
i = 0
freq_sorted = [arr[0]]

for element in arr[1:]:
    freq_sorted.append(element+ freq_sorted[i])
    i+= 1

test = int(input())
while(test > 0):
    positions = list(map(int, input().split()))
    right = positions[2] - 1
    left = positions[1] - 2
    ans = 0
    if positions[0] == 1:
        ans = freq[right] if left == -1 else freq[right] - freq[left]
    else:
        ans = freq_sorted[right] if left == -1 else freq_sorted[right] - freq[left]
    print(ans)
    test-=1


import math
def change_char(s, p, r):
    return s[:p]+r+s[p+1:]

size = int(input())
arr = list(map(int, input().split()))
freq = [arr[0]]
i = 0

for element in arr[1:]:
    freq.append(element+ freq[i])
    i+= 1

arr.sort()
i = 0
freq_sorted = [arr[0]]

for element in arr[1:]:
    freq_sorted.append(element+ freq_sorted[i])
    i+= 1

test = int(input())
while(test > 0):
    positions = list(map(int, input().split()))
    right = positions[2] - 1
    left = positions[1] - 2
    ans = 0
    if positions[0] == 1:
        ans = freq[right] if left == -1 else freq[right] - freq[left]
    else:
        ans = freq_sorted[right] if left == -1 else freq_sorted[right] - freq_sorted[left]
    print(ans)
    test-=1


import sys
# sys.stdin = open("input.txt","r")
# sys.stdout = open("output.txt","w")
input=lambda:sys.stdin.readline().strip()
li = lambda:list(map(int,input().split()))
I = lambda:int(input())
n = I()
l = li()
s = sorted(l)
p = [0]
tot = 0
for i in l :
	tot+=i
	p.append(tot)
ps = [0]
tot = 0
for i in s:
	tot+=i
	ps.append(tot)
m = I()
for i in range(m):
	t,l,r = li()
	if t==1:
		print(p[r]-p[l-1])
	else:
		print(ps[r]-ps[l-1])


n = int(input());
ls = list(map(int,input().split()));
ls1=sorted(ls);
for i in range(1,len(ls)):
    ls[i]=ls[i]+ls[i-1]
    ls1[i]=ls1[i]+ls1[i-1]
q=int(input());
# print(ls,ls1,sep='\n')
while(q):
    q-=1;
    c,l,r=map(int,input().split());
    if c==1:
        if l==1:
            print(ls[r-1])
        else:
            print(ls[r-1]-ls[l-2]);
    else:
        if l==1:
            print(ls1[r-1])
        else:

            print(ls1[r-1]-ls1[l-2]);


n=int(input())
v=list(map(int,input().split()))
m=int(input())
vv=v.copy()
vv.sort()
p,z=0,0
l,y=n*[0],n*[0]
for i in range (n):
    p+=v[i]
    z+=vv[i]
    l[i]=p
    y[i]=z
for _ in range (m):
    c,a,b=map(int,input().split())
    if c==1:
        if a==1 :
            print(l[b-1])
        else :
            print((l[b-1]-l[a-2]))
    else :
        if a==1 :
            print(y[b-1])
        else :
            print((y[b-1]-y[a-2]))


n = int(input())
ar = list(map(int, input().split()))
q = int(input())
sr = sorted(ar)
ps1 = [0] * (n + 1)
ps2 = [0] * (n + 1)

for i in range(1, n + 1):
    ps1[i] = ps1[i - 1] + ar[i - 1]
    ps2[i] = ps2[i - 1] + sr[i - 1]
for i in range(q):
    t, l, r = map(int, input().split())
    if t == 1:
        print(ps1[r] - ps1[l - 1])
    else:
        print(ps2[r] - ps2[l - 1])


import sys
input = sys.stdin.readline

n = int(input().strip())
u = list(map(int, input().strip().split()))
v = sorted(u)
u_pref = [0] * (n + 1)
v_pref = [0] * (n + 1)
for i in range(1, n + 1):
    u_pref[i] = u_pref[i - 1] + u[i - 1]
    v_pref[i] = v_pref[i - 1] + v[i - 1]
q = int(input().strip())
for i in range(q):
    t, l, r = map(int, input().strip().split())
    if t == 1: print(u_pref[r] - u_pref[l - 1])
    else: print(v_pref[r] - v_pref[l - 1])


from math import *
from copy import *
from string import *				# alpha = ascii_lowercase
from random import *
from sys import stdin
from sys import maxsize
from operator import *				# d = sorted(d.items(), key=itemgetter(1))
from itertools import *
from collections import Counter		# d = dict(Counter(l))
import math

def bin1(l,r,k,t,b,val,ans):
	if(l>r):
		return ans
	else:
		mid=(l+r)//2
		v=k**mid
		if(v==val):
			return v
		elif(v>val):
			ans=mid
			return bin1(mid+1,r,k,t,b,val,ans)
		else:
			return bin1(l,mid-1,k,t,b,val,ans)

def bin2(l,r,k,t,b,val,ans):
	if(l>r):
		return ans
	else:
		mid=(l+r)//2
		v=t*(k**mid)+b*(mid)
		if(v==val):
			return v
		elif(v>val):
			ans=mid
			return bin2(l,mid-1,k,t,b,val,ans)
		else:
			return bin2(mid+1,r,k,t,b,val,ans)

def SieveOfEratosthenes(n):

    # Create a boolean array "prime[0..n]" and initialize
    #  all entries it as true. A value in prime[i] will
    # finally be false if i is Not a prime, else true.
    prime = [True for i in range(n+1)]
    p = 2
    while (p * p <= n):

        # If prime[p] is not changed, then it is a prime
        if (prime[p] == True):

            # Update all multiples of p
            for i in range(p * p, n+1, p):
                prime[i] = False
        p += 1
    l=[]
    for i in range(2,n+1):
    	if(prime[i]):
    		l.append(i)
    return l
def bin(l,r,ll,val):
	if(l>r):
		return -1
	else:
		mid=(l+r)//2
		if(val>=ll[mid][0] and val<=ll[mid][1]):
			return mid
		elif(val<ll[mid][0]):
			return bin(l,mid-1,ll,val)
		else:
			return bin(mid+1,r,ll,val)
def deci(n):
	s=""
	while(n!=0):
		if(n%2==0):
			n=n//2
			s="0"+s
		else:
			n=n//2
			s="1"+s
	return s
def diff(s1,s2):
	if(len(s1)<len(s2)):
		v=len(s1)
		while(v!=len(s2)):
			s1="0"+s1
			v=v+1
	else:
		v=len(s2)
		while(v!=len(s1)):
			s2="0"+s2
			v=v+1
	c=0
	for i in range(len(s1)):
		if(s1[i:i+1]!=s2[i:i+1]):
			c=c+1
	return c
from sys import stdin, stdout
def fac(a,b):
	v=a
	while(a!=b):
		v*=a-1
		a=a-1
	return v
def bino(l,r,n):
	if(l>r):
		return -1
	else:
		mid=(l+r)//2
		val1=math.log((n/mid)+1,2)
		val2=int(val1)
		if(val1==val2):
			return val1
		elif(val1<1.0):
			return bino(l,mid-1,n)
		else:
			return bino(mid+1,r,n)

def binary(l,r,ll,val,ans):
	if(l>r):
		return ans
	else:
		mid=(l+r)//2
		if(ll[mid]<=val):
			ans=mid+1
			return binary(mid+1,r,ll,val,ans)
		else:
			return binary(l,mid-1,ll,val,ans)
def odd(n,ans,s):
	if(n%2!=0 or n in s):
		return ans
	else:
		s.add(n)
		return odd(n//2,ans+1,s)
def fact(n):
	if(n==0 or n==1):
		return 1
	else:
		return n*(fact(n-1))

if __name__ == '__main__':
	n=int(stdin.readline())
	l=list(map(int,stdin.readline().split(" ")))
	l1=[]
	for i in range(n):
		l1.append(l[i])
	l1.sort()
	ll1=[]
	ll2=[]
	c1=0
	for i in range(n):
		c1+=l[i]
		ll1.append(c1)
	c2=0
	for i in range(n):
		c2+=l1[i]
		ll2.append(c2)

	q=int(stdin.readline())
	for i in range(q):
		t,lo,r=map(int,stdin.readline().split(" "))
		if(t==1):
			stdout.write(str(ll1[r-1]-ll1[lo-1]+l[lo-1])+"\n")
		else:
			stdout.write(str(ll2[r-1]-ll2[lo-1]+l1[lo-1])+"\n")


n  = int(input())

t = list(map(int,input().split()))

g= sorted(t)

one = [ t[0]  ]
two =[g[0]  ]

if n>1:
    for j in range(1,n):
        one.append(one[-1]+t[j])

    for k in range(1,n):
        two.append(two[-1]+g[k])

for i in range(int(input())):

    a,l,r = map(int,input().split())
    l-=1
    r-=1

    if a==1:
        if l==0:
            print(one[r])
        else:
            print(one[r]-one[l-1])
    else:
        if l==0:
            print(two[r])
        else:
            print(two[r]-two[l-1])


n = int(input())
ar = list(map(int,input().split()))
arr = sorted(ar)
# print(arr)
# print(ar)
q = int(input())
pre1 = [0]*n
pre2 = [0]*n
pre1[0] = ar[0]
pre2[0] = arr[0]
sb =[]
for i in range(1,n):
    pre1[i] = pre1[i-1]+ar[i]
    pre2[i] = pre2[i-1]+arr[i]
while q!=0:
    q-=1
    x,a,b= map(int,input().split())
    a-=1
    b-=1
    if x==1:
        if a!=0:
            sb.append(str(pre1[b]-pre1[a-1]))
        else:
            sb.append(str(pre1[b]))
    else:
        if a!=0:
            sb.append(str(pre2[b]-pre2[a-1]))
        else:
            sb.append(str(pre2[b]))
print('\n'.join(sb))


from sys import stdin as sin , stdout as out
n = int(sin.readline())
ar = list(map(int,sin.readline().split()))
arr = sorted(ar)
# print(arr)
# print(ar)
q = int(sin.readline())
pre1 = [0]*n
pre2 = [0]*n
pre1[0] = ar[0]
pre2[0] = arr[0]
sb =[]
for i in range(1,n):
    pre1[i] = pre1[i-1]+ar[i]
    pre2[i] = pre2[i-1]+arr[i]
while q!=0:
    q-=1
    x,a,b= map(int,input().split())
    a-=1
    b-=1
    if x==1:
        if a!=0:
            sb.append(str(pre1[b]-pre1[a-1]))
        else:
            sb.append(str(pre1[b]))
    else:
        if a!=0:
            sb.append(str(pre2[b]-pre2[a-1]))
        else:
            sb.append(str(pre2[b]))
out.write('\n'.join(sb))
out.close()


"""
def solve(s,l,r):

    s.insert(0,0)
    pref = [0] * (n+1)
    pref[1] = s[1]

    for i in range(2,n+1):
        pref[i] = pref[i-1] + s[i]

    return(pref[r] - pref[l-1])

def solve2(s,l,r):
    s.insert(0, 0)
    s.sort()
    pref = [0] * (n + 1)
    pref[1] = s[1]

    for i in range(2, n + 1):
        pref[i] = pref[i - 1] + s[i]

    return(pref[r] - pref[l - 1])
"""

if __name__ == '__main__':
    n = int(input())
    ar = list(map(int, input().split()))

    q = int(input())
    for _ in range(q):
        t,l,r = map(int,input().split())

        if t == 1:
            ar1 = ar[:]
            ar1.insert(0, 0)
            pref = [0] * (n + 1)
            pref[1] = ar1[1]

            for i in range(2, n + 1):
                pref[i] = pref[i - 1] + ar1[i]

            print(pref[r] - pref[l - 1])

        else:
            ar2 = ar[:]
            ar2.insert(0, 0)
            ar2.sort()
            pref = [0] * (n + 1)
            pref[1] = ar2[1]

            for i in range(2, n + 1):
                pref[i] = pref[i - 1] + ar2[i]

            print(pref[r] - pref[l - 1])


"""
def solve(s,l,r):

    s.insert(0,0)
    pref = [0] * (n+1)
    pref[1] = s[1]

    for i in range(2,n+1):
        pref[i] = pref[i-1] + s[i]

    return(pref[r] - pref[l-1])

def solve2(s,l,r):
    s.insert(0, 0)
    s.sort()
    pref = [0] * (n + 1)
    pref[1] = s[1]

    for i in range(2, n + 1):
        pref[i] = pref[i - 1] + s[i]

    return(pref[r] - pref[l - 1])
"""

if __name__ == '__main__':
    n = int(input())
    ar = list(map(int, input().split()))
    y = ar[:] ##type 2 sort
    z = ar[:] ##type 1
    y.insert(0,0)
    z.insert(0,0)
    y.sort()

    for i in range(2,n+1):
        z[i] += z[i-1]
        y[i] += y[i-1]

    #print
    q = int(input())
    for _ in range(q):
        t,l,r = map(int,input().split())
        if t == 1:
            print(z[r]-z[l-1])
        else:
            print(y[r]-y[l-1])

#quicksort 로 nlog n까지 sort시키고 prefix sum으로 문제 해결 O(nlogn + q)


import sys
n=int(sys.stdin.readline())
l=list(map(int,sys.stdin.readline().split()))
m=sorted(l)
t=int(sys.stdin.readline())
for _ in range(t):
    a,b,c=map(int,sys.stdin.readline().split())
    if(a==1):
        p=l[b-1:c]
        print(sum(p))
    elif(a==2):
        q=m[b-1:c]
        print(sum(q))


import sys
n=int(sys.stdin.readline())
l=list(map(int,sys.stdin.readline().split()))
m=sorted(l)
t=int(sys.stdin.readline())
for _ in range(t):
    a,b,c=map(int,sys.stdin.readline().split())
    s=0
    if(a==1):
        while(b<=c):
            s+=l[b-1]
            b=b+1
        print(s)
    elif(a==2):
        while(b<=c):
            s+=m[b-1]
            b=b+1
        print(s)


from  itertools import accumulate
n = int(input())
arrs = [int(x) for x in input().split()]
arrss= sorted(arrs)
arrs = [0] + list(accumulate(arrs))
arrss= [0] + list(accumulate(arrss))
for _ in range(int(input())):
    o, l, r = [int(x) for x in input().split()]
    if o == 1:
        print(arrs[r] - arrs[l - 1])
    else:
        print(arrss[r] - arrss[l - 1])


from copy import deepcopy
n=int(input())
v=list(map(int,input().split()))
m=int(input())
v1=deepcopy(v)
v1.sort()
pre=[v[0]]
pre1=[v1[0]]
for i in range(1,n):
    pre.append(pre[i-1]+v[i])
    pre1.append(pre1[i-1]+v1[i])
for i in range(m):
    typ,l,r=map(int,input().split())
    if(typ==1):
        if(l==1):
            print(pre[r-1])
        elif(l==r):
            print(v[r-1])
        else:
            print(pre[r-1]-pre[l-2])
    else:
        if(l==r):
            print(v1[r-1])
        elif(l==1):
            print(pre1[r-1])
        else:
            print(pre1[r-1]-pre1[l-2])


from collections import deque
n = int(input())
arr = list(map(int,input().split()))
prs1 = [0] * (n + 1)
prs1[1] = arr[0]

for i in range(2 , n + 1 ):
    prs1[i] = prs1[i - 1] + arr[i -1]

l2 = sorted(arr)

prs2 = [0]*(n + 1)
prs2[1] = l2[0]

for i in range(2 , n + 1 ):
    prs2[i] = prs2[i - 1] + l2[i - 1]

q = int(input())
ans = deque()

for i in range(q):
    x , y , z = map(int,input().split())
    if (x == 1) :
        if (y == 1) :
            ans.append(prs1[z])
        else:
            ans.append(prs1[z] - prs1[y - 1])

    else:
        if (y == 1 ):
            ans.append(prs2[z])
        else:
            ans.append(prs2[z] - prs2[y - 1])

for i in ans:
    print(i)


from  itertools import accumulate

n = int(input())
l = list(map(int,input().split()))
l2 = l
l3 = list(accumulate(l))
l2.sort()
l4 = list(accumulate(l2))

m = int(input())
for i in range(m):
    t , r1 , r2 = map(int,input().split())
    if t == 1 :
        if r1 == 1 :

            print(l3[r2 - 1])

        else:
            print(l3[r2 - 1] - l3[r1 - 2])

    else:
        if r1 == 1:

            print(l4[r2 - 1])

        else:
            print(l4[r2 - 1] - l4[r1 - 2])


n=int(input())
a=list(map(int,input().strip().split()))
pa=[a[0]]
for i in range(1,n):
    pa.append(pa[i-1]+a[i])
b=sorted(a)
pb=[b[0]]
for i in range(1,n):
    pb.append(pb[i-1]+b[i])
m=int(input())
for i in range(m):
    t,l,r=map(int,input().strip().split())
    if t==1:
        if l==r:
            print(a[l-1])
        elif l==1 and r==n:
            print(pa[r-1])
        elif l-2<0:
               print(pa[r-1])
        else:
               print(pa[r-1]-pa[l-2])
    if t==2:
        if l==r:
            print(b[l-1])
        elif l==1 and r==n:
            print(pb[r-1])
        elif l-2<0:
               print(pb[r-1])
        else:
               print(pb[r-1]-pb[l-2])


n = int(input())
v = [int(i) for i in input().split()]
v2 = sorted(v)
m = int(input())
pref1 = [0] * n
pref2 = [0] * n

pref1[0] = v[0]
pref2[0] = v2[0]
for i in range(1, n):
    pref1[i] = pref1[i-1] + v[i]
    pref2[i] = pref2[i-1] + v2[i]

for i in range(m):
    t, l, r = [int(i) for i in input().split()]
    l = l - 1
    r = r - 1

    if t == 1:
        if l == 0:
            print(pref1[r])
        else:
            print(pref1[r] - pref1[l-1])
    else:
        if l == 0:
            print(pref2[r])
        else:
            print(pref2[r] - pref2[l-1])


n=int(input())
l=list(map(int,input().split()))
d=[]
for i in range(n):
    d.append(l[i])
l.sort()
for u in range(int(input())):
    q,x,y=map(int,input().split())
    if(q==1):
        print(sum(d[x-1:y]))
    else:
        print(sum(l[x-1:y]))


n=int(input())
l=list(map(int,input().split()))
d=[l[0]]
s=l[0]
for i in range(1,n):
    s=s+l[i]
    d.append(s)
l.sort()
s=l[0]
x=[l[0]]
for i in range(1,n):
    s=s+l[i]
    x.append(s)
for u in range(int(input())):
    q,z,y=map(int,input().split())
    if(q==1):
        if(z!=1):
            print(d[y-1]-d[z-2])
        else:
            print(d[y-1])
    else:
        if(z!=1):
            print(x[y-1]-x[z-2])
        else:
            print(x[y-1])


from functools import reduce
import os
import sys
from collections import *
#from fractions import *
from math import *
from bisect import *
from heapq import *
from io import BytesIO, IOBase
input = lambda: sys.stdin.readline().rstrip("\r\n")
def value(): return tuple(map(int, input().split())) # multiple values
def arr(): return [int(i) for i in input().split()] # array input
def sarr(): return [int(i) for i in input()] #array from string
def starr(): return [str(x) for x in input().split()] #string array
def inn(): return int(input()) # integer input
def svalue(): return tuple(map(str, input().split())) #multiple string values
def parr(): return [(value()) for i in range(n)] # array of pairs
mo = 1000000007
inf=1e18
div=998244353
#print("Case #{}:".format(_+1),end=" ")
# ----------------------------CODE------------------------------#
n=inn()
a=arr()
sm=0
res1=[0]
for i in a:
    sm+=i
    res1+=[sm]
a.sort()
res2=[0]
sm=0
for i in a:
    sm+=i
    res2+=[sm]
for _ in range(inn()):
    t,l,r=value()
    l-=1
    if(t==1):
        print(res1[r]-res1[l])
    else:
        print(res2[r]-res2[l])


n=int(input())
v=list(map(int,input().split()))
u=list(v)
u.sort()
for i in range(1,n):
    v[i]+=v[i-1]
    u[i]+=u[i-1]
u.insert(0,0)
v.insert(0,0)
for _ in range(int(input())):
    ty,l,r=map(int,input().split())
    print(v[r]-v[l-1] if ty==1 else u[r]-u[l-1])


n=int(input())
v=list(map(int,input().split()))
u=list(v)
u.sort()
for _ in range(int(input())):
    ty,l,r=map(int,input().split())
    print(sum(v[l-1:r]) if ty==1 else sum(u[l-1:r]))


import sys
n = int(sys.stdin.readline())
a = list(map(int, sys.stdin.readline().split()))
m = int(sys.stdin.readline())
b = a.copy()
b.sort()
dA = {}
dA[0] = a[0]
dB = {}
dB[0] = b[0]
for i in range(1, n):
    dA[i] = dA[i-1] + a[i]
    dB[i] = dB[i-1] + b[i]
for _ in range(m):
    t, l, r = map(int, sys.stdin.readline().split())
    if t == 1:
        res = dA[r-1]
        if l > 1: res -= dA[l-2]
    else:
        res = dB[r-1]
        if l > 1: res -= dB[l-2]
    print(res)


import sys
n = int(sys.stdin.readline())
a = list(map(int, sys.stdin.readline().split()))
m = int(sys.stdin.readline())
b = a.copy()
b.sort()
for _ in range(m):
    t, l, r = map(int, sys.stdin.readline().split())
    if t == 1:
        res = sum(a[l-1:r])
    else:
        res = sum(b[l-1:r])
    print(res)


n = int(input())
v = list(map(int, ('0 ' + input()).split()))
vs = sorted(v)

for i in range(1,n+1):
    v[i] += v[i-1]
    vs[i] += vs[i-1]

for i in range(int(input())):
    t,l,r = map(int, input().split())
    if t == 1:
        print(v[r]-v[l-1])
    else:
        print(vs[r]-vs[l-1])


n = int(input())
v = list(map(int, input().split()))
vs = sorted(v)

sums_v = []
sums_vs = []
sum_v = 0
sum_vs = 0
for i in range(n):
    sum_v += v[i]
    sum_vs += vs[i]
    sums_v.append(sum_v)
    sums_vs.append(sum_vs)
for i in range(int(input())):
    t,l,r = map(int, input().split())
    if t == 1:
        print(sums_v[r-1]-sums_v[l-1]+v[l-1])
    else:
        print(sums_vs[r-1]-sums_vs[l-1]+vs[l-1])


# your code goes here

from sys import stdin, stdout

n = int(stdin.readline())
v = list(map(int, stdin.readline().split()))

m = int(stdin.readline())

pv = [0]
for i in range(n):
	pv.append(pv[-1] + v[i])

u = sorted(v)

pu = [0]
for i in range(n):
	pu.append(pu[-1] + u[i])

for _ in range(m):
	typ, l, r = map(int, stdin.readline().split())

	if typ == 1:
		stdout.write(str(pv[r] - pv[l-1]) + "\n")
	else:
		stdout.write(str(pu[r] - pu[l-1]) + "\n")


n = int(input())

costs = list(map(lambda x: int(x), input().split()))

costsort = []

for c in costs:
    costsort.append(c)

costsort.sort()

for i in range(1,n):
    costs[i] += costs[i-1]
    costsort[i] += costsort[i-1]

costs = [0] + costs
costsort = [0] + costsort

m = int(input())

for i in range(m):
    line = input().split()
    if line[0] == "1":
        ans = costs[int(line[2])] - costs[int(line[1])-1]
        print(ans)
    else:
        ans = costsort[int(line[2])] - costsort[int(line[1])-1]
        print(ans)


n = int(input())

costs = list(map(lambda x: int(x), input().split()))

costsort = []

for c in costs:
    costsort.append(c)

costsort.sort()

m = int(input())

for i in range(m):
    line = input().split()
    if line[0] == "1":
        ans = sum(costs[int(line[1])-1:int(line[2])])
        print(ans)
    else:
        ans = sum(costsort[int(line[1])-1:int(line[2])])
        print(ans)


from copy import deepcopy
n=int(input())
li=list(map(int,input().split(" ")))
li2=deepcopy(li)
li2.sort()
x=len(li)

for i in range(1,x):
    li[i]+=li[i-1]
    li2[i]+=li2[i-1]
n2=int(input())
ans=[]

for i in range(n2):
    extra=list(map(int,input().split(" ")))
    if extra[0]==1:
        y=extra[1]-2
        if y<0:
            ans.append(li[extra[2]-1])
        else:
            ans.append(li[extra[2]-1]-li[y])
    else:
        y=extra[1]-2
        if y<0:
            ans.append(li2[extra[2]-1])
        else:
            ans.append(li2[extra[2]-1]-li2[y])

for i in range(n2):
    print(ans[i])


from copy import deepcopy
n=int(input())
#li=list(map(int,input().split(" ")))
s=input()
li=s.split(" ")
for i in range(len(li)):
    li[i]=int(li[i])
li2=deepcopy(li)
li2.sort()
ans=[]
n2=int(input())
for i in range(n2):
    x=0
    s2=input()
    extra=s2.split(" ")
    extra[0]=int(extra[0])
    extra[1]=int(extra[1])
    extra[2]=int(extra[2])
    if extra[0]==1:
        for i in range(extra[1]-1,extra[2]):
            x=x+li[i]
    elif extra[0]==2:
        for i in range(extra[1]-1,extra[2]):
            x=x+li2[i]
    ans.append(x)
for i in range(n2):
    print(ans[i])


from copy import deepcopy
n=int(input())
l1=list(map(int,input().split(' ')))
l2=deepcopy(l1)
l2.sort()
for x in range(1,n):
    l1[x]+=l1[x-1]
    l2[x]+=l2[x-1]
ans=[]
n2=int(input())
for x in range(n2):
    extra=list(map(int,input().split(' ')))

    if extra[0]==1:

        if extra[1]-2<0:
            y=0
        else:y=l1[extra[1]-2]
        ans.append(l1[extra[2]-1]-y)
    elif extra[0]==2:

        if extra[1]-2<0:y=0
        else:y=l2[extra[1]-2]
        ans.append(l2[extra[2]-1]-y)
for x in ans:
    print(x)


from copy import deepcopy
n=int(input())
li=list(map(int,input().split(" ")))
li2=deepcopy(li)
li2.sort()
x=len(li)
print(li)
print(li2)
for i in range(1,x):
    li[i]+=li[i-1]
    li2[i]+=li2[i-1]
n2=int(input())
ans=[]
print(li)
print(li2)
for i in range(n2):
    extra=list(map(int,input().split(" ")))
    if extra[0]==1:
        y=extra[1]-2
        if y<0:
            ans.append(li[extra[2]-1])
        else:
            ans.append(li[extra[2]-1]-li[y])
    else:
        y=extra[1]-2
        if y<0:
            ans.append(li2[extra[2]-1])
        else:
            ans.append(li2[extra[2]-1]-li2[y])

for i in range(n2):
    print(ans[i])


import copy
n=int(input())
li=list(map(int,input().split(" ")))
li2=copy.deepcopy(li)
li2.sort()
ans=[]
n2=int(input())
for i in range(n2):
    x=0
    extra=list(map(int,input().split(" ")))
    if extra[0]==1:
        for i in range(extra[1]-1,extra[2]):
            x=x+li[i]
    elif extra[0]==2:
        for i in range(extra[1]-1,extra[2]):
            x=x+li2[i]
    ans.append(x)
for i in range(n2):
    print(ans[i])


from copy import deepcopy
n=int(input())
li=list(map(int,input().split(" ")))
li2=deepcopy(li)
li2.sort()
ans=[]
n2=int(input())
for i in range(n2):
    x=0
    extra=list(map(int,input().split(" ")))
    if extra[0]==1:
        for i in range(extra[1]-1,extra[2]):
            x=x+li[i]
    elif extra[0]==2:
        for i in range(extra[1]-1,extra[2]):
            x=x+li2[i]
    ans.append(x)
for i in range(n2):
    print(ans[i])


#                           जय श्री राम

import sys; import math; from collections import *
# sys.setrecursionlimit(10**6)

def get_ints(): return map(int, input().split())
def get_list(): return list(get_ints())
def printspx(*args): return print(*args, end="")
def printsp(*args): return print(*args, end=" ")

UGLYMOD = int(1e9+7); SEXYMOD = 998244353; MAXN = int(1e5)

# sys.stdin  = open("input.txt","r"); sys.stdout = open("output.txt","w")

n = int(input())
li = get_list()
prefix = [0]
c = 0
for i in li:
    c += i
    prefix.append(c)
li.sort()
minprefix = [0]
c= 0
for i in li:
    c += i
    minprefix.append(c)
for _testcases_ in range(int(input())):
    t, l, r = get_ints()
    if t == 1:
        print(prefix[r] - prefix[l-1])
    else:
        print(minprefix[r] - minprefix[l-1])

'''
>>> COMMENT THE STDIN!! CHANGE ONLINE JUDGE !!
THE LOGIC AND APPROACH IS MINE @luctivud ( UDIT GUPTA )
Link may be copy-pasted here if it's taken from other source.
DO NOT PLAGIARISE.
>>> COMMENT THE STDIN!! CHANGE ONLINE JUDGE !!
'''


n = int(input())
stones = [int(num) for num in input().split()]
list1 = [0]
list2 = [0]
for i in range(len(stones)):
    list1.append(stones[i] + list1[i])
    list2.append(sorted(stones)[i] + list2[i])
for i in range(int(input())):
    l1 = [int(y) for y in input().split()]
    t = l1[0]
    l = l1[1]
    r = l1[2]
    if t == 1:
        print(list1[r] - list1[l - 1])
    else:
        print(list2[r] - list2[l - 1])


n = int(input())
stones = [int(num) for num in input().split()]
list1 = [0]
list2 = [0]
for i in range(len(stones)):
    list1.append(stones[i] + list1[i])
stones.sort()
for i in range(len(stones)):
    list2.append(stones[i] + list2[i])
for i in range(int(input())):
    l1 = [int(y) for y in input().split()]
    t = l1[0]
    l = l1[1]
    r = l1[2]
    if t == 1:
        print(list1[r] - list1[l - 1])
    else:
        print(list2[r] - list2[l - 1])