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.

/* package codechef; // don't place package name! */

import java.math.BigInteger;
import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
public class Solution
{
    // Complete the maximumSum function below.
    public static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private SpaceCharFilter filter;
        private BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

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

        public int read() {
            if (numChars==-1)
                throw new InputMismatchException();

            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                }
                catch (IOException e) {
                    throw new InputMismatchException();
                }

                if(numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            }
            catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
        public int nextInt() {
            int c = read();

            while(isSpaceChar(c))
                c = read();

            int sgn = 1;

            if (c == '-') {
                sgn = -1;
                c = read();
            }

            int res = 0;
            do {
                if(c<'0'||c>'9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            }
            while (!isSpaceChar(c));

            return res * sgn;
        }

        public long nextLong() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            long res = 0;

            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            }
            while (!isSpaceChar(c));
            return res * sgn;
        }

        public double nextDouble() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            double res = 0;
            while (!isSpaceChar(c) && c != '.') {
                if (c == 'e' || c == 'E')
                    return res * Math.pow(10, nextInt());
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            }
            if (c == '.') {
                c = read();
                double m = 1;
                while (!isSpaceChar(c)) {
                    if (c == 'e' || c == 'E')
                        return res * Math.pow(10, nextInt());
                    if (c < '0' || c > '9')
                        throw new InputMismatchException();
                    m /= 10;
                    res += (c - '0') * m;
                    c = read();
                }
            }
            return res * sgn;
        }

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

            return res.toString();
        }

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

        public String next() {
            return readString();
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);
        }
    }

    static boolean prime(long a){
        if(a==2||a==3)
            return true;
        if((a-1)%6==0)
            return true;
        if((a+1)%6==0)
            return true;
        return false;
    }
    public static  long gcd(long a,long b){
        if(b==0)
            return a;
        long r=a%b;
        return gcd(b,r);
    }

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

    public class ListNode {
        int val;
        ListNode next;
        ListNode() {}
        ListNode(int val) { this.val = val; }
        ListNode(int val, ListNode next) { this.val = val; this.next = next; }
    }

    public class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;
        TreeNode() {}
        TreeNode(int val) { this.val = val; }
        TreeNode(int val, TreeNode left, TreeNode right) {
            this.val = val;
            this.left = left;
            this.right = right;
        }
    }

    class Node {
        public int val;
        public List<Node> children;

        public Node() {}

        public Node(int _val) {
            val = _val;
        }

        public Node(int _val, List<Node> _children) {
            val = _val;
            children = _children;
        }
    }

    public ListNode insert(ListNode node,int ele){
        if(node==null||node.val>ele){
            ListNode head=new ListNode();
            head.val=ele;
            head.next=node;
            return head;
        }
        int p=node.val;
        ListNode temp=insert(node.next,ele);
        ListNode head=new ListNode();
        head.val=p;
        head.next=temp;
        return head;
    }

    public ListNode sortList(ListNode head) {
        if(head==null)
            return null;
        if(head.next==null)
            return head;
        int a=head.val;
        head=head.next;
        head=sortList(head);
        return insert(head,a);
    }

    // private static final FastReader scanner = new FastReader();
    public static void main(String[] args) throws IOException {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader scanner = new InputReader(inputStream);
        PrintWriter w = new PrintWriter(outputStream);
        BigInteger a=new BigInteger(scanner.next());
        BigInteger b=new BigInteger(scanner.next());
        while (true){
            if(a.compareTo(new BigInteger("0"))==0||b.compareTo(new BigInteger("0"))==0)
                break;
            else if(a.compareTo(b.multiply(new BigInteger("2")))>=0){
                a=a.mod(b.multiply(new BigInteger("2")));
            }
            else if(b.compareTo(a.multiply(new BigInteger("2")))>=0){
                b=b.mod(a.multiply(new BigInteger("2")));
            }
            else
                break;
        }
        w.println(a+" "+b);
        w.close();
    }

}

import java.util.Scanner;

public class JavaApplication3 {

    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        long a=sc.nextLong();
        long b=sc.nextLong();
        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;
            }
        }
        System.out.println(a+" "+b);
    }
}

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

// Good problem!
public class Weird_Subtraction_Process {
	public static long[] f( long a, long b)
	{
		long result[], k;
		if ( a == 0 || b == 0) result  = new long[]{a, b};
		else if ( a >= 2l*b ) { result = f(a % (2l*b), b); }
		else if ( b >= 2l*a ) { result = f(a, b % (2l*a)); }
		else result = new long[]{a, b};
		return result;
	}
	public static void main(String args[])
	{
		Scanner in = new Scanner(System.in);
		long a, b;
		a = in.nextLong();
		b = in.nextLong();
		long[] result = f(a, b);
		System.out.println(result[0]+" "+result[1]);
	}
}

//package main;

import java.util.Scanner;

public class TaskB {

    public static void main(String[] args) {

        Scanner in = new Scanner(System.in);
        long a, b;
        boolean flag = true;
        a = in.nextLong();
        b = in.nextLong();

        while (flag) {

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

                }
            }
        }

        System.out.println(a + " " + b);

    }
}

import java.util.*;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        long a = sc.nextLong();
        long b = sc.nextLong();

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

        System.out.print(a + " " + b);

    }

}

import java.util.*;

public class Substraction{

	long a,b;

	public static void Substract(long a, long b){

		if (a == 0 || b ==0){
			System.out.println(a + " " + b);
		}
		else if(a >= 2*b){
			Substract(a%(2*b),b);
			//System.out.println(a + " " + b);
		}
		else if(b >= 2*a){
			Substract(a,b%(2*a));
			//System.out.println(a + " " + b);
		}
		else
			System.out.println(a + " " + b);

	}

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long a = sc.nextLong();
		long b = sc.nextLong();

		Substract(a,b);
	}
}

import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc=new Scanner (System.in);
        long a=sc.nextLong();
        long b=sc.nextLong();
        while (a!=0 & b!=0){
            if (a>=2*b){
                a=a%(b*2);
            }
            else if (b>=2*a){
                b=b%(a*2);
            }
            else break;
        }
        System.out.print(a);
        System.out.print(" "+b);
    }
}

/*
   #######  ######    #####  ######  ######  #####
    #    #  #    #      #    #    #  #    #    #
    #    #  # #  #      #    # ## #  # ## #    #
    #    #  #  #    #   #    #    #  #    #    #
   #######  #   #   # # #    #    #  #    #    #
*/
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
import java.io.*;
import java.math.*;
import java.util.StringTokenizer;
public class Educationalround_39_2 {
    static PrintStream p = System.out;
    static long mod = (long)10e9+7;
    public static void main(String args[] ) throws Exception {
        long n = nextLong();
        long m = nextLong();
        while(true){
            if(n<=0 || m<=0) break;
            else if(n>=(2*m)){
                n%=2*m;
            }else if(m>=2*n){
                m%=2*n;
            }else{
                break;
            }
        }
        p.println(n+" "+m);

    }

//-------------------------------------------------fast Method---------------------------------------------------------------\\
    static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));;
    static StringTokenizer st;
    private static int[] inta(int n){
        int [] a = new int[n];
        for(int i = 0;i < n;i++)a[i] = nextInt();
            return a;
    }
    private static long[] longa(long n){
    long[] a = new long[(int)n];
        for(int i = 0;i < n;i++)a[i] = nextLong();
            return a;
    }
    private static void pla(long[] a){
        for(int i = 0;i <a.length;i++)
            p.print(a[i]+" ");
    }
    private static void pia(int[] a){
        for(int i = 0;i <a.length;i++)
            p.print(a[i]+" ");
    }
    private static String next(){
        while (st == null || !st.hasMoreElements()){
            try{
                st = new StringTokenizer(br.readLine());
            }
            catch (IOException  e){
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }
    private static int nextInt(){
        return Integer.parseInt(next());
    }

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

    private static double nextDouble(){
        return Double.parseDouble(next());
    }
    private static String nextLine(){
        String str = "";
        try{
            str = br.readLine();
        }
        catch (IOException e){
            e.printStackTrace();
        }
        return str;
    }
//-------------------------------------------------fast Method---------------------------------------------------------------\\
}

import java.util.Scanner;

public class Weird_Substraction {
	static Scanner sc = new Scanner(System.in);
	private static long a,b;

	public static void main (String args[]) {

		a=sc.nextLong();
		b=sc.nextLong();

		while (a!=0 && b!=0) {

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

			}

		}

		System.out.println(a+" "+b);

	}

}

import java.util.Scanner;
public class Ejercicio3 {

    public static void main(String [] args) {

        Scanner input = new Scanner(System.in);

        Long a = Long.parseUnsignedLong(input.next("\\d+"));
        Long b = Long.parseUnsignedLong(input.next("\\d+"));

        Long exp = Long.parseUnsignedLong("1000");

        while (a>0 && b>0 ){

            while(a>=(2*b)) {

                a %= (2*b);

                if(a==0)
                    break;
            }

            if(a==0)
                break;

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

            else
                break;
        }

        System.out.println(a+" "+b);

    }

    /*void step1(long a, long b){

        if(a==0 || b==0){
            String aStr = Long.toUnsignedString(a);
            String bStr = Long.toUnsignedString(b);
            System.out.println(a+" "+b);
        }

        else
            step2(a,b);
    }

    void step2(long a, long b){

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

        else{
            step3(a,b);
        }
    }

    void step3(long a, long b){

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

        else{
            String aStr = Long.toUnsignedString(a);
            String bStr = Long.toUnsignedString(b);
            System.out.println(a+" "+b);
        }
    }*/
}

import java.util.Scanner;
import java.lang.*;

public class Solution{
	public static void main(String args[]){
		Scanner sc=new Scanner(System.in);
		long a=sc.nextLong();
		long b=sc.nextLong();

	while(a!=0 && b!=0){
		//System.out.println(a+" "+b);
		if(a >= 2*b)
			a=a%(2*b);
		else if(b>= 2*a)
			b=b%(2*a);
		else
			break;
	}
	System.out.println(a+" "+b);
	}
}

//I AM THE CREED
/* package codechef; // don't place package name! */
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.util.*;

public class HelloWorld{
    public static void main(String[] args) throws IOException
    {

        Scanner input = new Scanner(System.in);
        while(input.hasNext()){
            long a=input.nextLong();
            long b=input.nextLong();
            while(true){
                if(a==0 || b==0){
                    System.out.println(a+" "+b);
                    break;
                }
                if(a>=(2*b)){
                    a=a%(2*b);
                    continue;
                }
                if(b>=(2*a)){
                    b=b%(2*a);
                    continue;
                }
                System.out.println(a+" "+b);
                break;
            }
         }
    }

}

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.IOException;

public class B{
    public static void main(String[] args)throws IOException{
	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	PrintWriter out = new PrintWriter(System.out);
	String s[] = br.readLine().split(" ");
	long a = Long.parseLong(s[0]);
	long b = Long.parseLong(s[1]);
	while(a!=0 && b!=0){
	    if(a>=2*b){
		a%=2*b;
	    }else if(b>=2*a){
		b%=2*a;
	    }else{
		break;
	    }
	}
	out.println(a+" "+b);
	out.close();
    }
}

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.IOException;

public class B{
    public static void main(String[] args)throws IOException{
	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	PrintWriter out = new PrintWriter(System.out);
	String s[] = br.readLine().split(" ");
	long a = Long.parseLong(s[0]);
	long b = Long.parseLong(s[1]);
	while(a!=0 && b!=0){
	    if(a>=2*b){
		a-=a/(2*b)*2*b;
	    }else if(b>=2*a){
		b-=b/(2*a)*2*a;
	    }else{
		break;
	    }
	}
	out.println(a+" "+b);
	out.close();
    }
}

import java.util.Scanner;
public class WeirdSubstraction {
    public static void main (String [] args){
        Scanner lector = new Scanner (System.in);
        long a=lector.nextLong(); long b = lector.nextLong();

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

            }
            else if(b>=2*a){
                b=b%(2*a);
            }
            else break;
        }
        System.out.println(a+" "+b);
    }
}

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

public class B {

	public static void main(String[] args)
	{
			Scanner in = new Scanner(System.in);
			long a = in.nextLong(), b = in.nextLong();

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

			System.out.println(a + " " + b);
	}

}

import java.io.*;
import java.math.BigInteger;
import java.util.*;

public class CodeForces {

	public static void main(String[] args) throws IOException,NumberFormatException{
		try {
			FastScanner sc=new FastScanner();
			long n=sc.nextLong(),m=sc.nextLong();
			while(n!=0&&m!=0) {
				if(n>=(2*m)) {
					n=n%(2*m);
					continue;
				}
				if(n==0)
					break;
				if(m>=(2*n))
					m=m%(2*n);
				else
					break;
			}
			System.out.println(n+" "+m);
		}
		catch(Exception e) {
			return ;
		}

	}

	public static boolean isPerfectSquare(int n) {
		int ans=(int)Math.sqrt(n);
		if(ans*ans==n)
			return true;
		else
			return false;
	}
	public static int GCD(int a,int b) {
		if(b==0)
			return a;
		return GCD(b,a%b);
	}
	public static class FastScanner {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer("");
		String next() {
			while (!st.hasMoreTokens())
				try {
                                      st=new StringTokenizer(br.readLine());
                              } catch (IOException e) {}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());
		}
		long nextLong() {
			return Long.parseLong(next());
		}

	}
}

import java.util.*;

public class WeirdProcess {
	public static long a;
	public static long b;

	public static void process() {
		while(true) {
			if(a == 0 || b == 0)
				return;
			if(a >= b * 2) {
				a = (a % (2 * b));
				continue;
			}
			if(b >= a * 2) {
				b = (b % (2 * a));
				continue;
			}
			return;
		}
	}

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);

		a = in.nextLong();
		b = in.nextLong();

		process();
		System.out.println(a + " " + b);
	}
}

import java.util.Scanner;

public class sss {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner s = new Scanner(System.in);
		long n = s.nextLong(), m = s.nextLong();
		while (true) {
			if (n == 0 || m == 0) {
				break;
			} else if (n >= m * 2) {
				n %= m * 2;
			} else if (m >= n * 2) {
				m %= n * 2;
			} else {
				break;
			}
		}
		System.out.println(n + " " + m);
	}

}

import java.util.Scanner;
import java.util.StringTokenizer;

import static java.lang.Long.parseUnsignedLong;

public class Main {

    public static void main(String args[]){

        Scanner stdin = new Scanner(System.in);

        String S= stdin.nextLine();

        StringTokenizer stoken = new StringTokenizer(S," ");

         Long  a=parseUnsignedLong( stoken.nextToken() );
         Long  b=parseUnsignedLong( stoken.nextToken() );

        if(a==b){
            String laStr = Long.toUnsignedString(a);
            String lbStr = Long.toUnsignedString(b);

            System.out.println(laStr+" "+lbStr);
            System.exit(0);}

       do {
            if (a==b||a==0||b==0){
                String laStr = Long.toUnsignedString(a);
                String lbStr = Long.toUnsignedString(b);

                System.out.println(laStr+" "+lbStr);
                System.exit(0);
            }

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

           }

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

           }
           else {
                String laStr = Long.toUnsignedString(a);
                String lbStr = Long.toUnsignedString(b);

                System.out.println(laStr+" "+lbStr);
                System.exit(0);
           }

       }while(true);

    }

}

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Swatantra
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskB {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            long a = in.nextLong();
            long b = in.nextLong();

            while ((a != 0) && (b != 0)) {

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

                    continue;
                } else
                    break;
            }
            out.println(a + " " + b);
        }

    }
}

import java.util.*;
public class WeirdSubtraction{

     public static void main(String []args){
        Scanner in = new Scanner(System.in);
        long a,b;
        a = in.nextLong();
        b = in.nextLong();
        WeirdSubt(a,b);
     }

static void WeirdSubt(long a, long 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);
	  }
      }
System.out.println(a+" "+b);
}
}

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.BitSet;
import java.util.HashMap;
import java.util.HashSet;
import java.util.PriorityQueue;
import java.util.StringTokenizer;
import java.util.TreeSet;

public class Main {
	static ArrayList<Integer> adj[];
	static PrintWriter out = new PrintWriter(System.out);
	public static long mod;

	static int [][]notmemo;
	static int k;
	static int a[];
	static int b[];
	static int m;
	static char c[];

	static int trace[];
	static int h[];
	static int x;
	static int ans1;
	static int ans2;
    static char t[];
	static char l[];
	static char r[];
    static int w;
    static int s;
	static int fn[];
    public static void main(String args[]) throws IOException {
		Scanner sc = new Scanner(System.in);
		long n=sc.nextLong();
		long m=sc.nextLong();
		while(n>=2*m||n*2<=m) {
			if(n==0||m==0) {
				break;
			}
		if(n>=2*m) {
			long temp=n/m;
			if(temp%2!=0)
			temp--;
			n=n-(temp*m);
		}
		else if(n*2<=m) {
			long temp=m/n;
			if(temp%2!=0)
			temp--;
			m=m-(temp*n);
		}
		}
		System.out.println(n+" "+m);
		out.flush();
    }
    static int dp(int i,int rem) {
	if(rem==0||i==0) {
		return 0;
	}
	if(notmemo[i][rem]!=-1) {
		return notmemo[i][rem];
	}

	int ans=0;
	for (int j = 1; j <=Math.min(rem,k); j++) {
		ans=Math.max(ans, dp(i-1,rem-j)+h[j]);
	}

	return notmemo[i][rem]=ans;
    }
    static String y;
    	static int nomnom[];
	static long fac[];

	static class book implements Comparable<book> {
		int idx;
		long score;

		public book(int i, long s) {
			idx = i;
			score = s;
		}

		public int compareTo(book o) {
			return (int) (o.score - score);
		}
	}

	static class library implements Comparable<library> {
		int numofbooks;
		int signup;
		int shiprate;
		int idx;

		public library(int a, int b, int c, int idx) {
			numofbooks = a;
			signup = b;
			shiprate = c;
			this.idx = idx;
		}

		@Override
		public int compareTo(library o) {
		if(signup==o.signup) {
			  return o.numofbooks-numofbooks;
		}
		return signup - o.signup;

		}
	}

	static boolean isOn(int S, int j) {
		return (S & 1 << j) != 0;
	}

	static boolean f = true;

	static class SegmentTree { // 1-based DS, OOP

		int N; // the number of elements in the array as a power of 2 (i.e. after padding)
		int[] array, sTree, lazy;

		SegmentTree(int[] in) {
			array = in;
			N = in.length - 1;
			sTree = new int[N << 1]; // no. of nodes = 2*N - 1, we add one to cross out index zero
			lazy = new int[N << 1];
			//build(1, 1, N);
		}

		void build(int node, int b, int e) // O(n)
		{
			if (b == e)
				sTree[node] = array[b];
			else {
				int mid = b + e >> 1;
				build(node << 1, b, mid);
				build(node << 1 | 1, mid + 1, e);
				sTree[node] = sTree[node << 1] + sTree[node << 1 | 1];
			}
		}

		void update_point(int index, int val) // O(log n)
		{
			index += N - 1;
			sTree[index] = val;
			while(index>1)
			{
				index >>= 1;
				sTree[index] = Math.max(sTree[index<<1] ,sTree[index<<1|1]);
			}
		}

		void update_range(int i, int j, int val) // O(log n)
		{
			update_range(1, 1, N, i, j, val);
		}

		void update_range(int node, int b, int e, int i, int j, int val) {
			if (i > e || j < b)
				return;
			if (b >= i && e <= j) {
				sTree[node] += (e - b + 1) * val;
				lazy[node] += val;
			} else {
				int mid = b + e >> 1;
				propagate(node, b, mid, e);
				update_range(node << 1, b, mid, i, j, val);
				update_range(node << 1 | 1, mid + 1, e, i, j, val);
				sTree[node] = sTree[node << 1] + sTree[node << 1 | 1];
			}

		}

		void propagate(int node, int b, int mid, int e) {
			lazy[node << 1] += lazy[node];
			lazy[node << 1 | 1] += lazy[node];
			sTree[node << 1] += (mid - b + 1) * lazy[node];
			sTree[node << 1 | 1] += (e - mid) * lazy[node];
			lazy[node] = 0;
		}

		int query(int i, int j) {
			return query(1, 1, N, i, j);
		}

		int query(int node, int b, int e, int i, int j) // O(log n)
		{
			if (i > e || j < b)
				return 0;
			if (b >= i && e <= j)
				return sTree[node];
			int mid = b + e >> 1;
			// propagate(node, b, mid, e);
			int q1 = query(node << 1, b, mid, i, j);
			int q2 = query(node << 1 | 1, mid + 1, e, i, j);
			return Math.max(q1,q2);

		}
	}

	static int memo[];

	static class UnionFind {
		int[] p, rank, setSize;
		int numSets;
		int max[];

		public UnionFind(int N) {
			p = new int[numSets = N];
			rank = new int[N];
			setSize = new int[N];
			for (int i = 0; i < N; i++) {
				p[i] = i;
				setSize[i] = 1;
			}
		}

		public int findSet(int i) {
			return p[i] == i ? i : (p[i] = findSet(p[i]));
		}

		public boolean isSameSet(int i, int j) {
			return findSet(i) == findSet(j);
		}

		public void unionSet(int i, int j) {
			if (isSameSet(i, j))
				return;
			numSets--;
			int x = findSet(i), y = findSet(j);
			if (rank[x] > rank[y]) {
				p[y] = x;
				setSize[x] += setSize[y];

			} else {
				p[x] = y;
				setSize[y] += setSize[x];
				if (rank[x] == rank[y])
					rank[y]++;

			}
		}

		public int numDisjointSets() {
			return numSets;
		}

		public int sizeOfSet(int i) {
			return setSize[findSet(i)];
		}
	}

	/**
	 * private static void trace(int i, int time) { if(i==n) return;
	 *
	 *
	 * long ans=dp(i,time);
	 * if(time+a[i].t<a[i].burn&&(ans==dp(i+1,time+a[i].t)+a[i].cost)) {
	 *
	 * trace(i+1, time+a[i].t);
	 *
	 * l1.add(a[i].idx); return; } trace(i+1,time);
	 *
	 * }
	 **/

	static class incpair implements Comparable<incpair> {
		int a;
		long b;
		int idx;

		incpair(int a, long dirg, int i) {
			this.a = a;
			b = dirg;
			idx = i;
		}

		public int compareTo(incpair e) {
			return (int) (b - e.b);
		}
	}

	static class decpair implements Comparable<decpair> {
		int a;
		long b;
		int idx;

		decpair(int a, long dirg, int i) {
			this.a = a;
			b = dirg;
			idx = i;
		}

		public int compareTo(decpair e) {
			return (int) (e.b - b);
		}
	}

	static long allpowers[];

	static class Quad implements Comparable<Quad> {
		int u;
		int v;
		char state;
		int turns;

		public Quad(int i, int j, char c, int k) {
			u = i;
			v = j;
			state = c;
			turns = k;
		}

		public int compareTo(Quad e) {
			return (int) (turns - e.turns);
		}

	}

	static long dirg[][];
	static Edge[] driver;

	static int n;

	static class Edge implements Comparable<Edge> {
		int node;
		long cost;

		Edge(int a, long dirg) {
			node = a;
			cost = dirg;
		}

		public int compareTo(Edge e) {
			return (int) (cost - e.cost);
		}
	}

	static long manhatandistance(long x, long x2, long y, long y2) {
		return Math.abs(x - x2) + Math.abs(y - y2);
	}

	static long fib[];

	static long fib(int n) {
		if (n == 1 || n == 0) {
			return 1;
		}
		if (fib[n] != -1) {
			return fib[n];
		} else
			return fib[n] = ((fib(n - 2) % mod + fib(n - 1) % mod) % mod);
	}

	static class Point  implements Comparable<Point>{
		int x, y;

		Point(int a, int b) {
			x = a;
			y = b;
		}

		@Override
		public int compareTo(Point o) {
		if(x!=o.x) {
			return x-o.x;
		}
		return y-o.y;
		}

	}

	static long[][] comb;

	static class Triple implements Comparable<Triple> {

		int l;
		int r;
		long cost;
		int idx;

		public Triple(int a, int b, long l1, int l2) {
			l = a;
			r = b;
			cost = l1;
			idx = l2;
		}

		public int compareTo(Triple x) {
			if (l != x.l || idx == x.idx)
				return l - x.l;
			return -idx;
		}

	}

	static TreeSet<Long> primeFactors(long N) // O(sqrt(N) / ln sqrt(N))
	{
		TreeSet<Long> factors = new TreeSet<Long>(); // take abs(N) in case of -ve integers
		int idx = 0, p = primes.get(idx);

		while (p * p <= N) {
			while (N % p == 0) {
				factors.add((long) p);
				N /= p;
			}
			if (primes.size() > idx + 1)
				p = primes.get(++idx);
			else
				break;
		}

		if (N != 1) // last prime factor may be > sqrt(N)
			factors.add(N); // for integers whose largest prime factor has a power of 1
		return factors;
	}

	static boolean visited[];

	/**
	 * static int bfs(int s) { Queue<Integer> q = new LinkedList<Integer>();
	 * q.add(s); int count=0; int maxcost=0; int dist[]=new int[n]; dist[s]=0;
	 * while(!q.isEmpty()) {
	 *
	 * int u = q.remove(); if(dist[u]==k) { break; } for(Pair v: adj[u]) {
	 * maxcost=Math.max(maxcost, v.cost);
	 *
	 *
	 *
	 * if(!visited[v.v]) {
	 *
	 * visited[v.v]=true; q.add(v.v); dist[v.v]=dist[u]+1; maxcost=Math.max(maxcost,
	 * v.cost); } }
	 *
	 * } return maxcost; }
	 **/
	public static boolean FindAllElements(int n, int k) {
		int sum = k;
		int[] A = new int[k];
		Arrays.fill(A, 0, k, 1);

		for (int i = k - 1; i >= 0; --i) {

			while (sum + A[i] <= n) {

				sum += A[i];
				A[i] *= 2;
			}
		}
		if (sum == n) {
			return true;
		} else
			return false;
	}

	static boolean vis2[][];

	static boolean f2 = false;

	static long[][] matMul(long[][] a2, long[][] b, int p, int q, int r) // C(p x r) = A(p x q) x (q x r) -- O(p x q x
																			// r)
	{
		long[][] C = new long[p][r];
		for (int i = 0; i < p; ++i) {
			for (int j = 0; j < r; ++j) {
				for (int k = 0; k < q; ++k) {
					C[i][j] = (C[i][j] + (a2[i][k] % mod * b[k][j] % mod)) % mod;
					C[i][j] %= mod;
				}

			}
		}
		return C;
	}

	static int memo1[];

	static boolean vis[];
	static TreeSet<Integer> set = new TreeSet<Integer>();

	static long modPow(long ways, long count, long mod) // O(log e)
	{
		ways %= mod;
		long res = 1;
		while (count > 0) {
			if ((count & 1) == 1)
				res = (res * ways) % mod;
			ways = (ways * ways) % mod;
			count >>= 1;
		}
		return res % mod;
	}

	static long gcd(long ans, long b) {
		if (b == 0) {
			return ans;
		}
		return gcd(b, ans % b);
	}

	static int[] isComposite;
	static int[] valid;

	static ArrayList<Integer> primes;
	static ArrayList<Integer> l1;

	static TreeSet<Integer> primus = new TreeSet<Integer>();

	static void sieveLinear(int N)
	{
		int[] lp = new int[N + 1];								//lp[i] = least prime divisor of i
		for(int i = 2; i <= N; ++i)
		{
			if(lp[i] == 0)
			{
				primus.add(i);
				lp[i] = i;
			}
			int curLP = lp[i];
			for(int p: primus)
				if(p > curLP || p * i > N)
					break;
				else
					lp[p * i] = i;
		}
	}

	public static int[] schuffle(int[] p) {
		for (int i = 0; i < p.length; i++) {
			int x = (int) (Math.random() * p.length);
			int temp = p[x];
			p[x] = p[i];
			p[i] = temp;
		}
		return p;
	}

	static int V;
	static long INF = (long) 1E16;

	static class Edge2 {
		int node;
		long cost;
		long next;

		Edge2(int a, int c, Long long1) {
			node = a;
			cost = long1;
			next = c;
		}

	}

	static class Scanner {
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream system) {
			br = new BufferedReader(new InputStreamReader(system));
		}

		public Scanner(String file) throws Exception {
			br = new BufferedReader(new FileReader(file));
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		public String nextLine() throws IOException {
			return br.readLine();
		}

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

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

		public char nextChar() throws IOException {
			return next().charAt(0);
		}

		public Long nextLong() throws IOException {
			return Long.parseLong(next());
		}

		public boolean ready() throws IOException {
			return br.ready();
		}

		public void waitForInput() throws InterruptedException {
			Thread.sleep(3000);
		}

		public int[] nxtArr(int n) throws IOException {
			int[] ans = new int[n];
			for (int i = 0; i < n; i++)
				ans[i] = nextInt();
			return ans;
		}
	}
}

import java.util.Scanner;
public class unusual_computing {
       public static void main(String[] args) {
    	   Scanner in=new Scanner(System.in);
    	   long a=in.nextLong();
    	   long b=in.nextLong();
    	   while((a!=0 && b!=0)){
    		   if(a>=2*b) {
    			   a=a%(2*b);
    		   }
    		   else if(b>=2*a) {
    			   b=b%(2*a);
    		   }
    		   else{
    			break;
    		   }}

            	System.out.println(a+" "+b);

       }
}

import java.util.Scanner;

public class weirdSubtractionProcess {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long a = sc.nextLong();
        long b = sc.nextLong();

                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;
                }
        System.out.println(a+" "+b);
        sc.close();
    }
}

import java.util.Scanner;

public class B {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long a, b;

        a = sc.nextLong();
        b = sc.nextLong();

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

        System.out.println(a + " " + b);
        sc.close();
    }
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class WeirdSubtractionProcess {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer(br.readLine());
        long a = Long.parseLong(st.nextToken());
        long b = Long.parseLong(st.nextToken());

        while(a != 0 && b != 0){
            if(a < 2*b && b < 2*a){
                break;
            }
            if(a > b){
                a = a % (2*b);
            }
            if(b > a && a != 0){
                b = b % (2*a);
            }
        }
        System.out.println(a + " " + b);
    }
}

import java.util.Scanner;
public class WeirdSubs{
	public static void main(String[] args) {
	Scanner tm= new Scanner(System.in);
	long a=tm.nextLong();
	long b=tm.nextLong();

		while (a!=0 && b!=0 && (a >= 2*b || b >= 2*a)){

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

		}
		System.out.println(a+" "+b);
	}

}

import java.util.Scanner;

/**
 *
 * @author Eduardo
 */
public class ProgramacionCompetitiva {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        long a,b;

        a = scan.nextLong();
        b = scan.nextLong();

        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;
            }
        }

        System.out.println(a+" "+b);
    }
}

import java.util.Scanner;

public class Weird_Substraction {
	static Scanner sc = new Scanner(System.in);
	private static long a,b;

	public static void main (String args[]) {

		a=sc.nextLong();
		b=sc.nextLong();

		while (a!=0 && b!=0) {

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

			}

		}

		System.out.println(a+" "+b);

	}

}

import java.util.Scanner;

public class WeirdSubstraction {

    public static void weirdSubstraction(){
        Scanner sc = new Scanner(System.in);
        long a = 0;
        long b = 0;

        a = sc.nextLong();
        b = sc.nextLong();

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

        System.out.println(a+" "+b);
    }

    public static void weirdSubstractionRec(long a, long b){
        if(a == 0 || b == 0){
            System.out.println(a+" "+b);
        }
        else if(a >= b*2) {
            a -= 2*b;
            weirdSubstractionRec(a, b);
        }
        else if(b >= a*2) {
            b -= 2*a;
            weirdSubstractionRec(a, b);
            }
        else {
            System.out.println(a+" "+b);
        }
    }

    public static void main(String[] args) {
        /*Scanner sc = new Scanner(System.in);

        long a = sc.nextLong();
        long b = sc.nextLong();
        */
        weirdSubstraction();
    }

}

import java.util.*;
public class weird_subtraction_process
{
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
	    long a=in.nextLong();
	    long b=in.nextLong();
	    while(a!=0 && b!=0)
	    {
	    	if(a>=(2*b))
	    	{
	    		a=a%(2*b);
	    	}
	    	else if(b>=(2*a))
	    	{
	    		b=b%(2*a);
	    	}
	    	else
	    	{
	    		System.out.println(a+" "+b);
	    		System.exit(0);
	    	}
	    }
	    System.out.println(a+" "+b);
	}
}

import java.util.Scanner;

public class ProblemB {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		long a = scan.nextLong();
		long b = scan.nextLong();
		long preA = a;
		long preB = b;
		while(true) {
			if(a == 0 || b == 0) {
				break;
			}else if(!(a >= b*2) && !(b >= a *2)){
				break;
			}
			a %= b*2;
			if(a == 0 || b == 0) {
				break;
			}else if(!(a >= b*2) && !(b >= a *2)){
				break;
			}
			b %= a*2;
			if(a == 0 || b == 0) {
				break;
			}else if(!(a >= b*2) && !(b >= a *2)){
				break;
			}

			if(a == preA && b == preB) {
				break;
			}else{
				preA = a;
				preB = b;
			}
		}
		System.out.println(a + " " + b);

	}

}

import java.math.BigInteger;
import java.util.*;
import java.io.*;

public class Main {

    /**
     */

    public static void main(String[] args) {
        FastReader sc = new FastReader();
        long a = sc.nextLong();
        long b = sc.nextLong();
        while (a!=0 && b!=0) {
            if (a>=2*b) {
                a%=2*b;
            } else if (b>=2*a) {
                b%=2*a;
            } else {
              break;
            }
        }
        System.out.println(a+" "+b);
    }

    private static int[] prefix_function(String s) {
        int n = s.length();
        int[] res = new int[n];
        for (int i = 1; i < n; i++) {
            int j = res[i-1];
            while (j > 0 && s.charAt(i) != s.charAt(j)) {
                j = res[j-1];
            }
            if (s.charAt(i)==s.charAt(j)) {
                j++;
            }
            res[i] = j;
        }
        return res;
    }

    private static boolean check(String s) {
        char cc = s.charAt(0);
        for (char c : s.toCharArray()) {
            if (c!=cc) return false;
        }
        return true;
    }

    private static int[] isPrime(int num) {
        for (int i = 2; i <= (int)Math.sqrt(num); i++) {
            if (num % i == 0) return new int[]{i, num/i};
        }
        return null;
    }

    private static int sign(long num) {
        if (num < 0) return -1;
        return 1;
    }

    private static class Pair {
        int x;
        int y;
        public Pair(int x, int y) {
            this.x=x;
            this.y=y;
        }
    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

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

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

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

    }

}

/**
 * 7 3
 * 3 1 5
 * 9 6 5
 *
 * i = 1: 1
 * i = 2: 2
 * i = 3: 3
 *
 *
 * 1 2 3 3 3 3 3
 */

/**
 *
 *  1+1
 **/

import java.util.*;

public class Ed39B {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		long a = sc.nextLong();
		long b = sc.nextLong();

		System.out.println(check(a, b));

	}

	private static String check(long a, long b) {
		if(a==0 || b==0){
			return a+" "+b;
		}
		if(a>=2*b){
			return check(a%(2*b), b);
		}
		if(b>=2*a){
			return check(a, b%(2*a));
		}
		return a+" "+b;
	}

}

import java.util.Scanner;

public class JavaApplication3 {

    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        long a=sc.nextLong();
        long b=sc.nextLong();
        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;
            }
        }
        System.out.println(a+" "+b);
    }
}

import java.io.*;
import java.util.*;
import static java.lang.Math.*;

public class CF {

    public static void main(String[] args) throws IOException {
        //BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        //BufferedReader in = new BufferedReader(new FileReader("a.in"));
        FastScanner in = new FastScanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
        long n = in.nextLong();
        long m = in.nextLong();
        while (m != 0 && n != 0) {
            if (n >= 2 * m) {
                n %= 2 * m;
            } else if (m >= 2 * n) {
                m %= 2 * n;
            } else {
                break;
            }
        }
        out.println(n + " " + m);
        out.close();
    }

    static class FastScanner {

        private BufferedReader in;
        private String[] line;
        private int index;
        private int size;

        public FastScanner(InputStream in) throws IOException {
            this.in = new BufferedReader(new InputStreamReader(in));
            init();
        }

        public FastScanner(String file) throws FileNotFoundException {
            this.in = new BufferedReader(new FileReader(file));
        }

        private void init() throws IOException {
            line = in.readLine().split(" ");
            index = 0;
            size = line.length;
        }

        public int nextInt() throws IOException {
            if (index == size) {
                init();
            }
            return Integer.parseInt(line[index++]);
        }

        public long nextLong() throws IOException {
            if (index == size) {
                init();
            }
            return Long.parseLong(line[index++]);
        }

        public float nextFloat() throws IOException {
            if (index == size) {
                init();
            }
            return Float.parseFloat(line[index++]);
        }

        public double nextDouble() throws IOException {
            if (index == size) {
                init();
            }
            return Double.parseDouble(line[index++]);
        }

        public String next() throws IOException {
            if (index == size) {
                init();
            }
            return line[index++];
        }

        public String nextLine() throws IOException {
            if (index == size) {
                init();
            }
            StringBuilder sb = new StringBuilder();
            for (int i = index; i < size; i++) {
                sb.append(line[i]).append(" ");
            }
            return sb.toString();
        }

    }

}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.StringTokenizer;

public class Holi {

	static class FastReader {

		BufferedReader br;
		StringTokenizer st;

		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

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

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

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

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

	public static void main(String[] args) throws IOException {
		FastReader sc = new FastReader();
		// codeChefQ2(sc);
		// codeChefQ3(sc);
		// codeChef4(sc);
		long a=sc.nextLong(),b=sc.nextLong();
		method(a,b);
//		System.out.println(a+" "+b);
	}
	public static void method(long a,long b){
	    while(true && a !=0 && b!=0){
	        if(a>=2*b){
	            a=a%(2*b);
	        } else if(b>=2*a){
	            b=b%(2*a);
	        } else if(a==0 || b==0||(a>=b && a<=2*b)||(b>a && b<2*a))break;
	    }

	    System.out.println(a+" "+b);
	}

	private static void codeChef4(FastReader sc) {
		int t = sc.nextInt();
		while (t-- > 0) {
			int n = sc.nextInt(), h = sc.nextInt();
			Integer[] arr = new Integer[n];
			long ans = 0;
			for (int i = 0; i < n; i++)
				arr[i] = sc.nextInt();
			Arrays.sort(arr, new Comparator<Integer>() {

				@Override
				public int compare(Integer o1, Integer o2) {
					// TODO Auto-generated method stub
					return o2 - o1;
				}
			});
			if (h >= n && (h - n) < n && (h - n) >= 0) {
				int ind = h - n;
				System.out.println(arr[ind]);
			} else
				System.out.println(0);
		}
	}

	private static void codeChefQ3(FastReader sc) {
		int t = sc.nextInt();
		while (t-- > 0) {
			java.util.HashMap<Integer, Integer> mp = new java.util.HashMap<>();
			int n = sc.nextInt();
			ArrayList<Integer> aa = new ArrayList<>();
			long ans = 0;
			for (int i = 0; i < n; i++) {
				int val = sc.nextInt();
				if (!mp.containsKey(val)) {
					mp.put(val, 1);
					aa.add(val);
				} else {
					int ind = aa.size() - 1;
					while (true && ind >= 0) {
						int num = val + aa.get(ind);
						if (!mp.containsKey(num)) {
							mp.put(num, 1);
							aa.add(num);
							ans++;
							break;
						} else
							ind--;
					}
					ind = aa.size() - 1;
				}
			}

			System.out.println(ans);
		}
	}

	private static void codeChefQ2(FastReader sc) {
		int t = sc.nextInt();
		while (t-- > 0) {
			int n = sc.nextInt();
			double ans = 0;
			for (int i = 0; i < n; i++) {
				double p = sc.nextDouble(), q = sc.nextDouble(), d = sc.nextDouble(), new_p, leftP;
				new_p = p;
				p = p + (p * d / 100);
				p = p - (p * d / 100);
				// System.out.println(" "+leftP);
				ans += ((new_p - p) * q);
			}
			System.out.printf("%.6f", ans);
			System.out.println();
		}

	}
}

import java.io.*;
import java.util.*;
public class Mohammad  {
    //------------------------------|بسم الله الرحمن الرحيم|------------------------------//
    public static void Mohammad_AboHasan() throws IOException{
        FastReader fr = new FastReader();
        long a = fr.nextLong();
        long b = fr.nextLong();
        while(a > 0 && b > 0){
            if(a >= b*2)
                a %= b*2;
            else if(b >= a*2)
                b %= a*2;
            else
                break;
        }
        System.out.println(a + " " + b);
    }
    //-----------------------------------|الحمدلله|-----------------------------------//

    public static void main(String[] args) throws IOException{
        Mohammad_AboHasan();
    }
    //-------------------------------------FAST I/O-------------------------------------//
    static class FastReader{
        BufferedReader br;
        StringTokenizer st;
        public FastReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }
        String next() throws IOException{
            while (st == null || !st.hasMoreElements()) {
                    st = new StringTokenizer(br.readLine());
            }
            return st.nextToken();
        }
        int nextInt() throws IOException{
            return Integer.parseInt(next());
        }
        long nextLong() throws IOException{
            return Long.parseLong(next());
        }
        double nextDouble() throws IOException{
            return Double.parseDouble(next());
        }
        String nextLine() throws IOException{
            String s = br.readLine();
            return s;
        }
    }
}

import java.util.Scanner;
import java.lang.*;

public class Solution{
	public static void main(String args[]){
		Scanner sc=new Scanner(System.in);
		long a=sc.nextLong();
		long b=sc.nextLong();

	while(a!=0 && b!=0){
		//System.out.println(a+" "+b);
		if(a >= 2*b)
			a=a%(2*b);
		else if(b>= 2*a)
			b=b%(2*a);
		else
			break;
	}
	System.out.println(a+" "+b);
	}
}

import java.util.*;

public class Main{
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);

        long a = sc.nextLong();
        long b = sc.nextLong();

        while(a != 0 && b != 0)
        {
            long t = 0;
            if(a >= 2 * b)
            {
                t = a / (2 * b);
                a = a - t * 2 * b;
                continue;
            } else if(b >= 2 * a)
            {
                t = b / (2 * a);
                b = b - t * 2 * a;
                continue;
            } else {
                break;
            }
        }
        cout(a);
        cout(" ");
        cout(b);
    }

    private static void cout(Object a) {
        System.out.print(a);
    }
}

import java.util.*;
public class B946 {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc1 = new Scanner(System.in);
		long a = sc1.nextLong();
		long b = sc1.nextLong();

		boolean flag = true;
		int x=1;
		while(flag) {
			if(a==0 || b==0) {
				System.out.println(a+" "+b);
				return;
			}
			else if(a>=2*b) {
				//a = a - 2*b;
				a = a%(2*b);
				//System.out.println("MIHIR"+a+" "+b);
			}
			else if(b>=2*a) {
				//b = b - 2*a;
				b = b%(2*a);

				//System.out.println("DIVY"+a+" "+b);
			}
			else {
				break;
			}
		}
		System.out.println(a+" "+b);
	}

}

import java.util.Scanner;

public class sequence {

    static long a, b;
    static Scanner scanner = new Scanner(System.in);

    public static void main(String[] args) {

        a = scanner.nextLong();
        b = scanner.nextLong();

        while(true)
        {

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

            if(a >=  b << 1){

                long bmult = b << 1;
                long multiplier = a / bmult;

                a -= (bmult * multiplier);
            }

            else if(b >= (a << 1)){

                long amult = a << 1;
                long multiplier = b / amult;

                b -= (amult * multiplier);
            }

            else
                break;
        }

        System.out.println(a + " " + b);

    }

}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class WeirdSubtractionProcess {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer(br.readLine());
        long a = Long.parseLong(st.nextToken());
        long b = Long.parseLong(st.nextToken());

        while(a != 0 && b != 0){
            if(a < 2*b && b < 2*a){
                break;
            }
            if(a > b){
                a = a % (2*b);
            }
            if(b > a && a != 0){
                b = b % (2*a);
            }
        }
        System.out.println(a + " " + b);
    }
}

import java.util.Scanner;
public class B {

	private static Scanner scanner = new Scanner(System.in);
	private static long a, b;

	public static void main(String[] args) {
		a = Long.parseLong(scanner.next());
		b = Long.parseLong(scanner.next());

		while (true) {
			if (a == 0 || b == 0 || a < 2 * b && b < 2 * a) break;
			a = a % (2 * b);
			if (a == 0 || b < 2 * a) break;
			b = b % (2 * a);
		}
		System.out.println(a + " " + b);

	}

}

import java.util.*;
public class Solution
{
    public static void main(String [] args)
    {
        Scanner sc=new Scanner(System.in);
        /*
        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.

Input
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.

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

Examples
inputCopy
12 5
output
0 1
inputCopy
31 12
output
7 12

        */
        long a=sc.nextLong();
        long b=sc.nextLong();
        long n=0;
        while(true)
        {
            //System.out.println("a="+a+" b="+b +" Outside");
            if(a==0 || b==0)
                break;
            if(a>=2*b)
            {
                n=(a/(2*b) );
                a=a-2*n*b;
               // System.out.println("a="+a+" b="+b+" n="+n+" Inside 1");
                continue;
            }
            if(b>=2*a)
            {
                n=(b/(2*a) );
                b=b-2*n*a;
               // System.out.println("a="+a+" b="+b+" n="+n+" Inside 2");
                continue;
            }
            break;
        }
        System.out.println(a+" "+b);
    }
}

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

// Good problem!
public class Weird_Subtraction_Process {
	public static long[] f( long a, long b)
	{
		long result[], k;
		if ( a == 0 || b == 0) result  = new long[]{a, b};
		else if ( a >= 2l*b ) { result = f(a % (2l*b), b); }
		else if ( b >= 2l*a ) { result = f(a, b % (2l*a)); }
		else result = new long[]{a, b};
		return result;
	}
	public static void main(String args[])
	{
		Scanner in = new Scanner(System.in);
		long a, b;
		a = in.nextLong();
		b = in.nextLong();
		long[] result = f(a, b);
		System.out.println(result[0]+" "+result[1]);
	}
}

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.IOException;

public class B{
    public static void main(String[] args)throws IOException{
	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	PrintWriter out = new PrintWriter(System.out);
	String s[] = br.readLine().split(" ");
	long a = Long.parseLong(s[0]);
	long b = Long.parseLong(s[1]);
	while(a!=0 && b!=0){
	    if(a>=2*b){
		a%=2*b;
	    }else if(b>=2*a){
		b%=2*a;
	    }else{
		break;
	    }
	}
	out.println(a+" "+b);
	out.close();
    }
}

import java.util.*;

public class WeirdSubstractionProcess {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		long a = sc.nextLong();
		long b = sc.nextLong();

		boolean flag = true;

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

		System.out.println(a+" "+b);

	}
}

import java.io.*;
import java.util.*;
import java.math.BigInteger;
public class Main {
    private static StringBuilder sb = new StringBuilder();
    private static void s(String s){
        System.out.print(s);
    }
    private static void s(Double s){
        System.out.print(s);
    }
    private static void s(char s){
        System.out.print(s);
    }
    private static void sn(String s){
        System.out.println(s);
    }
    private static void sn(Boolean s){
        System.out.println(s);
    }
    private static void sn(long s){
        System.out.println(s);
    }
    private static void sn(Double s){
        System.out.println(s);
    }
    private static void sn(String s, Object o){
        sb.append(s+"\n");
    }
    private static void sn(long s, Object o){
        sb.append(s+"\n");
    }
    private static void sn(boolean s, Object o){
        sb.append(s+"\n");
    }
    private static void pr() throws Exception{
        BufferedWriter bw =new BufferedWriter(new OutputStreamWriter(System.out));
        bw.write(sb.toString());
        bw.flush();
    }
    static class Reader{
        final private int BUFFER_SIZE = 1 << 16;
        private DataInputStream din;
        private byte[] buffer;
        private int bufferPointer, bytesRead;

        public Reader()
        {
            din = new DataInputStream(System.in);
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }

        public Reader(String file_name) throws IOException
        {
            din = new DataInputStream(new FileInputStream(file_name));
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }

        public String readLine() throws IOException
        {
            byte[] buf = new byte[51]; // line length
            int cnt = 0, c;
            while ((c = read()) != -1)
            {
                if (c == '\n')
                    break;
                buf[cnt++] = (byte) c;
            }
            return new String(buf, 0, cnt);
        }

        public int nextInt() throws IOException
        {
            int ret = 0;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do
            {
                ret = ret * 10 + c - '0';
            }  while ((c = read()) >= '0' && c <= '9');

            if (neg)
                return -ret;
            return ret;
        }

        public long nextLong() throws IOException
        {
            long ret = 0;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do {
                ret = ret * 10 + c - '0';
            }
            while ((c = read()) >= '0' && c <= '9');
            if (neg)
                return -ret;
            return ret;
        }

        public double nextDouble() throws IOException
        {
            double ret = 0, div = 1;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();

            do {
                ret = ret * 10 + c - '0';
            }
            while ((c = read()) >= '0' && c <= '9');

            if (c == '.')
            {
                while ((c = read()) >= '0' && c <= '9')
                {
                    ret += (c - '0') / (div *= 10);
                }
            }

            if (neg)
                return -ret;
            return ret;
        }

        private void fillBuffer() throws IOException
        {
            bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
            if (bytesRead == -1)
                buffer[0] = -1;
        }

        private byte read() throws IOException
        {
            if (bufferPointer == bytesRead)
                fillBuffer();
            return buffer[bufferPointer++];
        }

        public void close() throws IOException
        {
            if (din == null)
                return;
            din.close();
        }
    }
    private static boolean isPrime(Integer ii){
        return new BigInteger(ii+"").isProbablePrime(1);
    }
    private static boolean isDigit(int ii){
        return Character.isDigit((char)ii);
    }
    private static long fact(int f){
        if(f==0){
            return 1;
        }
        return (long)f * (long)fact(f-1);
    }
    private static Reader r = new Reader();
    private static int ni() throws Exception{
        return r.nextInt();
    }
    private static String ns() throws Exception{
            return r.readLine();
        }
    private static long nl() throws Exception{
        return r.nextLong();
    }
    private static int[] na(int a) throws Exception{
        int arr[] = new int[a];
        for(int i=0;i<a;i++){
            arr[i] = r.nextInt();
        }
        return arr;
    }
    private static long[] nal(int a) throws Exception{
        long arr[] = new long[a];
        for(int i=0;i<a;i++){
            arr[i] = r.nextLong();
        }
        return arr;
    }
        static void printSubsets(char set[])
    {
        int n = set.length;

        // Run a loop for printing all 2^n
        // subsets one by obe
        for (int i = 0; i < (1<<n); i++)
        {
            System.out.print("{ ");

            // Print current subset
            for (int j = 0; j < n; j++)

                // (1<<j) is a number with jth bit 1
                // so when we 'and' them with the
                // subset number we get which numbers
                // are present in the subset and which
                // are not
                if ((i & (1 << j)) > 0)
                    System.out.print(set[j] + " ");

            System.out.println("}");
        }
    }

    static class Query implements Comparable<Query>{
        int l,r,blk,idx;
        long an;
        Query(int l, int r, int blk, int f){
            this.l = l;
            this.r = r;
            this.blk = blk;
            idx= f;
        }

        public int compareTo(Query q){
            if(blk==q.blk){
                if((blk & 1) != 1){
                    return r - q.r;
                } else return q.r - r;

            }
            else{
                return blk-q.blk;
            }
        }
        public String toString(){
            return l+" "+r+ " "+blk+" "+idx;
        }

    }

    private static void add(int ind, int arr[]){
        ans+=(++cnt[arr[ind]]==1?1:0);
    }

    private static void remove(int ind, int arr[]){
        ans-=(cnt[arr[ind]]--==1?1:0);
    }

    static int ans =0;
    static int curl = 0;
   static int curr = 0;
   static int cnt[] = new int[1000006];
   class Sol{
       int idx,cnt;
       char rr;
   }
    private static void solve() throws Exception{
        long a = nl();
        long b = nl();
        while(a!=0 && b!=0){
            if(a>=2*b){
                a%=2*b;
            } else if(b>=a*2){
                b%=2*a;
            } else break;
        }
        sn(a+" "+b);
    }

	public static void main (String[] args) throws Exception{
	    int tc =1;
	    while(tc-->0){
	        solve();
	    }
	}
}

import java.util.Scanner;

public class b {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		long a = in.nextLong();
		long b = in.nextLong();
		while((a>=2*b || b>=2*a) && a!=0 && b!=0){
			if(b!=0 && a>=2*b) a%=2*b;
			else if(a!=0 && b>=2*a) b%=2*a;
			if(a>=2*b)a-=2*b;
			else if(b>=2*a)b-=2*a;
		}
		System.out.println(a+" "+b);
	}

}

import java.util.*;
public class MyClass {
    public static void main(String args[]) {
     Scanner in=new Scanner(System.in);long t=1,a=0,b=0,m=0,n=0,count=0;
   //  if(in.hasNext())
    // t=in.nextInt();
     for(int j=0;j<t;j++)
     {
         if(in.hasNext())
         a=in.nextLong();
          if(in.hasNext())
         b=in.nextLong();
         count=0;
         boolean c1=false,c2=false;
         while(a>0 && b>0)
         {
             c1=false;c2=false;
             if(a>=2*b)
             {a=a%(2*b);c1=true;}
             if(a==0 || b==0)
             break;
             if(b>=2*a)
             {b=b%(2*a);c2=true;}
             if(c1==false && c2==false)
             break;
            // m=Math.max(a,b);
             //n=Math.min(a,b);
             //b=m%n;
             //a=n*(b+1)-n*b;
             //count+=m/n;
             //System.out.println(a+" "+b);
         }
         System.out.println(a+" "+b);
     }
    }
}

import java.util.*;
public class Weird{
	public static void main(String[] args) {
		Scanner in=new Scanner(System.in);
		long a,b;
		a=in.nextLong();
		b=in.nextLong();
		while(a!=0&&b!=0){
			if(a>=2*b){
				a=a%(2*b);
			}
			else if(b>=2*a){
				b=b%(2*a);
			}
			else{
				break;
			}
		}
		System.out.print(a);
		System.out.print(' ');
		System.out.print(b);
	}
}

import java.util.Scanner;

public class Problem_b {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		long a= scan.nextLong();
		long b =scan.nextLong();
		while(true){
			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;
					if(a==0||b==0){
						break;
					}
				}
			}
			else if(b>=2*a){
				b%=2*a;
				if(a==0||b==0){
					break;
				}
			}
			else{
				break;
			}

		}

		System.out.println(a+" "+b);
	}

}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * Created by tejal.k on 3/17/2018.
 */
public class Eductional39ProblemB {
    public static void main(String[] args) throws IOException {
        BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
        String[] s = bf.readLine().split(" ");
        long a = Long.parseLong(s[0]);
        long b = Long.parseLong(s[1]);
        boolean setA = true, setB = true;
        while (a != 0 && b != 0 && (setA != false || setB != false)) {
            setA = false;setB=false;
            if (b != 0 && a >= 2*b) {
                setA = true;
                if (a>2*b) {
                    a = Math.floorMod(a,2*b);
                } else {
                    a -= 2*b;
                }
//                System.out.println("a " + a);
//                System.out.printf("seta " + setA);
            }
            if (a != 0 && b >= 2*a) {
                setB = true;
                if (b>2*a) {
                    b = Math.floorMod(b, 2*a);
                } else {
                    b -= 2 * a;
                }
//                System.out.println("b " + b);
//                System.out.printf("setb " + setB);
            }
        }
        System.out.println(a + " " + b);
    }
}

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author 4erneff
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskB {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            long a = (in.nextLong());
            long b = (in.nextLong());
            Pair ans = fun(a, b);
            out.println(String.format("%d %d", ans.first, ans.second));
        }

        private Pair fun(long a, long b) {
            //System.out.println(String.format("%d %d", a , b));
            if (a == 0 || b == 0) {
                return new Pair(a, b);
            } else {
                if (a / 2 >= b) {
                    long diff = a - 2 * b;
                    long times = diff / (2 * b) + 1;
                    return fun(a - 2 * times * b, b);
                } else {
                    if (b / 2 >= a) {
                        long diff = b - 2 * a;
                        long times = diff / (2 * a) + 1;
                        return fun(a, b - 2 * times * a);
                    } else return new Pair(a, b);
                }
            }
        }

        private class Pair {
            long first;
            long second;

            Pair(long a, long b) {
                this.first = a;
                this.second = b;
            }

        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputReader.SpaceCharFilter filter;

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

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

        public long nextLong() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            long res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

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

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}

import java.util.*;

public class Weird{
	public static void main (String[] args){
		long n, m;
		Scanner sc = new Scanner(System.in);
		n = sc.nextLong();
		m = sc.nextLong();
		if(n>=1 && m<= Math.pow(10, 18)) resta(n,m);

	}

	public static void resta(long a, long b){
		while(a!=0 && b!=0){
			if(a>=2*b){
				a %= (2*b);
			}
			else if(b >= 2*a){
				b %= (2*a);
			}
			else{break;}
		}
		System.out.println(a+" "+b);
	}
}

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

import java.util.Scanner;

/**
 *
 * @author cat_dominguez
 */
public class Prob3 {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
       long a, b;
        Scanner kb=new Scanner(System.in);
        a=kb.nextLong();
        b=kb.nextLong();
        while (a!=0 && b!=0 && (a>=b*2 || b>=a*2)){
            if(a>=b*2){
                a%=2*b;
           } else if (b>=a*2){
               b%=a*2;
           }
        }
        System.out.println(a+ " "+b);
    }

}

import java.util.Scanner;

public class Problema3{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		long a, b;
		a = sc.nextLong();
		b = sc.nextLong();

		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);
			}
		}
		System.out.println(a+" "+b);
	}
}

import java.util.*;

public class Main{
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);

        long a = sc.nextLong();
        long b = sc.nextLong();

        while(a != 0 && b != 0)
        {
            long t = 0;
            if(a >= 2 * b)
            {
                t = a / (2 * b);
                a = a - t * 2 * b;
                continue;
            } else if(b >= 2 * a)
            {
                t = b / (2 * a);
                b = b - t * 2 * a;
                continue;
            } else {
                break;
            }
        }
        cout(a);
        cout(" ");
        cout(b);
    }

    private static void cout(Object a) {
        System.out.print(a);
    }
}

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

public class B {

	public static void main(String[] args)
	{
			Scanner in = new Scanner(System.in);
			long a = in.nextLong(), b = in.nextLong();

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

			System.out.println(a + " " + b);
	}

}

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

public class solution {
    public static class InputReader {
        private final InputStream stream;
        private final byte[] buf = new byte[8192];
        private int curChar, snumChars;

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

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

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

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

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

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

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

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

        private boolean isEndOfLine(int c) {
            return c == '\n' || c == '\r' || c == -1;
        }
    }
   public static void ans(long a,long b){
        if(a == 0 || b == 0){
            System.out.println(a + " " + b);
            return;
        }
        else if(a>=2*b){
            a%=2*b;
            ans(a,b);
        }
        else if(b>=2*a){
            b%=2*a;
            ans(a,b);
        }
        else{
            System.out.println(a + " " + b);
            return;
        }
   }
    public static void main(String[] args) throws IOException {
        InputReader in = new InputReader(System.in);
        long a = in.nextLong();
        long b = in.nextLong();
        ans(a,b);
    }

    static class sort implements Comparator<ArrayList<Integer>> {

        @Override
        public int compare(ArrayList<Integer> o1, ArrayList<Integer> o2) {
            int c = o1.get(0).compareTo(o2.get(0));
            return c;
        }

    }
}

import java.util.Scanner;

public class RangeTest {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);

		long a = in.nextLong();
	    long b = in.nextLong();

		while(a!=0 && b!=0) {

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

		System.out.println(a + " " + b);
	}
}

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

// Good problem!
public class Weird_Subtraction_Process {
	public static long[] f( long a, long b)
	{
		long result[], k;
		if ( a == 0 || b == 0) result  = new long[]{a, b};
		else if ( a >= 2l*b ) { result = f(a % (2l*b), b); }
		else if ( b >= 2l*a ) { result = f(a, b % (2l*a)); }
		else result = new long[]{a, b};
		return result;
	}
	public static void main(String args[])
	{
		Scanner in = new Scanner(System.in);
		long a, b;
		a = in.nextLong();
		b = in.nextLong();
		long[] result = f(a, b);
		System.out.println(result[0]+" "+result[1]);
	}
}

import java.io.*;
import java.util.*;
import java.util.regex.*;
public class vk18
{
    public static void main(String[]stp) throws Exception
    {
    	Scanner scan=new Scanner(System.in);
        //BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        //String []s;
        long a=scan.nextLong(),b=scan.nextLong(),i;
        while(true)
        {
        	if(a==0 || b==0) { System.out.println(a+" "+b); System.exit(0); }
        	else if(a>=2*b) { a=a%(2*b); }
        	else if(b >= 2*a) { b=b%(2*a);}
        	else {
        		System.out.println(a+" "+b); System.exit(0);
        	}
        }
    }
}

import java.util.*;
import java.io.*;
public class subs{
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        long a=sc.nextLong();
        long b=sc.nextLong();
        while(true){
            if(a==0||b==0) break;
            else if(a>=2*b){
                long m=a/b;
                if(m%2==0)
                    a-=(m*b);
                else
                    a-=((m-1)*b);
                continue;
            }
            else if(b>=2*a){
                long m=b/a;
                if(m%2==0)
                    b-=(m*a);
                else
                    b-=((m-1)*a);
                continue;
            }
            else break;
        }
        System.out.println(a+" "+b);
    }
}

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

import java.util.Scanner;

/**
 *
 * @author A07025360
 */
public class BWeirdSubstractionProcess {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        long a = scan.nextLong();
        long b = scan.nextLong();

        while (a!=0 && b!=0 && (a >= 2*b || b >= 2*a)){
            if( a>=2*b){
                a%=(2*b);
            }else if(b>=2){
                b%=(2*a);
            }else{
                break;
            }
	}
	System.out.println(a+" "+b);
    }
}

import java.util.Scanner;

public class WeirdSubstractionProcess{

	public void weirdSubstract(long a, long b){
		if(a == 0 || b == 0){
			System.out.println(a + " " + b);
		}
		else if(a >= (2*b)){
			weirdSubstract(a%(2*b), b); 	//it is the same as doing weirdSubstract(a - (2*b), b);
		}
		else if(b >= (2*a)){
			weirdSubstract(a, b%(2*a));	//it is the same as doing weirdSubstract(a, b - (2*a))
		}
		else{
			System.out.println(a + " " + b);
		}
	}

	public static void main(String[] args){
		WeirdSubstractionProcess test = new WeirdSubstractionProcess();
		Scanner user_input = new Scanner( System.in );
		long a = user_input.nextLong();
		long b = user_input.nextLong();
		test.weirdSubstract(a, b);
	}
}

import java.util.*;
public class weird {
	public static void main(String[] args) {
		Scanner sc =new Scanner(System.in);
		long a =sc.nextLong(),b=sc.nextLong();

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

		System.out.println(a +" "+ b);

	}

}

import java.util.Scanner;

public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long a = sc.nextLong(), b = sc.nextLong();
        while (a != 0 && b != 0){
            if (a >= 2 * b) {
                long buf = a / (2 * b);
                a -= buf * 2 * b;
            }
            else if (b >= 2 * a) {
                long buf = b / (2 * a);
                b -= buf * 2 * a;
            }
            else break;
        }
        System.out.println(a + " " + b);
    }
}

import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		long a = s.nextLong();
		long b = s.nextLong();
		long temp=-1;
		boolean c = true;
		while(c){
			if (a>=2*b){
				long div = a/(2*b);
				a-=2*b*div;
				if (a == 0 || b == 0) {
					c=false;
				}
			}
			else if(b>=2*a){
				long div = b/(2*a);
				b-=2*a*div;
				if (a == 0 || b == 0){
					c=false;
				}
			}
			else{
				temp = a;
				c=false;
			}
		}
		if (temp>-1)
			System.out.printf("%d %d\n", temp, b);
		else
			System.out.printf("%d %d\n", a, b);
	}
}

import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.io.IOException;
import java.lang.reflect.Array;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Set;

public class Codesorcesb {
    public static void main(String[] args) throws IOException {
     BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
     String [] s = br.readLine().trim().split(" ");
     long a = Long.parseLong(s[0]);
     long b = Long.parseLong(s[1]);
     long diff = 0;
     while(true){
         if(a == 0 || b == 0 ||  (a < 2*b && b < 2*a) ) {
             break;
         }
         if(a >= 2*b){
             a = a % (2 * b);
         }
         else if(b >= 2*a){
             b = b % (2 * a);
         }
     }
     System.out.println(a +" "+ b);

        }}

import java.io.*;
import java.util.*;
import java.lang.Math;
public class Main {
        void solve()
        {
                long a = l(), b = l();
                int count = 0;
                while(true){
                        if(a==0||b==0){
                                out.println(a+" "+b);
                                return;
                        }
                        if(a>=2*b){
                                long m = (a)/(2*b);
                                a = a-2*m*b;
                                continue;
                        }
                        if(b>=2*a){
                                long m = (b)/(2*a);
                                b = b-2*m*a;
                                continue;
                        }
                        out.println(a+" "+b);
                        return;
                }
        }

        void run() throws Exception{
                is = System.in;
                out = new PrintWriter(System.out);
                long s = System.currentTimeMillis();//while(t-->0)
                solve();
                out.flush();
                //System.out.println(System.currentTimeMillis()-s+"ms");
        }
        public static void main(String[] args)throws Exception {
                new Main().run();
        }
        InputStream is;
        PrintWriter out;
        private byte[] inbuf = new byte[1024];
        public int lenbuf = 0, ptrbuf = 0;

        private int readByte()
        {
                if(lenbuf == -1)throw new InputMismatchException();
                if(ptrbuf >= lenbuf){
                        ptrbuf = 0;
                        try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }
                        if(lenbuf <= 0)return -1;
                }
                return inbuf[ptrbuf++];
        }

        private boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }
        private int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }

        private double d() { return Double.parseDouble(s()); }
        private char c() { return (char)skip(); }

        private String s()
        {
                int b = skip();
                StringBuilder sb = new StringBuilder();
                while(!(isSpaceChar(b))){ // when nextLine, (isSpaceChar(b) && b != ' ')
                        sb.appendCodePoint(b);
                        b = readByte();
                }
                return sb.toString();
        }

        private char[] sa(int n)
        {
                char[] buf = new char[n];
                int b = skip(), p = 0;
                while(p < n && !(isSpaceChar(b))){
                        buf[p++] = (char)b;
                        b = readByte();
                }
                return n == p ? buf : Arrays.copyOf(buf, p);
        }

        private char[][] nm(int n, int m)
        {
                char[][] map = new char[n][];
                for(int i = 0;i < n;i++)map[i] = sa(m);
                return map;
        }

        private int[] ia(int n)
        {
                int[] a = new int[n];
                for(int i = 0;i < n;i++)a[i] = i();
                return a;
        }

        private int i()
        {
                int num = 0, b;
                boolean minus = false;
                while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
                if(b == '-'){
                        minus = true;
                        b = readByte();
                }

                while(true){
                        if(b >= '0' && b <= '9'){
                                num = num * 10 + (b - '0');
                        }else{
                                return minus ? -num : num;
                        }
                        b = readByte();
                }
        }

        private long l()
        {
                long num = 0;
                int b;
                boolean minus = false;
                while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
                if(b == '-'){
                        minus = true;
                        b = readByte();
                }

                while(true){
                        if(b >= '0' && b <= '9'){
                                num = num * 10 + (b - '0');
                        }else{
                                return minus ? -num : num;
                        }
                        b = readByte();
                }
        }

}

import java.util.Scanner;

public class weirdSubtractionProcess {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		long n = scan.nextLong(), m = scan.nextLong();
		while (true) {
			if(n == 0 || m == 0) {
				break;
			} else if (n >= m * 2) {
				n %= m * 2;
			} else if (m >= n * 2) {
				m %= n * 2;
			} else {
				break;
			}
		}
		System.out.println(n + " " + m);
	}
}

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

import java.util.Scanner;

/**
 *
 * @author cat_dominguez
 */
public class Prob3 {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
       long a, b;
        Scanner tec=new Scanner(System.in);
        a=tec.nextLong();
        b=tec.nextLong();
        while (a!=0 && b!=0 && (a>=b*2 || b>=a*2)){
            if(a>=b*2){
                a%=2*b;
           } else if (b>=a*2){
               b%=a*2;
           }
        }
        System.out.println(a+ " "+b);
    }

}

import java.util.*;

public class helloWorld
{
	public static void main(String[] args)
	{
		Scanner in = new Scanner(System.in);
		long n = in.nextLong();
		long m = in.nextLong();

		while(n > 0 && m > 0)
			if(n >= 2*m)
				n %= 2*m;
			else if(m >= 2*n)
				m %= 2*n;
			else
				break;

		System.out.println(n + " " + m);

		in.close();
	}
}

import java.util.*;

public class WeirdSubstractionProcess {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		long a = sc.nextLong();
		long b = sc.nextLong();
		boolean flag = true;
		while( (a != 0 && b != 0) && flag) {
			if(a >= b*2) {
				a = a%(b*2);
			} else {
				if(b>= a*2) {
					b = b%(a*2);
				} else {
					flag = false;
				}
			}
		}
		System.out.println(a+" "+b);
	}
}

import java.util.*;

public class Substraction{

	long a,b;

	public static void Substract(long a, long b){

		if (a == 0 || b ==0){
			System.out.println(a + " " + b);
		}
		else if(a >= 2*b){
			Substract(a%(2*b),b);
			//System.out.println(a + " " + b);
		}
		else if(b >= 2*a){
			Substract(a,b%(2*a));
			//System.out.println(a + " " + b);
		}
		else
			System.out.println(a + " " + b);

	}

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long a = sc.nextLong();
		long b = sc.nextLong();

		Substract(a,b);
	}
}

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Objects;
import java.util.Stack;

import java.util.StringTokenizer;

 public class Test
 {

     static PrintWriter pw = new PrintWriter(System.out);

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

    public static void main(String[] args)throws Exception
    {
        Reader.init(System.in);
        long a = Reader.nextLong();
        long b = Reader.nextLong();
        StringBuilder str = new StringBuilder();

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

        str.append(a).append(" ").append(b);
        pw.print(str);
        pw.close();
    }

}

class Reader {

    static BufferedReader reader;
    static StringTokenizer tokenizer;

    public static int pars(String x) {
        int num = 0;
        int i = 0;
        if (x.charAt(0) == '-') {
            i = 1;
        }
        for (; i < x.length(); i++) {
            num = num * 10 + (x.charAt(i) - '0');
        }

        if (x.charAt(0) == '-') {
            return -num;
        }

        return num;
    }

    static void init(InputStream input) {
        reader = new BufferedReader(
                new InputStreamReader(input));
        tokenizer = new StringTokenizer("");
    }

    static void init(FileReader input) {
        reader = new BufferedReader(input);
        tokenizer = new StringTokenizer("");
    }

    static String next() throws IOException {
        while (!tokenizer.hasMoreTokens()) {
            tokenizer = new StringTokenizer(
                    reader.readLine());
        }
        return tokenizer.nextToken();
    }

    static int nextInt() throws IOException {
        return pars(next());
    }

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

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

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

import java.util.Scanner;

/**
 *
 * @author Administrator
 */
public class JavaApplication59 {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        Scanner ip = new Scanner(System.in);
        long a = ip.nextLong();
        long b = ip.nextLong();
        while(true)
        {
            if(a == 0 || b == 0)
            {
                break;
            }
            else
            {
                long temp = 2 * b;
                long temp1 = 2 * a;
                if(a >= temp)
                {
                   long n = a / temp;
                   a -= n * temp;
                }
                else
                {

                    if(b >= temp1)
                    {
                       long n = b / temp1;
                       b -= n * temp1;
                    }
                    else
                    {
                        break;
                    }
                }
            }
        }
        System.out.println(a+" "+b);
    }

}

import java.util.Scanner;

public class WeirdSubtraction {

//	static long a;
//	static long b;
	static boolean condition ;
	static boolean condition2;
	public static void main(String[] args) {
		// TODO Auto-generated method stub

		Scanner input =new Scanner(System.in);
		long  a = input.nextLong();
		long  b = input.nextLong();
		long v = weird_subtraction(a,b);
		if(condition2){
			return;
		}
		if(!condition){
			System.out.println(v+" "+0);
		}
		else
			System.out.println(0+" "+v);

	}

	static long weird_subtraction(long a, long b){
		if(a==0){
			condition = true;
			return b;
		}
		else if(b==0){
			return a;
		}
		else if(a>=2*b){

			return weird_subtraction(a%(2*b),b);
		}
		else if(b>=2*a){
			return weird_subtraction(a,b%(2*a));
		}
		else{
			System.out.println(a+" "+b);
		    condition2 =true;
		    return 0;
		}
	}

}

import java.util.*;
public class Wierd_subtraction {
  public static void main(String[]args){
    Scanner input = new Scanner(System.in);
    long a = input.nextLong();
    Long b = input.nextLong();
    while(a != 0 && b != 0 && ((a >= 2*b) || (b >= 2*a))){
      if(a >= 2 * b){
        a = a % (2 * b);
      }
      else{
        b = b % (2 * a);
      }
    }
    System.out.printf("%d %d",a,b);
  }
}

import java.util.Scanner;

public class B946WeirdSubtraction {

	public static void main(String[] args) {
		//Getting input
		Scanner sc = new Scanner(System.in);
		long a = sc.nextLong();
		long b = sc.nextLong();
		sc.close();
		//--------------

		while (a != 0 && b !=0) {
			if (a >= 2*b) {
				a = a % (2*b);
				//System.out.println(a);
			} else if (b >= 2*a ) {
				b = b % (2*a);
			} else {
				break;
			}
		}

		System.out.println(a + " " + b);

	}
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Random;
import java.util.StringTokenizer;

public class Main {

    public static void main(String[] args) throws ParseException {
        FastReader read = new FastReader();
        long a  = read.nextLong();
        long b  = read.nextLong();

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

        }
        System.out.println(a +" " + b );
    }

    }

class Pair implements Comparable<Pair> {

    int x, y;

    public Pair(int x, int y) {
        this.x = x;
        this.y = y;

    }

    @Override
    public int compareTo(Pair p) {
        if (this.x != p.x) {
            return this.x - p.x;
        } else {
            return p.y - this.y;
        }

    }

}

class FastReader {

    BufferedReader br;
    StringTokenizer st;

    public FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

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

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

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

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

import java.io.*;
import java.math.*;
import java.text.*;
import java.util.*;
import java.util.regex.*;

public class Codeforces {

    public static void main(String[] args) {
        Scanner in=new Scanner (System.in);
        long a=in.nextLong();
        long b=in.nextLong();

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

        	}
        	else if(b>=2*a)
        	{
        		//b=b-2*a;
        		long k=(long)b/a;
        		if(k%2==0)
        			b=b-k*a;
        		else
        			b=b-(k-1)*a;
        	}
        	else
        	{
        		break;
        	}
        }
        long temp=(long)a;
        long temp2=(long)b;
        System.out.println(temp+" "+temp2);
    }
}

import java.util.Scanner;

public class RangeTest {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);

		long a = in.nextLong();
	    long b = in.nextLong();

		while(a!=0 && b!=0) {

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

		System.out.println(a + " " + b);
	}
}

import java.util.Scanner;
public class Test{
    public static void main(String arg []){
        long a,b;
        Scanner sc = new Scanner(System.in);
        a = sc.nextLong();
        b = sc.nextLong();
        while(a!=0 && b!=0){
            if(a>=2*b){
                a%=(2*b);
            } else if( b>= 2*a) {
                b %=2*a;
            } else {
                break;
            }
        }
        System.out.println(a+" "+b);
    }
}

import java.util.Scanner;

public class b {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		long a = in.nextLong();
		long b = in.nextLong();
		while((a>=2*b || b>=2*a) && a!=0 && b!=0){
			if(b!=0 && a>=2*b) a%=2*b;
			else if(a!=0 && b>=2*a) b%=2*a;
			if(a>=2*b)a-=2*b;
			else if(b>=2*a)b-=2*a;
		}
		System.out.println(a+" "+b);
	}

}

import java.util.Scanner;

public class minusDop {
    public static void main(String[] args) {
        long a, b;
        Scanner s = new Scanner(System.in);
        a = s.nextLong();
        b = s.nextLong();
        while ((a != 0) && (b != 0)) {
            if (a >= 2 * b) a-=2*b;
            if (b >= a * 2) b-=2*a; else break;

        }
        System.out.println(a + " " + b);

    }
}

import java.util.Scanner;

public class minusDop {
    public static void main(String[] args) {
        long a, b;
        Scanner s = new Scanner(System.in);
        a = s.nextLong();
        b = s.nextLong();
        if(a!=0 && b!=0)
            while(a>=2*b)
                a-=b;
        if(a!=0 && b!=0)
            while(b>=2*a)
                b-=a;
        System.out.println(a + " " + b);

    }
}

import java.util.*;
public class Main{
public static void main(String[] args) {

Scanner scn = new Scanner(System.in);
long a = scn.nextLong();
long b = scn.nextLong();
while(a!=0 && b!=0){
    if(a>=2*b){
        a = a%2*b;
        continue;
    }
    if(b>=2*a){
        b = b%2*a;
        continue;
    }
    else{
        break;
    }
}
System.out.println(a + " " + b);
 }
}

import java.util.Scanner;
public class WeirdSubstraction {
    public static void main (String [] args){
        Scanner lector = new Scanner (System.in);
        int a=lector.nextInt(); int b = lector.nextInt();

        while(a!=0 && b!=0){
            System.out.println(a+" "+b);
            if(a>=2*b){
                a=a%(2*b);
                continue;

            }
            else if(b>=2*a){
                b=b%(2*a);
            }
            if(a<2*b && b<2*a){
              break;
            }
        }
        System.out.println(a+" "+b);
    }
}

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner read = new Scanner(System.in);

            long a = read.nextLong();
            long b = read.nextLong();

            boolean flag = false;

            while (a != 0 && b != 0 && flag == false) {
                if (a == 1 && b != 1) {
                    System.out.println(1 + " " + 0);
                    break;
                }
                if (b == 1 && a != 1) {
                    System.out.println(0 + " " + 1);
                    break;
                }
                first:
                {
                    if (a >= b * 2) {
                        a = a % (b * 2);
                        break first;
                    }
                    if (b >= a * a * 2) {
                        b = b % (a * 2);
                        break first;
                    } else {
                        flag = true;
                    }
                }
                System.out.println(a + " " + b);
            }
        }
    }

import java.util.*;

public class WeirdSubstractionProcess {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int a = sc.nextInt();
		int b = sc.nextInt();

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

		System.out.println(a+" "+b);

	}
}

import java.util.*;

public class Solution
{

  public static void main(String[] args)

  {

  Scanner sc=new Scanner(System.in);

   long n=sc.nextLong();

  long m=sc.nextLong();

n=n%1000000007;
m=m%1000000007;
    int flag=0;

      if(m==0||n==0)

   {

       System.out.println(n+" "+m);

       System.exit(0);

       }

       while(m>0 && n>0)

      {

           flag=0;

       if(n>=2*m)

       {

           flag++;

       n=n-(2*m);

       if(n==0)

       break;

       }

       else if(m>=2*n)

      {

       m=m-(2*n);

       flag++;

      if(m==0)

   break;

   }

 else

 m=m;

  if(flag==0)

     break;

 }

   System.out.println(n+" "+m);

   }
}

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Objects;
import java.util.Stack;

import java.util.StringTokenizer;

 public class Test
 {

     static PrintWriter pw = new PrintWriter(System.out);

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

    public static void main(String[] args)throws Exception
    {
        Reader.init(System.in);
        long a = Reader.nextLong();
        long b = Reader.nextLong();
        StringBuilder str = new StringBuilder();

        if(a == 0 || b == 0)
        {
            str.append(a).append(" ").append(b);
            pw.print(str);
            pw.close();
            return;
        }

        if(a >= 2*b)
        {
            a = a%(2*b);
            if(a == 0 || b == 0)
            {
                str.append(a).append(" ").append(b);
                pw.print(str);
                pw.close();
                return;
            }
        }

        if(b>=2*a)
            b = b%(2*a);
        /*while(b >= 2*a)
        {
            b = b-2*a;
            if(a == 0 || b == 0)
            {
                str.append(a).append(" ").append(b);
                pw.print(str);
                pw.close();
                return;
            }

            if(a >= 2*b)
            {
                a = a%(2*b);
                if(a == 0 || b == 0)
                {
                    str.append(a).append(" ").append(b);
                    pw.print(str);
                    pw.close();
                    return;
                }
            }

        }*/

        str.append(a).append(" ").append(b);
        pw.print(str);
        pw.close();
    }

}

class Reader {

    static BufferedReader reader;
    static StringTokenizer tokenizer;

    public static int pars(String x) {
        int num = 0;
        int i = 0;
        if (x.charAt(0) == '-') {
            i = 1;
        }
        for (; i < x.length(); i++) {
            num = num * 10 + (x.charAt(i) - '0');
        }

        if (x.charAt(0) == '-') {
            return -num;
        }

        return num;
    }

    static void init(InputStream input) {
        reader = new BufferedReader(
                new InputStreamReader(input));
        tokenizer = new StringTokenizer("");
    }

    static void init(FileReader input) {
        reader = new BufferedReader(input);
        tokenizer = new StringTokenizer("");
    }

    static String next() throws IOException {
        while (!tokenizer.hasMoreTokens()) {
            tokenizer = new StringTokenizer(
                    reader.readLine());
        }
        return tokenizer.nextToken();
    }

    static int nextInt() throws IOException {
        return pars(next());
    }

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

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

import java.util.Scanner;
public class ProblemaTres {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long a = sc.nextLong();
		long b = sc.nextLong();
		while (true) {
			System.out.println(a + " " + b);
			if (a == 0 || b == 0) {
				break;
			}
			else if (a >= (2*b)) {
				a %= 2*b;
			}
			else if (b >= (2*a)) {
				b %= 2*a;
			}
			else {
				break;
			}
		}
		System.out.println(a + " " + b);
	}
}

import java.util.Scanner;

public class B946 {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long a = sc.nextLong();
		long b = sc.nextLong();
		if(a<1 || b<1 || a>Math.pow(10,18) || b>Math.pow(10, 18))
			System.exit(0);
		if((a==1 || b==1) && (a%2==0||b%2==0)){
			System.out.println("1 0");
			System.exit(0);
		}
		while (a != b && a != 0 && b != 0) {
			if (a >= 2 * b){
				long temp = a/b;
				a -= (temp>2?(temp-1):temp) * b;
			}
			else if (b >= 2 * a){
				long temp = b/a;
				b -= (temp>2?(temp-1):temp) * a;
			}
			else {
				System.out.println(a + " " + b);
				System.exit(0);
			}
		}
		System.out.println(a + " " + b);
	}

}

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

public class WeirdSubstractionProcess{

    public static void main(String[] args) throws Exception{
        Scanner in =new Scanner(System.in);
         long  a = in.nextLong();
         long  b = in.nextLong();

        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;

            }
        }
        System.out.println(a + " " + b);
    }

}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class WeirdSubtractionProcess {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer(br.readLine());
        long a = Long.parseLong(st.nextToken());
        long b = Long.parseLong(st.nextToken());

        while(a != 0 && b != 0){
            if(a < 2*b && b < 2*a){
                break;
            }
            if(a > b){
                a = a % (2*b);
                System.out.println(a);
            }
            if(b > a && a != 0){
                b = b % (2*a);
            }
        }
        System.out.println(a + " " + b);
    }
}

import java.util.Scanner;

public class B946 {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long a = sc.nextLong();
		long b = sc.nextLong();
		if(a<1 || b<1 || a>Math.pow(10,18) || b>Math.pow(10, 18))
			System.exit(0);
		while (a != b && a != 0 && b != 0) {
			if (a >= 2 * b){
				long temp = a/b;
				a -= (temp>2?(temp-1):temp) * b;
			}
			else if (b >= 2 * a){
				long temp = b/a;
				b -= (temp>2?(temp-1):temp) * a;
			}
			else {
				System.out.println(a + " " + b);
				System.exit(0);
			}
		}
		System.out.println(a + " " + b);
	}

}

import java.util.Scanner;

public class B946 {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long a = sc.nextLong();
		long b = sc.nextLong();
		if(a<1 || b<1 || a>Math.pow(10,18) || b>Math.pow(10, 18))
			System.exit(0);
		while (a != b && a != 0 && b != 0) {
			if(a==1 && b%2==0){
				System.out.println("1 0");
				System.exit(0);
			} else if(b==1 && a%2==0){
				System.out.println("0 1");
				System.exit(0);
			}
			if (a >= 2 * b){
				long temp = a/b;
				if(temp>100)
					a -= (temp>4?(temp-4):temp) * b;
				else a -= 2*b;
			}
			else if (b >= 2 * a){
				long temp = b/a;
				if(temp>100)
					b -= (temp>4?(temp-4):temp) * a;
				else b -= 2*a;
			}
			else {
				System.out.println(a + " " + b);
				System.exit(0);
			}
		}
		System.out.println(a + " " + b);
	}

}

import java.util.Scanner;

public class B946WeirdSubtraction {

	public static void main(String[] args) {
		//Getting input
		Scanner sc = new Scanner(System.in);
		long a = sc.nextLong();
		long b = sc.nextLong();
		sc.close();
		//--------------

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

		System.out.println(a + " " + b);

	}
}

import java.util.Scanner;

public class ProblemB {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		long a = scan.nextLong();
		long b = scan.nextLong();
		long preA = a;
		long preB = b;
		while(true) {
			if(a == 0 || b == 0) {
				break;
			}else if(!(a >= b*2) && !(b >= a *2)){
				break;
			}
			a = a % b;
			if(a == 0 || b == 0) {
				break;
			}else if(!(a >= b*2) && !(b >= a *2)){
				break;
			}
			b = b % a;
			if(a == 0 || b == 0) {
				break;
			}else if(!(a >= b*2) && !(b >= a *2)){
				break;
			}

			if(a == preA && b == preB) {
				break;
			}else{
				preA = a;
				preB = b;
			}
		}
		System.out.println(a + " " + b);

	}

}

import java.util.Scanner;

public class B946 {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long a = sc.nextLong();
		long b = sc.nextLong();
		if(a<1 || b<1 || a>Math.pow(10,18) || b>Math.pow(10, 18))
			System.exit(0);
		while (a != b && a != 0 && b != 0) {
			if(a==1 && b%2==0){
				System.out.println("1 0");
				System.exit(0);
			} else if(b==1 && a%2==0){
				System.out.println("0 1");
				System.exit(0);
			}
			if (a >= 2 * b){
				long temp = a/b;
				if(temp>100)
					a -= (temp>2?(temp-1):temp) * b;
				else a -= 2*b;
			}
			else if (b >= 2 * a){
				long temp = b/a;
				if(temp>100)
					b -= (temp>2?(temp-1):temp) * a;
				else b -= 2*a;
			}
			else {
				System.out.println(a + " " + b);
				System.exit(0);
			}
		}
		System.out.println(a + " " + b);
	}

}

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

public class Weird_Subtraction_Process {
	public static long[] f( long a, long b)
	{
		long result[], k;
		if ( a == 0 || b == 0) result  = new long[]{a, b};
		else if ( a >= 2l*b ) { result = f(a%b, b); }
		else if ( b >= 2l*a ) { result = f(a, b%a); }
		else result = new long[]{a, b};
		return result;
	}
	public static void main(String args[])
	{
		Scanner in = new Scanner(System.in);
		long a, b;
		a = in.nextLong();
		b = in.nextLong();
		long[] result = f(a, b);
		System.out.println(result[0]+" "+result[1]);
	}
}

import java.util.*;
public class Weird{
	public static void main(String[] args) {
		Scanner in=new Scanner(System.in);
		double a,b;
		a=in.nextDouble();
		b=in.nextDouble();
		while(a!=0&&b!=0){
			if(a>=2*b){
				a=a-2*b;
			}
			else if(b>=2*a){
				b=b-2*a;
			}
			else{
				break;
			}
		}
		System.out.print(a);
		System.out.print(' ');
		System.out.print(b);
	}
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * Created by tejal.k on 3/17/2018.
 */
public class Eductional39ProblemB {
    public static void main(String[] args) throws IOException {
        BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
        String[] s = bf.readLine().split(" ");
        long a = Long.parseLong(s[0]);
        long b = Long.parseLong(s[1]);
        boolean setA = true, setB = true;
        while (a != 0 && b != 0 && (setA != false && setB != false)) {
            setA = false;setB=false;
            if (a >= 2*b) {
                setA = true;
                a -= 2*b;
//                System.out.println("a " + a);
//                System.out.printf("seta " + setA);
            }
            if (b >= 2*a) {
                setB = true;
                b -= 2*a;
//                System.out.println("b " + b);
//                System.out.printf("setb " + setB);
            }
        }
        System.out.println(a + " " + b);
    }
}

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

public class B {

	public static void main(String[] args) throws IOException{
		FastScanner sc = new FastScanner();
//		int yo = sc.nextInt();
//		while(yo-->0) {
//		}

		long a = sc.nextLong();
		long b = sc.nextLong();

		step1(a,b);

	}

	static void step1(long a, long b) {
		if(a == 0 || b == 0) {
			System.out.println(a + " " + b);
			return;
		}
		else {
			step2(a,b);
		}
	}

	static void step2(long a, long b) {
		if(a >= 2 * b) {
			a = a % 2 * b;
			step1(a,b);
		}
		else {
			step3(a,b);
		}
	}

	static void step3(long a, long b) {
		if(b >= 2 * a) {
			b = b % 2 * a;
			step1(a,b);
		}
		else {
			System.out.println(a + " " + b);
			return;
		}
	}

	static class Pair{
		int start;
		int end;
		public Pair(int start, int y) {
			this.start = start;
			this.end = end;
		}
	}

	static int mod = 1000000007;

	static long pow(int a, int b) {
		if(b == 0) {
			return 1;
		}
		if(b == 1) {
			return a;
		}
		if(b%2 == 0) {
			long ans = pow(a,b/2);
			return ans*ans;
		}
		else {
			long ans = pow(a,(b-1)/2);
			return a * ans * ans;
		}

	}

	static class FastScanner {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer("");
		String next() {
			while (!st.hasMoreTokens())
				try {
					st=new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());
		}
		int[] readArray(int n) {
			int[] a=new int[n];
			for (int i=0; i<n; i++) a[i]=nextInt();
			return a;
		}
		long nextLong() {
			return Long.parseLong(next());
		}
	}

	static int gcd(int a, int b) {
		return a%b == 0 ? b : gcd(b,a%b);
	}

	static boolean[] sieve(int n) {

		boolean isPrime[] = new boolean[n+1];
		for(int i = 2; i <= n; i++) {
			if(isPrime[i]) continue;
			for(int j = 2*i; j <= n; j+=i) {
				isPrime[j] = true;
			}

		}
		return isPrime;

	}

//	For Input.txt and Output.txt

//	FileInputStream in = new FileInputStream("input.txt");
//	FileOutputStream out = new FileOutputStream("output.txt");
//	PrintWriter pw = new PrintWriter(out);
//	Scanner sc = new Scanner(in);

// 	sc.nextLine()

}

import java.util.Scanner;

public class JavaApplication18 {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        long a=sc.nextLong();
        long b=sc.nextLong();
        while(a!=0 && b!=0){
            if(a>b){
                if(a-2*b < 0){
                    break;
                }
                else{
                    a=a%2*b;
                }
            }
            else if(b>a){
                if(b-2*a < 0){
                    break;
                }
                else{
                    b=b%2*a;
                }
            }
        }
        System.out.println(a+" "+b);
    }

}

import java.util.Scanner;

public class B946 {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long a = sc.nextLong();
		long b = sc.nextLong();
		if(a<1 || b<1 || a>Math.pow(10,18) || b>Math.pow(10, 18))
			System.exit(0);
		while (a != b && a != 0 && b != 0) {
			if((a==1 || b==1) && (a%2==0||b%2==0)){
				System.out.println("1 0");
				System.exit(0);
			}
			if (a >= 2 * b){
				long temp = a/b;
				a -= (temp>2?(temp-1):temp) * b;
			}
			else if (b >= 2 * a){
				long temp = b/a;
				b -= (temp>2?(temp-1):temp) * a;
			}
			else {
				System.out.println(a + " " + b);
				System.exit(0);
			}
		}
		System.out.println(a + " " + b);
	}

}

import java.util.*;

public class WeirdSubstractionProcess {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int a = sc.nextInt();
		int b = sc.nextInt();

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

		System.out.println(a+" "+b);

	}
}

import java.util.Scanner;

public class minusDop {
    public static void main(String[] args) {
        long a, b;
        Scanner s = new Scanner(System.in);
        a = s.nextLong();
        b = s.nextLong();
        while ((a != 0) && (b != 0)) {
            if (a >= 2 * b) a-=2*b;
            if (b >= a * 2) b-=2*a; else break;

        }
        System.out.println(a + " " + b);

    }
}

import java.util.Scanner;
public class WeirdSubstraction {
    public static void main (String [] args){
        Scanner lector = new Scanner (System.in);
        int a=lector.nextInt(); int b = lector.nextInt();

        while(a!=0 && b!=0){
            System.out.println(a+" "+b);
            if(a>=2*b){
                a=a%(2*b);
                continue;

            }
            else if(b>=2*a){
                b=b%(2*a);
            }
            if(a<2*b && b<2*a){
              break;
            }
        }
        System.out.println(a+" "+b);
    }
}

import java.util.Scanner;

public class B946 {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long a = sc.nextLong();
		long b = sc.nextLong();
		if(a<1 || b<1 || a>Math.pow(10,18) || b>Math.pow(10, 18))
			System.exit(0);
		while (a != b && a != 0 && b != 0) {
			if (a >= 2 * b){
				long temp = a/b;
				a -= temp * b;
			}
			else if (b >= 2 * a){
				long temp = b/a;
				b -= temp * a;
			}
			else {
				System.out.println(a + " " + b);
				System.exit(0);
			}
		}
		System.out.println(a + " " + b);
	}

}

import java.io.*;
import java.util.*;
import java.math.BigInteger;
public class Main {
    private static StringBuilder sb = new StringBuilder();
    private static void s(String s){
        System.out.print(s);
    }
    private static void s(Double s){
        System.out.print(s);
    }
    private static void s(char s){
        System.out.print(s);
    }
    private static void sn(String s){
        System.out.println(s);
    }
    private static void sn(Boolean s){
        System.out.println(s);
    }
    private static void sn(long s){
        System.out.println(s);
    }
    private static void sn(Double s){
        System.out.println(s);
    }
    private static void sn(String s, Object o){
        sb.append(s+"\n");
    }
    private static void sn(long s, Object o){
        sb.append(s+"\n");
    }
    private static void sn(boolean s, Object o){
        sb.append(s+"\n");
    }
    private static void pr() throws Exception{
        BufferedWriter bw =new BufferedWriter(new OutputStreamWriter(System.out));
        bw.write(sb.toString());
        bw.flush();
    }
    static class Reader{
        final private int BUFFER_SIZE = 1 << 16;
        private DataInputStream din;
        private byte[] buffer;
        private int bufferPointer, bytesRead;

        public Reader()
        {
            din = new DataInputStream(System.in);
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }

        public Reader(String file_name) throws IOException
        {
            din = new DataInputStream(new FileInputStream(file_name));
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }

        public String readLine() throws IOException
        {
            byte[] buf = new byte[51]; // line length
            int cnt = 0, c;
            while ((c = read()) != -1)
            {
                if (c == '\n')
                    break;
                buf[cnt++] = (byte) c;
            }
            return new String(buf, 0, cnt);
        }

        public int nextInt() throws IOException
        {
            int ret = 0;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do
            {
                ret = ret * 10 + c - '0';
            }  while ((c = read()) >= '0' && c <= '9');

            if (neg)
                return -ret;
            return ret;
        }

        public long nextLong() throws IOException
        {
            long ret = 0;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do {
                ret = ret * 10 + c - '0';
            }
            while ((c = read()) >= '0' && c <= '9');
            if (neg)
                return -ret;
            return ret;
        }

        public double nextDouble() throws IOException
        {
            double ret = 0, div = 1;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();

            do {
                ret = ret * 10 + c - '0';
            }
            while ((c = read()) >= '0' && c <= '9');

            if (c == '.')
            {
                while ((c = read()) >= '0' && c <= '9')
                {
                    ret += (c - '0') / (div *= 10);
                }
            }

            if (neg)
                return -ret;
            return ret;
        }

        private void fillBuffer() throws IOException
        {
            bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
            if (bytesRead == -1)
                buffer[0] = -1;
        }

        private byte read() throws IOException
        {
            if (bufferPointer == bytesRead)
                fillBuffer();
            return buffer[bufferPointer++];
        }

        public void close() throws IOException
        {
            if (din == null)
                return;
            din.close();
        }
    }
    private static boolean isPrime(Integer ii){
        return new BigInteger(ii+"").isProbablePrime(1);
    }
    private static boolean isDigit(int ii){
        return Character.isDigit((char)ii);
    }
    private static long fact(int f){
        if(f==0){
            return 1;
        }
        return (long)f * (long)fact(f-1);
    }
    private static Reader r = new Reader();
    private static int ni() throws Exception{
        return r.nextInt();
    }
    private static String ns() throws Exception{
            return r.readLine();
        }
    private static long nl() throws Exception{
        return r.nextLong();
    }
    private static int[] na(int a) throws Exception{
        int arr[] = new int[a];
        for(int i=0;i<a;i++){
            arr[i] = r.nextInt();
        }
        return arr;
    }
    private static long[] nal(int a) throws Exception{
        long arr[] = new long[a];
        for(int i=0;i<a;i++){
            arr[i] = r.nextLong();
        }
        return arr;
    }
        static void printSubsets(char set[])
    {
        int n = set.length;

        // Run a loop for printing all 2^n
        // subsets one by obe
        for (int i = 0; i < (1<<n); i++)
        {
            System.out.print("{ ");

            // Print current subset
            for (int j = 0; j < n; j++)

                // (1<<j) is a number with jth bit 1
                // so when we 'and' them with the
                // subset number we get which numbers
                // are present in the subset and which
                // are not
                if ((i & (1 << j)) > 0)
                    System.out.print(set[j] + " ");

            System.out.println("}");
        }
    }

    static class Query implements Comparable<Query>{
        int l,r,blk,idx;
        long an;
        Query(int l, int r, int blk, int f){
            this.l = l;
            this.r = r;
            this.blk = blk;
            idx= f;
        }

        public int compareTo(Query q){
            if(blk==q.blk){
                if((blk & 1) != 1){
                    return r - q.r;
                } else return q.r - r;

            }
            else{
                return blk-q.blk;
            }
        }
        public String toString(){
            return l+" "+r+ " "+blk+" "+idx;
        }

    }

    private static void add(int ind, int arr[]){
        ans+=(++cnt[arr[ind]]==1?1:0);
    }

    private static void remove(int ind, int arr[]){
        ans-=(cnt[arr[ind]]--==1?1:0);
    }

    static int ans =0;
    static int curl = 0;
   static int curr = 0;
   static int cnt[] = new int[1000006];

    private static void solve() throws Exception{
        long a = nl();
        long b = nl();
        while(a>=2*b && (a!=0 && b!=0) || (b>=2*a && (a!=0 && b!=0)))
        {
        while(a>=2*b){
            a=a%(2*b);
        }
        if(a==0)
        break;
        sn(a+" "+b);
        while(b>=2*a){
            b=b%(2*a);
        }
        }
    }

	public static void main (String[] args) throws Exception{
	    int tc =1;
	    while(tc-->0){
	        solve();
	    }
	}
}

import java.util.*;

public class WeirdProcess {
	public static long a;
	public static long b;

	public static void process() {
		while(a > 100 || b > 100) {
			if(a == 0 || b == 0)
				break;
			if(a >= b * 2) {
				a = (a % b) + b;
				continue;
			}
			if(b >= a * 2) {
				b = (b % a) + a;
				continue;
			}
			break;
		}
		while(true) {
			if(a == 0 || b == 0)
				return;
			if(a >= b * 2) {
				a -= b * 2;
				continue;
			}
			if(b >= a * 2) {
				b -= a * 2;
				continue;
			}
			return;
		}
	}

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);

		a = in.nextLong();
		b = in.nextLong();

		process();
		System.out.println(a + " " + b);
	}
}

import java.util.*;

public class helloWorld
{
	public static void main(String[] args)
	{
		Scanner in = new Scanner(System.in);
		long n = in.nextLong();
		long m = in.nextLong();

		while(n*m != 0)
			if(n >= 2*m)
				n %= 2*m;
			else if(m >= 2*n)
				m %= 2*n;
			else
				break;

		System.out.println(n + " " + m);

		in.close();
	}
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * Created by tejal.k on 3/17/2018.
 */
public class Eductional39ProblemB {
    public static void main(String[] args) throws IOException {
        BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
        String[] s = bf.readLine().split(" ");
        long a = Integer.parseInt(s[0]);
        long b = Integer.parseInt(s[1]);
        boolean setA = false, setB = false;
        while (a != 0 && b != 0 && (setA == false && setB == false)) {
            setA = false;setB=false;
            if (a >= 2*b) {
                setA = true;
                a -= 2*b;
            }
            if (b >= 2*a) {
                setB = true;
                b -= 2*a;
            }
        }
        System.out.println(a + " " + b);
    }
}

import java.util.*;
import javax.crypto.*;

public class aedhf
{
	static double x,s;

public static void step1(){
	if(s==0||x==0){

		stop();
	}else{
	step2();
	}
}
	public static void main(String[] args)
	{
		Scanner a1 = new Scanner(System.in);
		 s=a1.nextDouble();
		 x=a1.nextDouble();
		step1();
	}
	public static void step2(){
		if (s>=2*x){
			s=s%(2*x);

			step1();
		}else{
		step3();
		}}
		public static void step3(){
			if(x>=2*s){
				x=x%(2*s);
				step1();
			}else{
				stop();
			}
		}
	public static void stop(){
	System.out.println((int)s+" "+(int)x);
	}
}

/*
   #######  ######    #####  ######  ######  #####
    #    #  #    #      #    #    #  #    #    #
    #    #  # #  #      #    # ## #  # ## #    #
    #    #  #  #    #   #    #    #  #    #    #
   #######  #   #   # # #    #    #  #    #    #
*/
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
import java.io.*;
import java.math.*;
import java.util.StringTokenizer;
public class Educationalround_39_2 {
    static PrintStream p = System.out;
    static long mod = (long)10e9+7;
    public static void main(String args[] ) throws Exception {
        long n = nextLong();
        long m = nextLong();
        n%=m;
        while(true){
            if(n==0 || m==0) break;
            else if(n>=(2*m)){
                n-=2*m;
            }else if(m>=2*n){
                m-=2*n;
            }else{
                break;
            }
        }
        p.println(n+" "+m);

    }

//-------------------------------------------------fast Method---------------------------------------------------------------\\
    static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));;
    static StringTokenizer st;
    private static int[] inta(int n){
        int [] a = new int[n];
        for(int i = 0;i < n;i++)a[i] = nextInt();
            return a;
    }
    private static long[] longa(long n){
    long[] a = new long[(int)n];
        for(int i = 0;i < n;i++)a[i] = nextLong();
            return a;
    }
    private static void pla(long[] a){
        for(int i = 0;i <a.length;i++)
            p.print(a[i]+" ");
    }
    private static void pia(int[] a){
        for(int i = 0;i <a.length;i++)
            p.print(a[i]+" ");
    }
    private static String next(){
        while (st == null || !st.hasMoreElements()){
            try{
                st = new StringTokenizer(br.readLine());
            }
            catch (IOException  e){
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }
    private static int nextInt(){
        return Integer.parseInt(next());
    }

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

    private static double nextDouble(){
        return Double.parseDouble(next());
    }
    private static String nextLine(){
        String str = "";
        try{
            str = br.readLine();
        }
        catch (IOException e){
            e.printStackTrace();
        }
        return str;
    }
//-------------------------------------------------fast Method---------------------------------------------------------------\\
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Weird_Subtraction_Process {
    public static void main(String[] args) throws IOException {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        String str[]=br.readLine().split(" ");
        long a=Long.parseLong(str[0]);
        long b=Integer.parseInt(str[1]);
        int i=0;
        while(i==0)
        {
            if(a<=0||b<=0||a==b)
                break;
            if(a>b*10) {
                a = a / 10;
                continue;
            }
            if(b>a*10) {
                b = b / 10;
                continue;
            }
            if(a>=2*b)
                a=a-(2*b);
            else
                if(b>=2*a)
                    b=b-(2*a);
            else
                break;
           // System.out.println(a+" "+b);
        }
        System.out.println(a+" "+b);
    }
}

import java.awt.Point;
import java.util.*;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.*;
import java.util.*;

public class Main {
	//////
	static class FastReader {
		BufferedReader br;
		StringTokenizer st;

		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

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

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

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

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

	//////
	public static long modularExponentiation(long x, long n, long M) {
		long result = 1;
		while (n > 0) {
			if (n % 2 == 1)
				result = (result * x) % M;
			x = (x * x) % M;
			n = n / 2;
		}
		return result;
	}

	public static long modularExponentiation1(long x, long n) {
		long result = 1;
		while (n > 0) {
			if (n % 2 == 1)
				result = (result * x);
			x = (x * x);
			n = n / 2;
		}
		return result;
	}

	/////

	static public int fun(int num){
		int prod=1;
		while(num>0){
			if(num%10!=0){
			prod=prod*(num%10);
			}
			num=num/10;
		}
		return prod;
	}

	public static boolean dfs(int x,int find,boolean[] visited,int[][] matrix){

		boolean ans=false;
		if(x==find){
			ans=true;
			return true;
		}
		for(int i=0;i<26;i++){
			if(visited[i]==false&&matrix[x][i]==1){
				visited[i]=true;
				ans=ans||dfs(i,find,visited,matrix);
			}
		}

		return ans;
	}

	static int lis(int arr[],int n,int k,int b)
    {
          int lis[] = new int[n];
          int i,j,max = 0;

          /* Initialize LIS values for all indexes */
           for ( i = 0; i < n; i++ )
              lis[i] = 1;

           /* Compute optimized LIS values in bottom up manner */
           for ( i = 1; i < n; i++ )
              for ( j = 0; j < i; j++ )
                         if ( arr[i] >= k*arr[j]+b && lis[i] < lis[j] + 1)
                    lis[i] = lis[j] + 1;

           /* Pick maximum of all LIS values */
           for ( i = 0; i < n; i++ )
              if ( max < lis[i] )
                 max = lis[i];

            return max;
    }

	public static void main(String[] args) throws IOException {

		FastReader scan = new FastReader();
		PrintWriter pw = new PrintWriter(System.out);

		long a=scan.nextLong();
		long b=scan.nextLong();
		if(a>=2*b){
		a=a%(2*b);
		}
		if(a!=0&&b>=2*a){
		b=b%(2*a);
		}
		if(b!=0&&a%b==0){
			a=0;
		}
		System.out.println(a+" "+b);

	}
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * Created by tejal.k on 3/17/2018.
 */
public class Eductional39ProblemB {
    public static void main(String[] args) throws IOException {
        BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
        String[] s = bf.readLine().split(" ");
        long a = Integer.parseInt(s[0]);
        long b = Integer.parseInt(s[1]);
        boolean setA = false, setB = false;
        while (a != 0 && b != 0 && (setA == false && setB == false)) {
            setA = false;setB=false;
            if (a >= 2*b) {
                setA = true;
                a -= 2*b;
            }
            System.out.println("lol");
            if (b >= 2*a) {
                setB = true;
                b -= 2*a;
            }
        }
        System.out.println(a + " " + b);
    }
}

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

public class Weird_Subtraction_Process {
	public static long[] f( long a, long b)
	{
		long result[], k;
		if ( a == 0 || b == 0) result  = new long[]{a, b};
		else if ( a >= 2l*b ) { result = f(a%b, b); }
		else if ( b >= 2l*a ) { result = f(a, b%a); }
		else result = new long[]{a, b};
		return result;
	}
	public static void main(String args[])
	{
		Scanner in = new Scanner(System.in);
		long a, b;
		a = in.nextLong();
		b = in.nextLong();
		long[] result = f(a, b);
		System.out.println(result[0]+" "+result[1]);
	}
}

import java.util.*;
public class B946 {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc1 = new Scanner(System.in);
		long a = sc1.nextLong();
		long b = sc1.nextLong();

		boolean flag = true;
		int x=1;
		while(flag) {
			if(a==0 || b==0) {
				System.out.println("ROHAN"+a+" "+b);
				return;
			}
			else if(a>=2*b) {
				a = a - 2*b;
				//System.out.println("MIHIR"+a+" "+b);
			}
			else if(b>=2*a) {
				b = b - 2*a;
				//System.out.println("DIVY"+a+" "+b);
			}
			else {
				break;
			}
		}
		System.out.println(a+" "+b);
	}

}

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner read = new Scanner(System.in);

            long a = read.nextLong();
            long b = read.nextLong();

            boolean flag = false;

            while (a != 0 && b != 0 && flag == false) {
                if (a == 1 && b != 1) {
                    System.out.println(1 + " " + 0);
                    break;
                }
                if (b == 1 && a != 1) {
                    System.out.println(0 + " " + 1);
                    break;
                }
                first:
                {
                    if (a >= b * 2) {
                        a = a % (b * 2);
                        break first;
                    }
                    if (b >= a * a * 2) {
                        b = b % (a * 2);
                        break first;
                    } else {
                        flag = true;
                    }
                }
                System.out.println(a + " " + b);
            }
        }
    }

import java.util.Scanner;
public class ProblemaTres {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long a = sc.nextLong();
		long b = sc.nextLong();
		while (true) {
			System.out.println(a + " " + b);
			if (a == 0 || b == 0) {
				break;
			}
			else if (a >= (2*b)) {
				a %= 2*b;
			}
			else if (b >= (2*a)) {
				b %= 2*a;
			}
			else {
				break;
			}
		}
		System.out.println(a + " " + b);
	}
}

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Scanner;

public class New2 {

   public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
//        ArrayList<Integer> b= new ArrayList<>();
//        ArrayList<Integer> c= new ArrayList<>();
        long a=input.nextLong();
        long b=input.nextLong();
       while(a!=0 || b!=0) {
        if(test(a, b)){
            break;
        }
        else{
            if(a>=b*2){
                a-=b*2;
                if(test(a, b)){
                    break;
                }
                else{
                    if(b>=a*2){
                       b-=a*2;
                    if(test(a, b)){
                         break;
                   }
                  }else{
                        break;
                       }

            }}
   }
       }
       System.out.println(a);
       System.out.println(b);
}
   public static boolean test(long a,long b){
       boolean res=false;
               if(a==0 || b ==0){
            res=true;
        }
               return res;
   }
}

import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		long a;
		long b;

		a = sc.nextLong();
		b = sc.nextLong();

		resta(a,b);

	}

	public static void resta(long a, long b) {

		if(a == 0 || b == 0) {
			System.out.println(a + " " + b);
			System.exit(0);
		}
		else if(a >= (2*b)) {
			a = a%(2*b);
			resta(a,b);
			System.out.println(a + " " + b);
		}
		else if(b >= (2*a)) {
			b = b%(2*a);
			resta(a,b);
			System.out.println(a + " " + b);
		}
	}
}

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Objects;
import java.util.Stack;

import java.util.StringTokenizer;

 public class Test
 {

     static PrintWriter pw = new PrintWriter(System.out);

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

    public static void main(String[] args)throws Exception
    {
        Reader.init(System.in);
        long a = Reader.nextLong();
        long b = Reader.nextLong();
        StringBuilder str = new StringBuilder();
        long aa = b;
        long bb = a;

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

        str.append(a).append(" ").append(aa);
        pw.print(str);
        pw.close();
    }

}

class Reader {

    static BufferedReader reader;
    static StringTokenizer tokenizer;

    public static int pars(String x) {
        int num = 0;
        int i = 0;
        if (x.charAt(0) == '-') {
            i = 1;
        }
        for (; i < x.length(); i++) {
            num = num * 10 + (x.charAt(i) - '0');
        }

        if (x.charAt(0) == '-') {
            return -num;
        }

        return num;
    }

    static void init(InputStream input) {
        reader = new BufferedReader(
                new InputStreamReader(input));
        tokenizer = new StringTokenizer("");
    }

    static void init(FileReader input) {
        reader = new BufferedReader(input);
        tokenizer = new StringTokenizer("");
    }

    static String next() throws IOException {
        while (!tokenizer.hasMoreTokens()) {
            tokenizer = new StringTokenizer(
                    reader.readLine());
        }
        return tokenizer.nextToken();
    }

    static int nextInt() throws IOException {
        return pars(next());
    }

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

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

import java.util.*;

public class Solution
{

  public static void main(String[] args)

  {

  Scanner sc=new Scanner(System.in);

   long n=sc.nextLong();

  long m=sc.nextLong();

n=n%1000000007;
m=m%1000000007;
    int flag=0;

      if(m==0||n==0)

   {

       System.out.println(n+" "+m);

       System.exit(0);

       }

       while(m>0 && n>0)

      {

           flag=0;

       if(n>=2*m)

       {

           flag++;

       n=n-(2*m);

       if(n==0)

       break;

       }

       else if(m>=2*n)

      {

       m=m-(2*n);

       flag++;

      if(m==0)

   break;

   }

 else

 m=m;

  if(flag==0)

     break;

 }

   System.out.println(n+" "+m);

   }
}

import java.util.Scanner;
import java.util.StringTokenizer;

public class Main {

    public static void main(String args[]){

        Scanner stdin = new Scanner(System.in);

        String S= stdin.nextLine();

        StringTokenizer stoken = new StringTokenizer(S," ");

         int a=Integer.parseInt( stoken.nextToken() );
         int b=Integer.parseInt( stoken.nextToken() );

        if(a==b){
            System.out.println(a+" "+b);
            System.exit(0);}

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

           }

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

           }
           else {
               System.out.println(a+" "+b);
               System.exit(0);
           }

       }while(!(a!=b||a<=0||b<=0));

        System.out.println(a+" "+b);

    }

}

import java.util.Scanner;
public class UnusualMinus {
    public static void main(String[] args) {
        int a,b;
        Scanner s = new Scanner(System.in);
        a = s.nextInt();
        b = s.nextInt();
        boolean b1=((a!=0)&& (b!=0)),b3=(b>=2*a),b2=(a>=2*b);
        while(b1==true){
              if (b2==true) {a=a-2*b;b2=a>=2*b;b3=b>=2*a;b1=((a!=0)&& (b!=0));continue;} else
               if(b3==true){b=b-2*a;b3=b>=2*a;b2=a>=2*b;b1=((a!=0)&& (b!=0));continue;} else break;

        }
        System.out.println(a+""+b);

    }

}

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author 4erneff
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskB {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int a = in.nextInt();
            int b = in.nextInt();
            Pair ans = fun(a, b);
            out.println(String.format("%d %d", ans.first, ans.second));
        }

        private Pair fun(int a, int b) {
            if (a == 0 || b == 0) {
                return new Pair(a, b);
            } else {
                if (a >= 2 * b) return fun(a - 2 * b, b);
                else {
                    if (b >= 2 * a) return fun(a, b - 2 * a);
                    else return new Pair(a, b);
                }
            }
        }

        private class Pair {
            int first;
            int second;

            Pair(int a, int b) {
                this.first = a;
                this.second = b;
            }

        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputReader.SpaceCharFilter filter;

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

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

        public int nextInt() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

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

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}

import java.util.Scanner;

public class B946 {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long a = sc.nextLong();
		long b = sc.nextLong();
		if(a<1 || b<1 || a>Math.pow(10,18) || b>Math.pow(10, 18))
			System.exit(0);
		while (a != b && a != 0 && b != 0) {
			if(a==1 && b%2==0){
				System.out.println("1 0");
				System.exit(0);
			} else if(b==1 && a%2==0){
				System.out.println("0 1");
				System.exit(0);
			}
			if (a >= 2 * b){
				long temp = a/b;
				if(temp>100)
					a -= (temp>2?(temp-2):temp) * b;
				else a -= 2*b;
			}
			else if (b >= 2 * a){
				long temp = b/a;
				if(temp>100)
					b -= (temp>2?(temp-2):temp) * a;
				else b -= 2*a;
			}
			else {
				System.out.println(a + " " + b);
				System.exit(0);
			}
		}
		System.out.println(a + " " + b);
	}

}

import java.util.Scanner;

public class minusDop {
    public static void main(String[] args) {
        long a, b;
        Scanner s = new Scanner(System.in);
        a = s.nextLong();
        b = s.nextLong();
        while ((a != 0) && (b != 0)) {
            if (a >= 2 * b) a-=2*b;
            if (b >= a * 2) b-=2*a; else break;

        }
        System.out.println(a + " " + b);

    }
}

/*
 *
 * 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.
 *
 * Input
 * 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.
 *
 * Output
 * Print two integers — the values of a and b after the end of the process.
 *
 */

/*

Input:
12 5

Output:
0 1

Input:
31 12

Output:
7 12
 */

import java.util.Scanner;

public class B946 {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long a = sc.nextLong();
		long b = sc.nextLong();

//		while (true) {
			if (a == 0 || b == 0) {
				System.out.println(a + " " + b);
				return;
			}
			long qa = a / b;
			long qb = b / a;
			if (qa > 0) {
				if (qa%2 == 0)
					a -= qa * b;
				else
					a -= (qa -1) * b;
			}
			else if (qb > 0) {
				if (qb%2 == 0)
					b -= qb * a;
				else
					b -= (qb -1) * a;
			}
//		}
		System.out.println(a + " " + b);
	}
}

import java.io.*;
import java.util.*;
import static java.lang.Math.*;

public class CF {

    public static void main(String[] args) throws IOException {
        //BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        //BufferedReader in = new BufferedReader(new FileReader("a.in"));
        FastScanner in = new FastScanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
        long n = in.nextLong();
        long m = in.nextLong();
        while (m * n != 0) {
            if (n >= 2 * m) {
                n %= 2 * m;
            } else if (m >= 2 * n) {
                m %= 2 * n;
            } else {
                break;
            }
        }
        out.println(n + " " + m);
        out.close();
    }

    static class FastScanner {

        private BufferedReader in;
        private String[] line;
        private int index;
        private int size;

        public FastScanner(InputStream in) throws IOException {
            this.in = new BufferedReader(new InputStreamReader(in));
            init();
        }

        public FastScanner(String file) throws FileNotFoundException {
            this.in = new BufferedReader(new FileReader(file));
        }

        private void init() throws IOException {
            line = in.readLine().split(" ");
            index = 0;
            size = line.length;
        }

        public int nextInt() throws IOException {
            if (index == size) {
                init();
            }
            return Integer.parseInt(line[index++]);
        }

        public long nextLong() throws IOException {
            if (index == size) {
                init();
            }
            return Long.parseLong(line[index++]);
        }

        public float nextFloat() throws IOException {
            if (index == size) {
                init();
            }
            return Float.parseFloat(line[index++]);
        }

        public double nextDouble() throws IOException {
            if (index == size) {
                init();
            }
            return Double.parseDouble(line[index++]);
        }

        public String next() throws IOException {
            if (index == size) {
                init();
            }
            return line[index++];
        }

        public String nextLine() throws IOException {
            if (index == size) {
                init();
            }
            StringBuilder sb = new StringBuilder();
            for (int i = index; i < size; i++) {
                sb.append(line[i]).append(" ");
            }
            return sb.toString();
        }

    }

}

import java.util.Scanner;

public class RangeTest {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);

		long a = in.nextLong();
	    long b = in.nextLong();

		while(a!=0 && b!=0) {

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

		System.out.println(a + " " + b);
	}
}

import java.util.Scanner;

public class B946 {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long a = sc.nextLong();
		long b = sc.nextLong();
		if(a<1 || b<1 || a>Math.pow(10,18) || b>Math.pow(10, 18))
			System.exit(0);
		while (a != b && a != 0 && b != 0) {
			if (a >= 2 * b){
				long temp = a/b;
				a -= (temp-1) * b;
			}
			else if (b >= 2 * a){
				long temp = b/a;
				b -= (temp-1) * a;
			}
			else {
				System.out.println(a + " " + b);
				System.exit(0);
			}
		}
		System.out.println(a + " " + b);
	}

}

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author caoash
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastScanner in = new FastScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        BWeirdSubtractionProcess solver = new BWeirdSubtractionProcess();
        solver.solve(1, in, out);
        out.close();
    }

    static class BWeirdSubtractionProcess {
        public void solve(int testNumber, FastScanner br, PrintWriter pw) {
            int a = br.nextInt();
            int b = br.nextInt();
            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;
                }
            }

            pw.println(a + " " + b);
            pw.close();
        }

    }

    static class FastScanner {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private FastScanner.SpaceCharFilter filter;

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

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

        public int nextInt() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

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

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}

import java.util.*;
public class Solution
{
    public static void main(String [] args)
    {
        Scanner sc=new Scanner(System.in);
        /*
        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.

Input
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.

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

Examples
inputCopy
12 5
output
0 1
inputCopy
31 12
output
7 12

        */
        long a=sc.nextLong();
        long b=sc.nextLong();
        long n=0;
        while(true)
        {
           // System.out.println("a="+a+" b="+b +" Outside");
            if(a==0 || b==0)
                break;
            if(a>=2*b)
            {
                n=(a/b)-1;
                a=a-2*n*b;
                //System.out.println("a="+a+" b="+b+" n="+n+" Inside 1");
                continue;
            }
            if(b>=2*a)
            {
                n=(b/a)-1;
                b=b-2*n*a;
               // System.out.println("a="+a+" b="+b+" n="+" Inside 2");
                continue;
            }
            break;
        }
        System.out.println(a+" "+b);
    }
}

import java.util.*;
public class WeirdSubtraction{
     public static void main(String []args){
         Scanner in = new Scanner(System.in);
          long a,b;
         try{
            a = in.nextLong();
            b = in.nextLong();
            if((a<1 && a>Math.pow(10,18)) || (b<1 && b>Math.pow(10,18))){
            System.exit(0);
            test(a,b);
        }
         }catch(Exception e){System.exit(0);}
     }
     static void test(long n, long m){
        while(true){
        exit(n,m); //zeroes input exit
        stop(n,m); //one is zero, print and exit
        if(n>=(2*m)){n-=(2*m);}
        else if(m>=(2*n)){m-=(2*n);}
        else{System.out.printf("%d %d\n",n,m); break;}
        }
     }
     static void exit(long n, long m){
         if(n==0&&m==0){System.exit(0);}
     }
     static void stop(long n, long m){
         if(n==0||m==0){System.out.printf("%d %d\n",n,m); System.exit(0);}
     }
}

import java.util.*;

public class helloWorld
{
	public static void main(String[] args)
	{
		Scanner in = new Scanner(System.in);
		long n = in.nextLong();
		long m = in.nextLong();

		while(n*m != 0)
			if(n >= 2*m)
				n %= 2*m;
			else if(m >= 2*n)
				m %= 2*n;
			else
				break;

		System.out.println(n + " " + m);

		in.close();
	}
}

import java.util.*;

public class Substraction{

	int a,b;

	public static void Substract(int a, int b){

		if (a == 0 | b ==0){
			System.out.println(a + " " + b);
			System.exit(0);
		}
		else if(a >= 2*b){
			a = a-2*b;
			Substract(a,b);
			System.out.println(a + " " + b);
		}
		else if(b >= 2*a){
			b = b-2*a;
			Substract(a,b);
			System.out.println(a + " " + b);
		}
	}

	public static void main(String[] args) {
		/*Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt(); */

		int a=12;
		int b=5;

		Substract(a,b);
	}
}

import java.util.Scanner;

public class WeirdSubtraction {

//	static long a;
//	static long b;
	static boolean condition ;
	static boolean condition2;
	public static void main(String[] args) {
		// TODO Auto-generated method stub

		Scanner input =new Scanner(System.in);
		long  a = input.nextLong();
		long  b = input.nextLong();
		long v = weird_subtraction(a,b);
		if(condition2){
			return;
		}
		if(!condition){
			System.out.println(v+" "+0);
		}
		else
			System.out.println(0+" "+v);

	}

	static long weird_subtraction(long a, long b){
		if(a==0){
			condition = true;
			return b;
		}
		else if(b==0){
			return a;
		}
		else if(a>=2*b){

			return weird_subtraction((a%2*b),b);
		}
		else if(b>=2*a){
			return weird_subtraction(a,b%(2*a));
		}
		else{
			System.out.println(a+" "+b);
		    condition2 =true;
		    return 0;
		}
	}

}

import java.util.*;

public class Substraction{

	int a,b;

	public static void Substract(int a, int b){

		if (a == 0 | b ==0){
			System.out.println(a + " " + b);
			System.exit(0);
		}
		else if(a >= 2*b){
			a = a-2*b;
			Substract(a,b);
			System.out.println(a + " " + b);
		}
		else if(b >= 2*a){
			b = b-2*a;
			Substract(a,b);
			System.out.println(a + " " + b);
		}
	}

	public static void main(String[] args) {
		/*Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt(); */

		int a=31;
		int b=12;

		Substract(a,b);
	}
}

import java.util.*;
import javax.crypto.*;

public class aedhf
{
	static double x,s;

public static void step1(){
	if(s==0||x==0){

		stop();
	}else{
	step2();
	}
}
	public static void main(String[] args)
	{
		Scanner a1 = new Scanner(System.in);
		 s=a1.nextDouble();
		 x=a1.nextDouble();
		step1();
	}
	public static void step2(){
		if (s>=2*x){
			s=s%(2*x);

			step1();
		}else{
		step3();
		}}
		public static void step3(){
			if(x>=2*s){
				x=x%(2*s);
				step1();
			}else{
				stop();
			}
		}
	public static void stop(){
	System.out.println((long)s+" "+(long)x);
	}
}

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

public class Weird_Subtraction_Process {
	public static long[] f( long a, long b)
	{
		long result[], k;
		if ( a == 0 || b == 0) result  = new long[]{a, b};
		else if ( a >= 2l*b ) { result = f(a%b, b); }
		else if ( b >= 2l*a ) { result = f(a, b%a); }
		else result = new long[]{a, b};
		return result;
	}
	public static void main(String args[])
	{
		Scanner in = new Scanner(System.in);
		long a, b;
		a = in.nextLong();
		b = in.nextLong();
		long[] result = f(a, b);
		System.out.println(result[0]+" "+result[1]);
	}
}

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

import java.util.Scanner;

/**
 *
 * @author cat_dominguez
 */
public class Prob3 {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
       long a, b;
        Scanner kb=new Scanner(System.in);
        System.out.println("Introduce two integer numbers: ");
        a=kb.nextLong();
        b=kb.nextLong();
        while (a!=0 && a!=0 && (a>=b*2 || b>=a*2)){
            if(a>=b*2){
                a=a-(2*b);
           } else if (b>=a*2){
               b=b-a*2;
           }
        }
        System.out.println(a+ " "+b);
    }

}

import java.util.Scanner;

public class B {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		long a = scan.nextLong();
		long b =scan.nextLong();
		while(true){
			if(a==0 || b==0){
				break;
			}
			if(a>=2*b){
				a = a-2*b;
			}
			if(b>=2*a){
				b = b-2*a;
			}else{
				break;
			}
		}
		System.out.println(a+" "+b);

	}

}

public class WeirdSubstractionProcess{

	public void weirdSubstract(int a, int b){
		if(a == 0 || b == 0){
			System.out.println(a + " " + b);
		}
		else if(a >= (2*b)){
			weirdSubstract(a - (2*b), b);
		}
		else if(b >= (2*a)){
			weirdSubstract(a, b - (2*a));
		}
		else{
			System.out.println(a + " " + b);
		}
	}

	public static void main(String[] args){
		WeirdSubstractionProcess test = new WeirdSubstractionProcess();
		test.weirdSubstract(12, 5);
	}
}

import java.util.*;
public class Weird{
	public static void main(String[] args) {
		Scanner in=new Scanner(System.in);
		double a,b;
		a=in.nextDouble();
		b=in.nextDouble();
		while(a!=0&&b!=0){
			if(a>=2*b){
				a=a-2*b;
			}
			else if(b>=2*a){
				b=b-2*a;
			}
			else{
				break;
			}
		}
		System.out.print(a);
		System.out.print(' ');
		System.out.print(b);
	}
}

import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int a;
		int b;

		a = sc.nextInt();
		b = sc.nextInt();

		resta(a,b);

	}

	public static void resta(int a, int b) {
		if(a == 0 || b == 0) {
			System.out.println(a + " " + b);
			System.exit(0);
		}
		if(a >= (2+b)) {
			a = a - (2*b);
			resta(a,b);
			System.out.println(a + " " + b);
		}
		if(b >= (2*a)) {
			b = b - (2*a);
			resta(a,b);
			System.out.println(a + " " + b);
		}
	}
}

import java.util.Scanner;

public class Main {

	private static Scanner scanner = new Scanner(System.in);
	private static int n, m, a;

	public static void main(String[] args) {
		n = scanner.nextInt();
		m = scanner.nextInt();

		while ((n != 0 && m != 0) && (n < 2 * m && m < 2 * n)) {
			if (n >= 2 * m) {
				a = n / (2 * m);
				n = n - (a * 2 * m);
			} else if (m >= 2 * n) {
				a = m / (2 * n);
				m = m - (a * 2 * n);
			}
		}
		System.out.println(n + " " + m);

	}

}

import java.util.Scanner;

public class B946 {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		if(a<1 || b>Math.pow(10, 18))
		while (a != b && a != 0 && b != 0) {
			if (a >= 2 * b)
				a -= 2 * b;
			else if (b >= 2 * a)
				b -= 2 * a;
			else {
				System.out.println(a + " " + b);
				System.exit(0);
			}
		}
		System.out.println(a + " " + b);
	}

}

import java.util.Scanner;

public class minusDop {
    public static void main(String[] args) {
        long a, b;
        Scanner s = new Scanner(System.in);
        a = s.nextLong();
        b = s.nextLong();
        if(a!=0 && b!=0)
            while(a>=2*b)
                a-=b;
        if(a!=0 && b!=0)
            while(b>=2*a)
                b-=a;
        System.out.println(a + " " + b);

    }
}

import java.util.Scanner;

public class JavaApplication18 {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        long a=sc.nextLong();
        long b=sc.nextLong();
        while(a!=0 && b!=0){
            if(a>b){
                if(a-2*b < 0){
                    break;
                }
                else{
                    a=a%2*b;
                }
            }
            else if(b>a){
                if(b-2*a < 0){
                    break;
                }
                else{
                    b=b%2*a;
                }
            }
        }
        System.out.println(a+" "+b);
    }

}

public class WeirdSubstractionProcess{

	public void weirdSubstract(int a, int b){
		if(a == 0 || b == 0){
			System.out.println(a + " " + b);
		}
		else if(a >= (2*b)){
			weirdSubstract(a - (2*b), b);
		}
		else if(b >= (2*a)){
			weirdSubstract(a, b - (2*a));
		}
		else{
			System.out.println(a + " " + b);
		}
	}

	public static void main(String[] args){
		WeirdSubstractionProcess test = new WeirdSubstractionProcess();
		test.weirdSubstract(12, 5);
		test.weirdSubstract(31, 12);
	}
}

import java.util.*;
import javax.crypto.*;

public class aedhf
{
	static double x,s;

public static void step1(){
	if(s==0||x==0){

		stop();
	}else{
	step2();
	}
}
	public static void main(String[] args)
	{
		Scanner a1 = new Scanner(System.in);
		 s=a1.nextDouble();
		 x=a1.nextDouble();
		step1();
	}
	public static void step2(){
		if (s>=2*x){
			s=s%(2*x);

			step1();
		}else{
		step3();
		}}
		public static void step3(){
			if(x>=2*s){
				x=x%(2*s);
				step1();
			}else{
				stop();
			}
		}
	public static void stop(){
	System.out.println((int)s+" "+(int)x);
	}
}

import java.util.Scanner;

public class B946 {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long a = sc.nextLong();
		long b = sc.nextLong();
		if(a<1 || b<1 || a>Math.pow(10,18) || b>Math.pow(10, 18))
			System.exit(0);
		while (a != b && a != 0 && b != 0) {
			if(a==1 && b%2==0){
				System.out.println("1 0");
				System.exit(0);
			} else if(b==1 && a%2==0){
				System.out.println("0 1");
				System.exit(0);
			}
			if (a >= 2 * b){
				long temp = a/b;
				if(temp>100)
					a -= (temp>2?(temp-3):temp) * b;
				else a -= 2*b;
			}
			else if (b >= 2 * a){
				long temp = b/a;
				if(temp>100)
					b -= (temp>2?(temp-3):temp) * a;
				else b -= 2*a;
			}
			else {
				System.out.println(a + " " + b);
				System.exit(0);
			}
		}
		System.out.println(a + " " + b);
	}

}

import java.util.*;

public class WeirdProcess {
	public static long a;
	public static long b;

	public static void process() {
		while(true) {
			if(a == 0 || b == 0)
				return;
			if(Math.abs(a - b) < Math.min(a, b))
				return;
			if(a >= b) {
				a = a % b;
				continue;
			}
			if(b >= a) {
				b = b % a;
				continue;
			}
			return;
		}
	}

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);

		a = in.nextLong();
		b = in.nextLong();

		process();
		System.out.println(a + " " + b);
	}
}