cho.sh
Notes
Loading...

Manhattan Distance on a Four-Row Number Board

Time limit

2s

Memory limit

128 MB

Problem

There is a number board with 4 rows. Starting from 1, numbers are written down each column from top to bottom, then continue in the next column. Therefore 1, 2, 3, and 4 are in the first column, while 5, 6, 7, and 8 are in the second column.

Given two natural numbers A and B, find the Manhattan distance between their cells on the board. The Manhattan distance is the sum of the horizontal distance and the vertical distance.

Input

The first line contains two natural numbers A and B separated by a space. Each number is at most 10,000,000.

Output

Print the Manhattan distance between the cells containing the two numbers.