eolymp
bolt
Try our new interface for solving problems
Problems

Plumbing

Plumbing

\includegraphics{https://static.e-olymp.com/content/96/969a471d43d303422a413dca44ecae16f0512f30.jpg} City East are suffering from water scarcity. To resolve this problem, built a new water pipe. Construction of the pipe started from both ends simultaneously, and after a while half connected. Well, almost. The first half of the pipe ends at the point (\textbf{x_1}, \textbf{y_1}), and the second - at the point (\textbf{x_2}, \textbf{y_2}). Unfortunately, only a few segments of pipe of different lengths. Moreover, because of the specificity of local technology pipes can be laid only in the direction from north to south or from east to west and join to form or direct, or \textbf{90} degree angle. Requires knowing the lengths of the tubes \textbf{L_1}, \textbf{L_2}, ..., \textbf{L_K} and the number of segments each of length \textbf{C_1}, \textbf{C_2}, ..., \textbf{C_K}, to construct a pipeline connecting the two given points, or determine that it is impossible. \InputFile In the first row are the numbers \textbf{x_1}, \textbf{y_1}, \textbf{x_2}, \textbf{y_2}, \textbf{K}, then \textbf{2K} numbers: \textbf{L_1}, \textbf{L_2}, ..., \textbf{L_K}, \textbf{C_1}, \textbf{C_2}, ..., \textbf{C_K}. \textbf{1} ≤ \textbf{K} ≤ \textbf{4}, \textbf{1} ≤ \textbf{x_1}, \textbf{y_1}, \textbf{x_2}, \textbf{y_2}, \textbf{L_i} ≤ \textbf{1000}, \textbf{1} ≤ \textbf{C_i} ≤ \textbf{10}, all numbers are integers. \OutputFile Derive a single number - the minimum number of necessary segments of pipe, or \textbf{-1} if the connection is impossible.
Time limit 1 second
Memory limit 64 MiB
Input example #1
5 5 5 6 1 2 10
Output example #1
-1