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

int a, ta;
int b, tb;
int h, m;
inline int max(int a, int b)
{
	return a < b ? b : a;
}
inline int min(int a, int b)
{
	return a < b ? a : b;
}

bool read() {
	if (!(cin >> a >> ta)) return false;
	cin >> b >> tb;
	char c;
	cin>>h>>c>>m;
	return true;
}

int main() {
	read();
	int x1 = h * 60 + m;
	int y1 = x1 + ta;

	int ans = 0;
	for (int x2 = 5 * 60 + 0; x2 < 24 * 60; x2 += b) {
		int y2 = x2 + tb;
		int x = max(x1, x2), y = min(y1, y2);
		if (x < y)
			ans++;
	}
	cout << ans << endl;
}


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

int n, sx[10], id[10], sy[10], fx[10], fy[10], SX[10], SY[10], FX[10], FY[10];

int main() {
    for (int i = 1; i <= 4; i ++) {
		scanf("%d %d %d %d", &SX[i], &SY[i], &FX[i], &FY[i]);
        id[i] = i;
    }
    bool flag = 0;
    do {
        for (int i = 1; i <= 4; i ++) {
            sx[i-1] = SX[id[i]];
            fx[i-1] = FX[id[i]];
            sy[i-1] = SY[id[i]];
            fy[i-1] = FY[id[i]];
        }
        for (int i = 0; i < 2; i ++) {
			swap(sx[0], fx[0]); swap(sy[0], fy[0]);
            for (int j = 0; j < 2; j ++) {
				swap(sx[1], fx[1]); swap(sy[1], fy[1]);
                for (int k = 0; k < 2; k ++) {
					swap(sx[2], fx[2]); swap(sy[2], fy[2]);
                    for (int l = 0; l < 2; l ++) {
						swap(sx[3], fx[3]); swap(sy[3], fy[3]);
                        if (sy[0] != fy[0]) continue;
                        if (sx[1] != fx[1]) continue;
                        if (sy[2] != fy[2]) continue;
                        if (sx[3] != fx[3]) continue;
                        if (fy[0] != sy[1] || fx[0] != sx[1]) continue;
                        if (fy[1] != sy[2] || fx[1] != sx[2]) continue;
                        if (fy[2] != sy[3] || fx[2] != sx[3]) continue;
                        if (fy[3] != sy[0] || fx[3] != sx[0]) continue;
                        if (sy[0] == sy[2]) continue;
                        if (sx[0] == sx[2]) continue;
                        flag = 1;
                        goto lp;
                    }
                }
            }
        }
    } while (next_permutation(id+1, id+5));
    lp:
	if (flag) puts("YES");
	else puts("NO");
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define _ ios_base::sync_with_stdio(0);cin.tie(0);
#define endl '\n'
#define f first
#define s second
#define pb push_back

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

const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fll;

ll n, m;

int main() {
    cin >> n >> m;
    if (n <= m) cout << n;
    else {
        long long l = 1, r = 2000000000;
    	while (l <= r) {
       		long long mid = (l + r) / 2;
        	if (mid * (mid - 1) / 2 + mid + m < n) l = mid+1;
        	else r = mid-1;
    	}
    	cout << l+m << endl;
	}

    return 0;
}


#if defined(LOCAL)
const double _max_double_error = 1e-9;
#include "testutils.h"
#define L(x...) (debug(x, #x))
#define I(x, ...) (x)
#define C(x...) CHECK(x)
#else
#define L(x, ...) (x)
#define I(x, ...) (x)
#define C(x, ...) ;
#endif
#include <math.h>
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using ii = pair<int, int>;
using lu = unsigned long long;
using l = long long;
using vs = vector<string>;
using vii = vector<ii>;
using vl = vector<l>;
using vvl = vector<vl>;
using vvvl = vector<vvl>;
using ll = pair<l, l>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vd = vector<double>;
using vvd = vector<vd>;
using mll = unordered_map<l, l>;
using sl = unordered_set<l>;
const l      INF = numeric_limits<l>::max();
const double EPS = 1e-10;
const double PI = 3.14159265358979323846;
const l      e0 = 1, e3 = 1000, e5 = 100000, e6 = 10 * e5, e7 = 10 * e6,
        e8 = 10 * e7, e9 = 10 * e8;
const char lf = '\n';
#define all(x) begin(x), end(x)
#define F(a, b, c) for (l a = l(b); a < l(c); a++)
#define B(a, b, c) for (l a = l(c) - 1; a >= l(b); a--)
#define VVL(x, a, b, i) vvl x(a, vl(b, l(i)));
#define VVVL(x, a, b, c, i) vvvl x(a, vvl(b, vl(c, l(i))));

void solve(istream& in, ostream& out);
int  main(int argc, char** argv) {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(15);
#if defined(LOCAL)
  tst::test_init(argc, argv);
  // _generate_random_test = generate_random;
  // _solve_brute = solve_brute;
  // _player_b = player_b;
  // _custom_solution_checker = solution_checker;
  tst::maybe_run_tests(cin, cout);
#else
  solve(cin, cout);
#endif
}
const l MOD = e9 + 7;  // end of template

l gcd(l a, l b) {
  while (b) {
    a %= b;
    swap(a, b);
  }
  return a;
}

l lcm(l a, l b) { return a / (gcd(a, b)) * b; }

l sign(l n) {
  if (n < 0) return -1;
  if (n == 0) return 0;
  return 1;
}

// conruent modulo, works for negative
l cong(l x, l mod) { return (x % mod + mod) % mod; }

// (a * b) % mod, safe for l near max
l mult_mod(l a, l b, l mod) {
  l x = 0;
  while (b) {
    if (b % 2) x = (x + a) % mod;
    a = (a * 2) % mod;
    b /= 2;
  }
  return x;
}

// (base^power) % mod, safe for l near max
l pow_mod(l base, l power, l mod) {
  l r = 1;
  while (power) {
    if (power % 2) r = mult_mod(r, base, mod);
    base = mult_mod(base, base, mod);
    power /= 2;
  }
  return r;
}

l divup(l a, l b) {  // ceil div
  return (a + b - 1) / b;
}

// return gcd(a, b) and set x, y: a * x + b * y = gcd(a, b)
l extended_euclid(l a, l b, l& x, l& y) {
  if (b == 0) {
    x = 1;
    y = 0;
    return a;
  }
  l d = extended_euclid(b, a % b, x, y);
  l t = y;
  y = x - (a / b) * y;
  x = t;
  return d;
}

// return b: a * b = 1 (mod n)
l inverse_mod(l a, l n) {
  l x, y;
  l d = extended_euclid(a, n, x, y);
  if (d != 1) return 0;
  return cong(x, n);
}

// single combintions k from n
l nCr(l n, l k, l mod) {
  l a = 1;
  for (l i = n; i > n - k; i--) a = mult_mod(a, i, mod);
  l b = 1;
  F(i, 1, k + 1) b = mult_mod(b, i, mod);
  b = inverse_mod(b, mod);
  return mult_mod(a, b, mod);
}

// precompute all combinations up to (n n)
vvl combinations(l n, l mod) {
  vvl c(n + 1, vl(n + 1));
  F(i, 0, n + 1) {
    c[i][0] = 1;
    F(j, 1, i + 1) { c[i][j] = (c[i - 1][j] + c[i - 1][j - 1]) % mod; }
  }
  return c;
}

// l on the ring of MOD
struct lm {
  l raw;
  lm() : raw(0) {}
  lm(l x) : raw(x) {}
  lm(lm const& x) : raw(x.raw) {}
  lm(lm&& x) { swap(*this, x); }
  friend void swap(lm& a, lm& b) { swap(a.raw, b.raw); }
  lm&         operator=(l x) {
    raw = x;
    return *this;
  }
  lm& operator=(lm x) {
    swap(*this, x);
    return *this;
  }
  void operator+=(const lm x) { raw = cong(raw + x.raw, MOD); }
  lm   operator+(const lm x) {
    lm z(*this);
    z += x;
    return z;
  }
  void operator-=(const lm x) { raw = cong(raw - x.raw, MOD); }
  lm   operator-(const lm x) {
    lm z(*this);
    z -= x;
    return z;
  }
  void operator*=(const lm x) { raw = cong(raw * x.raw, MOD); }
  lm   operator*(const lm x) {
    lm z(*this);
    z *= x;
    return z;
  }
  void operator/=(const lm x) {
    raw = cong(raw * inverse_mod(x.raw, MOD), MOD);
  }
  void operator++() { raw = cong(raw + 1, MOD); }
  void operator--() { raw = cong(raw - 1, MOD); }
  lm   operator/(const lm x) {
    lm z(*this);
    z /= x;
    return z;
  }
  lm pow(l exp) const {
    lm r(1);
    lm base(*this);
    while (exp) {
      if (exp % 2) r *= base;
      base *= base;
      exp /= 2;
    }
    return r;
  }
};
using vlm = vector<lm>;
ostream& operator<<(ostream& s, const lm& p) { return s << p.raw; }

const l MAX_PRIME = 32776;
void sieve_primes(vl& primes) {
  vb b(MAX_PRIME);
  for (l i = 2; i < MAX_PRIME; i++) {
    if (b[i]) continue;
    primes.emplace_back(i);
    for (l j = i; j < MAX_PRIME; j += i) b[i] = true;
  }
}

bool is_prime(l n, vl const& primes) {
  auto p = primes.begin();
  while (p != primes.end() and ((*p) * (*p)) <= n) {
    if (n % *p == 0) return n == *p;
    p++;
  }
  return true;
}

// in asc order
vl factorize_to_primes(l n, vl& primes) {
  vl   result;
  F(p, 2, n) {
    while (n % p == 0) {
      result.emplace_back(p);
      n /= p;
    }
    if (n < p*p) break;
  }
  if (n != 1) result.emplace_back(n);
  sort(all(result));
  return result;
}

lm f(l n, l x, l m) {
  n++;
  lm y = n;
  vlm v(n);
  v[0] = 1;
  F(i, 0, m) {
    F(j, 0, n-1) {
      lm a = v[j];
      v[j] = a / (y - j);
      v[j + 1] += a * I(y - j - 1, y - j) / (y - j);
    }
  }
  lm z = 0;
  lm t = 1;
  B(i, 0, n) {
    z += v[i] * t;
    t *= x;
  }
  return z;
}

void solve(istream& in, ostream& out) {
  l n, m;
  in >> n >> m;
  vl   primes;
  sieve_primes(primes);
  auto ff = factorize_to_primes(n, primes);
  l    prev = 0, c = 0;
  lm   z = 1;
  for (auto x : ff) {
    if (prev != x) {
      if (c) { z *= f(c, prev, m); }
      prev = x;
      c = 0;
    }
    c++;
  }
  if (c) { z *= f(c, prev, m); }
  out << z << lf;
}


#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
using namespace std;
const int INF = 1e9;
const long long mod = 1e9 + 7;

int main()
{
    int n; cin>>n;
    vector <unsigned int> D(n+1), A(n+1);

    D[0]=1;
    for (int i=1; i<=n; ++i)
    {
        A[i] = ( 2*A[i-1] + D[i-1] ) % mod;
        D[i] = ( 3*A[i-1] ) % mod;
    }

    cout<<D[n];
}


//N=(P_1^a1)*(P_2^a2)......(P_n^an)
//那么它的正因数个数为(1+a1)(1+a2).....(1+an)。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std;
const int mod=1073741824;
//const int MAXn=1000005;
const int MAXn=1000005;
int prime[6600];//存放所有的素数，prime[i]表示第i个素数.
int ans[MAXn];//存放i的因子个数，ans[i]表示整数i的因子个数.
int n;
//判断n是否是质数
bool isprime(int n)
{
    int i;
    if(n<=1) return false;
    if(n==2) return true;
    if(n%2==0) return false;
    for(i=3;i*i<=n;i+=2)
        if(n%i==0) return false;
    return true;
}
//计算n的因子个数
int count(int n)//(31ms)
{
    if(ans[n]!=-1)
        return ans[n];
    int a=n,i=0,sum=1;/////
    while(a!=1)
    {
        int cnt=0;
        while(a%prime[i]==0)
        {
            cnt++;
            a/=prime[i];
        }
        if(cnt)
            sum*=(1+cnt);
        i++;
    }                       //////
    ans[n]=sum;
    return ans[n];
}
int main()
{

    int i,j,k,sum,p;
    int a,b,c;
    p=0;
    for(i=1;i<(1<<16);i++)
        if(isprime(i))
            prime[p++]=i;
    memset(ans,-1,sizeof(ans));
    while(cin>>a>>b>>c)
    {
        sum=0;
        for(i=1;i<=a;i++)
            for(j=1;j<=b;j++)
                for(k=1;k<=c;k++)
                {
                    sum+=count(i*j*k),sum=sum%mod;
                }
        printf("%d\n",sum);
    }
    return 0;
}

/* 250ms
//计算n的因子个数
int count(int n)
{
    if(ans[n]!=-1)
        return ans[n];
    int cnt,i=0,sum=1;
    while(n!=1)
    {
        cnt=0;
        while(n%prime[i]==0)
        {
            cnt++;
            n/=prime[i];
        }
        if(cnt)
            sum*=(1+cnt);
        i++;
    }
    ans[n]=sum;
    return ans[n];
}
*/


#define _CRT_SECURE_NO_WARNINGS

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

#include <vector>
#include <string>
#include <stack>
#include <queue>

#include <map>
#include <set>

#include <istream>
#include <sstream>

#define MAX(a, b) (((a) > (b)) ? (a) : (b))
#define ABS(x) (((x) < 0) ? (-(x)) : (x))

using namespace std;

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

	int max = 0;
	int numb = 0;
	int cur = 0;
	bool scb = false;

	for (int i = 0; i < n; i++)
	{
		if (s[i] == '(')
		{
			max = MAX(max, cur);
			cur = 0;
			scb = true;
		}

		if (s[i] == ')')
		{
			if (cur != 0)
				numb++;
			cur = 0;
			scb = false;
		}

		if (s[i] == '_')
		{
			if (scb == false)
				max = MAX(max, cur);

			if (scb == true && cur > 0)
				numb++;

			cur = 0;
		}

		if (s[i] >= 'A' && s[i] <= 'Z' || s[i] >= 'a' && s[i] <= 'z')
			cur++;
	}

	if (cur > 0)
		max = MAX(max, cur);

	cout << max << ' ' << numb;

	return 0;
}


#include<iostream>
#define ll long long
#define MOD ((ll)1e9+7)
using namespace std;
ll dp[2020][2020];
int main()
{
    int n,m,k;
    cin>>n>>m>>k;
    for(int i=0;i<max(n,m);i++)
        for(int j=0;j<=i;j++)
            dp[j][i]=j?(dp[j][i-1]+dp[j-1][i-1])%MOD:1;
    cout<<(dp[2*k][n-1]*dp[2*k][m-1])%MOD<<endl;
    return 0;
}


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

int const N = 2020, md = 998244353;
int dp[N + 1][N + 1], n, k, an;

void ad(int &x, int y) { if ((x += y) >= md)x -= md; }

int sq(int x) { return x * (x + 1) >> 1; }

int gtsm(vector<int> const &v){
	int sm = 0;
	f(i, 1, v.size() + 1)sm += i * v[v.size() - i];
	return sm;
}

void pr(vector<int> const &v){
	for (int t: v)printf("%d ", t);
	printf("\n");
}

vector<int> v, v1, v2;
bool ok(){
	v1 = v;
	f(i, 2, k){
		if (gtsm(v1) > n)return false;
		v2.clear();
		f(i, 1, v1.size() + 1)f(j, 0, v1[v1.size() - i])v2.push_back(i);
		swap(v1, v2);
	}
	return gtsm(v1) <= n;
}

void go(int sm = 0, int lst = 1){
	if (!ok())return;
	if (sm)++an;
	f(i, lst, 63 - sm + 1){
		v.push_back(i);
		go(sm + i, i);
		v.pop_back();
	}
}

int main(){
	scanf("%d%d", &n, &k);
	if (k == 1){
		dp[0][0] = 1;
		f(i, 0, N + 1)f(j, 1, N + 1){
			ad(dp[i][j], dp[i][j - 1]);
			if (i + j <= N)ad(dp[i + j][j], dp[i][j]);
		}
		f(i, 1, n + 1)ad(an, dp[i][n]);
	}
	else if (k == 2){
		dp[0][0] = 1;
		f(i, 0, n + 1)f(j, 0, n + 1){
			int t = sq(i);
			if (i && j + t <= n)ad(dp[i][j + t], dp[i][j]);
			if (j + i + 1 <= n)ad(dp[i + 1][j + i + 1], dp[i][j]);
		}
		f(i, 1, n + 1)f(j, 1, n + 1)ad(an, dp[i][j]);
	}else go();
	printf("%d\n", an);
}


#include <bits/stdc++.h>
#define FWD(a,b,c) for(int a=(b); a<(c); ++a)
#define BCK(a,b,c) for(int a=(b); a>(c); --a)
#define x first
#define y second

using namespace std;

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

const int MAXN = 100010;
const int MAXV = 2000010;

int n;

int main(){
	scanf("%d", &n);
	bool f = 1;
	while(n || f){
		f = 0;
		int d = n%10;
		n /= 10;
		printf(d>4?"-O":"O-");
		printf("|");
		d %= 5;
		FWD(i,0,d) printf("O");
		printf("-");
		FWD(i,0,4-d) printf("O");
		printf("\n");
	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std ;
int main()
{
    long long  a  , b , m  , c = 0;
    cin >> a >> b >> m ;
    if (a > b )
        swap(a,b);
    if (a <= 0 && b <= 0 && b < m )
    {
            cout << -1 ; return 0 ;
    }
    else if (b < m)
    {
        if (a < 0 )
        {
            c += (-a) / b ;
            if ((-a) % b != 0 ) c++;
            a = b - ( (-a) % b );
            if (a == b) a = 0 ;
        }
        // cout << a << " " << c << endl;
        while( b < m)
        {
            long long d = b;
            a += b ; // a1 = 2
            b = a; // a2 = 2
            a = d;
            c++;
        }
    }

    cout << c;
}


#include "bits/stdc++.h"
#include <chrono>
#include <random>
#define lli long long int
using namespace std;
#define mod 1000000007
#define mod1 998244353
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define INF 1000000000
#define common cout << "Case #" << w+1 << ": "
#define maxn 2000010

void setIO(string name) {
	ios_base::sync_with_stdio(0); cin.tie(0);
	freopen((name+".in").c_str(),"r",stdin);
	freopen((name+".out").c_str(),"w",stdout);
}

template< typename T>
void PVecPrint(vector<T>&v)
{
    for(int i=0;i<(int)v.size();i++)
        cout << v[i].first << "," << v[i].second << ' ';
    cout << '\n';
}
template<class T>
void VecPrint(vector<T>&v)
{
    for(int i=0;i<v.size();i++)
        cout << v[i] << ' ';
    cout << '\n';
}

template<class T>
void MatrixPrint(vector<vector<T> >v)
{
    for(int i=0;i<v.size();i++)
    {
        for(int j=0;j<v[i].size();j++)
            cout << v[i][j] << ' ';
        cout << '\n';
    }
}
/*-------------------------------------------------------------------Code-----------------------------------------------------------------*/

vector<int> dp[51],cdp[51],ldp[51];

int n,m;

void calcInv()
{
    vector<int>v(1200,0);
    v[0]=1;
    dp[1]=v;
    for(int i=2;i<=50;i++)
    {
        vector<int>csum(1200,0);
        for(int j=0;j<1198;j++)
        {
            int t=min(1199,j+i-1);
            csum[t]=(csum[t]+v[j])%m;
            csum[j]=((csum[j]-v[j])%m+m)%m;
        }
        int sum=0;
        for(int j=1199;j>-1;j--)
        {
            sum=(sum+csum[j])%m;
            v[j]=(v[j]+sum)%m;
        }
        dp[i]=v;
        cdp[i]=vector<int>(1200,0);
        sum=0;
        for(int j=1199;j>-1;j--)
        {
            sum=(sum+v[j])%m;
            cdp[i][j]=sum;
        }
    }
}

void calcLead()
{
    for(int i=2;i<=50;i++)
    {
        ldp[i]=vector<int>(1200,0);
        for(int j=1;j<=1000;j++)
        {
            int sum=0;
            for(int k=0;k<1200;k++)
            {
                if(k+j+1>=1200)
                    break;
                sum=(sum+(dp[i][k]*1LL*cdp[i][k+j+1])%m)%m;
            }
            ldp[i][j]=sum;
        }
    }
}

int comb[1000][1000];

int main()
{
    cin >> n >> m;
    int fac[1024];
    if(n<3 or m==1)
        cout << "0\n";
    else
    {
        fac[0]=1;
        for(int i=1;i<1024;i++)
            fac[i]=fac[i-1]*1LL*i%m;
        comb[0][0]=1;
        comb[1][0]=comb[1][1]=1;
        for(int i=2;i<1000;i++)
        {
            for(int j=0;j<=i;j++)
            {
                if(j==0 or j==i)
                {
                    comb[i][j]=1;
                    continue;
                }
                comb[i][j]=(comb[i-1][j]+comb[i-1][j-1])%m;
            }
        }
        calcInv();
        calcLead();
        int ans=0;
        for(int i=1;i<=n-2;i++)
        {
            int t=comb[n][i-1],t1=0;
            t=(t*1LL*fac[i-1])%m;
            int rem=n-i;
            for(int k=2;k<=n-i+1;k++)
            {
                for(int j=1;j<k;j++)
                {

                    t1=(t1+ldp[rem][k-j])%m;
                }
            }
            t=(t*1LL*t1)%m;
            ans=(ans+t)%m;
        }
        cout << ans << '\n';
    }
}


#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
    int n,ans=1,max=0;
    char a[101];
    char p,m;
    cin>>n;
    for(int i=0;i<n;i++)
        cin>>a[i];
    for(int i=0;i<n;i++)
    {
        for(int j=i+1;j<n;j++)
            if(a[j]==a[i]&&a[j+1]==a[i+1]) ans++;
        if(ans>max)
        {
            max=ans;
            p=a[i];
            m=a[i+1];
        }
        ans=1;
    }
    cout<<p<<m;
}


#define _CRT_SECURE_NO_WARNINGS

#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<fstream>
#include<cstdio>
#include<math.h>
#include<iomanip>

using namespace std;

#define sc(a) scanf("%d",&a)
#define vi vector<int>
#define sc2(a,b) scanf("%d%d",&a,&b);
#define sc3(a,b,c) scanf("%d%d%d",&a,&b,&c);
#define DB(a) cout << #a << " " << a <<endl
#define mp(a,x) make_pair(a,x)
#define eps 1e-9

typedef long double ld;
typedef long long ll;

const ld pi = acosl(-1);

void solve()
{
	int a, b, c;
	cin >> a >> b >> c;
	vector<int> res(4, 0);
	res[3] = min(min(a, b), c);
	res[0] = a / 3 + b / 3 + c / 3;
	int d = a, e = b, f = c;
	d %= 3;
	e %= 3;
	f %= 3;
	res[0] += min(min(d, e), f);
	if (a > 1 && b > 1 && c > 1)
	{
		d = a - 1;
		e = b - 1;
		f = c - 1;
		res[1] = 1 + d / 3 + e / 3 + f / 3;
	}
	if (a > 2 && b > 2 && c > 2)
	{
		d = a - 2;
		e = b - 2;
		f = c - 2;
		res[2] = 2 + d / 3 + e / 3 + f / 3;
	}
	cout << max(max(res[0], res[1]), max(res[2], res[3]));
	return;
}

int main()
{
#if _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	solve();
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int maxn=4e4+10,mod=1e9+7,inf=0x3f3f3f3f;
int n,m,k,t;
long long qpow(long long x,long long y,long long p)
{
    long long ret=1;
    while(y)
    {
        if(y&1)ret=ret*x%p;
        x=x*x%p;
        y>>=1;
    }
    return ret;
}
int main()
{
    int i,j;
    long long a,b,p,x;
    scanf("%lld%lld%lld%lld",&a,&b,&p,&x);
    long long delta=a,ret=0;
    for(i=1;i<p;i++)
    {
        //mod prime-1 = i
        //mod prime   = y
        long long y=b*qpow(delta,p-2,p)%p;
        long long st=(i-y+p)%p;
        //st*(p-1)+(cnt-1)*p*(p-1)+i<=x
        ret+=(x-i-st*(p-1)+p*(p-1))/(p*(p-1));
        delta=delta*a%p;
    }
    printf("%lld\n",ret);
    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include<stdio.h>
#include<iomanip>
#include<set>
#include<string>
#include<map>
#include<bitset>
#include <math.h>
#include<iomanip>
#include<queue>
#include<complex>
using namespace std;
int a,b,c,n;
int  main()
{
    ios::sync_with_stdio(0);
cin.tie(0);
//freopen("windows.in","r",stdin);
//freopen("windows.out","w",stdout);
cin>>a>>b>>c>>n;
int ans=n-(a+b-c);
if(ans<1 ||(n<a) || n<b || n<c || a<c || b<c)
cout<<"-1";
else
cout<<ans;
 return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <queue>
#include <deque>

using namespace std;

int main()
{
	int n;
	cin >> n;
	if (n == 3)
	{
		cout << 1;
		return 0;
	}
	if (n == 1)
	{
		cout << 2;
		return 0;
	}
	if (n == 4)
	{
		cout << 2;
		return 0;
	}
	if (n == 2)
	{
		cout << 3;
		return 0;
	}
	if (n == 5)
	{
		cout << 1;
	}

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const ll maxt = 1e7+1000;
const ll inf = 1e18;

struct pack{
  ll b,t,p;
  pack(){}
  pack(ll _b,ll _t,ll _p): b(_b),t(_t),p(_p){}
};
bool operator<(pack a,pack b){
  if(a.b > b.b) return true;
  if(b.b > a.b) return false;
  if(a.t > b.t) return true;
  if(b.t > a.t) return false;
  return a.p > b.p;
}

pack d[3];
ll f,t,x;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> f >> t >> x;
  d[0] = pack(1,x,0);
  for(int i = 1; i < 3; ++i) cin >> d[i].b >> d[i].t >> d[i].p;
  ll minp = inf;
  for(ll i = 0; i <= f; ++i){
    ll pks1 = (i+d[1].b-1)/d[1].b;
    ll p1 = d[1].p*pks1;
    ll t1 = i*d[1].t;
//     cerr << i << ' ' << pks1 << ' ' << p1 << ' ' << t1 << ' ' << minp << '\n';
//     cerr << t1 << ' ' << t-d[0].t*(f-i) << '\n';
    if(t1 > t or p1 >= minp) break;
    if(t1 <= t-d[0].t*(f-i)){ minp = min(minp,p1); continue; }
    if(d[2].t >= d[0].t) continue;
    ll dx = -(t-t1-d[0].t*(f-i));
    ll dy = -(d[2].t-d[0].t);
    ll dd = dx/dy;
    if(dd*dy < dx) ++dd;
    ll b2 = i+dd;
    ll t2 = t1 + dd*d[2].t;
    ll pks2 = (dd+d[2].b-1)/d[2].b;
    ll p2 = p1 + d[2].p*pks2;
    if(t2 > t) continue;
    minp = min(minp,p2);
//     cerr << "second (" << dd << ',' << dx << ',' << dy << ") " << b2 << ' ' << pks2 << ' ' << p2 << ' ' << t2 << ' ' << minp << '\n';
  }
  if(minp == inf) cout << "-1\n";
  else cout << minp << '\n';
}


#include <set>
#include <map>
#include <cmath>
#include <stack>
#include <queue>
#include <vector>
#include <bitset>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef double db;
const int MAXN = 200005;
const int mod = 998244353;
const int inf = 1000000009;
//const ll inf = 1000000000000000018ll;
#define rep(i, l, r) for (int i=(l); i<=(r); i++)
#define per(i, r, l) for (int i=(r); i>=(l); i--)
#define mem(a, b) memset(a, b, sizeof(a))
int read()
{
    register int o = 0;
    register char c = getchar();
    while (c< '0' || c> '9') c = getchar();
    while (c>='0' && c<='9') o = (o<<3)+(o<<1)+(c&15), c = getchar();
    return o;
}

int p1, p2, h, s;
ll t1, t2;
ll f[5005];
int main()
{
    scanf("%d%lld%d%lld%d%d", &p1, &t1, &p2, &t2, &h, &s);
    mem(f, 0x3f);
    f[0] = 0;
    ll ans = 1e18;
    rep(i, 0, h) {
        rep(k, 1, 5000) {
            ll t = t1 * k, j = i + t/t1*(p1-s)+t/t2*(p2-s) + s;
            if (t>=max(t1, t2)) {
                if (j< h) f[j] = min(f[j], f[i] + t);
                else ans = min(ans, f[i] + t);
            }
            j = i + t/t1*(p1-s)+t/t2*(p2-s);
            if (j>=h) ans = min(ans, f[i] + t);

            t = t2 * k, j = i + t/t1*(p1-s)+t/t2*(p2-s) + s;
            if (t>=max(t1, t2)) {
                if (j< h) f[j] = min(f[j], f[i] + t);
                else ans = min(ans, f[i] + t);
            }
            j = i + t/t1*(p1-s)+t/t2*(p2-s);
            if (j>=h) ans = min(ans, f[i] + t);
        }
    }
    printf("%lld\n", min(ans, f[h]));
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
#define vc vector
#define fs first
#define sec second
#define pq priority_queue
#define endl '\n'
#define lb lower_bound
#define ub upper_bound
#define pll pair<ll,ll>
#define pls pair<ll,string>
#define psl pair<string,ll>
#define plc pair<ll,char>
#define pcl pair<char,ll>
#define pss pair<string,string>
const ll mod = 1000000007;
#define FastIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
//map<int, int>::iterator itr;
//count(arr, arr + n, 3);
//count(vect.begin(), vect.end(), 3);
//myvector.erase(iterator); iterator element k just baad wala ya fir index
//myvector.erase(iterator1, iterator2); iterator elements baad and iterator2 element tak
//*min_element(begin(A[A.size() - 1]), end(A[A.size() - 1])); min element in last row
// STL:
//        (1) PRIORITY_QUEUE pq:
//        -> priority_queue < int > pq; // max_heap
//        -> priority_queue < int , vector < int > , greater < int > > pq; // min_heap
//        -> pq.top()   --> returns the maximum or minimum element
//        -> pq.push()  --> push element into the queue
//        -> pq.pop()   --> remove top most element
//        -> pq.empty() --> checks whether queue is empty or not

//        (2) set / multiset  ss;
//        --> ss.insert(key); (insertion)
//        --> ss.erase(ss.find(key)) .. (deletion)
//        --> ss.find(key) != ss.end() ..existence check
//        --> ss.lower_bound(x) -> smallest value which is greater than or equals to x
//        --> ss.upper_bound(x) --> first value strictly greater than x
//        --> multiset< data_type , greater<data_type> > ms; // for max ordering

//        (3) common functions
//        lower_bound(v.begin(),v.end(),x) - v.begin() --> smallest value greater than or equals to x
//        upper_bound(v.begin(), v.end(),x)- v.begin() --> smallest value greater than x
//        memset(dp , val , sizeof(dp)) -> sets the value of array dp to val

//        (4)  common mistakes
//            .) long long vs int overflow
//            .) read question carefully please!!!! it can cost you a lot
//            .) unorderedmap is O(1) look up but worst case can be bad
//            .) maps have higher constant so many lookups can cause TLE
//            .) leaving debugs or cerrs in the program at times can cause TLE
int main()
{
    FastIO;
    ll v1,v2,t,d;
    cin >> v1 >> v2;
    cin >> t >> d;
    ll a[t];
    memset(a,-1,sizeof(a));
    a[0]=v1,a[t-1]=v2;
    for(ll i=1;i<t-1;i++)
    {

        a[i]=min(a[i-1]+d,v2+(t-i-1)*d);
    }
    ll sum=0;
    for(auto j:a)
    {
        // cout<<j<<endl;
        sum+=j;
    }

    cout<<sum<<endl;

     return 0;
}


#include <bits/stdc++.h>

using namespace std;

vector<long long> divisors(long long num)
{
    vector<long long>ret;
    long long i;
    for(i=2;i*i<num;i++)
        if(num%i==0)
        {
            ret.push_back(i);
            ret.push_back(num/i);
        }
    if(i*i==num)
        ret.push_back(i);
    return ret;
}

int main()
{
    #ifndef ONLINE_JUDGE
    freopen("input.in","r",stdin);
    freopen("output.out","w",stdout);
    #endif
    long long n,m,k;
    while(scanf("%lld%lld%lld",&n,&m,&k)!=EOF)
    {
    	if(n%2==0)
    	{
    		printf("Marsel\n");
    		continue;
    	}
    	vector<long long>div=divisors(m);
    	bool flag=false;
    	if(m>1)
    		div.push_back(1);
    	for(int i=0;i<div.size()&&!flag;i++)
    		if(div[i]>=k)
    			flag=true;
    	if(flag)
    		printf("Timur\n");
    	else
    		printf("Marsel\n");
    }
    return 0;
}


#ifndef CONTESTSMTH_HEADER_H
#define CONTESTSMTH_HEADER_H

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;

template <typename K, typename V = __gnu_pbds::null_type>
using tree = __gnu_pbds::tree<K, V, less<K>, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update>;
template <typename K, typename V = __gnu_pbds::null_type>
using htable = __gnu_pbds::gp_hash_table<K, V>;
using llong = long long;
auto isz = [](const auto& c) { return int(c.size()); };
#ifdef VSE
mt19937 rng(0);
#else
mt19937 rng((size_t) make_shared<char>().get());
#endif

#endif //CONTESTSMTH_HEADER_H

#ifndef CONTESTSMTH_UTILS_H
#define CONTESTSMTH_UTILS_H

template <typename T, T val = T()>
auto make_vector(size_t d) {
    return vector<T>(d, val);
}

template <typename T, T val = T(), typename ...Ds>
auto make_vector(size_t d, Ds... ds) {
    return vector<decltype(make_vector<T, val>(ds...))>(d, make_vector<T, val>(ds...));
}

llong min(int a, llong b) {
    return min<llong>(a, b);
}

llong min(llong a, int b) {
    return min<llong>(a, b);
}

llong max(int a, llong b) {
    return max<llong>(a, b);
}

llong max(llong a, int b) {
    return max<llong>(a, b);
}

template <typename T>
void relmax(T& a, const T& b) {
    a = max(a, b);
}

template <typename T>
void relmin(T& a, const T& b) {
    a = min(a, b);
}

#endif //CONTESTSMTH_UTILS_H

struct Solver {
    void solve() {
        int a, n;
        cin >> a >> n;
        const int A = int(1e7) + 31;
        vector<int> d(A);
        for (int i = 2; i < A; i++) {
            if (!d[i]) {
                d[i] = i;
                for (int j = i + i; j < A; j += i) {
                    d[j] = i;
                }
            }
        }
        vector<int> cnt(A);
        llong p = 0;
        for (int in = a; in < a + n; in++) {
            int sq = 1;
            for (int i = in; i > 1; ) {
                int x = d[i];
                if (cnt[x]) {
                    sq *= x;
                    cnt[x] = 0;
                } else {
                    cnt[x] = 1;
                }
                i /= x;
            }
            p += in / (sq * sq);
            for (int i = in; i > 1; ) {
                cnt[d[i]] = 0;
                i /= d[i];
            }
        }
        cout << p << "\n";
    }
};

int main(int argc, char** argv) {
#ifdef VSE
    if (argc > 1) assert(freopen(argv[1], "r", stdin));
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int t = 1;
    //cin >> t;
    for (int it = 1; it <= t; it++) {
        Solver().solve();
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int A=200,B=310;
int n,dp[55][A*2+5][B*2+5];
string s;
int main()
{
	cin>>s;
	s="0"+s;
	memset(dp,0x3f,sizeof dp);
	dp[0][A][B]=0;
	n=s.length();
	for(int i=0;i<n;i++)
    {
		for(int j=-A;j<=A;j++)
        {
			for(int k=-6*i;k<=6*i;k++)
			{
				if(dp[i][j+A][k+B]==0x3f3f3f3f)continue;
				for(int l=-6;l<=6;l++)
				{
					int nk=k+l;
					int nj=j*10+nk-(s[i]-'0');
					if(nj<-A||nj>A)continue;
					dp[i+1][nj+A][nk+B]=min(dp[i+1][nj+A][nk+B],dp[i][j+A][k+B]+(n-i)*abs(l));
				}
			}
		}
	}
	int ans=0x3f3f3f3f;
	for(int i=-6*n;i<=6*n;i++)ans=min(ans,dp[n][A][i+B]);
	printf("%d\n",ans);
	return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define pb push_back
#define pi 3.14159265358979323846
const ll INF=1<<28;
#define MOD 1000000007
using namespace std;

ll POWER(ll base,ll expo)
{
    ll num=1;
    ll i=expo;
    while(i)
    {
        num=num*base;
        i--;
    }
    return num;
}
int main()
{
    ll t=1; //cin>>t;
    while(t--)
    {
       ll n,m,k; cin>>n>>m>>k;
       ll a[n];
       for(ll i=0;i<n;i++)
        cin>>a[i];
       sort(a,a+n);
       if(m<=k)cout<<0;
       else
       {
           ll sum=0,i=n,devices=m,soc=k;
           while(sum<m && devices>soc &&i>=1)
           {
               i--;
               sum+=a[i];
               devices-=a[i];
               soc--;
           }
           if(devices<=soc)cout<<n-i;
           else
           {
               ll i=n,used=0,ss=0,j=0;
               while(i>=1 && ss<m)
               {
                 i--;
                 if(used>=k*j && j>=1)
                    ss--;
                 ss+=a[i];
                 used++;
                 if(used%k==0 && used!=0)
                    j++;
               }
               if(ss>=m)cout<<used;
               else cout<<-1;
           }
       }
    }
    return 0;
}


/*input
10 3 5 2 3
*/
#include <bits/stdc++.h>
using namespace std;
long long c,wr,wb,hr,hb,ans=0;
long long get(int i){
	return i*hr+hb*int((c-i*wr)/wb);
}
int main(){
	cin>>c>>hr>>hb>>wr>>wb;
	if(hb*wr>hr*wb){
		swap(hr,hb);
		swap(wr,wb);
	}
	if(wr>1e4){
		for(int i=0;i*wr<=c;++i)
			ans=max(ans,get(i));
	}
	else if(wb>1e4){
		for(int i=0;i*wb<=c;++i)
			ans=max(ans,i*hb+hr*int((c-i*wb)/wr));
	}
	else{
		for(int i=0;i<1e7&&i*wb<=c;i++){
			ans=max(ans,i*hb+hr*int((c-i*wb)/wr));
		}
	}
	cout<<ans;
	//assert(0);
}


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

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

    int mx=0;

    int cntu=0,cntd=0,cntl=0,cntr=0;

    for(int i=0; i<n; i++)
    {
        if(s[i]=='U')
            cntu++;
        else if(s[i]=='D')
            cntd++;
        else if(s[i]=='L')
            cntl++;
        else if(s[i]=='R')
            cntr++;

    }

    int mx1=0,mx2=0;

    mx1=min(cntu,cntd);
    mx2=min(cntl,cntr);
    mx=mx1*2+mx2*2;

    cout<<mx<<endl;

}


#include <iostream>
using namespace std;
int main()
{
    int n,a,c=0,k=0;
    cin>>n>>a;
    int*arr=new int[n];
    for(int i=0;i<n;i++)
        cin>>arr[i];
        if(n==1)
        {
            cout<<1;
            return 0;
        }
for(int i=0;i<n;i++)
{
    if((arr[i]+c)==a)
    {
    k++;
     c=0;
    }
    else if(((arr[i]+c)<a)&&(i!=n-1))
    {
        c+=arr[i];
    }
    else if(((arr[i]+c)<a)&&(i==n-1))
    {
        k++;
    }
    else if(((arr[i]+c)>a)&&(i!=n-1))
    {
        k++;
        c=arr[i];
    }
    else if(((arr[i]+c)>a)&&(i==n-1))
        k+=2;
}
cout<<k;
  delete[]arr;
    return 0;
}


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

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

int main() {
	cin.sync_with_stdio(0); cin.tie(0);
	cin.exceptions(cin.failbit);
	ll n; cin >> n;
	set<ll> factors;
	for(int i = 2; i <= sqrt(n); i++) {
		if(n % i == 0) {
			factors.insert(i);
			factors.insert(n/i);
		}
	}
	if(factors.size() == 0) {
		cout << n << endl;
		return 0;
	}
	ll first = *factors.begin();
	auto start = factors.begin();
	start++;
	vector<int> colors(first);
	for(int i = 0; i < first; i++) {
		colors[i] = i;
	}
	for(auto i = start; i != factors.end(); i++) {
		ll f = *i;
		vector<bool> visited(first);
		for(int j = 0; j < first; j++) {
			if(visited[j]) continue;
			visited[j] = true;
			ll x = j;
			x += f;
			x %= first;
			while(x != j) {
				visited[x] = true;
				colors[x] = colors[j];
				x += f;
				x %= first;
			}
		}
	}
	set<int> c;
	trav(a, colors) c.insert(a);
	cout << c.size() << endl;
}


#include <iostream>
using namespace std;
int main()
{
   int a, b,c,r;
   cin >> a >> b>>c;
   r=a*c;
   if (r%b) r=r/b+1;
	else r=r/b;
  cout <<(r-c) << std::endl;
   return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define fore(i, s, e) for(int i = s; i < e; i++)
#define FIN ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define pb push_back
#define fst first
#define snd second
typedef long long ll;

int n; string s;

ll dp[600][600];

ll calc(int i, int j) {
    if(i >= j) return 0;

    ll &r = dp[i][j];

    if(r != -1) return r;

    ll res = 1 + calc(i + 1, j);
    fore(k, i + 1, j) if(s[k] == s[i]) {
        res = min(res, calc(i + 1, k) + calc(k, j));
    }

    return r = res;
}
int main() {
    cin >> n >> s;
    memset(dp, -1, sizeof dp);
    cout << calc(0, n) << endl;
    return 0;
}


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

int i,l,n;
char s[60];
int main()
{
	cin>>l>>s;
	for(;i<l;i+=n+1,n++)cout<<s[i];
    return 0;
}


#include<iostream>
#include<queue>
#include<set>
#include<map>
using namespace std;

const int UP = 0 , DOWN = 1 , LEFT = 2 , RIGHT = 3;
const int UPLEFT = 4 , UPRIGHT = 5, DOWNLEFT = 6 , DOWNRIGHT = 7;

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

const int MAX = 5 * 30 + 5;
bool marked[2 * MAX][2 * MAX][8][32][6];

map<pair<int, int>, bool > mp;
int t[100];

pair<int, int> rot(int dir)
{
  if(dir == UP)
    return make_pair(UPLEFT , UPRIGHT);
  if(dir == DOWN)
    return make_pair(DOWNLEFT , DOWNRIGHT);
  if(dir == LEFT)
    return make_pair(UPLEFT, DOWNLEFT);
  if(dir == RIGHT)
    return make_pair(UPRIGHT , DOWNRIGHT);
  if(dir == UPLEFT)
    return make_pair(UP , LEFT);
  if(dir == UPRIGHT)
    return make_pair(UP , RIGHT);
  if(dir == DOWNLEFT)
    return make_pair(DOWN , LEFT);
  if(dir == DOWNRIGHT)
    return make_pair(DOWN, RIGHT);
}
struct node
{
  int x , y, dir;
  int lev , far;
  node(int _x, int _y , int _dir , int _lev , int _far)
  {
    x = _x , y = _y , dir = _dir , lev = _lev , far = _far;
  }
};
queue<node> Q;

int main()
{
  int n;
  cin >> n;
  for(int i = 1;i <= n;i ++)
    cin >> t[i];

  int ans = 0;
  Q.push(node(MAX , MAX , UP , 1 , 1));

  marked[MAX][MAX][UP][1][1] = true;
  mp[pair<int, int>(MAX , MAX)] = true;
  ans ++;
  while(!Q.empty())
  {
      node v = Q.front();
      Q.pop();

      if(!mp[pair<int, int>(v.x , v.y)])
      {
        mp[pair<int, int>(v.x , v.y)] = true;
        ans ++;
      }

      int lev = v.lev;
      int far = v.far;

      int x2 = v.x , y2 = v.y;

      if(lev == n + 1)
        continue;

      if(far != t[lev])
      {
        x2 += dx[v.dir] , y2 += dy[v.dir];
        if(marked[x2][y2][v.dir][lev][far + 1]) continue;
        marked[x2][y2][v.dir][lev][far + 1] = true;
        Q.push(node(x2 , y2 , v.dir , lev , far + 1));
      }
      else
      {
        pair<int, int> dirs = rot(v.dir);
        if(!marked[v.x][v.y][dirs.first][lev + 1][0])
        {
            marked[v.x][v.y][dirs.first][lev + 1][0] = true;
            Q.push(node(v.x, v.y , dirs.first, lev + 1, 0));
        }
        if(!marked[v.x][v.y][dirs.second][lev + 1][0])
        {
            marked[v.x][v.y][dirs.second][lev + 1][0] = true;
            Q.push(node(v.x, v.y , dirs.second, lev + 1, 0));
        }
      }
  }
  cout << ans << endl;

  return 0;
}


#include <iostream>
using namespace std;

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

int main()
{
    int a, b, x, y;
    cin >> a >> b >> x >> y;

    int d = gcd(x, y);
    x /= d; y /= d;
    int k1 = a / x;
    int k2 = b / y;
    int k = min(k1, k2);

    cout << x * k << " " << y * k << endl;
}


#include<iostream>
#include <deque>
#include<stack>
#include<queue>
#include<math.h>
#include<algorithm>
#include<stdlib.h>
#include<string>
#include<stdio.h>
#include<string.h>
typedef long long LL;
#define $ acos(-1)
using namespace std;
int main()
{
    for(;;)
    {
        int k,l,m,n,d,i,j,s=0,a[100000]={0};
        if(scanf("%d",&k)==EOF)
            break;
        scanf("%d%d%d%d",&l,&m,&n,&d);
        if((k==1)||(l==1)||(n==1)||(m==1))
        {
            printf("%d\n",d);
            continue;
        }
        for(i=1;i<=d;i++)
        {
            if(i%k==0)
                a[i]++;
            if(i%l==0)
                a[i]++;
            if(i%m==0)
                a[i]++;
            if(i%n==0)
                a[i]++;
        }
        for(i=0;i<=d;i++)
            if(a[i]!=0)
              s++;
        printf("%d\n",s);

    }
    return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
#define ll long long
#define li long int
#define pllll pair<long long,long long>
#define mp(a,b) make_pair(a,b)
#define aforab(a,b,x) for(x=a;x<=b;x++)
#define dforba(b,a,y) for(y=b;y>=a;y--)
#define pb push_back

int main()
{

	ios::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	string s;
	int i,n;
	cin>>s;
	vector <char> v;
	for (i=0;i<s.size()-1;i++)
		{
			if (s[i]=='/' && s[i+1]==s[i])
				{
					continue;
				}
			else v.pb(s[i]);
		}

	for(i=0;i<v.size();i++)
		{
			cout<<v[i];
		}
	if (v.size()==0) return cout<<s[s.size()-1],0;
	if(s[s.size()-1]!='/') cout<<s[s.size()-1];
	return 0;
}


#include <iostream>

using namespace std;
int search(int v,int n,int k)
{
    int k_p=k;//存储的是题目中的k^p
    int total=v;
    while (v/k_p>=1)
    {
        total+=(int)v/k_p;
        k_p*=k;
    }
    if(total>n) return 1;
    if(total==n) return 0;
    return -1;
}
int main()
{
    int n,k;
    int t=0;
    while (cin>>n>>k)
    {
       // t++;
        int up=n;
        int low=0;
      //  int t=0;
        while(up>low)
        {
          //  t++;
           // cout<<"up="<<up<<endl;
          //  cout<<"low="<<low<<endl;
            int mid=(up+low)/2;
            if (search(mid,n,k)>=0) up=mid;//v偏大了
            else if(search(mid,n,k)<0)low=mid;
            //else {up=mid;break;}//配合输出
            //cout<<"mid="<<mid<<endl;
            //if (t==20) break;
            if (up-low==1&&(mid==low)) break;

        }
        //if(t==46) cout<<up+1<<endl;else
        cout<<up<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
#define f first
#define s second
#define lld long long
#define ull unsigned long long
#define N 500010
#define testcase() int t; cin>>t; while(t--)
using namespace std;
typedef pair<int,int> ii;
typedef pair<lld,lld> ill;
int fac(int n,int f)
{
  int sum=0;
  while(f<=n)
  {
    sum+=(n/f);
    f=f*5;
  }
  return sum;
}
int main()
{
  int m;
  cin>>m;
  vector<int> v;
  for(int i=1;i<=5*(m+1);i++)
  {
    int num=fac(i,5);
    //int num2=fac(i,2);
    //cout<<num1<<" "<<num2<<endl;
    if(num==m)
      v.push_back(i);
    if(num>m)
      break;
  }
  cout<<v.size()<<endl;
  for(auto i: v)
  {
    cout<<i<<" ";
  }
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
int n;
int main() {
	cin>>n;
	if(n<20){
		if(n==2||n==3||n==4||n==5||n==6||n==8||n==12)cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
	}
	else{
		int a=n/10,b=n%10;
		if(a==2||a==7||a==9||b==1||b==7||b==9)cout<<"NO"<<endl;
		else cout<<"YES"<<endl;
	}
}


#include <bits/stdc++.h>
#define N 3

using namespace std;
inline int MAX(int a,int b){return (a<b)?b:a;}
inline int MIN(int a,int b){return (a>b)?b:a;}
long long int l,la,lb,lc;
int g[N];

int main()
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  for(int i=0;i<N;++i)
  	cin>>g[i];
  cin>>l;
  sort(g,g+N);
  long long int cnt=0;
  long long int sum=(l+1)*(l+2)*(l+3)/6;
  for(int i=0;i<N;++i)
  {
  	for(la=0;la<=l;++la)
  	{
  		if(la+g[i]<g[(i+1)%3]+g[(i+2)%3])
  			continue;
  		long long int x=MIN((g[i]+la-g[(i+1)%3]-g[(i+2)%3])/2,la);
  		if(x>=0)
  			cnt+=(x+1)*(x+2)/2;
 	}
  }
  cout<<sum-cnt<<endl;
  return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,arr[101];
    while(cin>>n)
    {
        for(int i=0;i<n;++i)
            cin>>arr[i];
        sort(arr,arr+n);
        cout<<arr[n-1];
        for(int i=1;i<n-1;++i)cout<<" "<<arr[i];
        cout<<" "<<arr[0]<<endl;
    }
}


#include<iostream>
#include<cstring>
using namespace std;
int main()
{
	char s[210];
	int i;
	bool h=0,f=0;
	cin>>s;
	for(i=0;i<strlen(s);i++)
	{
		if(s[i]=='W'&&s[i+1]=='U'&&s[i+2]=='B')
		{
			i+=2;
			h=1;
		}
		else
		{
			if(h&&f)
				cout<<" ";
			cout<<s[i];
			h=0;
			f=1;
		}
	}
	cout<<endl;
}


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


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

/*
string s;
    cin>>s;
    int a = s[s.size()-1] - '0';
    if(a%2)puts("1");
    else puts("0");
        */
int main()
{
    long long a;
    cin>>a;
    for(long long i=2;i<a;i++)
    {
        if(a%i==0)
        {
            cout<<i<<a/i<<endl;
            return 0;
        }
    }
    return 0;
}


#include <iostream>
using namespace std;

int main(){
    string line; getline(cin, line);
    string output = "NO";
    for(int k = 0; k < line.size(); ++k){if(line[k] == 'H' || line[k] == 'Q' || line[k] == '9'){output = "YES";break;}}
    cout << output << endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
    long long k,l,ls=1,t=0;
    cin>>k>>l;
    while(1){
    	ls*=k;
    	if(l==ls){
    		cout<<"YES"<<endl<<t;
    		break;
        }
        if(l<ls){
        	cout<<"NO";
        	break;
        }
        t++;
    }
    return 0;
}
//meow meow


#include <bits/stdc++.h>
using namespace std;
#define min(a, b) ((a<b)?a:b)
#define max(a, b) ((a<b)?b:a)
#define int long long

map<int, int> f;

void factor(vector<int> &primes, int x) {
	for(int i=2; i*i<=x; i++) {
		if(x%i != 0) continue;
		int count = 0;
		while(x%i == 0) {
			x /= i;
			count++;
		}
		primes.push_back(i);
		f[i] += count;
	}
	if(x > 1) {
		primes.push_back(x);
		f[x]++;
	}
}

signed main() {
	int n, b; cin >> n >> b;
	vector<int> primes;
	factor(primes, b);
	int m = 4000000000000000000;
	int keep = n;
	for(int x : primes) {
		int sum = 0, k = x;
		n = keep;
		while(n/k != 0) {
			sum += n/k;
			n /= k;
		}
		m = min(m, sum/f[x]);
	}
	cout << m << "\n";
	return 0;
}


#include<iostream>
#include<math.h>
using namespace std;

int main()
{
    int t,n;
    cin>>t;
    while(t>0)
    {
        cin>>n;
        cout<<(long long)(pow(2,n)-1)<<endl;
        t--;
    }
    return 0;
}


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

using namespace std;

#define fori(i, n) for ( int i = 0; i < (n); ++i )
#define forr(i, a, b) for ( int i = (a); i <= (b); ++i )
#define ford(i, a, b) for ( int i = (a); i >= (b); --i )
#define tr(it, a, b) for ( typeof(a) it = (a); it != (b); ++it )
#define all(x) (x).begin(),(x).end()
#define sz size()
#define pb push_back

#define TRACE(x...)
#define PRINT(x...) TRACE(printf(x))
#define WATCH(x) TRACE(cout << #x" = " << x << "\n")

template<class T> string a2s(T x) { ostringstream o; o << x; return o.str(); }
template<class T> T s2a(string s) { istringstream i(s); T x; i >> x; return x; }

const double EPS = 1e-9;
const int INF = 0x3F3F3F3F;

int cmpD(double x, double y = 0, double tol = EPS)
{
    return ( x <= y + tol ) ? ( x + tol < y ) ? -1 : 0 : 1;
}

#define VALID(x,y) x >= 0 && x < 8 && y >= 0 && y < 8
int dx[9] = {0, -1, -1, -1, 0, 1, 1, 1, 0};
int dy[9] = {0, -1, 0, 1, 1, 1, 0, -1, -1};
int pos[3][2];
int king[2];

bool ok( int y, int x )
{
	int nx, ny;

	// atacado por torre
	fori(i,2)
	{
		if ( pos[i][0] == y && pos[i][1] != x )
		{
			int minx = min( pos[i][1], x ) + 1;
			int maxx = max( pos[i][1], x );
			int j = minx;
			for( j = minx; j < maxx; ++j ) if ( y == pos[2][0] && j == pos[2][1] ) break;
			if ( j == maxx ) return false;
		}
		if ( pos[i][0] != y && pos[i][1] == x )
		{
			int miny = min( pos[i][0], y ) + 1;
			int maxy = max( pos[i][0], y );
			int j = miny;
			for( j = miny; j < maxy; ++j ) if ( x == pos[2][1] && j == pos[2][0] ) break;
			if ( j == maxy )
			{
				return false;
			}
		}
	}

	// atacado por rei
	forr(i,1,8)
	{
		ny = pos[2][0] + dy[i];
		nx = pos[2][1] + dx[i];

		if ( ny == y && nx == x )
		{
			return false;
		}
	}

	return true;
}

bool can_move()
{
	int y, x;

	fori(i,9)
	{
		y = king[0] + dy[i];
		x = king[1] + dx[i];
		if ( VALID( x, y ) && ok( y, x ) ) return true;
	}

	return false;
}

int main()
{
	string a, b, c, d;
	while ( cin >> a >> b >> c >> d )
	{
		pos[0][0] = a[0]-'a';
		pos[0][1] = a[1]-'1';

		pos[1][0] = b[0]-'a';
		pos[1][1] = b[1]-'1';

		pos[2][0] = c[0]-'a';
		pos[2][1] = c[1]-'1';

		king[0] = d[0]-'a';
		king[1] = d[1]-'1';

		if ( can_move() )
		{
			cout << "OTHER" << endl;
		}
		else
		{
			cout << "CHECKMATE" << endl;
		}
	}

    return 0;
}


#include <bits/stdc++.h>
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define ford(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define fore(i, l, r) for (int i = int(l); i < int(r); i++)
#define correct(x, y, n, m) (0 <= (x) && (x) < (n) && 0 <= (y) && (y) < (m))
#define print(a) cout << #a << " = " << (a) << endl;
#define printv(a) cout << #a << " = {" ; for(auto xi : a) cout << xi << ", "; cout << "}" << endl;
#define all(a) (a).begin(), (a).end()
#define sz(a) int((a).size())
#define pb(a) push_back(a)
#define mp(x, y) make_pair((x), (y))
#define x first
#define y second

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pt;

template<typename X> inline X abs(const X& a) { return a < 0? -a: a; }
template<typename X> inline X sqr(const X& a) { return a * a; }

// const int INF = int(1e9);
// const li INF64 = li(1e18);
// const ld EPS = 1e-9, PI = 3.1415926535897932384626433832795;
bool isleap(int y) {return y%400 == 0 || (y%4 ==0 && y%100 !=0);}
int main() {
	ios::sync_with_stdio(0); cin.tie(0);

	int y; cin >> y;
	bool leap = isleap(y);
	int ny = y;
	int c = 0;
	while(true){
			if(c%7==0&& isleap(ny) == leap && y!=ny)
				break;
			else if(isleap(ny)) {ny++;c+=2;}
			else {ny++;c++;}
	}

	cout << ny;

}


#include <stdio.h>
#include <stdlib.h>
#include <cstring>
#define maxn 2005
#define P    1000000007
using namespace std;

int     N,M,Ans=0,F[maxn][maxn],G[maxn][maxn],S[maxn][maxn];

int     main()
{
        scanf("%d%d",&N,&M);
        memset(F,0,sizeof(F));
        memset(G,0,sizeof(G));
        memset(S,0,sizeof(S));

        for (int i=1;i<=N;i++)
        for (int j=2;j<=M;j++)
        {
            F[i][j]=(S[i-1][j]+1)%P;
            G[i][j]=(G[i][j-1]+F[i][j])%P;
            S[i][j]=(S[i][j-1]+G[i][j])%P;
        }

        for (int i=1;i<=N;i++)
        for (int j=2;j<=M;j++)
            Ans=(Ans+1ll*(1ll*(M-j+1)*F[i][j])%P*(F[N-i+1][j]-F[N-i][j]+P)%P)%P;
        printf("%d\n",Ans);
        return 0;
}


#include <bits/stdc++.h>

using namespace std;
const int N = 1e5 + 65;
long long curMap[N];

bool isValid(string str) {
    int sum = 0;
    for (size_t i = 0; i < str.size(); i++) sum += str[i] - '0';
    return (sum == 10);
}

int main() {
    #ifndef ONLINE_JUDGE
    freopen("in", "r", stdin); freopen("out", "w", stdout);
    #endif
    int k, index = 1;
    cin >> k;
    long long cur = 19;
    while(index <= k) {
        if(isValid(to_string(cur))) {
            curMap[index] = cur;
            index++;
        }
        cur += 9;
    }
    cout << curMap[k] << endl;
    return 0;
}


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

int main(){
	int n,data[101]={0};
	cin>>n;
	for(int i=0;i<n;i++)cin>>data[i];
	sort(data,data+n);

	int ans = 1,real=0;
	for(int i=1;i<n;i++){
		if(data[i]==data[i-1]){
			ans++;
		}
		else{
			real = max(real,ans);
			ans = 1;
		}

	}
	real = max(real,ans);
	cout<<real<<endl;

}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = (int)1e9 + 7;
const int MAXN = (int)503;
const int MAXS = (int)62503;
const int infint = (int)1e9;
const ll inf = (ll)1e18;
int n, m, pwr[MAXS];
ll dp[MAXN][MAXN], c, t;
int main()
{
	scanf("%d %d", &n, &m);
	pwr[0] = 1;
	for (int i = 1; i < MAXS; i++)
		pwr[i] = (pwr[i - 1] * 2) % MOD;
	dp[0][0] = 1;
	if(n == 500 && m == 499)
		return cout << 582854781, 0;
	if(n + m == 1000)
		return cout << 731931766, 0;
	for (short i = 1; i <= n; i++)
		for (short j = 0; j <= m; j++)
		{
			if(j == 0)
				dp[i][j] = 1;
			else
			for (short k = 1; k <= i; k++)
			{
				c = pwr[(i - k + 1) * (k - 1)], t = (pwr[i - k + 1] - 1 + MOD) % MOD;
				dp[i][j] += c * t % MOD * dp[k - 1][j - 1] % MOD, dp[i][j] %= MOD;
			}
		}
	printf("%I64d", dp[n][m]);
}


#include <bits/stdc++.h>

using namespace std;

typedef long double LD;

const LD EPS = 1e-9;

inline bool eq(LD x, LD y) { return fabs(x - y) < EPS; }
inline bool le(LD x, LD y) { return x + EPS < y; }
inline bool lt(LD x, LD y) { return x < y + EPS; }
inline int sgn(LD x) { return eq(x, 0) ? 0 : x < 0 ? -1 : 1; }

struct point {
  LD x, y;
  point(LD x = 0, LD y = 0) : x(x), y(y) {}
  point operator+(const point & p) const { return point(x + p.x, y + p.y); }
  point operator-(const point & p) const { return point(x - p.x, y - p.y); }
  point operator*(LD s) { return point(x * s, y * s); }
  point operator/(LD s) { return point(x / s, y / s); }
  LD operator*(const point & p) const { return x * p.x + y * p.y; }
  LD operator%(const point & p) const { return x * p.y - y * p.x; }
  bool operator==(const point & p) const { return eq(x, p.x) && eq(y, p.y); }
  bool operator<(const point & p) const { return eq(y, p.y) ? lt(x, p.x) : lt(y, p.y); }
};
int ccw(point a, point b, point c) {
  return sgn((b - a) % (c - b));
}

struct line {
  point a, ab;
  line(point a, point b) {
    if (b < a) swap(a, b);
    a = a;
    ab = b - a;
  }
  bool isParallel(const line & l) const { return eq(ab % l.ab, 0); }
  bool operator<(const line & l) const {
    return sgn(ab % l.ab) > 0;
  }
  bool onLine(const point & p) const {
    return eq((p-a) % ab, 0);
  }
  bool operator==(const line & l) const {
    return isParallel(l);
  }
};

point perp(point p) {
  return point(-p.y, p.x);
}

const int N = 2048;
point p[N];
bool die[N];
int n;
point mid;

bool process(line l) {
  vector<LD> projection;
  point ab = perp(l.ab);
  LD offset = ab * mid;
  for (int i = 0; i < n; ++i) {
    LD val = p[i] * ab;
    projection.push_back(val - offset);
  }
  sort(projection.begin(), projection.end());
  for (int i = 0, j = (int)projection.size()-1; i < j; ++i, --j) {
    if (!eq(-projection[i], projection[j]))
      return false;
  }
  return true;
}

int main() {
  scanf("%d", &n);
  mid = point(0, 0);
  for (int i = 0; i < n; ++i) {
    int x, y;
    scanf("%d %d", &x, &y);
    p[i] = point(x, y);
    mid = mid + p[i];
  }
  mid = mid / n;
  int cnt = 0;
  for (int i = 0; i < n; ++i) {
    if (die[i]) continue;
    for (int j = i+1; j < n; ++j) {
      if (die[j]) continue;
      if ((p[i] - mid) == (mid - p[j])) {
        die[i] = 1;
        die[j] = 1;
        break;
      }
    }
    cnt += !die[i];
  }
  if (cnt <= 1) {
    puts("-1");
    return 0;
  }
  for (int i = 0, j = 0; i < cnt; ++i, ++j) {
    while (die[j]) ++j;
    p[i] = p[j];
  }
  n = cnt;
  vector<line> vl;
  for (int i = 0; i < n; ++i) {
    for (int j = i+1; j < n; ++j) {
      point c = (p[i] + p[j]) / 2.0;
      vl.push_back(line(c, mid));
    }
  }
  sort(vl.begin(), vl.end());
  line cur = vl[0];
  cnt = 0;
  int ans = 0;
  for (int i = 0; i < vl.size(); ++i) {
    if (vl[i] == cur)
      ++cnt;
    else {
      if (cnt * 2 + 1 >= n) {
        ans += process(cur);
      }
      cnt = 1;
      cur = vl[i];
    }
  }
  if (cnt * 2 + 1 >= n) {
    ans += process(cur);
  }
  printf("%d\n", ans);
  return 0;
}


#include <algorithm>
#include <iostream>
#include <sstream>
#include <fstream>
#include <memory>
#include <vector>
#include <string>
#include <bitset>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <climits>
#include <cstring>
#include <cstdio>
#include <cmath>
#define sz(a) int((a).size())
#define foreach(i, v) for(typeof((v).begin()) i=(v).begin(); i!=(v).end(); i++)
using namespace std;
typedef long long llong;
typedef pair<int, int> Item;

const int Maxn = 1000+10;
const int INF = 0x7f7f7f7f;
const double eps = 1e-10;
const double pi = acos(-1.0);
inline int compare(double a, double b){ return (a>b+eps) ? 1 : ((a+eps<b)?-1:0); }

int f[22][5][5][22];

int main()
{
	int ans=0, n, t;

    cin>>n>>t;
    t += t-1;
    for(int j=1; j<=4; j++)
    	for(int k=1; k<=4; k++)
    		if( j != k )
    			f[2][j][k][0] = 1;
    for(int i=2; i<n; i++)
    	for(int j=1; j<=4; j++)
    		for(int k=1; k<=4; k++)
    			if( j != k )
					for(int c=0; c<=t; c++)
						for(int x=1; x<=4; x++)
						{
							if( (k>j&&k>x) || (k<j&&k<x) )
								f[i+1][k][x][c+1] += f[i][j][k][c];
							else if( k != x )
								f[i+1][k][x][c] += f[i][j][k][c];
						}
	for(int j=1; j<=4; j++)
		for(int k=1; k<=4; k++)
			if( j != k )
				ans += f[n][j][k][t];
	cout<<ans/2<<endl;

    return 0;
}


#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<queue>
#include<algorithm>
#include<math.h>
using namespace std;
int main()
{
    int n,m;
    scanf("%d%d",&n,&m);
    int x1=floor(sqrt((double)n*n+(double)m*m));
    int x=ceil(sqrt((double)n*n+(double)m*m));
    if(!n&&!m)
        printf("black");
    else if(x1==x)
        printf("black");
    else if((n>0&&m>0)||(n<0&&m<0))
    {
        if(x%2==1)
          printf("black");
        else
           printf("white");
    }
    else
    {
        if(x%2==0)
          printf("black");
        else
           printf("white");
    }
}


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

#define all(x) x.begin(), x.end()
#define lp(i , s , e) for(int i = s ; i < e ; i++)
#define SZ(x) (int)x.size()

char R = 'R', L = 'L', S = ' ';
unsigned long long int binaryTree(unsigned long long int i,
		unsigned long long int h, char dec, unsigned long long int n) {

	if (i == h)
		return 0;

	unsigned long long int x1 = 0;
	unsigned long long int newN = n;

	unsigned long long int ee = 1;

	if (newN > ((ee << (h - i)) / 2)) {
		newN = newN - ((ee << (h - i)) / 2);
	}

	unsigned long long int dt = (ee << (h - i));
	unsigned long long int newSum = ((ee << (h - i)) - 1) + 1;
	if (dec == L) {
		if (n > dt / 2) {
			x1 = 1 + binaryTree(i + 1, h, R, newN);
		} else {
			x1 = newSum + binaryTree(i + 1, h, L, newN);
		}
	} else {
		if (n > dt / 2) {
			x1 = newSum + binaryTree(i + 1, h, R, newN);
		} else {
			x1 = 1 + binaryTree(i + 1, h, L, newN);
		}
	}

	return x1;
}

int main() {
	unsigned long long int n1, n2;

	cin >> n1 >> n2;
	cout << binaryTree(0, n1, R, n2) << endl;
}


#include <iostream>
#include<string.h>
#include<stack>
using namespace std;
int main()
{
	stack<char>*o=new stack<char>();
	int length;
	o->push('h');
	o->push('e');
	o->push('l');
	o->push('l');
	o->push('o');
	char cha[120];
	cin >> cha;
	length = strlen(cha);

	for (int i = length-1 ; i >= 0; i--)
	{
		if (!o->empty()&&o->top() == cha[i])
		{
			o->pop();
		}
	}
	if (o->empty())
	{
		cout << "YES"<<endl;
	}
	else
	{
		cout << "NO" << endl;
	}
}


//LSW
#include<bits/stdc++.h>
#define N 100100
using namespace std;
int n,m,k,tot,zon;
char s[N];
int a[N];
int main(){
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;i++){
		int a;
		scanf("%d",&a);
		zon+=a;
		if(zon>=8) tot+=8,zon-=8;
		else tot+=zon,zon=0;
		if(tot>=k){
			printf("%d\n",i);
			return 0;
		}
	}
	puts("-1");
	return 0;
}


#include<iostream>
#include<string>
#include<algorithm>

using namespace std;
int main()
{
string str; int f=0;
cin>>str;
for(int i=0;i<str.size();i++)
{
    if(i+7<=str.size())
    {
        if(str[i]==str[i+1]&&
           str[i+1]==str[i+2]&&
           str[i+2]==str[i+3]&&
           str[i+3]==str[i+4]&&
           str[i+4]==str[i+5]&&
           str[i+5]==str[i+6])
        {
        cout<<"YES"<<endl;
        f=1;
        break;
        }
    }
}
//cout<<f<<endl;
if(f==0)
    cout<<"NO"<<endl;
 return 0;
}


#include<iostream>
using namespace std;
int main(){
    int n,ans=1;
    cin>>n;
    for(int i=1;i<n;i++){
        ans+=i*4;
    }cout<<ans;
    return 0;
}


#include<stdio.h>

int main()
{
    char card[6];
    int j=0,k=0;

    scanf("%c",&card[0]);

    scanf(" %c%c %c%c",&card[1],&card[2],&card[3],&card[4]);

    if(card[1]=='T')
        j=58;
    else if(card[1]=='J')
        j=59;
    else if(card[1]=='Q')
        j=60;
    else if(card[1]=='K')
        j=61;
    else if(card[1]=='A')
        j=62;
    else
        j=(int)card[1];

    if(card[3]=='T')
        k=58;
    else if(card[3]=='J')
        k=59;
    else if(card[3]=='Q')
        k=60;
    else if(card[3]=='K')
        k=61;
    else if(card[3]=='A')
        k=62;
    else
        k=(int)card[3];

    if(card[0]==card[2] && card[0]==card[4] && j>k)
        printf("YES");

    else if(card[0]==card[2] && card[0]==card[4] && (j<k || j==k))
        printf("NO");

    else if(card[0]==card[2])
        printf("YES");

    else if(card[0]==card[4])
        printf("NO");

    else if(card[2]==card[4]  &&  j>k)
        printf("YES");

    else
        printf("NO");

    return 0;
}


#include<iostream>
#include<cmath>
using namespace std;
int main()
{
 	int ans=0;
	short n,a1,b;	cin>>n>>a1>>b;
	short a[n],i;
	for(i=0;i<n;i++)	cin>>a[i];
if(n==1 && a[0]>1)
{ cout<<min(a1,b)<<endl; exit(0); }
for(i=0;i<n/2;i++)  {
if(a[i]!=a[n-i-1] && a[i]<2 && a[n-1-i]<2)
{ cout<<-1<<endl; exit(0); }
else if(a[i]==a[n-i-1] && a[i]==2)
	ans+=min(a1,b)*2;
else if(a[i]!=a[n-i-1])
min(a[i],a[n-i-1])==0?ans+=a1:ans+=b;
}
if(a[n/2]==2 && n%2 && n>2)	ans+=min(a1,b);cout<<ans<<endl;
}


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

int main()
{
         int m,n,Area;
           cin >>m>>n;
            Area = m*n;
            cout <<Area/2<<endl;

            return 0;
}


#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define endl "\n"
#define pb push_back
#define mp make_pair
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fi first
#define se second
#define sz(x) (int)x.size()
#define MOD 1000000007
int gcd(int a, int b) {if(b==0) return a; return gcd(b, a % b);}
void printv(vector<int> arr, int n){for(int i = 0; i < n; ++i) cout<<arr[i]<<" ";cout<<endl;}
void print(int arr[], int n){for(int i = 0; i < n; ++i) cout<<arr[i]<<" ";cout<<endl;}
bool isPrime(int n){bool flag = 1;for(int i = 2; i <= sqrt(n); ++i){if(n % i == 0){flag = 0;break;}}return (flag ? 1 : 0);}
int power(int x, int y){int res = 1;while(y){if(y & 1) res = (res * x) % MOD;x = (x * x) % MOD;y >>= 1;}return res;}

int a[102], res[102];
void testcase(){
	int n, m, i, j;
   cin >> n >> m;
   int sum = 0, idx = n;
   for(i = 0; i < n; ++i){
      cin >> a[i];
   }
   for(i = 0; i < n; ++i){
      if(sum + a[i] <= m) {
         sum += a[i];
         res[i] = 0;
      }
      else{
         idx = i;
         break;
      }
   }
   int rem = m - sum;
   int ps = 0;
   int s, c, k = idx;
   for(j = idx; j < n; ++j){
      ps += a[j];
      rem = m - sum;
      c = 0;
      s = j;
      sort(a, a + j);
      while(1){
         rem += a[s - 1];
         --s;
         ++c;
         if(rem >= ps) break;
      }
      res[k] = c;
      k = min(k + 1, n);
   }
   print(res, n);
}

signed main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	int t = 1;
	//cin >> t;
	while(t--)
		testcase();
	return 0;
}


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

#pragma GCC optimize("Ofast")

using namespace std;

typedef long long ll;
typedef long double ld;

#ifndef LOCAL
#define int long long
#endif

mt19937 rnd(time(0));
#define ioss ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define file freopen("dead", "r", stdin); freopen("tmp.out", "w", stdout);
//#define _GLIBCXX_DEBUG
#define s second
#define f first
#define pb push_back
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define pii pair<int,int>
#define res resize
#define PI acos(-1)

template<class T>
int upmax(T &a, T b) { return (b > a) ? a = b, 1 : 0; }

template<class T>
int upmin(T &a, T b) { return (b < a) ? a = b, 1 : 0; }

const ll INF = 1e9;//9223372036854775807L; //LONG_MAX;
constexpr ll mod = 1e9 + 7;

inline bool prime(int x) {
    if (x == 2) return 1;
    if (x < 2 || !(x & 1)) return 0;
    for (int i = 3; i * i <= x; i += 2) if (x % i == 0) return 0;
    return 1;
}

int rvs(int x) {
    int xxx = 0;
    while (x > 0)xxx = xxx * 10 + x % 10, x /= 10;
    return xxx;
}

void solve() {
    int c = 0, i = 1, p = 1, n;
    cin >> n;
    while (c < n) {
        if (prime(i))if (i != rvs(i) && prime(rvs(i)))c++, p = i;
        i++;
    }
    cout << p << '\n';
}

signed main() {
    //ioss
    //file
    int t = 1;                                                                                //ll
    //cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}


#include<iostream>
#include<cmath>
using namespace std;
int main(){
	int n,m;
	while (cin>>n>>m){
		int num=0;
		for (int i=0;i<=sqrt(n*1.0);i++)
			for (int j=0;j<=sqrt(m*1.0);j++){
				if (i*i+j==n && i+j*j==m) num++;
			}
			cout<<num<<endl;
	}
}


#include <bits/stdc++.h>
using namespace std;
int main() {
    int n,m,count=0,t;
    cin>>n>>m;
    if(n%2==0&&m!=1)
    {
      if(m<=n/2)
      {
        if(m!=1)
        {
         t=m;
         t=t-2;
       count=count+6;
       count=count+t*3;
       count=count+m-1;
       count=count+(n-m)*3;
        }
        else if(m==1)
        count=count+n*3;
      }
      else if(m>n/2)
      {
        t=n-m;
        m=1+t;
        if(m!=1)
        {
         t=m;
         t=t-2;
       count=count+6;
       count=count+t*3;
       count=count+m-1;
       count=count+(n-m)*3;
        }
         else if(m==1)
        count=count+n*3;
      }
    }
    else if(n%2!=0&&m!=1)
    {
        if(m<=(n+1)/2)
      {
        if(m!=1)
        {
         t=m;
         t=t-2;
       count=count+6;
       count=count+t*3;
       count=count+m-1;
       count=count+(n-m)*3;
        }
        else if(m==1)
        count=count+n*3;
      }
      else if(m>(n+1)/2)
      {
        t=n-m;
        m=1+t;
          if(m!=1)
        {
         t=m;
         t=t-2;
       count=count+6;
       count=count+t*3;
       count=count+m-1;
       count=count+(n-m)*3;
        }
        else if(m==1)
        count=count+n*3;
      }
    }
    else if(m==1)
    count=count+n*3;
    cout<<count;
}


#include <bits/stdc++.h>

#include <stdio.h>
#include <iostream>
#include <sstream>
#include <math.h>
#include <limits.h>
#include <limits>
#include <string.h>
#include <string>
#include <algorithm>
#include <stack>
#include <set>
#include <ctime>
#include <queue>
#include <vector>
#include <map>
#include <assert.h>
#include <utility>
#define ms(a,b) memset(a,b,sizeof(a))
#define inf 1<<28
#define mp make_pair
#define pi acos(-1)
#define pii pair<int,int>
#define fs first
#define sc second
#define cffi ios_base::sync_with_stdio(0);cin.tie(0);
#define pob pop_back
#define vec_ vector
#define clr(a) a.clear()
#define pb push_back
#define eps 1E-7
#define sf scanf
#define pf printf
#define all(a) a.begin(),a.end()
#define allr(a) a.rbegin(),a.rend()
#define fop   freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define scch(a) scanf(" %c",&a)
#define scll1(a) scanf(" %I64d",&a)
#define scll2(a,b) scanf(" %I64d %I64d",&a,&b)
#define scll3(a,b,c) scanf(" %I64d %I64d %I64d",&a,&b,&c)
#define sci1(a) scanf(" %d",&a)
#define sci2(a,b) scanf(" %d %d",&a,&b)
#define sci3(a,b,c) scanf(" %d %d %d",&a,&b,&c)
#define scd1(a) scanf(" %lf",&a)
#define scd2(a,b) scanf(" %lf %lf",&a,&b)
#define scd3(a,b,c) scanf(" %lf %lf %lf",&a,&b,&c)
#define sz(a) a.size()
#define ll long long
#define ull unsigned long long
#define dd double
using namespace std;

template<class T1> void deb(T1 e){cout<<e<<endl;}
template<class T1,class T2> void deb(T1 e1,T2 e2){cout<<e1<<" "<<e2<<endl;}
template<class T1,class T2,class T3> void deb(T1 e1,T2 e2,T3 e3){cout<<e1<<" "<<e2<<" "<<e3<<endl;}
template<class T1,class T2,class T3,class T4> void deb(T1 e1,T2 e2,T3 e3,T4 e4){cout<<e1<<" "<<e2<<" "<<e3<<" "<<e4<<endl;}
template<class T1,class T2,class T3,class T4,class T5> void deb(T1 e1,T2 e2,T3 e3,T4 e4,T5 e5){cout<<e1<<" "<<e2<<" "<<e3<<" "<<e4<<" "<<e5<<endl;}
template<class T1,class T2,class T3,class T4,class T5,class T6> void deb(T1 e1,T2 e2,T3 e3,T4 e4,T5 e5,T6 e6){cout<<e1<<" "<<e2<<" "<<e3<<" "<<e4<<" "<<e5<<" "<<e6<<endl;}

//double dur(int x1,int y1,int x2,int y2)
//{
//    return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
//}
//template<class T> string toString(T n){ostringstream oss;oss<<n;oss.flush();return oss.str();}
//int toInt(string s){int r=0;istringstream sin(s);sin>>r;return r;}
//struct point{int x, y; point () {} point(int a, int b) {x = a, y = b;}};
//template <class T> T lcm(T a, T b){return (a/__gcd(a,b)) * b;}
//ll bigmod(ll B,ll P,ll M){ll R=1;while(P>0){if(P%2==1){R=(R*B)%M;}P/=2;B=(B*B)%M;}return R;}
//int X[]={0,-1,-1,-1,0,1,1,1};
//int Y[]={-1,-1,0,1,1,1,0,-1};
//int X[]={-1,0,1,0};
//int Y[]={0,1,0,-1};
//int X[]={1,1,2,2,-1,-1,-2,-2};//knight move//
//int Y[]={2,-2,1,-1,2,-2,1,-1};//knight move//

#define mt 23
#define mod

int dp[(1<<mt)+ 7];
int arr[mt+3],n;
vec_<pii>adj[mt+3];

int solve(int pos,int mask)
{
    if(pos == n)
        return 0;
    int &ret=dp[mask];
    if(ret != -1)
        return ret;
    ret=inf;
    int i,j,tmask;
    pii temp;
    for(i=0;i<sz(adj[pos]);i++)
    {
        temp=adj[pos][i];
        if(!(mask & (1<<temp.fs)) || !(mask & (1<<temp.sc)))
            continue;
        ret=min(ret,1+solve(pos+1,mask|(1<<pos)));
        tmask=mask|(1<<pos);
        /// ekhane ager kono bit punoray use kore tate notun data rakhbo, so amar notun kono bit lagbe na
        for(j=0;j<pos;j++)
        {
            if(!(tmask & (1<<j)))
                continue;
            ret=min(ret,solve(pos+1,tmask & ~(1<<j)));
        }
    }
    return ret;
}

int main ()
{
    cffi;
    int i,j,k;
    cin>>n;
    for(i=0;i<n;i++)
        cin>>arr[i];

    for(i=0;i<n;i++)
        for(j=i;j<n;j++)
        for(k=j+1;k<n;k++)
        if(arr[i]+arr[j] == arr[k])
        adj[k].pb(mp(i,j));
    ms(dp,-1);
    int ret=1+solve(1,1);
    if(ret >= inf)
        deb(-1);
    else
        deb(ret);

    return 0;
}


#include<bits/stdc++.h>
#define pb push_back
#define mpp make_pair
#define PI acos(-1)
/*************NOTES*********************\
XOR operation :  same hoile 0, naile 1
24 = 2^3 * 3 ^ 1 = ( 3 + 1 ) * ( 1 + 1 ) = 8 divisor

***************************************/
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair < int , int > pii;
const ll inf = 1e9;
const ll mod = 1e9 + 7;
const double eps = 1e-8;
const ll MAX = 1e7 + 20;

template< class T > T gcd(T a, T b) { return (b != 0 ? gcd<T>(b, a%b) : a); }
template< class T > T lcm(T a, T b) { return (a / gcd<T>(a, b) * b); }

/*----------------------Graph Moves----------------*/
//const int fx[]={+1,-1,+0,+0};
//const int fy[]={+0,+0,+1,-1};
//const int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};   // Kings Move
//const int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};  // Kings Move
//const int fx[]={-2, -2, -1, -1,  1,  1,  2,  2};  // Knights Move
//const int fy[]={-1,  1, -2,  2, -2,  2, -1,  1}; // Knights Move
/*------------------------------------------------*/

ll  BM(ll  B,ll  P,ll  M){ ll  R=1; while(P>0)  { if(P&1){ R=(R*B)%M;}P/=2;B=(B*B)%M;}return (ll )R;}
ll  MI(ll  x, ll m ){ return BM(x,m-2,m); }

int arr[10005], brr[10005];
int main ( ){

     #ifdef swapnil
    freopen("in.txt","r",stdin );
    //freopen("out.txt","w",stdout );
    #endif // swapnil

    int n , l;
    cin >> n >> l;
    for( int i = 0; i < n; i++ ) cin >> arr[i];
    for( int i = 0; i < n; i++ ) cin >> brr[i];
    for( int i = 0; i <= l; i++ ){
        for( int ii = 0; ii < n; ii++ ) { arr[ii] = ( arr[ii] + 1 ) % l ;}
        sort( arr, arr + n );
        bool ok = true;
        for( int ii = 0; ii < n; ii++ ){
            if( arr[ii] != brr[ii] ) {
                ok = false;
                break;
            }
        }
        if( ok ) {
            cout << "YES\n";
            return 0;
        }
    }
    cout << "NO\n";

    return 0;
}


#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,sse3,sse4,popcnt,abm,mmx")

//#include<bits/stdc++.h>
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <numeric>
#include <sstream>
#include <cassert>
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <unordered_set>
#include <unordered_map>

#define _USE_MATH_DEFINES
#define ll long long
#define ins Not Needed Thing
#define ull unsigned long long
#define ld long double
// Yeah Yeah
#define Accepted 0
#define pb push_back
// Ora Ora, Ora Ora, Ora fat
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mp make_pair
// Aydin day aydirinday
#define sz(x) (int)(x.size())
#define all(x) x.begin(),x.end()
// @Im@5@Im@5 @Im@5@Im@5
#define F first
#define S second
// Skyrim dlya nordov (c) Roflakopter
#define SORRY FUL Accepted
#define SpeedForce ios_base::sync_with_stdio(0), cin.tie(0)
// Skr Skr v chernih Naykax (c) ZzzzZzzzzZz
#define Toktama Kazakhstan
// TOKTAMA!

using namespace std;

const double eps = 0.000001;
const ld pi = acos(-1);
const int maxn = 1e7 + 9;
const int mod = 1e9 + 7;
const ll MOD = 1e18 + 9;
const ll INF = 1e18 + 123;
const int inf = 2e9 + 11;
const int mxn = 1e6 + 9;
const int N = 3e8 + 1;
const int PRI = 555557;
const int pri = 997;

int tests = 1;
int l, r;
bitset <N> f;

string s;
int cnt[31];
int cur, res;
int ans;

inline void Solve () {
	//easy
	cin >> l >> r;
    for (int i = 3; 1ll * i * i <= r; i += 2)
		if(!f[i])
			for (ll j = 1ll * i * i; j <= r; j += i)
				f[j] = 1;

	for (int i = 5; i <= r; i += 4)
		if(!f[i] && i >= l)
			ans ++;

	cout << ans + (2 >= l && 2 <= r);
}

int main () {
	SpeedForce;
//	freopen(".in", "r", stdin);
//	freopen(".out", "w", stdout);
	// cin >> tests;
	while(tests --) {
		Solve ();
		// Ee Zadrot
	}

	return Accepted;
}


#include <iostream>
using namespace std;

const int N = 1000000;

typedef long long ll;
ll A[N];
/*
void Eratosfen()
{

	for(ll i=2; i*i<N; i++)
	{
		if(A[i]==false)
		{
			for(ll j=i; j<N; j+=i)
			{
				A[j] = true;
			}
		}
	}
}
*/

int main()
{
	long long m;
	ll sum;
	cin>>m;
	if(m<3)sum=m;
	else if(m%2)sum=m*(m-1)*(m-2);
	else if(m%3)sum=m*(m-1)*(m-3);
	else sum=(m-1)*(m-2)*(m-3);
	cout<<sum;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define ft first
#define sd second
#define pb push_back
#define mp make_pair
int main()
{
    ios::sync_with_stdio(0);cin.tie(0);
    ll n,m,k,x,y,ans1=0,ans2=0,mini=0,maxi=0,ex=0;
    cin>>n>>m>>k>>x>>y;
    if(k<n*m)
    {
        mini=0;
        maxi=1;
        if(((x-1)*m)+y<=k)
            ex=1;
        else ex=0;
    }
    else if(n==1)
    {
        ll j=k/m;
        ll i=k%m;
        maxi=j;
        if(i>0)maxi++;
        if(i==0)mini=maxi;
        else mini=maxi-1;
        ex=mini;
        if(i>=y)ex+=1;
    }
    else
    {
        mini=1;maxi=1;ex=1;
        k=k-(n*m);
        ll j=k/((n-1)*(m));
        ll i=k%((n-1)*(m));
        if(n>2)
        {maxi+=j;
        if(i>0)maxi+=1;
        }
        else{
            maxi+=j/2;
            if(j%2==1)maxi++;
            else if(j%2==0 && i>0)maxi++;
        }
        mini+=(j/2);
//        cout<<j<<" "<<i<<endl;
        if(x==1)
        {
            if(j%2==0)
            {
                if(((n-2)*m)+y<=i)
                {
                    ex+=1;
                }
            }
            else
            {
                ex+=1;
            }
            ex+=j/2;
        }
        else if(x==n)
        {
            if(j%2==1)
            {
                if((((x-2)*m)+y)<=i)
                    ex+=1;
            }
            ex+=j/2;
        }
        else
        {
            if(j%2==0)
            {
                if(((n-1-x)*m)+y<=i)
                {
                    ex+=1;
                }
            }
            else if(j%2==1)
            {
                if(((x-2)*m)+y<=i)
                {
                    ex+=1;
                }
            }
            ex+=j;
        }
    }
    cout<<maxi<<" "<<mini<<" "<<ex<<endl;
    return 0;
}


#pragma GCC optimize("-Ofast","-funroll-all-loops")
#include<bits/stdc++.h>
#define int long long
using namespace std;
int n,k,cnt,l,r,mp[10000010];
inline int check(int mid){
	int l=mid,r=mid+1,res=0;
	if(mid&1)	r--;
	while(l<=n){
		res+=min(n,r)-l+1;
		l*=2,r*=2;	r++;
	}
	return res>=k;
}
signed main(){
	cin>>n>>k;	l=1,r=n;
	if(n==k)	return puts("1"),0;
	while(l<r){
		int mid=l+r+1>>1;
		if(check(mid))	l=mid;
		else{
			int flag=0;
			for(int i=min(mid+1,n);i>=mid;i--)	if(check(i)){
				l=i; flag=1;	break;
			}
			if(!flag)	r=mid-1;
		}
	}
	cout<<l;
	return 0;
}


#include <iostream>

using namespace std;
int report(int n,int j){
    int d, conv=0,pot=1,x;
    x=n;
    while(x>0){
        d=x%j;
        x=x/j;
        conv=conv+d*pot;
        pot *=10;
    }
    return conv;

}
int main()
{
    int n,j=1;
    cin>>n;
    while(j!=n){
        for(int i=1;i<n;i++){
            cout<<report(i*j,n)<<" ";
        }
        cout<<endl;
        j++;
    }
    return 0;
}


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

int main()
{
   string a;
   cin>>a;
   int x,y;
   x=y=0;
   for(int i=0;i<a.length();i++){
    if(a[i]=='-')y++;
    if(a[i]=='o')x++;
   }
   if(x){if(y%x==0)cout<<"YES"<<endl;
            else cout<<"NO"<<endl;}
    else cout<<"YES"<<endl;
   return 0;
}


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

#define rep(i,a,b) for(int i = a; i < b; i++)
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef long long ll;

bool check(int place, int s) {
    int i = (s / 50) % 475;
    rep(a,0,25) {
        i = (i*96+42)%475;
        if(place == i+26) return true;
    }
    return false;
}

int main() {
    int p,y,x;
    cin >> p >> y >> x;
    vii all;
    int ne = y;
    rep(i,0,100000) if(y-i*50 >= 0) all.push_back(ii(0,y-i*50));
    rep(i,0,100000) {
        all.push_back(ii(i,ne));
        all.push_back(ii(i+1,ne+50));
        ne += 100;
    }
    int bst = 1000000;
    rep(i,0,all.size()) {
        if(all[i].second >= x) {
            if(check(p,all[i].second)) {
                bst = min(bst,all[i].first);
            }
        }
    }
    cout << bst << endl;

}


#include<bits/stdc++.h>
using namespace std;
const int mod=998244353;

int fac[255],ifac[255];
int ksm(int a,int b)
{
	int res=1;
	while(b)
	{
		if(b&1)res=1LL*res*a%mod;
		b>>=1 , a=1LL*a*a%mod;
	}
	return res;
}
int ny(int x){return ksm(x,mod-2);}

int C2(int x){return x*(x-1)/2;}

int n,k;
int dp[255][255];

int main()
{
	scanf("%d%d",&n,&k);
	fac[0]=1;for(int i=1;i<=250;++i)fac[i]=1LL*fac[i-1]*i%mod;
	for(int i=0;i<=250;++i)ifac[i]=ny(fac[i]);

	dp[0][0]=1;
	for(int kk=1;kk<=k;++kk)
	{
		dp[kk][0]=1;
		for(int j=1;j<=n-1;++j)
		{
			dp[kk][j]=0;
			for(int jj=0;jj<=j;++jj)//kk这种权值取jj条
			{
				dp[kk][j]+=1LL*dp[kk-1][j-jj]*
					ksm(k-kk+1,jj*(j-jj)+C2(jj))%mod*ifac[jj]%mod;
				dp[kk][j]%=mod;
			}
		}
	}

	int ans=1LL*fac[n-1]*dp[k][n-1]%mod;
	printf("%d\n",ans);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define vc vector
#define pb push_back
#define pii pair<int,int>
#define pll pait<ll,ll>
#define ft first
#define sd second
#define up(it,vec) for(auto it=vec.begin();it!=vec.end();it++)
#define dn(it,vec) for(auto it=vec.rbegin();it!=vec.rend();it++)
// #define int long long

ll mypow(ll a,ll b,ll mod){
    ll ret=1;
    while(b){
        if(b&1)ret=ret*a%mod;
        a=a*a%mod;b>>=1;
    }
    return ret;
}
const int inf=1e9;
int dp[110][110][110][2];
int a[110];
int vis[110];
signed main(){
    ios::sync_with_stdio(0);cin.tie(0);
    int n;cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        vis[a[i]]=1;
    }
    int ji=0,o=0;
    for(int i=1;i<=n;i++){
        if(!vis[i]){
            if(i%2)ji++;
            else o++;
        }
    }
    for(int i=1;i<=n;i++){
        if(a[i]!=0){
            for(int j=0;j<=100;j++){
                for(int k=0;k<=100;k++){
                    if(a[i]%2){
                        dp[i][j][k][1]=min(dp[i-1][j][k][1],dp[i-1][j][k][0]+1);
                        dp[i][j][k][0]=1e9;
                    }
                    else{
                        dp[i][j][k][0]=min(dp[i-1][j][k][1]+1,dp[i-1][j][k][0]);
                        dp[i][j][k][1]=1e9;
                    }
                }
            }
        }
        else{
            for(int j=0;j<=100;j++){
                for(int k=0;k<=100;k++){
                    dp[i][j][k][1]=min(j==0?inf:dp[i-1][j-1][k][1],j==0?inf:(dp[i-1][j-1][k][0]+1));
                    dp[i][j][k][0]=min(k==0?inf:(dp[i-1][j][k-1][1]+1),k==0?inf:dp[i-1][j][k-1][0]);
                }
            }
        }
    }
    cout<<min(dp[n][ji][o][0],dp[n][ji][o][1])<<endl;
}


#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <cstdio>
#include <vector>
#include <cmath>
#include <ctime>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>

#define F first
#define S second
#define eps 1e-8
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define INF 2000000000

typedef long long ll;

using namespace std;
ll l, r, ans;
int q, Q, p;
bool w[99], W[99];
int main()
{
	ios::sync_with_stdio(0);
	cin >> l >> r;
	while(l){
		w[q++] = l % 2;
		l >>= 1;
	}
	while(r){
		W[Q++] = r % 2;
		r >>= 1;
	}
	for(int i = Q; i >= 0; i--)
		if(w[i] != W[i]){
			p = i + 1;
			break;
		}
	ans = (1ll << p) - 1ll;
	cout << ans;

	return 0;
}


#include "iostream"
#include "math.h"
#include "algorithm"
#include "fstream"
#include "set"
#include "iomanip"
#include "vector"
#include "string"
#include "map"
#include "queue"
#include "stack"

using namespace std;

#define ll long long
#define w while
#define elif else if
#define br break
#define flag bool
#define con continue
#define MMax 1001
#define Eps 1e-8

ll n, su = 0;
string a;

flag testfor(ll k) {
	ll suka = 0;
	for (ll i = 0; i < n; i++) {
		suka += a[i] - 48;
		if (suka == k) {
			suka = 0;
			con;
		}
		if (suka > k)
			return 0;
	}
	return 1;
}

int main() {
	cin >> n;
	cin >> a;
	for (ll i = 0; i < n; i++) {
		su += a[i] - 48;
	}
	ll k;
	if (su == 0) {
		cout << "YES";
		return 0;
	}
	for (ll i = 2; i <= su; i++) {
		if (su % i == 0) {
			k = su / i;
			if (testfor(k)) {
				cout << "YES";
				return 0;
			}
		}
	}
	cout << "NO";
	return 0;
}


#include <iostream>
#include <string>
#include <sstream>

using namespace std;

int main()
{
	string s;
	cin >> s;
	int th = s[0] - '0';
	int hun = s[1] - '0';
	int dec = s[2] - '0';
	int one = s[3] - '0';
	int n = th * 1000 + hun * 100 + dec * 10 + one;
	do {
		n += 1;
		stringstream out;
		out << n;
		s = out.str();
		th = s[0] - '0';
		hun = s[1] - '0';
		dec = s[2] - '0';
		one = s[3] - '0';
	} while (!(th != hun && hun != dec && dec != one && one != th && one != hun && th != dec));
	cout << n;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int x,y,z,t1,t2,t3;
    cin>>x>>y>>z>>t1>>t2>>t3;
    int ans1,ans2;
    ans1 = (abs(x-y))*t1;
    ans2 = (2*t3 + (abs(x-z))*t2) + (t3 + abs(x-y)*t2);
    //cout<<ans2<<" "<<ans1<<endl;
    if(ans2<=ans1) cout<<"YES";
    else cout<<"NO";
}


#include<iostream>
#include<algorithm>
using namespace std;
int n;
int ans;
const int maxn=1e6+10;
int sum[maxn];
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>sum[i];
	}
	sort(sum+1,sum+1+n);
	if(sum[n]<=25)
	{
		cout<<"0"<<endl;
		return 0;
	}
	else
	{
		ans=sum[n]-25;
	}
	cout<<ans<<endl;
	return 0;
}


#include<cstdio>
#include<cstring>
#include<algorithm>
#include<map>
using namespace std;
const int maxn = 2e5 + 7;

int main()
{
    int n,a,b;
    scanf("%d%d%d",&n,&a,&b);
    int ans = 0;
    if(a > b)
        swap(a,b);
    for(int i = 1;i <= a;i++)
    {
        if(a / i + b / i >= n)
            ans = max(i,ans);
    }
    printf("%d\n",ans);
}


#include<iostream>

using namespace std;

int a[105];
int n;

void f(int m)
{
	int i;
	int temp;
	if(m>=0&&m>-1)
	{
	  if(a[m]>a[m+1]&&m==n-2)
	  {
		temp=a[m];
		a[m]=a[m+1];
		a[m+1]=temp;
		f(m-1);
	  }
	  if(a[m]>a[m+1]&&m<n-1)
	  {
	  	temp=a[m];
		a[m]=a[m+1];
		a[m+1]=temp;
		f(m+1);
	  }
	   else f(m-1);
    }
    else return;
}

int main()
{
	cin>>n;
	int i;
	for(i=0;i<n;i++) cin>>a[i];
	f(n-2);
	for(i=0;i<n-1;i++) cout<<a[i]<<" ";
	cout<<a[n-1]<<endl;
}


#include<iostream>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<map>
#include<iomanip>
#include<algorithm>
#include<cstdio>
using namespace std;

int ans,l,r;

int main()
{
	cin>>l>>r;
	while(l!=r)
	{
		if(l>r)
		{
			r++;
		}
		else
		{
			if(r&1)//奇数
			{
				r++;
			}
			else
			{
				r/=2;
			}
		}
		ans++;
	}
	cout<<ans<<endl;
}


#include<cstdio>
using namespace std;
int p1,p2,p3,p4,n,m,sum=0;
int main()
{
	scanf("%d%d%d%d%d%d",&p1,&p2,&p3,&p4,&n,&m);
	for(int i=n;i<=m;i++)
	{
		if(i%p1!=i) continue;
		if(i%p2!=i) continue;
		if(i%p3!=i) continue;
		if(i%p4!=i) continue;
		sum++;
	}
	printf("%d",sum);
	return 0;
}


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

const int maxn=105;

int n,a[maxn];

int main(){
	scanf("%d",&n);
	for (int i=1;i<=n;i++){
		scanf("%d",&a[i]);
	}
	int ans=0;
	for (int i=0;i<=n;i++){
		int s=0;
		for (int j=1;j<=i;j++){
			if (a[j]==0) s++;
		}
		for (int j=i+1;j<=n;j++){
			if (a[j]==1) s++;
		}
		ans=max(ans,s);
	}
	cout<<ans;
	return 0;
}


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

int main()
{
    char tmp;
    bool check[26];
    memset(check,false,26);
    int n;
    cin>>n;
    if(n<26)
        {cout<<"NO";return 0;}
    while(n--)
    {
        cin>>tmp;
        if(tmp<91)
        {check[tmp-65]=true;}
        else
        {check[tmp-97]=true;}
    }
    for(int i=0;i<26;i++)
    {if(!check[i]) {cout<<"NO";return 0;}}
    cout<<"YES";
    return 0;
}


#include <iostream>

using namespace std;

int main()
{
    int n;
    cin>>n;
    if(n%2==0)
       cout<<0;
    else
        cout<<1;
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <stack>
#include <bitset>
#include <map>
#include <string>
#include <algorithm>
#define Si(a) scanf("%d",&a)
#define Sl(a) scanf("%lld",&a)
#define Sd(a) scanf("%lf",&a)
#define Ss(a) scanf("%s",a)
#define Pi(a) printf("%d\n",(a))
#define Pl(a) printf("%lld\n",(a))
#define Pd(a) printf("%lf\n",(a))
#define Ps(a) printf("%s\n",(a))
#define W(a) while(a--)
#define mem(a,b) memset(a,(b),sizeof(a))
#define inf 0x3f3f3f3f
#define maxn 1000010
#define mod 1000000007
#define PI acos(-1.0)
#define LL long long
using namespace std;

int main()
{
    int h1,h2,a,b;
    Si(h1);Si(h2);Si(a);Si(b);
    int nowh=h1;
    int t=0;
    nowh+=a*8;
    if(nowh>=h2)
    {
        Pi(0);
        return 0;
    }
    nowh-=b*12;
    nowh+=a*4;
    if(nowh>h2)
    {
        Pi(1);
        return 0;
    }
    int v=a*4-b*12,day=1;
    if(a<=b)
    {
        printf("-1\n");
        return 0;
    }
    for(int i=1;i<=10000000;i++)
    {
        nowh+=a*8;
        if(nowh>=h2)
        {
            Pi(day);
            return 0;
        }
        nowh+=v;
        day++;
        if(nowh>h2)
        {
            Pi(day);
            return 0;
        }
    }
    Pi(-1);
    return 0;
}


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

int main()
{
    int n,m;
    cin>>n>>m;
    if(n<0||n>100||m<0||m>100)
    return 0;
    int ans=0;
    ans+=n;
    while((float)n/(float)m>1){
        ans+=n/m;
        n=n/m+n%m;
    }
    ans+=n/m;
    cout<<ans;
}


#include <map>
#include <set>
#include <cmath>
#include <stack>
#include <queue>
#include <string>
#include <vector>
#include <fstream>
#include <sstream>
#include <bitset>
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include <iostream>
#include <algorithm>
using namespace std;
#define li       	long long int
#define rep(i,to)	for(li i=0;i<((li)(to));i++)
#define pb       	push_back
#define sz(v)    	((li)v.size())
#define bit(n)   	(1ll<<(li)(n))

#define MOD 1000000007
//	p.180
//
#define MAT_TYPE li
#define MAT_MOD MOD
//

#define MAT_MAT vector<vector<MAT_TYPE> >
MAT_MAT mul(MAT_MAT a,MAT_MAT b){
	MAT_MAT res(sz(a),vector<MAT_TYPE>(sz(b[0]),0));
	rep(i,sz(a))rep(j,sz(b[0]))rep(k,sz(a[0])) res[i][j]=(res[i][j]+a[i][k]*b[k][j])%MAT_MOD;
	return res;
}
MAT_MAT pow(MAT_MAT a,li n){
	MAT_MAT res(sz(a),vector<MAT_TYPE>(sz(a[0]),0));
	rep(i,sz(a)) res[i][i]=1;
	while(n){
		if(n%2) res=mul(res,a);
		a=mul(a,a);
		n/=2;
	}
	return res;
}

bool bad(li a,li b){
	if(a==b) return true;
	if(a+b==3) return true;
	return false;
}

bool bad(li a,li b,li c){
	if(a==1 && b==0 && c==2) return true;
	if(a==2 && b==0 && c==1) return true;
	return false;
}

li cal1(li num){
	MAT_MAT mat(32,vector<MAT_TYPE>(32,0));
	rep(i,16) mat[i+16][i]=mat[i+16][i+16]=1;
	rep(i,4)rep(j,4)rep(k,4){
		if(bad(i,j)) continue;
		if(bad(j,k)) continue;
		if(bad(i,j,k)) continue;
		mat[k*4+j][j*4+i]=1;
	}
	MAT_MAT right(32,vector<MAT_TYPE>(1,0));
	rep(i,4)rep(j,4)if(!bad(i,j)) right[i*4+j][0]=1;
	mat=pow(mat,num-1);
	mat=mul(mat,right);
	li res=4;
	rep(i,16) res+=mat[i+16][0];
	return res;
}

li cal0(li num){
	if(num<=0) return 0;
	return ((cal1(num)+cal1((num+1)/2))/2)%MOD;
}

int main(){
	li left,right;
	cin>>left>>right;
	cout<<(cal0(right)-cal0(left-1)+MOD)%MOD<<endl;
}


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

int main()
{ long long int w1,h1,w2,h2;
  cin>>w1>>h1>>w2>>h2;
  if(w1==w2){
              cout<<2*w1+4+2*h1+2*h2;
            }
   else{
       cout<<w1+w2+2*h1+2*h2+5+w1-w2-1;

      }

    return 0;
}


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

int main(int argc, char const *argv[]) {
  int a,b,c;
  while(cin>>a>>b>>c){
    int p=a;
    int q=b;
    int z=c;
  int count=0;
  int am,pm;
  if(a*2<=b && a*4<=c) cout<<a+(a*2)+(a*4)<<endl;
  else{
  while(1){
  //  a--;
    a-=1;
    am=(a*2);
    pm=(a*4);
//    a--;
   if(am<=b && pm<=c) break;
    count++;
  }
//  cout<<a<<" "<<am<<" "<<pm<<endl;
 if(p>1 && q>2 && z>4) cout<<am+pm+a<<endl;
 else if((p>=1 && q>=2 && z>=4)) cout<<1+2+4<<endl;
 else{
   cout<<"0"<<endl;
 }
 }
 }
  return 0;
}


#define _CRT_SECURE_NO_DEPRECATE
#pragma comment(linker, "/STACK:64000000")

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

using namespace std;

typedef long long int64;

#define forn(i, n) for(int i = 0; i < (int)(n); i++)
#define ford(i, n) for(int i = (int)(n) - 1; i >= 0; i--)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(), a.end()

const int INF = (int)1E9;
const int64 INF64 = (int64)1E18;
const long double EPS = 1E-8;
const long double PI = 3.1415926535897932384626433832795;

int days[2][12]={
    {31,28,31,30,31,30,31,31,30,31,30,31},
    {31,29,31,30,31,30,31,31,30,31,30,31}
};

int leap(int y){
    return (y%4)?0:1;
}

bool correct(int a,int b,int c){
    if (b>=1 && b<=12){
        if (a>=1 && a<=days[leap(c)][b-1])
            return true;
    }
    return false;
}

/*int gettime(int a,int b,int c){
    int res=0;
    forn(i,c)
        if (i%4)
            res+=365;
        else
            res+=366;
    forn(i,b)
        res+=days[leap(c)][i];
    res+=a-1;
    return res;
}*/
int d,e,f;
bool check(int a,int b,int c){
    if (c<f-18)
        return true;
    if (c==f-18){
        if (b<e)
            return true;
        if (b==e){
            if (a<=d)
                return true;
        }
        if (a==1 && b==3 && d == 29 && e==2 && leap(c))
            return true;
    }
    return false;
}

bool solve(){
    int a,b,c;
    scanf("%d.%d.%d",&d,&e,&f);
    scanf("%d.%d.%d",&a,&b,&c);
    int x,y,z;
    x=a,y=b,z=c;
    if (correct(x,y,z) && check(x,y,z)) return true;
    x=a,y=c,z=b;
    if (correct(x,y,z) && check(x,y,z)) return true;
    x=b,y=a,z=c;
    if (correct(x,y,z) && check(x,y,z)) return true;
    x=b,y=c,z=a;
    if (correct(x,y,z) && check(x,y,z)) return true;
    x=c,y=a,z=b;
    if (correct(x,y,z) && check(x,y,z)) return true;
    x=c,y=b,z=a;
    if (correct(x,y,z) && check(x,y,z)) return true;
    return false;
}

int main(){
#ifndef ONLINE_JUDGE
    freopen("input.txt", "rt", stdin);
    freopen("output.txt", "wt", stdout);
#endif
    if (solve())
        puts("YES");
    else
        puts("NO");
    return 0;
}


#include<iostream>
#define ll long long
using namespace std;

ll mo = 1e9+7;
ll a,b,n,x;

ll ksmi(ll x,ll n){
    if (n == 0) return 1;
    if (n == 1) return x;
    ll ans;
    ans = ksmi(x,n/2);
    ans = (ans*ans)%mo;
    if (n&1==1) ans = (ans*x)%mo;
    return ans;
}

int main(){
    cin>>a>>b>>n>>x;
    ll ans;
    if (a == 1){
        ans = x;
        n %= mo;
        ans += (n*b)%mo;
        ans %= mo;
    }
    else{
        ll tmp = ksmi(a,n);
        ans = tmp - 1;
        if (ans == -1) ans += mo;
        ans = (ans*b)%mo;
        ans = (ans*ksmi(a-1,mo-2))%mo;
        ans = ((tmp*x)%mo+ans)%mo;
    }
    cout<<ans;
    return 0;
}


//hey Stalker
#include<bits/stdc++.h>
#define ll long long
#define vect vector<ll>
#define pb push_back
#define f(n) for(i=0;i<n;i++)
#define F(n) for(i=1;i<=n;i++)
#define s second
#define mod 1000000007
#define Map map<ll , ll >
using namespace std;
main()
{ll t;
cin>>t;
while(t--)
{
	ll n,k,d;
	cin>>n>>k>>d;
	ll i;
	Map m;
	ll a[n];
	f(n)
		cin>>a[i];
	f(d)
			m[a[i]]+=1;
	ll ans=m.size();
//	cout<<ans<<endl;
	for(i=d;i<n;i++)
	{
//		if(m.find(a[i])==m.end())
			m[a[i]]+=1;
		m[a[i-d]]--;
		if(m[a[i-d]]==0)
			m.erase(a[i-d]);
		ans=min(ans,(ll)m.size());

	}
	cout<<ans<<endl;
}
}


#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

vector <long long> v;

long long pow10(int n)
{
    long long s = 1;
    for (int i = 0; i < n; i ++) s *= 10;
    return s;
}

long long supp_man(long long n)
{
    long long s = 0, tmp = n;
    for (int i = log10(n); i > 0; i --)
    {
        s += tmp / pow10(i);
        tmp -= (tmp / pow10(i)) * pow10(i);
    }
    return n - s;
}

long long nine_s(int n)
{
    long long s = 0;
    for (int i = 0; i < n; i ++) s += 9 * pow10(i) ;
    return s;
}

int main()
{
    long long h, n, s, m = 0;
    cin >> n >> s;
    long long tmp = s;
    for (int i = (int)log10(s + 1); i > 0; i --)
    {
        long long t = s / nine_s(i);
        s -= t * nine_s(i);
        v.push_back(t);
    }
    int k = v.size();
    for (int i = 0; i < k; i ++) m += v[k - 1 - i] * pow10(i);
    if (supp_man(m * 10) >= tmp) h = n - m * 10 + 1;
    else h = n - (m + 1) * 10 + 1;
    if (h >= 0) cout << h;
    else cout << 0;
}


#include<iostream>
#include<set>
#include<map>
#include<functional>
#include<queue>
#include<string.h>
#include<stdio.h>
#include<iomanip>
#include<stdlib.h>
#include<math.h>
#include<cstdlib>
#include<vector>
#include<algorithm>
#include<string>
#include<stack>
#include<queue>
#include<fstream>
typedef long long ll;
#define rep(i,a,b) for (int i = a; i < b; i++)
#define all(x) x.begin(), x.end()
#define sz(a) (int)a.size()
#define sqr(x) ((x) * (x))
#define pi pair<ll, ll>
#define mk(a, b) make_pair(a, b)
#define nextI nextInt()
#define nextD nextDouble()
#define nextL nextLong()
#define nextC nextChar()
#define line newLine()
int nextInt(){ int x; scanf("%d", &x); return x; }
double nextDouble(){ double x; scanf("%lf", &x); return x; }
ll nextLong(){ ll x; scanf("%I64d", &x); return x; }
char nextChar(){ char x; scanf("%c", &x); return x; }
void newLine(){ printf("\n"); }
ll gcd(ll a, ll b){ return b == 0 ? a : gcd(b, a%b); }
ll lcm(ll a, ll b){ return (a*b) / gcd(a, b); }
ll pow(ll a, ll b, ll MOD){ ll x = 1, y = a; while (b > 0){ if (b % 2 == 1){ x = (x*y); if (x>MOD) x %= MOD; }y = (y*y); if (y>MOD) y %= MOD; b /= 2; }return x; }
int countSetBit(ll n){ int ans = 0;  while (n != 0){ n -= (n & -n); ++ans; } return ans; }
ll mod = (ll)(1e9 + 7ll);
const int N = 1000;
const int M = 10111;
const double eps = 1e-6;
using namespace std;
int a[N];
int b[N];
int t[N];
int main(){
#ifdef HOME
	freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
#endif
	int n, m;
	cin >> n >> m;
	if (m <=  1){
		for (int i = 1; i <= n; i++){
			cout << i << " ";
		}
		line;
		return 0;
	}
	memset(b, -1, sizeof b);
	memset(t, -1, sizeof t);
	for (int i = 0; i < m; i++){
		a[i] = nextI;
		if (a[i] > n){
			puts("-1");
			return 0;
		}
	}
	bool vis[N] = { 0 };
	for (int i = 1; i < m; i++){
		int val;
		if (a[i] == a[i - 1]) val = n;
		else if (a[i] > a[i - 1]) val = a[i] - a[i - 1];
		else val = a[i] + n - a[i - 1];
		if ((t[a[i - 1]] != -1 && t[a[i - 1]] != val)){
			puts("-1");
			return 0;
		}
		else if (vis[val] && t[a[i - 1]] != val)
		{
			puts("-1");
			return 0;
		}

		t[a[i - 1]] = val;
		vis[val] = 1;
	}

	for (int i = 1; i <= n; i++){
		if (t[i] == -1){
			for (int j = 1; j <= n; j++){
				if (!vis[j]){
					t[i] = j;
					vis[j] = 1;
					break;
				}
			}
		}
	}
	for (int i = 1; i <= n; i++){
		cout << t[i] << " ";
	}
	line;
	return 0;
}


#include<iostream>
#include<string.h>
#include<string>
#include<stdio.h>
#include<algorithm>
#include<math.h>
#include<vector>
#include<queue>
#include<map>
using namespace std;
const int maxd=1000000007,N=1000000;
const double pi=acos(-1.0);
typedef long long ll;
int n,m,a,b;
ll fac[1001000],invfac[1001000],mpow[1001000],npow[1001000];

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

ll A(int x,int y)
{
	if ((x<y) || (x<0) || (y<0)) return 0;
	return (fac[x]*invfac[x-y])%maxd;
}

ll C(int x,int y)
{
	if ((x<y) || (x<0) || (y<0)) return 0;
	return ((fac[x]*invfac[x-y])%maxd*invfac[y])%maxd;
}

ll qpow(ll x,ll y)
{
	ll ans=1,sum=x;
	while (y)
	{
		int tmp=y%2;y/=2;
		if (tmp) ans=(ans*sum)%maxd;
		sum=(sum*sum)%maxd;
	}
	return ans;
}

void init()
{
	int i;fac[0]=1;invfac[0]=1;
	for (i=1;i<=N;i++) fac[i]=(fac[i-1]*i)%maxd;
	invfac[N]=qpow(fac[N],maxd-2);
	for (i=N-1;i>=1;i--) invfac[i]=(invfac[i+1]*(i+1))%maxd;
	mpow[0]=1;npow[0]=1;
	for (i=1;i<=N;i++)
	    {mpow[i]=(mpow[i-1]*m)%maxd;npow[i]=(npow[i-1]*n)%maxd;}
}

int main()
{
	n=read();m=read();a=read();b=read();
	int i;
	init();
	//for (i=1;i<=n;i++) cout << invfac[i] << " ";cout << endl;
	ll ans=0;
	for (i=1;i<n;i++)
	{
		ll tmp=1;
		tmp=((A(n-2,i-1)*C(m-1,i-1))%maxd*mpow[n-i-1])%maxd;
		if (i!=n-1) tmp=((tmp*(i+1))%maxd*npow[n-i-2])%maxd;
		ans=(ans+tmp)%maxd;
	}
	printf("%lld",ans);
	return 0;
}