Polycarp takes part in a quadcopter competition. According to the rules a flying robot should:

  start the race from some point of a field,  go around the flag,  close cycle returning back to the starting point. 

Polycarp knows the coordinates of the starting point (x_1, y_1) and the coordinates of the point where the flag is situated (x_2, y_2). Polycarp’s quadcopter can fly only parallel to the sides of the field each tick changing exactly one coordinate by 1. It means that in one tick the quadcopter can fly from the point (x, y) to any of four points: (x - 1, y), (x + 1, y), (x, y - 1) or (x, y + 1).

Thus the quadcopter path is a closed cycle starting and finishing in (x_1, y_1) and containing the point (x_2, y_2) strictly inside.

 [Image] The picture corresponds to the first example: the starting (and finishing) point is in (1, 5) and the flag is in (5, 2). 

What is the minimal length of the quadcopter path?


-----Input-----

The first line contains two integer numbers x_1 and y_1 ( - 100 ≤ x_1, y_1 ≤ 100) — coordinates of the quadcopter starting (and finishing) point.

The second line contains two integer numbers x_2 and y_2 ( - 100 ≤ x_2, y_2 ≤ 100) — coordinates of the flag.

It is guaranteed that the quadcopter starting point and the flag do not coincide.


-----Output-----

Print the length of minimal path of the quadcopter to surround the flag and return back.


-----Examples-----
Input
1 5
5 2

Output
18

Input
0 1
0 0

Output
8

Source: codeforces | Difficulty: EASY
Tags: Mathematics

Greedy algorithms


Solutions:
def main():
	(x1, y1) = map(int, input().split())
	(x2, y2) = map(int, input().split())
	res = (abs(x2 - x1) + abs(y2 - y1) + 2) * 2
	if x1 == x2:
		res += 2
	if y1 == y2:
		res += 2
	print(res)
main()


(x1, y1) = map(int, input().split())
(x2, y2) = map(int, input().split())
if x1 == x2 or -x1 == -x2 or -y1 == -y2:
	print((max(x2, x1) - min(x2, x1) + 1) * 2 + (max(y2, y1) - min(y2, y1) + 1) * 2 + 2)
else:
	print((max(x2, x1) - min(x2, x1) + 1) * 2 + (max(y2, y1) - min(y2, y1) + 1) * 2)


(x1, y1) = map(int, input().split())
(x2, y2) = map(int, input().split())
print((abs(x1 - x2) + abs(y1 - y2) + 2 + int(x1 == x2) + int(y1 == y2)) * 2)


lstIn = map(int, input().split())
(x1, y1) = lstIn
lstIn = map(int, input().split())
(x2, y2) = lstIn
dx = abs(x1 - x2)
dy = abs(y1 - y2)
if dx < 2:
	dx = 2
else:
	dx += 1
if dy < 2:
	dy = 2
else:
	dy += 1
dist = dx * 2 + dy * 2
print(dist)


(x1, y1) = map(int, input().split())
(x2, y2) = map(int, input().split())
print(2 * (max(1, abs(x1 - x2)) + 1) + 2 * (max(1, abs(y1 - y2)) + 1))


(x1, y1) = map(int, input().split())
(x2, y2) = map(int, input().split())
if x1 == x2:
	print(4 + 2 * (abs(y2 - y1) + 1))
elif y1 == y2:
	print(4 + 2 * (abs(x2 - x1) + 1))
else:
	print(2 * (abs(x2 - x1) + 1) + 2 * (abs(y2 - y1) + 1))


(x1, y1) = [int(i) for i in input().split(' ')]
(x2, y2) = [int(i) for i in input().split(' ')]
x = max(abs(x2 + 1 - x1), abs(x2 - 1 - x1))
y = max(abs(y2 + 1 - y1), abs(y2 - 1 - y1))
if x1 == x2:
	x = 2
if y1 == y2:
	y = 2
print((x + y) * 2)


(a, b) = input().split()
(a, b) = (int(a), int(b))
(c, d) = input().split()
(c, d) = (int(c), int(d))
if abs(a - c) == 0:
	print(2 * abs(b - d) + 6)
elif abs(b - d) == 0:
	print(2 * abs(a - c) + 6)
else:
	print(2 * abs(a - c) + 2 * abs(b - d) + 4)


read = lambda : list(map(int, input().split()))
(x1, y1) = read()
(x2, y2) = read()
print(6 + 2 * (abs(x2 - x1) + abs(y2 - y1)) - 2 * (x1 != x2 and y1 != y2))


a = tuple(map(int, input().split()))
b = tuple(map(int, input().split()))
x = abs(a[0] - b[0])
y = abs(a[1] - b[1])
if x == 0:
	x += 2
else:
	x += 1
if y == 0:
	y += 2
else:
	y += 1
print(2 * (x + y))


(x1, y1) = [int(i) for i in input().split()]
(x2, y2) = [int(i) for i in input().split()]
h = abs(x1 - x2) + (1 if x1 != x2 else 2)
w = abs(y1 - y2) + (1 if y1 != y2 else 2)
print(h * 2 + w * 2)


def gcd(a, b):
	while b > 0:
		r = a % b
		a = b
		b = r
	return a
inp = lambda : map(int, input().split())
(x, y) = inp()
(a, b) = inp()
r = a - (2 * (x > a) - 1)
q = b - (2 * (y > b) - 1)
print(2 * max(abs(x - r), 2) + 2 * max(abs(y - q), 2))


(a, b) = map(int, input().split(' '))
(c, d) = map(int, input().split(' '))
j = 0
if c == a or b == d:
	j = 2
print((abs(c - a) + 1) * 2 + 2 * (abs(b - d) + 1) + j)


(n, k) = map(int, input().strip().split(' '))
(a, b) = map(int, input().strip().split(' '))
print(2 * (max(2, abs(a - n) + 1) + max(2, abs(b - k) + 1)))


(copterX, copterY) = map(int, input().split())
(flagX, flagY) = map(int, input().split())
if copterX == flagX:
	distance = abs(copterY - flagY)
	routeLength = (distance + 3) * 2
elif copterY == flagY:
	distance = abs(copterX - flagX)
	routeLength = (distance + 3) * 2
else:
	distanceX = abs(copterX - flagX)
	distanceY = abs(copterY - flagY)
	distanceXY = distanceX + distanceY
	routeLength = (distanceXY + 2) * 2
print(routeLength)


(x_1, y_1) = input().split()
(x_2, y_2) = input().split()
x_1 = int(x_1)
x_2 = int(x_2)
y_1 = int(y_1)
y_2 = int(y_2)
if x_1 == x_2:
	jwb = 2 * (abs(y_2 - y_1) + 1) + 4
elif y_1 == y_2:
	jwb = 2 * (abs(x_2 - x_1) + 1) + 4
else:
	jwb = 2 * (abs(x_2 - x_1) + 1) + 2 * (abs(y_2 - y_1) + 1)
print(jwb)


from collections import defaultdict as dd
from collections import Counter as ccd
from itertools import permutations as pp
from itertools import combinations as cc
from random import randint as rd
from bisect import bisect_left as bl
from bisect import bisect_right as br
import heapq as hq
import math
mod = pow(10, 9) + 7

def inp(flag=0):
	if flag == 0:
		return list(map(int, input().strip().split(' ')))
	else:
		return int(input())
(x1, y1) = inp()
(x2, y2) = inp()
xdist = 2 * (abs(x1 - x2) + 1)
ydist = 2 * (abs(y1 - y2) + 1)
if x1 == x2:
	xdist += 2
if y1 == y2:
	ydist += 2
ans = xdist + ydist
print(ans)


(x1, y1) = map(int, input().split())
(x2, y2) = map(int, input().split())
if x1 == x2:
	p = 2 * abs(y1 - y2) + 6
elif y2 == y1:
	p = 2 * abs(x1 - x2) + 6
else:
	p = abs(x1 - x2) * 2 + abs(y1 - y2) * 2 + 4
print(p)


(x1, y1) = map(int, input().split())
(x2, y2) = map(int, input().split())
ans = 2 * (abs(x1 - x2) + abs(y1 - y2) - 1) + 6
if x1 == x2 or y1 == y2:
	ans += 2
print(ans)


(x1, y1) = map(int, input().split(' '))
(x2, y2) = map(int, input().split(' '))
length = 0
if x2 > x1:
	length += 2 * (x2 + 1 - x1)
elif x2 < x1:
	length += 2 * (x1 + 1 - x2)
elif x2 == x1:
	length += 4
if y2 > y1:
	length += 2 * (y2 + 1 - y1)
elif y2 < y1:
	length += 2 * (y1 + 1 - y2)
elif y2 == y1:
	length += 4
print(length)


(x1, y1) = map(int, input().split())
(x2, y2) = map(int, input().split())
if x1 != x2 and y1 != y2:
	ans = abs(x1 - x2) + abs(y1 - y2) + 2
	print(ans * 2)
else:
	ans = abs(x1 - x2) + abs(y1 - y2) + 3
	print(ans * 2)


(x1, y1) = list(map(int, input().split()))
(x2, y2) = list(map(int, input().split()))
dx = max(2, abs(x1 - x2) + 1)
dy = max(2, abs(y1 - y2) + 1)
print(dx * 2 + dy * 2)


s = input()
xy1 = s.split()
xy1[0] = int(xy1[0])
xy1[1] = int(xy1[1])
s = input()
xy2 = s.split()
xy2[0] = int(xy2[0])
xy2[1] = int(xy2[1])
if xy1[0] == xy2[0] and xy1[1] == xy2[1]:
	print(10)
elif xy1[0] == xy2[0] and xy1[1] != xy2[1]:
	dify = xy2[1] - xy1[1]
	if dify < 0:
		dify = -1 * dify
	dify = dify + 1
	print(4 + 2 * dify)
elif xy1[0] != xy2[0] and xy1[1] == xy2[1]:
	difx = xy2[0] - xy1[0]
	if difx < 0:
		difx = -1 * difx
	difx = difx + 1
	print(4 + 2 * difx)
else:
	difx = xy2[0] - xy1[0]
	if difx < 0:
		difx = -1 * difx
	dify = xy2[1] - xy1[1]
	if dify < 0:
		dify = -1 * dify
	difx = difx + 1
	dify = dify + 1
	print(2 * difx + 2 * dify)


from sys import exit
(xs, ys) = map(int, input().split())
(xf, yf) = map(int, input().split())
if xs == xf:
	print((abs(yf - ys) + 1) * 2 + 4)
	exit(0)
elif ys == yf:
	print((abs(xf - xs) + 1) * 2 + 4)
	exit(0)
(xs, xf) = sorted([xs, xf])
(ys, yf) = sorted([ys, yf])
xf += 1
yf += 1
print(2 * (xf - xs) + 2 * (yf - ys))


(x1, y1) = map(int, input().split())
(x2, y2) = map(int, input().split())
if x1 == x2:
	print((max(y1, y2) - min(y1, y2) + 1) * 2 + 4)
elif y1 == y2:
	print((max(x1, x2) - min(x1, x2) + 1) * 2 + 4)
else:
	print((max(x1, x2) - min(x1, x2)) * 2 + (max(y1, y2) - min(y1, y2)) * 2 + 4)


(x1, y1) = map(int, input().split())
(x2, y2) = map(int, input().split())
if x1 - x2 == 0 or y1 - y2 == 0:
	print((abs(x1 - x2) + abs(y1 - y2)) * 2 + 6)
else:
	print((abs(x1 - x2) + abs(y1 - y2)) * 2 + 4)


(x1, y1) = [int(i) for i in input().split()]
(x2, y2) = [int(i) for i in input().split()]
minx = min(x1, x2 - 1)
miny = min(y1, y2 - 1)
maxx = max(x1, x2 + 1)
maxy = max(y1, y2 + 1)
print(2 * (maxx - minx + (maxy - miny)))


(x, y) = map(int, input().split())
(fx, fy) = map(int, input().split())
ans = 0
if x == fx or y == fy:
	ans = 2
ans += abs(fx - x) * 2 + abs(fy - y) * 2 + 4
print(ans)


q = [int(i) for i in input().split(' ')]
f = [int(i) for i in input().split(' ')]
d = [i for i in q]
compteur = 0
if q[0] > f[0]:
	while q[0] > f[0] + 1:
		q[0] -= 1
		compteur += 1
elif q[0] < f[0]:
	while q[0] < f[0] - 1:
		q[0] += 1
		compteur += 1
if q[1] > f[1]:
	while q[1] > f[1] + 1:
		q[1] -= 1
		compteur += 1
elif q[1] < f[1] - 1:
	while q[1] < f[1] - 1:
		q[1] += 1
		compteur += 1
compteur += 8
if q[0] < d[0]:
	while q[0] < d[0]:
		q[0] += 1
		compteur += 1
elif q[0] > d[0]:
	while q[0] > d[0]:
		q[0] -= 1
		compteur += 1
if q[1] < d[1]:
	while q[1] < d[1]:
		q[1] += 1
		compteur += 1
elif q[1] > d[1]:
	while q[1] > d[1]:
		q[1] -= 1
		compteur += 1
print(compteur)


from math import inf, sqrt, floor, ceil
from collections import Counter, defaultdict, deque
from heapq import heappush as hpush, heappop as hpop, heapify as h
from operator import itemgetter
from itertools import product
from bisect import bisect_left, bisect_right
(x1, y1) = map(int, input().split())
(x2, y2) = map(int, input().split())
l = abs(x1 - x2) + 1
b = abs(y1 - y2) + 1
if x1 == x2:
	l = abs(x1 - x2) + 2
if y1 == y2:
	b = abs(y1 - y2) + 2
print(2 * (l + b))


read = lambda : tuple(map(int, input().split()))
(x1, y1) = read()
(x2, y2) = read()
l = (-1, 0, 1)
ds = []
dist = lambda a, b: max(a, b) - min(a, b)
for i in l:
	for j in l:
		ds += [dist(x1, x2 + i) + dist(y1, y2 + j)]
print(min(ds) * 2 + 8)


(i, j) = input('').split()
i = int(i)
j = int(j)
(o, p) = input('').split()
o = int(o)
p = int(p)
a = i - o
b = j - p
if a < 0:
	a = 0 - a
if a == 0:
	a = 1
if b == 0:
	b = 1
if b < 0:
	b = 0 - b
x = (a + b + 2) * 2
print(x)


(x1, y1) = map(int, input().split())
(x2, y2) = map(int, input().split())
if x1 == x2 and y1 != y2:
	print(str(2 * (abs(x2 - x1) + 2 + (abs(y2 - y1) + 1))))
if x1 != x2 and y1 == y2:
	print(str(2 * (abs(x2 - x1) + 1 + (abs(y2 - y1) + 2))))
if x1 != x2 and y1 != y2:
	print(str(2 * (abs(x2 - x1) + 1 + (abs(y2 - y1) + 1))))
if x1 == x2 and y1 == y2:
	print(str(10))


def delta(a, b):
	return max(1, abs(a - b))
(x1, y1) = [int(s) for s in input().split()]
(x2, y2) = [int(s) for s in input().split()]
print(2 * (delta(x1, x2) + 1) + 2 * (delta(y1, y2) + 1))


X = list(map(int, input().split()))
Y = list(map(int, input().split()))
print(sum((4 if X[0] == Y[0] else (abs(X[0] - Y[0]) + 1) * 2, 4 if X[1] == Y[1] else (abs(X[1] - Y[1]) + 1) * 2)))


(x, y) = map(int, input().split())
(a, b) = map(int, input().split())
print((abs(a - x) + abs(b - y)) * 2 + 4 + (a == x or b == y) * 2)


(x1, y1) = map(int, input().split())
(x2, y2) = map(int, input().split())
if x1 == x2 or y1 == y2:
	r = 2
else:
	r = 0
print((abs(x1 - x2) + 1) * 2 + (abs(y1 - y2) + 1) * 2 + r)


import math
(x1, y1) = map(int, input().split())
(x2, y2) = map(int, input().split())
if x1 == x2:
	ans = 2 * abs(y1 - y2) + 6
elif y1 == y2:
	ans = 2 * abs(x1 - x2) + 6
else:
	ans = 2 * (abs(x1 - x2) + 1 + abs(y1 - y2) + 1)
print(ans)


data1 = input().split()
data2 = input().split()
(x1, y1) = (int(data1[0]), int(data1[1]))
(x2, y2) = (int(data2[0]), int(data2[1]))
w = max(2, abs(x1 - x2) + 1)
h = max(2, abs(y1 - y2) + 1)
print(w * 2 + h * 2)


line = input().split(' ')
x1 = int(line[0])
y1 = int(line[1])
line = input().split(' ')
x2 = int(line[0])
y2 = int(line[1])
result = 2 * abs(x2 - x1) + 2 * abs(y2 - y1) + 4
if x2 == x1 and y2 == y1:
	result = 0
elif x2 == x1 or y2 == y1:
	result += 2
print(result)


(x1, y1) = map(int, input().split())
(x2, y2) = map(int, input().split())
p = abs(x1 - x2) + abs(y1 - y2) + 2
print((p + 1) * 2) if x1 == x2 or y1 == y2 else print(2 * p)


(x1, y1) = list(map(int, input().split()))
(x2, y2) = list(map(int, input().split()))
x = 1 if not abs(x1 - x2) else abs(x1 - x2)
y = 1 if not abs(y1 - y2) else abs(y1 - y2)
print((x + 1) * 2 + (y + 1) * 2)


import math
import re

def ria():
	return [int(i) for i in input().split()]

def ri():
	return int(input())

def rfa():
	return [float(i) for i in input().split()]
eps = 1e-09

def is_equal(a, b):
	return abs(a - b) <= eps

def distance(p0, p1):
	return math.sqrt((p0[0] - p1[0]) ** 2 + (p0[1] - p1[1]) ** 2)
(xq, yq) = ria()
(xp, yp) = ria()
ar = [(xp + 1, yp + 1), (xp - 1, yp - 1), (xp - 1, yp + 1), (xp + 1, yp - 1)]
if xp == xq:
	print(2 * 2 + (abs(yp - yq) + 1) * 2)
	exit(0)
if yp == yq:
	print(2 * 2 + (abs(xp - xq) + 1) * 2)
	exit(0)
mni = 1000000000.0
for i in ar:
	(x1, y1) = i
	(mxx, mxy, mnx, mny) = (max(x1, xq), max(y1, yq), min(x1, xq), min(y1, yq))
	if mxx > xp and mxy > yp and (mnx < xp) and (mny < yp):
		mni = min(mni, (mxx - mnx) * 2 + (mxy - mny) * 2)
print(mni)


(x1, y1) = [int(x) for x in input().split(' ')]
(x2, y2) = [int(x) for x in input().split(' ')]
xoffset = 1
yoffset = 1
if x1 == x2:
	xoffset = 2
elif y1 == y2:
	yoffset = 2
print(2 * (abs(x1 - x2) + xoffset) + 2 * (abs(y1 - y2) + yoffset))


Q = input().split(' ')
F = input().split(' ')
xQ = int(Q[0])
yQ = int(Q[1])
xF = int(F[0])
yF = int(F[1])
if xQ == xF:
	print((abs(yQ - yF) + 1) * 2 + 4)
elif yQ == yF:
	print((abs(xQ - xF) + 1) * 2 + 4)
else:
	print((abs(xQ - xF) + 1) * 2 + (abs(yQ - yF) + 1) * 2)


(x1, y1) = map(int, input().split())
(x2, y2) = map(int, input().split())
travelx = abs(x1 - x2)
travely = abs(y1 - y2)
if travelx == 0:
	travelx += 2
else:
	travelx += 1
if travely == 0:
	travely += 2
else:
	travely += 1
travelx *= 2
travely *= 2
print(travelx + travely)


(x_1, y_1) = map(int, input().split())
(x_2, y_2) = map(int, input().split())
print((abs(x_1 - x_2) + 1 + abs(y_1 - y_2) + 1) * 2 + (2 if x_1 == x_2 or y_1 == y_2 else 0))


def main():
	(x1, y1) = [int(float(x)) for x in input().split(' ')]
	(x2, y2) = [int(float(x)) for x in input().split(' ')]
	xr = x2
	yr = y2
	if x2 > x1:
		xr += 1
	elif x2 != x1:
		xr -= 1
	if y2 > y1:
		yr += 1
	elif y2 != y1:
		yr -= 1
	if xr == x1:
		h = 2
	else:
		h = abs(x1 - xr)
	if yr == y1:
		w = 2
	else:
		w = abs(y1 - yr)
	print((h + w) * 2)
main()


(a, b) = map(int, input().split())
(c, d) = map(int, input().split())
print((max(2, abs(a - c) + 1) + max(2, abs(b - d) + 1)) * 2)


q = [int(i) for i in input().split()]
f = [int(i) for i in input().split()]
x = 1 if f[0] == q[0] else f[0] - q[0]
y = 1 if f[1] == q[1] else f[1] - q[1]
print((abs(x) + 1) * 2 + (abs(y) + 1) * 2)


(xs, ys) = list(map(int, input().split()))
(xf, yf) = list(map(int, input().split()))
if xs == xf:
	print((abs(yf - ys) + 1) * 2 + 4)
	return
elif ys == yf:
	print((abs(xf - xs) + 1) * 2 + 4)
	return
(xs, xf) = sorted([xs, xf])
(ys, yf) = sorted([ys, yf])
xf += 1
yf += 1
print(2 * (xf - xs) + 2 * (yf - ys))


(x1, y1) = map(int, input().split())
(x2, y2) = map(int, input().split())
w = 2 * (abs(x2 - x1) + abs(y2 - y1) + 2)
if x1 == x2 or y1 == y2:
	print(w + 2)
else:
	print(w)


start = input().split()
x1 = int(start[0])
y1 = int(start[1])
flag = input().split()
x2 = int(flag[0])
y2 = int(flag[1])
print(2 * max(1, abs(x1 - x2)) + 2 + 2 * max(abs(y1 - y2), 1) + 2)


(x1, y1) = map(int, input().split())
(x2, y2) = map(int, input().split())
if x1 == x2 and y1 == y2:
	print(8)
if y1 == y2:
	print((abs(x1 - x2) + 1) * 2 + 4)
elif x1 == x2:
	print((abs(y1 - y2) + 1) * 2 + 4)
else:
	distx = abs(x1 - x2) + 1
	disty = abs(y1 - y2) + 1
	print(2 * distx + 2 * disty)


I = lambda : map(int, input().split())
(a, b) = I()
(c, d) = I()
print((max(1, abs(a - c)) + max(1, abs(b - d)) << 1) + 4)


(x1, y1) = map(int, input().split())
(x2, y2) = map(int, input().split())

def abs(a, b):
	if a > b:
		return a - b
	else:
		return b - a
if x1 != x2 and y1 != y2:
	print(2 * (abs(x1, x2) + 1) + 2 * (abs(y1, y2) + 1))
elif x1 == x2:
	print(4 * (abs(x1, x2) + 1) + 2 * (abs(y1, y2) + 1))
elif y1 == y2:
	print(2 * (abs(x1, x2) + 1) + 4 * (abs(y1, y2) + 1))


(x1, y1) = map(int, input().split())
(x2, y2) = map(int, input().split())
y = abs(y1 - y2)
x = abs(x1 - x2)
if x != 0 and y != 0:
	sum = (abs(x1 - x2) + 1) * 2 + (abs(y1 - y2) + 1) * 2
elif x == 0:
	sum = (abs(y1 - y2) + 1) * 2 + 4
elif y == 0:
	sum = (abs(x1 - x2) + 1) * 2 + 4
print(sum)


(x1, y1) = map(int, input().split())
(x2, y2) = map(int, input().split())
upperx = x2 - 1
lowerx = x2 + 1
uppery = y2 - 1
lowery = y2 + 1
cnt = 4 + abs(upperx - x1) + abs(lowerx - x1) + abs(uppery - y1) + abs(lowery - y1)
print(cnt)


import sys

def solve(s, e):
	x1 = s[0]
	y1 = s[1]
	x2 = e[0]
	y2 = e[1]
	if abs(x1 - x2) + abs(y1 - y2) == 0:
		print(0)
		return
	if abs(x1 - x2) == 0:
		print(2 * (abs(y1 - y2) + 3))
		return
	elif abs(y1 - y2) == 0:
		print(2 * (abs(x1 - x2) + 3))
	else:
		print(2 * (abs(x1 - x2) + abs(y1 - y2) + 2))

def main():
	a = [list(map(int, x.split())) for x in sys.stdin]
	for x in range(0, len(a), 2):
		solve(a[x], a[x + 1])
main()


(x, y) = map(int, input().split())
(a, b) = map(int, input().split())
print((max(abs(a - x), 1) + max(abs(b - y), 1)) * 2 + 4)


(x1, y1) = map(int, input().split())
(x2, y2) = map(int, input().split())
(x, y) = (x2, y2)
if abs(x1 - x2) >= 1:
	if x1 > x2:
		x = x2 + 1
	else:
		x = x2 - 1
if abs(y1 - y2) >= 1:
	if y1 > y2:
		y = y2 + 1
	else:
		y = y2 - 1
if x == x2 and y == y2:
	print(8)
else:
	print(8 + 2 * (abs(x1 - x) + abs(y1 - y)))


(x1, y1) = [int(i) for i in input().split()]
(x2, y2) = [int(i) for i in input().split()]
if x1 == x2:
	print(4 + 2 * (abs(y1 - y2) + 1))
elif y1 == y2:
	print(4 + 2 * (abs(x1 - x2) + 1))
else:
	print(2 * (abs(x1 - x2) + 1) + 2 * (abs(y1 - y2) + 1))


(a, b) = input().split(' ')
(x, y) = input().split(' ')
a = int(a)
b = int(b)
x = int(x)
y = int(y)
x_ = 0
y_ = 0
if x == a:
	x_ = 2
	y_ = abs(y - b) + 1
elif y == b:
	x_ = abs(x - a) + 1
	y_ = 2
else:
	y_ = abs(y - b) + 1
	x_ = abs(x - a) + 1
print(2 * (x_ + y_))


(x1, y1) = [int(j) for j in input().split()]
(x2, y2) = [int(j) for j in input().split()]
(rx, ry) = (0, 0)
res = 0
if x1 < x2 and y1 < y2:
	(rx, ry) = (x2 + 1, y2 + 1)
elif x1 < x2 and y1 > y2:
	(rx, ry) = (x2 + 1, y2 - 1)
elif x1 > x2 and y1 < y2:
	(rx, ry) = (x2 - 1, y2 + 1)
elif x1 > x2 and y1 > y2:
	(rx, ry) = (x2 - 1, y2 - 1)
elif x1 == x2 or y1 == y2:
	res = 2
	if x1 == x2:
		rx = x1
		if y1 < y2:
			ry = y2 + 1
		else:
			ry = y2 - 1
	else:
		ry = y1
		if x1 < x2:
			rx = x2 + 1
		else:
			rx = x2 - 1
res += abs(rx - x1) + abs(ry - y1)
print(res * 2)


(a, b) = (int(i) for i in input().split())
(c, d) = (int(i) for i in input().split())
if a == c or b == d:
	k = (((c - a) ** 2) ** (1 / 2) + ((d - b) ** 2) ** (1 / 2)) * 2 + 6
else:
	k = (((c - a) ** 2) ** (1 / 2) + ((d - b) ** 2) ** (1 / 2)) * 2 + 4
d = k ** 2
print(int(d ** (1 / 2)))


(x1, y1) = map(int, input().split())
(x2, y2) = map(int, input().split())
dx = abs(x1 - x2)
dy = abs(y1 - y2)
if dx and dy:
	print(2 * (dx + dy) + 4)
else:
	print(2 * (dx + dy) + 6)


(x1, y1) = map(int, input().split())
(x2, y2) = map(int, input().split())
if abs(x1 - x2) != 0 and abs(y1 - y2) != 0:
	print((abs(x1 - x2) + 1) * 2 + (abs(y1 - y2) + 1) * 2)
else:
	print((abs(x1 - x2) + 1) * 2 + (abs(y1 - y2) + 1) * 2 + 2)


(x1, y1) = [i for i in map(int, input().split())]
(x2, y2) = [i for i in map(int, input().split())]
if x1 == x2 or y1 == y2:
	if x1 == x2:
		x1 += 1
	if y1 == y2:
		y1 += 1
x = x1 - x2
y = y1 - y2
if x < 0:
	x = -1 * x
if y < 0:
	y = -1 * y
x = 2 * (x + 1)
y = 2 * (y + 1)
print(x + y)


p1 = list(map(int, input().split()))
p2 = list(map(int, input().split()))
if p1[0] != p2[0] and p1[1] != p2[1]:
	ans = 2 * (abs(p1[0] - p2[0]) + 1) + 2 * (abs(p1[1] - p2[1]) + 1)
elif p1[0] != p2[0] and p1[1] == p2[1]:
	ans = 2 * (abs(p1[0] - p2[0]) + 1) + 4
else:
	ans = ans = 2 * (abs(p1[1] - p2[1]) + 1) + 4
print(ans)


(x1, y1) = [int(i) for i in input().split()]
(x2, y2) = [int(i) for i in input().split()]
l1 = abs(x1 - x2) + 1
l2 = abs(y1 - y2) + 1
if l1 == 1:
	l1 = 2
if l2 == 1:
	l2 = 2
print(2 * (l1 + l2))


z = lambda : map(int, input().split())
d = lambda a, b: max(abs(a - b), 1) * 2 + 2
(q, w) = z()
(e, r) = z()
print(d(q, e) + d(w, r))


(x1, y1) = map(int, input().split())
(x2, y2) = map(int, input().split())
a = abs(x1 - x2) + 1
b = abs(y1 - y2) + 1
if a == 1:
	a += 1
if b == 1:
	b += 1
print((a + b) * 2)


def main():
	(x0, y0) = map(int, input().split())
	(x1, y1) = map(int, input().split())
	print((max(abs(x1 - x0), 1) + max(abs(y1 - y0), 1)) * 2 + 4)
try:
	while True:
		main()
except EOFError:
	pass


f = lambda : map(int, input().split())
print(2 * sum((max(1, abs(a - b)) + 1 for (a, b) in zip(f(), f()))))


(x, y) = map(int, input().split())
(x2, y2) = map(int, input().split())
result = (abs(x - x2) + abs(y - y2) + 2) * 2
if x == x2:
	result += 2
if y == y2:
	result += 2
print(result)


a = input().split()
b = input().split()
x1 = int(a[0])
y1 = int(a[1])
x2 = int(b[0])
y2 = int(b[1])
count = 0
if x1 < x2 and y1 < y2:
	for i in range(x1, x2 + 1):
		count += 1
	for j in range(y1, y2 + 1):
		count += 1
	count *= 2
elif x1 < x2 and y1 > y2:
	for i in range(x1, x2 + 1):
		count += 1
	for j in range(y1, y2 - 1, -1):
		count += 1
	count *= 2
elif x1 > x2 and y1 < y2:
	for i in range(x1, x2 - 1, -1):
		count += 1
	for j in range(y1, y2 + 1):
		count += 1
	count *= 2
elif x1 > x2 and y1 > y2:
	for i in range(x1, x2 - 1, -1):
		count += 1
	for j in range(y1, y2 - 1, -1):
		count += 1
	count *= 2
elif x1 == x2 and y1 < y2:
	count += 2
	for i in range(y1, y2 + 1):
		count += 1
	count *= 2
elif x1 == x2 and y1 > y2:
	count += 2
	for i in range(y1, y2 - 1, -1):
		count += 1
	count *= 2
elif x1 < x2 and y1 == y2:
	count += 2
	for i in range(x1, x2 + 1):
		count += 1
	count *= 2
elif x1 > x2 and y1 == y2:
	count += 2
	for i in range(x1, x2 - 1, -1):
		count += 1
	count *= 2
print(count)


a = [int(s) for s in input().split()]
b = [int(s) for s in input().split()]
if a[0] == b[0]:
	x = (abs(b[1] - a[1]) + 1 + 2) * 2
	print(x)
elif a[1] == b[1]:
	x = (abs(b[0] - a[0]) + 1 + 2) * 2
	print(x)
else:
	x = (abs(b[0] - a[0]) + 1 + abs(b[1] - a[1]) + 1) * 2
	print(x)


import sys
import string
from collections import Counter, defaultdict
from math import fsum, sqrt, gcd, ceil, factorial
from operator import add
inf = float('inf')
flush = lambda : sys.stdout.flush
comb = lambda x, y: factorial(x) // factorial(y) // factorial(x - y)
ip = lambda : input()
ii = lambda : int(input())
r = lambda : map(int, input().split())
rr = lambda : list(r())
(a, b) = r()
(x, y) = r()
print(2 * (max(abs(a - x), 1) + 2 + max(abs(b - y), 1)))


import math
import collections
import bisect
import heapq
import time
import random
import itertools
import sys
(x1, y1) = map(int, input().split())
(x2, y2) = map(int, input().split())
print(2 * (2 + max(abs(x1 - x2), 1) + max(abs(y1 - y2), 1)))


first = list(map(int, input().split()))
second = list(map(int, input().split()))
x_len = abs(first[0] - second[0])
y_len = abs(first[1] - second[1])
len_to_point = x_len + y_len
if len_to_point == 1:
	print(8)
elif x_len == 0 or y_len == 0:
	print((len_to_point - 1) * 2 + 8)
else:
	print((len_to_point - 2) * 2 + 8)


ip = lambda : map(int, input().split())
(x1, y1) = ip()
(x2, y2) = ip()
x = max(2, abs(x1 - x2) + 1)
y = max(2, abs(y1 - y2) + 1)
print(2 * x + 2 * y)


(x, y) = map(int, input().split())
(x1, y1) = map(int, input().split())
ans1 = abs(x - x1) + 1
ans2 = abs(y - y1) + 1
if x == x1 or y == y1:
	ans1 += 1
print(ans1 * 2 + ans2 * 2)


(a, b) = map(int, input().split())
(x, y) = map(int, input().split())
p = abs(a - x) + 1
q = abs(y - b) + 1
p = max(p, 2)
q = max(q, 2)
print(2 * (p + q))


Start = input()
Flag = input()
s_lst = Start.split()
f_lst = Flag.split()
a = [int(d) for d in s_lst]
b = [int(d) for d in f_lst]
x1 = a[0]
y1 = a[1]
x2 = b[0]
y2 = b[1]
if x1 == x2:
	print(abs(y1 - y2) * 2 + 6)
elif y1 == y2:
	print(abs(x1 - x2) * 2 + 6)
else:
	print(abs(x1 - x2) * 2 + abs(y1 - y2) * 2 + 4)


(x1, y1) = map(int, input().split())
(x2, y2) = map(int, input().split())
import sys
if x1 == x2:
	res = 2 * (2 + abs(y1 - y2) + 1)
	print(res)
	sys.exit(0)
if y1 == y2:
	res = 2 * (2 + abs(x1 - x2) + 1)
	print(res)
	sys.exit(0)
res = 2 * (abs(x1 - x2) + 1 + abs(y1 - y2) + 1)
print(res)


I = lambda : map(int, input().split())
(x1, y1) = I()
(x2, y2) = I()
print(2 * (abs(x1 - x2) + abs(y1 - y2) + 2 + (x1 == x2 or y1 == y2)))


(x1, y1) = list(map(int, input().split()))
(x2, y2) = list(map(int, input().split()))
x = max(abs(x2 - x1) + 1, 2)
y = max(abs(y2 - y1) + 1, 2)
print((x + y) * 2)


cc = list(map(int, input().split()))
fc = list(map(int, input().split()))
print(2 * ((abs(fc[0] - cc[0]) if fc[0] - cc[0] != 0 else 1) + 1 + ((abs(fc[1] - cc[1]) if fc[1] - cc[1] != 0 else 1) + 1)))


(x1, y1) = [int(i) for i in input().split()]
(x2, y2) = [int(i) for i in input().split()]
print(max(abs(x1 - x2) + 1, 2) * 2 + max(abs(y1 - y2) + 1, 2) * 2)


line1 = input()
line2 = input()
dc = [int(s) for s in line1.split(' ')]
fc = [int(s) for s in line2.split(' ')]
d = [abs(a - b) for (a, b) in zip(dc, fc)]
transit_x = max(2, d[0] + 1) * 2
transit_y = max(2, d[1] + 1) * 2
t = transit_x + transit_y
print(t)


(x1, y1) = map(lambda x: int(x), input().split())
(x2, y2) = map(lambda x: int(x), input().split())
pathLen = abs(x2 - x1) + abs(y2 - y1)
if x2 == x1 and y2 == y1:
	print(10)
elif x2 == x1 or y2 == y1:
	print(2 * pathLen + 6)
else:
	print(2 * pathLen + 4)


(x, y) = map(int, input().split())
(p, q) = map(int, input().split())
ans = (abs(x - p) + abs(y - q) + 2) * 2
if x == p or y == q:
	ans += 2
print(ans)


(x1, y1) = map(int, input().split())
(x2, y2) = map(int, input().split())
if x1 == x2:
	print(2 * (3 + abs(y2 - y1)))
elif y1 == y2:
	print(2 * (abs(x2 - x1) + 3))
else:
	print(2 * (2 + abs(x2 - x1) + abs(y2 - y1)))


def dist(x1, y1, x2, y2):
	return abs(x2 - x1) + abs(y2 - y1)
(x, y) = map(int, input().split())
(a, b) = map(int, input().split())
r = 4 + 2 * dist(x, y, a, b)
if x == a or y == b:
	r += 2
print(r)


(x1, y1) = map(int, input().split())
(x2, y2) = map(int, input().split())
d1 = (abs(x1 - x2) + 1) * 2
d2 = (abs(y1 - y2) + 1) * 2
if x1 == x2 or y1 == y2:
	print(d1 + d2 + 2)
else:
	print(d1 + d2)


def f(l1, l2):
	g = lambda d: 2 if d == 0 else 1 + (d if d > 0 else -d)
	d2 = g(l1[0] - l2[0]) + g(l1[1] - l2[1])
	return d2 << 1
l1 = list(map(int, input().split()))
l2 = list(map(int, input().split()))
print(f(l1, l2))


from math import *
(xq, yq) = map(int, input().split())
(xf, yf) = map(int, input().split())
val = 0
if yq == yf and xq == xf:
	print(int(10))
elif xq == xf and yq != yf:
	print(int(2 * (fabs(yq - yf) - 1) + 8))
elif yq == yf and xq != xf:
	print(int(2 * (fabs(xq - xf) - 1) + 8))
elif fabs(xq - xf) + fabs(yq - yf) == 2:
	print(8)
elif xq != xf and yq != yf:
	print(int(2 * (fabs(xq - xf) + fabs(yq - yf)) + 4))


depart = list(map(int, input().split()))
drapeau = list(map(int, input().split()))
if drapeau[1] == depart[1]:
	print(4 + 2 * abs(max(drapeau[0], depart[0]) - min(drapeau[0], depart[0]) + 1))
elif drapeau[0] == depart[0]:
	print(4 + 2 * abs(max(drapeau[1], depart[1]) - min(drapeau[1], depart[1]) + 1))
else:
	print(2 * (abs(max(drapeau[0], depart[0]) - min(drapeau[0], depart[0])) + 1) + 2 * (abs(max(drapeau[1], depart[1]) - min(drapeau[1], depart[1])) + 1))


l1 = input().split()
(x1, y1) = (int(l1[0]), int(l1[1]))
l2 = input().split()
(x2, y2) = (int(l2[0]), int(l2[1]))
w = 0
h = 0
if x1 == x2:
	w = 2
else:
	w = abs(x1 - x2) + 1
if y1 == y2:
	h = 2
else:
	h = abs(y1 - y2) + 1
print((w + h) * 2)


(sa, sb) = map(int, input().split())
(a, b) = map(int, input().split())
print(2 * (max(abs(sa - a) + 1, 2) + max(abs(sb - b) + 1, 2)))


import sys, collections

def get_dist(a, b, c, d):
	return abs(a - c) + abs(b - d)
(x1, y1) = map(int, sys.stdin.readline().split())
(x2, y2) = map(int, sys.stdin.readline().split())
if x1 == x2 and y1 != y2:
	print(max(2 * get_dist(x1 - 1, y1, x2 + 1, y2 - 1), 2 * get_dist(x1 - 1, y1, x2 + 1, y2 + 1), 2 * get_dist(x1 - 1, y1, x2 - 1, y2 - 1), 2 * get_dist(x1 - 1, y1, x2 - 1, y2 + 1), 2 * get_dist(x1 + 1, y1, x2 + 1, y2 - 1), 2 * get_dist(x1 + 1, y1, x2 + 1, y2 + 1), 2 * get_dist(x1 + 1, y1, x2 - 1, y2 - 1), 2 * get_dist(x1 + 1, y1, x2 - 1, y2 + 1)))
elif x1 != x2 and y1 == y2:
	print(max(2 * get_dist(x1, y1 - 1, x2 + 1, y2 - 1), 2 * get_dist(x1, y1 - 1, x2 + 1, y2 + 1), 2 * get_dist(x1, y1 - 1, x2 - 1, y2 - 1), 2 * get_dist(x1, y1 - 1, x2 - 1, y2 + 1), 2 * get_dist(x1, y1 + 1, x2 + 1, y2 - 1), 2 * get_dist(x1, y1 + 1, x2 + 1, y2 + 1), 2 * get_dist(x1, y1 + 1, x2 - 1, y2 - 1), 2 * get_dist(x1, y1 + 1, x2 - 1, y2 + 1)))
else:
	print(max(2 * get_dist(x1, y1, x2 + 1, y2 - 1), 2 * get_dist(x1, y1, x2 + 1, y2 + 1), 2 * get_dist(x1, y1, x2 - 1, y2 - 1), 2 * get_dist(x1, y1, x2 - 1, y2 + 1)))


(x1, y1) = map(int, input().split())
(x2, y2) = map(int, input().split())
n = 2 * (abs(x2 - x1) + 1) + 2 * (abs(y2 - y1) + 1)
if x1 == x2:
	n += 2
if y1 == y2:
	n += 2
print(n)


import sys
import math
get_string = lambda : sys.stdin.readline().strip()
get_int_list = lambda : list(map(int, sys.stdin.readline().strip().split()))
get_int = lambda : int(sys.stdin.readline())
pt = lambda x: sys.stdout.write(str(x) + '\n')
(x, y) = get_int_list()
(x1, y1) = get_int_list()
if x == x1 or y == y1:
	if x == x1:
		d = 2 + abs(y - y1) + 1
	else:
		d = 2 + abs(x - x1) + 1
else:
	d = abs(x - x1) + 1 + abs(y - y1) + 1
print(2 * d)


(x1, y1) = map(int, input().split(' '))
(x2, y2) = map(int, input().split(' '))
gotox = x2
gotoy = y2
if x1 > x2:
	gotox -= 1
elif x2 > x1:
	gotox += 1
if y1 > y2:
	gotoy -= 1
elif y2 > y1:
	gotoy += 1
print((max(abs(x1 - gotox), 2) + max(abs(y1 - gotoy), 2)) * 2)


(x1, y1) = map(int, input().split())
(x2, y2) = map(int, input().split())
res = 0
if x1 == x2:
	res = 2 * abs(y2 - y1) + 6
elif y1 == y2:
	res = 2 * abs(x2 - x1) + 6
else:
	for (dx, dy) in [(1, 1), (1, -1), (-1, 1), (-1, -1)]:
		dist = abs(x2 + dx - x1) + abs(y2 + dy - y1)
		res = max(res, 2 * dist)
print(res)