#include <cstdio>
#include <utility>
#include <cmath>
#include <algorithm>
using namespace std;

#define gcu getchar_unlocked
int in(int c){int n=0;bool m=false;if(c=='-')m=true,c=gcu();
	do{n=10*n+(c-'0'),c=gcu();}while(c>='0');return m?-n:n;}
int in() {return in(gcu());}
bool scan(int &n){int c=gcu();return c==EOF?false:(n=in(c),true);}
bool scan(char &c){c=gcu();gcu();return c!=EOF;}
//bool scan(string &s){int c;s="";
//	for(;;){c=gcu();if(c=='\n'||c==' ')return true;else if(c==EOF)return false;s+=c;}}
#define pcu putchar_unlocked
#define vo inline void out
template <typename T>
vo(T n){static char buf[20];char *p=buf;
	if(n<0)pcu('-'),n*=-1;if(!n)*p++='0';else while(n)*p++=n%10+'0',n/=10;
	while (p!=buf)pcu(*--p);}
vo(const char *s){while(*s)pcu(*s++);}
vo(char c){pcu(c);}
//vo(string &s){for (char c: s) pcu(c);}
template <typename head, typename... tail> vo(head&& h, tail&&... t){out(h);out(move(t)...);}
//template <typename T> vo(vector<T> &v){for(T &x:v)out(&x == &v[0]?"":" "),out(x);out('\n');}
#undef vo

int main() {
	for (int e, m; (e = m = in());) {
		for (int z = cbrt(e) + 0.00001; z >= 0; z--) {
			int te = e - z * z * z;
			int y = (int)sqrt(te);
			int tm = z + y + te - y * y;
			if (y > m)
				break;
			m = min(m, tm);
		}
		out(m, '\n');
	}
}

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <time.h>
#include <math.h>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <iterator>
#include <sstream>
#include <string>
#include <bitset>
using namespace std;
#define FOR(I,F,N) for(int I = F; I < (int)(N); I++)
#define rep(i, n) FOR(i, 0, n)
#define FIN(V) cout<<V<<endl
#define pb push_back
#define INF (1 << 28)

template<typename T>
void remove(vector<T>& vector, unsigned int index){
vector.erase(vector.begin() + index);
}

typedef pair<int, int> P;
typedef long long ll;
typedef priority_queue<int> pq;
int StrToInt(string);
string IntToStr(int);
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};

int main(void){

  int e;
  while (cin >> e, e) {
    int min = e;
    for (int z=0; z*z*z<=e; z++) {
      for (int y=0; y*y<=e-z*z*z; y++) {
        int x = e - z*z*z - y*y;
        if (x + y + z < min) { min = x + y + z; }
      }
    }
    cout << min << endl;
  }

	return 0;
}

int StrToInt(string s){
	stringstream ss;
	ss << s;
	int val;
	ss >> val;
	return val;
}
string IntToStr(int i){
	stringstream ss;
	ss << i;
	return ss.str();
}


#include<stdio.h>
#include<iostream>
#include <algorithm>
#include <functional>
#include <array>
using namespace std;
long long modpow(long long a, long long n, long long mod);
long long modinv(long long a, long long mod);
//void margesort(int a[], int a_len, int left, int right);
//void margesortD(int a[], int b[], int a_len, int left, int right);
//int temp[100000];
//int tempb[100000];
//int b[100000];
//int c[100000];
int main() {
	/*
		int a, b;
		cin >> a;
		cin >> b;
		if (a <= 5) {
			cout << 0;
		}
		else if (a <= 12) {
			cout << b / 2;
		}else{
			cout << b;
		}

		return 0;
		*/
		//B
		/*long long int r, d, x;
		cin >> r;
		cin >> d;
		cin >> x;

		int i;
		for (i = 0; i < 10; i++) {
			x = r * x - d;
			cout << x;
			cout <<'\n';
		}

		return 0;*/
		//C
		/*int n, m;
		int l, r;
		cin >> n;
		cin >> m;

		int lmax, rmin;
		lmax = 1;
		rmin = n;
		int i;
		for (i = 0; i < m; i++) {
			cin >> l;
			cin >> r;
			if (l > lmax) {
				lmax = l;
			}
			if (r < rmin) {
				rmin = r;
			}
		}
		if (lmax <= rmin) {
			cout << (rmin - lmax + 1);
		}
		else {
			cout << 0;
		}

		return 0;*/

		//D
	/*int n, m;
	cin >> n;
	cin >> m;
	int i;
	int a[100000];
	for (i = 0; i < n; i++) {
		cin >> a[i];
	}
	margesort(a, n, 0, n - 1);

	for (i = 0; i < m; i++) {
		cin >> b[i];
		cin >> c[i];

	}
	margesortD(c, b, m, 0, m - 1);
	//sort(b.begin(), b.end());

	long long int d;
	d = 0;
	int j, k, flag;
	i = 0;
	j = m - 1;
	flag = 0;
	while (flag == 0) {
		for (k = i; k < i + b[j]; k++) {
			if (a[k] < c[j]) {
				a[k] = c[j];

			}
			else {
				flag = 1;
			}
			if (k == n) {
				flag = 1;
				break;
			}
		}
		i = i + b[j];
		j--;
		if (j == -1) { flag = -1; }
	}
	for (i = 0; i < n; i++) {
		d = d + a[i];
	}
	cout << d;

	return 0;
	*/

	//E
	long long int n, m, k;
	cin >> n;
	cin >> m;
	cin >> k;
	long long int p;
	p = 1000000007;
	long long int c;
	c = 0;
	//2駒総コストを求める.
	int i;
	int j;
	c = (((((((n * m) % p) * (n + m)) % p) * (n * m - 1)) % p) * modinv(6, p)) % p;
	//それを(nm-2)C(k-2)倍する.
	j = 1;
	for (i = n*m-2; i > (n * m - 2)-(k-2); i--) {
		c = (c * i) % p;
		c = (c * modinv(j, p)) % p;
		j++;
	}
	cout << c;
	return 0;

}
/*void margesort(int a[], int a_len, int left, int right)
{
	int i, j, mid, L, R;

	if (right <= left)
		return;

	mid = (left + right) / 2;
	margesort(a, mid, left, mid);
	margesort(a, a_len - mid, mid+1, right);

	for (i = left; i <= mid; i++)
		temp[i] = a[i];
	for (i = mid+1, j = right; i <= right; i++, j--)
		temp[i] = a[j];

	L = left;
	R = right;

	for (i = left; i <= right; i++)
	{
		if (temp[L] <= temp[R])
		{
			a[i] = temp[L];
			L++;
		}
		else
		{
			a[i] = temp[R];
			R--;
		}
	}
}

void margesortD(int a[], int b[], int a_len, int left, int right) {
	int i, j, mid, L, R;

	if (right <= left)
		return;

	mid = (left + right) / 2;
	margesortD(a, b, mid, left, mid);
	margesortD(a, b, a_len - mid, mid+1, right);

	for (i = left; i <= mid; i++) {
		temp[i] = a[i];
		tempb[i] = b[i];
	}
	for (i = mid+1, j = right; i <= right; i++, j--) {
		temp[i] = a[j];
		tempb[i] = b[j];
	}

	L = left;
	R = right;

	for (i = left; i <= right; i++)
	{
		if (temp[L] <= temp[R])
		{
			a[i] = temp[L];
			b[i] = tempb[L];
			L++;
		}
		else
		{
			a[i] = temp[R];
			b[i] = tempb[R];
			R--;
		}
	}
}*/

// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
	long long res = 1;
	while (n > 0) {
		if (n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}

// a^{-1} mod を計算する
long long modinv(long long a, long long mod) {
	return modpow(a, mod - 2, mod);
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define INF (1LL<<50)
#define MOD 1000000007

int main(){
    ll x,y;
    cin >> x >> y;
    ll ans;
    // 1回目に符号を反転させる場合
    ll A = 1 + y - (-x);
    // 最後に符号を反転させる場合
    ll B = (-y) - x + 1;
    // 最初と最後に符号を反転させる場合
    ll C = 2 + (-y) - (-x);
    // 反転させない場合
    ll D = y - x;
    if(A<0) A = INF;
    if(B<0) B = INF;
    if(C<0) C = INF;
    if(D<0) D = INF;
    ans = min(min(A,B),min(C,D));
    cout << ans << endl;
    return 0;
}


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

int main() {
  int N;
  cin>>N;
  string s,t;
  cin>>s>>t;
  reverse(s.begin(),s.end());
  for(int i=N;i<=2*N;i++){
    string S=s.substr(0,2*N-i);
    reverse(S.begin(),S.end());
    if(S==t.substr(0,2*N-i)){cout<<i<<endl;return 0;}
  }
  return 0;
}

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

int main(){
  int N;
  string S,T;
  cin >> N >> S >> T;
  bool a=false;
  for(int i=0;i<N;i++){
    if(S.substr(i,N-i)==T.substr(0,N-i)){
      a=true;
      cout << N+i << endl;
      break;
    }
  }
  if(!a){
    cout << 2*N << endl;
  }
}


#include <iostream>
using namespace std;
int main(){
	int l[10], v[2], sl;
	char c;
	while(cin >> l[0]){
		sl = l[0];
		for(int i = 1; i < 10; i++){
			cin >> c >> l[i];
			sl += l[i];
		}
		cin >> c >> v[0] >> c >> v[1];
		for(int i = 0; i < 10; i++){
			l[i] *= v[0] + v[1];
		}
		sl *= v[0];

		for(int i = 0; i < 10; i++){
			sl -= l[i];
			if(sl <= 0){
				cout << i + 1 << endl;
				break;
			}
		}
	}
	return 0;
}

#include <bits/stdc++.h>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll INF = 1e15;
const ll MOD = 1000000007;
typedef pair<ll,ll> P;
class Prim{
    public:
    struct Node{
        vector<P> edges; // cost node
        bool done;
        ll cost;
    };
    ll V;
    vector<Node> nodes;
    Prim(ll v){
        V = v;
        nodes.resize(v);
    }
    void add_edge(ll v,ll node,ll cost){
        nodes[v].edges.push_back(P(cost,node));
    }
    ll prim(){
        priority_queue<P,vector<P>,greater<P>> mincost;
        rep(i,V){
            nodes[i].cost = INF;
            nodes[i].done = false;
        }
        ll res = 0;
        mincost.push(P(0,0));
        while(!mincost.empty()){
            P p = mincost.top();mincost.pop();
            ll v = p.second;
            if (nodes[v].done) continue;
            nodes[v].done = true;
            res += p.first;
            for(P u:nodes[v].edges){
                if (!nodes[u.second].done) mincost.push(P(u.first,u.second));
            }
        }
        return res;
    }
};
int main(){
    ll v,e;
    cin >> v >> e;
    Prim g(v);
    ll s,t,w;
    rep(i,e){
        cin >> s >> t >> w;
        g.add_edge(s,t,w);
        g.add_edge(t,s,w);
    }
    PRINT(g.prim());
}


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

#define inf 1e+9
#define endl "\n"
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()

#define pb push_back
#define eb emplace_back
#define Size(c) (int)(c).size()

#define lb(c, x) distance((c).begin(), lower_bound(all(c), (x)))
#define ub(c, x) distance((c).begin(), upper_bound(all(c), (x)))

template <class T> using pq = priority_queue<T>;
template <class T> using pqg = priority_queue<T, vector<T>, greater<T>>;

template <class T, class S> inline bool chmax(T &a, S b) {
    if(a < b) {a = b;return 1;} return 0;
}
template <class T, class S> inline bool chmin(T &a, S b) {
    if(a > b) {a = b;return 1;} return 0;
}
template <class T>
void line(vector<T> &x){for (auto&& xi : x) cin >> xi;}

inline void IN(void){ return;}

template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){ cin >> first; IN(rest...); return;}

#define INT(...) int __VA_ARGS__; IN (__VA_ARGS__)
#define LINT(...) lint __VA_ARGS__; IN (__VA_ARGS__)
#define STR(...) string __VA_ARGS__; IN(__VA_ARGS__)

template <class T> void UNIQUE(vector<T> &x) {
    sort(all(x)); x.erase(unique(all(x)), x.end());
}
template <class T> void print_vec(vector<T> a){
    for (const auto& ai : a) cout << ai << " ";
    cout << endl;
}
vector<string> Yes = {"No", "Yes"};

int main(){
    INT(x, y, z);
    swap(x, y); swap(x, z);
    cout << x << " " << y << " " << z << endl;
}

#include <bits/stdc++.h>
#define boost_io ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define int long long
#define num(a) a-'0'
#define charr(a) (a - 'A' + 1)
#define rep(i,a,b) for(int i=a;i<b;i++)
#define maxs(a,b) if(b>a)a=b
#define mins(a,b) if(b<a)a=b
#define debug(x) cerr<<"["<<#x<<":"<<x<<"] "
#define debug2(a,b) debug(a);debug(b)
#define debug3(a,b,c) debug2(a,b);debug(c)
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*b)/(__gcd(a,b))
#define print(arr) for(auto it = arr.begin();it < arr.end();it ++){cout << *it << " ";}cout << ln;
#define all(a) (a).begin(), (a).end()
#define vi vector<long long>
#define v vector
#define p pair
#define pb push_back
#define mk make_pair
#define f first
#define s second
#define ln "\n"
typedef long double ld;
typedef double d;
using namespace std;
int modF=1e9+7;
int INF=1e11;

void solve(){
	int x,y,z;
	cin>>x>>y>>z;
	cout<<z<<" "<<x<<" "<<y<<ln;
}

signed main(){
	boost_io;
	solve();
	return 0;
}


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

#define gcu getchar_unlocked
#define pcu putchar_unlocked
#define _il inline
#define _in _il int in
#define _sc _il bool scan
_in(int c){int n=0;bool m=false;if(c=='-')m=true,c=gcu();
	do{n=10*n+(c-'0'),c=gcu();}while(c>='0');return m?-n:n;} //&&c<='9'
_in() {return in(gcu());}
_sc(int &n){int c=gcu();return c==EOF?false:(n=in(c),true);}
_sc(char &c){c=gcu();gcu();return c!=EOF;}
//_sc(string &s){int c;s="";
//	for(;;){c=gcu();if(c=='\n'||c==' ')return true;else if(c==EOF)return false;s+=c;}}
template <typename H,typename... T> _sc(H &h, T&&... t){return scan(h)&&scan(t...);}
#define _vo _il void out
#define _vl _il void outl
template <typename T>
_vo(T n){static char buf[20];char *p=buf;
	if(n<0)pcu('-'),n*=-1;if(!n)*p++='0';else while(n)*p++=n%10+'0',n/=10;
	while (p!=buf)pcu(*--p);}
_vo(const char *s){while(*s)pcu(*s++);}
_vo(char c){pcu(c);}
//_vo(string &s){for (char c: s) pcu(c);}
template <typename H,typename... T> _vo(H&& h, T&&... t){out(h);out(move(t)...);}
//template <typename T> _vo(vector<T> &v){for(T &x:v)out(&x == &v[0]?"":" "),out(x);out('\n');}
_vl(){out('\n');}
template <typename... T> _vl(T&&... t){out(move(t)...);outl();}

template<int N>
struct sieve {
	bool s[N];
	constexpr sieve() : s() {
		for (int i = 0; i < N; i++)
			s[i] = true;
		for (int i = 4; i < N; i += 2)
			s[i] = false;
		for (int i = 9; i < N; i += 6)
			s[i] = false;
		for (int i = 6, e = sqrt(N); i <= e; i += 6) {
			for (int j : {i - 1, i + 1})
				if (s[j])
					for (int k = j * j; k < N; k += j)
						s[k] = false;
		}
	}
};

int main() {
	enum {N = 10001};
	constexpr sieve<N> s;
	vector<int> t = {5};
	for (int i = 7; i < N; i += 6)
		if (s.s[i - 2] && s.s[i])
			t.push_back(i);
	for (int n; (n = in());) {
		auto r = upper_bound(t.begin(), t.end(), n) - 1;
		outl(*r - 2, ' ', *r);
	}
}

#include<iostream>
using namespace std ;

int table[10010] = {} ;

void f(){
	table[0] = 1 ;
	table[1] = 1 ;
	for( int i=2 ; i<=10000 ; i++ ){
		if( !table[i] ){
			for( int j=2 ; i*j<=10000 ; j++ ) table[i*j] = 1 ;
		}
	}
}

main(){
	f() ;

	int n ;
	while( cin >> n , n ){
		int p = 0 ;
		for( int i=5 ; i<=n ; i++ ){
			if( !table[i] && !table[i-2] ) p = i ;
		}

		cout << p-2 << " " << p << endl ;
	}
}


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

#define ll long long
#define pll pair<ll,ll>

#define left 2*node+1
#define right left+1
#define mid (s+e>>1)

const ll N=5e5+5;
vector<ll> T[4*N];

void build(ll A[], ll node, ll s, ll e){
	if(s==e){
		T[node].push_back(A[s]);
		return;
	}
	build(A, left, s, mid);
	build(A, right, mid+1, e);
	merge(T[left].begin(), T[left].end(), T[right].begin(), T[right].end(), back_inserter(T[node]));
}

ll query(ll node,ll s, ll e, ll x, ll y){
	if(e<s || s>y || e<x)
		return 0;
	if(x<=s && e<=y){
		ll a=upper_bound(T[node].begin(), T[node].end(), y)-T[node].begin();
		return T[node].size()-a;
	}
	ll p1=query(left, s, mid, x, y);
	ll p2=query(right, 1+mid,e, x, y);
	return p1+p2;
}

int main(){

	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	ll n, q;
	cin>>n>>q;
	ll A[n];
	ll B[n];
	for(ll i=0;i<n;i++)
		cin>>A[i];
	map<ll,ll> M;
	for(ll i=n-1;i>=0;i--){
		if(M.count(A[i]))
			B[i]=M[A[i]];
		else
			B[i]=INT_MAX;
		M[A[i]]=i;
	}

	build(B,0,0, n-1);

	while(q--){
		ll x, y;
		cin>>x>>y;
		ll ans=query(0,0,n-1,x-1,y-1);
		cout<<ans<<"\n";
	}

}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
ll bi[514514];
void add(ll n,ll i,ll x){
	for(;i<=n;i+=i&-i)bi[i]+=x;
}
ll sum(ll i){
	ll num=0;
	for(;i>0;i-=i&-i)num+=bi[i];
	return num;
}
ll c[514514],g[514514],ans[514514];
int main(){
	ll n,q;
	cin>>n>>q;
	vector<vector<ll>>v(n+1),w(n+1);
	for(int i=1;i<=n;i++)cin>>c[i];
	for(int i=0;i<q;i++){
		ll l,r;
		cin>>l>>r;
		v[r].push_back(l);
		w[r].push_back(i);
	}
	for(int i=1;i<=n;i++){
		if(g[c[i]])add(n,g[c[i]],-1);
		add(n,i,1);
		g[c[i]]=i;
		ll cnt=0;
		for(ll p:v[i]){
			ans[w[i][cnt]]=sum(i)-sum(p-1);
			cnt++;
		}
	}
	for(int i=0;i<q;i++)cout<<ans[i]<<endl;
	return 0;
}


#include <bit>
#include <bitset>
#include <assert.h>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <stdlib.h>
#include <queue>
#include <stack>

typedef long double ld;
typedef long long ll;

using namespace std;

int f(int x) {
	if (x <= 3) {
		return (4 - x);
	}
	return 0;
}

int main() {
	int x, y;
	cin >> x >> y;
	if (x == 1 && y == 1) {
		cout << 1000000 << endl;
	} else {
		cout << 100000 * (f(x) + f(y)) << endl;
	}
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//cout << fixed << setprecision(15);
vector<int> forintinput(int n) {
	vector<int> x;
	for(int i = 0;i < n;i++){
		int ia;
		cin >> ia;
		x.push_back(ia);
	}
	return x;
}
int main(){
	int a;
	cin >> a;
	if(a == 1) cout << "Hello World" << endl;
	else{
		int b,c;
		cin >> b >> c;
		cout << b+c << endl;
	}
	return 0;
}


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

int main(){
  int sum,i,j,kari;
  string data;
  while(getline(cin, data)) {
    data = data.insert(data.length(), "KKKKKK");
    sum = j = 0;

    for(j = 0; j < data.length(); j++) {
      if(data[j] == 'M'){
	sum += 1000;
      }else if(data[j] == 'D'){
	if(data[j + 1] == 'M'){
	  sum += 900;
	    j++;
	}else{
	  sum += 500;
	}
      }else if(data[j] == 'C'){
	if(data[j + 1] == 'D' || data[j + 1] == 'M'){
	  if(data[j + 1] == 'D'){
	    sum += 400;
	    j++;
	  }else{
	    sum += 900;
	    j++;
	  }
	}else{
	  sum += 100;
	}
      }else if(data[j] == 'L'){
	sum += 50;
      }else if(data[j] == 'X'){
	if(data[j+1] == 'L' || data[j+1] == 'C'){
	  if(data[j+1] == 'L'){
	    sum += 40;
	    j++;
	  }else{
	    sum += 90;
	    j++;
	  }
	}else{
	  sum += 10;
	}
      }else if(data[j] == 'V'){
	sum += 5;
      }else if(data[j] == 'I'){
	if(data[j + 1] == 'V' || data[j + 1] == 'X'){
	  if(data[j + 1] == 'V'){
	    sum += 4;
	    j++;
	  }else{
	    sum += 9;
	    j++;
	  }
	}
	else{
	  sum += 1;
	}
      }
    }

    cout << sum << endl;
  }

  return 0;
}

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>

using namespace std;

#ifdef _MSC_VER
#define __typeof__ decltype
template <class T> int __builtin_popcount(T n) { return n ? 1 + __builtin_popcount(n & (n - 1)) : 0; }
#endif

#define foreach(it, c) for (__typeof__((c).begin()) it=(c).begin(); it != (c).end(); ++it)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define popcount __builtin_popcount

#define rep(i, n) for (int i = 0; i < n; ++i)

template <class T> void max_swap(T& a, const T& b) { a = max(a, b); }
template <class T> void min_swap(T& a, const T& b) { a = min(a, b); }

typedef long long ll;
typedef pair<int, int> pint;

const double PI = acos(-1.0);
const int dx[] = { 0, 1, 0, -1 };
const int dy[] = { 1, 0, -1, 0 };

int roman_to_n(const string& s)
{
	static const int num[] = { 1, 5, 10, 50, 100, 500, 1000 };
	static const char* roman = "IVXLCDM";

	vector<int> digits(s.size());
	for (int i = 0; i < s.size(); ++i)
		digits[i] = num[strchr(roman, s[i]) - roman];

	int res = accumulate(digits.begin(), digits.end(), 0);
	for (int i = 0; i < digits.size() - 1; ++i)
		if (digits[i] < digits[i + 1])
			res -= 2 * digits[i];
	return res;
}
string to_roman(int n)
{
	static const char* roman[][10] = {
		{ "", "I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX" },
		{ "", "X", "XX", "XXX", "XL", "L", "LX", "LXX", "LXXX", "XC" },
		{ "", "C", "CC", "CCC", "CD", "D", "DC", "DCC", "DCCC", "CM" },
		{ "", "M", "MM", "MMM", "MMMM", "MMMMM" },
	};

	stringstream res;
	for (int i = 3, j = 1000; i >= 0; --i, j /= 10)
		res << roman[i][(n / j) % 10];
	return res.str();
}
int main()
{
	string s;
	while (cin >> s)
		cout << roman_to_n(s) << endl;
}


#include <bits/stdc++.h>

using namespace std;

const int MAX_N=1e6,MAX_A=1e5;

typedef long long ll;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)

int N;
int a[MAX_N];

ll sum[MAX_N+1];

int main(){
	do{
		scanf("%d",&N);
		if (N){
			REP(i,N){
				scanf("%d",&a[i]);
			}
			ll ma=-MAX_A;
			sum[0]=0;
			REP(i,N){
				sum[i+1]=sum[i]+a[i];
			}
			REP(i,N){
				FOR(j,i,N){
					ma=max(ma,sum[j+1]-sum[i]);
				}
			}
			printf("%lld\n",ma);
		}
	}while(N);
	return 0;
}

#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	while (1) {
		long a[5001] = { 0 };
		long n;
		cin >> n;
		if (n == 0)break;
		a[0] = 0;
		long maxv = -100000;
		for (int i = 1; i <= n; i++) {
			cin >> a[i];
		}
		for (int i = 1; i <= n; i++) {
			a[i] = max(a[i], a[i] + a[i - 1]);
			maxv = max(maxv, a[i]);
		}
		cout << maxv << endl;
	}
}


#include <stdio.h>
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <chrono>
#include <random>
#include <time.h>
#include <fstream>
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pq priority_queue<int>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define vec vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define endl "\n"
#define all(c) begin(c),end(c)
using namespace std;
int in() {int x;scanf("%d",&x);return x;}
ll lin() {ll x;scanf("%lld",&x);return x;}

#define INF 1e9+7
#define LLINF 1e18+7
#define N 3000000
ll MOD=998244353;

ll inv[N],prd[N],invprd[N];
void calc_inv(){
    inv[1]=1;
    rep2(i,2,N-1){
        inv[i]=((-(MOD/i)*inv[MOD%i])%MOD+MOD)%MOD;
    }
    return;
}
void calc_product(){
    prd[0]=prd[1]=1;
    invprd[0]=invprd[1]=1;
    rep2(i,2,N-1){
        prd[i]=i*prd[i-1]%MOD;
        invprd[i]=inv[i]*invprd[i-1]%MOD;
    }
    return ;
}
ll cmb(ll a,ll b){
    if(a<b)return 0;
    if(a<0||b<0)return 0;
    return prd[a]*invprd[b]%MOD*invprd[a-b]%MOD;
}
ll modpow(ll x,ll n){
    if(n==0) return 1;
    ll res=modpow(x*x%MOD,n/2);
    if(n&1) res=res*x%MOD;
    return res;
}

main(){
    calc_inv();
    calc_product();
    ll n=lin(),m=lin();
    ll ans=0;
    ans=cmb(m*3ll+n-1ll,n-1ll);
    rep2(x,1,m){
        ans=(ans+MOD-n*cmb(m+n-x-2ll,n-2ll)%MOD)%MOD;
        if(cmb(m+n-x-2ll,n-2ll)<0)cout<<0000;
        if(n*cmb(m+n-x-2ll,n-2ll)<0)cout<<000;
        //cout<<ans<<endl;
    }
    ll t=-1;
    ll p=m,q=m;
    rep2(x,m+1,(ll)min(m*3,n)){

        if(x>n)break;
        //ans=(ans+MOD-t*cmb(n,x)*cmb(p-q-1,q-1)%MOD)%MOD;
        if(n==x){
            if(m*3==n)
            ans=(ans+MOD+t*cmb(p,q)%MOD)%MOD;
            //cout<<ans<<endl;
        }
        if((m*3-x)%2)continue;
        ans=(ans+MOD+t*cmb(n,x)%MOD*cmb((m*3-x)/2+n-1,n-1)%MOD)%MOD;
    }
    cout<<ans<<endl;
}

#include <bits/stdc++.h>

#define M_PI       3.14159265358979323846   // pi

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> VI;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> t3;
typedef tuple<ll, ll, ll, ll> t4;
typedef tuple<ll, ll, ll, ll, ll> t5;

#define rep(a,n) for(ll a = 0;a < n;a++)
#define repi(a,b,n) for(ll a = b;a < n;a++)

using namespace std;

static const ll INF = 1e15;

template<typename T>
static inline void chmin(T& ref, const T  value) {
    if (ref > value) ref = value;
}

template<typename T>
static inline void chmax(T& ref, const T value) {
    if (ref < value) ref = value;
}

constexpr ll mod = 1000000007;

class modint {
	static constexpr std::int_fast64_t Modulus = 1e9 + 7;
	using u64 = std::int_fast64_t;

public:
	u64 a;
	constexpr modint(const u64 x = 0) noexcept : a(x% Modulus) {}
	constexpr u64& value() noexcept { return a; }
	constexpr const u64& value() const noexcept { return a; }
	constexpr modint operator+(const modint rhs) const noexcept {
		return modint(*this) += rhs;
	}
	constexpr modint operator-(const modint rhs) const noexcept {
		return modint(*this) -= rhs;
	}
	constexpr modint operator*(const modint rhs) const noexcept {
		return modint(*this) *= rhs;
	}
	constexpr modint& operator+=(const modint rhs) noexcept {
		a += rhs.a;
		if (a >= Modulus) {
			a -= Modulus;
		}
		return *this;
	}
	constexpr modint& operator-=(const modint rhs) noexcept {
		if (a < rhs.a) {
			a += Modulus;
		}
		a -= rhs.a;
		return *this;
	}
	constexpr modint& operator*=(const modint rhs) noexcept {
		a = a * rhs.a % Modulus;
		return *this;
	}
};

int main() {
    int n;
    cin >> n;
    vector<int> vs(n);
    rep(i, n) {
        cin >> vs[i];
    }
    vector<int> colors(3, 0);
    modint all = 1;
    rep(i, n) {
		int same = 0;
		rep(j, 3) {
			if (colors[j] == vs[i]) same++;
		}
		all *= same;
		rep(j, 3) {
			if (colors[j] == vs[i]) {
				colors[j]++;
				break;
			}
		}
    }
	cout << all.a << endl;
    return 0;
}


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

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

#define rep(i,cc,n) for(int i=cc;i<n;++i)
#define lrep(i,cc,n) for(long long i=cc;i<n;++i)
#define sqrep(i,cc,n) for(long long i=cc;i*i<=n;++i)
#define rrep(i,cc,n) for(long i=cc;i>n;--i)
#define pii pair<int, int>
#define pll pair<long long, long long>

using ll = long long;

const vector<int> dx = {1, 0, -1, 0};
const vector<int> dy = {0, 1, 0, -1};
const double PI = 3.1415926535;
const ll inf = 1001001001;
const ll e9  = 1000000000;
const ll mod = 1000000007;

const int MAX = 1000000;
const int MOD = 1000000007;

ll gcd(ll x, ll y) { return (x % y)? gcd(y, x % y): y; }

int main(){
  int n;
  cin >> n;
  vector<ll>a(n);
  rep(i, 0, n)cin >> a[i];
  int cnt=1000;
  rep(i, 0, n){
    int temp=0;
    while(a[i]%2==0){
      a[i]/=2;
      temp++;
    }
    cnt = min(temp,cnt);
  }
  cout << cnt << endl;
}

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

int main() {
  int N,A,a,imin,j;
  cin >> N >> A;
  for (imin = 0; A % 2 == 0; imin++)
    A /= 2;
  for (int i = 0;i < N-1; i++) {
    cin >> a;
    for (j = 0;a % 2 == 0;j++)
      a /= 2;
    if (j < imin)
      imin = j;
  }
  cout << imin << endl;
}


#include<iostream>
using namespace std;
int n, a, b, c;
int main() {
	while (true) {
		cin >> n; if (n == 0) { break; }
		for (int i = 0; i < n; i++) {
			cin >> a >> b >> c;
			if (a + b + c >= 240) { goto A; }
			if (a + b >= 180) { goto A; }
			if (a == 100 || b == 100 || c == 100) { goto A; }
			if (a + b + c >= 210) { goto B; }
			if (a + b + c >= 150 && (a >= 80 || b >= 80)) { goto B; }
			goto C;
		A:; cout << 'A' << endl; goto D;
		B:; cout << 'B' << endl; goto D;
		C:; cout << 'C' << endl; goto D;
		D:;
		}
	}
}

/*
 * src.cpp
 *
 *  Created on: 2016/08/04
 *      Author: joi
 */

#include <bits/stdc++.h>

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)

const int MAX_N=1e4;

int n;
int p[3];

char out[MAX_N+5];

int main(){
	do{
		cin>>n;
		if (n){
			REP(i,n){
				int ave=0;
				bool f=false;
				REP(j,3){
					cin>>p[j];
					ave+=p[j];
					if (p[j]==100){
						f=true;
					}
				}
				if (f){
					out[i]='A';
				}else if (p[0]+p[1]>=180){
					out[i]='A';
				}else if (ave>=80*3){
					out[i]='A';
				}else if (ave>=70*3){
					out[i]='B';
				}else if (ave>=50*3 && (p[0]>=80 || p[1]>=80)){
					out[i]='B';
				}else{
					out[i]='C';
				}
			}
			REP(i,n){
				cout<<out[i]<<endl;
			}
		}
	}while (n);
	return 0;
}


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

int main() {
  int a;
  int b;
  int c;
  int d;
  cin >> a;
  cin >> b;
  cin >> c;
  cin >> d;
  int l = a + b;
  int r = c + d;
  if(l > r){
    cout << "Left" << endl;
  }else if(l == r){
    cout << "Balanced" << endl;
  }else{
    cout << "Right" << endl;
  }
  return 0;
}

#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_poizcy.hpp>
typedef long long  ll;
#define pb                push_back
#define mp                make_pair
#define all(a)            (a).begin(), (a).end()
#define clr(a,h)          memset(a, (h), sizeof(a))
#define mem(a,h)          memset(a, (h), sizeof(a))
#define fi first
#define se second
#define por(a,b) (((a%MOD) * (b%MOD))%MOD)
#define forg(i, b, e, c)    for (ll i = (ll)b; i < (ll)e; i+=c)
#define forr(i, b, e)    for (ll i = b; i < e; i++)

using namespace std;
//using namespace __gnu_pbds;
typedef double lldb;
typedef pair<ll, ll>  ii;
typedef pair<double, double>  iidb;
typedef pair<ii, ll>  iii;
typedef vector<ll>     vi;
typedef vector<vi>     vvi;
typedef vector<ii>      vii;
typedef vector<ll>      vll;
//typedef tree<ii,null_type,less<ii>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
const ll INF = 1e18+7;
const double PI = acos(-1);
const ll MOD= 1e9+7;
#define initseg ll new_nodo=(nodo*2),mid=(iz+der)/2;

//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define tam 210000
#define offset 200
#define ptr nodo*

map<ll,vector<iii> > chocarx,chocary,flechader,flechaiz,flechader2,flechaiz2;
vector<pair<ii,string> >lst,lst2;
ll ANSWER;
void update(ii par1, ii par2)
{
	if (par1.fi==INF|| par2.fi==INF)return;
	ll dist=abs(par1.fi-par2.fi)+abs(par1.se-par2.se);
	ANSWER=min(ANSWER,dist*5);
}
void resolver1(map<ll,vector<iii> > & mapa)
{
	//<<"mira \n";
	for(auto ite:mapa)
	{
		sort(all(ite.se));
		ii actant={INF,INF};
		//<<ite.fi<<":\n";
		for(iii par:ite.second)
		{
			//<<par.fi.fi<<","<<par.fi.se<<" "<<par.se<<" - ";
			if (par.se==1)
			{
				actant=par.fi;
			}
			else
			{
				update(par.fi,actant);
			}
		}
		//<<endl;

	}
}
void resolver2(map<ll,vector<iii> > & mapa)
{
	for(auto ite:mapa)
	{
		sort(all(ite.se));
		ii actant={INF,INF};
		for(iii par:ite.second)
		{
			if (par.se==1)
			{
				actant=par.fi;
			}
			else
			{
				update(par.fi,actant);
			}
		}
	}
}
void solve(vector<pair<ii,string> >este)
{
	ll x,y;
	string tipo;
	chocarx.clear(),chocary.clear(),flechaiz.clear(),flechader.clear();
	flechaiz2.clear(),flechader2.clear();
	for(auto par:este)
	{
		x=par.fi.fi;
		y=par.fi.se;
		tipo=par.se;
		if (tipo=="U" || tipo=="D")
		chocarx[x].pb({{y,x},tipo=="U"});
		else
		chocary[y].pb({{y,x},tipo=="R"});

		if (tipo=="D"|| tipo=="U")
		{
			if (tipo=="U"){
				flechader[x-y].pb({{y,x},tipo=="U"});
				flechaiz[x+y].pb({{y,x},tipo=="U"});
			}
			else
			{
				flechader2[x-y].pb({{y,x},0});
				flechaiz2[x+y].pb({{y,x},0});
			}
		}
		else
		{
			if (tipo=="L")
			{
				flechader[x-y].pb({{y,x},tipo=="U"});
				flechaiz2[x+y].pb({{y,x},1});
			}
			else
			{
				flechaiz[x+y].pb({{y,x},tipo=="U"});
				flechader2[x-y].pb({{y,x},1});
			}
		}
	}

	resolver1(chocarx);
	resolver1(chocary);

	resolver1(flechaiz);
	resolver1(flechader);

	resolver1(flechaiz2);
	resolver1(flechader2);
}
int main()
{
	ANSWER=INF;
	ll n;
	cin>>n;
	ll x,y;
	string tipo;
	map<string,string> inv;
	inv["L"]="R";inv["R"]="L";inv["U"]="D";inv["D"]="U";
	forr(i,0,n)
	{
		cin>>x>>y>>tipo;
		lst.pb({{x,y},tipo});
		lst2.pb({{x,y},inv[tipo]});
	}
	solve(lst);
	//solve(lst2);
	if (ANSWER==INF)
		cout<<"SAFE\n";
	else
		cout<<ANSWER<<endl;
}


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

int a, b, c, n;
int parts[310];
int result[1010][4];
int main()
{
  while(cin >> a >> b >> c && (a || b || c)){
    cin >> n;
    for(int i = 1; i <= a + b + c; i++)
      parts[i] = 2;

    for(int i = 0; i < n; i++)
      for(int j = 0; j < 4; j++)
	cin >> result[i][j];

    for(int i = 0; i < n; i++)
      if(result[i][3])
	parts[result[i][0]] = parts[result[i][1]] = parts[result[i][2]] = 1;

    for(int i = 0; i < n; i++)
      if(!result[i][3]){
	if(parts[result[i][0]] == 1 && parts[result[i][1]] == 1)
	  parts[result[i][2]] = 0;
	if(parts[result[i][1]] == 1 && parts[result[i][2]] == 1)
	  parts[result[i][0]] = 0;
	if(parts[result[i][2]] == 1 && parts[result[i][0]] == 1)
	  parts[result[i][1]] = 0;
      }

    for(int i = 1; i <= a + b + c; i++)
      cout << parts[i] << endl;

  }
  return 0;
}

#include <cstdio>
#include <cstring>
#include <vector>
using namespace std;
struct Info {
	int i,j,k;
	Info(int _i,int _j,int _k) {i=_i,j=_j,k=_k;}
};
vector<Info> info[2];
int result[300];
int main() {
	int a,b,c,N;
	while(scanf("%d %d %d",&a,&b,&c),a|b|c) {
		scanf("%d",&N);
		info[0].clear();
		info[1].clear();
		memset(result,0,sizeof(result));
		for(int i=0;i<N;i++) {
			int I,J,K,R;
			scanf("%d %d %d %d",&I,&J,&K,&R);
			info[R].push_back(Info(I-1,J-1,K-1));
		}
		for(int i=0;i<info[1].size();i++) {
			Info I=info[1][i];
			result[I.i]=result[I.j]=result[I.k]=1;
		}
		for(int i=0;i<info[0].size();i++) {
			Info I=info[0][i];
			if(result[I.i]==1&&result[I.j]==1) result[I.k]=2;
			if(result[I.i]==1&&result[I.k]==1) result[I.j]=2;
			if(result[I.j]==1&&result[I.k]==1) result[I.i]=2;
		}
		for(int i=0;i<(a+b+c);i++) {
			printf("%d\n",(result[i]==2)?0:(result[i]==0)?2:1);
		}
	}
}


#include<bits/stdc++.h>

#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = (n)-1; i >= 0; i--)
#define rep1(i,n) for(int i = 1; i <= (n); i++)
#define rrep1(i,n) for(int i = (n); i > 0; i--)

#define ll long long
#define pi pair<int, int>
#define pll pair<ll, ll>

#define MOD 1000000007
#define INF 1000000000000000LL

using namespace std;

#define MAXN 300

// dp[i][j][k]:1スi枚,2スj枚,3スk枚
double dp[MAXN+1][MAXN+1][MAXN+1];
int n;

double rec(int i, int j, int k){
  if(!i && !j && !k)return 0.0;
  if(dp[i][j][k]>0.0)return dp[i][j][k];

  double sum = i+j+k;
  double ret = n/sum;
  if(i>0)ret += (double)(i/sum) * rec(i-1, j, k);
  if(j>0)ret += (double)(j/sum) * rec(i+1, j-1, k);
  if(k>0)ret += (double)(k/sum) * rec(i, j+1, k-1);

  return dp[i][j][k]=ret;
}

int main(){
  cin>>n;
  double dn=(double)n;
  vector<int>a(n);
  rep(i, n)cin>>a[i];

  map<int, int>m;
  for(auto t:a)m[t]++;

//  cout<<fixed<<setprecision(12)<<rec(m[1], m[2], m[3])<<endl;
  printf("%.12f", rec(m[1], m[2], m[3]));

  return 0;

rep(i, n)rep(j, n)rep(k, n)cout<<dp[i][j][k]<<' '<<i<<' '<<j<<' '<<k<<endl;

  return 0;
}

#include <bits/stdc++.h>

#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0, a1, a2, a3, a4, x, ...) x
#define dump_1(x1) cerr << #x1 << ": " << x1 << endl
#define dump_2(x1, x2) \
  cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << endl
#define dump_3(x1, x2, x3)                                                \
  cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " \
       << x3 << endl
#define dump_4(x1, x2, x3, x4)                                            \
  cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " \
       << x3 << ", " #x4 << ": " << x4 << endl
#define dump_5(x1, x2, x3, x4, x5)                                        \
  cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " \
       << x3 << ", " #x4 << ": " << x4 << ", " #x5 << ": " << x5 << endl
#define dump(...) \
  CHOOSE((__VA_ARGS__, dump_5, dump_4, dump_3, dump_2, dump_1, ~))(__VA_ARGS__)
#define check(s) cerr << s << endl

#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define unique(v) v.erase(unique(v.begin(), v.end()), v.end());
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)

using namespace std;

using ll = long long;

vector<int> dx = {0, 1, 0, -1};
vector<int> dy = {1, 0, -1, 0};

const ll LINF = 2e18;
const int INF = 1e9;

ll N;
std::vector<ll> a;
vector<vector<vector<double>>> dp;

double f(ll c1, ll c2, ll c3) {
  if (dp[c1][c2][c3] != -1.0) return dp[c1][c2][c3];

  if (c1 == 0 && c2 == 0 && c3 == 0) return 0.0;

  double ret = 0.0;
  if (c1 > 0) ret += f(c1 - 1, c2, c3) * c1;
  if (c2 > 0) ret += f(c1 + 1, c2 - 1, c3) * c2;
  if (c3 > 0) ret += f(c1, c2 + 1, c3 - 1) * c3;
  ret += N;
  ret *= 1.0 / (c1 + c2 + c3);
  return dp[c1][c2][c3] = ret;
}

void solve() {
  dp.resize(310, vector<vector<double>>(310, vector<double>(310, -1.0)));

  ll c1 = 0, c2 = 0, c3 = 0;
  rep(i, N) {
    if (a.at(i) == 1) c1++;
    if (a.at(i) == 2) c2++;
    if (a.at(i) == 3) c3++;
  }
  cout << f(c1, c2, c3) << endl;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  scanf("%lld", &N);
  a.resize(N);
  for (int i = 0; i < N; i++) {
    scanf("%lld", &a[i]);
  }
  solve();
  return 0;
}


#include<bits/stdc++.h>

using namespace std;

int main()
{
  vector<int> W;
  vector<int> K;

  for(int i = 0;i < 20;++i){
    int a;
    cin>>a;

    if(i < 10){
      W.push_back(a);
    }
    else{
      K.push_back(a);
    }
  }

  sort(W.begin(),W.end());
  reverse(W.begin(),W.end());
  sort(K.begin(),K.end());
  reverse(K.begin(),K.end());

  int a = 0;
  int W_p = 0;
  int K_p = 0;
  for(int e : W){
    W_p += e;
    ++a;

    if(a == 3){
      a = 0;
      break;
    }
  }

  for(int e : K){
    K_p += e;
    ++a;

    if(a == 3){
      break;
    }
  }

  cout<<W_p<<" "<<K_p<<endl;
  return 0;
}

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

int main(){
	int W[10], K[10];

	for(int i = 0; i < 10; i++) scanf("%d", &W[i]);
	for(int i = 0; i < 10; i++) scanf("%d", &K[i]);

	sort(W, W + 10);
	sort(K, K + 10);

	printf("%d %d\n", W[9] + W[8] + W[7], K[9] + K[8] + K[7]);

	return 0;
}


#include<iostream>
using namespace std;

int a[102][102],color;

void dfs(int x,int y){

    a[y][x] = 9;

    if(a[y+1][x] == color){
      dfs(x,y+1);
    }
    if(a[y][x+1] == color){
      dfs(x+1,y);
    }
    if(a[y-1][x] == color){
      dfs(x,y-1);
    }
    if(a[y][x-1] == color){
      dfs(x-1,y);
    }

}

int main(){

  int xs,ys,xg,yg,n,c,d,x,y,w,h;

  while(1){

    cin >>w>>h;

    if(w == 0 && h == 0)break;

    for(int i = 0 ; i < 102 ; i++){
      for(int j = 0 ; j < 102 ; j++){
	a[i][j]=0;
      }
    }

    cin >>xs>>ys;
    cin >>xg>>yg;

    cin >>n;

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

      cin >> c >> d >> x >> y;

      if( d == 0 ){
	for(int i = 0 ; i < 2 ; i++){
	  for(int j = 0 ; j < 4 ; j++){
	    a[i+y][j+x] = c;
	  }
	}
      }else{
	for(int i = 0 ; i < 4 ; i++){
	  for(int j = 0 ; j < 2 ; j++){
	    a[i+y][j+x] = c;
	  }
	}
      }

    }

    /*
      for(int i = 0 ; i < h+2 ; i ++){
      for(int j = 0 ; j < w+2 ; j++){
      cout << a[i][j];
      }
      cout <<endl;
      }
      cout <<endl;
    */

    if(a[ys][xs] != 0){
      color = a[ys][xs];
      dfs(xs,ys);
    }

    /*
      for(int i = 0 ; i < h+2 ; i ++){
      for(int j = 0 ; j < w+2 ; j++){
      cout << a[i][j];
      }
      cout <<endl;
      }
    */

    if(a[yg][xg] == 9){
      cout <<"OK"<<endl;
    }else{
      cout <<"NG"<<endl;
    }

  }

  return 0;

}

#include<iostream>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;

int main(){
	int n,p;
	while(1){
		cin>>n>>p;
		if(n==0 && p==0)break;
		int dt[n];
		int cop=p;
		int counta=0;
		rep(i,n)dt[i]=0;
		int ans;
		while(1){
			counta=counta%n;
			if(cop!=0){
				dt[counta]++;
				cop--;
			}else{
				int judge=0;
				rep(i,n){
					if(i!=counta)if(dt[i]==0)judge++;
				}
				if(judge==n-1){
					ans=counta;
					break;
				}else{
					cop=dt[counta];
					dt[counta]=0;
				}
			}
			counta++;
		}
		cout<<ans<<endl;
	}
	return 0;
}


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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}

int nextInt() { int x; scanf("%d", &x); return x;}

ll MOD = (ll)(1e9 + 7);

const int MAX_N = 1010;

const int SZ = 312345;

ll inv[SZ];
ll fact[SZ];
ll fact_inv[SZ];
ll choose(int n, int r) {
  if (n < 0 || r < 0 || n < r) return 0;
  return fact[n] * fact_inv[n-r] % MOD * fact_inv[r] % MOD;
}

ll mod_pow(ll a, ll b, ll p) {
  ll res = 1;
  while (b > 0) {
    if (b & 1) res = (res * a) % p;
    a = (a * a) % p;
    b >>= 1;
  }
  return res;
}

ll f(int m, int k) {
  ll res = fact[m*k];
  (res *= mod_pow(fact_inv[m], k, MOD)) %= MOD;
  (res *= fact_inv[k]) %= MOD;
  return res;
}

ll A, B, C, D;
ll dp[MAX_N][MAX_N];

ll rec(int n, int m) {
  if (n < 0) return 0;
  if (m == 0 && n == 0) return 1;
  if (m == 0 && n > 0) return 0;
  if (dp[n][m] != -1) return dp[n][m];
  ll res = rec(n, m-1);
  if (A <= m && m <= B) {
    for (int k = C; k <= D; k++) {
      if (n - k*m < 0) break;
      ll cur = rec(n - k*m, m-1);
      (cur *= choose(n, k*m)) %= MOD;
      (cur *= f(m, k)) %= MOD;
      res += cur;
    }
  }
  res %= MOD;
  return dp[n][m] = res;
}

int main2() {
  CLR(dp, -1);
  int N = nextInt();
  A = nextInt();
  B = nextInt();
  C = nextInt();
  D = nextInt();
  ll ans = rec(N, N);
  cout << ans << endl;
  return 0;
}

int main() {
  {
    inv[1] = 1;
    for (int i = 2; i < SZ; i++) inv[i] = inv[(int) (MOD % i)] * (MOD - MOD / i) % MOD;
    fact[0] = 1;
    for (int i = 1; i < SZ; i++) fact[i] = fact[i-1] * i % MOD;
    fact_inv[0] = 1;
    for (int i = 1; i < SZ; i++) fact_inv[i] = fact_inv[i-1] * inv[i] % MOD;
  }
#ifdef LOCAL
  for (;!cin.eof();cin>>ws)
#endif
    main2();
  return 0;
}

#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
#include<complex>
#include<numeric>
using namespace std;

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
ll mod = 998244353;
const ll INF = mod * mod;
typedef pair<int, int>P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-12;
const ld pi = acos(-1.0);

ll mod_pow(ll a, ll n, ll m = mod) {
	ll res = 1;
	while (n) {
		if (n & 1)res = res * a%m;
		a = a * a%m; n >>= 1;
	}
	return res;
}

struct modint {
	ll n;
	modint() :n(0) { ; }
	modint(ll m) :n(m) {
		if (n >= mod)n %= mod;
		else if (n < 0)n = (n%mod + mod) % mod;
	}
	operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint &a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint &a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint &a, modint b) { a.n = ((ll)a.n*b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, int n) {
	if (n == 0)return modint(1);
	modint res = (a*a) ^ (n / 2);
	if (n % 2)res = res * a;
	return res;
}

ll inv(ll a, ll p) {
	return (a == 1 ? 1 : (1 - p * inv(p%a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }
const int max_n = 10000;
modint fact[max_n], factinv[max_n];
void init_f() {
	fact[0] = modint(1);
	for (int i = 0; i < max_n - 1; i++) {
		fact[i + 1] = fact[i] * modint(i + 1);
	}
	factinv[max_n - 1] = modint(1) / fact[max_n - 1];
	for (int i = max_n - 2; i >= 0; i--) {
		factinv[i] = factinv[i + 1] * modint(i + 1);
	}
}
modint comb(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[b] * factinv[a - b];
}

int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };

modint dp[6001][2001];
void solve() {
	int n; cin >> n >> mod;
	init_f();
	dp[3 * n][0] = 1;
	for (int i = 3 * n; i > 0; i--) {
		for (int j = 0; j <= n; j++) {
			//one
			dp[i - 1][j] += dp[i][j];
			//two
			if (i>=2&&j < n) {
				dp[i - 2][j+1] += dp[i][j] * comb(i - 1, 1);
			}
			//three
			if (i >= 3 && j < n) {
				dp[i - 3][j + 1] += dp[i][j] * comb(i - 1, 2)*(modint)2;
			}
		}
	}
	modint ans = 0;
	rep(i, n + 1)ans += dp[0][i];
	cout << ans << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(7);
	//init_f();
	//init();
	//int t; cin >> t; rep(i, t)solve();
	solve();
	stop
		return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int (i)=0;(i)<(n);i++)
#define INF 1001001001
#define LLINF 1001001001001001001
#define MOD 1000000007
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define ALL(v) v.begin(), v.end()
typedef long long ll;
const ll mod=1000000007;

ll powmod(ll x,ll y){
    ll res=1;
    for(ll i=0;i<y;i++){
        res=res*x%mod;
    }
    return res;
}

int main(){
    int n;cin >> n;
    ll a[n];
    rep(i,n)cin >> a[i];
    sort(a,a+n);

    for(int i=0;i<n-1;i++){
        if(a[i]==a[i+1]){
            cout << "NO" << endl;
            return 0;
        }
    }

    cout << "YES" << endl;
}

#include <iostream>
//#include<stack>
#include<set>
#include<bits/stdc++.h>
using namespace std;
//int f[10005];
//int chazhao(int x)
//{
//	if(x==f[x])
//	return x;
//	else
//	return f[x]=chazhao(f[x]);
//}

int main()
{
	set<int >ss;
	int n,x;
	cin>>n>>x;
	ss.insert(x);
	for(int i=1;i<n;i++)
	{
		cin>>x;
	  if(ss.count(x)==0)
	  ss.insert(x);
	  else
	  continue;
	}
   int k=ss.size();
   if(k==n)
   cout<<"YES"<<endl;
   else
   cout<<"NO"<<endl;
 return 0;
}


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

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)
#define sz(obj) ((int)(obj).size())
#define pf push_front
#define pb push_back

int main()
{
  int n;
  cin >> n;
  int a[3] = {0};
  REP(i, n) cin >> a[i];
  if (n == 2){
    FOR(i, 1, min(a[0], a[1]) + 1){
      if (a[0] % i == 0 && a[1] % i == 0) cout << i << endl;
    }
  }
  else {
    FOR(i, 1, min(min(a[0], a[1]), a[2]) + 1){
      if (a[0] % i == 0 && a[1] % i == 0 && a[2] % i == 0) cout << i << endl;
    }
  }
}

#include <algorithm>
#include <functional>
#include <iostream>
#include <vector>

using namespace std;

int main()
{
    int n;
    cin >> n;

    auto gcd = [](int mm, int nn) {
        function<int(int, int)> f = [&f](int m, int n) {
            if (n == 0) {
                return m;
            }
            else {
                return f(n, m % n);
            }
        };
        return f(max(mm, nn), min(mm, nn));
    };
    auto gcd3 = [gcd](int n, int m, int o) { return gcd(n, gcd(m, o)); };
    vector<int> r;
    if (n == 2) {
        int a, b;
        cin >> a >> b;
        const auto s = gcd(a, b);
        for (int i = 1; i <= s; ++i) {
            if (a % i == 0 && b % i == 0) {
                r.push_back(i);
            }
        }
    }
    else {
        int a, b, c;
        cin >> a >> b >> c;
        const auto s = gcd3(a, b, c);
        for (int i = 1; i <= s; ++i) {
            if (a % i == 0 && b % i == 0 && c % i == 0) {
                r.push_back(i);
            }
        }
    }
    for (auto i : r) {
        cout << i << endl;
    }
}


// Problem : E - Colorful Blocks
// Contest : AtCoder - AtCoder Beginner Contest 167
// URL : https://atcoder.jp/contests/abc167/tasks/abc167_e
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
#define int long long
#define fastio                      \
  ios_base::sync_with_stdio(false); \
  cin.tie(0);                       \
  cout.tie(0);
#define sz(a) (int)((a).size())
#define pb push_back
#define mp make_pair
#define db1(x) cout << #x << "=" << x << endl
#define db2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define db3(x, y, z)                                                       \
  cout << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z \
       << endl
#define dbp(x) \
  cout << #x << "= {" << (x.first) << ", " << (x.second) << "}" << endl;
#define dbv(v)                         \
  {                                    \
    cout << #v << " : ";               \
    for (auto x : v) cout << x << ' '; \
    cout << endl;                      \
  }
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define rep2(i, a, b) for (int i = a; i >= b; i--)
#define die(x) return cout << x << '\n', 0;
const int MOD = 998244353;

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
const int MAX = 2e5;
ll modulo(ll a, ll b, ll n) {
  ll x = 1, y = a;
  while (b > 0) {
    if (b % 2 == 1) {
      x = (x * y) % n;  // multiplying with base
    }
    y = (y * y) % n;  // squaring the base
    b /= 2;
  }
  return x % n;
}
vi fact(MAX + 1), factinv(MAX + 1);

void pre() {
  fact[0] = 1;
  factinv[0] = 1;
  for (int i = 1; i <= MAX; ++i) {
    fact[i] = (fact[i - 1] * i) % MOD;
    factinv[i] = (factinv[i - 1] * modulo(i, MOD - 2, MOD)) % MOD;
  }
}

int mult(int a, int b) { return (a * b) % MOD; }
int nCr(int n, int r) {
  return mult(fact[n], mult(factinv[r], factinv[n - r]));
}

int32_t main() {
  fastio;
  //  freopen("input.txt", "r", stdin);
  //  freopen("output.txt", "w", stdout);
  int testcases;
  testcases = 1;
  // cin>>testcases;
  pre();
  while (testcases--) {
    int n, m, k;
    cin >> n >> m >> k;
    int ans = 0;
    rep(i, 0, k) {
      int temp = nCr(n - 1, i);
      temp = mult(temp, m);
      temp = mult(temp, modulo(m - 1, n - 1 - i, MOD));
      ans = (ans + temp) % MOD;
    }
    cout << ans << '\n';
  }

  return 0;
}

#include <bits/stdc++.h>
#define LL long long
using namespace std;
const int maxn=200005,K=998244353;
int n,m,p,ans,fac[maxn],inv[maxn];
int C(int A,int B) { return (LL)fac[A]*inv[B]%K*inv[A-B]%K; }
int Pow(int A,int B)
{
	int res=1;
	while (B)
	{
		if (B&1) res=(LL)res*A%K;
		A=(LL)A*A%K;
		B>>=1;
	}
	return res;
}
int main()
{
	scanf("%d%d%d",&n,&p,&m);
	fac[0]=1;
	for (int i=1;i<=n;i++) fac[i]=(LL)fac[i-1]*i%K;
	inv[n]=Pow(fac[n],K-2);
	for (int i=n-1;i>=0;i--) inv[i]=(LL)inv[i+1]*(i+1)%K;
	for (int i=m,now=(LL)p*Pow(p-1,n-m-1)%K;i>=0;i--)
	{
		//cerr<<">>>>>>"<<now<<endl;
		ans=(ans+(LL)now*C(n-1,i))%K;
		now=(LL)now*(p-1)%K;
	}
	printf("%d\n",ans);
	return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <numeric>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <deque>
#include <cmath>
#include <complex>
#include <cassert>
#include <cstring>
#include <functional>
#include <bitset>
#include <climits>

using namespace std;
typedef  long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
#define  MP make_pair
#define  PB push_back
#define inf  (1LL << 60)
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define cmn(x,y) x=min(x,y)
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}
template<typename T> class segtree {
private:
    int n,sz;
    vector<pair<T, int> > node;
public:
    segtree(vector<T>& v){
        sz = (int)v.size();
        n = 1;
        while(n < sz){
            n *= 2;
        }
        node.resize(2*n);
        rep(i,sz){
            node[i+n] = make_pair(v[i], i);
        }
        for(int i=n-1; i>=1; i--){
            node[i] = min(node[2*i], node[2*i+1]);
        }
    }
    void update(int k, T a)
    {
    	node[k+=n] = make_pair(a, k);
    	while(k>>=1){
            node[k] = min(node[2*k], node[2*k+1]);
    	}
    }
    pair<T, int> query(int a,int b,int k=0,int l=0,int r=-1)
    {
        pair<T, int> res1 = make_pair(inf, -1);
        pair<T, int> res2 = make_pair(inf, -1);
        a += n, b += n;
        while(a != b){
            if(a % 2) cmn(res1, node[a++]);
            if(b % 2) cmn(res2, node[--b]);
            a >>= 1, b>>= 1;
        }
        return min(res1, res2);
    }
    void print()
    {
        rep(i,sz){
            pair<T, int> p;
            p = query(i,i+1);
            cout << "st[" << i << "]: " << p.first << " " << p.second << endl;
        }
    }
};

int n;
ll d;
ll saiki(segtree<ll>& sg, int a,int b){
    //cerr << a << " " << b << endl;
    if(b==a+1)return 0;
    auto p = sg.query(a,b);
    ll s = p.first;
    ll ans = 0;
    int ind = p.second;
    if(ind-1>=a){
        ll xx = sg.query(ind-1,ind).first;
        ans += s+d+xx;
        sg.update(ind-1,min(xx,s+d));
        ans += saiki(sg,a,ind);
    }
    if(ind+1<b){
        ll xx = sg.query(ind+1,ind+2).first;
        ans += s+d+xx;
        sg.update(ind+1,min(xx,s+d));
        ans += saiki(sg,ind+1,b);
    }
    return ans;
}

int main(){
    cin >> n >> d;
    vector<ll>v(n+1);
    rep(i,n)cin >> v[i];
    segtree<ll> sg(v);
    ll ans = saiki(sg,0,n);
    cout << ans << endl;
    return 0;
}

#include<stdio.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<string.h>

#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define NDEBUG
#define eprintf(...) do {} while (0)
#endif
#include<cassert>

using namespace std;

typedef long long LL;
typedef vector<int> VI;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define EACH(i,c) for(__typeof((c).begin()) i=(c).begin(),i##_end=(c).end();i!=i##_end;++i)

template<class T> inline void amin(T &x, const T &y) { if (y<x) x=y; }
template<class T> inline void amax(T &x, const T &y) { if (x<y) x=y; }
template<class Iter> void rprintf(const char *fmt, Iter begin, Iter end) {
    for (bool sp=0; begin!=end; ++begin) { if (sp) putchar(' '); else sp = true; printf(fmt, *begin); }
    putchar('\n');
}

int N;

struct Data {
    int h, p;
    bool operator<(const Data &o) const {
	return min(h, o.h-p) > min(o.h, h-o.p);
    }
} D[5011];

LL X[5011];

void MAIN() {
    scanf("%d", &N);
    REP (i, N) scanf("%d%d", &D[i].h, &D[i].p);
    sort(D, D+N);

    memset(X, 0x3f, sizeof X);
    LL INF = X[0];
    X[0] = 0;
    REP (i, N) {
	for (int j=i; j>=0; j--) {
	    if (X[j] <= D[i].h) {
		amin(X[j+1], X[j] + D[i].p);
	    }
	}
    }
    int ans = 0;
    REP (i, N+1) if (X[i] < INF) ans = i;
    printf("%d\n", ans);
}

int main() {
    int TC = 1;
//    scanf("%d", &TC);
    REP (tc, TC) MAIN();
    return 0;
}


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

int main() { int N, K;
  cin >> N >> K;
  int s = 1;

  for (int i = 0; i < N; i++){
      if(s<K){
        s = 2 * s;
      }
      else{
        s = s + K;
      }

  }
  cout << s << endl;

}

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

int main() {
    int a,b;
    cin>>a>>b;
    if(a==b)
        cout<<a+b;
    else{
        int mx=max(a,b);
        int k=(mx-1)+mx;
        cout<<k;
    }
}


#include <bits/stdc++.h>
# define M_PI           3.14159265358979323846  /* pi */
using namespace std;

int main() {
	int N;
	cin >> N;
	vector<int>A(N);
	int count = 0;
	int result = 200;

	for (int i = 0; i < N; i++) {
		cin >> A.at(i);

		while (true) {
			if (A.at(i) % 2 != 0 || A.at(i) == 0) {
				break;
			}

			else if (A.at(i) % 2 == 0) {
				A.at(i) = A.at(i) / 2;
				count++;
			}
		}

		result = min(result, count);
		count = 0;
	}

	cout << result << endl;
}

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

#define PRINT(STR) cout << STR << endl;
#define REP(i, n) for (int (i) = 0; (i) < (int)(n); (i)++)
#define REG(i, a, b) for (int (i) = ((int)(a)); (i) < ((int)(b)); i++)
#define ALL(V) (V).begin(), (V).end()

typedef long long ll;

using namespace std;

int nextInt() { int n = -1; cin >> n; return n; }
double nextDouble() { double d = -1; cin >> d; return d; }
ll nextll() { ll n = -1; cin >> n; return n; }
string nextString() { string str; cin >> str; return str; }

int INF = 1LL << 25;
double EPS = 1e-9;

// BEGIN //////////////////////////////////////////////////////////////

int main() {
	while (true) {
		int N = nextInt();
		if (N == 0) break;
		int score_max = -INF, score = 0;
		REP(i, N) {
			int d = nextInt();
			score += d;
			score_max = max(score, score_max);
			score = max(score, 0);
		}
		PRINT(score_max);
	}

	return 0;
}

// END   //////////////////////////////////////////////////////////////


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

int main()
{
 vector<int>v;
 int a,b,c,k;
 cin >> a >> b >> c >> k;
 v.push_back(a);
 v.push_back(b);
 v.push_back(c);
 int sum = 0;
 while(k--)
 {
     sort(v.begin(),v.end());
     v[2]*=2;

 }

 sum = v[0] + v[1] + v[2];
 cout << sum << endl;

}

#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
  int n;
  cin>>n;
  int a[n][n];
  for(int i=0;i<n;i++)
    for(int j=0;j<n;j++)
      cin>>a[i][j];
  int ans=0;
  bool used[n];
  memset(used,0,sizeof(used));
  used[0]=1;
  int cost[n];
  for(int i=0;i<n;i++) cost[i]=a[0][i];
  while(1){
    int v=-1;
    for(int i=0;i<n;i++){
      if(used[i]||cost[i]<0) continue;
      //cout<<i<<":"<<cost[i]<<endl;
      if(v<0||cost[i]<cost[v]) v=i;
    }
    if(v<0) break;
    used[v]=1;
    ans+=cost[v];
    //cout<<v<<endl;
    for(int i=0;i<n;i++){
      if(a[v][i]<0) continue;
      if(cost[i]<0||a[v][i]<cost[i]) cost[i]=a[v][i];
    }
  }
  cout<<ans<<endl;
  return 0;
}


#include<bits/stdc++.h>
using namespace std;
const long long INF = 1LL << 60;
template<class T> inline bool chmax(T& a, T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a, T b){if(a>b){a=b;return 1;}return 0;}
#define rep(i,n) for(int i=0;i<n;i++)
#define all(a)  (a).begin(),(a).end()
#define P pair<int, int>
#define ll long long
const int MOD = 1000000007;
//bitset<64>(x).count()
//fixed << setprecision(15) <<

int main(){
  int n, l;
  cin >> n >> l;
  ll ans = (n*(n+2*l-1))/2;
  if(l>=0)
    ans -= l;
  else
    if(n+l-1<0)
      ans -=n+l-1;
  cout << ans << endl;
}

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <iomanip>

using namespace std;

int main() {
	int N, L;
	cin >> N >> L;
	int applepie = 0;
	for (int i = 1; i <= N; i++) {
		applepie += L + i - 1;
	}
	int ans;
	int diff = abs(L + 1 - 1);
	for (int i = 2; i <= N; i++) {
		diff = min(diff, abs(L + i - 1));
	}
	for (int i = 1; i <= N; i++) {
		if (abs(L + i - 1) == diff) ans = applepie - (L + i - 1);
	}
	cout << ans << endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main() {
  int A, B, C; cin >> A >> B >> C;
  cout << (((A < C && C < B) || (A > C && C > B)) ? "Yes" : "No") << endl;
}

#include <bits/stdc++.h>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstring>
#include <chrono>
#include <complex>
#define int long long int
#define vi vector<int>
#define vvi vector < vi >
#define pii pair<int,int>
#define mod 1000000007
#define inf 1000000000000000001
#define all(c) c.begin(),c.end()
#define mp(x,y) make_pair(x,y)
#define mem(a,val) memset(a,val,sizeof(a))
#define eb emplace_back
#define f first
#define s second
#define tr(k,st,en) for(int k = st; k <= en ; k++)

using namespace std;

int32_t main()
{
    std::ios::sync_with_stdio(false);
    int a,b,c;
    cin>>a>>b>>c;
    cout<<c<<' '<<a<<' '<<b<<endl;
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <utility>
#include <queue>
#include <climits>
using namespace std;

void floyd(vector<vector<long long> >& d)
{
    for (int k = 0; k < d.size(); k++) {
        for (int i = 0; i < d.size(); i++) {
            if (LLONG_MAX == d[i][k]) continue;
            for (int j = 0; j < d.size(); j++) {
                if (LLONG_MAX == d[k][j]) continue;
                d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
            }
        }
    }
}

int main()
{
    int v, e;
    cin >> v >> e;
    vector<vector<long long> > d(v, vector<long long>(v, LLONG_MAX));
    int s, t;
    for (int i = 0; i < v; i++) d[i][i] = 0;
    for (int i = 0; i < e; i++) {
        cin >> s >> t;
        cin >> d[s][t];
    }
    floyd(d);

    // check negative cycle
    for (int i = 0; i < v; i++) {
        if (d[i][i] < 0) {
            cout << "NEGATIVE CYCLE" << endl;
            return 0;
        }
    }

    for (int i = 0; i < v; i++) {
        for (auto itr = d.at(i).begin(); itr != d.at(i).end(); ++itr) {
            if (itr != d.at(i).begin()) cout << " ";
            if (LLONG_MAX == *itr) cout << "INF";
            else cout << *itr;
        }
        cout << endl;
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main(){
  int R;
  cin>>R;
  if(R<1200) cout<<"ABC"<<endl;
  else if(1200<=R && R<2800) cout<<"ARC"<<endl;
  else cout<<"AGC"<<endl;
  return 0;
}

#include <bits/stdc++.h>

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define bit(n) (1LL<<(n))

// #define DEBUG

#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif

template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}

using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;

const double EPS = 1e-10;
const double PI = acos(-1.0);
const int inf = INT_MAX;
const ll INF = LLONG_MAX;
const ll MOD = 1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};

ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b, const ll mod=MOD) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b, const ll mod=MOD) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b, const ll mod=MOD) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b, const ll mod=MOD) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);

    int R; cin >> R;

    string res = "AGC";
    if(R < 1200){
        res = "ABC";
    }
    else if(R < 2800){
        res = "ARC";
    }

    cout << res << endl;

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main(){

  int n, x;
  cin>>n>>x;

  long long int ans=0;
  long long int a;
  cin>>a;
  for(int i=0; i<n-1; i++){
    long long int b;
    long long int eat=0;
    cin>>b;

    eat=max(a+b-x, eat);
    ans+=eat;

    if(b<=eat) b=0;
    else b=b-eat;
    a=b;
  }

  cout<<ans<<endl;
}

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;

typedef pair<int, int> p;

int main() {
	cin.tie(0);
    ios::sync_with_stdio(false);

    int N;
    ll x;
    cin >> N >> x;

    vector<ll> a(N);

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

    ll ans = 0;

    for(int i = 1; i < N; i++) {
        if(a[i] + a[i - 1] <= x) continue;
        if(a[i - 1] <= x) {
            ans += a[i] + a[i - 1] - x;
            a[i] -= a[i] + a[i - 1] - x;
            //cerr << "a " << a[i - 1] << " " << a[i] << endl;
        } else {
            ans += a[i];
            a[i] = 0;
            ans += a[i - 1] - x;
            a[i - 1] = x;
            //cerr << "b " << a[i - 1] << " " << a[i] << endl;
        }
    }

    cout << ans << endl;
}


#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPS(I, a, b) for (int i = (a); i < (b); ++i)
using namespace std;
using ll = long long;

int main() {
  int n;
  cin >> n;
  vector<int> a(n,0);
  REP(i,n) cin >> a[i];

  sort(a.begin(), a.end());

  bool ok = true;
  REP(i,n){
    if(i != n-1){
      if(a[i] == a[i+1]){
        ok = false;
      }
    }
  }

  if(ok) cout << "YES" << endl;
  else cout << "NO" << endl;

}

#define _CRT_NO_SECURE_WARNINGS
#pragma warning(disable:4996)
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <cassert>
#include <cstdio>
#include <string>
#include <iomanip>
#include <set>
#include <random>
#include <queue>
#include <map>
#include <ctime>
#include <sstream>
#include <cstdlib>
using namespace std;
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
using namespace std; int INF = 1e6; typedef long long ll; typedef double d; typedef unsigned long long ull;

void solve() {
	int a, b, c;
	cin >> a >> b >> c;
	int first = a, s = b, th = c;
	vector<int>test(3);
	test[0] = first;
	test[1] = s;
	test[2] = th;
	sort(test.begin(), test.end());
	c == test[1] ? cout << "Yes" << endl : cout << "No" << endl;

}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	solve();
	return 0;
}


#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
using bint = boost::multiprecision::cpp_int;
using ll = long long;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repSE(i,s,n) for (int i = (s); i < (n); i++)
#define rrepSE(i,s,e) for (int i = (s); i > (e); i--)
#define ssort(v) sort(v.begin(), v.end())
#define gsort(v) sort(v.rbegin(), v.rend())
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &vec){ os << "["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const deque<T> &vec){ os << "deq["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa){ os << "(" << pa.first << "," << pa.second << ")"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const unordered_map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
template<typename T> bool chmax(T &m, const T q) { if (m < q) {m = q; return true;} else return false; }
template<typename T> bool chmin(T &m, const T q) { if (q < m) {m = q; return true;} else return false; }
#define DEBUG_PRINT(var) std::cout << #var << " = " << var << "\n";

int main()
{
    int n;
    cin >> n;
    vector<int> a(n), b(n), c(n);
    rep(i,n) cin >> a[i];
    rep(i,n) cin >> b[i];
    rep(i,n) cin >> c[i];
    ssort(a); ssort(b); ssort(c);
    vector<ll> upc(n), acu_upc(n);
    rep (i, n) {
        auto it = upper_bound(c.begin(), c.end(), b[i]);
        int cnt = c.end() - it;
        if (cnt < 0) cnt = 0;
        upc[i] = cnt;
    }
    acu_upc[n - 1] = upc[n-1];
    rrepSE (i, n - 2, -1) {
        acu_upc[i] = acu_upc[i+1] + upc[i];
    }
    ll ans = 0;
    rep(i,n) {
        auto it = upper_bound(b.begin(), b.end(), a[i]);
        int j = it - b.begin();
        if (j<=n-1) {
            ans += acu_upc[j];
        }
    }
    cout << ans << "\n";
    return 0;
}

#include<iostream>
using namespace std;
const int maxn = 200001;
const int INF = 0x7fffffff;

int L[maxn], R[maxn];
long long merge(int A[], int n, int left, int mid, int right)
{
    int i, j, k;
    long long cnt = 0;
    int n1 = mid - left;
    int n2 = right - mid;

    for(int i = 0; i < n1; i++) L[i] = A[left + i];
    for(int i = 0; i < n2; i++) R[i] = A[mid + i];
    L[n1] = R[n2] = INF;

    i = j = 0;
    for(int k = left; k < right; k++)
    {
        if(L[i] <= R[j])
            A[k] = L[i++];
        else
        {
            A[k] = R[j++];
            cnt += n1 - i;
        }
    }
    return cnt;
}

long long mergeSort(int A[], int n, int left, int right)
{
    int mid;
    long long v1, v2, v3;
    if(left + 1 < right)
    {
        mid = (left + right) / 2;
        v1 = mergeSort(A, n, left, mid);
        v2 = mergeSort(A, n, mid, right);
        v3 = merge(A, n, left, mid, right);
        return v1 + v2 + v3;
    }
    else
        return 0;
}

int main()
{
    int A[maxn], n;

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

    long long ans = mergeSort(A, n, 0, n);
    cout << ans << endl;
    return 0;
}


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

int N = 0, M = 0;
int points[1001];
int scores[1002001];

bool check(int a, int c){
    if(a >= (N + 2) * (N + 1) / 2 - 1){
        return true;
    }
    return (scores[a] <= c && scores[a + 1] > c);
}

int search2(int a, int b, int c){
    int pib = a + b - b / 2;
    if(check(pib, c)){
        return pib;
    }else if(scores[pib] < c){
        return search2(pib, b / 2, c);
    }else{
        return search2(a, b / 2, c);
    }
}

int main(){
    for(;;){
        for(int i = 0; i < 1001; i++){
            points[i] = 0;
        }
        for(int i = 0; i < 1002001; i++){
            scores[i] = 0;
        }
        if(cin >> N){
            if(N == 0){
                break;
            }
            cin >> M;
            for(int i = 1; i <= N; i++){
                cin >> points[i];
            }
            for(int i = 0; i <= N; i++){
                for(int j = i; j <= N; j++){
                    scores[(2 * N - i + 1) * i / 2 + j] = points[i] + points[j];
                }
            }
            int mxsco = 0;
            sort(scores, scores + ((N + 2) * (N + 1)) / 2);
            for(int i = 0; i < (N + 2) * (N + 1) / 2; i++){
                if(scores[i] > M){
                    break;
                }
                int nosco = scores[i] + scores[search2(0, (N + 2) * (N + 1) / 2, M - scores[i])];
                if(nosco >= mxsco &&  nosco <= M){
                    mxsco = nosco;
                }
            }
            cout << mxsco << endl;
        }else{
            break;
        }
    }
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define Rep(i, N) for(int i = 0; i < N; i++)

int main()
{
  int N, M;

  while(cin >> N >> M, N || M) {
    int A[1005] = {0};
    vector<int>sum;
    int maxv = 0;
    sum.push_back(0);
    for(int i = 1; i <= N; i++) {
      cin >> A[i];
      Rep(j, i + 1) {
	if(A[i] + A[j] <= M) sum.push_back(A[i] + A[j]);
      }
    }
    sort(sum.begin(), sum.end());
    Rep(i, sum.size()) {
      maxv = max(maxv, sum[i] + *(upper_bound(sum.begin(), sum.end(), M - sum[i]) - 1));
    }
    cout << maxv << endl;
  }
  return 0;
}


#include<bits/stdc++.h>
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define input freopen("1.txt","r",stdin);
#define output freopen("output.txt","w",stdout);
#define ll long long int
#define pb push_back
#define ppb pop_back
#define eb emplace_back
#define vi vector<int>
#define vii vector<vi>
#define vl vector<ll>
#define vll vector<vl>
#define pii pair<int, int>
#define pll pair<ll,ll>
#define mp make_pair
#define vpi vector<pii>
#define vpl vector<pll>
#define ss second
#define ff first

using namespace std;

const int p = 1e9 + 7;
const int maxn = 1e5 + 1;

void solve() {
    int n; cin >> n;
    int l[n];
    // vi psides;
    for(int i = 0; i < n; i++) cin >> l[i];
    int ans = 0;
    for(int i = 0; i < n; i++) {
        for(int j = i+1; j < n; j++) {
            for(int k = j+1; k < n; k++) {
                if(l[i] != l[j] && l[i] != l[k] && l[j] != l[k]) {
                    vi sides = {l[i], l[j], l[k]};
                    sort(sides.begin(), sides.end());
                    if(sides[0] + sides[1] > sides[2]) ans++;
                }
            }
        }
    }
    cout << ans;
}

int main() {
    fast
    int t = 1;
    // cin >> t;
    while(t--) solve();
    return 0;
}

#include<bits/stdc++.h>

#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define mp make_pair
#define pb push_back
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define dbg(x) cerr<<__LINE__<<": "<<#x<<" = "<<(x)<<endl

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
const int inf = (int)1e9;
const double INF = 1e12, EPS = 1e-9;

char in[1000100];

int main(){
	fgets(in, sizeof(in), stdin);
	vector<pi> v;
	int cnt = 0, ans = 0;

	for(int i = 0; ; i++){
		if(i && in[i] != in[i - 1]){
			v.pb(mp(in[i - 1], cnt));
			cnt = 1;
		}
		else cnt++;
		if(!in[i]) break;
	}

	rep(i, v.size() - 2) if(v[i].first == 'J'
		&& v[i + 1].first == 'O'
		&& v[i + 2].first == 'I'){

		if(v[i + 1].second <= v[i].second && v[i + 1].second <= v[i + 2].second)
		ans = max(ans, v[i + 1].second);
	}

	cout << ans << endl;

	return 0;
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, a, b) for(int i = a; i < b; i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fi first
#define se second
#define debug(x) cerr <<__LINE__<< ": " <<#x<< " = " << x << endl
#define debug_vec(v) cerr<<__LINE__<<": "<<#v<<" = ";rep(i,v.size())cerr<<" "<<v[i];cerr<<endl
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = (1<<30) - 1;
const ll LINF = (1LL<<60) - 1;

void solve() {
    int n;
    cin >> n;
    vector<int> A(n);
    for (auto &a : A) cin >> a;
    sort(all(A));
    A.erase(unique(all(A)), A.end());
    if (n == (int)A.size()) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    solve();
    return 0;
}

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

typedef long long ll;
const int INF = 1e9;
const ll LINF = 1e18;
const int mod = 1e9+7;

#define pi pair<int,int>
#define pl pair<lld,lld>

#define dump(x) cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define SANKOU(n,a,b) cout << ((n) ? (#a) : (#b) ) << endl

#define mem0(x) memset(x,0,sizeof(x))
#define fillnum(x,n) fill(begin(x),end(x),n)
#define asort(x) sort(x.begin(),x.end())
#define dsort(x,t) sort(x.begin(),x.end(),greater<t>())
#define vuniq(x) x.erase(unique(x.begin(), x.end()), x.end())

#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)

int main() {
    string S;
    cin >> S;
    if(S.size() == 3){
        reverse(S.begin(),S.end());
        cout << S << endl;
    } else {
        cout << S << endl;
    }
}


#include <bits/stdc++.h>
using namespace std;
long long fac[1010], finv[1010], inv[1010];
long long MOD = 1000000007;
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < 1005; i++) {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
long long COM(int n, int k) {
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
long long group(int k, int n, int r){
	long long num = COM(r, k*n) * fac[k*n] % MOD;
	for(int i = 0; i < n; i++){
		num *= finv[k]; num %= MOD;
	}
	num *= finv[n]; num %= MOD;
	return num; // r人残っているときにk人のグループをn個作る方法
}
int main(){
	int N, A, B, C, D;
	cin >> N >> A >> B >> C >> D;
	COMinit();
	long long dp[1010][1010] = {}; // i人のグループまで見てj人使いきってる
	dp[A-1][0] = 1;
	for(int i = A-1; i < B; i++){
		for(int j = 0; j <= N; j++){
			if(!dp[i][j]) continue;
			dp[i+1][j] += dp[i][j];
			dp[i+1][j] %= MOD;
			for(int k = C; k <= D; k++){
				if(j + (i+1)*k > N) break;
				dp[i+1][j + (i+1)*k] += dp[i][j] * group(i+1, k, N-j);
				dp[i+1][j + (i+1)*k] %= MOD;
			}
		}
	}
	cout << dp[B][N] << endl;
}

#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<queue>
#include<cmath>
using namespace std;
void read(int &x){
	char ch;bool ok;
	for(ok=0,ch=getchar();!isdigit(ch);ch=getchar())if(ch=='-')ok=1;
	for(x=0;isdigit(ch);x=x*10+ch-'0',ch=getchar());if(ok)x=-x;
}
#define rg register
const int maxn=1e5+10;
int mm,m,n,a[60];
long long f[60];
long long ans;
void dfs(int x,int n,long long sum){
	if(x==n/2+1){
		if(sum==m){
			long long now=a[1]>=0?(9-a[1]):(9+a[1]);
			for(rg int i=2;i<x;i++)now=now*(a[i]>=0?(10-a[i]):(10+a[i]));
			ans+=n&1?now*10:now;
		}
		return ;
	}
	if(sum+10ll*(f[n-x]-f[x-1])<m||sum-10ll*(f[n-x]-f[x-1])>m)return ;
	for(rg int i=-9;i<10;i++){
		a[x]=i;
		dfs(x+1,n,sum+1ll*a[x]*(f[n-x]-f[x-1]));
	}
}
int main(){
	read(m),mm=m;f[0]=1;
	while(mm)n++,mm/=10;
    for(rg int i=1;i<=18;i++)f[i]=f[i-1]*10;
	for(rg int i=n;i<=18;i++)dfs(1,i,0);
	printf("%lld\n",ans);
}


#include "bits/stdc++.h"
using ll = long long;
using namespace std;

const double pi = acos(-1);

pair <double, double> rotate(int x, int y, int degree, double d) {
   double theta = (2 * pi / 360) * degree;
   double x_ = x * cos (theta) - y * sin(theta);
   double y_ = x * sin (theta) + y * cos(theta);
   x_ *= d;
   y_ *= d;
   return {x_, y_};
}

const double eps = 1e-3;

int near(double x) {
   for(int i = (int)(x - 2); i < (int)(x + 2); i++) {
      if(abs(i - x) < eps) {
         return i;
      }
   }
   return 0;
}
void solve() {
   string s;
   int a, b;
   cin >> a >> b >> s;

   bool ok = true;
   ok &= s[a] == '-';
   for(int i = 0; i < s.length(); i++) {
      if(i == a)
         continue;
      else ok &= s[i] >= '0' && s[i] <= '9';
   }
   cout << (ok?"Yes":"No") << endl;
}

int main() {
   cin.tie(0);
   cin.sync_with_stdio(0);
   int testcase = 1;
   // cin >> testcase;

   for(int i = 0; i < testcase; i++) {
      solve();
   }
   return 0;
}

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for (int i = s; i < (int)(n); i++)
#define out(x) cout << x << endl;
#define INF 1ll<<60;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

using namespace std;
using ll = long long;
typedef pair<int, int> P;

int main(){
    int a, b; cin >> a >> b;
    string s; cin >> s;

    int cnt1 = 0, cnt2=0;
    int h_cnt=0;

    rep(i, s.size()){
       if(s[i]=='-'){
           h_cnt++;
           if(h_cnt==1)swap(cnt1, cnt2);
           continue;

       }
       else{
           cnt1++;
       }
    }
    if(h_cnt==0||h_cnt>1){
        out("No");
        return 0;
    }

    if(a==cnt2&&b==cnt1){
        out("Yes");
    }
    else out("No");
}


#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <iomanip>

#define REP(i,n) for(int i=0;i<n;++i)
#define RREP(i,n) for(int i=n-1;i>=0;--i)
#define FOR(i,m,n) for(int i=m;i<n;++i)
#define RFOR(i,m,n) for(int i=m-1;i>=n;--i)
#define ALL(v) v.begin(),v.end()
#define INF 1000000001
#define MOD 1000000007

using namespace std;

class Dice {
public:
	int num[6] = { 0,0,0,0,0,0 };
	void setnum(int*);
	void roll(char);
	void dice3(Dice, Dice);
};

void Dice::roll(char c) {
	switch
 (c) {
		int tmp;
	case'N':
		tmp = num[0];
		num[0] = num[1];
		num[1] = num[5];
		num[5] = num[4];
		num[4] = tmp;
		break;
	case'S':
		tmp = num[0];
		num[0] = num[4];
		num[4] = num[5];
		num[5] = num[1];
		num[1] = tmp;
		break;
	case'E':
		tmp = num[0];
		num[0] = num[3];
		num[3] = num[5];
		num[5] = num[2];
		num[2] = tmp;
		break;
	case'W':
		tmp = num[0];
		num[0] = num[2];
		num[2] = num[5];
		num[5] = num[3];
		num[3] = tmp;
		break;
	default:
		cout << "invalid char" << endl;
	}
}

void Dice::setnum(int* a) {
	REP(i, 6) {
		num[i] = a[i];
	}
}

bool isSame(Dice d1, Dice d2) {
	int flag = 1;
	REP(i, 6) {
		if (d1.num[i] != d2.num[i]) {
			flag = 0;
		}
	}
	if (flag) return true;
	else return false;
}

bool dice4(Dice d1, Dice d2) {
	int flag0 = 0;
	int a  = d1.num[0];
	REP(i, 6) {
		if (a == d2.num[i]) {
			flag0 = 1;
		}
	}
	if (flag0) {
		REP(i, 3) {
			REP(j, 4) {
				if (isSame(d1, d2)) {
					return true;
				}
				d1.roll('E');
				d1.roll('N');
				d1.roll('W');
			}
			d1.roll('E');
			REP(j, 4) {
				if (isSame(d1, d2)) {
					return true;
				}
				d1.roll('E');
				d1.roll('N');
				d1.roll('W');
			}
			d1.roll('N');
		}
	}
	return false;
}

int main() {
	int n,flag=0;
	cin >> n;
	vector<Dice> dice;
	REP(i, n) {
		Dice d;
		dice.push_back(d);
		int tmp[6];
		REP(j, 6){
			int c;
			cin >> c;
			tmp[j]=c;
		}
		dice[i].setnum(tmp);
	}
	REP(i, n) {
		FOR(j, i+1, n) {
			if (dice4(dice[i], dice[j]))flag = 1;
		}
	}
	if (flag)cout << "No" << endl;
	else cout << "Yes" << endl;
	return 0;
}

#include<iostream>
using namespace std;

int main(){
	int n,cnt=0,num=0;
	int base[4]={0};
	cin>>n;
	string s;
	while(1){
		cin>>s;
		if(s=="HIT"){
			base[3]+=base[2];
			base[2]=base[1];
			base[1]=base[0];
			base[0]=1;
		}
		if(s=="HOMERUN"){
			for(int i=0;i<3;i++){
				base[3]+=base[i];
				base[i]=0;
			}
			base[3]++;
		}
		if(s=="OUT"){
			cnt++;
		}
		if(cnt==3){
			cout<<base[3]<<endl;
			cnt=0;
			num++;
			base[0]=base[1]=base[2]=base[3]=0;
		}
		if(num==n)break;
	}
	return 0;
}


#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(n);i++)
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
const int INF=1e9;
const int MOD=1e9+7;
const double pi=acos(-1);

int main(){
  int n;
  cin >> n;
  ll s[200010];
  s[0]=0;
  rep(i,n){
    ll a;
    cin >> a;
    s[i+1]=s[i]+a;
  }

  ll ans=1e18;
  for(int i=2;i<n-1;i++){
    ll *l,*r;
    ll gap;
    l=lower_bound(s+1,s+i+1,s[i]/2+1);
    r=lower_bound(s+i+1,s+n+1,(s[n]+s[i])/2+1);
    rep(j,2){
      rep(k,2){
        gap=max({*l,s[i]-*l,*r-s[i],s[n]-*r})-min({*l,s[i]-*l,*r-s[i],s[n]-*r});
        ans=min(ans,gap);
        l--;
      }
      l+=2;
      r--;
    }
  }
  cout << ans << endl;
}

#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <unordered_map>
#include <functional>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cstdlib>

using namespace std;
typedef long long llong;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<llong, llong> pll;

int ch[100000];
deque<int> pr;
llong P1[500];
llong P2[500];
int main() {
	ios_base::sync_with_stdio(false); cin.tie(0);
	for (int i = 2; i < 100000; ++i) {
        if (ch[i]) continue;
        pr.push_back(i);
        for (llong j = (llong)i * i; j < 100000; j += i) ch[j] = 1;
	}

	int n;
	cin >> n;
	if (n == 2) {
        printf("4 7\n23 10\n");
        return 0;
	}
	for (int i = 0; i <= ((n + n - 2) >> 1); ++i) {
        P1[i] = pr.front();
        pr.pop_front();
	}
	for (int i = 0; i <= ((n + n - 2) >> 1); ++i) {
        P2[i] = pr.front();
        pr.pop_front();
	}
	for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            if ((i + j) & 1) {
                int x = (i + j), y = (i - j + (n - 1));
                llong ret = 1;
                if (x > 0) ret *= P1[x - 1 >> 1];
                if (x + 1 <= n + n - 2) ret *= P1[x + 1 >> 1];
                if (y > 0) ret *= P2[y - 1 >> 1];
                if (y + 1 <= n + n - 2) ret *= P2[y + 1 >> 1];
                printf("%lld", ret + 1);
                //if (ret > 1e15) { printf("%lld\n", ret); }
            }
            else {
                printf("%lld", P1[i + j >> 1] * P2[i - j + (n - 1) >> 1]);
            }
            if (j + 1 < n) printf(" ");
            else printf("\n");
        }
	}
	return 0;
}


#include<stdio.h>
int main(void)
{
	int n,pm,pe,pj,s,i;
	while(1){
		scanf("%d",&n);
		if(n==0) break;
		for(i=0;i<n;i++){
			scanf("%d%d%d",&pm,&pe,&pj);
			s=(pm+pe+pj)/3;
			if(pm==100||pe==100||pj==100) printf("A\n");
			else if((pm+pe)/2>=90) printf("A\n");
			else if(s>=80) printf("A\n");
			else if(s>=70) printf("B\n");
			else if(s>=50&&(pm>=80||pe>=80)) printf("B\n");
			else printf("C\n");
		}
	}
	return 0;
}

#include<iostream>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;

int color[200][200];
bool flg[200][200];
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int w,h,n,c,d,x,y;

void dfs(int ny,int nx,int gy,int gx){
	flg[ny][nx]=true;
	rep(i,4){
		int nex=nx+dx[i];
		int ney=ny+dy[i];
		if(nex>=w || nex<0 || ney>=h || ney<0)continue;
		if(color[ney][nex]==color[ny][nx] && flg[ney][nex]==false)dfs(ney,nex,gy,gx);
	}
	return;
}

int main(){
	pair<int,int> s,g;
	while(1){
		rep(i,200)rep(j,200)color[i][j]=flg[i][j]=0;
		cin>>w>>h;
		if(w==0 && h==0)break;
		cin>>s.first>>s.second;
		cin>>g.first>>g.second;
		cin>>n;
		rep(i,n){
			cin>>c>>d>>x>>y;
			if(d==0){
				rep(j,2){
					rep(k,4){
						color[y-1+j][x-1+k]=c;
					}
				}
			}else{
				rep(j,4){
					rep(k,2){
						color[y-1+j][x-1+k]=c;
					}
				}
			}
		}
		dfs(s.second-1,s.first-1,g.second-1,g.first-1);
		if(flg[g.second-1][g.first-1])cout<<"OK"<<endl;
		else cout<<"NG"<<endl;
	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int a[200005];

int main() {
    int n;
    scanf("%d", &n);

    for (int i = 0; i < n; i++) scanf("%d", &a[i]);
    sort(a, a + n);

    bool ok = 1;

    for (int i = 1; i < n; i++) {
        if (a[i] == a[i - 1]) ok = 0;
    }

    if (ok) printf("YES\n");
    else printf("NO\n");
}

/*
h s, d't skp th si tll i's sved
 * ABC141 E
 * ABC145 D
 * ABC147 F
*/
#include<bits/stdc++.h>
#define ll long long
#define mod 1000000007
using namespace std;
int main()
{
int n,x;
cin>>n;
set<int> st;
string ans="YES";
while(n--)
{
cin>>x;
if(st.count(x))
{
ans="NO";
break;
}
st.insert(x);
}
cout<<ans;
}


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

int rr[8], cc[8];
int r[8], c[8];

int main(){
  int k;
  cin >> k;
  int count=0;
  for(int i=0;i<k;i++) cin >> r[i] >> c[i];

  for(int co=0;co<pow(8,8-k);co++)
  {
    for(int i=0;i<8;i++)
    {
      rr[i]=-1;
      cc[i]=-1;
    }
    //無理やり配置を用意して

    for(int i=0;i<8;i++)
    {
      rr[i]=i;
      if(i<k) cc[r[i]]=c[i];
    }
    int hoge=0;
    for(int i=0;i<8;i++)
    {
      int a=pow(8,hoge);
      if(cc[i]==-1)
      {
        cc[i]=co%(a*8)/a;
        hoge++;
      }
    }
    //襲撃をtrueで埋めて
    bool masu[8][8]{false};
    for(int i=0;i<8;i++)
    {
      for(int j=1;j<8;j++)
      {
        if(cc[i]-j>=0) masu[rr[i]][cc[i]-j]=true;
        if(cc[i]+j<=7) masu[rr[i]][cc[i]+j]=true;
        if(rr[i]-j>=0) masu[rr[i]-j][cc[i]]=true;
        if(rr[i]+j<=7) masu[rr[i]+j][cc[i]]=true;

        if(rr[i]-j>=0&&cc[i]-j>=0) masu[rr[i]-j][cc[i]-j]=true;
        if(rr[i]+j<=7&&cc[i]-j>=0) masu[rr[i]+j][cc[i]-j]=true;
        if(rr[i]-j>=0&&cc[i]+j<=7) masu[rr[i]-j][cc[i]+j]=true;
        if(rr[i]+j<=7&&cc[i]+j<=7) masu[rr[i]+j][cc[i]+j]=true;
      }
    }

    count=0;
    for(int j=0;j<8;j++)
    {
      if(masu[rr[j]][cc[j]]==false) count++;
    }
    //cout << count << endl;
    if(count==8)
    {
      count=0;

      for(int j=0;j<k;j++)
      {
        if(c[j]==cc[r[j]]) count++;
      }

      if(count==k)
      {
        break;
        //return 0;
      }
    }
  }
  for(int i=0;i<8;i++)
        {
          for(int j=0;j<8;j++)
          {
            if(cc[i]==j) cout << 'Q';
            else cout <<'.';
          }
          cout << endl;
        }
  //cout << "hoge"<< endl;
  return 0;
}

#include <bits/stdc++.h>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

vector<string> split(const string &s, char delim) {
  vector<string> elems;
  string item;
  for (char ch: s) {
    if (ch == delim) {
      if (!item.empty()) {
        elems.push_back(item);
      }
      item.clear();
    }
    else {
      item += ch;
    }
  }
  if (!item.empty()) {
    elems.push_back(item);
  }
  return elems;
}

string to_str_with_zero(int i, int w) {
  ostringstream sout;
  sout << std::setfill('0') << std::setw(w) << i;
  string s = sout.str();
  return s;
}

int letter_to_int(char c) {
  return tolower(c) - 'a';
}

int compare_array(vector<int> a1, vector<int>a2) {
  int n1 = a1.size();
  int n2 = a2.size();
  if (n1 != n2) {
    return n1 - n2;
  }
  for (int i=0; i<n1; i++) {
    if (a1.at(i) != a2.at(i)) {
      return a1.at(i) - a2.at(i);
    }
  }
  return 0;
}

long gcd(long a, long b) {
  if(a % b == 0) {
    return b;
  }
  return gcd(b, a % b);
}

char int_to_char(int a) {
  if (a == -1) {
    return 'z';
  }
  else {
    return 'a' + a;
  }
}

long nCr(int n, int r) {
    long ans = 1;
    for (int i = n; i > n - r; --i) {
        ans = ans*i;
    }
    for (int i = 1 ; i < r + 1; ++i) {
        ans = ans / i;
    }
    return ans;
}

long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

int divide_count(int a, int divider) {
  int r = 0;
  while(a % divider == 0) {
    a /= divider;
    r++;
  }
  return r;
}

bool is_prime(int a) {
  int i = 2;
  while(i * i <= a) {
    if(a % i == 0) {
      return false;
    }
    i++;
  }
  return true;
}

vector<vector<int>> all_comb(int n, int k) {
  vector<vector<int>> combs(nCr(n, k), vector<int>(k));
  for(int i=0; i<k; i++) {
    combs[0][i] = i;
    combs[1][i] = i;
  }

  for(long i=1; i<nCr(n, k); i++) {
    int p = 1;
    while(combs[i][k - p] == n - p) {
      p++;
      if(p > k) {
        break;
      }
    }
    combs[i][k - p]++;
    int q = combs[i][k - p];
    for(int j=1; j<p; j++) {
      combs[i][k - p + j] = q + j;
    }

    if(i < nCr(n, k) - 1) {
      for(int j=0; j<k; j++) {
        combs[i + 1][j] = combs[i][j];
      }
    }
  }

  return combs;
}

template <typename TYPE> void co(TYPE a) {
  cout << a << endl;
}

template <typename TYPE> void co_2(TYPE a, TYPE b) {
  cout << a << ' ' << b << endl;
}

template <typename TYPE> void co_l(vector<TYPE> as) {
  int n = as.size();
  for(int i=0; i<n; i++) {
    cout << as[i] << endl;
  }
}

template <typename TYPE> void co_s(vector<TYPE> as) {
  int n = as.size();
  for(int i=0; i<n; i++) {
    if(i > 0) {
      cout << ' ';
    }
    cout << as[i];
  }
  cout << endl;
}

int main() {
  std::cout << std::setprecision(9);
  long mod = 1000000007;
  long a, b;
  cin >> a >> b;

  int ans = 1;
  long gcd = std::gcd(a, b);
  for(long i=2; i*i<=gcd; i++) {
    if(gcd % i == 0) {
      ans++;
      while(gcd % i == 0) {
        gcd /= i;
      }
    }
  }
  if(gcd > 1) {
    ans++;
  }
  co(ans);
}


#include <iostream>
#include <string>
using namespace std;
int main()
{
	string s, w, r;
	int q, i, j, a, b;
	cin >> s >> q;

	for(i = 0; i < q; ++i){
		cin >> w >> a >> b;
		if( w == "replace" ){
			cin >> r;
			for( j = a; j <= b; ++j)
				s[j] = r[j-a];
		}else if( w == "print" ){
			for( j = a; j <= b; ++j)
				cout << s[j];
			cout << "\n";
		}else if( w == "reverse" ){
			string c = s;
			for( j = a; j <= b; ++j)
				s[j] = c[b+a-j];
		}
	}

	return 0;
}

#include <bits/stdc++.h>

using namespace std;

const int N = 1e5 + 10;

int n, m, cnt, d[N << 3], v[N << 3], sum, ans;

map <int, int> mp[N << 3];

vector < pair <int, int> > e[N << 3];

queue <int> q;

void init ()
{
	scanf ( "%d%d" , &n, &m);
	cnt = n;
	for (int i = 1; i <= m; ++ i)
	{
		int p, q, c;
		scanf ( "%d%d%d" ,&p, &q, &c);
		if ( !mp[p].count (c) )
		{
			mp[p][c] = ++cnt;
			e[p].push_back ( make_pair (cnt, 1) );
			e[cnt].push_back ( make_pair (p, 1) );
		}
		if ( !mp[q].count (c) )
		{
			mp[q][c] = ++cnt;
			e[q].push_back ( make_pair (cnt, 1) );
			e[cnt].push_back ( make_pair (q, 1) );
		}
		e[ mp[p][c] ].push_back ( make_pair (mp[q][c], 0) );
		e[ mp[q][c] ].push_back ( make_pair (mp[p][c], 0) );
	}
}

void work ()
{
	memset ( d, 0x3f, sizeof (d) );
	d[1] = 0, v[1] = 1;
	q.push (1);
	for ( ; !q.empty (); )
	{
		int x = q.front ();
		q.pop ();
		for (int i = 0; i < e[x].size (); ++ i)
		{
			int y = e[x][i].first;
			if (d[y] > d[x] + e[x][i].second)
			{
				d[y] = d[x] + e[x][i].second;
				if (!v[y])
				{
					v[y] = 1;
					q.push (y);
				}
			}
		}
		v[x] = 0;
	}
	if (d[n] == 0x3f3f3f3f) sum = -1;
	else sum = d[n] / 2;
}

void prin ()
{
	printf ( "%d" , sum);
}

int main ()
{
	init ();
	work ();
	prin ();
	return 0;
}


#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <map>
#include <iomanip>
#include <deque>
#include <set>
#define rep(i,a,b) for(int i=a;i<b;++i)
#define rrep(i,a,b) for(int i=a;i>=b;--i)
#define fore(i,a) for(auto &i:a)
#define INF INT_MAX/2;
typedef long long ll;
using namespace std;
using vi = vector<int>;
using vll = vector<ll>;
ll mod = 1e9 + 7;
//ll llmax = 10000000000000000000ll;
using namespace std;
using Graph = vector<vector<int>>;

int cnt_digit(ll N)
{
	int digit = 0;

	while (N > 0)
	{
		N /= 10;
		digit++;
	}
	return digit;
}

 // 最大公約数計算

ll gcd(ll a, ll b)
{
	if (b == 0) {
		return a;
	}
	else {
		return gcd(b, a % b);
	}
}
// 最小公倍数の計算

ll lcm(ll a, ll b)
{
	ll g = gcd(a, b);

	return a / g * b;
}

struct union_find
{
	vector<int> par, r;
	union_find(int n)
	{
		par.resize(n);
		r.resize(n);
		init(n);
	}

	void init(int n)
	{
		for (int i = 0; i < n; i++) par[i] = i;
		for (int i = 0; i < n; i++) r[i] = 0;
	}

	int find(int x)
	{
		if (par[x] == x)return x;
		else return find(par[x]);
	}

	void unite(int x, int y)
	{
		x = find(x);
		y = find(y);

		if (r[x] < r[y])
		{
			par[x] = y;
		}
		else
		{
			par[y] = x;
			if (r[x] == r[y])
			{
				r[x]++;
			}
		}
	}
};

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	int a,b;
	cin >> a >> b;

	cout << max(max(a + b, a - b), a * b);

}

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

int main() {
    int current_rate, target_rate; //初期値
    double next_rate;

    cin >> current_rate >> target_rate;
    next_rate = target_rate*2 - current_rate;
    cout << next_rate << endl;

}


#include<iostream>
#include<stdio.h>
//#include <bits/stdc++.h>
#include<vector>
#include<float.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<cstring>
#include<math.h>
#include<cmath>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include<cassert>
#include<cmath>
#include<cstdint>

#define INF 1e9
#define rep(i,n)for(int i=0;(i)<(int)(n);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
#define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
#define vec(type,n) vector<type>(n)
#define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
#define ALL(a)  (a).begin(),(a).end()

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<ll, ll>;

const ll MOD = 998244353;

ll mpow(ll x, ll n){
    ll ans = 1;
    while(n != 0){
        if(n & 1)ans = ans * x % MOD;
        x = x * x % MOD;
        n = n >> 1;
    }
    return ans;
}

int main(){
    int n;
    cin >> n;
    VEC(int, a, n);

    bool ok = true;
    if(a[0] != 0)ok = false;
    map<int, int> mp;

    rep(i, n){
        mp[a[i]]++;
    }

    int now = 0;
    for(auto m : mp){
        if(now != m.first)ok = false;
        now++;
    }

    ll res = 1;
    ll p;
    if(mp[0] != 1)ok = false;

    if(ok){
        for(auto m : mp){
            if(m.first > 0)res = res * mpow(p, m.second) % MOD;
            p = m.second;
        }
    }
    else res = 0;
    cout << res;
}

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please

ll mod = 998244353;

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	int N;
	cin >> N;
	int A[300];
	rep(i, N) cin >> A[i];

	int goukei = 0;
	rep(i, N) goukei += A[i];
	int goukei2 = 0;
	ll dp[45001][301] = {};
	dp[0][0] = 1;
	ll dp2[301] = {};
	rep(i, N) {
		for (int k = i; k >= 0; k--) if (dp2[k]) {
			dp2[k + 1] += dp2[k];
			dp2[k + 1] %= mod;
		}
		int x = max(0, goukei2 - goukei / 2);
		for (int j = min(goukei2, (goukei + 1) / 2 - 1); j >= x; j--) {
			for (int k = i; k >= 0; k--) {
				if (dp[j][k]) {
					if (j + A[i] >= (goukei + 1) / 2) dp2[k + 1] = (dp2[k + 1] + dp[j][k]) % mod;
					else dp[j + A[i]][k + 1] = (dp[j + A[i]][k + 1] + dp[j][k]) % mod;
				}
			}
		}
		goukei2 += A[i];
	}

	ll zenbu = 1;
	rep(i, N) {
		zenbu *= 3;
		zenbu %= mod;
	}
	ll bairitu[301];
	bairitu[0] = 1;
	rep(i, 300) {
		bairitu[i + 1] = 2 * bairitu[i] % mod;
	}

	ll dame = 0;
	rep1(k, N - 1) {
		if (dp2[k]) {
			int k2 = N - k;
			ll kari = dp2[k] * bairitu[k2] % mod;
			kari -= 2 * dp2[k];
			dame += kari + mod;
			dame %= mod;
		}
	}

	dame *= 3;
	dame %= mod;

	ll kari = 1;
	rep(i, N) {
		kari *= 2;
		kari %= mod;
	}
	dame += kari * 3;
	dame %= mod;

	co((zenbu - dame + mod + 3) % mod);

	Would you please return 0;
}