Consider the following : For each $n\ge 1$, let $a_n$ be a finite sequence of $2n-2$ terms. We consider two cases, $n$ even and $n$ odd.
Let $n=2m$ be even. The sequence goes like this : $$1,1,2,2,3,3,\cdots, m-2, m-2, m-1, m-1, m-1, m-2, m-1, m-1, m, m, \cdots, n-4, n-4, n-3, n-3$$ i.e. $a_n(1)=a_n(2)=1, a_n(3)=a_n(4)=2$, etc.
Let $n=2m+1$ be odd. The sequence $a_n$ goes like this : $$1,1,2,2,3,3,\cdots, m-1, m-1, m, m-1, m-1, m-1, m,m,m+1, m+1,\cdots ,n-4, n-4, n-3, n-3 $$
So every integer appears twice consecutively until we reach m-1, then if it is even we get $m-1, m-2$ or if it is odd we get $m-1, m$. Then again depending on what the last number is, every integer appears consecutively twice until the end.
So my question is, can we get a closed formula for $p_n(x)=\sum_{k=1}^n a_n(k)x^{k-1}$? I can write down a closed formula for the sequence using conditions but I was wondering if there's any nice direct formula that works always. So any help would be appreciated. It's alright if you don't have or don't want to provide a proof, but I'm looking for any directions. Thanks in advance.