I'm trying to find a closed-form formula of the following expression involving a particular value. Consider a list of $n$ ones and $t$ twos $(a_1,\cdots,a_{n+t})=(1_1,\cdots,1_n,2_1,\cdots,2_t)$. For example $n=2$ and $t=4$: $(1_1,1_2,2_1,2_2,2_3,2_4)$. Define the sum over all ${n+1 \choose 2}$ unique pairs of (indexed) $1$'s and $2$'s $P=\{(a_i,a_j) \;|\; 1\le i < j \le n+t\}$ as follows: $$ S = \sum_{(a_i,a_j)\in P} a_ia_j $$ The sum can be decomposed in pairs of the form $(1,1)$, $(1,2)$ and $(2,2)$, which leads (I hope I didn't make any mistakes) to $$ S = \sum_{i=1}^n \sum_{j=i+1}^n 1 + \sum_{i=1}^n \sum_{k=1}^t 2 + \sum_{j=1}^t \sum_{k=j+1}^t 4 = \frac{n(n - 1) + 4t(n + t - 1)}{2}. $$
Is there some closed-form formula involving only the total sum of the values $\varphi=n+2t$? For example, after rearranging: $$ S = \frac{n(n - 1) + 4t(\varphi - t - 1)}{2} $$ but there are still $n$ and $t$ in the expression. Can someone provide a formula in the form I'm looking for?