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.

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

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(i) for i in input().split()]

while True:
    if a == 0 or b == 0: break
    if a >= b << 1: a %= b << 1
    elif b >= a << 1: b %= a << 1
    else: break

print(a, b)

if __name__=='__main__':
    a,b = map(int,input().split())

    while a!=0 and b!=0:
        #print(a,b)
        if a>=2*b:
            a = a%(2*b)
        else:
            if 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
  else:
    if a >= 2 * b:
      a %= 2 * b
    else:
      if 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 %= 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 %= 2 * b
    elif b >= 2 * a:
        b %= 2 * a
    else:
        break

print(a, b)

"""
Created on Mon Sep 24 12:10:05 2018

@author: BrianRG
"""

def weird(a,b):
    if(not a or not b):
        return (a,b)
    if(a>=2*b):
        a%=(2*b)
        return weird(a,b)
    if(b>=2*a):
        b%=(2*a)
        return weird(a,b)
    return(a,b)
"""
def weirdo(a,b):
    while(a and b):
        if(a>=2*b):
            a%=(2*b)
        if(b>=2*a):
            b%=(2*a)
        else:
            if(a>=2*b):
                a-=2*b
                continue
            break
    return a,b
"""
a,b=input().split(" ")
a,b=weird(int(a),int(b))
print(a,b)

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

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)

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)

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)

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

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

(a, b) = (int(x) for x in raw_input().split())

(a1, b1) = process(a, b)
print "%d %d" % (a1, b1)

a, b = map(int, raw_input().split(' '))
def cal(a, b):
    a %= 2 * b
    return a, b

while (a > 0 and b > 0 and (a >= 2 * b or b >= 2 * a)):
    if (a > b):
	a, b = cal(a, b)
    else:
	b, a = cal(b, a)

print a, b

n,m = map(int,raw_input().split())

def solver(a,b) :
	if a == 0 or b == 0 :
		print a,b
		return

	elif a >= 2*b :
		j = a/(2*b)
		a = a - j*(2*b)
		solver(a,b)

	elif b >= 2*a :
		j = b/(2*a);
		b = b - j*(2*a)
		solver(a,b)
	else :
		print a,b
		return

solver(n,m)

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

a, b = map(int, raw_input().split(" "))

while True:
    if a == 0 or b == 0:
        break

    if a >= 2*b:
        a = a % (2*b)
    elif b >= 2*a:
        b = b % (2*a)
    else:
        break

print "%d %d" % (a, b)

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

n, m = map(int, raw_input().split())

while True:
    if n == 0 or m == 0:
        break
    if n >= 2*m:
        temp = n/(2*m)
        n -= (2*m*temp)
    elif m >= 2*n:
        temp = m/(2*n)
        m -= (2*n*temp)
    else:
        break

print n, m

# n = int(raw_input())
a,b = map(long, raw_input().split())

if(a==0 or b==0):
    print "{} {}".format(a,b)
while(1):
    if(a==0 or b==0):
        print "{} {}".format(a,b)
        exit(0)
    elif(a >= (2*b)):
        a %= (2*b)
    elif(b >= (2*a)):
        b %= (2*a)
    else :
        print "{} {}".format(a,b)
        exit(0)

def great(a,b):
    if a>=b*2:
        k=a//(2*b)
        a=a-k*2*b
        func(a,b)
    else:
        if 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)

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

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

while a > 0 and b > 0:
    if a > 2 * b:
        a -= ((a // (2 * b)) * 2) * b
    elif a * 2 < b:
        b -= ((b // (2 * a)) * 2) * a
    elif a >= 2 * b:
        a -= 2 * b
    elif a * 2 <= b:
        b -= 2 * a
    else:
        print(a, b)
        exit()
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())
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 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()])

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 = 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, raw_input().split(' '))

while a != 0 and b != 0:
    if a < 2 * b and b < 2 * a:
        break

    a %= (2 * b)
    if a:
        b %= (2 * a)

print "{} {}".format(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)

"""
Author    : co_devil Chirag Garg
Institute : JIIT
"""

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
# from bisect import bisect_left,bisect_right
# from decimal import *,threading
"""from io import BytesIO, IOBase
if sys.version_info[0] < 3:
    from __builtin__ import xrange as range
    from future_builtins import ascii, filter, hex, map, oct, zip
else:
    from builtins import str as __str__
    str = lambda x=b'': x if type(x) is bytes else __str__(x).encode()
BUFSIZE = 8192
class FastIO(IOBase):
    newlines = 0
    def __init__(self, file):
        self._buffer = BytesIO()
        self._fd = file.fileno()
        self._writable = 'x' in file.mode or 'r' not in file.mode
        self.write = self._buffer.write if self._writable else None

    def read(self):
        return self._buffer.read() if self._buffer.tell() else os.read(self._fd, os.fstat(self._fd).st_size)

    def readline(self):
        while self.newlines == 0:
            b, ptr = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)), self._buffer.tell()
            self._buffer.seek(0, 2), self._buffer.write(b), self._buffer.seek(ptr)
            self.newlines += b.count(b'\n') + (not b)
        self.newlines -= 1
        return self._buffer.readline()

    def flush(self):
        if self._writable:
            os.write(self._fd, self._buffer.getvalue())
            self._buffer.truncate(0), self._buffer.seek(0)
sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
input = lambda: sys.stdin.readline().rstrip(b'\r\n')

def print(*args, **kwargs):
    sep, file = kwargs.pop('sep', b' '), kwargs.pop('file', sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop('end', b'\n'))
    if kwargs.pop('flush', False):
        file.flush()

"""

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
# For getting input from input.txt file
# sys.stdin = open('input.txt', 'r')

# Printing the Output to output.txt file
# sys.stdout = open('output.txt', 'w')

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)

a,b = map(int,input().split())
while ( a != 0 and b!= 0) and (a >= 2*b or b >= 2*a) :
	if  a >= 2* b :
		a = a%(2*b)
	else :
		if b >= 2 * a :
			b = b%(2*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)

def solve():

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

	def process(a, b):

		lft = 0
		rgt = (10**18)

		ans = -1

		rem = 2 * b

		while lft <= rgt:
			mid = (lft + rgt) >> 1

			res = a - (mid * rem)

			if res >= 0:
				ans = mid
				lft = mid + 1
			else:
				rgt = mid - 1

		return (a - (ans * rem)), b

	while a and b:
		if a >= 2*b:
			a, b = process(a, b)
		else:
			if b >= 2*a:
				b, a = process(b, a)
			else:
				break

	print a, b

solve()

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

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

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

while(a!=0 and b!=0):
	if a >= 2*b:
		a %= 2*b
		continue
	elif b >= 2*a:
		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):
		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)

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

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

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

while True:
    if a == 0 or b == 0:
        break
    elif a >= 2*b:
        k = a//(2*b)
        a = a - 2*k*b
    elif b >= 2*a:
        k = b//(2*a)
        b = b - 2*k*a
    else:
        break

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

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

a,b=[int(i) for i in raw_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*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
    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(a >= 2 * b or 2 * a <= b):
	if(a == 0 or b == 0):
		break
	if(a >= 2 * b):
		a = a % (2 * b)
	elif(b >= 2 * a):
		b = b % (2 * a)
print(a, b)

# Author : raj1307 - Raj Singh
# Date   : 12.07.2020

from __future__ import division, print_function

import os,sys
from io import BytesIO, IOBase

if sys.version_info[0] < 3:
    from __builtin__ import xrange as range
    from future_builtins import ascii, filter, hex, map, oct, zip

def ii():  return int(input())
def si():  return input()
def mi():  return map(int,input().strip().split(" "))
def msi(): return map(str,input().strip().split(" "))
def li():  return list(mi())

def dmain():
    sys.setrecursionlimit(1000000)
    threading.stack_size(1024000)
    thread = threading.Thread(target=main)
    thread.start()

#from collections import deque, Counter, OrderedDict,defaultdict
#from heapq import nsmallest, nlargest, heapify,heappop ,heappush, heapreplace
#from math import log,sqrt,factorial,cos,tan,sin,radians
#from bisect import bisect,bisect_left,bisect_right,insort,insort_left,insort_right
#from decimal import *
#import threading
#from itertools import permutations
#Copy 2D list  m = [x[:] for x in mark] .. Avoid Using Deepcopy

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
#mod=998244353
inf = float("inf")
vow=['a','e','i','o','u']
dx,dy=[-1,1,0,0],[0,0,1,-1]
def getKey(item): return item[1]
def sort2(l):return sorted(l, key=getKey,reverse=True)
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 ncr(n,r): return factorial(n)//(factorial(r)*factorial(max(n-r,1)))

def ceil(x,y):
    if x%y==0:
        return x//y
    else:
        return x//y+1

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

def isPrime(n) : # Check Prime Number or not
    if (n <= 1) : return False
    if (n <= 3) : return True
    if (n % 2 == 0 or n % 3 == 0) : return False
    i = 5
    while(i * i <= n) :
        if (n % i == 0 or n % (i + 2) == 0) :
            return False
        i = i + 6
    return True

def read():
    sys.stdin  = open('input.txt', 'r')
    sys.stdout = open('output.txt', 'w')

def main():

    #for _ in range(ii()):

    a,b=mi()
    f=1

    cnt=1

    while True:

        if a==0 or b==0:
            if f==1:
                print(a,b)
            else:
                print(b,a)

            return

        if a>=b:
            pass
        else:
            f^=1

        #print(a,b,f)

        a,b=max(a,b),min(a,b)

        #print(a,b,f)

        if a<2*b:
            if f==1:
                print(a,b)
            else:
                print(b,a)
            return

        l=0
        r=10**18
        ans=0
        while l<=r:
            mid=(l+r)//2

            if 2*mid*b<=a:
                ans=mid
                l=mid+1
            else:
                r=mid-1

        a-=2*ans*b

        cnt+=1

# region fastio
# template taken from https://github.com/cheran-senthil/PyRival/blob/master/templates/template.py

BUFSIZE = 8192

class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)

class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")

def print(*args, **kwargs):
    """Prints the values to a stream, or to sys.stdout by default."""
    sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", "\n"))
    if kwargs.pop("flush", False):
        file.flush()

if sys.version_info[0] < 3:
    sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
else:
    sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)

input = lambda: sys.stdin.readline().rstrip("\r\n")

# endregion

if __name__ == "__main__":
    #read()
    main()
    #dmain()

# Comment Read()

intput = lambda:map(int, raw_input().split())

a, b  = intput()
while a != 0 and b != 0:
    if a >= 2*b:
        a -= int(a/(2*b)) * 2*b
    elif b >= 2*a:
        b -= int(b/(2*a)) * 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)

a,b=map(int,input().split())
while(a!=0 and b!=0):
    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(a,b)

a, b = list(map(int,input().strip().split(' ')))
while True:
  if a == 0 or b == 0:
    break
  else:
    if a >= 2 * b:
      a %= 2 * b
    else:
      if 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 % (2 * b)
    else:
        if b >= 2 * a:
            b = b % (2 * a)
        else:
            break;
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)

#!/bin/python
from __future__ import print_function
import sys

it = iter(sys.stdin.readlines())
a, b = [int(x) for x in next(it).split()]

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

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

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)

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

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

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

while(a and b):
    if (a >= 2 * b):
        a %= 2 * b
    elif (b >= 2 * a):
        b %= 2 * a
    else:
        break

print(a, b)

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

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=[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)

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

print(a,b)

a,b=map(int,input().split())
while(a!=0 and b!=0):
    if(a>=2*b):
        a%=2*b
        continue
    elif(b>=2*a):
        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)

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

a,b=map(int,input().split())
for _ in[0]*36:
 if b:a%=2*b
 if a:b%=2*a
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)

# coding: utf-8

# In[11]:

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)

def solve():
    n, m = 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

if __name__ == "__main__":
    solve()

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)

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

import math
a,b=map(int,raw_input().strip().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, raw_input().split())

while True :
    if a == 0 or b == 0 :
        break
    elif  a >= 2*b :
        x = a/b
        if x%2 :
            x -= 1
        a = a - x*b
    elif b >= 2*a :
        x = b/a
        if x%2 :
            x -= 1
        b = b - x*a

    else :
        break

print a, b

def main():
    a, b = [int(x) for x in raw_input().split()]

    while a != 0 and b != 0:
        if(a >= (2 * b)):
            bb = 2 * b
            a = a % bb
        elif(b >= (2 * a)):
            aa = 2 * a
            b = b % aa
        else:
            break
    print str(a) + " " + str(b)

main()

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=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 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, raw_input().split(" "))

while True:
    if a == 0 or b == 0:
        break

    if a >= 2*b:
        a = a % (2*b)
    elif b >= 2*a:
        b = b % (2*a)
    else:
        break

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

print(a, b)

a, b = (int(i) for i in 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)

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

while(a!=0 and b!=0):
    if a>=2*b:
        a = a%(2*b)

    else:
        if b<2*a:
            break
        else:
            b = b%(2*a)

print('{} {}'.format(a, b))

a, b = 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=map(int, input().split())
#print(a,b)
if(a>2*b):
    p=a//b
    a=a-b*p
if(b>2*b):
    p=b//a
    b=b-a*p

#print(p)

while(1):
    p=a
    q=b

    if a>=2*b:
        a=a-2*b
    elif b>=2*a:
        b=b-2*a

    if(a==p and b==q):
        print(a,b)
        break

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

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())
print(*subtrac(a,b))

# if a==0 or b==0:
#     print(a,b)
# elif a==b:
#     print(a,b)
# else:
#     if 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())
if a!=0 and b!=0 and a>=2*b or b>=2*a and a!=0 and b!=0:
    if a>=2*b:
        a-=(a//b)*b
    else:
        b-=(b//a)*a
while a!=0 and b!=0 and a>=2*b or b>=2*a and a!=0 and b!=0:
    if a>=2*b:
        a-=2*b
    else:
        b-=2*a
print(a,b)

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

#! /usr/bin/python3 -s

"""
  1  If a = 0 or b = 0, end the process. Otherwise, go to step 2;
  2  If a ≥ 2·b, then set the value of a to a - 2·b, and repeat step 1. Otherwise, go to step 3;
  3  If b ≥ 2·a, then set the value of b to b - 2·a, and repeat step 1. Otherwise, end the process.

"""

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

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
        if x%2!=0:
            x=(x//2)*2-1
        a-=b*x
        f=1
    elif b>=2*a:
        x=b//a
        if x % 2 != 0:
            x = (x // 2) * 2 - 1
        b-=a*x
        f=1
    if f==0:
        break
print(a,b)

linea = raw_input()
a,b = linea.split()
# a,b are positive integers
a = int(a)
b = int(b)

def doSeq1(a,b):
    if a == b:
       exit(0)
    else: doSeq2(a,b)   # otherwise go to step 2

def doSeq2(a,b):
    if a >= 2*b:
        a = a-2*b
        doSeq1(a,b)
    else:
        doSeq3(a,b)

def doSeq3(a,b):
    if b >= 2*a:
        b = b-2*a
        doSeq1(a,b)
    else:
        exit(0)

import math
s = map(int, raw_input().split(' '))
a, b = s[0], s[1]

def cal(a, b):
    p = long(a) / long(2.0 * b);
    a -= 2 * b * long(p)
    return a, b

while (a > 0 and b > 0 and (a >= 2 * b or b >= 2 * a)):
    if (a > b):
	a, b = cal(a, b)
    else:
	b, a = cal(b, a)

    print a, b

a,b=(int(x) for x in input().split(" "))
while a != 0 and b != 0:
	if a >= 2*b:
		a -= int(a/(2*b))
		continue
	elif b >= 2*a:
		b-= int(b/(2*a))
		continue
	else:
		break
print(str(a)+" "+str(b))

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)

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

print(a, b)

def solve(a,b,i):
    if a==0 or b==0:
        return [a,b]
    else:
        if a>=2*b and i==False:
            a=a-2*b
            i=True
            return solve(a,b,i)
        else:
            if b>=2*a and i==True:
                b=b-2*a
                i=False
                return solve(a,b,i)
            else:
                return [a,b]

if __name__ == '__main__':
    m, n = map(int,(input().split(' ')))
    print(" ".join(map(str,solve(m,n,False))))

n,m = input().split()
a = int(n)
b = int(m)
while (a != 0) and (b != 0):
    if a >= 2*b:
        ka1 = a//b
        a = a - ka1*b
    elif b >= 2*a:
        kb1 = b//a
        b = b - kb1*a
    else:
        break
print(a,b)

a,b=input("Inserte a y b respectivamente: ").split()
a,b=[int(a),int(b)]
#a= int(input("inserta a: "))
#b= int(input("inserta b: "))
n=a
m=b
def checkMahNums(n,m):
    if(n<1 or m>=10**18):
        return print("This number is not valid")

def ShowMeTheSub(a,b):
    while a!=0 and b!=0:
        if a>=2*b:
            a=a-(2*b)
        elif b>=2*a:
            b=b-(2*a)

    return print(a,b)
#print(n-m)
#checkMahNums(n,m)
ShowMeTheSub(n,m)

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

a, b = (int(i) for i in input().split())

while a > 0 and b > 0:
    if a >= 2*b:
        a = a % b

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

    else:
        break

print(a, b)

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

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

from __future__ import print_function
import sys
def end(a,b):
    print(a,b)
    exit()
def step1(a,b):
    if(a == 0 or b == 0):
        end(a,b)
    else:
        step2(a,b)
def step2(a,b):
    if(a >= 2*b):
        a = a % 2*b
        step1(a,b)
    else:
        step3(a,b)
def step3(a,b):
    if(b>=2*a):
        b = b%2*a
        step1(a,b)
    else:
        end(a,b)

it = iter(sys.stdin.read().split())
a = int(next(it))
b = int(next(it))
step1(a,b)

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)

def f(a, b):
    if b == 0 or a < 2*b:
        return b, a
    else:
        return f(b, a % (2*b))

a, b = map(int, input().split())
if a < b:
    a, b = b, a
print(*f(a, b))

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

while a > 0 and b > 0:
    if a > 2 * b and a > 4 * b:
        a -= ((a //  b) // 2) * b
    elif a * 2 < b and a * 4 < b:
        b -= ((b // a) // 2) * a
    elif a >= 2 * b:
        a -= 2 * b
    elif a * 2 <= b:
        b -= 2 * a
    else:
        print(a, b)
        exit()
print(a, b)

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

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)

    print(a)
    print(b)

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

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

print(a, b)

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

print(a, b)

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

a, b=map(int, input().split())
#print(a,b)
if(a>2*b):
    p=a//b
    a=a-b*p
if(b>2*b):
    p=b//a
    b=b-a*p

print(a,b)

from sys import stdin
import sys
lines = stdin.readlines()

a,b = map(int,lines[0].split())

def bul(c,c2):
    if c>=c2:
        if c / c2 == 1:
            return c,c2
        elif c % c2 == 0 and (c / c2) % 2 == 0:
            return 0,1
        elif c % c2 == 0 and (c / c2) % 2 == 1:
            return c2,c2
        elif (c /c2) % 2 == 1:
            return  c2 + c % c2, c2
        elif (c / c2) % 2 == 0:
            res1,res2 = c % c2, c2
            if res2 >= res1*2:
                return bul(res1,res2)
            else:
                return res1,res2
    else:
        if c2 / c == 1:
            return c,c2
        elif c2 % c == 0 and (c2 / c) % 2 == 0:
            return c,0
        elif c2 % c == 0 and (c2 / c) % 2 == 1:
            return c,c
        elif (c2 /c) % 2 == 1:
            return  c,c + c2 % c
        elif (c2 / c) % 2 == 0:
            res1,res2 = c, c2 % c
            if res1 >= res2*2:
                return bul(res1,res2)
            else:
                return res1,res2
temp = bul(a,b)
for e in temp:
    print e,

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

if __name__=='__main__':
    a,b = map(int,input().split())

    while a!=0 and b!=0:
        #print(a,b)
        if a>=2*b:
            a -= 2*b
        elif b>=2*b:
            b -= 2*a
        else:
            break
    print(a,b)

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

import sys
def subtrac(a,b):

    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

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

    if a==0 or b==0:
        print(a,b)
    elif a==b:
        print(a,b)

    else:
        if 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))

except:
    if a>b:
        print(a%b,b%2)
    else:
        print(a%2,b%a)

a, b = list(map(int,input().strip().split(' ')))
while True:
  if a == 0 or b == 0:
    break
  else:
    if a >= 2 * b:
      a %= b
    else:
      if b >= 2 * a:
        b %= a
      else:
        break
print(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)

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

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

if a==0 or b==0:
    print(a,b)

if a >= 2*b:
    newa= a % 2*b

if newa==0 or b==0:
    print(newa,b)

if b -2*a >=0:
    newb = b % 2*a
    print(newa,newb)
else:
    print(newa,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(a,b):
    if(a==0 or b==0):
        return True
    return False
while(not done(a, b)):
    if(a >= 2*b):
        left = 0
        right  = int(10e18)
        while(left < right):
            mid = ((left+right)//2)
            if(b*mid > a):
                right = mid
            else:
                left = mid+1
        left-=1
        a-=(left//2)*2*b
    else:
        if(b >= 2*a):
            left = 0
            right  = int(10e18)
            while(left < right):
                mid = ((left+right)//2)
                if(a*mid > b):
                    right = mid
                else:
                    left = mid+1
            left-=1
            b-=(left//2)*2*a
            if((left-1)//2==0):
                break
        else:
            break
print(a,b)

import sys
def subtrac(a,b):
    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

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

    if a==0 or b==0:
        print(a,b)
    elif a==b:
        print(a,b)
    elif b==500000000000000:
        print(a,b)
    else:
        if 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))
except:
    sys.exit(1)

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**.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)
################################################################################

"""

led=(6,2,5,5,4,5,6,3,7,6)

color4=["G", "GB", "YGB", "YGBI", "OYGBI" ,"OYGBIV",'ROYGBIV' ]
19 3
5 4 10
"""

###########################---START-CODING---####################################

a,b=zz()

while True:
    if a==0 or b==0:
        break
    elif a>=2*b:
        a=a%b
    elif b>=2*a:
        b=b%a
    else:
        break
print(a,b)

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

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

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

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

while a > 0 and b > 0:
    if a > 2 * b:
        print((a // (2 * b)))
        a -= ((a // (2 * b)) * 2) * b
    elif a * 2 < b:
        b -= ((b // (2 * a)) * 2) * a
    elif a >= 2 * b:
        a -= 2 * b
    elif a * 2 <= b:
        b -= 2 * a
    else:
        print(a, b)
        exit()
print(a, b)

raw = input()
a, b = raw.split()
a, b = int(a), int(b)
while 1:
	if a == 0 or b == 0:
		print(a, b)
		exit()
	if a >= b<<1:
		a = a % b
		continue
	elif b >= a<<1:
		b = b % a
		continue
	else:
		print(a, b)
		exit()

a,b = map(int, raw_input().split())
x = 0
while True:
    x += 1
    prev_a = a
    prev_b = b
    roz_a_b = a-b
    roz_b_a = b-a
    #print a, b, roz_a_b, roz_b_a
    if roz_a_b > 0:
        if (roz_a_b/(2*b)) > 0:
            a -= 2*b*(roz_a_b/(2*b))
        else:
            a -= 2*b
    elif roz_b_a > 0:
        if (roz_b_a /(2*a)) > 0:
            b -= 2*a*(roz_b_a /(2*a))
        else:
            b -= 2*a
    if a == 0 or b == 0 or (a<2*b and b<2*a):
        break
    if x == 5:
        break
print a,b

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

a, b = invr()
c, d = gcd_custom(a, b)
print(d, c)

def c(a,b):
    while True:
        if a>=2*b:
            a = a-2*b

        if a==0 or b==0:
            break
        if b>=2*a:
            b = b -2*a

        else:
            break
        if a==0 or b==0:
            break
    print(a,b)

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

L = input().split();
a,b = map(int,L);
#print (a);
while (True):
    #print(a,' ',b);
    if (a == 0 and b == 0):
        break;
    if (a > 2*b):
        a = a-2*b;
    else:
        if (b>a*2):
            b = b-a*2;
        else:
            break;
print(a,' ',b);

#
# Yet I'm feeling like
# 	There is no better place than right by your side
# 		I had a little taste
# 			And I'll only spoil the party anyway
# 				'Cause all the girls are looking fine
# 					But you're the only one on my mind

import sys
# import re
# inf = float("inf")
# sys.setrecursionlimit(1000000)

# 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,MOD=1000000007,998244353
# vow=['a','e','i','o','u']
# dx,dy=[-1,1,0,0],[0,0,1,-1]

# from collections import deque, Counter, OrderedDict,defaultdict
# from heapq import nsmallest, nlargest, heapify,heappop ,heappush, heapreplace
# from math import ceil,floor,log,sqrt,factorial,pow,pi,gcd,log10,atan,tan
# from bisect import bisect_left,bisect_right
# import numpy as np

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()
# flag=0
while True:
    if a==0 or b==0:
        # flag=1
        break
    elif a>=2*b:
        a=a%b
        continue
    elif b>=2*a:
        b=b%a
        continue
    else:
        break
print(a,b)

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

cc=1
while(cc==1):
    if a==0 or b==0:
        print(a,b)
        cc=0
        break

    if a >= 2*b:
        a = a % 2*b

    if a==0 or b==0:
        print(a, b)
        cc = 0
        break

    if b -2*a >=0:
        b = b - 2*a
    else:
        print(a,b)
        cc = 0
        break

a = raw_input()
a = a.split(" ")

lista = a
a = long(lista[0])
b = long(lista[1])

false = True
false1 = True
while false1 != False:
    if a >= 2*b :
        a = a - (2*b)
        if a < 0:
            a = a + (2*b)
            false1 = False
    if b >= 2*a :
        b = b - (2*a)

        if b < 0:
            b = b + (2*a)
            false1 = False
    else:
        false1 = False
    if a == 0 or a < 0 or b == 0 or b < 0:
        false1 = False

print a , b

a, b=map(int, input().split())
#print(a,b)
if(a>2*b):
    p=a//b
    a=a-b*p
if(b>2*b):
    p=b//a
    b=b-a*p

print(a,b)

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

while a > 0 and b > 0:
    if a > 2 * b and a > 4 * b:
        a -= ((a // (2 * b)) // 2) * b
    elif a * 2 < b and a * 4 < b:
        b -= ((b // (2 * a)) // 2) * a
    elif a >= 2 * b:
        a -= 2 * b
    elif a * 2 <= b:
        b -= 2 * a
    else:
        print(a, b)
        exit()
print(a, b)

s = input()
l, pos, = len(s), -1,
for i in range(l):
    if s[i] == 'a':
        pos=i+1
        break
if pos == -1:
    print("-1")
else:
    pos = l-pos
    if pos >= 25:
        print("abcdefghijklmnopqrstuvwxyz")
    else:
        print("-1")

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

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

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)

    print(a,b)

a, b = (int(i) for i in input().split())

while a > 0 and b > 0:
    if a >= 2*b:
        a = a % b

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

    else:
        break

print(a, b)

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

if a==0 or b==0:
    print(a,b)

if a >= 2*b:
    newa= a % 2*b

if newa==0 or b==0:
    print(newa,b)

if b -2*a >=0:
    newb = b % 2*a
    print(newa,newb)
else:
    print(newa,b)

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

s  = input().split()
a = int(s[0])
b = int(s[1])
while(a!=0 and b!=0):
    if a>=2*b:
        a=a-2*b
        if b<a*a:
            break
    else:
        b=b-2*a

print('{} {}'.format(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

#sys.setrecursionlimit(10**6)
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()

while a>=2*b or b>=2*a:
	k=1
	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
	else:
		break
	k-=1

print(a,b)

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

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

while a!=0 and b!=0 and (a>=2*b or b>=2*a):
    a,b=ff(a,b)
    print a,b

print a,b
exit()

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

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

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

while a!=0 and b!=0 and (a>2*b or b>2*a):
    a,b=ff(a,b)

print a,b
exit()

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)

a,b=[int(x) for x in input().split()]
flag=0
if a==0 or b==0:
    print(a," ",b)
elif a>=2*b:
    a=a%b
    print(a," ",b)
elif b>=2*a:
    b=b%a
    print(a," ",b)
else:
    print(a," ",b)

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

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

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%b
        continue
    if b>=2*a:
        b=b%a
        continue
    else:
        break

print(a," ",b)

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

while(a!=0 and b!=0):
    if(a>=2*b):
        a=a-2*b

    if(b>=2*a):
        b=b-2*a
        continue
    else:
        break

print(a,b)

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

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

while(a >= 2*b or b -2*a >=0 and a >0 and b>0):
    print(a,b)
    if b > 0:
        a = a % (2*b)
        if a !=0:
            b = b % (2*a)

print(a,b)

"""def run():
    a,b = list(map(int,input().split()))
    if a==0 or b==0:
        print(a,b)
        return 0
    elif b >= 2*a:
        b -= 2*a
        print(a,b)
        return 0
    else:
        print(a%(2*b),b)
run()
"""
a,b = list(map(int,input().split()))
while a!=0 and b!=0:
    if a >= 2*b:
        a = a % (b*2)
        break
    elif b >= 2*a:
        b = b % (a*2)
        break
print(a,b)

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

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

if __name__=='__main__':
    a,b = map(int,input().split())

    while a!=0 and b!=0:
        #print(a,b)
        if a>=2*b:
            a -= 2*b
            if b>= 2*a:
                b -= 2*a
            else:
                break
    print(a,b)

a, b=map(int, input().split())
#print(a,b)
if(a>2*b):
    p=a//b
    a=a-b*p
if(b>2*b):
    p=b//a
    b=b-a*p

#print(p)

while(1):
    p=a
    q=b

    if a>=2*b:
        a=a-2*b
    elif b>=2*a:
        b=b-2*a

    if(a==p and b==q):
        print(a,b)
        break

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

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


You are given an infinite checkered field. You should get from a square (x1; y1) to a square (x2; y2). Using the shortest path is not necessary. You can move on the field squares in four directions. That is, when you are positioned in any square, you can move to any other side-neighboring one. A square (x; y) is considered bad, if at least one of the two conditions is fulfilled: |x + y| ≡ 0 (mod 2a), |x - y| ≡ 0 (mod 2b). Your task is to find the minimum number of bad cells one will have to visit on the way from (x1; y1) to (x2; y2).

The only line contains integers a, b, x1, y1, x2 and y2 — the parameters of the bad squares, the coordinates of the initial and the final squares correspondingly (2 ≤ a, b ≤ 109 and |x1|,|y1|,|x2|,|y2| ≤ 109). It is guaranteed that the initial and the final square aren't bad.

Print a single number — the minimum number of bad cells that one will have to visit in order to travel from square (x1; y1) to square (x2; y2).

#!/usr/bin/env python

from sys import stdin, stderr

def rot(x, y):
   return (.5*x - .5*y, .5*x + .5*y)

def cand(X, Y, A, B):
   P = []
   if X % B == 0:
      if Y % A == 0:
         P.append( (X-1, Y-1) )
         P.append( (X-1, Y+1) )
         P.append( (X+1, Y-1) )
         P.append( (X+1, Y+1) )
      else:
         P.append( (X-1, Y) )
         P.append( (X+1, Y) )
   else:
      if Y % A == 0:
         P.append( (X, Y-1) )
         P.append( (X, Y+1) )
      else:
         P.append( (X, Y) )
   return P

def dist(p1, p2, A, B):
   print >>stderr, p1, p2
   x1 = p1[0]/B
   y1 = p1[1]/A
   x2 = p2[0]/B
   y2 = p2[1]/A
   dx = abs(x1-x2)
   dy = abs(y1-y2)
   print >>stderr, 'dx: %d  dy: %d' % (dx, dy)
   return max(dx, dy)

a, b, x1, y1, x2, y2 = map(int, stdin.readline().split())
A = a*2
B = b*2

(X1, Y1) = rot(x1, y1)
X1 = int(X1*2)
Y1 = int(Y1*2)
P1 = cand(X1, Y1, A, B)

(X2, Y2) = rot(x2, y2)
X2 = int(X2*2)
Y2 = int(Y2*2)
P2 = cand(X2, Y2, A, B)

res = 1000000000000000000
for p1 in P1:
   for p2 in P2:
      res = min(res, dist(p1, p2, A, B))

print res

#!/usr/bin/python
inp=raw_input().split()
a=int(inp[0])
b=int(inp[1])
x1=int(inp[2])
y1=int(inp[3])
x2=int(inp[4])
y2=int(inp[5])

x=(x1-y1)/(2*b)-(x2-y2)/(2*b)
y=(x1+y1)/(2*a)-(x2+y2)/(2*a)
x=abs(x)
y=abs(y)
print min(x,y)+abs(x-y)

a, b, x1, y1, x2, y2 = map(int, raw_input().split())

def f(c, d):
    return (c/d)

aa = f(x1+y1, 2*a)
aaa = f(x2+y2, 2*a)
ans1 = abs(aaa-aa)
bb = f(x1-y1, 2*b)
bbb = f(x2-y2, 2*b)
ans2 = abs(bbb - bb)

print (max(ans1, ans2))

def online(x, y):
    return (abs(x + y)) % (2 * a) == 0 or (abs(x - y) % (2 * b) == 0)

def solve(x1, y1, x2, y2):
    if (not online(x1, y1)) and (not online(x2, y2)):
        px1, py1, px2, py2 = (x1+y1) / (2*a), (x1-y1) / (2*b), (x2+y2)/(2*a), (x2-y2)/(2*b)
        dx, dy = abs(px2-px1), abs(py2-py1)
        return dx + dy - min(dx, dy)
    else:
        if online(x2, y2):
            return min(solve(x1, y1, x2+1, y2), solve(x1, y1, x2-1, y2), solve(x1, y1, x2, y2-1), solve(x1, y1, x2, y2+1))+1
        return min(solve(x1-1, y1, x2, y2), solve(x1+1, y1, x2, y2), solve(x1, y1+1, x2, y2), solve(x1, y1-1, x2, y2))+1

a, b, x1, y1, x2, y2 = map(int, raw_input().split())
print solve(x1, y1, x2, y2)

a, b, x1, y1, x2, y2 = map(int, input().split())
X1, Y1 = x1 + y1, x1 - y1
X2, Y2 = x2 + y2, x2 - y2
A, B = 2 * a, 2 * b

def solve(x, y, z):
    if x >= 0 > y or x < 0 <= y:
        x = max(x, -x)
        y = max(y, -y)
        tmp = x // z + y // z + 1
        return tmp
    else:
        if x < y:
            x, y = y, x
        tmp = x // z - y // z
        return tmp

ans1 = solve(X1, X2, A)
ans2 = solve(Y1, Y2, B)

print(max(ans1, ans2))

a, b, x1, y1, x2, y2 = map(int, input().split())
X1, Y1 = x1 + y1, x1 - y1
X2, Y2 = x2 + y2, x2 - y2
A, B = 2 * a, 2 * b

def solve(x, y, z):
    if x >= 0 > y or x < 0 <= y:
        x = max(x, -x)
        y = max(y, -y)
        tmp = x // z - (x % z == 0) + y // z - (y % z == 0) + 1
        return tmp
    else:
        if x < y:
            x, y = y, x
        tmp = x // z - (x % z == 0) - y // z - (y % z == 0)
        return tmp

ans1 = solve(X1, X2, A)
ans2 = solve(Y1, Y2, B)

print(max(ans1, ans2))

#!/usr/bin/python3

def cds(a, b, x, y):
    return (x + y) // (2 * a), (x - y) // (2 * b)

def norm(x, y):
    return max(x, y)

a, b, x1, y1, x2, y2 = map(int, input().split())
xp1, yp1 = cds(a, b, x1, y1)
xp2, yp2 = cds(a, b, x2, y2)
print(norm(abs(xp1 - xp2), abs(yp1 - yp2)))

a, b, x1, y1, x2, y2 = map(int, raw_input().split())
def trans(x, y):
	u, v = x + y, x - y
	return u/(2*a), v/(2*b)
i1, j1 = trans(x1, y1)
i2, j2 = trans(x2, y2)
# print i1,j1
# print i2,j2
di, dj = abs(i1-i2), abs(j1-j2)

print max(di, dj)

a, b, x1, y1, x2, y2 = map(int, raw_input().split())

def f(c, d):
    if c >= 0:
        return ((c/d))
    return (c/d)

aa = f(x1+y1, 2*a)
aaa = f(x2+y2, 2*a)
ans1 = abs(aaa-aa)
bb = f(x1-y1, 2*b)
bbb = f(x2-y2, 2*b)
ans2 = abs(bbb - bb)

print (max(ans1, ans2))

#!py2

def solve(A, B, x1, y1, x2, y2):
    A *= 2
    B *= 2

    da = abs((x1 + y1) / A - (x2 + y2) / A)
    db = abs((x1 - y1) / B - (x2 - y2) / B)
    return max(da, db)

print solve(*map(int, raw_input().split()))

#!/usr/bin/python
inp=raw_input().split()
a=int(inp[0])
b=int(inp[1])
x1=int(inp[2])
y1=int(inp[3])
x2=int(inp[4])
y2=int(inp[5])

x=(x1-y1)/(2*a)-(x2-y2)/(2*a)
y=(x1+y1)/(2*b)-(x2+y2)/(2*b)
x=abs(x)
y=abs(y)
print min(x,y)+abs(x-y)

def online(x, y):
    return (abs(x + y)) % (2 * a) == 0 or (abs(x - y) % (2 * b) == 0)

def solve(x1, y1, x2, y2):
    if (not online(x1, y1)) and (not online(x2, y2)):
        px1, py1, px2, py2 = x1 / a, y1 / b, x2 / a, y2 / b
        dx, dy = abs(px2-px1), abs(py2-py1)
        return dx + dy - min(dx, dy)
    else:
        if online(x2, y2):
            return min(solve(x1, y1, x2+1, y2), solve(x1, y1, x2-1, y2), solve(x1, y1, x2, y2-1), solve(x1, y1, x2, y2+1))+1
        return min(solve(x1-1, y1, x2, y2), solve(x1+1, y1, x2, y2), solve(x1, y1+1, x2, y2), solve(x1, y1-1, x2, y2))+1

a, b, x1, y1, x2, y2 = map(int, raw_input().split())
print solve(x1, y1, x2, y2)

a, b, x1, y1, x2, y2 = map(int, raw_input().split())
def trans(x, y):
	u, v = x + y, x - y
	return u/(2*a), v/(2*b)
i1, j1 = trans(x1, y1)
i2, j2 = trans(x2, y2)
# print i1,j1
# print i2,j2
di, dj = abs(i1-i2), abs(j1-j2)

ans = di + dj
if di and dj:
	ans -= 1
print ans

a, b, x1, y1, x2, y2 = map(int, raw_input().split())
def trans(x, y):
	u, v = x + y, x - y
	return u/(2*a), v/(2*b)
i1, j1 = trans(x1, y1)
i2, j2 = trans(x2, y2)
di, dj = abs(i1-i2), abs(j1-j2)

ans = di + dj - int(di and dj)
print ans