Three sequences - MarisaOJ: Marisa Online Judge

Three sequences

Time limit: 1000 ms
Memory limit: 256 MB
Given three sequences $A$, $B$, and $C$, each consisting of $n$ elements. Find three indices $1 \le i, j, k \le n$ such that $|A_i - B_j| + |B_j - C_k| + |C_k - A_i|$ is minimized. ### Input - The first line contains an integer $n$. - The second line contains $n$ integers $A_i$. - The third line contains $n$ integers $B_i$. - The fourth line contains $n$ integers $C_i$. ### Output - Print an integer, the minimum value of $|A_i - B_j| + |B_j - C_k| + |C_k - A_i|$. ### Constraints - $1 \le n \le 10^5$. - $1 \le A_i, B_i, C_i \le 10^9$. ### Example Input: ``` 3 4 2 5 3 2 1 5 5 5 ``` Output: ``` 4 ```