# How to add a condition in the sum function in sage

I want to implement the following sum $\sum_{j=0}^{n}a_jx^j$ under the following conditions the coefficient $a_j=j$ if $j $ is even, or $j+1$ otherwise. My problem is how to include these cases in the sum function in sage. Normally the command is sum(a_j*x^j,j,1,n) but how to distinguish between the parity of j ?