#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long int
#define ld long double
#define pb push_back
#define pll pair<ll, ll>
#define vl vector<ll>
#define vvl vector< vector<ll> >
#define vlp vector< pair<ll, ll> >
#define vllp vector<pair<pll, ll> >
#define mll map<ll, ll>
#define rep(i,a)  for(ll i=0; i< a; i++)
#define rep1(i,a)   for(ll i = 1; i< a; i++)
#define foi(i, a, b)    for(ll i = a; i<b ; i++)
#define fod(i, a, b)    for(ll i = a; i>=b ; i--)
#define mp make_pair
#define all(v)  (v).begin(), (v).end()
#define fst first
#define sec second
#define ff first.first
#define fs first.second
#define max3(a, b, c)   max(max(a, b), c)
#define min3(a, b, c)   min(min(a, b), c)
#define MAX 1000001
#define MOD 1000000007
// #define MOD 998244353
#define endl "\n"
#define INF (ll)1e18
#define s(v) (ll)v.size()
#define e(v) v.empty()
#define bscount(x) __builtin_popcountll(x)
// #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

using namespace std;
// using namespace __gnu_pbds;

ll gcd(ll a, ll b){if(b==0)return a;return gcd(b, a%b);}
ll fexp(ll a, ll b){ll ans = 1;while(b){if(b&1) ans = ans*a%MOD; b/=2;a=a*a%MOD;}return ans;}
ll inverse(ll a, ll p){return fexp(a, p-2);}
void ingraph(vvl& graph, ll m){ll x, y;rep(i, m){cin>>x>>y;x--, y--;graph[x].pb(y);graph[y].pb(x);}}
ll modify(ll n){ll res = n;res%=MOD;res+=MOD;res%=MOD;return res;}

int main(){
    // #ifndef ONLINE_JUDGE
    //     freopen("../input.txt", "r", stdin);
    //     freopen("../output.txt", "w", stdout);
    // #endif
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    ll t;
    // cin>>t;
    t = 1;
    while(t--){
        ll n, m, v, p;
        cin>>n>>m>>v>>p;
        vl vec(n);
        rep(i, n)   cin>>vec[i];
        sort(all(vec));
        vl pref(n);
        ll cur = 0;
        rep(i, n){
            cur += vec[i];
            pref[i] = cur;
        }
        ll ans = 0;
        rep(i, n){
            ll nv = v;
            nv -= (i+1);
            bool poss = false;
            ll j = upper_bound(all(vec), vec[i] + m) - vec.begin();
            if(n - j >= p)  continue;
            else{
                nv -= (n - j);
                if(v <= 0)  {ans++;poss = true;}
                else{
                    ll np = p - (n - j) - 1;
                    if(j - i - 1 <= np) ans++;
                    else{
                        nv -= np;
                        ll del = (j - np - 1 - i)*(vec[i] + m) - (pref[j-np-1] - pref[i]);
                        if(del >= nv*m) ans++;
                    }
                }
            }
        }
        cout<<ans;
    }
}

#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#define N 100010
#define int long long
using namespace std;
int num[N];
signed main()
{
	int n,m,v,p;
	scanf("%lld%lld%lld%lld",&n,&m,&v,&p);
	for(int i=1;i<=n;i++) scanf("%d",&num[i]);
	sort(num+1,num+n+1);
	reverse(num+1,num+n+1);
	int sum=0,ans=p;
	for(int i=p+1;i<=n && num[i]+m>=num[p];i++)
	{
		int d=n-(i-p);
		if(v<=d) ++ans;
		else
		{
			int res=(1ll*(v-d)*m-sum-1)/(i-p)+1;
			if(num[p]+res<=num[i]+m) ++ans;
		}
		sum+=num[p]-num[i];
	}
	printf("%lld\n",ans);
	return 0;
}


#include<iostream>
#include<cmath>
using namespace std;
int main(){
  int h,w;
  while(cin>>h>>w,h||w){
    int a=h*h+w*w;
    bool hantei=false;
    while(1){
      while(1){
	h++;
	double s=sqrt(a-h*h);
	if(s-(int)s==0&&h*h<(a-h*h)){hantei=true;break;}
	if(a-h*h<1)break;
      }
      //cout<<a<<endl;
      if(hantei){cout<<h<<" "<<sqrt(a-h*h)<<endl;break;}
      a++;
      h=0;
    }
  }
}

#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<map>
using namespace std;
#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 irep(i,n) for(int i=((int)(n))-1;i>=0;i--)
#define ireg(i,a,b) for(int i=((int)(b));i>=((int)(a));i--)
typedef long long int lli;
typedef pair<int,int> mp;
#define fir first
#define sec second
#define IINF INT_MAX
#define LINF LLONG_MAX

int n;

bool isbig(mp pa,mp pb){
	int da = pa.fir*pa.fir+pa.sec*pa.sec;
	int db = pb.fir*pb.fir+pb.sec*pb.sec;
	if(da!=db)return (da>db);
	return (pa.fir>pb.fir);
}

int main(void){
	for(;;){
		int w,h;
		scanf("%d%d",&h,&w);
		if(h==0)break;
		mp cp(h,w);
		mp pa(1000,1000);
		reg(y,1,150){
			reg(x,y+1,150){
				mp np(y,x);
				if(!isbig(np,cp))continue;
				if(isbig(pa,np))pa=np;
			}
		}
		printf("%d %d\n",pa.fir,pa.sec);
	}
	return 0;
}


#include <iostream>
#include <algorithm>

using namespace std;

int main(){
	int a[4], b[2], sum;

	sum = 0;

	for (int i = 0; i < 4; i++){
		cin >> a[i];
	}

	cin >> b[0] >> b[1];

	if (b[0] <= b[1]){
		sum += b[1];
	}
	else {
		sum += b[0];
	}

	sort(a, a + 4);

	sum += a[1] + a[2] + a[3];

	cout << sum << endl;
}

//Author: Fuadul Hasan(fuadul202@gmail.com)
//BSMRSTU,Gopalganj
#include<bits/stdc++.h>
using namespace std;
//int input........
template <typename T> inline void readline(T &n) {n = 0; int f = 1; register int ch = getchar();
 for (; !isdigit(ch); ch = getchar()) if (ch == '-') f = -1;for (; isdigit(ch);
ch = getchar()) n = (n << 3) + (n << 1) + ch - '0';n = n * f;}
template <typename T, typename TT> inline void readline(T &n, TT &m) { readline(n); readline(m); }
template <typename T, typename TT, typename TTT> inline void readline(T &n, TT &m, TTT &l) { readline(n, m); readline(l);}
// long long input........
template <typename T> inline void readlinel(T &n) {n = 0; long long f = 1; register long long ch = getchar();
 for (; !isdigit(ch); ch = getchar()) if (ch == '-') f = -1;for (; isdigit(ch);
ch = getchar()) n = (n << 3) + (n << 1) + ch - '0';n = n * f;}
template <typename T, typename TT> inline void readlinel(T &n, TT &m) { readlinel(n); readlinel(m); }
template <typename T, typename TT, typename TTT> inline void readlinel(T &n, TT &m, TTT &l) { readlinel(n, m); readlinel(l);}
//debug..........
#define error(args...) {vector<string>_v=split(#args,',');err(_v.begin(),args);cout<<endl;}
vector<string> split(const string &s, char c) {vector<string>v; stringstream ss(s); string x;
while (getline(ss, x, c))v.emplace_back(x); return move(v);} void err(vector<string>::iterator it) {}
template<typename T, typename... Args>void err(vector<string>::iterator it, T a, Args...args) {
cout << it->substr((*it)[0] == ' ', it->length()) << " = " << a << " "; err(++it, args...);}
//............ignore it..................//
int dx[8]= {1,0,-1,0,-1,-1,1,1};int dy[8]= {0,1,0,-1,-1,1,-1,1}; int tc = 1;
#define F first
#define S second
#define pb  push_back
#define mp make_pair
#define Pi atan(1)*4
#define ll  long long int
#define happy cin.tie(0);
#define point(x) setprecision(x)
#define coding ios::sync_with_stdio(false);
#define Test printf("Case %d: ",tc++);
#define Unique(c) (c).resize(unique(all(c))-(c).begin())
#define vout(v) for (auto z: v) cout << z << " "; cout << endl;
void print(int n){printf("%d ", n);}
void print(int n,int m){printf("%d ",n);printf("%d ",m);}
void print(int n,int m,int k){printf("%d ",n);printf("%d ",m);printf("%d ",k);}
void print(ll n){printf("%I64d ", n);}
void print(ll n,ll m){printf("%I64d ",n);printf("%I64d ",m);}
void print(ll n,ll m,ll k){printf("%I64d ",n);printf("%I64d ",m);printf("%I64d ",k);}
int length(long long x){int l = 0;for(long long i=x;i;i/=10)l++;return l;}
int length(string s){return s.size();}

#define   pr 	pair<int, int>
#define   vpr 	vector<pr>
#define   vi   	std::vector<int>
#define   vll  	std::vector<ll>
#define   all(n) n.begin(),n.end()

const int M           	= 1e9 + 7;
const int Inf           = (int)2e9 + 5;
const ll  Lnf           = (ll)2e18 + 5;
const int N             = 4e5 + 5;
const int N1            = 1e5 + 5;

double vip(int x1,int y1,int x2,int y2){
	double x = (x1 - x2);
	double y = (y1 - y2);
	double ans = x*x + y*y;
	return sqrt(ans);
}

double fact(int n){
	double ans = 1.0;
	for(int i=1;i<=n;i++){
		ans *= (double)i;
	}
	return ans;
}

int solve()
{
	//happy coding

	int n;
	cin>>n;
	vector<pair<int,int>>v;
	for(int i=0;i<n;i++){
		int x,y;
		cin>>x>>y;
		v.pb({x,y});
	}

	sort(all(v));
	double dis = 0;
	do{
		for(int i=0;i<n-1;i++){
			//cout<<v[i].F<<" "<<v[i].S<<endl;
			dis += (vip(v[i].F,v[i].S,v[i+1].F,v[i+1].S));
		}
	}while(next_permutation(all(v)));
	double z = fact(n);
	//error(dis);
	cout<<point(10)<<dis/z<<endl;

	return 0;
	//error();
}
int main(){
	int test = 1;
	//readline(test);//(void)getchar();
	while (test--)solve();return 0;
}


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

#include <iostream>
//#include <vector>
#include <string>
//#include <algorithm>
//#include <math.h>
//#include <queue>
//#include <stack>
//#include <iomanip>

// sometimes used
//#include <set>
//#include <map>
//#include <numeric>
//#include <list>
//#include <deque>
//#include <unordered_map>

typedef long long LL;
//typedef long double LD;
using namespace std;

//#define MOD 1000000007
//#define MAX 100100
//#define NIL -1
//#define INFTY 1000000000000000000

int main(){
    string s;
    cin >> s;
    s[3]='8';
    cout << s << 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 ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

int main(){
    int n;
    cin >> n;
    vi a(n+1);
    rep1(i, n) cin >> a[i];
    vi b(n+1);
    rep1r(i, n) {
        int sum = 0;
        for (int j=i*2; j<=n; j+=i) sum ^= b[j];
        b[i] = sum ^ a[i];
    }
    vi ans;
    rep1(i, n) if (b[i] == 1) ans.pb(i);
    int m = sz(ans);
    cout << m << endl;
    rep(i, m) printf("%d%c", ans[i], (i<m-1?' ':'\n'));
    return 0;
}

#include <bits/stdc++.h>

using namespace std;

const int MAXN = 1E5;
bool isSheep[MAXN];
bool o[MAXN];
bool options[2] = {true, false};

bool isValid(int n)
{
    bool firstSheep = isSheep[0];
    for (int i = 1; i < n; i++)
    {
         if (isSheep[i] && o[i] || !isSheep[i] && !o[i])
         {
             isSheep[(i + 1) % n] = isSheep[i - 1];
         }
         else if (isSheep[i] && !o[i] || !isSheep[i] && o[i])
         {
             isSheep[(i + 1) % n] = !isSheep[i - 1];
         }
    }
    if (isSheep[0] != firstSheep)
        return false;
    if (firstSheep && o[0] || !firstSheep && !o[0])
    {
        return isSheep[n - 1] == isSheep[1];
    }
    else
    {
        return isSheep[n - 1] != isSheep[1];
    }
}

int main()
{
    int n;
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        char c;
        cin >> c;
        o[i] = c == 'o';
    }
    bool valid = false;
    for (bool s1 : options)
    {
        for (bool s2 : options)
        {
            isSheep[0] = s1;
            isSheep[1] = s2;
            if (isValid(n))
            {
                valid = true;
                break;
            }
        }
        if (valid)
            break;
    }
    if (valid)
    {
        stringstream ss;
        for (int i = 0; i < n; i++)
        {
            if (isSheep[i])
                ss << "S";
            else
                ss << "W";
        }
        cout << ss.str() << endl;
    }
    else
        cout << -1 << endl;
    return 0;
}


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

int main() {
	int H, W;
	cin >> H >> W;
	vector<string> S(H);
	for (int i = 0; i < H; i++) cin >> S[i];
	vector<vector<int> > A(H, vector<int>(W));
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			if (S[i][j] == '.') A[i][j] = 0;
			else A[i][j] = 1;
		}
	}
	vector<vector<int> > B(H, vector<int>(W - 1));
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W - 1; j++) {
			B[i][j] = A[i][j] ^ A[i][j + 1];
		}
	}
	vector<vector<int> > C(H, vector<int>(W - 1));
	for (int i = 0; i < W - 1; i++) {
		C[H - 1][i] = 1;
		for (int j = H - 2; j >= 0; j--) {
			if (B[j + 1][i] == B[j][i]) C[j][i] = C[j + 1][i] + 1;
			else C[j][i] = 1;
		}
	}
	int ANS = 0;
	for (int i = 0; i < H; i++) {
		stack<pair<int, int> > ST;
		ST.push({ C[i][0], 0 });
		for (int j = 1; j < W - 1; j++) {
			int X = j;
			while (!ST.empty() && ST.top().first > C[i][j]) {
				ANS = max(ANS, ST.top().first * (j - ST.top().second + 1));
				X = ST.top().second;
				ST.pop();
			}
			ST.push({ C[i][j], X });
		}
		while (!ST.empty()) {
			ANS = max(ANS, ST.top().first * (W - ST.top().second));
			ST.pop();
		}
	}
	cout << max(ANS, max(H, W)) << endl;
}

# include <iostream>
# include <string>
# include <algorithm>
# include <vector>
# include <cstring>
# include <stdio.h>
# include <map>
# include <queue>

# define ll long long
# define pii pair<int,int>
# define FOR(a,b) for(int a=1; a<=b; a++)
# define REP(a,b) for(int a=0; a<b; a++)
# define FORU(a,b,c) for(int a=b; a<=c; a++)
# define FORD(a,b,c) for(int a=b; a>=c; a--)

using namespace std;

char grid[2005][2005];
int tok[2005][2005];
int h[2005], w[2005];

int R, C;

int main(){

    ios :: sync_with_stdio(false);
    cin >> R >> C;
    FOR(i,R) FOR(j,C){
        cin >> grid[i][j];
    }

    int ans = max(R,C);
    FOR(i,R-1){
        FOR(j,C-1){
            int black = (grid[i][j] == '#') + (grid[i][j+1] == '#') + (grid[i+1][j] == '#') + (grid[i+1][j+1] == '#');
            tok[i][j] = black&1;
        }
    }

    FOR(i,R){
        FOR(j,C-1){
            if(tok[i-1][j]) h[j] = 1;
            else h[j]++;
        }

        int k = 0;
        FOR(j,C-1){
            while(h[j] <= h[w[k]]){
                ans = max(ans, h[w[k]]*(j - w[k-1]));
                k--;
            }
            w[++k] = j;
        }

        while(k > 0){
            ans = max(ans, h[w[k]] * (C - w[k-1]));
            k--;
        }
    }

    cout << ans << endl;
    return 0;
}


#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i <(n); ++i)
#define REP2(i,x,n) for (int i = x; i <(n); ++i)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using P = pair<int,int>;
static const double PI = acos(-1);
static const int INF = 1e9+7;
#define REP(i,n) for (int i = 0; i <(n); ++i)
//debug
#ifdef _DEBUG
#define debug(var)  do{cout << #var << " :";view(var);}while(0)
#else
#define debug(...)
#endif
template<typename T> void view(T e){cout << e << endl;}
template<typename T> void view(const vector<T>& v){for(const auto& e : v){ cout << e << " "; } cout << endl;}
template<typename T> void view(const vector<vector<T> >& vv){ for(const auto& v : vv){ view(v); } }

int main(){
  string s;
  cin >> s;
  map<char, bool> mp;
  for(char alp = 'a'; alp <='z'; alp++){
    mp[alp] = false;
  }

  REP(i,s.size()){
    mp[s[i]] = true;
  }
  for(char alp = 'a'; alp <='z'; alp++){
    if(mp[alp] == false) {
      cout << alp << endl;
      return 0;
    }
  }

  cout << "None" << endl;

  return 0;
}

#include <bits/stdc++.h>

using namespace std;

int main()
{
	string S , T;
	while(getline(cin , S))for(size_t i = 0; i < 26; i++)
	{
		for(auto &x : S)if('a' <= x&&x <= 'z')if(++x > 'z')x -= 26;
		stringstream SS;
		SS << S;
		vector<string>VS;
		while(SS >> T)if(T == "the" || T == "this" || T == "that" || T == "ths." || T == "this." || T == "that.")
		{
			cout << S << endl;
			break;
		}
	}
}


#include<bits/stdc++.h>
#define reg register int
#define il inline
#define fi first
#define se second
#define mk(a,b) make_pair(a,b)
#define numb (ch^'0')
#define pb push_back
#define solid const auto &
#define enter cout<<endl
#define pii pair<int,int>
using namespace std;
typedef long long ll;
template<class T>il void rd(T &x){
    char ch;x=0;bool fl=false;while(!isdigit(ch=getchar()))(ch=='-')&&(fl=true);
    for(x=numb;isdigit(ch=getchar());x=x*10+numb);(fl==true)&&(x=-x);}
template<class T>il void output(T x){if(x/10)output(x/10);putchar(x%10+'0');}
template<class T>il void ot(T x){if(x<0) putchar('-'),x=-x;output(x);putchar(' ');}
template<class T>il void prt(T a[],int st,int nd){for(reg i=st;i<=nd;++i) ot(a[i]);putchar('\n');}
namespace Modulo{
const int mod=1e9+7;
int ad(int x,int y){return (x+y)>=mod?x+y-mod:x+y;}
void inc(int &x,int y){x=ad(x,y);}
int mul(int x,int y){return (ll)x*y%mod;}
void inc2(int &x,int y){x=mul(x,y);}
int qm(int x,int y=mod-2){int ret=1;while(y){if(y&1) ret=mul(x,ret);x=mul(x,x);y>>=1;}return ret;}
}
using namespace Modulo;
namespace Miracle{
const int N=2002;
const int M=4000000+5+N+N;
int n,k;
int f[2][N];
int jie[M],inv[M];
int C(int n,int m){
    if(n<0||m<0||n<m) return 0;
    return mul(jie[n],mul(inv[m],inv[n-m]));
}
int main(){
    rd(n);rd(k);
    if(k==1){
        puts("1");return 0;
    }
    int lim=n*k+n+n;
    jie[0]=1;
    for(reg i=1;i<=lim;++i) jie[i]=mul(jie[i-1],i);
    inv[lim]=qm(jie[lim]);
    for(reg i=lim-1;i>=0;--i) inv[i]=mul(inv[i+1],i+1);
    int tmp=0;
    f[0][0]=1;
    for(reg i=2*n;i>=1;--i){
        tmp^=1;
        memset(f[tmp],0,sizeof f[tmp]);
        int re=2*n-i;
        for(reg j=0;j<=min(re,n);++j){
            if(!f[tmp^1][j]) continue;
            int le=re-j;
            if(le+1<=j) f[tmp][j]=ad(f[tmp][j],f[tmp^1][j]);
            if(j!=n){
                f[tmp][j+1]=ad(f[tmp][j+1],mul(f[tmp^1][j],C(k-2+le+j*(k-1),le+j*(k-1))));
            }
        }
    }
    ll ans=mul(f[tmp][n],jie[n]);
    ot(ans);
    return 0;
}

}
signed main(){
    Miracle::main();
    return 0;
}

/*
   Author: *Miracle*
*/

#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn=2000+10,mod=1e9+7;
ll f[maxn][maxn];
ll s[maxn*maxn+10],invs[maxn*maxn+10];
int n,m;
inline void read(int &x){
	char c=getchar();
	int f=1;
	x=0;
	while(c<'0' || c>'9'){if(c=='-')f=-1;c=getchar();}
	while(c>='0' && c<='9'){x=x*10+c-'0';c=getchar();}
	x*=f;
}
inline long long ksm(ll x,int y){
	ll sum=1;
	while(y){
		if(y&1){sum=(sum*x)%mod;}
		y/=2;
		x=(x*x)%mod;
	}
	return sum%mod;
}
inline ll cal(int x,int y){
	//cout<<s[x]<<" "<<s[y]<<endl;
	ll sum2=1,sum1=1,sum=0;
	//for(register int i=1;i<=y;i++)sum1=(sum1*i)%mod;
	//for(register int i=x-y+1;i<=x;i++)sum2=(sum2*i)%mod;
	//sum2=s[x];sum1=(s[x-y]*s[y])%mod;
	//sum=(sum2*ksm(sum1,mod-2))%mod;
	sum=((s[x]*invs[y])%mod*invs[x-y])%mod;
	//cout<<sum<<endl;
	return sum%mod;
}
int main(){
	int i,j,k;
	read(n);read(m);
	//cout<<n<<" "<<m<<endl;
	if(m==1){cout<<1<<endl;return 0;}
	f[0][0]=1;
	s[0]=1;
	//for(register int i=1;i<=n;i++)f[i][0]=1;
	for(register int i=1;i<=maxn*maxn;i++){s[i]=(s[i-1]*i)%mod;}
	invs[maxn*maxn]=ksm(s[maxn*maxn],mod-2);
	for(register int i=maxn*maxn-1;i>=0;i--)invs[i]=(invs[i+1]*(i+1))%mod;
	for(register int i=1;i<=n;i++)
		for(register int j=0;j<=i;j++){
			if(!j)f[i][j]=f[i-1][j]%mod;
			else f[i][j]=(f[i-1][j]+((f[i][j-1]*(n-j+1))%mod*cal(n*m-(j-1)*(m-1)-i-1,m-2)))%mod;
		}
	cout<<f[n][n]<<endl;
	return 0;
}


#include <cstdio>
#include <vector>

using namespace std;

class Edge{
public:
	int from,to,cost;
	Edge(int f,int t,int c){
		from = f;
		to = t;
		cost = c;
	}
	void swap(){
		int a = from;
		from = to;
		to = a;
	}
};

vector<Edge> edge;

int n,m;
const int INF = 999999999;

int solve(int s){
	int* d = new int[n + 1];
	for(int i=0;i<=n;i++){
		d[i] = INF;
	}
	d[s] = 0;

	while(1){
		bool f = true;
		vector<Edge>::iterator it;
		for(it = edge.begin();it<edge.end();it++){
			if(d[it->from] != INF){
				if(d[it->to] > d[it->from] + it->cost){
					d[it->to] = d[it->from] + it->cost;
					f = false;
				}
			}
		}
		if(f){
			break;
		}
	}
	int ans = 0;
	for(int i=2;i<=n;i++){
		if(d[i] <= 2){
			ans += 1;
		}
	}
	delete[] d;
	return ans;
}

int main(){
	int a,b;
	while(scanf("%d %d",&n,&m) && (n || m)){
		edge.clear();
		for(int i=0;i<m;i++){
			scanf("%d %d",&a,&b);
			edge.push_back( Edge(a,b,1) );
			edge.push_back( Edge(b,a,1) );
		}
		printf("%d\n",solve(1));
	}
}

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

int need[10] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};

int compare(string s, string t) {
    if (s.length() > t.length()) {
        return -1;
    } else if (s.length() < t.length()) {
        return 1;
    } else {
        if (s < t) {
            return 1;
        } else if (s == t) {
            return 0;
        } else {
            return -1;
        }
    }
}

string add(string s, char a) {
    if (s.length() == 0) {
        return string(1, a);
    }
    if (s[0] <= a) {
        return a + s;
    } else if (s.back() >= a) {
        return s + a;
    }
    for (int i = 0; i < (int)s.length(); i++) {
        if (s[i] < a) {
            return s.substr(0, i) + a + s.substr(i + 1);
        }
    }
    return "";
}

int main() {
    int N, M;
    cin >> N >> M;
    vector<int> A(M);
    for (int i = 0; i < M; i++) {
        cin >> A[i];
    }

    vector<string> dp(N + 1, "");
    for (int a : A) {
        if (need[a] > N)
            continue;
        if (dp[need[a]] == "") {
            dp[need[a]] = to_string(a);
        } else if (compare(dp[need[a]], to_string(a)) == 1) {
            dp[need[a]] = to_string(a);
        }
    }
    for (int i = 0; i <= N; i++) {
        if (dp[i] == "")
            continue;

        for (int a : A) {
            int nxt = i + need[a];
            if (nxt > N)
                continue;

            string added = add(dp[i], ('0' + a));
            if (dp[nxt] == "") {
                dp[nxt] = added;
            } else if (compare(dp[nxt], added) == 1) {
                dp[nxt] = added;
            }
        }
    }
    cout << dp[N] << endl;
}


#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define irep(i, n) for (int i = (n); i >= 0; i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1 << 30;

int main() {
  vector<queue<char>> s(3);
  rep(i,3) {
    string t; cin >> t;
    rep(j,t.size()) s[i].push(t[j]);
  }
  int turn = 0;
  //!s[0].empty()&&!s[1].empty()&&!s[2].empty()
  while (true)
  {
    if (s[turn].empty()) break;
    char c = s[turn].front(); s[turn].pop();
    if (c == 'a') turn = 0;
    else if (c=='b') turn = 1;
    else turn = 2;
  }
  if (turn==0) cout << 'A' << endl;
  else if (turn==1) cout << 'B' << endl;
  else cout << 'C' << endl;
  return 0;
}

#include <bits/stdc++.h>
using namespace std;
int main(){
  int H,W; cin>>H>>W;
  vector<vector<char>>A(H+2,vector<char>(W+2,'.'));
  for(int i=1;i<=H;i++){
    string S; cin>>S;
    for(int j=1;j<=W;j++){
      A[i][j]=S.at(j-1);
    }
  }
  for(int i=1;i<=H;i++){
    for(int j=1;j<=W;j++){
      if(A[i][j]=='.')continue;
      if(A[i+1][j]=='#')continue;
      if(A[i-1][j]=='#')continue;
      if(A[i][j+1]=='#')continue;
      if(A[i][j-1]=='#')continue;
      cout<<"No"<<endl;
      return 0;
    }
  }
  cout<<"Yes"<<endl;
}


#include <bits/stdc++.h>
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define debug  freopen("in.txt","r",stdin),freopen("out.txt","w",stdout);
#define pb push_back
#define all(x) x.begin(),x.end()
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int maxn = 5e5+10;
const int maxM = 1e6+10;
const int inf = 0x3f3f3f3f;

int N,Q;
int c[maxn];
int last[maxn],nx[maxn];
int root[maxn];
struct Tree
{
	struct node{
		int l,r;
		int sum;
	}tr[maxn*4 + maxn*19];
	int tail = 0;
	int build(int l,int r){
		int cur = ++tail;
		if(l == r) return cur;
		int mid = (l+r)>>1;
		tr[cur].l = build(l,mid);
		tr[cur].r = build(mid+1,r);
		return cur;
	}
	int insert(int pre,int l,int r,int x){
		int cur = ++tail;
		tr[cur] = tr[pre];
		if(l == r){
			tr[cur].sum++;
			return cur;
		}else{
			int mid = (l+r)>>1;
			if(x <= mid) tr[cur].l = insert(tr[pre].l,l,mid,x);
			else tr[cur].r = insert(tr[pre].r,mid+1,r,x);
			tr[cur].sum = tr[tr[cur].l].sum + tr[tr[cur].r].sum;
			return cur;
		}
	}
	int query(int cur,int pre,int l,int r,int R){
		if(l == r){
			if(R>l) return tr[cur].sum - tr[pre].sum;
			else return 0;
		}else{
			int mid = (l+r)>>1;
			if(R<=mid) return query(tr[cur].l,tr[pre].l,l,mid,R) + tr[tr[cur].r].sum - tr[tr[pre].r].sum;
			else return query(tr[cur].r,tr[pre].r,mid+1,r,R);
		}
	}
}tree;
void init(){
	for(int i = 1;i<=N;i++){
		if(last[c[i]]){
			nx[last[c[i]]] = i;
		}
		last[c[i]] = i;
	}
	for(int i = 1;i<=N;i++)  if(nx[i] == 0) nx[i] = N+1;
}
void solve(){
	root[0] = tree.build(1,N+1);
	for(int i = 1;i<=N;i++){
		root[i] = tree.insert(root[i-1],1,N+1,nx[i]);
	}
	while(Q--){
		int l,r;cin>>l>>r;
		int ans = tree.query(root[r],root[l-1],1,N+1,r);
		cout<<ans<<'\n';
	}
}
int main(){
	// debug;
	ios;

	cin>>N>>Q;
	for(int i =1;i<=N;i++) cin>>c[i];
	init();
	solve();

	return 0;
}

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int c[500005];
int d[500005];
int e[500005];
int a[500005];
int bit[500005];
vector<pair<int, int>> v[500005];
int n, q;
// 1 is true
// 0 is false

int esum(int l, int r) {
  int sum = 0;
  for (int i = l; i <= r; i++) {
    sum += e[i];
  }
  return sum;
}

void update(int i, int value) {
  for (; i <= n; i += i & -i) {
    bit[i] += value;
  }
}

int sum(int i) {
  int s = 0;
  for (; i > 0; i -= i & -i) {
    s += bit[i];
  }
  return s;
}

int main() {
  cin >> n >> q;
  for (int i = 1; i <= n; i++) {
    cin >> c[i];
  }
  for (int i = 1; i <= q; i++) {
    int l, r;
    cin >> l >> r;
    v[r].push_back({i, l});
  }

  for (int i = 1; i <= n; i++) {
    if (d[c[i]] != 0) {
      update(d[c[i]], -1);
    }
    d[c[i]] = i;
    update(i, 1);
    for (auto x : v[i]) {
      a[x.first] = sum(i) - sum(x.second - 1);
    }
    // for (int r = 1; r <= n; r++) {
    //   cout << c[r] << ' ';
    // }
    // cout << endl;
    // for (int r = 1; r <= n; r++) {
    //   cout << d[r] << ' ';
    // }
    // cout << endl;
    // for (int r = 1; r <= n; r++) {
    //   cout << e[r] << ' ';
    // }
    // cout << endl << "--------------------------------" << endl;
  }
  for (int i = 1; i <= q; i++) {
    cout << a[i] << endl;
  }
}


#include <iostream>
#include <algorithm>
#include <string>
#define N 50
using namespace std;
struct data{
  string l;
  int p,a,b,c,d,e,f,s,m;
  double cal;
};
int main(){
  int n,i,j,time;
  struct data d[N];
  while(1){
    cin >> n;
    if(n==0) break;
    for(i=0;i<n;i++){
      cin >> d[i].l >> d[i].p >> d[i].a >> d[i].b >> d[i].c;
      cin >> d[i].d >> d[i].e >> d[i].f >> d[i].s >> d[i].m;
      time=(d[i].a+d[i].b+d[i].c+d[i].d+d[i].e);
      d[i].m--;
      time+=(d[i].d+d[i].e)*d[i].m;
      d[i].cal=((double)d[i].f*d[i].s*(d[i].m+1)-d[i].p)/time;
    }
    for(i=0;i<n;i++){
      for(j=1;j<n;j++){
	if(d[j].l<d[j-1].l) swap(d[j],d[j-1]);
      }
    }
    for(i=0;i<n;i++){
      for(j=1;j<n;j++){
	if(d[j].cal>d[j-1].cal) swap(d[j],d[j-1]);
      }
    }
    for(i=0;i<n;i++) cout << d[i].l << endl;
    cout << '#' << endl;
  }
  return 0;
}

# define _CRT_SECURE_NO_WARNINGS 1
# define _USE_MATH_DEFINES
# include <iostream>
# include <numeric>
# include <string>
# include <bitset>
# include <vector>
# include <algorithm>
# include <cstdlib>
# include <cstdio>
# include <cstring>
# include <cstdlib>
# include <iomanip>
# include <queue>
# include <sstream>
# include <unordered_set>
# include <unordered_map>
# include <climits>
# include <complex>
# include <cmath>
# include <list>
# include <functional>
# include <string>
# include <ctime>
# include <set>
# include <forward_list>
# include <map>
# include <stack>
using namespace std;
# define INF ((int)(1<<25))
# define REP(i,n) for(int i=0;i<(int)n;i++)
# define FOR(i,n) REP(i,n)
# define FORI(i,k,n) for(int i=k;i<(int)n;i++)
# define TORAD 2.0*M_PI/360.0
# define INT(x) int x;cin>>x;
# define STR(x) string x;cin>>x;
# define ALL(x) begin(x),end(x)
# define RALL(x) (x).rbegin(),(x).rend()
# define DEBUG(x) cout<<#x<<":"<<x<<endl;
# define EPS 1e-12
#ifdef _MSC_VER
#include <intrin.h>
#define __builtin_popcount __popcnt
#endif
typedef long long lint;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<int> vi;
typedef vector<lint> vl;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
//const int dx[4] = { 0, 1, 0, -1 }, dy[4] = { -1, 0, 1, 0 };
const int dx[4] = {1,0,-1,0}, dy[4] = {0,1,0,-1};
template<class T> void debug(T a) { for (auto i : a)cout << i << endl; }

int main()
{
	while (true)
	{
		int w, h;
		pii start, goal;
		int n;
		int a[200][200] = {};
		bool flag[200][200] = {};
		bool ok = false;
		cin >> w >> h;if (!w)break;
		cin >> start.first >> start.second;
		cin >> goal.first >> goal.second;
		cin >> n;

		FOR(i, n)
		{
			int c, d, x, y;
			cin >> c >> d >> x >> y;
			for (int X = x; X <= x+1+(d?0:2); X++)
			{
				for (int Y = y; Y <= y + 1 + (d ? 2 : 0); Y++)
				{
					a[X][Y] = c;
				}
			}
		}

		flag[start.first][start.second] = true;
		queue<pii> que;
		if(a[start.first][start.second]!=0)que.push(start);

		while (!que.empty())
		{
			pii now = que.front(); que.pop();
			if (now == goal)
			{
				cout << "OK" << endl;
				ok = true;
			}

			FOR(i, 4)
			{
				pii next=now;
				next.first += dx[i]; next.second += dy[i];

				if (a[next.first][next.second] == a[now.first][now.second] && !flag[next.first][next.second])
				{
					flag[next.first][next.second] = true;
					que.push(next);
				}
			}
		}

		if (!ok)cout << "NG" << endl;
	}
}


#include <iostream>
#include <vector>
using namespace std;
const int MOD = 1000000007;
const int N_MAX = 100000;

long long mod(long long a) {
	a %= MOD;
	return a >= 0 ? a : a+MOD;
}

long long inverse[N_MAX+1+64];
long long factorial[N_MAX+1+64];
long long factorial_inverse[N_MAX+1+64];

void calc(int n) {
	inverse[1] = 1;
	factorial[0] = factorial[1] = 1;
	factorial_inverse[0] = factorial_inverse[1] = 1;
	for (int i = 2; i <= n; i++) {
		inverse[i] = MOD - inverse[MOD%i] * (MOD/i) % MOD;
		factorial[i] = i * factorial[i-1] % MOD;
		factorial_inverse[i] = inverse[i] * factorial_inverse[i-1] % MOD;
	}
}

long long comb(long long n, long long k) {
	return factorial[n] * (factorial_inverse[k] * factorial_inverse[n-k] % MOD) % MOD;
}

long long rep_comb(long long n, long long k) {
	return comb(n + k - 1, k);
}

vector<pair<long long, int>> prime_factorization(long long n) {
	vector<pair<long long, int>> v;
	for (long long i = 2; i * i <= n; ++i) {
		int e = 0;
		while (n % i == 0) {
			++e;
			n /= i;
		}
		if (e != 0) v.emplace_back(i, e);
	}
	if (n != 1) v.emplace_back(n, 1);
	return v;
}

int main() {
	calc(N_MAX+65);
	long long n, m;
	cin >> n >> m;
	long long ans = 1;
	auto v = prime_factorization(m);
	for (auto el : v) {
		long long e = el.second;
		ans = mod(ans * rep_comb(n, e));
	}
	cout << ans << endl;
	return 0;
}

#include <algorithm>
#include <iostream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <bitset>
#include <complex>
#include <unistd.h>
#include <cassert>
#include <cctype>
#include <random>
#include <time.h>
#include <functional>
#define _USE_MATH_DEFINES
#define _GLIBCXX_DEBUG
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef pair<double, ll> pdlg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef tuple<ll, ll, ll, ll> tlglglglg;
typedef tuple<double, double, double> tddd;
typedef complex<double> xy_t;
typedef vector<ll> vll;
typedef vector< vector<ll> > matrix;
typedef unsigned int uint;
typedef unsigned long long ull;
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;
template <class T> using VVV = V<VV<T>>;
#define REP(i, x, y) for(ll i = (ll)x; i < (ll)y; i++)
#define DREP(i, x, y, d) for(ll i = (ll)x; i < (ll)y; i += (ll)d)
#define PER(i, x, y) for(ll i = (ll)x; i > (ll)y; i--)
#define DPER(i, x, y, d) for(ll i = (ll)x; i > (ll)y; i -= (ll)d)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
double pi = 3.141592653589793;
ll mod = 1000000007;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775807;
int iinf = intmax / 8;
ll inf = llmax / 8;
double eps = 1e-12;
void yesno(bool ok, string yes = "Yes", string no = "No") {
    if (ok) {
        cout << yes << endl;
    } else {
        cout << no << endl;
    }
}

ll dp[310][310][310];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S;
    cin >> S;
    ll len = S.size();
    ll K;
    cin >> K;
    dp[0][0][0] = 0;
    REP(i, 0, len) {
        REP(k, 0, K + 1) {
            dp[i][i + 1][k] = 1;
        }
    }
    REP(j, 2, len + 1) {
        REP(i, 0, len) {
            if (i + j > len) {
                continue;
            }
            REP(k, 0, K + 1) {
                dp[i][i + j][k] = max(dp[i][i + j - 1][k], dp[i + 1][i + j][k]);
                if (k > 0) {
                    dp[i][i + j][k] = max(dp[i][i + j][k], dp[i + 1][i + j - 1][k - 1] + 2);
                }
                if (S[i] == S[i + j - 1]) {
                    dp[i][i + j][k] = max(dp[i][i + j][k], dp[i + 1][i + j - 1][k] + 2);
                }
            }
        }
    }
    // REP(i, 0, len + 1) {
    //     REP(j, 0, len + 1) {
    //         REP(k, 0, K + 1) {
    //             cout << dp[i][j][k] << " ";
    //         }
    //         cout << "aaa ";
    //     }
    //     cout << endl;
    // }
    ll ans = 0;
    REP(i, 0, K + 1) {
        ans = max(ans, dp[0][len][i]);
    }
    cout << ans << endl;
}


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

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

#include<iostream>
#include<string>
#include<vector>
#include<set>

using namespace std;

int main(void){
	int a,b,c,d;
	int n,k;
	while(1){
		cin >> n;
		cin >> k;
		if(n==0 && k==0)break;
		vector<string> num;
		set<string> str;
		for(a=0;a<n;a++){
			string s;
			cin >> s;
			num.push_back(s);
		}
		if(k==2){
			for(a=0;a<n;a++){
				for(b=0;b<n;b++){
					if(a!=b)str.insert(num[a]+num[b]);
				}
			}
		}
		if(k==3){
			for(a=0;a<n;a++){
				for(b=0;b<n;b++){
					if(a!=b)for(c=0;c<n;c++){
						if(a!=c && b!=c)str.insert(num[a]+num[b]+num[c]);
					}
				}
			}
		}
		if(k==4){
			for(a=0;a<n;a++){
				for(b=0;b<n;b++){
					if(a!=b)for(c=0;c<n;c++){
						if(a!=c && b!=c)for(d=0;d<n;d++){
							if(a!=d && b!=d && c!=d)str.insert(num[a]+num[b]+num[c]+num[d]);
						}
					}
				}
			}
		}
		cout << str.size() << endl;
	}
	return 0;
}


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

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

int main(){
  ll n;
  cin >> n;
  vector<ll> p(5);
  rep(i,5) cin >> p.at(i);

  ll mi = p.at(0);
  rep(i,5) mi = min(mi, p.at(i));

  ll ans = ceil(double(n/double(mi))) + 4;
  cout << ans;
}

#include <bits/stdc++.h>
int n, a[205];
int main()
{
 	scanf("%d", &n);
  	for(int i=1; i<=2*n; i++) scanf("%d", a+i);
  	std::sort(a+1, a+2*n+1);
  	int ans = 0;
  	for(int i=1; i<=2*n; i+=2) ans += a[i];
  	printf("%d\n", ans);
}


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

int solve () {
	int n;
	cin >> n;
	vector<long long> a(n);
	for (auto &e : a) cin >> e;
	string s;
	cin >> s;

	vector<long long> b;
	for (int i = n; i--> 0;) {
		long long e = a[i];
		for (const auto &c : b) e = min(e, e^c);
		if (e > 0) {
			if (s[i] == '1') return 1;
			b.push_back(e);
		}
	}
	return 0;
}

int main() {
	int t;
	cin >> t;
	while (t--) cout << solve() << '\n';
	return 0;
}

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

#define INPUT_FROM_FILE (0)
#if INPUT_FROM_FILE
#include <fstream>
#endif

int calc_gcd(int n, int m){
	if(n == m){ return n; }
	if(n > m){
		std::swap(n, m);
	}
	return calc_gcd(n, m - n);
}

int main(int argc, char **argv){
#if INPUT_FROM_FILE
	std::ifstream ifs("test.txt");
#endif
	int n = 0;
	std::vector<int> vec;
	int gcd = 1;

#if INPUT_FROM_FILE
	ifs >> n;
#else
	std::cin >> n;
#endif
	vec.resize(n);
	for(int i = 0; i < n; i++){
#if INPUT_FROM_FILE
		ifs >> vec[i];
#else
		std::cin >> vec[i];
#endif
	}
	std::sort(vec.begin(), vec.end());

	gcd = calc_gcd(vec[0], vec[1]);

	std::cout << "1" << std::endl;
	for(int i = 2; i <= gcd; i++){
		if(gcd % i == 0){
			if(n == 3){
				if(vec[2] % i == 0){
					std::cout << i << std::endl;
				}
			}
			else{
				std::cout << i << std::endl;
			}
		}
	}
	return 0;
}


/*

This Submission is to determine how many 120/240 min const. delivery point there are.

//info
120 req. steps <= 5
*/
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;
typedef string::const_iterator State;
#define Ma_PI 3.141592653589793
#define eps 1e-5
#define LONG_INF 1e18
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define MOD 1000000007
#define seg_size 262144
#define REP(a,b) for(long long a = 0;a < b;++a)

unsigned long xor128() {
	static unsigned long x = time(NULL), y = 362436069, z = 521288629, w = 88675123;
	unsigned long t = (x ^ (x << 11));
	x = y; y = z; z = w;
	return (w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)));
}
//do gift-wrapping method
#define double long double
double dot(complex<double> a, complex<double> b) {
	return a.real() * b.real() + a.imag() * b.imag();
}
double gyaku_dot(complex<double> a, complex<double> b) {
	return a.real() * b.imag() - a.imag() * b.real();
}
double leng(complex<double> a) {
	return sqrt(a.real() * a.real() + a.imag() * a.imag());
}
double angles(complex<double> a, complex<double> b) {
	double cosine = dot(a, b) / (leng(a) * leng(b));
	double sine = gyaku_dot(a, b) / (leng(a) * leng(b));
	double kaku = acos(min((double)1.0, max((double)-1.0, cosine)));
	if (sine <= 0) {
		kaku = 2 * Ma_PI - kaku;
	}
	return kaku;
}
vector<int> convex_hull(vector<complex<double>> a) {
	vector<int> ans;
	double now_minnest = a[0].real();
	int now_itr = 0;
	REP(i, a.size()) {
		if (now_minnest > a[i].real()) {
			now_minnest = a[i].real();
			now_itr = i;
		}
	}
	ans.push_back(now_itr);
	complex<double> ba(0, 1);
	while (true) {
		int now_go = 0;
		double now_min = 0;
		double now_length = 0;
		int starter = ans[ans.size() - 1];
		for (int i = 0; i < a.size(); ++i) {
			if (i != starter) {
				double goa = angles(ba, a[i] - a[starter]);
				if (goa - now_min >= eps||(abs(goa - now_min) <= eps&&(abs(a[i] - a[starter]) - now_length) >= eps)) {
					now_min = goa;
					now_go = i;
					now_length = abs(a[i] - a[starter]);
				}
			}
		}
		if (now_go == ans[0]) break;
		ans.push_back(now_go);
		ba = complex<double>(a[now_go] - a[starter]);
	}
	return ans;
}
double ans[2000] = {};
#undef double
int main() {
#define double long double
	int n;
	cin >> n;
	vector<complex<double>> inputs;
	REP(i, n) {
		double x, y;
		cin >> x >> y;
		inputs.push_back(complex<double>(x, y));
	}
	vector<int> hoge;
	if (n == 2) {
		hoge.push_back(0);
		hoge.push_back(1);
	}
	else {
		hoge = convex_hull(inputs);
	}
	hoge.push_back(hoge[0]);
	hoge.push_back(hoge[1]);
	for (int i = 1; i < hoge.size() - 1; ++i) {
		complex<double> A = inputs[hoge[i]] - inputs[hoge[i - 1]];
		complex<double> B = inputs[hoge[i + 1]] - inputs[hoge[i]];
		complex<double> C = complex<double>(A.imag() * -1.0, A.real());
		complex<double> D = complex<double>(B.imag() * -1.0, B.real());
		ans[hoge[i]] = angles(D,C) / (2.0 * Ma_PI);
	}
	cout << fixed << setprecision(50);
	REP(i, n) {
		cout << ans[i] << endl;
	}
}

#include <iostream>
#include <cstdio>
#include <algorithm>

using namespace std;

int p[500];

int sakurako(int a, int b, int c){
	bool f1, f2, f3;
	f1 = (p[a] == 1 ? true : false);
	f2 = (p[b] == 1 ? true : false);
	f3 = (p[c] == 1 ? true : false);

	if (f1 && f2 && !f3) return c;
	if (f1 && !f2 && f3) return b;
	if (!f1 && f2 && f3) return a;
	return -1;
}

int main(void)
{
	int a, b, c, n;
	int ni[1200], nj[1200], nk[1200], nr[1200];

	while(cin >> a >> b >> c){
		if (a == 0) break;
		cin >> n;

		fill(p, p + 500, 2);

		for (int i = 0; i < n; i++){
			scanf("%d %d %d %d", &ni[i], &nj[i], &nk[i], &nr[i]);
			if (nr[i] == 1){
				p[ni[i]] = 1;
				p[nj[i]] = 1;
				p[nk[i]] = 1;
			}
		}

		for (int i = 0; i < n; i++){
			if (nr[i] == 0){
				int re = sakurako(ni[i], nj[i], nk[i]);
				if (re == -1) continue;
				p[re] = 0;
			}
		}

		for (int i = 1; i <= a + b + c; i++){
			printf("%d\n", p[i]);
		}
	}

	return 0;
}


#include <iostream>
#include <algorithm>
using namespace std;
int main() {
	int A, B;
	cin >> A >> B;
	cout << max({ 2 * A - 1, 2 * B - 1, A + B }) << endl;
	return 0;
}

#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string.h>
using namespace std;
struct node{
	int a;
	int b;
}x[100005];

int main()
{
  int n,m;
  scanf("%d%d",&n,&m);
  for(int i=0;i<m;i++)
  {
      scanf("%d%d",&x[i].a,&x[i].b);
  }
  int start=x[0].a;
  int end=x[0].b;
  for(int i=1;i<m;i++)
  {
  	start=max(x[i].a,start);
  	end=min(x[i].b,end);
  }
  int sum=end-start+1;
  if(sum<0)
  sum=0;
  printf("%d\n",sum);
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
using pp=pair<int,char>;
using ll=long long;

int main() {
  int N, Y;
  cin >> N >> Y;
  string ans="No";
  int fin=0;
  for (int i=0; i<=Y/10000; i++) {
    for (int j=0; j<=(Y-10000*i)/5000; j++) {
      if (Y-10000*i-5000*j==(N-i-j)*1000) {
        cout << i << " " << j << " " << N-i-j << endl;
        fin =1;
        break;
      }
    }
    if (fin==1) {break;}
  }
  if (fin==0) {
    cout << -1 << " " << -1 << " " << -1 << endl;
  }
}

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()
#define all2(a, b) (a).begin(), (a).begin() + (b)
#define debug(vari) cerr << #vari << " = " << (vari) << endl;
const int MOD = 1e9 + 7;

int main()
{
    int n, y;
    cin >> n >> y;
    rep(i, n + 1)
    {
        rep(j, n + 1)
        {
            if (i + j + (y / 1000 - 10 * i - 5 * j) == n && (y / 1000 - 10 * i - 5 * j) >= 0)
            {
                printf("%d %d %d\n", i, j, y / 1000 - 10 * i - 5 * j);
                return (0);
            }
        }
    }

    printf("-1 -1 -1\n");
    return (0);
}


#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a), i##_max = (b); i < i##_max; ++i)
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()

using namespace std;
using vi = vector<int>;
using i64 = int64_t;

constexpr int INF = 1 << 30;
constexpr int MOD = 1000000007;

i64 cnt = 0;

template <typename T>
void print(vector<T> v) {
  REP(i, v.size()) {
    if (i) cout << " ";
    cout << v[i];
  }
  cout << endl;
}

void merge(vi &A, int left, int mid, int right) {
  auto n1 = mid - left;
  auto n2 = right - mid;
  vi L(n1 + 1), R(n2 + 1);
  copy(A.begin() + left, A.begin() + mid, L.begin());
  copy(A.begin() + mid, A.begin() + right, R.begin());
  L[n1] = INF;
  R[n2] = INF;
  int i = 0, j = 0;
  FOR(k, left, right) {
    if (L[i] <= R[j]) {
      A[k] = L[i++];
    } else {
      A[k] = R[j++];
      cnt += n1 - i;
    }
  }
}

void merge_sort(vi &A, int left, int right) {
  if (left + 1 < right) {
    int mid = (left + right) / 2;
    merge_sort(A, left, mid);
    merge_sort(A, mid, right);
    merge(A, left, mid, right);
  }
}

int main() {
  int n;
  cin >> n;
  vi S(n);
  REP(i, n) cin >> S[i];
  merge_sort(S, 0, n);
  cout << cnt << endl;
}

#include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>
using namespace std;
#define U(v) cerr << #v << ": " << (v) << endl

template <class T>
struct BIT {
    vector<T> a;
    BIT(int size) : a(size, 0) {}
    T sum(int r) const {
        T sm = 0;
        for (--r; r >= 0; r = (r & r + 1) - 1)
            sm += a[r];
        return sm;
    }
    T sum(int l, int r) const {
        return sum(r) - sum(l);
    }
    T at(int i) const {
        return sum(i, i + 1);
    }
    void add(int i, T v) {
        for (; i < (int)a.size(); i |= i + 1)
            a[i] += v;
    }
    void set(int i, T v) {
        add(i, v - at(i));
    }
};

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    vector<pair<int, int>> b(n);
    for (int i = 0; i < n; ++i) {
        cin >> b[i].first;
        b[i].second = i;
    }
    sort(b.begin(), b.end());
    for (int i = 0; i < n; ++i)
        a[b[i].second] = i;
    BIT<int> bit(n);
    long long sm = 0;
    for (int i = n - 1; i >= 0; --i) {
        sm += bit.sum(a[i]);
        bit.add(a[i], 1);
    }
    cout << sm << endl;
    return 0;
}


#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<queue>
#include<algorithm>
#define ll long long
#define rg register
#define go(i,x,a) for(rg int i=a;i<x;i++)
#define inf 0x3f3f3f3f
#define mod 1000000007
using namespace std;

const int maxn=5e5+5;
int n,a[maxn],b[maxn],hx[maxn],tl,s0[maxn],q[maxn],tt;
ll ans,f[maxn][2];
vector<int>g[maxn];

inline int rd(){
	int ret=0,af=1; char gc=getchar();
	while(gc < '0' || gc > '9'){ if(gc == '-') af=-af; gc=getchar(); }
	while(gc >= '0' && gc <= '9') ret=ret*10+gc-'0',gc=getchar();
	return ret*af;
}

inline void add(ll &a,ll b){ a=a+b; if(a >= mod) a-=mod; return; }
inline void dec(ll &a,ll b){ a=a-b; if(a < 0) a+=mod; return ; }

inline  void cal(int x){
	tt=0;
	go(i,g[x].size(),0) q[++tt]=g[x][i];
	ll sa=1,sb=0;
	go(i,tt+1,1){
		ll ss=s0[q[i]]-s0[q[i-1]];
		add(sa,sb*ss%mod);
		add(sb,sa);
	}
	if(q[tt] != n){
		ll ss=s0[n]-s0[q[tt]];
		add(sa,sb*ss%mod);
	}
	add(ans,b[n] == 0 ? sb : sa);
}

inline ll qpow(int x,int k){
	ll ss=1,tmp=x;
	while(k > 0){
		if(k & 1) ss=ss*tmp%mod;
		tmp=tmp*tmp%mod;
		k>>=1;
	}
	return ss;
}

int main(){
	n=rd();
	go(i,n+1,1){
		a[i]=rd();	b[i]=b[i-1]^a[i];
		if(b[i]) hx[++tl]=b[i];
	}
//	go(i,n+1,1) printf("%d ",b[i]);	puts("");
	go(i,n+1,1) s0[i]=s0[i-1]+(b[i] == 0);
	sort(hx+1,hx+tl+1); tl=unique(hx+1,hx+tl+1)-hx-1;
//	go(i,tl+1,1) printf("%d ",hx[i]); puts("");
	go(i,n+1,1)
		if(b[i]) b[i]=lower_bound(hx+1,hx+tl+1,b[i])-hx;
	go(i,n+1,1) g[b[i]].push_back(i);
	if(b[n] == 0){
		go(i,tl+1,1) cal(i);//,printf("%d: %lld\n",hx[i],ans);
		add(ans,qpow(2,s0[n]-1));
	}else cal(b[n]);
	printf("%lld",ans);
	return 0;
}


#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

int main(){
  int n, m;
  cin >> n >> m;
  ll ans = 1001001001;
  for(ll i = 1; i*i <= m; i++){
    if(m % i != 0) continue;
    ll j = m / i;
    if(i >= n){
      ans = min(ans, i);
    }
    if(j >= n){
      ans = min(ans, j);
    }
  }
  if(ans == 1001001001) ans = m;
  ans = m/ans;
  cout << ans << endl;
  return 0;
}

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

int main() {
    int R,G;
    cin >> R >> G;
    cout << G + G - R;
}


#include<iostream>
#include<iomanip>
using namespace std;
int main(void){
      int x;
       cin >> x;
       cout << x*x*x <<"\n";
    return 0;
}

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

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

  int ans = 1;
  for (int i = 0; i < 3; i++) {
    ans *= x;
  }
  cout << ans << endl;
}


#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <assert.h>
#include <memory.h>
#include <queue>
#include <string.h>
#include <map>
using namespace std;

#define N 40
#define BIT (1<<17)
#define mod 1000000007

int add(int x,int y) {
  int ret = x+y;
  if(ret<0) {
    ret += mod;
  } else if(ret>=mod) {
    ret -= mod;
  }
  return ret;
}
int n,x[3],maxi;

int dp[N][BIT][2];
map<int,int> failure;
int ar[1000],tot = 0;

int failureCall(int bit) {
  if(bit==0) {
    return 0;
  }
  int nbit;
  if(failure.count(bit)) {
    return failure[bit];
  }
  for(int i=0;;++i) {
    if(bit&(1<<i)) {
      nbit = bit>>(i+1);
      break;
    }
  }
  if(nbit==0) {
    return 0;
  }
  if(nbit>=BIT) {
    return failure[bit] = failureCall(nbit);
  }
  int ret = 0;
  int sum = 0,cur = 0;
  int lastBit = -1;
  bool isGood = true;
  for(int i=0;;++i) {
    if((1<<i) >nbit) {
      break;
    }
    if(nbit&(1<<i)) {
      int a = i-lastBit;
      lastBit = i;
      sum += a;
      if(sum==x[cur]) {
        ++cur;
        sum = 0;
      }else if (sum>x[cur]) {
        isGood = false;
        break;
      }
    }
  }
  if(isGood) {
    return failure[bit] = nbit;
  } else {
    return failure[bit] = failureCall(nbit);
  }
}

map<int,pair<int,int> > BB;
pair<int,int> newBit(int bit,int num) {
  tot = 0;
  int lastBit = -1;
  int pos = 0;
  for(int i=0;i<17;++i) {
    if(bit&(1<<i)) {
      ar[pos++] = i-lastBit;
      lastBit = i;
    }
  }
  if(num!=-1) {
    ar[pos++] = num;
    bit |= (1<<(lastBit + num));
  }
  if(bit>=BIT) {
    return newBit(failureCall(bit),-1);
  }
  int cur = 0,sum = 0;
  for(int i=0;i<pos;++i) {
    sum += ar[i];
    tot += ar[i];
    if(sum==x[cur]) {
      ++cur;
      sum = 0;
    } else if(sum>x[cur]) {
      return newBit(failureCall(bit),-1);
    }
  }
  if( cur!=3) {
    return make_pair(0, bit);
  } else {
    //success but need failure
    return make_pair(1 , failureCall(bit));
  }
}
int solveDp(int ind,int bit,int isSatisfy) {
  if(ind==n) {
    if(isSatisfy) {
      return 1;
    } else {
      return 0;
    }
  }
  int &ret = dp[ind][bit][isSatisfy];
  if(ret!=-1) {
    return ret;
  }
  ret = 0;
  for(int num=1;num<=10;++num) {
    pair<int,int> nBit;
    if(num>maxi) {
      nBit = make_pair(0,0);
    } else {
      nBit = newBit(bit,num);
    }
    ret = add(ret, solveDp(ind+1,nBit.second, isSatisfy | nBit.first));
  }
  return ret;
}
void solve() {
  scanf("%d ", &n);
  for(int i=0;i<3;++i) {
    scanf("%d ", &x[i]);
    maxi = max(maxi,x[i]);
  }
  memset(dp,-1,sizeof(dp));
  printf("%d\n", solveDp(0,0,0));
}

int main() {
  //freopen("input.txt","r",stdin);
  solve();
  return 0;
}

#include<algorithm>
#include<cstring>
#include<cstdio>
#define ll long long
#define qwq
const int mod=1e9+7;
int dp[50][(1<<17)+7];
int n,x,y,z;
ll all_ans=1;
int main(){
	scanf("%d%d%d%d",&n,&x,&y,&z);
	int gdans=(1<<(x+y+z-1))|(1<<(y+z-1))|(1<<(z-1));
	int limit=(1<<(x+y+z))-1;
	dp[0][0]=1;
	for(int i=1;i<=n;++i){
		all_ans*=10;
		all_ans%=mod;
		for(int s=0;s<=limit;++s){
			if((s&gdans)==gdans)continue;
			for(int c=1;c<=10;++c){
				int k=((s<<c)|(1<<(c-1)))&limit;
				if((k&gdans)==gdans)continue;
				dp[i][k]+=dp[i-1][s];
				dp[i][k]%=mod;
			}
		}
	}
	ll ans=0;
	for(int s=0;s<=limit;++s){
		ans+=dp[n][s];ans%=mod;
	}
	printf("%lld\n",(all_ans-ans+mod)%mod);
	return 0;
}


#include <bits/stdc++.h>
#define reg register
#define ll long long
#define ull unsigned long long
using namespace std;
const int MAXN = 110;
int n;
ll a[MAXN];
void work() {
  scanf("%d", &n);
  for(reg int i = 1; i <= n; ++i) scanf("%lld", &a[i]);
  int ans = 0;
  for(reg int i = 1; i <= n; ++i) {
    for(reg int j = i + 1; j <= n; ++j) {
      for(reg int k = j + 1; k <= n; ++k) {
        if(a[i] != a[j] && a[j] != a[k] && a[i] != a[k]) {
          if(a[i] + a[j] > a[k] && a[i] + a[k] > a[j] && a[j] + a[k] > a[i]) ++ans;
        }
      }
    }
  }
  printf("%d\n", ans);
}
signed main() {
  int _ = 1;
  // scanf("%d", &_);
  while(_--) {
    work();
  }
  return 0;
}

#include<iostream>
#include<algorithm>
#include<map>
#include<vector>
#include<cstdint>
#include<cstdlib>
template<typename T>
void fin(T const& t){ std::cout << t << std::endl; exit(0); }

int64_t const INF = 1e18;

int main() {
  std::cin.tie(0); std::ios::sync_with_stdio(false);
  int N; std::cin >> N;
  std::vector<int64_t> A(N), S(N+1, 0);
  for(int i = 0; i < N; ++i) std::cin >> A[i];
  for(int i = 0; i < N; ++i) S[i+1] = S[i] + A[i];
  auto split = [&](auto b, auto e)-> std::pair<int64_t,int64_t> {
    int64_t V = (*e + *b)/2;
    auto m = std::upper_bound(b, e, V);
    int64_t mi = INF;
    std::pair<int64_t, int64_t> res;
    for(auto i: {m-1, m, m+1}) if(b < i && i < e) {
      int64_t cur = std::abs((*i-*b) - (*e-*i));
      if(cur < mi) { mi = cur; res = std::make_pair(*i-*b, *e-*i); }
    }
    return res;
  };
  auto isOK = [&](int64_t k)->bool {
    int64_t vmi = (S[N]+1)/2 - k, vma = S[N]/2 + k;
    auto lb = std::lower_bound(S.begin()+2, S.end()-3, vmi);
    auto ub = std::upper_bound(S.begin()+2, S.end()-2, vma);
    for(auto it = lb; it != ub; ++it) {
      auto L = split(S.begin(), it);
      auto R = split(it, S.end()-1);
      int64_t P[4] = {L.first, L.second, R.first, R.second};
      if(*std::max_element(P, P+4) - *std::min_element(P, P+4) <= k) return true;
    }
    return false;
  };

  int64_t ng = -1;
  // rough try
  auto split2 = [&](auto b, auto e) {
    int64_t V = (*e + *b)/2;
    auto m = std::upper_bound(b, e, V);
    int64_t mi = INF;
    auto res = e+1;
    for(auto i: {m-1, m, m+1}) if(b < i && i < e) {
      int64_t cur = std::abs((*i-*b) - (*e-*i));
      if(cur < mi) { mi = cur; res = i; }
    }
    return res;
  };
  auto M = split2(S.begin(), S.end()-1);
  while((M-S.begin()) < 2) ++M;
  while((M-S.begin()) > S.size()-3) --M;
  auto L = split(S.begin(), M);
  auto R = split(M, S.end()-1);
  int64_t P[4] = {L.first, L.second, R.first, R.second};
  int64_t ok = *std::max_element(P, P+4) - *std::min_element(P, P+4);
  while(ok - ng > 1) {
    int64_t mid = (ok+ng)/2;
    if(isOK(mid)) ok = mid; else ng = mid;
  }
  fin(ok);
  return 0;
}


#include <iostream>
#include <vector>
#define INF (int)1e9

int bellman_ford(int m, int p, int q, std::vector<std::vector<std::pair<int, int> > > v) {
    std::vector<int> rvec(m, INF);
    bool flag;
    rvec[p] = 0;
    int value;
    int target;

    do{
        flag = false;
        for (int i = 0; i < m; i++) {
            for (int j = 0; j < v[i].size(); j++) {
                value = v[i][j].first;
                target = v[i][j].second;
                if (rvec[target] > rvec[i] + value) {
                    rvec[target] = rvec[i] + value;
                    flag = true;
                }
            }
        }
    } while(flag);

    return rvec[q];
}

int main(void) {
    int n;
    int m;

    int a;
    int b;
    int cost;
    int time;

    int k;

    int p;
    int q;
    int r;

    int res;

    while (true) {
        std::cin >> n >> m;
        if (n == 0 && m == 0) {
            break;
        }

        std::vector<std::vector<std::pair<int, int> > > vcost(m);
        std::vector<std::vector<std::pair<int, int> > > vtime(m);

        for (int i = 0; i < n; i++) {
            std::cin >> a >> b >> cost >> time;
            --a;
            --b;
            vcost[a].push_back(std::make_pair(cost, b));
            vcost[b].push_back(std::make_pair(cost, a));
            vtime[a].push_back(std::make_pair(time, b));
            vtime[b].push_back(std::make_pair(time, a));
        }

        std::cin >> k;

        for (int i = 0; i < k; i++) {
            std::cin >> p >> q >> r;
            --p;
            --q;

            // ????????????????????????
            if (r == 0) {
                res = bellman_ford(m, p, q, vcost);
            } else {
                res = bellman_ford(m, p, q, vtime);
            }
            std::cout << res << std::endl;
        }
    }
    return 0;
}

#include<cstdio>
#include<algorithm>
#include<queue>
#include<string>
#include<cstring>
#include<cstdlib>
#include<sstream>
#include<set>
using namespace std;
class P{
    public:
    int num;
    int cnt;
    bool used[10];
    P(){}
    P(int num,int cnt,bool a[10]):num(num),cnt(cnt){
        for(int i = 0; i < 10; i++){
            used[i] = a[i];
        }
    }
};
int bond(int x,int y){
    stringstream ss1;
    ss1 << x;
    stringstream ss2;
    ss2 << y;
    string ans = ss1.str() + ss2.str();
    stringstream Ans;
    Ans << ans;
    int res;
    Ans >> res;
    return res;
}
int main(){
    int n;
    int m;
    while(scanf("%d%d",&n,&m),(n|m)){
        int card[10];
        set<int> S;
        queue<P> Q;
        for(short i = 0; i < n; i++){
            bool x[10]={0};
            x[i] = 1;
            scanf("%d",&card[i]);
            Q.push(P(card[i],1,x));
        }
        short ans = 0;
        while( Q.size() ){
            P p = Q.front();Q.pop();
            if(p.cnt == m){
                if(S.find(p.num) == S.end())ans++,S.insert(p.num);
            }
            else{
                for(int i = 0; i < n; i++){
                    if(p.used[i] == 0){
                        p.used[i] = 1;
                        Q.push(P(bond(p.num,card[i]),p.cnt+1,p.used));
                        p.used[i] = 0;
                    }
                }
            }
        }
        printf("%d\n",ans);
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main(void) {
	int e;
	while(1) {
		cin >> e;
		if(e == 0) {
			break;
		}

		int tmpx, tmpy, tmpz, tmpe;
		tmpe = e;
		for(tmpz = 0; pow(tmpz, 3) <= tmpe; tmpz++){}
		tmpz--;
		tmpe = tmpe - pow(tmpz, 3);
		if(tmpe == 0){
			tmpy = 0; tmpx = 0;
		}else{
			for(tmpy = 0; pow(tmpy, 2) <= tmpe; tmpy++){}
			tmpy--;
			tmpe = tmpe - pow(tmpy, 2);
			if(tmpe == 0){
				tmpx = 0;
			}else{
				tmpx = tmpe;
			}
		}
		int tmpm = tmpx + tmpy + tmpz;
		//cout << tmpz << " ! " << endl;

		int tmp;
		for(int z = 0; z <= tmpz + 1; z++) {
			for(int y = tmpy; y <= min(tmpm - z, int(pow(e - pow(z, 3), 1.0 / 2.0))); y++) {
				int x = e - pow(y, 2) - pow(z, 3);
				tmp = x + y + z;
				if(tmp < tmpm) {
					tmpm = tmp;
				}
			}
		}

		cout << tmpm << endl;
	}
	return 0;
}

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

using namespace std;

string str="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";

char encode(char a,int k){
	int b;
	if(isupper(a))b=a-'A';
	else b=a-'a'+26;
	if(b-k>=0)return str[b-k];
	return str[52-abs(b-k)];
}

int main(void){

	int n;
	while(cin >> n,n){
		vector<int>k(n);
		for(int i=0;i<n;i++){
			cin >> k[i];
		}
		string s;
		cin >> s;
		for(int i=0;i<s.size();i++)s[i]=encode(s[i],k[i%n]);
		cout << s << endl;
	}

	return 0;
}


#include<bits/stdc++.h>

using namespace std;

#define LL long long
#define DD double
#define Pb push_back
#define Bp pop_back
#define Pf push_front
#define Fp pop_front
#define Ub upper_bound
#define Lb lower_bound
#define In insert
#define All(x) x.begin(), x.end()
#define mem(a, b) memset(a, b, sizeof(a))
#define fast ios_base::sync_with_stdio(0);cin.tie(0)
#define X first
#define Y second
#define mx1 10
#define mx2 110
#define mx3 1010
#define mx4 10010
#define mx5 100010
#define mx6 1000010

typedef vector<LL> Vl;
typedef vector<DD> Vd;
typedef vector<bool> Vb;
typedef vector<Vl> VVl;
typedef pair<LL, LL> Pll;
typedef pair<DD, DD> Pdd;
typedef vector<Pll> Vpl;
typedef vector<Pdd> Vpd;
typedef queue<LL> Ql;
typedef stack<LL> Sl;
typedef deque<LL> Dl;

LL _set(LL N, LL pos) {return N = N | (1 << pos);}
LL _reset(LL N, LL pos) {return N = N & ~(1 << pos);}
bool _check(LL N, LL pos) {return (bool)(N & (1 << pos));}
bool _upper(char a) {return a >= 'A' && a <= 'Z';}
bool _lower(char a) {return a >= 'a' && a <= 'z';}
bool _digit(char a) {return a >= '0' && a <= '9';}

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

///**************************DONE****************************///

int x[] = {111, 222, 333, 444, 555, 666, 777, 888, 999};

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

    for(int i = 0; i < 9; i++){
        if(x[i] >= n)
            return cout << x[i] << '\n', 0;
    }
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main()
{
  string s;
  cin >> s;

  bool flag = true;
  int n = s.size();
  int ok = 0;
  if(s[0] != 'A'){
    cout << "WA" << endl;
    return 0;
  }

  for(int i = 2; i <= n-2; i++){
    if(s[i] == 'C'){
      ok++;
    }
  }
  if(ok != 1){
    cout << "WA" << endl;
    return 0;
  }

  for(int i = 0; i < n; i++){
    if(s[i] != 'A' && s[i] != 'C' && isupper(s[i])){
      cout << "WA" << endl;
      return 0;
    }
  }

  cout << "AC" << endl;
}


#include<bits/stdc++.h>
#include<iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <queue>
#include <deque>
#include <map>
#include <stack>
#include<bitset>
#include<list>
#include<cassert>
#include<numeric>

using namespace std;

const long long N = 1000 * 100 + 5;
long long c[N], n, cnt = 0, is, bi, nbi;
vector < long long > graph[N];
bool mark[N], b;
void dfs(long long v)
{
	mark[v] = 1;
	for (auto u : graph[v])
	{
		if (c[u] == c[v])
		{
			b = 0;
		}
		if (!mark[u])
		{
			c[u] = 1 - c[v];
			dfs(u);
		}
	}
	return;
}
void dfs2()
{
	memset(c , -1 , sizeof c);
	for(long long i = 0; i < n; i++)
	{
		if(!mark[i])
		{
			cnt++;
			b = 1;
			c[i] = 1;
			if(graph[i].size())
			{
				dfs(i);
				if(b)
				{
					bi++;
				}
				else
				{
					nbi++;
				}
			}
			else
			{
				is++;
			}
		}
	}
	return;
}
int main()
{
	long long m;
	cin >> n >> m;
	for (long long i = 0; i < m; i++)
	{
		long long u, v;
		cin >> u >> v;
		graph[u - 1].push_back(v - 1);
		graph[v - 1].push_back(u - 1);
	}
	dfs2();
	cout << (bi + nbi) * (bi + nbi) + bi * bi + 2 * n * is - is * is << endl;
}

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

typedef long long s64;
s64 C2(int n)
{
	return (s64)n*(n-1)/2;
}
#define rep(i,l,r) for(int i=l;i<=r;++i)
const int N=1e5+5;
int fa[N],sz[N];bool d[N],have[N];
int find(int x)
{
	if(fa[x]==x)return x;
	find(fa[x]);
	d[x]^=d[fa[x]];
	return fa[x]=fa[fa[x]];
}

int main()
{
	//freopen("1.in","r",stdin);
	int n,m;
	cin>>n>>m;
	rep(i,1,n){fa[i]=i;sz[i]=1;}
	while(m--)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		int fx=find(x),fy=find(y);
		if(fx==fy)
		{
			have[fx]|=d[x]==d[y];
			continue;
		}
		fa[fy]=fx;d[fy]=d[x]^1^d[y];
		sz[fx]+=sz[fy];
		have[fx]|=have[fy];
	}
	int cnt1=0,cnt[2]={};
	rep(x,1,n)
	if(fa[x]==x)
	if(sz[x]==1)++cnt1;
	else ++cnt[have[x]];
	cout<<(s64)cnt[1]*cnt[0]*2+(s64)cnt1*(n-cnt1)*2
		+(s64)cnt[1]*cnt[1]+(s64)cnt[0]*cnt[0]*2+(s64)cnt1*cnt1;
}


#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <vector>
#include <assert.h>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <math.h>
#include <string>
#include <string.h>
#include <queue>
#include <complex>
#include <iomanip>
#include <stack>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
ll mod=1e9+7;
double eps=1e-7;
ll exp(ll x,ll y){if(y<0) return 0; ll ret=1;for(;y;y>>=1,x=(x*x)%mod){if(y&1)ret=(ret*x)%mod;}return ret;}
ull pexp(ull x,ull y){if(y<0) return 0; ull ret=1; for(;y;y>>=1,x=(x*x)){if(y&1)ret=(ret*x);}return ret;}
ll gcd(ll x,ll y){if(!x||!y) return x+y; return x%y==0?y:gcd(y,x%y);}
ll lcm(ll x,ll y){return x*(y/gcd(x,y));}
ll bsum(ll u,ll b){ll ret=0;if(u<b)return u;while(u){ret+=u%b;u/=b;}return ret;}
ll prival(ll u,ll p){ll cn=0;while(u%p==0){cn++;u=u/p;}return cn;}
ll minv(ll a,ll b){return 1<a?b-minv(b%a,a)*b/a:1;}
ll extm(ll a,ll b){ll ret=0;while(a!=0){if(a%2==1){ret+=b;ret%=mod;}a>>=1;b=(2*b)%mod;}return ret;}
ll eaphi(ll x){ll t=x,ret=x,i;for(i=2;i*i<=x;i++){if(t%i==0){ret-=ret/i;while(t%i==0) t/=i;}}if(t!=1) ret-=ret/t;return ret;}
ll eadivc(ll x){ll ret=0;ll i;for(i=1;i*i<=x;i++){if(x%i==0 && i*i!=x) ret+=2;if(x%i==0 && i*i==x) ret+=1;}return ret;}
ll eadivs(ll x){ll ret=0;ll i;for(i=1;i*i<=x;i++){if(x%i==0 && i*i!=x) ret+=i+x/i;if(x%i==0 && i*i==x) ret+=i;}return ret;}
ll ndig(ll x, ll b){ll ret=0;while(x){x/=b; ret++;}return ret;}
ll rev(ll n, ll b){ll ret=0;while(n){ret=b*ret+n%b; n/=b;}return ret;}
ll sq(ll x){ll t=(ll)sqrt(x); for(ll i=t-2 ; i<=t+2 ; i++) if(i*i==x) return abs(i); return -1;}
ll extexp(ll x,ll y){if(y<0) return 0; ll ret=1;for(;y;y>>=1,x=extm(x,x)){if(y&1)ret=extm(ret,x);}return ret;}
bool isprime(ll x){if(x<=1) return false; for(ll i=2;i*i<=x;i++){if(x%i==0){return false;}}return true;}
pair<ll, int> x[111111];
pair<ll, int> y[111111];
vector< pair< ll, pair<int, int> > > edge;
int par[111111]; ll ans, n;

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

void unite(int u, int v)
{
	if(find(u)==find(v)) return;
	par[find(u)]=v;
}

int main(void)
{
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin>>n; int i, j;
	for(i=1 ; i<=n ; i++) par[i]=i;
	for(i=1 ; i<=n ; i++) cin>>x[i].first>>y[i].first;
	for(i=1 ; i<=n ; i++) x[i].second=y[i].second=i;
	sort(x+1,x+n+1); sort(y+1,y+n+1);
	for(i=1 ; i<=n-1 ; i++) edge.push_back(make_pair(x[i+1].first-x[i].first,make_pair(x[i].second,x[i+1].second)));
	for(i=1 ; i<=n-1 ; i++) edge.push_back(make_pair(y[i+1].first-y[i].first,make_pair(y[i].second,y[i+1].second)));
	sort(edge.begin(),edge.end());
	for(i=0 ; i<edge.size() ; i++)
	{
		int u=edge[i].second.first;
		int v=edge[i].second.second;
		if(find(u)==find(v)) continue;
		unite(u,v); ans+=edge[i].first;
	}
	cout<<ans; return 0;
}

// 제출하기 전에 생각햇나요?
// it may be easier/harder than you think
// ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);

#include <bits/stdc++.h>

using ll = long long;
using Pii = std::pair<int, int>;
using Pll = std::pair<ll, ll>;

const ll INF = (ll)1e11;
const ll MOD = 998244353;

using namespace std;

int main() {
    ios::sync_with_stdio(false);

    int N;
    cin >> N;

    vector<int> A;
    ll S = 0;
    for (int i = 0, a; i < N; ++i) {
        cin >> a;
        A.push_back(a);
        S += a;
    }

    ll cnt = 1;
    for (int i = 0; i < N; ++i) {
        cnt *= 3;   // all ways to paint stones
        cnt %= MOD;
    }

    // subtract the numbers of ways to paint such that R,G,B cannot construct a triangle from all.

    {   // reduce the number of ways to paint such that R >= G + B, G >= B + R, B >= R + G
        vector<ll> dp(S + 10, 0);
        dp[0] = 1;  // assume that R = max(R,G,B) here
        for (auto a : A) {
            for (ll s = S; s > a - 1; --s) {
                dp[s] += 2 * dp[s-a];   // select a_i in G or B
                dp[s] %= MOD;
            }
        }

        for (ll s = 0; s < S / 2 + 1; ++s) {
            cerr << "----" << endl;
            cnt -= 3 * dp[s];   // subtract sum of R, G, B = max(R,G,B)
            while (cnt < 0) cnt += 3 * MOD;
            cnt %= MOD;

            cerr << cnt << endl;
        }
    }

    cerr << cnt << endl;

    if (S % 2 == 0) {   // add the number of ways to paint such that R == G && B == 0, G == B && R == 0, B == R && G == 0
        vector<ll> dp(S + 10, 0);
        dp[0] = 1;  // assume that R == G && B == 0 here
        for (auto&& a : A) {
            for (ll s = S; s > a - 1; --s) {
                dp[s] = (dp[s] + dp[s-a]) % MOD;   // select a_i in R (G)
                dp[s] %= MOD;
            }
        }

        cnt += 3ll * dp[S/2];   // add sum of R,G,B == 0
        cnt %= MOD;
    }

    cout << cnt << endl;

    return 0;
}


#include<iostream>

using namespace std;

int func(int x);

int main() {
	int x;
	while (true) {
		cin >> x;
		if (x == 0) { break; }
		cout << func(x) / 3650 + 1 << endl;
	}

	return 0;
}

int func(int x) {
	if (x == 1) {
		return 1;
	}
	else if (x == 2) {
		return 2;
	}
	else if (x == 3) {
		return 4;
	}
	else {
		return func(x - 1) + func(x - 2) + func(x - 3);
	}
}

#include <iostream>
#include <stdio.h>
#include <string>
#include <vector>
#include <queue>
#include <stdlib.h>

using namespace std;

int main(void){

	int n;
	cin >> n;

	for( int i = 0; i < n; i++ ) {
		int outs = 0, runner = 0, pts = 0;
		while( outs < 3 ) {
			string evt;
			cin >> evt;
			if( evt == "HIT" ) {
				if( runner < 3 ) {
					runner ++;
				} else {
					pts ++;
				}
			} else if( evt == "OUT" ) {
				outs ++;
			} else {
				pts += runner + 1;
				runner = 0;
			}
		}
		cout << pts << endl;
	}

	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define ll long long int
#define ull unsigned long long
#define si set <ll>
#define vi vector <ll>
#define popcount(x) __builtin_popcountll(x)
#define mii map <ll,ll>
#define vpi vector <pair <ll,ll> >
#define sz(c) (ll)c.size()
#define fr first
#define fastio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define sc second
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define mem0(a) memset(a,0,sizeof(a))
#define rep(i,a,n) for(ll i=a ; i<n ; i++)
#define ld long double
const ll INF = __LONG_LONG_MAX__;
#define rall(a) (a).rbegin(),(a).rend()
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")

ll power(ll b,ll e,ll m)
{
  if(b==0) return 0;
  if(e==0) return 1;
  if(e&1) return b*power(b*b%m,e/2,m)%m;
  return power(b*b%m,e/2,m);
}
ll power( ll b, ll e)
{
  if(b==0) return 0;
  if(e==0) return 1;
  if(e&1) return b*power(b*b,e/2);
  return power(b*b,e/2);
}
bool isPowerOfTwo(ll x)
{
    // x will check if x == 0 and !(x & (x - 1)) will check if x is a power of 2 or not
    return (x && !(x & (x - 1)));
}

ll ans(ll a[],ll n)
{
  ll sum=0;
  for(ll i=0;i<64;i++)
  {
    ll zero=0,one=0;
    for(ll j=0;j<n;j++)
    {
      if(a[j]&1) zero++;
      else one++;
      a[j]/=2;
    }
    ll x=(zero%MOD*one%MOD*power(2,i,MOD))%MOD;
    sum=(sum%MOD+x%MOD)%MOD;
  }
  return sum;
}

void solve()
{
   ll n;
   cin>>n;
   ll a[n];
   rep(i,0,n) cin>>a[i];
   cout<<ans(a,n);
}

int main()
{
  fastio
  ll tt=1;
  // cin>>tt;
  while(tt--)
  {
      solve();
      cout<<"\n";
  }
}


#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <array>
#include <queue>
#include <stack>
#include <algorithm>
#include <tuple>
#include <numeric>
#include <type_traits>

#define MOD 998244353

int main()
{
	long dp0[300*300+1]={}, dp1[300*300+1]={};
	long sub0[300*300+1]={}, sub1[300*300+1]={};

	long N;
	std::vector<int> A;
	std::cin >> N;
	A.resize(N);
	for (auto& a : A) {
		std::cin >> a;
	}
	long sum = 0;
	for (auto a : A) {
		sum += a;
	}

	dp0[0] = 1;
	sub0[0] = 1;

	long* prevdp = dp0;
	long* dp = dp1;
	long* prevsub = sub0;
	long* sub = sub1;

	for (auto a : A) {
		for (int i = 0; i < a; ++i) {
			dp[i] = prevdp[i]*2 % MOD;
			sub[i] = prevsub[i];
		}
		for (int i = a; i <= 300*300; ++i) {
			dp[i] = (prevdp[i-a] + prevdp[i]*2) % MOD;
			sub[i] = (prevsub[i-a] + prevsub[i]) % MOD;
		}
		std::swap(dp, prevdp);
		std::swap(sub, prevsub);
	}

	long ret = 1;
	for (long i = 0; i < N ; ++i)
		ret = (ret * 3) % MOD;

	for (long i = (sum+1)/2; i <= 300*300; ++i) {
		ret = (ret + (MOD - prevdp[i])*3) % MOD;
	}
	if (sum%2 == 0) {
		ret = (ret + prevsub[sum/2]*3) % MOD;
	}
	std::cout << ret << "\n";
}

#include <iostream>

using namespace std;

typedef long long ll;

const ll mod = 998244353;

int n;
int a[305];
ll dp[305][90005];
ll dp2[305][90005];

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

int main() {
  cin >> n;
  int sum = 0;
  int maxa = 0;
  for(int i = 0; i < n; i++) {
    cin >> a[i];
    sum += a[i];
    maxa = max(maxa,a[i]);
  }

  dp[0][0] = 1;

  for(int i = 0; i < n; i++) {
    for(int j = 0; j <= i * maxa; j++) {
      if(dp[i][j] == 0) continue;
      dp[i+1][j] = (dp[i+1][j] + dp[i][j] * 2) % mod;
      dp[i+1][j+a[i]] = (dp[i+1][j+a[i]] + dp[i][j]) % mod;

    }
  }
  dp2[0][0] = 1;
  for(int i = 0; i < n; i++) {
    for(int j = 0; j <= i * maxa; j++) {
       if(dp2[i][j] == 0) continue;
      dp2[i+1][j] = (dp2[i+1][j] + dp2[i][j]) % mod;
      dp2[i+1][j+a[i]] = (dp2[i+1][j+a[i]] + dp2[i][j]) % mod;
    }
  }

  ll ans = p(3,n);
  for(int i = 0; i <= n * maxa; i++) {
    if(i >= sum - i) {
      ans = (ans + mod - dp[n][i] * 3 % mod) % mod;
    }
    if(i == sum - i) {
      ans = (ans + dp2[n][i] * 3 % mod) % mod;
    }
  }
  if(ans < 0 ) cout << ans + mod << endl;
  else
  cout << ans << endl;
}


#include <bits/stdc++.h>
#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 sp(n) cout << fixed << setprecision(n)
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; }
typedef long long ll;
using namespace std;
int main(void){
    int n;cin>>n;
    vector<ll> a(n);
    rep(i,n) cin>>a[i];
    if(a[0]!=0){
        cout<<-1<<endl;
        return 0;
    }
    ll res=0;
    reverse(a.begin(),a.end());
    ll maxi=0;
    rep(i,n){
        if(a[i]<maxi){
            cout<<-1<<endl;
            return 0;
        }
        if(chmax(maxi,a[i]))res+=a[i];
        maxi--;
    }
    cout<<res<<endl;
}

#include<iostream>
#include<cstdio>
using namespace std;
#define N 200012
int n,a[N],las=0;bool vis[N];long long ans=0;
int main(){
	scanf("%d",&n);int i,l,r,lef;bool fl=true;
	for(i=1;i<=n;i++)scanf("%d",&a[i]);
	for(i=1;i<=n;i=r+1)
	{
		l=r=i;while((r<n)&&(a[r+1]==(a[r]+1)))++r;
		lef=l-a[l];if(lef<=las){printf("-1");fl=false;break;}
		ans+=r-lef;las=lef;
	}if(fl)printf("%lld",ans);return 0;
}


#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define _USE_MATH_DEFINES
#include <math.h>
#define rep(i,n) for(int i = 0;i < n;i++)
#define NIL = -1;
#define all(x) x.begin(),x.end()
const ll INF = 1e9;
const ll mod = 1e9 + 7;

int digit(ll x) {
    if (x / 10 == 0) return 1;
    return digit(x / 10) + 1;
}

ll gcd(long long a,long long b) {
    if (a < b) swap(a,b);
    if (b == 0) return a;

    return gcd(b,a%b);
}

bool is_prime(long long N){
    if (N == 1) return false;
    for (long long i = 2;i * i <= N;i++){
        if (N % i == 0) return false;
    }
    return true;
}

ll lcm(ll a,ll b){
    return ((a * b == 0)) ? 0 : (a / gcd(a,b) * b);
}

double DegreeToRadian(double degree){
    return degree * M_PI / 180.0;
}

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

///////////////////////////////////////////////////////////////////////////////////
char s[4010];
int main(){
    int n;
    cin >> n;
    long long r = 0, g = 0, b = 0;
    for (int i = 1;i <= n;i++){
        cin >> s[i];
        if (s[i] == 'R') r++;
        else if (s[i] == 'G') g++;
        else b++;
    }

    ll ans = r*g*b;

    for (int i = 1;i <= n;i++){
        for (int j = i + 1;j <= n;j++){
            if (s[i] != s[j]){
                int k = j + j - i;
                if (k > n) continue;
                if (s[i] != s[k] && s[j] != s[k]){
                    ans--;
                }
            }
        }
    }

    cout << ans << endl;
    return 0;
}

#include <iostream>
#include <string>
#include <set>

using namespace std;

void input(int& N, set<int>& R_INDEX, set<int>& G_INDEX, set<int>& B_INDEX)
{
  char c;
  for (int i= 0; i < N; i++){
    cin >> c;
    switch(c){
    case 'R':
      R_INDEX.insert(i);
      break;
    case 'G':
      G_INDEX.insert(i);
      break;
    case 'B':
      B_INDEX.insert(i);
      break;
    }
  }
}

long long int findsetnum(set<int>& R_INDEX, set<int>& G_INDEX, set<int>& B_INDEX)
{
  long long int sum = 0;
  int a, b, c;
  set<int>::iterator R_iter, G_iter;
  for (R_iter = R_INDEX.begin(); R_iter != R_INDEX.end(); R_iter++)
    for (G_iter = G_INDEX.begin(); G_iter != G_INDEX.end(); G_iter++){
      a = (B_INDEX.find(2 * (*G_iter) - *R_iter) == B_INDEX.end())? 0 : 1;
      b = (B_INDEX.find(2 * (*R_iter) - *G_iter) == B_INDEX.end())? 0 : 1;
      c = (B_INDEX.find((*G_iter + *R_iter) / 2) == B_INDEX.end() || (*G_iter + *R_iter) % 2 != 0)? 0 : 1;
      sum += (B_INDEX.size() - a - b - c);
    }
  return sum;
}

int main(void)
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N;
  cin >> N;
  set<int> R_INDEX, G_INDEX, B_INDEX;
  input(N, R_INDEX, G_INDEX, B_INDEX);
  cout << findsetnum(R_INDEX, G_INDEX, B_INDEX) << '\n';
  return 0;
}


#include <bits/stdc++.h>

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
#define ALL(a) (a).begin(),(a).end()

using namespace std;
using ll = long long;

const double PI = 3.14159265358979;

void solve()
{
  int n, k;
  cin >> n >> k;
  vector<int> a(n + 1, 0);
  for(int i = 0; i < n; ++i)
  {
    cin >> a[i];
  }

  for(int i = 0; i < k; ++i)
  {
    vector<int> next_a(n + 1, 0);
    for(int j = 0; j < n; ++j)
    {
      next_a[ max(0, j - a[j]) ]++;
      next_a[ min(n, j + a[j] + 1) ]--;
    }
    int max_cd_num = 0;
    for(int j = 0; j < n; ++j)
    {
      next_a[j + 1] += next_a[j];
      max_cd_num += (next_a[j] == n);
    }
    a = next_a;
    if (max_cd_num >= n) break;
  }

  for(int i = 0; i < n; ++i) cout << a[i] << " ";

}

int main()
{
  fastio;
  solve();

  return 0;
}

#include<bits/stdc++.h>
#define maxn 105
using namespace std;
int xe,ye;
short n,m,ans,a[maxn][maxn],p=0,np=1,dp[2][maxn][maxn][maxn];
char c[maxn][maxn];
void inline upd(short& x,short y){
	if(x<y){x=y;if(y>ans)ans=y;}
}
int inline z(int i,int j,int k,int l){
	return a[k][l]-a[i-1][l]-a[k][j-1]+a[i-1][j-1];
}
int inline cal1(int w,int h,int x,int l,int r){
	int ret=0,_w=n-w,_h=m-h;
	if(ye>1+_h)return 0;
	else return z(max(l,xe-_w+l-1),x,min(r,xe+l-1),x);
}
int inline cal2(int w,int h,int y,int l,int r){
	int ret=0,_w=n-w,_h=m-h;
	if(xe>1+_w)return 0;
	else return z(y,max(l,ye+l-_h-1),y,min(r,ye+l-1));
}
int inline cal3(int w,int h,int x,int l,int r){
	int ret=0,_w=n-w,_h=m-h;
	if(ye<h)return 0;
	else return z(max(l,xe-_w+l-1),x,min(r,xe+l-1),x);
}
int inline cal4(int w,int h,int y,int l,int r){
	int ret=0,_w=n-w,_h=m-h;
	if(xe<w)return 0;
	else return z(y,max(l,ye-_h+l-1),y,min(r,ye+l-1));
}
int main(){
//	freopen("in.txt","r",stdin);
	cin>>n>>m;
	for(int i=1;i<=n;++i)
		scanf("%s",c[i]+1);
	for(int i=1;i<=n;++i)
		for(int j=1;j<=m;++j){
			a[i][j]=(c[i][j]=='o')+a[i-1][j]+a[i][j-1]-a[i-1][j-1];
			if(c[i][j]=='E')xe=i,ye=j;
		}
	dp[np][1][1][m]=ans=1;
	for(int k=n;k>=1;--k,swap(p,np))for(int l=m;l>=1;--l)
		for(int i=1;i<=n-k+1;++i)for(int j=1;j<=m-l+1;++j)if(dp[np][i][j][l]){
			int x=dp[np][i][j][l];
//			printf("{%d,%d,%d,%d,%d}\n",i,j,k,l,x);
			upd(dp[np][i][j+1][l-1],x+cal1(k,l,j,i,i+k-1));
			upd(dp[p][i+1][j][l],x+cal2(k,l,i,j,j+l-1));
			upd(dp[np][i][j][l-1],x+cal3(k,l,j+l-1,i,i+k-1));
			upd(dp[p][i][j][l],x+cal4(k,l,i+k-1,j,j+l-1));
			dp[np][i][j][l]=0;
		}
	printf("%d",ans-1);
}


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

int  main()
{
	int n; cin >> n;
	int a,b;
	switch (n)
	{
		case 1:
			cout << "Hello World\n";
			break;
		case 2:
			cin >> a >> b; cout << a+b << endl;
			break;
	}
	return (0);
}

#include <bits/stdc++.h>
#define rep(i,n) for (int (i) = 0; (i) < (n); i++)
#define ll long long
using namespace std;
int main() {
  ll N = 0, A,B;;
  cin >> N >> A >> B;
  if(N == 1){
    cout << "Hello World";
  }
  else{
    cout << A + B;
  }
}


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

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

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = mod * mod;
const int INF_N = 1e+9;
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);
//typedef vector<vector<ll>> mat;
typedef vector<int> vec;

//繰り返し二乗法
ll mod_pow(ll a, ll n, ll m) {
	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;
}

//逆元(Eucledean algorithm)
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 = 1 << 18;
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];
}
using mP = pair<modint, modint>;

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

// 素因数が何乗かをmapで返却する
map< ll, int > prime_factor(ll n) {
  map< ll, int > ret;
  for(ll i = 2; i * i <= n; i++) {
    while(n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if(n != 1) ret[n] = 1;
  return ret;
}

void solve() {
    ll N, M; cin >> N >> M;
    auto pf = prime_factor(M);

    ll res = 1;
    for(auto a: pf){
        res = modint(modint(res) * comb(a.second + N - 1, a.second));
    }

    cout << res << endl;
}

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

#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"

using namespace std;

typedef long long ll;
typedef double db;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef pair<ll,ll> PLL;

#define REP(x,l,u) for(ll x = l; x < u; x++)
#define RREP(x,l,u) for(ll x = l; x >= u; x--)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define mst(x,v) memset(x, v, sizeof(x))
#define sz(x) (ll)x.size()

string to_string(string s) {return s;}
string to_string(char c) {string s = string(1, c);return s;}
template <typename A, typename B> string to_string(pair<A,B> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; }
template <typename A> string to_string(vector<A> v) { string s = "("; int first = 1; for (A a : v) { if (!first) { s += ", "; } first = 0; s += to_string(a); } s += ")"; return s; }
template <typename A> string to_string(set<A> v) { string s = "("; int first = 1; for (A a : v) { if (!first) { s += ", "; } first = 0; s += to_string(a); } s += ")"; return s; }

void debug_out() {cerr << endl;}
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << to_string(H); debug_out(T...); }

void in() {}
template <typename A> void in(A & x) { cin >> x; }
template <typename A, typename B> void in(pair<A,B> & x) { in(x.first); in(x.second); }
template <typename A> void in(vector<A> & x) { REP(i,0,(ll)x.size()) in(x[i]); }
template <typename Head, typename... Tail> void in(Head & H, Tail & ... T) {in(H); in(T...); }

#ifndef ONLINE_JUDGE
#define debug(...) do { cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__); } while (false)
#else
#define debug(...) do { } while (false)
#endif

const ll inf = (ll)1e18 + 5;
const ll mod = 1e9+7;

const ll nax = 100500;
ll F[nax], INVF[nax];

ll pow(ll a, ll b) {
	if (b == 0) return 1;
	ll h = pow(a, b/2);
	ll ans = b % 2 ? h * h % mod * a : h * h;
	ans %= mod;
	return ans;
}

ll ncr(ll n, ll r) {
	// n! / r! / (n-r)!
	ll ans = F[n];
	ans *= INVF[r];
	ans %= mod;
	ans *= INVF[n-r];
	ans %= mod;
	return ans;
}

void solve() {
	ll n, m;
	in(n, m);

	F[0] = 1;
	REP(i,1,nax) F[i] = (F[i-1] * i) % mod;
	REP(i,0,nax) INVF[i] = pow(F[i], mod-2);

	map<ll,ll> factors;
	ll f = 2;
	while (m != 1 && f*f <= m) {
		while (m % f == 0) {
			factors[f]++;
			m /= f;
		}
		f++;
	}
	if (m != 1) factors[m]++;

	ll ans = 1;
	for (PLL a : factors) {
		ans *= ncr(a.second + n - 1, a.second) % mod;
		ans %= mod;
	}
	cout << ans << endl;
}

signed main() {
	ll t = 1;
	REP(i,0,t) solve();
	return 0;
}


#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(a); (i)<(b); ++(i))
#define rFor(i, a, b) for(int (i)=(a)-1; (i)>=(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef complex<double> xy_t;
typedef vector<lint> poly;
template<class T>bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T>bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;}

const lint mod = 1e9+7;
const lint INF = mod*mod;
const int MAX = 1<<20;

lint powmod(lint x, lint n){
    lint ret = 1;
    while(n > 0){
        if(n&1) ret *= x, ret %= mod, n -= 1;
        else x *= x, x %= mod, n >>= 1;
    }
    return ret;
}

lint dp[MAX], zero[MAX], cnt[MAX], now;

int main(){
    int n;
    scanf("%d", &n);
    int a[n], s[n+1];
    s[0]=0;
    rep(i, n){
        scanf("%d", &a[i]);
        s[i+1]=s[i]^a[i];
    }
    rep(i, MAX){
        zero[i]=cnt[i]=0;
        dp[i]=1;
    }
    now=0;
    rep(i, n+1){
        if(s[i]==0) ++now;
        else{
            (dp[s[i]]+=zero[s[i]]*(now-cnt[s[i]])%mod)%=mod;
            (zero[s[i]]+=dp[s[i]])%=mod;
            cnt[s[i]]=now;
        }
    }
    if(s[n]!=0){
        printf("%lld\n", dp[s[n]]);
        return 0;
    }
    lint ans=0;
    rep(i, MAX)if(cnt[i]) (ans+=zero[i])%=mod;
    (ans+=powmod(2, now-2))%=mod;
    printf("%lld\n", ans);
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int maxn=2e5+5;
const int mod=1e9+7;
ll fac[maxn]={1},ifac[maxn];
inline ll fastpow(ll a,ll b) {
	ll ans=1;
	for(;b;b>>=1,a=a*a%mod) if(b&1) ans=ans*a%mod;
	return ans;
}
inline void  init() {
	for(int i=1;i<maxn;i++) fac[i]=fac[i-1]*i%mod;
	ifac[maxn-1]=fastpow(fac[maxn-1],mod-2);
	for(int i=maxn-2;~i;i--) ifac[i]=ifac[i+1]*(i+1)%mod;
}
inline ll C(ll n,ll m) {
	return fac[n]*ifac[m]%mod*ifac[n-m]%mod;
}
int main() {
    init();
    ll h,w,a,b;cin>>h>>w>>a>>b;
    ll ans=0;
    for(int i=b+1;i<=w;i++) {
    	ans=(ans+C(h-1-a+i-1,i-1)*C(w-i+a-1,a-1)%mod)%mod;
    }
    cout<<ans<<endl;
    return 0;
}


#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
ll const INF = 1LL << 60;

int main() {
  string s;
  cin >> s;
  if (s[0] > s[1]) {
    cout << s[0] << s[0] << s[0] << endl;
  } else if (s[0] < s[1]) {
    cout << s[0] - '0' + 1 << s[0] - '0' + 1 << s[0] - '0' + 1 << endl;
  } else if (s[0] > s[2]) {
    cout << s[0] << s[0] << s[0] << endl;
  } else if (s[0] < s[2]) {
    cout << s[0] - '0' + 1 << s[0] - '0' + 1 << s[0] - '0' + 1 << endl;
  } else {
    cout << s << endl;
  }
  return 0;
}


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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
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;

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    sort(all(a));
    for (int i = 1; i < n; ++i) {
        if (a[i] == a[i-1]){
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
}

#include <bits/stdc++.h>
using namespace std;
#define ff        first
#define ss        second
#define ll        long long
#define int       long long
#define inf       ((ll)1e18)
#define mod       1000000007
#define double    long double
#define ull       unsigned long long
#define vi        vector<ll>
#define ppi       pair<int,int>
#define pii       pair<pair<int,int>,int>
#define pb        push_back
#define pi        2*acos(0.0)
#define rev       greater<int>()
#define pr(a,x,y) for(int i=x;i<y;i++){cout<<a[i]<<" ";}
#define ps(s)     for(auto i:s){cout<<i<<" ";}
#define sp(x,y)   fixed<<setprecision(y)<<x
#define w(x)      ll x; cin>>x; while(x--)
#define all(v)    v.begin(), v.end()
#define rall(v)   v.rbegin(), v.rend()
#define test      cout<<"This is test"<<endl;
#define str       string
#define endl      '\n'
#define e         cout<<'\n';
void kehsihba(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	/*#ifndef ONLINE_JUDGE
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif*/
}
void solve(){
	ll n;cin>>n;
	ll x;
	set<int>s;
	for(int i=0;i<n;i++){
		cin>>x;s.insert(x);
	}
	cout<<(((int)s.size()==n)?"YES":"NO");
}
int32_t main(){
	kehsihba();
	//init();
	ll t=1;
	//cin>>t;
	for(int k=1;k<=t;k++){
		//cout<<"Case "<<k<<": ";
		solve();
		//e;
	}
}


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

const ll MAXN = 200000;
const ll INF = 1001001001;
const ll MOD = 1000000007;

ll N, ans=0, tmp=0;
vector<vector<ll>> A;
string S;

signed main(){
    cin >> S;
    A.resize(26);
    for(int i=0;i<S.size();i++) {
        ll abc = S[i]-'a';
        //cout << abc << endl;
        A[abc].push_back(i);
    }
    for(int i=0;i<26;i++) {
        for(int j=0;j<A[i].size();j++) {
            tmp = S.size()-A[i][j]-A[i].size()+j;
            ans += max(tmp, 0LL);
            //cout << ans << endl;
        }
    }
    cout << ans+1 << endl;
    return 0;
}

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

int main()
{
	string A;
	cin >> A;

	int N = A.size();
	vector<vector<long long>> v( N, vector<long long>( 26 ) );
	for( int i = 0; i < N; i++ ) {
		int j = A[N - 1 - i] - 'a';
		v[N - 1 - i][j]++;
	}
	for( int i = 0; i < N - 1; i++ ) {
		for( int j = 0; j < 26; j++ ) {
			v[N - 2 - i][j] += v[N - 1 - i][j];
		}
	}
	long long ans = 1;
	for( int i = 0; i < N; i++ ) {
		long long n = 0;
		int k = A[i] - 'a';
		for( int j = 0; j < 26; j++ ) {
			if( j == k ) continue;
			n += v[i][j];
		}
		ans += n;
	}

	cout << ans << endl;
}


//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int main(){
    int h,w,n,ans=inf; cin>>h>>w>>n;
    rep(i,h+1)rep(j,w+1){
        if(h*w-(h-i)*(w-j)>=n) ans=min(ans,i+j);
    }
    cout<<ans<<endl;
}

#include <bits/stdc++.h>
#define P pair<long long, long long>

using namespace std;
const int INF=1e5;

int main(){
  int h, w, n;
  cin >> h >> w >> n;
  int mx = max(h, w);
  cout << (n-1)/mx + 1 << endl;
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

#define INF 1e16
#define mod 1000000007

ll N,M;
vector<int> A;

int main(){
  cin>>N>>M;
  A.resize(M);
  rep(i,M)cin>>A[i];
  if(M==1){
    cout<<A[0]<<endl;
    if(A[0]>1){
      cout<<2<<endl;
      cout<<A[0]-1<<" "<<1<<endl;
    }else{
      cout<<1<<endl;
      cout<<1<<endl;
    }
    return 0;
  }
  vector<int> os;
  rep(i,M){
    if(A[i]%2==1)os.push_back(i);
  }
  if(os.size()>2){
    cout<<"Impossible"<<endl;
    return 0;
  }
  if(os.size()==1){
    swap(A[0],A[os[0]]);
  }else if(os.size()==2){
    swap(A[0],A[os[0]]);
    swap(A[M-1],A[os[1]]);
  }
  rep(i,M)cout<<A[i]<<" ";
  cout<<endl;
  if(A[0]-1>0){
    cout<<M<<endl;
    cout<<A[0]-1<<" ";
  }else{
    cout<<M-1<<endl;
  }
  repl(i,1,M-1)cout<<A[i]<<" ";
  cout<<A[M-1]+1<<endl;
  return 0;
}


#include <cstdio>
#include <algorithm>
#include <vector>
using namespace std;
#define rep1(i,n) for(int i=1;i<=n;i++)
struct rec{int di,h;};
vector<rec> vc;
bool comp(rec const &l,rec const &r){
	return l.di!=r.di ? l.di<r.di : l.h<r.h;
}
int main(){
	rep1(i,150) rep1(j,i-1) vc.push_back({i*i+j*j,j});
	sort(vc.begin(),vc.end(),comp);
	while(true){
		int n,m;
		scanf("%d%d",&n,&m);
		if(n==0) break;
		rec e={n*n+m*m,n};
		rec rc=*upper_bound(vc.begin(),vc.end(),e,comp);
		printf("%d %d\n",rc.h,(int)((1e-9)+sqrt(rc.di-rc.h*rc.h)));
	}
	return 0;
}

#include<iostream>
using namespace std;
int main(){
  int h,w;
  while(1){
    cin>>h>>w;
    if(h==0)break;
    int d=h*h+w*w,ah=100,aw=100;
    for(int i=1;i<=150;i++)
      for(int j=i+1;j<=150;j++){
	int k=i*i+j*j;
	if(((k==d&&i>h)||k>d)&&(ah*ah+aw*aw>k||(k==ah*ah+aw*aw&&ah>i)))ah=i,aw=j;
 }
    cout<<ah<<' '<<aw<<endl;
  }
  return 0;
}


#include<iostream>

using namespace std;

int main() {
  int n;
  int a[10000];
  int b[10000];

  while(cin >> n) {
    if(n == 0) {
      break;
    }

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

    int ans_a = 0;
    int ans_b = 0;
    for(int i = 0; i < n; i++) {
      if(a[i] < b[i]) {
        ans_b += a[i] + b[i];
      }else if(a[i] > b[i]) {
        ans_a += a[i] + b[i];
      }else {
        ans_a += a[i];
        ans_b += b[i];
      }
    }

    cout << ans_a << " " << ans_b << endl;
  }

  return 0;
}

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

int main(){
	int num_battle;
	int a, b;
	int point_a = 0;
	int point_b = 0;
	string cards;

	cin >> num_battle;

	for(; num_battle != 0;){
		while(num_battle > 0){
			cin >> a >> b;
			if(a == b){
				point_a += a;
				point_b += b;
			}else if(a > b){
				point_a += a + b;
			}else{
				point_b += a + b;
			}
			num_battle--;
		}
		cout << point_a << " " << point_b << endl;
		// initialize
		point_a = 0;
		point_b = 0;
		cin >> num_battle;
	}

	return 0;
}


#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <cstring>
using namespace std;
typedef long long int ll;
const int INF = 1000000000;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
int main(){
    string s;
    while(getline(cin, s)){
        rep(i, 26){
            for(char& c : s){
                if(isalpha(c)){
                    if(c != 'z') ++c;else c = 'a';
                }
            }
            if(s.find("that") != string::npos || s.find("this") != string::npos || s.find("the") != string::npos){
                cout << s << endl;
            }
        }
    }
    return 0;
}

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string.h>
#include <queue>
#include <stack>
#include <utility>
#include <queue>
#include <cmath>
#define mp make_pair
#define pii pair<int,int>
#define ff first
#define ss second

using namespace std;

int month[20]={0,31,29,31,30,31,30,31,31,30,31,30,31};
string days[10]={"Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"};
int a,b,c,d;
int main()
{
	while(1)
	{
		scanf("%d %d",&a,&b);
		c=0;
		if(a==0&&b==0)
		{
			break;
		}
		for(int i=1;i<a;i++)
		{
			c+=month[i];
		}
		c+=b+2;
		d=c%7;
		//printf("%d\n",c);
		cout<<days[d]<<endl;
	}
	return 0;
}