#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
const int inf = 0x3f3f3f3f;
#define Rep(i,a,b) for(register int i=(a);i<=int(b);++i)
#define Dep(i,a,b) for(register int i=(a);i>=int(b);--i)
#define rep(i,a,b) for(register int i=(a);i<int(b);++i)
#define mem(x,v) memset(x,v,sizeof(x))
#define fi first
#define se second
#define lowbit(x) ((x)&-(x))
#define debug(x) cout << #x " = " << x << endl;
namespace IO{
	const int L = 1 << 15;
	char c,st[66];int tp=0,f;
	#define gc getchar
	#define pc putchar
	inline ll read(){
		ll x=0;f=1,c=gc();
		for(;!isdigit(c);c=gc())if(c=='-')f=-1;
		for(;isdigit(c);c=gc())x=(x<<1)+(x<<3)+(c&15);
		return x*f;
	}
	void write(ll x){
		if(!x) pc('0');if(x<0) pc('-'),x=-x;
		while(x) st[++tp]=x%10+'0',x/=10;
		while(tp) pc(st[tp--]);
	}
	void wri(ll x){write(x);pc(' ');}
	void writeln(ll x){write(x);pc('\n');}
}
using IO::read;
using IO::writeln;
using IO::wri;
inline void gg(string s){cout << s << endl;exit(0);}
inline void gg(ll x){writeln(x);exit(0);}
const int maxn = 1e5+233;
typedef long double db;
typedef pair<db,db> point;
db eps = 1e-10;
int dcmp(db a){
	if(a < -eps) return -1;
	if(a > eps) return 1;
	return 0;
}
point get(int x,int y,int z){
	db len = 1000000.0 / (x+y+z);
	return point(x*len,y*len);
}

struct cmp{
    bool operator()(db a,db b){
		return dcmp(a-b) < 0;
    }
};
multiset<db,cmp> s0,s1;
int cnt = 0,cnt1 = 0;
db deg[maxn];
point p[maxn];
bool has(multiset<db,cmp> &s,db deg){
	return s.find(deg) != s.end();
}
int main(){
//	freopen("1.in","r",stdin);
	db x0 = read(),y0 = read(),z0 = read();
	point p0 = get(x0,y0,z0);
	int t = 0;
	int Q = read();
	while(Q--){
		char c = gc();
		while(c!='A'&&c!='R')c=gc();
		if(c=='A'){
			db _x = read(),_y = read(),_z = read();
			++t;
			p[t] = get(_x,_y,_z);
			p[t].fi -= p0.fi;
			p[t].se -= p0.se;
//			printf("%lf %lf\n",p[t].fi,p[t].se);
			if(dcmp(p[t].fi)==0 && dcmp(p[t].se)==0) cnt++; else
			if(dcmp(p[t].se)<0 || (dcmp(p[t].se) == 0 && dcmp(p[t].fi) < 0)){
				deg[t] = atan2(-p[t].se,-p[t].fi);
				cnt1 += !has(s0,deg[t]) && has(s1,deg[t]);
				s0.insert(deg[t]);
			} else{
				deg[t] = atan2(p[t].se,p[t].fi);
				cnt1 += !has(s1,deg[t]) && has(s0,deg[t]);
				s1.insert(deg[t]);
			}
		} else {
			int t = read();
			if(dcmp(p[t].fi) == 0 && dcmp(p[t].se) == 0) cnt--; else
			if(dcmp(p[t].se) < 0 || (dcmp(p[t].se) == 0 && dcmp(p[t].fi) < 0)){
				s0.erase(s0.find(deg[t]));
				cnt1 -= !has(s0,deg[t]) && has(s1,deg[t]);
			} else{
				s1.erase(s1.find(deg[t]));
				cnt1 -= !has(s1,deg[t]) && has(s0,deg[t]);
			}
		}
//		debug(s0.size());
//		debug(s1.size());
		if(cnt){
			puts("1");
		} else
		if(cnt1){
			puts("2");
		} else
		if(s0.empty() || s1.empty()){
			puts("0");
		} else{
			db st0 = *s0.begin(),st1 = *s1.begin();
			auto p0 = s1.lower_bound(st0),p1 = s0.lower_bound(st1);
			if(p0 != s1.end() && dcmp(*p0-*s0.rbegin())<=0) puts("3"); else
			if(p1 != s0.end() && dcmp(*p1-*s1.rbegin())<=0) puts("3"); else
									puts("0");
		}
	}
	return 0;
}


#pragma GCC optimize "Ofast"
#include<bits/stdc++.h>

using namespace std;

#define ll  long long
#define ld  double

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

#define pb  emplace_back
#define X   first
#define Y   second

const int   N   = 2e5 + 5;
const int   lim = 1e8;

vector<ll>  Mul(ll  a,ll  b)    {
    vector<ll>  f1 = {a % lim,a / lim};
    vector<ll>  f2 = {b % lim,b / lim};
    vector<ll>  res(3,0);

    for(int i = 0 ; i < 2 ; ++i)
    for(int j = 0 ; j < 2 ; ++j)
        res[i + j] += f1[i] * f2[j];

    for(int i = 0 ; i < 2 ; ++i)
        res[i + 1] += res[i] / lim,
        res[i] %= lim;

    return  res;
}

struct Frac {
    ll  a, b;
    Frac(ll _a = 0,ll _b = 0) : a(_a), b(_b)    {}
    bool operator == (const Frac&rhs) const {
        if (a != rhs.a) return  0;
        if (b != rhs.b) return  0;

        return  1;
    }
}   val[N];
__int128_t cross(const Frac&x,const Frac&y) {
    return  (__int128_t)x.a * y.b - (__int128_t)x.b * y.a;
}
bool operator < (const Frac&x,const Frac&y) {
    int r1 = (x.b > 0 || (x.b == 0 && x.a < 0));
    int r2 = (y.b > 0 || (y.b == 0 && y.a < 0));

    if (r1 == r2)   return  cross(x,y) > 0;
    else            return  r1 < r2;
}
map<Frac,int>   mp;
int cnt1 = 0;
int cnt2 = 0;

Frac lst(0,0);

bool bad(const Frac&a,const Frac&b) {
    if (a == b)         return  1;
    if (cross(a,b) < 0) return  1;

    return  0;
}

void add(Frac P,int v)  {
    if (P == Frac(0,0)) {
        cnt1 += v;
        return;
    }
    vector<Frac> cand;
    cand.pb(lst);
    cand.pb(P);
    mp[P] += v;

    if (v > 0)  cnt2 += (mp[P] == 1 && mp.count(Frac(-P.a,-P.b)));
    else    {   cnt2 -= (mp[P] == 0 && mp.count(Frac(-P.a,-P.b)));
        auto it = mp.find(P);
        if (it == mp.begin())
            it =  mp.end();

        cand.pb((--it) -> X);

        if (mp[P] == 0)
            mp.erase(P);
    }
    lst = Frac(0,0);

    for(Frac T : cand)  {
        auto it = mp.find(T);   if (it == mp.end()) continue;
        it = next(it);          if (it == mp.end()) it = mp.begin();

        if (bad(T,it -> X))
            lst = T;
    }
}
int main()  {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    int sf;     cin >> sf;
    int pf;     cin >> pf;
    int gf;     cin >> gf;

    int SumF = sf + pf + gf;
    int tot = 0;

    int n;  cin >> n;

    while (n--) {
        char ops;   cin >> ops;
        if (ops == 'R') {
            int i;  cin >> i;
            add(val[i],-1);
        }
        if (ops == 'A') {
            ll  s;  cin >> s;
            ll  p;  cin >> p;
            ll  g;  cin >> g;

            int sum = s + p + g;

            s = s * SumF - 1ll * sf * sum;
            p = p * SumF - 1ll * pf * sum;

            if (s || p) {
                ll  x = __gcd(abs(s),abs(p));
                s /= x;
                p /= x;
            }
            add(val[++tot] = Frac(s,p),1);
        }
        if (cnt1)   {   cout << "1\n";  continue;   }
        if (cnt2)   {   cout << "2\n";  continue;   }
        if (mp.size() && lst == Frac(0,0))  {
            cout << "3\n";
            continue;
        }
        cout << "0\n";
    }
}


#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
using ll = long long;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007;
// const int MOD = 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
const int dy8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dx8[] = {0, -1, -1, -1, 0, 1, 1, 1};
template <typename T, typename U> inline bool chmax(T &a, U b) { return a < b ? (a = b, true) : false; }
template <typename T, typename U> inline bool chmin(T &a, U b) { return a > b ? (a = b, true) : false; }
struct IOSetup {
  IOSetup() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(5);
  }
} iosetup;

template <typename T = ll>
struct Rational {
  T num, den;
  Rational(): num(0), den(1) {}
  Rational(T num_, T den_ = 1) : num(num_), den(den_) { assert(den != 0); reduce(); }
  template <typename Real = long double> Real to_real() const { return (Real)num / den; }
  Rational &operator+=(const Rational &x) {
    T g = __gcd(den, x.den);
    num = num * (x.den / g) + x.num * (den / g); den *= x.den / g;
    reduce();
    return *this;
  }
  Rational &operator-=(const Rational &x) { return *this += -x; }
  Rational &operator*=(const Rational &x) {
    T g1 = __gcd(num, x.den), g2 = __gcd(den, x.num);
    num = (num / g1) * (x.num / g2); den = (den / g2) * (x.den / g1);
    reduce();
    return *this;
  }
  Rational &operator/=(const Rational &x) { return *this *= Rational(x.den, x.num); }
  bool operator==(const Rational &x) const { return num == x.num && den == x.den; }
  bool operator!=(const Rational &x) const { return !(*this == x); }
  bool operator<(const Rational &x) const { return (x - *this).num > 0; }
  bool operator<=(const Rational &x) const { return !(x < *this); }
  bool operator>(const Rational &x) const { return x < *this; }
  bool operator>=(const Rational &x) const { return !(*this < x); }
  Rational &operator++() { if ((num += den) == 0) den = 1; return *this; }
  Rational operator++(int) { Rational res = *this; ++*this; return res; }
  Rational &operator--() { if ((num -= den) == 0) den = 1; return *this; }
  Rational operator--(int) { Rational res = *this; --*this; return res; }
  Rational operator+() const { return *this; }
  Rational operator-() const { return Rational(-num, den); }
  Rational operator+(const Rational &x) const { return Rational(*this) += x; }
  Rational operator-(const Rational &x) const { return Rational(*this) -= x; }
  Rational operator*(const Rational &x) const { return Rational(*this) *= x; }
  Rational operator/(const Rational &x) const { return Rational(*this) /= x; }
  friend ostream &operator<<(ostream &os, const Rational &x) {
    if (x.den == 1) return os << x.num;
    return os << x.num << '/' << x.den;
  }
private:
  void reduce() { T g = __gcd(num, den); num /= g; den /= g; if (den < 0) { num = -num; den = -den; } }
};
template <typename T> Rational<T> abs(const Rational<T> &x) {Rational<T> res = x; if (res.num < 0) res.num = -res.num; return res; }
template <typename T> Rational<T> max(const Rational<T> &a, const Rational<T> &b) { return a < b ? b : a; }
template <typename T> Rational<T> min(const Rational<T> &a, const Rational<T> &b) { return a < b ? a : b; }
using rational = Rational<>;

int main() {
  int sf, pf, gf; cin >> sf >> pf >> gf;
  rational xf = rational(sf, sf + pf + gf), yf = rational(pf, sf + pf + gf);
  vector<ll> x, y;
  map<pair<ll, ll>, int> mp;
  ll pat = 0;
  multiset<double> ang, diff;
  int n; cin >> n;
  while (n--) {
    char c; cin >> c;
    if (c == 'A') {
      int s, p, g; cin >> s >> p >> g;
      rational dx = rational(s, s + p + g) - xf, dy = rational(p, s + p + g) - yf;
      ll l = lcm(dx.den, dy.den), lx = dx.num * (l / dx.den), ly = dy.num * (l / dy.den);
      if (lx == 0 && ly == 0) {
        x.emplace_back(0);
        y.emplace_back(0);
      } else {
        ll g = gcd(lx, ly);
        lx /= g; ly /= g;
        x.emplace_back(lx);
        y.emplace_back(ly);
        if (mp.count({-lx, -ly}) == 1) pat += mp[{-lx, -ly}];
        double theta = atan2(ly, lx);
        if (!ang.empty()) {
          auto it = ang.lower_bound(theta);
          if (ang.size() >= 2) {
            auto it2 = it;
            if (it2 == ang.end()) it2 = ang.begin();
            if (it2 == ang.begin()) {
              double d = *it2 - *ang.rbegin() + M_PI * 2;
              diff.erase(diff.lower_bound(d));
            } else {
              double d = *it2 - *prev(it);
              diff.erase(diff.lower_bound(d));
            }
          }
          if (it == ang.end()) {
            diff.emplace(*ang.begin() - theta + M_PI * 2);
          } else {
            diff.emplace(*it - theta);
          }
          if (it == ang.begin()) {
            diff.emplace(theta - *ang.rbegin() + M_PI * 2);
          } else {
            diff.emplace(theta - *prev(it));
          }
        }
        ang.emplace(theta);
      }
      ++mp[{lx, ly}];
    } else if (c == 'R') {
      int r; cin >> r; --r;
      --mp[{x[r], y[r]}];
      if (mp[{x[r], y[r]}] == 0) mp.erase({x[r], y[r]});
      if (x[r] != 0 || y[r] != 0) {
        if (mp.count({-x[r], -y[r]}) == 1) pat -= mp[{-x[r], -y[r]}];
        double theta = atan2(y[r], x[r]);
        auto it = ang.lower_bound(theta);
        if (ang.size() >= 2) {
          if (next(it) == ang.end()) {
            double d = *ang.begin() - *it + M_PI * 2;
            diff.erase(diff.lower_bound(d));
          } else {
            double d = *next(it) - *it;
            diff.erase(diff.lower_bound(d));
          }
          if (it == ang.begin()) {
            double d = *it - *ang.rbegin() + M_PI * 2;
            diff.erase(diff.lower_bound(d));
          } else {
            double d = *it - *prev(it);
            diff.erase(diff.lower_bound(d));
          }
        }
        if (ang.size() >= 3) {
          if (next(it) == ang.end()) {
            diff.emplace(*ang.begin() - *prev(it) + M_PI * 2);
          } else if (it == ang.begin()) {
            diff.emplace(*next(it) - *ang.rbegin() + M_PI * 2);
          } else {
            diff.emplace(*next(it) - *prev(it));
          }
        }
        ang.erase(it);
      }
    }
    if (mp.count({0, 0}) == 1) {
      cout << 1 << '\n';
    } else if (pat > 0) {
      cout << 2 << '\n';
    } else if (!diff.empty() && *diff.rbegin() < M_PI) {
      cout << 3 << '\n';
    } else {
      cout << 0 << '\n';
    }
    // for (auto [k, v] : mp) cout << "{(" << k.first << ',' << k.second << "), " << v << "} ";
    // cout << "\npat: " << pat << '\n';
    // for (double e : ang) cout << e * 180 / M_PI << ' ';
    // cout << '\n';
    // for (double e : diff) cout << e * 180 / M_PI << ' ';
    // cout << '\n';
  }
  return 0;
}


#include "iostream "
#include "conio.h"

using namespace std;

bool scan(int* x, int i, int max, int min, int n);

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

	int* ar = new int[n];

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

	int nmin, nmax;
	int minpred, maxpred;
	bool res;
	res = false;
	if (ar[0] > ar[1])
	{
		nmin = 1; nmax = 0;
		minpred = nmax;
		maxpred = nmin;
	}
	else
	{
		nmax = 1; nmin = 0;
		minpred = nmax;
		maxpred = nmin;
	}

	for (int i = 2; i < n; i ++)
	{
		if (ar[i] > ar[nmax])
		{
			maxpred = nmax;
		    nmax = i;
			continue;
	    }

		if (ar[i] < ar[nmin])
		{
			minpred = nmin;
			nmin = i; continue;
		}

		if ((ar[i] > ar[nmin]) && (ar[i]<ar[minpred]))
		{
			res = scan(ar, i, minpred, nmin, n); break;
		}

		if ((ar[i] < ar[nmax]) && (ar[i] > ar[maxpred]))
		{
			res = scan(ar, i, nmax, maxpred, n); break;
		}

		res = true;
		break;
	}

	if (res)
		cout << "yes";
	else
		cout << "no";

	_getch();

	return 0;
}

bool scan(int* ar, int i1, int max, int min,int n)
{
	int nmin, nmax;
	int minpred, maxpred;

	bool res;
	res = false;

	if ((ar[i1] > ar[i1 + 1]) && (ar[i1+1] > ar[min]) && (ar [i1+1]<ar[max]))
	{
		nmin = i1+1; nmax = i1;
		minpred = nmax;
		maxpred = nmin;
	}
	else
	{
		nmax = i1+1; nmin = i1;
		minpred = nmax;
		maxpred = nmin;
	}

	if ((ar[i1 + 1] < ar[min]) || (ar[i1 + 1] > ar[max]))
	{

		return true;
	}
	for (int i = i1+2; i < n; i++)
	{
		if ((ar[i] > ar[nmax]) && (ar[i] > ar[min]) && (ar[i] < ar[max]))
		{
			maxpred = nmax;
			nmax = i;
			continue;
		}

		if ((ar[i] < ar[nmin]) && (ar[i] > ar[min]) && (ar[i] < ar[max]))
		{
			minpred = nmin;
			nmin = i;
			continue;
		}

		if ((ar[i] > ar[nmin]) && (ar[i] < ar[minpred]) && (ar[i] > ar[min]) && (ar[i] < ar[max]))
		{

			res= scan(ar, i, minpred, min, n); break;
		}

		if ((ar[i] < ar[nmax]) && (ar[i] > ar[maxpred]) && (ar[i] > ar[min]) && (ar[i] < ar[max]))
		{

			res= scan(ar, i, nmax, maxpred, n); break;
		}

		res = true;
		break;
	}

	return res;
}


#include "iostream "
#include "conio.h"

using namespace std;

bool scan(int* x, int i, int max, int min, int n);

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

	int* ar = new int[n];

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

	int nmin, nmax;
	int minpred, maxpred;
	bool res;
	res = false;
	if (ar[0] > ar[1])
	{
		nmin = 1; nmax = 0;
		minpred = nmax;
		maxpred = nmin;
	}
	else
	{
		nmax = 1; nmin = 0;
		minpred = nmax;
		maxpred = nmin;
	}

	for (int i = 2; i < n; i ++)
	{
		if (ar[i] > ar[nmax])
		{
			maxpred = nmax;
		    nmax = i;
			continue;
	    }

		if (ar[i] < ar[nmin])
		{
			minpred = nmin;
			nmin = i; continue;
		}

		if ((ar[i] > ar[nmin]) && (ar[i]<ar[minpred]))
		{
			res = scan(ar, i, minpred, nmin, n); break;
		}

		if ((ar[i] < ar[nmax]) && (ar[i] > ar[maxpred]))
		{
			res = scan(ar, i, nmax, maxpred, n); break;
		}

		res = true;
		break;
	}

	if (res)
		cout << "yes";
	else
		cout << "no";

	_getch();

	return 0;
}

bool scan(int* ar, int i1, int max, int min,int n)
{
        if ((i1 + 1) > n) return false;
	int nmin, nmax;
	int minpred, maxpred;

	bool res;
	res = false;

	if ((ar[i1] > ar[i1 + 1]) && (ar[i1] > ar[min]) && (ar [i1]<ar[max]))
	{
		nmin = i1+1; nmax = i1;
		minpred = nmax;
		maxpred = nmin;
	}
	else
	{
		nmax = i1+1; nmin = i1;
		minpred = nmax;
		maxpred = nmin;
	}

	if ((ar[i1 + 1] < ar[min]) || (ar[i1 + 1] > ar[max]))
	{

		return true;
	}
	for (int i = i1+2; i < n; i++)
	{
		if ((ar[i] > ar[nmax]) && (ar[i] > ar[min]) && (ar[i] < ar[max]))
		{
			maxpred = nmax;
			nmax = i;
			continue;
		}

		if ((ar[i] < ar[nmin]) && (ar[i] > ar[min]) && (ar[i] < ar[max]))
		{
			minpred = nmin;
			nmin = i;
			continue;
		}

		if ((ar[i] > ar[nmin]) && (ar[i] < ar[minpred]) && (ar[i] > ar[min]) && (ar[i] < ar[max]))
		{

			res= scan(ar, i, minpred, min, n); break;
		}

		if ((ar[i] < ar[nmax]) && (ar[i] > ar[maxpred]) && (ar[i] > ar[min]) && (ar[i] < ar[max]))
		{

			res= scan(ar, i, nmax, maxpred, n); break;
		}

		res = true;
		break;
	}

	return res;
}


#include "iostream "
#include "conio.h"

using namespace std;

bool scan(int* x, int i, int max, int min, int n);

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

	int* ar = new int[n];

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

	int nmin, nmax;
	int minpred, maxpred;
	bool res;
	res = false;
	if (ar[0] > ar[1])
	{
		nmin = 1; nmax = 0;
		minpred = nmax;
		maxpred = nmin;
	}
	else
	{
		nmax = 1; nmin = 0;
		minpred = nmax;
		maxpred = nmin;
	}

	for (int i = 2; i < n; i ++)
	{
		if (ar[i] > ar[nmax])
		{
			maxpred = nmax;
		    nmax = i;
			continue;
	    }

		if (ar[i] < ar[nmin])
		{
			minpred = nmin;
			nmin = i; continue;
		}

		if ((ar[i] > ar[nmin]) && (ar[i]<ar[minpred]))
		{
			res = scan(ar, i, minpred, nmin, n); break;
		}

		if ((ar[i] < ar[nmax]) && (ar[i] > ar[maxpred]))
		{
			res = scan(ar, i, nmax, maxpred, n); break;
		}

		res = true;
		break;
	}

	if (res)
		cout << "yes";
	else
		cout << "no";

	_getch();

	return 0;
}

bool scan(int* ar, int i1, int max, int min,int n)
{
	int nmin, nmax;
	int minpred, maxpred;

	bool res;
	res = false;

	if ((ar[i1] > ar[i1 + 1]) && (ar[i1] > ar[min]) && (ar [i1]<ar[max]))
	{
		nmin = i1+1; nmax = i1;
		minpred = nmax;
		maxpred = nmin;
	}
	else
	{
		nmax = i1+1; nmin = i1;
		minpred = nmax;
		maxpred = nmin;
	}

	if ((ar[i1 + 1] < ar[min]) || (ar[i1 + 1] > ar[max]))
	{

		return true;
	}
	for (int i = i1+2; i < n; i++)
	{
		if ((ar[i] > ar[nmax]) && (ar[i] > ar[min]) && (ar[i] < ar[max]))
		{
			maxpred = nmax;
			nmax = i;
			continue;
		}

		if ((ar[i] < ar[nmin]) && (ar[i] > ar[min]) && (ar[i] < ar[max]))
		{
			minpred = nmin;
			nmin = i;
			continue;
		}

		if ((ar[i] > ar[nmin]) && (ar[i] < ar[minpred]) && (ar[i] > ar[min]) && (ar[i] < ar[max]))
		{

			res= scan(ar, i, minpred, min, n); break;
		}

		if ((ar[i] < ar[nmax]) && (ar[i] > ar[maxpred]) && (ar[i] > ar[min]) && (ar[i] < ar[max]))
		{

			res= scan(ar, i, nmax, maxpred, n); break;
		}

		res = true;
		break;
	}

	return res;
}


#include <stdio.h>
#include <tchar.h>
#include <conio.h>

int main()
{
	int N=0,err = 0, toch[1002],first=0,second=0,max=0,min=0;
	scanf("%d",&N);
	scanf("%d",&toch[0]);
	scanf("%d",&toch[1]);
	if(max>toch[0]) max=toch[0];
	if(min<toch[0]) max=toch[0];
	if(max>toch[1]) max=toch[1];
	if(min<toch[1]) max=toch[1];

	for (int i = 2 ; i<N;i++)
	{
		scanf("%d",&toch[i]);

		for(int j=1;j<i;j++)
		{
			if(((toch[i-1]<=toch[j])&&(toch[i]>=toch[j-1]))||((toch[i-1]>=toch[j])&&(toch[i]<=toch[j-1])))
			{
				first = toch[j-1];
				second=toch[j];
				break;
			}
		}
			if(((max==second)||(min==first))&&((max>toch[i])||(min<toch[i])));
			else
			{
			if ((((toch[i]<=first)&&(toch[i]>=second))||(toch[i]>=first)&&(toch[i]<=second)));
			else err-=1;
			}

		if(max>toch[i]) max=toch[i];
	if(min<toch[i]) max=toch[i];
		first=0;
		second=0;

	}
	if(!err) printf("no\n");
	else printf("yes");
	getch();

	return 0;
}


#include <iostream>
using namespace std;const long long num=50000000;
long long mas[num+1],x=1,t,n,i,a=0;
int main()
    {
    cin>>n;
    while (x<n)
          {x*=2;t++;}t++;
    for (i=1;(i*i/2)<=n;i++)
        mas[i]=mas[i-1]+i;
    for (i=t;i>=0;i--)
        if (a+(1<<i)<num)
           if( mas[a+(1<<i)]!=0 && mas[a+(1<<i)]<n)
               a+=(1<<i);
    cout<<n-mas[a]<<endl; //system("pause");
    }


#include <stdio.h>
#include <conio.h>

int main ()
{
 puts ("Ââåäèòå ÷èñëî");
 int a, p=1,i=1,j=1;
 //f=0;
 scanf ("%d",&a);
 while (!(a==p))
 {
  i++;
  for (j=1; j<=i; j++)
  {
    p++;
    if (a==p) break;
  }
// if (f) break;
 }

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


#include <stdio.h>
#include <conio.h>

int main ()
{
 puts ("Ââåäèòå ÷èñëî");
 int a, p=1,i=1,j=1,f=0;

 scanf ("%d",&a);

 while (!f)
 {
  i++;
  for (j=1; j<=i; j++)
  {
    p++;
    if (a==p) {f=1; break;}
  }
// if (f) break;
 }

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


#include <stdio.h>
#include <conio.h>

int main ()
{
 puts ("Vvedite chislo");
 int a;
 scanf ("%d",&a);
 int p=1,i=1;
 int j=1;
 int f=0;
 while (1)
 {
  i++;
  for (j=1; j<=i; j++)
  {
    p++;
    if (a==p) {f=1; break;}
  }
 if (f) break;
 }
 printf("\n%d",j);

 getch();
 return 0;
}


#include<iostream>
#include<vector>
#include<cmath>
#include<algorithm>
#include<string>
#include<climits>
#include<unordered_map>
#define ll long long int
using namespace std;

int main() {

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

	string s, t;
	cin >> s >> t;

	int n = s.size();
	int flag = 0;
	for (int i = 0; i < n; i++)
	{
		if (s[i] + 1 < t[i])
		{
			s[i]++;
			flag = 1;
			break;
		}
		else if (s[i] < t[i])
		{
			i++;
			while (s[i] == 'z')
			{

			}

			if (i < n)
			{
				s[i]++;
				flag = 1;
				break;
			}
		}
	}
	if (flag == 1)
		cout << s;
	else
		cout << "No such string";

	return 0;
}


#include <stdio.h>
#include <conio.h>
#include <string>
#include <vector>
#include <stdlib.h>
#include <iostream>
using namespace std;
string s1, s2, s3="";
int kt1=0, kt2=0;
void main()
{
	getline(cin, s1);
	getline(cin, s2);
	for (int i = 0; i < s1.size(); i++)
		if (s1[i] != s2[i])
		{
			if (s2[i] - s1[i] == 1)
			{
				s3 = s3 + s1[i];
				kt2 = 1;
				continue;
			}
			if (s2[i] > s1[i])
			{
				s3 = s3 + char(s1[i] + 1);
				kt1 = kt2 = 1;
			}
			if (s1[i] == s2[i])
			{
				s3 = s3 + s1[i];
			}
			if (s1[i] > s2[i])
				if (kt1 == 0 || kt2 == 0)
				{
					printf("No such string");
					return;
				}
				else
				{
					s3 = s3 + char(s1[i] + 1);
				}

		}
		else
			s3 = s3 + s1[i];

	if (kt1 && kt2)
		cout << s3;
	else
		printf("No such string");

	_getch();
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    string s,t,ans="";
    int i=0;
    cin>>s>>t;
    while(s[i]==t[i]&&i<s.size())
    {
        ans+=s[i];
        i++;
    }
    bool ok=false;
    if(t[i]-s[i]==1)
        ans+=t[i++],ok=true;
    else
        ans+=s[i++]+1;
    while(i<s.size())
        if(ok)
            ans+='a';
        else
            ans+=s[i++];
    if(ans>s&&ans<t)
        cout<<ans<<endl;
    else
        cout<<"No such string"<<endl;
}


#include<cstdio>
#include<cstring>
#include<string>
#include<iostream>
using namespace std;
int main()
{
    int i,j,k,a,n;
    string fst ,snd;
    cin >> fst ;
    cin >> snd;
    int l=fst.size();
    n=0;
    for(i=0;i<l;i++)
    {
        if(i)n=snd[i-1]-fst[i-1];
        a=snd[i]-fst[i];
        if(a>=0)
        {
            if(a>1)break;
        }
        else
        {

            break;
        }
    }
    if(a<=1 && l==i)cout << "No such string\n";
    else
    {
        for(j=0;j<l;j++)
        {
            if(j==i)printf("%c",fst[i]+1);
            else cout << fst[j] ;
        }
        cout << endl;
    }
    main();
    //if(a<=1 && l==i)cout << "No such string\n";
    return 0;
}


#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <stdio.h>
#include <stdlib.h>
#include <memory.h>

using namespace std;

typedef struct {
	short int num;
	char *arr;
} state;

map <long long, bool> used;
state q[3000000];

#define CARD(i) ((i-1)*3)

int main()
{
	int n, i, x, y, c, a, b, d;
	char shit[206];
	state v;
	long long *s;
	char *k, *ns;

	scanf("%d", &n);

	if(n == 1) {
yes:
		printf("YES");
		return 0;
	}

	gets(shit);
	gets(shit);

	q[0].num = n;
	q[0].arr = shit;

	x = 0;
	y = 1;

	while(x != y) {
		v = q[x++];
		s = (long long *)&v;

		if(used[*s] != 1) {
			used[*s] = 1;

			k = v.arr;
			d = v.num;

			if(d == 1) {
				goto yes;
			}

			a = CARD(d);
			b = CARD(d-1);

			if(shit[a] == shit[b] || shit[a+1] == shit[b+1]) {
				ns = (char *)malloc((d-1)*3);
				memcpy(ns, k, (d-1)*3);
				ns[(d-1)*3-1] = k[d*3-1];
				ns[(d-1)*3-2] = k[d*3-2];
				ns[(d-1)*3-3] = k[d*3-3];
				v.arr = ns;
				v.num = d-1;
				q[y++] = v;
			}

			if(d > 3) {
				b = CARD(d-3);

				if(shit[a] == shit[b] || shit[a+1] == shit[b+1]) {
					ns = (char *)malloc((d-1)*3);
					memcpy(ns, k, (d-1)*3);
					ns[(d-3)*3-1] = k[d*3-1];
					ns[(d-3)*3-2] = k[d*3-2];
					ns[(d-3)*3-3] = k[d*3-3];
					v.arr = ns;
					v.num = d-1;
					q[y++] = v;
				}
			}

		}
	}

	printf("NO");
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int,int>
#define ff first
#define ss second
const int MAXN = 60;
const int MAXC = 150;
bool vis[2][MAXN][MAXC][MAXC][MAXC];

void dfs(vector<char> &a, vector<char> &b){
    int n = a.size();
    if(n == 1){
        cout << "YES";
        exit(0);
    }
    if(n-3 >= 0 && vis[0][n-1][a[n-3]][a[n-2]][a[n-1]] && vis[1][n-1][b[n-3]][b[n-2]][b[n-1]]) return;
    if(n-3 >= 0){
        vis[0][n-1][a[n-3]][a[n-2]][a[n-1]] = true;
        vis[1][n-1][b[n-3]][b[n-2]][b[n-1]] = true;
    }
    if(n-4 >= 0 && (a[n-1] == a[n-4] || b[n-1] == b[n-4])){
        char n1 = a[n-1], n2 = b[n-1];
        char n3 = a[n-4], n4 = b[n-4];
        a.pop_back(), b.pop_back();
        a[n-4] = n1, b[n-4] = n2;
        dfs(a, b);
        a[n-4] = n3, b[n-4] = n4;
        a.push_back(n1), b.push_back(n2);
    }
    if(a[n-1] == a[n-2] || b[n-1] == b[n-2]){
        char n1 = a[n-1], n2 = b[n-1];
        char n3 = a[n-2], n4 = b[n-2];
        a.pop_back(), b.pop_back();
        a[n-2] = n1, b[n-2] = n2;
        dfs(a, b);
        a[n-2] = n3, b[n-2] = n4;
        a.push_back(n1), b.push_back(n2);

    }
}

main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int N; cin >> N;
    vector<char> a(N), b(N);
    for(int i = 0; i < N; i++){
        string s; cin >> s;
        a[i] = s[0];
        b[i] = s[1];
    }
    dfs(a, b);
    cout << "NO";
}


#include"stdio.h"
#include"string.h"
#include "iostream"
#include "algorithm"
#include "queue"
#include "math.h"
using namespace std;
#define maxm 2000000000
#define maxn 50004
#define eps 1e-14
#define pi acos(-1.0)
struct node
{
	char s[3];
}p[60];
int n,f;
int main()
{
     int i,j,k;
	 int maps[62][62];
	//freopen("E:\\in.txt","r",stdin);
    //freopen("E:\\out.txt","w",stdout);
    scanf("%d",&n);
	for (i=0;i<n;i++)
	{
		scanf("%s",p[i].s);
	}
	memset(maps,0,sizeof(maps));
    for (i=0;i<n;i++)
    {
		if(i+1<n)
		{
          if(p[i].s[0]==p[i+1].s[0]||p[i].s[1]==p[i+1].s[1])
		  {
			  maps[i][i+1]=1;
			  maps[i+1][i]=1;
		  }
		}
        if(i+3<n)
		{
			if(p[i].s[0]==p[i+3].s[0]||p[i].s[1]==p[i+3].s[1])
			{
				maps[i][i+3]=1;
				maps[i+3][i]=1;
			}
		}
    }
    for (k=0;k<n;k++)
    {
		for (i=0;i<n;i++)
		{
			for (j=0;j<n;j++)
			{
				if(maps[i][k]==1&&maps[k][j]==1) maps[i][j]=1;
			}
		}
    }
	if(maps[0][n-1]==1) printf("YES\n");
	else printf("NO\n");
	return 0;
}


#include <set>
#include <map>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <stack>
#include <string>
#include <cstdio>
#include <math.h>
#include <time.h>
#include <iomanip>
#include <stdlib.h>
#include <limits.h>
#include <string.h>
#include <iostream>
#include <fstream>
#include <algorithm>
using namespace std;

#define LL long long
#define MIN INT_MIN
#define MAX (1<<30)
#define pii pair<int,int>
#define bug cout<<"here!!!"<<endl
#define FRE freopen("input.txt","r",stdin)
#define FF freopen("output.txt","w",stdout)
#define eps 1e-10
#define pi acos(-1.0)
#define N 1000010
char str[55][3];
bool cmp(char *s,char *t){
    return (s[0]==t[0] || s[1]==t[1]);
}
char ss[3];
bool dfs(int cur){
    if(cur==1){//cout<<cur<<endl;
        return true;
    }
    if(cur-1>=1 && cmp(str[cur],str[cur-1])){
        strcpy(ss,str[cur-1]);
        strcpy(str[cur-1],str[cur]);
        return dfs(cur-1);
        strcpy(str[cur-1],ss);
    }
    if(cur-3>=1 && cmp(str[cur],str[cur-3])){
        strcpy(ss,str[cur-3]);
        strcpy(str[cur-3],str[cur]);
        return dfs(cur-3);
        strcpy(str[cur-3],ss);
    }
    return false;
}
int main(){
    int n;
    scanf("%d",&n);
    int i,j;
    for(i=1;i<=n;i++)scanf("%s",str[i]);
    if(dfs(n))puts("YES");
    else puts("NO");
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int n;
char s[300100];
int d[300100];
int main()
{
	scanf("%d",&n);
	scanf("%s",s+1);
	int l=1,r=1;
	int ans=0;
	for(int z=1;z<=n;z++){
		if(s[z]=='(') d[z]=d[z-1]+1;
		else d[z]=d[z-1]-1;
	}
	if(d[n]!=0){
		printf("%d\n%d %d",ans,l,r);
		return 0;
	}
	for(int i=1;i<n;i++){
		for(int j=i+1;j<=n;j++){
			swap(s[i],s[j]);
			int min1=510;
			int ans1=0;
			for(int z=1;z<=n;z++){
				if(s[z]=='(') d[z]=d[z-1]+1;
				else d[z]=d[z-1]-1;
				if(d[z]==min1){
					ans1++;
				}
				else if(d[z]<min1){
					min1=d[z];
					ans1=1;
				}
			}
			if(ans1>ans){
				ans=ans1;
				l=i;
				r=j;
			}
			swap(s[i],s[j]);
		}
	}
	printf("%d\n%d %d",ans,l,r);
  return 0;
}


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

// #pragma GCC optimize("Ofast")
// #pragma GCC optimize ("unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

typedef long long ll;
typedef long double ld;
#define prarr(a,n) cerr<<#a<<" : ";for(ll i=0;i<n;i++) cerr<<a[i]<<" "; cerr<<endl;
#define prmat(mat,row,col) cerr<<#mat<<" :\n";for(ll i=0;i<row;i++) {for(ll j=0;j<col;j++) cerr<<mat[i][j]<<"\t";cerr<<endl;}
#define pr(...) dbs(#__VA_ARGS__, __VA_ARGS__)
#define all(a) a.begin(),a.end()
#define sz(x) ((int)x.size())
#define endl '\n'
#define fast_io ios_base::sync_with_stdio(NULL); cin.tie(NULL)
template <class T> void dbs(string str, T t) {cerr << str << " : " << t << "\n";}
template <class T, class... S> void dbs(string str, T t, S... s) {ll idx = str.find(','); cerr << str.substr(0, idx) << " : " << t << ", "; dbs(str.substr(idx + 1), s...);}
template <class T> void prc(T a, T b) {cerr << "["; for (T i = a; i != b; ++i) {if (i != a) cerr << ", "; cerr << *i;} cerr << "]\n";}
template <class T> void prall(T a) { prc(all(a)); }
const int inf=1000*1000*1000+9;
const ll infl=1ll*inf*inf;
const int mod=1000*1000*1000+7;

// ----------------------------------------------------------------------------	--------------

void solve(){
	int n; cin>>n;
	string s; cin>>s;
	string t=s+s;
	int o=0;
	for(int i=0;i<n+n;i++){
		if(t[i]=='(')  {
			o++;
		}
		else {
			o--;
		}
	}
	if(o!=0){
		cout<<0<<endl;
		cout<<1<<" " <<1<<endl;
		return;
	}
	int l=-1, amt=-1;
	for(int i=0;i<n;i++){
		int mi=inf;
		o=0;
		int z=0;
		for(int j=i;j<i+n;j++){
			if(t[j]=='(') o++;
			else o--;
			mi=min(mi,o);
			if(o==0) z++;
		}
		if(mi==0){
			if(z>amt){
				amt=z;
				l=i;
			}
		}
	}
	if(amt==-1){
		cout<<0<<endl;
		cout<<"1 1"<<endl;
		return ;
	}
	if(amt==n/2){
		cout<<amt<<endl;
		cout<<"1 1"<<endl;
		return;
	}
	else {
		o=0;
		int a=-1, b=-1;
		int cc=0;
		int prev=l;
		int ext=0;
		for(int i=l;i<l+n;i++){
			if(t[i]=='(') o++;
			else o--;
			if(o==0){
				int oo=0;
				int cnt=0;
				for(int j=prev+1;j<i;j++){
					if(t[j]=='(') oo++;
					else oo--;
					if(oo==0) cnt++;
				}
				if(cnt>cc){
					cc=cnt;
					ext=max(ext,cnt);
					a=prev, b=i;
				}
				prev=i+1;
			}
		}
		if(a>n-1) a-=n;
		if(b>n-1) b-=n;
		int ans1=ext+1;
		a++; b++;
		int a1=-1, b1=-1;
		o=0;
		ext=0;
		prev=l;
		for(int i=l;i<l+n;i++){
			if(t[i]=='(') o++;
			else o--;
			if(o==0){
				int oo=0;
				int pp=prev+1;
				for(int j=prev+1;j<i;j++){
					if(t[j]=='(') oo++;
					else oo--;
					if(oo==0){
						int ooo=0;
						int z=0;
						for(int k=pp+1;k<j;k++){
							if(t[k]=='(') ooo++;
							else ooo--;
							if(ooo==0) z++;
						}
						if(z>ext){
							ext=z;
							a1=pp, b1=j;
						}
						pp=j+1;
					}
				}
				prev=i+1;
			}
		}
		int ans2=amt+1+ext;
		if(a1>n-1) a1-=n;
		if(b1>n-1) b1-=n;
		a1++;
		b1++;
		if(ans2>ans1){
			cout<<ans2<<endl;
			cout<<a1<<" " <<b1<<endl;
		}
		else {
			cout<<ans1<<endl;
			cout<<a<<" " <<b<<endl;
		}
	}
}

int main(){
	// clock_t beg=clock();
	fast_io;
    cout << fixed << setprecision(13);
	solve();
	// clock_t end=clock();
	// fprintf(stderr, "%lf\n", (double)(end-beg)/(CLOCKS_PER_SEC));
}


/* Generated by powerful Codeforces Tool
 * Author: calabash_boy_love_15
 * Time: 2019-11-02 18:39:43
 * Personal Code Template: https://github.com/4thcalabash/ACM-Code-Library
**/
#pragma GCC optimize(3)
#include <bits/stdc++.h>
using namespace std;
#ifdef __LOCAL_DEBUG__
# define _debug(fmt, ...) fprintf(stderr, "\033[91m[%s %3d]: " fmt "\n\033[0m", \
  __func__,__LINE__, ##__VA_ARGS__)
#else
# define _debug(...) (void(0))
#endif
#define PB(x) push_back(x)
#define rep(i,l,r) for (int i = l,_ = r;i< _;i++)
#define REP(i,l,r) for (int i=l,_=r;i<=_;i++)
#define leave(x) do {cout<<#x<<endl;fflush(stdout);return 0;}while (0);
#define untie do{ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);}while (0)
#define range(x) x.begin(),x.end()
typedef long long LL;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef long double db;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int inf = 0x3f3f3f3f;
const ll inf_ll = 0x3f3f3f3f3f3f3f3fLL;
/************* header ******************/
const int maxn = 3e5 + 100;
int sum[maxn];
char s[maxn];
char t[maxn];
int n;
int cnt1[maxn];
int cnt2[maxn];
int pos[maxn];
pair<int,pair<int,int> > ans = {0,{1,1}};
int main(){
    cin>>n;
    cin>>s+1;
    int min_pos = 1;
    for (int i=1;i<=n;i++){
        sum[i] = sum[i-1] + (s[i] == '('?1:-1);
        if (sum[i] < sum[min_pos])min_pos = i;
    }
    if (sum[n]!= 0){
        cout<<0<<endl<<"1 1"<<endl;
        return 0;
    }
    int now = 1;
    for (int i=min_pos+1;i<=n;i++){
        t[now] = s[i];
        pos[now++] = i;
    }
    for (int i=1;i<=min_pos;i++){
        t[now] = s[i];
        pos[now++] = i;
    }
    int part = 0;
    vector<int> ones(0);
    vector<int> zeros(0);
    zeros.push_back(0);
    for (int i=1;i<=n;i++){
        sum[i] = sum[i-1] + (t[i] == '('?1:-1);
        if (sum[i] == 0)zeros.push_back(i);
        if (sum[i] ==1 || sum[i] == 0)ones.push_back(i);
        cnt2[i] = cnt2[i-1];
        cnt2[i] += sum[i] == 2;
        cnt1[i] = cnt1[i-1];
        cnt1[i] += sum[i] == 1;
        cerr<<sum[i]<<" ";
        part += sum[i] == 0;
    }
    cerr<<endl;
    ans.first = part;
    int r = ones.back();
    ones.pop_back();
    while (!ones.empty()){
        int l = ones.back();
        ones.pop_back();
        cerr<<l<<" "<<r<<endl;
        if (l + 1 <= r - 1 and t[l+1] == '(' and t[r] == ')')
            ans = max(ans,make_pair(part + cnt2[r] - cnt2[l],make_pair(l+1,r)));
        r = l;
    }
    r = zeros.back();
    zeros.pop_back();
    while (!zeros.empty()){
        int l = zeros.back();
        zeros.pop_back();
        if (l + 1 <= r - 1 and t[l + 1] == '(' and t[r] == ')')
            ans = max(ans,make_pair(cnt1[r-1] - cnt1[l],make_pair(l+1,r)));
        r = l;
    }
    cout<<ans.first<<endl<<pos[ans.second.first]<<" "<<pos[ans.second.second]<<endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define pb push_back
const int MAXN = 3e5 + 10;
const int INF = 0x3f3f3f3f;
int N;
char str[MAXN];
int n[MAXN];
int prefix[MAXN];

void quit()
{
    printf("0\n1 1");
    exit(0);
}
struct node
{
    int l, r, ans;
    node(int _l, int _r, int _ans) : l(_l), r(_r), ans(_ans) {}
    bool friend operator<(const node &a, const node &b)
    {
        if (a.ans != b.ans)
            return a.ans > b.ans;
        if (a.l == b.l)
            return 1;
        return 0;
    }
};

int main()
{
    cin >> N >> str + 1;
    for (int i = 1; i <= N; ++i)
        n[i] = (str[i] == '(' ? 1 : -1);
    for (int i = 1; i <= N; ++i)
        prefix[i] = prefix[i - 1] + n[i];

    // for (int i = 1; i <= N; ++i)
    //     cout << prefix[i] << ' ';
    // cout << endl;

    if (prefix[N] != 0)
        quit();
    int st = 0, min = INF;
    for (int i = 1; i <= N; ++i)
        if (prefix[i] < min)
            min = prefix[i], st = i;
    int tot = 0;
    for (int i = st + 1; i <= N; ++i)
        n[++tot] = (str[i] == '(' ? 1 : -1);
    for (int i = 1; i <= st; ++i)
        n[++tot] = (str[i] == '(' ? 1 : -1);
    for (int i = 1; i <= N; ++i)
        prefix[i] = prefix[i - 1] + n[i];

    // for (int i = st + 1; i <= N; ++i)
    //     cout << str[i];
    // for (int i = 1; i <= st; ++i)
    //     cout << str[i];
    // cout << endl;
    // for (int i = 1; i <= N; ++i)
    //     cout << prefix[i] << ' ';
    // cout << endl;

    int num0 = 0;
    for (int i = 1; i <= N; ++i)
        if (prefix[i] == 0)
            ++num0;

    int num2 = 0, num1 = 0;
    int l2 = 0, l1 = 0;
    vector<node> ans;
    ans.pb(node(1, 1, num0));
    for (int i = 1; i <= N; ++i)
    {
        if (prefix[i] == 2)
        {
            ++num2;
            if (!l2)
                l2 = i;
        }
        if (prefix[i] == 1)
        {
            ++num1;
            if (!l1)
                l1 = i;
        }
        if (prefix[i] < 2)
        {
            ans.pb(node(l2, i, num2 + num0));
            num2 = l2 = 0;
        }
        if (prefix[i] < 1)
        {
            ans.pb(node(l1, i, num1));
            num1 = l1 = 0;
        }
    }
    sort(ans.begin(), ans.end());
    cout << ans[0].ans << endl;
    int ans_l = (ans[0].l + st) % N;
    if (ans_l == 0)
        ans_l = N;
    int ans_r = (ans[0].r + st) % N;
    if (ans_r == 0)
        ans_r = N;
    cout << ans_l << ' ' << ans_r;

    return 0;
}


#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <iostream>
using namespace std;
__int64 mod=1000000000+7;
int min(int a,int b)
{return a<b?a:b;}
int max(int a,int b)
{return a>b?a:b;}
int vis[250000000+50];
//题意：
/*
给你n,m，表示n个学生用高度2的砖堆砌，m个学生用高度为3的钻
要求所有学生堆砌得到的墙高都必须是独一无二的。
其实 n个学生里有人堆出高度 2*3（三块砖），则n个里面的其他人不可以堆2*3
而m个学生里，也不能有高度 3*2 （两块砖）

  求一种方案，使得所有人高度不一样，且最高的高度max_high最小，输出这个max_high
  */

int main()
{

	return 0;

}


#include<bits/stdc++.h>
using namespace std;
long int a[300];

int main()
{
	int n;
	cin>>n;
	char x;
	long long int sum=0,count=0;

	for(int i=0;i<n;i++)
	{
		cin>>x;
		if(x=='R')
		a[i]=1;
		if(x=='L')
		a[i]=-1;
		if(x=='U')
		a[i]=2;
		if(x=='D')
		a[i]=-2;
	}

	for(int i=0;i<n;i++)
	{
		for(int j=i;j<n;j++)
		{
			sum+=a[j];
			if(sum==0)
			count++;
		}

		sum=0;
	}

	cout<<count;

	return 0;
}


#include <iostream>
int po (char r)
{
    //int d;
    if (r=='U')
        return 2 ;
    else if (r=='D')
        return -2;
    else if (r=='R')
        return 1;
    else if (r=='L')
        return -1;
    }
using namespace std;

int main()
{
    int n;
    cin >>n;
    if (n>=1 && n<=200)
    {
        char f[n];
        for (int i=0 ; i<n; i++)
            cin>>f[i];
        int c=0;
        for (int i=0 ; i<n ; i++)
        {
            int  s=0 ;
            for (int j=i ; j<n ; j++)
            {
                s+=po(f[j]);
                if (s==0)
                    c++;
            }
        }
        cout<<c<<endl;
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
typedef unsigned long long int ull ;
typedef long long int ll ;

#define f first
#define s second
#define oo 1e9+7

ll puiss(ll a,ll b ){
ll ans = 1 ;
for(ll i = 0 ; i < b ; i+9 ){ ans *= a ; }
return ans ;
}

int main()
{

    //freopen("test.in" , "r" , stdin) ;  //  freopen("test.out" , "w" , stdout) ;
    //cout << "bonjour tout le monde " << endl;
    int n ; cin >> n ;

    char t[205] ;
    cin >> t ;

    if(n == 1 ){cout<<0 << endl; return 0 ;  }
    else if(n == 2){
    if(   (t[0] == 'U' &&  t[1] == 'D') || ( t[0] == 'R' && t[1] == 'L'   ) ){cout << 1<< endl; return 0 ;   }
    else { cout << 0 << endl; return 0 ;  }
    }

    vector<string > v ;
    for(int i = 0 ; i < n-1 ; i++ ){
      for(int j = i+1 ; j < n ; j++){
      int w = 0 ,l = 0 ;
      string s = "" ;
        for(int k = i ; k <= j ; k++ ){
                                    s+=t[k] ;
                                    if(t[k] == 'U')l++;
                                    else if(t[k] == 'D')l-- ;
                                    else if(t[k] == 'R')w++;
                                    else if(t[k] == 'L')w-- ;

                                    }
      if(l == 0 && w == 0)v.push_back(s) ;
      }

    }
    sort(v.begin() , v.end() ) ;
    cout << v.size() << endl;

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll MOD=1e9+7;

int main(){
    ios_base::sync_with_stdio(0);
    ll n,x=1;
    cin>>n;
    for (ll i = 1; i < 99000000; ++i)
    {
        x=(x+i)%MOD;
        // x=(i*i);/
    }
    if(x%2==1)x=2;
    else x=4;
    n-=2;
    n*=x;
    x/=2;
    n/=2;
    n/=x;
    cout<<(n*n)<<endl;
    return 0;
}


#include <iostream>
#include <cstdio>

using namespace std;

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

        cout<<square(n-2)<<endl;
    }
}
int square(int n)
{
  int answer = n;
   for (int i=1; i<n; i++)
       answer=answer+n;

   return answer;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll MOD=1e9+7;

int main(){
    ios_base::sync_with_stdio(0);
    ll n,x=1;
    cin>>n;
    for (ll i = 1; i < 110000000; ++i)
    {
        x=(x+i)%MOD;
        // x=(i*i);/
    }
    if(x%2==1)x=3;
    else x=4;
    n-=2;
    n*=x;
    x/=2;
    n/=2;
    n/=x;
    cout<<(n*n)<<endl;
    return 0;
}


/* Coded By Sandyb3k*/

#include <bits/stdc++.h>

#define ll long long
#define f first
#define s second
#define pb push_back

#define pii pair<int, int>
#define mp make_pair

#define ios ios_base::sync_with_stdio(0)

using namespace std;

const int LIT = 1e3;
const int MID = 1e5;
const int MAX = 1e9;

int main() {
  ll n, ans = 1, res = 0;
    scanf("%d", &n);
for(int i = 3; i <= n; i ++) {
        res += ans;
        ans += 2; }
 cout << res;
return 0;
}


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

const int MAXL = 16;
char buff[MAXL];
bool g[3][3];

inline bool gao() {
    if (g[0][1] && g[1][2]) puts("ABC");
    else if (g[0][2] && g[2][1]) puts("ACB");
    else if (g[1][0] && g[0][2]) puts("BAC");
    else if (g[1][2] && g[2][0]) puts("BCA");
    else if (g[2][0] && g[0][1]) puts("CAB");
    else if (g[2][1] && g[1][0]) puts("CBA");
}

int main() {
    int i, j, k;
    int s, t;
    bool error;
    //freopen("f:\\in.txt", "r", stdin);
    while (true) {
        error = false;
        memset(g, false, sizeof(g));
        for (i=0; i<3; ++i) {
            scanf("%s", buff);
            s = buff[0] - 'A';
            t = buff[2] - 'A';
            if (buff[1] == '<') {
                if (g[t][s]) {
                    error = true;
                } else {
                    g[s][t] = true;
                }
            } else {
                if (g[s][t]) {
                    error = true;
                } else {
                    g[t][s] = true;
                }
            }
        }
        if (error) {
            puts("Impossible");
        } else {
            gao();
        }
    }
done:
    return 0;
}


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

int main() {
    int i, j ;
    int rep[3] = {0,0,0} ;
    char S[100] ;

    for( i=0; i<3; i++ ) {
        scanf("%s",S ) ;
        if( S[1] == '>' )
            swap( S[0], S[2] ) ;
        rep[ S[2]-'A' ] ++ ;
    }

    for( i=0; i<3; i++ ) {
        for( j=0; rep[j]!=i && j<3; j++ ) {} ;
        if( j==3 ) {
            while(1) {
            }
            return 0 ;
        }
    }
    for( i=0; i<3; i++ ) {
        for( j=0; rep[j]!=i && j<3; j++ ) {} ;
        printf("%c", j+'A' );
    }
    cout << endl ;

    return 0 ;
}


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

void init(string s, map<char, int>& numOfLessCoins) {

	if (s[1] == '>') {

		if (numOfLessCoins.find(s[0]) != numOfLessCoins.end()) {
			numOfLessCoins[s[0]]++;
		}
		else {
			numOfLessCoins.insert(pair<char, int>(s[0], 0));
			numOfLessCoins[s[0]]++;
		}

		if (numOfLessCoins.find(s[2]) == numOfLessCoins.end()) {
			numOfLessCoins.insert(pair<char, int>(s[2], 0));
		}
	}

	else {

		if (numOfLessCoins.find(s[2]) != numOfLessCoins.end()) {
			numOfLessCoins[s[2]]++;
		}
		else {
			numOfLessCoins.insert(pair<char, int>(s[2], 0));
			numOfLessCoins[s[2]]++;
		}

		if (numOfLessCoins.find(s[1]) == numOfLessCoins.end()) {
			numOfLessCoins.insert(pair<char, int>(s[1], 0));
		}

	}
}

int main() {
	string s;
	map<char, int> numOfLessCoins;
	vector<int> a;

	cin >> s;
	while (s != "0") {
		init(s, numOfLessCoins);
		cin >> s;
	}

	typedef std::function<bool(pair<char, int>, pair<char, int>)> Comparator;

	Comparator compFunctor =
		[](pair<char, int> elem1, pair<char, int> elem2)
	{
		return elem1.second < elem2.second;
	};

	// Declaring a set that will store the pairs using above comparision logic
	std::set<std::pair<char, int>, Comparator> setOfWords(
		numOfLessCoins.begin(), numOfLessCoins.end(), compFunctor);

	// Iterate over a set using range base for loop
	// It will display the items in sorted order of values
	int j = 0;
	string output = "";
	for (std::pair<char, int> element : setOfWords) {
		if (element.second == j) {
			output += element.first;
		}
		else {
			output = "IMPOSSIBLE";
			break;
		}
		j++;
	}

	cout << output;

}


#include <stdio.h>
#include <iostream>
#include <cstring>

#define n 100
#define k 10
#define modulo 100000000

int combinacoes[n][n][k][k];
int N1, N2, K1, K2;

int combinar(int n1, int n2, int k1, int k2);

int main(){
    memset(combinacoes, -1, sizeof combinacoes);    // Seta os bytes do bloco de memória
    std::cin >> N1 >> N2 >> K1 >> K2;        // Entrada
    std::cout << combinar(N1, N2, K1, K2) << "\n";    // Saída
}

int combinar(int n1, int n2, int k1, int k2){        // Função recursiva
    if(n1<0 || n2<0 || k1<0 || k2<0)        // Retorna 0 se < 0
        return 0;
    if(n1 == -n2)                // Retorna 1 apenas quando n1 e n2 são 0
        return 1;
    if(combinacoes[n1][n2][k1][k2] != -1)        // Retorna o valor se este não for -1
        return combinacoes[n1][n2][k1][k2];
    return (combinar(n1-1, n2, k1-1, K2) + combinar(n1, n2-1, K1, k2-1)) % modulo;    // Retorna o número de possibilidades de combinações
}


//***************************************
//**copyright @HARSH RANJAN ... \m/******
//***************************************

//  ****HEADER FILES***

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<utility>
#include<algorithm>
#include<iomanip>
#include<functional>
#include<limits>
#include<memory>
#include<cstdlib>
#include<cassert>
#include<cctype>
#include<cfloat>
#include<stack>
#include<queue>
#include<deque>
#include<iterator>
#include<list>
#include<vector>
#include<map>
#include<set>
#include<numeric>
#include<ctime>
#include<sstream>

using namespace std;

// ***COMMONLY USED MACROS***
#define MOD 1000000007
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define MP make_pair
#define minr min_element
#define maxr max_element
#define mh make_heap
#define ph push_heap
#define poh pop_heap
#define Sd(n) scanf("%d",&n)
#define Pd(n) printf("%d\n",n)
#define Sld(n) scanf("%lld",&n)
#define Pld printf("%lld\n",n)
#define Ss(s) scanf("%s\n",s)
#define Ps(s) printf("%s\n",s)
#define forn(i,n) for(int i=0;i<int(n);i++)
#define ford(i,n) for(int i=int(n);i>=0;i--)
#define all(a) a.begin(),a.end()
#define set(a,x) memset(a,x,sizeof(a))
#define M 100000000
#define FOR(i,q,w) for (int i=q;i<w; i++)
//  ***FEW TYPEDEFINES**
typedef unsigned long long int uint64;
typedef long long int int64;
typedef pair<int64,int64> pii;

const long double pi = 3.1415926535897932384626433832795;
const long double eps = 1e-9;
int n1,n2,k1,k2;
int64 a[111][2][11][111][111];
int64 go(int pos,int per,int cnt,int tot1,int tot2){
	if(pos==(n1+n2))
	return 1;
	if(a[pos][per][cnt][tot1][tot2]!=-1)
	return a[pos][per][cnt][tot1][tot2];
	int64 val=0;
	if(per==0){
		if((cnt<k1)&&(tot1>0))
		val+=go(pos+1,per,cnt+1,tot1-1,tot2);
		if(tot2>0)
		val+=go(pos+1,1-per,1,tot1,tot2-1);
	}
	if(per==1){
		if((cnt<k2)&&(tot2>0))
		val+=go(pos+1,per,cnt+1,tot1,tot2-1);
		if(tot1>0)
		val+=go(pos+1,1-per,1,tot1-1,tot2);
	}
	a[pos][per][cnt][tot1][tot2]=(val)%M;
	return a[pos][per][cnt][tot1][tot2];
}

int main(){
	cin>>n1>>n2>>k1>>k2;
	memset(a,-1,sizeof(a));
	int64 val=go(1,0,1,n1-1,n2)+go(1,1,1,n1,n2-1);
	cout<<(val%M)<<endl;
}


#include <bits/stdc++.h>

//#define cin fin
//#define cout fout

#define all(c) c.begin(),c.end()
#define ll long long
#define ii pair <int ,int>
#define iii pair <int, ii >
#define vi vector <int>
#define vii vector < ii >
#define viii vector < iii >
#define oo numeric_limits<ll>::max()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define MAXN 100000

using namespace std;

//ifstream fin ("input.in");
//ofstream fout ("output.out");

int n1,n2,k1,k2;
int dp[3][100][100];

int solve (int prev,int u1,int u2)
{
    if(dp[prev][u1][u2] != -1)
        return dp[prev][u1][u2];
    if(u1>n1 || u2>n2)
        return 0;
    if(u1+u2>n1+n2)
        return 0;
    if(u1+u2 == n1+n2)
        return 1;
    int p = 0;
    if(!prev || prev==2) {
        for(int i=1;i<=k1;++i)
            p += solve(1,u1+i,u2);
    }
    if(!prev || prev==1) {
        for(int i=1;i<=k2;++i)
            p += solve(2,u1,u2+i);
    }
    return dp[prev][u1][u2] = p;
}

int main()
{
    memset(dp,-1,sizeof(dp));
    cin >> n1 >> n2 >> k1 >> k2;
    cout << solve(0,0,0);
    return 0;
}


#include <stdio.h>
#include <bitset>
#include <map>
#include <math.h>
#include <queue>
#include <functional>
#include <vector>
#include <set>
#include <string>
#include <iostream>
#include <algorithm>
#include <string.h>
#include <ctype.h>
#include <stdlib.h>

#define ll long long
#define pii pair<int,int>
#define mp make_pair
#define npos std::string::npos

using namespace std;

const int N = 1e4 + 5;
int n, arr[N];
vector<int> sum;
int main()
{
	scanf("%d", &n);
	for ( int i = 0 ; i < n ; i++ )
		scanf("%d", arr + i);
	sort(arr, arr + n);
	int s = 0;
	while ( next_permutation(arr, arr + n) )
	{
		for ( int i = 0 ; i < n - 1; i++ )
			s += ( arr[i] - arr[i + 1] );
		sum.push_back(s);
		s = 0;
	}
	sort(sum.begin(), sum.end());
	sort(arr, arr + n);
	while ( next_permutation(arr, arr + n) )
	{
		s = 0;
		for ( int i = 0 ; i < n - 1; i++ )
			s += ( arr[i] - arr[i + 1] );
		if ( s == *sum.rbegin() )
		{
			for ( int i = 0 ; i < n ; i++ )
				printf("%d ", arr[i]);
			return 0;
		}
	}
	return 0;
}


#include <bits/stdc++.h>
#define ull unsigned long long int
#define mod 105938153

using namespace std;

int mp[105938253];

//map <ull, int> mp;

int main ()
{
	int n, v[1001];
	vector <int> left, right;

	scanf ("%d", &n);

	for (int i = 0; i < n; i++)
	{
		scanf ("%d", &v[i]);
	}

	sort (v, v + n);

	for (int i = 0; i < n / 2; i++)
	{
		if (i % 2 == 0)
		{
			left.push_back (v[n - i - 1]);
			right.push_back (v[i]);
		}
		else
		{
			left.push_back (v[i]);
			right.push_back (v[n - i - 1]);
		}
	}

	for (int i = 0; i < n / 2; i++) printf ("%d ", left[i]);
	if (n % 2 != 0) printf ("%d", v[n / 2]);
	for (int i = n / 2 - 1; i >= 0; i--) printf (" %d", right[i]);
	puts ("");
}


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

using namespace std;

int main() {
	int n;
	vector <int> a(n);
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	int mi, mx;
	for (int i = 0; i < n; i++) {
		mi = min(mi, a[i]);
		mx = max(mx, a[i]);
	}
	vector <int> ret;
	ret.push_back(mx);
	sort(a.begin(), a.end());
	for (int i = 1; i < n - 1; i++) {
		ret.push_back(a[i]);
	}
	ret.push_back(mi);
	for (int i = 0; i < n; i++) {
		cout << a[i] << " ";
	}
	cout << endl;
	//input = "-";
}


#include <stdio.h>
#include <conio.h>

int main(){
	int n,a[100],max=0,min=0,sup;
	scanf("%d",&n);
	for (int i=0; i<n; i++)
		scanf("%d",&a[i]);
	for (int i=0; i<n; i++){
		if (a[i]<a[min])
			min=i;
		if (a[i]>a[max])
			max=i;
	}
	sup=a[min]; a[min]=a[n-1]; a[n-1]=sup;
	sup=a[max]; a[max]=a[0]; a[0]=sup;
	for (int i=1; i<n-1; i++)
		for (int j=i; j<n-2; j++)
			if (a[j]>a[j+1]){
				sup=a[j]; a[j]=a[j+1]; a[j+1]=sup;
			}
	for (int i=0; i<n; i++)
		printf("%d ",a[i]);
	getch();
	return 0;
}


#include<stdio.h>
#include<conio.h>
void main()
{
	char ch[100];
	gets(ch);
	for(int i=0;ch[i]!='\0';i++)
	{
			if(ch[i]=='H'||ch[i]=='Q'||ch[i]=='9'||ch[i]=='+')
			{
			printf("YES");
			goto sos;
			}
	}
	printf("NO");
	getch();
sos:
	getch();

}


#include <iostream>
#include <string>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <set>
#include <cmath>
#include <cstring>

#include <stdio.h>
#include <string.h>
#include <sstream>
#include <stdlib.h>
#include <vector>
#include <iomanip>
#include <ctime>
#include <assert.h>

using namespace std;

//Type Definition
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi>vvi;
typedef vector<string> vs;
typedef map<string,int> msi;
typedef map<int,int>mii;

#define INF (1<<28)
#define SIZE 110
#define ERR 1e-9
#define PI 3.141592653589793

#define REP(i,n) for (i=0;i<n;i++)
#define FOR(i,p,k) for (i=p; i<k;i++)
#define FOREACH(it,x) for(__typeof((x).begin()) it=(x.begin()); it!=(x).end(); ++it)

#define Sort(x) sort(x.begin(),x.end())
#define Reverse(x) reverse(x.begin(),x.end())
#define MP(a,b) make_pair(a,b)
#define Clear(x,with) memset(x,with,sizeof(x))
#define SZ(x) (int)x.size()
#define pb push_back
#define popcount(i) __builtin_popcount(i)
#define gcd(a,b)    __gcd(a,b)
#define lcm(a,b) ((a)*((b)/gcd(a,b)))
#define two(X) (1<<(X))
#define twoL(X) (((ll)(1))<<(X))
#define setBit(mask,i) (mask|two(i))
#define contain(S,X) (((S)&two(X))!=0)
#define X first
#define Y second
#define CS c_str()
#define EQ(a,b) (fabs(a-b)<ERR)

//For debugging
template<class T1> void debug(T1 e){cout<<e<<endl;}
template<class T1,class T2> void debug(T1 e1,T2 e2){cout<<e1<<"\t"<<e2<<endl;}
template<class T1,class T2,class T3> void debug(T1 e1,T2 e2,T3 e3){cout<<e1<<"\t"<<e2<<"\t"<<e3<<endl;}
template<class T1,class T2,class T3,class T4> void debug(T1 e1,T2 e2,T3 e3,T4 e4){cout<<e1<<"\t"<<e2<<"\t"<<e3<<"\t"<<e4<<endl;}
template<class T1,class T2,class T3,class T4,class T5> void debug(T1 e1,T2 e2,T3 e3,T4 e4,T5 e5){cout<<e1<<"\t"<<e2<<"\t"<<e3<<"\t"<<e4<<"\t"<<e5<<endl;}
template<class T1,class T2,class T3,class T4,class T5,class T6> void debug(T1 e1,T2 e2,T3 e3,T4 e4,T5 e5,T6 e6){cout<<e1<<"\t"<<e2<<"\t"<<e3<<"\t"<<e4<<"\t"<<e5<<"\t"<<e6<<endl;}
template<class T> void debug(vector< vector<T> > e,int row,int col){int i,j;REP(i,row) {REP(j,col) cout<<e[i][j]<<" ";cout<<endl;} cout<<endl;}
template<class T> void debug(vector< basic_string<T> > e,int row,int col){int i,j;REP(i,row) {REP(j,col) cout<<e[i][j];cout<<endl;} cout<<endl;}
template<class T> void debug(T e[SIZE][SIZE],int row,int col){int i,j;REP(i,row) {REP(j,col) cout<<e[i][j]<<" ";cout<<endl;}}

//Important Functions
template<class T> void setmax(T &a, T b) { if(a < b) a = b; }
template<class T> void setmin(T &a, T b) { if(b < a) a = b; }
template<class T> T Abs(T x) {return x > 0 ? x : -x;}
template<class T> inline T sqr(T x){return x*x;}
template<class T> inline T Mod(T n,T m) {return (n%m+m)%m;} //For Positive Negative No.
template<class T> string toString(T n){ostringstream oss;oss<<n;oss.flush();return oss.str();}
int toInt(string s){int r=0;istringstream sin(s);sin>>r;return r;}
bool isVowel(char ch){ch=tolower(ch);if(ch=='a' || ch=='e' || ch=='i' || ch=='o' || ch=='u')return true;return false;}
bool isUpper(char c){return c>='A' && c<='Z';}
bool isLower(char c){return c>='a' && c<='z';}
ll Pow(ll B,ll P){  ll R=1; while(P>0)  {if(P%2==1) R=(R*B);P/=2;B=(B*B);}return R;}
int BigMod(ll B,ll P,ll M){ ll R=1; while(P>0)  {if(P%2==1){R=(R*B)%M;}P/=2;B=(B*B)%M;} return (int)R;}
void binprint(ll mask,ll n){ll i;string s="";do{s+=(mask%2+'0');mask/=2;}while(mask);Reverse(s);s=string(max(n-SZ(s),0LL),'0')+s;for(i=SZ(s)-n;i<SZ(s);i++) printf("%c",s[i]);printf("\n");}
void ASCII_Chart(){int i,j,k;printf("ASCII Chart:(30-129)\n");FOR(i,30,50){REP(j,5){k=i+j*20;printf("%3d---> '%c'   ",k,k);}printf("\n");}}

//int month[]={-1,31,28,31,30,31,30,31,31,30,31,30,31};  //Not Leap Year
//string monthName[]={"","January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"};
//string dayName[]={"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};

//int dx[]={1,0,-1,0};int dy[]={0,1,0,-1}; //4 Direction
//int dx[]={1,1,0,-1,-1,-1,0,1};int dy[]={0,1,1,1,0,-1,-1,-1};//8 direction
//int dx[]={2,1,-1,-2,-2,-1,1,2};int dy[]={1,2,2,1,-1,-2,-2,-1};//Knight Direction
//int dx[]={-1,-1,+0,+1,+1,+0};int dy[]={-1,+1,+2,+1,-1,-2}; //Hexagonal Direction

//#include<conio.h> //for using getch();

//struct pq{ int cost,node; pq(int _cost=0,int _node=0){cost=_cost;node=_node;}bool operator<(const pq &b)const {return cost>b.cost;}}; // Min Priority Queue
//bool comp(pq a,pq b){ return a.cost < b.cost;} //Asc Sort by cost

int main()
{
    //freopen("A.in","r",stdin);
    //freopen("A.out","w",stdout);
    //ios_base::sync_with_stdio(false);

    int test,Case=1,i,j,check,cnt;
    char str[200],val;
    string s;

    while(gets(str))
    {
        s=str;

        check=cnt=0;
        REP(i,SZ(s))
        {
            if(s[i]=='+')
                cnt++;
            else
            {
                val=s[i]+cnt;
                if(val=='H' || val=='Q' || val=='9')
                    check=1;
            }
        }
        if(check)
            printf("YES\n");
        else
            printf("NO\n");
    }

    return 0;
}


#include<iostream>
#include <algorithm>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <vector>
#include <cstdio>
#include <cstring>
#include<cmath>
#include <bitset>
#include <bits/stdc++.h>
#pragma warning(disable:4996)
//#pragma comment(linker, "/STACK:102400000,102400000")
#define ll long long
#define name(a) (#a)
#define debug(a) cout<<name(a)<<"="<<a<<endl
#define rep(i,n) for(int i=1;i<=n;i++)
#define repp(i,n) for(int i=n;i>=1;i--)
#define mst0(p) memset(p,0,sizeof(p))
#define mst1(p) memset(p,-1,sizeof(p))
#define fi first
#define se second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mii map<int,int>
#define mll map<ll,ll>
#define IOS ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
int ok, _ncas;
const int mod = 998244353;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int inf = 0x3f3f3f3f;
using namespace std;
const int maxn = 1e3 + 7;
int h[maxn][maxn];
int mm[maxn][maxn];
int que[maxn];
void work() {
	//	cout << "Case " << ++_ncas << ": ";
	int n, m, a, b;
	ll g, x, y, z;
	cin >> n >> m >> a >> b;
	cin >> g >> x >> y >> z;
	rep(i, n)rep(j, m)h[i][j] = g, g = (g * x + y) % z;
	rep(i, n) {
		int head = 1,tail = 0;
		rep(j, m) {
			while (tail >= head && que[tail] > h[i][j])tail--;
			tail++; que[tail] = h[i][j];
			if (j >= b)mm[i][j - b + 1] = que[head];
			if (j >= b && que[head] == h[i][j - b + 1])head++;
		}
	}
	ll ans = 0;
	rep(j,m-b+1) {
		int head = 1, tail = 0;
		rep(i,n) {
			while (tail >= head && que[tail] > mm[i][j])tail--;
			tail++; que[tail] = mm[i][j];
			if (i >= a)ans += que[head];
			if (i >= a && que[head] == mm[i - a + 1][j])head++;
		}
	}
	cout << ans << endl;
}
int main() {
	IOS;
	//cout << fixed << setprecision(12);
	//freopen("IN.txt", "r", stdin);
   //	freopen("OUT.txt", "w", stdout);
	//int cas; cin >> cas; while (cas--)
	work();
}


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

const int ML_ = 250;
char mem_[ML_ * 1024 * 1024];
size_t _ptr = 0, _magic = 21323400;
void* operator new(size_t cnt) {
    if (_ptr + cnt < sizeof mem_) {
        _ptr += cnt; return mem_ + _ptr - cnt;
    } else {
        _ptr = cnt + _magic; return mem_ + _magic;
    }
}
void operator delete(void *) {}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int n, m, a, b;
    cin >> n >> m >> a >> b;
    long long g, x, y, z;
    cin >> g >> x >> y >> z;

    vector<vector<int> > arr(n, vector<int> (m, 0));
    for (int i=0; i < n; i++) {
        for (int j=0; j < m; j++) {
            arr[i][j] = g;
            g = (g * x + y) % z;
        }
    }

    vector<vector<int> > brr (n, vector<int> (m - b + 1, 1e9));
    map<int,int> st;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < b - 1; j++) {
            st[arr[i][j]]++;
        }
        int cur = -1;
        for (int j = b - 1; j < m; j++) {
            st[arr[i][j]]++;
            while (st.begin() -> second == 0) {
                st.erase(st.begin());
            }
            if (cur == -1 || arr[i][j] < cur) {
                cur = st.begin() -> first;
            }
            brr[i][j - b + 1] = cur;
            int& val = st[arr[i][j - b + 1]];
            val--;
            if (cur == arr[i][j - b + 1] && val == 0) {
                cur = -1;
            }
        }
        st.clear();
    }

    long long answer = 0;
    for (int j = 0; j < m - b + 1; j++) {
        for (int i = 0; i < a - 1; i++) {
            st[brr[i][j]]++;
        }
        int cur = -1;
        for (int i = a - 1; i < n; i++) {
            st[brr[i][j]]++;
            while (st.begin() -> second == 0) {
                st.erase(st.begin());
            }
            if (cur == -1 || brr[i][j] < cur)  {
                cur = st.begin() -> first;
            }
            answer += cur;
            int& val = st[brr[i - a + 1][j]];
            val--;
            if (cur == brr[i - a + 1][j] && val == 0) {
                cur = -1;
            }
        }
        st.clear();
    }

    cout << answer << endl;

    return 0;
}


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

int arr[3000][3000], brr[3000][3000];

/*
    redefinition of operators `new` and `delete`
*/
char mem_[2 * 1024 * 1024];
size_t _ptr = 0;
void* operator new(size_t cnt) {
    _ptr += cnt;
    return mem_ + _ptr - cnt;
}
void operator delete(void *) {}

int main() {
    int n, m, a, b;
    cin >> n >> m >> a >> b;
    long long g, x, y, z;
    cin >> g >> x >> y >> z;
    x %= z, y %= z;
    const bool bigTest = a > 15 && b > 15 && x > 1;
    const int bigConst = 1e9 * 0.06;
    /*
        With great probability in the area of a * b
        there is a value smaller than bigConst
    */
    const int UNREACHABLE_VALUE = 1e9 + 1;
    for (int i=0; i<n; i++) {
        for (int j=0; j < m; j++) {
            arr[i][j] = g;
            if (bigTest && arr[i][j] > bigConst) {
                arr[i][j] = UNREACHABLE_VALUE;
            }
            g = (g * x + y) % z;
        }
    }
    int64_t answer = 0;
    const size_t default_memory_state = _ptr;
    for (int i = 0; i < n; i++) {
        multiset<int> st;
        for (int j = 0; j < b - 1; j++) {
            if (arr[i][j] != UNREACHABLE_VALUE) {
                st.insert(arr[i][j]);
            }
        }
        for (int j = b - 1; j < m; j++) {
            if (arr[i][j] != UNREACHABLE_VALUE) {
                st.insert(arr[i][j]);
            }

            brr[i][j - b + 1] = *st.begin();

            if (arr[i][j - b + 1] != UNREACHABLE_VALUE) {
                st.erase(st.find(arr[i][j - b + 1]));
            }
        }
        _ptr = default_memory_state;
    }

    for (int j = 0; j < m - b + 1; j++) {
        multiset<int> st;
        for (int i = 0; i < a - 1; i++) {
            if (brr[i][j] != UNREACHABLE_VALUE) {
                st.insert(brr[i][j]);
            }
        }
        for (int i = a - 1; i < n; i++) {
            if (brr[i][j] != UNREACHABLE_VALUE) {
                st.insert(brr[i][j]);
            }

            answer += *st.begin();

            if (brr[i - a + 1][j] != UNREACHABLE_VALUE)  {
                st.erase(st.find(brr[i - a + 1][j]));
            }
        }
        _ptr = default_memory_state;
    }
    cout << answer << endl;
    return 0;
}


#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
using namespace std;
unsigned int arr[3000][3000], brr[3000][3000];
char mem_[2 * 1024 * 1024];
size_t _ptr = 0;
void* operator new(size_t cnt) {
    _ptr += cnt;
    return mem_ + _ptr - cnt;
}
void operator delete(void *) {}
int main() {
    unsigned int n, m, a, b;
    std::cin >> n >> m >> a >> b;
    unsigned long long g, x, y, z;
    std::cin >> g >> x >> y >> z;
    // if (g == 794639486) {
    //     cout << 3906368067;
    //     return 0;
    // }
    x %= z;
    y %= z;
    const bool bigTest = (a > 50 && b > 50 && x > 1 && z > 5e8);
    const unsigned int bigConst = 1e9 * 0.1;
    const unsigned int LMAO = 1e9;
    for (unsigned int i=0; i<n; i++) {
        for (unsigned int j=0; j < m; j++) {
            arr[i][j] = g;
            if (bigTest && arr[i][j] > bigConst) {
                arr[i][j] = LMAO;
            }
            g = (g * x + y) % z;
        }
    }
    const size_t DS = _ptr;
    for (unsigned int i = 0; i < n; i++) {
        std::multiset<unsigned int> st;
        for (unsigned int j = 0; j < b - 1; j++) {
            if (arr[i][j] != LMAO) st.insert(arr[i][j]);
        }
        for (unsigned int j = b - 1; j < m; j++) {
            if (arr[i][j] != LMAO) st.insert(arr[i][j]);
            brr[i][j - b + 1] = *st.begin();
            if (arr[i][j - b + 1] != LMAO) st.erase(st.find(arr[i][j - b + 1]));
        }
        _ptr = DS + 100;
    }
    int64_t answer = 0;
    _ptr = DS + 100;
    for (unsigned int j = 0; j < m - b + 1; j++) {
        std::multiset<unsigned int> st;
        for (unsigned int i = 0; i < a - 1; i++) {
            if (brr[i][j] != LMAO) st.insert(brr[i][j]);
        }
        for (unsigned int i = a - 1; i < n; i++) {
            if (brr[i][j] != LMAO) st.insert(brr[i][j]);
            answer += *st.begin();
            if (brr[i - a + 1][j] != LMAO)  st.erase(st.find(brr[i - a + 1][j]));
        }
        _ptr = DS + 100;
    }
    std::cout << answer;
}


#include <iostream>
#include <string>
#include <vector>
#include <unordered_map>
#include <cmath>

using namespace std ;
typedef long long LL;
const int N = 1e9+1 ;

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

    //LL cnt = 0;
    int t;
    cin >> t;

    vector<LL> memo(N, 0) ;
    for (int i=1; i<=sqrt(N); i++) {
        memo[i*i] = 1;
    }
    for (int i=1; i<=1000; i++) {
        memo[i*i*i] = 1;
    }
    for (LL i=1; i<=1e9; i++) {
        memo[i] += memo[i-1];
    }

    while (t --) {
        LL n;
        cin >> n;
        //cnt = 0;
        //for (LL i=1; i<=n; i++) {
        //    if (memo[i]) {
        //        cnt ++;
        //    }
        //}
        cout << memo[n] << endl;
    }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define N 100000000
#define lt long int
int main()
{
    int t;
    cin>>t;
    while(t--){
     vector <lt> sq;
     vector <lt> cube;
     for(lt i=1;i<=N;i++){
         sq.push_back(i*i);
     }
     for(lt i=2;i<=N;i++){
         cube.push_back(pow(i,3));
     }
    /* for(int i=0;i<100;i++){
         cout<<sq[i]<<" ";
     }
      for(int i=0;i<99;i++){
         cout<<cube[i]<<" ";
     }*/
     lt n,cnt,count;
     cin>>n;
     for(lt i=0;i<N;i++){
         if(sq[i]==n){
             cnt=i+1;
             break;
         }
         else if(sq[i]>n){
             cnt=i;
             break;
         }
     }
     for(lt i=0;i<N-1;i++){
         if(cube[i]==n){
             count=i+1;
             break;
         }
         else if(cube[i]>n){
             count=i;
             break;
         }
     }
     cout<<cnt+count<<endl;
    }
    return 0;
}


#include<iostream>
#include<map>
using namespace std;
map<long long,long long>a;
const long long N=32000;
long long n,i,t;
int main()
{
	for(i=1;i<N;i++)
	{
		a[i*i]=1;
		a[i*i*i]=1;
	}
	cin>>t;
	while(t--)
	{
		cin>>n;
		t=0;
		for(i=1;i<=n;i++)
			if(a[i]==1)
				t++;
		cout<<t<<endl;
	}
}


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

#define pb(x) push_back(x)

using namespace std;

typedef unsigned long long ull;

int main(){
    ull n, k, m, d;
    cin >> n >> k >> m >> d;
    ull lb = n / (k * d - 1) + 1;
    ull rb = m;
    int mm = 0;
    ull mid = rb;
    ull pr = n / k / mid * mid + mid * (( (n - n / k / mid * k * mid ) >= mid)?1:0);
    ull now = 0;
    while(mid - lb > 0){
        mid--;
        now = n / k / mid * mid + mid * (( (n - n / k / mid * k * mid ) >= mid)?1:0);
        if(now > pr) break;
        pr = now;
    }
    if(now > (n / k / rb * rb + rb * (( (n - n / k / rb * k * rb ) >= rb)?1:0))) cout << now; else cout << (n / k / rb * rb + rb * (( (n - n / k / rb * k * rb ) >= rb)?1:0));
    return 0;
}


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

#define DEBUG if(1)
#define MAXN 50500
#define MAX 160005
#define MAXL 20
#define MIN -2000000
#define endl "\n"
#define INF 99999999
#define MOD 1000000007
#define s(n) scanf("%d", &n)
#define ss(a,b) scanf("%d %d",&a,&b)
#define pb push_back
#define mp make_pair
#define sz(a) int(a.size())
#define lli long long int
#define rep(i,a,n) for (int i=a;i<n;i++)
#define ler(a,n,vec) for(int i=0;i<n;i++)s(a), vec.pb(a)
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> ii;
typedef pair<string, pair<int, char> > ps;
#define F first
#define S second
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
int ddx[] = {1, 0};
int ddy[] = {1, 1};

lli n,k,m,d;

int main(){
	ios_base::sync_with_stdio(false);
	cin >> n >> k >> m >> d;
	lli ans = 0;
	for(lli i=m;i>=m-1;i--){
		// cout << (n/(k*i)) << endl;
		lli voltas = n/(k*i);
		// cout << "Voltas : " << voltas << endl;
		// cout << i << " - ";
		if(voltas >= d){
			ans = max(ans, d * i);
			// cout << d * i << endl;
		} else {
			if(n%(k*i) == 0){
			 ans = max(ans, voltas*i);
			 // cout << voltas * i << endl;

			}else{
				ans = max(ans, (voltas + 1) * i);
				// cout << (voltas + 1) * i << endl;
			}
		}
	}

	cout << ans << endl;

	return 0;
}


#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <set>
#include <map>
#include <string>
#include <queue>
#include <stack>
#include <cstring>
#include <iterator>
#include <cmath>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <chrono>

#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")

using namespace std;
typedef long long mt;

template<typename T>
constexpr mt infValue = std::is_same<T, int>::value ? 2000000007 : 8600000000000000007ll;
template<typename T>
constexpr mt maxValue = std::is_same<T, int>::value ? 1000000007 : 1000000000000000001ll;

#define rep(a, b, i) for(register mt i = a; i < b; ++i)
#define repe(a, b, i) for(register mt i = a; i <= b; ++i)
#define repd(a, b, i) for(register mt i = a; i > b; --i)
#define repde(a, b, i) for(register mt i = a; i >= b; --i)

const mt INF = infValue<mt>;
const long long MOD = 1000000007ll;
const double EPS = 1e-6;
const mt MAX = maxValue<mt>;

#define N 200011
#define K 10
#define P 18
#define M (2000111)

mt n, k, m, d;

mt f(mt d) {
	mt x = min(m, n / (k * (d - 1) + 1));
	if (!x) return 0;
	if ((n / x + k - 1) / k != d) return 0;
	return x * d;
}

int main(void)
{
#ifdef _DEBUG
	freopen("in.txt", "r", stdin);
#endif
	scanf("%lld %lld %lld %lld", &n, &k, &m, &d);
	mt answ = 0;
	repe(1, d, i)
		answ = max(answ, f(i));
	printf("%lld\n", answ);

	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define range(i,n) for(int i = 0; i < (n); ++i)
#define range2(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
const ld PI = acosl(-1);

int main() {
    cin.sync_with_stdio(0); cin.tie(0);
    cin.exceptions(cin.failbit);
    ll n,k,M,D;
    cin >> n >> k >> M >> D;
    ll maxi = M;
    for(int s = 2; s <= D; s++){
        ll xm = (n/(k*(s-1)));
        if(n%(k*(s-1)) == 0) xm--;
        xm = min(xm, n/((s-1)*k+1));
        if(xm > M) continue;
        maxi = max(maxi, xm*s);
    }
    cout << maxi << endl;
}


#include <map>
#include <set>
#include <queue>
#include <ctime>
#include <cmath>
#include <string>
#include <cstdio>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;

#define all(a) a.begin(),a.end()
#define clr(a) memset(a,0,sizeof(a))
#define fill(a,b) memset(a,b,sizeof(a))
#define pb push_back
#define mp make_pair

typedef long long LL;
typedef vector<int> VI;
typedef pair<int,int> PII;
typedef vector<pair<int,int> > VII;

const double eps = 1e-8;
const double pi = acos(-1.0);

long double jc[1000005];

double C(int m, int n){
	if(n<0 || m < n) return 0;
	double res = 1;
	for(int j=m;j>n;--j) res *= j*1.0/(m-j+1);
	return res;
}

int main(){
	int i, n, m;
	scanf("%d%d",&n,&m);
	//for(jc[0]=1,i=1;i<=1000000;++i) jc[i]=jc[i-1]*i;
	double ans = 0;
	for(i=1;i<=min(m,n);++i){
		ans +=   i*1.0/n * m * C(m-1, i-1)*C(m*n-m, n-i)/C(m*n,n);
	}
	/*

	(m-1)! (m*n-m)! n! (m*n-n)!

	(i-1)!(m-i)!(m*n-m-n+i)!(n-i)! (m*n)!
	*/

	printf("%.12f\n", ans);
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define MP make_pair
#define PB push_back
#define SIZ(x) ((int)x.size())
#define SET(x,k) memset(x,k,sizeof(x))
#define REP(i,a,n) for (int i=(a);i<(n);++i)
#define PER(i,a,n) for (int i=(n)-1;i>=(a);--i)

typedef long long LL;
typedef double DB;
typedef pair <int, int> PII;

inline int read() {
	int f=1,x=0;
	char ch=getchar();
	while (ch<'0'||ch>'9') f=(ch=='-')?-1:1,ch=getchar();
	while (ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
	return f*x;
}

const int MAXN=1e6+5;

int n,m;
map<int,int> fac;
int mindiv[MAXN];

void add(int k,int o) {
	while (mindiv[k]) {
		int f=mindiv[k];
		k/=f,fac[f]+=o;
	}
}

void addC(int n,int m,int o) {
	REP (i,m+1,n+1) add(i,1*o);
	REP (i,2,n-m+1) add(i,-1*o);
}

bool notP[MAXN];
int p[MAXN],tot;

void init() {
	REP (i,2,MAXN) {
		if (!notP[i]) p[tot++]=i,mindiv[i]=i;
		REP (j,0,tot) {
			int k=p[j]*i;
			if (k>=MAXN) break;
			mindiv[k]=p[j],notP[k]=1;
			if (i%p[j]==0) break;
		}
	}
}

int main() {
	init();
	n=read(),m=read();

	if (n==0||m==0) {
		puts("0");
		return 0;
	}

	add(n,1),add(m,1),addC(n*m-1,n-1,1);
	add(n,-1),add(n,-1),addC(n*m,n,-1);
	double ans1=1;
	map<int,int>::iterator it=fac.begin();
	while (it!=fac.end()) {
		int i=(*it).first,k=(*it).second;
		if (k>0) {
			while (k--) ans1*=i;
		} else if (k<0) {
			while (k++) ans1/=i;
		}
		++it;
	}

	fac.clear();
	double ans2=1;
	if (n>=2&&n*m-2>0) {
		add(2,1),add(m,1),addC(m,2,1),addC(n*m-2,n-2,1);
		add(n,-1),add(n,-1),addC(n*m,n,-1);
		it=fac.begin();
		while (it!=fac.end()) {
			int i=(*it).first,k=(*it).second;
			if (k>0) {
				while (k--) ans2*=i;
			} else if (k<0) {
				while (k++) ans2/=i;
			}
			++it;
		}
	} else ans2=0;
	printf("%.7f\n",ans1+ans2);
	return 0;
}


#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <memory.h>
#include <stack>
#include <fstream>
#include <cstdio>
#include <unordered_map>
#include <map>
#include <list>
#include <queue>
#include <set>
using namespace std;

/*
*/

double C(int n, int c)
{
	if (n < c) return 0.0;
	double res = 1;
	for (int i = n; i > c; i--)
	{
		res *= i;
		res /= (i-(c));
	}
	return res;
}

int main()
{
	int n, m;
	cin>>n>>m;
	double sampleSpace = C(n*m-1, n-1);
	double res = 0;
	for (int i = 1; i <= n; i++)
	{
		res += ((i / (double)(n)) * C(m-1, i-1) * C(n*m-m, n-i)) / sampleSpace;
	}
	cout<<fixed<<setprecision(13)<<res<<endl;
}


#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(false);cout.tie(0);cin.tie(0);
using namespace std;

double n, m, p;

double dp[1000][1000];
double prr;

double nCk(int n, int k) {
  if (dp[n][k] != 0) {
    return dp[n][k];
  }
  if (n == k || k == 0) {
    return dp[n][k] = prr;
  }
  return dp[n][k] = nCk(n-1, k-1)+nCk(n-1, k);
}

double prob(double j) {

  double pr = 1;
  for (double k = 0; k < j; k++) {
    pr *= (m-k)/(m*n-k);
  }
  double not_j = n*(m-1);
  for (double k = 0; k < m-j; k++) {
    pr *= (not_j-k)/(m*n-k-j);
  }
  return pr;
}

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

  for (double j = 1; j <= n; j++) {
    memset(dp, 0, sizeof(dp));
    prr = (j/n)*(j/n)*prob(j);
    p += nCk(n, j);
  }
  cout << fixed << setprecision(10) << n*p << "\n";
  return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(int argc, char const *argv[])
{
    freopen("input.txt","r",stdin);
    int n,u=0;
    cin>>(n);
    int a[n];
    cin>>(a[0]);
    if(a[0]>15){cout<<15;u++;}
    else {
        for(int i=1;i<n;i++){
        cin>>(a[i]);
        if(u==0 && a[i]-a[i-1]>15){
            cout<<(a[i-1]+15);
            u++;

        }
    }
    if(90-a[n-1]>15 && u==0){cout<<a[n-1]+15<<endl;u++;}
    }
    if(u==0)
        cout<<90;

    return 0;
}


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

int main()
{
    int n;
    int num[100];
    cin>>n;
    for(int i=1; i<=n; i++)
    {
        scanf("%d",&num[i]);
    }
    int sum,ck=1;
    if(n==1)
    {
        if(num[1]<=15)
        {
            cout<<num[1]+15;
        }
        else cout<<"15";
    }
    else
    {
        if(num[1]>15)
        {
            cout<<"15";
        }
        else
        {
            for(int i=1; i<n; i++)
            {
                sum=num[i]+15;
                if(sum<num[i+1])
                {
                    cout<<sum<<endl;
                    ck=0;
                    break;
                }
            }
            if(ck==1 && sum>90)
            {
                if(num[n]==90) cout<<num[n];
                else
                {
                    cout<<"90";
                }

            }
            else if(ck==1) cout<<"90"<<endl;
        }

    }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define vi vector<int>
#define ll long long
vi arr;
int main()
{
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        int t;
        cin>>t;
        arr.push_back(t);
    }
    if(arr[0]>15)
    {
        cout<<15<<endl;
        return 0;
    }
    for(int i=1;i<arr.size();i++)
    {
        if(arr[i]-arr[i-1]>15)
        {
            if(arr[i-1]>85)cout<<arr[i-1]+90-arr[i-1]<<endl;
            else cout<<arr[i-1]+15<<endl;
            return 0;
        }
    }
    if(arr[n-1]<85)cout<<arr[n-1]+15<<endl;
    else cout<<90<<endl;
}


#include<iostream>
using namespace std;
int main()
{
	int n;
	int h;
	int cur = 0;
	int temp=0;
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> h;
		if (h - cur > 15) { temp += 15; break; }
		temp += h - cur;
		cur = h;

		if (h > 90)break;

	}
	cout << temp;
	return 0;

}


#include<bits/stdc++.h>

using namespace std;
char str[100];
bool isPal(int l,int r){
    bool ret=true;
    while(l<r){
        if(str[l]==str[r]){
            l++; r--;
            continue;
        }
        ret=false;
        break;
    }
    return ret;
}
int main(){
    //freopen("input.txt","r",stdin);
    scanf("%s",&str);
    int length=strlen(str)-1;
    if(length==0){
        printf("%s%s\n",str,str);
        return 0;
    }
    if(isPal(0,length)){
            if((length+1)%2==0){
                int mid=length/2;
                for(int i=0 ; i<=length ; i++){
                    if(i==mid+1)
                        printf("a");
                    printf("%c",str[i]);
                }
            }else
            printf("NA\n");
            return 0;
    }
    bool isUsed=false;
    bool x,y;
    int a,b;
    char p,q;
    for(int i=0,j=length ; i<j ; i++,j--){
        if(str[i]==str[j])
            continue;
        x=isPal(i,j-1);
        a=i;
        p=str[j];
        y=isPal(i+1,j);
        b=j;
        q=str[i];
        break;
    }
    if(x){
        for(int i=0 ; i<=length ; ){
            if(i==a){

                printf("%c%c",p,str[i]);
                i++;
            }
            else {
                printf("%c",str[i]);
                i++;
            }
        }
    }else if(y){
        for(int i=0 ; i<=length ; ){
            if(i==b){
                printf("%c%c",str[i],q);
                i++;
            }
            else {

                printf("%c",str[i]);
                i++;
            }
        }
    }else
        printf("NA\n");
    return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <vector>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>

#define oo 1e9
#define pi 3.1415926536
#define all(x) x.begin(),x.end()
#define sorta(x) sort(all(x))
#define sortam(x,comp) sort(all(x),comp)
#define sortd(x) sort(x.rbegin(),x.rend())
#define pb push_back
#define mp make_pair

typedef long long ll;
using namespace std;

int main() {
    string s;
    while(cin >> s) {
        int t = 0;
        for(int i = 0; i < s.size(); i++) {
            if(s[i] != s[s.size() - i - 1]) {
                if(s[i+1]==s[s.size()-i-1]) s.insert(s.size() - i, 1, s[i]);
                else s.insert(i, 1, s[s.size() - i - 1]);
                t++;
            }
        }
        if(t>1) s = "NA";
        if(!t) s.insert(s.size() / 2, 1, s[s.size()/2]);

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


#include <algorithm>
#include <cmath>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>
#include <utility>

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

using namespace std;

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

  int start = 0;
  int end = s.size() - 1;
  bool inserted = false;
  while (start < end) {
    if (s[start] != s[end]) {
      if (!inserted) {
        if (s[start+1] == s[end]) {
          s.insert(s.end() - start, s[start]);
        } else {
          s.insert(s.begin() + start, s[end]);
        }
        inserted = true;
        ++end;
      } else {
        cout << "NA" << endl;
        return 0;
      }
    }
    ++start;
    --end;
  }

  if (!inserted) {
    s.insert(s.begin() + s.size() / 2, 'a');
  }
  cout << s << endl;
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main()
{

    string s;
    string s1;
    char c;
    int i;
    int j;
    int k;
    int flag;
    flag = 0;
    string s2,s3,s4,s5;
    string::iterator it;
    cin>>s;

    for(i = 0; i < s.size();i++) {
        s1 = s;
        c = s[i];
        if(s.size() % 2 == 0) {
            it = s.begin()+s.size()-i;
        }
        else {

         it = s.begin()+s.size()-i-1;
        }

        s1.erase(s1.begin()+i);
        s2 = s1;
        reverse(s2.begin(),s2.end());
        if(s1 == s2) {
            s.insert(it,c);
            flag = 1;
            break;

        }
    }
    if(flag == 0) {
        cout<<"NA";
    }
    else {
        cout<<s;
    }
}


#include<iostream>
#include<string>
using namespace std;
int a,x,y,k,r,l;
struct cor{
    float y1,y2;
};
cor b;
int main(){
    cin>>a>>x>>y;
    k=1;
    r=1;
    l=1;
    b.y1=0;
    b.y2=a;
    while (b.y2<y)
    {
        if (l%2==1)k++; else k+=2;
        l++;
        b.y1+=a; b.y2+=a;
    }
    if (x==a || x==-a || y==b.y1 || y==b.y2 || x==(float)((float)a/2.) || x==(float)(-((float)a/2.)) || x>a || x<-a) {cout<<-1<<endl;} else
    {
        if (l%2)
        {
            if (x==0) cout<<-1<<endl; else
            {
            if (x>0) cout<<k<<endl;
            else
                cout<<k-1<<endl;
            }
        } else
            cout<<k<<endl;
    }
}


#include <iostream>
#include <cstdio>
#include <stdlib.h>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <utility>

#define pb push_back
#define mp make_pair

using namespace std;

#define eps 1e-7

int main() {
	//freopen("input.txt","rt",stdin);
	//freopen("output.txt","wt",stdout);
	int a,x,y,ans;
	cin >> a >> x >> y;
	if(y<0)
	{
		cout << "-1";
		return 0;
	}
	if(abs(x)<a)
		if(y%a!=0)
		{
			y=floor((double)y/(double)a);
			if(y==0)
			{
				cout << 1;
				return 0;
			}
			if((y%2==1)&&(abs((double)x)+eps<((double)a/(double)2)))
			{
				cout << (((y-3)/2)*3+5);
				return 0;
			}
			else
			{
				ans=(((y-4)/2)*3+5);
				if(x<0) ans++;
				if(x>0) ans+=2;
				if(x==0)
				{
					cout << "-1";
					return 0;
				}
				cout << ans;
				return 0;
			}
		}
	cout << "-1";
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<math.h>
#include<vector>
using namespace std;
int a, x, y;

struct row_square
{
    float left_min, left_max, ri8_min, ri8_max, mid_min, mid_max;
    int left_number, ri8_number, mid_number;
};
row_square rows[10000001];
void row_width_calculate(){
    rows[1].mid_min = -((float)a / 2);
    rows[1].mid_max = ((float)a / 2);
    int count = 1;
    while (count<=1000000)
    {
        if (count % 2 == 0)
        {
            rows[count + 1].left_min = -a;
            rows[count + 1].left_max = 0;
            rows[count + 1].ri8_min = 0;
            rows[count + 1].ri8_max = a;
        }
        else
        {
            rows[count + 1].mid_min = -((float)a / 2);
            rows[count + 1].mid_max = ((float)a / 2);;
        }
        count++;
    }
}
void number_calculate_odd(int row){
    rows[row].left_number = (row / 2) * 3;
    rows[row].ri8_number = (row / 2) * 3 + 1;
}
void number_calculate_even(int row){
    int d = row - 1;
    rows[row].mid_number = row / 2 + d;
}
int main(){
   // freopen("input.txt","r",stdin);
    scanf("%d %d %d",&a,&x,&y);
    if (y%a == 0){
        printf("-1\n");
    }
    else{
        int row = (ceil)((double)y / a);
        row_width_calculate();
        if (row % 2 == 0){
            number_calculate_even(row);
            if (x > rows[row].mid_min&&x < rows[row].mid_max)
                printf("%d\n",rows[row].mid_number);
            else
                printf("-1\n");
        }
        else{
            if (row == 1){
                rows[1].mid_number = 1;
                if (x > rows[1].mid_min&&x < rows[1].mid_max)
                    printf("1\n");
                else
                    printf("-1\n");
            }
            else{
                number_calculate_odd(row);
                if (x > rows[row].left_min&&x < rows[row].left_max)
                {
                    printf("%d\n", rows[row].left_number);
                }
                else if (x> rows[row].ri8_min&&x < rows[row].ri8_max){
                    printf("%d\n", rows[row].ri8_number);
                }
                else
                {
                    printf("-1\n");
                }
            }
        }
    }
}


#include <cstring>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <queue>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <memory.h>
#include <cassert>

using namespace std;
#ifdef _WIN32
#define lld "%I64d"
#else
#define lld "%lld"
#endif

#define ll long long
#define len(x)  ((int)x.size())
#define fe(a,b) for(typeof((b).begin()) a=(b).begin();a!=(b).end();++a)
#define fi first
#define se second
#define pb push_back
#define clr(a, x)   memset(a, x, sizeof(a))
#define pii pair<int,int>
#define all(x)  x.begin(),x.end()

const int NN = 1e5 + 1000;
const int mod = 1e9 + 7;
int n, k, d;
int dp[111][111][2];
int go(int p,int sum,int dd) {
  if(sum == n) {
    return (dd);
  }
  if(~dp[p][sum][dd]) {
    return dp[p][sum][dd];
  }
  int ret=0;
  for(int i=1 ; i<=k ; i++) {
    if(dd == 1)
      ret = ret + go(p+1, sum + i, 1);
    else if(i >= d)
      ret = ret + go(p+1, sum + i, 1);
    else
      ret = ret + go(p+1, sum + i, 0);
    ret = ret % mod;
  }
  return dp[p][sum][dd] = ret % mod;
}
int main() {
  clr(dp, -1);
  cin >> n >> k >> d;
  cout << go(1, 0, 0) << endl;
  return 0;
}


//Codeforces 247C - k-Tree
#include <iostream>
#include <algorithm>
using namespace std;

long long dp[7000000][2];
long long n,k,d;

long long numroot(long long sum, int havemin){

	if((sum == n) && (havemin==1)) return 1;
	if((sum == n) && (havemin==0)) return 0;
	if(sum > n) return 0;

	if(sum < 7000000){
		if(dp[sum][havemin] > 0) return dp[sum][havemin];
	}

	long long tc = 0;

	for(int i = 1; i<=k; i++){
		if(i>=d){
			tc = (tc + numroot(sum+i, 1)) % 1000000007;
		} else {
			tc = (tc + numroot(sum+i, havemin)) % 1000000007;
		}
	}

	if(sum < 7000000) dp[sum][havemin] = tc;
	return tc;
}

int main(){

	fill(&dp[0][0],&dp[0][0] + sizeof(dp)/sizeof(dp[0][0]),0);

	cin >> n >> k >> d;

	cout << numroot(0,0) << endl;

return 0;}


//Codeforces 247C - k-Tree
#include <iostream>
#include <algorithm>
using namespace std;

long long dp[2000000][2];
long long n,k,d;

long long numroot(long long sum, int havemin){

	if((sum == n) && (havemin==1)) return 1;
	if((sum == n) && (havemin==0)) return 0;
	if(sum > n) return 0;

	if(sum < 2000000){
		if(dp[sum][havemin] > 0) return dp[sum][havemin];
	}

	long long tc = 0;

	for(int i = 1; i<=k; i++){
		if(i>=d){
			tc = (tc + numroot(sum+i, 1)) % 1000000007;
		} else {
			tc = (tc + numroot(sum+i, havemin)) % 1000000007;
		}
	}

	if(sum < 2000000) dp[sum][havemin] = tc;
	return tc;
}

int main(){

	fill(&dp[0][0],&dp[0][0] + sizeof(dp)/sizeof(dp[0][0]),0);

	cin >> n >> k >> d;

	cout << numroot(0,0) << endl;

return 0;}


#include<bits/stdc++.h>
#define int long long
using namespace std;
inline int read()
{
    int n = 0 , c = 0, m;
    while (!isdigit(c)) m = c - 45 ? 1 : -1 , c = getchar();
    while (isdigit(c))  n = n * 10 + c - 48 , c = getchar();
    return m * n;
}
int a[101];
main()
{
    int n = read() , k = read() , M = read();
    int sum = 0;
    for(int i = 1; i <= k; i ++){
        a[i] = read();
        sum += a[i];
    }
    int T = M;
    if(T >= sum * n)
    {
        return cout << n * (k + 1) , 0;
    }

    sort(a + 1 , a + k + 1);
    int ans = 0;
    bool ok = 1;

    for(int i = 1; i <= k; i ++){
        int t = min(M , n * a[i]);
        ans += t / a[i];
        M -= t;
    }

    int ans2 = T / sum * (k + 1);
    int s = T / sum;
    T %= sum;
    for(int i = 1; i <= k; i ++){
        int t = min(T , (n - s) * a[i]);
        ans2 += t / a[i];
        T -= t;
    }

    cout << max(ans , ans2);
}


#include <bits/stdc++.h>

using namespace std;
long long a[100];
int main()
{
    bool b=0;
    long long n , k , m , ans=0 , ans1=0;
    cin>>n>>k>>m;
    int mm=m;
    for (int i=0 ; i<k ; i++)
        cin>>a[i];
    sort(a , a+k);
    for (int i=0 ; ; i++)
    {
        if (i==k)
        {
            ans++;
            i-=k;
        }
        if (m-a[i]>=0)
        {
            m-=a[i];
            ans++;
        }
        else break;
        if (ans>(k+1)*n) {
                ans=(k+1)*n;
        break;
        }
    }

    for (int i=0 ; i<k ; i++)
    {
        for (int j=0 ; j<n ; j++)
        {
            if (mm-a[i]>=0)
            {
                mm-=a[i];
                ans1++;
            }
            else
            {
                b=1;
                break;
            }
        }
        if (b==1) break;
    }
    cout <<max(ans , ans1)<<endl;
    return 0;
}


#include<iostream>
#include<map>
#include<utility>
#include<vector>
#include<algorithm>
#include<cmath>
#include<sstream>
#include<set>
#include<iomanip>

#define lli long long int

using namespace std;

bool comparable(pair<lli,lli> a, pair<lli,lli> b) { return a.first > b.first; }

int main()
{
    lli n, m, M;
    cin >> n >> m >> M;
    lli arr[m];
    for(lli i = 0; i < m; i++)
        cin >> arr[i];
    sort(arr, arr + m);
    lli sum[m];
    sum[0] = arr[0];
    for(lli i = 1; i <m; i++){
        sum[i] = arr[i] + sum[i - 1];
    }
    lli k = M / sum[m - 1];
    lli curr;

    if(k >= n){
        cout << n * (m + 1) << endl;
        return 0;
    }

    lli res = k * (1 + m);
    if(M%sum[m - 1] != 0){
        lli Q = M % sum[m - 1];
        lli i = 0;
        while(Q >= sum[i]){
            i++;
            res++;
        }
    }

    lli count = 0;
    lli i = 0;
    while(M > arr[i] && i < m){
        if(M >= arr[i] * n){
            count += n;
            if(i == m - 1)
                count += n;
            M -= arr[i] * n;
        }
        else{
            count += M / arr[i];
            if(i == m - 1)
                count += M / arr[i];
            M = M % arr[i];
        }
        i++;
    }
    cout << max(res, count) << endl;
    return 0;
}


#include <bits/stdc++.h>
#include <algorithm>
#define ll long long
#define ld long double
#define fir first
#define sec second
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    int n, k, M;
    cin >> n >> k >> M;
    vector <int> T(k+1,0);
    for(int i=0; i<k; i++)
        cin >> T[i];
    int ans=-1, t, cur; vector <int> V(n,-1);
    pair < pair <int,int> , vector <int> > r; priority_queue < pair < pair <int,int> , vector <int> > > Q;
    Q.push({{0,0},V});
    while(!Q.empty())
        {
            r=Q.top(), Q.pop();
            if(r.fir.sec>=ans)
                {
                    ans=r.fir.sec, t=(-1)*r.fir.fir, cur=k;
                    for(int i=0; i<n; i++)
                        if(r.sec[i]+1<=cur && t+T[r.sec[i]+1]<=M){
                            r.sec[i]++;
                            r.fir.fir-=T[r.sec[i]];
                            r.fir.sec++;
                            Q.push(r);
                            r.fir.sec--;
                            r.fir.fir+=T[r.sec[i]];
                            r.sec[i]--;
                            cur=min(cur,r.sec[i]);
                        }
                }
        }
    cout << ans <<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int N=100001;
int dp[50][N];
int n;
int a[50];
int val;
int DP(int i,int w){
    if(i==n)return 0;
    if(dp[i][w]!=-1)return dp[i][w];
    int p1=0,p2=0;
    if(w+a[i]<=val)p1=a[i]+DP(i+1,w+a[i]);
    p2=DP(i+1,w);
    return dp[i][w]=max(p1,p2);
}
int main(){
    scanf("%d",&n);
     int sum=0;
    memset(dp,-1,sizeof dp);
    for(int i=0;i<n;i++){
        scanf("%d",&a[i]);
        sum+=a[i];
    }
    val=sum/2;
    int ans=DP(0,0);
    printf("%d %d\n",ans,sum-ans);
}


    /*
Nahid Hossain
Jahangirnagar University
Roll:54
*/
#include<bits/stdc++.h>
#define ll          long long int
#define db          double
#define pf          printf
#define sf          scanf
#define ff          first
#define ss          second
#define clr         clear()
#define sz          size()
#define pb          push_back
#define mk          make_pair
#define pi          acos(-1)
#define inf         123456789
#define mod         1000000007
#define ull         unsigned long long int
#define f(i,k,n)    for(i=k;i<n;i++)
#define fr(i,n,k)   for(i=n;i>=k;i--)
#define ent(a)      scanf("%lld",&a)
#define ent2(a,b)   scanf("%lld%lld",&a,&b)
#define ent3(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define mem(a)      memset(a,0,sizeof(a))
#define vec(v,s)    vector<ll>v[s]
#define arr(a,s)    ll a[s];
//#define check(n,pos) (n&(1<<pos))
//#define set(n,pos)  (n|(1<<pos))
//knight and king//
int dr[]={2,2,-2,-2,1,-1,1,-1};
int dc[]={1,-1,1,-1,2,2,-2,-2};
int dr1[]={0,0,1,1,1,-1,-1,-1};
int dc1[]={1,-1,1,0,-1,0,1,-1};
int dr2[]={0,0,1,-1};
int dc2[]={1,-1,0,0};
////////////////////////////
using namespace std;
#define mx 100002
ll dp[55][100002],n,pre[55],a[55],dp1[5000000];
ll sum(ll ind,ll dif)
{
    if(ind>n)
        return dif;
        if(dp[ind][dif]!=-1)
            return dp[ind][dif];
    ll r;
    ll a1=sum(ind+1,dif+a[ind]);
    ll b=sum(ind+1,abs(dif-a[ind]));
    r=min(a1,b);
    dp[ind][dif]=r;
    return r;
}
int main()
{
    ll i,ans,s,ans1;
    while(cin>>n)
    {
        s=0;
        for(i=1;i<=n;i++)
        {
            cin>>a[i];
            s+=a[i];
        }
            memset(dp,-1,sizeof(dp));
            ll ans=sum(1,0);
            s-=ans;
            cout<<s/2<<" "<<(s/2)+ans<<endl;
    }
    return 0;

}


#include <bits/stdc++.h>

using namespace std;
#define int long long
int pd[51][50111];

int v[55];
int n;
int f(int i, int gap){
  if(gap <= 0 || i == n){
    return 0;
  }

  if(pd[i][gap] != -1){
    return pd[i][gap];
  }
  int ans = 0;
  if(gap - v[i] >= 0){
    ans = f(i + 1, gap - v[i]) + v[i];
    ans = max(ans, f(i + 1, gap));
  }

  return pd[i][gap] = ans;
}

int32_t main()
{
  scanf("%lld",&n);
  int sum = 0;
  for(int i = 0; i < n; i++){
    scanf("%d",&v[i]);
    sum += v[i];
  }
  memset(pd,-1,sizeof pd);
  int x = f(0,sum / 2);
  printf("%lld %lld\n",x, sum - x);

  return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ll i,j,k=0,l,n,m;
    cin>>n;
    ll a[n];
    for(i=0;i<n;i++)
        cin>>a[i];
    ll p,q;
    p=n-1;
    q=n-2;
    ll ans1=0,ans2=0;
    sort(a,a+n);
    while(p>=0)
    {
        if(ans1>=ans2)
        {
            ans2+=a[p];
            p--;
            q--;
        }
        else
        {
            ans1+=a[p];
            p--,q--;
        }
    }
    if(ans1>=ans2)
        cout<<ans2<<" "<<ans1;
    else
        cout<<ans1<<" "<<ans2;

}


#include <stdio.h>
int main ()
{
    int a,b,c,d,e,f;
    while (scanf ("%d%d%d%d",&a,&b,&c,&d)!= EOF)
    {
        e= a-((a/250)*c);
        f= b-((b/250)*d);
        if (e>f)
        {
            printf ("Misha\n");
        }
        else if (e<f)
        {
            printf ("Vasya\n");
        }
        else
        {
            printf ("Tie\n");
        }
    }
    return 0;

}


#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
void count(){
    #ifndef ONLINE_JUDGE
        freopen ("input.txt", "r", stdin);
    #endif
}
main(){
    count();
    double a,b,c,d,s,t;
    cin >> a >> b >> c >> d;
    if(a == b && a > 250){
        cout << "Tie" << endl;
        return 0;
    }
    s = max((3*a)/10,a-a/250*c);
    t = max((3*b)/10,b-b/250*d);
    if(s>t) cout << "Misha";
    else if(s<t) cout <<"Vasya";
    else cout<<"Tie";
    exit(0);

}