Road

No attempts yetTime limit1sMemory limit1024 MB

Problem

An island is divided into $N$ plots of land, and each plot is an axis-aligned rectangle. A road must be built from point $A$ to point $B$. Because no landowner wants the road to split their plot into several smaller pieces, the road may run only along the plot boundaries (the edges of the rectangles).

Write a program that finds the length of the shortest such road from point $A$ to point $B$.

Input

The first line contains the number of plots $N$ ($1 \le N \le 1000$). Each of the next $N$ lines contains the coordinates $X_0$, $Y_0$, $X_1$, $Y_1$ of the bottom-left and top-right corners of the rectangle that describes one plot. The next line contains the coordinates $X_A$, $Y_A$ of point $A$, and the last line contains the coordinates $X_B$, $Y_B$ of point $B$.

All coordinates are non-negative integers not exceeding $1,000,000$. Points $A$ and $B$ always lie on the boundary of some plot. All plots together form a single island (which may contain lakes), and a road from $A$ to $B$ is guaranteed to exist.

Output

Output a single integer $L$ — the length of the shortest road from point $A$ to point $B$. Because all coordinates are integers and the road follows only axis-aligned segments, $L$ is always an integer.