4. There is a single-function calculator that can only perform the operation of finding the difference between any two integers and then taking the absolute value of the result. The operation process is: input integers $x_{1}, x_{2}$, and it displays $\left|x_{1}-x_{2}\right|$ (for example, input 1, 2, and the output is 1); thereafter, each input integer is processed by finding the difference with the previous displayed result and then taking the absolute value. Input the $n$ positive integers from $1 \sim n (n \geqslant 3)$ in any order, and let the final result displayed after all inputs be $m$. Then the sum of the minimum and maximum values of $m$ is $\qquad$
4. $n-1$ or $n$ or $n+1$.

Let the order of the $n$ input numbers be $x_{1}, x_{2}, \cdots, x_{n}$.
Then $m=|| \cdots|| x_{1}-x_{2}\left|-x_{3}\right|-\cdots\left|-x_{n}\right|$, $m$ must not exceed the maximum number among $x_{1}, x_{2}, \cdots, x_{n}$.
Therefore, $0 \leqslant m \leqslant n$.
It is easy to see that $m$ has the same parity as $1+2+\cdots+n$.
$1, 2, 3$ can get 0 in this way:
$$
|| 3-2|-1|=0 \text {; }
$$

Any four consecutive positive integers can get 0 in this way:
$$
|||a-(a+1)|-(a+3)|-(a+2)|=0 \text {. (1) }
$$

Next, construct according to the parity analyzed earlier, where $k$ is a non-negative integer, and the combination of four consecutive positive integers refers to the calculation structure of equation (1).

When $n=4 k$, $1+2+\cdots+n$ is even, then $m$ is even. Combining four consecutive positive integers can get 0, so the minimum value is 0. The first three combine to get 0, then the next four combine to get 0, leaving only $n$, so the maximum value is $n$.

When $n=4 k+1$, $1+2+\cdots+n$ is odd, then $m$ is odd. Except for 1, combining four consecutive positive integers can get 0, so the minimum value is 1. Starting from 1, combining four consecutive positive integers can get 0, leaving only $n$, so the maximum value is $n$.

When $n=4 k+2$, $1+2+\cdots+n$ is odd, then $m$ is odd. Starting from 1, combining four consecutive positive integers can get 0, leaving only $n$ and $n-1$, so the minimum value is 1. Starting from 2, combining four consecutive positive integers can get 0, leaving only 1 and $n$, the maximum value is $n-1$.

When $n=4 k+3$, $1+2+\cdots+n$ is even, then $m$ is even. The first three combine to get 0, then the next four combine to get 0, so the minimum value is 0. Starting from 3, combining four consecutive positive integers can get 0, leaving only $1, 2$ and $n$, so the maximum value is $n-1$.

In summary, the sum of the minimum and maximum values of $m$ is $n-1$ or $n$ or $n+1$.