/*
TASK:phrope
LANG:C++
*/
#include <iostream>
//#include <string>
#include <set>
//#include <conio.h>
using namespace std;
struct A
{
long long a;
long long b;
bool operator<(A i)
const{
return i.a<a;
}
};
set <A> u;
long long C,B;
long long t1,t2;
int play(long long i,long long j)
{
 //cout<<i<<" "<<j<<endl;
 if(j==0||i==0) return 0;
        A temp;
        temp.a=i;
        temp.b=j;
        int status=0;
        u.insert(temp);
        int k;
        int win=0;
        for(k=i;k>=1;k--) { temp.a=i-k;
                            temp.b=j-2*k;
                              status=0;
                            if(u.find(temp)!=u.end())
                           status=0;
                              else status=1;

                         if(status==1&&j-2*k>=0)
                         {
                         int temp1=play(i-k,j-2*k);
                         if(temp1==0) {win=1; t1=k; t2=2*k; return win;}
                         }}
         if(win==0)
         {
                 for(k=j;k>=1;k--){
                                   A temp;
                         temp.a=i-2*k;
                         temp.b=j-k;
                         status=0;
                         if(u.find(temp)!=u.end())
                              status=0;
                              else status=1;
                         if(status==1&&i-2*k>=0)
                         {
                         int temp1=play(i-2*k,j-k);
                         if(temp1==0) {win=1; t1=2*k; t2=k; return win;}
                         }}
         }
         return 0;
         }
int main()
{
//clrscr();
long long u1;
long long u2;
cin>>C>>B;

/*if(u.find(temp)!=u.end()) cout<<"bla"<<endl;
                             else cout<<"blabla"<<endl;
                          */
int solve=play(C,B);
if(solve==0) cout<<"0 0\n";
             else cout<<t1<<" "<<t2<<endl;
return 0;
}
