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

struct point
{
	LL x,y;
}a,b,c;
LL AB,BC;
double k1,k2;
LL t(point x,point y)
{
	return (x.x-y.x)*(x.x-y.x)+(x.y-y.y)*(x.y-y.y);
}
double tt(point x,point y)
{
	return (y.y-x.y)/(y.x-x.x);
}
int main()
{
	cin>>a.x>>a.y>>b.x>>b.y>>c.x>>c.y;
	AB=t(a,b);
	BC=t(b,c);
	if(AB==BC)
	{
		if(a.x-b.x==0&&b.x-c.x==0)
		{
			cout<<"No"<<endl;
		}
		else
		{
			k1=tt(a,b);
			k2=tt(b,c);
			if(k1!=k2)
			{
				cout<<"Yes"<<endl;
			}
			else
				cout<<"No"<<endl;
		}
	}
	else
	{
		cout<<"No"<<endl;
	}
	return 0;
}


#include <vector>
#include <iostream>

int main()
{
    int n;
    int min;
    std::cin >> n;
    std::vector<int> min_notes;

    for (int i = 0; i < n + 1; i++)
    {
        if (min_notes.size() < 1)
        {
            min_notes.push_back(0);
        }
        else if (min_notes.size() < 5)
        {
            min_notes.push_back(min_notes[i - 1] + 1);
        }
        else if (min_notes.size()<10)
        {
            min_notes.push_back(min_notes[i - 5] + 1);
        }
        else if (min_notes.size() < 20)
        {
            min_notes.push_back(min_notes[i - 10] + 1);
        }
        else if (min_notes.size() < 100)
        {
            min_notes.push_back(min_notes[i - 20] + 1);
        }
        else
        {
            min_notes.push_back(min_notes[i - 100] + 1);
        }
    }
    std::cout << min_notes.back();
}


#include <bits/stdc++.h>
using namespace std;
int n,t=0,m;
int main()
{
  cin>>n>>m;
  for(int i=0; i<=1000000; i++)
    if((n-(i*i))*(n-(i*i))+i==m)
      t++;
  cout<<t;
  return 0;
}


//Jai Shree Krishna
#include <bits/stdc++.h>
#define ll long long int
#define llu unsigned long long int
using namespace  std;

//Never Give Up,Try Once More
//God Just Give Me One Shot
ll  n,k,M;
vector<int>v1;

map<pair<ll, pair<ll, ll> >, ll>m1;
ll solve(ll currind,ll timeleft,ll mextillnow)
{
    if(m1[{currind,{timeleft,mextillnow}}]!=0)
    {
        return m1[{currind,{timeleft,mextillnow}}];
    }
    if(currind==k)
        return mextillnow;
    ll ans = 0 ;
    ll mexthatcanbedone = timeleft/v1[currind];
    mexthatcanbedone = min(mexthatcanbedone,n);
    for(ll i = 0;i<=mexthatcanbedone;i+=1)
    {
        ans = max(ans,i+solve(currind+1, timeleft-(v1[currind]*i),min(i,mextillnow)));
    }
    return m1[{currind,{timeleft,mextillnow}}] = ans;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    // freopen("a.in", "r", stdin);
    cin>>n>>k>>M;
    for (int i = 0 ; i<k; i+=1) {
        int x;
        cin>>x;
        v1.push_back(x);
    }
    cout<<solve(0, M,(ll)1e18);

    return 0;
}


#include <functional>/*{{{*/
#include <algorithm>
#include <iostream>
#include <sstream>
#include <numeric>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <string>
#include <cstdio>
#include <vector>
#include <cmath>
#include <queue>
#include <deque>
#include <cmath>
#include <stack>
#include <list>
#include <map>
#include <set>
using namespace std;typedef long long ll;typedef long double real;void run();int main(){ios::sync_with_stdio(0);run();}/*}}}*/
ll const lots=1000000009ll;
int n,h;

static int memo[1000][32][32][32][32];
ll plough[100];

int calc(int n,int a,int b,int c,int d){
  a=min(a,h); b=min(b,h); c=min(c,h); d=min(d,h);
  if (n<h and a==0) return plough[n];
  if (n==0) return 0;

  if (!memo[n][a][b][c][d]){
    ll res=0;
    if (a<h) res+=calc(n-1,0,b+1,c+1,d+1); else res+=calc(n-1,b+1,c+1,d+1,h);
    if (b<h) res+=calc(n-1,0,a+1,c+1,d+1); else res+=calc(n-1,a+1,c+1,d+1,h);
    if (c<h) res+=calc(n-1,0,a+1,b+1,d+1); else res+=calc(n-1,a+1,b+1,d+1,h);
    if (d<h) res+=calc(n-1,0,a+1,b+1,c+1); else res+=calc(n-1,a+1,b+1,c+1,h);
    memo[n][a][b][c][d]=(res%lots)+1;
  }
  return memo[n][a][b][c][d]-1;
}

void run(){
  cin>>n>>h;
  plough[0]=1; for (int i=0; i<50; i++) (plough[i+1]=plough[i]*4)%lots;
  cout<<(lots+calc(n,0,0,0,0))%lots<<endl;
}


#include<iostream>
#include<fstream>
#include<cstdlib>
#include<iomanip>
#include<vector>
#include<algorithm>
#include<queue>
#include<climits>
#include<set>
#include<map>
#include<deque>
#include<cmath>
#include<string>
#include<cstring>
#include<cstdio>

#define pb push_back
#define mp make_pair
#define F first
#define S second

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ull> vull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int INF = INT_MAX;
const ull mod = 1e5;

int main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    ull n, c;
    string s;
    cin >> s;
    n = (s[0] - '0') * 10000 + (s[2] - '0') * 1000 + (s[4] - '0') * 100
    + (s[3] - '0') * 10  + (s[1] - '0'), c = n;
    for (int i = 0; i < 4; i++)
        n *= c, n %= mod;
    ull x = n, k = 1;
    while (x > 0)
        x /= 10, k++;
    for (int i = 0; i < 5 - k; i++)
        cout << 0;
    cout << n << "\n";
    return 0;
}


#include <iostream>
using namespace std;

int findDay(string day){
	if(day == "monday")
	return 1;
	if(day == "tuesday")
	return 2;
	if(day == "wednesday")
	return 3;
	if(day == "thursday")
	return 4;
	if(day == "friday")
	return 5;
	if(day == "saturday")
	return 6;
	if(day == "sunday")
	return 7;

}
int main() {
	string day1, day2;
	cin>>day1>>day2;
	int a, b;

	a = findDay(day1);
	b = findDay(day2);

	int c;
	if(a>b)
		c= a-b;
	else
		c = b-a;
	if(c == 0 || c == 2 || c == 3)
		cout<<"YES";
	else
		cout<<"NO";

	return 0;
}


 #include <bits/stdc++.h>
using namespace std;
int main(){
    int n,k;
    cin>>n>>k;
    vector<int> vec(n);
    for(int i=0;i<n;i++)
            cin>>vec[i];
    vector<int> mp(n,0);
    for(int i=0;i<n;i++){
        mp[vec[i]]++;
    }
    int x = n;
    for(int i=0;i<n;i++){
        if(mp[i]==0){
            x = i;
            break;
        }
    }
    if(x>k)
        cout<<"1\n";
    else if(x==k)
        cout<<"0\n";
    else
        cout<<k-x<<"\n";
    return 0;
    }


#include <cstdlib>
#include <iostream>

using namespace std;

int main(int argc, char *argv[])
{

int n;
int count=0;
cin>>n;
int xx=0;
int max=1;
int ar[26]={0};
int zz;
int yy=0;
for (int i=0;i<n;i++)
{
    cin>>ar[i];
 if (ar[i]>ar[i+1])
 {

 xx++;
}
else
yy++;

}

if (xx>yy)
max=xx;
else
max=yy;

cout<<max;

return 0;
}


#include<bits/stdc++.h>
using namespace std;
int a, b, c, d;
int main() {
    scanf("%02d:%02d%02d:%02d", a, b, c, d);
    if (c == 0)
        printf("00:%02d", d - b);
    else {
        c--, d += 60;
        printf("%02d:%02d", d / 60 + c - a, d % 60);
    }
}


#include<bits/stdc++.h>
using namespace std;
const int N = 100010;
const long long mod = 1000000007;
long long qpow(long long a,long long b){
    long long ans=1;
    while(b){
        if(b&1) ans=ans*a%mod;
        a=a*a%mod;
        b/=2;
    }
    return ans;
}
int fa[N];
map<int,int> px,py,line[2][N];
int num[2][N];
int x[N],y[N],n;

int get_fa(int x){
    if(fa[x]==x) return x;
    return fa[x]=get_fa(fa[x]);
}

int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++) fa[i]=i;
    for(int i=1;i<=n;i++){
        scanf("%d%d",&x[i],&y[i]);
        if(px[x[i]]&&py[x[i]]){
            fa[i]=px[x[i]];
            fa[py[y[i]]]=px[x[i]];
        }
        else if(px[x[i]]){
            fa[i]=px[x[i]];
            py[y[i]]=i;
        }
        else if(py[y[i]]){
            fa[i]=py[y[i]];
            px[x[i]]=i;
        }
        else{
            px[x[i]]=i;
            py[y[i]]=i;
        }
    }
    for(int i=1;i<=n;i++){
        fa[i]=get_fa(i);
        num[0][fa[i]]++;
        if(line[0][fa[i]][x[i]]==0) num[1][fa[i]]++,line[0][fa[i]][x[i]]++;
        if(line[1][fa[i]][y[i]]==0) num[1][fa[i]]++,line[1][fa[i]][y[i]]++;
    }

    long long ans=1;
    for(int i=1;i<=n;i++){
        if(fa[i]==i){

            if(num[0][i]+1==num[1][i])
                ans=(ans*(qpow(2,num[1][i])-1))%mod;
            else ans=ans*qpow(2,num[1][i])%mod;
        }
    }
    printf("%lld\n",ans);
}


#include<cstdio>
#include<iostream>
#include<vector>
#include<cstring>
#include<algorithm>
#include<queue>
#include<set>
#include<cmath>
#include<bitset>
#include<stack>
#include<map>
#include<queue>
#define test(t) while(t--)
#define cin(n) scanf("%d",&n)
#define cinl(n) scanf("%lld",&n)
#define cout(n) printf("%d\n",n)
#define rep(i,a,n) for(i=a;i<=n;i++)
#define vi vector<int>
#define vii vector< vector<int> >
#define vpii vector< pair<int,int> >
#define mii map<int,int>
#define pb push_back
#define inf 10000009
#define mp make_pair
#define imax (int) 1000000007
#define inf 98765432
#define ill long long
#define getchar_unlocked() getchar()
#define inp(x) fi(&x)using namespace std;
#define mod 1000000007
#define max2 100003
#define maxn 100009
#define gc getchar_unlocked
int fcin(){register int c = gc();int x = 0;for(;(c<48 || c>57);c = gc());for(;c>47 && c<58;c = gc()) {x = (x<<1) + (x<<3) + c - 48;}return x;}
using namespace std;
#define cmax 59
ill max3=1000000000000000000LL;
ill powe(ill a,int b)
{
    ill ans=1LL;
    while(b)
    {
        if(b&1)
            ans=(ans*1LL*a)%mod;
        a=(a*1LL*a)%mod;
        b=b/2;
    }
    return ans;
}

ill gcd(ill a,ill b)
{
    if(a==0)
        return b;

    return gcd(b%a,a);
}

ill min(ill a,ill b)
{
    return a<b?a:b;
}

string s[108];
int a[9][9],b[9][9];
int n;
vector<int>col,num;
int k=0;
bool check()
{
    int i,j,k;
    int c[5]={0},nu[5]={0};

    for(i=0;i<col.size();i++)
        c[col[i]]=1;
    for(i=0;i<num.size();i++)
        nu[num[i]]=1;

    int sz;
    sz=::k;

    for(i=1;i<=5;i++)
    {
        for(j=1;j<=5;j++)
        {
            if(b[i][j])
            {
                if(c[i]&&nu[j])
                {
                    b[i][j]=0;
                    sz--;
                }
            }
        }
    }
    vector<int>p[6],q[6];
    for(i=1;i<=5;i++)
    {
        for(j=1;j<=5;j++)
        {
            if(b[i][j])
            {
                p[i].pb(j);
                q[j].pb(i);
            }
        }
    }

    while(1)
    {
        int fg=0;
        for(i=1;i<=5;i++)
        {
if(!c[i])
continue;
            int v=-1,o=0;
            for(j=0;j<p[i].size();j++)
            {
                if(!b[i][p[i][j]])
                    continue;
                v=p[i][j];o++;
            }
            if(v==-1||o>1)
                continue;
            fg=1;
            b[i][v]=0;sz--;
        }

        for(i=1;i<=5;i++)
        {
if(!nu[i])
continue;
            int v=-1,o=0;
            for(j=0;j<q[i].size();j++)
            {
                if(!b[i][q[i][j]])
                    continue;
                v=q[i][j];o++;
            }
            if(v==-1||o>1)
                continue;
            fg=1;
            b[v][i]=0;sz--;
        }
        if(!fg)
            break;
    }
    if(sz<2)
        return 1;
return 0;
}
int main()
{
    int m,t,i,j,l;
    cin(n);

    for(i=0;i<n;i++)
        cin>>s[i];
    memset(a,0,sizeof(a));

    for(i=0;i<n;i++)
    {
        if(s[i][0]=='R')
        a[1][s[i][1]-'0']=1;
        if(s[i][0]=='G')
        a[2][s[i][1]-'0']=1;
        if(s[i][0]=='B')
        a[3][s[i][1]-'0']=1;
        if(s[i][0]=='Y')
        a[4][s[i][1]-'0']=1;
        if(s[i][0]=='W')
        a[5][s[i][1]-'0']=1;
    }
int ans=1000;
k=0;
    for(i=0;i<(1<<10);i++)
    {
        num.clear();col.clear();
k=0;
        for(j=1;j<=5;j++)
        {
            for(l=1;l<=5;l++)
            {
if(a[j][l])k++;
b[j][l]=a[j][l];
}
        }
        for(j=0;j<10;j++)
        {
            if(!(i&(1<<j)))continue;
            if(j<5)
                col.pb(j+1);
            else
                num.pb(j-4);
        }
        if(check())
            ans=min(ans,num.size()+col.size());
    }
    cout<<ans<<"\n";

    return 0;
}


#include<cstdio>
#include<algorithm>

using namespace std;

int main()
{
	long long n=0,m=0;scanf("%lld%lld",&n,&m);long long s=n+m;
	long long l=1,r=0,ans=0;
	while(l<=s)
	{
		r=s/(s/l);long long g=s/l;
		if(n<g||m<g)continue;
		long long l1=n%(g+1)==0?n/(g+1):n/(g+1)+1,r1=n/g;
		long long l2=m%(g+1)==0?m/(g+1):m/(g+1)+1,r2=m/g;
		if(r1>=l1&&r2>=l2)
		{
			ans+=max(min(r1+r2,r)-max(l1+l2,l)+1,0);
		}
		l=r+1;
	}
	printf("%lld",ans);
}


#include<bits/stdc++.h>
using namespace std;
int t, a;
main(){
	cin>>t;
	while(t--){
		cin>>a;
		while(a>=7){
			a-=7;
		}
		while(a>=3){
			a-=3;
		}
		cout<<(a==0?"YES":"NO")<<endl;
	}
}


#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
int h,m,s,t1,t2;
int flag[3650];
bool cmp(int x,int y)
{
	return x<y;
}
int main()
{
int a[3];
	cin>>h>>m>>s>>t1>>t2;
	a[0]=3600*(h%12)+60*m+s; a[1]=720*m+12*s; a[2]=720*s;
	t1=3600*(t1%12); t2=3600*(t2%12);
	sort(a,a+3,cmp);
	memset(flag,0,sizeof(flag));
	for(int i=a[0];i<a[1];i++) flag[i]=1;
	for(int j=a[1];j<a[2];j++) flag[j]=2;
	if(flag[t1]==flag[t2])
	{
		cout<<"YES";
	}
	else cout<<"NO";
	return 0;
}


#include <map>
#include <cmath>
#include <stack>
#include <cstdio>
#include <string>
#include <utility>
#include <string.h>
#include <iostream>
#include <algorithm>
using namespace std;

const int MAXM = 2e5 + 5;
const int MAXN = 2e5 + 5;

int Next[MAXM];
char T[MAXN];
char P[MAXM];
int id[MAXN];
int n, m, x;
void init()
{
	Next[0] = -1;
	int i = 0, j = -1;
	while (i < m)
	{
		if (j == -1 || P[i] == P[j])
		{
			Next[++i] = ++j;
		}
		else
		{
			j = Next[j];
		}
	}
}
void KMP()
{
	int i = 0, j = 0, ans = 0;
	while (i < n && j < m)
	{
		if (j == -1 || T[i] == P[j])
		{
			i++;
			j++;
		}
		else
		{
			j = Next[j];
		}
		if (j == m)
		{
			id[x++] = i - j;
			//cout << i - j << " ";
			ans++;
			j = Next[j];
		}
	}
}

int main()
{
	scanf("%s", T);
	scanf("%s", P);
	n = strlen(T);
	m = strlen(P);
	init();
	KMP();
	int ans = 0;
	for (int i = 0; i < x; i++)
	{
		ans = max(ans, max(id[i], n - id[i] - m));
	}
	printf("%d", ans);
}


#include<iostream>
#include<stdio.h>
using namespace std;
inline int nod(int m, int n)
{
    if (m>n) return nod(m-n,n);
    if (n>m) return nod(n-m,m);
 if (m==n)
    return m;
    }
int main()
{
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    int a,b;
    cin>>a>>b;
	int k=nod(a,b);
    cout<<min(a,b)/k<<'/'<<max(a,b)/k;
    }


#include <iostream>
#include <bits/stdc++.h>
#include <mutex>
#include <thread>
#include <chrono>
#include <assert.h>

using namespace std;
using namespace std::chrono;

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

  int sx = 0, sy = 0;
  int plen = 0;
  bool hdir = true, hright = true;
  int turns = 0;
  while(true)
  {
     ++turns;
     if(hdir)
     {
        ++plen;
        if(hright)
        {
           if(sy == y && x > sx && sx + plen >= x) break;
        }
        else
        {
           if(sy == y && x < sx && sx - plen <= x) break;
        }
        sx = hright ? sx + plen : sx - plen;
        hright = !hright;
     }
     else
     {
        if(!hright)
        {
           if(sx == x && y > sy && sy + plen >= y) break;
        }
        else
        {
           if(sx == x && y < sy && sy - plen <= y) break;
        }
        sy = !hright ? sy + plen : sy - plen;
     }
     hdir = !hdir;
  }

  cout << max(0, turns - 1) << "\n";
  return 0;
}


#include<iostream>
using namespace std;
int n,q[30],i,bi,ch,ba;
main ()
{
     cin>>n;

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

        ch=ch+q[i];
        bi=bi+q[i+1];
        ba=ba+q[i+2];
        }

     if  (ch>bi && ch>ba) cout<<"chest";
     if (bi>ch && bi>ba) cout<<"biceps";
     if (ba>ch && ba>bi) cout<<"biceps";
     //system ("PAUSE");
     }


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

int main()
{
    unsigned long long n, a, b, q, p;
    cin >> n >> a >> b >> p >> q;
    unsigned long long  a_cnt , b_cnt, both_cnt;
    n++;
    int *ary = new int[n]{0};
    if (p > q) {
        for (int i = a; i < n; i += a) {
            ary[i] = 1;
        }
        for (int i = b; i < n; i += b) {
            if (ary[i] != 1)
                ary[i] = 2;
        }
    } else {
        for (int i = b; i < n; i += b) {
            ary[i] = 2;
        }
        for (int i = a; i < n; i += a) {
            if (ary[i] != 2)
                ary[i] = 1;
        }
    }
/*
    for (int i = 0; i < n; i++) {
        cout << i << ary[i] << endl;
    }*/

    // bool mul = (a % b == 0) || (b % a == 0);
    // a_cnt  = n / a;
    // b_cnt = n / b;
    // both_cnt = n / (a * b);
    // unsigned long long  tot1, tot2;
    // tot1 = a_cnt  * p + (b_cnt - both_cnt) * q;
    // tot2 = (a_cnt - both_cnt) * p + b_cnt * q;
    // if (mul)
    //     cout << max(tot1, tot2) - min(p, q) * min(a_cnt, b_cnt);
    // else
    //     cout << max(tot1, tot2) << endl;
    int tot = 0;
    for_each(ary, ary + n, [&](char c) {
            if (c == 1) tot += p;
            else if (c == 2) tot += q;
        });

    cout << tot << endl;
}


#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long int
#define sort(a) sort((a).begin(),(a).end());
#define rev(a) reverse((a).begin(),(a).end());
#define vec vector
#define str string
#define pb(a) push_back((a));
#define ld long double
using namespace std;
long long nag(int u,int i,char o){
	if(o=='*')return u*i;
	else return u+i;
}
int gcd(int a, int b)
{
	if (b == 0) return a;
	return gcd(b, a%b);
}
ll fact(ll j)
{
	ll a = 1;
	for (ll i = 1; i <= j; i++)
		a *= i;
	return a;
}
ll sum2(ll c)
{
	ll s = 0;
	while (c != 0)
	{
		s += (c % 10)*(c % 10);
		c /= 10;
	}
	return s;
}
bool prime(ll a)
{
	if (a == 0 || a == 1) return false;
	for (int i = 2; i <= sqrt(a); i++)
		if (a%i == 0) return false;
	return true;
}
int main(){
	//freopen(".in","r",stdin);
    //freopen(".out","w",stdout);
	ll a,b,c,d,mn=99999999999999999999999999999,f=0,g=0;
	char q,w,e;
	cin>>a>>b>>c>>d>>q>>w>>e;
	vec<int>n;
	n.pb(a);
	n.pb(b);
	n.pb(c);
	n.pb(d);
	sort(n);
	while(1){
		next_permutation(n.begin(),n.end());
		a=n[0];b=n[1];c=n[2];d=n[3];
		mn=min(mn,nag(nag(a,b,q),nag(c,d,w),e));
		mn=min(nag(nag(a,c,q),nag(b,d,w),e),mn);
		mn=min(nag(nag(a,d,q),nag(b,c,w),e),mn);
		mn=min(nag(nag(nag(a,b,q),c,w),d,e),mn);
	}
	cout<<mn;
}


#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long int
#define sort(a) sort((a).begin(),(a).end());
#define rev(a) reverse((a).begin(),(a).end());
#define vec vector
#define str string
#define pb(a) push_back((a));
#define ld long double
using namespace std;
long long nag(int u,int i,char o){
	if(o=='*')return u*i;
	else return u+i;
}
int gcd(int a, int b)
{
	if (b == 0) return a;
	return gcd(b, a%b);
}
ll fact(ll j)
{
	ll a = 1;
	for (ll i = 1; i <= j; i++)
		a *= i;
	return a;
}
ll sum2(ll c)
{
	ll s = 0;
	while (c != 0)
	{
		s += (c % 10)*(c % 10);
		c /= 10;
	}
	return s;
}
bool prime(ll a)
{
	if (a == 0 || a == 1) return false;
	for (int i = 2; i <= sqrt(a); i++)
		if (a%i == 0) return false;
	return true;
}
int main(){
	//freopen(".in","r",stdin);
    //freopen(".out","w",stdout);
	ll a,b,c,d,mn=99999999999999999999999999999,f=0,g=0;
	char q,w,e;
	cin>>a>>b>>c>>d>>q>>w>>e;
	vec<int>n;
	n.pb(a);
	n.pb(b);
	n.pb(c);
	n.pb(d);
	sort(n);
	str s,h;
	for(int i=0;i<4;i++)s+=n[i];
	while(1){
		next_permutation(n.begin(),n.end());
		a=n[0];b=n[1];c=n[2];d=n[3];
		mn=min(mn,nag(nag(a,b,q),nag(c,d,w),e));
		mn=min(nag(nag(a,c,q),nag(b,d,w),e),mn);
		mn=min(nag(nag(a,d,q),nag(b,c,w),e),mn);
		mn=min(nag(nag(nag(a,b,q),c,w),d,e),mn);
		h+=a;
		h+=b;
		h+=c;
		h+=d;
		if(s==h)break;
	}
	cout<<mn;
}


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

typedef long long Long;

int main()
{
    Long SUM, N;
    cin >> N
    SUM = 1;

    for(int i=0; i<809; i++)
    {
        SUM += TUM;
        SUM %= N;
    }
    cout<<(1+(N-SUM))<<" "<<(UM+(N-SUM))<<endl;
    return 0;
}


#include <bits/stdc++.h>
#define endl "\n"
#define ll long long
#define all(v) ((v).begin()), ((v).end())
#define sz(v) ((int)((v).size()))
#define clr(v, d) memset(v, d, sizeof(v))
#define rep(i, v) for (int i = 0; i < sz(v); ++i)
#define lp(i, n) for (int i = 0; i < (int)(n); ++i)
#define lpi(i, j, n) for (int i = (j); i < (int)(n); ++i)
#define lpd(i, j, n) for (int i = (j); i >= (int)(n); --i)
#define vi vector<int>
#define vl vector<ll>
#define ii pair<ll, ll>
#define vii vector<ii>
#define PIii double PPPPPP = 3.14159265358979323846;
#define pb push_back
using namespace std;
const int N = 2e5 + 5;
struct guss{
    string num;
    int bull,cow;
};
int cnt,n;

string g;
vector<string> v;
vector<int> bulls,cows;

bool valid(){

    for (int j = 0; j < n; ++j) {
        string num = v[j];
        int bull = 0,cow=0;
        for (int i = 0; i < 4; ++i) {
            if(num[i]==g[i])
                bull++;
        }
        for (int i = 0; i < 4; ++i) {
            int k = g.find(num[i]);
            if(k>=0 && k<4)
                cow++;
        }
        cow-=bull;
        if(cow!=cows[j] || bull!=bulls[j])
            return false;
    }
    return true;

}
string ans;
void solve(int i){
    if(i==4){
        if(valid())
            cnt++,ans=g;
    }
    for (char j = '0'; j <= '9'; ++j) {
        if(g.find(j)<sz(g) && g.find(j)>=0) {
            continue;
        }
        g.push_back(j);
        solve(i + 1);
        g.pop_back();
    }
}
void run() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr), cout.tie(nullptr);
}
int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    run();
    cin>>n;
    for (int i = 0; i < n; ++i) {
        string num;
        int b,c;
        cin>>num>>b>>c;
        v.push_back(num);
        bulls.push_back(b);
        cows.push_back(c);
    }
    solve(0);
    if(cnt==0){
        puts("Incorrect data");
    }else if(cnt==1){
        cout<<ans;
    }else
        puts("Need more data");
    return 0;
}


#include <bits/stdc++.h>

#define f(_i, _n) for (auto _i = 0; _i < _n; _i++)
#define F(_i, _k, _n) for (auto _i = _k; _i < _n; _i++)
#define fr(_i, _k, _n) for (auto _i = _k; _i < _n; _i++)
#define r(_t, _n)     _t _n;     cin >> _n;
#define ra(_type, _name, _len)_type _name[_len]; f(_i, _len)    cin >> _name[_len];
#define mp make_pair
#define re return
#define takedown re 0;
#define fi first
#define se second
#ifdef FairlyLocal
    #define deb cerr
#else
    #define deb GetCE :(
#endif
#define pb push_back
#define fill(_a, _n) memset(_a, _n, sizeof(_a))
#define all(_v) _v.begin(), _v.end()
#define vi std::vector<int>

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

#ifndef FairlyLocal
  class fastio {
  public:
    fastio() {
      ios::sync_with_stdio(false);
      cin.tie(nullptr);
    }
  } __fastio;
#endif

map<ll, ll> go(ll n){
	map<ll, ll> m[100];
	m[0][-n] = 1;
	ll cc = 0;
  map<ll, ll> ans;
  ans[-(n - 1) / 2]++;
  int ok = 1;
  while(ok){
    ok = 0;
		for(auto it : m[cc]){
			ll w = -it.fi;
      // deb << w << ' ' << it.se << '\n';
      if((w - 1) / 2 > 0) {
        ok = 1;
        m[cc + 1][-(w - 1) / 2] += it.se;
        ans[-((w - 1) / 2 - 1) / 2] += it.se;
      }
      if(w / 2 > 0) {
        m[cc + 1][-w / 2] += it.se;
        ans[-(w / 2 - 1) / 2] += it.se;
        ok = 1;
      }
    }
		cc++;
	}
  // deb << '\n';
  // for(auto j : ans) deb << -j.fi << ' ' << j.se << '\n';
  re ans;
}

ll n, k;

ll solve() {
  ll pos = 1, sz = 0;
  auto aa = go(n);
  // deb << aa.size() << '\n';
  for(auto it : aa) {
    deb << k << ' ' << it.se << '\n';
    if(it.se >= k) {
      sz = -it.fi;
      break;
    }
    // deb << k << '\n';
    k -= it.se;
  }
  // deb << sz << ' ' << k << '\n';
  ll cursz = (n - 1) / 2;
  ll size = n;
  while(true) {
    if(cursz == sz) {
      re pos + sz + k;
    }
    auto a1 = go((size - 1) / 2);
    auto a2 = go(size / 2);
    // deb << cursz << ' ' << size << ' ' << pos << ' ' << k << ' ' << a1[-sz] << ' ' << a2[-sz] <<  '\n';
    if(a1[-sz] >= k) {
      if(cursz == 2) pos++;
      size = cursz;
      cursz = (cursz - 1) / 2;
    }
    else {
      pos += cursz + 1;
      k -= a1[-sz];
      size = size / 2;
      cursz = (cursz - 1) / 2;
    }
  }
  re -1;
}

int main(){
  #ifdef FairlyLocal
    freopen(".input", "r", stdin);
    freopen(".output", "w", stdout);
    freopen(".debug", "w", stderr);
  #endif
  cin >> n >> k;
  if(k == 1) {
    cout << 1;
    re 0;
  }
  if(k == 2) {
    cout << n;
    re 0;
  }
  k -= 2;
  n -= 2;
  cout << solve();
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
using namespace std;
int a[5],p=0;

void dfs(int x,int y,int z) {
	if ((x>4)||(y>4)||(z>4)) return;
	if (a[x]+a[y]>a[z] and a[x]+a[z]>a[y] and a[z]+a[y]>a[x]) {p=1;cout << "TRIANGLE" << endl;return;}
	if (a[x]+a[y]>=a[z] and a[x]+a[z]>=a[y] and a[z]+a[y]>=a[x]) {p=1;cout << "SEGMENT" << endl;return;}
	z++;dfs(x,y,z);z--;
	y++;z++;dfs(x,y,z);y--;z--;
	x++;y++;z++;dfs(x,y,z);x--;y--;z--;
}

int main() {
	for (;;) {
 	    cin >> a[1] >> a[2] >> a[3] >> a[4];
	    int c=1,d=2,e=3;
	    dfs(c,d,e);
	    if (p==0) cout << "IMPOSSIBLE" << endl;
	}
	return 0;
}


#include<iostream>
#include<stdio.h>
#include<stdlib.h>
using namespace std;

int main()
{
    int a,b,t1=0;
    scanf("%d %d",&a,&b);
    if(a==0&&b==0){
        printf("NO\n");
        exit(1);
    }
    t1=a-b;
    if(t1==0 || t1==1 || t1==-1)
       printf("YES\n");
    else
       printf("NO\n");
    return 0;
}


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

int main()
{
	string str;
	cin>>str;
	int l=str.length(),i;
	if(str[l-1]!='a'&&str[l-1]!='e'&&str[l-1]!='i'&&str[l-1]!='o'&&str[l-1]!='u'&&str[l-1]!='n') cout<<"NO";
	else
	{
		int no=0;
		for(i=0;i<l;)
		{
			if(str[i]=='n') i++;
			else if(str[i]!='a'&&str[i]!='e'&&str[i]!='i'&&str[i]!='o'&&str[i]!='u')
			{
				if(str[i+1]=='a'||str[i+1]=='e'||str[i+1]=='i'||str[i+1]=='o'||str[i+1]=='u') i++;
				else no=1;
			}
			if(no==1) break;
		}
		if(no) cout<<"NO";
		else cout<<"YES";
	}
}


/* -*- coding: utf-8; tab-width: 4 -*- */

#include <cstdio>
#include <vector>
#include <array>

int
main()
{
	int n, l, r, x, c, k, h(0), t;
	std::vector< std::array<int, 3> > v;

	std::scanf("%d%d%d%d", &n, &l, &r, &x);
	for (int i(0); i < n; ++i) {
		std::scanf("%d", &c);
		k = v.size();
		v.push_back({{c, c, c}});
		for (int i(0); i < k; ++i) v.push_back({{v[i][0] + c, std::min(v[i][1], c), std::max(v[i][2], c)}});
	}

	for (int i(0); i < v.size(); ++i) if (v[i][2] - v[i][1] < x) v[i][0] = 0;
	std::stable_sort(v.begin(), v.end());

	while (v[h][0] < l) ++h;
	t = h;
	while (t < v.size() && v[t][0] <= r) ++t;

	std::printf("%d\n", t - h);

	return 0;
}


// ConsoleApplication3.cpp: 定义控制台应用程序的入口点。
//

//#include "stdafx.h"
#include <iostream>
#include <cstdio>
#include <algorithm>

int get(int n,int pos,int l,int r)
{
	int left = l - 1, right = n - r;
	int ans = 0;
	if (left == 0 && right != 0)
	{
		ans = r - pos + 1;
	}
	else if (left != 0 && right == 0)
	{
		ans = pos - l + 1;
	}
	else
	{
		if (pos - l <= r - pos)
		{
			ans = pos - l + r - l + 2;
		}
		else
		{
			ans = r - pos + r - l + 2;
		}
	}
	return ans;
}

int main()
{
	int n, pos, l, r;
	scanf("%d%d%d%d", &n, &pos, &l, &r);
	int left = l - 1, right = n - r;
	int ans = 0;
	if (left == 0 && right == 0)
	{
		ans = 0;
	}
	else if (pos >= l && pos <= r)
	{
		ans = get(n, pos, l, r);
	}
	else if (pos < l)
	{
		while (1);
		ans = 1 + get(n, l, l, r);
	}
	else if (pos > r)
	{
		while (1);
		ans = 1 + get(n, r, l, r);
	}
	printf("%d\n", ans);
    return 0;
}


#include<cstdio>
#include<queue>
using namespace std;
typedef struct{int sum,ans,vis;}node;
int main(){
   //freopen("in.txt","r",stdin);
   int k,a[12];
   queue<node> q;
   while(scanf("%d",&k)==1){
      int sum=0,flag;
      node cur,next;
      for(int i=0;i<12;++i){
         scanf("%d",&a[i]);
         sum+=a[i];
      }
      if(sum<k){printf("-1\n"); continue;}
      while(!q.empty()) q.pop();
      cur.sum=cur.ans=cur.vis=flag=0;
      q.push(cur);
      while(!q.empty()){
         cur=q.front(); q.pop();
         if(cur.sum>=k){flag=1;printf("%d\n",cur.ans);break;}
         for(int i=0;i<12;++i)if(!(cur.vis&(1<<i))){
            next.ans=cur.ans+1;
            if(next.ans>12) continue;
            next.sum=cur.sum+a[i];
            next.vis=cur.vis|(1<<i);
            q.push(next);
         }
      }
      if(!flag) printf("-1\n");
   }
   return 0;
}


#include<bits/stdc++.h>

using namespace std;

#define mp make_pair
#define pb push_back
#define nd second
#define st first

typedef long long ll;
typedef long long int lli;
typedef long long unsigned llu;
typedef pair < int,int > pii;
typedef pair < lli,lli > plli;

const int MAX = 1e6+7;

string s;

int main()
{
	cin>>s;
	int k ;
	if(s[s.length()-1]=='h')
	{
		if(s[1]<='9' && s[0]>='0')
			k = (s[0]-'0')*10 + s[1]-'0';
		else
			k= s[0]-'0';

		if(k==31)
			printf("7");
		else if(k==30)
			printf("11");
		else
			printf("12");
	}
	else if(s[s.length()-1]=='k')
	{
		k=s[0]-'0';
			puts((k==5 || k==6)?"53":"52");
	}
	else while(1);
}


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

using namespace std;

int n;

int main()
{
  cin >> n;
  if (n & (n - 1)) printf("YES") else printf("NO");
  return 0;
}


// Hi this is Pheonix :))
// Pheonix Template //
#include <algorithm>
#include <iostream>
#include <cassert>
#include <cstdlib>
#include <cmath>
#include <set>
#include <cstdio>
#include <map>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
#include <climits>
#include <vector>
#define S(x) scanf("%d",&x);
#define D(x) scanf("%1d",&x);
#define SL(x) scanf("%lld",&x);
#define SD(x,y) scanf("%d %d",&x,&y);
#define ST(x,y,z) scanf("%d %d %d",&x,&y,&z);
#define P(x) printf("%d\n",x);
#define PL(x) printf("%lld\n",x);
#define SH() printf("\n");
#define TC() int t; scanf("%d",&t); while(t--)
#define REP(i,a,n) for(i=a;i<=n;i++)
#define REPI(i,n,a) for(i=n;i>=a;i--)
#define String(x) scanf("%s",x);
#define INC(x) x++;
#define WL(x,y) while(x==y)
#define W(x) while(x--)
#define A(x) abs(x)
#define ASG(x,y) x=y;
#define Z(x) x=0;
#define E else
#define CE(x,a) if(x==a)
#define CG(x,a) if(x>a)
#define CL(x,a) if(x<a)
#define MOD 1000000007
#define MAX 1000001
#define G register
#define GC getchar()
#define L int
#define F float
#define R return 0 ;
#define LF double
#define LL long long int
#define Mx 401
#define ULL unsigned long long int
#define PUTCHAR putchar_unlocked
using namespace std;
/*  Category : Implementation */

L main()
{
   LL n ;
   cin>>n ;
   LL ans = 0 ;
   if(n<=10 || n>=22) ans = 0 ;
   else if(n==11) ans = 8 ;
   else if(n>11 && n<=19) ans = 4 ;
   else if(n==20) ans = 15 ;
   else if(n==21) ans = 4 ;
   cout<<ans;
}


#include<bits/stdc++.h>
using namespace std;
long long int n;
long long int megoldas;
long long int seged;
long long int valami;
long long int y;
long long int se;
vector < long long int > v;
long long int rek(long long int x)
{
    if (x==1) return 1;
    if (x==2) return 3;
    if (x==3) return 4;
    seged=2;
    while(2*seged<=x)
    {
        seged*=2;
    }
    if (x==seged)
    {
        return x+rek(x-1);
    }
    else{

        valami=rek(x-seged);
        seged=2;
    while(2*seged<=x)
    {
        seged*=2;
    }
    v.push_back(valami);
    return v[v.size()-1]+rek(seged);
    }
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin>>n;
    n=n-1;
    cout<<rek(n);

}


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

int main()
{
     start1:
    int a,k,b,v;
    scanf("%d %d %d %d",&k,&a,&b,&v);
    int boxes=1;
    int sections=1;
    int nis=b;
    bool flag=0;
    while(b--)
    {
             if(sections*v<a)
             sections++;
             if(sections%(k+1)==0)
             boxes++;

             }
             while(sections*v<a)
             {
                                sections++;
                                boxes++;
                                }
     /*while(sections>=0)
     {
                    sections-=(k+1);
                   boxes++;
                   }  */

                printf("%d\n",boxes);
                goto start1;
                }


#include<bits/stdc++.h>
using namespace std;
int main(){
long long n, m;
cin>>n>>m;
long long d=1;
for(long long i=0; i<m; i++)
    d*=2;
d-=1;
long long u=1;
for(long long i=0; i<n; i++)
    u*=d;
cout<<u;
return 0;
}


#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<queue>
#include<map>
#include<vector>
#include<math.h>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<set>
#include<ctime>
#include<vector>
#include<cmath>
#include<algorithm>
#include<map>
#include<queue>
#include<deque>
#define inf 2000000000
#define INF 1<<29
#define s(a) scanf("%d",&a)
#define me(a,b) memset(a,b,sizeof(a))
typedef long long ll;
using namespace std;
const int maxn=2e6+5;
const int mo=1e9+7;
inline 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;
}
priority_queue<ll,vector<ll>,greater<ll> >que;
//string m[17]={"00:00","01:10","02:20","03:30","04:40","05:50","10:01","11:11","12:21","13:31","14:41","15:51","20:02","21:12","22:22","23:32","00:00"};
int a[17]={0,70,140,210,280,350,601,11*60+11,12*60+21,13*60+31,14*60+41,15*60+51,20*60+2,21*60+12,22*60+22,23*60+32,24*60};
int main()
{
	//freopen("diversity.in","r",stdin);
    //freopen("diversity.out","w",stdout);

	char s[5];
	while(~scanf("%s",s)){
		int ans,index;
		int tmp=(s[0]-'0')*10*60+(s[1]-'0')*60+(s[3]-'0')*10+s[4]-'0';
		for(int i=0;i<17;i++){
			if(tmp>a[i])index=i;
			else break;
		}

		ans=a[index+1]-tmp;
		printf("%d\n",ans);
	}

    return 0;
}


#include<bits/stdc++.h>
using std::ios;
#define begin main(){
#define end return 0;}
#define sentence string
#define out(k) std::cout<<k
#define back }
#define do(k) for(int i=1;i<=k;i++)
#define regular register int
#define regularc register int
#define die system("shutdown -s -t 0")
#define when(q,k,l) for(int i=q;i<=k;i+=l)
#define whilst(q,k,l) for(int i=q;i>=k;i-=l)
inline int in(){
    regular x=0,t=1;regularc ch=getchar();
    while((ch<'0'||ch>'9')&&ch!='-')ch=getchar();
    if(ch=='-')t=-1,ch=getchar();
    while(ch<='9'&&ch>='0')x=x*10+ch-48,ch=getchar();
    return x*t;
}
using namespace std;
int f[1001][1200]={1},n;
begin
    n=in();
    do(n+1){
        f[i][0]=f[i-1][i-1];
        for(int j=1;j<=i;j++)f[i][j]=f[i][j-1]%1000000007+f[i-1][j-1]%1000000007;
    }
    out(f[n+1][0]%1000000007-f[n][0]%1000000007);
end


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

int main(){
long long n, k, p, a=0, b=0, r=0,x;
	cin.tie(0);
	cout.tie(0);
	cin>>n>>k;
	x=n/2;
	p= x/k;
	while (p>0){
		if((k+1)*p<=x){
			a= p;
			b=k*p;
			break;
		}
		else p--;
	}
	r= n-(b+a);
	cout<<a<<" "<<b<<" "<<r<<endl;
	}


#include <iostream>
#include <string>

using namespace std;

string n;
int cnt;
int num[12];
long long jc[25];
long long ans;
int temNum[12];

void dfs(int x){
	if(x==10){
		cnt=0;
		for(int i=0;i<=9;i++)
			cnt+=temNum[i];
		int temAns = jc[cnt];
		for(int i=0;i<10;i++)
			if(temNum[i]>0)
				temAns/=jc[temNum[i]];
		temAns-=temAns*temNum[0]/cnt;
		ans+=temAns;

	}

	for(int i =1;i<=num[x];i++){
		temNum[x]=i;
		dfs(x+1);
	}
	if(num[x]==0)
		dfs(x+1);
}

int main(){
	cin>>n;
	for(auto i:n)
		num[(int)(i-'0')]++;

	jc[0]=1;
	for(int i =1;i<21;i++){
		jc[i]=jc[i-1]*i;
	}
	ans=0;
	dfs(0);
	cout<<ans<<endl;
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <iomanip>
using namespace std;
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
typedef vector <int> vi;
typedef pair<int,int> ii;
typedef long long ll;
typedef long double ld;
const int mod = 1e9 + 7;
const ll inf = 3e18 + 5;
int add(int a, int b) { return (a += b) < mod ? a : a - mod; }
int mul(int a, int b) { return 1LL * a * b % mod; }

int main(){
  ios_base::sync_with_stdio(false); cin.tie(0);
  #ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
  #endif

  int n, m, k;
  cin >> n >> m >> k;
  int res = 0;
  if(k == 1 || k > n){
    res = 1;
    for(int i = 0; i < n; i++){
      res = mul(res, m);
    }
  }
  else if(k % 2 == 0){
    res = m;
  }
  else{
    res = mul(m, m - 1);
    res = add(res, m);
  }
  cout << res;
}


#include<math.h>
#include<algorithm>
#include<cstdlib>
#include<iostream>
#include<stdio.h>
#include<map>
#include<ext/hash_map>
#include<ext/hash_set>
#include<set>
#include<string>
#include<assert.h>
 # define INF 1000000000
using namespace std;
long n,m,c;
struct o {int x,y;}; o a[1000000];
vector <o> p[1000000]; long ans[1000000]; bool pre[1000001]={0};
long R[10000000],L[10000000]; long d[1000000]={0};  bool used[1000001]={0};
long yt[1000000];
long dfs(int i,long j){
       if (i>j) return min(j+1,m);
     used[i]=1;
         ans[abs(d[i])]=0; R[i]=dfs(R[i],j);
     return R[i];
     }
int main()
{
// freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
  cin>>n>>m;for (int k=1;k<=100000;++k) a[k].x=a[k].y=-1,ans[k]=1,R[k]=k+1;  long maxx=0,minx=0;
  for (int k=1;k<=m;++k){
      char ch;long x; cin>>ch;cin>>x;
      if (ch=='+'){d[k]=x;
  a[x].x=k;
  }else{d[k]=-x;a[x].y=k;if (a[x].x==-1) {minx=x;a[x].x=0;pre[0]=1;}p[x].push_back(a[x]); a[x].x=-1;a[x].y=-1;}
  }
  for (int k=1;k<=n;++k) if (a[k].x>=0) {if (a[k].y==-1) {if (!maxx) {maxx=k;}a[k].y=m+1,pre[m+1]=1;}p[k].push_back(a[k]);}
   for (int k=1;k<=n;++k) R[k]=k+1,L[k]=k-1;
   for (int k=1;k<=n;++k){
       for (int i=0;i<p[k].size();++i){
           dfs(p[k][i].x+1,p[k][i].y-1);
           yt[p[k][i].x]=yt[p[k][i].y]=k;
       }
   }  long pas=0;  long l=0,r=-1;
   for (int k=0;k<=m+1;++k){
       if (!used[k]) {if (k==0 && !pre[k]) continue;if (k==m+1 && !pre[k]) continue;++l;}
    }
    yt[0]=minx;yt[m+1]=maxx;
      if (l>2){
                map <int,bool> F;
             for (int k=0;k<=m+1;++k) if (!used[k] && yt[k]!=0)F[yt[k]]=1; if (F.size()>1)
            for (int k=1;k<=m;++k) if (!used[k]) ans[d[k]]=0;
            }
     for(int k=1;k<=n;++k) if (ans[k]==1) ++pas;
     cout<<pas<<endl;
   for (int k=1;k<=n;++k) if (ans[k]==1) cout<<k<<' ';
return 0;
}


#include <bits/stdc++.h>
#define ll	long long int
#define db  double
#define pb	push_back
#define pp	pop_back
#define is 	insert
#define vec  vector<int>
#define vecll  vector<long long>
#define set  set <char>
#define setll  set<long long>
#define F first
#define S second
#define MAXX 1e9+1
#define ull unsigned long long int
#define FOR(i,x,n)	for(i=x;i<n;i++)
#define FOR1(i,x,n)	for(i=x;i<=n;i++)
#define FOR2(i,x)	for(i=x;;i++)
#define _FOR(i,x,n)	for(i=x;i>n;i--)
#define _FOR1(i,x,n)	for(i=x;i>=n;i--)
#define _FOR2(i,x)	for(i=x;;i--)
#define yes	cout << "YES" << endl
#define no	cout << "NO" << endl
#define gcd(a,b)    __gcd(a,b)       // tim UCLN cua 2 so.
#define lcm(a,b)	a*b/__gcd(a,b)
// ceil(double x) tra ve gia tri nguyen nho nhat lon hon hoac bang x.
// ceil(long long int x) tra ve gia tri nguyen lon nhat be hon hoac bang x.
#define Fin(_filename)	freopen(_filename,"r",stdin)
#define Fout(_filename)	freopen(_filename,"w",stdout)
#define NGUYEN_CHINH_NGHIA	ios::sync_with_stdio(0);cin.tie(NULL),cout.tie(NULL)
using namespace std;
ll a[3], i, t, dem = 0;
int main (){
	NGUYEN_CHINH_NGHIA;
	FOR(i, 0, 3){
		cin >> a[i];
	}
	cin >> t;
	sort(a,a+3);
	while(a[0] - a[1] < t){
		dem++;
		a[0]--;
	}
	while(a[1] - a[2] < t){
		dem++;
		a[2]++;
	}
	cout << dem << endl;

	return 0;
}


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

using namespace std;

int n, pieces;

int bfs(int * state);
bool same_color(int * state);

int main() {
	while (cin >> n) {
		pieces = n / 2;
		int * s = new int[pieces];
		// vector<int> v;
		// v.assign(pieces, int());
		for (int i = 0; i < pieces; i++)
			cin >> s[i];
		int min_step = bfs(s);
		cout << min_step << endl;
	}
	return 0;
}

int bfs(int * state) {
	if (same_color(state))
		return 0;
	priority_queue<pair<int, int*>, vector<pair<int, int*>>, greater<pair<int, int*> >> pq;
	pq.push(make_pair(0, state));
	while (!pq.empty()) {
		pair<int, int*> p = pq.top();
		pq.pop();
		int* s = p.second;
		int steps = p.first;
		for (int i = 0; i < pieces; i++) {
			int * ns = new int[pieces];
			copy(s, s + pieces, ns);
			if (s[i] - 1 >= 1 && find(s, s + pieces, s[i] - 1) == s + pieces) {
				ns[i] = s[i] - 1;
				if (same_color(ns))
					return steps + 1;
				pq.push(make_pair(steps + 1, ns));
			}
			ns = new int[pieces];
			copy(s, s + pieces, ns);
			if (s[i] + 1 <= n && find(s, s + pieces, s[i] + 1) == s + pieces) {
				ns[i] = s[i] + 1;
				if (same_color(ns))
					return steps + 1;
				pq.push(make_pair(steps + 1, ns));
			}
		}
		delete(s);
	}
}

bool same_color(int * state) {
	for (int i = 1; i < pieces; i++) {
		if (state[i] % 2 != state[0] % 2)
			return false;
	}
	return true;
}


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

using namespace std;

typedef long long ll;

const int MOD = 1e9 + 7;

int n, k;
vector<vector<int>>	vec;
vector<int>	sec;
bool mark[20];
vector<int>	adj[20];

void gen(int rem){
	if (rem == 0){
		vec.push_back(sec);
		return;
	}

	for (int i = 0; i < k; i++){
		sec.push_back(i);
		gen(rem - 1);
		sec.pop_back();
	}
}

int dfs(int v){
	if (mark[v])	return	0;
	mark[v] = 1;
	int ret = 1;
	for (int u:adj[v])
		ret += dfs(u);
	return	ret;
}

ll get(){
	gen(k);
	int cnt = 0;
	for (vector<int>	tt:vec){
		memset(mark, 0, sizeof(mark));
		for (int i = 0; i < k; i++)	adj[i].clear();
		for (int i = 0; i < tt.size(); i++)
			adj[tt[i]].push_back(i);
		if (dfs(0) == k)	cnt++;
	}
	return	cnt;
}

int main(){
	cin >> n >> k;
	ll ans = 1;
	for (int i = 0; i < n - k; i++)
		ans = (ans * (n - k)) % MOD;
	ans = (ans * get()) % MOD;
	cout << ans << endl;
	return 0;
}


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

using namespace std;

long long  a,b,x,x2,y,y2,res1,res2,res,xx,xx2,yy,yy2,k,k2;
int i;

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

	yy=y;
	yy2=y2;
	for(i=1;i<=2*b;i++)
	{
		yy+=1;
		if((yy-x)%(2*b)==0) k=(yy-x)/(2*b);

		yy2+=1;
		if((yy2-x2)%(2*b)==0) k2=(yy2-x2)/(2*b);
	}
	if(k2>k) res1=k2-k;
	else res1=k-k2;

	xx=x;
	xx2=x2;
	for(i=1;i<=2*a;i++)
	{
		xx+=1;
		if((y+xx)%(2*a)==0) k=(xx+y)/(2*a);

		xx2+=1;
		if((y2+xx2)%(2*a)==0) k2=(xx2+y2)/(2*a);
	}

	if(k2>k) res2=k2-k;
	else res2=k-k2;

	res=max(res1,res2);

	cout<<res;

	return 0;
}


#include<iostream>
#include<string.h>
using namespace std;
int main()
{
    ios::sync_with_stdio(false);
    long long cop,org,value;
    int i;
    char RE;
    RE:
    cin>>cop>>org;
    if(cop==0)
        goto RE;
    if(org>cop)
        goto RE;
     value= cop-(org-1);
      if(value%2==0)
        cout<<"Yes";
      else
        cout<<"No";
      return 0;
}


#ifndef LOCAL
#define NDEBUG
#endif
#include<cassert>
#include<iostream>
#include<vector>
#include<algorithm>

#define MODULAR_LESS_EFFICIENT_BUT_EASIER_TO_CODE 0
int const MOD=998244353;
struct modular {
	int val;
	explicit constexpr operator int() const { return val; }
	constexpr modular():val(){}
#if MODULAR_LESS_EFFICIENT_BUT_EASIER_TO_CODE
	constexpr modular(int64_t v):val(int(v%MOD)){
		if(val<0)val+=MOD;
	}
#else
	constexpr modular(int v):val(v){
		assert(0<=v and v<MOD);
	}
#endif

#define COMPAREOP(OP) bool constexpr operator OP(modular b) const { return val OP b.val; }
	COMPAREOP(==) COMPAREOP(!=) COMPAREOP(<) COMPAREOP(>) COMPAREOP(<=) COMPAREOP(>=)
#undef COMPAREOP

	modular operator-() const { return modular(val ? MOD-val : 0); }
	modular constexpr& operator+=(modular m) { if ((val += m.val) >= MOD) val -= MOD; return *this; }
	modular constexpr& operator-=(modular m) { if ((val -= m.val) < 0) val += MOD; return *this; }

	void asm_mul(modular m){
		auto x=(uint64_t)val*m.val;
		unsigned xh = (unsigned) (x >> 32), xl = (unsigned) x, d, mm;
		asm(
			"divl %4; \n\t"
			: "=a" (d), "=d" (mm)
			: "d" (xh), "a" (xl), "r" (MOD)
		);
		val= mm;
	}

	modular constexpr& operator*=(modular m) {
		if(std::is_constant_evaluated()){
			val = int((int64_t)val*m.val%MOD);
		}else{
			asm_mul(m);
		}
		return *this;
	}
	modular constexpr pow(auto p) const {
		modular a=*this;
		modular ans = 1; for (; p; p /= 2, a *= a) if (p&1) ans *= a;
		return ans;
	}
	modular constexpr inv() const {
		int a=val,b=MOD, ax=1,bx=0;
		while(b){
			int q=a/b, t=a%b;
			a=b; b=t;
			t=ax-bx*q; ax=bx; bx=t;
		}
		assert(a==1);
		if(ax<0)ax+=MOD;
		return ax;
	}
	modular constexpr& operator/=(modular m) { return (*this) *= m.inv(); }

#define ARITHBINARYOP(OP) friend modular constexpr operator OP(modular a, modular b) { return a OP##= b; }
	ARITHBINARYOP(+) ARITHBINARYOP(-) ARITHBINARYOP(*) ARITHBINARYOP(/)
#undef ARITHBINARYOP

	friend auto& operator<<(std::ostream& str,modular x){
		return str<<( x.val>MOD/2 ? x.val-MOD : x.val );
	}
};

void process(int* const first,int* const last,int n){
	std::for_each(first,last,[&](int& x){
		x=(int)modular(x).pow(n);
		});
}

int main(){
	std::ios::sync_with_stdio(0);std::cin.tie(0);
	int n;std::cin>>n;

	auto const mul_1pow=[](modular a,int b){ // a * (-1)^b
		if(b&1) a=-a;
		return a;
	};
	auto const mul3=[](modular a){return a+a+a; };

	int i=0;
	modular three_pow_i=1; // - (3^i)

	std::vector<modular> inv(std::max(3,n+1));
	inv[1]=1;
	for(unsigned i=2;i<inv.size();++i) inv[i]=((int64_t)MOD*MOD-inv[MOD%i].val*int64_t(MOD/i))%MOD;
	// for some reason compute inv at the same time as the part below takes more time?...

	std::vector<int> tmp_pow_base(n);
	for(;i<n;
			++i,
			three_pow_i=mul3(three_pow_i)
			){
		tmp_pow_base[i]=int(1-three_pow_i);
	}

	int* const first=tmp_pow_base.data();
	int* const last=tmp_pow_base.data()+n;
	process(first,last,n);

	i=0;
	modular ff=MOD-1; // (n choose i) * (-1)**i
	modular out=0;
	for(;i<n;
			++i,
			ff*=(MOD - (n+1-i))*inv[i]
			){
		out.val=int((out.val+(int64_t)tmp_pow_base[i]*(int)ff)%MOD);
	}

	out=mul3(out);

	modular const three_pow_n_minus_one=modular(3).pow(n-1);
	auto zz = -three_pow_n_minus_one;
	auto const three_pow_n = mul3(three_pow_n_minus_one);
	auto const hh=-three_pow_n;
	out+= ( (zz+1).pow(n)-zz.pow(n) ) * mul_1pow(three_pow_n+three_pow_n, n+1);
	out+= mul_1pow(mul3( (hh+1).pow(n)-hh.pow(n) ), n);

	std::cout<<(int)out<<'\n';
}


#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
    int n,t,z=0,y=0;
    cin>>n>>t;
    int arr[n];
    for( int i=0;i<t;i++)
    {
      cin>>arr[i];

    }
    sort(arr,arr+t);

    for(int i=0;i<=t-n;i++)
    {
        if(i==0)
        {
            z=arr[n-1]-arr[i];
        }
        y=arr[n-1+i]-arr[i];
        if(y<z)
        {
            z=y;
        }
    }
    cout<<z;
}


#include <iostream>
using namespace std;
int main()
{
	int n;
	int m;
	int min = 0;
	int max = 0;

	cin >> n >> m;

	while (n != 0)
	{
		if (n >= m)
		{
			min = n;
			max = n + m - 1;
		}
		if (m > n)
		{
			min = n + (m - n);
			max = n + m - 1;
		}
		cout << min << ' ' << max;
	}
		 if (n == 0)
				cout << "Impossible";

}


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

int pr[100005];
int find(int r)
{
    return (pr[r]==r) ? r:  pr[r]=find(pr[r]);
}
struct mn
{
    int x,y;
};

int main()
{
    LL n;
    LL mx = 0;
    while(cin>>n)
    {
        vector<int>v;
        for(int i=0; i<9; i++)
            v.push_back(i);

        LL p = n + n -1;
        LL s = 9;
        int d=0;
        while(p>=s)
        {
            d++;
            s  = s*10 + 9;
        }
       // cout<<d<<endl;
        vector<LL>x;

        int t=d;
        s = 0;
        while(t--)
        {
            s = s*10 + 9;
        }
        x.push_back(s);
        while(s * 10<=p)
        {
            x.push_back(s);
            s = s*10;
        }
        for(int i=1;i<9;i++)
        {
            LL s = i;
            int t=d;
            while(t--)
            {
                s = s*10 + 9;
            }
           if(s<=p)
            x.push_back(s);
        }
       // cout<<x.size()<<endl;
       LL sum=0;
        for(int i=0;i<x.size();i++)
        {
            LL mn = min(n,x[i]);
            if(mn==x[i])
                sum+=mn/2;
            else
            {
               // cout<<mn<<" "<<x[i]/2<<endl;
              sum += abs(x[i]/2 - mn);
            }
            //cout<<x[i]<<endl;
        }
        cout<<sum<<endl;

    }

}


#include<iostream>
#include<string>
using namespace std;
int main()
{
    int n, m,b=1,arr[100][1000];
    cin >> n >> m;
    for (int i = 0; i <= n; i++)
    {
        for (int f = 0; f <= m; f++)
        {
            arr[i][f] = b;
            b++;
        }
    }
    bool t = true;
    for (int i = 0; i >=0; i++)
    {
        for (int j = i; j < n; j++)
        {
            arr[j][i] = 0;
        }
        for (int j = i; j < m; j++)
        {
            arr[i][j] = 0;
        }
        if (arr[n - 1][m - 1] == 0)
        {
            if ((i+1) % 2 == 0)
            {
                cout << "Malvika" << endl;
            }
            else
                cout << "Akshat" << endl;
            break;
        }
    }

    return 0;
}


#include<iostream>
using namespace std;
int main()
{
	long long n, m, a, b, i, sum1, sum2;
	scanf("%d %d %d %d", &n, &m, &a, &b);
	if(n % m == 0 )
		printf("0\n");
	else
	{
		for(i=1;;i++)
		{
			if ((n+i) % m == 0 )
			{
				sum1 = a * i;
				break;
			}
		}
		for (i=1; (n-i) >= 0; i++)
			if((n-i) % m == 0)
			{
				sum2 = b * i;
				break;
			}
			if (sum1>sum2)
				printf("%d\n",sum2);
			else
				printf("%d\n",sum1);
	}
	return 0;
}


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

int remove_zero(int p)
{
    int t,i=1,x=0;
    while(p)
    {
        t=p%10;
        if(t)
        {
            x=t*i+x;
            i*=10;
        }
        p/=10;
    }
    return x;
}

int b_d(long long n)
{
    int decimalNumber = 0, i = 0, remainder;
    while (n!=0)
    {
        remainder = n%10;
        n /= 10;
        decimalNumber += remainder*pow(2,i);
        ++i;
    }
    return decimalNumber;
}
bool checking(string  s)
{
    int c = 0;
    int n = s.length();

    for (int i = n - 1; i >= 0; i--)
    {
        if (s[i] == '0')
            c++;

        if (c >= 6 and s[i] == '1')
            return true;
    }

    return false;
}

string MaxFreq(string str)
{
    int n = str.size();

    unordered_map<string, int> m;

    for (int i = 0; i < n; i++) {
        string s = "";
        for (int j = i; j < n; j++) {
            s += str[j];
            m[s]++;
        }
    }

    int maxi = 0;

    string s;
    for (auto i = m.begin(); i != m.end(); i++) {
        if (i->second > maxi) {
            maxi = i->second;
            s = i->first;
        }
        else if (i->second == maxi) {
            string ss = i->first;
            if (ss.size() > s.size())
                s = ss;
        }
    }

    return s;
}

int main()
{
   int a,b,c,k;
   int count=0;
   cin>>a>>b>>c;
   k=__gcd(a,b)/a*b;
   for(int i=1;i*k<=c;i++)
   {
       if(k<c)
       {
                  count++;
       }

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


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a[3],x,y,z,k,ans;
int main()
{
	for(ll i=0;i<3;i++)
		cin>>a[i];
	while(true)
	{
		sort(a,a+3);
		x=a[0],y=a[1],z=a[2];
		if(!x)
			swap(x,y);
		if(x+y+z<3)
			break;
		if(z-x<2)
		{
			ans+=(z+x+y)/3;
			break;
		}
		else
		if((x+y)*2<=z)
		{
			ans+=x+y;
			break;
		}
		else
		{
			k=min(x,z-x);
			z-=2*k;
			x-=k;
			ans+=k;
		}
		a[0]=x,a[1]=y,a[2]=z;
	}
	cout<<ans;
}


#include <iostream>
using namespace std;
int a, a1, sum = 0, cont;
int main()
{
   cin >> a;
   a1 = a;
   while (a)
   {
     sum += a % 10;
     a /= 10;
    }
    cont = sum ÷ 4;
    return cout << a1 + cont, 0;
}


#include <iostream>
#include <fstream>
#include <vector>
#include <set>
#include <map>
#include <bitset>
#include <string>
#include <algorithm>
#include <cstring>
#include <cassert>
#include <cmath>
#include <queue>
#include <deque>
#include <numeric>
#include <random>
#define ll long long
#define ld long double
#define null NULL
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()

using namespace std;

template<class iterator> void output(iterator begin, iterator end, ostream& out = cerr) {
	while (begin != end) {
		out << (*begin) << " ";
		begin++;
	}
	out << endl;
}

template<class T> void output(const T &x, ostream &out = cerr) {
	output(all(x), out);
}

template<class T> int chkmin(T &a, const T &b) {
	if (b < a) {
		a = b;
		return 1;
	}
	return 0;
}

template<class T> int chkmax(T &a, const T &b) {
	if (b > a) {
		a = b;
		return 1;
	}
	return 0;
}

void fast_io() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
}

mt19937 rng(time(NULL));

struct hasher {
	int MOD, p = 0;

	hasher(int _MOD) {
		MOD = _MOD;
		while (p < 1000) {
			p = rng() % MOD;
		}
	}

	int n;
	vector<int> deg, h;

	int mul(int a, int b) {
		return (1LL * a * b) % MOD;
	}

	void load(vector<int> v) {
		n = v.size();
		deg.resize(n + 1);
		h.resize(n + 1);
		deg[0] = 1;
		for (int i = 1; i <= n; ++i) {
			deg[i] = mul(deg[i - 1], p);
		}
		for (int i = n - 1; i >= 0; --i) {
			h[i] = (mul(h[i + 1], p) + v[i]) % MOD;
		}
	}

	int get_hash(int l, int r) {
		return (h[l] - mul(h[r + 1], deg[r - l + 1]) + MOD) % MOD;
	}
};

const ll MOD1 = 1e9 + 7;
const ll MOD2 = 998244353;
const int mx = 2e5 + 228;
int n, s[mx], r0[mx], l0[mx], zero_id[mx], zero_pos_by_id[mx];
vector<int> mid_data;
hasher H1(MOD1), H2(MOD2);

pair<int, int> get_hash(int l, int r) {
	return {H1.get_hash(l, r), H2.get_hash(l, r)};
}

void read() {
	cin >> n;
	for (int i = 0; i < n; ++i) {
		char c;
		cin >> c;
		s[i] = c - '0';
	}
}

void gen_lr0() {
	int last_0 = -1;
	for (int i = 0; i < n; ++i) {
		if (s[i] == 0) {
			last_0 = i;
		}
		l0[i] = last_0;
	}
	last_0 = n;
	for (int i = n - 1; i >= 0; --i) {
		if (s[i] == 0) {
			last_0 = i;
		}
		r0[i] = last_0;
	}
	fill(zero_id, zero_id + n, -1);
	int cur_zero = 0;
	for (int i = 0; i < n; ++i) {
		if (s[i] == 0) {
			zero_pos_by_id[cur_zero] = i;
			zero_id[i] = cur_zero++;
		}
	}
	for (int i = 1; i < cur_zero; ++i) {
		mid_data.push_back((zero_pos_by_id[i] - zero_pos_by_id[i - 1] - 1) % 2);
	}
	H1.load(mid_data);
	H2.load(mid_data);
}

struct data {
	int l, r, b1, b2;
};

data get(int l, int r) {
	int left_0 = r0[l], right_0 = l0[r];
	if (left_0 > right_0) {
		return {0, -2, (r - l + 1) % 2, (r - l + 1) % 2};
	} else {
		return {zero_id[left_0], zero_id[right_0] - 1, (left_0 - l) % 2, (r - right_0) % 2};
	}
}

int equal(data a, data b) {
	if (a.b1 != b.b1 || a.b2 != b.b2) {
		return 0;
	}
	if (a.r - a.l != b.r - b.l) {
		return 0;
	}
	if (a.r - a.l == -2 || a.r - a.l == -1) {
		return 1;
	}
	return get_hash(a.l, a.r) == get_hash(b.l, b.r);
}

void process() {
	int q;
	cin >> q;
	for (int i = 0; i < q; ++i) {
		int l1, r1, l2, r2, len;
		cin >> l1 >> l2 >> len;
		l1--;
		l2--;
		r1 = l1 + len - 1;
		r2 = l2 + len - 1;
		data d1 = get(l1, r1);
		data d2 = get(l2, r2);
		int res = equal(d1, d2);
		cout << (res ? "Yes" : "No") << "\n";
	}
}

signed main() {
	fast_io();
	read();
	gen_lr0();
	process();
}


#include <iostream>
#include <string>
#include <cctype>
using namespace std;
int main(){
  string str,str1,st,st1;
  cin>>str>>str1;
  long c=str.length();

  for(int x = 0 ; x < c;x++){
    st[x] = tolower(str[x]);
    st1[x] = tolower(str1[x]);
  }
 int l =0,value;
 while(l<c){
   if(st[l] > st1[l]){
     value = 1;break;
   }else if(st[l] < st1[l]){
     value = -1;break;
   }else{
     value = 0;
   }
   l++;
 }
  cout<<value;
}


#include <stdio.h>
#include <string.h>
#include <queue>
using namespace std;
int main()
{

    int n,m;
    scanf("%d%d\n",&n,&m);
    char a[110];
    bool visited[110]={false};
    int s,e;
    for(int i=0;i<n;i++)
    {

        a[i]=getchar();
        if(a[i]=='G')
        {

            s=i;
        }
        else if(a[i]=='T')
        {

            e=i;
        }
    }
    queue<int> q;
    q.push(s);
    visited[s]=true;
    while(!q.empty())
    {

        int now=q.front();
        q.pop();
        if(now==e)
        {

            printf("YES");
            return 0;
        }
        if(now+m<n&&!visited[now+m]&&a[now+m]!='#')
        {

            q.push(now+m);
        }
        if(now-m>=0&&!visited[now-m]&&a[now-m]!='#')
        {

            q.push(now-m);
        }
    }
    printf("NO");
}


//
//  Created by  CQU_CST_WuErli
//  Copyright (c) 2015 CQU_CST_WuErli. All rights reserved.
//
// #include<bits/stdc++.h>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <algorithm>
#include <sstream>
#define CLR(x) memset(x,0,sizeof(x))
#define OFF(x) memset(x,-1,sizeof(x))
#define MEM(x,a) memset((x),(a),sizeof(x))
#define For_UVa if (kase!=1) cout << endl
#define BUG cout << "I am here" << endl
#define lookln(x) cout << #x << "=" << x << endl
#define SI(a) scanf("%d",&a)
#define SII(a,b) scanf("%d%d",&a,&b)
#define SIII(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define rep(flag,start,end) for(int flag=start;flag<=end;flag++)
#define Rep(flag,start,end) for(int flag=start;flag>=end;flag--)
#define Lson l,mid,rt<<1
#define Rson mid+1,r,rt<<1|1
#define Root 1,n,1
#define BigInteger bign
template <typename T> T gcd(const T& a,const T& b) {return b==0?a:gcd(b,a%b);}
const int MAX_L=2005;// For BigInteger
const int INF_INT=0x3f3f3f3f;
const long long INF_LL=0x7fffffff;
const int MOD=1e9+7;
const double eps=1e-9;
const double pi=acos(-1);
typedef long long  ll;
using namespace std;

int x,y;
int n,d;
int dp[1000][1000];
struct P{
    int x,y;
};
P p[22];

int dfs(int xx,int yy) {
    if (dp[xx][yy]!=-1) return dp[xx][yy];
    if ((xx-200)*(xx-200)+(yy-200)*(yy-200)>=d*d) return 1;
    int &ret=dp[xx][yy];
    rep(i,1,n) {
        if (!dfs(xx+p[i].x,yy+p[i].y)) return ret=1;
    }
    return ret=0;
}

int main(){
#ifdef LOCAL
    freopen("C:\\Users\\john\\Desktop\\in.txt","r",stdin);
//  freopen("C:\\Users\\john\\Desktop\\out.txt","w",stdout);
#endif
    while (SII(x,y)==2) {
        x+=200;
        y+=200;
        SII(n,d);
        rep(i,1,n) {
            cin >> p[i].x >> p[i].y;
        }
        OFF(dp);
//      dp[x][y]=0;
        if (dfs(x,y)) cout << "Anton" << endl;
        else cout << "Dasha" << endl;
    }
    return 0;
}
————————————————
版权声明：本文为CSDN博主「只玩三国的程序猿」的原创文章，遵循CC 4.0 BY-SA版权协议，转载请附上原文出处链接及本声明。
原文链接：https://blog.csdn.net/CQUWEL/java/article/details/50615040


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

#include <bits/stdc++.h>

using namespace std;

int n, x[4], y[4], r[4];

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

int getSign(int k, int i, int j) {
    int q = sqr(x[k] - i) + sqr(y[k] - j) - sqr(r[k]);
    return q == 0 ? 0 : q > 0 ? 1 : -1;
}

vector<int> getSigns(int i, int j) {
    vector<int> res;
    for(int k = 0; k < 3; k++) {
        res.push_back(getSign(k, i, j));
    }
    return res;
}

bool vis[2001][2001];

void dfs(int i, int j, const vector<int>& signs) {
    if(i < 0 || i > 2000 || j < 0 || j > 2000 || vis[i][j] ||
        signs != getSigns(i, j)) return;
    //cerr << i << " " << j << endl;
    vis[i][j] = true;
    dfs(i + 1, j, signs);
    dfs(i - 1, j, signs);
    dfs(i, j + 1, signs);
    dfs(i, j - 1, signs);
}

bool isntAtCircle(int i, int j) {
    for(int k = 0; k < 3; k++) {
        if(getSign(k, i, j) == 0) {
            return false;
        }
    }
    return true;
}

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

    #endif // Fekete

    cin >> n;
    for(int i = 0; i < n; i++) {
        cin >> x[i] >> y[i] >> r[i];
        x[i] += 10;
        y[i] += 10;
        x[i] *= 100;
        y[i] *= 100;
        r[i] *= 100;
    }
    int ans = 0;
    for(int i = 0; i <= 2000; i++){
        for(int j = 0; j <= 2000; j++) {
            if(!vis[i][j] && isntAtCircle(i, j)) {
                ans++;
                //cerr << ans << endl;
                dfs(i, j, getSigns(i, j));
            }
        }
    }

    cout << ans;
}


#include <bits/stdc++.h>

using namespace std;

constexpr int MOD = 1'000'000'007;

int mod_pow(int a, int b, int c) {
    long long x = 1, y = a;
    while (b > 0) {
        if (b % 2 == 1) {
            x = (x * y) % c;
        }
        y = (y * y) % c;
        b /= 2;
    }
    return x % c;
}
int mod_inv(int a) {
    return mod_pow(a, MOD - 2, MOD);
}
int choose(int n, int k, const vector<int> &fac) {
    if (k > n) return 0;
    return 1LL * fac[n] * mod_inv(1LL * fac[k] * fac[n - k] % MOD) % MOD;
}

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

    int n, m;
    cin >> n >> m;
    const int mx = max(n, m);
    vector<int> fac(mx + 1, 1);
    for (int i = 2; i <= mx; ++i) {
        fac[i] = (1LL * fac[i - 1] * i) % MOD;
    }
    vector<int> npow(n, 1), mpow(n, 1);
    for (int i = 1; i < n; ++i) {
        npow[i] = 1LL * npow[i - 1] * n % MOD;
        mpow[i] = 1LL * mpow[i - 1] * m % MOD;
    }

    int res = 0;
    for (int k = 1; k <= n - 1; ++k) {
        //int cur = x;
        //x = 1LL * x * (n - k - 1) % MOD;
        int cur = choose(n - 2, k - 1);
        cur = 1LL * cur * fac[k - 1] % MOD;

        cur = 1LL * cur * (k + 1) % MOD;
        if (n == k + 1) cur = 1LL * cur * mod_inv(n) % MOD;
        else cur = 1LL * cur * npow[n - k - 2] % MOD;

        cur = 1LL * cur * choose(m - 1, k - 1, fac) % MOD;

        cur = 1LL * cur * mpow[n - 1 - k] % MOD;

        res = (res + cur) % MOD;
    }
    cout << res << "\n";

    return 0;
}


#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
const int MAXN = 110000;
const int MOD = 1e9 + 9;
long long dp[MAXN];
int main(){
	int n; scanf("%d", &n);
	dp[0] = 1;
	long long mulv = 2, ans = 6;
	for(int i = 1; i <= n / 2 - 2; i++)
		mulv *= 2, mulv %= MOD;
		dp[i] = dp[i - 1] + mulv, dp[i] %= MOD;

	for(int i = 3; i <= n / 2; i++){
		mulv = 1;
		for(int j = 1; j <= i - 2; j++){
			mulv *= dp[j];
			mulv %= MOD;
		}
		ans += 4 * mulv;
		ans %= MOD;
	}
	ans = ans * ans % MOD + 1;
	ans *= 2;
	if(n != 2) printf("%lld", ans % MOD);
	else printf("10\n");
	return 0;
}


#include<iostream>

using namespace std;

int main(){
	int a,b,k,count=0,x,c;
	cin>>a>>b;
	if(a==b)
		cout<<"infinity"<<endl;
	else if(a%b==0 || b>a)
		cout<<0<<endl;
	else{
		c = a-b ;
		k = 1;
		while( c/k > b ){
			if(c%k==0)
				count++;
			k++;
		}
		cout<<count<<endl;
	}

	return 0;
}


#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <map>
#include <set>
#include <deque>

using namespace std;

typedef long long ll;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll n, ms = 0;
    cin >> n;
    string a;
    cin >> a;
    map<int, int> m;
    for (ll i = 0; i < n; ++i){
        m[i] = 1;
    }
    for (ll i = 0; i < (a.size() + 1) / 2; ++i){
        if (a[i] == a[a.size() - i - 1] && a[i] != '?'){
            n -= m[a[i] - 'a'];
            m[a[i] - 'a'] = 0;
        }
        else{
            if (a[i] != a[a.size() - i - 1] && (a[i] == '?' || a[a.size() - i - 1] == '?')){
                if (a[i] == '?')
                    a[i] = a[a.size() - i - 1];
                else
                    a[a.size() - i - 1] = a[i];
                n -= m[a[i] - 'a'];
                m[a[i] - 'a'] = 0;
            }
            else{
                if(a[i] != a[a.size() - i - 1]){
                    cout << "IMPOSSIBLE";
                    return 0;
                }
                else{
                    ms += 1;
                }
            }
        }
    }
    deque<int> va;
    for (auto i : m){
        if (i.second == 1){
            va.push_back(i.first);
            ms--;
        }
    }
    while (ms != 0){
        va.push_front(0);
        ms--;
    }
    for (ll i = 0; i < (a.size() + 1) / 2; ++i){
        if (a[i] == a[a.size() - i - 1] && a[i] == '?'){
            char ch(va.front() + 'a');
            a[i] = a[a.size() - i - 1] = ch;
            va.pop_front();
        }
    }
    if (va.size() != 0)
        cout << "IMPOSSIBLE";
    else
        cout << a;
}


#include<bits/stdc++.h>

using namespace std;

int n;
vector<int> ss;

int main(){
    cin >> n;
    bool gg = false;
    for(int i = 0; i < n; i++){
        int aux = 0;
        cin >> aux;
        if(aux == 0 && !gg) continue;
        if(aux == 1) gg = true;

        ss.push_back(aux);
    }

    for(int i = ss.size() - 1; ss[i] != 1; i--){
        ss[i] = -1;
    }

    int ans = 0;
    for(int i = 0; i < ss.size(); i++){
        if(ss[i] == -1) continue;
        if(ss[i] == 1){
            ans++;
        }else if(i+1 < ss.size() && ss[i+1] == 1){
            ans++;
            //cout << "entre";
        }else{
            for(int j = 0; j+i < ss.size() && ss[i+j] != 1; j++){
                ss[i+j] = -1;
            }
        }
        //cout << ss[i] << " ";
    }
    //cout << endl;
    cout << ans << endl;

    return 0;
}


#include<iostream>
#include<cstdio>
#define MN 7900
#define mod 1000000007
using namespace std;
inline 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;
}
const int md = (int) 1e9 + 7;

inline void add(int &a, int b) {
  a += b;
  if (a >= md) a -= md;
}

inline void sub(int &a, int b) {
  a -= b;
  if (a < 0) a += md;
}

inline int mul(int a, int b) {
  return (int) ((long long) a * b % md);
}

inline int power(int a, long long b) { // a^b mod md
  int res = 1;
  while (b > 0) {
    if (b & 1) {
      res = mul(res, a);
    }
    a = mul(a, a);
    b >>= 1;
  }
  return res;
}

inline int inv(int a) { // multiplicative inverse of a mod md
  a %= md;
  if (a < 0) a += md;
  int b = md, u = 0, v = 1;
  while (a) {
    int t = b / a;
    b -= t * a; swap(a, b);
    u -= t * v; swap(u, v);
  }
  assert(b == 1);
  if (u < 0) u += md;
  return u;
}

inline int pow(int x,int k)
{
	int sum=1;
	for(;k;k>>=1,x=1LL*x*x%mod) if(k&1) sum=1LL*sum*x%mod;
	return sum;
}
int a[MN+5][MN+5],res[MN+5];
int R,a1,a2,a3,a4,cnt,id[105][105],ans;
inline int&ID(int x,int y){return id[x+R+1][y+R+1];}
void Gauss()
{
	for(int i=1;i<=cnt;++i)
	{
		for(int j=i;j<=cnt&&j<=i+100;++j) if(a[j][i])
		{
			if(j!=i)
			{
				for(int k=i;k<=cnt&&k<=i+100;++k) swap(a[i][k],a[j][k]);
				swap(a[i][cnt+1],a[j][cnt+1]);
			}
			break;
		}
		if(!a[i][i])continue;
		int Inv=inv(a[i][i]);
		for(int j=i+1;j<=cnt&&j<=i+100;++j) if(a[j][i])
		{
			int t = mul(a[j][i],Inv);
			for(int k=i;k<=cnt&&k<=i+100;++k)
				sub(a[j][k],mul(a[i][k],t));
			sub(a[j][cnt+1],mul(a[i][cnt+1],t));
		}
	}
	for(int i=cnt;i;--i)
	{
		int t=a[i][cnt+1];
		for(int j=i+1;j<=cnt&&j<=i+100;++j) t=(t-1LL*a[i][j]*res[j]%mod+mod)%mod;
		res[i]=1LL*t*pow(a[i][i],mod-2)%mod;
		//ans=(ans+res[i])%mod;
	}
	ans = res[ID(0,0)];
}
int main()
{
	R=read();a1=read();a2=read();a3=read();a4=read();int inv=pow(a1+a2+a3+a4,mod-2);
	for(int i=-R;i<=R;++i)for(int j=-R;j<=R;++j) if(i*i+j*j<=R*R) ID(i,j)=++cnt,a[cnt][cnt]=1;
	a[ID(0,0)][cnt+1]=1;
	for(int i=-R;i<=R;++i) for(int j=-R;j<=R;++j) if(i*i+j*j<=R*R)
	{
		if(ID(i-1,j)) a[ID(i-1,j)][ID(i,j)]=mod-1LL*a1*inv%mod;
		if(ID(i,j-1)) a[ID(i,j-1)][ID(i,j)]=mod-1LL*a2*inv%mod;
		if(ID(i+1,j)) a[ID(i+1,j)][ID(i,j)]=mod-1LL*a3*inv%mod;
		if(ID(i,j+1)) a[ID(i,j+1)][ID(i,j)]=mod-1LL*a4*inv%mod;
		a[ID(i,j)][cnt+1] = 1;
	}
	Gauss();cout<<ans;
	return 0;
}


#include <iostream>
using namespace std;

int main()
{
	int a, b, y = 1;
	cin >> a >> b ;
	while (true)
	{
		if (a * 3 > b * 2)
		{
			break;
		}

		y++;
	}
	cout << y;

	return 0;
}


#include <bits/stdc++.h>

using namespace std;
using ll = long long;

const int MOD = 998244353;

inline int add(int a, int b) {
	a += b;
	return a - MOD * (a >= MOD);
}

inline int mult(int a, int b) {
	return (ll) a * b % MOD;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);

	int n, k;
	cin >> n >> k;
	vector<int> a(n);
	for (auto &el : a) {
		cin >> el;
	}

	for (int i = 0; i < n; i++) {
		a.push_back(a[i]);
	}
	a.insert(a.begin(), 0);

	vector<vector<int>> dp(n + 1, vector<int>(2 * n + 1, 0));
	dp[0][n] = 1;

	for (int i = 1; i <= n; i++) {
		if (a[i] != a[i + 1]) {
			for (int j = 0; j <= 2 * n; j++) {
				if (j) {
					dp[i][j] = add(dp[i][j], dp[i - 1][j - 1]);
				}
				if (j != 2 * n) {
					dp[i][j] = add(dp[i][j], dp[i - 1][j + 1]);
				}
			}
		}

		for (int j = 0; j <= 2 * n; j++) {
			dp[i][j] = add(dp[i][j], mult(dp[i - 1][j], max(0, k - 2 * (a[i] != a[i + 1]))));
		}
	}

	int ans = 0;
	for (int i = n + 1; i <= 2 * n; i++) {
		ans = add(ans, dp[n][i]);
	}

	cout << ans << '\n';
}


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

int min2(int a, int b)
{
	if (a <= b) return a;
	return b;
}
int min3(int a, int b, int c)
{
	if (min2(a, b) > c) return c;
	return min2(a, b);
}

int main()
{
	int n = 0;
	int a = 0;
	int b = 0;
	int c = 0;
	int result = 0;

	cin >> n >> a >> b >> c;

	if (n % 4 == 0)
	{
		result = 0;
	}
	if (n % 4 == 1)
	{
		int variant1, variant2, variant3;
		variant1 = c;
		variant2 = a + b;
		variant3 = a * 3;
		result = min3(variant1, variant2, variant3);
	};
	if (n % 4 == 2)
	{
		result = min3((a + a), (b), (c + c));
	};
	if (n % 4 == 3)
	{
		result = min3((a), (c + b), (3*c));
	};

	cout << result;

	return result;
};


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

vector<ll> v;

int main(){
    ll a, b, f, k; cin >> a >> b >> f >> k;

    v.push_back(f);

    while(k > 0){
        if(k == 1)
            v.push_back((a-f));
        else
            v.push_back((a-f)*2);
        k--;
        if(k == 0) break;

        if(k == 1)
            v.push_back(f);
        else
            v.push_back(2*f);
        k--;
    }

    if(max((a-f)*2, 2*f) > b){
        cout << -1 << endl;
        return -1;
    }

    int n = v.size();

    ll res = 0, pos = 0;
    while(pos < n){
        int sum = 0;
        while(pos < n && v[pos]+sum <= b)
            sum += v[pos++];
        if(pos != n)
            res++;

    }
    cout << res << endl;
    return 0;
}


#ifdef NALP_PROJECT
#pragma hdrstop
#else
#define _SECURE_SCL 0
#endif

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

#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <cctype>
#include <cmath>
#include <algorithm>
#include <utility>
#include <cassert>

#include <set>
#include <map>
#include <vector>
#include <string>
#include <queue>
#include <bitset>
#include <memory.h>

#include <iostream>
#include <fstream>
#include <sstream>

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 y1 YYY1
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()

#ifdef _WIN32
	#define LLD "%I64d"
#else
	#define LLD "%lld"
#endif

template<typename T> inline T Abs(T x) { return (x >= 0) ? x : -x; }
template<typename T> inline T sqr(T x) { return x * x; }
template<typename T> inline string toStr(T x) { stringstream st; st << x; string s; st >> s; return s; }
template<typename T> inline int bit(T mask, int b) { return (b >= 0 && (mask & (T(1) << b)) != 0) ? 1 : 0; }

inline int nextInt() { int x; if (scanf("%d", &x) != 1) throw; return x; }
inline int64 nextInt64() { int64 x; if (scanf(LLD, &x) != 1) throw; return x; }
inline double nextDouble() { double x; if (scanf("%lf", &x) != 1) throw; return x; }

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

const int64 MOD = INF + 9;
const int MAXN = 11;

int64 d[MAXN][1 << MAXN], D[MAXN][1 << MAXN][1 << MAXN];
vector<pair<int, int> > a;
bool used[MAXN];

void mul(int n, int64 a[1 << MAXN][1 << MAXN], int64 b[1 << MAXN][1 << MAXN]) {
	static int64 res[1 << MAXN][1 << MAXN];
	memset(res, 0, sizeof res);
	forn(i, n) {
		forn(j, n) {
			forn(k, n) {
				res[i][j] = (res[i][j] + a[i][k] * b[k][j]) % MOD;
			}
		}
	}

	forn(i, n) {
		forn(j, n) {
			a[i][j] = res[i][j];
		}
	}
}

void binPow(int64 a[1 << MAXN][1 << MAXN], int n, int64 b) {
	static int64 res[1 << MAXN][1 << MAXN];
	memset(res, 0, sizeof res);
	forn(i, n) {
		res[i][i] = 1;
	}

	while (b > 0) {
		if (b % 2 == 0) {
			mul(n, a, a);
			b /= 2;
		} else {
			mul(n, res, a);
			b--;
		}
	}

	forn(i, n) {
		forn(j, n) {
			a[i][j] = res[i][j];
		}
	}
}

void calcMoves(int n, int64 a[1 << MAXN][1 << MAXN], bool first) {
	forn(deprLeft, 1 << n) {
		forn(realLeft, 1 << n) {
			if ((deprLeft & realLeft) != 0) {
				continue;
			}

			if (first && realLeft + 1 != 1 << n) {
				continue;
			}

			forn(mid, 1 << (n - 1)) {
				int realMid = 1 + (mid << 1) + (1 << n);
				int deprRight = 0;
				forn(i, n) {
					if (bit(realMid, i) && bit(realMid, i + 1) && bit(realLeft, i)) {
						deprRight += 1 << i;
					}
				}

				a[deprLeft][deprRight]++;
			}
		}
	}
}

int64 move(int h, int w, int start, int finish, int pos) {
	if (!used[pos]) {
		used[pos] = true;
		static int64 a[1 << MAXN][1 << MAXN];

		memset(a, 0, sizeof a);
		calcMoves(h, a, pos == 0);
		binPow(a, 1 << h, w);

		forn(i, 1 << h) {
			forn(j, 1 << h) {
				D[pos][i][j] = a[i][j];
			}
		}
	}

	return D[pos][start][finish];
}

int64 get(int v, int mask) {
	if (v == int(a.size())) return (mask == 0) ? 1 : 0;
	if (mask >= (1 << a[v].first)) return 0;

	int64 &ans = d[v][mask];
	if (ans != -1) return ans;

	ans = 0;
	int h = a[v].first, w = a[v].second;
	forn(nmask, 1 << h) {
		ans = (ans + move(h, w, mask, nmask, v) * get(v + 1, nmask)) % MOD;
	}

	return ans;
}

int main() {
    cout.setf(ios::fixed);
    cout.precision(10);
	double _startTime = clock();
#ifdef NALP_PROJECT
	freopen("input.txt", "rt", stdin);
//	freopen("output.txt", "wt", stdout);
#else
#endif

	forn(i, 7) {
		int w = nextInt();
		if (w != 0) {
			a.pb(mp(i + 1, w));
		}
	}
	reverse(all(a));
	if (a[0].first > 1) {
		a.insert(a.begin(), mp(a[0].first, 1));
		a[1].second--;
	}

	memset(d, 255, sizeof d);
	cout << get(0, 0) << endl;

	cerr << "Elapsed " << (clock() - _startTime) / CLOCKS_PER_SEC << " s" << endl;
	return 0;
}


.#include<bits/stdc++.h>
using namespace std;
const int N=1e5+7;
int n,k,p,cnt[N]; long long ifac[N];
inline void solve(int l,int r,int t){
	if(t==1||l==r) {cnt[r-l+1]++; return;}
	int d=(l+r)>>1; solve(l,d,t-1),solve(d+1,r,t-1);
}
inline long long getans(int a,int b){
	long long sum=(p+1)/2,ans=sum*a%p*b%p;
	for(int i=1;i<=a;i++) ans=(ans-ifac[i+b]+ifac[i])%p;
	return (ans+p)%p;
}
int main(){
	cin>>n>>k>>p,ifac[0]=ifac[1]=1;
	for(int i=2;i<=n;i++) ifac[i]=ifac[p%i]*(p-p/i)%p;
	for(int i=1;i<=n;i++) ifac[i]=(ifac[i]+ifac[i-1])%p;
	solve(1,n,k); int a=0,b=0;
	for(int i=1;i<=n;i++) if(cnt[i]&&!a) a=i; else if(cnt[i]) b=i;
	long long s=getans(a,a)*((1ll*cnt[a]*(cnt[a]-1)/2)%p)%p;
	s=(s+getans(b,b)*((1ll*cnt[b]*(cnt[b]-1)/2)%p))%p;
	s=(s+getans(a,b)*cnt[a]%p*cnt[b]%p)%p;
	s=(s+(1ll*a*(a-1)/2*cnt[a]%p+1ll*b*(b-1)/2*cnt[b]%p)%p*((p+1)/2))%p;
	cout<<s<<endl;
	return 0;
}


#include <cstdio>
#include <algorithm>

using namespace std;

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

template <typename _type>
inline void chkmin(_type &x, _type y){
	if (x>y) x=y;
}

#define N 100005

int f[2][N],cur=0,pre=1,q[N];

int main(){
	int n=read(),k=read();
	f[0][0]=0;
	for (int i=1;i<=n;i++)
		f[0][i]=n;
	for (int j=1;j<=k;j++){
		int lt=read(),rt=read();
		cur^=1,pre^=1;
		for (int i=0;i<=n;i++)
			f[cur][i]=f[pre][i];
		for (int i=rt,l=1,r=0;i>=0;i--){
			if (l<=r&&q[l]<lt-i) l++;
			while (l<=r&&f[pre][rt-i]<=f[pre][q[r]]) r--;
			q[++r]=rt-i; chkmin(f[cur][i],f[pre][q[l]]+1);
		}
		for (int i=0,l=1,r=0;i<=n&&i<=rt;i++){
			if (l<=r&&q[l]<i-(rt-lt)) l++;
			while (l<=r&&f[pre][i]<=f[pre][q[r]]) r--;
			q[++r]=i; chkmin(f[cur][i],f[pre][q[l]]+2);
		}
	}
	if (f[cur][n]<n)
		printf("Full\n%d\n",f[cur][n]);
	else puts("Hungry");
	return 0;
}


#include <stdio.h>
#include <stdlib.h>
#include<iostream>
#include <vector>
#include <map>
#include <list>
#include <queue>
#include <string.h>
#include <string>
#include <limits.h>
#include <algorithm>
#include <set>
#include <ctime>
#include <cmath>
using namespace std;
#define SZ(x) ((int)(x).size())
#define rep(i,a,n) for (int i=a; i<(int)n; i++)
#define per(i,n,a) for (int i=n; i>=a; i--)
#define hk push_back
#define pk pop_back
#define mp make_pair
#define PI 3.141592653589793
#define clr(a) memset(a, 0, sizeof(a))
#define clr1(a) memset(a, -1, sizeof(a))
typedef vector<int> VI;
typedef vector< pair<int, int> > VIP;
typedef vector< pair<int, pair<int, double> > > VIPP;
typedef vector<string> VS;
typedef vector <double> VD;
typedef vector <bool> VB;
typedef long long ll;
#define MAX_V 1000
const ll mod = 1000000007;
ll powmod(ll a, ll b) {
    ll res = 1; a %= mod; for (; b; b >>= 1){ if (b & 1)res = res*a%mod; a = a*a%mod; }return res;
}

typedef unsigned long long ull;
ull n, k, l, m;

int main()
{
    cin >> n >> k >> l >> m;

    vector<ull> s;
    ull initS = (4 % m);
    s.push_back(initS);
    ull pow = initS;
    for (ull i = 3; i <= n; i++) {
        pow *= 2;
        pow %= m;
        if (pow == initS) {
            break;
        }
        s.push_back(pow);
    }

    ll s0, s1;
    if (n == 2) { s0 = 1; s1 = 3; }
    else if (n == 3) { s0 = 3; s1 = 5; }
    else {
        ull sz = s.size();
        ull prepre = 1, pre = 3;
        for (ull i = 4; i <= n; i++) {
            ull curr = prepre + pre + s[(i - 4) % sz];
            curr %= m;
            prepre = pre; pre = curr;
            if (prepre == 1 && pre == 3) {
                i += (ull)((n - i) / (i - 4)) * (i - 4);
            }
        }
        s0 = pre;
        s1 = (s[(n - 2) % sz] - s0 + m) % m;
//      s1 = (1ULL << n) - s0;
    }

    ull ret = 1;
    for (ull i = 0; i < l; i++) {

        if (k & (1ULL << i)) {
            ret *= s0;
        }
        else ret *= s1;
        ret %= m;
    }
    if (l < 64 && k >(1ULL << l) - 1) ret *= 0;

    cout << ret << endl;
}


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

int d[10];
long long c(int x, int y){
	if (y == 0)
		return 1;
	if (x == 1)
		return y;
	if (x == y)
		return 1;
	long long ab = c(x - 1, y - 1) + c(x, y-1);
	return ab;
}

int main(){
	int n, k;
	cin >> n >> k;
	long long ans = 1;
	d[1] = 0;
	d[2] = 1;
	d[3] = 2;
	d[4] = 9;
	for (int i = 1; i <= k; i++){
 		ans += c(n-i, n)*d[i];
		//cout << "*" << c(n - i, n)<< endl;
	}
	cout << ans << endl;
	//system("pause");
	return 0;
}


#include <iostream>
#include <vector>
//#include <algorithm>
using namespace std;
long long int a, b, c;
vector<char> in1;
vector<char> in2;
/*void print(char k)
{
	cout << k << ' ';
}*/
int main()
{
	cin >> a >> b >> c;
	for (int k = 0; k < a + c; k++)
		in1.push_back('a');
	for (int k = 0; k < b + c; k++)
		in2.push_back('b');
	if (in1.size() == in2.size())
		cout << in1.size() + in2.size();
	else
	{
		if (in1.size() > in2.size())
			cout << in2.size() * 2 + 1;
		else
		{
			cout << in1.size() * 2 + 1;
		}
	}
	/*cout << endl;
	for_each(in1.begin(), in1.end(), print);
	cout << endl;
	for_each(in2.begin(), in2.end(), print);
	cout << endl;*/

	return 0;
}


#include<cstdio>
#include<cmath>
const double eps=1e-8;
double Xv,Yv,Xp,Yp,Xw1,Yw1,Xw2,Yw2,Xm1,Ym1,Xm2,Ym2,Xc,Yc,Xg,Yg;
double Am,Bm,Cm,Av,Bv,Cv;
int Xot(double X1,double Y1,double X2,double Y2)
{
    double V=X1*Y2-X2*Y1;
    if(fabs(V)<eps) return 0;
    if(V<0) return -1;
    if(V>0) return 1;
}
int Cross(double X1,double Y1,double X2,double Y2,double X3,double Y3,double X4,double Y4)
{
	int v=Xot(X2-X1,Y2-Y1,X4-X3,Y4-Y3);
	if(v==0) return 1;
    int V1=Xot(X3-X1,Y3-Y1,X2-X1,Y2-Y1)*Xot(X4-X1,Y4-Y1,X2-X1,Y2-Y1);
    int V2=Xot(X1-X3,Y1-Y3,X4-X3,Y4-Y3)*Xot(X2-X3,Y2-Y3,X4-X3,Y4-Y3);
    if(V1>0||V2>0) return 1;
    if(V1<0&&V2<0) return -1;
    return 0;
}
void Node()
{
    double p;
    if(fabs(Am)<eps){Xc=Xv,Yc=Ym1;return;}
    if(fabs(Bm)<eps){Xc=Xm1,Yc=Yv;return;}
    Av=-Bm,Bv=Am,Cv=Xv*Av+Yv*Bv;
    p=Am/Av;
    Av*=p,Bv*=p,Cv*=p;
    if(fabs(Bv-Bm)>eps)
    {
    	Yc=(Cv-Cm)/(Bv-Bm);
    	Xc=(Cv-Bv*Yc)/Av;
	}
	else
	{
		Xc=(Cv-Cm)/(Av-Am);
    	Yc=(Cv-Av*Xc)/Bv;
	}
}
void Get()
{
    double p;
    Av=Yg-Yp,Bv=Xp-Xg,Cv=Xg*Av+Yg*Bv;
    if(fabs(Am)<eps)
	{
		Yc=Ym1;
		Xc=(Cv-Bv*Yc)/Av;
		return;
	}
    if(fabs(Bm)<eps)
	{
		Xc=Xm1;
		Yc=(Cv-Av*Xc)/Bv;
		return;
	}
	if(fabs(Av)<eps)
	{
		Yc=Yg;
		Xc=(Cm-Bm*Yc)/Am;
		return;
	}
	if(fabs(Bv)<eps)
	{
		Xc=Xg;
		Yc=(Cm-Am*Xc)/Bm;
		return;
	}
    p=Am/Av;
    Av*=p,Bv*=p,Cv*=p;
    if(fabs(Bv-Bm)>eps)
    {
    	Yc=(Cv-Cm)/(Bv-Bm);
    	Xc=(Cv-Bv*Yc)/Av;
	}
	else
	{
		Xc=(Cv-Cm)/(Av-Am);
    	Yc=(Cv-Av*Xc)/Bv;
	}
}
int main()
{
    scanf("%lf%lf",&Xv,&Yv);
    scanf("%lf%lf",&Xp,&Yp);
    scanf("%lf%lf%lf%lf",&Xw1,&Yw1,&Xw2,&Yw2);
    scanf("%lf%lf%lf%lf",&Xm1,&Ym1,&Xm2,&Ym2);
    Am=Ym1-Ym2,Bm=Xm2-Xm1,Cm=Xm1*Am+Ym1*Bm;
    if(Cross(Xv,Yv,Xp,Yp,Xw1,Yw1,Xw2,Yw2)>0&&Cross(Xv,Yv,Xp,Yp,Xm1,Ym1,Xm2,Ym2)>0)
    {
        printf("YES\n");
        return 0;
    }
    Node(),Xg=2*Xc-Xv,Yg=2*Yc-Yv;
    if(Cross(Xg,Yg,Xp,Yp,Xm1,Ym1,Xm2,Ym2)<=0)
    {
		Get();
		if(Cross(Xv,Yv,Xc,Yc,Xw1,Yw1,Xw2,Yw2)>0&&Cross(Xc,Yc,Xp,Yp,Xw1,Yw1,Xw2,Yw2)>0)
		{
        	printf("YES\n");
        	return 0;
    	}
	}
    printf("NO\n");
    return 0;
}


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

int main() {

int n,tmp;
vector<int> nums;
cin>>n;
int counter = 0;
string A ="chest";
string B = "biceps";
string C ="back";
int a =0, b = 0, c=0;
int MAx = -1;
for(int i =0; i < n; i++)
{
cin>>tmp;
counter++;

	if(counter == 1 )
	{a +=tmp;}
	else if (counter == 2)
	{b +=tmp;}
	else if(counter == 3)
	{c +=tmp;}

if(counter>3)
	counter = 0;

}
if(a>=b && a>=c)
	cout<<A<<endl;
else if(b>=a && b>=c)
	cout<<B<<endl;
else
	cout<<C<<endl;

	return 0;
}


#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	int a[3],d,cnt=0;
	cin>>a[0]>>a[1]>>a[2]>>d;
	sort(a,a+3);
	int l = a[1]-a[0];
	int r = a[2]-a[1];
	while(l<d||r<d)
	{
		if(l<3)
		{
			l++;
		}
		else if(r<3)
		{
			r++;
		}
		cnt++;
	}
	cout<<cnt;
	return 0;
}


#include<iostream>
#include<fstream>
#include<algorithm>
#include<cmath>
using namespace std;
const int INF = 1000000010;
long long n, m, c, i, a[100000001], res = 0, mx = -INF;
int main()
{
    cin>>n>>m;
    for(i = 1; i <= n; i++){
                  for(c = 1; c <= n; c++){
                    if(abs(c - i) < abs(c - m))
                    a[i]++;
            }
    }
    for(i = 1; i <= n; i++)
    if(a[i] > mx){
            mx = a[i];
            res = i;
    }
    cout<<res;
    //system("pause");
    return 0;
}


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

int main() {
    int a, b, m;
    int r0, r1;
    cin >> a >> b >> m >> r0;
    vector< vector<unsigned int> > arr;
    arr.resize(m);
    for (int i = 0; i < m; ++i) {
        arr[i] = vector<unsigned int>(m,0);
    }
    long long i = 1;
    while (true) {
        r1 = (a * r0 + b) % m;
        if (!arr[r0][r1]) {
            arr[r0][r1] = i;
            ++i;
            r0 = r1;
        }
        else {
            cout << i - arr[r0][r1];
            return 0;
        }
    }
}


#include <iostream>
#include <vector>
#include <cstdlib>
using namespace std;
vector <int> mrSequence;

int main(int argc, char** argv) {
    int mrA; int mrB; int mrsM; int mrR0;
    int mrResult;
    int mrSequenceIterator;
    cin >> mrA; cin >> mrB; cin >> mrsM; cin >> mrR0;
    mrSequence.push_back(mrR0);
    for (mrSequenceIterator = 1; 1 == 1; mrSequenceIterator++) {
        mrSequence.push_back((mrA * mrSequence[mrSequenceIterator-1] + mrB) % mrsM);
        if (mrSequenceIterator > 10) {
            if (mrSequence[mrSequenceIterator] == mrSequence[mrSequenceIterator-1]) {
                cout << '1';
                break;
            };
            if (mrSequence[mrSequenceIterator] == mrSequence[mrSequenceIterator-2]) {
                cout << '2';
                break;
            };
            if (mrSequence[mrSequenceIterator] == mrSequence[mrSequenceIterator-3]) {
                cout << '3';
                break;
            };
            if (mrSequence[mrSequenceIterator] == mrSequence[mrSequenceIterator-4]) {
                cout << '4';
                break;
            };
            if (mrSequence[mrSequenceIterator] == mrSequence[mrSequenceIterator-5]) {
                cout << '5';
                break;
            };
            if (mrSequence[mrSequenceIterator] == mrSequence[mrSequenceIterator-6]) {
                cout << '6';
                break;
            };
            if (mrSequence[mrSequenceIterator] == mrSequence[mrSequenceIterator-7]) {
                cout << '7';
                break;
            };
            if (mrSequence[mrSequenceIterator] == mrSequence[mrSequenceIterator-8]) {
                cout << '8';
                break;
            };
            if (mrSequence[mrSequenceIterator] == mrSequence[mrSequenceIterator-9]) {
                cout << '9';
                break;
            };
            if (mrSequence[mrSequenceIterator] == mrSequence[mrSequenceIterator-10]) {
                cout << '10';
                break;
            };
        };
    };
    return 0;
};


#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int n;
 cin>>n;
    if(n%2!=0)
    {
        long long int z=n/2;
        cout<<n-z;
    }
    else
    cout<<n/2;
}


#include<bits/stdc++.h>

using namespace std;

#define N 200005

int n, l[N], r[N], cnt = 0;

map <int, int> used;

struct seg
{
	int l, r, coll, colr, cnt, tag;
}tr[N << 8];

struct SEG
{
	void build(int rt, int l, int r)
	{
		tr[rt].l = l, tr[rt].r = r;
		if(l == r)
		{
			return;
		}
		int mid = l + r >> 1;
		build(rt << 1, l, mid);
		build(rt << 1 | 1, mid + 1, r);
	}

	void Pushdown(int rt)
	{
		if(tr[rt].tag)
		{
			tr[rt << 1].tag = tr[rt << 1 | 1].tag = 1;
			tr[rt << 1].cnt = tr[rt << 1 | 1].cnt = 1;
			tr[rt << 1].coll = tr[rt << 1].colr = 1;
			tr[rt << 1 | 1].coll = tr[rt << 1 | 1].colr = 1;
		}
	}

	void Pushup(int rt)
	{
		tr[rt].cnt = tr[rt << 1].cnt + tr[rt << 1 | 1].cnt;
		tr[rt].coll = tr[rt << 1].coll, tr[rt].colr = tr[rt << 1 | 1].colr;
		if(tr[rt << 1].colr == 1 && tr[rt << 1 | 1].coll == 1) tr[rt].cnt--;
	}

	void update(int rt, int x, int y)
	{
		Pushdown(rt);
		int l = tr[rt].l, r = tr[rt].r, mid = l + r >> 1;
		// cout << l << ' ' << r << ' ' << x << ' ' << y << endl;
		if(l == x && r == y)
		{
			tr[rt].cnt = 1, tr[rt].tag = 1, tr[rt].coll = 1, tr[rt].colr = 1;
			return;
		}
		if(y <= mid) update(rt << 1, x, y);
		else if(x > mid) update(rt << 1 | 1, x, y);
		else update(rt << 1, x, mid), update(rt << 1 | 1, mid + 1, y);
		Pushup(rt);
	}
}tree;

int main()
{
	// freopen("color.in","r",stdin);
	// freopen("color.out","w",stdout);
	scanf("%d", &n);
	int maxn = 0;
	for(int i = 1; i <= n; i++)
	{
		scanf("%d%d", &l[i], &r[i]);
		r[i]--;
		maxn = max(maxn, r[i] + 1);
		if(used[l[i]] == 0)
		{
			used[l[i]] = ++cnt;
		}
		if(used[r[i]] == 0)
		{
			used[r[i]] = ++cnt;
		}
		if(used[r[i] + 1] == 0)
		{
			used[r[i] + 1] = ++cnt;
		}
	}

	tree.build(1, 1, maxn);
	for(int i = 1; i <= n; i++)
	{
		tree.update(1, l[i], r[i]);
		cout << tr[1].cnt << endl;
	}
	return 0;
}


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

using namespace std;

map<char,bool> used;

int main(){
//        freopen("input.txt","r",stdin);
//	freopen("output.txt","w",stdout);

	int k;
	string s;

	cin>>k>>s;

	vector<int> qp;

	int ost=k;

	for(int i=0;i<s.length();i++){

		if(s[i]=='?'){

			if(s[s.length()-1-i]!='?')
				s[i]=s[s.length()-i-1];
			else qp.push_back(i);

		}

		else if(s[s.length()-i-1]=='?')
			s[s.length()-i-1]=s[i];

		if(s[i]!=s[s.length()-1-i]){cout<<"IMPOSSIBLE";return 0;}

		if(s[i]!='?' && !used[s[i]]){used[s[i]]=true;ost--;}

	}

	if(s[s.length()/2]=='?' && s.length()%2==1)qp.push_back(s.length()/2);

	if(qp.size()<ost){cout<<"IMPOSSIBLE";return 0;}

	while(ost>0){

		int nf=qp.back();

		if(s[nf]!='?')continue;

		char found;

		for(int i=k-1;i>=0;i--)
			if(!used['a'+i]){found='a'+i;break;}

           	s[nf]=found;
           	s[s.length()-1-nf]=found;

		used[found]=true;

		qp.pop_back();

		ost--;

	}

	while(!qp.empty()){

		if(s[qp.back()]!='?'){qp.pop_back();continue;}

		s[qp.back()]='a';

		s[s.length()-qp.back()-1]='a';

		qp.pop_back();

	}

	cout<<s;

}


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

int main()
{
    int q;
    cin>>q;
    int x[q];
    long long int y[q];
    char z[q];
    string a="What are you doing at the end of the world? Are you busy? Will you save us?";
    string b="What are you doing while sending \"";
    string c="\"? Are you busy? Will you send \"";
    string d="\"?";
int maxx=0;
    for(int i=0;i<q;i++)
    {
        cin>>x[i]>>y[i];
        if(x[i]>maxx)
            maxx=x[i];

    }
    for(int i=0;i<=maxx;i++)
    {
        for(int j=0;j<q;j++)
        {
            if(x[j]==i)
        {
            if(a.size()>=y[j])
            z[j]=a[y[j]-1];
            else
            z[j]='.';
        }
        }
        string e=a;
        a=b+e+c+e+d;
    }
    for(int i=0;i<q;i++)
        cout<<z[i];

        return 0;
}


#include <bits/stdc++.h>

using namespace std;
vector<int>arr;
int main()
{
   int n , k ;
   scanf("%d %d",&n,&k);
   arr.resize(n);
   int tot= 0 ;
   for( int i = 0 ; i < n ; i ++ ) {
        cin >> arr[ i ] ;
        tot+= arr[ i ] ;
   }
   int cnt= 0 , day = 0 ;
   while ( k ){
     day ++ ;
     if(tot>=8){
        tot -= 8 ;
        k-=8;
     }
     if ( k <= 0 ) break ;
     if ( k < 8 && (tot-k) >= 0 ){
        day ++ ;
        break;
     }else if ( k < 8 && (tot-k) <0 ) {
     cout << "-1" << endl;
     return 0 ;
     }
   }
   if ( day <= n )
   cout << day << endl ;
   else  cout << "-1" << endl;

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vl;
#define mod  1000000007
#define mp make_pair
#define pb push_back
#define sd second
#define mod  1000000007
#define ft first
#define all(x) x.begin(),x.end()
#define alr(x) x.rbegin(),x.rend()
#define endl '\n'
#define cnl cout<<endl;
#define pi  3.141592653589793238
#define ms(x,v) ((x), v, sizeof((x)))
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
ll i, j, k;
vector<string> split(const string &s, char delim)
{
    vector<string> elems;
    stringstream ss(s);
    string item;
    while (getline(ss, item, delim))
        elems.push_back(item);

    return elems;
}
void solve(){
      ll n, l, r, x; cin >> n >> l >> r >> x;
      vl v(n);
      for(i =0; i < n; i++) cin >>v[i];
        ll p = pow(2,n);

    vector<string> list;
    for (int i = 0; i < (int) pow(2, n); i++)
    {
        string subset = "";
        for (int j = 0; j < n; j++)
        {
            if ((i & (1 << j)) != 0)
                subset += to_string(v[j]) + "|";
        }
        if (find(list.begin(), list.end(), subset) == list.end())
            list.push_back(subset);
    }
    ll cnt =0;
    ll ans  = 0;
    for (string subset : list)
    {
        cnt = 0;
        ll sum = 0;
        vector<string> arr = split(subset, '|');
        for (string str: arr) {
          ll no =0;
          ll mn = 1e7;
          ll  mx = 0;
          for( i =0;i < str.size();i++){
              no = 10*no + (str[i]-'0');
              mn = min(mn, (str[i]-'0') );
              mx = max(mx, (str[i]-'0'));
          }
           sum = sum +no;
           cnt++;
        }
         if(cnt>=2 and sum>=l and sum <= r and (mx - mn)<=x) ans ++;
    }
    cout<< ans << endl;

     return ;
}
    signed main(){
    #ifndef ONLINE_JUDGE
    freopen( "input.txt", "r", stdin );
    freopen( "output.txt", "w", stdout );
    #endif
    //CASET
    solve();

    return 0;
  }


#include<bits/stdc++.h>

#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define forn(i,o,n) for(int i=o;i<n;i++)
#define int long long
#define endl "\n"
#define mod 1000000007
#define double long double
#define pb push_back
#define mk make_pair
#define swap(x,y) (x^=y^=x^=y)
#define TT int ttt;cin>>ttt;while(ttt--)

using namespace std;

int gcd(int a, int b){
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
bool isPrime(int n){
    if(n < 2)
        return 0;
    if(n < 4)
        return 1;
    if(n % 2 == 0 or n % 3 == 0)
        return 0;
    for(int i = 5; i*i <= n; i += 6)
        if(n % i == 0 or n % (i+2) == 0)
            return 0;
    return 1;
}
int modexpo(int x,int p){
    int res = 1;
    x = x%mod;
    while(p){
        if(p%2)
            res = res * x;
        p >>= 1;
        x = x*x % mod;
        res %= mod;
    }
    return res;
}

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

int min(int a,int b){
    if(a<b){
        return a;
    }
    return b;
}
int32_t main(){
    IOS
    int n,k,m,d;
    cin>>n>>k>>m>>d;
    if(m==1){
        cout<<1<<endl;
        return 0;
    }
    vector<int>v;
    for(int i=2;i<=sqrt(n);i++){
        if(i>m){
            break;
        }

        if(n%i==0){
            v.pb(i);
            int temp = n/i;
            if(temp == i){
                ;
            }
            else if(temp<=m){
                v.pb(temp);
            }
        }
    }
    int ans = m;
    for(int i=0;i<v.size();i++){
        int a = v[i]*k;
        int b = ceil((double)n/(double)a);
        if(b>d){
            continue;
        }
        int c = b*v[i];
        if(c>ans){
            ans = c;
        }
        //cout<<v[i]<<" "<<a<<" "<<b<<" "<<c<<endl;
    }
    cout<<ans<<endl;
}


/* Nurgazy Zhandos */

#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <iomanip>
#include <fstream>
#include <utility>
#include <string>
#include <vector>
#include <cstdio>
#include <queue>
#include <deque>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>

#define F first
#define S second

#define pf push_front
#define pb push_back
#define mp make_pair
#define pp pop_back

#define all(a) a.begin(), a.end()
#define sz(a) a.size()
#define STOP return 0

using namespace std;

typedef pair <long long, long long> PLL;
typedef unsigned long long ULL;
typedef pair <int, int> PII;
typedef long double LD;
typedef long long LL;

const int inf = 1e9 + 123;
const LL INF = 1e18 + 123;
const double eps = 1e-9;
const int mod = 1e9 + 7;

void boost() {
	ios_base :: sync_with_stdio(0);
	cin.tie(0), cout.tie(0);
}

int main () {
	//	freopen(".in", "r", stdin);
	//	freopen(".out", "w", stdout);

	LL a, b;
	cin >> a >> b;

	if(a < 5 && b < 5) {
		if(a == 0) a = 1;
		if(a == 1) a = 1;
		if(a == 2) a = 2;
		if(a == 3) a = 6;
		if(a == 4) a = 24;

		if(b == 0) b = 1;
		if(b == 1) b = 1;
		if(b == 2) b = 2;
		if(b == 3) b = 6;
		if(b == 4) b = 24;
		cout << b / a % 10;
		STOP;
	}

	if(b == 0) {
		cout << 0;
		STOP;
	}

	if(a == b) {
		cout << 1;
		STOP;
	}
	else{
		LL cnt = a;
		LL cnb = b;
			LL gg = cnb / cnt + 1;
			if(gg == 0) gg = 1;
			if(gg == 1) gg = 1;
			if(gg == 2) gg = 2;
			if(gg == 3) gg = 6;
			if(gg == 4) gg = 4;
			if(gg >= 5) gg = 0;
			cout << gg;
	}
}


#include<bits/stdc++.h>
using namespace std;
struct _ { ios_base::Init i; _(){ cin.sync_with_stdio(0); cin.tie(0);} } _;
int main()
{
    int tc;
    long long n,k,d1,d2;
    cin>>tc;
    while(tc--)
    {
        cin>>n>>k>>d1>>d2;
        long long x[4]={2*d1+d2,((d1>d2)?2*d1-d2:2*d2-d1),d1+d2,2*d2+d1};
        if(d2==0)
        {
            x[2]=x[3]=(int)1e18;
        }
        if(d1==0)
        {
            x[0]=x[2]=(int)1e18;
        }

        bool done=0;

        for(int i=0;i<4;++i)
        {
            //cout<<x[i]<<"\t";
            if(n-k>=x[i]&&(n-k-x[i])%3==0)
            {
                done=1;
                break;
            }
        }
        if(done)cout<<"yes\n";
        else cout<<"no\n";
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
#define ll long long
#define all(v)  	((v).begin()),((v).end())
#define sz(x)  		((int) (x).size())
#define clr(a,b)	memset(a,b,sizeof(a))
const double EPS = 1e-8;
const double pi = acos(-1);

int dcmp(double a, double b) {
	return fabs(a - b) <= EPS ? 0 : a < b ? -1 : 1;
}
void debug() {
	freopen("input.in", "r", stdin);
	freopen("output.in", "w", stdout);
}

int arr[101];
vector<pair<int, int>> vec;

int main() {
	cout << fixed << setprecision(0);
	ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
	int n;
	cin >> n;
	for (int i = 0; i < n; ++i) {
		cin >> arr[i];
	}
	int prev = 0, cnt = 0;
	for (int i = n-1; i > 0; --i) {
		if(arr[i] - arr[i-1] == prev) {
			cnt++;
		} else
			cnt = 0, prev = arr[i] - arr[i-1];
		vec.push_back({cnt, prev});
	}
	sort(vec.begin(), vec.end());
	pair<int, int> pr = vec[vec.size()-1];
	if(pr.first != 0 && arr[0] == 1 && arr[1] - arr[0] == pr.second)
		++pr.first;
	if(pr.first != 0 && arr[n-1] == 1000 && arr[n-1] - arr[n-2] == pr.second)
		++pr.first;

	cout << pr.first;
}


#include<cstdio>
int main()
{
	int a=0;
	char c;
	while(c=getchar())
		if(c=='0')
			++a;
	if(c>=6)
		printf("yes");
	else
		printf("no");
	return 0;
}


#include <stdio.h>
#include <stdlib.h>
#include <queue>

using namespace std;

queue<pair<int, int>> q;

int main()
{
    int n;
    int degree[15];
    int ans = 0;

    scanf("%d", &n);

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

    while(!q.empty())   q.pop();

    q.push(make_pair(0, degree[0]));

    while(!q.empty())
    {
        int index = q.front().first;
        int num = q.front().second;

        if(index == n && num%360 == 0)
        {
            ans = 1;
            break;
        }

        index++;
        if(index <= n)
        {
            q.push(make_pair(index, num + degree[index]));
            q.push(make_pair(index, num - degree[index]));
        }
    }

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