You have two variables a and b. Consider the following sequence of actions performed with these variables: If a = 0 or b = 0, end the process. Otherwise, go to step 2; If a ≥ 2·b, then set the value of a to a - 2·b, and repeat step 1. Otherwise, go to step 3; If b ≥ 2·a, then set the value of b to b - 2·a, and repeat step 1. Otherwise, end the process.Initially the values of a and b are positive integers, and so the process will be finite.You have to determine the values of a and b after the process ends.

The only line of the input contains two integers n and m (1 ≤ n, m ≤ 1018). n is the initial value of variable a, and m is the initial value of variable b.

Print two integers — the values of a and b after the end of the process.

NoteExplanations to the samples: a = 12, b = 5  a = 2, b = 5  a = 2, b = 1  a = 0, b = 1; a = 31, b = 12  a = 7, b = 12.

#include <iostream>

int main()
{
	unsigned long long a,b;
	std::cin>>a>>b;
	while(a!=0 && b!=0)
	{
		if(a>=2*b)
		{
			a = a%(2*b);
		}
		else if(b>=2*a)
		{
			b = b%(2*a);
		}
		else
			break;
	}
	std::cout<<a<<" "<<b<<std::endl;
}

#include <iostream>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <stack>
#include <cstdio>
#include <random>
#include <queue>

using namespace std;

#define x first
#define y second
#define mp make_pair
#define endl '\n'

typedef long long li;
typedef double ld;

const int INF = 1e9;
const long long INF64 = 1e18;
const int MOD = INF + 7;
const long long EPS = 1e-9;

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

	li a, b;

	cin >> a >> b;

	for (int i = 0; i < 100000 && a != 0 && b != 0; i++)
		if (a >= b * 2)
			a %= b * 2;
		else
			if (b >= 2 * a)
				b %= a * 2;

	cout << a << ' ' << b;

	//system("pause");
	return 0;
}

#include<iostream>

using namespace std;

int main()
{
    long long a, b;
    cin >> a >> b;

    while(a != 0 && b != 0 && (a >= 2*b || b >= 2*a))
    {
        if(a >= 2*b)
        {
            a %= (2*b);
        }
        else if(b >= 2*a)
        {
            b %= (2*a);
        }
    }

    cout << a << " " << b;
    return 0;
}

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

#define rep(i,n) for(int i=0;i<n;++i)

int main(){

	long long a, b;
	scanf("%lld %lld", &a, &b);

	while(1){

		if (a==0 | b==0) break;

		else{

			if (a/2>=b)	a -= ((a/b) - (a/b)%2) * b;

			else{
				if (b/2>=a) b -= ((b/a) - (b/a)%2) * a;
				else break;
			}
		}
	}

	printf("%lld %lld\n", a,b);
	return 0;
}

#include<iostream>
using namespace std ;
int main ()
{
	long long int x,y;
	cin>>x>>y;

	for(int i=0;i<100;i++)
	{
		if(x==0||y==0){break;}
		else if(x>=2*y){	x=x%(2*y);i--;}
		else if(y>=2*x){y=y%(2*x);i--;}
		else {break;}
	}
	cout<<x<<"  "<<y<<endl;
}

#include <iostream>

using namespace std;

void Weird(int a, int b);
 int main(){
 	long long a,b;
 	//cout<<"Inserte valores A y B"<<endl;
 	cin>> a >> b;

 	while (a !=0 && b!=0 && (a >= 2*b || b >= 2*a)){
	  if(a >= 2*b)
        {
            a %= (2*b);
        }
        else if(b >= 2*a)
        {
            b %= (2*a);
        }
	 }
	 cout<<a<<" "<<b;
 }

#include<bits/stdc++.h>
using namespace std;
int read(){
    int ans=0,flag=1;
    char ch=getchar();
    while( (ch>'9' || ch<'0') && ch!='-' ) ch=getchar();
    if(ch=='-') flag=-1,ch=getchar();
    while(ch>='0' && ch<='9') ans=ans*10+ch-'0',ch=getchar();
    return ans*flag;
}
long long a,b;
void first();
void sen();
void tir();
void first()
{
	if(a==0||b==0)
		return ;
	else
		sen();
}
void sen()
{
	if(a>=2*b){
		a%=2*b;
		if(a==0||b==0)
			return ;
	}
	if(a<2*b)
		tir();
}
void tir()
{
	if(b>=2*a)
	{
		b%=2*a;
		first();
	}
	if(b<2*a)
		return ;
}
int main()
{
	while(cin>>a>>b){
		first();
		cout<<a<<" "<<b<<endl;
	}
 	return 0;
}

//In the name of Allah

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

#define int long long
#define ll long long
#define ld long double
#define pb push_back
#define pf push_front
#define F first
#define S second
#define TL ios::sync_with_stdio(0); cin.tie(0);cout.tie(0);
const int MX=1e5+100,INF=1e18,INF2=-1e18,D=1e9+7;
int a , b;
int32_t main(){
    TL
    cin>>a>>b;
    while(a>0 && b>0&&(((b)/2)>=a || ((a)/2)>=b)){
        if(((b)/2)>=a){
            b=b%(a*2);
        }
        else{
            a=a%(b*2);
        }
    }
    cout<<a<<" "<<b<<endl;
    return 0;
}

#include <iostream>

int main() {
	long long a, b;
	std::cin >> a >> b;
	while (a != 0 && b != 0) {
		if (a >= 2*b) a %= 2 * b;
		else if (b < 2*a || a == 0) break;
		else b %= 2*a;
	}
	std::cout << a << " " << b;
	return 0;
}

#include <iostream>
using namespace std;

int main()
{
    long long a, b;
    cin >> a >> b;

    while(true)
    {
        if(a==0||b==0)
        {
            cout << a << " " << b << endl;
            return 0;
        }
        if(a>=2*b)
        a%=2*b;
        else if(b>=2*a)
        b%=2*a;
        else
        {
        cout << a << " " << b;
        return 0;
        }
    }
}

#include <stdio.h>
#include <string.h>

#define INT_MAX				 99999999
#define INT_MIN				-99999999
#define SUCCESS				0
#define MAX_DIM				20001

//signed long long input[MAX_DIM];
signed long long N;

//static to get inlined
static void test_wrapper()
{
	int test_cases, T;
	char str[50];
	signed long long correct_ans;
	signed long long i, j;
	long long a, b, c;

#ifdef WINDOWS_TEST
	/* Read number of test cases */
	scanf("%d", &T);
	for(test_cases = 1; test_cases <= T; test_cases++)
#endif
	{
		/* Read Inputs */
		scanf("%I64d %I64d", &a, &b);

		while(a > 0 && b > 0)
		{
			if(a == 0 || b == 0)
			{
				break;
			}
			else if(a >= (2 * b))
			{
				a %= (2 * b);
			}
			else if(b >= (2 * a))
			{
				b %= (2 * a);
			}
			else
			{
				break;
			}
		}

		printf("%I64d %I64d\n", a, b);
	}
}

int main()
{
	/* test wrapper function */
	test_wrapper();

	return 0;
}

#include<iostream>

using namespace std;
int main()
{
    long long a,b;
    cin>>a>>b;
    if(a>=0&&b>=0)
    {
    top:
        if(a==0||b==0)
    {
        cout<<a<<" "<<b;
        return 0;
    }
    else if(a>=2*b)
    {
        a%=2*b;
        goto top;
    }
    else if(b>=2*a)
    {
        b%=2*a;
        goto top;
    }
    else
        cout<<a<<" " <<b;
        //}while(a<0||b<0);
    return 0;
    }
}

#include<stdio.h>
int main()
{
	long long a,b;
	scanf("%lld %lld",&a,&b);
	for(int i;;i++)
	{
		A:
		if(a==0||b==0)
		break;
		else
		goto B;
		B:
		if(a>=2*b)
		{
		   a%= 2*b;
		   goto A;
	    }
		else
		goto C;
		C:
		if(b>=2*a)
		{
		b%=2*a;
			goto A;
		}
		else
		break;
	}
	printf("%lld %lld",a,b);
	return 0;
}

#include<iostream>
using namespace std;
int main()
{
	long long a, b;
	cin >> a >> b;
	while (a != 0 && b != 0) {
	    if (a >= 2 * b)a = a % (2 * b);
		if (b >= 2 * a&&a)b=b%(2 * a);
		else if(b<2*a&&a) break;
	}
	cout << a << " " << b;
	return 0;
}

#include<iostream>

using namespace std;

int main()
{
    long long int a,b;

    cin>>a>>b;

    while(1)
    {
        if(a>=2*b)
        {
            a=a%(2*b);
            if(a==0 || b==0)
                break;

        }

        else if(b>=2*a)
        {
            b=b%(2*a);
            if(a==0 || b==0)
                break;

        }
        else if(b<2*a)
            break;

    }
    cout<<a<<' '<<b;

}

#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<queue>
#include<functional>
#include<cmath>
#include<vector>
#include<stack>
#include<deque>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
int main() {
	ll a, b;
	cin >> a >> b;
	while (1) {
		if (a == 0 || b == 0)break;
		if ((a < 2 * b)&&(b < 2 * a))break;
		else (a >= 2 * b ? a = a % (2 * b) : b = b % (2 * a));
	}
	cout << a << ' ' << b;

	return 0;
}

#include <iostream>
#include <conio.h>
#include <string>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
//#pragma warning(disable:4996)
using namespace std;

int main()
{
	unsigned long long   n=0, m=0;
	cin >> n >> m;
	while (n != 0 && m != 0) //1 и 2 шаг
	{
		if (n >= 2 * m)
		{
			n%=2 * m;
		}
	 else if (m >= 2 * n)
		{
			m %=2 * n;
		}
	 else break;

	}
	cout << n << " " << m;
	//_getch();
	return 0;
}

#include <bits/stdc++.h>
#define lli long long int
#define timesave  ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
using namespace std;

int main()
{
    timesave;

    lli n, m, a, b;

    cin >> n >> m;
    a = n; b = m;

    while(1){
        if(a == 0 || b == 0) break;
        else if(a >= 2*b){
            a = a-((a/(2*b))*(2*b));
        }
        else if(b >= 2*a){
            b = b-((b/(2*a))*(2*a));
        }
        else break;
    }

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

    return 0;
}

#include <iostream>

using namespace std;

int main()
{
   long long x,y;
    cin>>x>>y;
          long long one=0;
         long long two=0;
     while(true)
     {
         if(x==0||y==0)
            break;
          one=x/y;
          two=y/x;
          if(one>=2)
          x-=(one-one%2)*y;
         else if(two>=2)
          y-=(two-two%2)*x;
          else
          break;
      one=0;
      two=0;
    }
    cout<<x<<"\t"<<y;
    return 0;
}

//#include <algorithm>
#include <iostream>
/*#include <iterator>
#include <numeric>
#include <sstream>
#include <fstream>
#include <cassert>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <string>
#include <cstdio>
#include <vector>
#include <bitset>
#include <cmath>
#include <queue>
#include <tuple>
#include <deque>
#include <stack>
#include <list>
#include <map>
#include <set>
*/
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;
typedef pair<string,int> si;
typedef pair<int,ii> iii;
/*typedef vector <si> vsi;
typedef vector <ii> vii;
typedef vector <int> vi;
typedef vector <char> vc;
typedef vector <string> vs;
typedef map <string,vs> msvs;
typedef map <string,int> msi;
typedef map <string,string> mss;
*/
//typedef FOR(i,a,b) for (int i=a;i<b;i++);

#define INF 1000000000

//using namespace std;

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

	while (a!=0 && b!=0){
		//cout << "Hola";
		//cout << a << " "<<b<<endl;

		if(a>=(2*b)){
			ll k = a/b;
			/*if(a%(2*b)){
				k-=1;
			}

			//cout <<k<<endl;
			if(a/b>1000000){
				//cout<<10000000*b<<endl;
				a-=k*b;
			}else{
				//cout <<"entro"<<endl;
				a-=2*b;
			}*/
			a=a%(2*b);

		}else if(b>=(2*a)){
			ll k = b/a;
		/*	if(b%(2*a)){
				cout <<"mod  "<<b%(2*a)<<endl;
				k-=1;
			}

			if(b/a>1000000){
				b-=k*a;
			}else{
				//cout << "entro"<<endl;
				b-=2*a;
			}
			*/
			b=b%(2*a);
		}else{
			break;
		}

	}
	cout << a << " "<<b<<endl;
	return 0;
}

#include <iostream>
using namespace std;
int main()
{
    long long int a = 0, b = 0;
    cin>>a>>b;
    while (a != 0 && b != 0)
    {
        if (a >= 2 * b)
        {
            a %= 2 * b;
        }
        else if (b >= 2 * a)
        {
            b %= 2 * a;
        }
        else {
            break;
        }
    }
    cout<<a<<" "<<b;
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define FN(i,a, n) for(i = a; i < n; i++)
#define FP(i,a, n) for(i = a; i >= n; i-- )
#define ll long long int
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb push_back
#define mp make_pair
vector <pair<ll , int>> v, v1;
vector <int>v3;
list <ll> l , l1;
map <char , int> m;
ll i , j, a, sum = 0, b , q, n;
string s;
int main(){
      IOS;
      cin >> a >> b;
      while(a && b){
          if(a >= 2*b){a %= 2*b;continue;}
          if(b >= 2*a){b %= 2*a;continue;}
          else break;
      }
      cout << a << " " << b;

}

#include <iostream>
#include <algorithm>
struct my_pair
{
	int64_t a;
	int64_t b;
};
my_pair foo_1(my_pair &t);
my_pair foo_2(my_pair &t);
my_pair foo_3(my_pair &t);

my_pair foo_4(my_pair& t) {
	auto d = std::minmax(t.a, t.b);
	my_pair r{ d.first,d.second };
	r.b = r.b % 2 * r.a;
	if (!(r.b == t.b || r.a == t.a))
		std::swap(r.a, r.b);
	return  r;
}

my_pair foo_1(my_pair &t){
	if (!(t.a == 0 || t.b == 0))
	{
		t = foo_4(t);
	}
	return t;
}
my_pair foo_2(my_pair &t) {
	if (t.a >= 2 * t.b)
	{
		t.a = t.a % (2 * t.b);
		t = foo_1(t);
	}
	else
	{
		t = foo_3(t);
	}
	return t;
}
my_pair foo_3(my_pair &t) {
	if (t.b >= 2 * t.a) {
		t.b = t.b % (2 * t.a);
		t = foo_1(t);
	}
	return t;
}

my_pair true_check(my_pair& r) {
	while (true) {
		if (r.a == 0 || r.b == 0)
			break;

		if (r.a >= 2 * r.b)
		{
			r.a = r.a % (2 * r.b);
			continue;
		}
		if (r.b >= 2 * r.a) {
			r.b = r.b % (2 * r.a);
			continue;
		}
		break;
	}
	return r;
}

int main()
{
	using namespace std;

	int64_t a, b;
	cin >> a >> b;
	my_pair r{ a,b };
	r = true_check(r);
	cout << r.a << " " << r.b;
	return 0;
}

  #include <stdio.h>
   int main()
   {
		long long a,b;
		scanf("%I64d %I64d",&a,&b);
		while(a&&b)
		{
			if(a/2>=b)
			{
				a = a%(2*b);
				continue;
			}
			else if(b/2>=a)
			{
				b= b%(2*a);
				continue;
			}
			else break;
		}
		printf("%I64d %I64d\n",a,b);
   }

#include <bits/stdc++.h>
using namespace std;
#define clr(a, x) memset(a, x, sizeof(a))
#define mp(x, y) make_pair(x, y)
#define pb(x) push_back(x)
#define X first
#define Y second
#define fastin                    \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);
typedef long long ll;
typedef long double ld;
typedef pair<int, int> PII;
typedef vector<int> VI;
const int INF = 0x3f3f3f3f;
const int mod = 1e9 + 7;
const double eps = 1e-6;

int main()
{
#ifndef ONLINE_JUDGE
    freopen("1.in", "r", stdin);
    freopen("1.out", "w", stdout);
#endif
    ll a, b;
    cin >> a >> b;
    while (a && b)
    {
        if (a >= b * 2)
            a %= (b * 2);
        else if (b >= a * 2)
            b %= (a * 2);
        else
            break;
    }
    cout << a << " " << b << endl;
    return 0;
}

/*********************************************************************\
    codeforces = Alhelal_ONE  ||  topcoder = Al..helal                |
    mail = alhelaliu@gmail.com                                        |
    CSE,Islamic University,Kushtia                                    |
**********************************************************************/
using namespace std;
#include<bits/stdc++.h>
typedef long long int   LL;
typedef   pair<LL,LL>  PII;
typedef   vector< PII > VPII;
typedef   vector<LL>   VI;
typedef   map<LL,LL>  MII;
///Scanf
#define sf(n)       scanf("%lld", &n)
#define sff(a,b)    scanf("%lld %lld", &a, &b)
#define sfff(a,b,c) scanf("%lld %lld %lld", &a, &b, &c)
///Printf
#define pf(a)  printf("%lld",a)
#define pff(a,b)  printf("%lld %lld",a,b)
#define nl printf("\n")
#define spc printf(" ")
#define line   printf("____________________________________\n")
#define case(no) printf("Case %lld: ",++no)
#define caseline(no) printf("Case %lld:\n",++no)
///LOOP
#define FORSTL(x,n) for(__typeof(n.begin()) x=n.begin();x!=n.end();x++)
#define repp(x,n) for(__typeof(n) x=1;x<=(n);x++)
#define rep(x,n) for(__typeof(n) x=0;x<(n);x++)
#define reps(i,s) for(int i=0;i<s.size();i++)
///Shortcut
#define Unique(store) store.resize(unique(store.begin(),store.end())-store.begin())
#define mem(ar,value) memset(ar,value,sizeof(ar))
#define all(x) x.begin(),x.end()
#define len(s) s.size()
#define mp make_pair
#define pb push_back
#define EPS (1e-9)
///DEBUG
#define trace(x) cerr<<x<<endl;
#define F(x) cerr<<__FUNCTION__<<":"<<__LINE__<<": "#x" = "<<x<<endl;
#define FF(x,y) cerr<<__FUNCTION__<<":"<<__LINE__<<": "#x" = "<<x<<" | "#y" = "<<y<<endl;
#define FFF(x,y,z) cerr<<__FUNCTION__<<":"<<__LINE__<<": "#x" = "<<x<<" | "#y" = "<<y<<" | "#z" = "<<z<<endl;
/**Define Bitwise operation**/
#define check(n, pos) (n & (1<<(pos)))
#define biton(n, pos) (n | (1<<(pos)))
#define bitoff(n, pos) (n & ~(1<<(pos)))
#define ledzero(n) (__builtin_clz(n))
#define trailzero(n) (__builtin_ctz(n))
#define onbit(n) (__builtin_popcount(n))
///upper bound and lower bound
#define LB(a,value) (lower_bound(all(a),value)-a.begin())
#define UB(a,value) (upper_bound(all(a),value)-a.begin())
#define PI acos(-1.0)
#define isEq(a,b) (fabs((a)-(b))<eps)
#define spDist(lat1,long1,lat2,long2,r) ((r)*acos(sin(lat1)*sin(lat2)+cos(lat1)*cos(lat2)*cos((long1)-(long2))))
#define area(x1,y1,x2,y2,x3,y3) ( x1*(y2-y3) + x2*(y3-y1) + x3*(y1-y2) )
#define distSqr(x1,y1,x2,y2) ( sqr(x1-x2) + sqr(y1-y2) )
#define dist4adj(x1,y1,x2,y2) ( abs(x1-x2) + abs(y1-y2) )
#define dist8adj(x1,y1,x2,y2) max( abs(x1-x2) , abs(y1-y2) )
///File
#define READ freopen("INPUT.txt","r",stdin)
#define WRITE freopen("OUTPUT.txt","w",stdout)
#define IOS ios_base::sync_with_stdio(false), cin.tie(false)
///NUMBER THEORY
template<class T>T gcd(T a,T b){return b == 0 ? a : gcd(b, a % b);}
template<typename T>T lcm(T a, T b) {return a / gcd(a,b) * b;}
template<class T>T my_pow(T n,T p){if(p==0)return 1;T x=my_pow(n,p/2);x=(x*x);if(p&1)x=(x*n);return x;} ///n to the power p
template<class T>T big_mod(T n,T p,T m){if(p==0)return (T)1;T x=big_mod(n,p/2,m);x=(x*x)%m;if(p&1)x=(x*n)%m;return x;}
template<typename T> T ModInverse(T n,T m) { return BigMod(n,m-2,m); }
///string to int
string itos(LL n){string s;while(n){s+=(n%10+48);n/=10;}reverse(all(s));return s;}
LL stoi(string s){LL n=0;rep(i,len(s))n=n*10+(s[i]-48);return n;}
/// GEOMETRY
//double DEG(double x) { return (180.0*x)/(PI);}
//double RAD(double x) { return (x*(double)PI)/(180.0);}
//template<typename T> T DIS(T x1,T y1,T x2, T y2){return sqrt( (double)( (x1-x2)*(x1-x2) + (y1-y2)*(y1-y2) ) );}
//template<typename T> T ANGLE(T x1,T y1,T x2, T y2){ return atan( double(y1-y2) / double(x1-x2));}
//template<typename T> LL isLeft(T a,T b,T c) { return (c.x-a.x)*(b.y-a.y)-(b.x-a.x)*(c.y-a.y); }
///Direction Array
///int fx[]={1,-1,0,0}; int fy[]={0,0,1,-1};
/// int fx[]={0,0,1,-1,-1,1,-1,1}; int fy[]={-1,1,0,0,1,1,-1,-1};
///struct info{LL x,y;}arr[N];bool com(info a,info b){return (a.x<b.x) or (a.x==b.x and a.y<b.y);}
///=======================================CODING=================================================///
const  long long int N=5e5+5,MOD=1e9+7,inf=1e18*1LL;
//LL ar[N],A[N];
LL a,b,c,r,rr,n,m,t,ks;
string s,ss;
int main()
{
    //READ;
    //IOS;
    cin>>n;cin>>m;
    while(n>0 && m>0)
    {

        if(n>=2LL*m)
        {
            //n=(n%2LL*m);
            LL aa=n/(2LL*m);
            n-=(aa*2LL*m);
        }
        else if(m>=(2LL*n))
        {
            LL aa=m/(2LL*n);
            m-=(aa*2LL*n);
        }
        else  break;

       // cout<<n<<" "<<m<<endl;
    }

    cout<<n<<" "<<m<<"\n";

     return 0;
}
///============= ALLAH HAFIZ ===================///

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
#define MAXP = 100000
#define FOR (a,b,c) for (int i=a;i<b; i+=c)
long long int a, b;
int rec() {
	if (a == 0 || b == 0) {
		return 0;
	}
		if (a >= (2 * b)) {
			a = (a - (2 * b))%(2*b);
			rec();
		}
		else {
			if (b >= (2 * a)) {
				b = (b - (2 * a)) % (2*a);
				rec();
			}
			else {
				return 0;
			}
		}
}
int main()
{
	cin >> a >> b;
	//rec();
	while (a != 0 || b != 0) {
		if (a >= (2*b)) {
			a = (a - (2 * b)) % (2 * b);
			if (a == 0 || b == 0)
				break;
		}
		else {
			if (b >= (2 * a)) {
				b = (b - (2 * a)) % (2 * a);
				if (a == 0 || b == 0)
					break;
			}
			else {
				break;
			}
		}
	}
	cout << a << " " << b;

    return 0;
}

 #include<bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
long long nCr(int n, int r)
{
    if(r > n - r) r = n - r; // because C(n, r) == C(n, n - r)
    long long ans = 1;
    int i;
    for(i = 1; i <= r; i++) {
        ans *= n - r + i;
        ans /= i;
    }
    return ans;
}
int main()
{
    IOS;
    long long a,b,c,d,e,g,h,n,t,f,k,l,m,f1=0,flag=0,flag1=0,co=0,co1=0,co2=0,arr1[100001]={0},arr[100001]={0},sum=0,sum1=0,ma=0,mi=1000000000000000001;
    long long co3=0,co4=0,co5=0,co6=0,co7=0,co8=0,mul=1;
    double pi=2 * acos (0.0);
    string str,str1,str2,str3;
    char ch;
    vector<long long>v;
    vector<long long>v1;
    vector<string>vs;
    vector<string>vs1;
    map<char,int>mp;
    map<char,int>mp1;
    set<long long>s;
    set<long long>s1;
    set<long long>::iterator it;
    queue<long long> q;
    //map<string,string>::iterator it;
    //vector< pair<char,int > > v;
    //vector< pair<char,int > > v1;
    int x[]={1,1,1,0,0,-1,-1,-1};
    int y[]={0,1,-1,1,-1,1,-1,0};
    cin>>a>>b;
    if(a>b)
    {
        c=a/b;
        if(c%2!=0)
            c--;
        a=a-(c*b);
    }
    else
    {
        c=b/a;
        if(c%2!=0)
            c--;
        b=b-(c*a);
    }
    if(a==0 || b==0)
    {
        cout<<a<<" "<<b<<endl;
        return 0;
    }

    while(1)
    {
        if(a>b)
        {
            if((a/b)>=2)
            {
                if((a/b)%2!=0)
                {
                    a=a-(b*((a/b)-1));
                }
                else a=a%b;
                if(a==0)
                    break;
            }
            else break;
        }
        else
        {
            if((b/a)>=2)
            {
                if((b/a)%2!=0)
                {
                    b=b-(a*((b/a)-1));
                }
                else b=b%a;
                if(b==0) break;
            }
            else break;
        }
        if(a==1 || b==1)
        {
            flag=1;
            break;
        }
    }
    if(flag==1)
    {
        if(a>b)
        {
            cout<<a%2<<" "<<b<<endl;
            return 0;
        }
        else if(b>a)
        {
            cout<<a<<" "<<b%2<<endl;
            return 0;
        }
        else
        {
            cout<<a<<" "<<b<<endl;
            return 0;
        }
    }
    cout<<a<<" "<<b<<endl;
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
int main()
{
      long long n,m;
      cin>>n>>m;
      while(n>0&&m>0){
            if(n>=2*m){
                n=n%(2*m);
                continue;
            }
            if(n<2*m){
                if(m>=2*n){
                    m=m%(2*n);
                    continue;

                }
                else break;
            }
            if(n==0||m==0)break;
      }
      cout<<n<<" "<<m;
}

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

using namespace std;
typedef long long ll;

int main()
{
    /*ll a,b;
    cin >> a >> b;
    int flag =0;
    if(a<b){
        swap(a,b);
    }
    while( a > 0 && b > 0){
        a %= 2*b;
        if ( b < 2*a ) break;
        else{
            swap(a,b);
            flag++;
        }
    }

    if(flag%2) cout << b << " " << a << endl;
    else cout << a << " " << b << endl;*/
         ll a,b;
    cin >> a >> b;
    int flag = 0;
    while( a > 0 && b > 0){
        a %= 2*b;
        if ( b > a ){
            swap(a,b);
            flag++;
        }
        if ( b*2 > a ) break;
    }

    if(flag%2) cout << b << " " << a << endl;
    else cout << a << " " << b << endl;
    return 0;
}

#include<iostream>
#include<stdio.h>
#include<vector>
#include<ctype.h>
#include<cstdio>
#include<string.h>
#include<algorithm>
#define ll long long

using namespace std;

//ll i=0, j=0,k=0;
//a = 12 b =5
//a=2 b=5
//a=2 b=1
//a=0 b=1

ll solve(ll &a, ll &b){
    while(a!=0 && b!=0){
        if(a >= 2*b){
            a %= (2*b);
            }
        else if(b >= 2*a){
            b %= (2*a);
                }
        else break;
    }
    cout<<a<<" "<<b;
return 0;
}

int main(){
    ll a,b;
    cin>>a>>b;
    solve(a,b);
    return 0;
}

#include <iostream>

using integer = unsigned long long;

void answer(integer x, integer y)
{
    std::cout << x << ' ' << y << '\n';
}

void solve(integer n, integer m)
{
    while (n != 0 && m != 0) {
        if (n >= 2 * m) {
            n %= 2 * m;
            continue;
        }
        if (m >= 2 * n) {
            m %= 2 * n;
            continue;
        }
        break;
    }

    answer(n, m);
}

int main()
{
    integer n, m;
    std::cin >> n >> m;

    solve(n, m);

    return 0;
}

#include <bits/stdc++.h>
using namespace std;
int main()
{
    long long int a,b;
    cin>>a>>b;
    while(a&&b)
    {
        if(a>=2*b)
            a%=(2*b);
        else if(b>=2*a)
            b%=(2*a);
        else
            break;
    }
    cout<<a<<" "<<b;

}

#include<iostream>
using namespace std;
main(){
long long int a,b;
cin>>a>>b;
while(a!=0&&b!=0)
{
    if(a>=2*b)
        a=a%(2*b);
    else if(b>=2*a)
        b=b%(2*a);
    else
        break;
}
cout<<a<<" "<<b<<endl;
}

#include <iostream>

using namespace std;

int main()
{
    unsigned long long int b,a,n,m,S1=0,x,S2=0,i,OK=1;
    cin>>n>>m;
    a=n;
    b=m;
    while (a!=0 && b!=0 && OK==1)
    {
        OK=0;
        if (a>=2*b)
        {
            x=a/(2*b);
            a=a-x*(2*b);
            OK=1;
        }
        if (b>=2*a && OK==0)
        {
            x=b/(2*a);
            b=b-x*(2*a);
            OK=1;
        }
    }
    cout<<a<<" "<<b;
    return 0;
}

#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll rec(ll n,ll m){
  if(n==0||m==0){
      cout<<n<<" "<<m;
        return 0;;
  }
  else if(n>=2*m)
  {
      n=n%(2*m);
      rec(n,m);
  }
  else if(m>=n*2){
    m=m%(2*n);
    rec(n,m);
  }
  else{
    cout<<n<<" "<<m;
    return 0;
  }
}
int main()
{
 ll n,m;
 cin>>n>>m;
 rec(n,m);
 return 0;
}

// 2003803.cpp: 定义控制台应用程序的入口点。
//
#include <bits/stdc++.h>
using namespace std;
int main()
{
	long long a, b;
	cin >> a >> b;
	while (a&&b)
	{
		if (a >= 2 * b)
		{
			a = a % (2 * b);
			continue;
		}
		else if (b >= 2 * a)
		{
			b = b % (2 * a);
			continue;
		}
		else
			break;
	}
	cout << a<<" " << b;
	return 0;
}

#define _CRT_SECURE_NO_WARNINGS
#include <numeric>
#include <functional>
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <string>
#include <fstream>
using namespace std;

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

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

int mod = 1000000007;

inline int add(int a, int b) {
	int ret = a + b;
	if (ret >= mod)
		ret -= mod;
	return ret;
}

const double pi = 3.14159265358979323846;

//const int MAXN = 1e5 + 1;
//int arr[MAXN];

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	long long n, m;
	cin >> n >> m;
	while (n&&m) {
		if (n >= 2 * m) n %= 2*m;
		else if (m >= 2 * n) m %= 2*n;
		else break;
	}
	cout << n << ' ' << m;
	/*system("pause");*/
	return 0;
}

#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <cmath>

using namespace std;
int main() {
	long long int n, m;
	cin >> n >> m;
	while (n != 0 && m != 0) {
		if (n >= (2 * m)) {
			n = n % (2 * m);
		}
		else if (m >= (2 *n)) {
			m = m % (2 * n);
		}
		else {
			cout << n << ' ' << m;
			return 0;
		}
	}

	cout << n << ' ' << m;
	return 0;
}

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
int main()
{
    ll a,b;
    cin>>a>>b;
    while ((a!=0)||(b!=0)){
        if (a>=2*b){a=a%(2*b);}else
            {
                if(b>=2*a){b=b%(2*a);}else{break;}
            }
            if((a==0)||(b==0)){break;}
    }
    cout<<a<<' '<<b<<endl;
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
//#define 100000007 1000000007
#define ll long long
int main()
{
    ll a,b;
    cin>>a>>b;
    while(true)
    {
    if(a==0LL || b==0LL)
    {
        cout<<a<<" "<<b;
        return 0;
    }
    else if(a>=2LL*b)
    {
        a=a%(2*b);
        continue;
    }
    else if(b>=2*a)
    {
        b=b%(2*a);
        continue;
    }
    else{
            cout<<a<<" "<<b;
        return 0;
    }
    }
}

#include<bits/stdc++.h>
using namespace std;
int main()
{
    unsigned long long a, b;
    cin>>a>>b;
    while(a!=0&&b!=0)
    {
        if(a>=2*b)
        {
            a %= (2*b);
        }
        else if(b>=2*a)
        {
            b %= (2*a);
        }
        else
        {
            break;
        }
    }
    cout<<a<<' '<<b<<endl;
    return 0;
}

#include<iostream>
using namespace std;

long long int a, b;

int main(){
	cin >> a >> b;

	while(1){
		if(a==0 || b==0)break;
		else if(a >= 2*b)a %= 2*b;
		else if(b >= 2*a)b %= 2*a;
		else break;
	}

	cout << a << " " << b ;
	return 0;
}

#include<bits/stdc++.h>
#define ll long long
#define maxx 1000000
using namespace std;
int main()
{
    ll a,b,c,d;
    cin>>a>>b;
    for(;;)
    {
        c=2*b;
        d=2*a;
       // cout<<c<<' '<<d<<endl;
        if(a==0||b==0)
        {
             cout<<a<<' '<<b;
             return 0;
        }
        else if(a>=c)
            a=a-c*(a/c);
        else if(b>=d)
            b=b-d*(b/d);
        else
        {
            cout<<a<<' '<<b;
            return 0;
        }
    }

}

//http://codeforces.com/problemset/problem/946/B

#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(0);cin.tie(0);

using namespace std;
long long a, b;

void process(){
    if(a == 0 || b==0) return;
    if(a >= 2*b){
        a=a - 2*b;
        process();
    }else if (b >= 2*a){
        b=b-2*a;
        process();
    } else return;
}

int main(){_
    cin>>a>>b;
    while(true){
        if(a==0 || b==0) break;
        else if(a>=2*b){
            a=a%(2*b);
        }else if(b>=2*a){
            b=b%(2*a);
        } else break;
    }
    cout<<a<<" "<<b;
}

#include <iostream>

int main()
{
	unsigned long long a,b;
	std::cin>>a>>b;
	while(a!=0 && b!=0)
	{
		if(a>=2*b)
		{
			a = a%(2*b);
		}
		else if(b>=2*a)
		{
			b = b%(2*a);
		}
		else
			break;
	}
	std::cout<<a<<" "<<b<<std::endl;
}

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

void firstStep(long long &a,long long  &b) {
	if(!(a==0 || b==0)){
		if(a>=2*b){
		a%=2*b;
		firstStep(a,b);
	}

	else
		if(b>=2*a){
			b%=2*a;
		   firstStep(a,b);
		}
	}

}

int main()
{
	long long a,b;

	scanf("%I64d %I64d ",&a,&b);
	firstStep(a,b);

	printf("%I64d %I64d ",a,b);

}

#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<set>
#include <initializer_list>
#include<unordered_set>
#include<map>
#include<cmath>
#include <iterator>
#include<stack>
#include<queue>
#include <iomanip>
#include<math.h>
#include <limits.h>
#include <numeric>
#include <functional>
using namespace std;
void past_code();
//bool fml(int l,int z);
//pair<int,int>a[100005];
//pair<int,int>b[100005];

/*int fml (int x ,int y)
{
	if (x>=y)
		return x-y;
	else{

	if (y%2==0)
	return 1+fml(x,y/2);

	else
		return  1+fml(x,y+1);
	}

}*/

/*int n,a,b,c;
int d[4001];
int omg (int n)
{
	if (n<=0)
		return 0;
	if (d[n]!=-1)
		return d[n];
	int r=-10000000;
	if(n>=a)
		r=max(r,omg(n-a)+1);
	if (n>=b)
		r=max(r,omg(n-b)+1);
	if (n>=c)
		r=max(r,omg(n-c)+1);
	return d[n]=r;
}*/
//int y[300001];
/*int q[501];
int y[101];
int l[2];*/
//int y[1001];
//bool y[3002];
//char c[100];
//bool q[101];
string s,t;
int c=0;
long double sum=0;
void gg(int a,int n,double p)
{
	if (a==t.length())
	{
		if (n==c)
		sum=sum+p;
	}
	else if (t[a]=='+')
		return gg(a+1,n+1,p);
	else if (t[a]=='-')
	 gg(a+1,n-1,p);

	else
	{
		 gg(a+1,n-1,p/2);
		 gg(a+1,n+1,p/2);
	}
}
int main(){
	long long x,y;
	cin>>x>>y;
	while (true)
	{
		//cout<<"hh\n";
		x=x%(2*y);
		if (x==0)
			break;
		y=y%(2*x);
		if (y==0)
			break;
		if((y*2)>x &&(x*2)>y)
			break;
	}
	cout<<x<<" "<<y<<endl;
	return 0;
}

#include <iostream>

using namespace std;

void weird(int a, int b);
 int main(){
 	long long a,b;
 	//cout<<"Inserte valores A y B"<<endl;
 	cin>> a >> b;

 	while (a !=0 && b!=0 && (a >= 2*b || b >= 2*a)){
	  if(a >= 2*b)
        {
            a %= (2*b);
        }
        else if(b >= 2*a)
        {
            b %= (2*a);
        }
	 }
	 cout<<a<<" "<<b;
 }

#include <bits/stdc++.h>

#define loop(n) for(int  i= 0 ; i< (n) ; i++)
#define ll long long
#define vi vector<int>
#define ii pair<int,int>

using namespace std;

int main() {

    cin.tie(0);
	cin.sync_with_stdio(0);

    ll a , b; cin >> a >> b;

    h1:;
    if(a==0 || b==0){
        goto out ;
    }
    else{
        if(a>=2*b){
            a = a%(2*b) ;
            goto h1 ;
        }
        else{
            if(b>=2*a){
                b = b%(2*a) ;
                goto h1 ;
            }
            else{
                goto out ;
            }
        }

    }

    out :;
    cout << a<<" "<< b ;

}

#include <iostream>

using namespace std;
int main()
{
	 long long int  a, b;
	cin >> a >> b;

	for ( int i = 0; true; i++) {
		if (a == 0 || b == 0)
		{
			break;
		}
		else if (a >= (2 * b))
		{
			a = (a % (2 * b));
		}
		else if (b >= (2 * a))
		{
			b = (b % (2 * a));

		}
		else
		{
			break;
		}

	}

cout << a << '\t' << b << endl;

return 0;
}

#include<iostream>
using namespace std;
long long n,m;
int main()
{
    cin>>n>>m;
    while(n&&m)
        if(n>=2*m)n%=2*m;
        else if(m>=2*n)m%=2*n;
        else break;
    cout<<n<<' '<<m<<endl;
    return 0;
}

#include <iostream>
#define LL long long
using namespace std;
int main(){
  LL a,b;
  cin>>a>>b;
  while (a>0 && b>0){
    if(a>=2*b) a%=2*b;
    else if (b>=2*a) b%=2*a;
    else break;
  }
  cout<<a<<" "<<b;
  return 0;
}

#include <iostream>
#include <stdint.h>
#include <vector>
#include <algorithm>
#include <string>
#include <math.h>

using namespace std;
int a[100000];

int main()
{
	int64_t a,b;
	cin >> a >> b;
	while (a && b)
	{
		if (a >= 2 * b)
		{
			a %= 2 * b;
		}
		else if (b >= 2 * a)
		{
			b %= 2 * a;
		}
		else break;
	}
	cout << a << " " << b << endl;
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll a,b;
void s1();
void s3();
void s2();

int main()
{
	cin>>a>>b;
	s1();
	cout<<a<<' '<<b;
	return 0;
}

void s2()
{
	if(a>=2*b)
	{
		a-=a/(2*b)*2*b;
		s1();
	}
	else
	s3();
}

void s1()
{
	if(a==0||b==0) return;
	else
	s2();
}

void s3()
{
	if(b>=2*a)
	{
		b-=b/(2*a)*2*a;
		s1();
	}
	else
	return;
}

#include <bits/stdc++.h>
using namespace std;
long long a,b;
int main() {
    cin >> a >> b;
    while (a>0 && b>0) {
        if (a>=2*b) a%=2*b;
        else
            if (b>=2*a) b%=2*a;
        else
        break;
    }
    cout<< a << ' ' << b;
    return 0;
}

#include<bits/stdc++.h>
#define r_0 return 0
#define pb push_back
#define ll long long
#define ld long double
#define pf push_front
#define fr first
#define se second
#define Time ios_base::sync_with_stdio(0);
using namespace std;
ll n,m,x,y,t, ans,res, sum, mx, mn = 1e9,z,cnt;
string s,s1,s3, s2, s4,s5;
set<char>st;
set<int>::iterator it;
pair<int , int>pr;
vector<ll>v,v1,v2,v3,v4;
map<int, int>mp , mpp;
char a, b, c,d;
bool tr = false, fl = false;
ll used[10001];
vector< pair< int , int  >> vp;

int main()
{
      cin >> n >> m;
      for ( int i = 0; i < 100000; i ++ ){
          if ( n ){
             if ( n % (2 * m) <= 0 ){
                 n = 0; break; }
             else
                 n %= (2 * m);
          }
         if ( m ){
            if ( m %( 2 * n) <= 0 ){
                   m= 0; break; }
            else
                m %= 2 * n;
         }
      }
      if ( n - ( 2 * m ) >= 0 )
        cout << n - 2 * m << " " << m;
      else
        cout << n << " " << m;

}

///made
///by

#include <iostream>
using namespace std;

int main() {
    unsigned long long a, b;
    cin >> a  >> b;
    while (a && b) {
        if (a >= 2*b) {
            a %= 2*b;
        }else if (b >= 2*a) {
            b %= 2*a ;
        }else{
            break;
        }
    }
    cout  << a << ' ' << b;
    return 0;
}

#include <bits/stdc++.h>

using namespace std;

typedef long long int lli;

long double n, m;
lli paso2;
lli paso3;

int main () {
    //freopen("0in.txt", "rt", stdin);
    //freopen("0out.txt", "wt", stdout);

    cout.precision(19);
    cin >> n >> m;
    while (true) {
        if (n >= 2.0 * m) {
            paso2 = lli((n - 2.0 * m) / (2.0 * m)) + 1;
            n -= paso2 * 2.0 * m;
        }
        if (m >= 2.0 * n) {
            paso3 = lli((m - 2.0 * n) / (2.0 * n)) + 1;
            //cout << "Pasos 3: " << paso3 << endl;
            m -= paso3 * 2.0 * n;
        }
        else break;
        //cout << n << " " << m << endl;
        if (n <= 0 || m <= 0) break;
        //system("PAUSE>NULL");
    }
    cout << n << " " << m << endl;

    return 0;
}

#include<iostream>
using namespace std;

int main()
{
	unsigned long long int n, m;
	cin >> n >> m;
	while (n&&m && (m>=2*n ||n>=2*m))
	{
		n = n % (2 * m);
		if (n>0)
			m = m % (2 * n);
	}
	cout << n << ' ' << m << endl;
	return 0;
}

#include <iostream>
#include <fstream>

using namespace std;
long long a ,b;

int main()
{

	//freopen("input.txt","r",stdin);

   scanf("%lld %lld",&a,&b);

    while(1)
    {
    	if(a==0 || b==0) break;
    	if(a>= (2*b))
    	{
    		a=a%(2*b);

    	}
    	else if(b>=(2*a))
    	{
    		b=b%(2*a);

    	}
    	else
    	  break;

    }

    cout<<a<<" "<<b;
    return 0;

}

#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <algorithm>
#include <time.h>
//#include <math.h>
#include <cmath>
#include <fstream>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <stdlib.h>
#include <cstdio>
//#include <stdio.h>

using namespace std;

#define flu fflush(stdout)
#define gg return 0
#define mp make_pair

long long mod = 27449/*1e9 + 7*/;
int inf = 1e9;
double eps = 1e-2;

ifstream in("input.txt");
ofstream out("output.txt");

long long ans = 0;

int main()
{
	long long a, b;
	cin >> a >> b;
	while (1)
	{
		if (a == 0 || b == 0)
		{
			break;
		}
		if (a >= 2 * b)
		{
			a %= 2 * b;
			continue;
		}
		if (b >= 2*a)
		{
			b %= 2 * a;
			continue;
		}
		break;
	}
	cout << a << " " << b;
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
int const Mod=1e9+7,M=2e5+10,INF=1e9+10;
int n;
int bpow(int x,int y)
{
	if(y==0)return 1;
	int tmp=bpow(x,y/2);
	if(y%2==0)return (tmp*tmp)%Mod;
	else return ((tmp*tmp)%Mod*x)%Mod;
}
int cil(int x,int y)
{
	if(x%y==0)return x/y;
	return x/y+1;
}
int32_t main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int a,b;
	cin>>a>>b;
	while(true)
	{
		//cout<<a<<" "<<b<<endl;
		if(a==0 || b==0)return cout<<a<<" "<<b,0;
		if(a>=2*b)
		{
			int tmp=a-b;
			int res=tmp/(2*b);
			a-=res*(2*b);
			if(a>=2*b)a-=2*b;
		}
		else if(b>=2*a)
		{
			int tmp=b-a;
			int res=tmp/(2*a);
			b-=res*(2*a);
			if(b>=2*a)b-=2*a;
		}
		else return cout<<a<<" "<<b,0;
	}
}

#include <iostream>

using namespace std;

int main()
{
	unsigned long long a, b; cin >> a >> b;

	while (a && b)
	{
		if (a >= 2 * b)
		{
			unsigned long long hanyszor = (unsigned long long)round((double)((a - b) / (2 * b)));
			a -= hanyszor * 2 * b;
			if (a >= 2 * b) a -= 2 * b;
		}
		else if (b >= 2 * a)
		{
			unsigned long long hanyszor = (unsigned long long)round((double)((b - a) / (2 * a)));
			b -= hanyszor * 2 * a;
			if (b >= 2 * a) b -= 2 * a;
		}
		else break;
	}

	cout << a << ' ' << b;

	return 0;
}

#include <iostream>
using namespace std;

unsigned long long int a, b;

int main()
{
	cin >> a >> b;
	if (!a || !b) {
		cout << a << " " << b;
		return 0;
	}
	while (a&&b && ((a >= 2 * b) || (b >= 2 * a))) {
		a = a % (2 * b);
		if (a) b = b % (2 * a);
	}
	cout << a << " " << b;
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
int main()
{
    long long int a,b;
  cin>> a >> b;
    while(a!=0 && b!=0)
    {
        if(a>=2*b)
        {
            a=a%(2*b);

        }
         else if(b>=2*a)
        {
            b=b%(2*a);

        }
        else
        {
            break;
        }

    }
     cout<<a<<" "<<b;
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
bool case1,case2,case3;

int main(){
       unsigned long long a,b;
      cin>>a>>b;

       if(a==0 || b== 0)case1= true;
       else if(a>=2*b){ case2 = true; }
       else case3 = true;
       while(case1 || case2 || case3){
              if(case1){
                        if(a==0 || b==0)break;
                       else { case1 = case3 = false;
                       case2 = true;
                        }
            }
            else if(case2){
                  if(a>=2*b){
                  a = a - 2* b* (a/(2*b));
                 case2 = false; case1 = true; }
                  else{ case2 = false; case3 = true; } }
              else if(case3){ if(b>=2*a){
                   b = b - a*2* (b/(2*a));

                 case3 = false; case1 = true; } else break; } }
    cout<<a<<" "<<b<<endl;
    return 0;
}

#include <iostream>

#define ll long long
using namespace std;
int flag=1;
int main() {
    ll a,b;
    cin>>a>>b;
    while(flag!=0){
        if(flag==1){
            if(a==0 || b==0 ){
                flag=0;
            }else{
                flag=2;
            }
        }else if(flag==2){
            if(a>=2*b){
                if(a%(2*b)==0){
                    a=0;
                }else{
                    ll temp = a / (2*b);
                    a -= temp*2*b;
                }
                flag=1;
            }else{
                flag=3;
            }
        }else if(flag==3){
            if(b>=2*a){
                if(b%(2*a)==0){
                    b=0;
                }else{
                    ll temp = b / (2*a);
                    b -= temp*2*a;
                }

                flag=1;
            }else{
                flag=0;
            }
        }

    }
    cout<<a<<" "<<b<<endl;
    return 0;
}

#include <bits/stdc++.h>

using namespace std;
typedef  long long LL;
typedef pair<int,int> P;
typedef pair<int,pair<int,int>> PP;
//typedef   unordered_map<string,void *> mstop;
int dx[8]={0,0,1,-1,1,-1,1,-1};
int dy[8]={1,-1,0,0,1,-1,-1,1};
struct pair_hash {
    inline std::size_t operator()(const std::pair<LL,LL> & v) const {
        return v.first*31+v.second;
    }
};

int main()
{
    //freopen("input", "r", stdin);
    //freopen("output", "w", stdout);
    //ios_base::sync_with_stdio(false);
    //cin.tie(NULL);
    long long a,b;
    cin>>a>>b;
    while(a!=0&&b!=0){
    //  cout<<a<<" "<<b<<endl;
      if(a-b>=b){a=a-(a/(2*b))*2*b;}
      else if(b-a>=a){b=b-(b/(2*a))*2*a;}
      else break;
    }
    cout<<a<<" "<<b<<endl;
}

#include <bits/stdc++.h>
using namespace std;
int main(void)
{
	long long int a,b;
	cin>>a>>b;
	while(a!=0&&b!=0)
	{
		if(a>=(2*b))
		{
			long long int temp = a/(2*b);
			a-=temp*2*b;
			continue;
		}
		else
		{
			if(b>=2*a)
			{
				b-=b/(2*a)*(2*a);
				continue;
			}
			else break;
		}
	}
	cout<<a<<" "<<b;
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
unsigned long long int a, b;

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

	cin>>a>>b;
	while(1)
	{
		if(a==0 || b==0)
			break;
		if(a>=2*b)
		{
			long long int temp=a/b;
			if(temp>=4)
			{
				a-=(temp/2)*2*b;
			}
			else
			a-=2*b;
		}
		else
		if(b>=2*a)
		{
			long long int temp=b/a;
			if(temp>=4)
			{
				b-=(temp/2)*2*a;
			}
			else
			b-=2*a;
		}
		else
			break;
	}
	cout<<a<<" "<<b;
}

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

int main() {
	long long a,b,i;
	cin >> a >> b;
	for(i=0;i<200;i++) {
	    if(a>=2*b and a!=0 and b!=0) {
	        a = a%(2*b);
    	}
    	if(b>=2*a and a!=0 and b!=0) {
    	    b = b%(2*a);
	    }
	}
// 	cout << a << ' ' << b << '\n';
	while(1) {
	    if(a==0 or b==0) {
	        cout << a << ' ' << b;
	        return 0;
	    }
	    else {
	        if(a>=2*b) {
	            a -= 2*b;
	        }
	        else {
	            if(b>=2*a) {
	                b-=2*a;
	            }
	            else {
	                cout <<a << ' ' << b;
	                return 0;
	            }
	        }
	    }
	}
	return 0;
}

#include <bits/stdc++.h>
#define mx(a, b) (a > b ? a : b)
#define mn(a, b) (a < b ? a : b)
#define all(v) (v).begin(), (v).end()
#define f first
#define s second

using namespace std;

int cant;

void recur(long long a, long long b){
    int cant = 0;
    while(a && b && (a >= 2 * b || b >= 2 * a)){
        if(a > b){
            swap(a, b);
            cant++;
        }
        long long aux = b / ( a * 2 );
        b -= aux * (a * 2);
    }
    if(cant % 2) cout<<b<<" "<<a;
    else cout<<a<<" "<<b;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    long long a, b;
    cin>>a>>b;
    recur(a,b);
    return 0;
}

#include <bits/stdc++.h>
#define sf scanf
#define pf              printf
#define sf(a)           scanf("%d",&a)
#define sfl(a)          scanf("%lld",&a)
#define sff(a,b)        scanf("%d %d",&a,&b)
#define sffl(a,b)       scanf("%lld %lld",&a,&b)
#define sfff(a,b,c)     scanf("%d %d %d",&a,&b,&c)
#define sfffl(a,b,c)    scanf("%lld %lld %lld",&a,&b,&c)
#define ms(a,b)         memset(a,b,sizeof(a))
#define pb(a)           push_back(a)
#define db              double
#define ft              float
#define ll              long long
#define ull             unsigned long long
#define ff              first
#define ss              second
#define sz(x)           x.size()
#define qu              queue
#define pqu             priority_queue
#define vc              vector
#define vi              vector<int>
#define vll             vector<long long>
#define pii             pair<int,int>
#define pis             pair<int,string>
#define psi             pair<string,int>
#define all(x)          x.begin(),x.end()
#define CIN             ios_base::sync_with_stdio(0); cin.tie(0)
#define loop0(i,n)      for(int i=0;i<n;i++)
#define loop1(i,n)      for(int i=1;i<=n;i++)
#define stlloop(x)     for(__typeof(x.begin()) it=x.begin();it!=x.end();it++)
#define gcd(a, b)       __gcd(a, b)
#define lcm(a, b)       ((a)*((b)/gcd(a,b)))
#define case1(z)         cout<<"Case "<<z<<": "
#define case2(z,x)       cout<<"Case "<<z<<": "<<x<<endl
#define PI              3.14159265358979323846264338328
#define valid(tx,ty)    tx>=0 && tx<r && ty>=0 && ty<c
#define intlim          2147483648
#define MAX             2000
#define inf             10000000

using namespace std;

int main()
{
	ll a,b,k=1;

	scanf("%I64d %I64d",&a,&b);

	while(1){

		if(a==0 || b==0)
		    break;

		else if(a>=2*b){

			k=a/(2*b);

			a=a-2*b*k;

			continue;

		}

		else if(b>=2*a){

			k=b/(2*a);

			b=b-2*a*k;

			continue;
		}

		else{

			break;
		}

	}

	pf("%I64d %I64d\n",a,b);

}

#include<iostream>
using namespace std;

int main()
{
	long long a, b; cin >> a >> b;

	while (a != 0 && b !=0)
	{
		if (a >= 2 * b)
		{
			long long n = a / (2 * b);
			a = a - n * 2 * b;
		}

		else if (b >= 2 * a)
		{
			long long n = b / (2 * a);
			b = b - n * 2 * a;
		}

		if (a < 2 * b &  b < 2 * a) { break; }
	}
	cout << a << " " << b << endl;
	return 0;
}

#include <bits/stdc++.h>

using namespace std;

int main()
{
    unsigned long long a, b, c;

    ios_base::sync_with_stdio( false ), cin.tie( nullptr ), cout.tie( nullptr ), cin >> a >> b;

    loop:
        if ( a >= ( c = b << 1 ) && ( a %= c ) > 0 )
            goto loop;

        if ( a > 0 && b >= ( c = a << 1 ) && ( b %= c ) > 0 )
            goto loop;

    cout << a << ' ' << b;
}

#include <iostream>
#include<cstring>
#include<cstdio>
#include<string>
#include<algorithm>
#include<cmath>
#include<map>
#include<iomanip>
#include<queue>
#include<set>
#include<stack>
#include<functional>
using namespace std;
int step1(long long &a, long long &b)
{
	if (a == 0 || b == 0)
		return 0;
	else
		return 2;
}
int step2(long long &a, long long &b)
{
	if (a >= 2 * b)
	{
		a = a % (2 * b);
		return 1;
	}
	else
		return 3;
}
int step3(long long &a, long long &b)
{
	if (b >= 2 * a)
	{
		b = b % (2 * a);
		return 1;
	}
	else
		return 0;
}
int main()
{
	long long a, b;
	int x;
	cin >> a >> b;
	if (a == 0 || b == 0)
	{
		cout << a << " " << b;
		return 0;
	}
	else
		x = 2;
	while (x != 0)
	{
		if (x == 1)
			x = step1(a, b);
		else if (x == 2)
			x = step2(a, b);
		else if (x == 3)
			x = step3(a, b);
	}
	cout << a << " " << b << endl;
	return 0;
}

#include <iostream>
using namespace std;
int main()
{
    long long a, b;
    cin >> a >> b;

    while(a != 0 && b != 0 && (a >= 2*b || b >= 2*a))
    {
        if(a >= 2*b)
        {
            a %= (2*b);
        }
        else if(b >= 2*a)
        {
            b %= (2*a);
        }
    }

    cout << a << " " << b;
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
long long n,m;
int main()
{
    long long div;
    cin>>n>>m;
    while(1)
    {
        if(n==0||m==0) return !printf("%I64d %I64d",n,m);
        if(n>=2*m);
        div=n/(2*m);
        n-=div*(2*m);
        if(n==0||m<2*n) return !printf("%I64d %I64d",n,m);
        div=m/(2*n);
        m-=div*2*n;
    }
    return 0;
}

#include <bits/stdc++.h>

#define inf 0x3f3f3f3f

#define INF 0x3f3f3f3f3f3f3f3fLL

#define MOD 1000000007

#define pb push_back

#define sq(x) ((x)*(x))

#define x first

#define y second

#define eps 1e-8

#define bpt(x) (__builtin_popcount(x))

#define bptl(x) (__builtin_popcountll(x))

#define bit(x, y) (((x)>>(y))&1)

#define bclz(x) (__builtin_clz(x))

#define bclzl(x) (__builtin_clzll(x))

#define bctz(x) (__builtin_ctz(x))

#define bctzl(x) (__builtin_ctzll(x))

using namespace std;

typedef long long INT;

typedef vector<int> VI;

typedef pair<int, int> pii;

typedef pair<pii, int> pi3;

typedef double DO;

template<typename T, typename U> inline void smin(T &a, U b) {if (a>b) a=b;}

template<typename T, typename U> inline void smax(T &a, U b) {if (a<b) a=b;}

template<typename T> inline void gn(T &x) {char c, sg=0; while (c=getchar(), (c>'9' || c<'0') && c!='-');for((c=='-'?sg=1, c=getchar():0), x=0; c>='0' && c<='9'; c=getchar()) x=(x<<1)+(x<<3)+c-'0';if (sg) x=-x;}

template<class T, class T1>inline void gn(T &x, T1 &y) {gn(x); gn(y);}

template<class T, class T1, class T2>inline void gn(T &x, T1 &y, T2 &z) {gn(x); gn(y); gn(z);}

template<typename T> inline void print(T x) {if (x<0) {putchar('-');return print(-x);}if (x<10) {putchar('0'+x);return;} print(x/10);putchar(x%10+'0');}

template<typename T> inline void println(T x) {print(x), putchar('\n');}

template<typename T> inline void printsp(T x) {print(x), putchar(' ');}

template<class T, class T1> inline void print(T x, T1 y) {printsp(x), println(y);}

template<class T, class T1, class T2> inline void print(T x, T1 y, T2 z) {printsp(x), printsp(y), println(z);}

int power(int a, int b, int m, int ans=1) {

	for (; b; b>>=1, a=1LL*a*a%m) if (b&1) ans=1LL*ans*a%m;

	return ans;

}

int main() {

#ifndef ONLINE_JUDGE

	freopen("in.in", "r", stdin);

	freopen("out.out", "w", stdout);

#endif

	INT a, b;

	gn(a, b);

	while(a && b){

		if(a>b){

			INT k=a/b;

			if(k%2) k--;

			if(k){

				a-=b*k;

				continue;

			}

		}

		if(b>a){

			INT k=b/a;

			if(k%2) k--;

			if(k){

				b-=a*k;

				continue;

			}

		}

		break;

	}

	print(a, b);

	return 0;

}

#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long a,b;
	cin>>a>>b;
	bool f=0;
	while(1)
	{
		if(a==0||b==0)break;
		f=0;
		if(a>=2*b)
		{
			a%=(2*b);
			f=1;
   		}
		if(a==0||b==0)break;
		if(b>=2*a)
		{
			b%=(2*a);
			f=1;
		}
    	if(f==0)
    	{
    		break;
		}
	}
	cout<<a<<' '<<b<<endl;
	return 0;
}

#include <iostream>

using namespace std;

int main()
{
    long long int a,b;
    cin>>a;
    cin>>b;

    while (a!=b)

    {    if (a==0 || b==0)
        {cout<<a<<" "<<b;
          return(0);}

        else if (a>=2*b) { a=a % (2*b);}
        else if (2*a<=b) { b=b % (2*a);}
        else break;

    }
        cout<<a<<" "<<b;

    return 0;
}

#include <iostream>

using namespace std;

void proc(long long int &a,long long int &b)
{
    if(a == 0 || b == 0)
        return;
    if(a >= 2*b)
    {
        a %= 2 * b;
        proc(a,b);
        return;
    }
    if(b >= 2*a)
    {
        b %= 2*a;
        proc(a,b);
        return;
    }
}

int main()
{
    long long int a,b;
    cin >> a >> b;
    proc(a,b);
    cout << a << " " << b << endl;
}

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
int main()
{
	LL a,b;
	cin>>a>>b;
	while(a!=0&&b!=0)
	{
		if(a>=2*b)
			a=a%(2*b);
		else if(b<2*a)
			break;
		else
		{
			LL k1=(2*b+3*a-1)/(4*a);
			LL k2=b/(2*a);
			if(k1>k2)
			{
				b=b-2*k2*a;
				break;
			}
			else
				b=b-2*k1*a;
		}
	}
	cout<<a<<" "<<b<<endl;
	return 0;
}

#include <stdio.h>

int main() {
	long long a, b;
	scanf("%I64d %I64d", &a, &b);
	while (a != 0 && b != 0) {
		if (a >= 2 * b) {
			long long times = (a - 2 * b) / (2 * b);
			if (times == 0) times++;
			a = a - 2 * b * times;
			continue;
		}
		else if (b >= 2 * a) {
			long long times = (b - 2 * a) / (2 * a);
			if (times == 0) times++;
			b = b - 2 * a * times;
		}
		else {
			break;
		}
	}
	printf("%I64d %I64d\n", a, b);

	return 0;
}

#include <bits/stdc++.h>

using namespace std;

int main() {
	long long a, b;

	cin >> a >> b;

	while (true) {
		if (a == 0 || b == 0) {
			break;
		}
		else if (a >= 2 * b) {
			a %= 2 * b;
		}
		else if (b >= 2 * a) {
			b %= 2 * a;
		}
		else {
			break;
		}
	}

	cout << a << ' ' << b;

	return 0;
}

#include<iostream>
using namespace std;
int main()
{
	long long a, b;
	cin >> a >> b;
	while (a != 0 && b != 0) {
	    if (a >= 2 * b)a = a % (2 * b);
		if (b >= 2 * a&&a)b=b%(2 * a);
		else if(b<2*a&&a) break;
	}
	cout << a << " " << b;
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
int main(){
    long long int a,b,flag = 0;
    cin>>a>>b;
    while(flag == 0){
        if(a == 0 || b == 0){
            flag = 1;
        }
        else if(a>=(2*b)){
            a = a%(2*b);
        }
        else if(b>=(2*a)){
            b = b%(2*a);
        }
        else{
            flag = 1;
        }
    }
    cout<<a<<" "<<b;
    return 0;
}

#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll a,b;
int main(){
	scanf("%lld%lld",&a,&b);
	if(a==0||b==0){
		printf("%lld %lld",a,b);
		return 0;
	}
	do{
		if(a>=2*b) a%=2*b;
		if(a==0) break;
		if(b>=2*a) b%=2*a;
		if(b==0) break;
	}while(a>=2*b);
	printf("%lld %lld",a,b);
	return 0;
}

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

typedef long long ll;

ll a, b;

int main()
{
	cin >> a >> b;
	while (a && b)
		if (a >= 2 * b) a %= 2 * b;
		else if (b >= 2 * a) b %= 2 * a;
		else break;
	cout << a << " " << b << endl;
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll a,b;
void s1();
void s3();
void s2();

int main()
{
	cin>>a>>b;
	s1();
	cout<<a<<' '<<b;
	return 0;
}

void s2()
{
	if(a>=2*b)
	{
		a-=a/(2*b)*2*b;
		s1();
	}
	else
	s3();
}

void s1()
{
	if(a==0||b==0) return;
	else
	s2();
}

void s3()
{
	if(b>=2*a)
	{
		b-=b/(2*a)*2*a;
		s1();
	}
	else
	return;
}

#include <bits/stdc++.h>

using namespace std;

int main(){
  long long a,b;
  cin>>a>>b;

  while(1)
  {
  if(a == 0||b == 0)
  {
  cout<<a<<" "<<b;
  return 0;
  }
  else if(a >= 2 * b)
  {

  if( (a / b) % 2 == 0)
 {
  a = a - b * (a/b);
  }
  else{
  a = a - b * ((a/b) - 1);
  }

  }

  else if(b >= 2 * a){
 if( (b / a) % 2 == 0)
 {
  b = b - a * (b/a);
  }
  else{
  b = b - a * ((b/a) - 1);
  }

  }
  else{
  cout<<a<<" "<<b;
  return 0;
  }
  }
  }

#include <iostream>

using namespace std;

int main()
{
    long long int a,b;
    cin>>a>>b;
    for(;;)
    {
        if(a==0||b==0)
        {
            break;
        }
        if(a>=2*b)
        {
            a%=(2*b);
        }
        if(a==0||b==0)
        {
            break;
        }
        if(b>=2*a)
        {
            b%=(2*a);
        }
        else
        {
            break;
        }
    }
    cout<<a<<' '<<b<<endl;
    return 0;
}

#include <iostream>

using namespace std;

int main(void) {

	unsigned long long a, b;
	cin >> a >> b;
	while (a && b) {
		if (a >= 2 * b) {
			a %=2 * b;
			continue;
		}
		if (b >= 2 * a) {
			b %=2 * a;
			continue;
		}
		else break;
	}
	cout << a << " " << b;

	return 0;
}

#include<iostream>
#include<vector>
#include<algorithm>
#include<limits>
#define sort(vec) sort(vec.begin(),vec.end())
using namespace std;
typedef unsigned long long ull;

long n,a,b,c,d;
void input(int arr[],int n)
{
	for(int c=0;c<n;++c)
		cin>>arr[c];
}
void output(int arr[],int n)
{
	for(int c=0;c<n;++c)
		cout<<arr[c];
}
int main()
{
	cin>>a>>b;
	while(a&&b)
	{
		if(a>2*b)	a-=2*b;
		else if(b>2*a) b-=2*a;
		else break;
	}
	cout<<a<<' '<<b;
	return 0;
}

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define For(i,a,b) for(int (i)=(a);(i) < (b); ++(i))
#define rof(i,a,b) for(int (i)=(a);(i) > (b); --(i))
#define coud(a,b) cout<<fixed << setprecision((b)) << (a)
#define iOS ios_base::sync_with_stdio(false),cout.tie(NULL),cin.tie(NULL)
#define Error(a,b) cerr<<"( "<<#a<<" , "<<#b<<" ) = ( "<<(a)<<" , "<<(b)<<" )\n";
#define errop(a) cerr<<#a<<" = ( "<<((a).x)<<" , "<<((a).y)<<" )\n";
#define error(x) cerr << #x << " = " << (x) <<endl
#define all(a) a.begin() , a.end()
#define double long double
#define pb push_back
#define PB pop_back()

typedef long long ll;
typedef pair<ll,ll>pii;
typedef vector<int> vi;
typedef complex<ll> point;

const ll maxn=1e18-1;
const int delta=1e9+7;
int32_t  main()
{
 iOS;
 int temp1,temp2,temp3,sum=0,n,m,k;
 int a,b;
 cin>>n>>m>>k;
 int timee[n][m];
 string s;
 For(i,0,n)
 {
     cin>>s;
     For(j,0,m)
     {
         if(s[j]=='0')
         {
             timee[i][j]=0;
         }
         else if(s[j]=='1')
         {
             timee[i][j]=1;
         }
     }
 }
 int x=0,big=0,y=0,check=0,delx=0,dely=0;
 For(i,0,k)
 {
 big=0;
 y=0;
 check=0;
 delx=0;
 dely=0;
 x=0;
     For(j,0,n)
     {
         rof(c,m-1,-1)
         {
             if(timee[j][c]==1 && check==1)
                {
                    x=c;
                    break;
                }
                 if(timee[j][c]==1 && check==0)
                {
                    y=c;
                    x=c;
                    ++check;
                }
         }
         cout<<y<<' '<<x<<endl;
         check=y-x+1;
         if(check>big)
         {
             big=check;
             delx=y;
             dely=j;
         }
     }

    timee[dely][delx]=0;
 }
  For(i,0,n)
 {
     For(j,0,m)
     {
        cout<<timee[i][j];
     }
     cout<<endl;
 }
}

#include<bits/stdc++.h>
using namespace std;
int main(){
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	long long int a,b,i,j,k;
	cin>>a>>b;
	while(a>0&&b>0){
		if(a==1||b==1){
			if(a==1){
				if(b%2==0){
					b=0;
				}
				else b=1;
			}
			if(b==1){
				if(a%2==0){
					a=0;
				}
				else a=1;
			}
			break;
		}
		if(a>=2*b){
			k=a/b;
			a=a%b;
			if(k%2==1&&a==1)
			 a=b+a;
		}
		else if(b>=2*a){
			k=b/a;
			b=b%a;
			if(k%2==1&&b==1)
			 b=a+b;
		}
		else break;
		//cout<<a<<" "<<b<<endl;
	}
	cout<<a<<" "<<b;
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
// #define
#define ve vector<ll>
#define ll long long
int main() {
    ll a,b;
    cin>>a>>b;
    while(1){
        // cout<<a<<" "<<b<<endl;
        if(a == 0 or b == 0)
            break;
        else if(a >=(2*b)){
            if(a/b > 2){
                a = a%b + b;
            }
            else
                a = a%b;
        }
        else if(b>=(2*a)){
            if(b/a > 2){
                b = b%a + a;
            }
            else
                b = b%a;
        }
        else
            break;
    }
    cout<<a<<" "<<b<<endl;
    return 0;
}

#include<cstdio>
int main(){
	int a,b;
	scanf("%d%d",&a,&b);
	while(a&&b){
		if(a>=b<<1){
			a-=b<<1;
			continue;
		}
		else if(b>=a<<1){
			b-=a<<1;
			continue;}
		else break;
	}
	printf("%d %d",a,b);
	return 0;
}

#include<bits/stdc++.h>

using namespace std;

#define SET(x) memset(x, 0, sizeof(x))
#define SETBOOL(x) memset(x,false,sizeof(x))
#define CLR(x) memset(x, -1, sizeof(x))
#define mp make_pair
#define p printf

#define s scanf

#define ll long long

#define pb push_back

#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define np std::string::npos

//this fuction sorts vector pair according to first element in descending order.
bool sortinrev(const pair<int,int> &a,const pair<int,int> &b)
{
    return a.first>b.first;
}

int main()

{
	IOS;
	ll n,m;
	while(cin>>n>>m)
    {
        int a,b;
        if(n>m)
        {
            if((m*2)>n) {cout<<m<<" "<<n<<endl; continue;}
            else
            {
                a=(n%(m*2));
                b=(m%(a*2));
            }
        }
        else
        {
            if((n*2)>m) {cout<<m<<" "<<n<<endl; continue;}
            else
            {
                a=(m%(n*2));
                b=(n%(a*2));
            }
        }
        if(a==2 && b==1) cout<<0<<" "<<1<<endl;
        else if(a==1 && b==2) cout<<1<<" "<<0<<endl;
        else cout<<a<<" "<<b<<endl;
    }

	 return 0;

}

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ii pair<int,int>
int main()
{
	ll a,b;
	cin>>a>>b;
	while(1)
	{
		if(a==0 || b==0) break;
		if(a>=2*b)
		{
			ll d=a/(b*2);d--;
			if(d>1)
			{
				a-=d*b;
			}
			else
			{
				a-=2*b;
			}
		}
		else if(b>=2*a)
		{
			ll d=b/(a*2);d--;
			if(d>1)
			{
				b-=d*a;
			}
			else
			{
				b-=2*a;
			}
		}
		else break;
	}
	cout<<a<<" "<<b<<endl;
}

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define inf 1e18
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
ll n,k,i,cnt=0,a,b,mn=INT_MIN,mx=0,aa,bb,sum;
cin>>a>>b;
mn=min(a,b);
mx=max(a,b);
sum=mx%(mn*2);
if(sum==0||sum==mn)
  {cout<<sum<<" "<<mn;return 0;}

while(1)
  {if(sum>=2*mn)
     sum-=2*mn;
  else if(mn>2*sum)
    mn-=2*sum;
    else {aa=sum;bb=mn;break;}
    if(sum<0||mn<0)
    {aa=sum;bb=mn;break;}
    else if(sum==0||mn==0)
    { aa=sum;bb=mn;break;}

    else {aa=sum;bb=mn;}}

     cout<<aa<<" "<<bb;}

#include<iostream>
using namespace std;
int main()
{
	int a;
	int b;
	cin >> a >> b;
	int c = abs(a - b);

	for (int i = 0; i < c; i++) {

		if (a == 0 && b == 0)
		{

			break;
		}
		else if (a >= 2 * b)
		{
			a = a - (2 * b);

		}
		else if (b >= 2 * a)
		{
			b = b - (2 * a);
		}
		else
			break;
	}

	cout << a << " " << b;
}

#include<bits/stdc++.h>
using namespace std;
main()
{
    int a,b,a1,b1;
    cin>>a>>b;
    while(1)
    {
    if(a==0||b==0)
    {
        break;
    }
    else if(a>=2*b)
    {
        a=a-2*b;
        if(a==0)
        {
            break;
        }
    }
    else if(b>=2*a)
    {
        b=b-2*a;
        if(b==0)
        {
            break;
        }
    }
    else if(a!=0&&b!=0&&a>!2*b&&b>!2*a)
    {
        a1=a;
        b1=b;
        break;
    }
    }
    if(a1==a&&b1==b)
    {
        cout<<a1<<" "<<b1<<endl;
    }
    else
    cout<<a<<" "<<b<<endl;

}

/*
                       _oo0oo_
                      o8888888o
                      88" . "88
                      (| -_- |)
                      0\  =  /0
                    ___/`---'\___
                  .' \\|     |// '.
                 / \\|||  :  |||// \
                / _||||| -:- |||||- \
               |   | \\\  -  /// |   |
               | \_|  ''\---/''  |_/ |
               \  .-\__  '-'  ___/-. /
             ___'. .'  /--.--\  `. .'___
          ."" '<  `.___\_<|>_/___.' >' "".
         | | :  `- \`.;`\ _ /`;.`/ - ` : | |
         \  \ `_.   \_ __\ /__ _/   .-` /  /
     =====`-.____`.___ \_____/___.-`___.-'=====
                       `=---='

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  Jaspreet singh  @jsar3004  Codechef/codeforces/topcoder
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
#include<bits/stdc++.h>
 #include<algorithm>
 #include <iterator>
// #include "boost/algorithm/string.hpp"
#define needforspeed ios_base::sync_with_stdio(false)
#define ll long long int
#define llu unsigned long long int
#define ld long double
#define revp(i,n) for(i=(n-1);i>=0;i--)
#define ff1(i,a,b) for(ll i=a;i<b;i++)
#define ff2(i,a,b) for(ll i=b;i>=a;i-=c)
#define pb push_back
#define pp pair<int,int>
#define mp make_pair
#define fi first
#define se second
#define in insert
#define INTMAX 1000001000
#define ddouble long double
#define PI 3.1415926535
#define coutd(x) cout << fixed << setprecision(x)
#define DECIMAL(n)  std::cout << std::fixed << std::setprecision(n);

using namespace std;
int maxint = numeric_limits<int>::max();
void filterChar(char *a,int no)
{
    int i=0;
    while(no>0)
    {
        if((no&1)==0)
        {
            cout<<"";
        }
        else
        {
            cout<<a[i];
        }
        i++;
        no=no>>1;
    }
    cout<<"\n";
}
void generatesubsets(char *a)
{
    int n=strlen(a);
    int range =(1<<n)-1;
    for(int i=1;i<=range;i++)
    {
        filterChar(a,i);
    }
}
ll revsum(ll a)
{
    ll sum=0;
    while(a!=0)
    {
        sum+=a%10;
        a=a/10;
    }
    return sum;
}
float distance1(ll x1, ll y1, ll x2, ll y2)
{
    // Calculating distance
    return sqrt(pow(x2 - x1, 2) +
                pow(y2 - y1, 2) * 1.0);
}
void swap(ll *xp, ll *yp)
{
    ll temp = *xp;
    *xp = *yp;
    *yp = temp;
}
bool sortbysec(const pair<int,int> &a,
              const pair<int,int> &b)
{
    return (a.second < b.second);
}
void solve()
{
    ll n,m;

    cin>>n>>m;
    while(n>=0&&m>=0)
    {
        if(n==0||m==0)
            break;
       else  if(n>=2*m)
            n=n%2*m;
        else if(m>=2*n)
            m=m%2*n;
            //cout<<n<<m<<endl;
    }
    cout<<n<<" "<<m;
}

int main()
{
    needforspeed;
    ll t=1;
   // cin>>t;
  // freopen("input.txt", "r", stdin);
  // freopen("output.txt", "w", stdout);
    while(t--)
    {
        solve();
    }
    return 0;
}

#include<bits/stdc++.h>
#define int long long
#define pb emplace_back
#define mp make_pair
#define tci(v,i) for(auto i=v.begin();i!=v.end();i++)
#define all(v) v.begin(),v.end()
#define rep(i,start,lim) for(long long (i)=(start);i<(lim);i++)
#define revrep(i,n) for(long long i=n-1;i>=0;i--)
#define boost ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define osit ostream_iterator<int> output (cout," ")
#define pv(x) copy(all(x),output)
#define pa(a) rep(i,0,sizeof(a)/sizeof(a[0]))cout<<a[i]<<" "
#define endl '\n'
#define f first
#define s second
#define PI 3.141592653589793
#define test int t;cin>>t; while(t--)
#define set0(x) memset(x,0,sizeof(x))
#define set1(x) memset(x,1,sizeof(x))
#define getarr(arr,n) int arr[n];rep(i,0,n)cin>>a[i]
#define getvec(vec,n) vi vec;int x;rep(i,0,n){cin>>x;vec.pb(x);}
#define dg(x) cout<<#x<<':'<<x<<endl;
#define dg2(x,y) cout<<#x<<':'<<x<<' '<<#y<<':'<<y<<endl;
#define dg3(x,y,z) cout<<#x<<':'<<x<<' '<<#y<<':'<<y<<' '<<#z<<':'<<z<<endl;
#define dg4(x,y,z,zz) cout<<#x<<':'<<x<<' '<<#y<<':'<<y<<' '<<#z<<':'<<z<<' '<<#zz<<':'<<zz<<endl;
using namespace std;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;
template<typename T> T gcd(T a,T b){if(a==0) return b; return gcd(b%a,a);}
vi b_v;void bin(unsigned int n) { if (n > 1) bin(n>>1); b_v.pb(n & 1); }
int isPowerof2(int x) { return (x && !(x & x-1)); }

int32_t main(){
	boost;osit;
	int a,b;
	cin>>a>>b;
	while(1){
		if(a==0 || b==0){
			break;
		}else if(a>=2*b){
			a%=b;
		}else if(b>=2*a){
			b%=a;
		}else{
			break;
		}
	}
	cout<<a<<" "<<b;
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long a,b;
    cin>>a>>b;
    if(a==0 || b==0) cout<<a<<" "<<b;
    else
    {
        for(int i=1;; i++)
        {
            if(a>=2*b)
            {
                a=a-2*b;
                if(a==0) break;
                else
                {
                    if(b>=2*a)
                    {
                        b=b-2*a;
                        if(b==0) break;
                    }
                    else break;
                }
            }
            else break;

        }

        cout<<a<<" "<<b;
    }
    return 0;
}

#include<iostream>
using namespace std;
int main() {
	int n, m,i=0;
	cin >> n >> m;
	while (true) {
		if (n == 0 || m == 0) {
			cout << n << " " << m << endl;
			break;
		}
		else if (n >= (2 * m)) {
			n -= (2 * m);
		}
		else if (m >= (2 * n)) {
			m -= (2 * n);
		}
		else {
			cout << n << " " << m << endl;
			break;
		}
	}

	return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ii pair<int,int>
int main()
{
	ll a,b;
	cin>>a>>b;
	while(1)
	{
		if(a==0 || b==0) break;
		if(a>=2*b)
		{
			ll d=a/(b*2);
			if(d!=1)
			{
				a-=d*b;
			}
			else
			{
				a-=2*b;
			}
		}
		else if(b>=2*a)
		{
			int d=b/(a*2);
			if(d!=1)
			{
				b-=d*a;
			}
			else
			{
				b-=2*a;
			}
		}
		else break;
	}
	cout<<a<<" "<<b<<endl;
}

#include <iostream>

using namespace std;

int main(){

    int a, b;
    cin >> a >> b;

    while (a!=0 && b!=0){
        if (a>=2*b){
            a = a%(2*b);
        }
        else if (b>=2*a){
            b = b%(2*a);
        }
        else{
        	cout << a << " " << b;
        	return 0;
        };
    }

    cout << a << " " << b;
}

#include<iostream>
#include<iomanip>
#include<algorithm>
using namespace std;
int main()
{
	int a, b;
	while (cin >> a >> b)
	{
		while (a!=0&&b!=0)
		{
			if (a >= 2 * b || b >= 2 * a)
			{
				if (a >= 2 * b)a = a - 2 * b;
				else if (b >= 2 * a)b = b - 2 * a;
			}
			else break;
		}
		cout << a << " " << b << endl;
	}

}

#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long a;long long b;
	scanf("%l64d%l64d",&a,&b);
	while(a!=0 && b!=0)
	{
		if(a>=2*b)
		{a=a-2*b;}
		else if(b>=2*a)
		{b=b-2*a;}
		else break;
	}
	cout << a << ' ' << b << endl;
	return 0;
}

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

int main()
{
  int a,b;
  cin>>a>>b;
  if(a<1||b<1||a>pow(10,18)||b>pow(10,18))
  {
    return 0;
  }
  bool bflag=false;
  while(bflag==false)
  {
    if(a==0||b==0)
    {
      bflag=true;
    }
    else
    {
      if(a>=2*b)
      {
        a=a-2*b;
      }
      else
      {
        if(b>=2*a)
        {
          b=b-2*a;
        }
        else
        {
          bflag=true;
        }
      }
    }
  }
  cout<<a<<" "<<b<<endl;
  return 0;
}

#include <iostream>
#include <ostream>
#include <vector>
#include<math.h>
#include<map>

using namespace std;

int main()
{
    size_t n, m;
    cin >> n >> m;

    for (;;)
    {
        if(n !=  0 && m !=  0)
        {
            if(n >= 2*m)
                n = n - 2*m;

            else
            {
                if(m >= 2*n)
                    m = m - 2*n;
                else
                {
                    cout << n << " " <<m;
                    break;
                }
            }
        }

        else
        {
            cout << n << " " <<m;
            break;
        }
    }
}

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

int main(){
	long long a;
	long long b;
	bool i;
	cin>>a>>b;
	if(a>1000000) a=1000000;
	if(b>1000000) b=1000000;
	while(!i){
		if(a==0 || b==0){
			cout<<a<<" "<<b<<endl;
			i=true;
		}
		else if(a >= 2*b){
			a=a-2*b;
		}
		else if(b>=2*a){
			b=b-2*a;
		}
		else{
			cout<<a<<" "<<b<<endl;
			i=true;
		}
	}
	return 0;
}

#include <iostream>
using namespace std;

int main() {
    int a, b;
    cin >> a  >> b;
    while ( (a > 0 && b > 0) && ((a >= 2*b)||(b >= 2*a) )){
        if (a >= 2*b) {
            a = a-2*b;
        }else if (b >= 2*a) {
            b = b-2*a ;
        }
    }
    cout  << a << ' ' << b;
    return 0;
}

#include <iostream>

using namespace std;

int main(){
    long long n, m;
    cin >> n >> m;
    while (true){

        if (n == 0 || m == 0)
            break;
        if (n >= 2 * m){
            if (n >= 4 * m)
                n = n % m;
            else
                n -= 2 * m;
        } else {
            if (m >= 2 * n){
                if (m >= 4 * m)
                    m = m % n;
                else
                    m -= 2 * n;
            } else {
                break;
            }
        }

    }
    cout << n << " " << m;
    return 0;
}

/*
    Starting with the name of Allah
    Md.Sayeed Hasan
    City University
    Judge Name: Codeforces
    problem no:
    Status :
*/

#include<bits/stdc++.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define ll long long int

using namespace std;

int main()
{

    //freopen("morse.txt", "r", stdin);

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

    ll a,b;

    while(cin>>a>>b && (a!=EOF || b!=EOF) ){

    while(true){

        if(a>100000000 && b<1000000) a = a/2;
        if(b>100000000 && a<1000000) b = b/2;

        if(a==0 || b==0) break;

        //cout<<a<<" : "<<b<<endl;

        if(a>=2*b){

           //if(a>b*8) a = a/2;
           a = a-(2*b);
            //a=a%b;
            continue;
        }
        else{
            if(b>=2*a){
                //if(b>a*6) b = b/2;
                b= b-(2*a);
                //b=b%a;
                continue;
            }
            else break;
        }
    }

    cout<<a<<" "<<b<<endl;
    }

    return 0;
}

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

// int n, m, a[10000];
// vector<int>adj[100005];
// int visited[100005];

// void _initialize()
// {
// 	for (int i = 0;  i < n; ++i)visited[i] = 0;

// }

// int c = 0, cn = 0;
// void dfs(int s)
// {
// 	//cout << "The Parent is " << s << endl;
// 	//cout << "The leafs of under this parent : " << endl;
// 	if (a[s] == 1)++c;
// 	else ++cn;
// 	visited[s] = 1;
// 	for (int i = 0; i < adj[s].size(); ++i)
// 	{
// 		if (visited[adj[s][i]] == 0 && c <= m)
// 		{
// 			//cout << adj[s][i] << " ";
// 			dfs(adj[s][i]);
// 		}
// 	}
// 	if (a[s] == 1)c--;
// 	//cout << endl;
// }

// int main ()
// {
// 	cin >> n >> m;
// 	for (int i = 1; i <= n; ++i)
// 	{
// 		cin >> a[i];
// 	}
// 	for (int i = 1; i < n; ++i)
// 	{
// 		int x, y;
// 		cin >> x >> y;
// 		adj[x].push_back(y);
// 		adj[y].push_back(x);
// 	}
// 	_initialize();
// 	dfs(1);
// 	cout << cn << endl;
// }

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

long long _ab(long long a, long long b)
{
	long long mn = min(a, b);
	if (a == 0 || b == 0)
	{
		if (a == 0)cout << a << " " << b << endl;
		else cout << b << " " << a << endl;
		return 0;
	}
	if (mn == a)
	{
		if (b % a == 0)
		{
			cout << "0 " << a << endl;
			return 0;
		}
		else if (b >= 2 * a)
		{
			b = b - 2 * a;
			if (b == 0){ cout << b << " " << a << endl; return 0; }
			_ab(a, b % (2  * a));
		}
		else
		{
			cout << a  << " " << b << endl;
			return 0;
		}

	}
	else
	{
		if (a % b == 0)
		{
			cout << "0 " << b << endl;
			return 0;
		}
		else if (a >= 2 * b)
		{
			a = a - 2 * b;
			if (a == 0){ cout << a << " " << b << endl; return 0;}
			_ab(a % (2 * b), b);
		}
		else
		{
			cout << b << " " << a << endl;
			return 0;
		}
	}
}

int main ()
{
	long long n, m;
	cin >> n >> m;
	_ab(n, m);
}

/* Which of the favors of your Lord will you deny? */

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

#define pi       acos(-1)

#define SI(n)    scanf("%d",&n)
#define SLL(n)   scanf("%lld",&n)
#define SULL(n)   scanf("%llu",&n)
#define SC(n)    scanf("%c",&n)
#define SD(n)    scanf("%lf",&n)

#define fr(i,a,b) for(int i=a ,_b=(b) ;i<= _b;i++)

#define LL      long long
#define PUB     push_back
#define POB     pop_back
#define MP      make_pair;
#define PII     pair<int,int>
#define PLL     pair<ll,ll>

#define GCD     __gcd
#define DEBUG   cout<<"aw"<<endl;

int main()
{
    LL a,b;
    SLL(a),SLL(b);

    while(1)
    {

    step1:
        if(a==0 || b==0)
            break;

        else if(a>=2*b)
        {
            a = a-2*b;

            if(a==0 || b==0)
                break;

        }

        if(b>=2*a)
        {
            b = b-2*a;

            goto step1;
        }
        else
            break;

        //cout<<a<<" "<<b<<endl;
    }

    printf("%lld %lld\n",a,b);

    return 0;
}

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

ll a,b;

int main(){

      cin >> a >> b;

      while(1){

           if(a == 0 || b == 0)

                break;

           else if(a >= 2 * b)

                a %= 2 * b;

           else if(b >= 2 * a)

                b %= 2 * a;

           break;

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

     }

     return 0;

}

#include <bits/stdc++.h>
using namespace std;
void weirdSubtraction(long a,long b)
{
	if(a==0 || b==0)
	cout<<a<<' '<<b;
	else if(a>=2*b)
	weirdSubtraction(a-2*b,b);
	else if(b>=2*a)
	weirdSubtraction(a,b-2*a);
	else
	cout<<a<<' '<<b;
}
int main()
{
	long a,b;
	cin>>a>>b;
	weirdSubtraction(a,b);
}

#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long a,b,i,j;
    cin>>a>>b;
    if(a>2*b)
    {
        a=a%(2*b);
        if(a==0)
		{
			cout<<a<<" "<<b<<endl;
			return 0;
		}
    }
    if(b>2*a)
    {
        b=b%(2*a);
        if(b==0)
		{
			cout<<b<<" "<<a<<endl;
			return 0;
		}
    }
    //cout<<a<<" "<<b<<endl;
    int f=0;
    while(f==0)
    {
        if(a==0||b==0)
        {
            f=1;
        }
        else if(a>=2*b)
        {
            a=a-2*b;
        }
        else if(b>=2*a)
        {
            b=b-2*a;
        }
        else{
            f=1;
        }
    }
    cout<<a<<" "<<b<<endl;
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int a,b;
    cin>>a>>b;
    while(1)
    {
        if(a==0 || b==0)
        {
            break;
        }
        else if(a>=2*b)
        {
            a=a%(2*b);
            //break;
        }
        else if(b>2*a)
        {
            b=b%(2*a);
           // break;
        }
        else break;
    }
    cout<<a<<" "<<b<<endl;
}

#include <bits/stdc++.h>
#define fRead           freopen("input.txt","r",stdin)
#define fWrite          freopen("output.txt","w",stdout)
#define eps             1e-9
#define inf             0x3f3f3f3f
#define INF             2e18
#define LL              long long
#define ULL             unsigned long long
#define PI              acos(-1.0)
#define pb              push_back
#define mk              make_pair
#define pii             pair <int,int>
#define pLL             pair <LL,LL>
#define ff              first
#define ss              second
#define all(a)          a.begin(),a.end()
#define rall(a)         a.rbegin(),a.rend()
#define SQR(a)          ((a)*(a))
#define Unique(a)       sort(all(a)),a.erase(unique(all(a)),a.end())
#define min3(a,b,c)     min(a,min(b,c))
#define max3(a,b,c)     max(a,max(b,c))
#define min4(a,b,c,d)   min(min(a,b),min(c,d))
#define max4(a,b,c,d)   max(max(a,b),max(c,d))
#define max5(a,b,c,d,e) max(max3(a,b,c),max(d,e))
#define min5(a,b,c,d,e) min(min3(a,b,c),min(d,e))
#define Iterator(a)     __typeof__(a.begin())
#define rIterator(a)    __typeof__(a.rbegin())
#define FOR(a,it)       for(Iterator(a) it = a.begin();it != a.end(); it++)
#define rFOR(a,it)      for(rIterator(a) it = a.rbegin();it != a.rend(); it++)
#define FastRead        ios_base::sync_with_stdio(0);cin.tie(0)
#define vi              vector <int>
#define v2di			vector < vector <int> >
#define v2dL			vector < vector <LL> >
#define vL              vector <LL>
#define For(I,A,B)      for(int I = (A); I  < (B); ++I)
#define rFor(I,A,B)     for(int I = (A); I >= (B); --I)
const int MOD = 1e9 + 7;
#define sci(a) scanf("%d",&a)
#define scc(a) scanf(" %c",&a)
#define sci2(a,b) sci(a) , sci(b)
#define sci3(a,b,c) sci(a), sci(b), sci(c)
#define sci4(a,b,c,d) sci(a), sci(b), sci(c), sci(d)
#define scl(a) scanf("%lld", &a)
#define scl2(a,b) scl(a) , scl(b)
#define scl3(a,b,c) scl(a), scl(b), scl(c)
#define scl4(a,b,c,d) scl(a), scl(b), scl(c), scl(d)
#define ABS(x) ((x)<0?-(x):(x))
#define SORT(v) sort(v.begin(),v.end())
#define REV(v) reverse(v.begin(),v.end())
#define sp printf(" ");
#define pfi(n) printf("%d", n);
#define pfl(n) printf("%lld", n);
#define nl printf("\n");
#define sf(str) getline(cin,str)
using namespace std;

LL a, b;

void bigshot(){
    if(!a || !b){
        return;
    }
    else if(a >= 2*b){
        a = a%(2*b);
    }
    else if(a >= 2*b){
        b = b%(2*a);
    }
    else return;
    bigshot();
}

int main()
{
    scl2(a,b);
    bigshot();
    pfl(a);
    sp;
    pfl(b);
    return 0;
}

#include<iostream>
using namespace std;
int main()
{
    unsigned long long a, b;
    cin >> a >> b;

    while(a*b){
        if( a >= 2*b){
            a = a - a/(2*b)*(2*b);
        }
        else if( b >= 2*a){
            b = b - b/(2*a)*(2*a);
        }
        else{
            break;
        }
    }
    cout << a << " " << b << endl;
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define sf(n) scanf("%d",&n)
#define pd(n)  printf("%.12lf",n)
#define pf(n)  printf("%d", n)
#define p() 	printf("\n")
#define ps() 	printf(" ")
#define ll long long
#define ull unsigned long long
#define MAX 1e9
#define mod 1000000000
#define pi 3.1415926536
#define ex 1e9
#define dbl 1e09
#define  qu(q)    queue<int>q
#define pqu(q)    priority_queue<int>q
#define len(s)   s.length()
#define sz(x)    x.size()
#define pb(x)    push_back(x)
#define all(x)   x.begin(),x.end()
#define rall(x)  x.rbegin(),x.rend()

int a[105];
int pos,neg;
int main(){

	//freopen("input.txt","r",stdin);
	//freopen("output.tx(t","w",stdout);
	int a,b;
	cin>>a>>b;
step1:
	if(a==0 || b==0){
		cout<<a<<" "<<b<<endl;
		return 0;
	}
	else {
		goto step2;
	}
step2:
	if(a>=2*b){
		a-=2*b;
		goto step1;
	}
	else {
		goto step3;
	}
step3:
	if(b>=2*a){
		b-=2*a;
		goto step1;
	}
	else{
		cout<<a<<" "<<b<<endl;
		return 0;
	}
	return 0;
}

#include<iostream>
using namespace std;
int main()
{
	int a, b;
	cin >> a >> b;
	while (true)
	{
		if (a == 0 || b == 0)
			break;
		else if (a >= 2 * b)
			a = a % (2 * b);
		else if (b >= 2 * a)
			b = b % (2 * a);
		else
			break;
	}
	cout << a << " " << b;
	return 0;
}

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

void weirdProcess(int &a,int&b){
	if(b==0) return;
	if(a<2*b) return;
	int tmp=b;
	b=a%b;
	a=tmp;
	return weirdProcess(a,b);
}

int main(){
	int a,b;
	cin>>a>>b;
	weirdProcess(a,b);
	cout<<b<<" "<<a<<"\n";
	return 0;
}

#include <iostream>
#include <string>
#include <stdlib.h>
#include <bits/stdc++.h>

using namespace std;

int counter = 0;

void step1(int &a, int&b);

void step2(int& a, int&b){
    while(b >= 2*a){
        counter++;
        b = b - 2*a;
        if(a == 0 ||b == 0) return;
        step1(a,b);
    }
}

void step1(int &a, int& b){
    while(a >= 2*b)
    {
        counter++;
        a = a - 2*b;
        if(a == 0 ||b == 0) return;

    }
    step2(a,b);
}

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

    if(a == 0 || b == 0){

    }else{
        step1(a,b);
    }
    cout << a << " " << b << endl;
    return 0;
}

#include<iostream>
using namespace std;
long int md=0;
void wired(long int a, long int b)
{
	if( (a ==2*b ))
	{
		cout<<a%(2*b)<<" "<<b;
		return ;
	}
	if( (a <2*b ))
	{
		cout<<b<<" "<<a%(2*b);
		return ;
	}
	else
	{
		md=a%(2*b);

		wired(b,md);
	}
}
int main()
{
	long int a ,b;
	cin >> a>> b;
	wired(a,b);
}

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
int main()
{
    ll m,n;
    cin>>m>>n;
    while (1){
        if ((m<=0)||(n<=0)){break;}
        if (m==n){break;}
        if (m/2>=n){m=m-2*n;}
        if (n>m/2){n=n-2*m;}
    }
    cout<<m<<' '<<n<<endl;
    return 0;
}

#include<stdio.h>
int main(){
    int a,b;
    scanf("%i %i",&a,&b);
    while(a!=0 && b!=0){
        if(a >= (2*b)){
           a = a - (2*b);
        }else if(b >=(2*a)){
            b = b - (2*a);
        }else{
            break;
        }
    }
    printf("%i %i",a,b);
    return 0;
}

#include <iostream>
#include <string>
#include <algorithm>
#include <cctype>
#include <math.h>
#include <stdio.h>
#include <sstream>
#include <queue>
#include <stack>

using namespace std;
#define pi acos(-1)

int main(int argc, char *argv[]) {
	int a,b;
	cin>>a>>b;
	while(1)
	{
		if(a==0||b==0)
			break;
		if(a>=2*b)
		{
			a=a-2*b;
			continue;
		}
		if(b>=2*a)
		{
			b=b-2*a;
			continue;
		}
		else
			break;
	}
	cout<<a<<" "<<b;
}

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b;
    cin>>a>>b;
    while(1)
        {
            if(a==0||b==0)
                break;
            if(a>=2*b)
                a%=2*b;
            else if(b>=2*a)
                b%=2*a;
            else
                break;
        }
    cout<<a<<" "<<b<<endl;
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ii pair<int,int>
int main()
{
	ll a,b;
	cin>>a>>b;
	while(1)
	{
		if(a==0 || b==0) break;
		if(a>=2*b)
		{
			ll d=a/(b*2);
			if(a-2*b>=2*b)
			{
				a-=d*b;
			}
			else
			{
				a-=2*b;
			}
		}
		else if(b>=2*a)
		{
			int d=b/(a*2);
			if(b-2*a>=2*a)
			{
				b-=d*a;
			}
			else
			{
				b-=2*a;
			}
		}
		else break;
	}
	cout<<a<<" "<<b<<endl;
}

#include <iostream>
using namespace std;

int main() {
	int a,b;
	cin >> a >> b;
	while (a!=0 and b!=0){
		if (a>=2*b){
			a = a%(2*b);
		}
		else if (b>=2*a){
			b = b%(2*a);
		}
		else {
			break;
		}
	}
	cout << a << " " << b;
	return 0;
}

#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<set>
using namespace std;
int main(){
long long a,b;
cin>>a>>b;
while (true){

	if (a==0 && b==0)
	{
		break;
	}
	else if (a>=(2*b))
	{
		a=a%b;
		if (a==0)
		break;
		continue;
	}
	else if (b>=(2*a)){
		b=b%a;
		if (b==0)
		break;
		continue;
	}
	else if (a==0 or b==0)
	break;
	else
	break;

}
		cout<<a<<" "<<b;
		return 0;

}

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

int main()
{
    ios_base::sync_with_stdio(false);
     cin.tie(NULL);
    unsigned long a,b,a1,b1;
    cin>>a>>b;
    while(1)
    {
    if(a==0||b==0)
    {
        break;
    }
    else if(a>=2*b)
    {
        a=a-2*b;
        if(a==0)
        {
            break;
        }
    }
    else if(b>=2*a)
    {
        b=b-2*a;
        if(b==0)
        {
            break;
        }
    }
    else if(a!=0&&b!=0&&a>!2*b&&b>!2*a||a==b)
    {
        a1=a;
        b1=b;
        break;
    }
    }
    if(a1==a&&b1==b)
    {
        cout<<a1<<" "<<b1<<endl;
    }
    else
    cout<<a<<" "<<b<<endl;
    return(0);
}

#include <iostream>

using namespace std;

int main (void)
{
    int p,q;

    cin >> p >> q;

    while(p>0 && q>0){
        if(p>=(2*q))p = p - (2*q);
        if(q>=(2*p))q = q - (2*p);
        else break;
    }
    cout << p << ' '<< q << endl;

    return 0;
}

#include<iostream>
using namespace std;

int main()
{
	int n, m;
	cin >> n >> m;
	while (n&&m && (m>=2*n ||n>=2*m))
	{
		n = n % (2 * m);
		if (n>0)
			m = m % (2 * n);
	}
	cout << n << ' ' << m << endl;
	return 0;
}

#include <iostream>
using namespace std;
int main() {
    int a, b, neg = 0;
    cin >> a >> b;
    while (a != 0 && b != 0) {
        if (a >= 2*b) {
            a = a - 2*b;
            continue;
        }
        else if (b >= 2*a) {
            b = b - 2*a;
            continue;
        }
        else
            break;
    }
    cout << a << " " << b;
}

//
//  main.cpp
//  Problem - 946B
//
//  Created by Gerardo Silva Razo on 9/24/18.
//  Copyright © 2018 Gerardo Silva Razo. All rights reserved.
//
//

#include <iostream>
using namespace std;

void subtract(int &a, int &b) {
    if (a!=0 && b!=0) {
        if (a >= 2*b) {
            a -= 2*b;
            subtract(a, b);
        } else {
            if (b >= 2*a) {
                b -= 2*a;
                subtract(a, b);
            }
        }
    }
}

int main(int argc, const char * argv[]) {
    //Declaración de vars
    int a = 1000000000000000000;
    int b = 7;

    //Input
    //cin >> a >> b;

    //func recursiva
    subtract(a, b);

    cout << a << " " << b;

//    do {
//
//        if (a <= 2*b) {
//            a -= 2*b;
//            if (a == 0 || b == 0) {
//                cout << a << " " << b;
//                return 0;
//            }
//        } else {
//            if (b <= 2*a) {
//                b -= 2*a;
//                if (a == 0 || b == 0) {
//                    cout << a << " " << b;
//                    return 0;
//                }
//            } else {
//                cout << a << " " << b;
//                return 0;
//            }
//        }
//
//    } while (true);

}

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

long long bins(long long hi,long long lo)
{
    long long bot=0;
    long long top=hi;
    long long middle;
    long long wynik=0;
    while(top>=bot)
    {
        middle=(top+bot)/2;
        if(hi-middle*2*lo>=2*lo)
        {
            bot=middle+1;
        }
        else
        {
            wynik=middle;
            top=middle-1;
        }
    }
    return wynik*2*lo;
}

int main()
{
    ios_base::sync_with_stdio(false);
    long long a,b;
    cin>>a>>b;
    while(a!=0&&b!=0)
    {
        if(a>=2*b)
            a-=bins(a,b);
        else
        if(b>=2*a)
            b-=2*a;
        else
        {
            cout<<a<<" "<<b;
            return 0;
        }
    }
    cout<<a<<" "<<b;

}

#include<bits\stdc++.h>
using namespace std;
pair<long long, long long> agcd(long long x,long long y)
{
	if (x == 0 || y == 0)  return pair<long long, long long>(x, y);
	return x / y < 2 && y / x < 2 ? pair<long long,long long>(x, y) : !(x / y < 2) ? agcd( x%y,y) : agcd(x, y%x);
}
int main()
{
	long long m,n;
	cin >> m>>n;
	cout << agcd(m, n).first<<" "<< agcd(m, n).second;
}

#include<bits/stdc++.h>
using namespace std;
const int maxn=5e5+10000;
typedef long long ll;
ll a,b;
int main(){
    int i,j;
    ll n,m;
    while(cin>>n>>m){
        if(n==1&&m==1){
            cout<<1<<" "<<1<<endl;
            continue;
        }
        if(n==1){
            cout<<1<<" "<<0<<endl; continue;
        }
        if(m==1){
            cout<<0<<" "<<1<<endl; continue;
        }
        if(n>m){
            ll k=n%(2*m);
            if(k*2<=m) cout<<0<<" "<<m%(2*k)<<endl;
            else cout<<k<<" "<<m<<endl;
        }
        else{
            if(n*2<=m) cout<<0<<" "<<m%(2*n)<<endl;
            else cout<<n<<" "<<m<<endl;
        }
    }
    return 0;
}

#include<iostream>
#include<stdio.h>
#include<vector>
#include<ctype.h>
#include<cstdio>
#include<string.h>
#include<algorithm>
#define ll long long
#define mod 1000000007

using namespace std;

//ll i=0, j=0,k=0;

ll solve(ll &a, ll &b){
    if(a==0 && b==0){
        return 0;
    }
    else if(a >= 2*b){
        a = (2*b)%a;
        solve(a,b);
    }
    else if(b >= 2*a){
        b = (2*a)%b;
        solve(a,b);
    }
return 0;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll a,b;
    cin>>a>>b;
    solve(a,b);
    cout<<a<<" "<<b;
    return 0;
}

#include <iostream>

using namespace std;

int main() {
	int a, b;
	cin >> a >> b;
	bool t = 1;
	while (a != 0 && b != 0) {
		if (t) {
			if (a >= 2*b) a -= 2*b;
			t = 0;
		}
		else {
			if (b >= 2*a) b -= 2*a;
			else break;
			t = 1;
		}
	}
	cout << a << ' ' << b << endl;
}

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

int main(){
    long long a, b,aa,bb;
    cin>>a>>b;
    while(a!=0 && b!=0){
        if(bb=2*b && a>=bb){
            a = a-bb;
        }else if(aa=2*a && b>=aa){
            b = b-aa;
        }else{
            break;
        }
    }
    cout<<a<<" "<<b<<endl;
    return 0;
}

#include <iostream>
using namespace std;

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

    while (1)
    {
        if (a * b == 0)
            break;
        if (a >= 2 * b)
        {
            a -= 2 * b;
            continue;
        }
        if (b >= 2 * a)
        {
            b -= 2 * a;
            continue;
        }
        break;
    }
    cout << a << " " << b << endl;
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long a,b;
    cin>>a>>b;
    while(a!=0 && b!=0 && (a>=2*b || b>=2*b))
    {
        if(a>=2*b) a%=2*b;
        else b%=2*a;
    }
    cout<<a<<" "<<b;

}

#include <iostream>
#define ll long long

using namespace std;

int main(){
    ll a,b;
  while(cin>>a>>b){
      while(b != 0 && a != 0){
        if(a >= 2*b)
           a%=b;
        else if(b >= 2*a)
           b%=a;
        else
          break;
      }
      cout<<a<<" "<<b<<endl;
  }
  return 0;
}

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

void weird(int a, int b);

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

	if(a!=0 && b!=0){
		weird(a,b);
	}
	cout<<a<<" "<<b;
	return 0;
}

void weird(int a, int b){
	do{
		if (a>=2*b){
			a%=2*b;
		}else if (b>=2*a){
			b%=2*a;
		}else{
			cout<<a<<" "<<b<<endl;
		}
	} while (a!=0 && b!=0);
}

#include<bits/stdc++.h>
using namespace std;
int main(){
    long int n,m;
    cin >> n >> m;
    long int a=n;
    long int b=m;
    if(a==0 && b==0){
        return 0;
    }
    if(a>=(2*b)){
        a=a-(2*b);
    }
    if(b>=(2*a)){
        b=b-(2*a);
    }
    printf("%d %d",a,b);
    return 0;
}

#include <iostream>
#include <ostream>
#include <vector>
#include<math.h>
#include<map>

using namespace std;

int main()
{
    size_t n, m;
    cin >> n >> m;

    for (;;)
    {
        if(n !=  0 && m !=  0)
        {
            if(n >= 2*m)
                n = n - 2*m;

            else
            {
                if(m >= 2*n)
                    m = m - 2*n;
                else
                {
                    cout << n << " " <<m;
                    break;
                }
            }
        }

        else
        {
            cout << n << " " <<m;
            break;
        }
    }
}

#include <bits/stdc++.h>

using namespace std;

long long a , b ;

void rec(long long aa , long long bb){
	if(aa == 0 || bb == 0){
		a = aa ; b = bb ;
		// cout << a << " " << b << " -  " << endl ;
		return ;
	}
	if(aa >= 2*bb){
		aa = aa - 2*bb ;
		rec(aa , aa);
	}
	if(bb >= 2*aa){
		bb = bb - 2*aa ;
		rec(aa , bb);
	}
}

int main(){
	cin >> a >> b ;
	rec(a, b);
	cout << a << " " << b <<endl ;
	return 0 ;
}

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

using namespace std;

#define ll long long
#define D(a) cout<<#a<<" = "<<(a)<<endl;
#define INF (2147483647)
const int N = 1000500;

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

	ll a, b;
	cin >> a >> b;

	if (a >= 2 * b)
		a %= 2*b;
	if (a != 0)
		if (b >= 2 * a)
			b %= 2*a;
	if(b!=0)
		if (a >= 2 * b)
			a %= 2 * b;

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

   return 0;
}

/*

*/

#include <iostream>

int main() {
	int a, b;
	std::cin >> a >> b;

	while (!(a == 0 || b == 0)) {
		if (a >= 2 * b) {
			a -= 2 * b;
		}
		else if(b >= 2 * a) {
			b -= 2 * a;
		}
		else {
			break;
		}
	}

	std::cout << a << " " << b;

	return 0;
}

#include <iostream>
#include <cmath>
#include <cstdio>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <climits>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <string>
#include <cstring>
#include <cstdlib>
#include <complex>
#include <functional>
#include <ios>
#include <istream>
#include <iterator>
#include <numeric>
#include <ctime>
#include <new>
using namespace std;

#define Fin(io) freopen((io+".in").c_str(), "r", stdin)
#define Fout(io) freopen((io+".out").c_str(), "w", stdout)
#define Storaket(n) cout.setf(ios::fixed); cout.setf(ios::showpoint); cout.precision(n)

#define F first
#define S second

#define WRNGS
//#define FILEIN
//#define FILEOUT
//#define FLOATPOINT
//#define MULTITEST1
//#define MULTITEST2

#ifdef WRNGS
#define _CRT_SECURE_NO_WARNINGS
#endif

typedef pair<int, int> pi;
typedef long long LL;
typedef long double LD;
typedef vector<int> vi;
typedef set<int> si;
typedef map<int, int> mi;
typedef unsigned long long uLL;

const LL INF = LLONG_MAX/2;
const int mod = (1000*1000*1000+7);
const int inf = INT_MAX/2;
const int N = 201;
const LL H = 31;
const double Pi=acos((-1));
const double EPS=1.0/(9999999.9*(double)inf);
const string io = "2";

LL n, m, i, j, ans, p=1;

void solve() {
	cin>>n>>m;
	while(1) {
		if (p==1) {
			if (n==0 || m==0)
				break;
			else
				p=2;
		}
		if (p==2) {
			if (n>=2*m) {
				int cur=n/m;
				n=n%m;;
				p=1;
			}
			else
				p=3;
		}
		if (p==3) {
			if (m>=2*n) {
				m=m%n;
				p=1;
			}
			else
				break;
		}
	}
	cout<<n<<" "<<m<<endl;
}

int main() {
	ios_base::sync_with_stdio(NULL);
	cin.tie(NULL);
	#ifdef FILEIN
	Fin(io);
	#endif
	#ifdef FILEOUT
	Fout(io);
	#endif
	#ifdef FLOATPOINT
	Storaket(69);
	#endif
	#ifdef MULTITEST1
	int T;
	cin>>T;
	T--;
	while(T--)
		solve();
	#endif
	#ifdef MULTITEST2
	int TT;
	cin>>TT;
	for(int TTT=1;TTT<=TT;TTT++)
		solve();
	#endif
	solve();
	return 0;
}

#include<cstdio>
#include<climits>
#include<cstring>
#include<cstdlib>

int main()
{
	long long int a;
	long long int b;
	scanf("%%I64d %%I64d",&a,&b);
	long long int a2,b2;

	int choice=1;
	while(1)
	{
		b2=2*b;
		a2=2*a;
		step1:
		if(a==0||b==0)
		{
			break;
		}
		else
		{
			if(a>=b2)
			{
				a-=b2;
				a2=2*a;
				goto step1;
			}
			else
			{
				if(b>=a2)
				{
					b-=a2;
					b2=2*b;
					goto step1;
				}
				else
				{
					break;
				}
			}
		}
	}

	printf("%I64d %I64d",a,b);
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long a,b;
    cin>>a>>b;
    while(1)
    {
        if(a>=2*b)
        {
            a=a-2*b;
        }
        else
        {
            break;
        }
        if(a==0 || b==0)
        {
            break;
        }
        if(b>=2*a)
        {
            b=b-2*a;
        }
        else
        {
            break;
        }
        if(a==0 || b==0)
        {
            break;
        }
    }
    cout<<a<<" "<<b;
}

#include<bits\stdc++.h>
using namespace std;
pair<long long, long long> agcd(long long x,long long y)
{
	if (x == 0 || y == 0)  return pair<long long, long long>(x, y);
	return x / y < 2 && y / x < 2 ? pair<long long,long long>(x, y) : !(x / y < 2) ? agcd( x%y,y) : agcd(x, y%x);
}
int main()
{
	long long m,n;
	cin >> m>>n;
	cout << agcd(m, n).first<<" "<< agcd(m, n).second;
}

#include <stdio.h>
#include <iostream>

using namespace std;

void weirdsub(long a, long b) {

    while(true) {
        if(a==0 || b == 0) {
            cout << a << " " << b << endl;
            return;
        }
        else if(a >= 2*b) {
            a = a-(2*b);
        }
        else if(b >= 2*a) {
            b = b-(2*a);
        } else {
            cout << a << " " << b << endl;
            return;
        }
    }
}

int main()
{
   long a,b;
   cin >> a >> b;
   weirdsub(a,b);
}

#include <bits/stdc++.h>
using namespace std;
unsigned long a = 0, b = 0, r = 0, x = 0;

bool
paso1 ()
{
  if (a != 0 && b != 0)
    return true;
  else
    return false;
}

int
main ()
{

  cin >> a >> b;

  while (paso1 ())
    {
      if (a >= (2 * b)){
	x=a/(2*b);
	a -= x * 2 * b;
	}

      else if (b >= (2 * a)){
	x=b/(2*a);
	b -= x * 2 * a;
	}

      else
	break;

    }

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

  return 0;
}

#include <iostream>

using namespace std;

//void weird(int a, int b);
 int main(){
 	int a,b;
 	cout<<"Inserte valores A y B"<<endl;
 	cin>> a >> b;

 	while (a !=0 && b!=0 && (a >= 2*b || b >= 2*a)){
	  if(a >= 2*b)
        {
            a %= (2*b);
        }
        else if(b >= 2*a)
        {
            b %= (2*a);
        }
	 }
	 cout<<a<<" "<<b;
 }

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

#define For(i, x, y) for(int i = x; i <= y; ++i)
#define Forr(i, x, y) for(int i = x; i <= y; --i)
#define sz() size()
#define push_back() pb()

using namespace std;

int main()
{
    //ifstream fin("test.in");
    ios_base::sync_with_stdio(false);
    long long a, b;
    cin >> a >> b;
    while((a >= 2 * b or b >= 2 * a) and !(a == 0 or b == 0)){
        if(a >= 2 * b) a %= b;
        else
        if(b >= 2 * a) b %= a;
    }
    cout << a << ' ' << b;
    return 0;
}

#include<iostream>

using namespace std;

int main()
{
    long long a = 0;
    long long b = 0;
    cin >> a >> b;
    bool seguir = true;
    while(seguir){
        if(a == 0 || b == 0 || a== 2*b|| b == 2 * a){
            seguir = false;
        }
        else if(a >= 2*b){
            a -= 2*b;
        }
        else if(b >= 2*a){
            b -= 2*a;
        }
        else{
            seguir = false;
        }
    }
    cout << a << " " << b<< endl;
}

//https://codeforces.com/problemset/problem/946/B
//

#include<stdio.h>
using namespace std;
int newA, newB;
void substract(int a, int b) {
    if (a == 0 || b == 0)
    {
        newA = a;
        newB = b;
        return;
    }
    else if (a >= 2 * b)
        {

            a -= 2 * b;
            substract(a, b);
        }
        else if (b >= 2 * a)
        {
            b -= 2 * a;

            substract(a, b);
        }
        else
        {
            newA = a;
            newB = b;
        }
    }

int main()
{
    int x=0, y=0;
    scanf_s("%d%d", &x, &y);
    substract(x, y);
    printf("%d %d", newA, newB);
}

#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<string>
#include<cmath>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<vector>
#include<bitset>
using namespace std;
typedef long long ll;
long long int  a, b;
int main()
{
	scanf("%l64d%l64d", &a, &b);
	for (; a != 0 && b != 0;)
	{
		if (a >= 2 * b)
		{
			a = a - b * 2;
			continue;
		}
		if (b >= 2 * a)
		{
			b = b - a * 2;
			continue;
		}
		break;
	}
	printf("%l64d %l64d\n", a, b);
	return 0;

}

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

int main()
{
    ll a,b;
    while(cin>>a>>b){
       while(true){
        if(a == 0 || b == 0){
            cout<<a<<" "<<b<<endl;
            break;
        }
        if(a >= (2*b))
            a = a%b;

        else if(b >= (2*a))
            b = b % a;

         else{
             cout<<a<<" "<<b<<endl;
             break;
         }
       }
    }
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
long long a,b;bool f;
int main(){
	scanf("%d%d",&a,&b);
	while(1){
		f=1;
		if(a==0||b==0) break;
		if(a>=b*2){
			a-=b*2;
			f=0;
		}
		if(b>=a*2){
			b-=a*2;
			f=0;
		}
		if(f==0) break;
	}
	printf("%d %d",a,b);
	return 0;
}

#include <bits/stdc++.h>

using namespace std;

void steps(int& n, int& m) {
    if (n == 0 || m == 0)
        return;
    else {
        if (n >= 2 * m) {
            n = n - 2 * m;
            steps(n, m);
        }
        else {
            if (m >= 2 * n) {
                m = m - 2 * n;
                steps(n, m);
            }
            else {
                return;
            }
        }
    }
}

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

    int a = n;
    int b = m;
    steps(a, b);

    cout << a << " " << b;

    return 0;

}

#include <bits/stdc++.h>

using namespace std;

int main()
{
	long long a, b;
	cin >> a >> b;
	while (a > 0 && b > 0)
	{
		if (a >= 2 * b)
			a %= 2 * b;
		else if (b >= 2 * a)
			b %= 2 * a;
		else break;
	}
	cout << a << b;
	return 0;
}

#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
long long n,m;
int main(){
	int i,j;
	scanf("%I64d%64d",&n,&m);
	int flag=1,sum=0;
	while(n!=0&&m!=0){
		if(sum==100000) break;
		sum++;
		n%=2*m;
		if(n==0) break;
		m%=2*n;
		if(m==0)break;
	}
	printf("%I64d %I64d\n",n,m);
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b;
    cin>>a>>b;
    One:
        if(a==0 || b==0) goto exit;
        else goto two;
    two:
        if(a>= 2*b) {a=a-2*b; goto One;}
        else goto three;
    three:
        if(b>=2*a) {b=b-2*a; goto One;}
        else goto exit;

    exit:
        cout<<a<<" "<<b<<endl;
}

#include <iostream>

using namespace std;

int main(){
    long long n, m;
    cin >> n >> m;
    while (true){

        if (n == 0 || m == 0)
            break;
        if (n >= 2 * m){
            if (n > 3 * m)
                n = n % m;
            else
                n -= 2 * m;
        } else {
            if (m >= 2 * n){
                if (m > 3 * m)
                    m = m % n;
                else
                    m -= 2 * n;
            } else {
                break;
            }
        }

    }
    cout << n << " " << m;
    return 0;
}

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

// int n, m, a[10000];
// vector<int>adj[100005];
// int visited[100005];

// void _initialize()
// {
// 	for (int i = 0;  i < n; ++i)visited[i] = 0;

// }

// int c = 0, cn = 0;
// void dfs(int s)
// {
// 	//cout << "The Parent is " << s << endl;
// 	//cout << "The leafs of under this parent : " << endl;
// 	if (a[s] == 1)++c;
// 	else ++cn;
// 	visited[s] = 1;
// 	for (int i = 0; i < adj[s].size(); ++i)
// 	{
// 		if (visited[adj[s][i]] == 0 && c <= m)
// 		{
// 			//cout << adj[s][i] << " ";
// 			dfs(adj[s][i]);
// 		}
// 	}
// 	if (a[s] == 1)c--;
// 	//cout << endl;
// }

// int main ()
// {
// 	cin >> n >> m;
// 	for (int i = 1; i <= n; ++i)
// 	{
// 		cin >> a[i];
// 	}
// 	for (int i = 1; i < n; ++i)
// 	{
// 		int x, y;
// 		cin >> x >> y;
// 		adj[x].push_back(y);
// 		adj[y].push_back(x);
// 	}
// 	_initialize();
// 	dfs(1);
// 	cout << cn << endl;
// }

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

long long _ab(long long a, long long b)
{
	long long mn = min(a, b);
	if (a == 0 || b == 0 || a == b)
	{
		cout << a << " " << b << endl;
		return 0;
	}
	if (mn == a)
	{
		if (b % a == 0)
		{
			cout << a << " 0" << endl;
			return 0;
		}
		else if (b >= 2 * a)
		{
			int xb = b - 2 * a;
			if (xb == 0){ cout << a << " " << xb << endl; return 0; }
			_ab(a, b % (2  * a));
		}
		else
		{
			cout << a  << " " << b << endl;
			return 0;
		}

	}
	else
	{
		if (a % b == 0)
		{
			cout << b << " 0" << endl;
			return 0;
		}
		else if (a >= 2 * b)
		{
			int xa = a - 2 * b;
			if (xa == 0){ cout << xa << " " << b << endl; return 0;}
			_ab(a % (2 * b), b);
		}
		else
		{
			cout << a << " " << b << endl;
			return 0;
		}
	}
}

int main ()
{
	long long n, m;
	cin >> n >> m;
	_ab(n, m);
}

#include <iostream>
#include <algorithm>
struct my_pair
{
	int64_t a;
	int64_t b;
};
my_pair foo_1(my_pair &t);
my_pair foo_2(my_pair &t);
my_pair foo_3(my_pair &t);

my_pair foo_4(my_pair& t) {
	auto d = std::minmax(t.a, t.b);
	my_pair r{ d.first,d.second };
	r.b = r.b % r.a;
	if (!(r.b == t.b || r.a == t.a))
		std::swap(r.a, r.b);
	return  r;
}

my_pair foo_1(my_pair &t){
	if (!(t.a == 0 || t.b == 0))
	{
		t = foo_4(t);
	}
	return t;
}
my_pair foo_2(my_pair &t) {
	if (t.a >= 2 * t.b)
	{
		t.a = t.a - 2 * t.b;
		t = foo_1(t);
	}
	else
	{
		t = foo_3(t);
	}
	return t;
}
my_pair foo_3(my_pair &t) {
	if (t.b >= 2 * t.a) {
		t.b = t.b - 2 * t.a;
		t = foo_1(t);
	}
	return t;
}

int true_check() {
	my_pair r{0,0};
	while (true) {
		if (r.a == 0 || r.b == 0)
			break;

		if (r.a >= 2 * r.b)
		{
			r.a = r.a - 2 * r.b;
			continue;
		}
		if (r.b >= 2 * r.a) {
			r.b = r.b - 2 * r.a;
			continue;
		}
		break;
	}
	return 0;
}

int main()
{
	using namespace std;

	int64_t a, b;
	cin >> a >> b;
	my_pair r{ a,b };
	while (true) {
		r = foo_4(r);
		if ((r.a==0||r.b==0))
			break;
		if ((r.b < 2 * r.a) && (r.a < 2 * r.b))
			break;
	}
	cout << r.a << " " << r.b;
	return 0;
}

#include<bits/stdc++.h>
#define r_0 return 0
#define pb push_back
#define ll long long
#define ld long double
#define pf push_front
#define fr first
#define se second
#define Time ios_base::sync_with_stdio(0);
using namespace std;
ll n,m,x,y,t, ans,res, sum, mx, mn = 1e9,z,cnt;
string s,s1,s3, s2, s4,s5;
set<char>st;
set<int>::iterator it;
pair<int , int>pr;
vector<ll>v,v1,v2,v3,v4;
map<int, int>mp , mpp;
char a, b, c,d;
bool tr = false, fl = false;
ll used[10001];
vector< pair< int , int  >> vp;

int main()
{
      cin >> n >> m;
      for ( int i = 0; i < 100000; i ++ ){
          if ( n ){
             if ( n % (2 * m) <= 0 )
                break;
             else
                 n %= (2 * m);
          }
         if ( m ){
            if ( m %( 2 * n) <= 0 )
                break;
            else
                m %= 2 * n;
         }
      }
      if ( n - ( 2 * m ) >= 0 )
        cout << n - 2 * m << " " << m;
      else
        cout << n << " " << m;

}

///made
///by

#include<bits/stdc++.h>
using namespace std;
int main()
{
    unsigned long long int a,b;
    cin>>a>>b;
    while(1)
    {
        if(a==0 || b==0)
        {
            break;
        }
        if(a>=(2*b))
        {
            a=a%(2*b);
            cout<<a;
            //break;
        }
        else if(b>=2*a)
        {
            b=b%(2*a);
           // break;
        }
        else break;
    }
    cout<<a<<" "<<b<<endl;
}

#include<bits/stdc++.h>
using namespace std;
int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    int a,b;
    cin>>a>>b;
    while(a>0&&b>0)
    {
        while(a>=(2*b))
        {

            a=a-(2*b);
            //cout<<a<<endl;
        }
        if(a<=0)
        {
            break;
        }
        while(b>=(2*a))
        {
           b=b-(2*a);
           //cout<<b<<endl;
        }
         if(a<(2*b)&&b<2*a)
           break;

        }
    cout<<a<<" "<<b<<endl;

}

#include <bits/stdc++.h>

using namespace std;

typedef long long int lli;

long double n, m;
lli paso2;

int main () {
    //freopen("0in.txt", "rt", stdin);
    //freopen("0out.txt", "wt", stdout);

    cin >> n >> m;
    while (true) {
        paso2 = lli((n - 2.0 * m) / (2.0 * m)) + 1;
        n -= paso2 * 2.0 * m;
        if (m >= 2.0 * n) m -= 2.0 * n;
        else break;
        if (n <= 0 || m <= 0) break;
    }
    cout << n << " " << m << endl;

    return 0;
}

#include <iostream>

using namespace std;

int main()
{
    long long n , m;
    cin>>n>>m;

    while  (  n > 0 && m > 0   ){
        if (n >= 2*m) {
            n = n % 2*m ;
        }else if (m >= 2*n) {
            m = m % 2*n ;
        }else {
            break ;
        }
    }
    cout<< n << " " << m ;
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b;
    cin>>a>>b;
    while(a&&b)
        {
            if(a>=2*b)
                a%=2*b;
            else if(b>=2*a)
                b%=2*a;
            else
                break;
        }
    cout<<a<<" "<<b<<endl;
    return 0;
}

#include <iostream>
using namespace std;
long long a ,b;
void step1(long long ,long long);

void step3(long long c,long long d)
{
    if(d>=2*c)
    {
        d-=2*c;
        step1(c,d);
    }
else;
        cout<<c<<" "<<d;
}

void step2(long long c,long long d)
{
    if(c>=2*d)
    {c-=2*d;step1(c,d) ;}
    else
        step3(c,d);
}

void step1(long long c,long long d)
{
    if(c==0|| d==0)
        cout<<c<<" "<<d;
    else step2(c,d);
}

int main()
{

    cin>>a>>b;
    step1(a,b);

    return 0;

}

#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
long long n,m;
int main(){
	int i,j;
	scanf("%I64d%64d",&n,&m);
	int flag=1;
	while(1){
		if(n==0||m==0) break;
		if(n>=2*m){
			n%=2*m;
			if(n==0)
				break;
		}
		if(m>=2*n){
			m%=2*n;
			if(m==0)
				break;
		}
		else
			break;
	}
	printf("%I64d %I64d\n",n,m);
	return 0;
}

//OM
#include<bits/stdc++.h>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<sstream>
#include<cstdio>
const double PI=3.141592653589793238462643383279502884197169399375105820974944;
# define ull unsigned long long int
# define ll long long int
# define ld long double
# define tri pair<int,pair<int,int> >
# define fastio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
# define mem(v,val) memset(v,val,sizeof v)
# define vull vector<unsigned long long>
# define vll vector<long long>
# define vl vector<long>
# define vi vector<int>
# define pii pair<int,int>
# define vs vector<string>
# define vvi vector<vector<int>>
# define vii vector<pair<int,int>>
# define viii vector<tri>
# define rep(i,a,b) for(int i=a;i<=b;i++)
# define pb push_back
# define mp make_pair
# define F first
# define S second
# define all(v) v.begin(),v.end()
# define flush fflush(stdout)
//typedef _int128 Bigint;
using namespace std;
const int MOD=1e9+7;
double gcd(double a,double b)
{
    return a < 0.01 ? b : gcd(fmod(b,a),a);
}
template<typename T>
T mymax(T a,T b)
{
	return (a>b)?a:b;
}
template<typename T>
T mymax(T a,T b,T c)
{
	return mymax(a,mymax(b,c));
}
template<typename T>
T mymin(T a,T b)
{
	return (a<b)?a:b;
}
template<typename T>
T mymin(T a,T b,T c)
{
	return mymin(a,mymin(b,c));
}
template<typename T>
T power(T x,T y)
{
	T res=1;
	x=x%MOD;
	while(y>0)
	{
		if(y&1)
		res=(res*x)%MOD;
		y=y>>1;
		x=(x*x)%MOD;
	}
	return res;
}
template<typename T>
void swap(T *x,T *y)
{
	T temp;
	temp=*y;
	*y=*x;
	*x=temp;
}
template<typename T>
T mod(T a)
{
	if(a>0)
	return a;
	else
	return -a;
}
template<typename T>
T logg(T  a)
{
    T  x=0;
    while(a>1)
    {
        x++;
        a/=2;
    }
    return x;
}
int main()
{
	fastio
	ll n,m;cin>>n>>m;
	//bool f=0;
	while(!(n==0||m==0||n==m))
	{
		if(n>=2*m)
		{
			ll p=1LL*2*m;
			if(p!=0)
			n=n%p;
		}
		if(n==0||m==0||n==m)
			break;
		if(m>=2*n)
		{
			ll r=m-(n/2);
			ll g=r/(2*n);
			m-=(g*2*n);
			if(n==0||m==0||n==m)
			break;
			if((n<2*m))
			{
				m-=(2LL*n);
				if(m==0)
					break;
			}
		}
		else
		{
			break;
		}
	}
	cout<<n<<' '<<m<<'\n';
	return 0;
}