You are given a rectangular grid of lattice points from (0, 0) to (n, m) inclusive. You have to choose exactly 4 different points to build a polyline possibly with self-intersections and self-touching. This polyline should be as long as possible.

A polyline defined by points p_1, p_2, p_3, p_4 consists of the line segments p_1 p_2, p_2 p_3, p_3 p_4, and its length is the sum of the lengths of the individual line segments.


-----Input-----

The only line of the input contains two integers n and m (0 ≤ n, m ≤ 1000). It is guaranteed that grid contains at least 4 different points.


-----Output-----

Print 4 lines with two integers per line separated by space — coordinates of points p_1, p_2, p_3, p_4 in order which represent the longest possible polyline.

Judge program compares your answer and jury's answer with 10^{ - 6} precision.


-----Examples-----
Input
1 1

Output
1 1
0 0
1 0
0 1

Input
0 10

Output
0 1
0 10
0 0
0 9

Difficulty: interview

Starter code:

Solutions:
import math
n, m = list(map(int, input().split()))
if n == 0 : 
    print(0, 1)
    print(0, m)
    print(0, 0)
    print(0, m - 1)
elif m == 0 : 
    print(1, 0)
    print(n, 0)
    print(0, 0)
    print(n - 1, 0)
else :
    l = math.sqrt((n - 1) ** 2 + m ** 2) + math.sqrt(n ** 2 + m ** 2) + math.sqrt(n ** 2 + (m - 1) ** 2)
    l1 = max(m, n) + math.sqrt(n * n + m * m) * 2
    l2 = math.sqrt(n ** 2 + m ** 2) + math.sqrt((n - 1) ** 2 + m ** 2) * 2
    l3 = math.sqrt(n ** 2 + m ** 2) + math.sqrt((m - 1) ** 2 + n ** 2) * 2
    ans = max(l, l1, l2, l3)
    if l == ans :
        print(1, 0)
        print(n, m)
        print(0, 0)
        print(n, m - 1)
    elif l1 == ans :
        if n > m :
            print(n, m)
            print(0, 0)
            print(n, 0)
            print(0, m)
        else :
            print(n, m)
            print(0, 0)
            print(0, m)
            print(n, 0)
    elif l2 == ans :
        print(1, 0)
        print(n, m)
        print(0, 0)
        print(n - 1, m)
    else :
        print(0, 1)
        print(n, m)
        print(0, 0)
        print(n, m - 1)


def dist(x1, y1, x2, y2):
    return ((x1 - x2) ** 2 + (y1 - y2) ** 2) ** 0.5

def ddist(a):
    res = 0.0
    for i in range(3):
        res += dist(a[i][0], a[i][1], a[i + 1][0], a[i + 1][1])
    return res;

n, m = list(map(int, input().split()))
if (n == 0):
    print("0 1")
    print("0", m)
    print(0, 0)
    print(0, m - 1)
elif (m == 0):
    print(1, 0)
    print(n, 0)
    print(0, 0)
    print(n - 1, 0)
else:
    aa = [[[n - 1, m], [0, 0], [n, m], [1, 0]], [[0, 1], [n, m], [0, 0], [n, m - 1]], [[0, 0], [n, m], [0, m], [n, 0]], [[n, m], [0, 0], [0, m], [n, 0]]]
    a = max(aa, key = ddist)
    for i in a:
        print(i[0], i[1])
    


n, m = list(map(int, input().split()))
a = ([[0, 1], [0, m], [0, 0], [0, m - 1]], [[1, 0], [n, 0], [0, 0], [n - 1, 0]], \
     [[0, 1], [n, m], [0, 0], [n, m - 1]], [[1, 0], [n, m], [0, 0], [n - 1, m]], \
     [[0, 0], [n, m], [0, m], [n, 0]], [[0, 0], [n, m], [n, 0], [0, m]])
for x in max(a, key = lambda a: (len(set(map(tuple, a))) == len(a)) * all(map((lambda x: min(x[1], x[0]) >= 0), a)) * sum(((a[i][0] - a[i + 1][0]) ** 2 + (a[i][1] - a[i + 1][1]) ** 2) ** 0.5 for i in range(len(a) - 1))):
    print(*x)
print()


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

swapped = False
if n > m:
    n, m = m, n
    swapped = True

def mprint(x, y):
    nonlocal swapped
    if swapped:
        print(y, x)
    else:
        print(x, y)

def mlen(pnt):
    res = 0.0
    for i in range(1, 4):
        val = (pnt[i][0] - pnt[i - 1][0]) ** 2
        val += (pnt[i][1] - pnt[i - 1][1]) ** 2
        val = math.sqrt(val)
        res += val
    return res

if n == 0:
    mprint(0, 1)
    mprint(0, m)
    mprint(0, 0)
    mprint(0, m - 1)
else:
    one = [(0, 0), (n, m), (n, 0), (0, m)]
    two = [(1, 0), (n, m), (0, 0), (n - 1, m)]
    if mlen(one) > mlen(two):
        two = one
    for x in two:
        mprint(*x)


def dist(v):
    ans = 0
    for i in range(4):
        for j in range(4):
            if i != j and v[i] == v[j]:
                return 0
    for i in range(3):
        ans += (v[i][0] - v[i + 1][0]) ** 2 + (v[i][1] - v[i + 1][1]) ** 2
    return ans
now = [0] * 4

n, m = list(map(int, input().split()))
best = 0
if n == 0:
    print(0, 1)
    print(0, m)
    print(0, 0)
    print(0, m - 1)
elif m == 0:
    print(1, 0)
    print(n, 0)
    print(0, 0)
    print(n - 1, 0)
else:
    v = [[(0, 0), (n, m), (0, m), (n, 0)],
         [(0, 0), (n, m), (n, 0), (0, m)],
         
         [(0, 0), (n, m), (0, 1), (n, m - 1)],
         [(0, 0), (n, m), (1, 0), (n - 1, m)],
         [(0, 0), (n, m), (0, 1), (n - 1, m)],
         [(0, 0), (n, m), (1, 0), (n, m - 1)],

         [(0, 1), (n, m), (0, 0), (n, m - 1)],
         [(1, 0), (n, m), (0, 0), (n - 1, m)],
         [(0, 1), (n, m), (0, 0), (n - 1, m)],
         [(1, 0), (n, m), (0, 0), (n, m - 1)],

         [(0, 1), (n, m - 1), (0, 0), (n, m)],
         [(1, 0), (n - 1, m), (0, 0), (n, m)],
         [(0, 1), (n - 1, m), (0, 0), (n, m)],
         [(1, 0), (n, m - 1), (0, 0), (n, m)],

         [(0, 1), (n, m - 1), (1, 0), (n, m)],
         [(1, 0), (n - 1, m), (0, 1), (n, m)],
         [(0, 1), (n - 1, m), (1, 0), (n, m)],
         [(1, 0), (n, m - 1), (0, 1), (n, m)],

         [(0, 1), (n, m - 1), (1, 0), (n - 1, m)],
         [(1, 0), (n - 1, m), (0, 1), (n, m - 1)],
         [(0, 1), (n - 1, m), (1, 0), (n, m - 1)],
         [(1, 0), (n, m - 1), (0, 1), (n - 1, m)],

         
         [(0, 0), (n, m - 1), (0, 1), (n, m)],
         [(0, 0), (n - 1, m), (1, 0), (n, m)],
         [(0, 0), (n - 1, m), (0, 1), (n, m)],
         [(0, 0), (n, m - 1), (1, 0), (n, m)]]
    for i in range(len(v)):
        now = dist(v[i])
        if now > best:
            best = now
            ans = i
    for i in range(4):
        print(v[ans][i][0], v[ans][i][1])
         


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


if(m==0):
    print(1,0)
    print(n,0)
    print(0,0)
    print(n-1,0)
elif(n==0):
    print(0,1)
    print(0,m)
    print(0,0)
    print(0,m-1)
elif(n==1 and m==1):
    print(1,1)
    print(0,0)
    print(1,0)
    print(0,1)
elif(n==1):
    print(0,0)
    print(1,m)
    print(1,0)
    print(0,m)
elif(m==1):
    print(0,0)
    print(n,1)
    print(0,1)
    print(n,0)
else:
    
    if(n<m):
        a=pow(n**2+m**2,1/2)*2+max(n,m)
        b=pow((n-1)**2+m**2,1/2)*2+pow(m**2+n**2,1/2)
        if(b>a):
            print(1,0)
            print(n,m)
            print(0,0)
            print(n-1,m)
        else:
            print(0,0)
            print(n,m)
            print(n,0)
            print(0,m)
    else:
        a=pow(n**2+m**2,1/2)*2+max(n,m)
        b=pow((m-1)**2+n**2,1/2)*2+pow(m**2+n**2,1/2)
        if(b>a):
            print(0,1)
            print(n,m)
            print(0,0)
            print(n,m-1)
        else:
            print(0,0)
            print(n,m)
            print(0,m)
            print(n,0)


from math import *

def d(p1x,p1y,p2x,p2y,p3x,p3y,p4x,p4y):
	if len(set([(p1x,p1y),(p2x,p2y),(p3x,p3y),(p4x,p4y)])) != 4:
		return (0,0)
	dis = sqrt((p2x-p1x)*(p2x-p1x) + (p2y-p1y)*(p2y-p1y)) + \
		sqrt((p3x-p2x)*(p3x-p2x) + (p3y-p2y)*(p3y-p2y)) + \
		sqrt((p4x-p3x)*(p4x-p3x) + (p4y-p3y)*(p4y-p3y))
	return (dis,(p1x,p1y,p2x,p2y,p3x,p3y,p4x,p4y))

def bf():
	l = []
	for p1x in range(0,n+1):
		for p1y in range(0,m+1):
			for p2x in range(0,n+1):
				for p2y in range(0,m+1):
					for p3x in range(0,n+1):
						for p3y in range(0,m+1):
							for p4x in range(0,n+1):
								for p4y in range(0,m+1):
									if len(set([(p1x,p1y),(p2x,p2y),(p3x,p3y),(p4x,p4y)])) == 4:
										l.append(d(p1x,p1y,p2x,p2y,p3x,p3y,p4x,p4y))

	print(list(reversed(sorted(l)))[0])

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

#bf()

if m==0:
	print("%d %d\n%d %d\n%d %d\n%d %d\n"%(1,0,n,m,0,0,n-1,m))
elif n==0:
	print("%d %d\n%d %d\n%d %d\n%d %d\n"%(0,1,n,m,0,0,n,m-1))
else:
	l = []
	l.append(d(n-1,m,0,0,n,m,0,1))
	l.append(d(n,m-1,0,0,n,m,1,0))
	l.append(d(1,0,n,m,0,0,n-1,m))
	l.append(d(0,1,n,m,0,0,n,m-1))
	l.append(d(0,0,n,m,0,1,n-1,m))
	l.append(d(0,0,n,m,1,0,n,m-1))
	l.append(d(0,0,n,m,n,0,0,m))
	l.append(d(0,0,n,m,0,m,n,0))
	
	a = list(reversed(sorted(l)))[0]
	#print(a)
	a = a[1]
	for i in range(4):
		print(a[i*2],a[i*2+1])



def dist(v):
    ans = 0
    if (v[1] == v[2]):
        return 0
    for i in range(3):
        ans += (v[i][0] - v[i + 1][0]) ** 2 + (v[i][1] - v[i + 1][1]) ** 2
    return ans
now = [0] * 4

n, m = map(int, input().split())
best = 0
if n == 0:
    print(0, 1)
    print(0, m)
    print(0, 0)
    print(0, m - 1)
elif m == 0:
    print(1, 0)
    print(n, 0)
    print(0, 0)
    print(n - 1, 0)
else:
    v = [[(0, 0), (n, m), (0, m), (n, 0)],
         [(0, 0), (n, m), (n, 0), (0, m)],
         
         [(0, 0), (n, m), (0, 1), (n, m - 1)],
         [(0, 0), (n, m), (1, 0), (n - 1, m)],
         [(0, 0), (n, m), (0, 1), (n - 1, m)],
         [(0, 0), (n, m), (1, 0), (n, m - 1)],

         [(0, 1), (n, m), (0, 0), (n, m - 1)],
         [(1, 0), (n, m), (0, 0), (n - 1, m)],
         [(0, 1), (n, m), (0, 0), (n - 1, m)],
         [(1, 0), (n, m), (0, 0), (n, m - 1)],

         [(0, 1), (n, m - 1), (0, 0), (n, m)],
         [(1, 0), (n - 1, m), (0, 0), (n, m)],
         [(0, 1), (n - 1, m), (0, 0), (n, m)],
         [(1, 0), (n, m - 1), (0, 0), (n, m)],

         [(0, 1), (n, m - 1), (1, 0), (n, m)],
         [(1, 0), (n - 1, m), (0, 1), (n, m)],
         [(0, 1), (n - 1, m), (1, 0), (n, m)],
         [(1, 0), (n, m - 1), (0, 1), (n, m)],

         [(0, 1), (n, m - 1), (1, 0), (n - 1, m)],
         [(1, 0), (n - 1, m), (0, 1), (n, m - 1)],
         [(0, 1), (n - 1, m), (1, 0), (n, m - 1)],
         [(1, 0), (n, m - 1), (0, 1), (n - 1, m)],

         
         [(0, 0), (n, m - 1), (0, 1), (n, m)],
         [(0, 0), (n - 1, m), (1, 0), (n, m)],
         [(0, 0), (n - 1, m), (0, 1), (n, m)],
         [(0, 0), (n, m - 1), (1, 0), (n, m)]]
    for i in range(len(v)):
        now = dist(v[i])
        if now > best:
            best = now
            ans = i
    for i in range(4):
        print(v[ans][i][0], v[ans][i][1])

import math

def __starting_point():
    (x,y) = (int(a) for a in input().split(' '))
    ans = []
    if x == 0:
##        print('Enters 1')
        ans.append((0,1))
        ans.append((0,y))
        ans.append((0,0))
        ans.append((0,y-1))
    elif y == 0:
##        print('Enters 2')
        ans.append((1,0))
        ans.append((x,0))
        ans.append((0,0))
        ans.append((x-1,0))
    else:
        if x > y:
            if (y < 2) or (math.sqrt(x**2 + y**2) + x > 2*math.sqrt(x**2 + (y-1)**2)):
##                print('Enters 3')
                ans.append((0,0))
                ans.append((x,y))
                ans.append((0,y))
                ans.append((x,0))
            else:
##                print('Enters 4')
                ans.append((0,1))
                ans.append((x,y))
                ans.append((0,0))
                ans.append((x,y-1))
        else:
            if (x < 2) or (math.sqrt(x**2 + y**2) + y > math.sqrt(y**2 + (x-1)**2) + math.sqrt(y**2 + (x-1)**2)):
##                print('Enters 5')
                ans.append((0,0))
                ans.append((x,y))
                ans.append((x,0))
                ans.append((0,y))
            else:
##                print('Enters 6')
                ans.append((1,0))
                ans.append((x,y))
                ans.append((0,0))
                ans.append((x-1,y))
    for a in ans:
        print(str(a[0])+' '+str(a[1]))
        

__starting_point()

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

A = set((i, j) for i in range(2) for j in range(2) if i <= n and j <= m)
A |= set((n - i, m - j) for i in range(2) for j in range(2) if i <= n and j <= m)
A |= set((i, m - j) for i in range(2) for j in range(2) if i <= n and j <= m)
A |= set((n - i, j) for i in range(2) for j in range(2) if i <= n and j <= m)

def dist2(a, b):
    return (a[0] - b[0]) ** 2 + (a[1] - b[1]) ** 2

ans = sorted((dist2(p1, p2) + dist2(p2, p3) + dist2(p3, p4), p1, p2, p3, p4) for p1 in A for p2 in A for p3 in A for p4 in A if len(set([p1, p2, p3, p4])) == 4)[-1][1:5]

print('\n'.join(str(p[0]) + ' ' + str(p[1]) for p in ans))

n, m = map(int, input().split())
if n == 0: print('0 1\n0 ' + str(m) + '\n0 0\n0 ' + str(m - 1))
elif m == 0: print('1 0\n' + str(n) + ' 0\n0 0\n' + str(n - 1) + ' 0')
elif n < m:
    if (n ** 2 + m ** 2) ** 0.5 + m < 2 * ((n - 1) ** 2 + m ** 2) ** 0.5:
        print(str(n - 1) + ' ' + str(m) + '\n0 0\n' + str(n) + ' ' + str(m) + '\n1 0')
    else: print('0 0\n' + str(n) + ' ' + str(m) + '\n' + str(n) + ' 0\n0 ' + str(m))
else:
    if (n ** 2 + m ** 2) ** 0.5 + n < 2 * (n ** 2 + (m - 1) ** 2) ** 0.5:
        print(str(n) + ' ' + str(m - 1) + '\n0 0\n' + str(n) + ' ' + str(m) + '\n0 1')
    else: print('0 0\n' + str(n) + ' ' + str(m) + '\n0 ' + str(m) + '\n' + str(n) + ' 0')

import math
a,b=list(map(int,input().split(' ')))
if a==0:
    print(0,' ',1)
    print(0,' ',b)
    print(0,' ',0)
    print(0,' ',b-1)
elif b==0:
    print(1,' ',0)
    print(a,' ',0)
    print(0,' ',0)
    print(a-1,' ',0)
elif a>=b:
    if math.sqrt(a**2+b**2)+a>2*math.sqrt(a**2+(b-1)**2):
        print(0,' ',0)
        print(a,' ',b)
        print(0,' ',b)
        print(a,' ',0)
    else:
        print(0,' ',1)
        print(a,' ',b)
        print(0,' ',0)
        print(a,' ',b-1)
else:
    if math.sqrt(a**2+b**2)+b>2*math.sqrt((a-1)**2+b**2):
        print(0,' ',0)
        print(a,' ',b)
        print(a,' ',0)
        print(0,' ',b)
    else:
        print(1,' ',0)
        print(a,' ',b)
        print(0,' ',0)
        print(a-1,' ',b)


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

data = [[0, i] for i in range(min(m + 1, 5))] + [[j, 0] for j in range(min(n + 1, 5))] + [[n, k] for k in range(max(0, m - 5), m + 1)] + [[l, m] for l in range(max(n - 5, 0), n + 1)]
a, b, c, d = 0, 0, 0, 0
r = -1

def check(a, b, c, d):
    return ((a[0] - b[0]) ** 2 + (a[1] - b[1]) ** 2) ** 0.5 + ((b[0] - c[0]) ** 2 + (b[1] - c[1]) ** 2) ** 0.5 + ((c[0] - d[0]) ** 2 + (c[1] - d[1]) ** 2) ** 0.5
for i in range(len(data)):
    for j in range(len(data)):
        for k in range(len(data)):
            for l in range(len(data)):
                if not (data[i] != data[k] and data[j] != data[l] and data[i] != data[j] and data[i] != data[l] and data[j] != data[k] and data[k] != data[l]):
                    continue
                if r < check(data[i], data[j], data[k], data[l]):
                    r = check(data[i], data[j], data[k], data[l])
                    #print(i, j, k, l)
                    a, b, c, d = data[i], data[j], data[k], data[l]
print(a[0], a[1])
print(b[0], b[1])
print(c[0], c[1])
print(d[0], d[1])


n, m = [int(s) for s in input().split()]

p = [(i, j) for i in range(4) for j in range(4) if i + j < 4 and (i <= n) and (j <= m)]
q = [(n - i, m - j) for i, j in p]

p = set(p + q)
from math import sqrt
def dist(a, b):
    return sqrt((a[0]-b[0])**2. + (a[1]-b[1])**2.)

def dp(a, b, c, d):
    return dist(a, b) + dist(b, c) + dist(c, d)

t = -1
r = None
for a in p:
    for b in p:
        if b == a:
            continue
        for c in p:
            if c == a or c == b:
                continue
            for d in p:
                if d == a or d == b or d == c:
                    continue
                f = dp(a, b, c, d)
                if f > t:
                    r = (a, b, c, d)
                    t = f

for i, j in r:
    print(i, j)


inp = input().split()
x = int(inp[0])
y = int(inp[1])


def distance(points):
	d = 0
	for i in range(len(points) - 1):
		p1 = points[i]
		p2 = points[i + 1]
		d += ((p1[0] - p2[0]) ** 2 + (p1[1] - p2[1]) ** 2) ** 0.5
	return d

res = None
poss = []
if x != 0 and y != 0:
	poss.append([(0,1), (x, y), (0, 0), (x, y-1)])
	poss.append([(1,0), (x, y), (0, 0), (x - 1, y)])
	poss.append([(0,0), (x, y), (x, 0), (0, y)])
	poss.append([(0,0), (x, y), (0, y), (x, 0)])

	d1 = distance(poss[0])
	d2 = distance(poss[1])
	d3 = distance(poss[2])
	d4 = distance(poss[3])
	if d1 >= d2 and d1 >= d3 and d1 >= d4:
		res = poss[0]
	elif d2 >= d1 and d2 >= d3 and d2 >= d4:
		res = poss[1]
	elif d3 >= d1 and d3 >= d2 and d3 >= d4:
		res = poss[2]
	else:
		res = poss[3]
elif x == 0 and y != 0:
	res = [(0, 1), (0,y), (0,0), (0, y - 1)]
elif x != 0 and y == 0:
	res = [(1, 0), (x,0), (0,0), (x - 1,0)]
else:
	res = [(0,0),(0,0),(0,0),(0,0)]

for i in res:
	print(i[0], i[1])


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

a = ([[0, 1], [0, m], [0, 0], [0, m - 1]], [[1, 0], [n, 0], [0, 0], [n - 1, 0]], \

     [[0, 1], [n, m], [0, 0], [n, m - 1]], [[1, 0], [n, m], [0, 0], [n - 1, m]], \

     [[0, 0], [n, m], [0, m], [n, 0]], [[0, 0], [n, m], [n, 0], [0, m]])

for x in max(a, key = lambda a: (len(set(map(tuple, a))) == len(a)) * all(map((lambda x: min(x[1], x[0]) >= 0), a)) * sum(((a[i][0] - a[i + 1][0]) ** 2 + (a[i][1] - a[i + 1][1]) ** 2) ** 0.5 for i in range(len(a) - 1))):

    print(*x)

print()





# Made By Mostafa_Khaled


n , m = map(int,input().split())
if n == 0 :
    print (0, 1)
    print (0, m)
    print (0, 0)
    print (0, m - 1)
elif m == 0 :
    print (1, 0)
    print (n, 0)
    print (0, 0)
    print (n - 1, 0)
elif m >= n :
    if 2 * (m ** 2 + (n - 1) ** 2) ** 0.5 >= m + (m ** 2 + n ** 2) ** 0.5 :
        print (1, 0)
        print (n, m)
        print (0, 0)
        print (n - 1, m)
    else :
        print (n, m)
        print (0, 0)
        print (0, m)
        print (n, 0)
else :
    if 2 * ((m - 1) **  2 + n ** 2) ** 0.5 >= n + (m ** 2 + n ** 2) ** 0.5 :
        print (0, 1)
        print (n, m)
        print (0, 0)
        print (n, m - 1)
    else :
        print (n, m)
        print (0, 0)
        print (n, 0)
        print (0, m)

from math import hypot
n, m = list(map(int, input().split()))
f = False
if n > m:
    n, m = m, n
    f = True
if n == 0:
    for el in [(0, 1), (0, m), (0, 0), (0, m - 1)]:
        print(*(el if not f else reversed(el)))
else:
    p = [
        [(0, 0), (n, m), (n, 0), (0, m)],
        [(1, 0), (n, m), (0, 0), (n - 1, m)]
    ]
    t = lambda x: sum((hypot(x[i][0] - x[i - 1][0], x[i][1] - x[i - 1][1])) for i in range(1, 4))
    for el in max(p, key=t):
        print(*(el if not f else reversed(el)))