#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <deque>
#include <string>
#include <memory.h>

#define sci(a) scanf("%d", &a)
#define scii(a, b) scanf("%d%d", &a, &b)
#define sciii(a, b, c) scanf("%d%d%d", &a, &b, &c)

#define scid(a) int a; sci(a)
#define sciid(a, b) int a, b; scii(a, b)
#define sciiid(a, b, c) int a, b, c; sciii(a, b, c)

#define rea(a, n) for (int i = 0; i < n; i++) sci(a[i])

#define init_cin ios_base::sync_with_stdio(false); cin.tie(0);

typedef long long lint;

using namespace std;

int main() {
    sciid(n, m);
    if (n == 1 && m == 1) {
        cout << "0 0\n1 1\n1 0\n0 1";
        return 0;
    }
    if (n == 0) {
        cout << 0 << " " << 1 << "\n";
        cout << 0 << " " << m << "\n";
        cout << 0 << " " << 0 << "\n";
        cout << 0 << " " << m - 1 << "\n";
    } else if (m == 0) {
        cout << 1 << " " << 0 << "\n";
        cout << n << " " << 0 << "\n";
        cout << 0 << " " << 0 << "\n";
        cout << n - 1 << " " << 0 << "\n";
    } else if (n > m) {
        cout << 0 << " " << 1 << "\n";
        cout << n << " " << m << "\n";
        cout << 0 << " " << 0 << "\n";
        cout << n << " " << m - 1 << "\n";
    } else {
        cout << n - 1 << " " << m << "\n";
        cout << 0 << " " << 0 << "\n";
        cout << n << " " << m << "\n";
        cout << 1 << " " << 0 << "\n";
    }

    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <deque>
#include <string>
#include <memory.h>

#define sci(a) scanf("%d", &a)
#define scii(a, b) scanf("%d%d", &a, &b)
#define sciii(a, b, c) scanf("%d%d%d", &a, &b, &c)

#define scid(a) int a; sci(a)
#define sciid(a, b) int a, b; scii(a, b)
#define sciiid(a, b, c) int a, b, c; sciii(a, b, c)

#define rea(a, n) for (int i = 0; i < n; i++) sci(a[i])

#define init_cin ios_base::sync_with_stdio(false); cin.tie(0);

typedef long long lint;

using namespace std;

int main() {
    sciid(n, m);
    if (n == 0) {
        cout << 0 << " " << 1 << "\n";
        cout << 0 << " " << m << "\n";
        cout << 0 << " " << 0 << "\n";
        cout << 0 << " " << m - 1 << "\n";
    } else if (m == 0) {
        cout << 1 << " " << 0 << "\n";
        cout << n << " " << 0 << "\n";
        cout << 0 << " " << 0 << "\n";
        cout << n - 1 << " " << 0 << "\n";
    } else if (n > m) {
        cout << 1 << " " << 0 << "\n";
        cout << n << " " << m << "\n";
        cout << 0 << " " << 0 << "\n";
        cout << n - 1 << " " << m << "\n";
    } else {
        cout << 0 << " " << 1 << "\n";
        cout << n << " " << m << "\n";
        cout << 0 << " " << 0 << "\n";
        cout << n << " " << m - 1 << "\n";
    }

    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <deque>
#include <string>
#include <memory.h>

#define sci(a) scanf("%d", &a)
#define scii(a, b) scanf("%d%d", &a, &b)
#define sciii(a, b, c) scanf("%d%d%d", &a, &b, &c)

#define scid(a) int a; sci(a)
#define sciid(a, b) int a, b; scii(a, b)
#define sciiid(a, b, c) int a, b, c; sciii(a, b, c)

#define rea(a, n) for (int i = 0; i < n; i++) sci(a[i])

#define init_cin ios_base::sync_with_stdio(false); cin.tie(0);

typedef long long lint;

using namespace std;

int main() {
    sciid(n, m);
    if (n == 0) {
        cout << 0 << " " << 0 << "\n";
        cout << 0 << " " << m << "\n";
        cout << 0 << " " << 1 << "\n";
        cout << 0 << " " << m - 1 << "\n";
    } else if (m == 0) {
        cout << 0 << " " << 0 << "\n";
        cout << n << " " << 0 << "\n";
        cout << 1 << " " << 0 << "\n";
        cout << n - 1 << " " << 0 << "\n";
    } else if (n > m) {
        cout << 0 << " " << 0 << "\n";
        cout << n << " " << m << "\n";
        cout << 0 << " " << 1 << "\n";
        cout << n << " " << m - 1 << "\n";
    } else {
        cout << 0 << " " << 0 << "\n";
        cout << n << " " << m << "\n";
        cout << 1 << " " << 0 << "\n";
        cout << n - 1 << " " << m << "\n";
    }

    return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define M_PI (2*acos(0))
#define MAX_N 100001
using namespace std;

int main(){

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    ll n,m;
    cin>>n>>m;

    if((n==0)&&(m==0)){
        cout<<0<<" "<<0<<endl;
        cout<<0<<" "<<0<<endl;
        cout<<0<<" "<<0<<endl;
        cout<<0<<" "<<0<<endl;
        return 0;
    }

    if(n==0){
        cout<<0<<" "<<1<<endl;
        cout<<0<<" "<<m<<endl;
        cout<<0<<" "<<0<<endl;
        cout<<0<<" "<<m-1<<endl;
        return 0;
    }

    if(m==0){
        cout<<1<<" "<<0<<endl;
        cout<<n<<" "<<0<<endl;
        cout<<0<<" "<<0<<endl;
        cout<<n-1<<" "<<0<<endl;
        return 0;
    }

    if(n>=m){
        cout<<0<<" "<<0<<endl;
        cout<<n<<" "<<m<<endl;
        cout<<0<<" "<<m<<endl;
        cout<<n<<" "<<0<<endl;
        return 0;
    }

    if(m>n){
        cout<<0<<" "<<0<<endl;
        cout<<n<<" "<<m<<endl;
        cout<<n<<" "<<0<<endl;
        cout<<0<<" "<<m<<endl;
    }

}


#include<bits/stdc++.h>
#define P(x,y) make_pair(x,y)
#define sqr(x) ((x) * (x))
using namespace std;
const long long MX = 2009;
typedef long long ll;
typedef pair < int , int > pii;
int dis(pii a , pii b){
    return sqr ( abs(a.first - b.first) ) + sqr( abs(a.second - b.second) );
}
int main(){
    int n , m;
    cin>>n>>m;
    set < pii > S;
    for(int dx = 0;dx<=2;dx++){
        for(int dy=0;dy<=2;dy++){
            if(!(dx > n || dy > m))
                S.insert({dx , dy});
            if(!(dx>n || m-dy<0))
                S.insert({dx , m-dy});
            if(!(n-dx<0 || dy>m))
                S.insert({n-dx , dy});
            if(!(n-dx<0 || m-dy<0))
                S.insert({n-dx , m-dy});
        }
    }
    vector < pair < int , int > > v;
    for(auto pp : S) v.push_back(pp);
    int sol[4] , best=0;
    n = v.size();
    for(int j=0;j<n;j++){
        for(int i=0;i<n;i++){
            if(i == j) continue;
            for(int k=0;k<n;k++){
                if(k==i || k==j) continue;
                for(int l=0;l<n;l++){
                    if(l==k || l==i || l==j) continue;
                    int tt = dis(v[j] , v[i]) + dis(v[i] , v[k]) + dis(v[k] , v[l]);
                    if(tt > best){
                        best = tt;
                        sol[0] = j;
                        sol[1] = i;
                        sol[2] = k;
                        sol[3] = l;
                    }
                }
            }
        }
    }
    //cout<<ans<<endl;
    for(int j=0;j<4;j++) cout<<v[sol[j]].first<<' '<<v[sol[j]].second<<endl;
}


#include<bits/stdc++.h>
using namespace std;
const long long MX=(1<<20);
int N , M;
long double dp[MX];
int main(){
    int n , m;
    cin>>n>>m;

    cout<<0<<' '<<0<<endl<<n<<' '<<m<<endl;
    //cout<<0<<' '<<1<<endl<<' '<<n<<' '<<m-1<<endl;
    if(m){
        cout<<0<<' '<<1<<endl<<n<<' '<<m-1<<endl;
    }
    else cout<<1<<' '<<0<<endl<<n-1<<' '<<m<<endl;
}


#include<bits/stdc++.h>
#define P(x,y) make_pair(x,y)
using namespace std;
const long long MX = 2009;
typedef long long ll;
typedef pair < int , int > pii;
int dis(pii a , pii b){
    return abs(a.first - b.first) + abs(a.second - b.second);
}
int main(){
    int n , m;
    cin>>n>>m;
    set < pii > S;
    for(int dx = 0;dx<=2;dx++){
        for(int dy=0;dy<=2;dy++){
            if(!(dx > n || dy > m))
                S.insert({dx , dy});
            if(!(dx>n || m-dy<0))
                S.insert({dx , m-dy});
            if(!(n-dx<0 || dy>m))
                S.insert({n-dx , dy});
            if(!(n-dx<0 || m-dy<0))
                S.insert({n-dx , m-dy});
        }
    }
    vector < pair < int , int > > v;
    for(auto pp : S) v.push_back(pp);
    int sol[4] , best=0;
    n = v.size();
    for(int j=0;j<n;j++){
        for(int i=0;i<n;i++){
            if(i == j) continue;
            for(int k=0;k<n;k++){
                if(k==i || k==j) continue;
                for(int l=0;l<n;l++){
                    if(l==k || l==i || l==j) continue;
                    int tt = dis(v[j] , v[i]) + dis(v[i] , v[k]) + dis(v[k] , v[l]);
                    if(tt > best){
                        best = tt;
                        sol[0] = j;
                        sol[1] = i;
                        sol[2] = k;
                        sol[3] = l;
                    }
                }
            }
        }
    }
    //cout<<ans<<endl;
    for(int j=0;j<4;j++) cout<<v[sol[j]].first<<' '<<v[sol[j]].second<<endl;
}


// from editorial !

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

#define mp make_pair

double dis( pair<int,int> p , pair<int,int> q )
{
	return sqrt( (1.0*p.first-q.first)*(1.0*p.first-q.first) + (1.0*p.second-q.second)*(1.0*p.second-q.second) );
}

int main()
{
	int n , m;
	set< pair<int,int> > s , k;
	cin>>n>>m;

	for ( int i=0 ; i<4 ; i++ ) for ( int j=0 ; j<4 ; j++ )
		if ( i<=n && j<=m )
			s.insert( mp( i , j ) );

	for ( int i=n ; i>n-4 ; i-- ) for ( int j=m ; j>m-4 ; j-- )
		if ( i>=0 && j>=0 )
			s.insert( mp( i , j ) );

	for ( int i=0 ; i<4 ; i++ ) for ( int j=m ; j>m-4 ; j-- )
		if ( i<=n && j>=0 )
			s.insert( mp( i , j ) );

	for ( int i=n ; i>n-4 ; i-- ) for ( int j=0 ; j<4 ; j++ )
		if ( i>=0 && j<=m )
			s.insert( mp( i , j ) );

	k = s;

	vector<pair<int,int> > ans; double ans_d = 0;
	while ( k.size() )
	{
		pair<int,int> now = *k.begin();
		k.erase( k.begin() );

		set< pair<int,int> > save = s;
		vector< pair<int,int> > v;

		v.push_back( now );
		s.erase( now );
		pair<int,int> neu = now; double d = 0;

		for ( int z = 0 ; z<3 ; z++ )
		{
			for ( set<pair<int,int> >::iterator si = s.begin() ; si != s.end() ; si++ )
			{
				double t = dis( now , *si );
				if ( t > d )
					neu = *si , d = t;
			}
			v.push_back( neu );
			s.erase( neu );
			now = neu , d = 0;
		}

		double thiz = dis( v[0] , v[1] ) + dis( v[1] , v[2] ) + dis( v[2] , v[3] );

		if ( thiz > ans_d )
			ans_d = thiz , ans = v;

		s = save;
	}

	for ( int i=0 ; i<4 ; i++ )
		cout<<ans[i].first<<" "<<ans[i].second<<"\n";

	return 0;
}


// from editorial !

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

#define mp make_pair

double dis( pair<int,int> p , pair<int,int> q )
{
	return sqrt( (1.0*p.first-q.first)*(1.0*p.first-q.first) + (1.0*p.second-q.second)*(1.0*p.second-q.second) );
}

int main()
{
	int n , m;
	vector< pair<int,int> > v;
	cin>>n>>m;

	for ( int i=0 ; i<4 ; i++ ) for ( int j=0 ; j<4 ; j++ )
		if ( i<=n && j<=m )
			v.push_back( mp( i , j ) );

	for ( int i=n ; i>n-4 ; i-- ) for ( int j=m ; j>m-4 ; j-- )
		if ( i>=0 && j>=0 )
			v.push_back( mp( i , j ) );

	for ( int i=0 ; i<4 ; i++ ) for ( int j=m ; j>m-4 ; j-- )
		if ( i<=n && j>=0 )
			v.push_back( mp( i , j ) );

	for ( int i=n ; i>n-4 ; i-- ) for ( int j=0 ; j<4 ; j++ )
		if ( i>=0 && j<=m )
			v.push_back( mp( i , j ) );

	sort( v.begin() , v.end() );
	int sz = unique( v.begin() , v.end() ) - v.begin();
	v.resize( sz );

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

	int ans[4]; double ans_d = 0;
	int vs = v.size();

	for ( int i=0 ; i<vs ; i++ )
		for ( int j=0 ; j<vs ; j++ )
			for ( int k=0 ; k<vs ; k++ )
				for ( int t=0 ; t<vs ; t++ )
				{
					if ( i==j || i==k || i==t || j==k || j==t || k==t ) continue;
					double z = dis( v[i] , v[j] ) + dis( v[j] , v[k] ) + dis( v[k] , v[t] );
					if ( z > ans_d )
						ans_d =z , ans[0]=i , ans[1]=j , ans[2]=k , ans[3]=t;
				}

	for ( int i=0 ; i<4 ; i++ )
		cout<<v[ans[i]].first<<" "<<v[ans[i]].second<<"\n";

	return 0;
}


#include <bits/stdc++.h>
#define fr(a, b, c) for(int a = b; a < c; ++a)
#define sc(a) scanf("%d", &a)
#define pb push_back
#define mp make_pair

using namespace std;

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

int main()
{
    int n, m;
    sc(n); sc(m);
    if (!n) {
        cout << "0 1" << endl;
        cout << "0 " << m << endl;
        cout << "0 0" << endl;
        cout << "0 " << m-1 << endl;
    } else if (!m) {
        cout << "1 0" << endl;
        cout << n << " 0" << endl;
        cout << "0 0" << endl;
        cout << n-1 << " 0" << endl;
    } else if (n == m && (n == 1 || n == 2 || n == 3)) {
        cout << "0 0" << endl;
        cout << n << " " << m << endl;
        cout << n << " 0" << endl;
        cout << "0 " << m << endl;
    } else if (n == m || n > m) {
        cout << n <<  " " << m-1 << endl;
        cout << "0 0" << endl;
        cout << n << " " << m << endl;
        cout << "0 " << 1 << endl;
    } else {
        cout << n-1 <<  " " << m << endl;
        cout << "0 0" << endl;
        cout << n << " " << m << endl;
        cout << 1 << " 0" << endl;
    }
    return 0;
}


#include <bits/stdc++.h>
#define fr(a, b, c) for(int a = b; a < c; ++a)
#define sc(a) scanf("%d", &a)
#define pb push_back
#define mp make_pair

using namespace std;

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

int main()
{
    int n, m;
    sc(n); sc(m);
    if (!n) {
        cout << "0 1" << endl;
        cout << "0 " << m << endl;
        cout << "0 0" << endl;
        cout << "0 " << m-1 << endl;
    } else if (!m) {
        cout << "1 0" << endl;
        cout << n << " 0" << endl;
        cout << "0 0" << endl;
        cout << n-1 << " 0" << endl;
    } else if (n == 1 && m == 1) {
        cout << "0 0" << endl;
        cout << n << " " << m << endl;
        cout << n << " 0" << endl;
        cout << "0 " << m << endl;
    } else {
        cout << n <<  " " << m-1 << endl;
        cout << "0 0" << endl;
        cout << n << " " << m << endl;
        cout << 1 << " 0" << endl;
    }
    return 0;
}


#include <bits/stdc++.h>
#define fr(a, b, c) for(int a = b; a < c; ++a)
#define sc(a) scanf("%d", &a)
#define pb push_back
#define mp make_pair

using namespace std;

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

int main()
{
    int n, m;
    sc(n); sc(m);
    if (!n) {
        cout << "0 1" << endl;
        cout << "0 " << m << endl;
        cout << "0 0" << endl;
        cout << "0 " << m-1 << endl;
    } else if (!m) {
        cout << "1 0" << endl;
        cout << n << " 0" << endl;
        cout << "0 0" << endl;
        cout << n-1 << " 0" << endl;
    } else {
        cout << "0 0" << endl;
        cout << n << " " << m << endl;
        cout << "0 " << m << endl;
        cout << n << " 0" << endl;
    }
    return 0;
}


#include <bits/stdc++.h>
#define fr(a, b, c) for(int a = b; a < c; ++a)
#define sc(a) scanf("%d", &a)
#define pb push_back
#define mp make_pair

using namespace std;

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

int main()
{
    int n, m;
    sc(n); sc(m);
    if (!n) {
        cout << "0 1" << endl;
        cout << "0 " << m << endl;
        cout << "0 0" << endl;
        cout << "0 " << m-1 << endl;
    } else if (!m) {
        cout << "1 0" << endl;
        cout << n << " 0" << endl;
        cout << "0 0" << endl;
        cout << n-1 << " 0" << endl;
    } else if (n == 1 && m == 1) {
        cout << "0 0" << endl;
        cout << n << " " << m << endl;
        cout << n << " 0" << endl;
        cout << "0 " << m << endl;
    } else if (n == m || n > m) {
        cout << n <<  " " << m-1 << endl;
        cout << "0 0" << endl;
        cout << n << " " << m << endl;
        cout << 1 << " 0" << endl;
    } else {
        cout << n-1 <<  " " << m << endl;
        cout << "0 0" << endl;
        cout << n << " " << m << endl;
        cout << 1 << " 0" << endl;
    }
    return 0;
}


#include <bits/stdc++.h>
#define fr(a, b, c) for(int a = b; a < c; ++a)
#define sc(a) scanf("%d", &a)
#define pb push_back
#define mp make_pair

using namespace std;

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

int main()
{
    int n, m;
    sc(n); sc(m);
    if (!n) {
        cout << "0 1" << endl;
        cout << "0 " << m << endl;
        cout << "0 0" << endl;
        cout << "0 " << m-1 << endl;
    } else if (!m) {
        cout << "1 0" << endl;
        cout << n << " 0" << endl;
        cout << "0 0" << endl;
        cout << n-1 << " 0" << endl;
    } else {
        double v1, v2;
        v1 = 2*(hypot(n, m)) + max(n, m);
        v2 = hypot(n, m) + 2*(hypot(max(n, m), min(n, m)-1));
        if (v1 > v2) {
            if (n > m) {
                cout << "0 0" << endl;
                cout << n << " " << m << endl;
                cout << "0 " << m << endl;
                cout << n << " 0" << endl;
            } else {
                cout << "0 0" << endl;
                cout << n << " " << m << endl;
                cout << n << " 0" << endl;
                cout << "0 " << m << endl;
            }
        } else if (n >= m) {
            cout << n <<  " " << m-1 << endl;
            cout << "0 0" << endl;
            cout << n << " " << m << endl;
            cout << "0 " << 1 << endl;
        } else {
            cout << n-1 <<  " " << m << endl;
            cout << "0 0" << endl;
            cout << n << " " << m << endl;
            cout << 1 << " 0" << endl;
        }
    }
    return 0;
}


#include <bits/stdc++.h>
#define rep(i, a) rep2 (i, 0, a)
#define rep2(i, a, b) for (int i = (a); i < (b); i++)
#define repr(i, a) repr2 (i, 0, a)
#define repr2(i, a, b) for (int i = (b) - 1; i >= (a); i--)
using namespace std;
typedef long long ll;

int main() {
	int n, m;
	cin >> n >> m;
	int a[4];
	rep (i, 4) a[i] = i;
	int xs[4], ys[4];
	if (n == 0) {
		xs[0] = 0; ys[0] = 0;
		xs[1] = 0; ys[1] = 1;
		xs[2] = n; ys[2] = m;
		xs[3] = n; ys[3] = m - 1;
	} else if (m == 0) {
		xs[0] = 0; ys[0] = 0;
		xs[1] = 1; ys[1] = 0;
		xs[2] = n; ys[2] = m;
		xs[3] = n - 1; ys[3] = m;
	} else if (n <= m) {
		xs[0] = 0; ys[0] = 0;
		xs[1] = 1; ys[1] = 0;
		xs[2] = n; ys[2] = m;
		xs[3] = n - 1; ys[3] = m;
	} else {
		xs[0] = 0; ys[0] = 0;
		xs[1] = 0; ys[1] = 1;
		xs[2] = n; ys[2] = m;
		xs[3] = n; ys[3] = m - 1;
	}
	double dist = 0;
	vector<int> ansx, ansy;
	do {
		double cand = 0;
		rep (i, 3) {
			cand += hypot(xs[a[i + 1]] - xs[a[i]], ys[a[i + 1]] - ys[a[i]]);
		}
		if (dist < cand) {
			dist = cand;
			ansx.clear();
			ansy.clear();
			rep (i, 4) {
				ansx.push_back(xs[a[i]]);
				ansy.push_back(ys[a[i]]);
			}
		}
	} while (next_permutation(a, a + 4));
	rep (i, 4) {
		cout << ansx[i] << " " << ansy[i] << endl;
	}
	return 0;
}


#include <bits/stdc++.h>
#define rep(i, a) rep2 (i, 0, a)
#define rep2(i, a, b) for (int i = (a); i < (b); i++)
#define repr(i, a) repr2 (i, 0, a)
#define repr2(i, a, b) for (int i = (b) - 1; i >= (a); i--)
using namespace std;
typedef long long ll;

int main() {
	int n, m;
	cin >> n >> m;
	int a[4];
	rep (i, 4) a[i] = i;
	int xs[4], ys[4];
	if (n >= 1) {
		xs[0] = 0; ys[0] = 0;
		xs[1] = 1; ys[1] = 0;
		xs[2] = n; ys[2] = m;
		xs[3] = n - 1; ys[3] = m;
	} else {
		xs[0] = 0; ys[0] = 0;
		xs[1] = 0; ys[1] = 1;
		xs[2] = n; ys[2] = m;
		xs[3] = n; ys[3] = m - 1;
	}
	double dist = 0;
	vector<int> ansx, ansy;
	do {
		double cand = 0;
		rep (i, 3) {
			cand += hypot(xs[a[i + 1]] - xs[a[i]], ys[a[i + 1]] - ys[a[i]]);
		}
		if (dist < cand) {
			dist = cand;
			ansx.clear();
			ansy.clear();
			rep (i, 4) {
				ansx.push_back(xs[a[i]]);
				ansy.push_back(ys[a[i]]);
			}
		}
	} while (next_permutation(a, a + 4));
	rep (i, 4) {
		cout << ansx[i] << " " << ansy[i] << endl;
	}
	return 0;
}


#include <bits/stdc++.h>
#define rep(i, a) rep2 (i, 0, a)
#define rep2(i, a, b) for (int i = (a); i < (b); i++)
#define repr(i, a) repr2 (i, 0, a)
#define repr2(i, a, b) for (int i = (b) - 1; i >= (a); i--)
using namespace std;
typedef long long ll;

vector<int> xs, ys;
set<pair<int, int>> ps;
double dist;
vector<int> ax, ay;
int n, m;

void add(int x, int y) {
	if (x < 0 || x > n || y < 0 || y > m) return;
	if (ps.count(make_pair(x, y))) return;
	ps.emplace(x, y);
	xs.push_back(x);
	ys.push_back(y);
}

void dfs(int n, int k, int pos, vector<int> &p) {
	if (pos == k) {
		double cand = 0;
		rep (i, 3) {
			double x1 = xs[p[i]];
			double y1 = ys[p[i]];
			double x2 = xs[p[i + 1]];
			double y2 = ys[p[i + 1]];
			cand += hypot(x2 - x1, y2 - y1);
		}
		if (dist < cand) {
			dist = cand;
			ax.clear();
			ay.clear();
			rep (i, 4) {
				ax.push_back(xs[p[i]]);
				ay.push_back(ys[p[i]]);
			}
		}
		return;
	}
	rep2 (i, pos, n) {
		swap(p[pos], p[i]);
		dfs(n, k, pos + 1, p);
		swap(p[pos], p[i]);
	}
}

int main() {
	cin >> n >> m;
	int x[4], y[4];
	int dx[] = {0, 0, 1, 0, -1};
	int dy[] = {0, 1, 0, -1, 0};
	x[0] = 0; y[0] = 0;
	x[1] = n; y[1] = 0;
	x[2] = n; y[2] = m;
	x[3] = 0; y[3] = m;
	rep (i, 4) {
		rep (k, 5) {
			int nx = x[i] + dx[k];
			int ny = y[i] + dy[k];
			add(nx, ny);
		}
	}
	vector<int> p(xs.size());
	rep (i, p.size()) p[i] = i;
	dfs(p.size(), 4, 0, p);
	rep (i, 4) {
		cout << ax[i] << " " << ay[i] << endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define eps 1e-10
int f[1010][1010];
int main(){
#ifndef ONLINE_JUDGE
	freopen("in.in","r",stdin);
	freopen("out.out","w",stdout);
#endif
	int n,m;
	cin>>n>>m;
	if(n==0){
		cout<<0<<" "<<1<<endl;
		cout<<0<<" "<<m<<endl;
		cout<<0<<" "<<0<<endl;
		cout<<0<<" "<<m-1<<endl;
		return 0;
	}
	if(m==0){
		cout<<1<<" "<<0<<endl;
		cout<<n<<" "<<0<<endl;
		cout<<0<<" "<<0<<endl;
		cout<<n-1<<" "<<0<<endl;
		return 0;
	}
	if(n>m){
		double L=hypot(n,m)+n;
		double R=2*hypot(n,m-1);
		if(L<R) {
			cout<<0<<" "<<1<<endl;
			cout<<n<<" "<<m<<endl;
			cout<<0<<" "<<0<<endl;
			cout<<n<<" "<<m-1<<endl;
			return 0;
		}
		else {
			cout<<0<<" "<<0<<endl;
			cout<<n<<" "<<m<<endl;
			cout<<0<<" "<<m<<endl;
			cout<<n<<" "<<0<<endl;
			return 0;
		}
	}
	else {
		double L=hypot(n,m)+m;
		double R=2*hypot(n-1,m);
		if(L<R) {
			cout<<1<<" "<<0<<endl;
			cout<<n<<" "<<m<<endl;
			cout<<0<<" "<<0<<endl;
			cout<<n-1<<" "<<m<<endl;
			return 0;
		}
		else {
			cout<<0<<" "<<0<<endl;
			cout<<n<<" "<<m<<endl;
			cout<<0<<" "<<m<<endl;
			cout<<n<<" "<<0<<endl;
			return 0;
		}
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long INT;
#define rt(x) (x)*(x)
int main(){
#ifndef ONLINE_JUDGE
	freopen("in.in","r",stdin);
#endif
	int n,m;
	scanf("%d%d",&n,&m);
	if(n==1 and m==1){
		cout<<1<<' '<<1<<endl;
		cout<<0<<' '<<0<<endl;
		cout<<1<<' '<<0<<endl;
		cout<<0<<' '<<1<<endl;
		return 0;
	}
	if(n==0){

		cout<<0<<" "<<1<<endl;
		cout<<0<<" "<<m<<endl;
		cout<<0<<" "<<0<<endl;
		cout<<0<<" "<<m-1<<endl;
		return 0;
	}
	if(m==0){
		cout<<1<<" "<<0<<endl;
		cout<<n<<" "<<0<<endl;
		cout<<0<<" "<<0<<endl;
		cout<<n-1<<" "<<0<<endl;
		return 0;
	}
	if(n>m){
		double a=2.0*sqrt(rt(n)+rt(m-1));
		double b=(double)sqrt(rt(n)+rt(m))+n;
		if(a<b){
			cout<<0<<" "<<0<<endl;
			cout<<n<<" "<<m<<endl;
			cout<<0<<" "<<m<<endl;
			cout<<n<<" "<<0<<endl;
			return 0;
		}
		else{
			cout<<0<<" "<<m-1<<endl;
			cout<<n<<" "<<0<<endl;
			cout<<0<<" "<<m<<endl;
			cout<<n<<" "<<1<<endl;
			return 0;
		}
	}
	else {
		double a=2.0*sqrt(rt(m)+rt(n-1));
		double b=(double)sqrt(rt(m)+rt(n))+m;
		if(a<b){
			cout<<0<<" "<<0<<endl;
			cout<<n<<" "<<m<<endl;
			cout<<n<<" "<<0<<endl;
			cout<<0<<" "<<m<<endl;
			return 0;
		}
		else {
			cout<<1<<" "<<0<<endl;
			cout<<n<<" "<<m<<endl;
			cout<<0<<" "<<0<<endl;
			cout<<n-1<<" "<<m<<endl;
			return 0;
		}
	}
}


#include<bits/stdc++.h>
using namespace std;
typedef long long INT;
#define rt(x) (x)*(x)
int main(){
#ifndef ONLINE_JUDGE
   freopen("in.in","r",stdin);
   freopen("out.out","w",stdout);
#endif
   int n,m;
   scanf("%d%d",&n,&m);
   if(n==1 and m==1) {printf("1 1\n0 0\n1 0\n0 1\n");return 0;}
   if(n==0){printf("0 1\n0 %d\n0 0\n0 %d\n",m,m-1);return 0;}
   if(m==0){printf("1 0\n%d 0\n0 0\n%d 0\n",n,n-1);return 0;}
   if(n>m){
      double a=sqrt(rt(n)+rt(m-1))*2;
      double b=sqrt(rt(n)+rt(m))+n;
      if(a>b){printf("0 %d\n%d 0\n0 %d\n%d 1\n",m-1,n,m,n);return 0;}
      else {printf("0 0\n%d %d\n0 %d\n%d 0\n",n,m,m,n);return 0;}
   }
   else{
      double a=sqrt(rt(n)+rt(n-1))*2;
      double b=sqrt(rt(n)+rt(m))+m;
      if(a>b){printf("1 0\n%d %d\n0 0\n%d %d\n",n,m,n-1,m);return 0;}
      else {printf("0 0\n%d %d\n%d 0\n0 %d\n",n,m,n,m);return 0;}
   }
}


#include<bits/stdc++.h>
using namespace std;
typedef long long INT;
#define rt(x) ((x)*(x))
int main(){
#ifndef ONLINE_JUDGE
	freopen("in.in","r",stdin);
#endif
	int n,m;
	scanf("%d%d",&n,&m);
	if(n==1&&m==1){
		puts("1 1");
      puts("0 0");
		puts("1 0");
      puts("0 1");
		return 0;
   }
	if(n==0){
		puts("0 1");
      printf("0 %d\n",m);
      puts("0 0");
      printf("0 %d\n",m-1);
      return 0;
   }
	if(m==0){
	   puts("1 0");
      printf("%d 0\n",n);
	   puts("0 0");
      printf("%d 0\n",n-1);
		return 0;
   }
	if(n>m){
		double a=sqrt(rt(n)+rt(m-1))*2;
		double b=sqrt(rt(n)+rt(m))+n;
		if(a>b){
		   printf("0 %d\n",m-1);printf("%d 0\n",n);
		   printf("0 %d\n",m);printf("%d 1\n",n);
			return 0;}
		else{
		   puts("0 0");printf("%d %d\n",n,m);
			printf("0 %d\n",m);printf("%d 0\n",n);
         return 0;} }
	else {
		double a=sqrt(rt(m)+rt(n-1))*2;
		double b=sqrt(rt(m)+rt(n))+m;
		if(a>b){
			puts("0 0");printf("%d %d\n",n,m);
			puts("0 0");printf("%d %d\n",n-1,m);
			return 0;}
		else {
         puts("0 0");printf("%d %d\n",n,m);
			printf("%d 0",n);printf("0 %d\n",m);
			return 0;
      }
	}
}


#include<bits/stdc++.h>
using namespace std;
typedef long long INT;
#define rt(x) ((x)*(x))
int main(){
#ifndef ONLINE_JUDGE
	freopen("in.in","r",stdin);
#endif
	int n,m;
	scanf("%d%d",&n,&m);
	if(n==1&&m==1){
		puts("1 1");
      puts("0 0");
		puts("1 0");
      puts("0 1");
		return 0;
   }
	if(n==0){
		puts("0 1");
      printf("0 %d\n",m);
      puts("0 0");
      printf("0 %d\n",m-1);
      return 0;
   }
	if(m==0){
	   puts("1 0");
      printf("%d 0\n",n);
	   puts("0 0");
      printf("%d 0\n",n-1);
		return 0;
   }
	if(n>m){
		double a=sqrt(rt(n)+rt(m-1))*2;
		double b=sqrt(rt(n)+rt(m))+n;
		if(a>b){
		   printf("0 %d\n",m-1);
         printf("%d 0\n",n);
		   printf("0 %d\n",m);
         printf("%d 1\n",n);
			return 0;
      }
		else{
		   puts("0 0");
         printf("%d %d\n",n,m);
			printf("0 %d\n",m);
         printf("%d 0\n",n);
         return 0;
      }
   }
	else {
		double a=sqrt(rt(m)+rt(n-1))*2;
		double b=sqrt(rt(m)+rt(n))+m;
		if(a>b){
			puts("0 0");
         printf("%d %d\n",n,m);
			puts("0 0");
         printf("%d %d\n",n-1,m);
			return 0;
      }
		else {
         puts("0 0");
         printf("%d %d\n",n,m);
			printf("%d 0\n",n);
         printf("0 %d\n",m);
			return 0;
      }
	}
}


#include <bits/stdc++.h>
using namespace std;
typedef double DO;
double sq(int x,int y,int xx,int yy){
	return sqrt((x-xx)*(x-xx)+(y-yy)*(y-yy));
}
int main() {
#ifndef ONLINE_JUDGE
	freopen("in.in", "r", stdin);
	freopen("out.out", "w", stdout);
#endif
	int n,m;
	scanf("%d%d",&n,&m);
	if(n==0){ printf("%d %d\n%d %d\n%d %d\n%d %d\n",0,1,n,m,0,0,n,m-1);return 0;}
	if(m==0){ printf("%d %d\n%d %d\n%d %d\n%d %d\n",1,0,n,m,0,0,n-1,m);return 0;}
	if(n>m){
		DO l1=sq(0,1,n,m)*2.0+sq(0,0,n,m);
		DO l2=sq(0,0,n,m)*2.0+sq(0,0,n,0);
		if(l1>l2) printf("%d %d\n%d %d\n%d %d\n%d %d\n",0,1,n,m,0,0,n,m-1);
		else printf("%d %d\n%d %d\n%d %d\n%d %d\n",0,0,n,m,0,m,n,0);
	}
	else {
		DO l1=sq(0,0,n-1,m)*2.0+sq(0,0,n,m);
		DO l2=sq(0,0,n,m)*2.0+sq(0,0,0,m);
		if(l1>l2) printf("%d %d\n%d %d\n%d %d\n%d %d\n",1,0,n,m,0,0,n-1,m);
		else printf("%d %d\n%d %d\n%d %d\n%d %d\n",0,0,n,m,n,0,0,m);
	}

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long INT;
#define rt(x) (x)*(x)
int main(){
#ifndef ONLINE_JUDGE
   freopen("in.in","r",stdin);
   freopen("out.out","w",stdout);
#endif
   int n,m;
   scanf("%d%d",&n,&m);
   if(n==1 and m==1) {printf("1 1\n0 0\n1 0\n0 1\n");return 0;}
   if(n==0){printf("0 1\n0 %d\n0 0\n0 %d\n",m,m-1);return 0;}
   if(m==0){printf("1 0\n%d 0\n0 0\n%d 0\n",n,n-1);return 0;}
   if(n>m){
      double a=sqrt(rt(n)+rt(m-1))*2;
      double b=sqrt(rt(n)+rt(m))+n;
      if(a>b){printf("0 1\n%d %d\n0 0\n%d %d\n",n,m,n,m-1);return 0;}
      else {printf("0 0\n%d %d\n0 %d\n%d 0\n",n,m,m,n);return 0;}
   }
   else{
      double a=sqrt(rt(n)+rt(n-1))*2;
      double b=sqrt(rt(n)+rt(m))+m;
      if(a>b){printf("%d %d\n0 0\n%d %d\n0 1\n",n-1,m,n,m);return 0;}
      else {printf("0 0\n%d %d\n%d 0\n0 %d\n",n,m,n,m);return 0;}
   }
}


#include<bits/stdc++.h>
using namespace std;
typedef long long INT;
#define rt(x) ((x)*(x))
int main(){
#ifndef ONLINE_JUDGE
	freopen("in.in","r",stdin);
#endif
	int n,m;
	scanf("%d%d",&n,&m);
	if(n==1&&m==1){
		puts("1 1");puts("0 0");
		puts("1 0");puts("0 1");
		return 0;}
	if(n==0){
		puts("0 1");printf("0 %d\n",m);
      puts("0 0");printf("0 %d\n",m-1);
      return 0;}
	if(m==0){
	   puts("1 0");printf("%d 0\n",n);
	   puts("0 0");printf("%d 0\n",n-1);
		return 0;}
	if(n>m){
		double a=2*sqrt(rt(n)+rt(m-1));
		double b=sqrt(rt(n)+rt(m))+n;
		if(a>b){
		   printf("0 %d\n",m-1);printf("%d 0\n",n);
		   printf("0 %d\n",m);printf("%d 1\n",n);
			return 0;}
		else{
		   puts("0 0");printf("%d %d\n",n,m);
			printf("0 %d\n",m);printf("%d 0\n",n);
         return 0;} }
	else {
		double a=2*sqrt(rt(m)+rt(n-1));
		double b=sqrt(rt(m)+rt(n))+m;
		if(a<b){
			puts("0 0");printf("%d %d\n",n,m);
		   printf("%d 0\n",n);printf("0 %d\n",m);
			return 0;}
		else {
         puts("0 0");printf("%d %d\n",n,m);
			puts("0 0");printf("%d %d\n",n-1,m);
			return 0;
      }
	}
}


#include<bits/stdc++.h>
using namespace std;
#define eps 1e-10
int f[1010][1010];
int main(){
#ifndef ONLINE_JUDGE
	freopen("in.in","r",stdin);
	freopen("out.out","w",stdout);
#endif
	int n,m;
	cin>>n>>m;
	if(n==1&&m==1){
		printf("1 1\n0 0\n1 0\n0 1\n");
		return 0;
	}
	if(n==0){
		cout<<0<<" "<<1<<endl;
		cout<<0<<" "<<m<<endl;
		cout<<0<<" "<<0<<endl;
		cout<<0<<" "<<m-1<<endl;
		return 0;
	}
	if(m==0){
		cout<<1<<" "<<0<<endl;
		cout<<n<<" "<<0<<endl;
		cout<<0<<" "<<0<<endl;
		cout<<n-1<<" "<<0<<endl;
		return 0;
	}
	if(m>=n){
		double x=2*sqrt(1.0*m*m+(n-1.0)*(n-1.0));
		double y=sqrt(1.0*m*m+1.0*n*n)+1.0*m;
		if(x<y){
			printf("%d %d\n",0,0);
			printf("%d %d\n",n,m);
			printf("%d %d\n",n,0);
			printf("%d %d\n",0,m);
			return 0;
		}
		else {
			printf("%d %d\n",1,0);
			printf("%d %d\n",n,m);
			printf("%d %d\n",0,0);
			printf("%d %d\n",n-1,m);
			return 0;
		}
	}
	if(m<n){
		double x=2*sqrt(n*n+(m-1)*(m-1));
		double y=sqrt(n*n+m*m)+n;
		if(x<y){
			printf("%d %d\n",0,0);
			printf("%d %d\n",n,m);
			printf("%d %d\n",0,m);
			printf("%d %d\n",n,0);
			return 0;
		}
		else {
			printf("%d %d\n",0,m-1);
			printf("%d %d\n",n,0);
			printf("%d %d\n",0,m);
			printf("%d %d\n",n,1);
			return 0;
		}
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long INT;
#define sq(x) ((x)*(x))
int main(){
#ifndef ONLINE_JUDGE
	freopen("in.txt","r",stdin);
#endif
	int n,m;
	cin>>n>>m;
	if(n==1&&m==1){
		cout<<1<<' '<<1<<endl;
		cout<<0<<' '<<0<<endl;
		cout<<1<<' '<<0<<endl;
		cout<<0<<' '<<1<<endl;
		return 0;
	}
	if(n==0){

		cout<<0<<' '<<1<<endl;
		cout<<0<<' '<<m<<endl;
		cout<<0<<' '<<0<<endl;
		cout<<0<<' '<<m-1<<endl;
		return 0;
	}
	if(m==0){
		cout<<1<<' '<<0<<endl;
		cout<<n<<' '<<0<<endl;
		cout<<0<<' '<<0<<endl;
		cout<<n-1<<' '<<0<<endl;
		return 0;
	}
	if(n>m){
		double a=2*sqrt(sq(n)+sq(m-1));
		double b=sqrt(sq(n)+sq(m))+n;
		if(a,b){
			cout<<0<<' '<<0<<endl;
			cout<<n<<' '<<m<<endl;
			cout<<0<<' '<<m<<endl;
			cout<<n<<' '<<0<<endl;
			return 0;
		}
		else{
			cout<<0<<' '<<m-1<<endl;
			cout<<n<<' '<<0<<endl;
			cout<<0<<' '<<m<<endl;
			cout<<n<<' '<<1<<endl;
			return 0;
		}
	}
	else if(m>=n){
		double a=2*sqrt(sq(m)+sq(n-1));
		double b=sqrt(sq(m)+sq(n))+m;
		if(a<b){
			cout<<0<<' '<<0<<endl;
			cout<<n<<' '<<m<<endl;
			cout<<n<<' '<<0<<endl;
			cout<<0<<' '<<m<<endl;
			return 0;
		}
		else {
			cout<<1<<' '<<0<<endl;
			cout<<n<<' '<<m<<endl;
			cout<<0<<' '<<0<<endl;
			cout<<n-1<<' '<<m<<endl;
			return 0;
		}
	}
}


#include<bits/stdc++.h>
using namespace std;
#define eps 1e-10
int f[1010][1010];
int main(){
#ifndef ONLINE_JUDGE
	freopen("in.in","r",stdin);
	freopen("out.out","w",stdout);
#endif
	int n,m;
	cin>>n>>m;
	if(n==0){
		cout<<0<<" "<<1<<endl;
		cout<<0<<" "<<m<<endl;
		cout<<0<<" "<<0<<endl;
		cout<<0<<" "<<m-1<<endl;
		return 0;
	}
	if(m==0){
		cout<<1<<" "<<0<<endl;
		cout<<n<<" "<<0<<endl;
		cout<<0<<" "<<0<<endl;
		cout<<n-1<<" "<<0<<endl;
		return 0;
	}
	double L=hypot(n,m)+max(n,m);
	cerr<<L;
	if(n>m){
		double R=2*hypot(n,m-1);
		if(L>R+eps) {
			cout<<0<<" "<<0<<endl;
			cout<<n<<" "<<m<<endl;
			cout<<0<<" "<<m<<endl;
			cout<<n<<" "<<0<<endl;
			return 0;
		}
		else {
			cout<<0<<" "<<1<<endl;
			cout<<n<<" "<<m<<endl;
			cout<<0<<" "<<0<<endl;
			cout<<n<<" "<<m-1<<endl;
			return 0;
		}
	}
	else {
		double R=2*hypot(n-1,m);
		if(L>R+eps) {
			cout<<0<<" "<<0<<endl;
			cout<<n<<" "<<m<<endl;
			cout<<0<<" "<<m<<endl;
			cout<<n<<" "<<0<<endl;
			return 0;
		}
		else {
			cout<<1<<" "<<0<<endl;
			cout<<n<<" "<<m<<endl;
			cout<<0<<" "<<0<<endl;
			cout<<n-1<<" "<<m<<endl;
			return 0;
		}
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long INT;
#define rt(x) ((x)*(x))
int main(){
#ifndef ONLINE_JUDGE
	freopen("in.in","r",stdin);
#endif
	int n,m;
	scanf("%d%d",&n,&m);
	if(n==1&&m==1){
		puts("1 1");
      puts("0 0");
		puts("1 0");
      puts("0 1");
		return 0;
   }
	if(n==0){
		puts("0 1");
      printf("0 %d\n",m);
      puts("0 0");
      printf("0 %d\n",m-1);
      return 0;
   }
	if(m==0){
	   puts("1 0");
      printf("%d 0\n",n);
	   puts("0 0");
      printf("%d 0\n",n-1);
		return 0;
   }
	if(n>m){
		double a=sqrt(rt(n)+rt(m-1))*2;
		double b=sqrt(rt(n)+rt(m))+n;
		if(a>=b){
		   printf("0 %d\n",m-1);
         printf("%d 0\n",n);
		   printf("0 %d\n",m);
         printf("%d 1\n",n);
			return 0;
      }
		else{
		   puts("0 0");
         printf("%d %d\n",n,m);
			printf("0 %d\n",m);
         printf("%d 0\n",n);
         return 0;
      }
   }
	else {
		double a=sqrt(rt(m)+rt(n-1))*2;
		double b=sqrt(rt(m)+rt(n))+m;
		if(a>=b){
			puts("0 0");
         printf("%d %d\n",n,m);
			puts("0 0");
         printf("%d %d\n",n-1,m);
			return 0;
      }
		else {
         puts("0 0");
         printf("%d %d\n",n,m);
			printf("%d 0\n",n);
         printf("0 %d\n",m);
			return 0;
      }
	}
}


#include<bits/stdc++.h>
using namespace std;
#define eps 1e-10
int f[1010][1010];
int main(){
#ifndef ONLINE_JUDGE
	freopen("in.in","r",stdin);
	freopen("out.out","w",stdout);
#endif
	int n,m;
	cin>>n>>m;
	if(n==0){
		cout<<0<<" "<<1<<endl;
		cout<<0<<" "<<m<<endl;
		cout<<0<<" "<<0<<endl;
		cout<<0<<" "<<m-1<<endl;
		return 0;
	}
	if(m==0){
		cout<<1<<" "<<0<<endl;
		cout<<n<<" "<<0<<endl;
		cout<<0<<" "<<0<<endl;
		cout<<n-1<<" "<<0<<endl;
		return 0;
	}
	if(n>m){
		double L=hypot(n,m)+n;
		double R=2*hypot(n,m-1);
		if(L<R-eps) {
			cout<<0<<" "<<1<<endl;
			cout<<n<<" "<<m<<endl;
			cout<<0<<" "<<0<<endl;
			cout<<n<<" "<<m-1<<endl;
			return 0;
		}
		else {
			cout<<0<<" "<<0<<endl;
			cout<<n<<" "<<m<<endl;
			cout<<0<<" "<<m<<endl;
			cout<<n<<" "<<0<<endl;
			return 0;
		}
	}
	else {
		double L=hypot(n,m)+m;
		double R=2*hypot(n-1,m);
		if(L<R-eps) {
			cout<<1<<" "<<0<<endl;
			cout<<n<<" "<<m<<endl;
			cout<<0<<" "<<0<<endl;
			cout<<n-1<<" "<<m<<endl;
			return 0;
		}
		else {
			cout<<0<<" "<<0<<endl;
			cout<<n<<" "<<m<<endl;
			cout<<0<<" "<<m<<endl;
			cout<<n<<" "<<0<<endl;
			return 0;
		}
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long INT;
#define rt(x) (x)*(x)
int main(){
#ifndef ONLINE_JUDGE
   freopen("in.in","r",stdin);
   freopen("out.out","w",stdout);
#endif
   int n,m;
   scanf("%d%d",&n,&m);
   if(n==1 and m==1) printf("1 1\n0 0\n1 0\n0 1\n");
   if(n==0) printf("0 1\n0 %d\n0 0\n0 %d\n",m,m-1);return 0;
   if(m==0) printf("1 0\n%d 0\n0 0\n%d 0\n",n,n-1);return 0;
   if(n>m){
      double a=sqrt(rt(n)+rt(m-1))*2;
      double b=sqrt(rt(n)+rt(m))+n;
      if(a>b) printf("0 1\n%d %d\n0 0\n%d %d\n",n,m,n,m-1);
      else printf("0 0\n%d %d\n0 %d\n%d 0\n",n,m,m,n);
   }
   else{
      double a=sqrt(rt(n)+rt(n-1))*2;
      double b=sqrt(rt(n)+rt(m))+m;
      if(a>b) printf("%d %d\n0 0\n%d %d\n0 1\n",n-1,m,n,m);
      else printf("0 0\n%d %d\n%d 0\n0 %d\n",n,m,n,m);
   }
   return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long INT;
#define sq(x) ((x)*(x))
int main(){
#ifndef ONLINE_JUDGE
	freopen("in.txt","r",stdin);
#endif
	int n,m;
	cin>>n>>m;
	if(n==1&&m==1){
		cout<<1<<' '<<1<<endl;
		cout<<0<<' '<<0<<endl;
		cout<<1<<' '<<0<<endl;
		cout<<0<<' '<<1<<endl;
		return 0;
	}
	if(n==0){

		cout<<0<<' '<<1<<endl;
		cout<<0<<' '<<m<<endl;
		cout<<0<<' '<<0<<endl;
		cout<<0<<' '<<m-1<<endl;
		return 0;
	}
	if(m==0){
		cout<<1<<' '<<0<<endl;
		cout<<n<<' '<<0<<endl;
		cout<<0<<' '<<0<<endl;
		cout<<n-1<<' '<<0<<endl;
		return 0;
	}
	if(n>m){
		double a=2*sqrt(sq(n)+sq(m-1));
		double b=sqrt(sq(n)+sq(m))+n;
		if(a<b){
			cout<<0<<' '<<0<<endl;
			cout<<n<<' '<<m<<endl;
			cout<<0<<' '<<m<<endl;
			cout<<n<<' '<<0<<endl;
			return 0;
		}
		else{
			cout<<0<<' '<<m-1<<endl;
			cout<<n<<' '<<0<<endl;
			cout<<0<<' '<<m<<endl;
			cout<<n<<' '<<1<<endl;
			return 0;
		}
	}
	else if(m>=n){
		double a=2*sqrt(sq(m)+sq(n-1));
		double b=sqrt(sq(m)+sq(n))+m;
		if(a<b){
			cout<<0<<' '<<0<<endl;
			cout<<n<<' '<<m<<endl;
			cout<<n<<' '<<0<<endl;
			cout<<0<<' '<<m<<endl;
			return 0;
		}
		else {
			cout<<1<<' '<<0<<endl;
			cout<<n<<' '<<m<<endl;
			cout<<0<<' '<<0<<endl;
			cout<<n-1<<' '<<m<<endl;
			return 0;
		}
	}
}


#include <bits/stdc++.h>
#include <ext/hash_map>
#include <ext/numeric>
using namespace std;
using namespace __gnu_cxx;

#define EPS      1e-9
#define F        first
#define S        second
#define pi       acos(-1)
#define ll       long long
#define oo       0x3f3f3f3f
#define sz(x)    (int)x.size()
#define sc(x)    scanf("%d",&x)
#define all(x)   x.begin(),x.end()
#define rall(x)  x.rbegin(),x.rend()

int n, m;
int main() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
#endif
  sc(n), sc(m);
  if (n == 0) {
    cout << 0 << " " << 0 << endl;
    cout << 0 << " " << m << endl;
    cout << 0 << " " << 1 << endl;
    cout << 0 << " " << m - 1 << endl;
    return 0;
  }
  if (m == 0) {
    cout << 0 << " " << 0 << endl;
    cout << n << " " << 0 << endl;
    cout << 1 << " " << 0 << endl;
    cout << n - 1 << " " << 0 << endl;
    return 0;
  }
  cout << 0 << " " << 0 << endl;
  cout << n << " " << m << endl;
  if (n > m) {
    cout << 0 << " " << m << endl;
    cout << n << " " << 0 << endl;
  } else {
    cout << n << " " << 0 << endl;
    cout << 0 << " " << m << endl;
  }
}


#include <bits/stdc++.h>
#include <ext/hash_map>
#include <ext/numeric>
using namespace std;
using namespace __gnu_cxx;

#define EPS      1e-9
#define F        first
#define S        second
#define pi       acos(-1)
#define ll       long long
#define oo       0x3f3f3f3f
#define sz(x)    (int)x.size()
#define sc(x)    scanf("%d",&x)
#define all(x)   x.begin(),x.end()
#define rall(x)  x.rbegin(),x.rend()

int n, m;
int main() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
#endif
  sc(n), sc(m);
  if (n == 0) {
    cout << 0 << " " << 1 << endl;
    cout << 0 << " " << m << endl;
    cout << 0 << " " << 0 << endl;
    cout << 0 << " " << m - 1 << endl;
    return 0;
  }
  if (m == 0) {
    cout << 1 << " " << 0 << endl;
    cout << n << " " << 0 << endl;
    cout << 0 << " " << 0 << endl;
    cout << n - 1 << " " << 0 << endl;
    return 0;
  }
  if (n == m && n == 1) {
    cout << 0 << " " << 0 << endl;
    cout << 1 << " " << 1 << endl;
    cout << 0 << " " << 1 << endl;
    cout << 1 << " " << 0 << endl;
    return 0;
  }
  if (n < m) {
    cout << n - 1 << " " << m << endl;
    cout << 0 << " " << 0 << endl;
    cout << n << " " << m << endl;
    cout << 1 << " " << 0 << endl;
  } else {
    cout << n << " " << m - 1 << endl;
    cout << 0 << " " << 0 << endl;
    cout << n << " " << m << endl;
    cout << 0 << " " << 1 << endl;
  }
}


#include <bits/stdc++.h>
#include <ext/hash_map>
#include <ext/numeric>
using namespace std;
using namespace __gnu_cxx;

#define EPS      1e-9
#define F        first
#define S        second
#define pi       acos(-1)
#define ll       long long
#define oo       0x3f3f3f3f
#define sz(x)    (int)x.size()
#define sc(x)    scanf("%d",&x)
#define all(x)   x.begin(),x.end()
#define rall(x)  x.rbegin(),x.rend()

int n, m;
int main() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
#endif
  sc(n), sc(m);
  if (n == 0) {
    cout << 0 << " " << 1 << endl;
    cout << 0 << " " << m << endl;
    cout << 0 << " " << 0 << endl;
    cout << 0 << " " << m - 1 << endl;
    return 0;
  }
  if (m == 0) {
    cout << 1 << " " << 0 << endl;
    cout << n << " " << 0 << endl;
    cout << 0 << " " << 0 << endl;
    cout << n - 1 << " " << 0 << endl;
    return 0;
  }
  if (n > m) {
    cout << 0 << " " << 0 << endl;
    cout << n << " " << m << endl;
    cout << 1 << " " << 0 << endl;
    cout << n - 1 << " " << m << endl;
  } else {
    cout << 0 << " " << 0 << endl;
    cout << n << " " << m << endl;
    cout << 0 << " " << 1 << endl;
    cout << n << " " << m - 1 << endl;
  }
}


#include <bits/stdc++.h>
#include <ext/hash_map>
#include <ext/numeric>
using namespace std;
using namespace __gnu_cxx;

#define EPS      1e-9
#define F        first
#define S        second
#define pi       acos(-1)
#define ll       long long
#define oo       0x3f3f3f3f
#define sz(x)    (int)x.size()
#define sc(x)    scanf("%d",&x)
#define all(x)   x.begin(),x.end()
#define rall(x)  x.rbegin(),x.rend()

int n, m;
int main() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
#endif
  sc(n), sc(m);
  if (n == 0) {
    cout << 0 << " " << 1 << endl;
    cout << 0 << " " << m << endl;
    cout << 0 << " " << 0 << endl;
    cout << 0 << " " << m - 1 << endl;
    return 0;
  }
  if (m == 0) {
    cout << 1 << " " << 0 << endl;
    cout << n << " " << 0 << endl;
    cout << 0 << " " << 0 << endl;
    cout << n - 1 << " " << 0 << endl;
    return 0;
  }
  if (n == m && n == 1) {
    cout << 0 << " " << 0 << endl;
    cout << 1 << " " << 1 << endl;
    cout << 0 << " " << 1 << endl;
    cout << 1 << " " << 0 << endl;
    return 0;
  }
  if (n > m) {
    cout << n - 1 << " " << m << endl;
    cout << 0 << " " << 0 << endl;
    cout << n << " " << m << endl;
    cout << 1 << " " << 0 << endl;
  } else {
    cout << n << " " << m - 1 << endl;
    cout << 0 << " " << 0 << endl;
    cout << n << " " << m << endl;
    cout << 0 << " " << 1 << endl;
  }
}


#include <bits/stdc++.h>
#include <ext/hash_map>
#include <ext/numeric>
using namespace std;
using namespace __gnu_cxx;

#define EPS      1e-9
#define F        first
#define S        second
#define pi       acos(-1)
#define ll       long long
#define oo       0x3f3f3f3f
#define sz(x)    (int)x.size()
#define sc(x)    scanf("%d",&x)
#define all(x)   x.begin(),x.end()
#define rall(x)  x.rbegin(),x.rend()

int n, m;

int dist(pair<int, int> &a, pair<int, int> &b) {
  return ((a.F - b.F) * (a.F - b.F) + (a.S - b.S) * (a.S - b.S));
}

vector<pair<int, int> > lol;
vector<pair<int, int> > best, picks;
int mx;

void solve(int i) {
  if (i == sz(lol)) {
    if (sz(picks) != 4)
      return;
    vector<pair<int, int> > tmp = picks;
    sort(all(tmp));
    do {
      int d = dist(tmp[0], tmp[1]) + dist(tmp[1], tmp[2])
          + dist(tmp[2], tmp[3]);
      if (d > mx)
        mx = d, best = tmp;
    } while (next_permutation(all(tmp)));
    return;
  }
  picks.push_back(lol[i]);
  solve(i + 1);
  picks.pop_back();
  solve(i + 1);
}

int main() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
#endif
  sc(n), sc(m);
  if (n == 0) {
    cout << 0 << " " << 1 << endl;
    cout << 0 << " " << m << endl;
    cout << 0 << " " << 0 << endl;
    cout << 0 << " " << m - 1 << endl;
    return 0;
  }
  if (m == 0) {
    cout << 1 << " " << 0 << endl;
    cout << n << " " << 0 << endl;
    cout << 0 << " " << 0 << endl;
    cout << n - 1 << " " << 0 << endl;
    return 0;
  }
  lol.push_back(make_pair(0, 0));
  lol.push_back(make_pair(n, 0));
  lol.push_back(make_pair(0, m));
  lol.push_back(make_pair(n, m));
  lol.push_back(make_pair(1, 0));
  lol.push_back(make_pair(0, 1));
  lol.push_back(make_pair(n - 1, 0));
  lol.push_back(make_pair(0, m - 1));
  lol.push_back(make_pair(n, 1));
  lol.push_back(make_pair(1, m));
  lol.push_back(make_pair(n - 1, m));
  lol.push_back(make_pair(n, m - 1));
  sort(all(lol));
  lol.resize(unique(all(lol)) - lol.begin());
  solve(0);
  for (int i = 0; i < 4; i++)
    cout << best[i].F << " " << best[i].S << endl;
}


#include <bits/stdc++.h>
#include <ext/hash_map>
#include <ext/numeric>
using namespace std;
using namespace __gnu_cxx;

#define EPS      1e-9
#define F        first
#define S        second
#define pi       acos(-1)
#define ll       long long
#define oo       0x3f3f3f3f
#define sz(x)    (int)x.size()
#define sc(x)    scanf("%d",&x)
#define all(x)   x.begin(),x.end()
#define rall(x)  x.rbegin(),x.rend()

int n, m;
int main() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
#endif
  sc(n), sc(m);
  if (n == 0) {
    cout << 0 << " " << 1 << endl;
    cout << 0 << " " << m << endl;
    cout << 0 << " " << 0 << endl;
    cout << 0 << " " << m - 1 << endl;
    return 0;
  }
  if (m == 0) {
    cout << 1 << " " << 0 << endl;
    cout << n << " " << 0 << endl;
    cout << 0 << " " << 0 << endl;
    cout << n - 1 << " " << 0 << endl;
    return 0;
  }
  cout << 0 << " " << 0 << endl;
  cout << n << " " << m << endl;
  if (n > m) {
    cout << 0 << " " << m << endl;
    cout << n << " " << 0 << endl;
  } else {
    cout << n << " " << 0 << endl;
    cout << 0 << " " << m << endl;
  }
}


#include <bits/stdc++.h>
#include <ext/hash_map>
#include <ext/numeric>
using namespace std;
using namespace __gnu_cxx;

#define EPS      1e-9
#define F        first
#define S        second
#define pi       acos(-1)
#define ll       long long
#define oo       0x3f3f3f3f
#define sz(x)    (int)x.size()
#define sc(x)    scanf("%d",&x)
#define all(x)   x.begin(),x.end()
#define rall(x)  x.rbegin(),x.rend()

int n, m;
int main() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
#endif
  sc(n), sc(m);
  if (n == 0) {
    cout << 0 << " " << 1 << endl;
    cout << 0 << " " << m << endl;
    cout << 0 << " " << 0 << endl;
    cout << 0 << " " << m - 1 << endl;
    return 0;
  }
  if (m == 0) {
    cout << 1 << " " << 0 << endl;
    cout << n << " " << 0 << endl;
    cout << 0 << " " << 0 << endl;
    cout << n - 1 << " " << 0 << endl;
    return 0;
  }
  if (n > m) {
    cout << n - 1 << " " << m << endl;
    cout << 0 << " " << 0 << endl;
    cout << n << " " << m << endl;
    cout << 1 << " " << 0 << endl;
  } else {
    cout << n << " " << m - 1 << endl;
    cout << 0 << " " << 0 << endl;
    cout << n << " " << m << endl;
    cout << 0 << " " << 1 << endl;
  }
}


#include <cstdio>
#include <iostream>
#include <cstring>
#include <cctype>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <deque>
#include <set>
#include <map>
#include <bitset>
#include <queue>
#include <list>
#include <numeric>
#include <cassert>

using namespace std;

using pii = pair<int,int>;
using vpii = vector<pii>;

void EXEC() {
	int n, m;
	cin >> n >> m;

	double ans = 0.0;
	vpii sol;

	auto renew = [&](const vpii &sol2) {
		auto cal = [](const vpii &sol) {
			auto dist = [](pii a, pii b) {
				auto sqr = [](int x) { return x * x; };
				return sqrt(sqr(a.first - b.first) + sqr(a.second - b.second));
			};
			double re = 0.0;
			for (int i = 0; i + 1 < sol.size(); ++i)
				re += dist(sol[i], sol[i + 1]);
			return re;
		};
		if (cal(sol2) > ans)
			tie(ans, sol) = make_pair(cal(sol2), sol2);
	};

	if (m >= 1)
		renew({{n, m - 1}, {0, 0}, {n, m}, {0, 1}});
	if (n >= 1)
		renew({{n - 1, m}, {0, 0}, {n, m}, {1, 0}});
	if (n >= 1 && m >= 1) {
		renew({{0, 0}, {n, m}, {0, m}, {n, 0}});
		renew({{0, 0}, {n, m}, {n, 0}, {0, m}});
	}

	for (auto &i : sol)
		cout << i.first << ' ' << i.second << endl;
}

int main() {
	EXEC();
	return 0;
}


#include <cstdio>
#include <iostream>
#include <cstring>
#include <cctype>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <deque>
#include <set>
#include <map>
#include <bitset>
#include <queue>
#include <list>
#include <numeric>
#include <cassert>

using namespace std;

using pii = pair<int,int>;
using vpii = vector<pii>;

void EXEC() {
	int n, m;
	cin >> n >> m;

	double ans = 0.0;
	vpii sol;

	auto renew = [&](const vpii &sol2) {
		auto cal = [](const vpii &sol) {
			auto dist = [](pii a, pii b) {
				auto sqr = [](int x) { return x * x; };
				return sqrt(sqr(a.first - b.first) + sqr(a.second - b.second));
			};
			double re = 0.0;
			for (int i = 0; i + 1 < sol.size(); ++i)
				re += dist(sol[i], sol[i + 1]);
			return re;
		};
		if (cal(sol2) > ans)
			tie(ans, sol) = make_pair(cal(sol2), sol2);
	};

	if (m >= 1)
		renew({{n, m - 1}, {0, 0}, {n, m}, {0, 1}});
	if (n >= 1)
		renew({{n - 1, m}, {0, 0}, {n, m}, {1, 0}});
	if (n >= 1 && m >= 1)
		renew({{0, 0}, {n, m}, {0, m}, {n, 0}});

	for (auto &i : sol)
		cout << i.first << ' ' << i.second << endl;
}

int main() {
	EXEC();
	return 0;
}


//
//  main.cpp
//  CF MemSQL Start[c]UP 2.0 - Round 1 B
//
//  Created by luras on 16/7/27.
//  Copyright (c) 2016年 luras. All rights reserved.
//

#define ms(x, y) memset(x, y, sizeof(x))
#define mc(x, y) memcpy(x, y, sizeof(x))
#define lson o << 1, l, mid
#define rson o << 1 | 1, mid + 1, r
#define ls o << 1
#define rs o << 1 | 1
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<queue>
#include<map>
#include<stack>
#include<vector>
#include<list>
#include<set>
#include<string>
#include<algorithm>
#pragma comment(linker,"/STACK:102400000,102400000")
template <class T> inline void gmax(T &a, T b){if(b > a) a = b;}
template <class T> inline void gmin(T &a, T b){if(b < a) a = b;}
using namespace std;
const int N = 1e5 + 10, M = 2e6 + 10, Z = 1e9 + 7, maxint = 2147483647, ms1 = 16843009, ms31 = 522133279, ms63 = 1061109567, ms127 = 2139062143;
const double PI = acos(-1.0), eps = 1e-8;
typedef long long LL;
void fre()
{
    freopen("/Users/luras/Desktop/in.txt", "r", stdin);
    freopen("/Users/luras/Desktop/out.txt", "w", stdout);
}
const int INF = 1e9;
int casenum, casei;

int n, m;

int main()
{
    while(~ scanf("%d%d", &n, &m)){
        if(n && m){
            if(n == m){
                printf("%d %d\n", n, n);
                printf("%d %d\n", 0, 0);
                printf("%d %d\n", n, 0);
                printf("%d %d\n", 0, n);
            }
            else if(n > m){
                printf("%d %d\n", n, m - 1);
                printf("%d %d\n", 0, 0);
                printf("%d %d\n", n, m);
                printf("%d %d\n", 0, 1);
            }
            else{
                printf("%d %d\n", n - 1, m);
                printf("%d %d\n", 0, 0);
                printf("%d %d\n", n, m);
                printf("%d %d\n", 1, 0);
            }
        }
        else if(n){
            printf("%d %d\n", 1, 0);
            printf("%d %d\n", n, 0);
            printf("%d %d\n", 0, 0);
            printf("%d %d\n", n - 1, 0);
        }
        else{
            printf("%d %d\n", 0, 1);
            printf("%d %d\n", 0, m);
            printf("%d %d\n", 0, 0);
            printf("%d %d\n", 0, m - 1);

        }
    }
    return 0;
}

/*

 题意:

 类型:
    分类讨论
 分析:

 优化:

 trick:

 数据:

 Sample Input

 Sample Output

 */


//
//  main.cpp
//  CF MemSQL Start[c]UP 2.0 - Round 1 B
//
//  Created by luras on 16/7/27.
//  Copyright (c) 2016年 luras. All rights reserved.
//

#define ms(x, y) memset(x, y, sizeof(x))
#define mc(x, y) memcpy(x, y, sizeof(x))
#define lson o << 1, l, mid
#define rson o << 1 | 1, mid + 1, r
#define ls o << 1
#define rs o << 1 | 1
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<queue>
#include<map>
#include<stack>
#include<vector>
#include<list>
#include<set>
#include<string>
#include<algorithm>
#pragma comment(linker,"/STACK:102400000,102400000")
template <class T> inline void gmax(T &a, T b){if(b > a) a = b;}
template <class T> inline void gmin(T &a, T b){if(b < a) a = b;}
using namespace std;
const int N = 1e5 + 10, M = 2e6 + 10, Z = 1e9 + 7, maxint = 2147483647, ms1 = 16843009, ms31 = 522133279, ms63 = 1061109567, ms127 = 2139062143;
const double PI = acos(-1.0), eps = 1e-8;
typedef long long LL;
void fre()
{
    freopen("/Users/luras/Desktop/in.txt", "r", stdin);
    freopen("/Users/luras/Desktop/out.txt", "w", stdout);
}
const int INF = 1e9;
int casenum, casei;

int n, m;

int main()
{
    while(~ scanf("%d%d", &n, &m)){
        if(n && m){
            if(n == m && n <= 5){
                printf("%d %d\n", n, n);
                printf("%d %d\n", 0, 0);
                printf("%d %d\n", n, 0);
                printf("%d %d\n", 0, n);
            }
            else if(n > m){
                printf("%d %d\n", n, m - 1);
                printf("%d %d\n", 0, 0);
                printf("%d %d\n", n, m);
                printf("%d %d\n", 0, 1);
            }
            else{
                printf("%d %d\n", n - 1, m);
                printf("%d %d\n", 0, 0);
                printf("%d %d\n", n, m);
                printf("%d %d\n", 1, 0);
            }
        }
        else if(n){
            printf("%d %d\n", 1, 0);
            printf("%d %d\n", n, 0);
            printf("%d %d\n", 0, 0);
            printf("%d %d\n", n - 1, 0);
        }
        else{
            printf("%d %d\n", 0, 1);
            printf("%d %d\n", 0, m);
            printf("%d %d\n", 0, 0);
            printf("%d %d\n", 0, m - 1);

        }
    }
    return 0;
}

/*

 题意:

 类型:
    分类讨论
 分析:

 优化:

 trick:

 数据:

 Sample Input

 Sample Output

 */


//
//  main.cpp
//  CF MemSQL Start[c]UP 2.0 - Round 1 B
//
//  Created by luras on 16/7/27.
//  Copyright (c) 2016年 luras. All rights reserved.
//

#define ms(x, y) memset(x, y, sizeof(x))
#define mc(x, y) memcpy(x, y, sizeof(x))
#define lson o << 1, l, mid
#define rson o << 1 | 1, mid + 1, r
#define ls o << 1
#define rs o << 1 | 1
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<queue>
#include<map>
#include<stack>
#include<vector>
#include<list>
#include<set>
#include<string>
#include<algorithm>
#pragma comment(linker,"/STACK:102400000,102400000")
template <class T> inline void gmax(T &a, T b){if(b > a) a = b;}
template <class T> inline void gmin(T &a, T b){if(b < a) a = b;}
using namespace std;
const int N = 1e5 + 10, M = 2e6 + 10, Z = 1e9 + 7, maxint = 2147483647, ms1 = 16843009, ms31 = 522133279, ms63 = 1061109567, ms127 = 2139062143;
const double PI = acos(-1.0), eps = 1e-8;
typedef long long LL;
void fre()
{
    freopen("/Users/luras/Desktop/in.txt", "r", stdin);
    freopen("/Users/luras/Desktop/out.txt", "w", stdout);
}
const int INF = 1e9;
int casenum, casei;

int n, m;

int main()
{
    while(~ scanf("%d%d", &n, &m)){
        if(n && m){
            if(n == 1 && m == 1){
                printf("%d %d\n", 1, 1);
                printf("%d %d\n", 0, 0);
                printf("%d %d\n", 1, 0);
                printf("%d %d\n", 0, 1);
            }
            else if(n >= m){
                printf("%d %d\n", n, m - 1);
                printf("%d %d\n", 0, 0);
                printf("%d %d\n", n, m);
                printf("%d %d\n", 0, 1);
            }
            else{
                printf("%d %d\n", n - 1, m);
                printf("%d %d\n", 0, 0);
                printf("%d %d\n", n, m);
                printf("%d %d\n", 1, 0);
            }
        }
        else if(n){
            printf("%d %d\n", 1, 0);
            printf("%d %d\n", n, 0);
            printf("%d %d\n", 0, 0);
            printf("%d %d\n", n - 1, 0);
        }
        else{
            printf("%d %d\n", 0, 1);
            printf("%d %d\n", 0, m);
            printf("%d %d\n", 0, 0);
            printf("%d %d\n", 0, m - 1);

        }
    }
    return 0;
}

/*

 题意:

 类型:

 分析:

 优化:

 trick:

 数据:

 Sample Input

 Sample Output

 */


//
//  main.cpp
//  CF MemSQL Start[c]UP 2.0 - Round 1 B
//
//  Created by luras on 16/7/27.
//  Copyright (c) 2016年 luras. All rights reserved.
//

#define ms(x, y) memset(x, y, sizeof(x))
#define mc(x, y) memcpy(x, y, sizeof(x))
#define lson o << 1, l, mid
#define rson o << 1 | 1, mid + 1, r
#define ls o << 1
#define rs o << 1 | 1
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<queue>
#include<map>
#include<stack>
#include<vector>
#include<list>
#include<set>
#include<string>
#include<algorithm>
#pragma comment(linker,"/STACK:102400000,102400000")
template <class T> inline void gmax(T &a, T b){if(b > a) a = b;}
template <class T> inline void gmin(T &a, T b){if(b < a) a = b;}
using namespace std;
const int N = 1e5 + 10, M = 2e6 + 10, Z = 1e9 + 7, maxint = 2147483647, ms1 = 16843009, ms31 = 522133279, ms63 = 1061109567, ms127 = 2139062143;
const double PI = acos(-1.0), eps = 1e-8;
typedef long long LL;
void fre()
{
    freopen("/Users/luras/Desktop/in.txt", "r", stdin);
    freopen("/Users/luras/Desktop/out.txt", "w", stdout);
}
const int INF = 1e9;
int casenum, casei;

int n, m;

int main()
{
    while(~ scanf("%d%d", &n, &m)){
        if(n && m){
            printf("%d %d\n", 0, 0);
            printf("%d %d\n", 0, m);
            printf("%d %d\n", n, 0);
            printf("%d %d\n", n, m);
        }
        else if(n){
            printf("%d %d\n", 0, 0);
            printf("%d %d\n", 1, 0);
            printf("%d %d\n", n - 1, 0);
            printf("%d %d\n", n, 0);
        }
        else{
            printf("%d %d\n", 0, 0);
            printf("%d %d\n", 0, 1);
            printf("%d %d\n", 0, m - 1);
            printf("%d %d\n", 0, m);

        }
    }
    return 0;
}

/*

 题意:

 类型:

 分析:

 优化:

 trick:

 数据:

 Sample Input

 Sample Output

 */


import java.io.*;
import java.util.*;

public class Main {

    private static void solve(InputReader in, OutputWriter out) {
        int n = in.nextInt();

        List<Integer> hotels = new LinkedList<>();
        for (int i = 1; i <= n; i++) {
            if (in.nextInt() == 1) {
                hotels.add(i);
            }
        }

        int[] childCount = new int[n + 1];
        int[] parent = new int[n + 1];
        for (int i = 1; i <= n; i++) {
            int p = in.nextInt();
            parent[i] = p;
            childCount[p]++;
        }

        List<Integer> maxPath = new LinkedList<>();
        int maxPathLen = 0;
        for (int obj : hotels) {
            int pathLen = 1;
            List<Integer> path = new LinkedList<>();
            path.add(obj);

            while (parent[obj] != 0 && childCount[parent[obj]] == 1) {
                obj = parent[obj];
                pathLen++;
                path.add(obj);
            }

            if (pathLen > maxPathLen) {
                maxPathLen = pathLen;
                maxPath = path;
            }
        }

        out.println(maxPathLen);
        ListIterator<Integer> lit = maxPath.listIterator(maxPath.size());
        while (lit.hasPrevious()) {
            out.print(lit.previous() + " ");
        }
    }

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

    private static void shuffleArray(int[] array) {
        int index;
        Random random = new Random();
        for (int i = array.length - 1; i > 0; i--) {
            index = random.nextInt(i + 1);
            if (index != i) {
                array[index] ^= array[i];
                array[i] ^= array[index];
                array[index] ^= array[i];
            }
        }
    }

    public static void main(String[] args) {
        InputReader in = new InputReader(System.in);
        OutputWriter out = new OutputWriter(System.out);
        solve(in, out);
        in.close();
        out.close();
    }

    private static class InputReader {
        private BufferedReader br;
        private StringTokenizer st;

        InputReader(InputStream is) {
            br = new BufferedReader(new InputStreamReader(is));
            st = null;
        }

        String nextLine() {
            String line = null;
            try {
                line = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return line;
        }

        String next() {
            while (st == null || !st.hasMoreTokens()) {
                String line = nextLine();
                if (line == null) return null;
                st = new StringTokenizer(line);
            }
            return st.nextToken();
        }

        byte nextByte() {
            return Byte.parseByte(next());
        }

        short nextShort() {
            return Short.parseShort(next());
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        void close() {
            try {
                br.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

    private static class OutputWriter {
        BufferedWriter bw;

        OutputWriter(OutputStream os) {
            bw = new BufferedWriter(new OutputStreamWriter(os));
        }

        void print(int i) {
            print(Integer.toString(i));
        }

        void println(int i) {
            println(Integer.toString(i));
        }

        void print(long l) {
            print(Long.toString(l));
        }

        void println(long l) {
            println(Long.toString(l));
        }

        void print(double d) {
            print(Double.toString(d));
        }

        void println(double d) {
            println(Double.toString(d));
        }

        void print(boolean b) {
            print(Boolean.toString(b));
        }

        void println(boolean b) {
            println(Boolean.toString(b));
        }

        void print(char c) {
            try {
                bw.write(c);
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

        void println(char c) {
            println(Character.toString(c));
        }

        void print(String s) {
            try {
                bw.write(s);
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

        void println(String s) {
            print(s);
            print('\n');
        }

        void close() {
            try {
                bw.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}


import java.util.*;
import java.io.*;

public class Main
{
    static PrintWriter out;
    public static void main(String[] args)
    {
        Scanner in = new Scanner(System.in);
        out = new PrintWriter(new BufferedOutputStream(System.out),true);
        int n = in.nextInt(),tempy;
        int[] from = new int[n+1],happens = new int[n+1];
        ArrayList<Integer> hotels = new ArrayList();
        ArrayList<Integer> ar = new ArrayList() ,temp;
        for (int i = 1; i <= n; i++)
            if (in.nextInt() == 1)
                hotels.add(i);
        for (int i = 1; i <= n; i++)
        {
            tempy = in.nextInt();
            from[i] = tempy;
            happens[tempy]++;
        }
        for (int i = 0; i < hotels.size(); i++)
        {
            temp = new ArrayList();
            int index = hotels.get(i);
            while (happens[index] < 2 && index != 0)
            {

                    temp.add(index);
                    index = from[index];
            }
            if (ar.size() < temp.size())
            {
                ar = temp;
            }
        }
        out.println(ar.size());
        for (int i = ar.size()-1; i >= 0; i--)
        {
            out.printf("%d ",ar.get(i));
        }
        out.println();
    }
}


import java.io.*;
import java.util.*;

public class Main{
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		StringTokenizer st = new StringTokenizer(br.readLine());
		boolean[] hotel = new boolean[n];
		for (int i = 0; i < n; i++)
			hotel[i] = Integer.parseInt(st.nextToken()) == 1;
		st = new StringTokenizer(br.readLine());
		int[] aa = new int[n];
		int[] dd = new int[n];
		for (int i = 0; i < n; i++) {
			int a = Integer.parseInt(st.nextToken()) - 1;
			aa[i] = a;
			if (a >= 0)
				dd[a]++;
		}
		int max = 0, imax = -1;
		for (int i = 0; i < n; i++)
			if (hotel[i]) {
				int cnt = 1;
				for (int a = aa[i]; a >= 0 && dd[a] == 1; a = aa[a])
					cnt++;
				if (max < cnt) {
					max = cnt;
					imax = i;
				}
			}
		int[] pp = new int[max];
		int cnt = 0;
		pp[cnt++] = imax;
		for (int a = aa[imax]; a >= 0 && dd[a] == 1; a = aa[a])
			pp[cnt++] = a;
		StringBuilder sb = new StringBuilder();
		for (int i = max - 1; i >= 0; i--)
			sb.append((pp[i] + 1) + " ");
		System.out.println(max);
		System.out.println(sb);
	}
}


import java.io.*;
import java.util.*;

public class Template implements Runnable {

    BufferedReader in;
    PrintWriter out;
    StringTokenizer tok = new StringTokenizer("");

    void init() throws FileNotFoundException {
        try {
            in = new BufferedReader(new FileReader("input.txt"));
            out = new PrintWriter("output.txt");
        } catch (Exception e) {
            in = new BufferedReader(new InputStreamReader(System.in));
            out = new PrintWriter(System.out);
        }
    }

    String readString() throws IOException {
        while (!tok.hasMoreTokens()) {
            try {
                tok = new StringTokenizer(in.readLine(), " :");
            } catch (Exception e) {
                return null;
            }
        }
        return tok.nextToken();
    }

    int readInt() throws IOException {
        return Integer.parseInt(readString());
    }

    int[] readIntArray(int size) throws IOException {
        int[] res = new int[size];
        for (int i = 0; i < size; i++) {
            res[i] = readInt();
        }
        return res;
    }

    long readLong() throws IOException {
        return Long.parseLong(readString());
    }

    double readDouble() throws IOException {
        return Double.parseDouble(readString());
    }

    <T> List<T>[] createGraphList(int size) {
        List<T>[] list = new List[size];
        for (int i = 0; i < size; i++) {
            list[i] = new ArrayList<>();
        }
        return list;
    }

    public static void main(String[] args) {
        new Template().run();
        // new Thread(null, new Template(), "", 1l * 200 * 1024 * 1024).start();
    }

    long timeBegin, timeEnd;

    void time() {
        timeEnd = System.currentTimeMillis();
        System.err.println("Time = " + (timeEnd - timeBegin));
    }

    long memoryTotal, memoryFree;

    void memory() {
        memoryFree = Runtime.getRuntime().freeMemory();
        System.err.println("Memory = " + ((memoryTotal - memoryFree) >> 10)
                + " KB");
    }

    public void run() {
        try {
            timeBegin = System.currentTimeMillis();
            memoryTotal = Runtime.getRuntime().freeMemory();
            init();
            solve();
            out.close();
            if (System.getProperty("ONLINE_JUDGE") == null) {
                time();
                memory();
            }
        } catch (Exception e) {
            e.printStackTrace();
            System.exit(-1);
        }
    }

    void solve() throws IOException {
        int n = readInt();
        int[] type = readIntArray(n);
        int[] v = readIntArray(n);
        for (int i=0;i<n;i++) v[i]--;
        int[] to = new int[n];
        Arrays.fill(to, -1);
        for (int i = 0; i < n; i++) {
            if (v[i] == -1) continue;
            if (to[v[i]] != -1) {
                to[v[i]] = -2;
            } else {
                to[v[i]] = i;
            }
        }
        List<Integer> withoutReferences = new ArrayList<>();
        List<Integer> answer = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            if (type[i] == 0) {
                if (v[i] == -1 || to[v[i]] == -2) {
                    withoutReferences.add(i);
                }
            } else {
                answer.clear();
                answer.add(i);
            }
        }

        for (int s : withoutReferences) {
            int cur = s;
            List<Integer> curAns = new ArrayList<>();
            boolean ok = false;
            while (true) {
                curAns.add(cur);
                if (type[cur] == 1) {
                    ok = true;
                    break;
                }
                if (to[cur] == -1 || to[cur] == -2) break;
                cur = to[cur];
            }
            if (ok) {
                if (curAns.size() > answer.size()) {
                    answer = curAns;
                }
            }
        }
        out.println(answer.size());
        for (int x : answer) {
            out.print((x + 1) + " ");
        }

    }

}


import javafx.scene.layout.Priority;

import java.io.*;
import java.lang.reflect.Array;
import java.net.Inet4Address;
import java.util.*;
import java.lang.*;
import java.util.HashMap;
import java.util.PriorityQueue;
public class templ implements Runnable {
    static class pair implements Comparable
    {
        int f,s;
        pair(int fi,int se)
        {
            f=fi;
            s=se;
        }
        public int compareTo(Object o)
        {
            pair pr=(pair)o;
            if(f>pr.f)
                return 1;
            else
                return -1;
        }
        public boolean equals(Object o)
        {
            pair ob=(pair)o;
            int ff;
            int ss;
            if(o!=null)
            {
                ff=ob.f;
                ss=ob.s;
                if((ff==this.f)&&(ss==this.s))
                    return true;
            }
            return false;
        }
        public int hashCode()
        {
            return (this.f+" "+this.s).hashCode();
        }
    }
    public class triplet implements Comparable
    {
        int f,s;
        int t;
        triplet(int f,int s,int t)
        {
            this.f=f;
            this.s=s;
            this.t=t;
        }
        public boolean equals(Object o)
        {
            triplet ob=(triplet)o;
            int ff,ss;
            int tt;
            if(o!=null)
            {
                ff=ob.f;
                ss=ob.s;
                tt=ob.t;
                if((ff==this.f)&&(ss==this.s)&&(tt==this.t))
                    return true;
            }
            return false;
        }
        public int hashCode()
        {
            return (this.f+" "+this.s+" "+this.t).hashCode();
        }
        public int compareTo(Object o)
        {
            triplet tr=(triplet)o;
            if(f>tr.f)
                return 1;
            else if(f==tr.f)
            {
                if(s>tr.s)
                    return -1;
                else
                    return 1;
            }
            else
                return -1;
        }
    }
    HashSet<Integer>hs=new HashSet<>();
    ArrayList<Integer>g[];
    int dp[],child[];
    int p;
    int m[];
    int dfs(int u,int pp)
    {
        //System.out.println(u+" "+pp);
        if(u!=p&&hs.contains(u))
        {
            child[pp]=pp;
            dp[u]=0;
            return 0;
        }
        if(m[u]>1)
        {
            child[pp]=pp;
            dp[u]=0;
            return 0;
        }
        if(u!=p&&g[u].size()==0)
        {
            child[u]=u;
            dp[u]=1;
            return 1;
        }
        if(dp[u]!=-1)
        {
            return dp[u];
        }
        for(int v : g[u])
        {
            if(v!=pp)
            {
                child[u]=v;
                dp[u]=1+dfs(v,u);
            }
        }
        return dp[u];
    }
    public static void main(String args[])throws Exception
    {
        new Thread(null,new templ(),"templ",1<<27).start();
    }
    public void run()
    {
        try
        {
            InputReader in = new InputReader(System.in);
            PrintWriter out = new PrintWriter(System.out);
            int n=in.ni();
            g=new ArrayList[n+1];
            dp=new int[n+1];
            child=new int[n+1];
            m=new int[n+1];
            Arrays.fill(dp,-1);
            for(int i=1;i<=n;i++)
                g[i]=new ArrayList<>();
            for(int i=1;i<=n;i++)
            {
                int x=in.ni();
                if(x==1)
                    hs.add(i);
            }
            for(int i=1;i<=n;i++)
            {
                int x=in.ni();
                if(x!=0)
                {
                    g[i].add(x);
                }
            }
            for(int i=1;i<=n;i++)
            {
                for(int j : g[i])
                    m[j]++;
            }
            for(int i : hs)
            {
                dp[i]=1;
                child[i]=i;
                p=i;
                dfs(p,0);
            }
            int ans=0;
            int ind=0;
            for(int i=1;i<=n;i++)
            {
                if(dp[i]>ans)
                {
                    ans=dp[i];
                    ind=i;
                }
            }
            out.println(ans);
            Stack<Integer>st=new Stack<>();
            while(true)
            {
                st.add(ind);
                if(ind==child[ind])
                    break;
                ind=child[ind];
            }
            while(!st.isEmpty())
                out.print(st.pop()+" ");
            out.close();
        }
        catch(Exception e){
            return;
        }
    }
    static class InputReader {

        private final InputStream stream;
        private final byte[] buf = new byte[8192];
        private int curChar, snumChars;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (snumChars == -1)
                throw new InputMismatchException();
            if (curChar >= snumChars) {
                curChar = 0;
                try {
                    snumChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (snumChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public int ni() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public long nl() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            long res = 0;
            do {
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public int[] nextIntArray(int n) {
            int a[] = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = ni();
            }
            return a;
        }

        public String readString() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isSpaceChar(c));
            return res.toString();
        }

        public String nextLine() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isEndOfLine(c));
            return res.toString();
        }

        public boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        private boolean isEndOfLine(int c) {
            return c == '\n' || c == '\r' || c == -1;
        }

    }
}


import javafx.scene.layout.Priority;

import java.io.*;
import java.lang.reflect.Array;
import java.net.Inet4Address;
import java.util.*;
import java.lang.*;
import java.util.HashMap;
import java.util.PriorityQueue;
public class templ implements Runnable {
    static class pair implements Comparable
    {
        int f,s;
        pair(int fi,int se)
        {
            f=fi;
            s=se;
        }
        public int compareTo(Object o)
        {
            pair pr=(pair)o;
            if(f>pr.f)
                return 1;
            else
                return -1;
        }
        public boolean equals(Object o)
        {
            pair ob=(pair)o;
            int ff;
            int ss;
            if(o!=null)
            {
                ff=ob.f;
                ss=ob.s;
                if((ff==this.f)&&(ss==this.s))
                    return true;
            }
            return false;
        }
        public int hashCode()
        {
            return (this.f+" "+this.s).hashCode();
        }
    }
    public class triplet implements Comparable
    {
        int f,s;
        int t;
        triplet(int f,int s,int t)
        {
            this.f=f;
            this.s=s;
            this.t=t;
        }
        public boolean equals(Object o)
        {
            triplet ob=(triplet)o;
            int ff,ss;
            int tt;
            if(o!=null)
            {
                ff=ob.f;
                ss=ob.s;
                tt=ob.t;
                if((ff==this.f)&&(ss==this.s)&&(tt==this.t))
                    return true;
            }
            return false;
        }
        public int hashCode()
        {
            return (this.f+" "+this.s+" "+this.t).hashCode();
        }
        public int compareTo(Object o)
        {
            triplet tr=(triplet)o;
            if(f>tr.f)
                return 1;
            else if(f==tr.f)
            {
                if(s>tr.s)
                    return -1;
                else
                    return 1;
            }
            else
                return -1;
        }
    }
    ArrayList<Integer>g[];
    int child[],dp[];
    HashSet<Integer>hs=new HashSet<>();
    void dfs(int u ,int pp)
    {
        int count=0;
        int p=0;
        for(int v : g[u])
        {
            if(v!=pp)
            {
                dfs(v,u);
                p=v;
                count++;
            }
        }
        if(count>1)
            child[u]=u;
        else
            child[u]=p;
    }
    int solve(int i)
    {
        if(i==child[i])
        {
            if(hs.contains(i))
            {
                dp[i]=1;
                return 1;
            }
            else
            {
                dp[i]=-100000000;
                return -100000000;
            }
        }
        if(hs.contains(i))
        {
            dp[i]=1;
            return 1;
        }
        if(dp[i]!=-1)
            return dp[i];
        dp[i]=1+solve(child[i]);
        return dp[i];
    }
    public static void main(String args[])throws Exception
    {
        new Thread(null,new templ(),"templ",1<<27).start();
    }
    public void run()
    {
        try
        {
            InputReader in = new InputReader(System.in);
            PrintWriter out = new PrintWriter(System.out);
            int n=in.ni();
            g=new ArrayList[n+1];
            int m[]=new int[n+1];
            child=new int[n+1];
            dp=new int[n+1];
            Arrays.fill(dp,-1);
            for(int i=1;i<=n;i++)
                g[i]=new ArrayList<>();
            for(int i=1;i<=n;i++)
            {
                int x=in.ni();
                if(x==1)
                   hs.add(i);
            }
            //out.println(hs);
            for(int i=1;i<=n;i++)
            {
                int x=in.ni();
                m[i]=x;
                if(x==0)
                    continue;
                g[x].add(i);
                g[i].add(x);
            }
            for(int i=1;i<=n;i++)
            {
                if(m[i]==0)
                {
                    dfs(i,0);
                }
            }
            for(int i=1;i<=n;i++)
            {
                if(dp[i]==-1)
                    solve(i);
            }
            int ans=0;
            int ind=0;
            for(int i=1;i<=n;i++)
            {
                if(dp[i]>ans)
                {
                    ans=dp[i];
                    ind=i;
                }
            }
            out.println(ans);
            while(true)
            {
                out.print(ind+" ");
                if(hs.contains(ind))
                    break;
                ind=child[ind];
            }
            out.close();
        }
        catch(Exception e){
            return;
        }
    }
    static class InputReader {

        private final InputStream stream;
        private final byte[] buf = new byte[8192];
        private int curChar, snumChars;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (snumChars == -1)
                throw new InputMismatchException();
            if (curChar >= snumChars) {
                curChar = 0;
                try {
                    snumChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (snumChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public int ni() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public long nl() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            long res = 0;
            do {
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public int[] nextIntArray(int n) {
            int a[] = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = ni();
            }
            return a;
        }

        public String readString() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isSpaceChar(c));
            return res.toString();
        }

        public String nextLine() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isEndOfLine(c));
            return res.toString();
        }

        public boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        private boolean isEndOfLine(int c) {
            return c == '\n' || c == '\r' || c == -1;
        }

    }
}


import javafx.scene.layout.Priority;

import java.io.*;
import java.lang.reflect.Array;
import java.net.Inet4Address;
import java.util.*;
import java.lang.*;
import java.util.HashMap;
import java.util.PriorityQueue;
public class templ implements Runnable {
    static class pair implements Comparable
    {
        int f,s;
        pair(int fi,int se)
        {
            f=fi;
            s=se;
        }
        public int compareTo(Object o)
        {
            pair pr=(pair)o;
            if(f>pr.f)
                return 1;
            else
                return -1;
        }
        public boolean equals(Object o)
        {
            pair ob=(pair)o;
            int ff;
            int ss;
            if(o!=null)
            {
                ff=ob.f;
                ss=ob.s;
                if((ff==this.f)&&(ss==this.s))
                    return true;
            }
            return false;
        }
        public int hashCode()
        {
            return (this.f+" "+this.s).hashCode();
        }
    }
    public class triplet implements Comparable
    {
        int f,s;
        int t;
        triplet(int f,int s,int t)
        {
            this.f=f;
            this.s=s;
            this.t=t;
        }
        public boolean equals(Object o)
        {
            triplet ob=(triplet)o;
            int ff,ss;
            int tt;
            if(o!=null)
            {
                ff=ob.f;
                ss=ob.s;
                tt=ob.t;
                if((ff==this.f)&&(ss==this.s)&&(tt==this.t))
                    return true;
            }
            return false;
        }
        public int hashCode()
        {
            return (this.f+" "+this.s+" "+this.t).hashCode();
        }
        public int compareTo(Object o)
        {
            triplet tr=(triplet)o;
            if(f>tr.f)
                return 1;
            else if(f==tr.f)
            {
                if(s>tr.s)
                    return -1;
                else
                    return 1;
            }
            else
                return -1;
        }
    }
    HashSet<Integer>hs=new HashSet<>();
    ArrayList<Integer>g[];
    int dp[],child[];
    int p;
    int m[];
    int dfs(int u,int pp)
    {
        //System.out.println(u+" "+pp);
        if(u!=p&&hs.contains(u))
        {
            child[pp]=pp;
            dp[u]=0;
            return 0;
        }
        if(m[u]>1)
        {
            child[pp]=pp;
            dp[u]=0;
            return 0;
        }
        if(u!=p&&g[u].size()==0)
        {
            child[u]=u;
            dp[u]=1;
            return 1;
        }
        if(dp[u]!=-1)
        {
            return dp[u];
        }
        for(int v : g[u])
        {
            if(v!=pp)
            {
                child[u]=v;
                dp[u]=1+dfs(v,u);
            }
        }
        return dp[u];
    }
    public static void main(String args[])throws Exception
    {
        new Thread(null,new templ(),"templ",1<<27).start();
    }
    public void run()
    {
        try
        {
            InputReader in = new InputReader(System.in);
            PrintWriter out = new PrintWriter(System.out);
            int n=in.ni();
            g=new ArrayList[n+1];
            dp=new int[n+1];
            child=new int[n+1];
            m=new int[n+1];
            Arrays.fill(dp,-1);
            for(int i=1;i<=n;i++)
                g[i]=new ArrayList<>();
            for(int i=1;i<=n;i++)
            {
                int x=in.ni();
                if(x==1)
                    hs.add(i);
            }
            for(int i=1;i<=n;i++)
            {
                int x=in.ni();
                if(x!=0)
                {
                    g[i].add(x);
                }
            }
            for(int i=1;i<=n;i++)
            {
                for(int j : g[i])
                    m[j]++;
            }
            for(int i : hs)
            {
                p=i;
                dfs(p,0);
            }
            int ans=0;
            int ind=0;
            for(int i=1;i<=n;i++)
            {
                if(dp[i]>ans)
                {
                    ans=dp[i];
                    ind=i;
                }
            }
            out.println(ans);
            Stack<Integer>st=new Stack<>();
            while(true)
            {
                st.add(ind);
                if(ind==child[ind])
                    break;
                ind=child[ind];
            }
            while(!st.isEmpty())
                out.print(st.pop()+" ");
            out.close();
        }
        catch(Exception e){
            return;
        }
    }
    static class InputReader {

        private final InputStream stream;
        private final byte[] buf = new byte[8192];
        private int curChar, snumChars;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (snumChars == -1)
                throw new InputMismatchException();
            if (curChar >= snumChars) {
                curChar = 0;
                try {
                    snumChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (snumChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public int ni() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public long nl() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            long res = 0;
            do {
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public int[] nextIntArray(int n) {
            int a[] = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = ni();
            }
            return a;
        }

        public String readString() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isSpaceChar(c));
            return res.toString();
        }

        public String nextLine() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isEndOfLine(c));
            return res.toString();
        }

        public boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        private boolean isEndOfLine(int c) {
            return c == '\n' || c == '\r' || c == -1;
        }

    }
}