#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <ctime>
#include <list>
#include <string>
#include <map>
#include <vector>
#include <algorithm>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <iostream>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>

using namespace std;

#define F_TO_R          freopen("input.txt", "r" , stdin)
#define _pair(x,y)      make_pair(x,y)
#define INF             (1<<30)
#define sf              scanf
#define pf              printf
#define mem(a,b)        memset(a, b, sizeof(a))
#define fs              first
#define se              second
#define MAX             1010
#define MAXR            50010
#define MAXC            1000000000000LL
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int u_int;
const double PI = 2.0 * acos(0.0);
const double eps = 1e-11;
const int _mod = 1000000;
const int save[10][4] = {{0},{0},{6,2,4,8},{1,3,9,7},{6,4},{0},{0},{1,7,9,3},{6,8,4,2},{1,9}};
int todigit(char c) { return ( isdigit(c) ) ?( c - 48 ) : c ; }
int toint(string s) { int r = 0; istringstream sin(s); sin >> r; return r; }
ll tolong(string s) {  ll r = 0; istringstream sin(s); sin >> r; return r; }
double todouble(string s) { double r = 0.0 ; istringstream sin(s); sin >> r; return r; }
bool bit_check(int k , int p){ return (bool)(k&(1 << p)); }
int bit_set(int k , int p) { return k = (k|(1 << p));}
template < class T > string toString(T n) { ostringstream ost; ost << n; ost.flush() ; return ost.str(); }
template < class T > T Abs(T x) { return x > 0 ? x : -x;}
template < class T > T power(T N , T P) { return (P == 0) ?  1 : N * power(N , P - 1); }
template < class T > inline T max_(T a,T b) {return a > b ? a : b ;}
template < class T > inline T min_(T a,T b) {return a < b ? a : b ;}
template < class T > inline T gcd(T a,T b) {if(a < 0) return gcd(-a,b); if(b < 0)return gcd(a,-b); return (b == 0) ? a : gcd(b ,a % b);}
template < class T > inline T lcm(T a,T b) {if(a < 0) return lcm(-a,b); if(b < 0)return lcm(a,-b); return a * (b / gcd(a , b));}

//ll big_mod(ll n , ll  p , ll m)
//{
//  ll sum;
//  if(!p) return 1;
//  if(p % 2 == 0) { sum = big_mod(n  , p / 2 , m); return ((sum % m ) *(sum % m)) % m; }
//  else return (( n % m) * (big_mod( n , p - 1 , m) % m ))% m;
//}

//bool siv[MAX];
//int prime[MAXR];
//void is_prime()
//{
//    int k = 0;
//    int n = sqrt(MAX);
//    prime[k++] = 2;
//    for(int i = 3 ; i < n ; i += 2) if(!siv[i]) for(int j = i * i ; j < MAX ; j += (2 * i)) siv[j] = true;
//    for(int i = 3 ; i < MAX ; i += 2) if(!siv[i]) prime[k++] = i;
//}

//int one[]={1,0,-1,0}; //4 Direction
//int two[]={0,1,0,-1}; //4 Direction
//int two[]={0,1,1,1,0,-1,-1,-1};//8 direction
//int one[]={2,1,-1,-2,-2,-1,1,2}; //Knight Direction
//int two[]={1,2,2,1,-1,-2,-2,-1};//Knight Direction

///***************************************  END  **********************************************///

list < int > le;

int main()
{
    int t, temp, one = 0 , two = 0 ;
    sf("%d", &t);
    while(t--)
    {
        sf("%d", &temp);
        le.push_back(temp);
    }
    temp = 1;
    while(!le.empty())
    {
        if(le.front() >= le.back())
        {
            if(temp == 1) one = one + le.front(), temp = 2;
            else if(temp == 2) two = two + le.front(), temp = 1;
            le.pop_front();
        }
        if(le.empty()) break;
        else
        {
            if(temp == 2) two = two + le.back(), temp = 1;
            else if(temp == 1) one = one + le.back(), temp = 2;
            le.pop_back();
        }
    }
    pf("%d %d", one , two);
    return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <ctime>
#include <list>
#include <string>
#include <map>
#include <vector>
#include <algorithm>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <iostream>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>

using namespace std;

#define F_TO_R          freopen("input.txt", "r" , stdin)
#define _pair(x,y)      make_pair(x,y)
#define INF             (1<<30)
#define sf              scanf
#define pf              printf
#define mem(a,b)        memset(a, b, sizeof(a))
#define fs              first
#define se              second
#define MAX             1010
#define MAXR            50010
#define MAXC            1000000000000LL
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int u_int;
const double PI = 2.0 * acos(0.0);
const double eps = 1e-11;
const int _mod = 1000000;
const int save[10][4] = {{0},{0},{6,2,4,8},{1,3,9,7},{6,4},{0},{0},{1,7,9,3},{6,8,4,2},{1,9}};
int todigit(char c) { return ( isdigit(c) ) ?( c - 48 ) : c ; }
int toint(string s) { int r = 0; istringstream sin(s); sin >> r; return r; }
ll tolong(string s) {  ll r = 0; istringstream sin(s); sin >> r; return r; }
double todouble(string s) { double r = 0.0 ; istringstream sin(s); sin >> r; return r; }
bool bit_check(int k , int p){ return (bool)(k&(1 << p)); }
int bit_set(int k , int p) { return k = (k|(1 << p));}
template < class T > string toString(T n) { ostringstream ost; ost << n; ost.flush() ; return ost.str(); }
template < class T > T Abs(T x) { return x > 0 ? x : -x;}
template < class T > T power(T N , T P) { return (P == 0) ?  1 : N * power(N , P - 1); }
template < class T > inline T max_(T a,T b) {return a > b ? a : b ;}
template < class T > inline T min_(T a,T b) {return a < b ? a : b ;}
template < class T > inline T gcd(T a,T b) {if(a < 0) return gcd(-a,b); if(b < 0)return gcd(a,-b); return (b == 0) ? a : gcd(b ,a % b);}
template < class T > inline T lcm(T a,T b) {if(a < 0) return lcm(-a,b); if(b < 0)return lcm(a,-b); return a * (b / gcd(a , b));}

//ll big_mod(ll n , ll  p , ll m)
//{
//  ll sum;
//  if(!p) return 1;
//  if(p % 2 == 0) { sum = big_mod(n  , p / 2 , m); return ((sum % m ) *(sum % m)) % m; }
//  else return (( n % m) * (big_mod( n , p - 1 , m) % m ))% m;
//}

//bool siv[MAX];
//int prime[MAXR];
//void is_prime()
//{
//    int k = 0;
//    int n = sqrt(MAX);
//    prime[k++] = 2;
//    for(int i = 3 ; i < n ; i += 2) if(!siv[i]) for(int j = i * i ; j < MAX ; j += (2 * i)) siv[j] = true;
//    for(int i = 3 ; i < MAX ; i += 2) if(!siv[i]) prime[k++] = i;
//}

//int one[]={1,0,-1,0}; //4 Direction
//int two[]={0,1,0,-1}; //4 Direction
//int two[]={0,1,1,1,0,-1,-1,-1};//8 direction
//int one[]={2,1,-1,-2,-2,-1,1,2}; //Knight Direction
//int two[]={1,2,2,1,-1,-2,-2,-1};//Knight Direction

///***************************************  END  **********************************************///

list < int > le;

int main()
{
    int t, temp, one = 0 , two = 0 ;
    sf("%d", &t);
    while(t--)
    {
        sf("%d", &temp);
        le.push_back(temp);
    }
    temp = 1;
    while(!le.empty())
    {
        if(le.front() >= le.back())
        {
            if(temp == 1) one = one + le.front(), temp = 2;
            else if(temp == 2) two = two + le.front(), temp = 1;
            le.pop_front();
        }
        else if(le.empty()) break;
        else
        {
            if(temp == 2) two = two + le.back(), temp = 1;
            else if(temp == 1) one = one + le.back(), temp = 2;
            le.pop_back();
        }
    }
    pf("%d %d", one , two);
    return 0;
}


#include <set>
#include <map>
#include <list>
#include <stack>
#include <cmath>
#include <queue>
#include <bitset>
#include <climits>
#include <vector>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <utility>
#include <string.h>
#include <iostream>
#include <algorithm>
using namespace std;
#define xx first
#define yy second
#define mp make_pair
#define pb push_back
#define MM 1001
#define sqr(x) ((x) * (x))
#define ABS(x) ((x < 0) ? -(x) : (x))
#define eps (1e-9)
#define equal(a, b) (ABS(a - b) < eps)
typedef unsigned long long ULL;
typedef long long LL;
#define PII pair<int, int>
typedef pair< int, PII > Edge;

bool cmp(int a, int b) {
    return a > b;
}
int main() {
    int n,a[MM];
    cin>>n;
    for(int i = 0; i < n; i++ ) {
        cin>>a[i];
    }
    int s = 0, s1 = 0;
    sort(a, a+n, &cmp);
    for(int i = 0; i < n; i+=2)
        s+=a[i];
    for(int i = 1; i < n; i+=2)
        s1+=a[i];
    cout<<s<<" "<<s1<<endl;
    return 0;
}


#include <set>
#include <map>
#include <list>
#include <stack>
#include <cmath>
#include <queue>
#include <bitset>
#include <climits>
#include <vector>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <utility>
#include <string.h>
#include <iostream>
#include <algorithm>
using namespace std;
#define xx first
#define yy second
#define mp make_pair
#define pb push_back
#define MM 1001
#define sqr(x) ((x) * (x))
#define ABS(x) ((x < 0) ? -(x) : (x))
#define eps (1e-9)
#define equal(a, b) (ABS(a - b) < eps)
typedef unsigned long long ULL;
typedef long long LL;
#define PII pair<int, int>
typedef pair< int, PII > Edge;

bool cmp(int a, int b) {
    return a > b;
}
int main() {
    int n,a[MM];
    cin>>n;
    for(int i = 0; i < n; i++ ) {
        cin>>a[i];
    }
    sort(a, a+n, &cmp);
    int s = 0, s1 = 0;

    for(int i = 0; i < n; i+=2) {
        s+=a[i];
        s1+=a[i+1];
    }

    cout<<s<<" "<<s1<<endl;
    return 0;
}


#include <set>
#include <map>
#include <list>
#include <stack>
#include <cmath>
#include <queue>
#include <bitset>
#include <climits>
#include <vector>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <utility>
#include <string.h>
#include <iostream>
#include <algorithm>
using namespace std;
#define xx first
#define yy second
#define mp make_pair
#define pb push_back
#define MM 1001
#define sqr(x) ((x) * (x))
#define ABS(x) ((x < 0) ? -(x) : (x))
#define eps (1e-9)
#define equal(a, b) (ABS(a - b) < eps)
typedef unsigned long long ULL;
typedef long long LL;
#define PII pair<int, int>
typedef pair< int, PII > Edge;

int main() {
    int n,a;
    cin>>n;
    vector<int> v;
    for(int i = 0; i < n; i++ ) {
        cin>>a;
        v.pb(a);
    }
    int s = 0, s1 = 0;
    int k = 0;
    while(!v.empty()) {
        if(k == 0) {
            if(v[v.size() - 1] < v[0]) {
                s+=v[0];
                int tmp = v[0];
                v[0] = v[v.size() - 1];
                v[v.size() - 1] = tmp;
                v.pop_back();
            }else {
                s+=v[v.size()-1];
                v.pop_back();
            }
            k=1;
        }else {
            if(v[v.size() - 1] < v[0]) {
                s1+=v[0];
                int tmp = v[0];
                v[0] = v[v.size() - 1];
                v[v.size() - 1] = tmp;
                v.pop_back();
            }else {
                s1+=v[v.size()-1];
                v.pop_back();
            }
            k=0;
        }
    }
    cout<<s<<" "<<s1<<endl;
    return 0;
}


#include <set>
#include <map>
#include <list>
#include <stack>
#include <cmath>
#include <queue>
#include <bitset>
#include <climits>
#include <vector>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <utility>
#include <string.h>
#include <iostream>
#include <algorithm>
using namespace std;
#define xx first
#define yy second
#define mp make_pair
#define pb push_back
#define MM 1001
#define sqr(x) ((x) * (x))
#define ABS(x) ((x < 0) ? -(x) : (x))
#define eps (1e-9)
#define equal(a, b) (ABS(a - b) < eps)
typedef unsigned long long ULL;
typedef long long LL;
#define PII pair<int, int>
typedef pair< int, PII > Edge;

bool cmp(int a, int b) {
    return a > b;
}
int main() {
    int n,a[MM];
    cin>>n;
    for(int i = 0; i < n; i++ ) {
        cin>>a[i];
    }
    int s = 0, s1 = 0;
    if(n == 1) {
        s = a[0];
        cout<<s<<" "<<s1<<endl;
        return 0;
    }
    sort(a, a+n, &cmp);

    for(int i = 0; i < n; i+=2) {
        s+=a[i];
        s1+=a[i+1];
    }

    cout<<s<<" "<<s1<<endl;
    return 0;
}


#include <set>
#include <map>
#include <list>
#include <stack>
#include <cmath>
#include <queue>
#include <bitset>
#include <climits>
#include <vector>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <utility>
#include <string.h>
#include <iostream>
#include <algorithm>
using namespace std;
#define xx first
#define yy second
#define mp make_pair
#define pb push_back
#define MM 1001
#define sqr(x) ((x) * (x))
#define ABS(x) ((x < 0) ? -(x) : (x))
#define eps (1e-9)
#define equal(a, b) (ABS(a - b) < eps)
typedef unsigned long long ULL;
typedef long long LL;
#define PII pair<int, int>
typedef pair< int, PII > Edge;

int main() {
    int n,a;
    cin>>n;
    vector<int> v;
    for(int i = 0; i < n; i++ ) {
        cin>>a;
        v.pb(a);
    }
    int s = 0, s1 = 0;
    int l = 0;
    while(!v.empty()) {
        int k = v.size();
        if(v[k-1] > v[0]) {
            if(l == 0) {
                s+=v[k - 1];
                l = 1;
                v.pop_back();
            } else {
                s1 += v[k - 1];
                v.pop_back();
                l = 0;
            }
        } else {
            if(l == 0) {
                s+=v[0];
                l = 1;
                v.erase(v.begin());
            } else {
                s1 += v[0];
                v.erase(v.begin());
                l = 0;
            }
        }
    }
    cout<<s<<" "<<s1<<endl;
    return 0;
}


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

int main(){
    int n,se=0,di=0;
    cin>>n;
    int b[n];
    for(int i=0;i<n;i++){
        cin>>b[i];
    }
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            if(b[i]>=b[j]){
                swap(b[i],b[j]);
            }
        }
    }
    for(int i=1;i<=n;i++){
        if(i%2!=0){
            se=se+b[i-1];
        }else if(i%2==0){
            di=di+b[i-1];
        }
    }
    cout<<se<<" "<<di;
}


#include<iostream>
#include<conio.h>
#include<cmath>
#include<algorithm>
#include<math.h>
using namespace std;
int main(){
	int n,sum1=0,sum2=0,sum=0;
	cin>>n;
	int arr[n];
	for(int i=0;i<n;i++){
		cin>>arr[i];
	}
	for(int j=0;j<n;j++){
		for(int i=j;i<n;i++){
			if(arr[j]>arr[i]){
				swap(arr[j],arr[i]);
			}
		}
		}
		if(n%2!=0){
			for(int h=0;h<n;h++){
				if(h%2==0){
					sum1=sum1+arr[h];
				}
				sum=sum+arr[h];
			}
			sum2=sum-sum1;
			cout<<sum1<<" "<<sum2;
		}
		else{
				for(int h=0;h<n;h++){
				if(h%2!=0){
					sum1=sum1+arr[h];
				}
				sum=sum+arr[h];
			}
			sum2=sum-sum1;
			cout<<sum1<<" "<<sum2;

		}

}


#include<iostream>

using namespace std;
int main(){
	int n,se=0,de=0;
	cin>>n;
	int b[n];
	for(int i=0;i<n;i++){
		cin>>b[i];
	}
	for(int i=0;i<n;i++){
		if(i%2==0){
			if(b[i]>b[n-i-1]){
				se=se+b[i];
			}else{
				se=se+b[n-i-1];
			}
		}else if(i%2!=0){
			if(b[i]>b[n-i-1]){
				de=de+b[i];
			}else{
				de=de+b[n-i-1];
			}
		}
	}
	cout<<se<<" "<<de;
}


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

int main(){
    int n,se=0,di=0;
    cin>>n;
    int b[n];
    for(int i=0;i<n;i++){
        cin>>b[i];
    }
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            if(b[i]>=b[j]){
                swap(b[i],b[j]);
            }
        }
    }
    for(int i=0;i<n;i++){
        if(i%2!=0){
            di=di+b[i];
        }else if(i%2==0){
            se=se+b[i];
        }
    }
    cout<<se<<" "<<di;
}


#include<iostream>
#include<conio.h>
#include<algorithm>
#include<math.h>
#include<cmath>
using namespace std;
int main(){
	int n,h,k,sum1=0,sum2=0,l=1,e=1;
	cin>>n;
	int arr[n];
	for(int i=0;i<n;i++){
		cin>>arr[i];
	}
	h=arr[0];
	k=arr[n-1];
	for(int i=1;i<=n;i++){
		if(i%2!=0){
	   if(h>k){
	   	sum1=sum1+h;
	   	if(l<n){
	   	h=arr[l];
		   l++;
	}
	   }
	   else if(k>=h){
	   	sum1=sum1+k;
	   	if(n-1-e>=0){
	   	k=arr[n-1-e];
		e++;
	}
	   }
    }
    if(i%2==0){
    	if(h>k){
    		sum2=sum2+h;
    		if(l<n){
    		h=arr[l];
    		l++;
    	}
		}
		else if(k>=h){
			sum2=sum2+k;
			if(n-1-e>=0){
			k=arr[n-1-e];
			e++;
		}
		}
	}
	}
	cout<<sum1<<" "<<sum2;
}


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

int main(){
    int n,se=0,di=0;
    cin>>n;
    int b[n];
    for(int i=0;i<n;i++){
        cin>>b[i];
    }
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            if(b[i]>b[j]){
                swap(b[i],b[j]);
            }
        }
    }
    for(int i=1;i<=n;i++){
        if(i%2!=0){
            se=se+b[i-1];
        }else if(i%2==0){
            di=di+b[i-1];
        }
    }
    cout<<se<<" "<<di;
}


#include <bits/stdc++.h>
using namespace std;
int main(){
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    int n, b = 0, c = 0; cin >> n; int a[n];  for(int i = 0; i < n; i++) cin >> a[i];
    int l = 0, r = n - 1, p = 0; while(r >= l){ p = 1 - p; if(p){ if(a[r] > a[l]) b += a[r], r--; else b += a[l], l++;}
        else{ if(a[r] > a[l]) c += a[r], r--; else c += a[l], l++; }
    }
    cout << b << " " << c << endl;
}


#include <bits/stdc++.h>
using namespace std;
int main(){
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    int n, b = 0, c = 0; cin >> n; int a[n];  for(int i = 0; i < n; i++) cin >> a[i];
    int l = 0, r = n - 1; while(r >= l){ if((l + r + 10000) % 2 == 0){ if(a[r] > a[l]) b += a[r], r--; else b += a[l], l++;}
        else{ if(a[r] > a[l]) c += a[r], r--; else c += a[l], l++; }
    }
    cout << max(b, c) << " " << min(b, c) << endl;
}


#include <bits/stdc++.h>
using namespace std;
int main(){
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    int n, b = 0, c = 0; cin >> n; int a[n];  for(int i = 0; i < n; i++) cin >> a[i];
    int l = 0, r = n - 1; while(r >= l){ if(l + r % 2 == 0){ if(a[r] > a[l]) b += a[r], r--; else b += a[l], l++;}
        else{ if(a[r] > a[l]) c += a[r], r--; else c += a[l], l++; }
    }
    cout << max(b, c) << " " << min(b, c) << endl;
}


#include <bits/stdc++.h>
using namespace std;
int main(){
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    int n, b = 0, c = 0; cin >> n; int a[n];  for(int i = 0; i < n; i++) cin >> a[i];
    int l = 0, r = n - 1, p = 0; while(r >= l){ p = 1 - p; if(p){ if(a[r] > a[l]) b += a[r], r--; else b += a[l], l++;}
        else{ if(a[r] > a[l]) c += a[r], r--; else c += a[l], l++; }
    }
    cout << max(b, c) << " " << min(b, c) << endl;
}


#include <iostream>
#include <deque>
using namespace std;
int n,x=0,y=0;
int main()
{
    cin >> n;
    deque<int> q(n);
    for (int i=0; i<n; i++)cin >> q[i];
    while(!q.empty())
    {
        if (q.front()>q.back())x+=q.front(),q.pop_front();
        else x+=q.back(),q.pop_back();
        if (q.front()>q.back())y+=q.front(),q.pop_front();
        else y+=q.back(),q.pop_back();
    }
    cout << x << " " << y;
    return 0;
}


#include <iostream>
#include <algorithm>
using namespace std;
int n,x=0,y=0,v[1009];
int main()
{
   cin >> n;
   for (int i=0;i<n;i++)cin >> v[i];
   int z=n,a=0,b=n-1;
   while(z>0){
        if (v[a]>v[b])x+=v[a],a++,z--;
        else x+=v[b],b--,z--;

        if (v[a]>v[b])y+=v[a],a++,z--;
        else y+=v[b],b--,z--;
   }
   cout << x << " " << y;
    return 0;
}


#include <iostream>
#include <algorithm>
using namespace std;
int n,x=0,y=0,v[1009];
int main()
{
   cin >> n;
   for (int i=0;i<n;i++)cin >> v[i];
   int z=n,a=0,b=n-1;
   for (int i=0;i<n;i++){

        if (z<=0)break;
        if (v[a]>v[b])x+=v[a],a++,z--;
        else x+=v[b],b--,z--;
        if (z<=0)break;
        if (v[a]>v[b])y+=v[a],a++,z--;
        else y+=v[b],b--,z--;
   }
   cout << x << " " << y;
    return 0;
}


#include <iostream>
#include <algorithm>
using namespace std;
int n,x=0,y=0,v[1009];
int main()
{
   cin >> n;
   for (int i=0;i<n;i++)cin >> v[i];
   sort(v,v+n);
   for (int i=n-1;i>=0;i-=2)x+=v[i];
   for (int i=n-2;i>=0;i-=2)y+=v[i];
   cout << x << " " << y;
    return 0;
}


#include <iostream>

using namespace std;
int n,x=0,y=0,v[1009];
int main()
{
   cin >> n;
   for (int i=0;i<n;i++)cin >> v[i];
   sort(v,v+n);
   for (int i=n-1;i>=0;i-=2)x+=v[i];
   for (int i=n-2;i>=0;i-=2)y+=v[i];
   cout << x << " " << y;
    return 0;
}


#include <iostream>
#include <algorithm>
using namespace std;
int n,x=0,y=0,v[1009];
int main()
{
   cin >> n;
   for (int i=0;i<n;i++)cin >> v[i];
   sort(v,v+n);
   int z=n,a=0,b=n-1;
   for (int i=0;i<n;i++){

        if (z<=0)break;
        if (v[a]>v[b])x+=v[a],a++,z--;
        else x+=v[b],b--,z--;
        if (z<=0)break;
        if (v[a]>v[b])y+=v[a],a++,z--;
        else y+=v[b],b--,z--;
   }
   cout << x << " " << y;
    return 0;
}


#include <iostream>
#include <deque>
using namespace std;
int n,x=0,y=0;
int main()
{
    cin >> n;
    deque<int> q(n);
    for (int i=0; i<n; i++)cin >> q[i];
    while(!q.empty())
    {
        if (q.front()>q.back())x+=q.front(),q.pop_front();
        else x+=q.back(),q.pop_back();
        if (q.empty())break;
        if (q.front()>q.back())y+=q.front(),q.pop_front();
        else y+=q.back(),q.pop_back();
    }
    cout << x << " " << y;
    return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
typedef long long int lld;
typedef long int ld;
#define gc getchar
#define pc putchar

int main() {
	ld n,i,sum_s=0,sum_o=0,j;
	scanf("%ld",&n);
	//a=(ld*)malloc(n+1*sizeof(ld));
	ld a[10100];
	for(i=0;i<n;i++)
	{
		scanf("%ld",&a[i]);
	}
	i=0; j=n-1;

	while(i<=j)
	{                                            //                                        printf("i=%d,j=%d\n",i,j);
		if(a[i]>=a[j])
	     {
	        sum_s+=a[i];
	        a[i]=0; i++;
		 }

		 else if(a[i]<a[j])
	     {
	     	sum_s+=a[j];
	     	a[j]=0; j--;
		 }

	     if(a[i]>=a[j])
	     {
	     	sum_o+=a[i];
	     	a[i]=0; i++;
		 }

		 else if (a[i]<a[j])
		 {
		 	sum_o+=a[j];
		 	a[j]=0;
		 	j--;
		 }
	                                          //                   printf("sum_s=%d,sum_o=%d\n",sum_s,sum_o);
	}

	printf("%ld %ld\n",sum_s,sum_o);

//	free(a);

	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
typedef long long int lld;
typedef long int ld;
#define gc getchar
#define pc putchar

int main() {
	ld n,i,sum_s=0,sum_o=0;
	scanf("%ld",&n);
	//a=(ld*)malloc(n+1*sizeof(ld));
	ld a[10100];
	for(i=0;i<n;i++)
	{
		scanf("%ld",&a[i]);
	}

	for(i=0;i<(n+1)/2;i++)
	{
		if(a[i]>a[n-1-i])
		{
			sum_s+=a[i];
			sum_o+=a[n-1-i];
		}

	    else
		{
			sum_o+=a[i];
			sum_s+=a[n-1-i];
		}
	                                                          //printf(" %ld%ld \n",sum_s,sum_o);
	}

	printf("%ld %ld\n",sum_s,sum_o);

//	free(a);

	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
typedef long long int lld;
typedef long int ld;
#define gc getchar
#define pc putchar

int main() {
	ld n,*a,i,sum_s=0,sum_o=0;
	scanf("%ld",&n);
	a=(ld*)malloc(n+1*sizeof(ld));
	for(i=0;i<n;i++)
	{
		scanf("%ld",&a[i]);
	}

	for(i=0;i<(n+1)/2;i++)
	{
		if(a[i]>a[n-1-i])
		{
			sum_s+=a[i];
			sum_o+=a[n-1-i];
		}

	    else
		{
			sum_o+=a[i];
			sum_s+=a[n-1-i];
		}
	                                                          //printf(" %ld%ld \n",sum_s,sum_o);
	}

	printf("%ld %ld\n",sum_s,sum_o);

	free(a);

	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
typedef long long int lld;
typedef long int ld;
#define gc getchar
#define pc putchar

int main() {
	ld n,*a,i,sum_s=0,sum_o=0;
	scanf("%ld",&n);
	a=(ld*)malloc(n+1*sizeof(ld));
	for(i=0;i<n;i++)
	{
		scanf("%ld",&a[i]);
	}

	for(i=0;i<(n+1)/2;i++)
	{
		if(a[i]>a[n-1-i])
		{
			sum_s+=a[i];
			sum_o+=a[n-1-i];
		}

	    else
		{
			sum_o+=a[i];
			sum_s+=a[n-1-i];
		}
	                                                          //printf(" %ld%ld \n",sum_s,sum_o);
	}

	printf("%ld %ld\n",sum_s,sum_o);

	return 0;
}


#include<stdio.h>
#include<string.h>
#include<map>
#include<stdlib.h>
#include<algorithm>
using namespace std;
int s[10008];
int main()
{
    int n,i;
    while(~scanf("%d",&n))
    {
        for(i=0;i<n;i++)
            scanf("%d",&s[i]);
        sort(s,s+n);
        int a=0,b=0;
        int l=n-1;
        int temp=1;
        int t=0;
        while(1)
        {
            if(temp==1)
            a+=s[l--],temp=2,t++;
            else
            b+=s[l--],temp=1,t++;
            if(t==n||l<0) break;

        }
        printf("%d %d\n",a,b);

    }

  return 0;
}/*2017-08-04 19:08:51.271*/


#include<stdio.h>
int num[1010];
int main()
{
	int sum1,sum2,n,m,i,j,k;
	while(scanf("%d",&n)!=EOF)
	{
		for(i=0;i<n;i++)
		scanf("%d",&num[i]);
		sum1=0;
		sum2=0;
		i=0;
		k=n-1;
		while(i<=k)
		{
			if(i<k)
			{
				if(num[i]<num[k])
				{
						sum1+=num[k];
					k--;
				}
				else if(num[i]>num[k])
				{
					sum1+=num[i];
					i++;
				}
			}
			else if(i==k)
			{
			sum1+=num[k];
				break;
			}
			if(i<k)
			{
				if(num[i]<num[k])
				{
					sum2+=num[k];
					k--;
				}
				else if(num[i]>num[k])
				{
					sum2+=num[i];
					i++;
				}
			}
			else if(i==k)
			{
				sum2+=num[i];
				break;
			}

		}
		printf("%d %d\n",sum1,sum2);
	}
}/*2017-08-04 19:15:24.105*/


#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
#define N 1005

int main()
{
    int t, i, l, r, sl, sr, a[N];

    scanf("%d", &t);
    memset(a, 0, sizeof(a));
    for (i = 0; i < t; i++)
        scanf("%d", &a[i]);
    l = 0, r = t - 1;
    sl = 0, sr = 0;
    i = 0;
    while (1)
    {
        if (a[l] > a[r])
            sl += a[l], l++;
        else
            sl += a[r], r--;
        i++;
        if (i >= t) break;

        if (a[l] > a[r])
            sr += a[l], l++;
        else
            sr += a[r], r--;
        i++;
        if (i >= t) break;
    }
    printf("%d %d\n", sl, sr);
}
/*2017-08-04 19:07:03.257*/


#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#define N 1010
using namespace std;

int a[1010];
int main()
{
    int n;
    scanf("%d",&n);
    for (int i=0;i<n;++i)
        scanf("%d",a+i);
    long long s1=0,s2=0;
    int l=0,r=n-1;
    for (int i=0;i<n;++i)
    {
        if (i%2==0)
        {
            if (a[l]>a[r])
            {
                s1+=a[l++];
            }
            else
                s1+=a[r--];
        }
        else
        {
            if (a[l]>a[r])
            {
                s2+=a[l++];
            }
            else
            {
                s2+=a[r--];
            }
        }
    }
    printf("%I64d %I64d",s1,s2);
    return 0;
}

/*2017-08-04 19:04:06.004*/


#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<stack>
using namespace std;

int main()
{
    int n;
    int ans=0;
    int sum=0;
    int a[10005];
    scanf("%d",&n);
    for(int i=0; i<n; i++)
        scanf("%d",&a[i]);

    int i=0;
    int j=n-1;
    int flag=0;
    while(1)
    {
        if(i==j)
            break;
        if(flag==0)
        {
            if(a[i]>=a[j])
            {
                sum=sum+a[i];
                i++;
                flag=1;
            }
            else
            {
                sum=sum+a[j];
                j--;
                flag=1;
            }
        }
        if(flag==1)
        {
            if(a[i]>=a[j])
            {
                ans=ans+a[i];
                i++;
                flag=0;
            }
            else
            {
                ans=ans+a[j];
                j--;
                flag=0;
            }
        }

    }
    sort(a,a+n);
    if(n%2==0)
        printf("%d %d",sum,ans);
    else
        printf("%d %d",sum+a[0],ans);
    return 0;
}
/*2017-08-04 19:26:01.315*/


#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<cstdio>
#include<stack>
#include<climits>
using namespace std;
int main()
{
int n,i,a,b,ans1=0,ans2=0;
cin>>n;
int arr[n+10],min=10010;

for(i=0;i<n;i++)
{
    cin>>arr[i];
    if(arr[i]<min)
        min=arr[i];
}
if(n==1)
    cout<<arr[0]<<" "<<"0"<<endl;
else
{
    if(n%2==1)
        ans1+=min;
int m=n;
i=0;
for(int k=0;k<m/2;k++)
{
    a=max(arr[i],arr[n-1]);
    if(a==arr[i])
        i++;
    else
        n--;
    ans1+=a;
   // cout<<"ans1"<<ans1<<endl;
    b=max(arr[i],arr[n-1]);
if(b==arr[i])
    i++;
    else
        n--;
        ans2+=b;
       // cout<<"ans2"<<ans2<<endl;
}
//cout<<"i "<< i<<endl;

cout<<ans1<<" "<<ans2<<endl;
}
    return 0;
}


#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<cstdio>
#include<stack>

using namespace std;
int main()
{
int n,i,a,b,ans1=0,ans2=0;
cin>>n;
int arr[n+10];
for(i=0;i<n;i++)
{
    cin>>arr[i];
}
int m=n;
i=0;
for(int k=0;k<m/2;k++)
{
    a=max(arr[i],arr[n-1]);
    if(a==arr[i])
        i++;
    else
        n--;
    ans1+=a;
    b=max(arr[i],arr[n-1]);
if(b==arr[i])
    i++;
    else
        n--;
        ans2+=b;
}
if(m/2%2)
    ans1+=arr[i];
cout<<ans1<<" "<<ans2<<endl;

    return 0;
}


#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<cstdio>
#include<stack>

using namespace std;
int main()
{
int n,i,a,b,ans1=0,ans2=0;
cin>>n;
int arr[n+10];
for(i=0;i<n;i++)
{
    cin>>arr[i];
}
int m=n;
i=0;
for(int k=0;k<m/2;k++)
{
    a=max(arr[i],arr[n-1]);
    if(a==arr[i])
        i++;
    else
        n--;
    ans1+=a;
    b=max(arr[i],arr[n-1]);
if(b==arr[i])
    i++;
    else
        n--;
        ans2+=b;
}
if(m/2%2||n%2)
    ans1+=arr[i];
cout<<ans1<<" "<<ans2<<endl;

    return 0;
}


#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<cstdio>
#include<stack>

using namespace std;
int main()
{
int n,i,a,b,ans1=0,ans2=0;
cin>>n;
int arr[n+10];
for(i=0;i<n;i++)
{
    cin>>arr[i];
}
if(n==1)
    cout<<arr[0]<<" "<<"0"<<endl;
else
{
int m=n;
i=0;
for(int k=0;k<m/2;k++)
{
    a=max(arr[i],arr[n-1]);
    if(a==arr[i])
        i++;
    else
        n--;
    ans1+=a;
   // cout<<"ans1"<<ans1<<endl;
    b=max(arr[i],arr[n-1]);
if(b==arr[i])
    i++;
    else
        n--;
        ans2+=b;
       // cout<<"ans2"<<ans2<<endl;
}
//cout<<"i "<< i<<endl;

if((m/2)%2==1)
    ans1+=arr[i];

cout<<ans1<<" "<<ans2<<endl;
}
    return 0;
}


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

	 }
    cout<<pirveli<<" "<<meore;
 //   system("pause");

}


# include <iostream>
using namespace std;
int n,a[100005],p,pirveli, meore,k;
int main()
{
    cin>>n;
    for (int i=1; i<=n; i++)
    cin>>a[i];
    p=n;
    k=1;
    for (int i=1; i<=p; i++)
    {
    if (a[i]>=a[p] && k%2==1 ) pirveli+=a[i];
    else
    if (a[i]>=a[p] && k%2==0) meore+=a[i];
    else
    if (a[i]<=a[p] && k%2==0) {  i--; meore+=a[p]; p--; }
    else
    if (a[i]<=a[p] && k%2==1) { i--;  pirveli+=a[p]; p--; }
   //cout<<pirveli<<" "<<meore<<endl;
	 k++;

	 }
    cout<<pirveli<<" "<<meore;
   // system("pause");

}


# include <iostream>
# include <algorithm>
using namespace std;
int n,a[100005],pirveli,meore;
int main()
{
 	 cin>>n;
 	 for(int i=0; i<n; i++)
 	 cin>>a[i];
 	 sort(a,a+n);
 	 reverse(a, a+n);
	  for (int i=0; i<n; i++)
 	 if (i%2==0) pirveli+=a[i];
 	 else meore+=a[i];
 	 cout<<pirveli<<" "<<meore;

}


# include <iostream>
using namespace std;
int n,a[100005],p,pirveli, meore;
int main()
{
    cin>>n;
    for (int i=1; i<=n; i++)
    cin>>a[i];
    p=n;

    for (int i=1; i<=n; i++)
    {
    if (a[i]>=a[p] && i%2==1) pirveli+=a[i];
    else
    if (a[i]<=a[p] && i%2==1) {  pirveli+=a[p]; p--; }
    else
    if (a[i]>=a[p] && i%2==0) meore+=a[i];
    else
    if (a[i]<=a[p] && i%2==0) {  meore+=a[p]; p--; }
    }
    cout<<pirveli<<" "<<meore;

}


# include <iostream>
using namespace std;
int n,a[100005],p,n,pirveli, meore;
int main()
{
    cin>>n;
    for (int i=1; i<=n; i++)
    cin>>a[i];
    p=n;

    for (int i=1; i<=n; i++)
    {
    if (a[i]>=a[p] && i%2==1) pirveli+=a[i];
    else
    if (a[i]<=a[p] && i%2==1) {  pirveli+=a[p]; p--; }
    else
    if (a[i]>=a[p] && i%2==0) meore+=a[i];
    else
    if (a[i]<=a[p] && i%2==0) {  meore+=a[p]; p--; }
    }
    cout<<pirveli<<" "<<meore;
}


# include <iostream>
using namespace std;
int n,a[100005],p,pirveli, meore;
int main()
{
    cin>>n;
    for (int i=1; i<=n; i++)
    cin>>a[i];
    p=n;

    for (int i=1; i<=n; i++)
    {
    if (a[i]>=a[p] && i%2==1) pirveli+=a[i];
    else
    if (a[i]<=a[p] && i%2==1) {  pirveli+=a[p]; p--; }
    else
    if (a[i]>=a[p] && i%2==0) meore+=a[i];
    else
    if (a[i]<=a[p] && i%2==0) {  meore+=a[p]; p--; }
    }
    cout<<pirveli<<" "<<meore;
}


# include <iostream>
using namespace std;
int n,a[100005],p,pirveli, meore,k;
int main()
{
    cin>>n;
    for (int i=1; i<=n; i++)
    cin>>a[i];
    p=n;
    k=1;
    for (int i=1; i<=p; i++)
    {
    if (a[i]>=a[p] && k%2==1 ) pirveli+=a[i];
    else
    if (a[i]>=a[p] && k%2==0) meore+=a[i];
    else
    if (a[i]<=a[p] && k%2==0) {  i--; meore+=a[p]; p--; }
    else
    if (a[i]<=a[p] && k%2==1) { i--;  pirveli+=a[p]; p--; }
   //cout<<pirveli<<" "<<meore<<endl;
	 k++;

	 }
   // cout<<pirveli<<" "<<meore;
    system("pause");

}


#include <stdio.h>
#include <string.h>
int x[1001];
int sereja=0;
void run(int l,int r,bool type){
	if(l==r)
	{
		if(type)sereja+=x[l];
		return;
	}
	if(x[l]<x[r]){
		if(type){
			sereja+=x[r];
		}
		run(l,r--,!type);
	}
	else{
		if(type){
			sereja+=x[l];
		}
		run(l++,r,!type);
	}
}

int main(){
	int n;
	scanf("%d",&n);
	int total=0;
	for(int i=0;i<n;i++){scanf("%d\n",&x[i]);total+=x[i];}
	run(0,n-1,true);
	printf("%d %d\n",sereja,total-sereja);
	return 0;
}


#include <stdio.h>
#include <string.h>
int x[1001];
int sereja=0;
void run(int l,int r,bool type){
	if(l==r)
	{
		if(type)sereja+=x[l];
		return;
	}
	if(x[l]<x[r]){
		if(type){
			sereja+=x[r];
		}
		run(l,r-1,!type);
	}
	else{
		if(type){
			sereja+=x[l];
		}
		run(l+1,r,!type);
	}
}

int main(){
	int n;
	scanf("%d",&n);
	int total=0;
	for(int i=0;i<n;i++){scanf("%d\n",&x[i]);total+=x[i];}
	run(0,n-1,true);
	printf("%d %d\n",sereja,total-sereja);
	return 0;
}


#include <stdio.h>
#include <string.h>
int x[1001];
int sereja=0;
void run(int l,int r,bool type){
	if(l==r)
	{
		if(type)sereja+=x[l];
		return;
	}
	if(x[l]<x[r]){
		if(type){
			sereja+=x[r];
			run(l,r-1,true);
		}
		else{run(l,r-1,false);}
	}
	else{
		if(type){
			sereja+=x[l];
			run(l+1,r,true);
		}
		else{run(l+1,r,false);}
	}
}

int main(){
	int n;
	scanf("%d",&n);
	int total=0;
	for(int i=0;i<n;i++){scanf("%d\n",&x[i]);total+=x[i];}
	run(0,n-1,true);
	printf("%d %d\n",sereja,total-sereja);
	return 0;
}


#include <stdio.h>
#include <string.h>
int x[1001];
int sereja=0;
void run(int l,int r,bool type){
	if(l==r&&type)
	{
		sereja+=x[l];
		return;
	}
	if(x[l]<x[r]){
		if(type){
			sereja+=x[r];
		}
		run(l,r--,!type);
	}
	else{
		if(type){
			sereja+=x[l];
		}
		run(l++,r,!type);
	}
}

int main(){
	int n;
	scanf("%d",&n);
	int total=0;
	for(int i=0;i<n;i++){scanf("%d\n",&x[i]);total+=x[i];}
	run(0,n-1,true);
	printf("%d %d\n",sereja,total-sereja);
	return 0;
}


#include <stdio.h>
#include <string.h>
int x[1001];
int sereja=0;
void run(int l,int r,bool type){
	if(l==r)
	{
		if(type)sereja+=x[l];
		return;
	}
	if(x[l]<x[r]){
		if(type){
			sereja+=x[r];
		}
		else{run(l,r-1,!type);}
	}
	else{
		if(type){
			sereja+=x[l];
		}
		else{run(l+1,r,!type);}
	}
}

int main(){
	int n;
	scanf("%d",&n);
	int total=0;
	for(int i=0;i<n;i++){scanf("%d\n",&x[i]);total+=x[i];}
	run(0,n-1,true);
	printf("%d %d\n",sereja,total-sereja);
	return 0;
}


#include <stdio.h>
#include <string.h>
int x[1001];
int sereja=0;
void run(int l,int r,bool type){
	if(l==r)
	{
		if(type)sereja+=x[l];
		return;
	}
	if(x[l]<x[r]){
		if(type){
			sereja+=x[r];
			run(l,r--,true);
		}
		else{run(l,r--,false);}
	}
	else{
		if(type){
			sereja+=x[l];
			run(l++,r,true);
		}
		else{run(l++,r,false);}
	}
}

int main(){
	int n;
	scanf("%d",&n);
	int total=0;
	for(int i=0;i<n;i++){scanf("%d\n",&x[i]);total+=x[i];}
	run(0,n-1,true);
	printf("%d %d\n",sereja,total-sereja);
	return 0;
}


#include <stdio.h>
#include <string.h>
int x[1001];
int sereja=0;
void run(int l,int r,bool type){
	if(l==r)
	{
		if(type)sereja+=x[l];
		return;
	}
	if(x[l]<x[r]){
		if(type){
			sereja+=x[r];
		}
		run(l,r-1,!type);
	}
	else{
		if(type){
			sereja+=x[l];
		}
		run(l++,r,!type);
	}
}

int main(){
	int n;
	scanf("%d",&n);
	int total=0;
	for(int i=0;i<n;i++){scanf("%d\n",&x[i]);total+=x[i];}
	run(0,n-1,true);
	printf("%d %d\n",sereja,total-sereja);
	return 0;
}


#include <stdio.h>
#include <string.h>
int x[1001];
int sereja=0;
void run(int l,int r,bool type){
	if(l==r)
	{
		if(type)sereja+=x[l];
		return;
	}
	if(x[l]<x[r]){
		if(type){
			sereja+=x[r];
			run(l,r-1,false);
		}
		else{run(l,r-1,true);}
	}
	else{
		if(type){
			sereja+=x[l];
			run(l+1,r,false);
		}
		else{run(l+1,r,true);}
	}
}

int main(){
	int n;
	scanf("%d",&n);
	int total=0;
	for(int i=0;i<n;i++){scanf("%d\n",&x[i]);total+=x[i];}
	run(0,n-1,true);
	printf("%d %d\n",sereja,total-sereja);
	return 0;
}


#include <stdio.h>
#include <string.h>
int x[1001];
int sereja=0;
void run(int l,int r,bool type){
	if(l==r&&type)
	{
		sereja+=x[l];
		return;
	}
	if(x[l]<x[r]){
		if(type){
			sereja+=x[r];
		}
		run(l,--r,!type);
	}
	else{
		if(type){
			sereja+=x[l];
		}
		run(++l,r,!type);
	}
}

int main(){
	int n;
	scanf("%d",&n);
	int total=0;
	for(int i=0;i<n;i++){scanf("%d\n",&x[i]);total+=x[i];}
	run(0,n-1,true);
	printf("%d %d\n",sereja,total-sereja);
	return 0;
}


#include <stdio.h>
#include <string.h>
int x[1001];
int sereja=0;
void run(int l,int r,bool type){
	if(l==r)
	{
		if(type)sereja+=x[l];
		return;
	}
	if(x[l]<x[r]){
		if(type){
			sereja+=x[r];
		}
		run(l,r-1,!type);
	}
	else{
		if(type){
			sereja+=x[l];
		}
		run(++l,r,!type);
	}
}

int main(){
	int n;
	scanf("%d",&n);
	int total=0;
	for(int i=0;i<n;i++){scanf("%d\n",&x[i]);total+=x[i];}
	run(0,n-1,true);
	printf("%d %d\n",sereja,total-sereja);
	return 0;
}


#include <stdio.h>
#include <string.h>
int x[1001];
int sereja=0;
void run(int l,int r,bool type){
	if(l==r&&type)
	{
		sereja+=x[l];
		return;
	}
	if(x[l]<x[r]){
		if(type){
			sereja+=x[r];
			run(l,r--,false);
		}
		run(l,r--,true);
	}
	else{
		if(type){
			sereja+=x[l];
			run(l++,r,false);
		}
		run(l++,r,true);
	}
}

int main(){
	int n;
	scanf("%d",&n);
	int total=0;
	for(int i=0;i<n;i++){scanf("%d\n",&x[i]);total+=x[i];}
	run(0,n-1,true);
	printf("%d %d\n",sereja,total-sereja);
	return 0;
}


#include <iostream>
#include <algorithm>

using namespace std;

int n,a[100009];

int main()
{

    cin >> n;

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

    int l=0,r=n-1,f=0,s=0;
    bool one=1;

    while(l<=n)
        if ( a[l] > a[n] )
        {
            if ( one )
                f+=a[l],one=0;
            else
                s+=a[r],one=1;

            l++;
        }

        else
        {
            if ( one )
                f+=a[l],one=0;
            else
                s+=a[r],one=1;
            r--;
        }

    cout << f << " " << s;

    return 0;
}


#include <iostream>
#include <algorithm>

using namespace std;

int n,a[1000009];

int main()
{

    cin >> n;

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

    int l=0,r=n-1,f=0,s=0;
    bool one=1;

    while(l<=n)
        if ( a[l] > a[n] )
        {
            if ( one )
                f+=a[l],one=0;
            else
                s+=a[r],one=1;

            l++;
        }

        else
        {
            if ( one )
                f+=a[l],one=0;
            else
                s+=a[r],one=1;
            r--;
        }

    cout << f << " " << s;

    return 0;
}


#include <iostream>
#include <algorithm>

using namespace std;

int n,a[1000009];

int main()
{

    cin >> n;

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

    int l=0,r=n-1,f=0,s=0;
    int cnt=0;

    while(l<=r)
        if ( a[l] > a[r] )
        {
            if ( one )
                f+=a[l],one=0;
            else
                s+=a[r],one=1;

            l++;
        }

        else
        {
            if ( one )
                f+=a[l],one=0;
            else
                s+=a[r],one=1;
            r--;
        }

    cout << f << " " << s;

    return 0;
}


#include <iostream>
#include <algorithm>

using namespace std;

int n,a[100009];

int main()
{

    cin >> n;

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

    int l=0,r=n-1,f=0,s=0;
    bool one=1;

    while(l<=n)
    	if ( a[l] > a[n] )
    	{
			if ( one )
				f+=a[l],one=0;
			else
				s+=a[r],one=1;

			l++;
		}

		else
		{
			if ( one )
				f+=a[l],one=0;
			else
				s+=a[r],one=1;
			r--;
		}

	cout << f << " " << s;

    return 0;
}


#include <iostream>
#include <algorithm>

using namespace std;

int n,a[100009];

int main()
{

    cin >> n;

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

    int l=0,r=n-1,f=0,s=0;
    bool one=1;

    while(l<=r)
        if ( a[l] > a[r] )
        {
            if ( one )
                f+=a[l],one=0;
            else
                s+=a[l],one=1;

            l++;
        }

        else
        {
            if ( one )
                f+=a[r],one=0;
            else
                s+=a[r],one=1;
            r--;
        }

    cout << f << " " << s;

    return 0;
}


#include <iostream>
#include <algorithm>

using namespace std;

int n,a[100009];

int main()
{

    cin >> n;

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

    int l=0,r=n-1,f=0,s=0;
    bool one=1;

    while(l<=n)
    	if ( a[l] > a[n] )
			if ( one )
				f+=a[l],one=0;
			else
				s+=a[r],one=1;

		else
			if ( one )
				f+=a[l],one=0;
			else
				s+=a[r],one=1;

	cout << f << " " << s;

    return 0;
}


#include <iostream>
#include <algorithm>

using namespace std;

int n,a[100009];

int main()
{

    cin >> n;

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

    sort(a,a+n);

    bool one=0;
    int f=0,s=0;

    for ( int i = n-1; i >= 0; i-- )
        if ( one )
            s+=a[i],one=0;
        else
            f+=a[i],one=1;

    cout << f << " " << s;

    return 0;
}


#In The Nam Of GOd

n=int(input());
if(n==1):
    print("YES",1);
    exit();
if(n==2):
    print("YES",1,2,sep="\n");
    exit();
if(n==4):
    print("YES",1,3,2,4,sep="\n");
    exit();
for i in range(2,n):
    if n%i==0:
        print("NO");
        exit();

print("YES",1,sep="\n");
for i in range (2,n):
    print((i*pow(i-1,n-2))%n);
print(n);


#In The Nam Of GOd

n=int(input());
if(n==1):
    print("YES",1);
    exit();
if(n==2):
    print("YES",1,2,sep="\n");
    exit();
if(n==4):
    print("YES",1,3,2,4,sep="\n");
    exit();
for i in range(2,n):
    if n%i==0:
        print("NO");
        exit();

print("YES",1,sep="\n");
for i in range (2,n):
    print(i,(i*pow(i-1,n-2))%n);
print(n);


n = int(input())
if n == 4:
    print ("YES\n1 3 2 4")
elif [i for i in range(2,n) if n%i==0]:
    print("NO")
else:
    print("YES\n1 %s"%(" ".join(str((pow(x+1,n-2,n)*(x+2))%n or n) for x in range(n-1))))


from sys import stdout
def main():
    n = int(raw_input())
    if n == 1:
        print "YES"
        print 1
        return
    if n == 2:
        print "YES"
        print 1
        print 2
        return
    if n == 4:
        print "YES"
        print 1
        print 3
        print 2
        print 4
        return
    a = [0] * (n + 10)
    for i in xrange(2, n + 10):
        if a[i]:
            continue
        j = i + i
        while j < n + 10:
            a[j] = i
            j += i
    if a[n]:
        print "NO"
        return
    b = range(2, n)
    ans = [1, b[0]]
    for i in xrange(1, n-2):
        x = b[i] * pow(b[i-1], n-2, n) % n
        ans.append(x)
    print "YES"
    ans += [n]
    stdout.write("\n".join(map(str, ans)))
main()


from sys import stdout
def main():
    n = int(raw_input())
    if n == 1:
        print "YES"
        print 1
        return
    if n == 2:
        print "YES"
        print 1
        print 2
        return
    a = [0] * (n + 10)
    for i in xrange(2, n + 10):
        if a[i]:
            continue
        j = i + i
        while j < n + 10:
            a[j] = i
            j += i
    if a[n]:
        print "NO"
        return
    b = range(2, n)
    while 1:
        ans = [1, b[0]]
        s = set()
        for i in xrange(1, n-2):
            x = b[i] * pow(b[i-1], n-2, n) % n
            if x not in s:
                ans.append(x)
                s.add(x)
            else:
                break
        if len(ans) == n - 1:
            print "YES"
            ans += [n]
            stdout.write("\n".join(map(str, ans)))
            return
    b = n - 1
    p = []
    while a[b]:
        p.append(a[b])
        b /= a[b]
    p = set(p + [b])
    for i in xrange(2, n):
        if all(pow(i, (n-1)/x, n) != 1 for x in p):
            b = i
            break
main()


#!/usr/bin/python
# coding: utf-8

def isPrime(n):
  if n == 2:
    return True
  if n % 2 == 0:
    return False
  for i in xrange(3, (int)(n ** 0.5) + 1, 2):
    if n % i == 0:
      return False
  return True
n = input()
if n == 1:
  print 'YES\n1'
elif n == 4:
  print 'YES\n1\n3\n2\n4'
elif not isPrime(n):
  print 'NO'
else:
  print 'YES\n1'
  inv = [0, 1]
  for i in xrange(2, n):
    inv.append((n - n / i) * inv[n % i] % n)
    print i * inv[i - 1] % n
  print n


import sys

def egcd(a, b):
    if a == 0:
        return (b, 0, 1)
    else:
        g, y, x = egcd(b % a, a)
        return (g, x - (b // a) * y, y)

def modinv(a, m):
    g, x, y = egcd(a, m)
    assert(g == 1)
    return x % m

def solve(n):
    if n == 1:
        return [1]
    if n == 4:
        return [1, 3, 2, 4]
    return [1] + [(i*modinv(i-1, n))%n for i in xrange(2, n)] + [n]

n = int(sys.stdin.readline())
try:
    s = solve(n)
    print 'YES'
    for x in s:
        print x
except:
    print 'NO'


n = int(raw_input())
if n==1:
    print "YES"
    print 1
elif n==4:
    for i in [1,3,2,4]:
        print i
era = [1] * (n+2)
era[0]=0
era[1]=0
for i in range(2,n+2):
    if era[i]==1:
        for j in range(i*i,n+2,i):
            era[j]=0
if era[n]==1:
    print "YES"
    print 1
    for i in range(2,n):
        print (i*pow(i-1,n-2,n))%n
    print n
else:
    print "NO"


n = int(raw_input())
if n==1:
    print "YES"
    print 1
elif n==4:
    for i in [1,3,2,4]:
        print i
else:
    era = [1] * (n+2)
    era[0]=0
    era[1]=0
    for i in range(2,n+2):
        if era[i]==1:
            for j in range(i*i,n+2,i):
                era[j]=0
    if era[n]==1:
        print "YES"
        print 1
        for i in range(2,n):
            print (i*pow(i-1,n-2,n))%n
        print n
    else:
        print "NO"


n = int(raw_input())
if n==1:
    print "YES"
    print 1
elif n==4:
    print "YES"
    for i in [1,3,2,4]:
        print i
else:
    era = [1] * (n+2)
    era[0]=0
    era[1]=0
    for i in range(2,n+2):
        if era[i]==1:
            for j in range(i*i,n+2,i):
                era[j]=0
    if era[n]==1:
        print "YES"
        print 1
        for i in range(2,n):
            print (i*pow(i-1,n-2,n))%n
        print n
    else:
        print "NO"


from math import sqrt
n=input()
if n==4 :
    print "YES"
    print 1
    print 3
    print 2
    print 4
elif n==1:
    print "yes"
    print 1
else :
    prime=[1]*(n+1)
    prime[0]=0
    prime[1]=0
    i=2
    while i<= int(sqrt(n))+1:
        if prime[i]==1:
            for s in range(i*i,n+1,i):
                prime[s]=0
        if prime[n]==0:
            break
        i=i+1
    if prime[n]:
        print "YES"
        print 1
        i=2
        while i<n:
            print ((i*pow(i-1,n-2,n))%n)
            i=i+1
        print n
    else:
        print "NO"


n=input()
if n==4 :
    print "Yes"
    print 1
    print 3
    print 2
    print 4
else :
    prime=[1]*(n+1)
    prime[0]=0
    prime[1]=0
    i=2
    while i<=n:
        if prime[i]==1:
            j=2
            while j<=(n/i):
                prime[j*i]=0
                j=j+1
        if prime[n]==0:
            break
        i=i+1
    if prime[n]:
        print "Yes"
        print 1
        i=2
        while i<n:
            print ((i*((i-1)**(n-2))) % n)
            i=i+1
        print n
    else:
        print "No"


from math import sqrt
n=input()
if n==4 :
    print "YES"
    print 1
    print 3
    print 2
    print 4
else :
    prime=[1]*(n+1)
    prime[0]=0
    prime[1]=0
    i=2
    while i<= int(sqrt(n))+1:
        if prime[i]==1:
            for s in range(i*i,n+1,i):
                prime[s]=0
        if prime[n]==0:
            break
        i=i+1
    if prime[n]:
        print "YES"
        print 1
        i=2
        while i<n:
            print ((i*pow(i-1,n-2,n))%n)
            i=i+1
        print n
    else:
        print "NO"


from math import sqrt
n=input()
if n==4 :
    print "YES"
    print 1
    print 3
    print 2
    print 4
elif n==1:
    print "YES"
    print 1
else :
    prime=[1]*(n+1)
    prime[0]=0
    prime[1]=0
    i=2
    while i<= int(sqrt(n))+1:
        if prime[i]==1:
            for s in range(i*i,n+1,i):
                prime[s]=0
        if prime[n]==0:
            break
        i=i+1
    if prime[n]:
        print "YES"
        print 1
        i=2
        while i<n:
            print ((i*pow(i-1,n-2,n))%n)
            i=i+1
        print n
    else:
        print "NO"


n=input()
if n==4 :
    print "YES"
    print 1
    print 3
    print 2
    print 4
else :
    prime=[1]*(n+1)
    prime[0]=0
    prime[1]=0
    i=2
    while i<=n:
        if prime[i]==1:
            j=2
            while j<=(n/i):
                prime[j*i]=0
                j=j+1
        if prime[n]==0:
            break
        i=i+1
    if prime[n]:
        print "YES"
        print 1
        i=2
        while i<n:
            print ((i*((i-1)**(n-2))) % n)
            i=i+1
        print n
    else:
        print "NO"


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

n = input()

if n == 1:
    print 'YES'
    print 1
elif n == 4:
    print 'YES'
    print 1
    print 3
    print 2
    print 4
elif:
    if not prime(n): print 'NO'
    else:
        print 'YES'
        print 1
        for i in xrange(2,n):
            print pow(i,n-2,n)
        print n


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

n = input()

if n == 1:
    print 'YES'
    print 1
elif n == 4:
    print 'YES'
    print 1
    print 3
    print 2
    print 4
else:
    if not prime(n): print 'NO'
    else:
        print 'YES'
        print 1
        for i in xrange(2,n):
            print i*pow(i-1,n-2,n)%n
        print n


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

n = input()

if n == 1:
    print 'YES'
    print 1
elif n == 4:
    print 'YES'
    print 1
    print 3
    print 2
    print 4
else:
    if not prime(n): print 'NO'
    else:
        print 'YES'
        print 1
        for i in xrange(2,n):
            print pow(i,n-2,n)
        print n


#include<stdio.h>
#include<math.h>
int main()
{
    int i,j,n;
    scanf("%d",&n);
    if(n==1){puts("YES\n1");return 0;}
    if(n==4){puts("YES\n1\n3\n2\n4");return 0;}
    for(i=2;i*i<=n;i++){
        if(n%i==0){puts("NO");return 0;}
    }

    puts("YES\n1");
    for(i=2;i<n;i++){
        for(j=1;j<n;j++){
            if((j*(i-1))%n==i){printf("%d\n",j);break;}
        }
    }
    printf("%d\n",n);
}


#include<stdio.h>
#include<math.h>

long long i,j,n;

long long ksm(long long a,long long p){
    long long res=1;
    while(p){
    if(p&1){res=res*a%n;}
        a=a*a%n;p>>=1;
    }
    return res;
}

int main()
{
    scanf("%lld",&n);
    if(n==1){puts("YES\n1");return 0;}
    if(n==4){puts("YES\n1\n3\n2\n4");return 0;}
    for(i=2;i*i<=n;i++){
        if(n%i==0){puts("NO");return 0;}
    }

    puts("YES\n1");
    for(i=2;i<n;i++){
        printf("%lld\n",i*ksm(i-1,n-2)%n);
    }
    printf("%lld\n",n);
}


#include<stdio.h>
#include<math.h>

long long i,j,n;

long long ksm(long long a,long long p){
    long long res=1;
    while(p){
    if(p&1){res=res*a%n;}
        a=a*a%n;p>>=1;
    }
    return res;
}

int main()
{
    scanf("%d",&n);
    if(n==1){puts("YES\n1");return 0;}
    if(n==4){puts("YES\n1\n3\n2\n4");return 0;}
    for(i=2;i*i<=n;i++){
        if(n%i==0){puts("NO");return 0;}
    }

    puts("YES\n1");
    for(i=2;i<n;i++){
        printf("%lld\n",i*ksm(i-1,n-2)%n);
    }
    printf("%d\n",n);
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Codeforces
{

    class Program
    {
        public static readonly int MOD = Convert.ToInt32(1e9 + 7);
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            if (n == 1)
            {
                Console.Write("YES\n1");
                return;
            }
            if (n == 4)
            {
                Console.Write("YES\n1\n3\n2\n4");
                return;
            }

            for (int i = 2; i <= Math.Sqrt(n); i++)
            {
                if (n % i == 0)
                {
                    Console.Write("NO");
                    return;
                }
            }

            StringBuilder ans = new StringBuilder();
            ans.Append("YES\n1\n");
            for (int i = 2; i < n; i++)
            {
                ans.Append(i * ModPow(i - 1, n - 2, n) % n + "\n");
            }
            ans.Append(n);
            Console.Write(ans);

        }

        static long ModPow(long num, long exponent, long mod)
        {
            if (exponent == 0) return 1;
            long m = ModPow(num, exponent >> 1, mod);
            return exponent % 2 == 0 ? m * m % mod : m * m % mod * num % mod;
        }

        static long Inv(long num, long mod)
        {
            return ModPow(num, MOD - 2, mod);
        }
    }

}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Codeforces
{

    class Program
    {
        public static readonly int MOD = Convert.ToInt32(1e9 + 7);
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            if (n == 1)
            {
                Console.Write(1);
                return;
            }
            if (n == 4)
            {
                Console.Write("YES\n1\n2\n3\n4");
                return;
            }

            for (int i = 2; i <= Math.Sqrt(n); i++)
            {
                if (n % i == 0)
                {
                    Console.Write("NO");
                    return;
                }
            }

            StringBuilder ans = new StringBuilder();
            ans.Append("YES\n1\n");
            for (int i = 2; i < n; i++)
            {
                ans.Append(i * ModPow(i - 1, n - 2) % n + "\n");
            }
            ans.Append(n);
            Console.Write(ans);

        }

        static long ModPow(long num, long exponent)
        {
            if (exponent == 0) return 1;
            long m = ModPow(num, exponent >> 1);
            return exponent % 2 == 0 ? m * m % MOD : m * m % MOD * num % MOD;
        }

        static long Inv(long num)
        {
            return ModPow(num, MOD - 2);
        }
    }

}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Codeforces
{

    class Program
    {
        public static readonly int MOD = Convert.ToInt32(1e9 + 7);
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            if (n == 1)
            {
                Console.Write("YES\n1");
                return;
            }
            if (n == 4)
            {
                Console.Write("YES\n1\n2\n3\n4");
                return;
            }

            for (int i = 2; i <= Math.Sqrt(n); i++)
            {
                if (n % i == 0)
                {
                    Console.Write("NO");
                    return;
                }
            }

            StringBuilder ans = new StringBuilder();
            ans.Append("YES\n1\n");
            for (int i = 2; i < n; i++)
            {
                ans.Append(i * ModPow(i - 1, n - 2, n) % n + "\n");
            }
            ans.Append(n);
            Console.Write(ans);

        }

        static long ModPow(long num, long exponent, long mod)
        {
            if (exponent == 0) return 1;
            long m = ModPow(num, exponent >> 1, mod);
            return exponent % 2 == 0 ? m * m % mod : m * m % mod * num % mod;
        }

        static long Inv(long num, long mod)
        {
            return ModPow(num, MOD - 2, mod);
        }
    }

}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Codeforces
{

    class Program
    {
        public static readonly int MOD = Convert.ToInt32(1e9 + 7);
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            if (n == 1)
            {
                Console.Write(1);
                return;
            }
            if (n == 4)
            {
                Console.Write("YES\n1\n2\n3\n4");
                return;
            }

            for (int i = 2; i <= Math.Sqrt(n); i++)
            {
                if (n % i == 0)
                {
                    Console.Write("NO");
                    return;
                }
            }

            StringBuilder ans = new StringBuilder();
            ans.Append("YES\n1\n");
            for (int i = 2; i < n; i++)
            {
                ans.Append(i * ModPow(i - 1, n - 2, n) % n + "\n");
            }
            ans.Append(n);
            Console.Write(ans);

        }

        static long ModPow(long num, long exponent, long mod)
        {
            if (exponent == 0) return 1;
            long m = ModPow(num, exponent >> 1, mod);
            return exponent % 2 == 0 ? m * m % mod : m * m % mod * num % mod;
        }

        static long Inv(long num, long mod)
        {
            return ModPow(num, MOD - 2, mod);
        }
    }

}


fn pow_mod(r: u64, mut n: u64, m: u32) -> u64 {
    assert!(m > 0);
    if m == 1 {
        return 0;
    }
    let m = m as u64;
    let mut t = 1;
    let mut s = r % m;
    while n > 0 {
        if n & 1 == 1 {
            t = t * s % m;
        }
        s = s * s % m;
        n >>= 1;
    }
    t
}

fn is_prime(n: u64) -> bool {
    (2u64..).take_while(|p| p * p <= n).all(|p| n % p != 0)
}

// ---------- begin input macro ----------
// reference: https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, bytes) => {
        read_value!($iter, String).bytes().collect::<Vec<u8>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}
// ---------- end input macro ----------

use std::io::Write;

fn run() {
    input! {
        n: usize,
    }
    if n == 1 {
        println!("YES\n1");
        return;
    }
    if n == 2 {
        println!("YES\n1\n2");
        return;
    }
    if n == 4 {
        println!("YES\n1\n3\n2\n4");
        return;
    }
    if !is_prime(n as u64) {
        println!("NO");
        return;
    }
    let mut ans = vec![1];
    for i in 1..(n - 1) {
        let v = ((i + 1) as u64 * pow_mod(i as u64, (n - 2) as u64, n as u32) % n as u64) as usize;
        ans.push(v);
    }
    ans.push(n);
    let out = std::io::stdout();
    let mut out = std::io::BufWriter::new(out.lock());
    writeln!(out, "YES").ok();
    for a in ans {
        writeln!(out, "{}", a).ok();
    }
}

fn main() {
    run();
}


fn pow_mod(r: u64, mut n: u64, m: u32) -> u64 {
    assert!(m > 0);
    if m == 1 {
        return 0;
    }
    let m = m as u64;
    let mut t = 1;
    let mut s = r % m;
    while n > 0 {
        if n & 1 == 1 {
            t = t * s % m;
        }
        s = s * s % m;
        n >>= 1;
    }
    t
}

fn is_prime(n: u64) -> bool {
    (2u64..).take_while(|p| p * p <= n).all(|p| n % p != 0)
}

// ---------- begin input macro ----------
// reference: https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, bytes) => {
        read_value!($iter, String).bytes().collect::<Vec<u8>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}
// ---------- end input macro ----------

use std::io::Write;

fn run() {
    input! {
        n: usize,
    }
    if n > 1 && !is_prime(n as u64) {
        println!("NO");
        return;
    }
    if n == 1 {
        println!("YES\n1");
        return;
    }
    if n == 2 {
        println!("YES\n1\n2");
        return;
    }
    if n == 4 {
        println!("YES\n1\n3\n2\n4");
        return;
    }
    let mut ans = vec![1];
    for i in 1..(n - 1) {
        let v = ((i + 1) as u64 * pow_mod(i as u64, (n - 2) as u64, n as u32) % n as u64) as usize;
        ans.push(v);
    }
    ans.push(n);
    let out = std::io::stdout();
    let mut out = std::io::BufWriter::new(out.lock());
    writeln!(out, "YES").ok();
    for a in ans {
        writeln!(out, "{}", a).ok();
    }
}

fn main() {
    run();
}


def is_prime(n):
	i = 2;
	while i*i <= n:
		if n%i == 0: return 0;
		i += 1;
	return n > 1;

n = int(raw_input());
if n == 1: print "YES\n",1;
elif n == 4: print "YES\n","4\n1\n3\n2\n4";
elif is_prime(n):
	ans = [i*pow(i-1,n-2,n) if i != 1 else 1 for i in xrange(1,n+1)];
	ans = [x%n for x in ans];
	ans = [x if x else n for x in ans];
	ans = [str(x) for x in ans];
	print "YES";
	print "\n".join(ans);
else: print "NO";


def is_prime(n):
	i = 2;
	while i*i <= n:
		if n%i == 0: return 0;
		i += 1;
	return n > 1;

n = int(raw_input());
if n == 1: print "YES\n",1;
elif n == 4: print "YES\n","4\n1\n3\n2\n4";
elif is_prime(n):
	ans = [i*pow(i-1,n-2,n) if i != 1 else 1 for i in xrange(1,n+1)];
	ans = [str(x%n) for x in ans];
	print "YES";
	print "\n".join(ans);
else: print "NO";


def is_prime(n):
	i = 2;
	while i*i <= n:
		if n%i == 0: return 0;
		i += 1;
	return n > 1;

n = int(raw_input());
if n == 1: print "YES\n",1;
elif n == 4: print "YES\n","1\n3\n2\n4";
elif is_prime(n):
	ans = [i*pow(i-1,n-2,n) if i != 1 else 1 for i in xrange(1,n+1)];
	ans = [x%n for x in ans];
	ans = [x if x else n for x in ans];
	ans = [str(x) for x in ans];
	print "YES";
	print "\n".join(ans);
else: print "NO";


def is_prime(n):
	i = 2;
	while i*i <= n:
		if n%i == 0: return 0;
		i += 1;
	return n > 1;

n = int(raw_input());
if n == 1: print "YES\n",1;
elif n == 4: print "YES\n","4\n1\n3\n2\n4";
elif is_prime(n):
	ans = [i*pow(i-1,n-2,n) if i != 1 else 1 for i in xrange(1,n+1)];
	ans = [str(x) for x in ans];
	print "YES";
	print "\n".join(ans);
else: print "NO";


import math
import sys
input = sys.stdin.readline
n = int(input())
def isPrime(n):
    for i in range(2, n):
        if n % i == 0:
            return False
    return True
if isPrime(n):
    print('YES')
    print('\n'.join(list(map(str, [1] + [i * pow(i - 1, n - 2, n) % n for i in range(2, n)] + [n]))[:n]))
elif n == 4:
    print('YES')
    print('\n'.join(map(str, [1, 3, 2, 4])))
else:
    print('NO')


import math
import sys
input = sys.stdin.readline
n = int(input())
if math.factorial(n - 1) % n == n - 1:
    print('YES')
    print('\n'.join(list(map(str, [1] + [i * pow(i - 1, n - 2, n) % n for i in range(2, n)] + [n]))[:n]))
elif n == 4:
    print('YES')
    print('\n'.join(map(str, [1, 3, 2, 4])))
else:
    print('NO')


import math
import sys
input = sys.stdin.readline
n = int(input())
def isPrime(n):
    for i in range(2, n):
        if n % i == 0:
            return False
    return True
if isPrime(n):
    print('YES')
    print('\n'.join(map(str, [1] + [i * pow(i - 1, n - 2, n) % n for i in range(2, n)] + [n])))
elif n == 4:
    print('YES')
    print('\n'.join(map(str, [1, 3, 2, 4])))
else:
    print('NO')


using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;

// (づ°ω°)づﾐ★゜・。。・゜゜・。。・゜☆゜・。。・゜゜・。。・゜
public class Solver
{
    long ModPow(long x, long p, long m)
    {
        long ret = 1;
        while (p > 0)
        {
            if ((p & 1) == 1)
                ret = ret * x % m;
            x = x * x % m;
            p >>= 1;
        }
        return ret;
    }

    long Inv(long x, long m)
    {
        return ModPow(x, m - 2, m);
    }

    public object Solve()
    {
        int n = ReadInt();

        if (n > 5)
            for (int i = 2; i * i <= n; i++)
                if (n % i == 0)
                    return "NO";

        var ans = new long[n];
        ans[0] = 1;
        ans[n - 1] = n;

        if (n == 4)
        {
            ans[1] = 3;
            ans[2] = 2;
        }
        else
        {
            for (int i = 1; i < n - 1; i++)
                ans[i] = Inv(i, n) * (i + 1) % n;
        }

        Write("YES");
        for (int i = 0; i < n; i++)
            Write(ans[i]);

        return null;
    }

    #region Main

    protected static TextReader reader;
    protected static TextWriter writer;

    static void Main()
    {
#if DEBUG
        reader = new StreamReader("..\\..\\input.txt");
        writer = Console.Out;
        //writer = new StreamWriter("..\\..\\output.txt");
#else
        reader = new StreamReader(Console.OpenStandardInput());
        writer = new StreamWriter(Console.OpenStandardOutput());
        //reader = new StreamReader("instruction.in");
        //writer = new StreamWriter("instruction.out");
#endif
        try
        {
            object result = new Solver().Solve();
            if (result != null)
                writer.WriteLine(result);
        }
        catch (Exception ex)
        {
#if DEBUG
            Console.WriteLine(ex);
#else
            Console.WriteLine(ex);
            throw;
#endif
        }
        reader.Close();
        writer.Close();
    }

    #endregion

    #region Read / Write

    private static Queue<string> currentLineTokens = new Queue<string>();

    private static string[] ReadAndSplitLine()
    {
        return reader.ReadLine().Split(new[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
    }

    public static string ReadToken()
    {
        while (currentLineTokens.Count == 0)
            currentLineTokens = new Queue<string>(ReadAndSplitLine());
        return currentLineTokens.Dequeue();
    }

    public static int ReadInt()
    {
        return int.Parse(ReadToken());
    }

    public static long ReadLong()
    {
        return long.Parse(ReadToken());
    }

    public static double ReadDouble()
    {
        return double.Parse(ReadToken(), CultureInfo.InvariantCulture);
    }

    public static int[] ReadIntArray()
    {
        return ReadAndSplitLine().Select(int.Parse).ToArray();
    }

    public static long[] ReadLongArray()
    {
        return ReadAndSplitLine().Select(long.Parse).ToArray();
    }

    public static double[] ReadDoubleArray()
    {
        return ReadAndSplitLine().Select(s => double.Parse(s, CultureInfo.InvariantCulture)).ToArray();
    }

    public static int[][] ReadIntMatrix(int numberOfRows)
    {
        int[][] matrix = new int[numberOfRows][];
        for (int i = 0; i < numberOfRows; i++)
            matrix[i] = ReadIntArray();
        return matrix;
    }

    public static int[][] ReadAndTransposeIntMatrix(int numberOfRows)
    {
        int[][] matrix = ReadIntMatrix(numberOfRows);
        int[][] ret = new int[matrix[0].Length][];
        for (int i = 0; i < ret.Length; i++)
        {
            ret[i] = new int[numberOfRows];
            for (int j = 0; j < numberOfRows; j++)
                ret[i][j] = matrix[j][i];
        }
        return ret;
    }

    public static string[] ReadLines(int quantity)
    {
        string[] lines = new string[quantity];
        for (int i = 0; i < quantity; i++)
            lines[i] = reader.ReadLine().Trim();
        return lines;
    }

    public static void WriteArray<T>(IEnumerable<T> array)
    {
        writer.WriteLine(string.Join(" ", array));
    }

    public static void Write<T>(params T[] array)
    {
        WriteArray(array);
    }

    public static void WriteLines<T>(IEnumerable<T> array)
    {
        foreach (var a in array)
            writer.WriteLine(a);
    }

    #endregion
}


#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define int long long
using namespace std;
int n;
bool prime(int x){
    for(int i=2;i<=sqrt(x);i++)if(x%i==0)return 0;
    return 1;
}
int powe(int x,int y){
    if(y==0)return 1;
    return y%2 ? (powe(x,y/2)*powe(x,y/2))%n : (powe(x,y-1)*x)%n;
}
main() {
    cin>>n;
    if(n==1)return cout<<"YES"<<endl<<1,0;
    if(n==4)return cout<<"YES"<<endl<<1<<endl<<3<<endl<<2<<endl<<4,0;
    if(!prime(n))return cout<<"NO",0;
    cout<<"YES"<<endl<<1<<endl;
    for(int i=2;i<n;i++)cout<<powe(i-1,n-2)*i%n<<endl;
    cout<<n<<endl;
}


#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define int long long
using namespace std;
int n;
bool prime(int x){
    for(int i=2;i<=sqrt(x);i++)if(x%i==0)return 0;
    return 1;
}
int powe(int x,int y){
    if(y==0)return 1;
    int t=powe(x,y/2);
    if(y%2)return (x*t*t)%n;
    else return (t*t)%n;
}
main() {
    cin>>n;
    if(n==1)return cout<<"YES"<<endl<<1,0;
    if(n==4)return cout<<"YES"<<endl<<1<<endl<<3<<endl<<2<<endl<<4,0;
    if(!prime(n))return cout<<"NO",0;
    cout<<"YES"<<endl<<1<<endl;
    for(int i=2;i<n;i++)cout<<(powe(i-1,n-2)*i)%n<<endl;
    cout<<n<<endl;
}


#include <iostream>
using namespace std;

typedef long long ll;

bool prime(ll n){
    if(n == 1) return false;
    for(ll j=2; j*j<=n; j++)
        if(n%j == 0) return false;
    return true;
}

ll mod_pow(ll b, ll e, ll m){
    if(e == 0) return 1LL;
    long long res = mod_pow((b*b)%m, e/2, m);
    return (res * ((e%2)?b:1)) % m;
}

ll N;

int main(){
    cin >> N;
    if(N > 4 && !prime(N)){ cout << "NO" << endl; return 0; }
    cout << "YES\n";

    if(N == 4){ cout << "1\n3\n2\n4" << endl; return 0; }
    else{
        ll v = 1; cout << v << "\n";
        for(ll i=2; i<=N; i++){
            ll res = (i * mod_pow(v, N-2, N)) % N;
            if(!res) res += N;
            cout << res << "\n";
            v = (v * res) % N;
        }
    }

    cout.flush();
    return 0;
}


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

int N;

bool is_prime(int x){
  for(int i = 2; i * i <= x; i++){
    if(x % i == 0) return 0;
  }
  return x > 2;
}

int modpow(int x, int p, int m){
  if(p == 0) return 1;
  int s = modpow(x, p / 2, m);
  return s * s % m * (p & 1 ? x : 1) % m;
}

int main(){
  cin >> N;
  if(N == 1){
    cout << "YES\n1\n";
  } else if(N == 4){
    cout << "YES\n1\n3\n2\n4\n";
  } else if(is_prime(N)){
    int k = N - 1, r;
    vector<int> v;
    for(int i = 2; i <= k; i++){
      if(k % i != 0) continue;
      v.push_back(i);
      while(k % i == 0) k /= i;
    }
    for(r = 1; r < N; r++){
      bool ok = 1;
      for(int j = 0; j < v.size(); j++){
        ok &= (modpow(r, v[j], N) != 1);
      }
      if(ok) break;
    }
    cout << "YES\n";
    for(int i = 1; i < N; i++){
      cout << modpow(r, i % 2 ? i - 1 : N - i, N) << '\n';
    }
    cout << N << '\n';
  } else cout << "NO\n";
}


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

typedef long long ll;

int N;

bool is_prime(int x){
  for(int i = 2; i * i <= x; i++){
    if(x % i == 0) return 0;
  }
  return x > 2;
}

int modpow(int x, int p, int m){
  if(p == 0) return 1;
  ll s = modpow(x, p / 2, m);
  return s * s % m * (p & 1 ? x : 1) % m;
}

int main(){
  cin >> N;
  if(N == 1){
    cout << "YES\n1\n";
  } else if(N == 4){
    cout << "YES\n1\n3\n2\n4\n";
  } else if(is_prime(N)){
    int k = N - 1, r;
    vector<int> v;
    for(int i = 2; i <= k; i++){
      if(k % i != 0) continue;
      v.push_back(i);
      while(k % i == 0) k /= i;
    }
    for(r = 2; r < N; r++){
      bool ok = 1;
      for(int j = 0; j < v.size(); j++){
        ok &= (modpow(r, (N - 1) / v[j], N) != 1);
      }
      if(ok) break;
    }
    cout << "YES\n";
    for(int i = 1; i < N; i++){
      cout << modpow(r, i % 2 ? i - 1 : N - i, N) << '\n';
    }
    cout << N << '\n';
  } else cout << "NO\n";
}


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

typedef long long ll;

int N;

bool is_prime(int x){
  for(int i = 2; i * i <= x; i++){
    if(x % i == 0) return 0;
  }
  return x > 1;
}

int modpow(int x, int p, int m){
  if(p == 0) return 1;
  ll s = modpow(x, p / 2, m);
  return s * s % m * (p & 1 ? x : 1) % m;
}

int main(){
  cin >> N;
  if(N == 1){
    cout << "YES\n1\n";
  } else if(N == 4){
    cout << "YES\n1\n3\n2\n4\n";
  } else if(is_prime(N)){
    int k = N - 1, r;
    vector<int> v;
    for(int i = 2; i <= k; i++){
      if(k % i != 0) continue;
      v.push_back(i);
      while(k % i == 0) k /= i;
    }
    for(r = 2; r < N; r++){
      bool ok = 1;
      for(int j = 0; j < v.size(); j++){
        ok &= (modpow(r, (N - 1) / v[j], N) != 1);
      }
      if(ok) break;
    }
    cout << "YES\n";
    for(int i = 1; i < N; i++){
      cout << modpow(r, i % 2 ? i - 1 : N - i, N) << '\n';
    }
    cout << N << '\n';
  } else cout << "NO\n";
}


#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;

const int NMAX = 100010;

int N, V[NMAX], Aux[NMAX];

int LgPow(int N, int P, int MOD)
{
    if(!P) return 1;
    if(P & 1) return (1LL * N * LgPow(N, P - 1, MOD)) % MOD;
    int X = LgPow(N, P / 2, MOD);
    return (1LL * X * X) % MOD;
}

int main()
{
    scanf("%i", &N);
    if(N == 4)
    {
        printf("YES\n1\n3\n2\n4\n");
        return 0;
    }

    bool Prime = 1;
    for(int i = 2; 1LL * i * i <= N; ++ i)
        if(N % i == 0)
            Prime = 0;

    if(!Prime)
    {
        printf("NO");
        return 0;
    }

    V[1] = 1;
    V[N] = N;

    for(int i = 2; i < N; ++ i)
        V[i] = (1LL * i * LgPow(i - 1, N - 2, N)) % N;

    for(int i = 1; i <= N; ++ i)
        Aux[i] = V[i];
    sort(Aux + 1, Aux + N + 1);

    for(int i = 2; i <= N; ++ i)
        if(Aux[i] == Aux[i - 1] || Aux[i] - Aux[i - 1] >= 2)
        {
            printf("NO");
            return 0;
        }

    printf("YES\n");
    for(int i = 1; i <= N; ++ i)
        printf("%i\n", V[i]);
}


//ITNOG
#include <bits/stdc++.h>

using namespace std;
#define int long long
const int maxN = 100*1000 + 5;
const int mod = 1000*1000*1000 + 7;
int n;

int power(int t, int k)
{
    if(k == 0) return 1;
    int ans = power(t, k / 2);
    ans = ans * ans % n;
    if(k & 1) ans = ans * t % n;
    return ans;
}

bool isprime(int x)
{
    for(int i = 2; i * i <= x; i ++)
	  if(x % i == 0) { return false; }
    return true;
}

main()
{
    ios::sync_with_stdio(0); cin.tie(0);
    cin >> n;
    if(n != 1 && n != 4 && !isprime(n)) { cout << "NO" << endl; return 0; }

    cout << "YES" << endl;
    if(n == 1) { cout << 1 << endl; return 0; }

    if(n == 4) { cout << "1 3 2 4" << endl; return 0; }

    cout << 1 << '\n';

    for(int i = 2; i < n; i ++)
	  cout << i * power(i - 1, n - 2) % n << '\n';

    cout << n << endl;
    return 0;
}


#pragma comment(linker,"/stack:256000000")
#include <string>
#include <vector>
#include <cstring>
#include <cstdio>
#include <iostream>
#include <sstream>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#include <cstdlib>
#include <cfloat>
#include <ctime>
#include<cassert>
#include<cstdlib>
#include<fstream>
#include<iomanip>

using namespace std;

#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define sz(v) (int)(v).size()
#define all(v) (v).begin(), (v).end()

bool isPrime(int n){
	for(int i=2;i*i<=n;i++){
		if(n%i==0){
			return false;
		}
	}
	return true;
}

long long r[100100];

int main() {
#ifdef LOCAL
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
#endif
	int m;
	cin>>m;
	if(m==1){
		cout<<"YES"<<endl;
		cout<<"1"<<endl;
		return 0;
	}
if(m==4){
cout<<"YES\n1\n3\n2\n4\n";
return 0;
}
	if(isPrime(m)){
		cout<<"YES"<<endl;
		r[1] = 1;
		for (int i=2; i<m; ++i)
			r[i] = (m - (m/i) * r[m%i] % m) % m;
		printf("1\n");
		for(int i=1;i<m-1;i++){
			printf("%d\n",((i+1)*r[i])%m);
		}
		cout<<m<<endl;
	}else{
		cout<<"NO"<<endl;
	}
	return 0;
}


#pragma comment(linker,"/stack:256000000")
#include <string>
#include <vector>
#include <cstring>
#include <cstdio>
#include <iostream>
#include <sstream>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#include <cstdlib>
#include <cfloat>
#include <ctime>
#include<cassert>
#include<cstdlib>
#include<fstream>
#include<iomanip>

using namespace std;

#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define sz(v) (int)(v).size()
#define all(v) (v).begin(), (v).end()

bool isPrime(int n){
	for(int i=2;i*i<=n;i++){
		if(n%i==0){
			return false;
		}
	}
	return true;
}

long long r[100100];

int main() {
#ifdef LOCAL
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
#endif
	int m;
	cin>>m;
	if(m==1){
		cout<<"YES"<<endl;
		cout<<"1"<<endl;
		return 0;
	}
	if(isPrime(m)){
		cout<<"YES"<<endl;
		r[1] = 1;
		for (int i=2; i<m; ++i)
			r[i] = (m - (m/i) * r[m%i] % m) % m;
		cout << "1 ";
		for(int i=1;i<m-1;i++){
			cout<<((i+1)*r[i])%m<<" ";
		}
		cout<<m<<endl;
	}else{
		cout<<"NO"<<endl;
	}
	return 0;
}


#pragma comment(linker,"/stack:256000000")
#include <string>
#include <vector>
#include <cstring>
#include <cstdio>
#include <iostream>
#include <sstream>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#include <cstdlib>
#include <cfloat>
#include <ctime>
#include<cassert>
#include<cstdlib>
#include<fstream>
#include<iomanip>

using namespace std;

#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define sz(v) (int)(v).size()
#define all(v) (v).begin(), (v).end()

bool isPrime(int n){
	for(int i=2;i*i<=n;i++){
		if(n%i==0){
			return false;
		}
	}
	return true;
}

long long r[100100];

int main() {
#ifdef LOCAL
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
#endif
	int m;
	cin>>m;
	if(m==1){
		cout<<"YES"<<endl;
		cout<<"1"<<endl;
		return 0;
	}
	if(isPrime(m)){
		cout<<"YES"<<endl;
		r[1] = 1;
		for (int i=2; i<m; ++i)
			r[i] = (m - (m/i) * r[m%i] % m) % m;
		printf("1\n");
		for(int i=1;i<m-1;i++){
			printf("%d\n",((i+1)*r[i])%m);
		}
		cout<<m<<endl;
	}else{
		cout<<"NO"<<endl;
	}
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <iterator>
#include <ctime>
#include <iomanip>

typedef unsigned int uint32;
typedef signed long long int64;
typedef unsigned long long uint64;

using namespace std;

#define ALL(a) a.begin(), a.end()
#define FOR(a) for (int i = 0; i < (a); ++i)
#define D(a) #a << ": " << a << "\n"

// a * (a-1)^(n-2) % n
int calc(int a, int n)
{
    int p = n-2;
    int mul = a-1;
    int64 res = 1;
    while (p)
    {
        if (p & 1)
            res = (res * mul) % n;

        mul = (mul * mul) % n;
        p /= 2;
    }

    return (res * a) % n;
}

int main()
{
    int n;
    cin >> n;
    if (n == 4)
    {
        printf("YES\n1\n3\n2\n4\n");
        return 0;
    }

    for (int i = 2; i*i <= n; ++i)
    {
        if (n % i)
            continue;

        printf("NO\n");
        return 0;
    }

    printf("YES\n1\n");
    int num = 1;
    for (int i = 2; i < n; ++i)
        printf("%d\n", calc(i, n));

    printf("%d\n", n);
    return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <iterator>
#include <ctime>
#include <iomanip>

typedef unsigned int uint32;
typedef signed long long int64;
typedef unsigned long long uint64;

using namespace std;

#define ALL(a) a.begin(), a.end()
#define FOR(a) for (int i = 0; i < (a); ++i)
#define D(a) #a << ": " << a << "\n"

// a * (a-1)^(n-2) % n
int calc(int a, int n)
{
    int p = n-2;
    int64 mul = a-1;
    int64 res = 1;
    while (p)
    {
        if (p & 1)
            res = (res * mul) % n;

        mul = (mul * mul) % n;
        p /= 2;
    }

    return (res * a) % n;
}

int main()
{
    int n;
    cin >> n;
    if (n == 4)
    {
        printf("YES\n1\n3\n2\n4\n");
        return 0;
    }

    for (int i = 2; i*i <= n; ++i)
    {
        if (n % i)
            continue;

        printf("NO\n");
        return 0;
    }

    printf("YES\n1\n");
    int num = 1;
    for (int i = 2; i < n; ++i)
        printf("%d\n", calc(i, n));

    printf("%d\n", n);
    return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <iterator>
#include <ctime>
#include <iomanip>

typedef unsigned int uint32;
typedef signed long long int64;
typedef unsigned long long uint64;

using namespace std;

#define ALL(a) a.begin(), a.end()
#define FOR(a) for (int i = 0; i < (a); ++i)
#define D(a) #a << ": " << a << "\n"

// a * (a-1)^(n-2) % n
int calc(int a, int n)
{
    int p = n-2;
    int64 mul = a-1;
    int64 res = 1;
    while (p)
    {
        if (p & 1)
            res = (res * mul) % n;

        mul = (mul * mul) % n;
        p /= 2;
    }

    return (res * a) % n;
}

int main()
{
    int n;
    cin >> n;
    if (n == 4)
    {
        printf("YES\n1\n3\n2\n4\n");
        return 0;
    }

    for (int i = 2; i*i <= n; ++i)
    {
        if (n % i)
            continue;

        printf("NO\n");
        return 0;
    }

    printf("YES\n1\n");
    int num = 1;
    for (int i = 2; i < n; ++i)
        printf("%d\n", calc(i, n));

    if (n > 1)
        printf("%d\n", n);
    return 0;
}


//   PAP's Code!

#include<iostream>
#include<algorithm>

using namespace std;

#define int long long
int n;

int POW(int x, int y)
{
	if(y == 0)
		return 1;
	int ans = POW(x, y / 2);
	ans *= ans;
	ans %= n;
	if(y % 2 == 1)
		ans *= x;
	return ans % n;
}

bool prime(int n)
{
	if(n == 1)
		return false;
	for(int i = 2; i * i <= n; i++)
		if(n % i == 0)
			return false;
	return true;
}

main()
{
	cin >> n;
	if(n == 1)
		cout << "YES \n1" << endl;
	else if(n == 4)
		cout << "YES \n1 3 2 4" << endl;
	else if(!prime(n))
		cout << "NO" << endl;
	else
	{
		cout << "YES" << endl;
		cout << 1 << endl;
		for(int i = 1; i < n - 1; i++)
			cout << (i + 1) * POW(i, n - 2) % n << endl;
		cout << n << endl;
	}
	return 0;
}


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

typedef long long ll;

ll N;
bool is_prime[100010];

void prep();
void solve();

ll pwr(ll, ll);

int main() {
  prep();
  cin >> N;
  solve();

  return 0;
}

void prep() {
  fill(&is_prime[2], &is_prime[100010], true);
  for (ll i = 2; i <= 100000; ++i)
    if (is_prime[i]) {
      for (ll j = i; i * j < 100010; ++j)
        is_prime[i * j] = false;
    }
}

void solve() {
  if (N == 1)
    cout << "YES\n1\n";
  else if (N == 4)
    cout << "YES\n1\n3\n2\n4\n";
  else {
    if (!is_prime[N])
      cout << "NO\n";
    else {
      cout << "YES\n1\n";
      for (ll i = 2; i < N; ++i)
        cout << i * pwr(i - 1, N - 2) % N << "\n";
      cout << N << "\n";
    }
  }
}

ll pwr(ll p, ll q) {
  if (q == 0)
    return 1;
  else {
    ll t = pwr(p, q / 2);
    return q % 2 == 0 ? t * t % N : t * t % N * p % N;
  }
}


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

typedef long long ll;

int N;
bool is_prime[100010];

void prep();
void solve();

int pwr(int, int);

int main() {
  prep();
  cin >> N;
  solve();

  return 0;
}

void prep() {
  fill(&is_prime[2], &is_prime[100010], true);
  for (ll i = 2; i <= 100000; ++i)
    if (is_prime[i]) {
      for (ll j = i; i * j < 100010; ++j)
        is_prime[i * j] = false;
    }
}

void solve() {
  if (N == 1)
    cout << "YES\n1\n";
  else if (N == 4)
    cout << "YES\n1\n3\n2\n4\n";
  else {
    if (!is_prime[N])
      cout << "NO\n";
    else {
      cout << "YES\n1\n";
      for (int i = 2; i < N; ++i)
        cout << i * pwr(i - 1, N - 2) % N << "\n";
      cout << N << "\n";
    }
  }
}

int pwr(int p, int q) {
  if (q == 0)
    return 1;
  else {
    int t = pwr(p, q / 2);
    return q % 2 == 0 ? t * t % N : t * t % N * p % N;
  }
}


#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <stack>
#include <set>
#define SIZE 100005

using namespace std;
typedef long long int ll;

ll mpow(ll m,ll t,ll p)
{
	if(t==0) return 1;
	ll ret=mpow(m,t/2,p);
	ret=ret*ret%p;
	if(t%2==1) ret=ret*m%p;
	return ret;
}
int main()
{
	int n;
	scanf("%d",&n);
	if(n==1)
	{
		puts("YES");
		puts("1");
		return 0;
	}
	if(n==4)
	{
		puts("YES");
		puts("1");
		puts("3");
		puts("2");
		puts("4");
		return 0;
	}
	if(n==2)
	{
		puts("YES");
		puts("1");
		puts("2");
		return 0;
	}
	for(int i=2;i<n;i++)
	{
		if(n%i==0)
		{
			puts("NO");
			return 0;
		}
	}
	vector <int> div;
	for(int i=2;i<n-1;i++)
	{
		if((n-1)%i==0)
		{
			div.push_back(i);
		}
	}
	int g=-1;
	for(int i=2;i<n;i++)
	{
		bool ok=true;
		for(int j=0;j<div.size();j++)
		{
			if(mpow(i,div[j],n)==1)
			{
				ok=false;
				break;
			}
		}
		if(ok)
		{
			g=i;
			break;
		}
	}
	puts("YES");
	for(int i=1;i<=n-1;i++)
	{
		if(i==1) puts("1");
		else
		{
			if(i%2==0) printf("%d\n",(int) mpow(g,i-1,n));
			else printf("%d\n",(int) mpow(g,n-i,n));
		}
	}
	printf("%d\n",n);
	return 0;
}


#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
typedef long long ll;
const int MN = 1<<20;
int as[MN];
int rs[MN];
bool done[MN];

typedef ll T;
typedef pair<T,T> IP;
pair<T,T> egcd(T a, T b)
{
  if (a%b==0) return IP(0,1);
  pair<T,T> x=egcd(b,a%b);
  return make_pair(x.second, x.first-x.second*(a/b));
}
T mod(T a, T b) {
  T r = a%b;
  return r<0 ? r+b : r;
}
T modinv(T x, T p)
{
  return mod(egcd(x,p).first,p);
}

int main() {
  cout.sync_with_stdio(0);
  int n;
  cin>>n;
  for(int i=2; i*i<=n; ++i) if (n%i==0) {
    cout<<"NO\n";
    return 0;
  }
  cout<<"YES\n";
  cout<<1<<'\n';
  for(ll i=1; i+1<n; ++i) {
    ll x = modinv(i, n) * (i+1) % n;
    cout<<x<<'\n';
  }
  cout<<n<<'\n';
}


#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
typedef long long ll;
const int MN = 1<<20;
int as[MN];
int rs[MN];
bool done[MN];

typedef ll T;
typedef pair<T,T> IP;
pair<T,T> egcd(T a, T b)
{
  if (a%b==0) return IP(0,1);
  pair<T,T> x=egcd(b,a%b);
  return make_pair(x.second, x.first-x.second*(a/b));
}
T mod(T a, T b) {
  T r = a%b;
  return r<0 ? r+b : r;
}
T modinv(T x, T p)
{
  return mod(egcd(x,p).first,p);
}

int main() {
  cout.sync_with_stdio(0);
  int n;
  cin>>n;
  if (n==1) {
    cout<<"YES\n";
    cout<<1<<'\n';
    return 0;
  }
  for(int i=2; i*i<=n; ++i) if (n%i==0) {
    cout<<"NO\n";
    return 0;
  }
  cout<<"YES\n";
  cout<<1<<'\n';
  for(ll i=1; i+1<n; ++i) {
    ll x = modinv(i, n) * (i+1) % n;
    cout<<x<<'\n';
  }
  cout<<n<<'\n';
}


#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
typedef long long ll;
const int MN = 1<<20;
int as[MN];
int rs[MN];
bool done[MN];

typedef ll T;
typedef pair<T,T> IP;
pair<T,T> egcd(T a, T b)
{
  if (a%b==0) return IP(0,1);
  pair<T,T> x=egcd(b,a%b);
  return make_pair(x.second, x.first-x.second*(a/b));
}
T mod(T a, T b) {
  T r = a%b;
  return r<0 ? r+b : r;
}
T modinv(T x, T p)
{
  return mod(egcd(x,p).first,p);
}

int main() {
  cout.sync_with_stdio(0);
  int n;
  cin>>n;
  if (n==1) {
    cout<<"YES\n";
    cout<<1<<'\n';
    return 0;
  } else if (n==4) {
    cout<<"YES\n";
    cout<<1<<'\n';
    cout<<3<<'\n';
    cout<<2<<'\n';
    cout<<4<<'\n';
    return 0;
  }

#if 0
  for(int i=0; i<n; ++i) as[i]=i+1;
  do {
    ll r=1;
    memset(done,0,n+1);
    int i;
    for(i=0; i<n; ++i) {
      r *= as[i];
      r %= n;
      if (done[r]) break;
      done[r] = 1;
    }
    if (i==n) {
      cout<<"YES\n";
      for(i=0; i<n; ++i) cout<<as[i]<<'\n';
      return 0;
    }
  } while(next_permutation(as,as+n));
  cout<<"NO\n";
  return 0;
#endif

  for(int i=2; i*i<=n; ++i) if (n%i==0) {
    cout<<"NO\n";
    return 0;
  }
  cout<<"YES\n";
  cout<<1<<'\n';
  for(ll i=1; i+1<n; ++i) {
    ll x = modinv(i, n) * (i+1) % n;
    cout<<x<<'\n';
  }
  cout<<n<<'\n';
}