#include<cstdio>
#include<algorithm>
using namespace std;
#define x first
#define y second
typedef pair<int,int> P;
P a[100005];
bool cmp(P a,P b){if(a.x==b.x)return a.y>b.y;return a.x<b.x;}
int n,i,v,b[00005],k,r;
int main()
{
    scanf("%d",&n);
    for(i=0;i<n;i++)scanf("%d%d",&a[i].x,&a[i].y);
    scanf("%d",&v);
    for(i=0;i<n;i++)
    {
        P t=a[i];
        a[i].x=t.x+v*t.y;
        a[i].y=t.x-v*t.y;
    }
    n++;
    sort(a,a+n,cmp);
    for(i=n-1;i>=0;i--)
    {
        int p=upper_bound(b,b+k,a[i].y)-b;
        if(!a[i].x&&!a[i].y)r=p;
        else {b[p]=a[i].y;if(p==k)k++;}
    }
    printf("%d %d\n",r,k);
    return 0;
}


#include<cstdio>
#include<algorithm>
#include<iostream>
using namespace std;
#define x first
#define y second
typedef pair<int,int> per;
const int N = 100005;
per a[N];
int b[N];
int main()
{
    int n,i,v;
    scanf("%d",&n);
    for(i=0;i<n;i++)scanf("%d%d",&a[i].x,&a[i].y);
    scanf("%d",&v);
    for(i=0;i<n;i++)
    {
        per t=a[i];
        a[i].x=t.first+v*t.y;
        a[i].y=t.first-v*t.y;
    }
    a[n++]=make_pair(0,0);
    sort(a,a+n);
    int k=0,r=0;
    for(i=n-1;i>=0;i--)
    {
        int p=upper_bound(b,b+k,a[i].y)-b;
        if(!a[i].x&&!a[i].y)printf("%d ",p);
        else {b[p]=a[i].y;if(p==k)k++;}
    }
    printf("%d\n",k);
    return 0;
}


#include<cstdio>
#include<algorithm>
#include<iostream>
using namespace std;
#define x first
#define y second
typedef pair<int,int> per;
const int N = 100005;
per a[N];
int b[N];
bool cmp(per a,per b){if(a.x==b.x)return a.y>b.y;return a.x<b.x;}
int main()
{
    int n,i,v;
    scanf("%d",&n);
    for(i=0;i<n;i++)scanf("%d%d",&a[i].x,&a[i].y);
    scanf("%d",&v);
    for(i=0;i<n;i++)
    {
        per t=a[i];
        a[i].x=t.x+v*t.y;
        a[i].y=t.x-v*t.y;
    }
    a[n++]=make_pair(0,0);
    sort(a,a+n,cmp);
    int k=0,r=0;
    for(i=n-1;i>=0;i--)
    {
        int p=upper_bound(b,b+k,a[i].y)-b;
        if(!a[i].x&&!a[i].y)printf("%d ",p);
        else {b[p]=a[i].y;if(p==k)k++;}
    }
    printf("%d\n",k);
    return 0;
}


#include<stdio.h>
#include<algorithm>
#include<map>
using namespace std;
int getint()
{
	int ret=0;bool ok=false,neg=false;
	for(;;)
	{
		int c=getchar();
		if(c>='0'&&c<='9')ret=(ret<<3)+ret+ret+c-'0',ok=true;
		else if(ok)return neg?-ret:ret;
		else if(c=='-')neg=true;
	}
}
int n;
int V;
const int maxn=100010;
typedef pair<int,int> pii;
int x[maxn],t[maxn];
pii P[maxn];
typedef map<int,int> mii;
typedef mii::iterator iter;
mii M;
inline int query(int x)
{
	iter i=M.lower_bound(x);
	if(i==M.end())return 0;
	return i->second;
}
inline void insert(int i,int x)
{
	iter p=M.lower_bound(i);
	if(p!=M.end()&&p->second>=x)return;
	M[i]=x;
	p=M.find(i);
	for(;;)
	{
		if(p==M.begin())return;
		iter pp=p;
		pp--;
		if(pp->second>x)return;
		M.erase(pp);
	}
}
int ans,ans0;
inline bool cmp(const pii &k1,const pii &k2){return k1.first==k2.first?k1.second>k2.second:k1.first<k2.first;}
int main()
{
	n=getint();
	for(int i=1;i<=n;i++)x[i]=getint(),t[i]=getint();
	V=getint();
	n++;
	for(int i=1;i<=n;i++)P[i]=make_pair(x[i]-V*t[i],x[i]+V*t[i]);
	sort(P+1,P+n+1,cmp);
	for(int i=1;i<=n;i++)
	{
		int tans=query(P[i].second)+1;
		if(P[i]==make_pair(0,0))ans0=tans-1;
		else insert(P[i].second,tans),ans=max(ans,tans);
	}
	printf("%d\n%d\n",ans0,ans);
	return 0;
}


#include<stdio.h>
#include<algorithm>
#include<map>
using namespace std;
int getint()
{
	int ret=0;bool ok=false,neg=false;
	for(;;)
	{
		int c=getchar();
		if(c>='0'&&c<='9')ret=(ret<<3)+ret+ret+c-'0',ok=true;
		else if(ok)return neg?-ret:ret;
		else if(c=='-')neg=true;
	}
}
int n;
int V;
const int maxn=100010;
typedef pair<int,int> pii;
int x[maxn],t[maxn];
pii P[maxn];
typedef map<int,int> mii;
typedef mii::iterator iter;
mii M;
inline int query(int x)
{
	iter i=M.lower_bound(x);
	if(i==M.end())return 0;
	return i->second;
}
inline void insert(int i,int x)
{
	iter p=M.lower_bound(i);
	if(p!=M.end()&&p->second>=x)return;
	M[i]=x;
	p=M.find(i);
	for(;;)
	{
		if(p==M.begin())return;
		iter pp=p;
		pp--;
		if(pp->second>x)return;
		M.erase(pp);
	}
}
int ans,ans0;
int main()
{
	n=getint();
	for(int i=1;i<=n;i++)x[i]=getint(),t[i]=getint();
	V=getint();
	n++;
	for(int i=1;i<=n;i++)P[i]=make_pair(x[i]-V*t[i],x[i]+V*t[i]);
	sort(P+1,P+n+1);
	for(int i=1;i<=n;i++)
	{
		int tans=query(P[i].second)+1;
		if(P[i]==make_pair(0,0))ans0=tans-1;
		else insert(P[i].second,tans),ans=max(ans,tans);
	}
	printf("%d\n%d\n",ans0,ans);
	return 0;
}


#include<stdio.h>
#include<algorithm>
#include<map>
#include<functional>
using namespace std;
int getint()
{
	int ret=0;bool ok=false,neg=false;
	for(;;)
	{
		int c=getchar();
		if(c>='0'&&c<='9')ret=(ret<<3)+ret+ret+c-'0',ok=true;
		else if(ok)return neg?-ret:ret;
		else if(c=='-')neg=true;
	}
}
int n;
int V;
const int maxn=100010;
typedef pair<int,int> pii;
int x[maxn],t[maxn];
pii P[maxn];
typedef map<int,int> mii;
typedef mii::iterator iter;
mii M;
inline int query(int x)
{
	iter i=M.lower_bound(x);
	if(i==M.end())return 0;
	return i->second;
}
inline void insert(int i,int x)
{
	iter p=M.lower_bound(i);
	if(p!=M.end()&&p->second>=x)return;
	M[i]=x;
	p=M.find(i);
	for(;;)
	{
		if(p==M.begin())return;
		iter pp=p;
		pp--;
		if(pp->second>x)return;
		M.erase(pp);
	}
}
int ans,ans0;
int main()
{
	n=getint();
	for(int i=1;i<=n;i++)x[i]=getint(),t[i]=getint();
	V=getint();
	n++;
	for(int i=1;i<=n;i++)P[i]=make_pair(x[i]-V*t[i],x[i]+V*t[i]);
	sort(P+1,P+n+1,greater<pii>());
	for(int i=n;i;i--)
	{
		int tans=query(P[i].second)+1;
		if(P[i]==make_pair(0,0))ans0=tans-1;
		else insert(P[i].second,tans),ans=max(ans,tans);
	}
	printf("%d\n%d\n",ans0,ans);
	return 0;
}


#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <vector>
#include <string>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <algorithm>
#include <utility>

using namespace std;

#define llong long long
const double pi = acos(-1.0);

const int N = 100005;
int n,V;

struct Node{
	int x,t;
}node[N];

llong ls[N*3];
int cntls;
int wht(llong x){
	int l = 0,r = cntls-1;
	while(l<=r){
		int mid = (l+r)>>1;
		if(ls[mid]<=x)l = mid+1;
		else r = mid-1;
	}
	return r;
}

int ind[N],ans[N];

bool cmp(int x,int y){
	return x==n || node[x].t<node[y].t;
}

struct Seg{
	int l,r,max;
	int lch,rch;
}seg[N*6];
int tot_seg;

void build(int k,int l,int r){
	seg[k].l = l;
	seg[k].r = r;
	seg[k].max = 0;
	if(l==r){
		seg[k].lch = seg[k].rch = -1;
	}else{
		int mid = (l+r)>>1;
		seg[k].lch = ++tot_seg;
		seg[k].rch = ++ tot_seg;
		build(seg[k].lch,l,mid);
		build(seg[k].rch,mid+1,r);
		seg[k].max=  0;
	}
}

int the_max(int k,int l,int r){
	if(l<=seg[k].l && seg[k].r<=r){
		return seg[k].max;
	}else{
		int mid = (seg[k].l+seg[k].r)>>1;
		int ret = 0;
		if(l<=mid)ret = max(ret,the_max(seg[k].lch,l,r));
		if(r>mid)ret = max(ret,the_max(seg[k].rch,l,r));
		return ret;
	}
}

void ins(int k,int x,int w){
	if(seg[k].l==seg[k].r){
		seg[k].max=  w;
	}else{
		int mid = (seg[k].l+seg[k].r)>>1;
		if(x<=mid)ins(seg[k].lch,x,w);
		else ins(seg[k].rch,x,w);
		seg[k].max = max(seg[seg[k].lch].max,seg[seg[k].rch].max);
	}
}
void solve(int n){
	int i,j,k;
	sort(ind,ind+n,cmp);
	tot_seg = 0;
	build(0,0,cntls-1);
	for(i = 0;i<n;i++){
		k = ind[i];
		int a = wht(node[k].x-(llong)node[k].t*V);
		int b = wht(node[k].x+(llong)node[k].t*V);
		int c = wht(node[k].x);
		int tmp = the_max(0,a,b);
		ans[k] = tmp+1;
		ins(0,c,ans[k]);
	}
}
int main(){
	//freopen("in.txt","r",stdin);
	//freopen("out.txt","w",stdout);
	int i,j,k,t,nc = 0;
	while(scanf("%d",&n)!=EOF){
		for(i = 0;i<n;i++){
			scanf("%d%d",&node[i].x,&node[i].t);
		}
		scanf("%d",&V);
		node[n].x = 0;
		node[n].t = 0;
		cntls = 0;
		for(i = 0;i<=n;i++){
			ls[cntls++] = node[i].x-(llong)node[i].t*V;
			ls[cntls++] = node[i].x+(llong)node[i].t*V;
			ls[cntls++] = node[i].x;
		}
		sort(ls,ls+cntls);
		for(i = 0,j = 0;i<cntls;i++){
			if(j==0 || ls[j-1]!=ls[i]){
				ls[j++] = ls[i];
			}
		}
		cntls = j;
		for(i = 0;i<=n;i++)ind[i] = i;
		solve(n);
		int tmax2 = 0;
		for(i = 0;i<n;i++){
			if(tmax2<ans[i])tmax2 = ans[i];
		}
		solve(n+1);
		int tmax1 = ans[n];
		printf("%d %d\n",tmax1,tmax2);
	}
	return 0;
}


#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <vector>
#include <string>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <algorithm>
#include <utility>

using namespace std;

#define llong long long
const double pi = acos(-1.0);

const int N = 100005;
int n,V;

struct Node{
	int x,t;
}node[N];

llong ls[N*3];
int cntls;
int wht(llong x){
	int l = 0,r = cntls-1;
	while(l<=r){
		int mid = (l+r)>>1;
		if(ls[mid]<=x)l = mid+1;
		else r = mid-1;
	}
	return r;
}

int ind[N],ans[N];

bool cmp(int x,int y){
	return x==n || node[x].t<node[y].t;
}

struct Seg{
	int l,r,max;
	int lch,rch;
}seg[N*6];
int tot_seg;

void build(int k,int l,int r){
	seg[k].l = l;
	seg[k].r = r;
	seg[k].max = 0;
	if(l==r){
		seg[k].lch = seg[k].rch = -1;
	}else{
		int mid = (l+r)>>1;
		seg[k].lch = ++tot_seg;
		seg[k].rch = ++ tot_seg;
		build(seg[k].lch,l,mid);
		build(seg[k].rch,mid+1,r);
		seg[k].max=  0;
	}
}

int the_max(int k,int l,int r){
	if(l<=seg[k].l && seg[k].r<=r){
		return seg[k].max;
	}else{
		int mid = (seg[k].l+seg[k].r)>>1;
		int ret = 0;
		if(l<=mid)ret = max(ret,the_max(seg[k].lch,l,r));
		if(r>mid)ret = max(ret,the_max(seg[k].rch,l,r));
		return ret;
	}
}

void ins(int k,int x,int w){
	if(seg[k].l==seg[k].r){
		seg[k].max = max(seg[k].max,w);
	}else{
		int mid = (seg[k].l+seg[k].r)>>1;
		if(x<=mid)ins(seg[k].lch,x,w);
		else ins(seg[k].rch,x,w);
		seg[k].max = max(seg[seg[k].lch].max,seg[seg[k].rch].max);
	}
}
void solve(int n){
	int i,j,k;
	sort(ind,ind+n,cmp);
	tot_seg = 0;
	build(0,0,cntls-1);
	for(i = 0;i<n;i++){
		k = ind[i];
		int a = wht(node[k].x-(llong)node[k].t*V);
		int b = wht(node[k].x+(llong)node[k].t*V);
		int c = wht(node[k].x);
		int tmp = the_max(0,a,b);
		ans[k] = tmp+1;
		ins(0,c,ans[k]);
	}
}
int main(){
	//freopen("in.txt","r",stdin);
	//freopen("out.txt","w",stdout);
	int i,j,k,t,nc = 0;
	while(scanf("%d",&n)!=EOF){
		for(i = 0;i<n;i++){
			scanf("%d%d",&node[i].x,&node[i].t);
		}
		scanf("%d",&V);
		node[n].x = 0;
		node[n].t = 0;
		cntls = 0;
		for(i = 0;i<=n;i++){
			ls[cntls++] = node[i].x-(llong)node[i].t*V;
			ls[cntls++] = node[i].x+(llong)node[i].t*V;
			ls[cntls++] = node[i].x;
		}
		sort(ls,ls+cntls);
		for(i = 0,j = 0;i<cntls;i++){
			if(j==0 || ls[j-1]!=ls[i]){
				ls[j++] = ls[i];
			}
		}
		cntls = j;
		for(i = 0;i<=n;i++)ind[i] = i;
		solve(n);
		int tmax2 = 0;
		for(i = 0;i<n;i++){
			if(tmax2<ans[i])tmax2 = ans[i];
		}
		solve(n+1);
		int tmax1 = ans[n];
		printf("%d %d\n",tmax1,tmax2);
	}
	return 0;
}


#include<iostream>
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<algorithm>
using namespace std;

#define llong long long
const int N = 100005;

llong ls[N];
int cntls;
int wht(llong x){
	int l = 0,r = cntls-1;
	while(l<=r){
		int mid = (l+r)>>1;
		if(ls[mid]<=x)l = mid+1;
		else r = mid-1;
	}
	return r;
}

int n,V;
struct Node{
	llong x,t;
}node[N];

int ind[N];

bool cmp(int x,int y){
	return node[x].t*V-node[x].x<node[y].t*V-node[y].x;
}

llong d[N];

llong the_max(int n){
	llong ret = 0;
	while(n>0){
		ret = max(ret,d[n]);
		n -= n&(-n);
	}
	return ret;
}

void update(int n,llong w){
	while(n<N){
		d[n] = max(d[n],w);
		n += n&(-n);
	}
}
llong ans[N];
void solve(int n){
	int i,j,k;
	sort(ind,ind+n,cmp);
	memset(d,0,sizeof(d));
	for(i = 0;i<n;i++){
		j = ind[i];
		k = wht(node[j].t*V+node[j].x);
		ans[i] = the_max(k+1)+1;
		update(k+1,ans[i]);
	}
}
int main(){
	//freopen("in.txt","r",stdin);
	//freopen("out.txt","w",stdout);
	int i,j,k,t,nc = 0;
	while(scanf("%d",&n)!=EOF){
		for(i = 0;i<n;i++){
			scanf("%I64d%I64d",&node[i].x,&node[i].t);
		}
		scanf("%d",&V);
		node[n].t = node[n].x = 0;

		cntls = 0;
		for(i = 0;i<=n;i++){
			ls[cntls++] = node[i].t*V+node[i].x;
		}
		sort(ls,ls+cntls);
		for(i = 0,j = 0;i<cntls;i++){
			if(j==0 || ls[j-1]!=ls[i]){
				ls[j++] = ls[i];
			}
		}
		cntls = j;

		for(i = 0;i<=n;i++)ind[i] = i;

		solve(n);
		llong tmax1 = 0;
		for(i = 0;i<n;i++){
			if(tmax1<ans[i])tmax1 = ans[i];
		}
		cntls = j;
		solve(n+1);
		llong tmax2 = ans[n];
		printf("%I64d %I64d\n",tmax2-1,tmax1);
	}
	return 0;
}


#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <vector>
#include <string>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <algorithm>
#include <utility>

using namespace std;

#define llong long long
const double pi = acos(-1.0);

const int N = 100005;
int n,V;

struct Node{
	int x,t;
}node[N];

llong ls[N*3];
int cntls;
int wht(llong x){
	int l = 0,r = cntls-1;
	while(l<=r){
		int mid = (l+r)>>1;
		if(ls[mid]<=x)l = mid+1;
		else r = mid-1;
	}
	return r;
}

int ind[N],ans[N];

bool cmp(int x,int y){
	return x==n || node[x].t<node[y].t;
}

struct Seg{
	int l,r,max;
	int lch,rch;
}seg[N*6];
int tot_seg;

void build(int k,int l,int r){
	seg[k].l = l;
	seg[k].r = r;
	seg[k].max = 0;
	if(l==r){
		seg[k].lch = seg[k].rch = -1;
	}else{
		int mid = (l+r)>>1;
		seg[k].lch = ++tot_seg;
		seg[k].rch = ++ tot_seg;
		build(seg[k].lch,l,mid);
		build(seg[k].rch,mid+1,r);
		seg[k].max=  0;
	}
}

int the_max(int k,int l,int r){
	if(l<=seg[k].l && seg[k].r<=r){
		return seg[k].max;
	}else{
		int mid = (seg[k].l+seg[k].r)>>1;
		int ret = 0;
		if(l<=mid)ret = max(ret,the_max(seg[k].lch,l,r));
		if(r>mid)ret = max(ret,the_max(seg[k].rch,l,r));
		return ret;
	}
}

void ins(int k,int x,int w){
	if(seg[k].l==seg[k].r){
		seg[k].max=  w;
	}else{
		int mid = (seg[k].l+seg[k].r)>>1;
		if(x<=mid)ins(seg[k].lch,x,w);
		else ins(seg[k].rch,x,w);
		seg[k].max = max(seg[seg[k].lch].max,seg[seg[k].rch].max);
	}
}
void solve(int n){
	int i,j,k;
	sort(ind,ind+n,cmp);
	tot_seg = 0;
	build(0,0,cntls-1);
	for(i = 0;i<n;i++){
		k = ind[i];
		int a = wht(node[k].x-(llong)node[k].t*V);
		int b = wht(node[k].x+(llong)node[k].t*V);
		int c = wht(node[k].x);
		int tmp = the_max(0,a,b);
		ans[k] = tmp+1;
		ins(0,c,ans[k]);
	}
}
int main(){
	//freopen("in.txt","r",stdin);
	//freopen("out.txt","w",stdout);
	int i,j,k,t,nc = 0;
	while(scanf("%d",&n)!=EOF){
		for(i = 0;i<n;i++){
			scanf("%d%d",&node[i].x,&node[i].t);
		}
		scanf("%d",&V);
		node[n].x = 0;
		node[n].t = 0;
		cntls = 0;
		for(i = 0;i<=n;i++){
			ls[cntls++] = node[i].x-(llong)node[i].t*V;
			ls[cntls++] = node[i].x+(llong)node[i].t*V;
			ls[cntls++] = node[i].x;
		}
		sort(ls,ls+cntls);
		for(i = 0,j = 0;i<=n;i++){
			if(j==0 || ls[j-1]!=ls[i]){
				ls[j++] = ls[i];
			}
		}
		cntls = j;
		for(i = 0;i<=n;i++)ind[i] = i;
		solve(n);
		int tmax2 = 0;
		for(i = 0;i<n;i++){
			if(tmax2<ans[i])tmax2 = ans[i];
		}
		solve(n+1);
		int tmax1 = ans[n];
		printf("%d %d\n",tmax1,tmax2);
	}
	return 0;
}


#include<iostream>
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<algorithm>
using namespace std;

#define llong long long
const int N = 100005;

llong ls[N];
int cntls;
int wht(llong x){
	x = -x;
	int l = 0,r = cntls-1;
	while(l<=r){
		int mid = (l+r)>>1;
		if(ls[mid]<=x)l = mid+1;
		else r = mid-1;
	}
	return r;
}

int n,V;
struct Node{
	llong x,t;
}node[N];

int ind[N];

bool cmp(int x,int y){
	return node[x].t*V-node[x].x>node[y].t*V-node[y].x
		|| node[x].t*V-node[x].x>node[y].t*V-node[y].x
		&& node[x].t*V+node[x].x>node[y].t*V+node[y].x;
}

int d[N];

int the_max(int n){
	int ret = 0;
	while(n>0){
		ret = max(ret,d[n]);
		n -= n&(-n);
	}
	return ret;
}

void update(int n,int w){
	while(n<N){
		d[n] = max(d[n],w);
		n += n&(-n);
	}
}
int ans[N];
void solve(int n){
	int i,j,k;
	sort(ind,ind+n,cmp);
	memset(d,0,sizeof(d));
	for(i = 0;i<n;i++){
		j = ind[i];
		k = wht(node[j].t*V+node[j].x);
		ans[j] = the_max(k+1)+1;
		update(k+1,ans[j]);
	}
}
int main(){
	//freopen("in.txt","r",stdin);
	//freopen("out.txt","w",stdout);
	int i,j,k,t,nc = 0;
	while(scanf("%d",&n)!=EOF){
		for(i = 0;i<n;i++){
			scanf("%I64d%I64d",&node[i].x,&node[i].t);
		}
		scanf("%d",&V);
		node[n].t = node[n].x = 0;

		cntls = 0;
		for(i = 0;i<=n;i++){
			ls[cntls++] = node[i].t*V+node[i].x;
			ls[cntls-1] *= -1;
		}
		sort(ls,ls+cntls);
		for(i = 0,j = 0;i<cntls;i++){
			if(j==0 || ls[j-1]!=ls[i]){
				ls[j++] = ls[i];
			}
		}
		cntls = j;

		for(i = 0;i<=n;i++)ind[i] = i;

		solve(n);
		int tmax1 = 0;
		for(i = 0;i<n;i++){
			if(tmax1<ans[i])tmax1 = ans[i];
		}

		solve(n+1);
		int tmax2 = ans[n];
		printf("%d %d\n",tmax2-1,tmax1);
	}
	return 0;
}


#include<iostream>
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<algorithm>
using namespace std;

#define llong long long
const int N = 100005;

llong ls[N];
int cntls;
int wht(llong x){
	x = -x;
	int l = 0,r = cntls-1;
	while(l<=r){
		int mid = (l+r)>>1;
		if(ls[mid]<=x)l = mid+1;
		else r = mid-1;
	}
	return r;
}

int n,V;
struct Node{
	llong x,t;
}node[N];

int ind[N];

bool cmp(int x,int y){
	return node[x].t*V-node[x].x>node[y].t*V-node[y].x;
}

int d[N];

int the_max(int n){
	int ret = 0;
	while(n>0){
		ret = max(ret,d[n]);
		n -= n&(-n);
	}
	return ret;
}

void update(int n,int w){
	while(n<N){
		d[n] = max(d[n],w);
		n += n&(-n);
	}
}
int ans[N];
void solve(int n){
	int i,j,k;
	sort(ind,ind+n,cmp);
	memset(d,0,sizeof(d));
	for(i = 0;i<n;i++){
		j = ind[i];
		k = wht(node[j].t*V+node[j].x);
		ans[j] = the_max(k+1)+1;
		update(k+1,ans[j]);
	}
}
int main(){
	//freopen("in.txt","r",stdin);
	//freopen("out.txt","w",stdout);
	int i,j,k,t,nc = 0;
	while(scanf("%d",&n)!=EOF){
		for(i = 0;i<n;i++){
			scanf("%I64d%I64d",&node[i].x,&node[i].t);
		}
		scanf("%d",&V);
		node[n].t = node[n].x = 0;

		cntls = 0;
		for(i = 0;i<=n;i++){
			ls[cntls++] = node[i].t*V+node[i].x;
			ls[cntls-1] *= -1;
		}
		sort(ls,ls+cntls);
		for(i = 0,j = 0;i<cntls;i++){
			if(j==0 || ls[j-1]!=ls[i]){
				ls[j++] = ls[i];
			}
		}
		cntls = j;

		for(i = 0;i<=n;i++)ind[i] = i;

		solve(n);
		int tmax1 = 0;
		for(i = 0;i<n;i++){
			if(tmax1<ans[i])tmax1 = ans[i];
		}
		cntls = j;
		solve(n+1);
		int tmax2 = ans[n];
		printf("%d %d\n",tmax2-1,tmax1);
	}
	return 0;
}


#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <vector>
#include <string>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <algorithm>
#include <utility>

using namespace std;

#define llong long long
const double pi = acos(-1.0);

const int N = 100005;
int n,V;

struct Node{
	int x,t;
}node[N];

llong ls[N*3];
int cntls;
int wht(llong x){
	int l = 0,r = cntls-1;
	while(l<=r){
		int mid = (l+r)>>1;
		if(ls[mid]<=x)l = mid+1;
		else r = mid-1;
	}
	return r;
}

int ind[N],ans[N];

bool cmp(int x,int y){
	return node[x].t<node[y].t;
}

struct Seg{
	int l,r,max;
	int lch,rch;
}seg[N*6];
int tot_seg;

void build(int k,int l,int r){
	seg[k].l = l;
	seg[k].r = r;
	seg[k].max = 0;
	if(l==r){
		seg[k].lch = seg[k].rch = -1;
	}else{
		int mid = (l+r)>>1;
		seg[k].lch = ++tot_seg;
		seg[k].rch = ++ tot_seg;
		build(seg[k].lch,l,mid);
		build(seg[k].rch,mid+1,r);
		seg[k].max=  0;
	}
}

int the_max(int k,int l,int r){
	if(l<=seg[k].l && seg[k].r<=r){
		return seg[k].max;
	}else{
		int mid = (seg[k].l+seg[k].r)>>1;
		int ret = 0;
		if(l<=mid)ret = max(ret,the_max(seg[k].lch,l,r));
		if(r>mid)ret = max(ret,the_max(seg[k].rch,l,r));
		return ret;
	}
}

void ins(int k,int x,int w){
	if(seg[k].l==seg[k].r){
		seg[k].max=  w;
	}else{
		int mid = (seg[k].l+seg[k].r)>>1;
		if(x<=mid)ins(seg[k].lch,x,w);
		else ins(seg[k].rch,x,w);
		seg[k].max = max(seg[seg[k].lch].max,seg[seg[k].rch].max);
	}
}
void solve(int n){
	int i,j,k;
	sort(ind,ind+n,cmp);
	tot_seg = 0;
	build(0,0,cntls-1);
	for(i = 0;i<n;i++){
		k = ind[i];
		int a = wht(node[k].x-node[k].t*V);
		int b = wht(node[k].x+node[k].t*V);
		int c = wht(node[k].x);
		int tmp = the_max(0,a,b);
		ans[k] = tmp+1;
		ins(0,c,ans[k]);
	}
}
int main(){
	//freopen("in.txt","r",stdin);
	//freopen("out.txt","w",stdout);
	int i,j,k,t,nc = 0;
	while(scanf("%d",&n)!=EOF){
		for(i = 0;i<n;i++){
			scanf("%d%d",&node[i].x,&node[i].t);
		}
		scanf("%d",&V);
		node[n].x = 0;
		node[n].t = 0;
		cntls = 0;
		for(i = 0;i<=n;i++){
			ls[cntls++] = node[i].x-(llong)node[i].t*V;
			ls[cntls++] = node[i].x+(llong)node[i].t*V;
			ls[cntls++] = node[i].x;
		}
		sort(ls,ls+cntls);
		for(i = 0,j = 0;i<=n;i++){
			if(j==0 || ls[j-1]!=ls[i]){
				ls[j++] = ls[i];
			}
		}
		cntls = j;
		for(i = 0;i<=n;i++)ind[i] = i;
		solve(n);
		int tmax2 = 0;
		for(i = 0;i<n;i++){
			if(tmax2<ans[i])tmax2 = ans[i];
		}
		solve(n+1);
		int tmax1 = ans[n];
		printf("%d %d\n",tmax1,tmax2);
	}
	return 0;
}


#include<iostream>
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<algorithm>
using namespace std;

#define llong long long
const int N = 100005;

llong ls[N];
int cntls;
int wht(llong x){
	int l = 0,r = cntls-1;
	while(l<=r){
		int mid = (l+r)>>1;
		if(ls[mid]<=x)l = mid+1;
		else r = mid-1;
	}
	return r;
}

int n,V;
struct Node{
	llong x,t;
}node[N];

int ind[N];

bool cmp(int x,int y){
	return node[x].t*V-node[x].x<node[y].t*V-node[y].x;
}

int d[N];

int the_max(int n){
	int ret = 0;
	while(n>0){
		ret = max(ret,d[n]);
		n -= n&(-n);
	}
	return ret;
}

void update(int n,int w){
	while(n<N){
		d[n] = max(d[n],w);
		n += n&(-n);
	}
}
int ans[N];
void solve(int n){
	int i,j,k;
	sort(ind,ind+n,cmp);
	memset(d,0,sizeof(d));
	for(i = 0;i<n;i++){
		j = ind[i];
		k = wht(node[j].t*V+node[j].x);
		ans[j] = the_max(k+1)+1;
		update(k+1,ans[j]);
	}
}
int main(){
	//freopen("in.txt","r",stdin);
	//freopen("out.txt","w",stdout);
	int i,j,k,t,nc = 0;
	while(scanf("%d",&n)!=EOF){
		for(i = 0;i<n;i++){
			scanf("%I64d%I64d",&node[i].x,&node[i].t);
		}
		scanf("%d",&V);
		node[n].t = node[n].x = 0;

		cntls = 0;
		for(i = 0;i<=n;i++){
			ls[cntls++] = node[i].t*V+node[i].x;
		}
		sort(ls,ls+cntls);
		for(i = 0,j = 0;i<cntls;i++){
			if(j==0 || ls[j-1]!=ls[i]){
				ls[j++] = ls[i];
			}
		}
		cntls = j;

		for(i = 0;i<=n;i++)ind[i] = i;

		solve(n);
		int tmax1 = 0;
		for(i = 0;i<n;i++){
			if(tmax1<ans[i])tmax1 = ans[i];
		}
		cntls = j;
		solve(n+1);
		int tmax2 = ans[n];
		printf("%d %d\n",tmax2-1,tmax1);
	}
	return 0;
}


#include<iostream>
#include<cstdlib>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;

#define llong long long

const int N = 100005;
struct Node{
	int x,t;
}node[N];

llong ls[N];
int cntls;
int wht(llong x){
	int l = 0,r = cntls-1;
	while(l<=r){
		int mid = (l+r)>>1;
		if(ls[mid]<=x)l = mid+1;
		else r = mid-1;
	}
	return r;
}

int n,V,ans[N],ind[N];

int d[N];
inline int lowbit(int x){
	return x&(-x);
}
int the_max(int n){
	int ret = 0;
	while(n>0){
		ret = max(ret,d[n]);
		n -= lowbit(n);
	}
	return ret;
}

void ins(int n,int w){
	while(n<N){
		d[n] = max(d[n],w);
		n += lowbit(n);
	}
}
bool cmp(int x,int y){
	return (llong)node[x].t*V-node[x].x>(llong)node[y].t*V-node[y].x
		|| (llong)node[x].t*V-node[x].x==(llong)node[y].t*V-node[y].x
		&& (llong)node[x].t*V+node[x].x>(llong)node[y].t*V+node[y].x;
}
void solve(int n){
	int i,j,k;
	memset(d,0,sizeof(d));
	for(i = 0;i<n;i++)ind[i] = i;
	sort(ind,ind+n,cmp);
	for(i = 0;i<n;i++){
		j = ind[i];
		llong tmp = (llong)node[j].t*V+node[j].x;
		k = wht(-tmp)+1;
		ans[j] = the_max(k)+1;
		ins(k,ans[j]);
	}
}
int main(){
	//freopen("in.txt","r",stdin);
	//freopen("out.txt","w",stdout);
	int i,j,k,t,nc = 0;
	while(scanf("%d",&n)!=EOF){
		for(i = 0;i<n;i++){
			scanf("%d%d",&node[i].x,&node[i].t);
		}
		scanf("%d",&V);
		node[n].x = node[n].t = 0;
		cntls = 0;
		for(i = 0;i<n;i++){
			ls[cntls++] = (llong)node[i].t*V+node[i].x;
			ls[cntls-1] *= -1;
		}
		sort(ls,ls+cntls);
		for(i = 0,j = 0;i<cntls;i++){
			if(j==0 || ls[j-1]!=ls[i]){
				ls[j++] = ls[i];
			}
		}
		cntls = j;

		int tmax1 = 0;
		solve(n);
		for(i = 0;i<n;i++){
			if(tmax1<ans[i])tmax1 = ans[i];
		}

		solve(n+1);
		int tmax2 = ans[n];

		printf("%d %d\n",tmax2-1,tmax1);
	}
	return 0;
}


#include<iostream>
#include<cstdlib>
#include<cstdio>
#include<algorithm>
using namespace std;

#define llong long long

const int N = 100005;
struct Node{
	int x,t;
}node[N];

llong ls[N];
int cntls;
int wht(llong x){
	int l = 0,r = cntls-1;
	while(l<=r){
		int mid = (l+r)>>1;
		if(ls[mid]<=x)l = mid+1;
		else r = mid-1;
	}
	return r;
}

int n,V,ans[N],ind[N];

int d[N];
inline int lowbit(int x){
	return x&(-x);
}
int the_max(int n){
	int ret = 0;
	while(n>0){
		ret = max(ret,d[n]);
		n -= lowbit(n);
	}
	return ret;
}

void ins(int n,int w){
	while(n<N){
		d[n] = max(d[n],w);
		n += lowbit(n);
	}
}
bool cmp(int x,int y){
	return (llong)node[x].t*V-node[x].x>(llong)node[y].t*V-node[y].x
		|| (llong)node[x].t*V-node[x].x==(llong)node[y].t*V-node[y].x
		&& (llong)node[x].t*V+node[x].x>(llong)node[y].t*V+node[y].x;
}
void solve(int n){
	int i,j,k;
	memset(d,0,sizeof(d));
	for(i = 0;i<n;i++)ind[i] = i;
	sort(ind,ind+n,cmp);
	for(i = 0;i<n;i++){
		j = ind[i];
		llong tmp = (llong)node[j].t*V+node[j].x;
		k = wht(-tmp)+1;
		ans[j] = the_max(k)+1;
		ins(k,ans[j]);
	}
}
int main(){
	//freopen("in.txt","r",stdin);
	//freopen("out.txt","w",stdout);
	int i,j,k,t,nc = 0;
	while(scanf("%d",&n)!=EOF){
		for(i = 0;i<n;i++){
			scanf("%d%d",&node[i].x,&node[i].t);
		}
		scanf("%d",&V);
		node[n].x = node[n].t = 0;
		cntls = 0;
		for(i = 0;i<n;i++){
			ls[cntls++] = (llong)node[i].t*V+node[i].x;
			ls[cntls-1] *= -1;
		}
		sort(ls,ls+cntls);
		for(i = 0,j = 0;i<cntls;i++){
			if(j==0 || ls[j-1]!=ls[i]){
				ls[j++] = ls[i];
			}
		}
		cntls = j;

		int tmax1 = 0;
		solve(n);
		for(i = 0;i<n;i++){
			if(tmax1<ans[i])tmax1 = ans[i];
		}

		solve(n+1);
		int tmax2 = ans[n];

		printf("%d %d\n",tmax2-1,tmax1);
	}
	return 0;
}


#include<cstdio>
#include<cstdlib>
#include<algorithm>
using namespace std;
int n,sh,sh2,f,l,m;
long long x[100001],t[100001],v,save[100001],n_s = -1,ans[100001];
pair < pair<long long,long long>, int > P[100001];
int main(){
    scanf("%d",&n);
    for(int i=0;i<n;i++) scanf("%I64d %I64d",&x[i],&t[i]);
    scanf("%I64d",&v);
    for(int i=0;i<n;i++)
       P[i] = make_pair( make_pair(t[i]*v+x[i],v*t[i]-x[i]), i);
    sort(P,P+n);
    sh = 0; sh2 = -1;
    for(int i=0;i<n;i++){
        f = 0,l = n_s;
        while(f<l){
            m = (f+l)/2;
            if(save[m] <= P[i].first.second) f = m+1;
            else  l = m-1;
        }
        l++;
        if(l > n_s) n_s = l;
        sh = max(sh,l);
        if(abs(x[P[i].second]) <= v*t[P[i].second]) sh2 = max(sh2,l);
        save[l] = P[i].first.second;
    }
    printf("%d %d\n",sh2+1,sh+1);
    //system("pause");
    return 0;
}


#include<cstdio>
#include<cstdlib>
#include<algorithm>
using namespace std;
int n,sh,sh2,f,l,m;
long long x[100001],t[100001],v,save[100001],n_s = -1,ans[100001];
pair < pair<long long,long long>, int > P[100001];
int main(){
    scanf("%d",&n);
    for(int i=0;i<n;i++) scanf("%I64d %I64d",&x[i],&t[i]);
    scanf("%I64d",&v);
    for(int i=0;i<n;i++)
       P[i] = make_pair( make_pair(t[i]*v+x[i],v*t[i]-x[i]), i);
    sort(P,P+n);
    sh = 0; sh2 = -1;
    for(int i=n-1;i>=0;i--){
        f = 0,l = n_s;
        //printf("%I64d \t %I64d\n",P[i].first.first,P[i].first.second);
        while(f<=l){
            //printf("%d %d\n",f,l);
            m = (f+l)/2;
            if(save[m] >= P[i].first.second) f = m+1;
            else  l = m-1;
        }
        l++; //printf("%d\n",l);
        if(l > n_s) n_s = l;
        sh = max(sh,l);
        if(abs(x[P[i].second]) <= v*t[P[i].second]) sh2 = max(sh2,l);
        save[l] = P[i].first.second;
    }
    printf("%d %d\n",sh2+1,sh+1);
    //system("pause");
    return 0;
}


#include<cstdio>
#include<cstdlib>
#include<algorithm>
using namespace std;
int n,sh,sh2,f,l,m;
long long x[100001],t[100001],v,save[100001],n_s = -1,ans[100001];
pair < pair<long long,long long>, int > P[100001];
int main(){
    scanf("%d",&n);
    for(int i=0;i<n;i++) scanf("%I64d %I64d",&x[i],&t[i]);
    scanf("%I64d",&v);
    for(int i=0;i<n;i++)
       P[i] = make_pair( make_pair(t[i]*v+x[i],v*t[i]-x[i]), i);
    sort(P,P+n);
    sh = 0; sh2 = -1;
    for(int i=n-1;i>=0;i--){
        f = 0,l = n_s;
        //printf("%I64d \t %I64d\n",P[i].first.first,P[i].first.second);
        while(f<=l){
            //printf("%d %d\n",f,l);
            m = (f+l)/2;
            if(save[m] > P[i].first.second) f = m+1;
            else  l = m-1;
        }
        l++; //printf("%d\n",l);
        if(l > n_s) n_s = l;
        sh = max(sh,l);
        if(abs(x[P[i].second]) <= v*t[P[i].second]) sh2 = max(sh2,l);
        save[l] = P[i].first.second;
    }
    printf("%d %d\n",sh2+1,sh+1);
    //system("pause");
    return 0;
}


#include<cstdio>
#include<cstdlib>
#include<algorithm>
using namespace std;
int n,sh,sh2,f,l,m;
long long x[100001],t[100001],v,save[100001],n_s = -1,ans[100001];
pair < pair<long long,long long>, int > P[100001];
int main(){
    scanf("%d",&n);
    for(int i=0;i<n;i++) scanf("%I64d %I64d",&x[i],&t[i]);
    scanf("%I64d",&v);
    for(int i=0;i<n;i++)
       P[i] = make_pair( make_pair(t[i]*v+x[i],v*t[i]-x[i]), i);
    sort(P,P+n);
    sh = 0; sh2 = -1;
    for(int i=0;i<n;i++){
        f = 0,l = n_s;
        //printf("%I64d \t %I64d\n",P[i].first.first,P[i].first.second);
        while(f<=l){
            //printf("%d %d\n",f,l);
            m = (f+l)/2;
            if(save[m] <= P[i].first.second) f = m+1;
            else  l = m-1;
        }
        l++; //printf("%d\n",l);
        if(l > n_s) n_s = l;
        sh = max(sh,l);
        if(abs(x[P[i].second]) <= v*t[P[i].second]) sh2 = max(sh2,l);
        save[l] = P[i].first.second;
    }
    printf("%d %d\n",sh2+1,sh+1);
    //system("pause");
    return 0;
}


#include <iostream>
#include <algorithm>
#define inf 1000000000
using namespace std;
typedef long long L;
L lmax;
struct point{
    L x,t,p,q;
};
L n;
L v;
point A[100001];
L X[100001];
int ls;
bool var;

int f(point a,point b){
    if(a.p!=b.p)return a.p<b.p;
    return a.q<b.q;
}

int find(int b,int n){

    if(A[b].q==-lmax)b++;
    ls=2;
    X[1]=A[b].q;

    for(int i=b+1;i<=n;i++){
        int idx=(int)(upper_bound(X,X+ls,A[i].q)-X);
        if(idx>1){
            if(idx==ls)X[ls++]=A[i].q;
            else X[idx]=A[i].q;
        }
        /*for(int j=1;j<ls;j++)
            cout<<X[j]<<" ";
        cout<<endl;*/
    }

    return ls-1;

}

int main()
{
    var=false;
    lmax=(L)inf*(L)inf;

    cin>>n;
    for(int i=0;i<n;i++){
        cin>>A[i].x>>A[i].t;
        if(A[i].x==0&&A[i].t==0)var=true;
    }
    cin>>v;

   for(int i=0;i<n;i++){
        A[i].p=-A[i].x+A[i].t*v;
        A[i].q=A[i].x+A[i].t*v;
    }

    if(!var){
        A[n].p=A[n].q=0;
        sort(A,A+(n+1),f);

        int idx=0;
        while(A[idx].p!=0||A[idx].q!=0)idx++;

        cout<<find(idx,n)-1<<" ";
        A[idx].q=-lmax;

        /*for(int i=0;i<=n;i++)
            cout<<A[i].p<<" "<<A[i].q<<endl;
        cout<<endl;*/

        cout<<find(0,n)<<endl;
    }
    else{
        sort(A,A+n,f);
        int idx=0;
        while(A[idx].p!=0||A[idx].q!=0)idx++;

        //for(int i=0;i<=n;i++)
        //    cout<<A[i].p<<" "<<A[i].q<<endl;
        //cout<<endl;
        cout<<find(idx,n-1)<<" "<<find(0,n-1)<<endl;
    }

    return 0;
}


#include <iostream>
#include <algorithm>
#define inf 1000000000
using namespace std;
typedef long long L;
L lmax;
struct point{
    L x,t,p,q;
};
L n;
L v;
point A[100001];
L X[100001];
int ls;
bool var;

int f(point a,point b){
    if(a.p!=b.p)return a.p<b.p;
    return a.q<b.q;
}

int find(int b,int n){

    ls=2;
    X[1]=A[b].q;

    for(int i=b+1;i<=n;i++){
        int idx=(int)(upper_bound(X,X+ls,A[i].q)-X);
        if(idx>1){
            if(idx==ls)X[ls++]=A[i].q;
            else X[ls]=A[i].q;
        }
        //cout<<X[ls-1]<<endl;
    }

    return ls-1;

}

int main()
{
    var=false;
    lmax=(L)inf*(L)inf;

    cin>>n;
    for(int i=0;i<n;i++){
        cin>>A[i].x>>A[i].t;
        if(A[i].x==0&&A[i].t==0)var=true;
    }
    cin>>v;

   for(int i=0;i<n;i++){
        A[i].p=-A[i].x+A[i].t*v;
        A[i].q=A[i].x+A[i].t*v;
    }

    if(!var){
        A[n].p=A[n].q=0;
        sort(A,A+(n+1),f);

        int idx=0;
        while(A[idx].p!=0||A[idx].q!=0)idx++;

        cout<<find(idx,n)-1<<" ";
        A[idx].q=-lmax;

        /*for(int i=0;i<=n;i++)
            cout<<A[i].p<<" "<<A[i].q<<endl;
        cout<<endl;*/

        cout<<find(0,n)<<endl;
    }
    else{
        sort(A,A+n,f);
        int idx=0;
        while(A[idx].p!=0||A[idx].q!=0)idx++;

        //for(int i=0;i<=n;i++)
        //    cout<<A[i].p<<" "<<A[i].q<<endl;
        //cout<<endl;
        cout<<find(idx,n-1)<<" "<<find(0,n-1)<<endl;
    }

    system("PAUSE");
    return 0;
}


#include <iostream>
#include <algorithm>
#define inf 1000000000
using namespace std;
typedef long long L;
L lmax;
struct point{
    L x,t,p,q;
};
L n;
L v;
point A[100001];
L X[100001];
int ls;
bool var;

int f(point a,point b){
    if(a.p!=b.p)return a.p<b.p;
    return a.q<b.q;
}

int find(int b,int n,bool bl){

    if(A[b].q==-lmax)b++;
    ls=2;
    X[1]=A[b].q;

    for(int i=b+1;i<=n;i++){
        int idx=(int)(upper_bound(X,X+ls,A[i].q)-X);
        if(!(bl&&idx==1)){
            if(idx==ls)X[ls++]=A[i].q;
            else X[idx]=A[i].q;
        }
        /*for(int j=1;j<ls;j++)
            cout<<X[j]<<" ";
        cout<<endl;*/
    }

    return ls-1;

}

int main()
{
    var=false;
    lmax=(L)inf*(L)inf;

    cin>>n;
    for(int i=0;i<n;i++){
        cin>>A[i].x>>A[i].t;
        if(A[i].x==0&&A[i].t==0)var=true;
    }
    cin>>v;

   for(int i=0;i<n;i++){
        A[i].p=-A[i].x+A[i].t*v;
        A[i].q=A[i].x+A[i].t*v;
    }

    if(!var){
        A[n].p=A[n].q=0;
        sort(A,A+(n+1),f);

        int idx=0;
        while(A[idx].p!=0||A[idx].q!=0)idx++;

        cout<<find(idx,n,true)-1<<" ";
        A[idx].q=-lmax;

        /*for(int i=0;i<=n;i++)
            cout<<A[i].p<<" "<<A[i].q<<endl;
        cout<<endl;*/

        cout<<find(0,n,false)<<endl;
    }
    else{
        sort(A,A+n,f);
        int idx=0;
        while(A[idx].p!=0||A[idx].q!=0)idx++;

        //for(int i=0;i<=n;i++)
        //    cout<<A[i].p<<" "<<A[i].q<<endl;
        //cout<<endl;
        cout<<find(idx,n-1,true)<<" "<<find(0,n-1,false)<<endl;
    }

    return 0;
}


#include <iostream>
using namespace std;

int main()
{
	unsigned long long int S = 0, D = 0, x;
	int n;
	cin >> n;
	int *Numbers = new int[n];
	for (int i = 0; i < n; i++)
		cin >> Numbers[i];
	for (int i = 0; i < n; i++)
	{
		for (int j = i + 1; j < n; j++)
		{
			if (Numbers[i] < Numbers[j])
				swap(Numbers[i], Numbers[j]);
		}
	}
	for (int i = 0; i < n; i++)
	{
		if (i % 2 == 0)
			S += Numbers[i];
		else
		{
			D += Numbers[i];
		}
	}
	cout << S << " " << D;
	return 0;
}


#include <iostream>
using namespace std;

int main()
{
	unsigned long long int S = 0, D = 0, x;
	int n;
	cin >> n;
	int *Numbers = new int[n];

	for (int i = 0; i < n; i++)
		cin >> Numbers[i];

	int turn = 0;
	for (int i = 0, j = n - 1; j>=i;)
	{
		if (Numbers[i] > Numbers[j])
		{
			i++;
			if (turn % 2 == 0)
				S += Numbers[i-1];
			else
			{
				D += Numbers[i-1];
			}
		}
		else
		{
			j--;
			if (turn % 2 == 0)
				S += Numbers[j+1];
			else
			{
				D += Numbers[j+1];
			}
		}
		turn++;
	}
	cout << S << " " << D;
	return 0;
}


#include<iostream>
#include<algorithm>
using namespace std;
int sum1;
int sum2;
int a[1001];
int i;
int main() {
	int n;
	cin >> n;
	int b = n - 1;
	for (int i = 0;i <= b;i++) {
		cin >> a[i];
	}
	while (i <= b && b >= 1) {
		if (a[i] >= a[b]) {
			sum1 = sum1 + a[i];
			i++;
		}
		else {
			sum1 = sum1 + a[b];
			b--;
		}
		if (a[i] >= a[b]) {
			sum2 = sum2 + a[i];
			i++;
		}
		else {
			sum2 = sum2 + a[b];
			b--;
			if (i == b) {
				sum1 = sum1 + a[i];
			}
		}
	}
	if (n == 1) {
		sum1 = a[0];
	}
	cout << sum1 << " " << sum2;
	return 0;
}


#include<iostream>
#include<algorithm>
using namespace std;
int sum1;
int sum2;
int a[1001];
int main() {
	int n;
	cin >> n;
	int b = n - 1;
	for (int i = 0;i <= b;i++) {
		cin >> a[i];
	}
	int i = 0;
	while (i != b) {
		if (a[i] >= a[b]) {
			sum1 = sum1 + a[i];
			if (i == b) {
				break;
			}
			i++;
		}
		else {
			sum1 = sum1 + a[b];
			if (i == b) {
				break;
			}
			b--;
		}
		if (a[i] >= a[b]) {
			sum2 = sum2 + a[i];
			if (i == b) {
				break;
			}
			i++;
		}
		else {
			sum2 = sum2 + a[b];
			if (i == b) {
				break;
			}
			b--;
			if (i == b) {
				sum1 = sum1 + a[i];
			}
		}
	}
	if (n == 1) {
		sum1 = a[0];
	}
	cout << sum1 << " " << sum2;
	return 0;
}


#include<iostream>
#include<algorithm>
using namespace std;
int sum1;
int sum2;
int main() {
	int n;
	cin >> n;
	int a[1001];
	for (int i = 0;i < n;i++) {
		cin >> a[i];
	}
	sort(a, a + n);
	if (n % 2 == 0) {
		for (int i = 1;i < n;i += 2) {
			sum1 = sum1 + a[i];
		}
		for (int i = 0;i < n;i += 2) {
			sum2 = sum2 + a[i];
		}
	}
	else {
		for (int i = 1;i < n;i += 2) {
			sum2 = sum2 + a[i];
		}
		for (int i = 0;i < n;i += 2) {
			sum1 = sum1 + a[i];
		}
	}
	cout << sum1 << " " << sum2;
	return 0;
}


#include<iostream>
using namespace std;
int sum1;
int sum2;
int c;
int a[1001];
int main(){
	int n;
	cin >> n;
	int j = n - 1;
	for (int i = 0;i < n;i++) {
		cin >> a[i];
	}
	for (int i = 0;i < n;i++) {
		if (i % 2 == 0) {
			if (a[c] > a[j]) {
				sum1 = sum1 + a[c];
				c++;
			}
			else {
				sum1 = sum1 + a[j];
				j--;
			}
		}
		else {
			if (a[c] > a[j]) {
				sum2 = sum2 + a[c];
				c++;
			}
			else {
				sum2 = sum2 + a[j];
				j--;
			}
		}
	}
	cout << sum1 << " " << sum2;
	return 0;
}


#include<iostream>
#include<algorithm>
using namespace std;
int sum1;
int sum2;
int a[1001];
int main() {
	int n;
	cin >> n;
	int b = n - 1;
	for (int i = 0;i <= b;i++) {
		cin >> a[i];
	}
	int i = 0;
	while (i != b) {
		if (a[i] >= a[b]) {
			sum1 = sum1 + a[i];
			if (i == b) {
				break;
			}
			i++;
		}
		else {
			sum1 = sum1 + a[b];
			if (i == b) {
				break;
			}
			b--;
		}
		if (a[i] >= a[b]) {
			sum2 = sum2 + a[i];
			if (i == b) {
				break;
			}
			i++;
		}
		else {
			sum2 = sum2 + a[b];
			if (i == b) {
				break;
			}
			b--;
			if (i == b) {
				sum1 = sum1 + a[i];
			}
		}

	}
	cout << sum1 << " " << sum2;
	return 0;
}


#include<iostream>
using namespace std;
void main()
{
	int n , loop , cards[1005] , z , sere=0 , dema=0 , x ,  y , loop2;
	cin>>n;
	for(loop=0;loop<n;loop++)
		cin>>cards[loop];
	for(loop2=0;loop2<n;loop2++)
	{
		for(loop=0;loop<n-1;loop++)
		{
			if(cards[loop]>cards[loop+1])
			{
				z=cards[loop];
				cards[loop]=cards[loop+1];
				cards[loop+1]=z;
			}
		}
	}
	for(x=1;x<n;x=x+2)
	{
		sere=cards[x]+sere;
	}
	for(y=0;y<n;y=y+2)
	{
		dema=cards[y]+dema;
	}
	if(dema>sere)
		cout<<dema<<" "<<sere;
	else cout<<sere<<" "<<dema;
}


#include<iostream>
using namespace std;
void main()
{
	int n , loop , cards[1005] , z , sere=0 , dema=0 , x ,  y ;
	cin>>n;
	for(loop=0;loop<n;loop++)
		cin>>cards[loop];
	for(loop=0;loop<n-1;loop++)
	{
		if(cards[loop]>cards[loop+1])
		{
			z=cards[loop];
			cards[loop]=cards[loop+1];
			cards[loop+1]=z;
		}
	}
	for(x=1;x<n;x=x+2)
	{
		sere=cards[x]+sere;
	}
	for(y=0;y<n;y=y+2)
	{
		dema=cards[y]+dema;
	}
	if(dema>sere)
		cout<<dema<<" "<<sere;
	else cout<<sere<<" "<<dema;
}


#include<iostream>
using namespace std;
void main()
{
	int n , loop , cards[105] , z , sere=0 , dema=0 , x ,  y ;
	cin>>n;
	for(loop=0;loop<n;loop++)
		cin>>cards[loop];
	for(loop=0;loop<n-1;loop++)
	{
		if(cards[loop]>cards[loop+1])
		{
			z=cards[loop];
			cards[loop]=cards[loop+1];
			cards[loop+1]=z;
		}
	}
	for(x=1;x<n;x=x+2)
	{
		sere=cards[x]+sere;
	}
	for(y=0;y<n;y=y+2)
	{
		dema=cards[y]+dema;
	}
	if(dema>sere)
		cout<<dema<<" "<<sere;
	else cout<<sere<<" "<<dema;
}


#include<iostream>
using namespace std;
void main()
{
	int n , loop , cards[1005] , l=0 , r , sere=0 , dema=0 , sera=0 , deja=0;
	cin>>n;
	r=n-1;
	for(loop=0;loop<n;loop++)
	{
		cin>>cards[loop];

	}
	while(r>=0)
	{
		if(cards[r]>cards[l])
			sere=cards[r];
		else sere=cards[l];
		sera=sere+sera;
		if(cards[r]==cards[l])
			break;
		if(cards[l]==sere || cards[l]==dema)
			l++;
		if(cards[r]==sere || cards[r]==dema)
			r--;
		if(cards[r]>cards[l])
			dema=cards[r];
		else dema=cards[l];
		deja=dema+deja;
		if(cards[r]==cards[l])
			break;
		if(cards[l]==sere || cards[l]==dema)
			l++;
		if(cards[r]==sere || cards[r]==dema)
			r--;
		}
	cout<<sera<<" "<<deja;
}


#include<iostream>
#include <vector>

using namespace std;
#define fast_scan() (ios_base::sync_with_stdio(false),cin.tie(NULL))
typedef vector<int> vi;
int main()
{
	fast_scan();
	int n, ans[2] = {0};
	bool turn = false;
	cin >> n;
	vi nums(n);
	repi(n) cin >> nums[i];
	int l = 0, r = n - 1;
	while (l <= r) { ans[turn] += max(nums[l], nums[r]); if (nums[l] > nums[r]) l++; else r--; turn = !turn; }
	cout << ans[0] << " " << ans[1];
	getchar();
	getchar();
	return 0;
}


#include<iostream>
#include <vector>

using namespace std;
#define repi(n)  for(int i = 0; i < (int)(n); ++i)
#define fast_scan() (ios_base::sync_with_stdio(false),cin.tie(NULL))
typedef vector<int> vi;
int main()
{
	fast_scan();
	int n, ans[2] = {0};
	bool turn = false;
	cin >> n;
	vi nums(n);
	repi(n) cin >> nums[i];
	int l = 0, r = n - 1;
	while (l <= r) { ans[turn] += max(nums[l], nums[r]); if (nums[l] > nums[r]) l++; else r--; turn = !turn; }
	cout << ans[0] << " " << ans[1];
	getchar();
	getchar();
	return 0;
}


#include<iostream>
#include <vector>

using namespace std;
#define repi(n)  for(int i = 0; i < (int)(n); ++i)
#define fast_scan() (ios_base::sync_with_stdio(false),cin.tie(NULL))
typedef vector<int> vi;
int main()
{
	fast_scan();
	int n, ans[2] = {0};
	bool turn = false;
	cin >> n;
	vi nums(n);
	repi(n) cin >> nums[i];
	int l = 0, r = n - 1;
	while (l <= r) { ans[turn] += max(nums[l], nums[r]); if (nums[l] > nums[r]) l++; else r--; turn = !turn; }
	cout << ans[0] << " " << ans[1];
	return 0;
}


#include "iostream"
#include "math.h"
#include "string"
#include "vector"
using namespace std;

void swap(int x[], int i, int j)
{

	x[i] = x[j] + x[i];
	x[j] = x[i] - x[j];
	x[i] = x[i] - x[j];
}
int main()
{

	int serena =0 ,dima=0, i=0 , n ;
	cin >> n;
	vector <int> x(n);
	vector <int> y;

for (i = 0;  i < n; i++)
	{
		cin >> x[i];
	}
for (i = 1; i < n; i++)
{
	if (x[i] < x[x.size() - 1])
	{
		y.push_back(x[x.size() - 1]);
		x.pop_back();
	}
	else { y.push_back(x[x.begin()]);
		   x.erase(x.begin());
		}

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

	if (i % 2 == 0) serena += y[i];
	else dima += y[i];
}
    cout << serena<<dima ;

	return 0;
}


#include "iostream"
#include "math.h"
#include "string"
#include "vector"
using namespace std;

void swap(int x[], int i, int j)
{

	x[i] = x[j] + x[i];
	x[j] = x[i] - x[j];
	x[i] = x[i] - x[j];
}
int main()
{

	int serena =0 ,dima=0, i=0 , n ;
	cin >> n;
	vector <int> x(n);
	vector <int> y;

for (i = 0;  i < n; i++)
	{
		cin >> x[i];
	}
for (i = 1; i <= n; i++)
{
	if (x[0] < x[x.size() - 1])
	{
		y.push_back(x[x.size() - 1]);
		x.pop_back();
	}
	else { y.push_back(x[0]);
		   x.erase(x.begin());
		}

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

	if (i % 2 == 0) serena += y[i-1];
	else dima += y[i-1];
}
    cout << serena<<dima ;

	return 0;
}


#include "iostream"
#include "math.h"
#include "string"
#include "vector"
using namespace std;

void swap(int x[], int i, int j)
{

	x[i] = x[j] + x[i];
	x[j] = x[i] - x[j];
	x[i] = x[i] - x[j];
}
int main()
{

	int serena =0 ,dima=0, i=0 , n ;
	cin >> n;
	vector <int> x(n);
	vector <int> y;

for (i = 0;  i < n; i++)
	{
		cin >> x[i];
	}
for (i = 1; i <= n; i++)
{
	if (x[0] < x[x.size() - 1])
	{
		y.push_back(x[x.size() - 1]);
		x.pop_back();
	}
	else { y.push_back(x[0]);
		   x.erase(x.begin());
		}

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

	if (i % 2 == 0) serena += y[i-1];
	else dima += y[i-1];
}
    cout <<dima<<" "<<serena ;

	return 0;
}


#include<iostream>
using namespace std;
int main()
{int n,i,s,d;
int X[100]={ };
cin>>n;
for(i=1;i<=n;i++)
	cin>>X[i];
i=1;
for(int j=1;j<=n;j++)
	if(j%2==1)
	{if(X[i]>X[n])
	{s+=X[i];
      i++;}
	else {s+=X[n];
	n--;}

	}
	else{ if(X[i]>X[n])
	{d+=X[i];
i++;}
	else {d+=X[n];
	n--;}
	}
	cout<<s<<d;
return 0;
}


#include<iostream>
using namespace std;
int main()
{int n,i,s,d;
int X[1000]={ };
cin>>n;
for(i=1;i<=n;i++)
	cin>>X[i];
i=1;
s=0;
d=0;
int v=n;
for(int j=1;j<=n;j++)
	if(j%2==1)
	{if(X[i]>=X[v])
	{s+=X[i];
      i++;}
	else {s+=X[v];
	v--;}
	}
	else{ if(X[i]>=X[v])
	{d+=X[i];
    i++;}
	else {d+=X[v];
	v--;}
	}
	cout<<s<<' '<<d;
return 0;
}


#include<iostream>
using namespace std;
int main()
{int n,i,s,d;
int X[100]={ };
cin>>n;
for(i=1;i<=n;i++)
	cin>>X[i];
i=1;
int v=n;
for(int j=1;j<=n;j++)
	if(j%2==1)
	{if(X[i]>=X[v])
	{s+=X[i];
      i++;}
	else {s+=X[v];
	v--;}
	}
	else{ if(X[i]>=X[v])
	{d+=X[i];
    i++;}
	else {d+=X[v];
	v--;}
	}
	cout<<s<<d;
return 0;
}


#include <iostream>
using namespace std;

int main()
{
    int n, start, end, flag = 1, sSum = 0, dSum = 0;
    cin>>n;
    int *arr = new int[n];
    for(int i = 0; i < n; i++)
    {
        cin>>arr[i];
    }

    start = 0;
    end = n-1;
    for(int i = 0; i < n; i++)
    {
        if(flag)
        {
            if(arr[start]> arr[end])
            {
                sSum += arr[start];
                start++;
            }
            else
            {
                sSum += arr[end];
                end--;
            }
            flag = 0;
        }
        else
        {
            if(arr[start] > arr[end])
            {
                dSum += arr[start];
                start++;
            }
            else
            {
                dSum += arr[end];
                end--;
            }
            flag = 1;
        }

    }

    cout<< sSum <<" "<<dSum<<endl;

    return 0;
}


#include <iostream>

using namespace std;
void swap(int *xp, int *yp);
void bubbleSort(int *arr, int n);
int main()
{
    int max, n, flag = 1, sSum = 0, dSum = 0;
    cin>>n;
    int *arr = new int[n];
    for(int i = 0; i < n; i++)
    {
        cin>>arr[i];
    }

    bubbleSort(arr, n);

    for(int i = n-1; i >= 0; i--)
    {
        if(flag)
        {
            sSum += arr[i];
            flag = 0;
        }
        else
        {
            dSum += arr[i];
            flag = 1;
        }
    }

    cout<< sSum <<" "<<dSum<<endl;

    return 0;
}

void swap(int *xp, int *yp)
{
    int temp = *xp;
    *xp = *yp;
    *yp = temp;
}

// A function to implement bubble sort
void bubbleSort(int *arr, int n)
{
    int i, j;
    for (i = 0; i < n-1; i++)

    // Last i elements are already in place
    for (j = 0; j < n-i-1; j++)
        if (arr[j] > arr[j+1])
            swap(&arr[j], &arr[j+1]);
}


#include <iostream>
#include<algorithm>

using namespace std;

int main()
{
    int card;
    int *num;
    cin>>card;
    num= new int [card];
    for(int i=0; i<card; i++)
    {
        cin>>num[i];
    }

    int serja=0;
    int dima=0;
    int sum=0;
    int i=0;
    int j =card-1;

    while(i<=j)
       {

        if(num[i]>=num[j])
    {
    serja+=num[i];
                   ++i;}

        else
        {
            serja+=num[j];
                   --j;
            }
            if (i>j)
                break;

            if(num[i]>=num[j])
                {dima+=num[i];
            i++;}
            else
                {dima+=num[j];
            --j;}}

cout<<serja << " "<<dima<<endl;

            return 0;
        }


#include <iostream>
#include<algorithm>

using namespace std;

int main()
{
    int card;
    int *num;
    cin>>card;
    num= new int [card];
    for(int i=0; i<card; i++)
    {
        cin>>num[i];
    }

    int serja=0;
    int dima=0;
    int sum=0;
    int i=0;
    int j =card-1;

    while(i<=j)
       {

        if(num[i]>num[j])
    {
    serja+=num[i];
                   ++i;}

        else
        {
            serja+=num[j];
                   --j;
            }
            if ((j<0)||(i>card))
                break;

            if(num[i]>num[j])
                {dima+=num[i];
            i++;}
            else
                {dima+=num[j];
            --j;}}

cout<<serja << " "<<dima<<endl;

            return 0;
        }


#include <iostream>
#include<algorithm>

using namespace std;

int main()
{
    int card;
    int *num;
    cin>>card;
    num= new int [card];
    for(int i=0;i<card;i++)
    {
        cin>>num[i];
    }
    sort(num,num+card);
    int serja=0;
    int dima=0;
    int sum=0;
    for(int i=0;i<card;i++)
    {
        sum+=num[i];
    }
    for (int i=card-1;i>=0;i--)
        {serja+=num[i];
        dima+=num[i-1];
        i--;}
        cout<<serja<<" "<<dima<<endl;

    return 0;
}


#include <iostream>
#include<algorithm>

using namespace std;

int main()
{
    int card;
    int *num;
    cin>>card;
    num= new int [card];
    for(int i=0;i<card;i++)
    {
        cin>>num[i];
    }
    sort(num,num+card);
    int serja=0;
    int dima=0;
    int sum=0;
    for(int i=0;i<card;i++)
    {
        sum+=num[i];
    }
    while(sum!=0)
    {
        serja+=num[card-1];
        dima+=num[card-2];
        card=card-2;
        sum=sum-(serja+dima);}

    cout<<serja<<" "<<dima<<endl;
    return 0;
}


#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main()
{
      int n; cin>>n; int s=0,d=0;
	  int *arr=new int[n];
	  for(int i=0;i<n;i++)
	      cin >>arr[i];
	  sort(arr, arr+n);
	  for(int i=n-1;i>=0; i-=2){
	        s+=arr[i];
			if(i-1>=0)
			d+=arr[i-1];
	  }

	  cout<<s<<" "<<d;

}


#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main()
{
      int n; cin>>n; int s=0,d=0; int end=n-1, i=0 ,j=0;
	  int *arr=new int[n];
	  for(int i=0;i<n;i++)
	      cin >>arr[i];

    while(i < end+1){
	     j++;
		if(arr[i] > arr[end]){
		       if(j%2!=0)
				   s+=arr[i];
			   else
				   d+=arr[i];
			   i++;
		      }
		else{
		   if(j%2!=0)
				   s+=arr[end];
			   else
				   d+=arr[end];
			   end--;

		}
	}
	cout<<s<<"  "<<d;
}


#include<iostream>
using namespace std;
#include<string.h>
int main(){
int num,card[10000],str=0,end;
long long int count1=0,count2=0;
cin>>num;
end=num-1;
for(int i=0;i<num;i++)
    cin>>card[i];
for(int j=0;j<num;j++){
    if(j%2==0){
    if(card[str]>=card[end])
    count1+=card[str++];
    else
    count1+=card[end--];
    }
    if(j%2==1){
    if(card[str]>=card[end])
        count2+=card[str++];
    else
    count2+=card[end--];
    }
}
cout<<count1<<" "<<count2;

    return 0;
}


#include<iostream>
using namespace std;
#include<string.h>
int main(){
int num,card[100],count1=0,count2=0,str=0,end;
cin>>num;
end=num-1;
for(int i=0;i<num;i++)
    cin>>card[i];
for(int j=0;j<num;j++){
    cout<<str<<end<<endl;
    if(j%2==0){
    if(card[str]>=card[end])
    count1+=card[str++];
    else
    count1+=card[end--];
    }
    if(j%2==1){
    if(card[str]>=card[end])
        count2+=card[str++];
    else
    count2+=card[end--];
    }
}
cout<<count1<<" "<<count2;

    return 0;
}


#include<iostream>
using namespace std;
#include<string.h>
int main(){
int num,card[100],count1=0,count2=0,str=0,end;
cin>>num;
end=num-1;
for(int i=0;i<num;i++)
    cin>>card[i];
for(int j=0;j<num;j++){
    if(j%2==0){
    if(card[str]>=card[end])
    count1+=card[str++];
    else
    count1+=card[end--];
    }
    if(j%2==1){
    if(card[str]>=card[end])
        count2+=card[str++];
    else
    count2+=card[end--];
    }
}
cout<<count1<<" "<<count2;

    return 0;
}


//#include<iostream>
#include<vector>
#include<iomanip>
#include <algorithm>
using namespace std;
#include <bits/stdc++.h>

int main(){
	int n, temp,first = 0, second=0;
	vector<int> vec;
	cin >> n;

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

		cin >> temp;
		vec.push_back(temp);

	}

	sort(vec.begin(), vec.end());
	int x = 1;
	int size = vec.size();
	for (int j = size-1; j >= 0; j--)
	{
		if (x % 2 != 0)
			first += vec[j ];
		else
			second += vec[j];

		//vec.pop_back();
		x++;
	}

	cout << first << " " << second;

	return 0;
}


#include<iostream>
#include<vector>
#include<iomanip>
#include <algorithm>
using namespace std;
//#include <bits/stdc++.h>
int main(){
	int n, temp,first = 0, second=0;
	vector<int> vec;
	cin >> n;

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

		cin >> temp;
		vec.push_back(temp);

	}

	sort(vec.begin(), vec.end());
	int x = 1;
	int size = vec.size();
	for (int j = size-1; j >= 0; j--)
	{
		if (x % 2 != 0)
			first += vec[j ];
		else
			second += vec[j];

		//vec.pop_back();
		x++;
	}

	cout << first << " " << second;

	return 0;
}


#include<iostream>
#include<vector>
#include<iomanip>
#include <algorithm>
using namespace std;
//#include <bits/stdc++.h>

int main(){
	int n, temp,first = 0, second=0,left = 0,right;
	vector<int> vec;
	cin >> n;

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

		cin >> temp;
		vec.push_back(temp);

	}

	int x = 1;
	int size = vec.size();
	right = size - 1;
	for (int j = size-1; j >= 0; j--)
	{
		if (x % 2 != 0)
			if (vec[left] > vec[right])
			{
				first += vec[left]; left++;
			}
			else
			{
				first += vec[right]; right--;
			}
		else
			if (vec[left] > vec[right])
			{
				second += vec[left]; left++;
			}
			else
			{
				second += vec[right]; right--;
			}
		x++;
	}

	cout << first << " " << second;

	return 0;
}


#include<iostream>
using namespace std;
int main()
{
	int n,k;
	int arr[1000];
	int re[1000];
	int s = 0;
	int d = 0;
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> arr[i];
	}
	k = n;
	for (int i = 0; i < k; i++)
	{
		if (arr[0]>arr[n - 1])
		{
			re[i] = arr[0];
			arr[0] = arr[n - 1];
			n--;
		}
		else
		{
			re[i] = arr[n - 1];
			n--;
		}
	}
	for (int i = 0; i < k; i+=2)
	{
		s += re[i];
		if (i < k-1)
		{
			d += re[i + 1];
		}

	}
	cout << s <<" "<< d;
}


#include<iostream>
using namespace std;
int main()
{
	int n,k;
	int arr[1000];
	int re[1000];
	int s = 0;
	int d = 0;
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> arr[i];
	}
	k = n;
	for (int i = 0; i < k; i++)
	{
		if (arr[0]>arr[n - 1])
		{
			re[i] = arr[0];
			for (int j = 0; j < n; j++)
			{
				arr[j] = arr[j + 1];
			}
			n--;
		}
		else
		{
			re[i] = arr[n - 1];
			n--;
		}
	}
	for (int i = 0; i < k; i+=2)
	{
		s += re[i];
		if (i < k-1)
		{
			d += re[i + 1];
		}

	}
	cout << s <<" "<< d;
}


#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
bool cmd(int a,int b)
{
	if(a>=b)return 1;
	else return 0;

}
int main(){

	int n;
	cin>>n;
	vector<int>sor;
	for(int i=0;i<n;i++)
	{
		int temp;
		cin>>temp;
		sor.push_back(temp);

	}
	sort(sor.begin(),sor.end(),cmd);
	int mi=0;
	int max=0;
	for(int i=0;i<n;i++)
	{
		if(i%2==0)
		mi+=sor[i];
		else
			max+=sor[i];

	}
	//if(mi<max)
		//swap(mi,max);
	cout<<mi<<" "<<max;
}


#include<iostream>
#include<vector>
//#include<algorithm>
using namespace std;
int maxim(int a,int b){
if(a>b)return a;
else return b;}
bool cmd(int a,int b)
{
	if(a>=b)return 1;
	else return 0;

}
int main(){

	int n;
	cin>>n;
	vector<int>sor;
	for(int i=0;i<n;i++)
	{
		int temp;
		cin>>temp;
		sor.push_back(temp);

	}
	//sort(sor.begin(),sor.end(),cmd);
	int mi=0;
	int max=0;
	for(int i=0, j=n-1,k=0;i<n&&j>=i;k++)
	{
		int ch;
		if(sor[i]>sor[j]){

			ch=sor[i];
		i++;

		}
		else{
			ch=sor[j];
			j--;

		}
		if(k%2==0)
		mi+=ch;
		else
			max+=ch;

	}
	//if(mi<max)
		//swap(mi,max);
	cout<<mi<<" "<<max;
}


#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){

	int n;
	cin>>n;
	vector<int>sor;
	for(int i=0;i<n;i++)
	{
		int temp;
		cin>>temp;
		sor.push_back(temp);

	}
	sort(sor.begin(),sor.end());
	int mi=0;
	int max=0;
	for(int i=0;i<n;i++)
	{
		if(i%2==0)
		mi+=sor[i];
		else
			max+=sor[i];

	}
	if(mi<max)
		swap(mi,max);
	cout<<mi<<" "<<max;
}


#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
	int S=0,D=0,n,a,sum=0;
	vector<int>v;
	cin>>n;
	while(n--)
	{
		cin>>a;
		v.push_back(a);
	}
	sort(v.begin(),v.end());
	for (int i=(v.size())-1;i>=0;i=i-2)
	{
		S=S+v[i];
		if(i!=0)
			D=D+v[i-1];
	}
	cout<<S<<" " <<D<<endl;
	return 0;
}


#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
	int s=0,d=0,n,a,sum=0;
	vector<int>v;
	cin>>n;
	int j=n;
	while(n--)
	{
		cin>>a;
		v.push_back(a);
	}
	int i=0;
	int k=j-1;
	while (true)
	{
		if(v[i]>v[k])
		{
			s=s+v[i];
			i++;
			if(i==k)
			{ d=d+v[i]; break;}
			else if(v[i]>v[k])
			{ d=d+v[i]; i++;}
			else
			{ d=d+v[k]; k--;}
		}

		else if(v[i]<v[k])
		{
			s=s+v[k];
			k--;
			if(k==i)
			{d=d+v[i]; break;}
			else if(v[k]>v[i])
			{d=d+v[k]; k--;}
			else
			{d=d+v[i]; i++;}
		}
		else
		{s=s+v[i]; break;}
	}
	cout<<s<<" "<<d<<endl;
	return 0;
}


#include<iostream>
using namespace std;
int main()
{
	int size, *x, p1=0, p2=0;
	bool choice =true;
	cin >> size;
	int count1 = 0, count2 = size;
	x = new int[size];
	for (int i = 0; i < size; i++)
	{
		cin >> *(x + i);
	}
	int i = 0, j = size - 1;
	for (int m = 1; m < size+1; m++)
	{
		if (x[i] > x[j])
		{
			if (m % 2 == 0)
				p2 += x[i];
			else
				p1 += x[i];
			i++;
		}
		else
		{
			if (m % 2 == 0)
				p2 += x[j];
			else
				p1 += x[j];
			j--;
		}
	}
	cout << p1 << " " << p2 << endl;
	return 0;
}


#include<iostream>
using namespace std;
int main()
{
	int size, *x, p1=0, p2=0;
	bool choice =true;
	cin >> size;
	x = new int[size];
	for (int i = 0; i < size; i++)
	{
		cin >> *(x + i);
	}
	for (int i = 0; i < size; i++)
	{
		for (int j = 0; j < size-1; j++)
		{
			if (x[j] < x[j + 1])
			{
				x[j] = x[j + 1] + x[j];
				x[j + 1] = x[j] - x[j + 1];
				x[j] = x[j] - x[j + 1];
			}
		}
	}
	for (int i = 0; i < size; i++)
	{
		if (choice == true)
		{
			p1 += x[i];
			choice = false;
		}
		else
		{
			p2 += x[i];
			choice = true;
		}
	}
	cout << p1 << " " << p2 << endl;
	return 0;
}


#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int main()
{
	int numberofin,sum1=0,sum2=0,start1=0;
	bool flag = 0;

	cin >> numberofin;
	int *input = new int[numberofin];
	for (int i = 0; i < numberofin; i++)
	{
		cin >> input[i];
	}
	start1 = 0;
	//sort(input, input + numberofin);
	for (int i = numberofin - 1;;)
	{
		if (start1 > i)
			break;
		if (flag == 0)
		{
			if (input[start1] > input[i])
			{
				sum1 += input[start1];
				start1++;
			}
			else
			{
				sum1 += input[i];
				i--;
			}
			flag = 1;
		}
		if (start1 > i)
			break;
		if (flag == 1)
		{
			if (input[start1] > input[i])
			{
				sum2 += input[start1];
				start1++;
			}
			else
			{
				sum2 += input[i];
				i--;
			}
			flag = 0;
		}
	}
	cout << sum1 << " " << sum2 << endl;

	delete input;
	return 0;
	}


#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int main()
{
	int numberofin,sum1=0,sum2=0;
	bool flag = 0;

	cin >> numberofin;
	int *input = new int[numberofin];
	for (int i = 0; i < numberofin; i++)
	{
		cin >> input[i];
	}
	sort(input, input + numberofin);
	for (int i = numberofin-1; i>=0; i--)
	{
		if (flag == 0)
		{
			sum1 += input[i];
			flag = 1;
		}
		else
		{
			sum2 += input[i];
			flag = 0;
		}

	}
	cout << sum1 << " " << sum2 << endl;
	delete input;
	return 0;
	}


#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int main()
{
	int numberofin,sum1=0,sum2=0;

	cin >> numberofin;
	int *input = new int[numberofin];
	for (int i = 0; i < numberofin; i++)
	{
		cin >> input[i];
	}
	sort(input, input + numberofin);
	for (int i = numberofin-1; i>=0; i-=2)
	{
		sum1 += input[i];
		if (input[i - 1] != -1)
			sum2 += input[i - 1];
	}
	cout << sum1 << " " << sum2 << endl;
	delete input;
	return 0;
	}


#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int main()
{
	int numberofin,sum1=0,sum2=0,start1=0;
	bool flag = 0;

	cin >> numberofin;
	int *input = new int[numberofin];
	for (int i = 0; i < numberofin; i++)
	{
		cin >> input[i];
	}
	start1 = 0;
	//sort(input, input + numberofin);
	for (int i = numberofin - 1;;)
	{
		if (start1 > i)
			break;
		if (flag == 0)
		{
			if (input[start1] > input[i])
			{
				sum1 += input[start1];
				start1++;
			}
			else
			{
				sum1 += input[i];
				i--;
			}
			flag = 1;
		}

		if (flag == 1)
		{
			if (input[start1] > input[i])
			{
				sum2 += input[start1];
				start1++;
			}
			else
			{
				sum2 += input[i];
				i--;
			}
			flag = 0;
		}
	}
	cout << sum1 << " " << sum2 << endl;

	delete input;
	return 0;
	}


#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int main()
{
	int numberofin,sum1=0,sum2=0;
	int *input = new int[1000];
	cin >> numberofin;
	for (int i = 0; i < numberofin; i++)
	{
		cin >> input[i];
	}
	sort(input, input + numberofin);
	for (int i = 1000; input[i]!=-1; i-=2)
	{
		sum1 += input[i];
		if (input[i - 1] != -1)
			sum2 += input[i - 1];
	}
	cout << sum1 << " " << sum2 << endl;
	delete input;
	return 0;
	}


#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int main()
{
	int numberofin,sum1=0,sum2=0;
	bool flag = 0;

	cin >> numberofin;
	int *input = new int[numberofin];
	for (int i = 0; i < numberofin; i++)
	{
		cin >> input[i];
	}
	sort(input, input + numberofin);
	for (int i = numberofin-1; i>=0; i--)
	{
		if (flag == 0)
		{
			sum1 += input[i];
			flag = 1;
		}
		else
		{
			sum2 += input[i - 1];
			flag = 0;
		}

	}
	cout << sum1 << " " << sum2 << endl;
	delete input;
	return 0;
	}


#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int main()
{
	int numberofin,sum1=0,sum2=0;
	int input[1000] = { -1 };
	cin >> numberofin;
	for (int i = 0; i < numberofin; i++)
	{
		cin >> input[i];
	}
	sort(input, input + numberofin);
	for (int i = 1000; input[i]!=-1; i-=2)
	{
		sum1 += input[i];
		if (input[i - 1] != -1)
			sum2 += input[i - 1];
	}
	cout << sum1 << " " << sum2 << endl;
	return 0;
	}


#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int main()
{
	int numberofin,sum1=0,sum2=0;
	bool flag = 0;

	cin >> numberofin;
	int *input = new int[numberofin];
	for (int i = 0; i < numberofin; i++)
	{
		cin >> input[i];
	}
	sort(input, input + numberofin);
	for (int i = numberofin-1; i>=0; i--)
	{
		if (flag == 0)
		{
			sum1 += input[i];
			flag = 1;
		}
		else
		{
		sum2 += input[i - 1];
		flag = 0;

	}
	cout << sum1 << " " << sum2 << endl;
	delete input;
	return 0;
	}


#include <deque>
#include <iostream>
using namespace std;

int main(int arg, int args []) {
	int n;
	cin>>n;

	deque <int> deck;
	for(int i=0; i<n; i++){
	    int temp;
	    cin>>temp;
	    deck.push_back(temp);
	}

	int sereja = 0;
	int dima = 0;

	while(!deck.empty()){
	    int front = deck.front();
	    int back = deck.back();

	    if(front>=back){
	        sereja+=front;
	        deck.pop_front();
	        front = deck.front();
	    } else{
	        sereja+=back;
	        deck.pop_back();
	        back = deck.back();
	    }

	    if(deck.empty()){
	        break;
	    }

	    if(front>=back){
	        dima+=front;
	        deck.pop_front();
	        front = deck.front();
	    } else{
	        dima+=back;
	        deck.pop_back();
	        back = deck.back();
	    }

	}

	cout<<sereja<<" "<<dima<<endl;
    return 0;
}


#include <deque>
#include <iostream>
using namespace std;

int main(int arg, int args []) {
	int n;
	cin>>n;

	deque <int> deck;
	for(int i=0; i<n; i++){
	    int temp;
	    cin>>temp;
	    deck.push_back(temp);
	}

	int sereja = 0;
	int dima = 0;

	while(!deck.empty()){
	    int front = deck.front();
	    int back = deck.back();

	    if(front>=back){
	        sereja+=front;
	        deck.pop_front();
	        front = deck.front();
	    } else{
	        sereja+=back;
	        deck.pop_back();
	        back = deck.back();
	    }

	    if(front>=back){
	        dima+=front;
	        deck.pop_front();
	        front = deck.front();
	    } else{
	        dima+=back;
	        deck.pop_back();
	        back = deck.back();
	    }

	}

	cout<<sereja<<" "<<dima<<endl;
    return 0;
}


#include<iostream>
using namespace std;

int main()
{
	int i = 1,j, x[10000], n,s=0,d=0;
	cin >> n;
	x[0] = 0;
	for (j = 1; j <= n; j++) {
		cin >> x[j];
	}
	int m = n;
	for (j = 1; j <= n; j++) {

		while (i <= m) {
			if (j % 2 != 0) {
				if (x[i]>x[m]) {
					s += x[i];
					i++;
					break;
				}
				else {
					s += x[m];
					m--;
					break;
				}
			}
			else {

					if (x[i] > x[m]) {
						d += x[i];
						i++;
						break;
					}
					else {
						d += x[m];
						m--;
						break;
					}

				}

		}
	}
	cout << s << " " << d;
    return 0;
}


#include<iostream>
using namespace std;

int main()
{
	int i = 1,j, x[1000], n,s=0,d=0;
	cin >> n;
	x[0] = 0;
	for (j = 1; j <= n; j++) {
		cin >> x[j];
	}
	int m = n;
	for (j = 1; j <= n; j++) {

		while (i <= m) {
			if (j % 2 != 0) {
				if (x[i]>x[m]) {
					s += x[i];
					i++;
					break;
				}
				else {
					s += x[m];
					m--;
					break;
				}
			}
			else {

					if (x[i] > x[m]) {
						d += x[i];
						i++;
						break;
					}
					else {
						d += x[m];
						m--;
						break;
					}

				}

		}
	}
	cout << s << " " << d;
    return 0;
}


#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
#include <set>
#include <map>
using namespace std;

#define ll long long
const double eps = 1e-9;
const double PI = acos(-1.);
const int INF = 1000000000;

#define fr(i,n) for(int i=0;i<n;i++)
#define fru(i,a,b) for(int i=a;i<=b;i++)
#define frd(i,a,b) for(int i=a;i>=b;i--)

#define N 1010

int n, k, m;
int a[N]={0};
//int dp[][]={0}

void GetData() {
    cin>>n;
    fru(i,1,n)  { cin>>a[i]; }

}

void Run() {
    ll d=0, s=0;

    int i=1, j=n;
     bool r=true;

    while(i<=j) {
        if(r) {
          if(a[i]<=a[j]) { s+=a[j]; j--; }
          else { s+=a[i]; i++; }
         r=false;
        }
        else {
           if(a[i]<=a[j]) { d+=a[j]; j--; }
           else { d+=a[i]; i++; }
          r=true;
        }
        }

cout<<s<<" "<<d;
}

int main() {
    GetData();
    Run();
    return 0;
}


#include "stdafx.h"
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
#include <set>
#include <map>
using namespace std;

#define ll long long
const double eps = 1e-9;
const double PI = acos(-1.);
const int INF = 1000000000;

#define fr(i,n) for(int i=0;i<n;i++)
#define fru(i,a,b) for(int i=a;i<=b;i++)
#define frd(i,a,b) for(int i=a;i>=b;i--)

#define N 1010

int n, k, m;
int a[N]={0};
//int dp[][]={0}

void GetData() {
    cin>>n;
    fru(i,1,n)  { cin>>a[i]; }

}

void Run() {
    ll d=0, s=0;

    sort(a+1,a+n+1);
    reverse(a+1,a+n+1);

    int i=1;
    while(i<=n) {
        s+=a[i];
        d+=a[i+1];
        i+=2;
    }

cout<<s<<" "<<d;
}

int main() {
    GetData();
    Run();
    return 0;
}


#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
#include <set>
#include <map>
using namespace std;

#define ll long long
const double eps = 1e-9;
const double PI = acos(-1.);
const int INF = 1000000000;

#define fr(i,n) for(int i=0;i<n;i++)
#define fru(i,a,b) for(int i=a;i<=b;i++)
#define frd(i,a,b) for(int i=a;i>=b;i--)

#define N 1010

int n, k, m;
int a[N]={0};
//int dp[][]={0}

void GetData() {
    cin>>n;
    fru(i,1,n)  { cin>>a[i]; }

}

void Run() {
    ll d=0, s=0;

    sort(a+1,a+n+1);
    reverse(a+1,a+n+1);

    int i=1;
    while(i<=n) {
        s+=a[i];
        d+=a[i+1];
        i+=2;
    }

cout<<s<<" "<<d;
}

int main() {
    GetData();
    Run();
    return 0;
}


//#pragma comment (linker, "/STACK:65777216")
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <math.h>
#include <vector>
#include <string>
#include <cstring>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <list>
#include <ctime>

using namespace std;

#define pb push_back
#define mp make_pair
#define fs first
#define sc second

typedef long long li;
typedef unsigned long long uli;
typedef long double ld;

const int INF = 1e9;
const int P = 1e9 + 7;
const double PI = 3.14159265358979;
const li lINF = 1e18;
const double eps = 1e-9;

int main ()
{
    //freopen ("problem.in", "r", stdin);

    int n;
    cin >> n;
    int a[1005];
    for (int i = 0 ; i < n ; ++i)
        cin >> a[i];
    int f = 0, s = 0;
    int l = 0, r = n - 1;
    bool x = false;
    while (r > l)
    {
        int cur;
        if (a[l] > a[r])
        {
            cur = a[l];
            ++l;
        }
        else
        {
            cur = a[r];
            --a[r];
        }
        if (x)
            s += cur;
            else
            f += cur;
        x = !x;
    }
    cout << f << ' ' << s;
    return 0;
}


//#pragma comment (linker, "/STACK:65777216")
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <math.h>
#include <vector>
#include <string>
#include <cstring>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <list>
#include <ctime>

using namespace std;

#define pb push_back
#define mp make_pair
#define fs first
#define sc second

typedef long long li;
typedef unsigned long long uli;
typedef long double ld;

const int INF = 1e9;
const int P = 1e9 + 7;
const double PI = 3.14159265358979;
const li lINF = 1e18;
const double eps = 1e-9;

int main ()
{
    //freopen ("problem.in", "r", stdin);

    int n;
    cin >> n;
    int a[1005];
    for (int i = 0 ; i < n ; ++i)
        cin >> a[i];
    int f = 0, s = 0;
    int l = 0, r = n - 1;
    bool x = false;
    while (r > l)
    {
        int cur;
        if (a[l] > a[r])
        {
            cur = a[l];
            ++l;
        }
        else
        {
            cur = a[r];
            --r;
        }
        if (x)
            s += cur;
            else
            f += cur;
        x = !x;
    }
    cout << f << ' ' << s;
    return 0;
}


//#pragma comment (linker, "/STACK:65777216")
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <math.h>
#include <vector>
#include <string>
#include <cstring>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <list>
#include <ctime>

using namespace std;

#define pb push_back
#define mp make_pair
#define fs first
#define sc second

typedef long long li;
typedef unsigned long long uli;
typedef long double ld;

const int INF = 1e9;
const int P = 1e9 + 7;
const double PI = 3.14159265358979;
const li lINF = 1e18;
const double eps = 1e-9;

int main ()
{
    //freopen ("problem.in", "r", stdin);

    int n;
    cin >> n;
    int a[1005];
    for (int i = 0 ; i < n ; ++i)
        cin >> a[i];
    int f = 0, s = 0;
    int l = 0, r = n - 1;
    bool x = false;
    while (r >= l)
    {
        int cur;
        if (a[l] > a[r])
        {
            cur = a[l];
            ++l;
        }
        else
        {
            cur = a[r];
            --r;
        }
        if (x)
            s += cur;
            else
            f += cur;
        x = !x;
    }
    cout << f << ' ' << s;
    return 0;
}


#include <iostream>
#include <cmath>
#include<vector>
#include<deque>
#include<algorithm>
using namespace std;

int main()
{
    int n, k, j = 0, d = 0, m = 0;
    deque<int>deq;
    cin >> n;
    for (int i = 0;i < n;i++)
    {
        cin >> k;
        deq.push_back(k);
    }

    int a = deq.size();
    for (int i = 1;i <= a;i++)
    {
        if (i % 2 != 0)
        {
            if (deq.back() > deq.front())
            {
                j += deq.back();
                deq.pop_back();
            }
            else if(deq.back() < deq.front())
            {
                j += deq.front();
                deq.pop_front();
            }
            else
            {
                j += deq.front();
            }

        }
        else if(i%2==0)
        {
            if (deq.back() > deq.front())
            {
                d += deq.back();
                deq.pop_back();
            }
            else if(deq.back() < deq.front())
            {
                d += deq.front();
                deq.pop_front();
            }
            else
            {
                d += deq.front();
            }
        }
        if (deq.size() == 0)break;

    }

    cout << j << " " << d << "\n";
    return 0;
}


#include <iostream>
#include <cmath>
#include<vector>
#include<stack>
#include<algorithm>
using namespace std;

int main()
{
 int n,k,j=0,d=0;
 vector<int>v;
 stack<int>s;
 cin>>n;
 for(int i=0;i<n;i++)
 {
     cin>>k;
 v.push_back(k);
 }
 sort(v.rbegin(),v.rend());
 for(int i=0;i<v.size();i+=2)
 {
     j+=v[i];

 }

 for(int i=1;i<v.size();i+=2)
 {
     d+=v[i];

 }
 cout<<j<<" "<<d<<"\n";
    return 0;
}


#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
using namespace std;

int main()
{
    int n;
    cin>>n;
    vector<int> arr;
    for(int i=0;i<n;i++)
    {
        int x;
        cin>>x;
        arr.push_back(x);
    }

    int s=0,d=0,f=0,l=n-1;

    for(int i=0;i<n;i++)
    {
        if(arr[l]>arr[f])
        {
            if(i%2==0){
            s+=arr[l]
            }
            else
            {
                d+=arr[l];
            }
            l--;
        }
        else
        {
            if(i%2==0)
            s+=arr[f];

            else
            d+=arr[f];

            f++;
        }
    }
    cout<<s<<" "<<d;
}


#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
using namespace std;

int main()
{
    int n;
    cin>>n;
    vector<int> arr;
    for(int i=0;i<n;i++)
    {
        int x;
        cin>>x;
        arr.push_back(x);
    }

    int s=0,d=0,f=0,l=n-1;

    for(int i=0;i<n;i++)
    {
        if(arr[l]>arr[f])
        {
            if(i%2==0){
            s+=arr[l]
            }
            else
            {
                d+=arr[l];
            }
            l--;
        }
        else
        {
            if(i%2==0)
            s+=arr[f];

            else
            d+=arr[f];

            f++;
        }
    }
    cout<<s<<" "<<d;
    return 0;
}


#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
using namespace std;

int main()
{
    int n;
    cin>>n;
    vector<int> arr;
    for(int i=0;i<n;i++)
    {
        int x;
        cin>>x;
        arr.push_back(x);
    }

    int s=0,d=0,f=0,l=n-1;

    for(int i=0;i<n;i++)
    {
        if(arr[l]>arr[f])
        {
            if(i%2==0){
            s+=arr[l];
            }
            else
            {
                d+=arr[l];
            }
            l--;
        }
        else
        {
            if(i%2==0)
            s+=arr[f];

            else
            d+=arr[f];

            f++;
        }
    }
    cout<<s<<" "<<d;
    return 0;
}


#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	int n;
	while(cin>>n)
	{
		int a[1001];
		for(int i=0;i<n;++i)
		{
			cin>>a[i];
		}
		int sum1=0;
		int sum2=0;
		int r=n-1,l=0;
		int t=1;
		while(r>=l)
		{
			if(a[r]>a[l])
			{
				if(t%2)
					sum1+=a[r];
				else
					sum2+=a[r];
				r--;
			}
			else if(a[r]==a[l])
			{
				if(a[r-1]>a[l+1])
				{
					if(t%2)
						sum1+=a[l];
					else
						sum2+=a[l];
					l++;
				}
				else
				{
					if(t%2)
						sum1+=a[r];
					else
						sum2+=a[r];
					r--;
				}
			}
			else
			{
				if(t%2)
					sum1+=a[l];
				else
					sum2+=a[l];
				l++;
			}
			t++;
		}
		cout<<sum1<<" "<<sum2<<endl;
	}
	return 0;
}


#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	int n;
	while(cin>>n)
	{
		int a[1001];
		int sum=0;
		for(int i=0;i<n;++i)
		{
			cin>>a[i];
			sum+=a[i];
		}
		sort(a,a+n);
		int sum1=0;
		for(int i=n-1;i>=0;i-=2)
		{
			sum1+=a[i];
		}
		cout<<sum1<<" "<<sum-sum1<<endl;
	}
	return 0;
}


#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	int n;
	while(cin>>n)
	{
		int a[1001];
		int sum=0;
		for(int i=0;i<n;++i)
		{
			cin>>a[i];
			sum+=a[i];
		}
		sort(a,a+n);
		int sum1=0;
		for(int i=n-2;i>=0;i-=2)
		{
			sum1+=a[i];
		}
		cout<<sum-sum1<<" "<<um1<<endl;
	}
	return 0;
}


#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<ctype.h>
#include<cstring>
#include<sstream>
using namespace std;
int main()
{
    int n;
    cin >> n;
    int *arr = new int[n];
    int Sereja = 0;
    int Dima = 0;
    for (int i = 0; i < n; i++)
        cin >> arr[i];
    sort(arr, arr + n);
    for (int i = n - 1; i >= 0; i-=2)
        Sereja += arr[i];
    for (int i = n - 2; i >= 0; i -= 2)
        Dima += arr[i];
    cout << Sereja << " " << Dima;
        return 0;
}


/*
* CF.cpp
*
*  Created on: 2 / 2 / 2015
*      Author: Sohieb Mohamed ( Deader )
*/

#include<iostream>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<iterator>
#include<cmath>
#include<string>
#include<sstream>
#include<cstring>
#include<ctype.h>
#include<iomanip>
#include<bitset>
#include<stdio.h>
#include<fstream>

// Suppress some compilation warning messages
#define _CRT_SECURE_NO_DEPRECATE 1
#define _CRT_SECURE_NO_WARNINGS 1
#define all(v) ((v).begin()),((v).end())
#define loop(n) for(int i=0;i<n;i++)
#define lop(i,n) for(int i=1;i<=n;i++)

using namespace std;

typedef string            ss;
typedef long long         ll;
typedef pair <int, int>   ii;
typedef pair<string, int> si;
typedef pair<int, string> is;
typedef vector<ii>       vii;
typedef vector<int>       vi;
typedef vector<vi>       vvi;
typedef vector<string>    vs;
#define INF 1000000000

int n, index,s,d;
vi vec(1001);
int main()
{
    cin >> n;
    loop(n) cin >> vec[i];
    int i = 0, j = n - 1;
    while (i<=j)
            if (vec[i] > vec[j])
                (index++%2==0)?s += vec[i++]:d+=vec[i++];
            else
                (index++%2==0)?s += vec[j--]:d+=vec[j--];
            cout << s << " " << d;
}


#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<ctype.h>
#include<cstring>
#include<sstream>
using namespace std;
int main()
{
    int n;
    cin >> n;
    int *arr = new int[n];
    int Sereja = 0;
    int Dima = 0;
    for (int i = 0; i < n; i++)
        cin >> arr[i];
    for (int i = 0, k = n - 1, j = 0; i < n, k >= 0, j < n; j++)
    {
        if (j % 2 == 0)
        {
            if (arr[i]>arr[k])
            {
                Sereja += arr[i];
                i++;
            }
            else
            {
                Sereja += arr[k];
                k--;
            }
        }
        else
        {
            if (arr[i] > arr[k])
            {
                Dima += arr[i];
                i++;
            }
            else
            {
                Dima += arr[k];
                k--;
            }
        }
    }

    cout << Sereja << " " << Dima;
        return 0;
}


#include<iostream>
using namespace std;
struct card
{
    int po,nee;
};
card all[1050];
int main( )
{
    int n;
    while(cin>>n)
    {
    for(int i=0;i<n;i++)
    {
        all[i].nee=1;
        cin>>all[i].po;
    }
    int sum1=0,sum2=0;
    int m1,m2;
    int t1,t2;
    for(int i=0;i<n;i++)
    {
        m1=0,m2=0;
        t1=t2=1020;
        for(int j=0;j<n;j++)
        {
            if(all[j].nee==1)
            {
                m1=all[j].po;
                t1=j;
                all[j].nee=0;
                break;
            }
        }
        for(int j=n-1;j>=0;j--)
        {
            if(all[j].nee==1)
            {
                m2=all[j].po;
                t2=j;
                all[j].nee=0;
                break;
            }
        }
        int max=0;
        if(m1>=m2)
        {
            max=m1;
            all[t2].nee=1;
        }
        else
        {
            max=m2;
            all[t1].nee=1;
        }
        if(max>0)
        {
        if(i%2==0) sum1+=max;
        else sum2+=max;
        }
    }
    cout<<sum1<<" "<<sum2<<endl;
    }
    return 0;
}


#include<iostream>
using namespace std;
struct card
{
    int po,nee;
};
card all[1050];
int main( )
{
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        all[i].nee=1;
        cin>>all[i].po;
    }
    int sum1=0,sum2=0;
    int m1,m2;
    int t1,t2;
    for(int i=0;i<n;i++)
    {
        m1=0,m2=0;
        t1=t2=1020;
        for(int j=0;j<(n/2);j++)
        {
            if(all[j].nee==1)
            {
                m1=all[j].po;
                t1=j;
                all[j].nee=0;
                break;
            }
        }
        for(int j=n-1;j>=(n/2);j--)
        {
            if(all[j].nee==1)
            {
                m2=all[j].po;
                t2=j;
                all[j].nee=0;
                break;
            }
        }
        int max=0;
        if(m1>=m2)
        {
            max=m1;
            all[t2].nee=1;
        }
        else
        {
            max=m2;
            all[t1].nee=1;
        }
        if(max>0)
        {
        if(i%2==0) sum1+=max;
        else sum2+=max;
        }
    }
    cout<<sum1<<" "<<sum2<<endl;
    return 0;
}


#include<iostream>
using namespace std;
struct card
{
    int po,nee;
};
card all[1050];
int main( )
{
    int n;
    while(cin>>n)
    {
    for(int i=0;i<n;i++)
    {
        all[i].nee=1;
        cin>>all[i].po;
    }
    int sum1=0,sum2=0;
    int m1,m2;
    int t1,t2;
    for(int i=0;i<n;i++)
    {
        m1=0,m2=0;
        t1=t2=1020;
        for(int j=0;j<(n/2);j++)
        {
            if(all[j].nee==1)
            {
                m1=all[j].po;
                t1=j;
                all[j].nee=0;
                break;
            }
        }
        for(int j=n-1;j>=(n/2);j--)
        {
            if(all[j].nee==1)
            {
                m2=all[j].po;
                t2=j;
                all[j].nee=0;
                break;
            }
        }
        int max=0;
        if(m1>=m2)
        {
            max=m1;
            all[t2].nee=1;
        }
        else
        {
            max=m2;
            all[t1].nee=1;
        }
        if(max>0)
        {
        if(i%2==0) sum1+=max;
        else sum2+=max;
        }
    }
    cout<<sum1<<" "<<sum2<<endl;
    }
    return 0;
}


#include <iostream>
#include <algorithm>
#include <functional>
#include <numeric>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>
#include <cassert>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <bitset>
#include <sstream>

using namespace std;

#ifndef _DEPRECATION_DISABLE   /* One time only */
#define _DEPRECATION_DISABLE   /* Disable deprecation true */
#if (_MSC_VER >= 1400)         /* Check version */
#pragma warning(disable: 4996) /* Disable deprecation */
#endif /* #if defined(NMEA_WIN) && (_MSC_VER >= 1400) */
#endif /* #ifndef _DEPRECATION_DISABLE */

int main()
{
	int ls = 0, ld = 0,z=0;
	int m[1111];
	int n;
	cin >> n;

	for (int j = 0; j < n; j++)cin >> m[j];

	int t = 2,q=0,l=0;
	bool s = true;

	int left = 0, right = 0;

	while (s){

		for (int j = left, k = n - 1 - right; (left + right) < n; j++, k--)
	{

		if (m[j] > m[k] && t % 2 == 0)
		{

			ls += m[j];
			m[j] = 0;
			left++;
			break;

		}
		if (m[j] < m[k] && t % 2 == 0)
		{

			ls += m[k];
			m[k]=0;
			right++;
			break;
		}
		if (m[j] > m[k] && t % 2 != 0)
		{

			ld += m[j];
			m[j] = 0;
			left++;
			break;

		}
		if (m[j] < m[k] && t % 2 != 0)
		{

			ld += m[k];
			m[k] = 0;
			right++;
			break;
		}

	}
	for (int t = 0; t < n; t++)
	{
		if (m[t] == 0)z++;
	}
	if (z == n-1)
	{
		z = 0;
		t++;
		s = false;

	}
	else
	{

		z = 0;
		t++;

	}

	}

	if (t % 2 == 0)
	{

		for (int t = 0; t < n; t++)
		{
			if (m[t] != 0)
			{
                cout << (ls + m[t]) << " " << ld;
				return 0;

			}

		}

	}
	else
	{
			for (int t = 0; t < n; t++)
			{
				if (m[t] != 0)
				{
					cout << ls << " " << (ld + m[t]);
					return 0;

				}

			}

	}
return 0;
}


#include <iostream>
#include <algorithm>
#include <functional>
#include <numeric>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>
#include <cassert>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <bitset>
#include <sstream>

using namespace std;

#ifndef _DEPRECATION_DISABLE   /* One time only */
#define _DEPRECATION_DISABLE   /* Disable deprecation true */
#if (_MSC_VER >= 1400)         /* Check version */
#pragma warning(disable: 4996) /* Disable deprecation */
#endif /* #if defined(NMEA_WIN) && (_MSC_VER >= 1400) */
#endif /* #ifndef _DEPRECATION_DISABLE */

int main()
{
	int ls = 0, ld = 0,z=0;
	int m[1111];
	int n;
	cin >> n;

	for (int j = 0; j < n; j++)cin >> m[j];

	int t = 2,q=0,l=0;
	bool s = true;

	int left = 0, right = 0;

	while (s){

		for (int j = left, k = n - 1 - right; j < k; j++, k--)
	{

		if (m[j] > m[k] && t % 2 == 0)
		{

			ls += m[j];
			m[j] = 0;
			left++;
			break;

		}
		if (m[j] < m[k] && t % 2 == 0)
		{

			ls += m[k];
			m[k]=0;
			right++;
			break;
		}
		if (m[j] > m[k] && t % 2 != 0)
		{

			ld += m[j];
			m[j] = 0;
			left++;
			break;

		}
		if (m[j] < m[k] && t % 2 != 0)
		{

			ld += m[k];
			m[k] = 0;
			right++;
			break;
		}

	}
	for (int t = 0; t < n; t++)
	{
		if (m[t] == 0)z++;
	}
	if (z == n-1)
	{
		z = 0;
		t++;
		s = false;

	}
	else
	{

		z = 0;
		t++;

	}

	}

	if (t % 2 == 0)
	{

		for (int t = 0; t < n; t++)
		{
			if (m[t] != 0)
			{
                cout << (ls + m[t]) << " " << ld;
				return 0;

			}

		}

	}
	else
	{
			for (int t = 0; t < n; t++)
			{
				if (m[t] != 0)
				{
					cout << ls << " " << (ld + m[t]);
					return 0;

				}

			}

	}
return 0;
}


#include <iostream>
#include <algorithm>
#include <functional>
#include <numeric>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>
#include <cassert>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <bitset>
#include <sstream>

using namespace std;

#ifndef _DEPRECATION_DISABLE   /* One time only */
#define _DEPRECATION_DISABLE   /* Disable deprecation true */
#if (_MSC_VER >= 1400)         /* Check version */
#pragma warning(disable: 4996) /* Disable deprecation */
#endif /* #if defined(NMEA_WIN) && (_MSC_VER >= 1400) */
#endif /* #ifndef _DEPRECATION_DISABLE */

int main()
{
	int ls = 0, ld = 0,z=0;
	int m[1111];
	int n;
	cin >> n;

	for (int j1 = 0; j1 < n; j1++)cin >> m[j1];

	int t = 2,q=0,l=0,d=0;
	bool s = true;

	int left = 0, right = n-1;

	while(d < n-1)
	{

		if (m[left] > m[right] && t % 2 == 0)
		{

			ls += m[left];
			m[left] = 0;
			left++;
			t++;
			continue;

		}
		if (m[left] < m[right] && t % 2 == 0)
		{

			ls += m[right];
			m[right] = 0;
			right--;

			t++;
			continue;
		}
		if (m[left] > m[right] && t % 2 != 0)
		{

			ld += m[left];
			m[left] = 0;
			left++;
			t++;
			continue;

		}
		if (m[left] < m[right] && t % 2 != 0)
		{

			ld += m[right];
			m[right] = 0;
			right--;
			t++;
			continue;
		}
		d++;

	}

	if (t % 2 == 0)
	{

		for (int t1 = 0; t1 < n; t1++)
		{
			if (m[t1] != 0)
			{
                cout << (ls + m[t1]) << " " << ld;
				return 0;

			}

		}

	}
	else
	{
			for (int t2 = 0; t2 < n; t2++)
			{
				if (m[t2] != 0)
				{
					cout << ls << " " << (ld + m[t2]);
					return 0;

				}

			}

	}
return 0;
}


#include <iostream>
#include <algorithm>
#include <functional>
#include <numeric>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>
#include <cassert>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <bitset>
#include <sstream>

using namespace std;

#ifndef _DEPRECATION_DISABLE   /* One time only */
#define _DEPRECATION_DISABLE   /* Disable deprecation true */
#if (_MSC_VER >= 1400)         /* Check version */
#pragma warning(disable: 4996) /* Disable deprecation */
#endif /* #if defined(NMEA_WIN) && (_MSC_VER >= 1400) */
#endif /* #ifndef _DEPRECATION_DISABLE */

int main()
{
	int ls = 0, ld = 0,z=0;
	int m[1111];
	int n;
	cin >> n;

	for (int j = 0; j < n; j++)cin >> m[j];

	int t = 2,q=0,l=0;
	bool s = true;

	int left = 0, right = 0;

	while (s){

		for (int j = left, k = n - 1 - right; (left + right) < n; j++, k--)
	{

		if (m[j] > m[k] && t % 2 == 0)
		{

			ls += m[j];
			m[j] = 0;
			left++;
			break;

		}
		if (m[j] < m[k] && t % 2 == 0)
		{

			ls += m[k];
			m[k]=0;
			right++;
			break;
		}
		if (m[j] > m[k] && t % 2 != 0)
		{

			ld += m[j];
			m[j] = 0;
			left++;
			break;

		}
		if (m[j] < m[k] && t % 2 != 0)
		{

			ld += m[k];
			m[k] = 0;
			right++;
			break;
		}

	}
	for (int t = 0; t < n; t++)
	{
		if (m[t] == 0)z++;
	}
	if (z == n-1)
	{
		z = 0;
		t++;
		s = false;

	}
	else
	{

		z = 0;
		t++;

	}

	}

	if (t % 2 == 0)
	{

		for (int t1 = 0; t1 < n; t1++)
		{
			if (m[t1] != 0)
			{
                cout << (ls + m[t1]) << " " << ld;
				return 0;

			}

		}

	}
	else
	{
			for (int t2 = 0; t2 < n; t2++)
			{
				if (m[t2] != 0)
				{
					cout << ls << " " << (ld + m[t2]);
					return 0;

				}

			}

	}
return 0;
}


#include <iostream>
#include <algorithm>
#include <functional>
#include <numeric>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>
#include <cassert>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <bitset>
#include <sstream>

using namespace std;

#ifndef _DEPRECATION_DISABLE   /* One time only */
#define _DEPRECATION_DISABLE   /* Disable deprecation true */
#if (_MSC_VER >= 1400)         /* Check version */
#pragma warning(disable: 4996) /* Disable deprecation */
#endif /* #if defined(NMEA_WIN) && (_MSC_VER >= 1400) */
#endif /* #ifndef _DEPRECATION_DISABLE */

int main()
{
	int ls = 0, ld = 0,z=0;
	int m[1111];
	int n;
	cin >> n;

	for (int j = 0; j < n; j++)cin >> m[j];

	int t = 2,q=0,l=0;
	bool s = true;

	int left = 0, right = 0;

	while (s){

		for (int j = left, k = n - 1 - right; j <= k; j++, k--)
	{

		if (m[j] > m[k] && t % 2 == 0)
		{

			ls += m[j];
			m[j] = 0;
			left++;
			break;

		}
		if (m[j] < m[k] && t % 2 == 0)
		{

			ls += m[k];
			m[k]=0;
			right++;
			break;
		}
		if (m[j] > m[k] && t % 2 != 0)
		{

			ld += m[j];
			m[j] = 0;
			left++;
			break;

		}
		if (m[j] < m[k] && t % 2 != 0)
		{

			ld += m[k];
			m[k] = 0;
			right++;
			break;
		}

	}
	for (int t = 0; t < n; t++)
	{
		if (m[t] == 0)z++;
	}
	if (z == n-1)
	{
		z = 0;
		t++;
		s = false;

	}
	else
	{

		z = 0;
		t++;

	}

	}

	if (t % 2 == 0)
	{

		for (int t = 0; t < n; t++)
		{
			if (m[t] != 0)
			{
                cout << (ls + m[t]) << " " << ld;
				return 0;

			}

		}

	}
	else
	{
			for (int t = 0; t < n; t++)
			{
				if (m[t] != 0)
				{
					cout << ls << " " << (ld + m[t]);
					return 0;

				}

			}

	}
return 0;
}


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

int n,a,Sereja,Dima,num[1005];

int bigger(int &left,int &right)
{
	if (num[left]>num[right])
	{
		left++;return num[left-1];
	}
	else
	{
		right--;return num[right+1];
	}
}

void main()
{
	int left,right;
	while(scanf("%d",&n)!=EOF)
	{
		for (a=1;a<=n;a++)
			scanf("%d",&num[a]);
		left=1;
		right=n;
		Sereja=0;Dima=0;
		for (a=1;a<=n;a++)
		{
			if (a%2==1) Sereja+=bigger(left,right);
			else Dima+=bigger(left,right);
		}
		printf("%d %d\n",Sereja,Dima);
	}
}


#include <iostream>
using namespace std;

int n,a,Sereja,Dima,num[1005];

int bigger(int &left,int &right)
{
	if (num[left]>num[right])
	{
		left++;return num[left-1];
	}
	else
	{
		right--;return num[right+1];
	}
}

int main()
{
	int left,right;
	while(scanf("%d",&n)!=EOF)
	{
		for (a=1;a<=n;a++)
			scanf("%d",&num[a]);
		left=1;
		right=n;
		Sereja=0;Dima=0;
		for (a=1;a<=n;a++)
		{
			if (a%2==1) Sereja+=bigger(left,right);
			else Dima+=bigger(left,right);
		}
		printf("%d %d\n",Sereja,Dima);
	}
	return 0;
}


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

int n,a,Sereja,Dima,num[1005];

int bigger(int &left,int &right)
{
	if (num[left]>num[right])
	{
		left++;return num[left-1];
	}
	else
	{
		right--;return num[right+1];
	}
}

int main()
{
	int left,right;
	while(scanf("%d",&n)!=EOF)
	{
		for (a=1;a<=n;a++)
			scanf("%d",&num[a]);
		left=1;
		right=n;
		Sereja=0;Dima=0;
		for (a=1;a<=n;a++)
		{
			if (a%2==1) Sereja+=bigger(left,right);
			else Dima+=bigger(left,right);
		}
		printf("%d %d\n",Sereja,Dima);
	}
	return 0;
}


#include <iostream>
using namespace std;
int main ()
{
int n,qula[2]={0};
int k[1000];
cin>>n;
for (int i=0; i<n; i++)
cin>>k[i];
for (int i=0; i<n; i++)
{if (k[0]>k[n-i-1]) {qula[i%2]+=k[0]; for (int j=0; j<n-i-1; j++) k[j]=k[j+1];}
else qula[i%2]+=k[n-i-1];
}
cout<<qula[0]<<" "<<qula[1]<<endl;
//system ("pause");
return 0;
}


#include <iostream>
using namespace std;
int main ()
{
int n,qula[2]={0};
int k[1000],j;
cin>>n;
j=n-1;
for (int i=0; i<n; i++)
cin>>k[i];
int i=0;
for (int p=0; p<n; p++)
{if (k[i]>k[j]) {qula[i%2]+=k[i]; i++;}
else {qula[i%2]+=k[j]; j--;}
}
cout<<qula[0]<<" "<<qula[1]<<endl;
//system ("pause");
return 0;
}


#include <iostream>
using namespace std;
int main ()
{
int n,qula[2]={0};
int k[1000],j;
cin>>n;
j=n-1;
for (int i=0; i<n; i++)
cin>>k[i];
int i=0;
for (int p=0; p<n; p++)
{if (k[i]>k[j]) {qula[p%2]+=k[i]; i++;}
else {qula[p%2]+=k[j]; j--;}
}
cout<<qula[0]<<" "<<qula[1]<<endl;
return 0;
}


#include<iostream>
#include<string>
using namespace std;
int main()
{
	int n;
	cin>>n;
	int *p;
	p=new int [n];
	for(int i=0 ; i<n ; i++)
	{
		cin>>p[i];
	}
	int sum1=0 , sum2=0;
	int temp;
	for(int i=0 , j=n-1 , a=1 ; i<j , j>=i ; a++ )
	{
		if(a%2==0)
		{
			if(p[i]>p[j])
			{
				sum1+=p[i];
				++i;
			}
			else
			{
				sum1+=p[j];
				--j;
			}
		}
		else
		{
			if(p[i]>p[j])
			{
				sum2+=p[i];
				++i;
			}
			else
			{
				sum2+=p[j];
				--j;
			}
		}
	}
	cout<<sum2<<" "<<sum1;
}


#include<iostream>
#include<string>
using namespace std;
int main()
{
	int n;
	cin>>n;
	int *p;
	p=new int [n];
	for(int i=0 ; i<n ; i++)
	{
		cin>>p[i];
	}
	int sum1=0 , sum2=0;
	int temp;
	for(int i=0 ; i<n ; i++)
	{
		for(int j=i+1 ; j<n ; j++)
		{
			if(p[i]<p[j])
			{
				temp=p[i];
				p[i]=p[j];
				p[j]=temp;
			}
		}
	}
	for(int i=0 ; i<n ; i++)
	{
		if((i+1)%2==0)
			sum1+=p[i];
		else
			sum2+=p[i];
	}
	cout<<sum1<<" "<<sum2;
}


#include<iostream>
#include<string>
using namespace std;
int main()
{
	int n;
	cin>>n;
	int *p;
	p=new int [n];
	for(int i=0 ; i<n ; i++)
	{
		cin>>p[i];
	}
	int sum1=0 , sum2=0;
	int temp;
	for(int i=0 ; i<n ; i++)
	{
		for(int j=i+1 ; j<n ; j++)
		{
			if(p[i]<p[j])
			{
				temp=p[i];
				p[i]=p[j];
				p[j]=temp;
			}
		}
	}
	for(int i=0 ; i<n ; i++)
	{
		if(i%2==0)
			sum1+=p[i];
		else
			sum2+=p[i];
	}
	cout<<sum1<<" "<<sum2;
}


#include<iostream>
#include<string>
using namespace std;
int main()
{
	int n;
	cin>>n;
	int *p;
	p=new int [n];
	for(int i=0 ; i<n ; i++)
	{
		cin>>p[i];
	}
	int sum1=0 , sum2=0;
	int temp;
	for(int i=0 ; i<n ; i++)
	{
		for(int j=i+1 ; j<n ; j++)
		{
			if(p[i]<p[j])
			{
				temp=p[i];
				p[i]=p[j];
				p[j]=temp;
			}
		}
	}
	for(int i=0 ; i<n ; i++)
	{
		if((i+1)%2==0)
			sum1+=p[i];
		else
			sum2+=p[i];
	}
	if(sum1>sum2)
		cout<<sum1<<" "<<sum2;
	else
		cout<<sum2<<" "<<sum1;
}


#include<bits/stdc++.h>
#define bug(a) (cout<<'*'<<a<<endl)
#define bugg(a,b) (cout<<'*'<<a<<' '<<b<<endl)
#define buggg(a,b,c) (cout<<'*'<<a<<' '<<b<<' '<<c<<endl)
#define pn (cout<<endl)
typedef long long ll;
using namespace std;
int ar[100002];
int main()
{
	int t, i, j, n, num1, num2, t1, t2, minn = 999999999, dif, ans, maxx, sum;
	scanf("%d", &t);
	while (t--)
	{
		maxx = -1, minn = 999999999, t1 = -1, sum = 1;
		scanf("%d", &n);
		for (i = 1; i <= n; i++)
		{
			scanf("%d", &ar[i]);
		}
		for (i = 1; i < n; i++)
		{
			for (j = i + 1; j <= n; j++)
			{
				if (ar[j] >= ar[i])
					continue;
				maxx = max(maxx,ar[i] - ar[j]);
			}
		}
		if (maxx == -1)
		{
			printf("0\n");
			continue;
		}
		for (i = 1; sum < maxx; i++)
		{
			sum *= 2;
		}
		printf("%d\n", i);
	}
	return 0;
}


#include<bits/stdc++.h>
#define bug(a) (cout<<'*'<<a<<endl)
#define bugg(a,b) (cout<<'*'<<a<<' '<<b<<endl)
#define buggg(a,b,c) (cout<<'*'<<a<<' '<<b<<' '<<c<<endl)
#define pn (cout<<endl)
typedef long long ll;
using namespace std;
ll ar[100002];
int main()
{
	ll t, i, j, n, num1, num2, t1, t2, minn = 999999999, dif, ans, maxx;
	ll sum, summ;
	scanf("%lld", &t);
	while (t--)
	{
		maxx = -1, minn = 999999999, t1 = -1, sum = 1, summ = 1;
		scanf("%lld", &n);
		for (i = 1; i <= n; i++)
		{
			scanf("%lld", &ar[i]);
		}
		maxx = ar[1];
		dif = 0;
		for (i = 1; i <= n; i++)
		{
			dif = max(dif, maxx - ar[i]);
			maxx = max(maxx, ar[i]);
		}
		if (dif == 0)
		{
			printf("0\n");
			continue;
		};
		maxx = dif;
		for (i = 1; summ < maxx; i++)
		{
			sum *= 2;
			summ += sum;
			//bug(sum);
		}
		printf("%lld\n", i);
	}
	return 0;
}


#include<bits/stdc++.h>
#define bug(a) (cout<<'*'<<a<<endl)
#define bugg(a,b) (cout<<'*'<<a<<' '<<b<<endl)
#define buggg(a,b,c) (cout<<'*'<<a<<' '<<b<<' '<<c<<endl)
#define pn (cout<<endl)
typedef long long ll;
using namespace std;
ll ar[100002];
int main()
{
	ll t, i, j, n, num1, num2, t1, t2, minn = 999999999, dif, ans, maxx;
	ll sum, summ;
	scanf("%lld", &t);
	while (t--)
	{
		maxx = -1, minn = 999999999, t1 = -1, sum = 1, summ = 1;
		scanf("%lld", &n);
		for (i = 1; i <= n; i++)
		{
			scanf("%lld", &ar[i]);
		}
		maxx = -1;
		dif = 0;
		for (i = 1; i <= n; i++)
		{
			dif = max(dif, maxx - ar[i]);
			maxx = max(maxx, ar[i]);
		}
		maxx = dif;
		if (maxx == -1)
		{
			printf("0\n");
			continue;
		};
		for (i = 1; summ < maxx; i++)
		{
			sum *= 2;
			summ += sum;
			//bug(sum);
		}
		printf("%lld\n", i);
	}
	return 0;
}


#include<bits/stdc++.h>
#define bug(a) (cout<<'*'<<a<<endl)
#define bugg(a,b) (cout<<'*'<<a<<' '<<b<<endl)
#define buggg(a,b,c) (cout<<'*'<<a<<' '<<b<<' '<<c<<endl)
#define pn (cout<<endl)
typedef long long ll;
using namespace std;
int ar[100002];
int main()
{
	int t, i, j, n, num1, num2, t1, t2, maxx = -1, minn = 999999999, dif;
	double ans;
	scanf("%d", &t);
	while (t--)
	{
		maxx = -1, minn = 999999999, t1 = -1;
		scanf("%d", &n);
		for (i = 1; i <= n; i++)
		{
			scanf("%d", &ar[i]);
		}
		for (i = 1; i < n; i++)
		{
			for (j = i + 1; j <= n; j++)
			{
				if (ar[j] >= ar[i])
					continue;
				maxx = max(maxx, ar[i] - ar[j]);
			}
		}
		if (maxx == -1)
		{
			printf("0\n");
			continue;
		}
		ans = (-1 + sqrt(1.0 + 8 * maxx)) / 2.0;
		if (ans != (int)ans)
			ans++;
		printf("%d\n", (int)ans);
	}
	return 0;
}


#include<bits/stdc++.h>
#define bug(a) (cout<<'*'<<a<<endl)
#define bugg(a,b) (cout<<'*'<<a<<' '<<b<<endl)
#define buggg(a,b,c) (cout<<'*'<<a<<' '<<b<<' '<<c<<endl)
#define pn (cout<<endl)
typedef long long ll;
using namespace std;
int ar[100002];
int main()
{
	int t, i, j, n, num1, num2, t1, t2,minn = 999999999, dif;
	double ans, maxx;
	scanf("%d", &t);
	while (t--)
	{
		maxx = -1, minn = 999999999, t1 = -1;
		scanf("%d", &n);
		for (i = 1; i <= n; i++)
		{
			scanf("%d", &ar[i]);
		}
		for (i = 1; i < n; i++)
		{
			for (j = i + 1; j <= n; j++)
			{
				if (ar[j] >= ar[i])
					continue;
				maxx = max(maxx,(double)ar[i] - ar[j]);
			}
		}
		if (maxx == -1)
		{
			printf("0\n");
			continue;
		}
		ans = (-1 + sqrt(1.0 + 8 * maxx)) / 2.0;
		if (ans != (int)ans)
			ans++;
		printf("%d\n", (int)ans);
	}
	return 0;
}