#include <bits/stdc++.h>

using namespace std;

int t,n,Max;

int main()
{
    cin >> n;

    for(int i = 0; i < n; i++)
    {
        cin >> t;
        Max = Max < t ? t : Max;
    }
    cout << Max < 25 ? 0 : (Max-25) ;
}


/***    author:  zxwsbg    ***/
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
using namespace std;

#define INIT(x) memset(x,0,sizeof(x))
#define eps 1e-8
#define next next_
typedef long long ll;
typedef unsigned long long ull;
const ll IINF = 9223372036854775807;
const int INF = 0x7fffffff;
const int inf = 0x3f3f3f3f;
const int maxn = 200005;
const int N = 105;

inline void read(int &x) {
    int f=1;x=0;char s=getchar();
    while(s<'0'||s>'9'){if(s=='-')f=-1;s=getchar();}
    while(s>='0'&&s<='9'){x=x*10+s-'0';s=getchar();}
    x*=f;
}

int n,m,a[maxn],sum;

bool check(int x) {
	 int res = 0;
	 for(int i=0;i<n;i++) {
	 	res += max(0,a[i]-i/x);
	 }
	 return res>=m;
}

int main() {
	read(n), read(m);
	for(int i=0;i<n;i++) {
		read(a[i]);
		sum += a[i];
	}
	//sort(a,a+n,greater<int>());
	if(sum<m) {
		cout<<-1<<endl;
		return 0;
	}
	int l=0,r=n;
	while(l<r-1) {
		int mid = (l+r) / 2;
		if(check(mid)) r = mid;
		else l = mid;
	}
	cout<<r<<endl;
	return 0;
}


#include <iostream>
using namespace std;
int main(){
	long long int a,b,c;
	cin>>a>>b>>c;
	if((b-a)%c==0)cout<<"YES";
	else cout<<"NO";
}


#include<bits/stdc++.h>
using namespace std;
const int N=10001;
const int mod=1e9+7;
long long int C[N][N];
void build()
{
	int i,j;
	for(i=0;i<N;++i)		C[i][0]=1;
	for(i=0;i<N;++i)		C[i][i]=1;
	for(j=1;j<N;++j)
		for(i=j+1;i<N;++i)
			C[i][j]=(C[i-1][j-1]+C[i-1][j])%mod;
}
int num(int r,int b,int k)
{
	if(b==0) 			return 1;
	int ans=0,u;
	for(u=1;u<=r+1&&(k==0||u<=(b-1)/k);++u)
	{
		ans+=1ll*C[r+1][u]*C[b-k*u-1][u-1]%mod;
		ans%=mod;
	}
	return ans;
}
long long int binpow(long long int x,long long int pow)
{
	if(pow==0)			return 1LL;
	if(pow==1)			return x;
	if(pow%2==0)		return binpow((x*x)%mod,pow/2)%mod;
	if(pow%2==1)
	{
		long long int k=x;
		return k%mod*binpow((x*x)%mod,pow/2)%mod;
	}
}
int main ()
{
	build();
	int f,w,h;
	scanf("%d %d %d",&f,&w,&h);
	int sn=num(f,w,h);
	int sd=C[f+w][w];
	printf("%I64d",1LL*sn*binpow(sd,mod-2)%mod);
	return 0;
}


#include <stdio.h>
#include <algorithm>

using namespace std;

#define N 102

int main()
{
    int n, d, m;

    scanf ("%d%d", &n, &d);
    int price[N] = {0};
    for (int i = 1; i <= n; i++)
    {
        scanf ("%d", &price[i]);
    }
    sort (price, price + n + 1);
    for (i = 1; i <= n; i++)
    {
        price[i] += price[i - 1];
    }
    scanf ("%d", &m);
    int benfit = (m > n) ? price[n] - (m - n) * d : price[m];
    printf ("%d\n", benfit);
    return 0;
}


#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<iostream>
using namespace std;
typedef long long LL;
const int M=1000000007;

LL fpw(LL a,LL b)
{
	LL s=1;
	for(a%=M;b;b>>=1,a=a*a%M)
		if(b&1)s=s*a%M;
	return s;
}

struct num
{
	LL r,i;

	num(const LL &_r=0,const LL &_i=0):r(_r),i(_i){}
	num operator+(const num &o)const
	{return num((r+o.r)%M,(i+o.i)%M);}
	num operator-(const num &o)const
	{return num((r-o.r)%M,(i-o.i)%M);}
	num operator*(const num &o)const
	{return num((r*o.r+5LL*i*o.i)%M,(r*o.i+i*o.r)%M);}
	num operator/(const num &o)const
	{
		LL d=(o.r*o.r-5LL*o.i*o.i)%M;
		d=fpw(d,M-2);
		num t((r*o.r-5LL*i*o.i)%M,(i*o.r-r*o.i)%M);
		t.r=t.r*d%M;
		t.i=t.i*d%M;
		return t;
	}
	void mod()
	{r=(r%M+M)%M;i=(i%M+M)%M;}
};

num fpw(num a,LL b)
{
	num s(1,0);
	for(;b;b>>=1,a=a*a)
		if(b&1)s=s*a;
	return s;
}

LL K,L,R;
LL comb[205][205];
LL work(int k)
{
	num a=num(1,1)/num(2,0),b=num(1,-1)/num(2,0),c0=fpw(num(1,0)/num(0,1),k);
	num res(0,0),t,w;
	for(int i=0;i<=k;i++)
	{
		t=num(comb[k][i],0);
		t=t*c0;
		w=fpw(a,i)*fpw(b,k-i);
		w.mod();
		num t1=(fpw(w,R+1)-fpw(w,L));
		num t2=(w-num(1,0));
		num t3=t1/t2;
		if(w.r==1LL&&w.i==0LL)w=num((R-L+1)%M,0);
		else w=(fpw(w,R+1)-fpw(w,L))/(w-num(1,0));
		t=t*w;
		if(k-i&1)res=res-t;
		else res=res+t;
	}
	return res.r;
}

vector<LL> xs,xs_;

int main()
{
	//freopen("a.in","r",stdin);
	//freopen("a.out","w",stdout);
	for(int i=comb[0][0]=1;i<=200;i++)
		for(int j=comb[i][0]=1;j<=i;j++)
			comb[i][j]=(comb[i-1][j]+comb[i-1][j-1])%M;
	cin>>K>>L>>R;L+=2,R+=2;
	LL d=1;
	for(int i=1;i<=K;i++)
		d=d*fpw(LL(i),LL(M-2))%M;
	xs.push_back(d);
	for(int i=0;i<K;i++)
	{
		xs_.resize(xs.size()+1,0);
		for(int j=0;j<xs.size();j++)
		{
			xs_[j]+=(-i)*xs[j];
			xs_[j+1]+=xs[j];
		}
		xs.resize(xs.size()+1,0);
		for(int j=0;j<xs.size();j++)
			xs[j]=xs_[j]%M;
	}
	LL ans=0;
	for(int i=0;i<xs.size();i++)
		ans=(ans+xs[i]*work(i))%M;
	ans=(ans+M)%M;
	cout<<ans<<endl;
	return 0;
}


#include <iostream>
#include <algorithm>

using namespace std;

long double pi = atan((long double)1)*4;

class Point
{
public:
	long double x;
	long double y;
	Point(long double xi, long double yi)
	{
		x=xi;
		y=yi;
	};
	Point()
	{
	};
};

class Segment
{
public:
	Point p1;
	Point p2;
	Segment(Point p1i, Point p2i)
	{
		p1.x=p1i.x;
		p1.y=p1i.y;
		p2.x=p2i.x;
		p2.y=p2i.y;
	};
	long double length()
	{
		return sqrt( (p1.x-p2.x)*(p1.x-p2.x) + (p1.y-p2.y)*(p1.y-p2.y) );
	}
};

void pos_circle(Point p, long double v, long double t, Point* final_p)
{
	long double R = sqrt((long double)(p.x*p.x+p.y*p.y));
	long double time_360 = 2*pi*R/v;
	long double ini_angle = atan2((long double)p.y,(long double)p.x) *180 /pi;
	long double final_angle = t*2*pi/time_360;

	final_p->x=cos(final_angle)*R;
	final_p->y=sin(final_angle)*R;
}

long double distance_to_segment (Point p, Segment seg)
{
	Segment a(seg.p1, p);
	Segment b(seg.p2, p);
	Segment* max;
	Segment* min;
	if(a.length() > b.length())
	{
		max = &a;
		min = &b;
	}
	else
	{
		max = &b;
		min = &a;
	}

	if(seg.length()==0 || min->length()==0)
		return min->length();

	if ((min->length() * min->length() + seg.length() * seg.length() - max->length() * max->length()) / (2*min->length()*seg.length()) < 0)
		return min->length();

	long double s = (a.length() + b.length() + seg.length())/2;
	return 2 * sqrt( s * ( s - a.length() ) * (s - b.length() ) * (s - seg.length() ) ) / seg.length();

}

void tangent_points_to_circle(Point center, long double R, Point p, Point* p1, Point* p2)
{
	Segment s(center, p);
	if( s.length() <= R)
		return;
	else
	{
		long double ini_angle = atan2(p.y - center.y , p.x - center.x);
		long double final_angle1 = ini_angle + acos(R/s.length()) ;
		long double final_angle2 = ini_angle - acos(R/s.length()) ;
		p1->x=cos(final_angle1)*R + center.x;
		p1->y=sin(final_angle1)*R + center.y;
		p2->x=cos(final_angle2)*R + center.x;
		p2->y=sin(final_angle2)*R + center.y;
	}
}

int main()
{
	cout.precision(20);
	int xp,yp,vp, xs,ys,V, R;

	cin >> xp;
	cin >> yp;
	cin >> vp;
	cin >> xs;
	cin >> ys;
	cin >> V;
	cin >> R;

	Point ini_perse(xp,yp);
	Point perse(0,0);
	Point center(0,0);
	Point ship(xs,ys);
	long double time = 0;
	long double time_ship = 0;
	long double range_min,range_max;

	if(ini_perse.x == ship.x && ini_perse.y == ship.y)
		cout << time;

	time = 100;

	while(true)
	{
		pos_circle(ini_perse,vp,time,&perse);
		Segment s(perse, ship);
		long double distance = distance_to_segment(center, s);
		if(distance >= R)
			time_ship =  s.length()/V;
		else
		{
			Point ship_tang1, ship_tang2, perse_tang1, perse_tang2;
			tangent_points_to_circle(center, R, ship, &ship_tang1, &ship_tang2);
			tangent_points_to_circle(center, R, perse, &perse_tang1, &perse_tang2);
			Segment route1_ship(ship, ship_tang1);
			Segment route2_ship(ship, ship_tang2);
			Segment route1_perse(perse_tang2, perse);
			Segment route2_perse(perse_tang1, perse);

			long double distance1 = route1_ship.length() + abs(atan2(ship_tang1.y, ship_tang1.x) - atan2(perse_tang2.y, perse_tang2.x))*2*R + route1_perse.length();
			long double distance2 = route2_ship.length() + abs(atan2(ship_tang2.y, ship_tang2.x) - atan2(perse_tang1.y, perse_tang1.x))*2*R + route2_perse.length();
			time_ship = min(distance1, distance2)/V;
		}
		if( time_ship < time )
			break;
		else
			time *= 2;
	}

	range_max = time;
	range_min = 0 ;

	while(true)
	{
		time = (range_max + range_min ) / 2;
		//time = 9.584544103;
		pos_circle(ini_perse,vp,time,&perse);
		Segment s(perse, ship);
		long double distance = distance_to_segment(center, s);
		if(distance >= R)
			time_ship =  s.length()/V;
		else
		{
			Point ship_tang1, ship_tang2, perse_tang1, perse_tang2;
			tangent_points_to_circle(center, R, ship, &ship_tang1, &ship_tang2);
			tangent_points_to_circle(center, R, perse, &perse_tang1, &perse_tang2);
			Segment route1_ship(ship, ship_tang1);
			Segment route2_ship(ship, ship_tang2);
			Segment route1_perse(perse_tang2, perse);
			Segment route2_perse(perse_tang1, perse);

			long double distance1 = route1_ship.length() + abs(atan2(ship_tang1.y, ship_tang1.x) - atan2(perse_tang2.y, perse_tang2.x))*R + route1_perse.length();
			long double distance2 = route2_ship.length() + abs(atan2(ship_tang2.y, ship_tang2.x) - atan2(perse_tang1.y, perse_tang1.x))*R + route2_perse.length();
			time_ship = min(distance1,distance2)/V;
		}

		if(abs(time-time_ship)<0.0000000001)
			break;

		if(time_ship < time)
			range_max = time;
		else
			range_min = time;
	}
	cout << time;
	return 0;
}


#include <iostream>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <cstdio>
#include <ctime>
using namespace std;
#define START clock_t _clock = clock();
#define END cerr << endl << "time: " << (clock() - _clock) / LD(CLOCKS_PER_SEC) << endl;
typedef long double LD;
typedef long long LL;

const LD pi = acos(-1.0);
const LD eps = 1e-9;
LD xp, yp, vp, xs, ys, v, r;

LD sqr(LD x)
{
    return x * x;
}

LD mmax(LD x, LD y)
{
    return x > y ? x : y;
}

LD mmin(LD x, LD y)
{
    return x < y ? x : y;
}

LD distance(LD x1, LD y1, LD x2, LD y2)
{
    return sqrt( LD(sqr(x1 - x2) + sqr(y1 - y2)) );
}

LD cathetus(LD hyp, LD cath)
{
    return sqrt(sqr(hyp) - sqr(cath));
}

// в начале планета имеет угол atan(yp / xp)
// возвращает момент времени >= tm, когда планет будет иметь угол angle
LD ptime(LD angle, LD tm)
{
    // радиус обращения планеты
    LD R = distance(xp, yp, 0, 0);
    // начальный угол планеты
    LD pangle = atan2(yp, xp);
    if (pangle < 0)
        pangle += 2 * pi;
    // время достижения планетой угла angle
    LD res = ( angle + (angle < pangle ? 2 * pi : 0) - pangle) / vp * R;
    // время обращения планеты
    LD ptm = 2 * pi * R / vp;

    res += floor((res - ptm) / ptm) * ptm;
    while (res < tm)
        res += ptm;

    return res;
}

LD time(LD angle)
{
    // радиус обращения планеты
    LD R = distance(xp, yp, 0, 0);
    // место встречи планеты и корабля (D)
    LD xd = R * cos(angle);
    LD yd = R * sin(angle);

/*------------- придётся ли огибать звезду -----------------------------------*/
    bool intersect = false;

    // коэффициенты уравнения прямой
    LD A = ys - yd;
    LD B = xd - xs;
    LD C = xs * yd - xd * ys;
    // квадрат расстояния от центра окружности (0,0) до прямой SD
    LD sdist = sqr(C) / (sqr(A) + sqr(B));

    // если прямая и окружность пересекаются
    if (sdist <= sqr(r))
    {
        // коэффициенты квадратного уравнения персечения
        LD a = 1 + sqr(A / B);
        LD b = 2 * A * C / sqr(B);
        LD c = sqr(C / B) - sqr(r);
        LD discr = sqr(b) - 4 * a * c;
        // точки пересечения:
        LD x1 = (-b - sqrt(discr)) / (2 * a);
        LD x2 = (-b + sqrt(discr)) / (2 * a);
        // если отрезок и окружность пересекаются, то придётся огибать звезду
        if (min(xs, xd) <= x1 && x1 <= max(xs, xd) || min(xs, xd) <= x2 && x2 <= max(xs, xd))
            intersect = true;
    }
/*-----------------------------------------------------------------------------*/

    LD dist; // длина маршрута из точки S в точку D
    if (intersect)
    {
        LD a = distance(xs, ys, 0, 0);
        LD b = cathetus(a, r);  // расстояние до дуги

        LD c = distance(xd, yd, 0, 0);
        LD d = cathetus(c, r);  // расстояние после дуги

        LD e = distance(xs, ys, xd, yd);
        LD alpha = acos( (sqr(c) + sqr(a) - sqr(e)) / (2 * c * a) );
        LD alpha1 = atan2(d, r);
        LD alpha2 = atan2(b, r);

        LD phi = alpha - alpha1 - alpha2;
        LD arc = phi * r; // длина дуги

        // всё расстояние
        dist = b + arc + d;
    }
    else
        dist = distance(xs, ys, xd, yd);

    // время прибытия корабля в точку на орбите с углом angle:
    LD tm = dist / v;

    // время следующего прибытия планеты в эту же точку
    return ptime(angle, tm);
}

LD getminangle(LD left, LD right, LD step)
{
    LD  minangle = left,
        mintime = time(minangle);
    for (LD angle = left + step; angle < right; angle += step)
    {
        LD tm = time(angle);
        if (tm < mintime)
            mintime = tm,
            minangle = angle;
    }
    return minangle;
}

main()
{
    cin >> xp >> yp >> vp >> xs >> ys >> v >> r;

    const LD step = 0.00005;
    const LD u = 0.0008;
    const LD left = 0.0;
    const LD right = 2 * pi;

    // находим угол при котором значение функции time минимально на всём интервале углов
    LD a = getminangle(left, right, step);
    // находим минимальное время в окрестности угла a
    LD res = time(getminangle(mmax(left, a - u), mmin(right, a + u), eps));

    cout.setf(ios::fixed); cout.precision(8);

    cout << res << endl;
}
/*

Идея решения:

Возьмём произвольную точку на окружности (D), по которой обращается планета.
Определим расстояние от места старта корабля (S до этой точки.
Если на пути встетится окружность звезды, то придётся делать огибание,
в таком случае расстояние увеличится.

Теперь определим время (tm) прохождени корабля от S до D.

Результатом f(alpha) будет минимальное время, большее либо равное tm, при котором планета будет в точке D.

Ответом будет min(f(alpha)), которое можно найти тернарным поиском. alpha задаёт однозначное положение точки D.

*/


#include<iostream>
#include<algorithm>
#include<utility>
#include<cstring>
#include<cstdio>
#include<math.h>
#include<vector>
#include<set>
#include<cmath>
#include<stdlib.h>
#include<stdio.h>
#include<iomanip>
#include<string.h>
#include<map>
#include<stack>
#include<queue>
#include<unordered_map>
#include<numeric>
#define ll long long
typedef long double ld;
#define stt string
#define ve vector<ll>
#define se set<ll>
#include<unordered_set>
#include<array>
#define ar array
using namespace std;
   ll nn,m;
ll gcd(ll x, ll y)
{
    if(y==0)
        return x;
    return gcd(y,x%y);
}
bool sum(int n)
{
    unordered_map<int, int> s;
    for (int i = 1; i * i <= n; ++i) {
        s[i * i] = 1;
        if (s.find(n - i * i) != s.end() && ( sqrt(n-i*i)<=nn && i<=nn))
        {

            return true;
        }
    }
    return false;
}

bool isP(long double x)
{
  long double sr = sqrt(x);
  return ((sr - floor(sr)) == 0);
}
int main()
{
    ios::sync_with_stdio(false);
       cin.tie(0);
       cout.tie(0);
    cin>>nn>>m;
    if(m==1)
        cout<<nn*nn;
    else
    {
        ll x=nn*nn,ans=0;
          x=x+x;
        ve g;
        ll s=m;
        while(s<=x)
        {
            g.push_back(s);
            s+=m;
        }
        for(auto x:g)
        {

            if(sum(x))
            {
                x/=2;
                if(isP(x))
                    ans++;
                else
                    ans+=2;
            }
        }
        cout<<ans;

    }
}


#include <iostream>
using namespace std;

int main ()
{
   int x, t, a, b, da, db;
   int ta, tb, dbtb;
   cin >> x >> t >> a >> b >> da >> db;
   int c = a + b - x;
   bool p = false;
   if (x == 0)
      p = true;
   else if (a == x || b == x)
   {
      p = true;
   }
   else if ((x - a) % da == 0)
   {
      ta = (x - a) / da;
      if (ta < t && ta >= 0)
         p = true;
   }
   else if ((x - b) % db == 0)
   {
      tb = (x - b) / tb;
      if (tb < t && tb >= 0)
         p = true;
   }
   else if (c == 0)
      p = true;
   else
   {
      for (ta = 0; ta < t; ta++)
      {
         dbtb = c - da * ta;
         if (dbtb == 0)
         {
            p = true;
            break;
         }
         if (dbtb % db == 0)
         {
            tb = dbtb / db;
            if (tb >= 0 && tb < t)
            {
               p = true;
               break;
            }
         }
      }
   }
   if (p)
      cout << "YES";
   else
      cout << "NO";
   //cin.get ();
   //cin.get ();
   return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ull unsigned long long int
#define ll long long int
#define vi vector<int>
#define vvi vector<vector<int>>
#define pll pair<ll, ll>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vpll vector<pair<ll,ll>>
#define umap unordered_map
#define uset unordered_set
#define all(c) c.begin(), c.end()
#define maxarr(A) *max_element(A, A+n)
#define maxvec(v) *max_element(all(v))
#define present(map,elem) map.find(elem)!=map.end()
#define lb(v,elem) lower_bound(all(v),elem)
#define ub(v,elem) upper_bound(all(v),elem)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define For(i,a,b) for(int i=a; i<b; ++i)
#define rep(i,a,b) for(ll i=a; i<b; ++i)
#define debug(v) for(ll i=0; i<v.size(); i++) cout<<v[i]<<" "; cout<<endl;
#define debugn(v,n) for(ll i=0; i<n; i++) cout<<v[i]<<" "; cout<<endl;
#define mod 1000000007
#define INF (int)1e18
#define endl '\n'

bool cmp(pair<ll, char> p1, pair<ll,char>p2){
   return p1.ff>p2.ff;
}

ll binpow(ll a, ll b) {
	if (b == 0)
		return 1;
	ll res = binpow(a, b / 2);
	if (b % 2)
		return res * res * a;
	else
		return res * res;
}

const int MAX = (int)1e3 + 5;
vvi adj(MAX);

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  //freopen("1.in","r",stdin);
  int t=1;
  //cin>>t;
  while(t--){
  	 int x1,y1;
  	 cin>>x1>>y1;
  	 // -10 5
  	 // -5 10
  	 if(abs(x1)==abs(y1)){
  	 	if(x1>0 && y1>0){
  	 		cout<<0<<" "<<2*x1<<" "<<2*x1<<" "<<0;
  	 	}else if(x1>0 && y1<0){
  	 		cout<<0<<" "<<-2*x1<<" "<<2*x1<<" "<<0;
  	 	}else if(x1<0 && y1>0){
  	 		cout<<-2*x1<<" "<<0<<" "<<0<<" "<<2*x1;
  	 	}else{
  	 		cout<<0<<" "<<-2*x1<<" "<<-2*x1<<" "<<0;
  	 	}
  	 }
  	 int x2=y1*(y1/abs(y1))*(x1/abs(x1)), y2=x1*(x1/abs(x1))*(y1/abs(y1));
  	 //cout<<x2<<" "<<y2<<endl;
  	 int m = (y2-y1)/(x2-x1);
  	 //cout<<m<<endl;
  	 int y3 = y1 - m*x1;
  	 int x3=0, x4=(x1 - y1/m), y4=0;
  	 if(x3>x4) cout<<x4<<" 0 "<<"0 "<<y3;
  	 else cout<<x3<<" "<<y3<<" "<<x4<<" "<<y4<<endl;

  }
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

ll cuadrados(int s)
{
	if(s <= 0) return 1;
	return cuadrados(s-1) + 2*(s+1) + 2*(s-1);
}

ll triangulo(int l)
{
	if(l < 0) return 0;
	return max((ll)0 , (ll)l*l);
}
ll triangulo(int n, int i, int d)
{
	if(n < 0) return 0;
	i++; d++;
	d = min(d,n);
	i = min(i,n);
	return max((ll)0 , -(ll)n + (ll)n*(ll)d + (ll)n *(ll)i + ((ll)d + (ll)i - (ll)d*(ll)d - (ll)i*(ll)i)/(ll)2);
}

ll cuadrados(int &s, int &x, int &y, int &n)
{
	return cuadrados(s) - triangulo(s-abs(n-y)) - triangulo(s-y) - triangulo(s-x, y, n-y) - triangulo(s-abs(n-x),y,n-1);
}

int main() {

	int n, x, y;
	ll c;
	cin >> n >> x >> y >> c;

	x--; y--; n--;

	if(c <= 1)
	{
		cout << 0 << endl;
		return 0;
	}

	int izq = 0;
	int der = (2*(n+1))+1;
	int mid;

	while(izq != der)
	{
		mid = (izq + der+1)/2;
		if(cuadrados(mid, x, y, n) < c)
		{
			izq = mid;
		}
		else
		{
			der = mid-1;
		}
	}

	cout << izq+1 << endl;

	return 0;
}


#include <bits/stdc++.h>
using namespace std;
int n,x,i,r=1,a[2179];
int main(){
	cin>>n;
	for(i=2,x=n;i*i<=n;i++)for(;x%i==0;a[i]++,x/=i);
	if(x)a[x]++;
	for(i=2;i<2000;i++)if(a[i])r*=i;
	cout<<r<<" "<<(r<n)+ceil(log2(*max_element (a,a+2000)));
}


#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<stack>
#include<string.h>
#include<queue>
#include<algorithm>
//#include<windows.h>
#define N 10000
int a[N][N];
#include<math.h>
using namespace std;
int dp(int n,int m)
{
	if(n<=0||m<=0) return 0;
	return max(dp(n-1,m-2)+1,dp(n-2,m-1)+1);
}
int main()
{
	int ex,ne;
	while(scanf("%d%d",&ex,&ne)!=EOF)
	{
		int sum=0;
		sum=dp(ex,ne);
		printf("%d\n",sum);
	}
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <fstream>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <string>
#include <algorithm>
#include <set>
using namespace std;
//ifstream cin("bigwaLL.in");
//ofstream cout("bigwaLL.out");
typedef long long LL;
typedef long double LD;
LD eps = 1e-9;
const LD INF = 1e18;
int main()
{
    LL a, b;
    queue<pair<LL, LL> > q;
    queue<LL> g;
    cin >> a >> b;
    q.push(make_pair(a, b));
    g.push(0);
    LL res = 0;
    while (!q.empty())
    {
        pair<LL, LL> p = q.front();
        if (!p.first || !p.second)
        {
            res = max(res, g.front());
            g.pop();
            q.pop();
            continue;
        }
        q.push(make_pair(q.front().first - 2, q.front().second + 1));
        q.push(make_pair(q.front().first + 1, q.front().second - 2));
        q.pop();
        g.push(g.front() + 1);
        g.push(g.front() + 1);
        g.pop();
    }
    cout << res;
    return 0;
}


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

int main()
{
    string s;
    int n;
    cin>>n;
    char ch;
    for(int i=1;i<=n;i++)
    {
        cin>>ch;
        s=s+ch;
    }
    cin>>s;
    int c=0;
    string sc;
    for(int i=0;i<s.length()-1;i++)
    {
        if(s[i]==s[i+1])
        {
            c++;
            sc=sc+s[i];
            for(int j=i+2;j<s.length();j++)
            {
                sc=sc+s[j];
            }
            s=sc;
        }
        else
       sc=sc+s[i];
    }
    cout<<c;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pb push_back
#define F first
#define S second
#define mp make_pair
#define I insert

ll N=1e9+7;

ll power(ll a, ll b, ll mod){
	ll x = 1, y = a;
	while (b > 0){
		if (b%2){
			x = (x*y)%mod;
		}
		y = (y*y)%mod;
		b /= 2;
	}
	return x%mod;
}

map<string ,ll > M;ll fib[105];
void mpas(string s){
    ll a,b,c;string y;
    a=s.length();
    ll j=1;ll i,k;k=1;
    for(i=0;i<a;i++){
        for(j=i;j<a;j++){
            y=s.substr(i,j-i+1);
            if(M.count(y))continue;
            M[y]=k++;
        }
    }
}
ll dp[105][10005];
ll st[105][10005],en[105][10005];ll ns[105][10005];
//ll two[105];
ll nos(ll a,string s ){
	ll b,c,d,i,j,k,n,x;
    string p,q,r;
    b=M[s];if(ns[a][b]!=-1)return ns[a][b];
    d=0;d+=(nos(a-1,s)+nos(a-2,s))%N;c=s.size();
    for(i=1;i<=c-1;i++){
    	p=s.substr(0,i);q=s.substr(i,c-i);
    	d+=(nos(a-1,p)*nos(a-2,q))%N;d%=N;
    }
    return ns[a][b]=d;
}
ll sta(ll a,string s){
    ll b,c,d,i,j,k,n,x;
    string p,q,r;
    b=M[s];if(st[a][b]!=-1)return st[a][b];
    d=0;d+=(sta(a-1,s)*(power(2,fib[a-2],N)))%N;d%=N;c=s.size();d+=sta(a-2,s);d%=N;
    for(i=1;i<=c-1;i++){
    	p=s.substr(0,i);q=s.substr(i,c-i);
    	d+=(nos(a-1,p)*sta(a-2,q))%N;d%=N;
    }
    return st[a][b]=d;
}
ll end1(ll a,string s){
    ll b,c,d,i,j,k,n,x;
    string p,q,r;
    b=M[s];if(en[a][b]!=-1)return en[a][b];
    d=0;d+=(end1(a-2,s)*(power(2,fib[a-1],N)))%N;c=s.size();d%=N;d+=end1(a-1,s);d%=N;
    for(i=1;i<=c-1;i++){
    	p=s.substr(0,i);q=s.substr(i,c-i);
    	d+=(end1(a-1,p)*nos(a-2,q))%N;d%=N;
    }
    return en[a][b]=d;
}
ll fn(ll a,string s ){
   // cout<<a<<" "<<s<<"\n";
    ll b,c,d,i,j,k,n,x;
    string p,q,r;
    b=M[s];if(dp[a][b]!=-1)return dp[a][b];
    ll ans=0;ans+=((fn(a-1,s)*(power(2,fib[a-2],N)))%N+(fn(a-2,s)*(power(2,fib[a-1],N)))%N)%N;ans%=N;
    c=s.size();
    for(i=1;i<=c-1;i++){
        p=s.substr(0,i);q=s.substr(i,c-i);
        ans+=(end1(a-1,p)*sta(a-2,q))%N;ans%=N;
    }
    return dp[a][b]=ans;
}

int main() {
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    cout<<setprecision(25);
    ll a,b,c,d,i,j,k,n,x;
    string p,q,r,s;
    fib[0]=fib[1]=1;for(i=2;i<=100;i++)fib[i]=(fib[i-1]+fib[i-2])%(N-1);
    //a=1;for(i=1;i<=100;i++){a*=2;a%=M;two[i]=a;}two[0]=1;
    cin>>n>>x>>s;
    mpas(s);//map<string ,ll> :: iterator it;for(it=M.begin();it!=M.end();it++)cout<<(*it).F<<"-"<<(*it).S<<" ";
    for(i=0;i<105;i++)for(j=0;j<10005;j++)dp[i][j]=-1,st[i][j]=-1,en[i][j]=-1,ns[i][j]=-1;
    for(i=0;i<10005;i++)dp[0][i]=dp[1][i]=st[0][i]=en[1][i]=st[1][i]=en[0][i]=0,ns[0][i]=ns[1][i]=0;
    if(M.count("0"))dp[0][M["0"]]=1,st[0][M["0"]]=1,en[0][M["0"]]=1,ns[0][M["0"]]=1;if(M.count("1"))dp[1][M["1"]]=1,st[1][M["1"]]=1,en[1][M["1"]]=1,ns[1][M["1"]]=1;
//    cout<<x<<"\n";
    cout<<fn(x,s)<<"\n";
    //for(i=0;i<=4;i++){for(j=1;j<=5;j++)cout<<dp[i][j]<<" ";cout<<"\n";}
    //cout<<end1(2,"1");
    return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <tuple>
#include <string>
#include <iomanip>
#include <sstream>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <iomanip>
using namespace std;

#define prec setprecision

typedef long long ll;
typedef unsigned long long llu;
template<typename T> T gcd(T x, T y){ if(x<y) swap(x,y); while(y>0) { T f = x%y; x = y; y = f; } return x; }
void exgcd(ll a, ll b, ll &d, ll &x, ll &y) {
	if (!b) {d = a; x = 1; y = 0;}
	else {exgcd(b, a % b, d, y, x); y -= x * (a / b);}
}

ll inv(ll a, ll m) {
	ll x, y, d; exgcd(a, m, d, x, y);
	return d == 1 ? ((x%m) + m) % m : -1;
}

#ifndef ONLINE_JUDGE
#define DEBUG 1
#else
#define DEBUG 0
#endif

ll MOD = 1e9 + 7;

int n, x;
char s[555];
ll pf2[555];
ll dp[555][555][555];

// number of occurences of s[fr..to] within subsequences of F[k]
ll solve(int fr, int to, int k) {
	if(k==0) return fr == to && s[fr] == '0';
	if(k==1) return fr == to && s[fr] == '1';
	ll& r = dp[fr][to][k];
	if(r>=0) return r;
	r = 0;
	r = (r + ((fr==0 ? pf2[k-1] : 1ll) * solve(fr, to, k-2) % MOD)) % MOD;
	r = (r + (solve(fr, to, k-1) * (to == n-1 ? pf2[k-2] : 1ll) % MOD)) % MOD;
	for(int m=fr;m<to;m++) {
		r = (r + ( solve(fr, m, k-1) * solve(m+1, to, k-2) % MOD)) % MOD;
	}
	return r;
}

int main(int argc, char *argv[]) {
	std::cin.sync_with_stdio(false);std::cin.tie(nullptr);
	#if DEBUG
	freopen("/tmp/in.txt", "r", stdin);
	while(cin >> n >> x >> s)
	#else
	cin >> n >> x >> s;
	#endif
	{
		pf2[0] = 2;
		pf2[1] = 2;
		for(int i=2;i<=x;i++) pf2[i] = (pf2[i-1]*pf2[i-2])%MOD;
		memset(dp, -1, sizeof(dp));
		cout << solve(0, n-1, x) << endl;
	}
	return 0;
}


#include <iostream>

using namespace std;

const int MAX_INT=0x7fffffff;

typedef long long ll ;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<char,ll> pcl;

#define fan(i,a,n) for(auto i=a; i<n; i++)
#define fna(i,n,a) for(int i=n-1; i>=a; i--)
#define rep(i,n) for(auto i=0; i<n; i++)
#define rrep(i,n) for(auto i=n-1; i>=0; i--)
#define fit(it,x) for(auto it=x.begin();it!=x.end();it++)
#define all(a) a.begin(), a.end()
#define mp make_pair
#define pb push_back
#define rs resize
#define sz size
#define ins insert
#define ce cout << endl

//#define dbg(x)
//
//vector<vector<int>> dfsv;
//vector<char> used;
//void dfs(int n){
//    used[n]=true;
//    fit(it,dfsv[n]){
//        if(!used[*it])dfs(*it);
//    }
//}

//map<int,int> chs;
//ll fact (int n){
//    if(n==1)return 1;
//    return n*fact(n-1);
//}
//
//ll kls(int c,map<int,int> chs2){
//    ll sumd=0;
//    fit(it,chs2){
//        sumd+=fact(it->second);
//    }
//    return (fact(c)/sumd);
//}
//
//ll rek(int siz,map<int,int> mapa,int ind){
//    ll sum=0;
//    while(mapa[ind]>0){
//        //sum+=kls(siz,mapa);
//        rek(siz-1,mapa,mapa[ind])
//        mapa[ind]--;
//    }
//}

ll n;
bool chk(ll k){
    ll ans=n,sch=0;
    while(ans>0){
        ans-=k;
        sch+=k;
        ans-=(ans/10);
        if(sch>n/2){return true;}
    }
}

signed main() {
    //ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin >> n;
    ll l=1,r=n,mid,ans;
    while(l<=r) {
        mid = (r + l) / 2;
        if (chk(mid)) {
            ans = min(ans, mid);
            r = mid-1;
        } else {
            l = mid+1;
        }
    }
    cout << ans;
    return 1;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    int t1,t2,h,m,s;
    cin >> h >> m >> s >> t1 >> t2;
    if (h == 12) h -= 12;
    vector<int> v(43200,0);
    v[h*5] = 1;
    v[m] = 1;
    v[s] = 1;
    t1 *= 5; t2 *= 5;
    if (t1 > t2) swap(t1,t2);
    bool no_1 = false;
    for (int i = t1; i <= t2; ++i) {
        if (v[i]) {
            no_1 = true;
            break;
        }
    }
    //cout << no_1 << endl;
    bool no_2 = false;
    for (int i = 0; i <= t1; ++i) {
        if (v[i]) {
            no_2 = true;
            break;
        }
    }
    //cout << no_2 << endl;
    for (int i = t2; i < v.size(); ++i) {
        if (v[i]) {
            no_2 = true;
            break;
        }
    }
    cout << no_2 << endl;
    if (no_1 && no_2) cout << "NO";
    else cout << "YES";
    return 0;
}


#include<bits/stdc++.h>
#define maxs 100000000
using namespace std;
vector <long long int> arr(10000,-1);
void fact()
{
    long long int i,j;
    for(i=2;i<=maxs;i++)
    {
        if(arr[i]==-1)
        {
            for(j=i;j<=maxs;j+=i)
            {
                if(arr[j]==-1)
                {
                    arr[j]=i;
                }
            }

        }

    }
}
int main()
{

   fact();
   arr[1]=1;
   long long int n;
   cin>>n;
   while(arr[n]!=1)
    {
        cout<<arr[n];
        n=n/arr[n];
    }
    cout<<endl;

      return 0;
}


#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <set>
using namespace std;
typedef long long ll;
const int mx = 1e3+10;
int n,m;
int a[mx];
int main (){
	while(~scanf("%d%d",&n,&m)){
		int ans = 0;
		for(int i=0;i<n;i++) scanf("%d",a+i);
		sort(a,a+n);
		int maxx = a[n-1],t = n-1,cnt;
		while(2*m<maxx){
			cnt = (maxx-1)/2+1;
			int po = lower_bound(a,a+t,cnt)-a;
			if(po == t){
			   ans++,maxx = cnt;;
			}
			else{
				t = po;
				if(t<0) break;
				else maxx = a[po];
			}
		}
		while(maxx>2*m){
			maxx = (maxx-1)/2+1;
			ans++;
		}
		cout << ans << endl;
	}
	return 0;
}


/* ****revpro**** */

#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define endl	   '\n'
#define pii         pair<ll,ll>
#define vi          vector<ll>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll)x.size()
#define hell        1000000007
#define rep(i,a,b)  for(ll i=a;i<b;i++)
#define repr(i,a,b) for(ll i=b-1;i>=a;i--)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define mii	    map<ll,ll>
using namespace std;

#define N  100005
ll add(ll x,ll y,ll mod=hell) { x += y; if(x >= mod) x -= mod; return x;}
ll sub(ll x,ll y,ll mod=hell) { x -= y; if(x < 0) x += mod; return x;}
ll mul(ll x,ll y,ll mod=hell) { return (x * 1ll * y) % mod;}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int TESTS=1;
//	cin>>TESTS;
	while(TESTS--)
	{
		ll n;
		cin>>n;
		ll dp1[n+1]={0};
		ll dp2[n+1]={0};
		dp1[0]=1;
		vector <ll> s;
		s.pb(1);
		rep(i,1,2*n+1)
		{
			rep(j,0,n+1) dp2[j]=0;
			rep(j,0,n+1)
			{
				if(j)
				{
					dp2[j-1]=add(dp1[j],dp2[j-1]);
					if(j<=2*n-(i+1))
						dp2[j+1]=add(dp2[j+1],dp1[j]);
				}
				else
					dp2[1]=add(dp1[0],dp2[1]);
			}
			ll sum=0;
			rep(j,0,n+1)
			{
				sum+=dp2[j];
				swap(dp1[j],dp2[j]);
			}
			s.pb(sum);
		}
		ll sum=0;
		rep(i,1,2*n)
		{
			sum=add(sum,s[i]);
			i++;
		}
		cout<<sum;
	}
	return 0;
}


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

using namespace std;

const int N=101;
int n,k;
int a[N];
int zl[N];
bool have[N];
int tot=0,ans=0;
int p[N],f;

void pd()  //虽然我们记录了从今天之后出现的书的情况
{  //但是如果有书在之后都不会出现，我们选择扔ta肯定更优
	int i;
	for (int i=1;i<=zl[0];i++)
	    if (p[zl[i]]==0)
	    {
	    	f=zl[i];
	    	return;
		}
	return;
}

int main()
{
	memset(have,0,sizeof(have));
	scanf("%d%d",&n,&k);
	for (int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		p[a[i]]++;
		if (p[a[i]]==1) zl[0]++,zl[zl[0]]=a[i];  //不同的书的种类
	}
	for (int i=1;i<=n;i++)  //从1到n扫一遍
	{
		if (have[a[i]]==0&&tot<k)  //没有这本书，而且图书馆没满
		{
			ans++; //直接买
			tot++;
			have[a[i]]=1;
		}
		else if (have[a[i]])
		{
			continue;
		}
		else  //图书馆满了
		{
			have[a[i]]=1;  //先把当前需要的书买进来
			ans++;
			//扔掉哪本书呢???就是在最近用不到的书
			int r=i+1;
			memset(p,0,sizeof(p));  //判断书在之后的几天会不会用到
			while (p[0]<k&&r<=n)  //书店最多放k本书
				if (p[a[r]]==0&&have[a[r]])
				{
					p[a[r]]=1;
					p[0]++;
					f=a[r];  //记录在今天之后一定范围内最后出现的书
					r++;
				}
			pd();
			have[f]=0;
		}
	}
	printf("%d",ans);
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int MOD=1e9+7;

//const int MOD=998244353;

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

    int n;
    cin>>n;

    vector<string> vs(n);
    for(auto &s:vs)cin>>s;

    queue<pair<int,string>> q;
    string s="";
    for(int i=max(0,n-3); i<n; i++){
        s+=vs[i];
    }
    q.push({n-1,s});
    while(q.size()){
        auto cur=q.front();
        q.pop();
        int i=cur.first;
        string s=cur.second;
        int sz=s.size();
        if(!i){
            cout<<"YES";
            return 0;
        }
        if(i>=3 && (s[5]==vs[i-3][1]|| s[4]==vs[i-3][0])){
            string s2="";
            s2+=s[4];
            s2+=s[5];
            s2+=vs[i-2];
            s2+=vs[i-1];
            q.push({i-1,s2});
        }
        if(s[sz-1]==vs[i-1][1] || s[sz-2]==vs[i-1][0]){
            string s2="";
            s2+=s[4];
            s2+=s[5];
            for(int j=i+1; j<i; j++){
                s2+=vs[j];
            }
            q.push({i-1,s2});

        }

    }
    cout<<"NO";
    return 0;

}


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

int main(){
    bool find=true;
    int count=0;
    char str[8];
    while(count<8){
        count++;
        scanf("%s", str);
        for(int i=0; i<8; i+=2)
        {
            if(str[i]==str[i+1])
            {
                find=false;
                break;
            }
        }

    }
    if(find)cout << "YES";
    else cout << "NO";
    while(true);
    return 0;
}


#include <iostream>

using namespace std;

const int limite=152;

typedef long long int lint;

lint modulo=1000000007;

lint cuantos[limite][limite][limite];
lint cuantosle[limite][limite][limite];
lint cuantosri[limite][limite][limite];
lint cuantosleri[limite][limite][limite];

lint suma[limite][limite][limite];
lint sumale[limite][limite][limite];
lint sumari[limite][limite][limite];
lint sumaleri[limite][limite][limite];

lint n,m;

lint total=0;

void computasuma(int i)
{
  lint (&s)[limite][limite]=suma[i];
  lint (&sl)[limite][limite]=sumale[i];
  lint (&sr)[limite][limite]=sumari[i];
  lint (&slr)[limite][limite]=sumaleri[i];
  for (int j=1;j<=m;j++) {
    for (int k=1;k<=m;k++) {
      s[j][k]=(cuantos[j][k]+s[j-1][k]+s[j][k-1]-s[j-1][k-1])%modulo;
      sl[j][k]=(cuantosle[j][k]+sl[j-1][k]+sl[j][k-1]-sl[j-1][k-1])%modulo;
      sr[j][k]=(cuantosri[j][k]+sr[j-1][k]+sr[j][k-1]-sr[j-1][k-1])%modulo;
      slr[j][k]=(cuantosleri[j][k]+slr[j-1][k]+slr[j][k-1]-slr[j-1][k-1])%modulo;
    }
  }
  total=(total+(s[m][m]+sl[m][m]+sr[m][m]+slr[m][m])*(n-i))%modulo;
}

int main()
{
  cin>>n>>m;
  for (int j=1;j<=m;j++)
    for (int k=j;k<=m;k++)
      cuantos[0][j][k]=1;
  computasuma(0);
  for (int i=1;i<n;i++) {
    lint (&s)[limite][limite]=suma[i-1];
    lint (&sl)[limite][limite]=sumale[i-1];
    lint (&sr)[limite][limite]=sumari[i-1];
    lint (&slr)[limite][limite]=sumaleri[i-1];
    for (int j=1;j<=m;j++) {
      for (int k=j;k<=m;k++) {
	cuantos[i][j][k]=(s[k][k]-s[j-1][k])%modulo;
	cuantosle[i][j][k]=(sl[j][k]-sl[j-1][k-1]+
			    s[j-1][k]-s[j-1][k-1])%modulo;
	cuantosri[i][j][k]=(sr[k][m]-sr[k-1][k-1]-sr[j-1][m]+sr[j-1][k-1]+
			    s[k][m]-s[k][k]-s[j-1][m]+s[j-1][k])%modulo;
	cuantosleri[i][j][k]=(slr[j][m]-slr[j][k-1]+
			      sl[j][m]-sl[j][k]+
			      sr[j-1][m]-sr[j-1][k-1]+
			      s[j-1][m]-s[j-1][k])%modulo;
      }
    }
    computasuma(i);
  }
  total=(total+modulo)%modulo;
  cout<<total<<endl;
}


/*#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#include<string>
#include<set>
#include<map>
using namespace std;
#define INF 99999999
#define max(a,b) (a > b ? a : b)
#define min(a,b) (a < b ? a : b)
const int nMax = 1e5;
int a[nMax];
int mark[11];
int main()
{
    int n,k;
    scanf("%d%d",&n,&k);
    for(int i = 0;i < n;i++)
        scanf("%d",&a[i]);
    int ans = 0;
    for(int i = 0;i < n;i++){
        memset(mark,0,sizeof(mark));
        while(a[i]){
            int temp = a[i]%10;
            a[i]/=10;
            mark[temp]++;
        }
        int countnum = 0;
        for(int j = 0;j <= k;j++)
            if( mark[j] != 0 )
                countnum++;
        if( countnum == k+1 )
            ans++;
    }
    cout<<ans<<endl;
}
*//*
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int const nMax = 1e5+100;
int a[nMax];
int main()
{
    int n;
    scanf("%d",&n);
    for(int i = 0;i < n;i++)
        scanf("%d",&a[i]);
    if( n <= 2 ){
        cout<<n<<endl;
        return 0;
    }
    int ans = 2;
    int countnum = 2;
    for(int i = 2;i < n;i++){
        if( a[i] == a[i-1]+a[i-2] ){
            countnum++;
        }
        else{
            ans = max(countnum,ans);
            countnum = 2;
        }
    }
    ans = max(countnum,ans);
    cout<<ans<<endl;
}
*//*
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
using namespace std;
const int nMax = 50000;
const int INF = 1e9+1;
string ss;
long long ans,x,n,a[nMax],s[nMax],h[nMax];
int main()
{
    cin>>x>>ss;
    n = ss.length();
    for(int i = 0;i < n;i++){
        a[i+1] = ss[i]-'0';
        s[i+1] = s[i] + a[i+1];
    }
    for(int i = 1;i <= n;i++)
        for(int j = 0;j < i;j++)
            h[s[i]-s[j]]++;
    if( x==0 )
        for(int i = 0;i <= s[n];i++)
            ans+=h[0]*h[i];
    for(int i = 1;i <= s[n];i++)
        if( (x%i == 0) && (x/i <= s[n]) )
        ans+=h[i]*h[x/i];
    cout<< ans <<endl;
    return 0;
}*/

#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
int dp[500010];
int c[100];
int main()
{
    int n,d;
    scanf("%d%d",&n,&d);
    memset(dp,0,sizeof(dp));
    for(int i = 1;i <= n;i++)
        scanf("%d",&c[i]);
    dp[0] = 1;
    for(int i = 1;i <= n;i++){
        for(int j = 500000-c[i];j >= 0;j--){
            if( dp[j] )
                dp[j+c[i]] = 1;
        }
    }
    int mas = 0;
    int day = 0;
    while(1){
        int x = mas+d;
        while( x != mas && !dp[x] ) x--;
        if( x == mas ){
            printf("%d %d\n",mas,day);
            break;
        }
        mas = x;
        day++;
    }
    return 0;
}


#include<cstdio>
#include<iostream>
#include<cstdlib>
#include<algorithm>
#include<vector>
#include<cstring>
#include<ctype.h>
#include<climits>
#include<set>

using namespace std;

#define FOR(i, a, b) for(i=(a);i<=(b);i++)
#define FORR(i, a, b) for(i=(a);i>=(b);i--)
#define S(n) scanf("%d", &n)
#define P(n) printf(" %d", n)
#define pb push_back
#define mp make_pair
#define ll long long

ll dp(int l, int r){
    if(r < l) return 0;
    if(l<10 && r>=10) return (10-l) + dp(10, r);
    if(l<10 && r<10) return r-l+1;
    ll t1, t2, ans;
    if(l == r){
        t1 = l%10;
        t2 = l;
        while(t2>=10){
            t2 = (t2-(t2%10))/10;
        }
        if(t1 == t2)
        return 1;
        else return 0;
    }
    t1 = l%10;
    t2 = l;
    while(t2>=10){
    t2 = (t2-(t2%10))/10; }
    if(t1 == t2) return 1+dp(l+1, r);
    else return dp(l+1, r);

}

int main(){
    ll l, r;
    cin>>l>>r;
    cout<<dp(l, r);
    //system("pause");
    return 0;
}


#include <stdio.h>
#include <string>
#include <iostream>
using namespace std;
string op;
bool F[400][400];
int dir[4][2] = { 1,0,0,1,-1,0,0,-1 };
int main() {
	int x = 200, y = 200;
	F[x][y] = true;
	cin >> op;
	for (int i = 0; i < op.size(); i++) {
		switch (op[i]) {
		case 'L': y--;
			break;
		case 'R': y++;
			break;
		case 'U': x--;
			break;
		case 'D': x++;
		}
		F[x][y] = true;
		int cnt = 0;
		for (int i = 0; i < 4; i++) {
			if (F[x + dir[i][0]][y + dir[i][1]]) cnt++;
		}
		if (cnt >= 2) {
			printf("BUG\n");
			return 0;
		}
	}
	printf("OK\n");
	return 0;
}


#include <iostream>

using namespace std;
bool e[200];
int main() {
    ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
    int n,mx=0,mn=200,c=0;
    char a;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a;
        if(a=='*'){
        e[i+1]=true;
        mx=max(mx,i+1);
        mn=min(mn,i+1);}
    }
    for(int i=mn;i<=mx;i++){
        if(e[i]){
            int k=mx-i/4;
            for(int y=1;y<=k;y++){
                for(int j=1;j<5;j++){
                        if(e[i+y*j])
                        c++;
                        else
                        break;
                        // cout<<i+y*j<<" ";
                }//cout<<endl;
                if(c==3)
                return cout<<"yes",0;
                c=0;
            }
        }
    }

    cout<<"no";
    return 0;
}#include <iostream>

using namespace std;
bool e[200];
int main() {
    ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
    int n,mx=0,mn=200,c=0;
    char a;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a;
        if(a=='*'){
        e[i+1]=true;
        mx=max(mx,i+1);
        mn=min(mn,i+1);}
    }
    for(int i=mn;i<=mx;i++){
        if(e[i]){
            int k=mx-i/4;
            for(int y=1;y<=k;y++){
                for(int j=1;j<5;j++){
                        if(e[i+y*j])
                        c++;
                        else
                        break;
                        // cout<<i+y*j<<" ";
                }//cout<<endl;
                if(c==3)
                return cout<<"yes",0;
                c=0;
            }
        }
    }

    cout<<"no";
    return 0;
}


#include <iostream>
#include <math.h>
using namespace std;
int main()
{
    long m, n, a;
    cin >> m;
    cin >> n;
    cin >> a;
    a = ceil(m / a)*ceil(n / a);
    return a;
}


//  Copyright ? 2017 Deev Roman. All rights reserved.
#include <iostream>
#include <vector>
#include <cmath>
#include <map>
#include <algorithm>
#include <string>
using namespace std;

int main() {
    int n;
    cin >> n;
    n++;
    int cnt_to = 0;

    while (1){
	int i = n;
	int cnt = 0;

    while (i != 0){
    	if (i % 10 != 0) cnt++;
    	i = i / 10;
	}
	cnt_to++;
	if (cnt <= 1) break;

	n++;
	}

	cout << cnt_to;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main(){
	int n;
	string s;
	cin>>n>>s;
	for (int i=0;i<n;i++){
		if (s[i]>s[i+1]){
			for (int p=i;p<n-1;p++){
				s[p]=s[p+1];
			}
			s.erase(n-1);
			break;
		}

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


#include<bits/stdc++.h>
using namespace std;
const int N=1e3+10;
const int mod=1e9+7;
int k,pa,pb,f[N][N];
int qpow(int a,int b) {
  int ret=1;
  while(b) {
    if(b&1) ret=1ll*ret*a%mod; a=1ll*a*a%mod; b>>=1;
  }
  return ret;
}
int dfs(int i,int j) {
  if(i+j>=k) return ((i+j)%mod+1ll*pa*qpow(pb,mod-2)%mod)%mod;
  if(f[i][j]!=-1) return f[i][j];
  return 1ll*pa*qpow((pa+pb)%mod,mod-2)%mod*dfs(i+1,j)%mod+1ll*pb*qpow((pa+pb)%mod,mod-2)%mod*dfs(i,i+j)%mod;
}
int main() {
  cin>>k>>pa>>pb;
  memset(f,-1,sizeof(f));
  printf("%d\n",dfs(1,0));
  return 0;
}


#include <bits/stdc++.h>
// #pragma GCC optimize ("O3")
// #pragma GCC target ("sse4")

using namespace std;

#define li long long int
#define ld double_t
#define mod (li)(1e9+7)
const int MX1=1e3+5;
const int MX2=1e6+5;
const li inf=1e18;

li power(li a,li b){li res=1;while(b){if(b%2)res=(res*a)%mod;
a=(a*a)%mod;b/=2;}return res;}

li mmi(li a){return power(a,mod-2);}

li cntbit(li n){li cnt=0;while(n){n&=(n-1);cnt++;}return cnt;}

int n,a,b;
vector<int> v;

int chk(int x){
	if(x==1) swap(a,b);
	int cnt=1;
	int m=a*4;
	if(x==1) m=2*a;
	int t=n;
	v.clear();
	while(m){
		if(n-a>=0){
			m-=a;
			n-=a;
		}else{
			v.push_back(n);
			n=t;
			cnt++;
		}
	}
	if(n<t) v.push_back(n);
	m=b*2;
	if(x==1) m=4*b;
	int i=0,ok=0;
	n=t;
	while(m){
		if(i<(int)v.size() and v[i]-b>=0){
			v[i]-=b;
			m-=b;
		}else if(i<(int)v.size()){
			i++;
		}else{
			if(n-b>=0){
				ok=1;
				n-=b;
				m-=b;
			}else{
				n=t;
				cnt++;
			}
		}
	}
	if(ok) cnt++;
	return cnt;
}

void solve(){
	cin>>n>>a>>b;
	cout<<min(chk(0),chk(1));
}

int main(){
	ios_base::sync_with_stdio(false);
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif
	int t=1;
	//cin>>t;
	while(t--){
		solve();
	}
	return 0;
}


#include<bits/stdc++.h>
#define rec(i,a,b)       for(int i=a; i<=b; i++)
using namespace std;
int solve()
{
    int l,r,a;
    cin>>l>>r>>a;
    if((l==0 || r==0) && a==0 )
    return 0;
    while(1)
    { if(l<r)
      {
          l++;
          a--;
      }
      else if(r<l)
      {
          r++;
          a--;
      }
      else if(r==l)
      {
          l++;
          r++;
          a=a-2;
      }
      if(a==0 || a==1 && l==r)
        break;

    }
    if(l<r)
        return 2*l;
    else if(r<l) return 2*r;
    else if(l==r) return r+l;

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


#include<iostream>
using namespace std;
unsigned long long f(unsigned long long a, unsigned long long b){
	if(a==0) return 0;
	if(a<b) return 1+f(a,b-a);
	return a/b+f(a-(a/b)*b,b);
}
int main(){
	unsigned long long a,b;
	cin>>a>>b;
	cout<<f(a,b)<<endl;
	return 0;
}
/* Esta no corria en 5/8
int main(){
	unsigned long long a,b;
	cin>>a>>b;
//primero verificamos que el numero sea entero
	if(a%b==0){ cout<<a/b<<endl; return 0;}
//agregamos enteros
	unsigned long long cont=a/b;
	a-=b*cont;

	cout<<a<<" "<<b<<endl;
	cout<<cont<<endl;

	unsigned long long xn=b-b%a;
	unsigned long long n=xn/a;
	cout<<b<<"=("<<a<<"*"<<n<<")+"<<b%a<<endl;
	if(a==1) cont+=b;
	else cont+=n+a;
cout<<cont<<endl;
	return 0;
}
*/


#include <bits/stdc++.h>

using namespace std;

string s, t;
vector< pair<char, int> > a, b;
vector< pair<int, int> > bleach;
vector< pair<char, int> > ta, tb;
bool flag = false;

void add(vector< pair<char, int> > &tren, pair<char, int> s) {
    if (!tren.empty() && tren.back().first == s.first) tren.back().second += s.second;
    else tren.push_back(s);
}

inline void addchar(vector< pair<char, int> > &tren, char s) {
    add(tren, make_pair(s, 1));
}

int pop(vector< pair<char, int> > &tren, int kol) {
    int sol = 0;
    for (int i = 0; i < kol; i++) {
        sol += tren.back().second;
        tren.pop_back();
    }
    return sol;
}

void query(int acx, int acy) {
    //printf("query: %d %d\n", acx, acy);
    if (flag) swap(acx, acy);
    ta.clear(); tb.clear();
    for (int i = 0; i < acx; i++) ta.push_back(a[i]);
    for (int i = 0; i < acy; i++) tb.push_back(b[i]);
    int kolx = pop(a, acx);
    int koly = pop(b, acy);

    for (int i = 0; i < acx; i++) add(b, ta[ta.size() - 1 - i]);
    for (int i = 0; i < acy; i++) add(a, tb[tb.size() - 1 - i]);
    bleach.push_back(make_pair(kolx, koly));
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> s >> t;

    reverse(s.begin(), s.end());
    reverse(t.begin(), t.end());
    for (int i = 0; i < s.size(); i++) addchar(a, s[i]);
    for (int i = 0; i < t.size(); i++) addchar(b, t[i]);

    while (a.size() != 1 || b.size() != 1) {
        int la = a.size();
        int lb = b.size();

        if (la < lb) {
            swap(la, lb);
            flag = true;
        }
        const char kuraca = a.back().first;
        const char kuracb = b.back().first;

        //printf("%d %d -> %c %c\n", la, lb, kuraca, kuracb);
        if (kuraca != kuracb) {
            if (lb <= 2) {
                if (la <= 3) query(1, 1);
                else query(3, 1);
            } else query(1, 1);
        } else {
            if (lb == 1) {
                if (la <= 3) query(1, 0);
                else query(3, 0);
            } else if (lb == 2) {
                if (la == 2) query(1, 0);
                else query(2, 1);
            } else query(3, 2);
        }
        flag = false;
    }

    printf("%d\n", bleach.size());
    for (int i = 0; i < bleach.size(); i++)
        printf("%d %d\n", bleach[i].first, bleach[i].second);
    return 0;
}


 #include <bits/stdc++.h>
using namespace std;
const long long MAX=2e9, N=5e3+10, MOD = 1e9+7;
#define ll long long
#define pi pair<ll,ll>
#define ft first
#define sd second
#define mp make_pair
#define pb push_back

#define VI vector<int>
#define VPI vector<pi>
#define VL vector<ll>
#define int ll
#define PI 3.14159265
#define sz(a) (int)(a.size())
string s, t;

VI zmiany(string a, char c)
{
    VI q;
    char l=c;
    for(int i=sz(a)-1;i>=0;i--)
    {
        if(a[i]!=l)
        {
            l=a[i];
            q.pb(i+1);
        }
    }
    return q;
}

VPI solv(string a, string b)
{
    VI p =zmiany(a, 'a');
    VI q =zmiany(b, 'b');
    while(sz(p) < sz(q))
        p.pb(0);
    while(sz(q) < sz(p))
        q.pb(0);
    VPI res;
    for(int i=0;i<q.size();i++)
    {
        res.pb(pi(p[i], q[i]));
        swap(p, q);
    }
    return res;
}

VPI solve(string a, string b)
{
    VPI res=solv(a, b);
    VI p =zmiany(a,'a');
    VI q =zmiany(b, 'b');
    int roznica = p.size()-q.size();
    roznica/=2;
    p.pb(0);
    q.pb(0);
//    cerr<<"p: ";
//    for(int i:p)
//        cerr<<i<<" "; cerr<<"\n";
//    cerr<<"q: ";
//    for(int i:q)
//        cerr<<i<<" "; cerr<<"\n";
//    cerr<<a<<" "<<b<<"\n";
    for(int i=0;i<=40;i++)
    {
        for(int j=0;j<=20;j++)
        {
            int u = abs(roznica)-2+i;
            int v= j;
            if(roznica<0)
                swap(u, v);
            if( u <0 || p.size() <=u || v <0 || q.size() <=v)
                continue;
//            cerr<<u<<" "<<v<<"\n";
            u=p.size()-u-1;
            v=q.size()-v-1;
//            cerr<<u<<" "<<v<<"\n";
            string a2="", b2="";
            for(int k=0;k<q[v];k++)
                a2+=b[k];
            for(int k=p[u];k<a.size();k++)
                a2+=a[k];
            for(int k=0;k<p[u];k++)
                b2+=a[k];
            for(int k=q[v];k<b.size();k++)
                b2+=b[k];
//            cerr<<a2<<" "<<b2<<"\n";
            VPI temp = solv(a2, b2);
            reverse(temp.begin(), temp.end());
            temp.pb(pi(p[u], q[v]));
            reverse(temp.begin(), temp.end());
            if(temp.size() < res.size())
                res=temp;
        }
    }
    return res;
}

#undef int
int main()
{
    #define int ll
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cerr.tie(0);
    cin>>s>>t;
    VPI res1=solve(s, t);
    VPI res2=solve(t, s);
    cout<<min(sz(res1), sz(res2))<<"\n";
//    cerr<<"\n";
    if(res2.size() < res1.size())
        for(pi i:res2)
            cout<<i.sd<<" "<<i.ft<<"\n";
    else
        for(pi i:res1)
            cout<<i.ft<<" "<<i.sd<<"\n";
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int inf=0x3f3f3f3f;
const ll linf=0x3f3f3f3f3f3f3f3f;
const int maxn=3e3+10;
const ll mod=1e9+7;
int n,m,ta[maxn],tb[maxn],sz[maxn];
vector<int>v[maxn];
struct DP
{
    int a=0;
    ll b=-linf;
}dp[maxn][maxn];
bool operator<(DP a,DP b)
{
    if(a.a!=b.a)return a.a<b.a;
    return a.b<b.b;
}
void dfs(int x,int f)
{
    sz[x]=1;
    dp[x][0]={0,tb[x]-ta[x]};
    for(auto y:v[x])if(y!=f)
    {
        dfs(y,x);
        DP tmp[maxn];
        for(int i=0;i<sz[x];i++)
            for(int j=0;j<=sz[y];j++)
                tmp[i+j]=max(tmp[i+j],(DP){dp[x][i].a+dp[y][j].a,dp[x][i].b+dp[y][j].b});

        sz[x]+=sz[y];
        for(int i=0;i<sz[x];i++)dp[x][i]=tmp[i];
    }
    dp[x][sz[x]]={dp[x][sz[x]-1].a+(dp[x][sz[x]-1].b>0),0};
//
//    cout<<x<<endl;
//    for(int i=0;i<=sz[x];i++)
//    {
//        cout<<i<<' '<<dp[x][i].a<<' '<<dp[x][i].b<<endl;
//    }
}

int main()
{
//    freopen("in.txt","r",stdin);
    int t;
    for(scanf("%d",&t);t--;)
    {
        scanf("%d%d",&n,&m);
        for(int i=1;i<=n;i++)scanf("%d",ta+i);
        for(int i=1;i<=n;i++)scanf("%d",tb+i);
        for(int i=0;i<n-1;i++)
        {
            int a,b;
            scanf("%d%d",&a,&b);
            v[a].push_back(b);
            v[b].push_back(a);
        }
        dfs(1,0);
        printf("%d\n",dp[1][m-1].a+(dp[1][m-1].b>0));
    }
    return 0;
}


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

/*
now we have 7 days with no. of pages I read everyday and total no. of pages in the book
    if pages are divisible by the weekly sums than divide the total pages with sum of the weekly pages and
and then minus the 1 week and check for the day on which it finished
    else in the other cases there is chance of doing it simple by checking by firstly doing
*/
void solve()
{
    int pages; cin>>pages;
    int arr[7];
    int sum = 0;
    for(int i = 0; i < 7; ++i){
        cin>>arr[i];
        sum += arr[i];
    }
    int weekly = pages / sum;

    if ( pages % sum == 0){
        pages -= weekly;
    }else{
        pages = pages % weekly;
    }
    for(int i = 0; i < 7; ++i){
        if (pages <= arr[i]){
            cout<<i+1<<'\n';
            return;
        }
        pages -= arr[i];
    }
}

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


// Example program
#include <bits/stdc++.h>

using namespace std;

vector <long long> v;
long long l[40000000];
int main()
{
    int a,b,c,s=0,d;
    cin>>a>>b>>c;
    for (int i=1;i<=a;i++){
        for (int j=1;j<=b;j++){
            for (int k=1;k<=c;k++){
                v.push_back(i*j*k);
            }
        }
    }
    bool o;
    for (int u=0;u<v.size();u++){
        o=0;
        for (int j=0;j<u;j++){
            if (v[u]==v[j]){
                s+=l[j];
                o=1;
                break;
            }
        }
        if (o==1){
            continue;
        }
        d=0;
        for (int i=1;i*i<=v[u];i++){
            if (v[u]%i==0 && v[u]!=i*i){
                d+=2;
            }else if(v[u]==i*i){
                d++;
            }
        }
        l[u]=d;
        s+=d;
    }
    cout<<s;
}


#include <bits/stdc++.h>

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define TRACE(x) cout << #x << " = " << x << "\n"
#define _ << " _ " <<
#define ll long long

using namespace std;

ll sol(ll x) {
  ll out = x;
  while (x > 0) {
    out -= x % 10;
    x /= 10;
  }
  return out;
}

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

  ll n, s;
  cin >> n >> s;
  ll lo = 1, hi = n;
  while (lo < hi) {
    ll mi = lo + (hi - lo) / 2;
    if (sol(mi) < s) {
      lo = mi + 1;
    } else {
      hi = mi;
    }
  }
  if (lo > n + 1) cout << 0 << endl;
  else            cout << n - lo + 1 << endl;

  return 0;
}


#include <bits/stdc++.h>

using namespace std;

vector<int> primef(vector<int> Array, int n){
    int i = 2;
    while (n != 1){
        if (n % i==0){
            Array.push_back(i);
            n/=i;
        }
        else{
            i++;
        }
    }
    return Array;
}

int main()
{
    int a,b;
    vector <int> m;
    m = primef(m, b);
    cout<<m.size();
    return 0;
}


#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
const ll inf = 1LL << 60;
const ll MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}

struct segtree {
    ll H, W;
    vector<vector<ll>> dat;
    segtree() {}
    segtree(vector<vector<ll>> &f) {
        H = W = 1;
        while (H < (ll)f.size())
            H <<= 1;
        while (W < (ll)f[0].size())
            W <<= 1;
        dat.assign(2 * H - 1, vector<ll>(2 * W - 1, inf));
        init(f);
    }
    void init(vector<vector<ll>> &f) {
        for (ll i = 0; i < (ll)f.size(); i++)
            for (ll j = 0; j < (ll)f[0].size(); j++)
                dat[i + H - 1][j + W - 1] = f[i][j];
        for (ll i = 2 * H - 2; i > H - 2; i--)
            for (ll j = W - 2; j >= 0; j--)
                dat[i][j] = min(dat[i][2 * j + 1], dat[i][2 * j + 2]);
        for (ll i = H - 2; i >= 0; i--)
            for (ll j = 0; j < 2 * W - 1; j++)
                dat[i][j] = min(dat[2 * i + 1][j], dat[2 * i + 2][j]);
    }
    ll minimum(ll li, ll lj, ll ri, ll rj) { return minimum_h(li, lj, ri, rj, 0, H, 0); }
    ll minimum_h(ll li, ll lj, ll ri, ll rj, ll si, ll ti, ll k) {
        if (ri <= si or ti <= li)
            return inf;
        if (li <= si and ti <= ri)
            return minimum_w(lj, rj, 0, W, k, 0);
        const ll mi = (si + ti) / 2;
        return min(minimum_h(li, lj, ri, rj, si, mi, 2 * k + 1), minimum_h(li, lj, ri, rj, mi, ti, 2 * k + 2));
    }
    ll minimum_w(ll lj, ll rj, ll sj, ll tj, ll i, ll k) {
        if (rj <= sj or tj <= lj)
            return inf;
        if (lj <= sj and tj <= rj)
            return dat[i][k];
        const ll mj = (sj + tj) / 2;
        return min(minimum_w(lj, rj, sj, mj, i, 2 * k + 1), minimum_w(lj, rj, mj, tj, i, 2 * k + 2));
    }
};
int main() {
    int n, m, a, b;
    cin >> n >> m >> a >> b;
    ll g, x, y, z;
    cin >> g >> x >> y >> z;
    vvl h(n, vl(m));

    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < m; ++j) {
            if (i == 0 && j == 0)
                h[i][j] = g;
            else {
                g = (g * x + y) % z;
                h[i][j] = g;
            }
        }
    }
    segtree tr(h);
    ll ret = 0;
    for (int i = 0; i <= n - a; ++i) {
        for (int j = 0; j <= m - b; ++j) {
            ret += tr.minimum(i, j, i + a, j + b);
        }
    }
    cout << ret << "\n";

    return 0;
}


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

using namespace std;

long long turn(int n)
{
    if (n == 0)
    {
        return 1;
    }
    else
    {
        return turn(n - 1) + 6 * n;
    }
}

int main()
{
    int n;
    cin >> n;
    cout << turn(n);
    return 0;
}


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

#define st first
#define nd second
#define mp make_pair
#define pb push_back
#define cl(x, v) memset((x), (v), sizeof(x))
#define gcd(x,y) __gcd((x),(y))

#ifndef ONLINE_JUDGE
  #define db(x) cerr << #x << " == " << x << endl
  #define dbs(x) cerr << x << endl
  #define _ << ", " <<
#else
  #define db(x) ((void)0)
  #define dbs(x) ((void)0)
#endif

typedef long long ll;
typedef long double ld;

typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;

const ld EPS = 1e-9, PI = acos(-1.);
const int INF = 0x3f3f3f3f, MOD = 1e9+7;
const int N = 1e5+5;

vector<ll> to_base(ll v, ll b) {
  vector<ll > ret;
  while (v) {
    ll r = v%b;
    v /= b;
    if (r < 0) r -= b, v++;
    ret.push_back(r);
  }
  return ret;
}

ll p, k;

int main() {
  scanf("%d%d", &n, &k);
  auto ans = to_base(n, -k);
  printf("%d\n", (int)ans.size());
  for (int x : ans) printf("%d ", x);
  printf("\n");
  return 0;
}


#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cstring>
#include <string>
#include <map>
#include <queue>
#include <sstream>
#include <numeric>
#include <functional>
#include <set>
#include <cmath>
#include <stack>
#include <fstream>
#include <cassert>
#ifdef HOME_PC
#include <ctime>
#endif
using namespace std;

#pragma comment(linker,"/stack:16000000")
#pragma warning (disable : 4996)

#define ALL(v) v.begin(),v.end()
#define SZ(v) (int)v.size()
#define mset(A,x) memset((A),(x),sizeof(A))
#define FOR(i,start,N) for(int i=(start);i<(N);++i)
#define FORSZ(i,start,v) FOR(i,start,SZ(v))
#define REPSZ(i,v) FORSZ(i,0,v)
#define FORE(i,start,N) FOR(i,start,N+1)
#define make_unique(v) v.resize(unique(ALL(v))-v.begin())
#define debug(x) cout<<#x<<" = "<<x<<endl;
#define adebug(A,N) FOR(i,0,N) cout<<#A<<"["<<i<<"] = "<<A[i]<<endl;
#define adebug2d(a,n,m) FOR(i,0,n) { FOR(j,0,m) { cout<<a[i][j]<<" ";} cout<<endl;}
#define vdebug(v) REPSZ(i,v) cout<<#v<<"["<<i<<"] = "<<v[i]<<endl;
#define selfx(x,f,a) x = f(x,a)
#define sqr(x) ((x)*(x))

typedef pair<int,int> pii;
typedef long long i64;
typedef vector<int> VI; typedef vector< vector<int> > VVI;
typedef vector<string> VS;

const int inf = 1<<25;
const double eps = 1e-9;

i64 memo[50][50];

i64 f(int h,int n)
{
    if(h > n)
        return 0;
    if(h == 0 && n == 0)
        return 1;

    i64& ret = memo[h][n];
    if(ret != -1)
        return ret;
    ret = 0;
    FORE(i,1,n)
    {
        int ln = i-1, rn = n-i;
        FOR(hl,0,h-1)
            ret += f(hl,ln)*f(h-1,rn) + f(h-1,ln)*f(hl,rn);
        ret+= f(h-1,ln)*f(h-1,rn);
    }
    return ret;
}

int main()
{
#ifdef HOME_PC
    //freopen ("input.txt","r",stdin);
    //freopen ("in.txt","r",stdin);
    //freopen ("output.txt","w",stdout);
#endif

    int n,h;
    cin>>n>>h;
    mset(memo,-1);
    i64 ans = 0;
    FORE(hx,h,n)
        ans+=f(hx,n);
    cout<<ans<<endl;

#ifdef HOME_PC
    cerr<<endl<<"Execution time = "<<clock()<<" ms"<<endl;
#endif
    return 0;
}


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

using namespace std;

#define vs  vector <string>
#define vi vector <int>
#define vii vector <vector <int> >
#define vp vector <pair <int,int> >
#define pb push_back
#define si size
#define FOR(i,j,k) for(int i = (j); i <= (k); i++)
#define FORN(i,j,k) for(int i = (j); i >= (k); i--)
#define ll long long
#define pi 3.141592653

int main(){
int r1,r2,c1,c2,d1,d2;
cin>>r1 >>r2 >>c1 >>c2 >>d1 >>d2;
int w,x,y,z;
x=(d2-r2+c2)/2;
y=(r1-d1+c2)/2;
if(x!=y || x>9){
cout<<"-1"<<endl;
return 0;
}
w=r1-x;
z=d1-w;
y=r2-z;
if(w<10 && y<10 && z<10 && w!=x && y!=z && w!=z && x!=y && x>0 && y>0 && z>0 && w>0){
cout<<w<<" "<<x<<endl;
cout<<y<<" "<<z<<endl;
return 0;
}
cout<<"-1"<<endl;
return 0;
}


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

int fsum_of_digits(int a) {
    int ret = 0;
    while(a != 0) {
        ret += a % 10;
        a /= 10;
    }
    return ret;
}

int main() {
    int n;
    cin >> n;
    vector<int> ans;
    int start = n/2;
    int sum_of_digits = fsum_of_digits(start) - 1;
    for(int i = start; i<=n; i++) {
        sum_of_digits++;
        if(i % 1000000000 == 0) {
            sum_of_digits -= 81;
        } else if(i % 100000000 == 0) {
            sum_of_digits -= 72;
        } else if(i % 10000000 == 0) {
            sum_of_digits -= 63;
        } else if(i % 1000000 == 0) {
            sum_of_digits -= 54;
        } else if(i % 100000 == 0) {
            sum_of_digits -= 45;
        } else if(i % 10000 == 0) {
            sum_of_digits -= 36;
        } else if(i % 1000 == 0) {
            sum_of_digits -= 27;
        } else if(i % 100 == 0) {
            sum_of_digits -= 18;
        } else if(i % 10 == 0) {
            sum_of_digits -= 9;
        }
        if(sum_of_digits + i == n) ans.push_back(i);
    }
    cout << ans.size() << endl;
    for(auto i : ans) cout << i << endl;
    return 0;
}


#include <iostream>

using namespace std;

bool judge(long int n)
{
    if(n%2)
        return true;
    return false;
}

int main()
{
    long int han, ten;
    long int temp;
    long int count  = 0;
    long int a, b;
    cin >> han >> ten;
    a = han/4;
    b = ten/4;
    temp = a < b ? a : b;
    if( temp == a)
    {
        han = han%4;
        ten = ten - temp*4;
    }
    else
    {
        han = han - temp*4;
        ten = ten%4;
    }
    if((han-2 >= 0) && (ten-2 >= 0))
    {
        count ++;
        han = han-2;
        ten = ten-2;
    }
    if(han ==1)
    {
        if(ten-12 >= 0)
        {
            count++;
            han = 0;
            ten = ten -12;
        }
    }
    if(han == 0)
    {
        count += ten/22;
        if(judge(count))
        {
            cout << "Ciel";
            return 1;
        }
        else
        {
            cout << "Hanako";
            return 1;
        }
    }
    if(judge(count))
    {
        cout << "Ciel";
        return 1;
    }
    else
    {
        cout << "Hanako";
        return 1;
    }
    return 0;
}


#include<iostream>
using namespace std;

int  main()
{
int a,b,c,d,e,f,tot,max=0,m,i,j,n;//a d// b c d//e//f
cin>>a>>b>>c>>d>>e>>f;
if (b>c) m=c; else m=b;
if (a>d) n=d; else n=a;

for (i=0;i<n||i==n;i++)
{j=d-i;if (j>m) j=m;
 for(;(j<m||j==m)&&j>-1;j--)
 {tot=i*e+j*f;
 if (max<tot) max=tot;}}

cout<<max<<endl;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
	freopen("in.in","r",stdin);
	freopen("out.out","w",stdout);
	int a,b;
	scanf("%d%d",&a,&b);
	for(int i=1;;i++){
		if(i%2==1) a-=i;
		if(i%2==0) b-=i;
		if(a<0) {printf("Vladik");return 0;}
		if(b<0) {printf("Valera");return 0;}
	}
}


#include <bits/stdc++.h>
using namespace std;
#define mod 1e9+7
#define endl '\n'
#define pb push_back
#define r(i,n) for(ll i=0;i<n;i++)
typedef long long ll;

double tick(){
    static clock_t oldt,newt=clock();
    double diff=1.0* (newt-oldt)/CLOCKS_PER_SEC;
    oldt=newt;
    return diff;
}

string binary(ll x)
{
    string s;
    do
    {
        s.push_back('0' + (x & 1));
        // cout<<s<<endl;
    } while (x >>= 1);
    reverse(s.begin(), s.end());
    return s;
}

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

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

    ll t=1;
    // cin>>t;
    while(t--){
        string s1,s2;
        cin>>s1>>s2;
        ll a=bitset<64>(s1).to_ullong(),b=bitset<64>(s2).to_ullong();
        a=a^b;
        string bin=binary(a);
        string s(s1.size()-bin.size(),'0');
        bin=s+bin;
        cout<<bin<<endl;
    }
    return 0;
}


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

typedef long long ull;

ull n;

bool tr(ull k) {
	ull s1 = 0, s2 = 0, t = n, l = (n - 1) / 2 + 1;
	while (t) {
		if (t < k) {
			s1 += t;
			t = 0;
		}
		else {
			t -= k;
			s1 += k;
		}
		s2 += t / 10;
		t -= t / 10;
		if (s1 >= l)
			return true;
		if (s2 > l)
			return false;
	}
}

int main() {
	cin >> n;
	ull l = 1, r = n;
	while (r - l > 1) {
		ull m = l + (r - l) / 2;
		if (tr(m))
			r = m;
		else
			l = m + 1;
	}
	if (!tr(l))
		++l;
	cout << l << endl;
	system("pause");
	return 0;
}


//#include "stdafx.h"
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <stdio.h>
#include <string>
#include <iomanip>
#include <utility>
#include <algorithm>
#include <queue>
#include <set>
#include <cmath>

typedef long long ll;
typedef long double ld;
const ll INF = 9999999999999;

#define forn(ii,kk,nn) for(ll ii = kk; ii < nn; ++ii)

using namespace std;
using namespace std;

ll fact(ll n)
{
    ll res = 1;
    forn(i,1,n+1)
    {
            res*=i;
            res %= (ll)(1e9+7);
    }
    return res;
}

int main()
{
    //freopen("area.in","r",stdin);
     //freopen("area.out","w",stdout);
    ll n;
    cin >> n;
    vector<ll> s(n+1,0);
    s[1] = 1;
    s[3] = 3;
    s[5] = 15;
    s[7] = 133;
    s[9] = 2025;
    s[11] = 37851;
    s[13] = 1030367;
    s[15] = 36362925;
    if(n%2==0)
    {
        cout << fact(n) << endl;
        return 0;
    }
    cout << s[n]*fact(n) << endl;
    return 0;
}


#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <sstream>
#include <cmath>
#include <cstring>
#include <deque>
#include <set>
#include <queue>
#include <stack>
#include <utility>
#include <forward_list>
#include <fcntl.h>
#include <set>

#define gcd(x,y) __gcd(x,y)
#define pair(x, y) make_pair(x, y)

using namespace std;

typedef forward_list < int > adj_list;

typedef vector < adj_list > graph;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int n;
	cin >> n;
	vector<int> colors(3);
	for(int i = 0; i < n; ++i) {
	  char c;
	  cin >> c;
	  if(c == 'R') {
	    ++colors[0];
	  }
	  else if(c == 'G') {
	    ++colors[1];
	  }
	  else if(c == 'B') {
	    ++colors[2];
	  }
	  else {
	    --i;
	  }
	}
	set<char> s;
	queue<vector<int>> q;
	q.push(colors);

	while(!q.empty()) {
	  auto x = q.front();
	           q.pop();
	  int a = x[0];
	  int b = x[1];
	  int c = x[2];

	  if(s.size() == 3)
	    break;

	  if(a == 0 && b == 0)
	    s.insert('B');
	  else if(c == 0 && b == 0)
	    s.insert('R');
	  else if(a == 0 && c == 0)
	    s.insert('G');
	  else {
	    if(a > 0 && b > 0)
	      q.push((vector<int>&&) {a-1, b - 1, c + 1});

	    if(b > 0 && c > 0)
	      q.push((vector<int>&&) {a+1, b - 1, c - 1});

	    if(a > 0 && c > 0)
	      q.push((vector<int>&&) {a-1, b + 1, c - 1});

	    if(a < 3 && a > 1)
	      q.push((vector<int>&&) {a-1, b, c});
	    if(b < 3 && b > 1)
	      q.push((vector<int>&&) {a, b-1, c});
	    if(c < 3 && c > 1)
	      q.push((vector<int>&&) {a, b, c-1});
	  }
	}

	for(auto & c : s)
	  cout << c;

	cout.flush();
}


#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <climits>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <deque>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <list>
#include <bitset>
#include <cassert>
#define clr(x) memset((x), 0, sizeof(x))
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define mp make_pair
#define For(i, st, en) for(int i=(st); i<=(int)(en); i++)
#define Ford(i, st, en) for(int i=(st); i>=(int)(en); i--)
#define forn(i, n) for(int i=0; i<(int)(n); i++)
#define ford(i, n) for(int i=(n)-1; i>=0; i--)
#define fori(it, x) for (__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define in(x) int (x); input((x));
#define x first
#define y second
#define less(a,b) ((a) < (b) - EPS)
#define more(a,b) ((a) > (b) + EPS)
#define eq(a,b) (fabs((a) - (b)) < EPS)
#define remax(a, b) ((a) = (b) > (a) ? (b) : (a))
#define remin(a, b) ((a) = (b) < (a) ? (b) : (a))
using namespace std; typedef long double ld; template <class _T> inline _T sqr(const _T& x) {return x * x;} template <class _T> inline string tostr(const _T& a) {ostringstream os(""); os << a; return os.str();} const ld PI = 3.1415926535897932384626433832795L; const ld EPS = 5e-12; char TEMPORARY_CHAR; typedef long long ll; typedef unsigned long long ull; typedef set < int > SI; typedef vector < int > VI; typedef vector < vector < int > > VVI; typedef map < string, int > MSI; typedef pair < int, int > PII; const int INF = 1e9; typedef complex<ld> cbase; inline void fft (vector<cbase> &a, bool invert) {int n = (int)a.size(); for (int i = 1, j = 0; i < n; ++i) {int bit = n >> 1; for (; j >= bit; bit >>= 1) j -= bit; j += bit; if (i < j) swap(a[i], a[j]);} for (int len = 2; len <= n; len <<= 1) {ld ang = 2 * PI / len * (invert ? -1 : 1); cbase wlen(cos(ang), sin(ang)); for (int i = 0; i < n; i += len) {cbase w(1); for (int j=0; j < len / 2; ++j) {cbase u = a[i + j], v = a[i + j + len / 2] * w; a[i + j] = u + v; a[i + j + len / 2] = u - v; w *= wlen;}}} if (invert) for (int i = 0; i < n; ++i) a[i] /= n;} inline void input(int &a) {a = 0; while (((TEMPORARY_CHAR = getchar()) > '9' || TEMPORARY_CHAR < '0') && (TEMPORARY_CHAR != '-')){} char neg = 0; if (TEMPORARY_CHAR == '-') {neg = 1; TEMPORARY_CHAR = getchar();} while (TEMPORARY_CHAR <= '9' && TEMPORARY_CHAR >= '0') {a = (a << 3) + (a << 1) + TEMPORARY_CHAR - '0'; TEMPORARY_CHAR = getchar();} if (neg) a = -a;} inline void out(ll a) {if (!a) putchar('0'); if (a < 0) {putchar('-'); a = -a;} char s[20]; int i; for(i = 0; a; ++i) {s[i] = '0' + a % 10; a /= 10;} ford(j, i) putchar(s[j]);} inline int nxt() {in(ret); return ret;} struct lnum {vector <int> a; int base; lnum(int num = 0, int base = 1000000000):base(base) {if (!num) a.resize(1); while(num) {a.pb(num % base); num /= base;}} inline int len() const {return a.size();} lnum & operator=(const lnum &l) {if (this != &l) {a = l.a; base = l.base;} return *this;} inline friend lnum operator+(const lnum &l, const lnum &r) {lnum ret(0, l.base); int base = l.base; int ln = l.len(), rn = r.len(); int n = max(ln, rn); ret.a.resize(n); int o = 0; for(int i = 0; i < n; ++i) {int s = o; if (i < ln) s += l.a[i]; if (i < rn) s += r.a[i]; o = s >= base; if (o) s -= base; ret.a[i] = s;} if (o) ret.a.push_back(1); return ret;} inline friend lnum operator-(const lnum &l, const lnum &r) {lnum ret(0, l.base); int base = l.base; int n = l.len(); int rn = r.len(); ret.a.resize(n); int o = 0; for(int i = 0; i < n; ++i) {int s = l.a[i] - o; if (i < rn) s -= r.a[i]; o = s < 0; if (o) s += base; ret.a[i] = s;} if (ret.len() > 1 && !ret.a.back()) ret.a.pop_back(); return ret;} inline friend lnum operator*(const lnum &l, const lnum &r) {lnum ret(0, l.base); int base = l.base; if (l.len() * r.len() > 1000000) {vector<cbase> fa (l.a.begin(), l.a.end()), fb (r.a.begin(), r.a.end()); int n = 1; while (n < max (l.len(), r.len())) n <<= 1; n <<= 1; fa.resize (n), fb.resize (n); fft (fa, false), fft (fb, false); for (int i = 0; i < n; ++i) fa[i] *= fb[i]; fft (fa, true); ret.a.resize(n); for (int i = 0; i < n; ++i) ret.a[i] = int (fa[i].real() + 0.5); int carry = 0; for (int i=0; i < n; ++i) {ret.a[i] += carry; carry = ret.a[i] / base; ret.a[i] %= base;}} else {ret.a.resize(l.len() + r.len()); for (int i = 0; i < l.len(); ++i) for (int j = 0, carry = 0; j < r.len() || carry; ++j) {long long cur = ret.a[i + j] + (ll)l.a[i] * (j < r.len() ? r.a[j] : 0) + carry; ret.a[i + j] = cur % base; carry = cur / base;}} while (ret.len() > 1 && !ret.a.back()) ret.a.pop_back(); return ret;} inline friend lnum operator/(const lnum &l, const int &r) {lnum ret(0, l.base); ret.a.resize(l.len()); int carry = 0; for(int i = l.len() - 1; i >= 0; --i) {long long cur = l.a[i] + (ll)carry * l.base; ret.a[i] = cur / r; carry = cur % r;} while (ret.len() > 1 && ret.a.back() == 0) ret.a.pop_back(); return ret;}  inline friend bool operator<(const lnum &l, const lnum &r) {if (l.len() < r.len()) return true; if (l.len() > r.len()) return false; int n = l.len(); for(int i = n - 1; i >= 0; --i) {if (l.a[i] < r.a[i]) return true; if (l.a[i] > r.a[i]) return false;} return false;} inline friend bool operator>(const lnum &l, const lnum &r) {return r < l;} inline friend bool operator==(const lnum &l, const lnum &r) {if (l.len() != r.len()) return false; int n = l.len(); for(int i = n - 1; i; --i) {if (l.a[i] != r.a[i]) return false;} return true;} inline friend bool operator!=(const lnum &l, const lnum &r) {return !(l == r);} inline void print() {if (base == 1000000000) {printf("%d", a.back()); for(int i = a.size() - 2; i >=0; --i) printf("%09d", a[i]);} else {for(int i = a.size() - 1; i >= 0; --i) printf("%d", a[i]);}}};

vector <int> per;
vector <int> kol;

vector <ll> ans;

void rec()
{
    int n = per.size();
    int cnt = 0;
    forn(i, n)
    {
        if (kol[i])
        {
            For(j, i + 1, n - 1)
            {
                if (kol[j])
                {
                    ++cnt;
                    kol[i]--;
                    kol[j]--;
                    swap(per[i], per[j]);
                    rec();
                    swap(per[i], per[j]);
                    kol[i]++;
                    kol[j]++;
                }
            }
        }
    }
    ll ha = 0;
    forn(i, n)
        ha = ha * n + per[i];
    ans.pb(ha);
}

int main()
{
    in(n);
    per.resize(n);
    kol.resize(n);
    forn(i, n)
    {
        kol[i] = nxt();
        per[i] = i;
    }
    rec();
    sort(all(ans));
    cout << unique(all(ans)) - ans.begin() << endl;
    return 0;
}


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

#define fi first
#define se second
#define pb push_back
#define sz(a) ((int)a.size())
#define abs(a) ((a)<0 ? ((a)*-1) : (a))

using namespace std;

typedef pair<int,int> ii;
typedef long long int Lint;

const int MAXN=100;

int N;
int ar[MAXN];
int fact[MAXN];

string s;

vector<string> res;

void f(){

	res.pb(s);

	for( int i=0 ; i<N-1 ; i++ )
		for( int j=i+1 ; j<N ; j++ )
			if( ar[i] && ar[j] ){
				swap(s[i],s[j]);
				ar[i]--;
				ar[j]--;
				f();
				swap(s[i],s[j]);
				ar[i]++;
				ar[j]++;
			}

}

int main(){

	scanf(" %d",&N);

	fact[0]=1;
	for( int i=1 ; i<=N ; i++ )
		fact[i]=fact[i-1]*i;

	for( int i=0 ; i<N ; i++ )
		scanf(" %d",ar+i);

	switch(N){
		case 1: s="1";f();
		break;
		case 2: s="12";f();
		break;
		case 3: s="123";f();
		break;
		case 4: s="1234";f();
		break;
		case 5: s="12345";f();
		break;
		case 6: s="123456";f();
		break;
		case 7: s="1234567";f();
		break;
		case 8: s="12345678";f();
		break;
		case 9: s="123456789";f();
		break;
		case 10: s="1234567890";f();
	}

	sort(res.begin(),res.end());
	res.resize(unique(res.begin(),res.end())-res.begin());
	printf("%d\n",sz(res));
	return 0;
}


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

#define ff first
#define ss second

int main()
{
    ios_base::sync_with_stdio(false),cin.tie(NULL);
    int n=0,m=0;
    cin>>n>>m;
    vector<pair<int,int>> v;
    map<pair<int,int>,int> we;
    vector<pair<int,int>> v1;
    map<pair<int,int>,int> we1;
    for(int i=0;i<n;i++)
    {
        int x,y;
        cin>>x>>y;
        v.push_back({x,y});
        we[{x,y}]=i;
    }
    for(int i=0;i<m;i++)
    {
        int x,y;
        cin>>x>>y;
        v1.push_back({x,y});
        we1[{x,y}]=i;
    }
    vector<vector<int>> dp(n+1,vector<int>(3,0));
    vector<vector<int>> dp1(m+1,vector<int>(3,0));

    for(auto u:v)
    {
        for(auto p:v1)
        {
            if(u==p) continue;
            if(u.ff==p.ff and u.ss!=p.ss) dp[we[u]][1]=1;
            else if(u.ff==p.ss and u.ss!=p.ff) dp[we[u]][1]=1;
            else if(u.ss==p.ss and u.ff!=p.ff) dp[we[u]][2]=1;
            else if(u.ss==p.ff and u.ff!=p.ss) dp[we[u]][2]=1;
        }
    }

    for(auto u:v1)
    {
        for(auto p:v)
        {
            if(u==p) continue;
            if(u.ff==p.ff and u.ss!=p.ss) dp1[we1[u]][1]=1;
            else if(u.ff==p.ss and u.ss!=p.ff) dp1[we1[u]][1]=1;
            else if(u.ss==p.ss and u.ff!=p.ff) dp1[we1[u]][2]=1;
            else if(u.ss==p.ff and u.ff!=p.ss) dp1[we1[u]][2]=1;
        }
    }

    int cnt=0,fl=0,ans=-1;
    int cnt1=0,fl1=0,ans1=-1;

    for(int i=0;i<n;i++)
    {
        if(dp[i][1] and dp[i][2]) fl=1;
        else if(dp[i][1])
        {
            cnt++;
            ans=v[i].ff;
        }
        else if(dp[i][2])
        {
            cnt++;
            ans=v[i].ss;
        }
    }

    for(int i=0;i<m;i++)
    {
        if(dp1[i][1] and dp1[i][2]) fl1=1;
        else if(dp1[i][1])
        {
            cnt1++;
            ans1=v1[i].ff;
        }
        else if(dp[i][2])
        {
            cnt1++;
            ans1=v1[i].ss;
        }
    }

    if(cnt==1 and fl==0) cout<<ans;
    else if(cnt1==1 and fl1==0) cout<<ans1;
    else if(fl==0 and fl1==0) cout<<"0";
    else cout<<"-1";
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define PB push_back
#define MP make_pair
#define F first
#define S second
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9 + 7;
const int MAXD = 5;

const int MAXN = 10;
const int MAXM = 275;

int hx[] = {1, 2, 2, 1, -1, -2, -2, -1};
int hy[] = {2, 1, -1, -2, -2, -1, 1, 2};

int n;
int A[MAXN][MAXN];
pii dist[MAXM][MAXM];
pii dp[MAXN * MAXN][3];
// pii road[MAXN * MAXN][3];
pii pos[MAXN * MAXN];

pii operator+(pii a, pii b) {
	return MP(a.F + b.F, a.S + b.S);
}

int getIndex(int x, int y, int b) {
	return 3 * x * n + 3 * y + b;
}

bool isInside(int x, int y) {
	return (0 <= x && x < n && 0 <= y && y < n);
}

void input() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			cin >> A[i][j];
			A[i][j]--;
			pos[A[i][j]] = MP(i, j);
		}
	}
}

void solve() {

	for (int i = 0; i < MAXM; i++) {
		for (int j = 0; j < MAXM; j++) {
			dist[i][j] = MP(INF, INF);
		}
	}
	for (int i = 0; i < MAXM; i++) {
		dist[i][i] = MP(0, 0);
	}

	for (int x = 0; x < n; x++) {
		for (int y = 0; y < n; y++) {
			// ruch skoczkiem - 0
			for (int h = 0; h < 8; h++) {
				int wx = x + hx[h];
				int wy = y + hy[h];
				if (isInside(wx, wy)) {
					dist[getIndex(x, y, 0)][getIndex(wx, wy, 0)] = MP(1, 0);
				}
			}
			// ruch wieza - 1
			for (int w = 0; w < n; w++) {
				if (w != x) { // pionowy
					dist[getIndex(x, y, 1)][getIndex(w, y, 1)] = MP(1, 0);
				}
				if (w != y) { // poziomy
					dist[getIndex(x, y, 1)][getIndex(x, w, 1)] = MP(1, 0);
				}
			}
			// ruch goncem - 2
			for (int g = -n + 1; g < n; g++) {
				if (g == 0) {
					continue;
				}
				if (isInside(x + g, y + g)) {
					dist[getIndex(x, y, 2)][getIndex(x + g, y + g, 2)] = MP(1, 0);
				}
				if (isInside(x + g, y - g)) {
					dist[getIndex(x, y, 2)][getIndex(x + g, y - g, 2)] = MP(1, 0);
				}
			}
			// zmiana bierki
			for (int b1 = 0; b1 < 3; b1++) {
				for (int b2 = 0; b2 < 3; b2++) {
					if (b1 != b2) {
						dist[getIndex(x, y, b1)][getIndex(x, y, b2)] = MP(1, 1);
					}
				}
			}
		}
	}

	for (int k = 0; k < MAXM; k++) {
		for (int i = 0; i < MAXM; i++) {
			for (int j = 0; j < MAXM; j++) {
				dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
			}
		}
	}

	for (int i = 0; i < MAXN * MAXN; i++) {
		for (int b = 0; b < 3; b++) {
			dp[i][b] = MP(INF, INF);
		}
	}

	dp[0][0] = dp[0][1] = dp[0][2] = MP(0, 0);
	for (int i = 0; i < n * n - 1; i++) {
		for (int b1 = 0; b1 < 3; b1++) {
			for (int b2 = 0; b2 < 3; b2++) {
				dp[i + 1][b2] = min(dp[i + 1][b2], dp[i][b1]
					+ dist[getIndex(pos[i].F, pos[i].S, b1)][getIndex(pos[i + 1].F, pos[i + 1].S, b2)]);
				/* if (dp[i][b1] + dist[getIndex(pos[i].F, pos[i].S, b1)][getIndex(pos[i + 1].F, pos[i + 1].S, b2)] < dp[i+1][b2]) {
					dp[i + 1][b2] = dp[i][b1]
						+ dist[getIndex(pos[i].F, pos[i].S, b1)][getIndex(pos[i + 1].F, pos[i + 1].S, b2)];
					road[i+1][b2] =

				}*/
			}
		}
	}

	pii ans = MP(INF, INF);
	for (int b = 0; b < 3; b++) {
		ans = min(ans, dp[n * n - 1][b]);
	}
	cout << ans.F << " " << ans.S << "\n";

	/* int figura = -1;
	for (int i = 0; i < n * n; i++) {
		ans = MP(INF, INF);
		for (int b = 0; b < 3; b++) {
			if (ans > dp[i][b]) {
				ans = dp[i][b];
				figura = b;
			}
		}
		cout << i + 1 << ": " << ans.first << " " << ans.second;
		if (figura == 0) cout << "skoczek";
		if (figura == 1) cout << "wieza";
		if (figura == 2) cout << "goniec";
		cout << "\n";
	}
	*/
	// cout << ans.F << " " << ans.S << "\n";

}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);

	input();
	solve();

	return 0;
}


//
//  main.cpp
//  codeforces 3
//
//  Created by dive5617 on 13-6-26.
//  Copyright (c) 2013年 dive5617. All rights reserved.
//

#include <iostream>
#include <cstdio>
#include <cmath>
#define mx 1000
#define mod 1000000007
using namespace std;

int len;

long long sum(int pos){
    long long all=0;
    int t=0;
    for(int i=len-1; i>=pos; i--){
        long long tmp=(long long)pow(2,t)%mod;
        tmp*=tmp;
        all+=tmp%mod;
        t++;
    }
    return all;
}

int main(){
    char str[mx];
    long long ans;
    while(cin>>str){
        ans=0;
        len=strlen(str);
        for(int i=len-1; i>=0; i--){
            if(str[i]=='1') {ans+=sum(i)%mod; }
            else if(str[i]=='0') ans*=2;
        }
        cout<<ans<<endl;
    }
    return 0;
}


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

#define pb push_back
#define pii pair<int,int>
#define ll long long
#define pll pair<long,long>
#define vi vector<int>
#define vii vector<pii>
#define vll vector<ll>
#define MOD 1000000007
#define EPS 1e-7
#define mem(x,y) memset(x,y,sizeof x)
#define MAX 4e18
#define ff(i,a,b) for(int i=(a);i<=(b);i++)
#define fb(i,a,b) for(int i=(a);i>=(b);i--)

class compare{
public:
    bool operator()(pii x,pii y){
        if(x.second==y.second){
            return x.first<y.first;
        }
        return x.second<y.second;
    }
};
int Set(int N,int pos) { return N=N|(1<<pos); }
int reset(int N,int pos){ return N=N&~(1<<pos);}
bool check(int N,int pos){  return (bool) (N&(1<<pos));}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    int a,b; cin>>a>>b;
    if(a==b){
        cout<<"infinity"<<endl;
        return 0;
    }

    if(a==0){
        cout<<0<<endl;
        return 0;
    }

    if(a<b){
        cout<<0<<endl;
        return 0;
    }

    int ans=0;
    ff(i,b,a){
        if(a%i==b){
            ans++;
        }
    }
    cout<<ans<<endl;

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,a,b,c,u,v;
	int ans=0;
	cin>>n>>a>>b>>c;
	for(int i=0;(i*0.5<=n)&&(i<=a);i++)
		for(int j=0;(j+i*0.5<=n)&&(j<=b);j++)
			if(i+j*2==n){
                if(j*2==n){
                    ans++;
                    continue;
                }
                if(max(u/2,v)>=i) ans+=min(i+1,min(u/2,v)+1);
                else ans+=min(u/2,v)-(i-max(u/2,v))+1;
            }
	cout<<ans<<endl;
	return 0;
}


#include<iostream>
#include<cmath>

using namespace std;

typedef long long ll;

ll mini(ll a[],ll l)
{
    ll m=a[0];
    for(ll i=0;i<l;i++)
    {
        if(a[i]<m)
            m=a[i];
    }
    return m;
}

int main()
{
    ll n,a,b,c,k;
    cin >> n >> a >> b >> c;
    k=4-(n%4);
    // total books to buy k
    ll r[3];
    ll ans;
    if(k==3)
    {
        r[0]=c;

        r[1]=b+a;

        r[2]=3*a;

        r[3]=a+2*b;
        ans =mini(r,4);
    }
    else if(k==2)
    {
        r[0]=b;

        r[1]=2*a;

        r[2]=2*c;

        r[3]=3*b;

        ans =mini(r,4);
    }
    else if(k==1)
    {
        r[0]=a;

        r[1]=c+b;

        r[2]=3*c;

        r[3]=3*b+c;

        r[4]=4*c+a;

        r[5]=6*b+a;

        ans=mini(r,6);
    }
    else
        ans=0;
    cout << ans << endl;
    return 0;

}


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

vector < ll > v ;

void fill ( ll n ){
  for ( int i = 1 ; i <= n ; i*=2 ){
    v.push_back(i) ;
  }
}

main ()

{
  ll n, k ;
  cin >> n >> k ;
  fill(n) ;

  ll ans = 0 ;
  ll fin = v.size()-1 ;
  for ( int i = fin ; i >= fin-k+1 && i >= 0 ; i-- ){
    ans += v[i] ;
  }
  cout << ans << endl ;
  return 0 ;
}


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

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

	int a[n],i,x,j,ans,max,temp;

	vector<int> vec,t;

	for(i=0; i<n; i++)
	{
		cin>>x;
		vec.push_back(x);
	}

	max=INT_MIN;
	ans=INT_MAX;

	for(i=1; i<=n-2; i++)
	{
		temp=vec[i];
		vec.erase(vec.begin()+i);

		for(j=0; j<n-1; j++)
			if(vec[j+1]-vec[j]>max)
				max=vec[j+1]-vec[j];

		t.push_back(max);

		vec.push_back(temp);
		sort(vec.begin(),vec.end());
	}

	sort(t.begin(),t.end());
	cout<<t[0]<<endl;
}


#include <bits/stdc++.h>

using namespace std;

#define maxn 150010
#define ff first
#define ss second
#define endl '\n'
typedef long long ll;

int n, m;
string s, t;
int ans = 0;

bool nxt(int idx, int from) {
  if (idx == m) return true;
  bool f = 0;
  for (int i = from + 1; i < n; ++i) {
    if (s[i] == t[idx]) {
      if (nxt(idx + 1, i)) {
        ans = max(i - from - 1, ans);
        if (idx == m - 1) {
          ans = max(ans, n - i - 1);
          f = 1;
        }
        f = 1;
      }
      else break;
    }
  }
  if (f) return true;
  return false;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> s >> t;
  n = s.size();
  m = t.size();
  for (int i = 0; i < n; ++i) {
    if (s[i] == t[0]) {
      if (nxt(1, i)) ans = max(ans, i);
      else break;
    }
  }
  cout << ans << endl;
}


#include<stdio.h>
int main()
{
	int n,i;
	double m;
	while(~scanf("%d",&n),n)
	{
		m=(n-2)*(n-2)*1.0;
		printf("%.0lf\n",m);
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    char s[n];
    cin>>s;
    vector<char> a;
    a.push_back(s[0]);
    int i=1,j=2,cnt=1;
        while(s[i]!='/0')
        {
            a.push_back(s[i]);
          while(cnt<j)
          {
              i++;
              cnt++;
          }
          j++;
        }
        for(int i=0;i<a.size();i++)
            cout<<a[i];
        return 0;
}


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

int main() {
	int n;
	cin >> n;
	int a[n], max = 0;
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
		if (a[i] > max)
			max = a[i];
	}
	int b[max];
	for (int i = 0; i < max; ++i)
	{
		b[i] = 0;
	}
	for (int i = 0, j = 0; j < max; ++i)
	{
		if (i == n) {
			j++;
			i = 0;
		}
		if (j == max)
			break;
		if (a[i]) {
			a[i]--;
			b[j++];
		}
	}
	for (int i = max-1; i >= 0; ++i)
	{
		cout << b[i] << ' ';
	}
	cout << '\n';
	return 0;
}


#include<iostream>
using namespace std;
int n, m, k;
int ans;
int main()
{
	cin >> n >> m;
	if(n == m)
	{
		cout << 0;
		return 0;
	}
	if(m % n != 0)
	{
		cout << -1;
		return 0;
	}
	k = m / n;
	cout << ans;
	return 0;
}


#include <bits/stdc++.h>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstring>
#include <chrono>
#include <complex>
#define endl "\n"
#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define vvi vector < vi >
#define pii pair<int,int>
#define pll pair<long long, long long>
#define mod 1000000007
#define inf 1000000000000000001;
#define all(c) c.begin(),c.end()
#define mp(x,y) make_pair(x,y)
#define mem(a,val) memset(a,val,sizeof(a))
#define eb emplace_back
#define f first
#define s second

using namespace std;

void solve(){
	int n, sum =0;
	cin>>n;
	int x = n%10;
	while(x>0){
		sum++;
		n /= 10;
	}
	int ans = ((x-1)*10)+ (sum *(sum+1))/2;
	cout<<ans<<endl;

}

int main()
{
	std::ios::sync_with_stdio(false);
	int T;
	cin >> T;
	// cin.ignore(); must be there when using getline(cin, s)
	while (T--)
	{
		solve();
	}
	return 0;
}


#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,avx")
#pragma GCC target ("avx2,fma")
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
//#include <atcoder/all>

#define F first
#define S second
#define int long long
#define ll long long
//#define int  unsigned long long
#define pb push_back
#define rank fewfewf
#define double long double

using namespace std;
using namespace __gnu_pbds;
//using namespace atcoder;

typedef  tree< int , null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int N = 1100105;
const int K = 90;
const int mod = 1e9 + 7;
int p[N], a[N], have[N], b[N], taken[N];
vector<pair<int,int>> d[N];
main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int n;
    cin >> n;
    for (int i = 2; i < N; i++){
        if (p[i] == 0){
            for (int j = i; j < N; j++){
                p[j] = i;
            }
        }
    }
    for (int i = 0; i < n; i++) cin >> a[i];
    reverse(a, a + n);
    for (int i = 0; i < n; i++){
        if (taken[a[i]]){
            b[i] = a[i] - 1;
            int y = b[i];
            while(y != 1){
                int x = p[y];
                int k = 0;
                while(y % x == 0){
                    y /= x;
                    k++;
                }
                d[i].pb({x, k});
            }
            for (auto x: d[i]){
                taken[x.F] = 1;
            }
        } else{
            b[i] = a[i];
            taken[a[i]] = 1;
            d[i].pb({a[i], 1});
        }
    }
    int z = 0;
    for (int i = 0; i < n; i++){
        int ok = 0;
        for (auto x: d[i]){
            if (have[x.F] < x.S) ok = 1;
            have[x.F] = max(x.S, have[x.F]);
        }
        if (!ok) z = 1;
    }
    int res = 1;
    for (int i = 1; i < N; i++){
        for (int j = 0; j < have[i]; j++){
            res = res * i % mod;
        }
    }
    cout << (z + res) % mod;
}


#include<iostream>
using namespace std;
int main()
{
   int n,i,k,m,s=0;
   cin>>n;
   i=n-1;
   k=1;
   while(i==k)
   {
       m=i*k;
       s=s+m;
   }
   s=2*s+i*i+n;
   cout<<s;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
long long int s(long long int i)
{
   long long int k=i,sum=0;
    while(k!=0)
    {
     sum+=k%10;
     k=k/10;
     }

   return sum;
}

/*int bs(int i,int j)
{
        long long int lo=1,hi=q;
              while(lo <= hi)
              {
                 long long int mi = lo + (hi - lo) / 2;

                  if(ok(mi))
                    {
                     lo=mi+1;

                    else
                    {
                    hi=mi-1;
                    }
              }

            return lo;
    }*/
    int main()
    {   long long int n,a[100],p=1;
    cin>>n;
     	  for(int i=sqrt(n);i>=1;--i)
     	  {
                if(n%i==0){
                        a[p]=n/i;++p;a[p]=i;++p;
                }

          }
    sort(a+1,a+p);
    for(int i=1;i<p;++i)
    {
        long long int x=sqrt(s(a[i])*s(a[i])+4*n)-s(a[i]);

     if((x%2==0)&&((x+s(a[i]))*(x+s(a[i])))==(s(a[i])*s(a[i])+4*n))
      {

      cout<<x/2<<"\n";return 0;
      }
     }

    cout<<-1<<"\n";
    }


#include<iostream>
#include<algorithm>
#include<bitset>
using namespace std;
bitset<550> grid[550];
bool used[550];
int cha[550];
int main() {
    ios::sync_with_stdio(0);
    int n, m;cin >> n >> m;
    for (int i = 1;i <= m;++i) {
        int a, b;cin >> a >> b;
        grid[a][b] = 1;grid[b][a] = 1;
    }for (int i = 1;i <= n;++i)grid[i][i] = 1;
    int tot = 0;
    for (int i = 1;i <= n;++i) {
        if (used[i])continue;
        used[i] = 1;cha[i] = ++tot;
        for (int j = i + 1;j <= n;++j) {
            if (!used[j] && grid[i] == grid[j]) {
                used[j] = true;
                cha[j] = cha[i];
            }
        }
    }
    if (tot > 3) {
        cout << "NO\n";
    }
    else if (tot <= 2) {
        cout << "YES\n";
        for (int i = 1;i <= n;++i)
            cout << (char)('a' + cha[i] - 1);
    }
    else {
        int cct[4] = { 0,0,0,0 };
        int cmp1[4] = { -1,-1,-1,-1 };
        int cmp2[4] = { -1,-1,-1,-1 };
        for (int i = 1;i <= n;++i) {
            for (int j = 1;j <= n;++j) {
                if (grid[i][j] && cha[i] != cha[j]) {
                    if (cmp1[cha[i]] == -1 || cmp1[cha[i]] == cha[j]) {
                        if (cmp1[cha[i]] == -1)++cct[cha[i]];
                        cmp1[cha[i]] = cha[j];
                    }
                    else if (cmp2[cha[i]] == -1 || cmp2[cha[i]] == cha[j]) {
                        if (cmp2[cha[i]] == -1)++cct[cha[i]];
                        cmp2[cha[i]] = cha[j];
                    }
                    else {
                        if (cha[j] != cmp1[cha[i]] && cha[j] != cmp2[cha[i]]) {
                            cout << "NO\n";
                            return 0;
                        }
                    }
                }
            }
        }int c1 = 0;int c2 = 0;
        for (int i = 1;i <= 3;++i)
            if (cct[i] == 2)++c1;
            else if (cct[i] == 1)++c2;
        if (c1 == 1 && c2 == 2) {
            char mp[4] = { 0,0,0 };
            char ch = 'a';
            for (int i = 1;i <= 3;++i)
                if (cct[i] == 2)mp[i] = 'b';
                else {
                    mp[i] = ch;
                    ch += 2;
                }
            cout << "YES\n";
            for (int i = 1;i <= n;++i)
                cout << mp[cha[i]];
        }
        else cout << "NO\n";

    }
}


#include<bits/stdc++.h>
using namespace std;
int a,b,c,d,e,f;
int gett(int y,int m,int d){
	if(m < 3){
		y-=1;
        m+=12;
	}
    return 365*y+y/4-y/100 +y/400+ (153*m-457)/5+d-306;
}
int main(){
	scanf("%d:%d:%d",&a,&b,&c);
	scanf("%d:%d:%d",&d,&e,&f);
	cout<<gett(d,e,f)-gett(a,b,c);
	return 0;
}


#include <vector>
#include <cstdio>
#include <set>
#include <map>
#include <algorithm>
#include <cstdlib>
#include <sstream>
#include <numeric>
#include <queue>
#include <iostream>
#include <string>
#include <cstring>
#include <utility>
#define sz(a) ((int)(a).size())
#define pb push_back
#define mk make_pair
#define fi first
#define se second
#define Rep(i,j,k) for (int i=(j); i<=(k); i++)
#define Repd(i,j,k) for (int i=(j); i>=(k); i--)
#define ALL(c) (c).begin(),(c).end()
#define TR(c,i) for(typeof((c).begin()) i = (c).begin(); i != (c).end(); i++)
#define SUM(a) accumulate(all(a),string())
#define online1
#define RAND ((rand()<<15)+rand())
using namespace std;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef pair<int,int> II;
typedef long long LL;

const int MOD=51123987;
const int N=54;

int n;
char s[N];
int f[151][N][N][N];

void update(int &x, int y){
	x=(x+y)%MOD;
}

int main(){
	cin>>n;
	scanf("%s",s+1);
	f[0][0][0][0]=1;
	int ans=0;
	Rep(i,0,n)
		Rep(j,0,min(52,n))
			Rep(k,0,min(52,n-j))
				Rep(l,0,min(52,n-j-k))if (f[i][j][k][l]){
					if (j+k+l==n)
						if (abs(j-k)<=1 && abs(j-l)<=1 && abs(k-l)<=1)
							update(ans,f[i][j][k][l]);
					int num[3]={0,0,0};
					if (i!=0) num[s[i]-'a']++;
					Rep(x,i+1,n){
						if (num[s[x]-'a']++) continue;
						if (s[x]=='a')
							update(f[x][j+1][k][l], f[i][j][k][l]);
						if (s[x]=='b')
							update(f[x][j][k+1][l], f[i][j][k][l]);
						if (s[x]=='c')
							update(f[x][j][k][l+1], f[i][j][k][l]);
					}
					if (!i) continue;
					if (s[i]=='a')
						update(f[i][j+1][k][l],f[i][j][k][l]);
					if (s[i]=='b')
						update(f[i][j][k+1][l],f[i][j][k][l]);
					if (s[i]=='c')
						update(f[i][j][k][l+1],f[i][j][k][l]);
				}

	cout<<ans<<endl;

    return 0;
}


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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N;
ll mo=1000000007;

ll dp[405][405];

void solve() {
	int i,j,k,l,r,x,y; string s;

	dp[0][0]=1;
	for(i=1;i<=400;i++) {
		FOR(x,404) FOR(y,404) if(x+y<404) {
			ll pat=dp[i-1][x]*dp[i-1][y]%mo;
			//take 0 and connect 1
			(dp[i][x+y] += pat*(1+2*(x+y))%=mo;
			//connect 2
			if(x+y>0) (dp[i][x+y-1] += pat*((x+y)*(x+y-1)))%=mo;
			//new
			dp[i][x+y+1] += pat;
			if(dp[i][x+y+1]>=mo) dp[i][x+y+1]-=mo;
		}
	}
	cin>>N;
	cout<<dp[N][1]<<endl;

}

int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n';
	FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	solve(); return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,m;cin>>n>>m;
	if(m==0)
	return 1;
	int k=(n+1)/2;
	if(m<k)
	cout<<m;
	else
	cout<<n-m;
}