In how many ways can you choose a group of $n$ digits from $[0,1,2]$ so that the digit $1$ will appear even number of times In how many ways can you choose a group of $n$ digits from $[0,1,2]$ {means there's no importance for the order of choice, Only the amount of times each digit is chosen} so that the digit $1$ will appear even number of times?
The answer should be a closed formula, But i don't even know how to start. Any ideas?
 A: For $i\in\{0,1,2\}$ let $x_i$ be the number of $i$’s chosen; you’re looking for the number of solutions to the equation $$x_0+x_1+x_2=n\tag{1}$$ in non-negative integers $x_0,x_1,x_2$ such that $x_1$ is even. Let $m=\left\lfloor\frac{n}2\right\rfloor$; clearly we must have $x_1=2k$ for some $k\in\{0,1,\dots,m\}$. For each such $k$ rewrite $(1)$ as $$x_0+x_2=n-2k\;.\tag{2}$$ If $a\in\Bbb N$, the equation $x+y=a$ has $a+1$ solutions in non-negative integers, since $x$ can be any element of $\{0,1,\dots,a\}$ and completely determines $y$. Thus, $(2)$ has $n-2k+1$ solutions in non-negative integers, and you want
$$\sum_{k=0}^m(n-2k+1)=\sum_{k=0}^m(n+1)-2\sum_{k=0}^mk\;.\tag{3}$$
The first summation on the righthand side of $(3)$ is very easy to evaluate in closed form, though getting rid of $m$ will require either using the floor (= greatest integer) function $\lfloor\cdot\rfloor$ or splitting the expression into separate cases for odd and even $n$. The second summation is just the sum of consecutive integers, which is pretty well-known; if you’re not familiar with it, you might want to read about sums of finite arithmetic progressions.
Added: It appears from the comments that what is really wanted is the generating function for the numbers $a_n$ given by $(3)$. Evaluating $(3)$, we find that
$$\begin{align*}a_n&=\sum_{k=0}^m(n+1)-2\sum_{k=0}^mk\\
&=(m+1)(n+1)-m(m+1)\\
&=(m+1)(n+1-m)\\
&=\left(\left\lfloor\frac{n}2\right\rfloor+1\right)\left(n+1-\left\lfloor\frac{n}2\right\rfloor\right)\\
&=\left(\left\lfloor\frac{n}2\right\rfloor+1\right)\left(\left\lceil\frac{n}2\right\rceil+1\right)\\
&=\left\lfloor\frac{n}2\right\rfloor\left\lceil\frac{n}2\right\rceil+n+1\\
&=\frac14\left(n^2-[n\text{ is odd}]\right)+n+1\;,
\end{align*}$$
where $[n\text{ is odd}]$ is an Iverson bracket. Thus,
$$\sum_{n\ge 0}a_nx^n=\frac14\sum_{n\ge 0}n^2x^n+\sum_{n\ge 0}nx^n+\sum_{n\ge 0}x^n-\frac14\sum_{n\ge 0}x^{2n+1}\;,$$
and it’s a standard exercise to find generating functions for each of these series.
A: Hint: $\sum_{k=0}^{2k\le n} (n-2k+1)$, since there is no order, there is $n-2k+1$ ways to choose $n-2k$ digits from $\{0, 2\}$.
