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 ≤ 10^18). 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-----
Input
12 5

Output
0 1

Input
31 12

Output
7 12



-----Note-----

Explanations to the samples: a = 12, b = 5 $\rightarrow$ a = 2, b = 5 $\rightarrow$ a = 2, b = 1 $\rightarrow$ a = 0, b = 1; a = 31, b = 12 $\rightarrow$ a = 7, b = 12.

Source: codeforces | Difficulty: EASY
Tags: Number theory

Mathematics


Solutions:
(a, b) = input().split()
(a, b) = (int(a), int(b))
while a > 0 and b > 0:
	if a >= b + b:
		a = a % (b + b)
	elif b >= a + a:
		b = b % (a + a)
	else:
		break
print(a, b)


(a, b) = map(int, input().split())
while 1 > 0:
	if a == 0 or b == 0:
		break
	if a >= 2 * b:
		a = a % (2 * b)
		continue
	if b >= 2 * a:
		b = b % (2 * a)
		continue
	break
print(a, b)


from sys import stdin, stdout

def solution(a, b):
	if max(a, b) < min(a, b) * 2 or not a or (not b):
		stdout.write(str(a) + ' ' + str(b))
		return
	if a > b:
		m = a // b
		if m & 1:
			solution(a - (m - 1) * b, b)
		else:
			solution(a - m * b, b)
	else:
		m = b // a
		if m & 1:
			solution(a, b - (m - 1) * a)
		else:
			solution(a, b - a * m)
(a, b) = map(int, stdin.readline().split())
solution(a, b)


(a, b) = [int(i) for i in input().split(' ')]
while a != 0 and b != 0:
	if a >= 2 * b:
		a %= 2 * b
	elif b >= 2 * a:
		b %= 2 * a
	else:
		break
print(a, b)


(a, b) = map(int, input().split())
while a != 0 and b != 0:
	if a >= 2 * b:
		a = a - a // (2 * b) * (2 * b)
		continue
	if b >= 2 * a:
		b = b - b // (2 * a) * (2 * a)
		continue
	else:
		break
print(a, b)


def f(l):
	(a, b) = l
	while True:
		if 0 in [a, b]:
			return [a, b]
		if a >= b << 1:
			a = a % (b << 1)
		elif b >= a << 1:
			b = b % (a << 1)
		else:
			return [a, b]
l = list(map(int, input().split()))
print(*f(l))


(a, b) = input().split(' ')
a = int(a)
b = int(b)
while a > 0 and b > 0:
	if a >= 2 * b:
		a = a % (2 * b)
	elif b >= 2 * a:
		b = b % (2 * a)
	else:
		print(a, b)
		exit()
print(a, b)


(n, m) = list(map(int, input().split()))
while n > 0 and m > 0:
	if n >= 2 * m:
		n %= 2 * m
	elif m >= 2 * n:
		m %= 2 * n
	else:
		break
print(str(n) + ' ' + str(m))


(a, b) = tuple(map(int, input().split()))

def step(a, b):
	if a == 0 or b == 0:
		n = 0
	elif a > b:
		n = a // (2 * b)
		a = a - n * 2 * b
	else:
		n = b // (2 * a)
		b -= n * 2 * a
	if n != 0:
		return step(a, b)
	return (a, b)
d = step(a, b)
print(d[0], d[1])


def solve(a, b, i):
	if a == 0 or b == 0:
		return [a, b]
	elif a >= 2 * b:
		a = a % (2 * b)
		return solve(a, b, i)
	elif b >= 2 * a:
		b = b % (2 * a)
		return solve(a, b, i)
	else:
		return [a, b]
(m, n) = map(int, input().split(' '))
print(' '.join(map(str, solve(m, n, False))))


(a, b) = [int(x) for x in input().split()]
flag = 0
while True:
	if a == 0 or b == 0:
		break
	if a >= 2 * b:
		a = a % (2 * b)
		continue
	if b >= 2 * a:
		b = b % (2 * a)
		continue
	else:
		break
print(a, ' ', b)


(a, b) = map(int, input().split())

def f(x, y):
	xx = x
	yy = y
	if xx >= 2 * yy:
		xx %= 2 * yy
	elif yy >= 2 * xx:
		yy %= 2 * xx
	if (xx == 0 or yy == 0) or (xx < 2 * yy and yy < 2 * xx):
		return (xx, yy)
	else:
		return f(xx, yy)
print(' '.join(map(str, f(a, b))))


(a, b) = map(int, input().split())
while a * b:
	if a >= 2 * b:
		a = a % (2 * b)
	elif b >= 2 * a:
		b = b % (2 * a)
	else:
		break
print(a, b)


(x, y) = map(int, input().split())
while x and y:
	if x >= 2 * y:
		x -= x // (2 * y) * 2 * y
	elif y >= 2 * x:
		y -= y // (2 * x) * 2 * x
	else:
		break
print(x, y)


ab = list(map(int, input().split()))

def down(a, b):
	if a == 0 or b == 0:
		print(a, b)
	elif a >= 2 * b:
		div = a // b
		if div % 2 == 1:
			div -= 1
		a -= div * b
		down(a, b)
	elif b >= 2 * a:
		div = b // a
		if div % 2 == 1:
			div -= 1
		b -= div * a
		down(a, b)
	else:
		print(a, b)
down(ab[0], ab[1])


(a, b) = map(int, input().split())
while True:
	f = True
	if b == 0:
		break
	if a >= 2 * b:
		a = a % (2 * b)
		f = False
	if a == 0:
		break
	if b >= 2 * a:
		b = b % (2 * a)
		f = False
	if f:
		break
print(a, b)


s = input()
a = int(s.split()[0])
b = int(s.split()[1])
while a != 0 and b != 0:
	if a >= 2 * b:
		a = a % (2 * b)
	elif b >= 2 * a:
		b = b % (2 * a)
	else:
		break
print(str(a) + ' ' + str(b))


def subtrac(a, b):
	try:
		if a == 0 or b == 0:
			return (a, b)
		elif a >= 2 * b:
			return subtrac(a - 2 * b, b)
		elif b >= 2 * a:
			return subtrac(a, b - 2 * a)
		else:
			return (a, b)
	except:
		if a > b:
			return (a % (2 * (b % a)), b)
		else:
			return (a, b % (2 * (a % b)))
(a, b) = map(int, input().split())
if a == 0 or b == 0:
	print(a, b)
elif a == b:
	print(a, b)
elif a < b:
	a_n = a % b
	if a_n == 0:
		print(*subtrac(a_n, b))
	else:
		b_n = b % (2 * a_n)
		print(*subtrac(a_n, b_n))
else:
	b_n = b % a
	if b_n == 0:
		print(*subtrac(a, b_n))
	else:
		print(*subtrac(a % (2 * b_n), b_n))


def read():
	return [int(v) for v in input().split()]

def main():
	(a, b) = read()
	while True:
		if a == 0 or b == 0:
			break
		if a >= 2 * b:
			a %= 2 * b
			continue
		if b >= 2 * a:
			b %= 2 * a
			continue
		break
	print(a, b)
main()


import sys
(n, m) = map(int, input().split())
while n and m:
	if n >= m * 2:
		n %= m * 2
	elif n * 2 <= m:
		m %= n * 2
	else:
		break
print(n, m)


(a, b) = map(int, input().split())
while 1 == 1:
	if not b <= 0:
		a %= 2 * b
	else:
		print(a, b)
		break
	if not a <= 0:
		b %= 2 * a
	else:
		print(a, b)
		break
	if a < 2 * b and b < 2 * a:
		print(a, b)
		break


(a, b) = map(int, input().split(' '))

def end(a, b):
	print('{} {}'.format(a, b))
i = True
while i:
	if a == 0 or b == 0:
		end(a, b)
		i = False
	elif a >= 2 * b:
		z = a // (2 * b)
		a = a - 2 * b * z
	elif b >= 2 * a:
		z = b // (2 * a)
		b = b - 2 * a * z
	else:
		i = False
		end(a, b)


(x, y) = map(int, input().split())
while 1:
	if x == 0 or y == 0:
		break
	elif x >= 2 * y:
		x = x % (2 * y)
	elif y >= 2 * x:
		y = y % (2 * x)
	else:
		break
print(x, y)


buff = input().split(' ')
a = int(buff[0])
b = int(buff[1])
while (a >= 2 * b or b >= 2 * a) and (a != 0 and b != 0):
	if a >= 2 * b and b > 0:
		a -= a // (2 * b) * (2 * b)
	if b >= 2 * a and a > 0:
		b -= b // (2 * a) * (2 * a)
print(a, b)


import math
lista = list(map(int, input().split()))
a = lista[0]
b = lista[1]

def resta(a, b):
	if a == 0 or b == 0:
		return f'{a} {b}'
	else:
		if a >= 2 * b:
			c = a // (2 * b)
			if c >= 1:
				a = a - 2 * b * c
				return resta(a, b)
			else:
				a = a - 2 * b
				return resta(a, b)
		if b >= 2 * a:
			d = b // (2 * a)
			if d >= 1:
				b = b - 2 * a * d
				return resta(a, b)
			else:
				b = b - 2 * a
				return resta(a, b)
		else:
			return f'{a} {b}'
print(resta(a, b))


(a, b) = map(int, input().split())
while True:
	if a == 0 or b == 0:
		print(a, b)
		exit(0)
	elif a >= 2 * b:
		a = a % (2 * b)
	elif b >= 2 * a:
		b = b % (2 * a)
	else:
		print(a, b)
		exit(0)


import atexit
import io
import sys
_INPUT_LINES = sys.stdin.read().splitlines()
input = iter(_INPUT_LINES).__next__
_OUTPUT_BUFFER = io.StringIO()
sys.stdout = _OUTPUT_BUFFER

@atexit.register
def write():
	sys.__stdout__.write(_OUTPUT_BUFFER.getvalue())
(a, b) = map(int, input().split())
while True:
	if a == 0 or b == 0:
		break
	elif a >= 2 * b:
		a = a % (2 * b)
	elif b >= 2 * a:
		b = b % (2 * a)
	else:
		break
print(a, b)


(a, b) = [int(x) for x in input().split()]
while a != 0 and b != 0:
	x = a
	y = b
	if a >= 2 * b:
		a = a % (2 * b)
		continue
	elif b >= 2 * a:
		b = b % (2 * a)
		continue
	if x == a and y == b:
		break
print(a, b)


def one(a, b):
	if a == 0 or b == 0:
		print(a, b)
		exit(0)
	else:
		return two(a, b)

def two(a, b):
	if a >= 2 * b:
		a = a % (2 * b)
		return one(a, b)
	else:
		return three(a, b)

def three(a, b):
	if b >= 2 * a:
		b = b % (2 * a)
		return one(a, b)
	else:
		print(a, b)
		exit(0)
(a, b) = list(map(int, input().split()))
one(a, b)


(a, b) = map(int, input().split())
while True:
	if (a == 0 or b == 0) or max(a, b) < 2 * min(a, b):
		print(a, b)
		break
	elif a >= 2 * b:
		a = a - a // (2 * b) * 2 * b
	else:
		b = b - b // (2 * a) * 2 * a


(a, b) = list(map(int, input().split()))
while a and b:
	if a >= 2 * b:
		a %= 2 * b
		continue
	if b >= 2 * a:
		b %= 2 * a
		continue
	break
print(a, b)


def fuck(a, b):
	if a * b == 0:
		print(a, b)
		return
	if a >= 2 * b:
		t = 2 * b
		a -= a // t * t
		fuck(a, b)
	elif b >= 2 * a:
		t = 2 * a
		b -= b // t * t
		fuck(a, b)
	else:
		print(a, b)
		return
fuck(*[int(i) for i in input().split()])


X = list(map(int, input().split()))
while 0 not in X:
	if X[0] >= 2 * X[1]:
		T = X[0] // (X[1] * 2)
		X[0] -= T * 2 * X[1]
	elif X[1] >= 2 * X[0]:
		T = X[1] // (X[0] * 2)
		X[1] -= T * 2 * X[0]
	else:
		break
print(*X)


import re
import sys
from bisect import bisect, bisect_left, insort, insort_left
from collections import Counter, defaultdict, deque
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from itertools import accumulate, combinations, combinations_with_replacement, groupby, permutations, product
from math import acos, asin, atan, ceil, cos, degrees, factorial, hypot, log2, pi, radians, sin, sqrt, tan
from operator import itemgetter, mul
from string import ascii_lowercase, ascii_uppercase, digits

def inp():
	return int(input())

def inlist():
	return list(map(int, input().split()))

def instr():
	s = input()
	return list(s[:len(s)])

def invr():
	return map(int, input().split())

def gcd_custom(a, b):
	if a == 0 or b == 0:
		return (a, b)
	if a >= 2 * b:
		return gcd_custom(a % (2 * b), b)
	elif b >= 2 * a:
		return gcd_custom(a, b % (2 * a))
	else:
		return (a, b)
(a, b) = invr()
(c, d) = gcd_custom(a, b)
print(c, d)


import sys

def subtrac(a, b):
	try:
		if a == 0 or b == 0:
			return (a, b)
		elif a >= 2 * b:
			return subtrac(a - 2 * b, b)
		elif b >= 2 * a:
			return subtrac(a, b - 2 * a)
		else:
			return (a, b)
	except:
		if a > b:
			return (a % (2 * (b % a)), b)
		else:
			return (a, b % (2 * (a % b)))
(a, b) = map(int, input().split())
sys.setrecursionlimit(1000)
if a == 0 or b == 0:
	print(a, b)
elif a == b:
	print(a, b)
elif a < b:
	a_n = a % b
	if a_n == 0:
		print(*subtrac(a_n, b))
	else:
		b_n = b % (2 * a_n)
		print(*subtrac(a_n, b_n))
else:
	b_n = b % a
	if b_n == 0:
		print(*subtrac(a, b_n))
	else:
		print(*subtrac(a % (2 * b_n), b_n))


(a, b) = map(int, input().split())
for _ in [0] * 24:
	if b:
		a %= 2 * b
	if a:
		b %= 2 * a
print(a, b)


class CodeforcesTask946BSolution:

	def __init__(self):
		self.result = ''
		self.n_m = []

	def read_input(self):
		self.n_m = [int(x) for x in input().split(' ')]

	def process_task(self):
		(a, b) = self.n_m
		while True:
			if not a or not b:
				break
			elif a >= 2 * b:
				a -= a // (2 * b) * 2 * b
			elif b >= 2 * a:
				b -= b // (2 * a) * 2 * a
			else:
				break
		self.result = '{0} {1}'.format(a, b)

	def get_result(self):
		return self.result
Solution = CodeforcesTask946BSolution()
Solution.read_input()
Solution.process_task()
print(Solution.get_result())


(a, b) = list(map(int, input().split()))
flag = 0
while flag == 0 and a != 0 and (b != 0):
	if a >= 2 * b:
		diff = a - 2 * b
		a -= diff - diff % (2 * b)
		if a >= 2 * b:
			a -= 2 * b
	elif b >= 2 * a:
		diff = b - 2 * a
		b -= diff - diff % (2 * a)
		if b >= 2 * a:
			b -= 2 * a
	else:
		flag = 1
print(a, b)


(a, b) = map(int, input().split())
while a and b and (a >= 2 * b or b >= 2 * a):
	if a > b:
		a %= 2 * b
	else:
		b %= 2 * a
print('{} {}'.format(a, b))


inp = input().split()
a = int(inp[0])
b = int(inp[1])
while True:
	if a == 0 or b == 0:
		break
	elif a >= b << 1:
		n = a // (b << 1)
		a -= n * (b << 1)
	elif b >= a << 1:
		n = b // (a << 1)
		b -= n * (a << 1)
	else:
		break
print(a, ' ', b)


import math
import collections
import bisect
import heapq
import time
import random
import itertools
import sys
(a, b) = map(int, input().split())
while a > 0 and b > 0:
	if a >= 2 * b:
		t = a // b // 2
		t *= 2
		a -= t * b
	elif b >= 2 * a:
		t = b // a // 2
		t *= 2
		b -= t * a
	else:
		break
print(a, b)


import sys, os

def main():
	(a, b) = list(map(int, sys.stdin.readline().rstrip().split()))
	while 1:
		if a == 0 or b == 0:
			break
		if a >= b << 1:
			a = a % (b << 1)
		elif b >= a << 1:
			b = b % (a << 1)
		else:
			break
	print(a, b)
main()


import sys, re, math
from collections import deque, defaultdict, Counter, OrderedDict
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd
from heapq import heappush, heappop, heapify, nlargest, nsmallest

def STR():
	return list(input())

def INT():
	return int(input())

def MAP():
	return map(int, input().split())

def LIST():
	return list(map(int, input().split()))

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def sortListWithIndex(listOfTuples, idx):
	return sorted(listOfTuples, key=lambda x: x[idx])

def sortDictWithVal(passedDic):
	temp = sorted(passedDic.items(), key=lambda kv: (kv[1], kv[0]))
	toret = {}
	for tup in temp:
		toret[tup[0]] = tup[1]
	return toret

def sortDictWithKey(passedDic):
	return dict(OrderedDict(sorted(passedDic.items())))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

def solveBF(a, b):
	while True:
		if a == 0 or b == 0:
			return (a, b)
		if a > b:
			k = (a - b) // (2 * b)
			if k < 0:
				k = 0
			a = a - 2 * b * k
		elif a < b:
			k = (b - a) // (2 * a)
			if k < 0:
				k = 0
			b = b - 2 * k * a
		if a >= 2 * b:
			a = a - 2 * b
		elif b >= 2 * a:
			b = b - 2 * a
		else:
			return (a, b)
(a, b) = MAP()
(A, B) = solveBF(a, b)
print(A, B)


(a, b) = map(int, input().split())
if a < b:
	(a, b) = (b, a)
	swap = 1
else:
	swap = 0
while b:
	(div, mod) = divmod(a, b)
	(a, b) = (b, mod)
	swap = 1 - swap
	if div % 2:
		b += a
		break
if swap:
	(a, b) = (b, a)
print(a, b)


(a, b) = list(map(int, input().split()))
while a > 0 and b > 0:
	if a >= 2 * b:
		a %= 2 * b
	elif b >= 2 * a:
		b %= 2 * a
	else:
		break
print(a, b)


(a, b) = map(int, input().split())
while a != 0 and b != 0:
	if a >= 2 * b:
		z = a // b
		if z % 2 != 0:
			z = z - 1
		a = a - b * z
		continue
	if b >= 2 * a:
		z = b // a
		if z % 2 != 0:
			z = z - 1
		b = b - a * z
		continue
	break
print(a, b)


def main():
	(N, M) = map(int, input().split())
	a = N
	b = M
	if not b:
		a %= 2 * b
	if not a:
		b %= 2 * a
	while 1:
		if any((not a, not b)):
			print(a, b)
			break
		elif a >= 2 * b:
			a %= 2 * b
		elif b >= 2 * a:
			b %= 2 * a
		else:
			print(a, b)
			break
main()


def weirdSubtraction(a, b):
	try:
		if a == 0 or b == 0:
			return [a, b]
		elif a >= 2 * b:
			a %= 2 * b
			result = weirdSubtraction(a, b)
		elif b >= 2 * a:
			b %= 2 * a
			result = weirdSubtraction(a, b)
		else:
			return [a, b]
		return result
	except RuntimeError:
		return [a, b]
numbers = input()
numbersList = numbers.split()
numbersList = weirdSubtraction(int(numbersList[0]), int(numbersList[1]))
print(str(numbersList[0]) + ' ' + str(numbersList[1]))


(a, b) = list(map(int, input().strip().split(' ')))
while True:
	if a == 0 or b == 0:
		break
	elif a >= 2 * b:
		a %= 2 * b
	elif b >= 2 * a:
		b %= 2 * a
	else:
		break
print(a, b)


(a, b) = map(int, input().split())
while True:
	if a == 0 or b == 0:
		break
	elif a >= 2 * b:
		qtd = a // (2 * b)
		a -= qtd * 2 * b
	elif b >= 2 * a:
		qtd = b // (2 * a)
		b -= qtd * 2 * a
	else:
		break
print(a, b)


import sys
import math
import itertools
import collections

def sieve(n):
	if n < 2:
		return list()
	prime = [True for _ in range(n + 1)]
	p = 3
	while p * p <= n:
		if prime[p]:
			for i in range(p * 2, n + 1, p):
				prime[i] = False
		p += 2
	r = [2]
	for p in range(3, n + 1, 2):
		if prime[p]:
			r.append(p)
	return r

def divs(n, start=1):
	r = []
	for i in range(start, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n / i == i:
				r.append(i)
			else:
				r.extend([i, n // i])
	return r

def prime(n):
	if n == 2:
		return True
	if n % 2 == 0 or n <= 1:
		return False
	sqr = int(math.sqrt(n)) + 1
	for d in range(3, sqr, 2):
		if n % d == 0:
			return False
	return True

def convn(number, base):
	newnumber = 0
	while number > 0:
		newnumber += number % base
		number //= base
	return newnumber

def cdiv(n, k):
	return n // k + (n % k != 0)

def ii():
	return int(input())

def mi():
	return map(int, input().split())

def li():
	return list(map(int, input().split()))

def lcm(a, b):
	return abs(a * b) // math.gcd(a, b)

def wr(arr):
	return ' '.join(map(str, arr))

def revn(n):
	return str(n)[::-1]

def dd():
	return collections.defaultdict(int)

def ddl():
	return collections.defaultdict(list)
(a, b) = mi()
while a != 0 and b != 0 and (a >= 2 * b or b >= 2 * a):
	a %= 2 * b
	if a == 0:
		break
	b %= 2 * a
print(a, b)


def STR():
	return list(input())

def INT():
	return int(input())

def MAP():
	return map(int, input().split())

def MAP2():
	return map(float, input().split())

def LIST():
	return list(map(int, input().split()))

def STRING():
	return input()
import string
import sys
from heapq import heappop, heappush
from bisect import *
from collections import deque, Counter, defaultdict
from math import *
from itertools import permutations, accumulate
dx = [-1, 1, 0, 0]
dy = [0, 0, 1, -1]
(a, b) = MAP()
flag = True
while flag:
	if a == 0 or b == 0:
		flag = False
		break
	elif a >= 2 * b:
		a = a % (2 * b)
	elif b >= 2 * a:
		b = b % (2 * a)
	else:
		flag = False
		break
print(a, b)


(a, b) = map(int, input().split())
while a * b != 0 and (not (a < 2 * b and b < 2 * a)):
	if a >= 2 * b:
		a = a % (2 * b)
	elif b >= 2 * a:
		b = b % (2 * a)
print(a, b)


(n, m) = map(int, input().split())
a = n
b = m
while a * b > 0:
	if a >= 2 * b:
		a = a % (2 * b)
	elif b >= 2 * a:
		b = b % (2 * a)
	else:
		break
print(a, b)


in_x = input().split(' ')
(a, b) = (int(in_x[0]), int(in_x[1]))
while a != 0 and b != 0:
	if a >= 2 * b:
		a = a % (2 * b)
		continue
	elif b >= 2 * a:
		b = b % (2 * a)
		continue
	else:
		break
print(a, b)


import sys
(a, b) = map(int, input().split())
while 1:
	if a == 0 or b == 0:
		print(a, end=' ')
		print(b)
		sys.exit()
	if a >= 2 * b:
		a %= 2 * b
	elif b >= 2 * a:
		b %= 2 * a
	else:
		print(a, end=' ')
		print(b)
		sys.exit()


line = input('').split()
a = int(line[0])
b = int(line[1])
while a != 0 and b != 0 and (a >= 2 * b or b >= 2 * a):
	if a >= b * 2:
		a %= 2 * b
	elif b >= 2 * a:
		b %= 2 * a
	else:
		break
print(str(a) + ' ' + str(b))


l = []

def p_1(a, b):
	if a == 0 or b == 0:
		l.append(a)
		l.append(b)
		return l
	else:
		return q_1(a, b)

def q_1(a, b):
	if a >= 2 * b:
		a = a % (2 * b)
		return p_1(a, b)
	else:
		return r_1(a, b)

def r_1(a, b):
	if b >= 2 * a:
		b = b % (2 * a)
		return p_1(a, b)
	else:
		l.append(a)
		l.append(b)
		return l
(a, b) = map(int, input().split())
c = p_1(a, b)
print(c[0], c[1])


def sub(a, b):
	if a == 0 or b == 0:
		return (a, b)
	if a >= 2 * b:
		return sub(a % (2 * b), b)
	if b >= 2 * a:
		return sub(a, b % (2 * a))
	return (a, b)
arr = list(map(int, input().split()))
a = arr[0]
b = arr[1]
print(*sub(a, b))


import sys

def f(a, b):
	if a == 0 or b == 0:
		return (a, b)
	elif a >= 2 * b:
		return f(a - 2 * b, b)
	elif b >= 2 * a:
		return f(a, b - 2 * a)
	else:
		return (a, b)

def g(a1, a2):
	a = a1
	b = a2
	while True:
		if a == 0 or b == 0:
			return (a, b)
		elif a >= 2 * b:
			q = a // (2 * b)
			a = a - 2 * b * q
		elif b >= 2 * a:
			q = b // (2 * a)
			b = b - 2 * a * q
		else:
			return (a, b)
for line in sys.stdin:
	d = tuple(line.split(' '))
	d = (int(d[0]), int(d[1]))
	d = g(*d)
	print('{0} {1}'.format(d[0], d[1]))


from decimal import *

class WSP:

	def main(self):
		(a, b) = map(int, input().strip().split(' '))
		a = Decimal(a)
		b = Decimal(b)
		n = True
		while n:
			if a == 0 or b == 0:
				n = False
			elif a >= 2 * b:
				a = a % (2 * b)
			elif b >= 2 * a:
				b = b % (2 * a)
			else:
				n = False
		print(a, b)
wsp = WSP()
wsp.main()


(x, y) = map(int, input().split())
T = True
while T:
	if x == 0 or y == 0:
		print(x, ' ', y)
		T = False
	elif x >= 2 * y:
		x %= 2 * y
	elif y >= 2 * x:
		y %= 2 * x
	else:
		print(x, y)
		T = False
		break


k = input().split()
a = int(k[0])
b = int(k[1])

def f1(a, b):
	if a == 0 or b == 0:
		print(a, b)
	else:
		f2(a, b)

def f2(a, b):
	if a >= 2 * b:
		if a % (2 * b) != 0:
			a = a % (2 * b)
			f3(a, b)
		else:
			print(0, b)
	else:
		f3(a, b)

def f3(a, b):
	if b >= 2 * a:
		if b % (2 * a) != 0:
			b = b % (2 * a)
			f2(a, b)
		else:
			print(a, 0)
	else:
		print(a, b)
f1(a, b)


(a, b) = map(int, input().split())
while a != 0 and b != 0:
	if a >= 2 * b:
		c = a // (2 * b)
		c = max(1, c)
		a = a - 2 * b * c
	elif b >= 2 * a:
		c = b // (2 * a)
		c = max(1, c)
		b = b - 2 * a * c
	else:
		break
print(a, b)


(a, b) = map(int, input().split())
while a * b and (a >= b * 2 or b >= 2 * a):
	(a, b) = [(a % (2 * b), b), (a, b % (2 * a))][a < b]
print(a, b)


(a, b) = map(int, input().split())
while a != 0 and b != 0:
	if a >= 2 * b:
		(q, r) = divmod(a, b)
		if q % 2 == 0:
			a = r
		else:
			a = b + r
	elif b >= 2 * a:
		(q, r) = divmod(b, a)
		if q % 2 == 0:
			b = r
		else:
			b = a + r
	else:
		break
print(a, b)


def read():
	return list(map(int, input().split()))
(a, b) = read()
while True:
	if a == 0 or b == 0:
		break
	elif a >= 2 * b:
		a %= 2 * b
	elif b >= 2 * a:
		b %= 2 * a
	else:
		break
print(a, b)


import sys
[a, b] = map(int, sys.stdin.readline().strip().split())
while a != 0 and b != 0:
	(a_old, b_old) = (a, b)
	a %= 2 * b
	if a == 0:
		break
	b %= 2 * a
	if a == a_old and b == b_old:
		break
print(a, b)


(a, b) = map(int, input().split())
while a:
	if a == 0 or b == 0:
		break
	if a >= 2 * b:
		div = a // (2 * b)
		a -= div * b * 2
	elif b >= 2 * a:
		div = b // (2 * a)
		b -= div * a * 2
	else:
		break
print(a, b)


(a, b) = input().split()
a = int(a)
b = int(b)
while 1:
	if a == b == 0:
		break
	elif a == 0 or b == 0:
		break
	elif a >= 2 * b:
		a = a % (2 * b)
		continue
	elif b >= 2 * a:
		b = b % (2 * a)
		continue
	else:
		break
print(a, b)


import math
(n, m) = map(int, input().split())
while n != 0 and m != 0:
	if n >= 2 * m:
		n = n % (2 * m)
		continue
	if m >= 2 * n:
		m = m % (2 * n)
		continue
	else:
		break
print(n, m)


(m, n) = map(int, input().split())
while m and n and (m >= 2 * n or n >= 2 * m):
	if m >= 2 * n:
		m %= 2 * n
	elif n >= 2 * m:
		n %= 2 * m
print(str(m) + ' ' + str(n))


(a, b) = map(int, input().split())
done = False
while not done:
	if a == 0 or b == 0:
		done = True
	elif a >= 2 * b:
		a = a % (2 * b)
	elif b >= 2 * a:
		b = b % (2 * a)
	else:
		done = True
print(a, b)


def great(a, b):
	if a >= b * 2:
		k = a // (2 * b)
		a = a - k * 2 * b
		func(a, b)
	elif b >= a * 2:
		s = 0
		k = b // (2 * a)
		b = b - k * 2 * a
		func(a, b)
	else:
		print(a, b)

def func(a, b):
	if a == 0 or b == 0:
		print(a, b)
	else:
		great(a, b)
(a, b) = map(int, input().split())
func(a, b)


import sys
sys.setrecursionlimit(1000000)
string = input()
string = string.split(' ')
a = int(string[0])
b = int(string[1])

def problem3(a, b):
	flag = True
	while (a != 0 and b != 0) and flag:
		tmp = a % (2 * b)
		b = b % (2 * a)
		a = tmp
		if a >= 2 * b:
			a = a - 2 * b
		elif b >= 2 * a:
			b = b - 2 * a
		else:
			flag = False
	print(a, b)
problem3(a, b)


(a, b) = map(int, input().split())

def solve(a, b):
	while a and b:
		if a >= 2 * b:
			a %= 2 * b
		elif b >= 2 * a:
			b %= 2 * a
		else:
			break
	return (a, b)
(a, b) = solve(a, b)
print(a, b)


(a, b) = map(int, input().split())
l = []

def simple(a, b):
	if a != 0 and b != 0:
		if a >= 2 * b:
			a = a % (2 * b)
			simple(a, b)
		elif b >= 2 * a:
			b = b % (2 * a)
			simple(a, b)
		else:
			l.append(a)
			l.append(b)
			return True
	else:
		l.append(a)
		l.append(b)
		return True
simple(a, b)
print(*l)


(a, b) = map(int, input().strip().split(' '))

def res(a, b):
	L = [a, b]
	if a == 0 or b == 0:
		return L
	elif a >= 2 * b:
		return res(a % (2 * b), b)
	elif b >= 2 * a:
		return res(a, b % (2 * a))
	else:
		return L
L = res(a, b)
print(L[0], end=' ')
print(L[1])


(a, b) = [int(i) for i in input().split()]
state = 1
while True:
	if state == 1:
		if a * b == 0:
			break
		else:
			state = 2
	elif state == 2:
		if a >= 2 * b:
			a = a % (2 * b)
			state = 1
		else:
			state = 3
	elif state == 3:
		if b >= 2 * a:
			b = b % (2 * a)
			state = 1
		else:
			break
print(a, b)


def solve():
	(n, m) = list(map(int, input().split()))
	while True:
		if n == 0 or m == 0:
			print(n, m)
			return
		elif n >= 2 * m:
			n = n % (2 * m)
			continue
		elif m >= 2 * n:
			m = m % (2 * n)
			continue
		else:
			print(n, m)
			return

def __starting_point():
	solve()
__starting_point()


(z, zz, dgraphs, mod) = (input, lambda : list(map(int, z().split())), {}, 10 ** 9 + 7)
from string import *
from collections import *
from queue import *
from sys import *
from collections import *
from math import *
from heapq import *
from itertools import *
from bisect import *
from collections import Counter as cc
from math import factorial as f

def lcd(xnum1, xnum2):
	return xnum1 * xnum2 // gcd(xnum1, xnum2)

def prime(x):
	p = ceil(x ** 0.5) + 1
	for i in range(2, p):
		if x % i == 0 and x != 2:
			return 0
	return 1

def dfs(u, visit, graph):
	visit[u] = True
	for i in graph[u]:
		if not visit[i]:
			dfs(i, visit, graph)
(a, b) = zz()
while True:
	if a == 0 or b == 0:
		break
	elif a >= 2 * b:
		a = a % (2 * b)
	elif b >= 2 * a:
		b = b % (2 * a)
	else:
		break
print(a, b)


(n, m) = [int(i) for i in input().split()]
while n != 0 and m != 0:
	if n >= 2 * m:
		k = n // (2 * m)
		n -= 2 * m * k
	elif m >= 2 * n:
		k = m // (2 * n)
		m -= 2 * n * k
	else:
		break
print(n, m)


(a, b) = map(int, input().split())

def func(a, b):
	if a == 0 or b == 0:
		return (a, b)
	if a >= 2 * b:
		return func(a % (2 * b), b)
	if b >= 2 * a:
		return func(a, b % (2 * a))
	return (a, b)
print(*func(a, b))


(a, b) = map(int, input().split())
rec = {}

def f(m, n):
	if (m, n) in rec:
		return rec[m, n]
	if n == 0:
		rec[m, n] = (m, 0)
		return (m, 0)
	if m == 0:
		rec[m, n] = (0, n)
		return (0, n)
	if m >= 2 * n:
		m = m % (2 * n)
		rec[m, n] = f(m, n)
		return rec[m, n]
	elif n >= 2 * m:
		n = n % (2 * m)
		rec[m, n] = f(m, n)
		return rec[m, n]
	else:
		rec[m, n] = (m, n)
		return (m, n)
(p, q) = f(a, b)
print('{} {}'.format(p, q))


(a, b) = map(int, input().split(' '))
s = 1
while 1:
	if a == 0 or b == 0:
		break
	elif a >= 2 * b:
		a %= 2 * b
	elif b >= 2 * a:
		b %= 2 * a
	else:
		break
print(a, b)


def weird(a, b):
	if not a or not b:
		return (a, b)
	if a >= 2 * b:
		return weird(a % (2 * b), b)
	if b >= 2 * a:
		return weird(a, b % (2 * a))
	return (a, b)
print(*weird(*map(int, input().split())))


(a, b) = map(int, input().split())
while a != 0 and b != 0:
	if a >= 2 * b:
		if a // b % 2 == 0:
			a = a % b
		else:
			a = a % b + b
	elif b // a % 2 == 0:
		b = b % a
	else:
		b = b % a + a
	if not (a >= 2 * b or b >= 2 * a):
		break
print(a, b)


def run():
	import sys
	sys.stdin = open('/home/punit/Documents/Cpp Programs/input.txt', 'r')
	sys.stdout = open('/home/punit/Documents/Cpp Programs/output.txt', 'w')
	from math import ceil, sqrt, floor
(a, b) = map(int, input().split())
while a > 0 and b > 0:
	if a >= 2 * b:
		a = a % (b + b)
	elif b >= 2 * a:
		b = b % (a + a)
	else:
		break
print(a, b)


(n, m) = map(int, input().split())
while True:
	if n == 0 or m == 0:
		break
	elif n >= 2 * m:
		n = n % (2 * m)
	elif m >= 2 * n:
		m = m % (2 * n)
	else:
		break
print(n, m)


(a, b) = map(int, input().split())
while a > 0 and b > 0:
	if a >= 2 * b:
		r = a - b
		r = r // b
		if r % b != 0 or b == 1:
			r += 1
		r = r - r % 2
		a = a - r * b
	elif b >= 2 * a:
		r = b - a
		r = r // a
		if r % a != 0 or a == 1:
			r += 1
		r = r - r % 2
		b = b - r * a
	else:
		break
print(a, b)


(a, b) = map(int, input().split())
for i in range(10 ** 10):
	if a != 0 and b != 0:
		if a >= 2 * b:
			k = a // (b * 2)
			a -= k * (b * 2)
		elif b >= 2 * a:
			k = b // (a * 2)
			b -= k * (2 * a)
		else:
			break
	else:
		break
print(a, b)


(x, y) = map(int, input().split())
ans = []
k = 0
while True:
	if x >= 2 * y:
		x %= 2 * y
	else:
		y %= 2 * x
	if x == 0 or y == 0:
		break
	if ans == [x, y]:
		k += 1
	else:
		ans = [x, y]
		k = 0
	if k == 5:
		break
print(x, y)


(a, b) = map(int, input().split())
while True:
	if a == 0 or b == 0:
		break
	if a > 2 * b:
		temp = a // (2 * b)
		a = a - 2 * b * temp
	elif b > 2 * a:
		temp = b // (2 * a)
		b = b - 2 * a * temp
	else:
		break
while True:
	if a == 0 or b == 0:
		print(a, b)
		break
	elif a >= 2 * b:
		a = a - 2 * b
		continue
	elif b >= 2 * a:
		b = b - 2 * a
		continue
	else:
		print(a, b)
		break


(a, b) = input().split()
a = int(a)
b = int(b)
activo = True
while activo:
	if a == 0 or b == 0:
		activo = False
		break
	elif a >= 2 * b:
		a %= 2 * b
	elif b >= 2 * a:
		b %= 2 * a
	else:
		activo = False
		break
print(str(a) + ' ' + str(b))


(a, b) = map(int, input().split())
for i in range(26):
	if b:
		a = a % (2 * b)
	if a:
		b = b % (2 * a)
print(a, b)


def weirdSubstractionProcess(a, b):
	while a and b:
		if a >= 2 * b:
			a %= 2 * b
		elif b >= 2 * a:
			b %= 2 * a
		else:
			return (a, b)
	return (a, b)
(a, b) = map(int, input().split())
(a, b) = weirdSubstractionProcess(a, b)
print(a, b)


def f(a, b):
	if a == 0 or b == 0:
		return [a, b]
	elif a >= 2 * b:
		return f(a % (2 * b), b)
	elif b >= 2 * a:
		return f(a, b % (2 * a))
	else:
		return [a, b]
(a, b) = map(int, input().split())
l = f(a, b)
print(*l)


(a, b) = map(int, input().split())
while True:
	if a * b:
		old_a = a
		old_b = b
		a %= 2 * b
		if a * b:
			b %= 2 * a
		else:
			break
		if old_a == a and old_b == b:
			break
	else:
		break
print(a, b)


def funct_1(a, b):
	if a == 0 or b == 0:
		return [a, b]
	else:
		return funct_2(a, b)

def funct_2(a, b):
	if a >= 2 * b:
		rest = a % b
		coef = (a - rest) // b
		if coef % 2 == 0:
			a = rest
		else:
			a = a - (coef - 1) * b
		return funct_1(a, b)
	else:
		return funct_3(a, b)

def funct_3(a, b):
	if b >= 2 * a:
		rest = b % a
		coef = (b - rest) // a
		if coef % 2 == 0:
			b = rest
		else:
			b = b - (coef - 1) * a
		return funct_1(a, b)
	else:
		return [a, b]

def main():
	[a, b] = [int(x) for x in input('').split()]
	if a == 0 or b == 0:
		rpta = funct_1(a, b)
	elif a >= 2 * b:
		rpta = funct_2(a, b)
	elif b >= 2 * a:
		rpta = funct_3(a, b)
	else:
		rpta = [a, b]
	print('%d %d' % (rpta[0], rpta[1]))
main()


def first(a, b):
	if a == 0 or b == 0:
		print(a, b)
	else:
		if a > b * 5:
			k = a // b
			if k % 2 == 0:
				a = a - b * (k - 4)
			else:
				a = a - b * (k - 5)
		if b > a * 5:
			k = b // a
			if k % 2 == 0:
				b = b - a * (k - 4)
			else:
				b = b - a * (k - 5)
		second(a, b)

def second(a, b):
	if a >= 2 * b:
		a = a - 2 * b
		first(a, b)
	else:
		third(a, b)

def third(a, b):
	if b >= 2 * a:
		b = b - 2 * a
		first(a, b)
	else:
		print(a, b)
(n, m) = map(int, input().split())
if n > m * 5:
	a = n // m
	if a % 2 == 0:
		n = n - m * (a - 4)
	else:
		n = n - m * (a - 5)
if m >> n * 5:
	a = m // n
	if a % 2 == 0:
		m = m - n * (a - 4)
	else:
		m = m - n * (a - 5)
first(n, m)


R = lambda : list(map(int, input().split()))
(n, m) = R()

def pr(a, b):
	if a == 0 or b == 0:
		return [a, b]
	if a // (2 * b) > 0:
		return pr(a - a // (2 * b) * 2 * b, b)
	if b // (2 * a) > 0:
		return pr(a, b - b // (2 * a) * 2 * a)
	return [a, b]
ans = pr(n, m)
print(ans[0], ans[1])


from sys import stdin, stdout
ii1 = lambda : int(stdin.readline().strip())
is1 = lambda : stdin.readline().strip()
iia = lambda : list(map(int, stdin.readline().strip().split()))
isa = lambda : stdin.readline().strip().split()
mod = 1000000007
(n, m) = iia()
prev = [n, m]
while n and m:
	if m:
		n %= 2 * m
	if n:
		m %= 2 * n
	if [n, m] == prev:
		break
	prev = [n, m]
print(n, m)


mod = 10 ** 9 + 7
ii = lambda : int(input())
si = lambda : input()
dgl = lambda : list(map(int, input()))
f = lambda : map(int, input().split())
il = lambda : list(map(int, input().split()))
ls = lambda : list(input())
(n, m) = f()
while (n != 0 and m != 0) and (n >= 2 * m or m >= 2 * n):
	if n > m:
		n %= 2 * m
	else:
		m %= 2 * n
print(n, m)


ab = input().split()
a = int(ab[0])
b = int(ab[1])
while a != 0 and b != 0:
	if a >= 2 * b:
		a = a % (2 * b)
	elif b >= 2 * a:
		b = b % (2 * a)
	else:
		break
print(a, b)


import math as mt
import sys, string, bisect
input = sys.stdin.readline
from collections import deque
L = lambda : list(map(int, input().split()))
Ls = lambda : list(input().split())
M = lambda : map(int, input().split())
I = lambda : int(input())

def rec(a, b):
	if a * b == 0:
		return [a, b]
	elif a >= 2 * b:
		return rec(a % (2 * b), b)
	elif b >= 2 * a:
		return rec(a, b % (2 * a))
	else:
		return [a, b]
(a, b) = M()
print(*rec(a, b))


(m, n) = map(int, input().split())
if m != 1 and n != 1:
	while 1:
		if n * m == 0:
			break
		elif n >= 2 * m:
			n = n % (2 * m)
		elif m >= 2 * n:
			m = m % (2 * n)
		else:
			break
	print(m, n)
elif m % 2 == 1 and n == 1 or (m == 1 and n % 2 == 1):
	print(1, 1)
elif m % 2 == 0 or n % 2 == 0:
	if n == 1:
		print(0, 1)
	else:
		print(1, 0)


def wsp(a, b):
	while True:
		if a == 0 or b == 0:
			break
		elif a >= 2 * b:
			a = a % (2 * b)
		elif b >= 2 * a:
			b = b % (2 * a)
		else:
			break
	print(str(a) + ' ' + str(b))
a = input()
b = a.split()
wsp(int(b[0]), int(b[1]))


a = [int(i) for i in input().split()]
while True:
	if a[0] == 0 or a[1] == 0:
		break
	elif a[0] >= a[1] * 2:
		e = a[0] // a[1]
		if e % 2 != 0:
			e -= 1
		a[0] -= a[1] * e
	elif a[1] >= a[0] * 2:
		e = a[1] // a[0]
		if e % 2 != 0:
			e -= 1
		a[1] -= a[0] * e
	else:
		break
print(a[0], a[1])


line = input()
(a, b) = list(map(int, line.strip().split()))

def helper(a, b):
	if a == 0 or b == 0:
		print(a, b)
	elif a >= 2 * b:
		times = a // (2 * b)
		a -= times * 2 * b
		helper(a, b)
	elif b >= 2 * a:
		times = b // (2 * a)
		b -= times * 2 * a
		helper(a, b)
	else:
		print(a, b)
helper(a, b)


def calc(a, b):
	if a == 0 or b == 0:
		return [a, b]
	elif a >= 2 * b:
		return calc(a % (2 * b), b)
	elif b >= 2 * a:
		return calc(a, b % (2 * a))
	else:
		return [a, b]
(a, b) = [int(i) for i in input('').split(' ')]
temp = calc(a, b)
print('{0} {1}'.format(*temp))


numbers = input()
numbers = numbers.split()
a = int(numbers[0])
b = int(numbers[1])
x = True
while x:
	if a == 0:
		x = False
		break
	if b == 0:
		x = False
		break
	if a >= 2 * b:
		a = a % (2 * b)
		continue
	if b >= 2 * a:
		b = b % (2 * a)
		continue
	x = False
print(a, b)


(a, b) = map(int, input().split())
while a and b:
	c = 0
	while a > 0 and b > 0 and (a >= 2 * b):
		a -= 2 * b * (a // (2 * b))
		c = 1
	while a > 0 and b > 0 and (b >= 2 * a):
		b -= 2 * a * (b // (2 * a))
		c = 1
	if c == 0:
		break
print(a, b)


(a, b) = map(int, input().split())
while True:
	if a == 0 or b == 0:
		break
	z = a // b
	if z & 1:
		a -= b * (z - 1)
	else:
		a -= b * z
	if a == 0:
		break
	z = b // a
	if z & 1:
		b -= a * (z - 1)
	else:
		b -= a * z
	if z < 2:
		break
print(a, b, end=' ')


(n, m) = input().split()
n = int(n)
m = int(m)
while n > 0 and m > 0:
	if n >= 2 * m:
		n %= 2 * m
	elif m >= 2 * n:
		m %= 2 * n
	else:
		break
print(n, m)


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
eps = 1.0 / 10 ** 15
mod = 10 ** 9 + 7

def LI():
	return [int(x) for x in sys.stdin.readline().split()]

def LI_():
	return [int(x) - 1 for x in sys.stdin.readline().split()]

def LF():
	return [float(x) for x in sys.stdin.readline().split()]

def LS():
	return sys.stdin.readline().split()

def I():
	return int(sys.stdin.readline())

def F():
	return float(sys.stdin.readline())

def S():
	return input()

def pf(s):
	return print(s, flush=True)

def main():
	(a, b) = LI()
	while a > 0 and b > 0:
		if a * 2 <= b:
			b %= a * 2
		elif b * 2 <= a:
			a %= b * 2
		else:
			break
	return '{} {}'.format(a, b)
print(main())


(a, b) = map(int, input().split())
while True:
	if not a or not b:
		break
	newa = a - a // (2 * b) * 2 * b
	newb = b - b // (2 * a) * 2 * a
	if newa == a and newb == b:
		break
	else:
		a = newa
		b = newb
print(a, b)


def test_2_2():
	(n, m) = list(map(int, input().split(' ')))
	(a, b) = (n, m)
	while a != 0 and b != 0:
		if a >= 2 * b:
			a = a % (2 * b)
		elif b >= 2 * a:
			b = b % (2 * a)
		else:
			break
	print(a, b)
test_2_2()


def solve(x, y):
	if x == 0 or y == 0:
		return (x, y)
	if x >= 2 * y and y != 0:
		x %= 2 * y
	if y >= 2 * x and x != 0:
		y %= 2 * x
	if x == 0 or y == 0:
		return (x, y)
	if x < 2 * y and y < 2 * x:
		return (x, y)
	return solve(x, y)
(x, y) = list(map(int, input().split()))
ans = solve(x, y)
print(ans[0], ans[1])


(n, m) = map(int, input().split())
fl = 0
while True:
	if n == 0 or m == 0 or (n < 2 * m and m < 2 * n):
		break
	if n >= 2 * m:
		n = n % (2 * m)
	if n == 0 or m == 0 or (n < 2 * m and m < 2 * n):
		break
	if m >= 2 * n:
		m = m % (2 * n)
print(n, m)


from math import *
(a, b) = list(map(int, input().split()))
while a != 0 and b != 0:
	if a >= 2 * b:
		can_a_multiplied_by = ceil(a / (2 * b)) / 2
		can_a_multiplied_by = ceil(can_a_multiplied_by)
		a -= can_a_multiplied_by * 2 * b
		continue
	if b >= 2 * a:
		can_b_multiplied_by = ceil(b / (2 * a)) / 2
		can_b_multiplied_by = ceil(can_b_multiplied_by)
		b -= can_b_multiplied_by * 2 * a
		continue
	break
print(int(a), int(b))


l = list(map(int, input().split()))
if 0 in l:
	print(*l)
else:
	while max(l) >= 2 * min(l):
		a = l.index(max(l))
		d = l[a] // l[1 - a]
		if d % 2 == 1:
			d -= 1
		l[a] = l[a] - l[1 - a] * d
		if 0 in l:
			break
	print(*l)


(a, b) = map(int, input().split())
while a != 0 and b != 0:
	bd = 2 * b
	ad = 2 * a
	if a >= bd:
		a -= bd * (a // bd)
	elif b >= ad:
		b -= ad * (b // ad)
	else:
		print(a, b)
		exit()
print(a, b)


import sys
sys.setrecursionlimit(10000000)

def find_ans(a, b):
	if a == 0 or b == 0:
		print(a, b)
	elif a >= 2 * b:
		a = a - a // (2 * b) * (2 * b)
		find_ans(a, b)
	elif b >= 2 * a:
		b = b - b // (2 * a) * (2 * a)
		find_ans(a, b)
	else:
		print(a, b)
(a, b) = map(int, input().split())
find_ans(a, b)


(a, b) = map(int, input().split())
while a > 0 and b > 0:
	cnt = 0
	if a >= b * 2:
		a %= b * 2
		cnt += 1
	elif b >= a * 2:
		b %= a * 2
		cnt += 1
	if cnt == 0:
		break
print(a, b)


import sys
(mod, MOD) = (1000000007, 998244353)

def get_array():
	return list(map(int, sys.stdin.readline().strip().split()))

def get_ints():
	return map(int, sys.stdin.readline().strip().split())

def input():
	return sys.stdin.readline().strip()
(a, b) = get_ints()
while True:
	if a == 0 or b == 0:
		break
	elif a >= 2 * b:
		a = a % (2 * b)
	elif b >= 2 * a:
		b = b % (2 * a)
	else:
		break
print(a, b)


(a, b) = map(int, input().split())
while True:
	if a < 2 * b and b < 2 * a:
		break
	if a >= 2 * b:
		a = a % (2 * b)
		if a == 0 or b == 0:
			break
	if b >= 2 * a:
		b = b % (2 * a)
		if a == 0 or b == 0:
			break
print(a, b)


(a, b) = map(int, input().split())
while True:
	if a == 0 or b == 0:
		break
	elif a >= 2 * b:
		a %= 2 * b
	elif b >= 2 * a:
		b %= 2 * a
	else:
		break
print('%d %d\n' % (a, b))


(a, b) = map(int, input().split())
while a > 0 and b > 0:
	if b >= 2 * a:
		p = b - 2 * a
		q = p // (2 * a)
		b -= q * (2 * a)
		if q == 0:
			b -= 2 * a
	elif a >= 2 * b:
		p = a - 2 * b
		q = p // (2 * b)
		a -= q * (2 * b)
		if q == 0:
			a -= 2 * b
	else:
		break
print(a, b)


arr1 = str(input())
arr = arr1.split()
a = int(arr[0])
b = int(arr[1])
flag = 2
while (a != 0 and b != 0) and (a >= 2 * b or b >= 2 * a):
	if flag == 1:
		if a == 0 or b == 0:
			break
		flag = 2
		continue
	elif flag == 2 and a >= 2 * b:
		k = a // b
		if k > 2:
			if k & 1:
				a -= (k - 1) * b
			else:
				a -= k * b
			continue
		a -= 2 * b
		flag = 1
		continue
	elif b >= 2 * a:
		b -= 2 * a
		k = b // a
		if k > 2:
			if k & 1:
				b -= (k - 1) * a
			else:
				b -= k * a
		flag = 1
	else:
		break
strs = str(a) + ' ' + str(b)
print(strs)


(m, n) = [int(i) for i in input().split()]
while True:
	if m == 0 or n == 0:
		break
	elif m >= 2 * n:
		m %= 2 * n
	elif n >= 2 * m:
		n %= 2 * m
	else:
		break
print(m, n)


from math import log2

def minpow2(x, y):
	return int(log2(x // y))
(a, b) = list(map(int, input().split()))
while a > 0 and b > 0:
	if a >= 2 * b:
		a = a % (2 * b)
		continue
	elif b >= 2 * a:
		b = b % (2 * a)
		continue
	else:
		break
print(a, b)


(n, m) = map(int, input().split())
a = n
b = m
while True:
	f = 0
	if a == 0 or b == 0:
		f = 1
		break
	elif a >= 2 * b:
		x = a // b
		x = x // 2 * 2
		a -= b * x
		f = 1
	elif b >= 2 * a:
		x = b // a
		x = x // 2 * 2
		b -= a * x
		f = 1
	if f == 0:
		break
print(a, b)


(a, b) = list(map(int, input().split()))
while a != 0 and b != 0 and (a >= 2 * b or b >= 2 * a):
	if a >= 2 * b:
		a = a - a // (2 * b) * (b * 2)
	else:
		b = b - b // (2 * a) * (a * 2)
print(a, b)


(a, b) = map(int, input().split())
while True:
	if not a or not b:
		break
	if a >= b << 1:
		a %= b << 1
	elif b >= a * 2:
		b %= a << 1
	else:
		break
print(a, b)


import sys
from collections import defaultdict as dd
from collections import deque
from fractions import Fraction as f
from copy import *
from bisect import *
from heapq import *
from math import *
from itertools import permutations

def eprint(*args):
	print(*args, file=sys.stderr)
zz = 1
if zz:
	input = sys.stdin.readline
else:
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('all.txt', 'w')

def li():
	return [int(x) for x in input().split()]

def fli():
	return [float(x) for x in input().split()]

def gi():
	return [x for x in input().split()]

def fi():
	return int(input())

def swap(a, i, j):
	(a[i], a[j]) = (a[j], a[i])

def si():
	return list(input().rstrip())

def mi():
	return map(int, input().split())

def gh():
	sys.stdout.flush()

def graph(n, m):
	for i in range(m):
		(x, y) = mi()
		a[x].append(y)
		a[y].append(x)

def bo(i):
	return ord(i) - ord('a')
(a, b) = mi()
tle = 0
while a >= 2 * b or b >= 2 * a:
	k = 1
	if a == 0 or b == 0:
		break
	while a >= 2 ** k * b:
		k += 1
	k -= 1
	a -= 2 ** k * b if k > 0 else 0
	k = 1
	if a == 0 or b == 0:
		break
	while b >= 2 ** k * a:
		k += 1
	k -= 1
	b -= 2 ** k * a if k > 0 else 0
print(a, b)


import math

def prime(n):
	ok = True
	for i in range(2, int(math.sqrt(n))):
		if n % i == 0:
			ok = False
			break
	if ok:
		return True
	else:
		return False

def fact(a, b):
	ans = 1
	for i in range(a, b + 1):
		ans *= i
	return str(ans) - 1

def comb(n, c):
	return fact(n) // (fact(n - c) * c)
(a, b) = map(int, input().split())

def done(c, d):
	if c == 0 or d == 0:
		return True
	else:
		return False
while not done(a, b):
	if a >= 2 * b:
		a = int(a % (2 * b))
	elif b >= 2 * a:
		b = int(b % (2 * a))
	else:
		break
print(a, b)


(a, b) = map(int, input().split())
while a * b and (not a < 2 * b < 4 * a):
	if b < a:
		a %= 2 * b
	else:
		b %= 2 * a
print(a, b)


import time
values = list(map(int, input().split()))
while values[0] >= 2 * values[1] or values[1] >= 2 * values[0]:
	if values[0] == 0 or values[1] == 0:
		break
	if values[0] >= 2 * values[1]:
		values[0] %= 2 * values[1]
	elif values[1] >= 2 * values[0]:
		values[1] %= 2 * values[0]
print(values[0], values[1])


from sys import stdin

def iinput():
	return int(stdin.readline())

def sinput():
	return input()

def minput():
	return map(int, stdin.readline().split())

def linput():
	return list(map(int, stdin.readline().split()))
(a, b) = minput()
while a and b:
	if a >= 2 * b:
		a = a % (2 * b)
	elif b >= 2 * a:
		b = b % (2 * a)
	else:
		break
print(a, b)


(a, b) = list(map(int, input().strip().split(' ')))
while True:
	if a == 0 or b == 0:
		break
	if a >= 2 * b:
		d = a // (2 * b)
		d = max(d - 1, 1)
		a = a - d * 2 * b
	if a == 0 or b == 0:
		break
	if b >= 2 * a:
		d = b // (a * 2)
		d = max(d - 1, 1)
		b = b - d * 2 * a
	if a == 0 or b == 0:
		break
	if a < 2 * b and b < 2 * a:
		break
print(a, b)


args = [int(x) for x in input().split(' ')]
a = args[0]
b = args[1]
continu = True
while continu:
	if a == 0 or b == 0:
		continu = False
	elif a >= 2 * b:
		a = a % (2 * b)
	elif b >= 2 * a:
		b = b % (2 * a)
	else:
		continu = False
print(a, b)


def find(a, b):
	while 1:
		if a == 0 or b == 0:
			break
		elif a >= 2 * b:
			a %= 2 * b
			continue
		elif b >= 2 * a:
			b %= 2 * a
			continue
		break
	return [a, b]
(n, m) = [int(i) for i in input().split(' ')]
ans = find(n, m)
print(*ans)


def s1(a, b):
	if a == 0 or b == 0:
		print(a, b)
	else:
		s2(a, b)

def s2(a, b):
	if a >= 2 * b:
		x = a // b
		if x % 2 == 1:
			x = x - 1
		a = a - b * x
		s1(a, b)
	else:
		s3(a, b)

def s3(a, b):
	if b >= 2 * a:
		x = b // a
		if x % 2 == 1:
			x = x - 1
		b = b - a * x
		s1(a, b)
	else:
		print(a, b)
(a, b) = map(int, input().split())
s1(a, b)


(a, b) = map(int, input().split())
while a != 0 and b != 0:
	t = 2 * b
	if a >= t:
		temp = a // b
		p = -1
		while temp:
			temp = temp // 2
			p += 1
		temp = 2 ** p
		a -= b * temp
	else:
		t = 2 * a
		if b >= t:
			temp = b // a
			p = -1
			while temp:
				temp = temp // 2
				p += 1
			temp = 2 ** p
			b -= temp * a
		else:
			break
print(a, b)


(a, b) = map(int, input().split())
while a != 0 and b != 0 and (min(a, b) * 2 <= max(a, b)):
	if a >= 2 * b:
		(a, b) = (a - 2 * b * ((a - 2 * b) // (2 * b) + 1), b)
		if b < 0:
			b += 2 * a
	elif b >= 2 * a:
		(a, b) = (a, b - 2 * a * ((b - 2 * a) // (2 * a) + 1))
		if a < 0:
			a += 2 * b
print(a, b)


(a, b) = map(int, input().strip().split())
while True:
	if a == 0 or b == 0:
		break
	if a >= 2 * b:
		k = a // (2 * b)
		a = a - k * (2 * b)
	elif b >= 2 * a:
		k = b // (2 * a)
		b = b - k * (2 * a)
	else:
		break
print(' '.join(map(str, [a, b])))


(a, b) = [int(x) for x in input().split(' ')]
while min(a, b) > 0:
	if a >= 2 * b:
		a = a % (2 * b)
	elif b >= 2 * a:
		b = b % (2 * a)
	else:
		break
print(a, b)


(a, b) = map(int, input().split())
while True:
	if a == 0 or b == 0:
		break
	tmp = 2 * b
	if a >= tmp:
		delta = len(str(a)) - len(str(tmp))
		if delta > 1:
			tmp = tmp * 10 ** (delta - 1)
		a = a - tmp
		continue
	tmp = 2 * a
	if b >= tmp:
		delta = len(str(b)) - len(str(tmp))
		if delta > 1:
			tmp = tmp * 10 ** (delta - 1)
		b = b - tmp
		continue
	break
print(a, b, end='')


import sys
(a, b) = list(map(int, input().split()))
while True:
	if a == 0 or b == 0:
		print(a, b)
		return
	if a >= 2 * b:
		a = a % (2 * b)
	elif b >= 2 * a:
		b = b % (2 * a)
	else:
		print(a, b)
		return


(a, b) = map(int, input().split())
while a != 0 and b != 0:
	if a >= 2 * b and b != 0:
		a %= 2 * b
	if b >= 2 * a and a != 0:
		b %= 2 * a
	if a < 2 * b and b < 2 * a:
		print(a, b)
		exit()
print(a, b)


(n, m) = map(int, input().split())
while True:
	if n == 0 or m == 0:
		break
	if n >= 2 * m:
		can = n // (2 * m)
		n -= 2 * m * can
		continue
	if m >= n * 2:
		can = m // (2 * n)
		m -= 2 * n * can
		continue
	break
print(n, m)


def f(a, b):
	if a == 0 or b == 0:
		return (a, b)
	if a >= 2 * b:
		return f(a % (2 * b), b)
	elif b >= 2 * a:
		return f(a, b % (2 * a))
	return (a, b)
(a, b) = map(int, input().split())
print(' '.join(list(map(str, f(a, b)))))


(a, b) = map(int, input().split())

def huh(a, b):
	if a * b == 0:
		return (a, b)
	elif a >= 2 * b:
		return huh(a % (2 * b), b)
	elif b >= 2 * a:
		return huh(a, b % (2 * a))
	else:
		return (a, b)
(a, b) = huh(a, b)
print(a, b)


def main():
	(a, b) = input().split()
	stepOne(int(a), int(b))

def stepOne(a, b):
	if a == 0 or b == 0:
		print(a, b)
	elif checkValue(a, b):
		a = changeValue(a, b)
		stepOne(a, b)
	elif checkValue(b, a):
		b = changeValue(b, a)
		stepOne(a, b)
	else:
		print(a, b)

def changeValue(num, num2):
	return num % (2 * num2)

def checkValue(num, num2):
	if num >= 2 * num2:
		return 1
	return 0
main()


(a, b) = map(int, input().split())
while (a >= 2 * b or b >= 2 * a) and a != 0 and (b != 0):
	if a >= 2 * b:
		a = a % (2 * b)
	elif b >= 2 * a:
		b = b % (2 * a)
print(str(a) + ' ' + str(b))


(a, b) = list(map(int, input().strip().split(' ')))

def step1():
	global a, b
	if a == 0 or b == 0:
		return True
	else:
		return False

def step2():
	global a, b
	if a >= 2 * b:
		a %= 2 * b
		return True
	else:
		return False

def step3():
	global a, b
	if b >= 2 * a:
		b %= 2 * a
		return True
	else:
		return False

def endprog():
	global a, b
	print(a, b)
while not step1():
	if step2():
		continue
	elif step3():
		continue
	else:
		break
endprog()


import sys

def WeirdSub(a, b):
	while a != 0 and b != 0:
		if a >= 2 * b:
			a %= 2 * b
		elif b >= 2 * a:
			b %= 2 * a
		else:
			break
	return (a, b)
(a, b) = map(int, sys.stdin.readline().split())
l = list(WeirdSub(a, b))
a = l[0]
b = l[1]
print(a, b)


def p3(a, b):
	if not a or not b:
		return (a, b)
	if a >= 2 * b:
		a %= 2 * b
		return p3(a, b)
	if b >= 2 * a:
		b %= 2 * a
		return p3(a, b)
	return (a, b)
(a, b) = input().split(' ')
(a, b) = p3(int(a), int(b))
print(a, b)


(a, b) = map(int, input().split())
while True:
	c = a // (2 * b)
	a -= c * 2 * b
	if a == 0:
		break
	d = b // (2 * a)
	b -= d * 2 * a
	if d == 0 or b == 0:
		break
print(str(a) + ' ' + str(b))


def solve(a, b):
	if a == 0 or b == 0:
		return (a, b)
	if a >= 2 * b:
		return solve(a % (2 * b), b)
	if b >= 2 * a:
		return solve(a, b % (2 * a))
	return (a, b)
(a, b) = list(map(int, input().split()))
print(*solve(a, b))


(a, b) = map(int, input().split())
mark = True
while a > 0 and b > 0 and mark:
	mark = False
	if a >= 2 * b and b > 0:
		a = a % (2 * b)
		mark = True
	if b >= 2 * a and a > 0:
		b = b % (2 * a)
		mark = True
print(a, b)


import sys
sys.setrecursionlimit(1000000)

def ans(a, b):
	if a == 0 or b == 0:
		return (a, b)
	elif a >= 2 * b:
		a = a - a // (2 * b) * 2 * b
		return ans(a, b)
	elif b >= 2 * a:
		b = b - b // (2 * a) * 2 * a
		return ans(a, b)
	else:
		return (a, b)
(a, b) = map(int, input().split())
(tb1, tb2) = ans(a, b)
print(tb1, tb2)


(a, b) = map(int, input().split())
while a != 0 and b != 0:
	if a > 2 * b or b > 2 * a:
		while a > 2 * b and b != 0:
			k = a // (2 * b)
			a -= 2 * b * k
		while b > 2 * a and a != 0:
			k = b // (2 * a)
			b -= 2 * a * k
	elif a == 2 * b:
		a = 0
	elif b == 2 * a:
		b = 0
	else:
		exit(print(a, b))
print(a, b)


numbers = input().split(' ')
a = int(numbers[0])
b = int(numbers[1])
con = 1
while a != 0 and b != 0:
	if a >= 2 * b:
		a = a % (2 * b)
	elif b >= 2 * a:
		b = b % (2 * a)
	else:
		break
print(a, b)


(n, m) = input().split()
a = int(n)
b = int(m)
k = 0
while a != 0 and b != 0 and (k != 1):
	if a >= 2 * b:
		ka = a // b
		if ka % 2 != 0:
			ka = ka - 1
		a = a - ka * b
	elif b >= 2 * a:
		kb = b // a
		if kb % 2 != 0:
			kb = kb - 1
		b = b - kb * a
	else:
		k = 1
print(a, ' ', b)


getInputList = lambda : list(input().split())
getInputIntList = lambda : list(map(int, input().split()))
(a, b) = getInputIntList()
prea = a
preb = b
while a > 0 and b > 0:
	if a == b:
		break
	elif a > b:
		a = a % (2 * b)
	else:
		b = b % (2 * a)
	if prea == a and preb == b:
		break
	prea = a
	preb = b
print(a, b)


(a, b) = map(int, input().split())
while a != 0 and b != 0:
	c = 2 * a
	d = 2 * b
	if a >= d:
		a %= d
	elif b >= c:
		b %= c
	else:
		break
print(a, b)


import math
(a, b) = map(int, input().split())
while a != 0 and b != 0:
	if a >= 2 * b:
		a = a % (2 * b)
		continue
	elif b >= 2 * a:
		b = b % (2 * a)
		continue
	else:
		break
print(a, b)


import math
(n, m) = (int(i) for i in input().split())
while n != 0 and m != 0 and (n >= m and n >= 2 * m or (m > n and m >= 2 * n)):
	if n >= m:
		n %= 2 * m
	else:
		m %= 2 * n
print(n, m)


(a, b) = [int(s) for s in input().split()]
while a != 0 and b != 0:
	if a // (2 * b) > 0:
		a %= 2 * b
		continue
	elif b // (2 * a) > 0:
		b %= 2 * a
		continue
	else:
		break
print(a, b)


(n, m) = map(int, input().strip().split(' '))
if n >= 2 * m or m >= 2 * n:
	while n >= 2 * m or m >= 2 * n:
		if n == 0 or m == 0:
			break
		if m > n:
			k = m // (n * 2)
			m -= k * (n * 2)
		elif n > m:
			k = n // (m * 2)
			n -= k * (m * 2)
	print(n, m, end=' ')
else:
	print(n, m, end=' ')


(a, b) = map(int, input().split())
while True:
	if a == 0 or b == 0:
		break
	elif a >= 2 * b:
		h = a // (2 * b)
		a -= h * (2 * b)
	elif b >= 2 * a:
		v = b // (2 * a)
		b -= v * (2 * a)
	else:
		break
print(a, b)


def ans(a, b):
	if a == 0 or b == 0:
		return (a, b)
	if a < 2 * b and b < 2 * a:
		return (a, b)
	if a >= 2 * b:
		a %= 2 * b
		return ans(a, b)
	else:
		b %= 2 * a
		return ans(a, b)
(a, b) = map(int, input().split())
(a, b) = ans(a, b)
print(a, b)


i = lambda : map(int, input().split())
(a, b) = i()
while True:
	if a == 0 or b == 0:
		break
	elif a >= 2 * b and a != 0 and (b != 0):
		a = a % (2 * b)
	elif b >= 2 * a and a != 0 and (b != 0):
		b = b % (2 * a)
	else:
		break
print(a, b)


(a, b) = map(int, input().split())
while True:
	if a * b == 0:
		break
	if a >= 2 * b:
		a = a % (2 * b)
		continue
	if b >= 2 * a:
		b = b % (2 * a)
		continue
	break
print(a)
print(b)


(a, b) = input().split()
(a, b) = (int(a), int(b))
while True:
	if a == 0 or b == 0 or (b < 2 * a and a < 2 * b):
		print(a, b)
		break
	elif a >= 2 * b:
		a = a % (2 * b)
	else:
		b = b % (2 * a)


(a, b) = map(int, input().split())
while a > 0 and b > 0:
	if a >= 2 * b:
		k = (a + 2 * b - 1) // (2 * b) - 1
		if k == 0:
			k = 1
		a -= 2 * k * b
	elif b >= 2 * a:
		k = (b + 2 * a - 1) // (2 * a) - 1
		if k == 0:
			k = 1
		b -= 2 * k * a
	else:
		break
print(a, b)


from __future__ import division, print_function
import itertools, os, sys, threading
from collections import deque, Counter, OrderedDict, defaultdict
import heapq
from math import ceil, floor, log, sqrt, factorial, pow, pi

def ii():
	return int(input())

def si():
	return str(input())

def mi():
	return map(int, input().split())

def li():
	return list(mi())
abc = 'abcdefghijklmnopqrstuvwxyz'
abd = {'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12, 'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24, 'z': 25}
mod = 1000000007
(dx, dy) = ([-1, 1, 0, 0], [0, 0, 1, -1])

def getKey(item):
	return item[0]

def sort2(l):
	return sorted(l, key=getKey)

def d2(n, m, num):
	return [[num for x in range(m)] for y in range(n)]

def isPowerOfTwo(x):
	return x and (not x & x - 1)

def decimalToBinary(n):
	return bin(n).replace('0b', '')

def ntl(n):
	return [int(i) for i in str(n)]

def powerMod(x, y, p):
	res = 1
	x %= p
	while y > 0:
		if y & 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x
graph = defaultdict(list)
visited = [0] * 1000000
col = [-1] * 1000000

def dfs(v, c):
	if visited[v]:
		if col[v] != c:
			print('-1')
			exit()
		return
	col[v] = c
	visited[v] = 1
	for i in graph[v]:
		dfs(i, c ^ 1)

def bfs(d, v):
	q = []
	q.append(v)
	visited[v] = 1
	while len(q) != 0:
		x = q[0]
		q.pop(0)
		for i in d[x]:
			if visited[i] != 1:
				visited[i] = 1
				q.append(i)
		print(x)
	print(l)

def make_graph(e):
	d = {}
	for i in range(e):
		(x, y) = mi()
		if x not in d.keys():
			d[x] = [y]
		else:
			d[x].append(y)
		if y not in d.keys():
			d[y] = [x]
		else:
			d[y].append(x)
	return d

def gr2(n):
	d = {}
	for i in range(n):
		(x, y) = mi()
		if x not in d.keys():
			d[x] = [y]
		else:
			d[x].append(y)
	return d

def connected_components(graph):
	seen = set()

	def dfs(v):
		vs = set([v])
		component = []
		while vs:
			v = vs.pop()
			seen.add(v)
			vs |= set(graph[v]) - seen
			component.append(v)
		return component
	ans = []
	for v in graph:
		if v not in seen:
			d = dfs(v)
			ans.append(d)
	return ans
(a, b) = mi()
while 1:
	if a == 0 or b == 0:
		break
	if a >= 2 * b and b > 0:
		a = a % (2 * b)
	if b >= 2 * a and a > 0:
		b = b % (2 * a)
	else:
		break
print(a, b)


from sys import stdin
input = stdin.buffer.readline
(n, m) = map(int, input().split())
while n and m and (n >= 2 * m or m >= 2 * n):
	n %= 2 * m
	if not n:
		break
	m %= 2 * n
print(n, m)


def check1(a, b):
	if a == 0 or b == 0:
		print(a, b)
	else:
		check2(a, b)

def check2(a, b):
	if a >= 2 * b:
		a = a % (2 * b)
		check1(a, b)
	else:
		check3(a, b)

def check3(a, b):
	if b >= 2 * a:
		b = b % (2 * a)
		check1(a, b)
	else:
		print(a, b)
t = list(map(int, input().split()))
a = t[0]
b = t[1]
check1(a, b)


def f(a, b):
	if a == 0 or b == 0:
		return (a, b)
	if a >= 2 * b:
		a = a - 2 * b * ((a - 2 * b) // (2 * b) + 1)
		return f(a, b)
	if b >= 2 * a:
		b = b - 2 * a * ((b - 2 * a) // (2 * a) + 1)
		return f(a, b)
	return (a, b)
(a, b) = map(int, input().split())
(a, b) = f(a, b)
print(a, b)


(a, b) = map(int, input().split())
while True:
	if a == 0 or b == 0:
		break
	if not (a >= 2 * b or b >= 2 * a):
		break
	if a >= 2 * b:
		a = a % (2 * b)
	else:
		b = b % (2 * a)
print(a, b)


(a, b) = [int(x) for x in input().split()]

def func(a, b):
	if a == 0 or b == 0:
		return (a, b)
	elif a >= 2 * b:
		return func(a - a // (2 * b) * (2 * b), b)
	elif b >= 2 * a:
		return func(a, b - b // (2 * a) * 2 * a)
	return (a, b)
for i in func(a, b):
	print(i, end=' ')


import sys
(m, n) = [int(x) for x in input().split()]
if n == 0 or m == 0:
	print(m, n)
	sys.exit()
while (m >= 2 * n or n >= 2 * m) and (m > 0 and n > 0):
	if m >= 2 * n:
		m = m % (2 * n)
	else:
		n = n % (2 * m)
print(m, n)


(a, b) = input().split()
(a, b) = [int(a), int(b)]
n = a
m = b

def ShowMeTheSub(a, b):
	while a != 0 and b != 0 and (a >= 2 * b or b >= 2 * a):
		if a >= 2 * b:
			a %= 2 * b
		elif b >= 2 * a:
			b %= 2 * a
		else:
			return print(a, b)
	return print(a, b)
ShowMeTheSub(n, m)


def f(a, b):
	if a == 0 or b == 0:
		return (a, b)
	if a >= 2 * b:
		return f(a % (2 * b), b)
	if b >= 2 * a:
		return f(a, b % (2 * a))
	return (a, b)
(n, m) = map(int, input().split())
print(*f(n, m))


import math
from sys import stdin
string = stdin.readline().strip().split()
a = int(string[0])
b = int(string[1])

def func(x, y):
	if x * y == 0:
		print(x, y)
	elif x >= 2 * y:
		q = x % (2 * y)
		x = q
		func(x, y)
	elif y >= 2 * x:
		q = y % (2 * x)
		y = q
		func(x, y)
	else:
		print(x, y)
func(a, b)


(a, b) = map(int, input().split())

def solve(x, y):
	if x >= 2 * y:
		x %= 2 * y
	elif y >= 2 * x:
		y %= 2 * x
	if (x == 0 or y == 0) or (x < 2 * y and y < 2 * x):
		return (x, y)
	else:
		return solve(x, y)
print(' '.join(map(str, solve(a, b))))


(n, m) = map(int, input().split())
while n and m:
	f = 0
	s = 0
	if n >= 2 * m and n > 0 and (m > 0):
		f = 1
		if m != 0:
			fin = n // m
			if fin % 2 == 0:
				n = n - fin * m
			else:
				fin -= 1
				n = n - fin * m
	if m >= 2 * n and n > 0 and (m > 0):
		s = 1
		if n != 0:
			sin = m // n
			if sin % 2 == 0:
				m = m - sin * n
			else:
				sin -= 1
				m = m - sin * n
	if n == 0 or m == 0:
		break
	if f == 0 and s == 0:
		break
print(n, m)


def main():
	(a, b) = map(int, input().split())
	s = 1
	while a > 0 < b:
		if a < b:
			(a, b, s) = (b, a, 1 - s)
		if a < b * 2:
			break
		else:
			a %= b * 2
	print(*([a, b] if s else [b, a]))
main()


def weird_substraction(a, b):
	if a == 0 or b == 0:
		print(str(a) + ' ' + str(b))
	elif a >= 2 * b:
		n = a % (2 * b)
		weird_substraction(n, b)
	elif b >= 2 * a:
		n = b % (2 * a)
		weird_substraction(a, n)
	else:
		print(str(a) + ' ' + str(b))
(a, b) = map(int, input().split())
weird_substraction(a, b)