P8537 "Wdoi-2" Flowers Like Fantasy

Background

Winter’s white is dotted with the sunlight of spring, and Gensokyo has fully regained the colors of life. But sakura, sunflowers, wild chrysanthemums, bellflowers... even though it is still spring, all the flowers of the whole year have bloomed. The great war sixty years ago (note: 1945 in the real world), amid cannon fire and flying bullets, countless innocent souls. Sixty years later, they have fallen into fantasy one after another, resting upon every single flower. Each flower carries the essential nature of a soul. Sunflowers house the souls of cheerful people. Higanbana (pinyin: bǐ àn huā) house lonely souls with no friends, and beneath the purple cherry trees are ghosts stained with sin. Since the virtuous ghosts are sent to the other shore in order, those left to the end will all be sakura. The illusory other shore seen by humans outside is now returning to this shore of fantasy.

Description

## Brief Statement There is a sequence $a$ of length $n$. You may perform two types of operations: - Reverse the entire sequence. - Add an **integer** to some element in the sequence. Find the minimum number of operations needed to transform sequence $a$ into sequence $b$. ## Original Statement More than ten protagonists who took part in resolving the flower incident were not yet 60 years old, and had not experienced the previous flower incident. In the sea of flowers, the urgency of resolving the incident gradually faded away, replaced by playing games with flowers. Reimu arranged $n$ flowers in a row. The $i$-th flower has a corresponding beauty value $a_i$. Meanwhile, Marisa, as a magician, has two abilities. She can perform several operations. In each operation, she can **reverse the positions of these $\bm n$ flowers completely**, or she can **increase or decrease the beauty value of one flower by an integer**. Reimu believes that if Marisa’s operations can make the final beauty values of the flowers become the sequence $b_i$, that would be great. To resolve the incident smoothly, Marisa wants to use as few operations as possible. So, what is the minimum number of operations Marisa needs to satisfy Reimu’s wish? --- The flowers of Gensokyo gradually fall, and fresh green begins to step toward a beautiful season. After sixty years, there may be no memories that will not be forgotten.

Input Format

- The first line contains an integer $n$. - The second line contains $n$ integers $a_1,a_2,\cdots,a_n$. - The third line contains $n$ integers $b_1,b_2,\cdots,b_n$.

Output Format

- Output one line with an integer, representing the minimum number of operations needed.

Explanation/Hint

## Sample Explanation \#1 $$ \begin{array}{cccl} \color{red}1&\color{red}2&\color{red}3&\downarrow\text{reverse}\\ 3&2&1& \end{array} $$ ## Sample Explanation \#2 $$ \begin{array}{ccl} \color{red}3&\color{red}1&\downarrow\text{reverse}\\ 1&\color{red}3&\downarrow\text{add }-1\\ 1&2& \end{array} $$ ## Constraints $$ \def\arraystretch{1.5} \begin{array}{|c|c|c|c|}\hline \textbf{Subtask} & \bm{n\le} & \textbf{Special Property} & \textbf{Score}\\\hline 1 & 10 & - & 10\\\hline 2 & 10^3 & - & 30\\\hline 3 & 5\times 10^5 & \text{A} & 5 \\\hline 4 & 5\times 10^5 & - & 55 \\\hline \end{array}$$ - Special Property $\textbf{A}$: It is guaranteed that there exists an optimal (minimum-cost) solution that does not require performing the second type of operation. For all testdata, $1 \leq n \leq 5\times10^5$, $1 \leq a_i,b_i \leq 10^9$。 Translated by ChatGPT 5