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.

Difficulty: interview

Starter code:

Solutions:
a, b = [int(v) for v 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=list(map(int,input().split()))
while a>0 and b>0:
  if a>=b+b:a%=b+b
  elif b>=a+a:b%=a+a
  else: break
print(a,b)


a, b = list(map(int, input().split()))
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)


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

while 1:
    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)

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 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])


a, b = input().split()
a, b = int(a), 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:
		break
print(a, b)

a, b = list(map(int, input().split()))
while True:
    if a == 0 or b == 0:
        break
    elif a >= 2 * b:
        a -= 2 * b * (a // (2 * b))
    elif b >= 2 * a:
        b -= 2 * a * (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 = list(map(int,input().split(" ")))

while True:
	if a == 0 or b == 0:
		print(str(a) + " " + str(b))
		return

	elif a >= 2 * b:
		a = a % (2 * b)

	elif b >= 2 * a:
		b = b % (2 * a)

	else:
		print(str(a) + " " + str(b))
		return


#n = int(input())
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 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)

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:
        a %= 2 * b
    elif b >= 2 * a:
        b %= 2 * a
    else:
        break
print(a, b)

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

while (n != 0 and m != 0) or (n >= 2 * m) or (m >= 2 * n):
    if n == 0:
        break
    elif 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= (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)



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])


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])


#!/usr/bin/env python3

import sys

[a, b] = list(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)


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)



a, b = 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)

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)
            
    


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()