
The city of Eastowner is perpetually plagued by water shortages, so a new water pipe is being built. Construction started from both ends at the same time, and the two halves were finally joined — almost. The first half ends at point (x1,y1) and the second half ends at point (x2,y2). Only a few leftover pipe segments of various lengths are available. Because of the peculiarities of local technology, each segment may be laid only in the north–south or the east–west direction, and two segments may be connected only so that they continue in a straight line or make a 90∘ turn (a 180∘ U-turn is not allowed).
Given the available segment lengths L1,…,Lk and the number of segments Ci of each length Li, construct a pipe that connects (x1,y1) and (x2,y2), or report that it is impossible. Output the minimum number of segments required.
The input contains the integers x1 y1 x2 y2 k, followed by 2k integers L1 L2 … Lk C1 C2 … Ck. The values are separated by whitespace (spaces or newlines).
Output a single integer — the minimum number of segments required, or −1 if the connection is impossible.