An interesting contest math problem: find the maximum value of $f(a_1,a_2,...,a_n)$ 
Suppose the sequence $a_1,a_2,...,a_n$ is a permutation of the sequene $1+2^1,2+2^2,...,n+2^n$. Find the maximum value of $f(a_1,a_2,...,a_n)=\vert a_1-a_2\vert+\vert a_2-a_3\vert+\cdots+\vert a_{n-1}-a_n\vert$.

This is an interesting problem found in a math contest. I used to be a contest math lover when I was a high school student. I know I may solve it by finding the possible regular formula when $n=2,3,4,...$, but the method is not always effective so I hope someone can give me some hints.
By the way, as a student majored in math now, if there exists an advanced method behind it, can anyone share it with me or at least tell me what it may related with. Thanks for your answer.

Inspired by John Omielan's answer,here is my attempt.
Our goal is to find the maximum value of \begin{equation}\begin{aligned}
f(a_1,a_2,...,a_n) & = \vert a_1-a_2\vert+\vert a_2-a_3\vert+...+\vert a_{n-1}-a_n\vert \\
& = \sum_{i=1}^{n-1}\vert a_{i} - a_{i+1} \vert
\end{aligned}\end{equation}
We can regard $f(a_1,a_2,...,a_n)$ as the foumula with coefficients$$f(a_1,a_2,...,a_n)=x_1a_1+x_2a_2+...+x_na_n$$
An important observation is that the sum of the coefficients $x_1+x_2+...+x_n$ has to be $0$.On the other hand, $a_1$ and $a_n$ appear only once and the other terms $a_i,(0\leqslant i \leqslant n-1)$ appear twice, so we get $x_1,x_n \in \{-1,1\}$, and $x_i\in\{-2,0,2\}$, $(0\leqslant i \leqslant n-1)$.
Now the problem seems to get clear.It's time to discuss $n$ is even or odd now.We first let $b_i=i+2^i,1\leqslant i \leqslant n$
$(1)$ When $n$ is even:
The coefficients $2$ appear ${n\over 2}$ times,the coefficients $-2$ appear ${n\over 2}$ times either.And the coefficients $1$ and $-1$ both appear once.
Suppose $n=2k,k\geqslant 2$
\begin{align}
f(a_1,a_2,...,a_n)&=2(b_{2k}+...+b_{k+2})+b_{k+1}-b_k-2(b_{k-1}+...+b_1)\\
&=2[(2k)+...+(k+1)-k-...-1]+k-(k+1)\\
&+2[2^{2k}+...+2^{2k-1}-2^k-...-2]+2^k-2^{k+1}\\
&=2k^2-1+2^{2k+2}-2^{k+3}-2^k+4\\
&=\frac 12 n^2+4\cdot 2^{n}-9\cdot 2^{\frac n2}+3
\end{align}
$(2)$ When $n$ is odd:
The situation is a bit different but actually both $[1]$ and $[2]$ are the same.
$[1]$ The coefficients $2$ may appear ${n-1\over 2}$ times,while $-2$ appear ${n-3\over 2}$ times,$1$ appear twice and no $-1$.
$[2]$ The coefficients $2$ appear ${n-3\over 2}$ times,while $-2$ appear ${n-1\over 2}$ times,$-1$ appear twice and no $1$.
Suppose $n=2k+1,k\geqslant 1$
\begin{align}
f(a_1,a_2,...,a_n)&=2(b_{2k+1}+...+b_{k+2})-b_{k+1}-b_k-2(b_{k-1}+...+b_1)\\
&=2[(2k+1)+...+(k+2)-(k+1)-k-...-1]+(k+1)+k\\
&+2[2^{2k+1}+...+2^{k+2}-2^{k+1}-...-2]+2^k+2^{k+1}\\
&=2k^2+2k-1+2^{2k+3}-13\cdot 2^{k+1}+4\\
&=\frac 12 n^2+4\cdot2^{n}-13\cdot 2^{n-1 \over 2}+\frac52
\end{align}
So we find the maximal value of it.
