Grocery Shopping for Ingredients
Limits: 1 sec., 256 MiB
This statement was translated automatically from Ukrainian.
Zenyk loves sandwiches very much, and his favorite sandwich consists of bread, sausage, and cheese. One morning, Zenyk noticed that he ran out of sandwich ingredients, so he needs to buy bread, sausage, and cheese at the store. Fortunately, Zenyk lives in a neighborhood with many different stores:
\(n\) bakeries, with the \(i\)-th bakery located at coordinate \(x_i\).
\(n\) cheese shops, with the \(i\)-th cheese shop located at coordinate \(y_i\).
\(n\) meat shops, with the \(i\)-th meat shop located at coordinate \(c_i\).
\(n\) supermarkets, with the \(i\)-th supermarket located at coordinate \(d_i\).
A supermarket has sausage, bread, and cheese all together. However, a supermarket might be located very far away, and then it is easier to buy all the ingredients separately in different stores. Zenyk’s house is located at coordinate 0.
Help Zenyk find the minimum distance he must walk to buy all the necessary ingredients and return back home, since Zenyk is very tired after writing a programming Olympiad.
Input
The first line contains a single integer \(n\).
The second line contains \(n\) integers \(x_i\) — the coordinates of the bakeries.
The third line contains \(n\) integers \(y_i\) — the coordinates of the cheese shops.
The fourth line contains \(n\) integers \(c_i\) — the coordinates of the meat shops.
The fifth line contains \(n\) integers \(d_i\) — the coordinates of the supermarkets.
Output
In a single line, output a single integer — the minimum distance Zenyk needs to walk.
Constraints
\(1 \le n \le 10^5\),
\(-10^9 \le x_i, y_i, c_i, d_i \le 10^9\),
\(5\) points — a block of tests in which \(n = 1\),
\(10\) points — a block of tests in which \(n \le 100\),
\(10\) points — a block of tests in which \(n \le 10^5\).
Samples
| Input (stdin) | Output (stdout) |
|---|---|
| 1 2 3 -1 -10 | 8 |
Submit a solution
| Element Type | Created | Who | Problem | Compiler | Result | Time (sec.) | Memory (MiB) | # | Actions |
|---|
| Element Type | Created | Who | Problem | Compiler | Result | Time (sec.) | Memory (MiB) | # | Actions |
|---|